@@ -10,6 +10,64 @@ private import semmle.code.cpp.ir.implementation.Opcode
1010private import semmle.code.cpp.models.interfaces.PointerWrapper
1111private import semmle.code.cpp.models.interfaces.SideEffect
1212
13+ private predicate isDeeplyConst ( Type t ) {
14+ t .isConst ( ) and
15+ isDeeplyConstBelow ( t )
16+ or
17+ isDeeplyConst ( t .( Decltype ) .getBaseType ( ) )
18+ or
19+ isDeeplyConst ( t .( ReferenceType ) .getBaseType ( ) )
20+ or
21+ exists ( SpecifiedType specType | specType = t |
22+ specType .getASpecifier ( ) .getName ( ) = "const" and
23+ isDeeplyConstBelow ( specType .getBaseType ( ) )
24+ )
25+ or
26+ isDeeplyConst ( t .( ArrayType ) .getBaseType ( ) )
27+ }
28+
29+ private predicate isDeeplyConstBelow ( Type t ) {
30+ t instanceof BuiltInType
31+ or
32+ not t instanceof PointerWrapper and
33+ t instanceof Class
34+ or
35+ t instanceof Enum
36+ or
37+ isDeeplyConstBelow ( t .( Decltype ) .getBaseType ( ) )
38+ or
39+ isDeeplyConst ( t .( PointerType ) .getBaseType ( ) )
40+ or
41+ isDeeplyConst ( t .( ReferenceType ) .getBaseType ( ) )
42+ or
43+ isDeeplyConstBelow ( t .( SpecifiedType ) .getBaseType ( ) )
44+ or
45+ isDeeplyConst ( t .( ArrayType ) .getBaseType ( ) )
46+ or
47+ isDeeplyConst ( t .( GNUVectorType ) .getBaseType ( ) )
48+ or
49+ isDeeplyConst ( t .( FunctionPointerIshType ) .getBaseType ( ) )
50+ or
51+ isDeeplyConst ( t .( PointerWrapper ) .getTemplateArgument ( 0 ) )
52+ or
53+ isDeeplyConst ( t .( PointerToMemberType ) .getBaseType ( ) )
54+ or
55+ isDeeplyConstBelow ( t .( TypedefType ) .getBaseType ( ) )
56+ }
57+
58+ private predicate isConstPointerLike ( Type t ) {
59+ (
60+ t instanceof PointerWrapper
61+ or
62+ t instanceof PointerType
63+ or
64+ t instanceof ArrayType
65+ or
66+ t instanceof ReferenceType
67+ ) and
68+ isDeeplyConstBelow ( t )
69+ }
70+
1371/**
1472 * Holds if the specified call has a side effect that does not come from a `SideEffectFunction`
1573 * model.
@@ -45,7 +103,7 @@ private predicate hasDefaultSideEffect(Call call, ParameterIndex i, boolean buff
45103 ) and
46104 (
47105 isWrite = true and
48- not call .getTarget ( ) .getParameter ( i ) .getType ( ) . isDeeplyConstBelow ( )
106+ not isConstPointerLike ( call .getTarget ( ) .getParameter ( i ) .getUnderlyingType ( ) )
49107 or
50108 isWrite = false
51109 )
0 commit comments