This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Adds TrustReturnsNonnullChecker
ClosedPublic

Authored by t-rasmud on Jan 31 2022, 2:40 PM.

Details

Summary

This checker adds nullability-related assumptions to methods annotated with returns_nonnull attribute.

Diff Detail

Event Timeline

t-rasmud created this revision.Jan 31 2022, 2:40 PM
t-rasmud requested review of this revision.Jan 31 2022, 2:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 31 2022, 2:40 PM
NoQ edited reviewers, added: NoQ; removed: dergachev.a.Jan 31 2022, 5:46 PM
NoQ added a subscriber: NoQ.

Lovely! I have some nits.

@NoQ is my actual account, sorry for the mess >.<

clang/lib/StaticAnalyzer/Checkers/TrustReturnsNonnullChecker.cpp
2–3

This line broke.

43

Parameter C appears to be unused.

48

Call.getDecl() has to be checked for null. Calls with null decls appear when the function being called is unknown, eg. during calls through unknown/symbolic pointer-to-function:

void test(void *(*f)(void)) {
  // will probably crash the compiler, worth a test case
  f();
}
49
if (x) {
  return true;
}
return false;

can usually be shortened to

return x;

.

NoQ retitled this revision from Adds TrustReturnsNonnullChecker to [analyzer] Adds TrustReturnsNonnullChecker.Jan 31 2022, 5:46 PM
t-rasmud updated this revision to Diff 405030.Feb 1 2022, 12:00 PM

This diff addresses review comments.

NoQ added a comment.Feb 1 2022, 12:21 PM

Great, thanks!

The phabricator expects complete patches reuploaded (i.e., diffs against main branch rather than diffs against the previous upload); but it knows how to produce patches-on-patches from complete patches through the History tab. Another reason to upload complete patches is to unconfuse pre-merge buildbots (the "Build Status: patch application failed" part).

So please re-upload and that'd be a ✅

clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
113–115

As this checker mimics that other checker, the question inevitably arises whether the two can be merged. The other checker is currently stuffed with extra code to handle operator == which is possibly no longer necessary since D82445 provides a more general solution. I guess this could be an interesting refactoring pass.

clang/test/Analysis/test-decl-crash.cpp
6 ↗(On Diff #405030)

It makes sense to put the new test into the same file given that they share the RUN: line.

t-rasmud updated this revision to Diff 405091.Feb 1 2022, 1:51 PM

This diff merges relevant test cases into one file.

NoQ accepted this revision.Feb 1 2022, 8:20 PM

Awesome! I'll commit.

This revision is now accepted and ready to land.Feb 1 2022, 8:20 PM
This revision was landed with ongoing or failed builds.Feb 2 2022, 11:47 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2022, 11:47 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript