aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-11-19 19:14:53 +0100
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-12-13 09:36:03 +0100
commita72d2abbfc10e4d9620b17ffc41bdbcb98bff100 (patch)
tree395d5faa194a1dc9294dba1e71bb3cd463cac6ae /gcc/ada/gcc-interface
parentb1b7e36153bbe8ff695a66950b7f6cbb273a7356 (diff)
downloadgcc-a72d2abbfc10e4d9620b17ffc41bdbcb98bff100.zip
gcc-a72d2abbfc10e4d9620b17ffc41bdbcb98bff100.tar.gz
gcc-a72d2abbfc10e4d9620b17ffc41bdbcb98bff100.tar.bz2
ada: Fix internal error on packed record with 0-size component
The problem is that the order of components listed in a constant CONSTRUCTOR does not match that of the associated record type. gcc/ada/ChangeLog: * gcc-interface/utils2.cc (compare_elmt_bitpos): Deal specially with 0-sized components when the bit position is the same.
Diffstat (limited to 'gcc/ada/gcc-interface')
-rw-r--r--gcc/ada/gcc-interface/utils2.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index 8eebf59..e91f67d 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -2113,7 +2113,23 @@ compare_elmt_bitpos (const void *rt1, const void *rt2)
const int ret
= tree_int_cst_compare (bit_position (field1), bit_position (field2));
- return ret ? ret : (int) (DECL_UID (field1) - DECL_UID (field2));
+ if (ret)
+ return ret;
+
+ /* The bit position can be the same if one of the fields has zero size.
+ In this case, if the other has nonzero size, put the former first to
+ match the layout done by components_to_record. Otherwise, preserve
+ the order of the source code. */
+
+ const bool field1_zero_size = integer_zerop (DECL_SIZE (field1));
+ const bool field2_zero_size = integer_zerop (DECL_SIZE (field2));
+
+ if (field1_zero_size && !field2_zero_size)
+ return -1;
+ else if (!field1_zero_size && field2_zero_size)
+ return 1;
+ else
+ return (int) (DECL_UID (field1) - DECL_UID (field2));
}
/* Return a CONSTRUCTOR of TYPE whose elements are V. */