Bootstrapped and regression tested on x86_64.


    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 --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 4452bb32728..043e49794ca 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 00000000000..59883ba2365
--- /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