[PATCH] fix struct alignment problem with empty base class

Eli Friedman eli.friedman at gmail.com
Mon Jul 15 17:23:42 PDT 2013


On Mon, Jul 15, 2013 at 5:25 AM,  <Andrea_DiBiagio at sn.scee.net> wrote:
> Hi Eli,
>
>> From: Eli Friedman <eli.friedman at gmail.com>
>> On Fri, Jul 12, 2013 at 6:46 AM,  <Andrea_DiBiagio at sn.scee.net> wrote:
>> > Hi,
>> > attached is a patch to fix an alignment problem affecting classes
> derived
>> > from a base with no fields but with strong alignment constraints.
>> >
>> > Let A be a strongly aligned struct/class with no fields.
>> > Let B be a derived class with A as its direct base class.
>> >
>> > When performing the layout of B, A is correctly placed at offset 0 of
> B.
>> > However, the alignment of B is wrongly left unchanged.
>> >
>> > <snip>
>> >
>> > This patch fixes the problem with the alignment and adds a test case
> to
>> > verify that the alignment info is correctly updated.
>> > One thing to note is that this change may have an effect on binary
>> > compatibility between obj/libs built with and without this change (but
>> > only in the - hopefully rare - case described above).
>>
>> Index: test/CodeGenCXX/alignof.cpp
>> ===================================================================
>> --- test/CodeGenCXX/alignof.cpp (revision 0)
>> +++ test/CodeGenCXX/alignof.cpp (revision 0)
>>
>> Please move the test into SemaCXX, and use static_assert to verify the
>> alignment instead of checking the IR.
>
> I moved the test from CodeGenCXX to SemaCXX.
> I renamed the test file into "alignment-of-derived-class.cpp" because I
> noticed that there was already a test called alignof.cpp in SemaCXX  which
> however tested something completely different.
>
>>
>> +    // Remember max struct/class alignment.
>>
>> This comment is useless.
>
> I removed the comment above from the patch.
>
>>
>> Otherwise, looks fine.
>>
>
> Thanks!
> In case, if this new version of the patch is ok, could you please commit
> it for me?

r186370.

-Eli



More information about the cfe-commits mailing list