@@ -19,30 +19,20 @@ import cpp
19
19
import codingstandards.cpp.autosar
20
20
import codingstandards.cpp.SmartPointers
21
21
22
- class AutosarSharedPointerOrDerived extends Type {
23
- AutosarSharedPointerOrDerived ( ) {
24
- this .getUnspecifiedType ( ) instanceof AutosarSharedPointer or
25
- this .getUnspecifiedType ( ) .( DerivedType ) .getBaseType ( ) instanceof AutosarSharedPointer
26
- }
27
- }
28
-
29
- Expr underlyingObjectAffectingSharedPointerExpr ( Function f ) {
30
- result =
31
- any ( VariableAccess va , FunctionCall fc |
32
- va .getEnclosingFunction ( ) = f and
33
- // The type of the variable is either a shared_ptr, or a reference or pointer to a shared_ptr
34
- va .getType ( ) instanceof AutosarSharedPointerOrDerived and
35
- fc .getQualifier ( ) = va and
36
- // include only calls to methods which modify the underlying object
37
- fc .getTarget ( ) .hasName ( [ "operator=" , "reset" , "swap" ] )
38
- |
39
- va
40
- )
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
+ )
41
31
}
42
32
43
33
predicate flowsToUnderlyingObjectAffectingExpr ( Parameter p ) {
44
34
// check if a parameter flows locally to an expression which affects smart pointer lifetime
45
- p .getType ( ) instanceof AutosarSharedPointerOrDerived and
35
+ p .getType ( ) . stripType ( ) instanceof AutosarSharedPointer and
46
36
localExprFlow ( p .getAnAccess ( ) , underlyingObjectAffectingSharedPointerExpr ( p .getFunction ( ) ) )
47
37
or
48
38
// else handle nested cases, such as passing smart pointers as reference arguments
@@ -60,7 +50,7 @@ predicate flowsToUnderlyingObjectAffectingExpr(Parameter p) {
60
50
from DefinedSmartPointerParameter p , string problem
61
51
where
62
52
not isExcluded ( p , SmartPointers1Package:: smartPointerAsParameterWithoutLifetimeSemanticsQuery ( ) ) and
63
- p .getType ( ) instanceof AutosarSharedPointerOrDerived and
53
+ p .getType ( ) . stripType ( ) instanceof AutosarSharedPointer and
64
54
(
65
55
// handle the parameter depending on its derived type
66
56
p .getType ( ) instanceof RValueReferenceType and
0 commit comments