serge-sans-paille created this revision.
serge-sans-paille added reviewers: sberg, kees.
Herald added a project: All.
serge-sans-paille requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132853
Files:
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
Index: clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
===================================================================
--- clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
+++ clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -verify -fstrict-flex-arrays=2 %s
+// RUN: %clang_cc1 -verify=relaxed -fstrict-flex-arrays=1 %s
+// RUN: %clang_cc1 -verify=relaxed,strict -fstrict-flex-arrays=2 %s
// We cannot know for sure the size of a flexible array.
struct t {
@@ -9,16 +10,26 @@
s2->a[2] = 0; // no-warning
}
-// Under -fstrict-flex-arrays `a` is not a flexible array.
+// Under -fstrict-flex-arrays={1,2} `a` is not a flexible array
+struct t0 {
+ int f;
+ int a[10]; // relaxed-note {{array 'a' declared here}}
+};
+void test0(t0 *s2) {
+ s2->a[12] = 0; // relaxed-warning {{array index 12 is past the end of the
array (which contains 10 elements)}}
+}
+
+
+// Under -fstrict-flex-arrays=2 `a` is not a flexible array, but it is under
-fstrict-flex-arrays=1
struct t1 {
int f;
- int a[1]; // expected-note {{array 'a' declared here}}
+ int a[1]; // strict-note {{array 'a' declared here}}
};
void test1(t1 *s2) {
- s2->a[2] = 0; // expected-warning {{array index 2 is past the end of the
array (which contains 1 element)}}
+ s2->a[2] = 0; // strict-warning {{array index 2 is past the end of the array
(which contains 1 element)}}
}
-// Under -fstrict-flex-arrays `a` is a flexible array.
+// Under -fstrict-flex-arrays={1,2} `a` is a flexible array.
struct t2 {
int f;
int a[0];
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15852,7 +15852,7 @@
if (StrictFlexArraysLevel >= 2 && Size != 0)
return false;
- if (StrictFlexArraysLevel == 1 && Size.ule(1))
+ if (StrictFlexArraysLevel == 1 && Size.uge(2))
return false;
// FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
Index: clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
===================================================================
--- clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
+++ clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -verify -fstrict-flex-arrays=2 %s
+// RUN: %clang_cc1 -verify=relaxed -fstrict-flex-arrays=1 %s
+// RUN: %clang_cc1 -verify=relaxed,strict -fstrict-flex-arrays=2 %s
// We cannot know for sure the size of a flexible array.
struct t {
@@ -9,16 +10,26 @@
s2->a[2] = 0; // no-warning
}
-// Under -fstrict-flex-arrays `a` is not a flexible array.
+// Under -fstrict-flex-arrays={1,2} `a` is not a flexible array
+struct t0 {
+ int f;
+ int a[10]; // relaxed-note {{array 'a' declared here}}
+};
+void test0(t0 *s2) {
+ s2->a[12] = 0; // relaxed-warning {{array index 12 is past the end of the array (which contains 10 elements)}}
+}
+
+
+// Under -fstrict-flex-arrays=2 `a` is not a flexible array, but it is under -fstrict-flex-arrays=1
struct t1 {
int f;
- int a[1]; // expected-note {{array 'a' declared here}}
+ int a[1]; // strict-note {{array 'a' declared here}}
};
void test1(t1 *s2) {
- s2->a[2] = 0; // expected-warning {{array index 2 is past the end of the array (which contains 1 element)}}
+ s2->a[2] = 0; // strict-warning {{array index 2 is past the end of the array (which contains 1 element)}}
}
-// Under -fstrict-flex-arrays `a` is a flexible array.
+// Under -fstrict-flex-arrays={1,2} `a` is a flexible array.
struct t2 {
int f;
int a[0];
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15852,7 +15852,7 @@
if (StrictFlexArraysLevel >= 2 && Size != 0)
return false;
- if (StrictFlexArraysLevel == 1 && Size.ule(1))
+ if (StrictFlexArraysLevel == 1 && Size.uge(2))
return false;
// FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits