From: George Karpenkov Date: Fri, 10 Aug 2018 21:42:19 +0000 (+0000) Subject: [analyzer] Fix tracking expressions through negation operator X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ffc857a528123fe02c165670316e1c13f99a7eea;p=clang [analyzer] Fix tracking expressions through negation operator Differential Revision: https://reviews.llvm.org/D50537 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339476 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 6111d324fb..8ad300278b 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/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(Ex)) + if (UO->getOpcode() == UO_LNot) + return peelOffOuterExpr(UO->getSubExpr(), N); + return Ex; } diff --git a/test/Analysis/diagnostics/no-store-func-path-notes.cpp b/test/Analysis/diagnostics/no-store-func-path-notes.cpp index b869f81b6d..6e7aca05c8 100644 --- a/test/Analysis/diagnostics/no-store-func-path-notes.cpp +++ b/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}} +}