[PATCH] D62978: [analyzer] ReturnVisitor: Handle non-null ReturnStmts

Csaba Dabis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 6 13:35:48 PDT 2019


Charusso created this revision.
Charusso added reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus.
Charusso added a project: clang.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet.
Charusso added a comment.

Suppressed example: F9091784: return-non-null.html <https://reviews.llvm.org/F9091784>


If we have a value at the return side do not write out it is being null.


Repository:
  rC Clang

https://reviews.llvm.org/D62978

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/diagnostics/find_last_store.c
  clang/test/Analysis/inlining/false-positive-suppression.cpp


Index: clang/test/Analysis/inlining/false-positive-suppression.cpp
===================================================================
--- clang/test/Analysis/inlining/false-positive-suppression.cpp
+++ clang/test/Analysis/inlining/false-positive-suppression.cpp
@@ -1,5 +1,13 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config suppress-null-return-paths=false -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify -DSUPPRESSED=1 %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-config suppress-null-return-paths=false \
+// RUN:  -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -DSUPPRESSED=1 \
+// RUN:  -verify %s
+
+#ifdef SUPPRESSED
+// expected-no-diagnostics
+#endif
 
 namespace rdar12676053 {
   // Delta-reduced from a preprocessed file.
@@ -85,7 +93,10 @@
 
     int *&box2 = m.getValue(i);
     box2 = 0;
-    *box2 = 1; // expected-warning {{Dereference of null pointer}}
+    *box2 = 1;
+#ifndef SUPPRESSED
+    // expected-warning at -2 {{Dereference of null pointer}}
+#endif
   }
 
   SomeClass *&getSomeClass() {
Index: clang/test/Analysis/diagnostics/find_last_store.c
===================================================================
--- clang/test/Analysis/diagnostics/find_last_store.c
+++ clang/test/Analysis/diagnostics/find_last_store.c
@@ -1,4 +1,9 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-config suppress-null-return-paths=false \
+// RUN:  -analyzer-output=text -verify %s
+
+// FIXME: Make it work with suppress-null-return-paths=true.
+
 typedef struct { float b; } c;
 void *a();
 void *d() {
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -827,8 +827,7 @@
   /// the statement is a call that was inlined, we add the visitor to the
   /// bug report, so it can print a note later.
   static void addVisitorIfNecessary(const ExplodedNode *Node, const Stmt *S,
-                                    BugReport &BR,
-                                    bool InEnableNullFPSuppression) {
+                                    BugReport &BR, bool IsNullFPSuppression) {
     if (!CallEvent::isCallStmt(S))
       return;
 
@@ -877,11 +876,11 @@
     // See if the return value is NULL. If so, suppress the report.
     AnalyzerOptions &Options = State->getAnalysisManager().options;
 
+    // If we have a value at the return side do not write out it is being null.
     bool EnableNullFPSuppression = false;
-    if (InEnableNullFPSuppression &&
-        Options.ShouldSuppressNullReturnPaths)
+    if (IsNullFPSuppression && Options.ShouldSuppressNullReturnPaths)
       if (Optional<Loc> RetLoc = RetVal.getAs<Loc>())
-        EnableNullFPSuppression = State->isNull(*RetLoc).isConstrainedTrue();
+        EnableNullFPSuppression = true;
 
     BR.markInteresting(CalleeContext);
     BR.addVisitor(llvm::make_unique<ReturnVisitor>(CalleeContext,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62978.203434.patch
Type: text/x-patch
Size: 3181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190606/61b0da17/attachment.bin>


More information about the cfe-commits mailing list