Skip to content

Commit 7029739

Browse files
committed
C++: Replace getResultType() with getResultIRType() in IR range analysis
1 parent a405a95 commit 7029739

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

cpp/ql/src/experimental/semmle/code/cpp/rangeanalysis/Bound.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ private newtype TBound =
88
exists(Instruction i |
99
vn.getAnInstruction() = i and
1010
(
11-
i.getResultType() instanceof IntegralType or
12-
i.getResultType() instanceof PointerType
11+
i.getResultIRType() instanceof IRIntegerType or
12+
i.getResultIRType() instanceof IRAddressType
1313
) and
1414
not vn.getAnInstruction() instanceof ConstantInstruction
1515
|

cpp/ql/src/experimental/semmle/code/cpp/rangeanalysis/RangeAnalysis.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ class CondReason extends Reason, TCondReason {
244244
/**
245245
* Holds if `typ` is a small integral type with the given lower and upper bounds.
246246
*/
247-
private predicate typeBound(IntegralType typ, int lowerbound, int upperbound) {
248-
typ.isSigned() and typ.getSize() = 1 and lowerbound = -128 and upperbound = 127
247+
private predicate typeBound(IRIntegerType typ, int lowerbound, int upperbound) {
248+
typ.isSigned() and typ.getByteSize() = 1 and lowerbound = -128 and upperbound = 127
249249
or
250-
typ.isUnsigned() and typ.getSize() = 1 and lowerbound = 0 and upperbound = 255
250+
typ.isUnsigned() and typ.getByteSize() = 1 and lowerbound = 0 and upperbound = 255
251251
or
252-
typ.isSigned() and typ.getSize() = 2 and lowerbound = -32768 and upperbound = 32767
252+
typ.isSigned() and typ.getByteSize() = 2 and lowerbound = -32768 and upperbound = 32767
253253
or
254-
typ.isUnsigned() and typ.getSize() = 2 and lowerbound = 0 and upperbound = 65535
254+
typ.isUnsigned() and typ.getByteSize() = 2 and lowerbound = 0 and upperbound = 65535
255255
}
256256

257257
/**
@@ -260,14 +260,14 @@ private predicate typeBound(IntegralType typ, int lowerbound, int upperbound) {
260260
private class NarrowingCastInstruction extends ConvertInstruction {
261261
NarrowingCastInstruction() {
262262
not this instanceof SafeCastInstruction and
263-
typeBound(getResultType(), _, _)
263+
typeBound(getResultIRType(), _, _)
264264
}
265265

266266
/** Gets the lower bound of the resulting type. */
267-
int getLowerBound() { typeBound(getResultType(), result, _) }
267+
int getLowerBound() { typeBound(getResultIRType(), result, _) }
268268

269269
/** Gets the upper bound of the resulting type. */
270-
int getUpperBound() { typeBound(getResultType(), _, result) }
270+
int getUpperBound() { typeBound(getResultIRType(), _, result) }
271271
}
272272

273273
/**

cpp/ql/src/experimental/semmle/code/cpp/rangeanalysis/RangeUtils.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ predicate backEdge(PhiInstruction phi, PhiInputOperand op) {
8686
* range analysis.
8787
*/
8888
pragma[inline]
89-
private predicate safeCast(IntegralType fromtyp, IntegralType totyp) {
90-
fromtyp.getSize() < totyp.getSize() and
89+
private predicate safeCast(IRIntegerType fromtyp, IRIntegerType totyp) {
90+
fromtyp.getByteSize() < totyp.getByteSize() and
9191
(
9292
fromtyp.isUnsigned()
9393
or
9494
totyp.isSigned()
9595
)
9696
or
97-
fromtyp.getSize() <= totyp.getSize() and
97+
fromtyp.getByteSize() <= totyp.getByteSize() and
9898
(
9999
fromtyp.isSigned() and
100100
totyp.isSigned()
@@ -109,8 +109,8 @@ private predicate safeCast(IntegralType fromtyp, IntegralType totyp) {
109109
*/
110110
class PtrToPtrCastInstruction extends ConvertInstruction {
111111
PtrToPtrCastInstruction() {
112-
getResultType() instanceof PointerType and
113-
getUnary().getResultType() instanceof PointerType
112+
getResultIRType() instanceof IRAddressType and
113+
getUnary().getResultIRType() instanceof IRAddressType
114114
}
115115
}
116116

@@ -119,7 +119,7 @@ class PtrToPtrCastInstruction extends ConvertInstruction {
119119
* that cannot overflow or underflow.
120120
*/
121121
class SafeIntCastInstruction extends ConvertInstruction {
122-
SafeIntCastInstruction() { safeCast(getUnary().getResultType(), getResultType()) }
122+
SafeIntCastInstruction() { safeCast(getUnary().getResultIRType(), getResultIRType()) }
123123
}
124124

125125
/**

cpp/ql/src/experimental/semmle/code/cpp/rangeanalysis/SignAnalysis.qll

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,17 +469,21 @@ module SignAnalysisCached {
469469
not exists(certainInstructionSign(i)) and
470470
not (
471471
result = TNeg() and
472-
i.getResultType().(IntegralType).isUnsigned()
472+
i.getResultIRType().(IRIntegerType).isUnsigned()
473473
) and
474474
(
475475
unknownSign(i)
476476
or
477477
exists(ConvertInstruction ci, Instruction prior, boolean fromSigned, boolean toSigned |
478478
i = ci and
479479
prior = ci.getUnary() and
480-
(if ci.getResultType().(IntegralType).isSigned() then toSigned = true else toSigned = false) and
481480
(
482-
if prior.getResultType().(IntegralType).isSigned()
481+
if ci.getResultIRType().(IRIntegerType).isSigned()
482+
then toSigned = true
483+
else toSigned = false
484+
) and
485+
(
486+
if prior.getResultIRType().(IRIntegerType).isSigned()
483487
then fromSigned = true
484488
else fromSigned = false
485489
) and
@@ -512,11 +516,11 @@ module SignAnalysisCached {
512516
i instanceof ShiftLeftInstruction and result = s1.lshift(s2)
513517
or
514518
i instanceof ShiftRightInstruction and
515-
i.getResultType().(IntegralType).isSigned() and
519+
i.getResultIRType().(IRIntegerType).isSigned() and
516520
result = s1.rshift(s2)
517521
or
518522
i instanceof ShiftRightInstruction and
519-
not i.getResultType().(IntegralType).isSigned() and
523+
not i.getResultIRType().(IRIntegerType).isSigned() and
520524
result = s1.urshift(s2)
521525
)
522526
or

0 commit comments

Comments
 (0)