Skip to content

Commit 43f0289

Browse files
C++: Remove Phi instructions from previous IR generations
It turns out that when building aliased SSA IR, we were still keeping around the Phi instructions from unaliased SSA IR. These leftover instructions didn't show up in dumps because they were not assigned to a block. However, when dumping additional instruction properties, they would show up as a top-level node in the dump, without a label.
1 parent 46b2c19 commit 43f0289

File tree

9 files changed

+33
-11
lines changed

9 files changed

+33
-11
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ module InstructionSanity {
107107
operand = op.getOperand(tag) and
108108
operand.getFunctionIR() != op.getFunctionIR()
109109
}
110+
111+
/**
112+
* Holds if instruction `instr` is not in exactly one block.
113+
*/
114+
query predicate instructionWithoutUniqueBlock(Instruction instr, int blockCount) {
115+
blockCount = count(instr.getBlock()) and
116+
blockCount != 1
117+
}
110118
}
111119

112120
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ cached private module Cached {
3030
}
3131

3232
cached newtype TInstructionTag =
33-
WrappedInstructionTag(OldIR::Instruction oldInstruction) or
33+
WrappedInstructionTag(OldIR::Instruction oldInstruction) {
34+
not oldInstruction instanceof OldIR::PhiInstruction
35+
} or
3436
PhiTag(Alias::VirtualVariable vvar, OldIR::IRBlock block) {
3537
hasPhiNode(vvar, block)
3638
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ module InstructionSanity {
107107
operand = op.getOperand(tag) and
108108
operand.getFunctionIR() != op.getFunctionIR()
109109
}
110+
111+
/**
112+
* Holds if instruction `instr` is not in exactly one block.
113+
*/
114+
query predicate instructionWithoutUniqueBlock(Instruction instr, int blockCount) {
115+
blockCount = count(instr.getBlock()) and
116+
blockCount != 1
117+
}
110118
}
111119

112120
/**

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ module InstructionSanity {
107107
operand = op.getOperand(tag) and
108108
operand.getFunctionIR() != op.getFunctionIR()
109109
}
110+
111+
/**
112+
* Holds if instruction `instr` is not in exactly one block.
113+
*/
114+
query predicate instructionWithoutUniqueBlock(Instruction instr, int blockCount) {
115+
blockCount = count(instr.getBlock()) and
116+
blockCount != 1
117+
}
110118
}
111119

112120
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ cached private module Cached {
3030
}
3131

3232
cached newtype TInstructionTag =
33-
WrappedInstructionTag(OldIR::Instruction oldInstruction) or
33+
WrappedInstructionTag(OldIR::Instruction oldInstruction) {
34+
not oldInstruction instanceof OldIR::PhiInstruction
35+
} or
3436
PhiTag(Alias::VirtualVariable vvar, OldIR::IRBlock block) {
3537
hasPhiNode(vvar, block)
3638
}

cpp/ql/test/library-tests/ir/ir/aliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ missingPhiOperand
55
instructionWithoutSuccessor
66
unnecessaryPhiInstruction
77
operandAcrossFunctions
8+
instructionWithoutUniqueBlock

cpp/ql/test/library-tests/ir/ir/raw_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ missingPhiOperand
55
instructionWithoutSuccessor
66
unnecessaryPhiInstruction
77
operandAcrossFunctions
8+
instructionWithoutUniqueBlock

cpp/ql/test/library-tests/ir/ir/unaliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ missingPhiOperand
55
instructionWithoutSuccessor
66
unnecessaryPhiInstruction
77
operandAcrossFunctions
8+
instructionWithoutUniqueBlock

cpp/ql/test/library-tests/valuenumbering/GlobalValueNumbering/ir_gvn.expected

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@ test.cpp:
6767
# 1| v0_33(void) = UnmodeledUse : mu*
6868
# 1| v0_34(void) = ExitFunction :
6969

70-
# 53| 1644
71-
# 53| valnum = unique
72-
73-
# 56| 1646
74-
# 56| valnum = unique
75-
76-
# 88| 1755
77-
# 88| valnum = unique
78-
7970
# 12| test01(int, int) -> int
8071
# 12| Block 0
8172
# 12| v0_0(void) = EnterFunction :

0 commit comments

Comments
 (0)