Skip to content

Commit fd14eb4

Browse files
author
Robert Marsh
committed
C++: remove unreachable IR operands in late stages
1 parent a404ca6 commit fd14eb4

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ private import internal.OperandInternal
1717
* An operand of an `Instruction` in this stage of the IR. Implemented as a union of the branches
1818
* of `TOperand` that are used in this stage.
1919
*/
20-
private class TStageOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
20+
private class TStageOperand =
21+
TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
2122

2223
/**
2324
* An operand of an `Instruction`. The operand represents a use of the result of one instruction
2425
* (the defining instruction) in another instruction (the use instruction)
2526
*/
2627
class Operand extends TStageOperand {
28+
Operand() {
29+
// Ensure that the operand does not refer to instructions from earlier stages that are unreachable here
30+
exists(Instruction use, Instruction def | this = registerOperand(use, _, def))
31+
or
32+
exists(Instruction use | this = nonSSAMemoryOperand(use, _))
33+
or
34+
exists(Instruction use, Instruction def, IRBlock block | this = phiOperand(use, def, block, _))
35+
or
36+
exists(Instruction use | this = chiOperand(use, _))
37+
}
38+
2739
/** Gets a textual representation of this element. */
2840
string toString() { result = "Operand" }
2941

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ private import internal.OperandInternal
1717
* An operand of an `Instruction` in this stage of the IR. Implemented as a union of the branches
1818
* of `TOperand` that are used in this stage.
1919
*/
20-
private class TStageOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
20+
private class TStageOperand =
21+
TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
2122

2223
/**
2324
* An operand of an `Instruction`. The operand represents a use of the result of one instruction
2425
* (the defining instruction) in another instruction (the use instruction)
2526
*/
2627
class Operand extends TStageOperand {
28+
Operand() {
29+
// Ensure that the operand does not refer to instructions from earlier stages that are unreachable here
30+
exists(Instruction use, Instruction def | this = registerOperand(use, _, def))
31+
or
32+
exists(Instruction use | this = nonSSAMemoryOperand(use, _))
33+
or
34+
exists(Instruction use, Instruction def, IRBlock block | this = phiOperand(use, def, block, _))
35+
or
36+
exists(Instruction use | this = chiOperand(use, _))
37+
}
38+
2739
/** Gets a textual representation of this element. */
2840
string toString() { result = "Operand" }
2941

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ private import internal.OperandInternal
1717
* An operand of an `Instruction` in this stage of the IR. Implemented as a union of the branches
1818
* of `TOperand` that are used in this stage.
1919
*/
20-
private class TStageOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
20+
private class TStageOperand =
21+
TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
2122

2223
/**
2324
* An operand of an `Instruction`. The operand represents a use of the result of one instruction
2425
* (the defining instruction) in another instruction (the use instruction)
2526
*/
2627
class Operand extends TStageOperand {
28+
Operand() {
29+
// Ensure that the operand does not refer to instructions from earlier stages that are unreachable here
30+
exists(Instruction use, Instruction def | this = registerOperand(use, _, def))
31+
or
32+
exists(Instruction use | this = nonSSAMemoryOperand(use, _))
33+
or
34+
exists(Instruction use, Instruction def, IRBlock block | this = phiOperand(use, def, block, _))
35+
or
36+
exists(Instruction use | this = chiOperand(use, _))
37+
}
38+
2739
/** Gets a textual representation of this element. */
2840
string toString() { result = "Operand" }
2941

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ private import internal.OperandInternal
1717
* An operand of an `Instruction` in this stage of the IR. Implemented as a union of the branches
1818
* of `TOperand` that are used in this stage.
1919
*/
20-
private class TStageOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
20+
private class TStageOperand =
21+
TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
2122

2223
/**
2324
* An operand of an `Instruction`. The operand represents a use of the result of one instruction
2425
* (the defining instruction) in another instruction (the use instruction)
2526
*/
2627
class Operand extends TStageOperand {
28+
Operand() {
29+
// Ensure that the operand does not refer to instructions from earlier stages that are unreachable here
30+
exists(Instruction use, Instruction def | this = registerOperand(use, _, def))
31+
or
32+
exists(Instruction use | this = nonSSAMemoryOperand(use, _))
33+
or
34+
exists(Instruction use, Instruction def, IRBlock block | this = phiOperand(use, def, block, _))
35+
or
36+
exists(Instruction use | this = chiOperand(use, _))
37+
}
38+
2739
/** Gets a textual representation of this element. */
2840
string toString() { result = "Operand" }
2941

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ private import internal.OperandInternal
1717
* An operand of an `Instruction` in this stage of the IR. Implemented as a union of the branches
1818
* of `TOperand` that are used in this stage.
1919
*/
20-
private class TStageOperand = TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
20+
private class TStageOperand =
21+
TRegisterOperand or TNonSSAMemoryOperand or TPhiOperand or TChiOperand;
2122

2223
/**
2324
* An operand of an `Instruction`. The operand represents a use of the result of one instruction
2425
* (the defining instruction) in another instruction (the use instruction)
2526
*/
2627
class Operand extends TStageOperand {
28+
Operand() {
29+
// Ensure that the operand does not refer to instructions from earlier stages that are unreachable here
30+
exists(Instruction use, Instruction def | this = registerOperand(use, _, def))
31+
or
32+
exists(Instruction use | this = nonSSAMemoryOperand(use, _))
33+
or
34+
exists(Instruction use, Instruction def, IRBlock block | this = phiOperand(use, def, block, _))
35+
or
36+
exists(Instruction use | this = chiOperand(use, _))
37+
}
38+
2739
/** Gets a textual representation of this element. */
2840
string toString() { result = "Operand" }
2941

0 commit comments

Comments
 (0)