[analyzer] Fix tracking expressions through negation operator

Differential Revision: https://reviews.llvm.org/D50537

llvm-svn: 339476
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 6111d32..8ad3002 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/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;
 }
 
diff --git a/clang/test/Analysis/diagnostics/no-store-func-path-notes.cpp b/clang/test/Analysis/diagnostics/no-store-func-path-notes.cpp
index b869f81..6e7aca0 100644
--- a/clang/test/Analysis/diagnostics/no-store-func-path-notes.cpp
+++ b/clang/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@-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@-1{{Returning from default constructor for 'HasForgottenField'}}
+  return !a.x; // expected-warning{{Undefined or garbage value returned to caller}}
+               // expected-note@-1{{Undefined or garbage value returned to caller}}
+}