]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Call relayout_decl in build_compound_literal when completing type [PR123365]
authorJakub Jelinek <jakub@redhat.com>
Wed, 18 Feb 2026 16:46:38 +0000 (17:46 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 18 Feb 2026 16:46:38 +0000 (17:46 +0100)
Most other spots inthe C FE which change type of some VAR_DECL
through complete_array_type call relayout_decl to fix up DECL_MODE
etc., but build_compound_literal strangely does not.

It has layout_decl (decl, 0); call later on but I think that is
quite useless given that already the build_decl call earlier
calls that and so the second layout_decl probably does nothing
most of the time.

On the following testcase, the compound literal VAR_DECL has
BLKmode from the time it had incomplete array type and isn't
changed to DImode that the completed type has and asm stmt
expansion is unhappy about that.

Fixed thusly.

2026-02-18  Jakub Jelinek  <jakub@redhat.com>

PR c/123365
* c-decl.cc (build_compound_literal): Call relayout_decl
after completing the type.

* gcc.c-torture/compile/pr123365.c: New test.

gcc/c/c-decl.cc
gcc/testsuite/gcc.c-torture/compile/pr123365.c [new file with mode: 0644]

index f2440a0a630091449f7015452a35350c819dee3e..80eebc3590848344f36849c8b9d16e3b6ae3062f 100644 (file)
@@ -6541,6 +6541,7 @@ build_compound_literal (location_t loc, tree type, tree init, bool non_const,
 
       type = TREE_TYPE (decl);
       TREE_TYPE (DECL_INITIAL (decl)) = type;
+      relayout_decl (decl);
     }
 
   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr123365.c b/gcc/testsuite/gcc.c-torture/compile/pr123365.c
new file mode 100644 (file)
index 0000000..b107363
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR c/123365 */
+
+void
+foo ()
+{
+  __asm__ volatile ("" : "+r" ((long long[]) { 0 }));
+}