summaryrefslogtreecommitdiff
path: root/test/Analysis
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2017-12-05 21:19:59 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2017-12-05 21:19:59 +0000
commit7a80359d95188d12fafad3e93d057171ceeb711d (patch)
treedd400e580de473d76459ee9fb3b2ea45829d99fd /test/Analysis
parent8df79b8c01236478ed93b6825df2450a43eebb07 (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319834 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/vector.m (renamed from test/Analysis/vector.c)33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/Analysis/vector.c b/test/Analysis/vector.m
index 32b568f6b0..e74c487d3a 100644
--- a/test/Analysis/vector.c
+++ b/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;
+}