Fixes incorrect encoding for zero-sized arrays in C
GCC fixes a regression where zero-sized arrays in C were incorrectly encoded on 32-bit architectures, leading to compilation issues.
This commit partially reverts a previous change that introduced a regression for zero-sized arrays in C, specifically impacting 32-bit architectures. The original change incorrectly replaced build_range_type with build_index_type when completing array types, causing zero-sized arrays created from empty initializers to be represented as [0, -1] instead of the expected [0, NULL_TREE]. This fix restores the correct representation, resolving compilation issues for C code that uses such arrays.
In Details
This commit addresses PR125618 by partially reverting an earlier change (106970adca69) in gcc/c-family/c-common.cc. Specifically, within the complete_array_type function, the build_range_type call is reinstated, replacing the build_index_type which had been incorrectly introduced. The issue arose because build_index_type could lead to a [0, -1] representation for zero-sized arrays created from empty initializers, which is problematic on 32-bit systems. While this fix resolves the immediate problem, it reintroduces an inconsistency with the C++ front-end's representation for such a…
For Context
This update for GCC, a widely used compiler, fixes a problem specifically affecting C programs that use 'zero-sized arrays,' which are arrays declared to have no elements. The issue, which cropped up on 32-bit computer systems, was that the compiler was internally representing these arrays in a way that caused errors during compilation. This fix essentially undoes a problematic change that had altered how the compiler internally defines the size and range of arrays. By reverting to the previous, correct method, GCC can now properly handle zero-sized arrays in C, preventing unexpected compilation failures for those types of programs.