https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63645
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |jsm28 at gcc dot gnu.org --- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Pedantically speaking, the testcase is invalid I think, in C writing one union member invalidates all the other union members. But as a GNU extension, we allow more relaxed handling of unions, type punning through unions etc., and regarding the sizes of the objects, I believe we do allow having size of just one of the union members for the whole object, what else are union tree_node in tree-core.h or struct rtx_def's union u in rtl.h in GCC sources? So, just by quickly saying what the testcase does is invalid even under extensions I believe most of the GCC codebase would be similarly invalid, don't we use heavily if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t)) and similar? TREE_CODE being t->base.code and DECL_HARD_REGISTER t->decl_with_vis.hard_register ? Here for many trees, the allocated size of them is smaller than offsetof of the decl_with_vis.hard_register field, the reason why we never hit this problem is just that sizeof (tree_base) is 8, and thus the fold_truth_andor_1 optimization doesn't consider if (a->fld1 == N && a->fld2 == M) to be adjacent tnough to optimize. I believe this is the fold_truth_andor_1 optimization at work, the question is how we'd want to change that optimization. I'd say giving up immediately if you access different union members would be too pessimistic, so perhaps just bail out if the size of the first union member is smaller than the offset of the second access + access size?