summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2018-08-10 21:42:19 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2018-08-10 21:42:19 +0000
commitb5dd3ccdbde1fdeaeaceba3c8920e327abdd8da9 (patch)
tree373d27a06ce473a4341ba1fc1f5e299848523a2d /clang
parent09a9e3abfe879c9d5878d870e59860001ea5a767 (diff)
downloadbcm5719-llvm-b5dd3ccdbde1fdeaeaceba3c8920e327abdd8da9.tar.gz
bcm5719-llvm-b5dd3ccdbde1fdeaeaceba3c8920e327abdd8da9.zip
[analyzer] Fix tracking expressions through negation operator
Differential Revision: https://reviews.llvm.org/D50537 llvm-svn: 339476
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp4
-rw-r--r--clang/test/Analysis/diagnostics/no-store-func-path-notes.cpp15
2 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 6111d324fbd..8ad300278bb 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -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;
}
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 b869f81b6dd..6e7aca05c88 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 @@ 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}}
+}
OpenPOWER on IntegriCloud