[gcc r15-1382] c: Implement C2Y alignof on incomplete arrays
Joseph Myers
jsm28@gcc.gnu.org
Mon Jun 17 19:46:23 GMT 2024
https://gcc.gnu.org/g:edf514f83fa41012e52aaef2faef5a649e4b3f6d
commit r15-1382-gedf514f83fa41012e52aaef2faef5a649e4b3f6d
Author: Joseph Myers <josmyers@redhat.com>
Date: Mon Jun 17 19:45:43 2024 +0000
c: Implement C2Y alignof on incomplete arrays
C2Y has adopted support for alignof applied to incomplete array types
(N3273). Add this support to GCC. As the relevant checks are in
c-family code that doesn't have access to functions such as
pedwarn_c23, this remains a hard error for older versions and isn't
handled by -Wc23-c2y-compat, although preferably it would work like
pedwarn_c23 (pedwarn-if-pedantic for older versions, warning with
-Wc23-c2y-compat in C2Y mode).
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc/c-family/
* c-common.cc (c_sizeof_or_alignof_type): Allow alignof on an
incomplete array type for C2Y.
gcc/testsuite/
* gcc.dg/c23-align-10.c, gcc.dg/c2y-align-1.c,
gcc.dg/c2y-align-2.c: New tests.
Diff:
---
gcc/c-family/c-common.cc | 4 +++-
gcc/testsuite/gcc.dg/c23-align-10.c | 6 ++++++
gcc/testsuite/gcc.dg/c2y-align-1.c | 6 ++++++
gcc/testsuite/gcc.dg/c2y-align-2.c | 8 ++++++++
4 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 24335deeb582..7d752acd430c 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -3972,7 +3972,9 @@ c_sizeof_or_alignof_type (location_t loc,
value = size_one_node;
}
else if (!COMPLETE_TYPE_P (type)
- && (!c_dialect_cxx () || is_sizeof || type_code != ARRAY_TYPE))
+ && ((!c_dialect_cxx () && !flag_isoc2y)
+ || is_sizeof
+ || type_code != ARRAY_TYPE))
{
if (complain)
error_at (loc, "invalid application of %qs to incomplete type %qT",
diff --git a/gcc/testsuite/gcc.dg/c23-align-10.c b/gcc/testsuite/gcc.dg/c23-align-10.c
new file mode 100644
index 000000000000..bd6b9c268c3a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-align-10.c
@@ -0,0 +1,6 @@
+/* Test C2Y alignof on an incomplete array type: not allowed in C23. */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+
+int a = alignof(int[]); /* { dg-error "incomplete" } */
+int b = alignof(int[][1]); /* { dg-error "incomplete" } */
diff --git a/gcc/testsuite/gcc.dg/c2y-align-1.c b/gcc/testsuite/gcc.dg/c2y-align-1.c
new file mode 100644
index 000000000000..3f9ab18c5186
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2y-align-1.c
@@ -0,0 +1,6 @@
+/* Test C2Y alignof on an incomplete array type. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2y -pedantic-errors" } */
+
+int a = alignof(int[]);
+int b = alignof(int[][1]);
diff --git a/gcc/testsuite/gcc.dg/c2y-align-2.c b/gcc/testsuite/gcc.dg/c2y-align-2.c
new file mode 100644
index 000000000000..b7b871504137
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2y-align-2.c
@@ -0,0 +1,8 @@
+/* Test C2Y alignof on an incomplete array type: still not allowed for other
+ incomplete types. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2y -pedantic-errors" } */
+
+int a = alignof(void); /* { dg-error "void" } */
+struct s;
+int b = alignof(struct s); /* { dg-error "incomplete" } */
More information about the Gcc-cvs
mailing list