public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-8-branch)] PR c++/92745 - bogus error when initializing array of vectors.
@ 2020-09-17 16:46 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-17 16:46 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:98b9702e3a5e8449a1c4f058fe00e5466f5d47d8
commit 98b9702e3a5e8449a1c4f058fe00e5466f5d47d8
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Dec 20 23:30:04 2019 +0000
PR c++/92745 - bogus error when initializing array of vectors.
In r268428 I changed reshape_init_r in such a way that when it sees
a nested { } in a CONSTRUCTOR with missing braces, it just returns
the initializer:
+ else if (COMPOUND_LITERAL_P (stripped_init)
...
+ ++d->cur;
+ gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
+ return init;
But as this test shows, that's incorrect: if TYPE is an array, we need
to proceed to reshape_init_array_1 which will iterate over the array
initializers:
6006 /* Loop until there are no more initializers. */
6007 for (index = 0;
6008 d->cur != d->end && (!sized_array_p || index <= max_index_cst);
6009 ++index)
6010 {
and update d.cur accordingly. In other words, when reshape_init gets
{{col[0][0], col[1][0], col[2][0], col[3][0]},
{col[0][1], col[1][1], col[2][1], col[3][1]},
{col[0][2], col[1][2], col[2][2], col[3][2]},
{col[0][3], col[1][3], col[2][3], col[3][3]}}
we recurse on the first element:
{col[0][0], col[1][0], col[2][0], col[3][0]}
and we can't just move d.cur to point to
{col[0][1], col[1][1], col[2][1], col[3][1]}
and return; we need to iterate, so that d.cur ends up being properly
updated, and after all initializers have been seen, points to d.end.
Currently we skip the loop, wherefore we hit this:
6502 /* Make sure all the element of the constructor were used. Otherwise,
6503 issue an error about exceeding initializers. */
6504 if (d.cur != d.end)
6505 {
6506 if (complain & tf_error)
6507 error ("too many initializers for %qT", type);
6508 return error_mark_node;
6509 }
gcc/cp/ChangeLog
2020-02-25 Marek Polacek <polacek@redhat.com>
PR c++/92745 - bogus error when initializing array of vectors.
* decl.c (reshape_init_r): For a nested compound literal, do
call reshape_init_{class,array,vector}.
gcc/testsuite/ChangeLog
2020-02-25 Marek Polacek <polacek@redhat.com>
Jakub Jelinek <jakub@redhat.com>
PR c++/92745
* g++.dg/cpp0x/initlist118.C: New test.
* g++.dg/cpp0x/initlist118.C: Add -Wno-psabi -w to dg-options.
Diff:
---
gcc/cp/ChangeLog | 6 ++++++
gcc/cp/decl.c | 15 +++++++--------
gcc/testsuite/ChangeLog | 7 +++++++
gcc/testsuite/g++.dg/cpp0x/initlist118.C | 26 ++++++++++++++++++++++++++
4 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a1fee505da6..b73cc568b63 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-25 Marek Polacek <polacek@redhat.com>
+
+ PR c++/92745 - bogus error when initializing array of vectors.
+ * decl.c (reshape_init_r): For a nested compound literal, do
+ call reshape_init_{class,array,vector}.
+
2020-02-25 Jason Merrill <jason@redhat.com>
PR c++/89917 - ICE with lambda in variadic mem-init.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c55cdbed170..6dc23ec3273 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6162,14 +6162,13 @@ reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p,
by the front end. Here we have e.g. {.__pfn=0B, .__delta=0},
which is missing outermost braces. We should warn below, and
one of the routines below will wrap it in additional { }. */;
- /* For a nested compound literal, there is no need to reshape since
- we called reshape_init in finish_compound_literal, before calling
- digest_init. */
- else if (COMPOUND_LITERAL_P (init)
- /* Similarly, a CONSTRUCTOR of the target's type is a
- previously digested initializer. */
- || same_type_ignoring_top_level_qualifiers_p (type,
- init_type))
+ /* For a nested compound literal, proceed to specialized routines,
+ to handle initialization of arrays and similar. */
+ else if (COMPOUND_LITERAL_P (init))
+ gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (init));
+ /* A CONSTRUCTOR of the target's type is a previously
+ digested initializer. */
+ else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
{
++d->cur;
gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (init));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index beb1092cd87..c893053097f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2020-02-25 Marek Polacek <polacek@redhat.com>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/92745
+ * g++.dg/cpp0x/initlist118.C: New test.
+ * g++.dg/cpp0x/initlist118.C: Add -Wno-psabi -w to dg-options.
+
2020-02-25 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/93908
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist118.C b/gcc/testsuite/g++.dg/cpp0x/initlist118.C
new file mode 100644
index 00000000000..a2267661532
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist118.C
@@ -0,0 +1,26 @@
+// PR c++/92745 - bogus error when initializing array of vectors.
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wno-psabi -w" }
+
+template <typename a, int b> struct c {
+ typedef a d[b];
+};
+
+template <typename a, int b> struct array {
+ typename c<a, b>::d e;
+ a operator[](long);
+};
+
+template<class T>
+using vec4_t __attribute__((vector_size(4*sizeof(T)))) = float;
+
+array<vec4_t<float>, 4>
+transpose(array<vec4_t<float>, 4> col)
+{
+ array<vec4_t<float>, 4>
+ ret{vec4_t<float>{col[0][0], col[1][0], col[2][0], col[3][0]},
+ vec4_t<float>{col[0][1], col[1][1], col[2][1], col[3][1]},
+ vec4_t<float>{col[0][2], col[1][2], col[2][2], col[3][2]},
+ vec4_t<float>{col[0][3], col[1][3], col[2][3], col[3][3]}};
+ return ret;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-17 16:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 16:46 [gcc(refs/vendors/redhat/heads/gcc-8-branch)] PR c++/92745 - bogus error when initializing array of vectors Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).