@@ -38,24 +38,39 @@ predicate isNonEscapingArgument(Expr escaped) {
38
38
)
39
39
}
40
40
41
+ pragma [ noinline]
42
+ predicate callToMemsetWithRelevantVariable (
43
+ LocalVariable v , VariableAccess acc , FunctionCall call , MemsetFunction memset
44
+ ) {
45
+ not v .isStatic ( ) and
46
+ // Reference-typed variables get special treatment in `variableAddressEscapesTree` so we leave them
47
+ // out of this query.
48
+ not v .getUnspecifiedType ( ) instanceof ReferenceType and
49
+ call .getTarget ( ) = memset and
50
+ acc = v .getAnAccess ( ) and
51
+ // `v` escapes as the argument to `memset`
52
+ variableAddressEscapesTree ( acc , call .getArgument ( 0 ) .getFullyConverted ( ) )
53
+ }
54
+
55
+ pragma [ noinline]
56
+ predicate relevantVariable ( LocalVariable v , FunctionCall call , MemsetFunction memset ) {
57
+ exists ( VariableAccess acc , VariableAccess anotherAcc |
58
+ callToMemsetWithRelevantVariable ( v , acc , call , memset ) and
59
+ // `v` is not only just used in the call to `memset`.
60
+ anotherAcc = v .getAnAccess ( ) and
61
+ acc != anotherAcc and
62
+ not anotherAcc .isUnevaluated ( )
63
+ )
64
+ }
65
+
41
66
from FunctionCall call , LocalVariable v , MemsetFunction memset
42
67
where
43
- call . getTarget ( ) = memset and
68
+ relevantVariable ( v , call , memset ) and
44
69
not isFromMacroDefinition ( call ) and
45
- // `v` escapes as the argument to `memset`
46
- variableAddressEscapesTree ( v .getAnAccess ( ) , call .getArgument ( 0 ) .getFullyConverted ( ) ) and
47
- // ... and `v` doesn't escape anywhere else.
70
+ // `v` doesn't escape anywhere else.
48
71
forall ( Expr escape | variableAddressEscapesTree ( v .getAnAccess ( ) , escape ) |
49
72
isNonEscapingArgument ( escape )
50
73
) and
51
- not v .isStatic ( ) and
52
- // Reference-typed variables get special treatment in `variableAddressEscapesTree` so we leave them
53
- // out of this query.
54
- not v .getUnspecifiedType ( ) instanceof ReferenceType and
55
- // `v` is not only just used in the call to `memset`.
56
- exists ( Access acc |
57
- acc = v .getAnAccess ( ) and not call .getArgument ( 0 ) .getAChild * ( ) = acc and not acc .isUnevaluated ( )
58
- ) and
59
74
// There is no later use of `v`.
60
75
not v .getAnAccess ( ) = call .getASuccessor * ( ) and
61
76
// Not using the `-fno-builtin-memset` flag
0 commit comments