C++: Implement Expr::mayBeFromImplicitlyDeclaredFunction

This commit is contained in:
Calum Grant
2024-10-16 10:23:39 +01:00
parent 853128c9c3
commit 6a48ad0ee7
11 changed files with 37 additions and 1 deletions

View File

@@ -300,6 +300,11 @@ class FunctionCall extends Call, @funbindexpr {
this.isVirtual() or
this.getTarget().getAnAttribute().getName() = "weak"
}
override predicate mayBeFromImplicitlyDeclaredFunction() {
this.getType() instanceof IntType and
this.getTarget().getADeclarationEntry().isImplicit()
}
}
/** A _user-defined_ unary `operator*` function. */

View File

@@ -534,6 +534,9 @@ class Expr extends StmtParent, @expr {
/** Gets the function containing this control-flow node. */
override Function getControlFlowScope() { result = this.getEnclosingFunction() }
/** Holds if this expression could be the return value of an implicitly declared function. */
predicate mayBeFromImplicitlyDeclaredFunction() { none() }
}
/**

View File

@@ -171,7 +171,7 @@ where
not arg.isAffectedByMacro() and
not arg.isFromUninstantiatedTemplate(_) and
not actual.getUnspecifiedType() instanceof ErroneousType and
not arg.(Call).getTarget().getADeclarationEntry().isImplicit()
not arg.mayBeFromImplicitlyDeclaredFunction()
select arg,
"This format specifier for type '" + expected.getName() + "' does not match the argument type '" +
actual.getUnspecifiedType().getName() + "'."

View File

@@ -0,0 +1 @@
| file://:0:0:0:0 | <error expr> |

View File

@@ -0,0 +1,5 @@
import cpp
from Expr e
where e.getType() instanceof ErroneousType
select e

View File

@@ -0,0 +1,2 @@
| file://:0:0:0:0 | There was an error during this compilation |
| implicit.cpp:5:5:5:5 | identifier 'g' is undefined |

View File

@@ -0,0 +1,4 @@
import cpp
from Diagnostic d
select d

View File

@@ -0,0 +1,4 @@
void f() {
f();
g();
}

View File

@@ -0,0 +1,6 @@
// semmle-extractor-options: --expect_errors
void f() {
f();
g();
}

View File

@@ -0,0 +1 @@
| implicit.c:3:5:3:5 | call to g |

View File

@@ -0,0 +1,5 @@
import cpp
from Expr e
where e.mayBeFromImplicitlyDeclaredFunction()
select e