mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
Merge pull request #864 from jbj/ir-TIRVariable-shared
Approved by dave-bartolomeo
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 =
|
||||
|
||||
25
cpp/ql/src/semmle/code/cpp/ir/internal/TIRVariable.qll
Normal file
25
cpp/ql/src/semmle/code/cpp/ir/internal/TIRVariable.qll
Normal 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user