On Fri, 3 May 2019, Jakub Jelinek wrote: > Hi! > > The following two functions assume that all types (in the latter case only > the TYPE_MAIN_VARIANT of it) have non-NULL TYPE_CANONICAL. That is > generally not something the FEs guarantee, if TYPE_CANONICAL is NULL, that > is TYPE_STRUCTURAL_EQUALITY_P and generally the middle-end either punts on > those, or does use more careful type comparison etc. In the testcase > we have a FUNCTION_TYPE for which TYPE_STRUCTURAL_EQUALITY_P is true and > the C++ FE sets template types where any of the template parameters requires > structural equality also to require structural equality. > > In the following functions, we already have a type (TYPE_MAIN_VARIANT), > using its TYPE_CANONICAL instead when it is NULL means a certain ICE, but I > don't see why we couldn't just use those types. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and > later for 9.2?
OK. Richar. > 2019-05-03 Jakub Jelinek <ja...@redhat.com> > > PR tree-optimization/90303 > * ipa-devirt.c (obj_type_ref_class, get_odr_type): Don't use > TYPE_CANONICAL for TYPE_STRUCTURAL_EQUALITY_P types in !in_lto_p mode. > > * g++.target/i386/pr90303.C: New test. > > --- gcc/ipa-devirt.c.jj 2019-04-15 19:45:28.796340266 +0200 > +++ gcc/ipa-devirt.c 2019-05-02 10:46:03.077896176 +0200 > @@ -2020,7 +2020,7 @@ obj_type_ref_class (const_tree ref) > ref = TREE_VALUE (TYPE_ARG_TYPES (ref)); > gcc_checking_assert (TREE_CODE (ref) == POINTER_TYPE); > tree ret = TREE_TYPE (ref); > - if (!in_lto_p) > + if (!in_lto_p && !TYPE_STRUCTURAL_EQUALITY_P (ret)) > ret = TYPE_CANONICAL (ret); > else > ret = get_odr_type (ret)->type; > @@ -2042,7 +2042,7 @@ get_odr_type (tree type, bool insert) > int base_id = -1; > > type = TYPE_MAIN_VARIANT (type); > - if (!in_lto_p) > + if (!in_lto_p && !TYPE_STRUCTURAL_EQUALITY_P (type)) > type = TYPE_CANONICAL (type); > > gcc_checking_assert (can_be_name_hashed_p (type) > --- gcc/testsuite/g++.target/i386/pr90303.C.jj 2019-05-02 > 10:51:42.208456515 +0200 > +++ gcc/testsuite/g++.target/i386/pr90303.C 2019-05-02 10:52:15.300925960 > +0200 > @@ -0,0 +1,8 @@ > +// PR tree-optimization/90303 > +// { dg-do compile { target ia32 } } > +// { dg-additional-options "-O2" } > + > +struct A { virtual void foo (); }; > +template <class> class B : A {}; > +typedef void (__attribute__((fastcall)) F) (); > +B<F> e; > > Jakub > -- Richard Biener <rguent...@suse.de> SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer, Mary Higgins, Sri Rasiah; HRB 21284 (AG Nürnberg)