https://gcc.gnu.org/g:44da5c23ddeca7e9297a0f265ccfb942cc3787d0

commit r16-8382-g44da5c23ddeca7e9297a0f265ccfb942cc3787d0
Author: Martin Uecker <[email protected]>
Date:   Fri Mar 27 19:45:42 2026 +0100

    c: Fix ICE related to field members that are arrays of pointers to structs 
[PR124635]
    
    We get a checking error in verify_type, because I did not copy
    TYPE_REVERSE_STORAGE_ORDER over from the original when reconstructing
    derived types during the contruction of canonical types.
    
            PR c/124635
    
    gcc/c/ChangeLog:
            * c-typeck.cc (c_reconstruct_complex_type): Copy
            TYPE_REVERSE_STORAGE_ORDER.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/pr124635.c: New test.

Diff:
---
 gcc/c/c-typeck.cc               |  6 ++++++
 gcc/testsuite/gcc.dg/pr124635.c | 10 ++++++++++
 2 files changed, 16 insertions(+)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 4452bb32728c..043e49794cae 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -548,8 +548,14 @@ c_reconstruct_complex_type (tree type, tree bottom)
     }
   else if (TREE_CODE (type) == ARRAY_TYPE)
     {
+      bool rso = TYPE_REVERSE_STORAGE_ORDER (type);
       inner = c_reconstruct_complex_type (TREE_TYPE (type), bottom);
       outer = c_build_array_type (inner, TYPE_DOMAIN (type));
+      if (rso)
+       {
+         outer = build_distinct_type_copy (outer);
+         TYPE_REVERSE_STORAGE_ORDER (outer) = 1;
+       }
 
       gcc_checking_assert (C_TYPE_VARIABLE_SIZE (type)
                           == C_TYPE_VARIABLE_SIZE (outer));
diff --git a/gcc/testsuite/gcc.dg/pr124635.c b/gcc/testsuite/gcc.dg/pr124635.c
new file mode 100644
index 000000000000..59883ba23652
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr124635.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -g" } */
+
+#pragma scalar_storage_order big-endian
+
+struct S {
+  struct S *s[1];
+  char c;
+};
+

Reply via email to