C++: Update escape analysis tests to new API

This commit is contained in:
Dave Bartolomeo
2020-01-28 10:57:07 -07:00
parent bb9485d548
commit 7013bc6bf4
2 changed files with 12 additions and 10 deletions

View File

@@ -16,9 +16,9 @@ where
exists(IRFunction irFunc |
irFunc = var.getEnclosingIRFunction() and
(
shouldEscape(var) and variableAddressEscapes(var)
shouldEscape(var) and allocationEscapes(var)
or
not shouldEscape(var) and not variableAddressEscapes(var)
not shouldEscape(var) and not allocationEscapes(var)
)
)
select var

View File

@@ -1,23 +1,25 @@
import default
import semmle.code.cpp.ir.implementation.aliased_ssa.internal.AliasAnalysis
import semmle.code.cpp.ir.implementation.aliased_ssa.internal.AliasConfiguration
import semmle.code.cpp.ir.implementation.unaliased_ssa.IR
import semmle.code.cpp.ir.implementation.UseSoundEscapeAnalysis
predicate shouldEscape(IRAutomaticUserVariable var) {
exists(string name |
name = var.getVariable().getName() and
name.matches("no_%")
)
class InterestingAllocation extends VariableAllocation {
IRUserVariable userVar;
InterestingAllocation() { userVar = this.getIRVariable() }
final predicate shouldEscape() { userVar.getVariable().getName().matches("no_%") }
}
from IRAutomaticUserVariable var
from InterestingAllocation var
where
exists(IRFunction irFunc |
irFunc = var.getEnclosingIRFunction() and
(
shouldEscape(var) and variableAddressEscapes(var)
var.shouldEscape() and allocationEscapes(var)
or
not shouldEscape(var) and not variableAddressEscapes(var)
not var.shouldEscape() and not allocationEscapes(var)
)
)
select var