Skip to content

Commit bb204a0

Browse files
committed
C++: Phi instruction toString based on memory locs
1 parent 614a765 commit bb204a0

File tree

8 files changed

+51
-5
lines changed

8 files changed

+51
-5
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Instruction extends Construction::TStageInstruction {
4141
}
4242

4343
/** Gets a textual representation of this element. */
44-
final string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
44+
string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
4545

4646
/**
4747
* Gets a string showing the result, opcode, and operands of the instruction, equivalent to what
@@ -2035,6 +2035,11 @@ class PhiInstruction extends Instruction {
20352035
result = this.getAnOperand() and
20362036
result.getPredecessorBlock() = predecessorBlock
20372037
}
2038+
2039+
2040+
override string toString() {
2041+
result = "Phi: " + Construction::getPhiLocationString(this)
2042+
}
20382043
}
20392044

20402045
/**

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,13 @@ predicate canReuseSsaForMemoryResult(Instruction instruction) {
10011001
// We don't support reusing SSA for any location that could create a `Chi` instruction.
10021002
}
10031003

1004+
string getPhiLocationString(PhiInstruction phi) {
1005+
exists(Alias::MemoryLocation loc |
1006+
phi = getPhi(_, loc) and
1007+
result = loc.toString()
1008+
)
1009+
}
1010+
10041011
/** DEPRECATED: Alias for canReuseSsaForMemoryResult */
10051012
deprecated predicate canReuseSSAForMemoryResult = canReuseSsaForMemoryResult/1;
10061013

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Instruction extends Construction::TStageInstruction {
4141
}
4242

4343
/** Gets a textual representation of this element. */
44-
final string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
44+
string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
4545

4646
/**
4747
* Gets a string showing the result, opcode, and operands of the instruction, equivalent to what
@@ -2035,6 +2035,11 @@ class PhiInstruction extends Instruction {
20352035
result = this.getAnOperand() and
20362036
result.getPredecessorBlock() = predecessorBlock
20372037
}
2038+
2039+
2040+
override string toString() {
2041+
result = "Phi: " + Construction::getPhiLocationString(this)
2042+
}
20382043
}
20392044

20402045
/**

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Instruction extends Construction::TStageInstruction {
4141
}
4242

4343
/** Gets a textual representation of this element. */
44-
final string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
44+
string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
4545

4646
/**
4747
* Gets a string showing the result, opcode, and operands of the instruction, equivalent to what
@@ -2035,6 +2035,11 @@ class PhiInstruction extends Instruction {
20352035
result = this.getAnOperand() and
20362036
result.getPredecessorBlock() = predecessorBlock
20372037
}
2038+
2039+
2040+
override string toString() {
2041+
result = "Phi: " + Construction::getPhiLocationString(this)
2042+
}
20382043
}
20392044

20402045
/**

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,13 @@ predicate canReuseSsaForMemoryResult(Instruction instruction) {
10011001
// We don't support reusing SSA for any location that could create a `Chi` instruction.
10021002
}
10031003

1004+
string getPhiLocationString(PhiInstruction phi) {
1005+
exists(Alias::MemoryLocation loc |
1006+
phi = getPhi(_, loc) and
1007+
result = loc.toString()
1008+
)
1009+
}
1010+
10041011
/** DEPRECATED: Alias for canReuseSsaForMemoryResult */
10051012
deprecated predicate canReuseSSAForMemoryResult = canReuseSsaForMemoryResult/1;
10061013

csharp/ql/src/experimental/ir/implementation/raw/Instruction.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Instruction extends Construction::TStageInstruction {
4141
}
4242

4343
/** Gets a textual representation of this element. */
44-
final string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
44+
string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
4545

4646
/**
4747
* Gets a string showing the result, opcode, and operands of the instruction, equivalent to what
@@ -2035,6 +2035,11 @@ class PhiInstruction extends Instruction {
20352035
result = this.getAnOperand() and
20362036
result.getPredecessorBlock() = predecessorBlock
20372037
}
2038+
2039+
2040+
override string toString() {
2041+
result = "Phi: " + Construction::getPhiLocationString(this)
2042+
}
20382043
}
20392044

20402045
/**

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Instruction extends Construction::TStageInstruction {
4141
}
4242

4343
/** Gets a textual representation of this element. */
44-
final string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
44+
string toString() { result = this.getOpcode().toString() + ": " + this.getAst().toString() }
4545

4646
/**
4747
* Gets a string showing the result, opcode, and operands of the instruction, equivalent to what
@@ -2035,6 +2035,11 @@ class PhiInstruction extends Instruction {
20352035
result = this.getAnOperand() and
20362036
result.getPredecessorBlock() = predecessorBlock
20372037
}
2038+
2039+
2040+
override string toString() {
2041+
result = "Phi: " + Construction::getPhiLocationString(this)
2042+
}
20382043
}
20392044

20402045
/**

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/internal/SSAConstruction.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,13 @@ predicate canReuseSsaForMemoryResult(Instruction instruction) {
10011001
// We don't support reusing SSA for any location that could create a `Chi` instruction.
10021002
}
10031003

1004+
string getPhiLocationString(PhiInstruction phi) {
1005+
exists(Alias::MemoryLocation loc |
1006+
phi = getPhi(_, loc) and
1007+
result = loc.toString()
1008+
)
1009+
}
1010+
10041011
/** DEPRECATED: Alias for canReuseSsaForMemoryResult */
10051012
deprecated predicate canReuseSSAForMemoryResult = canReuseSsaForMemoryResult/1;
10061013

0 commit comments

Comments
 (0)