------- Comment #5 from dgregor at gcc dot gnu dot org 2007-04-30 15:30 ------- Thanks for tracking this down.
I'm not sure I understand the fix. The comment just above the changes code in build_new_1 reads: We need a copy of the type as build_array_type will return a shared copy of the incomplete array type. Actually, I don't understand why we aren't just calling build_cplus_array_type(type, index) to create full_type. Why do we need a distinct copy of the type, which the comment claims? With the change above, we're not really getting a distinct copy, because type_hash_canon is exactly what build_array_type does to share type nodes. For reference, the following patch fixes the test cases in this PR and doesn't cause any regressions in the test suite. It also sets TYPE_CANONICAL properly, whereas the patch above does not. Index: init.c =================================================================== --- init.c (revision 124119) +++ init.c (working copy) @@ -1636,11 +1636,7 @@ build_new_1 (tree placement, tree type, index = convert (sizetype, nelts); index = size_binop (MINUS_EXPR, index, size_one_node); index = build_index_type (index); - full_type = build_cplus_array_type (type, NULL_TREE); - /* We need a copy of the type as build_array_type will return a shared copy - of the incomplete array type. */ - full_type = build_distinct_type_copy (full_type); - TYPE_DOMAIN (full_type) = index; + full_type = build_cplus_array_type (type, index); } else { -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31724