diff options
| author | Kristof Umann <dkszelethus@gmail.com> | 2019-06-16 15:41:25 +0000 |
|---|---|---|
| committer | Kristof Umann <dkszelethus@gmail.com> | 2019-06-16 15:41:25 +0000 |
| commit | e20b388e2f923bfc98f63a13fea9fc19aeaec425 (patch) | |
| tree | 788cd98c6b99e16890e15db0a792b40fc68c22b1 /clang/test | |
| parent | c8d88ad1a916d7e877f28bce752e8f63b73b164a (diff) | |
| download | bcm5719-llvm-e20b388e2f923bfc98f63a13fea9fc19aeaec425.tar.gz bcm5719-llvm-e20b388e2f923bfc98f63a13fea9fc19aeaec425.zip | |
[analyzer] Push correct version of 'Track indices of arrays'
Messed up the commit, oops.
llvm-svn: 363512
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/diagnostics/track_subexpressions.cpp | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/clang/test/Analysis/diagnostics/track_subexpressions.cpp b/clang/test/Analysis/diagnostics/track_subexpressions.cpp index 9097a05a490..99fc0a6e384 100644 --- a/clang/test/Analysis/diagnostics/track_subexpressions.cpp +++ b/clang/test/Analysis/diagnostics/track_subexpressions.cpp @@ -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@-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@-1 3{{Loop condition is true. Entering loop body}} + // expected-note@-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@-1 {{Returning from 'getIndex'}} + // expected-note@-2 {{'n' initialized to 3}} consume(arr[n]); + // expected-note@-1 {{1st function call argument is an uninitialized value}} + // expected-warning@-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@-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@-1 3{{Loop condition is true. Entering loop body}} + // expected-note@-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@-1 {{Returning from 'getIndex'}} + // expected-note@-2 {{'n' initialized to 3}} + consume(arr[1][n]); + // expected-note@-1 {{1st function call argument is an uninitialized value}} + // expected-warning@-2{{1st function call argument is an uninitialized value}} +} +} // end of namespace mulit_array_index_tracking |

