Skip to content

Commit c46898c

Browse files
committed
C++: Make implicit this receivers explicit
1 parent ffa3028 commit c46898c

File tree

68 files changed

+589
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+589
-560
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class NoReason extends Reason, TNoReason {
238238
class CondReason extends Reason, TCondReason {
239239
IRGuardCondition getCond() { this = TCondReason(result) }
240240

241-
override string toString() { result = getCond().toString() }
241+
override string toString() { result = this.getCond().toString() }
242242
}
243243

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

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

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

273273
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ private predicate safeCast(IRIntegerType fromtyp, IRIntegerType totyp) {
109109
*/
110110
class PtrToPtrCastInstruction extends ConvertInstruction {
111111
PtrToPtrCastInstruction() {
112-
getResultIRType() instanceof IRAddressType and
113-
getUnary().getResultIRType() instanceof IRAddressType
112+
this.getResultIRType() instanceof IRAddressType and
113+
this.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().getResultIRType(), getResultIRType()) }
122+
SafeIntCastInstruction() { safeCast(this.getUnary().getResultIRType(), this.getResultIRType()) }
123123
}
124124

125125
/**

cpp/ql/lib/experimental/semmle/code/cpp/rangeanalysis/extensions/ConstantBitwiseAndExprRange.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ private class ConstantBitwiseAndExprRange extends SimpleRangeAnalysisExpr {
5050
// If an operand can have negative values, the lower bound is unconstrained.
5151
// Otherwise, the lower bound is zero.
5252
exists(float lLower, float rLower |
53-
lLower = getFullyConvertedLowerBounds(getLeftOperand()) and
54-
rLower = getFullyConvertedLowerBounds(getRightOperand()) and
53+
lLower = getFullyConvertedLowerBounds(this.getLeftOperand()) and
54+
rLower = getFullyConvertedLowerBounds(this.getRightOperand()) and
5555
(
5656
(lLower < 0 or rLower < 0) and
5757
result = exprMinVal(this)
@@ -68,10 +68,10 @@ private class ConstantBitwiseAndExprRange extends SimpleRangeAnalysisExpr {
6868
// If an operand can have negative values, the upper bound is unconstrained.
6969
// Otherwise, the upper bound is the minimum of the upper bounds of the operands
7070
exists(float lLower, float lUpper, float rLower, float rUpper |
71-
lLower = getFullyConvertedLowerBounds(getLeftOperand()) and
72-
lUpper = getFullyConvertedUpperBounds(getLeftOperand()) and
73-
rLower = getFullyConvertedLowerBounds(getRightOperand()) and
74-
rUpper = getFullyConvertedUpperBounds(getRightOperand()) and
71+
lLower = getFullyConvertedLowerBounds(this.getLeftOperand()) and
72+
lUpper = getFullyConvertedUpperBounds(this.getLeftOperand()) and
73+
rLower = getFullyConvertedLowerBounds(this.getRightOperand()) and
74+
rUpper = getFullyConvertedUpperBounds(this.getRightOperand()) and
7575
(
7676
(lLower < 0 or rLower < 0) and
7777
result = exprMaxVal(this)
@@ -85,6 +85,6 @@ private class ConstantBitwiseAndExprRange extends SimpleRangeAnalysisExpr {
8585
}
8686

8787
override predicate dependsOnChild(Expr child) {
88-
child = getLeftOperand() or child = getRightOperand()
88+
child = this.getLeftOperand() or child = this.getRightOperand()
8989
}
9090
}

cpp/ql/lib/experimental/semmle/code/cpp/rangeanalysis/extensions/ConstantShiftExprRange.qll

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ConstantRShiftExprRange extends SimpleRangeAnalysisExpr {
5050
* We don't handle the case where `a` and `b` are both non-constant values.
5151
*/
5252
ConstantRShiftExprRange() {
53-
getUnspecifiedType() instanceof IntegralType and
53+
this.getUnspecifiedType() instanceof IntegralType and
5454
exists(Expr l, Expr r |
5555
l = this.(RShiftExpr).getLeftOperand() and
5656
r = this.(RShiftExpr).getRightOperand()
@@ -84,19 +84,19 @@ class ConstantRShiftExprRange extends SimpleRangeAnalysisExpr {
8484

8585
override float getLowerBounds() {
8686
exists(int lLower, int lUpper, int rLower, int rUpper |
87-
lLower = getFullyConvertedLowerBounds(getLeftOperand()) and
88-
lUpper = getFullyConvertedUpperBounds(getLeftOperand()) and
89-
rLower = getFullyConvertedLowerBounds(getRightOperand()) and
90-
rUpper = getFullyConvertedUpperBounds(getRightOperand()) and
87+
lLower = getFullyConvertedLowerBounds(this.getLeftOperand()) and
88+
lUpper = getFullyConvertedUpperBounds(this.getLeftOperand()) and
89+
rLower = getFullyConvertedLowerBounds(this.getRightOperand()) and
90+
rUpper = getFullyConvertedUpperBounds(this.getRightOperand()) and
9191
lLower <= lUpper and
9292
rLower <= rUpper
9393
|
9494
if
9595
lLower < 0
9696
or
9797
not (
98-
isValidShiftExprShift(rLower, getLeftOperand()) and
99-
isValidShiftExprShift(rUpper, getLeftOperand())
98+
isValidShiftExprShift(rLower, this.getLeftOperand()) and
99+
isValidShiftExprShift(rUpper, this.getLeftOperand())
100100
)
101101
then
102102
// We don't want to deal with shifting negative numbers at the moment,
@@ -111,19 +111,19 @@ class ConstantRShiftExprRange extends SimpleRangeAnalysisExpr {
111111

112112
override float getUpperBounds() {
113113
exists(int lLower, int lUpper, int rLower, int rUpper |
114-
lLower = getFullyConvertedLowerBounds(getLeftOperand()) and
115-
lUpper = getFullyConvertedUpperBounds(getLeftOperand()) and
116-
rLower = getFullyConvertedLowerBounds(getRightOperand()) and
117-
rUpper = getFullyConvertedUpperBounds(getRightOperand()) and
114+
lLower = getFullyConvertedLowerBounds(this.getLeftOperand()) and
115+
lUpper = getFullyConvertedUpperBounds(this.getLeftOperand()) and
116+
rLower = getFullyConvertedLowerBounds(this.getRightOperand()) and
117+
rUpper = getFullyConvertedUpperBounds(this.getRightOperand()) and
118118
lLower <= lUpper and
119119
rLower <= rUpper
120120
|
121121
if
122122
lLower < 0
123123
or
124124
not (
125-
isValidShiftExprShift(rLower, getLeftOperand()) and
126-
isValidShiftExprShift(rUpper, getLeftOperand())
125+
isValidShiftExprShift(rLower, this.getLeftOperand()) and
126+
isValidShiftExprShift(rUpper, this.getLeftOperand())
127127
)
128128
then
129129
// We don't want to deal with shifting negative numbers at the moment,
@@ -137,7 +137,7 @@ class ConstantRShiftExprRange extends SimpleRangeAnalysisExpr {
137137
}
138138

139139
override predicate dependsOnChild(Expr child) {
140-
child = getLeftOperand() or child = getRightOperand()
140+
child = this.getLeftOperand() or child = this.getRightOperand()
141141
}
142142
}
143143

@@ -163,7 +163,7 @@ class ConstantLShiftExprRange extends SimpleRangeAnalysisExpr {
163163
* We don't handle the case where `a` and `b` are both non-constant values.
164164
*/
165165
ConstantLShiftExprRange() {
166-
getUnspecifiedType() instanceof IntegralType and
166+
this.getUnspecifiedType() instanceof IntegralType and
167167
exists(Expr l, Expr r |
168168
l = this.(LShiftExpr).getLeftOperand() and
169169
r = this.(LShiftExpr).getRightOperand()
@@ -197,19 +197,19 @@ class ConstantLShiftExprRange extends SimpleRangeAnalysisExpr {
197197

198198
override float getLowerBounds() {
199199
exists(int lLower, int lUpper, int rLower, int rUpper |
200-
lLower = getFullyConvertedLowerBounds(getLeftOperand()) and
201-
lUpper = getFullyConvertedUpperBounds(getLeftOperand()) and
202-
rLower = getFullyConvertedLowerBounds(getRightOperand()) and
203-
rUpper = getFullyConvertedUpperBounds(getRightOperand()) and
200+
lLower = getFullyConvertedLowerBounds(this.getLeftOperand()) and
201+
lUpper = getFullyConvertedUpperBounds(this.getLeftOperand()) and
202+
rLower = getFullyConvertedLowerBounds(this.getRightOperand()) and
203+
rUpper = getFullyConvertedUpperBounds(this.getRightOperand()) and
204204
lLower <= lUpper and
205205
rLower <= rUpper
206206
|
207207
if
208208
lLower < 0
209209
or
210210
not (
211-
isValidShiftExprShift(rLower, getLeftOperand()) and
212-
isValidShiftExprShift(rUpper, getLeftOperand())
211+
isValidShiftExprShift(rLower, this.getLeftOperand()) and
212+
isValidShiftExprShift(rUpper, this.getLeftOperand())
213213
)
214214
then
215215
// We don't want to deal with shifting negative numbers at the moment,
@@ -228,19 +228,19 @@ class ConstantLShiftExprRange extends SimpleRangeAnalysisExpr {
228228

229229
override float getUpperBounds() {
230230
exists(int lLower, int lUpper, int rLower, int rUpper |
231-
lLower = getFullyConvertedLowerBounds(getLeftOperand()) and
232-
lUpper = getFullyConvertedUpperBounds(getLeftOperand()) and
233-
rLower = getFullyConvertedLowerBounds(getRightOperand()) and
234-
rUpper = getFullyConvertedUpperBounds(getRightOperand()) and
231+
lLower = getFullyConvertedLowerBounds(this.getLeftOperand()) and
232+
lUpper = getFullyConvertedUpperBounds(this.getLeftOperand()) and
233+
rLower = getFullyConvertedLowerBounds(this.getRightOperand()) and
234+
rUpper = getFullyConvertedUpperBounds(this.getRightOperand()) and
235235
lLower <= lUpper and
236236
rLower <= rUpper
237237
|
238238
if
239239
lLower < 0
240240
or
241241
not (
242-
isValidShiftExprShift(rLower, getLeftOperand()) and
243-
isValidShiftExprShift(rUpper, getLeftOperand())
242+
isValidShiftExprShift(rLower, this.getLeftOperand()) and
243+
isValidShiftExprShift(rUpper, this.getLeftOperand())
244244
)
245245
then
246246
// We don't want to deal with shifting negative numbers at the moment,
@@ -258,6 +258,6 @@ class ConstantLShiftExprRange extends SimpleRangeAnalysisExpr {
258258
}
259259

260260
override predicate dependsOnChild(Expr child) {
261-
child = getLeftOperand() or child = getRightOperand()
261+
child = this.getLeftOperand() or child = this.getRightOperand()
262262
}
263263
}

cpp/ql/lib/experimental/semmle/code/cpp/rangeanalysis/extensions/RangeNode.qll

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,23 @@ private class ExprRangeNode extends DataFlow::ExprNode {
8383
private string getCallBounds(Call e) {
8484
result =
8585
getExprBoundAsString(e) + "(" +
86-
concat(Expr arg, int i | arg = e.getArgument(i) | getIntegralBounds(arg) order by i, ",") +
87-
")"
86+
concat(Expr arg, int i |
87+
arg = e.getArgument(i)
88+
|
89+
this.getIntegralBounds(arg) order by i, ","
90+
) + ")"
8891
}
8992

9093
override string toString() {
91-
exists(Expr e | e = getExpr() |
94+
exists(Expr e | e = this.getExpr() |
9295
if hasIntegralOrReferenceIntegralType(e)
9396
then
94-
result = super.toString() + ": " + getOperationBounds(e)
97+
result = super.toString() + ": " + this.getOperationBounds(e)
9598
or
96-
result = super.toString() + ": " + getCallBounds(e)
99+
result = super.toString() + ": " + this.getCallBounds(e)
97100
or
98-
not exists(getOperationBounds(e)) and
99-
not exists(getCallBounds(e)) and
101+
not exists(this.getOperationBounds(e)) and
102+
not exists(this.getCallBounds(e)) and
100103
result = super.toString() + ": " + getExprBoundAsString(e)
101104
else result = super.toString()
102105
)
@@ -108,8 +111,8 @@ private class ExprRangeNode extends DataFlow::ExprNode {
108111
*/
109112
private class ReferenceArgumentRangeNode extends DataFlow::DefinitionByReferenceNode {
110113
override string toString() {
111-
if hasIntegralOrReferenceIntegralType(asDefiningArgument())
112-
then result = super.toString() + ": " + getExprBoundAsString(getArgument())
114+
if hasIntegralOrReferenceIntegralType(this.asDefiningArgument())
115+
then result = super.toString() + ": " + getExprBoundAsString(this.getArgument())
113116
else result = super.toString()
114117
}
115118
}

cpp/ql/lib/experimental/semmle/code/cpp/rangeanalysis/extensions/StrlenLiteralRangeExpr.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ private import experimental.semmle.code.cpp.models.interfaces.SimpleRangeAnalysi
77
*/
88
class StrlenLiteralRangeExpr extends SimpleRangeAnalysisExpr, FunctionCall {
99
StrlenLiteralRangeExpr() {
10-
getTarget().hasGlobalOrStdName("strlen") and getArgument(0).isConstant()
10+
this.getTarget().hasGlobalOrStdName("strlen") and this.getArgument(0).isConstant()
1111
}
1212

13-
override int getLowerBounds() { result = getArgument(0).getValue().length() }
13+
override int getLowerBounds() { result = this.getArgument(0).getValue().length() }
1414

15-
override int getUpperBounds() { result = getArgument(0).getValue().length() }
15+
override int getUpperBounds() { result = this.getArgument(0).getValue().length() }
1616

1717
override predicate dependsOnChild(Expr e) { none() }
1818
}

cpp/ql/lib/experimental/semmle/code/cpp/rangeanalysis/extensions/SubtractSelf.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import experimental.semmle.code.cpp.models.interfaces.SimpleRangeAnalysisExpr
33
private class SelfSub extends SimpleRangeAnalysisExpr, SubExpr {
44
SelfSub() {
55
// Match `x - x` but not `myInt - (unsigned char)myInt`.
6-
getLeftOperand().getExplicitlyConverted().(VariableAccess).getTarget() =
7-
getRightOperand().getExplicitlyConverted().(VariableAccess).getTarget()
6+
this.getLeftOperand().getExplicitlyConverted().(VariableAccess).getTarget() =
7+
this.getRightOperand().getExplicitlyConverted().(VariableAccess).getTarget()
88
}
99

1010
override float getLowerBounds() { result = 0 }

cpp/ql/lib/semmle/code/cpp/Compilation.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Compilation extends @compilation {
4242
}
4343

4444
/** Gets a file compiled during this invocation. */
45-
File getAFileCompiled() { result = getFileCompiled(_) }
45+
File getAFileCompiled() { result = this.getFileCompiled(_) }
4646

4747
/** Gets the `i`th file compiled during this invocation */
4848
File getFileCompiled(int i) { compilation_compiling_files(this, i, unresolveElement(result)) }
@@ -74,7 +74,7 @@ class Compilation extends @compilation {
7474
/**
7575
* Gets an argument passed to the extractor on this invocation.
7676
*/
77-
string getAnArgument() { result = getArgument(_) }
77+
string getAnArgument() { result = this.getArgument(_) }
7878

7979
/**
8080
* Gets the `i`th argument passed to the extractor on this invocation.

cpp/ql/lib/semmle/code/cpp/Field.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class Field extends MemberVariable {
3939
* complete most-derived object.
4040
*/
4141
int getAByteOffsetIn(Class mostDerivedClass) {
42-
result = mostDerivedClass.getABaseClassByteOffset(getDeclaringType()) + getByteOffset()
42+
result =
43+
mostDerivedClass.getABaseClassByteOffset(this.getDeclaringType()) + this.getByteOffset()
4344
}
4445

4546
/**
@@ -116,10 +117,10 @@ class BitField extends Field {
116117
int getBitOffset() { fieldoffsets(underlyingElement(this), _, result) }
117118

118119
/** Holds if this bitfield is anonymous. */
119-
predicate isAnonymous() { hasName("(unnamed bitfield)") }
120+
predicate isAnonymous() { this.hasName("(unnamed bitfield)") }
120121

121122
override predicate isInitializable() {
122123
// Anonymous bitfields are not initializable.
123-
not isAnonymous()
124+
not this.isAnonymous()
124125
}
125126
}

cpp/ql/lib/semmle/code/cpp/Linkage.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class LinkTarget extends @link_target {
2424
* captured as part of the snapshot, then everything is grouped together
2525
* into a single dummy link target.
2626
*/
27-
predicate isDummy() { getBinary().getAbsolutePath() = "" }
27+
predicate isDummy() { this.getBinary().getAbsolutePath() = "" }
2828

2929
/** Gets a textual representation of this element. */
30-
string toString() { result = getBinary().getAbsolutePath() }
30+
string toString() { result = this.getBinary().getAbsolutePath() }
3131

3232
/**
3333
* Gets a function which was compiled into this link target, or had its

cpp/ql/lib/semmle/code/cpp/NameQualifiers.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class NameQualifier extends NameQualifiableElement, @namequalifier {
2424
* Gets the expression ultimately qualified by the chain of name
2525
* qualifiers. For example, `f()` in `N1::N2::f()`.
2626
*/
27-
Expr getExpr() { result = getQualifiedElement+() }
27+
Expr getExpr() { result = this.getQualifiedElement+() }
2828

2929
/** Gets a location for this name qualifier. */
3030
override Location getLocation() { namequalifiers(underlyingElement(this), _, _, result) }
@@ -56,12 +56,12 @@ class NameQualifier extends NameQualifiableElement, @namequalifier {
5656
if nqe instanceof SpecialNameQualifyingElement
5757
then
5858
exists(Access a |
59-
a = getQualifiedElement() and
59+
a = this.getQualifiedElement() and
6060
result = a.getTarget().getDeclaringType()
6161
)
6262
or
6363
exists(FunctionCall c |
64-
c = getQualifiedElement() and
64+
c = this.getQualifiedElement() and
6565
result = c.getTarget().getDeclaringType()
6666
)
6767
else result = nqe
@@ -109,7 +109,7 @@ class NameQualifiableElement extends Element, @namequalifiableelement {
109109
* namespace.
110110
*/
111111
predicate hasGlobalQualifiedName() {
112-
getNameQualifier*().getQualifyingElement() instanceof GlobalNamespace
112+
this.getNameQualifier*().getQualifyingElement() instanceof GlobalNamespace
113113
}
114114

115115
/**
@@ -119,7 +119,7 @@ class NameQualifiableElement extends Element, @namequalifiableelement {
119119
*/
120120
predicate hasSuperQualifiedName() {
121121
exists(NameQualifier nq, SpecialNameQualifyingElement snqe |
122-
nq = getNameQualifier*() and
122+
nq = this.getNameQualifier*() and
123123
namequalifiers(unresolveElement(nq), _, unresolveElement(snqe), _) and
124124
snqe.getName() = "__super"
125125
)
@@ -164,5 +164,5 @@ library class SpecialNameQualifyingElement extends NameQualifyingElement,
164164
/** Gets the name of this special qualifying element. */
165165
override string getName() { specialnamequalifyingelements(underlyingElement(this), result) }
166166

167-
override string toString() { result = getName() }
167+
override string toString() { result = this.getName() }
168168
}

0 commit comments

Comments
 (0)