On Mon, Dec 9, 2019 at 1:23 PM Eric Botcazou <ebotca...@adacore.com> wrote: > > Hi, > > this is a regression present on the mainline and 9 branch: the compiler gives > an ICE for the attached Ada testcase on the following assertion: > > if (DECL_P (ref)) > { > /* We shouldn't have true variables here. */ > gcc_assert (TREE_READONLY (ref)); > subst = ref; > } > > in self_referential_size because the size function machinery is invoked again > by the *free_lang_data pass, more precisely from fld_process_array_type: > > if (!existed) > { > array > = build_array_type_1 (t2, TYPE_DOMAIN (t), TYPE_TYPELESS_STORAGE (t), > false, false); > TYPE_CANONICAL (array) = TYPE_CANONICAL (t); > if (!fld->pset.add (array)) > add_tree_to_fld_list (array, fld); > } > > through the call to build_array_type_1, and more precisely through the > recursive call made for computing TYPE_CANONICAL: > > if (TYPE_CANONICAL (t) == t) > { > if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) > || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)) > || in_lto_p) > SET_TYPE_STRUCTURAL_EQUALITY (t); > else if (TYPE_CANONICAL (elt_type) != elt_type > || (index_type && TYPE_CANONICAL (index_type) != index_type)) > TYPE_CANONICAL (t) > = build_array_type_1 (TYPE_CANONICAL (elt_type), > index_type > ? TYPE_CANONICAL (index_type) : NULL_TREE, > typeless_storage, shared, set_canonical); > } > > > That's a bit surprising because t2 is an incomplete type and we have these > lines in build_array_type_1 just before: > > /* If the element type is incomplete at this point we get marked for > structural equality. Do not record these types in the canonical > type hashtable. */ > if (TYPE_STRUCTURAL_EQUALITY_P (t)) > return t; > > so the computation of TYPE_CANONICAL should be skipped. But it turns out that > these lines from 2009 are obsolete because layout_type no longer forces the > TYPE_STRUCTURAL_EQUALITY_P on the array when the element type is incomplete. > > > Since fld_process_array_type overwrites TYPE_CANONICAL just after the call to > build_array_type_1, there is no point for the latter in computing it so the > proposed fix is to add a new SET_CANONICAL parameter to build_array_type_1. > > Tested on x86_64-suse-linux, OK for mainline and 9 branch?
OK. > > 2019-12-09 Eric Botcazou <ebotca...@adacore.com> > > * tree.c (build_array_type_1): Add SET_CANONICAL parameter and compute > TYPE_CANONICAL from the element type only if it is set. Remove > obsolete > lines and adjust recursive call. > (fld_process_array_type): Adjust call to build_array_type_1. > (build_array_type): Likewise. > (build_nonshared_array_type): Likewise. > > > 2019-12-09 Eric Botcazou <ebotca...@adacore.com> > > * gnat.dg/lto23.adb: New test. > > -- > Eric Botcazou