Skip to content

Commit daabb2c

Browse files
authored
Merge pull request github#2082 from rdmarsh2/rdmarsh/cpp/ir-getASTVariable
IR: add getASTVariable to VariableInstruction
2 parents c8e5be7 + 6e587f3 commit daabb2c

File tree

15 files changed

+47
-22
lines changed

15 files changed

+47
-22
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,12 @@ class VariableInstruction extends Instruction {
611611

612612
override string getImmediateString() { result = var.toString() }
613613

614-
final IRVariable getVariable() { result = var }
614+
final IRVariable getIRVariable() { result = var }
615+
616+
/**
617+
* Gets the AST variable that this instruction's IR variable refers to, if one exists.
618+
*/
619+
final Language::Variable getASTVariable() { result = var.(IRUserVariable).getVariable() }
615620
}
616621

617622
class FieldInstruction extends Instruction {

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/ValueNumbering.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ private predicate variableAddressValueNumber(
135135
VariableAddressInstruction instr, IRFunction irFunc, IRVariable var
136136
) {
137137
instr.getEnclosingIRFunction() = irFunc and
138-
instr.getVariable() = var
138+
instr.getIRVariable() = var
139139
}
140140

141141
private predicate initializeParameterValueNumber(
142142
InitializeParameterInstruction instr, IRFunction irFunc, IRVariable var
143143
) {
144144
instr.getEnclosingIRFunction() = irFunc and
145-
instr.getVariable() = var
145+
instr.getIRVariable() = var
146146
}
147147

148148
private predicate initializeThisValueNumber(InitializeThisInstruction instr, IRFunction irFunc) {

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private predicate automaticVariableAddressEscapes(IRAutomaticVariable var) {
282282
// The variable's address escapes if the result of any
283283
// VariableAddressInstruction that computes the variable's address escapes.
284284
exists(VariableAddressInstruction instr |
285-
instr.getVariable() = var and
285+
instr.getIRVariable() = var and
286286
resultEscapesNonReturn(instr)
287287
)
288288
}
@@ -305,7 +305,7 @@ predicate variableAddressEscapes(IRVariable var) {
305305
*/
306306
predicate resultPointsTo(Instruction instr, IRVariable var, IntValue bitOffset) {
307307
// The address of a variable points to that variable, at offset 0.
308-
instr.(VariableAddressInstruction).getVariable() = var and
308+
instr.(VariableAddressInstruction).getIRVariable() = var and
309309
bitOffset = 0
310310
or
311311
exists(Operand operand, IntValue originalBitOffset, IntValue propagatedBitOffset |

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private module Cached {
334334
IRVariable getInstructionVariable(Instruction instruction) {
335335
result = getNewIRVariable(getOldInstruction(instruction)
336336
.(OldIR::VariableInstruction)
337-
.getVariable())
337+
.getIRVariable())
338338
}
339339

340340
cached

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,12 @@ class VariableInstruction extends Instruction {
611611

612612
override string getImmediateString() { result = var.toString() }
613613

614-
final IRVariable getVariable() { result = var }
614+
final IRVariable getIRVariable() { result = var }
615+
616+
/**
617+
* Gets the AST variable that this instruction's IR variable refers to, if one exists.
618+
*/
619+
final Language::Variable getASTVariable() { result = var.(IRUserVariable).getVariable() }
615620
}
616621

617622
class FieldInstruction extends Instruction {

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ private predicate variableAddressValueNumber(
135135
VariableAddressInstruction instr, IRFunction irFunc, IRVariable var
136136
) {
137137
instr.getEnclosingIRFunction() = irFunc and
138-
instr.getVariable() = var
138+
instr.getIRVariable() = var
139139
}
140140

141141
private predicate initializeParameterValueNumber(
142142
InitializeParameterInstruction instr, IRFunction irFunc, IRVariable var
143143
) {
144144
instr.getEnclosingIRFunction() = irFunc and
145-
instr.getVariable() = var
145+
instr.getIRVariable() = var
146146
}
147147

148148
private predicate initializeThisValueNumber(InitializeThisInstruction instr, IRFunction irFunc) {

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,12 @@ class VariableInstruction extends Instruction {
611611

612612
override string getImmediateString() { result = var.toString() }
613613

614-
final IRVariable getVariable() { result = var }
614+
final IRVariable getIRVariable() { result = var }
615+
616+
/**
617+
* Gets the AST variable that this instruction's IR variable refers to, if one exists.
618+
*/
619+
final Language::Variable getASTVariable() { result = var.(IRUserVariable).getVariable() }
615620
}
616621

617622
class FieldInstruction extends Instruction {

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/ValueNumbering.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ private predicate variableAddressValueNumber(
135135
VariableAddressInstruction instr, IRFunction irFunc, IRVariable var
136136
) {
137137
instr.getEnclosingIRFunction() = irFunc and
138-
instr.getVariable() = var
138+
instr.getIRVariable() = var
139139
}
140140

141141
private predicate initializeParameterValueNumber(
142142
InitializeParameterInstruction instr, IRFunction irFunc, IRVariable var
143143
) {
144144
instr.getEnclosingIRFunction() = irFunc and
145-
instr.getVariable() = var
145+
instr.getIRVariable() = var
146146
}
147147

148148
private predicate initializeThisValueNumber(InitializeThisInstruction instr, IRFunction irFunc) {

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private predicate automaticVariableAddressEscapes(IRAutomaticVariable var) {
282282
// The variable's address escapes if the result of any
283283
// VariableAddressInstruction that computes the variable's address escapes.
284284
exists(VariableAddressInstruction instr |
285-
instr.getVariable() = var and
285+
instr.getIRVariable() = var and
286286
resultEscapesNonReturn(instr)
287287
)
288288
}
@@ -305,7 +305,7 @@ predicate variableAddressEscapes(IRVariable var) {
305305
*/
306306
predicate resultPointsTo(Instruction instr, IRVariable var, IntValue bitOffset) {
307307
// The address of a variable points to that variable, at offset 0.
308-
instr.(VariableAddressInstruction).getVariable() = var and
308+
instr.(VariableAddressInstruction).getIRVariable() = var and
309309
bitOffset = 0
310310
or
311311
exists(Operand operand, IntValue originalBitOffset, IntValue propagatedBitOffset |

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private module Cached {
334334
IRVariable getInstructionVariable(Instruction instruction) {
335335
result = getNewIRVariable(getOldInstruction(instruction)
336336
.(OldIR::VariableInstruction)
337-
.getVariable())
337+
.getIRVariable())
338338
}
339339

340340
cached

0 commit comments

Comments
 (0)