[PATCH] D132853: [clang] Fix -Warray-bound interaction with -fstrict-flex-arrays=1
serge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 30 05:50:59 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG31dd0255aeaa: [clang] Fix -Warray-bound interaction with -fstrict-flex-arrays=1 (authored by serge-sans-paille).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132853/new/
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132853.456638.patch
Type: text/x-patch
Size: 2043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220830/1c5fdce9/attachment.bin>
More information about the cfe-commits
mailing list