https://gcc.gnu.org/g:68d3f1e2c20efe07f99de3720d1732c4b987ff22

commit r17-1397-g68d3f1e2c20efe07f99de3720d1732c4b987ff22
Author: Martin Uecker <[email protected]>
Date:   Sat Jun 6 15:08:19 2026 +0200

    c: fix wrong encoding for zero-sized arrays [PR125618]
    
    This reverts one change from 106970adca69c9c577e6c75f4e69a08cd9ea2df0
    that replaced build_range_type with build_index_type.  In the function
    complete_array_type this breaks zero-sized arrays created from an empty
    initializer which there are represented using the C++ FE way [0, -1]
    causing issues on 32 bit architectures.
    
    After this partial revert this representation remains inconsistent to
    the usual C FE representation [0, NULL_TREE] (as before by change).
    
            PR c/125618
    
    gcc/c-family/ChangeLog:
            * c-common.cc (complete_array_type): Change back to using
            build_range_type.

Diff:
---
 gcc/c-family/c-common.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index ba72278bd522..a16288f4441c 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -7457,7 +7457,9 @@ complete_array_type (tree *ptype, tree initial_value, 
bool do_default)
      TYPE_LANG_FLAG_? bits that the front end may have set.  */
   main_type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
   TREE_TYPE (main_type) = unqual_elt;
-  TYPE_DOMAIN (main_type) = build_index_type (maxindex);
+  TYPE_DOMAIN (main_type)
+    = build_range_type (TREE_TYPE (maxindex),
+                       build_int_cst (TREE_TYPE (maxindex), 0), maxindex);
   TYPE_TYPELESS_STORAGE (main_type) = TYPE_TYPELESS_STORAGE (type);
   layout_type (main_type);

Reply via email to