Author: charusso Date: Wed Aug 21 17:06:58 2019 New Revision: 369604 URL: http://llvm.org/viewvc/llvm-project?rev=369604&view=rev Log: [analyzer] TrackConstraintBRVisitor: Do not track unknown values
Summary: - Reviewers: NoQ, Szelethus Reviewed By: NoQ, Szelethus Differential Revision: https://reviews.llvm.org/D66267 Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp cfe/trunk/test/Analysis/cast-value.cpp Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=369604&r1=369603&r2=369604&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug 21 17:06:58 2019 @@ -1992,9 +1992,10 @@ bool bugreporter::trackExpressionValue(c report.markInteresting(V, TKind); report.addVisitor(std::make_unique<UndefOrNullArgVisitor>(R)); - // If the contents are symbolic, find out when they became null. - if (V.getAsLocSymbol(/*IncludeBaseRegions*/ true)) - report.addVisitor(std::make_unique<TrackConstraintBRVisitor>( + // If the contents are symbolic and null, find out when they became null. + if (V.getAsLocSymbol(/*IncludeBaseRegions=*/true)) + if (LVState->isNull(V).isConstrainedTrue()) + report.addVisitor(std::make_unique<TrackConstraintBRVisitor>( V.castAs<DefinedSVal>(), false)); // Add visitor, which will suppress inline defensive checks. Modified: cfe/trunk/test/Analysis/cast-value.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cast-value.cpp?rev=369604&r1=369603&r2=369604&view=diff ============================================================================== --- cfe/trunk/test/Analysis/cast-value.cpp (original) +++ cfe/trunk/test/Analysis/cast-value.cpp Wed Aug 21 17:06:58 2019 @@ -152,8 +152,7 @@ void evalReferences(const Shape &S) { void evalNonNullParamNonNullReturnReference(const Shape &S) { const auto *C = dyn_cast_or_null<Circle>(S); // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' succeeds}} - // expected-note@-2 {{Assuming pointer value is null}} - // expected-note@-3 {{'C' initialized here}} + // expected-note@-2 {{'C' initialized here}} (void)(1 / !(bool)C); // expected-note@-1 {{'C' is non-null}} @@ -165,8 +164,7 @@ void evalNonNullParamNonNullReturnRefere void evalNonNullParamNonNullReturn(const Shape *S) { const auto *C = cast<Circle>(S); // expected-note@-1 {{Checked cast from 'Shape' to 'Circle' succeeds}} - // expected-note@-2 {{Assuming pointer value is null}} - // expected-note@-3 {{'C' initialized here}} + // expected-note@-2 {{'C' initialized here}} (void)(1 / !(bool)C); // expected-note@-1 {{'C' is non-null}} @@ -178,7 +176,6 @@ void evalNonNullParamNonNullReturn(const void evalNonNullParamNullReturn(const Shape *S) { const auto *C = dyn_cast_or_null<Circle>(S); // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' fails}} - // expected-note@-2 {{Assuming pointer value is null}} if (const auto *T = dyn_cast_or_null<Triangle>(S)) { // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Triangle' succeeds}} @@ -207,9 +204,8 @@ void evalNullParamNullReturn(const Shape void evalZeroParamNonNullReturnPointer(const Shape *S) { const auto *C = S->castAs<Circle>(); - // expected-note@-1 {{Assuming pointer value is null}} - // expected-note@-2 {{Checked cast to 'Circle' succeeds}} - // expected-note@-3 {{'C' initialized here}} + // expected-note@-1 {{Checked cast to 'Circle' succeeds}} + // expected-note@-2 {{'C' initialized here}} (void)(1 / !(bool)C); // expected-note@-1 {{'C' is non-null}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits