aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-01-03 17:59:57 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2025-01-03 17:59:57 +0100
commit6f444e45d3fd6c45fc34a79ac66bf46c20fd95b1 (patch)
tree7f8cfef370d3616038a78df2bae0868cbc719f0c
parent514577c66b39fc321bec1c957130fbcd66207822 (diff)
downloadgcc-6f444e45d3fd6c45fc34a79ac66bf46c20fd95b1.zip
gcc-6f444e45d3fd6c45fc34a79ac66bf46c20fd95b1.tar.gz
gcc-6f444e45d3fd6c45fc34a79ac66bf46c20fd95b1.tar.bz2
varasm: Fix up array_size_for_constructor RAW_DATA_CST handling once again [PR118275]
As the following testcases show (the latter only if I revert the temporary reversion of the C++ large array speedup), the FEs aren't really consistent in the type of array CONSTRUCTOR_ELTS indexes, it can be bitsizetype, but can be sizetype as well. Given that everything else is able to cope with it just fine, I'm using build_int_cst which also doesn't care what type it is, instead of bitsize_int, which I've used in PR117190 fix (previously it was size_int). 2025-01-03 Jakub Jelinek <jakub@redhat.com> PR c++/118275 * varasm.cc (array_size_for_constructor): Use build_int_cst with TREE_TYPE (index) as first argument, instead of bitsize_int. * g++.dg/cpp/embed-18.C: New test. * g++.dg/ext/flexary41.C: New test.
-rw-r--r--gcc/testsuite/g++.dg/cpp/embed-18.C15
-rw-r--r--gcc/testsuite/g++.dg/ext/flexary41.C24
-rw-r--r--gcc/varasm.cc3
3 files changed, 41 insertions, 1 deletions
diff --git a/gcc/testsuite/g++.dg/cpp/embed-18.C b/gcc/testsuite/g++.dg/cpp/embed-18.C
new file mode 100644
index 0000000..c7ab8dc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/embed-18.C
@@ -0,0 +1,15 @@
+// PR c++/118275
+// { dg-do compile }
+// { dg-options "" }
+
+struct A { int a; char b[]; };
+void bar (A *);
+
+void
+foo ()
+{
+ static struct A a = { .a = 1, .b = {
+#embed __FILE__
+ } };
+ bar (&a);
+}
diff --git a/gcc/testsuite/g++.dg/ext/flexary41.C b/gcc/testsuite/g++.dg/ext/flexary41.C
new file mode 100644
index 0000000..da80ba3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/flexary41.C
@@ -0,0 +1,24 @@
+// PR c++/118275
+// { dg-do compile }
+// { dg-options "" }
+
+struct A { int a; char b[]; };
+void bar (A *);
+
+void
+foo ()
+{
+ static struct A a = { .a = 1, .b = {
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+ } };
+ bar (&a);
+}
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 3538e29..6d93fe9 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -5648,7 +5648,8 @@ array_size_for_constructor (tree val)
index = TREE_OPERAND (index, 1);
if (value && TREE_CODE (value) == RAW_DATA_CST)
index = size_binop (PLUS_EXPR, index,
- bitsize_int (RAW_DATA_LENGTH (value) - 1));
+ build_int_cst (TREE_TYPE (index),
+ RAW_DATA_LENGTH (value) - 1));
if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
max_index = index;
}