Skip to content

Commit a79ad24

Browse files
authored
Merge pull request #338 from github/lcartey/final-compiler-compat-issues
Fixing the final compatibility issues
2 parents a03c176 + a24fca8 commit a79ad24

File tree

50 files changed

+501
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+501
-374
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A8-4-13`
2+
- Address false positives caused by missing modelling of modifying operations for smart pointers for some standard libraries (such as libstdc++).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- `A20-8-1`/`MEM56-CPP`
2+
- Address false negatives caused by lack of modelling of flow through smart pointers.
3+
- Reduce flow paths through standard library headers to simplify results.
4+
- `A18-1-4`
5+
- Address false positives caused by missing modelling of modifying operations for smart pointers for some standard libraries (such as libstdc++).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `STR51-CPP`
2+
- Address false negatives caused by incomplete modelling of the `std::string::replace()` function.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `A15-5-1`
2+
- Rephrase alert message for `noalert(false)` special functions to clarify that this permits exceptions.
3+
- Additional results for implicit `noexcept(true)` special functions highlighting that the specification should be made explicit.

cpp/autosar/src/rules/A15-2-2/ConstructorErrorLeavesObjectInInvalidState.ql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,18 @@ class DeleteWrapperFunction extends Function {
7878
class ExceptionThrownInConstructor extends ExceptionThrowingExpr {
7979
Constructor c;
8080

81-
ExceptionThrownInConstructor() { exists(getAFunctionThrownType(c, this)) }
81+
ExceptionThrownInConstructor() {
82+
exists(getAFunctionThrownType(c, this)) and
83+
// The constructor is within the users source code
84+
exists(c.getFile().getRelativePath())
85+
}
8286

8387
Constructor getConstructor() { result = c }
8488
}
8589

90+
/**
91+
* Add the `nodes` predicate to ensure results with an empty path are still reported.
92+
*/
8693
query predicate nodes(ExceptionFlowNode node) { any() }
8794

8895
from

cpp/autosar/src/rules/A15-5-1/SpecialFunctionMissingNoExceptSpecification.ql

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,25 @@ import codingstandards.cpp.exceptions.ExceptionSpecifications
2222
from SpecialFunction f, string message
2323
where
2424
not isExcluded(f, Exceptions2Package::specialFunctionMissingNoExceptSpecificationQuery()) and
25-
not isNoExceptTrue(f) and
25+
not isFDENoExceptTrue(f.getDefinition()) and
2626
not f.isCompilerGenerated() and
2727
not f.isDeleted() and
2828
not f.isDefaulted() and
2929
(
3030
isNoExceptExplicitlyFalse(f) and
31-
message = f.getQualifiedName() + " should not be noexcept(false)."
31+
message =
32+
"Special function " + f.getQualifiedName() +
33+
" has a noexcept(false) specification that permits exceptions."
3234
or
35+
isNoExceptTrue(f) and
36+
message =
37+
f.getQualifiedName() +
38+
" has an implicit noexcept(true) specification but should make that explicit."
39+
or
40+
not isNoExceptTrue(f) and
3341
not isNoExceptExplicitlyFalse(f) and
34-
message = f.getQualifiedName() + " is implicitly noexcept(false) and might throw."
42+
message =
43+
"Special function " + f.getQualifiedName() +
44+
" has an implicit noexcept(false) specification that permits exceptions."
3545
)
3646
select f, message

cpp/autosar/src/rules/A18-1-4/PointerToAnElementOfAnArrayPassedToASmartPointer.ql

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,28 @@ class SingleObjectSmartPointerArrayConstructionConfig extends TaintTracking::Con
4646
(
4747
sp.getAConstructorCallWithExternalObjectConstruction().getAnArgument() = sink.asExpr()
4848
or
49-
sink.asExpr() =
50-
any(FunctionCall fc, MemberFunction mf |
51-
mf = fc.getTarget() and
52-
mf.getDeclaringType() = sp and
53-
mf.getName() = "reset"
54-
|
55-
fc.getArgument(0)
56-
)
49+
sink.asExpr() = sp.getAResetCall().getArgument(0)
5750
)
5851
)
5952
}
53+
54+
override predicate isAdditionalTaintStep(DataFlow::Node source, DataFlow::Node sink) {
55+
exists(AutosarUniquePointer sp, FunctionCall fc |
56+
fc = sp.getAReleaseCall() and
57+
source.asExpr() = fc.getQualifier() and
58+
sink.asExpr() = fc
59+
)
60+
}
61+
62+
override predicate isSanitizerIn(DataFlow::Node node) {
63+
// Exclude flow into header files outside the source archive which are summarized by the
64+
// additional taint steps above.
65+
exists(AutosarUniquePointer sp |
66+
sp.getAReleaseCall().getTarget() = node.asExpr().(ThisExpr).getEnclosingFunction()
67+
|
68+
not exists(node.getLocation().getFile().getRelativePath())
69+
)
70+
}
6071
}
6172

6273
from

cpp/autosar/src/rules/A8-4-13/SharedPtrPassedToFunctionWithImproperSemantics.ql

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@ import cpp
1919
import codingstandards.cpp.autosar
2020
import codingstandards.cpp.SmartPointers
2121

22-
Expr underlyingObjectAffectingSharedPointerExpr(Function f) {
23-
result =
24-
any(VariableAccess va, FunctionCall fc |
25-
va.getEnclosingFunction() = f and
26-
// strip the type so as to include reference parameter types
27-
va.getType().stripType() instanceof AutosarSharedPointer and
28-
fc.getTarget().getDeclaringType().stripType() instanceof AutosarSharedPointer and
29-
fc.getQualifier() = va and
30-
// include only calls to methods which modify the underlying object
31-
fc.getTarget().hasName(["operator=", "reset", "swap"])
32-
|
33-
va
34-
)
22+
VariableAccess underlyingObjectAffectingSharedPointerExpr(Function f) {
23+
exists(FunctionCall fc |
24+
// Find a call in the function
25+
fc.getEnclosingFunction() = f and
26+
// include only calls to methods which modify the underlying object
27+
fc = any(AutosarSharedPointer s).getAModifyingCall() and
28+
// Report the qualifier
29+
fc.getQualifier() = result
30+
)
3531
}
3632

3733
predicate flowsToUnderlyingObjectAffectingExpr(Parameter p) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-w

cpp/autosar/test/rules/A12-0-2/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <cstdlib>
2-
#include <string>
2+
#include <cstring>
33

44
class A {
55
public:

0 commit comments

Comments
 (0)