aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2025-03-04 16:13:09 +0100
committerRichard Biener <rguenth@gcc.gnu.org>2025-03-05 11:05:38 +0100
commit556e25f0e9abc720c940994bd9a1491062933d49 (patch)
treeec72265fff5dc26f96a57523070996e3f3754f71 /gcc
parent2653d988e92bc9d70a3ac674d1b819610858e00a (diff)
downloadgcc-556e25f0e9abc720c940994bd9a1491062933d49.zip
gcc-556e25f0e9abc720c940994bd9a1491062933d49.tar.gz
gcc-556e25f0e9abc720c940994bd9a1491062933d49.tar.bz2
middle-end/97323 - TYPE_CANONICAL vs. ARRAY_TYPE modes
For strict-alignment targets we can end up with BLKmode single-element array types when the element type is unaligned. This confuses type checking since the canonical type would have an aligned element type and a non-BLKmode mode. The following simply ignores the mode we assign to array types for this purpose, like we already do for record and union types. PR middle-end/97323 * tree.cc (gimple_canonical_types_compatible_p): Ignore TYPE_MODE also for ARRAY_TYPE. (verify_type): Likewise. * gcc.dg/pr97323.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/pr97323.c5
-rw-r--r--gcc/tree.cc2
2 files changed, 7 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/pr97323.c b/gcc/testsuite/gcc.dg/pr97323.c
new file mode 100644
index 0000000..8845a34
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97323.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-g" } */
+
+typedef int a __attribute__((aligned(2)));
+a b[1];
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 0743ed7..4e855b4 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -13982,6 +13982,7 @@ gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
flexible array members, we allow mismatching modes for structures or
unions. */
if (!RECORD_OR_UNION_TYPE_P (t1)
+ && TREE_CODE (t1) != ARRAY_TYPE
&& TYPE_MODE (t1) != TYPE_MODE (t2))
return false;
@@ -14313,6 +14314,7 @@ verify_type (const_tree t)
flexible array members. */
&& !RECORD_OR_UNION_TYPE_P (t)
&& !RECORD_OR_UNION_TYPE_P (TYPE_CANONICAL (t))
+ && TREE_CODE (t) != ARRAY_TYPE
&& TYPE_MODE (t) != TYPE_MODE (TYPE_CANONICAL (t)))
{
error ("%<TYPE_MODE%> of %<TYPE_CANONICAL%> is not compatible");