https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65892
--- Comment #46 from James Kuyper Jr. <jameskuyper at alumni dot caltech.edu> --- (In reply to Andrew Haley from comment #42) ... > 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. ... Speaking from a developer's perspective rather than an implementor's perspective, the implementation already needs to keep track of where the union's completed definition is in scope, because it's only in those locations where it would be permitted to define an object having the union's type. This is just a different use for the same information; it shouldn't require storing any additional information; nor should it require holding on to that information for any longer than is already required. As a matter of efficient implementation, rather than correctness, I think it might be useful to store, for each struct type, a list of the union definitions for which this might be an issue, a list that would not be needed for any other reason. However, most of the time, that list would be empty - only when it's not empty would the compiler need to review that list to determine which other struct types might be permitted to alias this type, to a limited extent. > ... 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. Why not use the actual scope of the completed union declaration, which is what the relevant rule refers to? > So, if any union types with a common initial sequence are declared > anywhere in a program, then their member types alias. As I understand it, the visibility rule was added specifically for the purpose of NOT requiring that the entire program be covered by this exception. Knowledgeable people writing code intended to take advantage of this feature of C are likely to carefully place completed declarations of the union's type so they disable those optimizations only where they need to be disabled, and to minimize the amount of code where this exception would unnecessarily disable useful optimizations.