r339476 - [analyzer] Fix tracking expressions through negation operator
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 10 14:42:19 PDT 2018
Author: george.karpenkov
Date: Fri Aug 10 14:42:19 2018
New Revision: 339476
URL: http://llvm.org/viewvc/llvm-project?rev=339476&view=rev
Log:
[analyzer] Fix tracking expressions through negation operator
Differential Revision: https://reviews.llvm.org/D50537
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=339476&r1=339475&r2=339476&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Aug 10 14:42:19 2018
@@ -1560,6 +1560,10 @@ static const Expr *peelOffOuterExpr(cons
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;
}
Modified: cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp?rev=339476&r1=339475&r2=339476&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp Fri Aug 10 14:42:19 2018
@@ -357,3 +357,18 @@ int forceElementRegionApperence() {
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}}
+}
More information about the cfe-commits
mailing list