diff options
| author | George Karpenkov <ekarpenkov@apple.com> | 2017-12-05 21:19:59 +0000 |
|---|---|---|
| committer | George Karpenkov <ekarpenkov@apple.com> | 2017-12-05 21:19:59 +0000 |
| commit | 8d345cb8a549dcf9e8965c2c718a6538af6653d1 (patch) | |
| tree | 1c854e3e8a4ae8569581180dd3af70658f8dd9d2 /clang/test/Analysis | |
| parent | d4953014144a6160c2df0e1729fe532be23407f9 (diff) | |
| download | bcm5719-llvm-8d345cb8a549dcf9e8965c2c718a6538af6653d1.tar.gz bcm5719-llvm-8d345cb8a549dcf9e8965c2c718a6538af6653d1.zip | |
[analyzer] do not crash on cases where an array subscript is an rvalue
Array subscript is almost always an lvalue, except for a few cases where
it is not, such as a subscript into an Objective-C property, or a
return from the function.
This commit prevents crashing in such cases.
Fixes rdar://34829842
Differential Revision: https://reviews.llvm.org/D40584
llvm-svn: 319834
Diffstat (limited to 'clang/test/Analysis')
| -rw-r--r-- | clang/test/Analysis/vector.m (renamed from clang/test/Analysis/vector.c) | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/clang/test/Analysis/vector.c b/clang/test/Analysis/vector.m index 32b568f6b00..e74c487d3a6 100644 --- a/clang/test/Analysis/vector.c +++ b/clang/test/Analysis/vector.m @@ -2,6 +2,7 @@ typedef int __attribute__((ext_vector_type(2))) V; +void clang_analyzer_warnIfReached(); void clang_analyzer_numTimesReached(); void clang_analyzer_eval(int); @@ -26,3 +27,35 @@ V dont_crash_and_dont_split_state(V x, V y) { clang_analyzer_numTimesReached(); // expected-warning{{2}} return z; } + +void test_read() { + V x; + x[0] = 0; + x[1] = 1; + + clang_analyzer_eval(x[0] == 0); // expected-warning{{TRUE}} +} + +V return_vector() { + V z; + z[0] = 0; + z[1] = 0; + return z; +} + +int test_vector_access() { + return return_vector()[0]; // no-crash no-warning +} + +@interface I +@property V v; +@end + +// Do not crash on subscript operations into ObjC properties. +int myfunc(I *i2) { + int out = i2.v[0]; // no-crash no-warning + + // Check that the analysis continues. + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + return out; +} |

