[cfe-dev] Performing a path-sensitive check only when a function return value is ignored
Artem Dergachev via cfe-dev
cfe-dev at lists.llvm.org
Tue Jun 14 06:13:17 PDT 2016
For implementing your approach, i'd suggest something like that (untested!):
void YourChecker::checkPreCall(const CallEvent &Call, CheckerContext &C)
const {
const CallExpr *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr());
if (!CE)
return;
// Find the parent statement of the call expression, which should be
somewhere in the caller's body.
const Stmt *Parent =
C.getLocationContext()->getCurrentStackFrame()->getParent()->getParentMap().getParent(CE);
if (!isa<CompoundStmt>(Parent)) // Return value not discarded?
return;
// Proceed with your checks.
}
However, you might also consider the path-sensitive approach to finding
discarded/unchecked return values. That is, if the return value was
saved into a variable, it might have still been discarded, so a
syntax-only check is not enough, you'd need to see how the value flows.
For that, you'd need to subscribe to checkDeadSymbols, and see if upon
the death of the symbol there are no range constraints on it; then, if
the value was truly unchecked, you can throw the warning on the original
call expression. But that's more complicated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160614/82abde5c/attachment.html>
More information about the cfe-dev
mailing list