Skip to content

Commit 9bb97a9

Browse files
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/resolves-to-type-lib
2 parents ae3ce28 + cf6f60c commit 9bb97a9

34 files changed

+3291
-434
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ When reviewing tests, it is critical to:
5555
- Check that there are no `.expected` rows that refer to test code cases marked as `COMPLIANT`, or with no comment
5656
- Note that it is OK if the locations of the comment are not precisely aligned with the alert
5757
- Check that the alert message and placeholders are accurate and understandable.
58+
- Check that the locations do not refer to files in the standard library, as these have issues in GitHub's Code Scanning UI and complicate our compiler compatibility tests.
5859
- Consider the "test coverage" of the query, are each of its logical statements effectively exercised individually, collectively? The test should neither be overly bloated nor under specified.
5960
- Consider the edge cases of the language itself, will the analysis work in non-trivial cases, are all relevant language concepts tested here? This doesn't need to be exhaustive, but it should be thoughfully thorough.

c/common/src/codingstandards/c/Objects.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cpp
2-
import codingstandards.c.StorageDuration
2+
import codingstandards.cpp.lifetimes.StorageDuration
33
import codingstandards.c.IdentifierLinkage
44
import semmle.code.cpp.valuenumbering.HashCons
55
import codingstandards.cpp.Clvalues
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `A-23-0-1`, `A-23-0-2`, `CTR-51-CPP`, `CTR-52-CPP`, `CTR-53-CPP`, `CTR-54-CPP`, `CTR-55-CPP`, `STR-52-CPP` - `IteratorImplicitlyConvertedToConstIterator.ql`, `ValidContainerElementAccess.ql`, `UsesValidContainerElementAccess.ql`, `GuaranteeGenericCppLibraryFunctionsDoNotOverflow.ql`, `UseValidIteratorRanges.ql`, `DoNotSubtractIteratorsForDifferentContainers.ql`, `DoNotUseAnAdditiveOperatorOnAnIterator.ql`, `UseValidReferencesForElementsOfString.ql`:
2+
- Iterator access methods `rbegin`, `rend`, `crbegin`, `crend` are now recognized on containers.
3+
- Shared library `Iterators.qll` has been refactored by splitting out container type logic into a separate library and add logic to differentiate types of containers, such as associative, indexed, and strings.
4+
- Shared library `Iterators.qll`, used by many queries, has been moved.

cpp/autosar/src/rules/A23-0-1/IteratorImplicitlyConvertedToConstIterator.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import cpp
1515
import codingstandards.cpp.autosar
16-
import codingstandards.cpp.Iterators
16+
import codingstandards.cpp.standardlibrary.Iterators
1717

1818
/*
1919
* Due to inconsistent typedefs across STL containers the way this is parsed

cpp/autosar/test/rules/A23-0-1/IteratorImplicitlyConvertedToConstIterator.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
| test.cpp:10:39:10:48 | call to __iterator | Non-const version of container call immediately converted to a `const_iterator`. |
22
| test.cpp:13:38:13:42 | call to begin | Non-const version of container call immediately converted to a `const_iterator`. |
33
| test.cpp:16:44:16:48 | call to begin | Non-const version of container call immediately converted to a `const_iterator`. |
4-
| test.cpp:19:43:19:47 | call to begin | Non-const version of container call immediately converted to a `const_iterator`. |
5-
| test.cpp:22:50:22:54 | call to begin | Non-const version of container call immediately converted to a `const_iterator`. |
4+
| test.cpp:19:41:19:50 | call to __iterator | Non-const version of container call immediately converted to a `const_iterator`. |
5+
| test.cpp:22:47:22:57 | call to __iterator | Non-const version of container call immediately converted to a `const_iterator`. |
66
| test.cpp:25:8:25:16 | call to __iterator | Non-const version of container call immediately converted to a `const_iterator`. |
77
| test.cpp:27:10:27:14 | call to begin | Non-const version of container call immediately converted to a `const_iterator`. |
88
| test.cpp:29:11:29:15 | call to begin | Non-const version of container call immediately converted to a `const_iterator`. |

cpp/cert/src/rules/CTR52-CPP/GuaranteeGenericCppLibraryFunctionsDoNotOverflow.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import cpp
2020
import codingstandards.cpp.cert
21-
import codingstandards.cpp.Iterators
21+
import codingstandards.cpp.standardlibrary.Iterators
2222
import codingstandards.cpp.rules.containeraccesswithoutrangecheck.ContainerAccessWithoutRangeCheck as ContainerAccessWithoutRangeCheck
2323
import semmle.code.cpp.controlflow.Guards
2424
import semmle.code.cpp.dataflow.TaintTracking

cpp/cert/src/rules/CTR53-CPP/UseValidIteratorRanges.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import cpp
2020
import codingstandards.cpp.cert
21-
import codingstandards.cpp.Iterators
21+
import codingstandards.cpp.standardlibrary.Iterators
2222
import semmle.code.cpp.dataflow.DataFlow
2323

2424
predicate startEndArgumentsDoNotPointToTheSameContainer(

cpp/cert/src/rules/CTR54-CPP/DoNotSubtractIteratorsForDifferentContainers.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import cpp
2020
import codingstandards.cpp.cert
21-
import codingstandards.cpp.Iterators
21+
import codingstandards.cpp.standardlibrary.Iterators
2222

2323
/** Models the subtraction operator */
2424
class SubtractionOperator extends Function {

cpp/cert/src/rules/CTR55-CPP/DoNotUseAnAdditiveOperatorOnAnIterator.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import cpp
2020
import codingstandards.cpp.cert
21-
import codingstandards.cpp.Iterators
21+
import codingstandards.cpp.standardlibrary.Iterators
2222
import semmle.code.cpp.controlflow.Dominance
2323
import semmle.code.cpp.dataflow.DataFlow
2424

cpp/common/src/codingstandards/cpp/Iterators.qll

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -252,78 +252,6 @@ class AdditiveOperatorFunctionCall extends FunctionCall {
252252
}
253253
}
254254

