@@ -38,24 +38,39 @@ predicate isNonEscapingArgument(Expr escaped) {
3838 )
3939}
4040
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+
4166from FunctionCall call , LocalVariable v , MemsetFunction memset
4267where
43- call . getTarget ( ) = memset and
68+ relevantVariable ( v , call , memset ) and
4469 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.
4871 forall ( Expr escape | variableAddressEscapesTree ( v .getAnAccess ( ) , escape ) |
4972 isNonEscapingArgument ( escape )
5073 ) 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
5974 // There is no later use of `v`.
6075 not v .getAnAccess ( ) = call .getASuccessor * ( ) and
6176 // Not using the `-fno-builtin-memset` flag
0 commit comments