Improve -Warray-bounds to handle multiple array extents rather than only handling the top-most array extent.
Patch by Bevin Hansson.
llvm-svn: 330759
diff --git a/clang/test/SemaCXX/array-bounds.cpp b/clang/test/SemaCXX/array-bounds.cpp
index 8ae92e7..a97f8e3 100644
--- a/clang/test/SemaCXX/array-bounds.cpp
+++ b/clang/test/SemaCXX/array-bounds.cpp
@@ -269,3 +269,18 @@
struct P x[10] = {0}; // expected-note {{array 'x' declared here}}
return x[1] + x[11]; // expected-warning {{array index 11 is past the end of the array (which contains 10 elements)}}
}
+
+int multi[2][2][2]; // expected-note 3 {{array 'multi' declared here}}
+int test_multiarray() {
+ return multi[2][0][0] + // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+ multi[0][2][0] + // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+ multi[0][0][2]; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+}
+
+struct multi_s {
+ int arr[4];
+};
+struct multi_s multi2[4]; // expected-note {{array 'multi2' declared here}}
+int test_struct_multiarray() {
+ return multi2[4].arr[0]; // expected-warning {{array index 4 is past the end of the array (which contains 4 elements)}}
+}