[PATCH] D73898: [analyzer] StdLibraryFunctionsChecker: Add argument constraints

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 20 07:08:29 PST 2020


martong added a comment.

I've done a major refactor with the handling of argument constraints. I am now reusing `ValueRange::apply` in `checkPreCall` on "negated" value ranges to check if the constraint is violated.



================
Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:411
+      if (ExplodedNode *N = C.generateErrorNode(State)) {
+        // FIXME Add detailed diagnostic.
+        std::string Msg = "Function argument constraint is not satisfied";
----------------
NoQ wrote:
> Yeah, a must-have for this check to be enabled by default would be to be able to provide a specific warning message for every function. I guess we could include them in the summaries as an extra argument of `ArgConstraint`.
What about warning messages with placeholders? E.g. "Argument constraint of {nth} argument of {fun} is not satisfied. The value is {v}, however it should be in {range}." 
There will be a bunch of functions whose warning message template would be the same. On the other hand some others could have different warnings, and that justifies the need for specialized warnings.
Still, I think the warning message in the summary should be optional, because otherwise it would be really hard to automatically add summaries from other sources (like from cppcheck).

No matter how it turns out, this should be handled in a different patch.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:414
+        auto R = std::make_unique<PathSensitiveBugReport>(BT, Msg, N);
+        bugreporter::trackExpressionValue(N, Call.getArgExpr(0), *R);
+        C.emitReport(std::move(R));
----------------
NoQ wrote:
> Let's test our notes.
> 
> That'll be especially important when we get to non-concrete values, because the visitor might need to be expanded (or we might need a completely new visitor).
Ok, I added a separate test file where the tests focus on the bug path.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73898/new/

https://reviews.llvm.org/D73898





More information about the cfe-commits mailing list