Merge pull request #864 from jbj/ir-TIRVariable-shared

Approved by dave-bartolomeo
This commit is contained in:
semmle-qlci
2019-02-05 07:55:28 +00:00
committed by GitHub
6 changed files with 50 additions and 121 deletions

View File

@@ -3,31 +3,7 @@ import FunctionIR
import cpp
import semmle.code.cpp.ir.implementation.TempVariableTag
private import semmle.code.cpp.ir.internal.TempVariableTag
private newtype TIRVariable =
TIRAutomaticUserVariable(LocalScopeVariable var, FunctionIR funcIR) {
exists(Function func |
func = funcIR.getFunction() and
(
var.getFunction() = func or
var.(Parameter).getCatchBlock().getEnclosingFunction() = func
)
)
} or
TIRStaticUserVariable(Variable var, FunctionIR funcIR) {
(
var instanceof GlobalOrNamespaceVariable or
var instanceof MemberVariable and not var instanceof Field
) and
exists(VariableAccess access |
access.getTarget() = var and
access.getEnclosingFunction() = funcIR.getFunction()
)
} or
TIRTempVariable(FunctionIR funcIR, Locatable ast, TempVariableTag tag,
Type type) {
Construction::hasTempVariable(funcIR.getFunction(), ast, tag, type)
}
private import semmle.code.cpp.ir.internal.TIRVariable
IRUserVariable getIRUserVariable(Function func, Variable var) {
result.getVariable() = var and
@@ -40,7 +16,7 @@ IRUserVariable getIRUserVariable(Function func, Variable var) {
* generated by the AST-to-IR translation (`IRTempVariable`).
*/
abstract class IRVariable extends TIRVariable {
FunctionIR funcIR;
Function func;
abstract string toString();
@@ -72,14 +48,14 @@ abstract class IRVariable extends TIRVariable {
* Gets the IR for the function that references this variable.
*/
final FunctionIR getFunctionIR() {
result = funcIR
result.getFunction() = func
}
/**
* Gets the function that references this variable.
*/
final Function getFunction() {
result = funcIR.getFunction()
result = func
}
}
@@ -126,7 +102,7 @@ class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable,
LocalScopeVariable localVar;
IRAutomaticUserVariable() {
this = TIRAutomaticUserVariable(localVar, funcIR) and
this = TIRAutomaticUserVariable(localVar, func) and
var = localVar
}
@@ -137,7 +113,7 @@ class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable,
class IRStaticUserVariable extends IRUserVariable, TIRStaticUserVariable {
IRStaticUserVariable() {
this = TIRStaticUserVariable(var, funcIR)
this = TIRStaticUserVariable(var, func)
}
}
@@ -152,7 +128,7 @@ class IRTempVariable extends IRVariable, IRAutomaticVariable, TIRTempVariable {
Type type;
IRTempVariable() {
this = TIRTempVariable(funcIR, ast, tag, type)
this = TIRTempVariable(func, ast, tag, type)
}
override final Type getType() {

View File

@@ -40,20 +40,8 @@ cached private module Cached {
}
private IRVariable getNewIRVariable(OldIR::IRVariable var) {
result.getFunction() = var.getFunction() and
(
exists(OldIR::IRUserVariable userVar, IRUserVariable newUserVar |
userVar = var and
newUserVar.getVariable() = userVar.getVariable() and
result = newUserVar
) or
exists(OldIR::IRTempVariable tempVar, IRTempVariable newTempVar |
tempVar = var and
newTempVar.getAST() = tempVar.getAST() and
newTempVar.getTag() = tempVar.getTag() and
result = newTempVar
)
)
// This is just a type cast. Both classes derive from the same newtype.
result = var
}
cached newtype TInstruction =

View File

@@ -3,31 +3,7 @@ import FunctionIR
import cpp
import semmle.code.cpp.ir.implementation.TempVariableTag
private import semmle.code.cpp.ir.internal.TempVariableTag
private newtype TIRVariable =
TIRAutomaticUserVariable(LocalScopeVariable var, FunctionIR funcIR) {
exists(Function func |
func = funcIR.getFunction() and
(
var.getFunction() = func or
var.(Parameter).getCatchBlock().getEnclosingFunction() = func
)
)
} or
TIRStaticUserVariable(Variable var, FunctionIR funcIR) {
(
var instanceof GlobalOrNamespaceVariable or
var instanceof MemberVariable and not var instanceof Field
) and
exists(VariableAccess access |
access.getTarget() = var and
access.getEnclosingFunction() = funcIR.getFunction()
)
} or
TIRTempVariable(FunctionIR funcIR, Locatable ast, TempVariableTag tag,
Type type) {
Construction::hasTempVariable(funcIR.getFunction(), ast, tag, type)
}
private import semmle.code.cpp.ir.internal.TIRVariable
IRUserVariable getIRUserVariable(Function func, Variable var) {
result.getVariable() = var and
@@ -40,7 +16,7 @@ IRUserVariable getIRUserVariable(Function func, Variable var) {
* generated by the AST-to-IR translation (`IRTempVariable`).
*/
abstract class IRVariable extends TIRVariable {
FunctionIR funcIR;
Function func;
abstract string toString();
@@ -72,14 +48,14 @@ abstract class IRVariable extends TIRVariable {
* Gets the IR for the function that references this variable.
*/
final FunctionIR getFunctionIR() {
result = funcIR
result.getFunction() = func
}
/**
* Gets the function that references this variable.
*/
final Function getFunction() {
result = funcIR.getFunction()
result = func
}
}
@@ -126,7 +102,7 @@ class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable,
LocalScopeVariable localVar;
IRAutomaticUserVariable() {
this = TIRAutomaticUserVariable(localVar, funcIR) and
this = TIRAutomaticUserVariable(localVar, func) and
var = localVar
}
@@ -137,7 +113,7 @@ class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable,
class IRStaticUserVariable extends IRUserVariable, TIRStaticUserVariable {
IRStaticUserVariable() {
this = TIRStaticUserVariable(var, funcIR)
this = TIRStaticUserVariable(var, func)
}
}
@@ -152,7 +128,7 @@ class IRTempVariable extends IRVariable, IRAutomaticVariable, TIRTempVariable {
Type type;
IRTempVariable() {
this = TIRTempVariable(funcIR, ast, tag, type)
this = TIRTempVariable(func, ast, tag, type)
}
override final Type getType() {

View File

@@ -3,31 +3,7 @@ import FunctionIR
import cpp
import semmle.code.cpp.ir.implementation.TempVariableTag
private import semmle.code.cpp.ir.internal.TempVariableTag
private newtype TIRVariable =
TIRAutomaticUserVariable(LocalScopeVariable var, FunctionIR funcIR) {
exists(Function func |
func = funcIR.getFunction() and
(
var.getFunction() = func or
var.(Parameter).getCatchBlock().getEnclosingFunction() = func
)
)
} or
TIRStaticUserVariable(Variable var, FunctionIR funcIR) {
(
var instanceof GlobalOrNamespaceVariable or
var instanceof MemberVariable and not var instanceof Field
) and
exists(VariableAccess access |
access.getTarget() = var and
access.getEnclosingFunction() = funcIR.getFunction()
)
} or
TIRTempVariable(FunctionIR funcIR, Locatable ast, TempVariableTag tag,
Type type) {
Construction::hasTempVariable(funcIR.getFunction(), ast, tag, type)
}
private import semmle.code.cpp.ir.internal.TIRVariable
IRUserVariable getIRUserVariable(Function func, Variable var) {
result.getVariable() = var and
@@ -40,7 +16,7 @@ IRUserVariable getIRUserVariable(Function func, Variable var) {
* generated by the AST-to-IR translation (`IRTempVariable`).
*/
abstract class IRVariable extends TIRVariable {
FunctionIR funcIR;
Function func;
abstract string toString();
@@ -72,14 +48,14 @@ abstract class IRVariable extends TIRVariable {
* Gets the IR for the function that references this variable.
*/
final FunctionIR getFunctionIR() {
result = funcIR
result.getFunction() = func
}
/**
* Gets the function that references this variable.
*/
final Function getFunction() {
result = funcIR.getFunction()
result = func
}
}
@@ -126,7 +102,7 @@ class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable,
LocalScopeVariable localVar;
IRAutomaticUserVariable() {
this = TIRAutomaticUserVariable(localVar, funcIR) and
this = TIRAutomaticUserVariable(localVar, func) and
var = localVar
}
@@ -137,7 +113,7 @@ class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable,
class IRStaticUserVariable extends IRUserVariable, TIRStaticUserVariable {
IRStaticUserVariable() {
this = TIRStaticUserVariable(var, funcIR)
this = TIRStaticUserVariable(var, func)
}
}
@@ -152,7 +128,7 @@ class IRTempVariable extends IRVariable, IRAutomaticVariable, TIRTempVariable {
Type type;
IRTempVariable() {
this = TIRTempVariable(funcIR, ast, tag, type)
this = TIRTempVariable(func, ast, tag, type)
}
override final Type getType() {

View File

@@ -40,20 +40,8 @@ cached private module Cached {
}
private IRVariable getNewIRVariable(OldIR::IRVariable var) {
result.getFunction() = var.getFunction() and
(
exists(OldIR::IRUserVariable userVar, IRUserVariable newUserVar |
userVar = var and
newUserVar.getVariable() = userVar.getVariable() and
result = newUserVar
) or
exists(OldIR::IRTempVariable tempVar, IRTempVariable newTempVar |
tempVar = var and
newTempVar.getAST() = tempVar.getAST() and
newTempVar.getTag() = tempVar.getTag() and
result = newTempVar
)
)
// This is just a type cast. Both classes derive from the same newtype.
result = var
}
cached newtype TInstruction =

View File

@@ -0,0 +1,25 @@
private import cpp
private import semmle.code.cpp.ir.implementation.TempVariableTag
private import semmle.code.cpp.ir.implementation.raw.internal.IRConstruction as Construction
newtype TIRVariable =
TIRAutomaticUserVariable(LocalScopeVariable var, Function func) {
Construction::functionHasIR(func) and
var.getFunction() = func or
var.(Parameter).getCatchBlock().getEnclosingFunction() = func
} or
TIRStaticUserVariable(Variable var, Function func) {
Construction::functionHasIR(func) and
(
var instanceof GlobalOrNamespaceVariable or
var instanceof MemberVariable and not var instanceof Field
) and
exists(VariableAccess access |
access.getTarget() = var and
access.getEnclosingFunction() = func
)
} or
TIRTempVariable(Function func, Locatable ast, TempVariableTag tag, Type type) {
Construction::hasTempVariable(func, ast, tag, type)
}