C++: Make recursive predicates recursive and non-recursive predicates non-recursive

This commit is contained in:
Dave Bartolomeo
2019-03-26 14:36:35 -07:00
parent 669ac2f4b4
commit f13fc42a85
3 changed files with 13 additions and 19 deletions

View File

@@ -31,7 +31,7 @@ from
where
not cmp.isInMacroExpansion() and
not cmp.isFromTemplateInstantiation(_) and
not containsDisabledCode(cmp.getEnclosingFunction()) and
not functionContainsDisabledCode(cmp.getEnclosingFunction()) and
reachablePointlessComparison(cmp, left, right, value, ss) and
// a comparison between an enum and zero is always valid because whether

View File

@@ -27,12 +27,12 @@ predicate accessInInitOfForStmt(Expr e) {
* Holds if the function `f`, or a function called by it, contains
* code excluded by the preprocessor.
*/
predicate containsDisabledCodeRecursive(Function f) {
containsDisabledCode(f) or
predicate functionContainsDisabledCodeRecursive(Function f) {
functionContainsDisabledCode(f) or
// recurse into function calls
exists(FunctionCall fc |
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
* preprocessor branch that may have code in another arm
*/
predicate definedInIfDefRecursive(Function f) {
definedInIfDef(f) or
predicate functionDefinedInIfDefRecursive(Function f) {
functionDefinedInIfDef(f) or
// recurse into function calls
exists(FunctionCall fc |
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 peivc.getEnclosingFunction().isCompilerGenerated() and
not peivc.getType() instanceof UnknownType and
not containsDisabledCodeRecursive(peivc.(FunctionCall).getTarget()) and
not definedInIfDefRecursive(peivc.(FunctionCall).getTarget()) and
not functionContainsDisabledCodeRecursive(peivc.(FunctionCall).getTarget()) and
not functionDefinedInIfDefRecursive(peivc.(FunctionCall).getTarget()) and
if peivc instanceof FunctionCall then
exists(Function target |
target = peivc.(FunctionCall).getTarget() and

View File

@@ -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.
*/
predicate definedInIfDef(Function f) {
predicate functionDefinedInIfDef(Function f) {
exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int pbdEndLine, int fBlockStartLine,
int fBlockEndLine |
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
* code excluded by the preprocessor.
* Holds if the function `f` contains code excluded by the preprocessor.
*/
predicate containsDisabledCode(Function f) {
predicate functionContainsDisabledCode(Function f) {
// `f` contains a preprocessor branch that was not taken
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
pbdStartLine <= fBlockEndLine and
pbdStartLine >= fBlockStartLine and
@@ -275,10 +274,5 @@ predicate containsDisabledCode(Function f) {
// was not taken.
pbd instanceof PreprocessorElse
)
) or
// recurse into function calls
exists(FunctionCall fc |
fc.getEnclosingFunction() = f and
containsDisabledCode(fc.getTarget())
)
}