Skip to content

Commit 04ce405

Browse files
committed
C++: Add more comments to describe the constant expression hack.
1 parent 5b5c1de commit 04ce405

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,14 @@ module GuardsInput implements SharedGuards::InputSig<Cpp::Location, Instruction,
9797
this.(ConstantInstruction).getValue().toInt() = value and
9898
this.getResultIRType() instanceof IRIntegerType
9999
or
100-
// In order to have an "integer constant" for a switch case
100+
// In order to have an integer constant for a switch case
101101
// we misuse the first instruction (which is always a NoOp instruction)
102102
// as a constant with the switch case's value.
103+
// Even worse, since we need a case range to generate an `TIntRange`
104+
// guard value we must ensure that there exists `ConstantExpr`s whose
105+
// integer value is the end-points. So we let this constant expression
106+
// have both end-point values. Luckily, these `NoOp` instructions do not
107+
// interact with SSA in any way. So this should not break anything.
103108
exists(CaseEdge edge | this = any(SwitchInstruction switch).getSuccessor(edge) |
104109
value = edge.getMaxValue().toInt()
105110
or

0 commit comments

Comments
 (0)