diff mbox

RFA: PATCH to build_array_type_1 for c++/55032 (array template argument)

Message ID 50C0C2AA.9040308@redhat.com
State New
Headers show

Commit Message

Jason Merrill Dec. 6, 2012, 4:07 p.m. UTC
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?

Comments

Paolo Carlini Dec. 6, 2012, 4:16 p.m. UTC | #1
.. looks like the patch fixes c++/55245 too.

Thanks!
Paolo.
Jakub Jelinek Dec. 6, 2012, 4:48 p.m. UTC | #2
On Thu, Dec 06, 2012 at 11:07:06AM -0500, Jason Merrill wrote:
> Tested x86_64-pc-linux-gnu.  OK for 4.7 and 4.8?
> 

> commit 429af9226fcba2450a8fbfcfba85801a38d0d129
> Author: Jason Merrill <jason@redhat.com>
> 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.

If you can't avoid calling build_array_type_1 with incomplete types
initially, this is ok.  Thanks.

	Jakub
diff mbox

Patch

commit 429af9226fcba2450a8fbfcfba85801a38d0d129
Author: Jason Merrill <jason@redhat.com>
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<typename T>
+struct vec3t {
+  T c[3];
+};
+
+typedef vec3t<float> vec3;
+
+class Bounds {
+  public:
+    Bounds(const vec3 bb[2]);
+    void foo(const vec3 & v) { v.c[0]; }
+};
+
+template<typename T>
+void work(T& value);
+
+void foo() {
+  vec3 bb[2];
+  work(bb);
+}