mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
C++: Make recursive predicates recursive and non-recursive predicates non-recursive
This commit is contained in:
@@ -31,7 +31,7 @@ from
|
|||||||
where
|
where
|
||||||
not cmp.isInMacroExpansion() and
|
not cmp.isInMacroExpansion() and
|
||||||
not cmp.isFromTemplateInstantiation(_) and
|
not cmp.isFromTemplateInstantiation(_) and
|
||||||
not containsDisabledCode(cmp.getEnclosingFunction()) and
|
not functionContainsDisabledCode(cmp.getEnclosingFunction()) and
|
||||||
reachablePointlessComparison(cmp, left, right, value, ss) and
|
reachablePointlessComparison(cmp, left, right, value, ss) and
|
||||||
|
|
||||||
// a comparison between an enum and zero is always valid because whether
|
// a comparison between an enum and zero is always valid because whether
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ predicate accessInInitOfForStmt(Expr e) {
|
|||||||
* Holds if the function `f`, or a function called by it, contains
|
* Holds if the function `f`, or a function called by it, contains
|
||||||
* code excluded by the preprocessor.
|
* code excluded by the preprocessor.
|
||||||
*/
|
*/
|
||||||
predicate containsDisabledCodeRecursive(Function f) {
|
predicate functionContainsDisabledCodeRecursive(Function f) {
|
||||||
containsDisabledCode(f) or
|
functionContainsDisabledCode(f) or
|
||||||
// recurse into function calls
|
// recurse into function calls
|
||||||
exists(FunctionCall fc |
|
exists(FunctionCall fc |
|
||||||
fc.getEnclosingFunction() = f and
|
fc.getEnclosingFunction() = f and
|
||||||
containsDisabledCode(fc.getTarget())
|
functionContainsDisabledCodeRecursive(fc.getTarget())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,12 +40,12 @@ predicate containsDisabledCodeRecursive(Function f) {
|
|||||||
* Holds if the function `f`, or a function called by it, is inside a
|
* Holds if the function `f`, or a function called by it, is inside a
|
||||||
* preprocessor branch that may have code in another arm
|
* preprocessor branch that may have code in another arm
|
||||||
*/
|
*/
|
||||||
predicate definedInIfDefRecursive(Function f) {
|
predicate functionDefinedInIfDefRecursive(Function f) {
|
||||||
definedInIfDef(f) or
|
functionDefinedInIfDef(f) or
|
||||||
// recurse into function calls
|
// recurse into function calls
|
||||||
exists(FunctionCall fc |
|
exists(FunctionCall fc |
|
||||||
fc.getEnclosingFunction() = f and
|
fc.getEnclosingFunction() = f and
|
||||||
definedInIfDef(fc.getTarget())
|
functionDefinedInIfDefRecursive(fc.getTarget())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,8 +79,8 @@ where // EQExprs are covered by CompareWhereAssignMeant.ql
|
|||||||
not parent instanceof PureExprInVoidContext and
|
not parent instanceof PureExprInVoidContext and
|
||||||
not peivc.getEnclosingFunction().isCompilerGenerated() and
|
not peivc.getEnclosingFunction().isCompilerGenerated() and
|
||||||
not peivc.getType() instanceof UnknownType and
|
not peivc.getType() instanceof UnknownType and
|
||||||
not containsDisabledCodeRecursive(peivc.(FunctionCall).getTarget()) and
|
not functionContainsDisabledCodeRecursive(peivc.(FunctionCall).getTarget()) and
|
||||||
not definedInIfDefRecursive(peivc.(FunctionCall).getTarget()) and
|
not functionDefinedInIfDefRecursive(peivc.(FunctionCall).getTarget()) and
|
||||||
if peivc instanceof FunctionCall then
|
if peivc instanceof FunctionCall then
|
||||||
exists(Function target |
|
exists(Function target |
|
||||||
target = peivc.(FunctionCall).getTarget() and
|
target = peivc.(FunctionCall).getTarget() and
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ private predicate functionLocation(Function f, string file, int fBlockStartLine,
|
|||||||
/**
|
/**
|
||||||
* Holds if the function `f` is inside a preprocessor branch that may have code in another arm.
|
* Holds if the function `f` is inside a preprocessor branch that may have code in another arm.
|
||||||
*/
|
*/
|
||||||
predicate definedInIfDef(Function f) {
|
predicate functionDefinedInIfDef(Function f) {
|
||||||
exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int pbdEndLine, int fBlockStartLine,
|
exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int pbdEndLine, int fBlockStartLine,
|
||||||
int fBlockEndLine |
|
int fBlockEndLine |
|
||||||
functionLocation(f, file, fBlockStartLine, fBlockEndLine) and
|
functionLocation(f, file, fBlockStartLine, fBlockEndLine) and
|
||||||
@@ -258,13 +258,12 @@ predicate definedInIfDef(Function f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds if the function `f`, or a function called by it, contains
|
* Holds if the function `f` contains code excluded by the preprocessor.
|
||||||
* code excluded by the preprocessor.
|
|
||||||
*/
|
*/
|
||||||
predicate containsDisabledCode(Function f) {
|
predicate functionContainsDisabledCode(Function f) {
|
||||||
// `f` contains a preprocessor branch that was not taken
|
// `f` contains a preprocessor branch that was not taken
|
||||||
exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int fBlockStartLine, int fBlockEndLine |
|
exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int fBlockStartLine, int fBlockEndLine |
|
||||||
functionLocation(f, file, fBlockStartLine, fBlockEndLine) and
|
functionLocation(f, file, fBlockStartLine, fBlockEndLine) and
|
||||||
pbdLocation(pbd, file, pbdStartLine) and
|
pbdLocation(pbd, file, pbdStartLine) and
|
||||||
pbdStartLine <= fBlockEndLine and
|
pbdStartLine <= fBlockEndLine and
|
||||||
pbdStartLine >= fBlockStartLine and
|
pbdStartLine >= fBlockStartLine and
|
||||||
@@ -275,10 +274,5 @@ predicate containsDisabledCode(Function f) {
|
|||||||
// was not taken.
|
// was not taken.
|
||||||
pbd instanceof PreprocessorElse
|
pbd instanceof PreprocessorElse
|
||||||
)
|
)
|
||||||
) or
|
|
||||||
// recurse into function calls
|
|
||||||
exists(FunctionCall fc |
|
|
||||||
fc.getEnclosingFunction() = f and
|
|
||||||
containsDisabledCode(fc.getTarget())
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user