Skip to content

Commit 5d62aa5

Browse files
authored
Merge pull request #6994 from erik-krogh/redundant-cast
Approved by RasmusWL, aschackmull, esbena, geoffw0, hvitved, nickrolfe
2 parents e2cb53c + f676fc0 commit 5d62aa5

File tree

78 files changed

+131
-163
lines changed

Some content is hidden

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

78 files changed

+131
-163
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class Class extends UserType {
237237
exists(ClassDerivation cd | cd.getBaseClass() = base |
238238
result =
239239
this.accessOfBaseMemberMulti(cd.getDerivedClass(),
240-
fieldInBase.accessInDirectDerived(cd.getASpecifier().(AccessSpecifier)))
240+
fieldInBase.accessInDirectDerived(cd.getASpecifier()))
241241
)
242242
}
243243

@@ -261,8 +261,7 @@ class Class extends UserType {
261261
* includes the case of `base` = `this`.
262262
*/
263263
AccessSpecifier accessOfBaseMember(Declaration member) {
264-
result =
265-
this.accessOfBaseMember(member.getDeclaringType(), member.getASpecifier().(AccessSpecifier))
264+
result = this.accessOfBaseMember(member.getDeclaringType(), member.getASpecifier())
266265
}
267266

268267
/**
@@ -319,7 +318,7 @@ class Class extends UserType {
319318
exists(Type t | t = this.getAFieldSubobjectType().getUnspecifiedType() |
320319
// Note: Overload resolution is not implemented -- all copy
321320
// constructors are considered equal.
322-
this.cannotAccessCopyConstructorOnAny(t.(Class))
321+
this.cannotAccessCopyConstructorOnAny(t)
323322
)
324323
or
325324
// - T has direct or virtual base class that cannot be copied (has deleted,
@@ -392,7 +391,7 @@ class Class extends UserType {
392391
exists(Type t | t = this.getAFieldSubobjectType().getUnspecifiedType() |
393392
// Note: Overload resolution is not implemented -- all copy assignment
394393
// operators are considered equal.
395-
this.cannotAccessCopyAssignmentOperatorOnAny(t.(Class))
394+
this.cannotAccessCopyAssignmentOperatorOnAny(t)
396395
)
397396
or
398397
exists(Class c | c = this.getADirectOrVirtualBase() |

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,7 @@ class AccessHolder extends Declaration, TAccessHolder {
490490
*/
491491
pragma[inline]
492492
predicate canAccessMember(Declaration member, Class derived) {
493-
this.couldAccessMember(member.getDeclaringType(), member.getASpecifier().(AccessSpecifier),
494-
derived)
493+
this.couldAccessMember(member.getDeclaringType(), member.getASpecifier(), derived)
495494
}
496495

497496
/**

cpp/ql/lib/semmle/code/cpp/commons/Dependency.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,17 @@ private predicate dependsOnDeclarationEntry(Element src, DeclarationEntry dest)
275275
dependsOnTransitive(src, mid) and
276276
not mid instanceof Type and
277277
not mid instanceof EnumConstant and
278-
getDeclarationEntries(mid, dest.(DeclarationEntry)) and
278+
getDeclarationEntries(mid, dest) and
279279
not dest instanceof TypeDeclarationEntry
280280
)
281281
or
282282
exists(Declaration mid |
283283
// dependency from a Type / Variable / Function use -> any (visible) definition
284284
dependsOnTransitive(src, mid) and
285285
not mid instanceof EnumConstant and
286-
getDeclarationEntries(mid, dest.(DeclarationEntry)) and
286+
getDeclarationEntries(mid, dest) and
287287
// must be definition
288-
dest.(DeclarationEntry).isDefinition()
288+
dest.isDefinition()
289289
)
290290
}
291291

@@ -307,7 +307,7 @@ private predicate dependsOnFull(DependsSource src, Symbol dest, int category) {
307307
// dependency from a Variable / Function use -> non-visible definition (link time)
308308
dependsOnTransitive(src, mid) and
309309
not mid instanceof EnumConstant and
310-
getDeclarationEntries(mid, dest.(DeclarationEntry)) and
310+
getDeclarationEntries(mid, dest) and
311311
not dest instanceof TypeDeclarationEntry and
312312
// must be definition
313313
dest.(DeclarationEntry).isDefinition() and

cpp/ql/lib/semmle/code/cpp/commons/Printf.qll

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ class FormattingFunctionCall extends Expr {
175175
/**
176176
* Gets the index at which the format string occurs in the argument list.
177177
*/
178-
int getFormatParameterIndex() {
179-
result = this.getTarget().(FormattingFunction).getFormatParameterIndex()
180-
}
178+
int getFormatParameterIndex() { result = this.getTarget().getFormatParameterIndex() }
181179

182180
/**
183181
* Gets the format expression used in this call.
@@ -191,7 +189,7 @@ class FormattingFunctionCall extends Expr {
191189
exists(int i |
192190
result = this.getArgument(i) and
193191
n >= 0 and
194-
n = i - this.getTarget().(FormattingFunction).getFirstFormatArgumentIndex()
192+
n = i - this.getTarget().getFirstFormatArgumentIndex()
195193
)
196194
}
197195

@@ -251,7 +249,7 @@ class FormattingFunctionCall extends Expr {
251249
int getNumFormatArgument() {
252250
result = count(this.getFormatArgument(_)) and
253251
// format arguments must be known
254-
exists(this.getTarget().(FormattingFunction).getFirstFormatArgumentIndex())
252+
exists(this.getTarget().getFirstFormatArgumentIndex())
255253
}
256254

257255
/**
@@ -289,35 +287,27 @@ class FormatLiteral extends Literal {
289287
* a `char *` (either way, `%S` will have the opposite meaning).
290288
* DEPRECATED: Use getDefaultCharType() instead.
291289
*/
292-
deprecated predicate isWideCharDefault() {
293-
this.getUse().getTarget().(FormattingFunction).isWideCharDefault()
294-
}
290+
deprecated predicate isWideCharDefault() { this.getUse().getTarget().isWideCharDefault() }
295291

296292
/**
297293
* Gets the default character type expected for `%s` by this format literal. Typically
298294
* `char` or `wchar_t`.
299295
*/
300-
Type getDefaultCharType() {
301-
result = this.getUse().getTarget().(FormattingFunction).getDefaultCharType()
302-
}
296+
Type getDefaultCharType() { result = this.getUse().getTarget().getDefaultCharType() }
303297

304298
/**
305299
* Gets the non-default character type expected for `%S` by this format literal. Typically
306300
* `wchar_t` or `char`. On some snapshots there may be multiple results where we can't tell
307301
* which is correct for a particular function.
308302
*/
309-
Type getNonDefaultCharType() {
310-
result = this.getUse().getTarget().(FormattingFunction).getNonDefaultCharType()
311-
}
303+
Type getNonDefaultCharType() { result = this.getUse().getTarget().getNonDefaultCharType() }
312304

313305
/**
314306
* Gets the wide character type for this format literal. This is usually `wchar_t`. On some
315307
* snapshots there may be multiple results where we can't tell which is correct for a
316308
* particular function.
317309
*/
318-
Type getWideCharType() {
319-
result = this.getUse().getTarget().(FormattingFunction).getWideCharType()
320-
}
310+
Type getWideCharType() { result = this.getUse().getTarget().getWideCharType() }
321311

322312
/**
323313
* Holds if this `FormatLiteral` is in a context that supports
@@ -896,7 +886,7 @@ class FormatLiteral extends Literal {
896886
exists(string len, string conv |
897887
this.parseConvSpec(n, _, _, _, _, _, len, conv) and
898888
(len != "l" and len != "w" and len != "h") and
899-
this.getUse().getTarget().(FormattingFunction).getFormatCharType().getSize() > 1 and // wide function
889+
this.getUse().getTarget().getFormatCharType().getSize() > 1 and // wide function
900890
(
901891
conv = "c" and
902892
result = this.getNonDefaultCharType()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ predicate definitionUsePair(SemanticStackVariable var, Expr def, Expr use) {
2525
* Holds if the definition `def` of some stack variable can reach `node`, which
2626
* is a definition or use, without crossing definitions of the same variable.
2727
*/
28-
predicate definitionReaches(Expr def, Expr node) { def.(Def).reaches(true, _, node.(DefOrUse)) }
28+
predicate definitionReaches(Expr def, Expr node) { def.(Def).reaches(true, _, node) }
2929

3030
private predicate hasAddressOfAccess(SemanticStackVariable var) {
3131
var.getAnAccess().isAddressOfAccessNonConst()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SsaDefinition extends ControlFlowNodeBase {
6262
BasicBlock getBasicBlock() { result.contains(this.getDefinition()) }
6363

6464
/** Holds if this definition is a phi node for variable `v`. */
65-
predicate isPhiNode(StackVariable v) { exists(StandardSSA x | x.phi_node(v, this.(BasicBlock))) }
65+
predicate isPhiNode(StackVariable v) { exists(StandardSSA x | x.phi_node(v, this)) }
6666

6767
/** Gets the location of this definition. */
6868
Location getLocation() { result = this.(ControlFlowNode).getLocation() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ library class SSAHelper extends int {
292292
*/
293293
cached
294294
string toString(ControlFlowNode node, StackVariable v) {
295-
if phi_node(v, node.(BasicBlock))
295+
if phi_node(v, node)
296296
then result = "SSA phi(" + v.getName() + ")"
297297
else (
298298
ssa_defn(v, node, _, _) and result = "SSA def(" + v.getName() + ")"

cpp/ql/lib/semmle/code/cpp/controlflow/internal/CFG.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private class PostOrderInitializer extends Initializer {
231231
or
232232
this.getDeclaration() = for.getRangeVariable()
233233
or
234-
this.getDeclaration() = for.getBeginEndDeclaration().(DeclStmt).getADeclaration()
234+
this.getDeclaration() = for.getBeginEndDeclaration().getADeclaration()
235235
)
236236
}
237237
}
@@ -1143,7 +1143,7 @@ private class ExceptionSource extends Node {
11431143
this.reachesParent(mid) and
11441144
not mid = any(TryStmt try).getStmt() and
11451145
not mid = any(MicrosoftTryStmt try).getStmt() and
1146-
parent = mid.(Node).getParentNode()
1146+
parent = mid.getParentNode()
11471147
)
11481148
}
11491149

cpp/ql/lib/semmle/code/cpp/controlflow/internal/ConstantExprs.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ library class ExprEvaluator extends int {
484484
this.interestingInternal(e, req, true) and
485485
(
486486
result = req.(CompileTimeConstantInt).getIntValue() or
487-
result = this.getCompoundValue(e, req.(CompileTimeVariableExpr))
487+
result = this.getCompoundValue(e, req)
488488
) and
489489
(
490490
req.getUnderlyingType().(IntegralType).isSigned() or
@@ -611,7 +611,7 @@ library class ExprEvaluator extends int {
611611
or
612612
exists(AssignExpr req | req = val | result = this.getValueInternal(e, req.getRValue()))
613613
or
614-
result = this.getVariableValue(e, val.(VariableAccess))
614+
result = this.getVariableValue(e, val)
615615
or
616616
exists(FunctionCall call | call = val and not callWithMultipleTargets(call) |
617617
result = this.getFunctionValue(call.getTarget())
@@ -663,7 +663,7 @@ library class ExprEvaluator extends int {
663663
this.interestingInternal(_, req, false) and
664664
(
665665
result = req.(CompileTimeConstantInt).getIntValue() or
666-
result = this.getCompoundValueNonSubExpr(req.(CompileTimeVariableExpr))
666+
result = this.getCompoundValueNonSubExpr(req)
667667
) and
668668
(
669669
req.getUnderlyingType().(IntegralType).isSigned() or
@@ -787,7 +787,7 @@ library class ExprEvaluator extends int {
787787
or
788788
exists(AssignExpr req | req = val | result = this.getValueInternalNonSubExpr(req.getRValue()))
789789
or
790-
result = this.getVariableValueNonSubExpr(val.(VariableAccess))
790+
result = this.getVariableValueNonSubExpr(val)
791791
or
792792
exists(FunctionCall call | call = val and not callWithMultipleTargets(call) |
793793
result = this.getFunctionValue(call.getTarget())

cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Expr extends StmtParent, @expr {
3131
override Stmt getEnclosingStmt() {
3232
result = this.getParent().(Expr).getEnclosingStmt()
3333
or
34-
result = this.getParent().(Stmt)
34+
result = this.getParent()
3535
or
3636
exists(Expr other | result = other.getEnclosingStmt() and other.getConversion() = this)
3737
or

0 commit comments

Comments
 (0)