C++: Fully delete TRange.

This commit is contained in:
Mathias Vorreiter Pedersen
2025-09-25 08:30:42 +01:00
parent a07d03f49b
commit b169ccf29a

View File

@@ -30,35 +30,10 @@ module GuardsInput implements SharedGuards::InputSig<Cpp::Location, Instruction,
IRCfg::BasicBlock getBasicBlock() { result = this.getBlock() } IRCfg::BasicBlock getBasicBlock() { result = this.getBlock() }
} }
private newtype TConstantValue =
// This is slightly abusing the shared guards library. Using
// `TRange(40, 50)` to model a constant expression in the program such as
// the literal "42" causes the shared guards library to make incorrect
// inferences.
// However, since we only use them to model `CaseConstant::asConstantValue`
// this does not cause any wrong inferences (at least for now).
TRange(string minValue, string maxValue) {
minValue != maxValue and
exists(EdgeKind::caseEdge(minValue, maxValue))
}
/** /**
* The constant values that can be inferred. The only additional constant * The constant values that can be inferred.
* value required is the GCC extension for case ranges.
*/ */
class ConstantValue extends TConstantValue { class ConstantValue = Void;
/**
* Holds if this constant value is the case range `minValue..maxValue`.
*/
predicate isRange(string minValue, string maxValue) { this = TRange(minValue, maxValue) }
string toString() {
exists(string minValue, string maxValue |
this.isRange(minValue, maxValue) and
result = minValue + ".." + maxValue
)
}
}
private class EqualityExpr extends CompareInstruction { private class EqualityExpr extends CompareInstruction {
EqualityExpr() { EqualityExpr() {
@@ -508,22 +483,10 @@ deprecated class BooleanValue extends AbstractValue {
* A value that represents a match against a specific `switch` case. * A value that represents a match against a specific `switch` case.
*/ */
deprecated class MatchValue extends AbstractValue { deprecated class MatchValue extends AbstractValue {
MatchValue() { MatchValue() { exists(this.asIntValue()) }
exists(this.asIntValue())
or
this.asConstantValue().isRange(_, _)
}
/** Gets the case. */ /** Gets the case. */
CaseEdge getCase() { CaseEdge getCase() { result.getValue().toInt() = this.asIntValue() }
result.getValue().toInt() = this.asIntValue()
or
exists(string minValue, string maxValue |
result.getMinValue() = minValue and
result.getMaxValue() = maxValue and
this.asConstantValue().isRange(minValue, maxValue)
)
}
} }
/** /**