Skip to content

Commit f13fc42

Browse files
C++: Make recursive predicates recursive and non-recursive predicates non-recursive
1 parent 669ac2f commit f13fc42

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ from
3131
where
3232
not cmp.isInMacroExpansion() and
3333
not cmp.isFromTemplateInstantiation(_) and
34-
not containsDisabledCode(cmp.getEnclosingFunction()) and
34+
not functionContainsDisabledCode(cmp.getEnclosingFunction()) and
3535
reachablePointlessComparison(cmp, left, right, value, ss) and
3636

3737
// a comparison between an enum and zero is always valid because whether

cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ predicate accessInInitOfForStmt(Expr e) {
2727
* Holds if the function `f`, or a function called by it, contains
2828
* code excluded by the preprocessor.
2929
*/
30-
predicate containsDisabledCodeRecursive(Function f) {
31-
containsDisabledCode(f) or
30+
predicate functionContainsDisabledCodeRecursive(Function f) {
31+
functionContainsDisabledCode(f) or
3232
// recurse into function calls
3333
exists(FunctionCall fc |
3434
fc.getEnclosingFunction() = f and
35-
containsDisabledCode(fc.getTarget())
35+
functionContainsDisabledCodeRecursive(fc.getTarget())
3636
)
3737
}
3838

3939
/**
4040
* Holds if the function `f`, or a function called by it, is inside a
4141
* preprocessor branch that may have code in another arm
4242
*/
43-
predicate definedInIfDefRecursive(Function f) {
44-
definedInIfDef(f) or
43+
predicate functionDefinedInIfDefRecursive(Function f) {
44+
functionDefinedInIfDef(f) or
4545
// recurse into function calls
4646
exists(FunctionCall fc |
4747
fc.getEnclosingFunction() = f and
48-
definedInIfDef(fc.getTarget())
48+
functionDefinedInIfDefRecursive(fc.getTarget())
4949
)
5050
}
5151

@@ -79,8 +79,8 @@ where // EQExprs are covered by CompareWhereAssignMeant.ql
7979
not parent instanceof PureExprInVoidContext and
8080
not peivc.getEnclosingFunction().isCompilerGenerated() and
8181
not peivc.getType() instanceof UnknownType and
82-
not containsDisabledCodeRecursive(peivc.(FunctionCall).getTarget()) and
83-
not definedInIfDefRecursive(peivc.(FunctionCall).getTarget()) and
82+
not functionContainsDisabledCodeRecursive(peivc.(FunctionCall).getTarget()) and
83+
not functionDefinedInIfDefRecursive(peivc.(FunctionCall).getTarget()) and
8484
if peivc instanceof FunctionCall then
8585
exists(Function target |
8686
target = peivc.(FunctionCall).getTarget() and

cpp/ql/src/semmle/code/cpp/Preprocessor.qll

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private predicate functionLocation(Function f, string file, int fBlockStartLine,
239239
/**
240240
* Holds if the function `f` is inside a preprocessor branch that may have code in another arm.
241241
*/
242-
predicate definedInIfDef(Function f) {
242+
predicate functionDefinedInIfDef(Function f) {
243243
exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int pbdEndLine, int fBlockStartLine,
244244
int fBlockEndLine |
245245
functionLocation(f, file, fBlockStartLine, fBlockEndLine) and
@@ -258,13 +258,12 @@ predicate definedInIfDef(Function f) {
258258
}
259259

260260
/**
261-
* Holds if the function `f`, or a function called by it, contains
262-
* code excluded by the preprocessor.
261+
* Holds if the function `f` contains code excluded by the preprocessor.
263262
*/
264-
predicate containsDisabledCode(Function f) {
263+
predicate functionContainsDisabledCode(Function f) {
265264
// `f` contains a preprocessor branch that was not taken
266265
exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int fBlockStartLine, int fBlockEndLine |
267-
functionLocation(f, file, fBlockStartLine, fBlockEndLine) and
266+
functionLocation(f, file, fBlockStartLine, fBlockEndLine) and
268267
pbdLocation(pbd, file, pbdStartLine) and
269268
pbdStartLine <= fBlockEndLine and
270269
pbdStartLine >= fBlockStartLine and
@@ -275,10 +274,5 @@ predicate containsDisabledCode(Function f) {
275274
// was not taken.
276275
pbd instanceof PreprocessorElse
277276
)
278-
) or
279-
// recurse into function calls
280-
exists(FunctionCall fc |
281-
fc.getEnclosingFunction() = f and
282-
containsDisabledCode(fc.getTarget())
283277
)
284278
}

0 commit comments

Comments
 (0)