Skip to content

Commit 0f58887

Browse files
author
Robert Marsh
committed
C++: unique value number for filtered instructions
Instructions that are removed from the normal value numbering recursion because they have a duplicated type or AST element get unique value numbers rather than going unnumbered. This ensures comparisons of value numbers using `!=` hold for filtered instructions.
1 parent ed7888c commit 0f58887

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ private predicate numberableInstruction(Instruction instr) {
9696
instr instanceof LoadTotalOverlapInstruction
9797
}
9898

99+
private predicate filteredNumberableInstruction(Instruction instr) {
100+
// count rather than strictcount to handle missing AST elements
101+
// separate instanceof and inline casts to avoid failed casts with a count of 0
102+
instr instanceof VariableAddressInstruction and
103+
count(instr.(VariableAddressInstruction).getIRVariable().getAST()) != 1
104+
or
105+
instr instanceof ConstantInstruction and
106+
count(instr.getResultIRType()) != 1
107+
or
108+
instr instanceof FieldAddressInstruction and
109+
count(instr.(FieldAddressInstruction).getField()) != 1
110+
}
111+
99112
private predicate variableAddressValueNumber(
100113
VariableAddressInstruction instr, IRFunction irFunc, Language::AST ast
101114
) {
@@ -208,7 +221,11 @@ private predicate loadTotalOverlapValueNumber(
208221
private predicate uniqueValueNumber(Instruction instr, IRFunction irFunc) {
209222
instr.getEnclosingIRFunction() = irFunc and
210223
not instr.getResultIRType() instanceof IRVoidType and
211-
not numberableInstruction(instr)
224+
(
225+
not numberableInstruction(instr)
226+
or
227+
filteredNumberableInstruction(instr)
228+
)
212229
}
213230

214231
/**

0 commit comments

Comments
 (0)