r363512 - [analyzer] Push correct version of 'Track indices of arrays'
Kristof Umann via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 16 08:41:25 PDT 2019
Author: szelethus
Date: Sun Jun 16 08:41:25 2019
New Revision: 363512
URL: http://llvm.org/viewvc/llvm-project?rev=363512&view=rev
Log:
[analyzer] Push correct version of 'Track indices of arrays'
Messed up the commit, oops.
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/diagnostics/track_subexpressions.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=363512&r1=363511&r2=363512&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Sun Jun 16 08:41:25 2019
@@ -1740,9 +1740,10 @@ bool bugreporter::trackExpressionValue(c
if (const Expr *Receiver = NilReceiverBRVisitor::getNilReceiver(Inner, LVNode))
trackExpressionValue(LVNode, Receiver, report, EnableNullFPSuppression);
+ // Track the index if this is an array subscript.
if (const auto *Arr = dyn_cast<ArraySubscriptExpr>(Inner))
trackExpressionValue(
- LVNode, Arr->getIdx(), report, EnableNullFPSuppression);
+ LVNode, Arr->getIdx(), report, /*EnableNullFPSuppression*/ false);
// See if the expression we're interested refers to a variable.
// If so, we can track both its contents and constraints on its value.
Modified: cfe/trunk/test/Analysis/diagnostics/track_subexpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/track_subexpressions.cpp?rev=363512&r1=363511&r2=363512&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/track_subexpressions.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/track_subexpressions.cpp Sun Jun 16 08:41:25 2019
@@ -23,11 +23,12 @@ void consume(int);
int getIndex(int x) {
int a;
- if (x > 0)
- a = 3;
+ if (x > 0) // expected-note {{Assuming 'x' is > 0}}
+ // expected-note at -1 {{Taking true branch}}
+ a = 3; // expected-note {{The value 3 is assigned to 'a'}}
else
a = 2;
- return a;
+ return a; // expected-note {{Returning the value 3 (loaded from 'a')}}
}
int getInt();
@@ -36,9 +37,47 @@ void testArrayIndexTracking() {
int arr[10];
for (int i = 0; i < 3; ++i)
+ // expected-note at -1 3{{Loop condition is true. Entering loop body}}
+ // expected-note at -2 {{Loop condition is false. Execution continues on line 43}}
arr[i] = 0;
int x = getInt();
- int n = getIndex(x);
+ int n = getIndex(x); // expected-note {{Calling 'getIndex'}}
+ // expected-note at -1 {{Returning from 'getIndex'}}
+ // expected-note at -2 {{'n' initialized to 3}}
consume(arr[n]);
+ // expected-note at -1 {{1st function call argument is an uninitialized value}}
+ // expected-warning at -2{{1st function call argument is an uninitialized value}}
}
} // end of namespace array_index_tracking
+
+namespace multi_array_index_tracking {
+void consume(int);
+
+int getIndex(int x) {
+ int a;
+ if (x > 0) // expected-note {{Assuming 'x' is > 0}}
+ // expected-note at -1 {{Taking true branch}}
+ a = 3; // expected-note {{The value 3 is assigned to 'a'}}
+ else
+ a = 2;
+ return a; // expected-note {{Returning the value 3 (loaded from 'a')}}
+}
+
+int getInt();
+
+void testArrayIndexTracking() {
+ int arr[2][10];
+
+ for (int i = 0; i < 3; ++i)
+ // expected-note at -1 3{{Loop condition is true. Entering loop body}}
+ // expected-note at -2 {{Loop condition is false. Execution continues on line 75}}
+ arr[1][i] = 0;
+ int x = getInt();
+ int n = getIndex(x); // expected-note {{Calling 'getIndex'}}
+ // expected-note at -1 {{Returning from 'getIndex'}}
+ // expected-note at -2 {{'n' initialized to 3}}
+ consume(arr[1][n]);
+ // expected-note at -1 {{1st function call argument is an uninitialized value}}
+ // expected-warning at -2{{1st function call argument is an uninitialized value}}
+}
+} // end of namespace mulit_array_index_tracking
More information about the cfe-commits
mailing list