https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65892
--- Comment #42 from Andrew Haley <aph at gcc dot gnu.org> --- On 04/29/2018 05:42 PM, rguenther at suse dot de wrote:> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65892 > > --- Comment #41 from rguenther at suse dot de <rguenther at suse dot de> --- > On April 29, 2018 1:51:58 PM GMT+02:00, "aph at gcc dot gnu.org" > <gcc-bugzi...@gcc.gnu.org> wrote: >> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65892 >> >> --- Comment #40 from Andrew Haley <aph at gcc dot gnu.org> --- >> (In reply to rguent...@suse.de from comment #29) >> >>> Note I repeatedly said this part of the standard is just stupid. It >> makes >>> most if not all type-based alias analysis useless. >> >> I don't think so. It does mean that we'd have to feed all declared >> union types (or, at least the ones containing structs with common >> initial sequences) into the alias oracle. While unpleasant, in that >> simply declaring a type without even declaring an object of that type >> changes code generation, it doesn't render all type-based alias >> analysis useless. > > How do you handle this within the LTO framework? In order to use type-based alias analysis in any LTO framework it's necessary to save type information, and this is just more type information. The question is, I suppose, how to handle the scopes of union declarations. I'd just treat them as being global, which in practice isn't unrealistic because such declarations are in header files in global scope and shared anyway. So, if any union types with a common initial sequence are declared anywhere in a program, then their member types alias. Alternatively, a tighter implementation might restrict such declarations to a compilation unit, in which case the alias oracle would scan only the union types declared in that unit. >>> Which means I'll refuse any patches implementing it in a way that >>> affects default behavior. >> >> Maybe --pedantic or even --pedantic-aliasing? > > Whatever you call it I doubt any working solution will fit nicely > into our existing TBAA framework. Well, perhaps not, but this is the language specification. > When I read the language text then a union declaration in between > two accesses will change the semantic of the second? Not necessarily. It would be correct to collect all union declarations at the end of parsing and then use those to feed the alias oracle. There's no actual need to restrict their scope. Sure, it would lead to GCC being somewhat over-cautious, but that's OK.