]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix tracking expressions through negation operator
authorGeorge Karpenkov <ekarpenkov@apple.com>
Fri, 10 Aug 2018 21:42:19 +0000 (21:42 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Fri, 10 Aug 2018 21:42:19 +0000 (21:42 +0000)
Differential Revision: https://reviews.llvm.org/D50537

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339476 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6111d324fbdaf26ffc9c0fd2bc783bda576779e9..8ad300278bb3dbcaebc9dc6360e609eb2e6623d2 100644 (file)
@@ -1560,6 +1560,10 @@ static const Expr *peelOffOuterExpr(const Expr *Ex,
     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 b869f81b6dd0f90c02a67497cea6b05815b09147..6e7aca05c88a606ab642843811dbd8161230068c 100644 (file)
@@ -357,3 +357,18 @@ int forceElementRegionApperence() {
   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}}
+}