[PATCH] D50537: [analyzer] Fix tracking expressions through negation operator

George Karpenkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 10 14:42:52 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL339476: [analyzer] Fix tracking expressions through negation operator (authored by george.karpenkov, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50537?vs=160009&id=160183#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50537

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1560,6 +1560,10 @@
     if (const Expr *SubEx = peelOffPointerArithmetic(BO))
       return peelOffOuterExpr(SubEx, N);
 
+  if (auto *UO = dyn_cast<UnaryOperator>(Ex))
+    if (UO->getOpcode() == UO_LNot)
+      return peelOffOuterExpr(UO->getSubExpr(), N);
+
   return Ex;
 }
 
Index: cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
===================================================================
--- cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
+++ cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
@@ -357,3 +357,18 @@
   return ((HasFieldB*)&a)->x; // expected-warning{{Undefined or garbage value returned to caller}}
                               // expected-note at -1{{Undefined or garbage value returned to caller}}
 }
+
+////////
+
+struct HasForgottenField {
+  int x;
+  HasForgottenField() {} // expected-note{{Returning without writing to 'this->x'}}
+};
+
+// Test that tracking across exclamation mark works.
+bool tracksThroughExclamationMark() {
+  HasForgottenField a; // expected-note{{Calling default constructor for 'HasForgottenField'}}
+                       // expected-note at -1{{Returning from default constructor for 'HasForgottenField'}}
+  return !a.x; // expected-warning{{Undefined or garbage value returned to caller}}
+               // expected-note at -1{{Undefined or garbage value returned to caller}}
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50537.160183.patch
Type: text/x-patch
Size: 1654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180810/89ff189a/attachment.bin>


More information about the llvm-commits mailing list