From patchwork Thu Dec 6 16:07:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: RFA: PATCH to build_array_type_1 for c++/55032 (array template argument) Date: Thu, 06 Dec 2012 06:07:06 -0000 From: Jason Merrill X-Patchwork-Id: 204286 Message-Id: <50C0C2AA.9040308@redhat.com> To: Jakub Jelinek Cc: gcc-patches List In this PR, strip_typedefs rebuilds an array type without any typedefs and then gets confused when the rebuilt type has a different TYPE_ALIGN than the typedef-using type. This happens because the rebuilt type was found in the type_hash_canon hash table, and was originally built before the element type was complete, so the rebuilt type hasn't been laid out yet. Since we already do layout_type in build_array_type_1, it seems appropriate that it should always return a laid out type, so this patch causes us to repeat the layout if we found the type already in the hash table. Tested x86_64-pc-linux-gnu. OK for 4.7 and 4.8? commit 429af9226fcba2450a8fbfcfba85801a38d0d129 Author: Jason Merrill Date: Thu Dec 6 10:21:25 2012 -0500 PR c++/55032 * tree.c (build_array_type_1): Re-layout if we found it in the hash table. diff --git a/gcc/tree.c b/gcc/tree.c index 7cacb2a..429db49 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -7505,7 +7505,12 @@ build_array_type_1 (tree elt_type, tree index_type, bool shared) hashval_t hashcode = iterative_hash_object (TYPE_HASH (elt_type), 0); if (index_type) hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode); + tree old_t = t; t = type_hash_canon (hashcode, t); + if (t != old_t) + /* Lay it out again in case the element type has been completed since + the array was added to the hash table. */ + layout_type (t); } if (TYPE_CANONICAL (t) == t) diff --git a/gcc/testsuite/g++.dg/template/array24.C b/gcc/testsuite/g++.dg/template/array24.C new file mode 100644 index 0000000..07879d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/array24.C @@ -0,0 +1,22 @@ +// PR c++/55032 + +template +struct vec3t { + T c[3]; +}; + +typedef vec3t vec3; + +class Bounds { + public: + Bounds(const vec3 bb[2]); + void foo(const vec3 & v) { v.c[0]; } +}; + +template +void work(T& value); + +void foo() { + vec3 bb[2]; + work(bb); +}