GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

c++: Don't assume full alignment for possible base subobjects

Fixes alignment issues for virtual bases, preventing runtime faults.

This commit addresses an alignment problem in C++ where virtual bases with stricter alignment requirements than the containing class could lead to misaligned memory accesses. Previously, the compiler assumed full alignment for all subobjects, causing issues like the SLP vectorizer using movaps instructions that would fault. The fix ensures that references to potential base subobjects use the correct, potentially lower, alignment.

In Details

The commit modifies cp-tree.h, class.cc, module.cc, and cp-gimplify.cc to correctly handle alignment for class types that may represent base subobjects, particularly virtual bases with specific alignment needs (Itanium ABI "nvalign"). When CLASSTYPE_ALIGN is less than TYPE_ALIGN, cp_genericize_r now uses a type variant with the base alignment for INDIRECT_REFs that might point to such a subobject, unless resolves_to_fixed_type_p indicates otherwise. Additionally, fixup_type_variants is updated to prevent alignment overwrites from lazily declared member functions.

For Context
alignment
The requirement that data be stored at memory addresses that are multiples of a specific value (e.g., 4-byte alignment for 32-bit integers). Proper alignment is crucial for performance and correctness on many architectures.
virtual base
In C++, a base class that is inherited through multiple paths in a class hierarchy. Virtual inheritance ensures that only one instance of the virtual base subobject exists within the most derived object.
Itanium ABI
The Application Binary Interface standard for the IA-64 architecture, defining conventions for function calls, data types, and object file formats. It specifies details like name mangling and object layout.
nvalign
In the Itanium C++ ABI, the minimum alignment required for a type when it appears as a base subobject, which may be less than the type's fundamental alignment.
SLP vectorizer
Short Loop Vectorizer, a GCC optimization pass that transforms independent scalar operations within a loop into SIMD (Single Instruction, Multiple Data) vector instructions.
movaps
An x86 SSE (Streaming SIMD Extensions) instruction that moves 128 bits (a quadword) of data between XMM registers or between an XMM register and memory. It requires memory operands to be 16-byte aligned.
INDIRECT_REF
A GCC Internal Representation (IR) construct representing an indirect memory reference, such as dereferencing a pointer.
PR103303
A problem report (bug number) in the GCC bug tracking system, indicating a specific issue that has been fixed by this commit.
Filed Under: c++optimizationalignmenti386