@@ -16,20 +16,22 @@ import cpp
16
16
import semmle.code.cpp.ir.ValueNumbering
17
17
import semmle.code.cpp.ir.IR
18
18
19
+ predicate instructionHasVariable ( VariableAddressInstruction vai , StackVariable var , Function f ) {
20
+ var = vai .getASTVariable ( ) and
21
+ f = vai .getEnclosingFunction ( ) and
22
+ // Pointer-to-member types aren't properly handled in the dbscheme.
23
+ not vai .getResultType ( ) instanceof PointerToMemberType and
24
+ // Rule out FPs caused by extraction errors.
25
+ not any ( ErrorExpr e ) .getEnclosingFunction ( ) = f
26
+ }
27
+
19
28
/**
20
29
* Holds if `source` is the base address of an address computation whose
21
30
* result is stored in `address`.
22
31
*/
23
32
predicate stackPointerFlowsToUse ( Instruction address , VariableAddressInstruction source ) {
24
- exists ( VariableAddressInstruction var |
25
- var = address and
26
- var = source and
27
- var .getASTVariable ( ) instanceof StackVariable and
28
- // Pointer-to-member types aren't properly handled in the dbscheme.
29
- not var .getResultType ( ) instanceof PointerToMemberType and
30
- // Rule out FPs caused by extraction errors.
31
- not any ( ErrorExpr e ) .getEnclosingFunction ( ) = var .getEnclosingFunction ( )
32
- )
33
+ address = source and
34
+ instructionHasVariable ( source , _, _)
33
35
or
34
36
stackPointerFlowsToUse ( address .( CopyInstruction ) .getSourceValue ( ) , source )
35
37
or
@@ -158,11 +160,10 @@ StoreInstruction getAStoreStrictlyAfter(StoreInstruction store) {
158
160
predicate stackAddressEscapes (
159
161
StoreInstruction store , StackVariable var , TGlobalAddress globalAddress , Function f
160
162
) {
163
+ globalAddress = globalValueNumber ( store .getDestinationAddress ( ) ) and
161
164
exists ( VariableAddressInstruction vai |
162
- stackPointerFlowsToUse ( store .getSourceValue ( ) , vai ) and
163
- globalAddress = globalValueNumber ( store .getDestinationAddress ( ) ) and
164
- f = vai .getEnclosingFunction ( ) and
165
- var = vai .getASTVariable ( )
165
+ instructionHasVariable ( pragma [ only_bind_into ] ( vai ) , var , f ) and
166
+ stackPointerFlowsToUse ( store .getSourceValue ( ) , vai )
166
167
) and
167
168
// Ensure there's no subsequent store that overrides the global address.
168
169
not globalAddress = globalValueNumber ( getAStoreStrictlyAfter ( store ) .getDestinationAddress ( ) )
0 commit comments