255-
/**
256-
* Models a collection of STL container classes.
257-
*/
258-
class STLContainer extends Class {
259-
STLContainer() {
260-
getNamespace() instanceof StdNS and
261-
getSimpleName() in [
262-
"vector", "list", "deque", "set", "multiset", "map", "multimap", "stack", "queue",
263-
"priority_queue", "string", "forward_list", "unordered_set", "unordered_multiset",
264-
"unordered_map", "unordered_multimap", "valarray", "string", "basic_string"
265-
]
266-
or
267-
getSimpleName() = "string"
268-
or
269-
getSimpleName() = "basic_string"
270-
}
271-
272-
/**
273-
* Get a call to a named function of this class.
274-
*/
275-
FunctionCall getACallTo(string name) {
276-
exists(Function f |
277-
f = getAMemberFunction() and
278-
f.hasName(name) and
279-
result = f.getACallToThisFunction()
280-
)
281-
}
282-
283-
/**
284-
* Gets all calls to all functions of this class.
285-
*/
286-
FunctionCall getACallToAFunction() {
287-
exists(Function f |
288-
f = getAMemberFunction() and
289-
result = f.getACallToThisFunction()
290-
)
291-
}
292-
293-
FunctionCall getACallToSize() { result = getACallTo("size") }
294-
295-
FunctionCall getANonConstIteratorBeginFunctionCall() { result = getACallTo("begin") }
296-
297-
IteratorSource getAConstIteratorBeginFunctionCall() { result = getACallTo("cbegin") }
298-
299-
IteratorSource getANonConstIteratorEndFunctionCall() { result = getACallTo("end") }
300-
301-
IteratorSource getAConstIteratorEndFunctionCall() { result = getACallTo("cend") }
302-
303-
IteratorSource getANonConstIteratorFunctionCall() {
304-
result = getACallToAFunction() and
305-
result.getTarget().getType() instanceof NonConstIteratorType
306-
}
307-
308-
IteratorSource getAConstIteratorFunctionCall() {
309-
result = getACallToAFunction() and
310-
result.getTarget().getType() instanceof ConstIteratorType
311-
}
312-
313-
IteratorSource getAnIteratorFunctionCall() {
314-
result = getANonConstIteratorFunctionCall() or result = getAConstIteratorFunctionCall()
315-
}
316-
317-
IteratorSource getAnIteratorBeginFunctionCall() {
318-
result = getANonConstIteratorBeginFunctionCall() or
319-
result = getAConstIteratorBeginFunctionCall()
320-
}
321-
322-
IteratorSource getAnIteratorEndFunctionCall() {
323-
result = getANonConstIteratorEndFunctionCall() or result = getAConstIteratorEndFunctionCall()
324-
}
325-
}
326-
327255
/**
328256
* Models the set of iterator sources. Useful for encapsulating dataflow coming
329257
* from a function call producing an iterator.
@@ -338,13 +266,6 @@ class IteratorSource extends FunctionCall {
338266
Variable getOwner() { result = getQualifier().(VariableAccess).getTarget() }
339267
}
340268

341-
/**
342-
* Models a variable that is a `STLContainer`
343-
*/
344-
class STLContainerVariable extends Variable {
345-
STLContainerVariable() { getType() instanceof STLContainer }
346-
}
347-
348269
/**
349270
* Usually an iterator range consists of two sequential iterator arguments, for
350271
* example, the start and end. However, there are exceptions to this rule so

0 commit comments

Comments
 (0)