https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103303
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Jason Merrill <[email protected]>: https://gcc.gnu.org/g:e3f8eeac3fc7d2c9dc298121126b0a1c17c6b99a commit r17-5231-ge3f8eeac3fc7d2c9dc298121126b0a1c17c6b99a Author: Illia Polishchuk <[email protected]> Date: Thu Oct 15 23:43:24 2026 -0400 c++: Don't assume full alignment for possible base subobjects [PR103303] When a class has a virtual base that needs more alignment than the rest of the class, its alignment as a base (the Itanium ABI "nvalign", CLASSTYPE_ALIGN) is smaller than TYPE_ALIGN. A base subobject of such a class, e.g. a virtual base of a derived class, may therefore be placed at an address that is only aligned to nvalign. But accesses through 'this' or any other pointer to the class were given the full TYPE_ALIGN, so e.g. the SLP vectorizer used movaps to store adjacent members in the base constructor, which faults at runtime. Fix this by giving an INDIRECT_REF of such a class type a variant of the type with the base alignment, unless resolves_to_fixed_type_p indicates it cannot be a base subobject. Also update fixup_type_variants to only propagate alignment when called from finish_struct_bits or trees_in::read_class_def, so that lazily declared member functions do not overwrite variant alignments. PR c++/103303 gcc/cp/ChangeLog: * cp-tree.h (fixup_type_variants): Add update_align parameter. * class.cc (fixup_type_variants): Only update alignment if update_align is true. (finish_struct_bits): Pass update_align = true. * module.cc (trees_in::read_class_def): Likewise. * cp-gimplify.cc (cp_genericize_r) <case INDIRECT_REF>: Use the alignment of the class as a base for references to a class that might be a base subobject. gcc/testsuite/ChangeLog: * g++.dg/torture/pr103303.C: New test. * g++.target/i386/pr103303.C: New test. Signed-off-by: Illia Polishchuk <[email protected]>
