[PATCH] fix struct alignment problem with empty base class

Andrea_DiBiagio at sn.scee.net Andrea_DiBiagio at sn.scee.net
Fri Jul 12 06:46:20 PDT 2013


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.

See example below:

/////////////
struct A {
  // no fields
} __attribute__ ((aligned(16)));

struct B : public A {
};
/////////////

The alignment of B is wrongly set to 1 while the alignment of A is 
correctly 
set to 16. According to gcc, the alignment of B should be 16.

The problem is in method RecordLayoutBuilder::LayoutBase() (file 
"lib/AST/RecordLayoutBuilder.cpp"), which forgets to update field 
`Alignment' with the alignment information associated to the empty base 
class in the case where base is placed at relative offset 0.

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).

Thanks,
Andrea Di Biagio
SN Systems - Sony Computer Entertainment Group



**********************************************************************
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
If you have received this email in error please notify postmaster at scee.net
This footnote also confirms that this email message has been checked for 
all known viruses.
Sony Computer Entertainment Europe Limited
Registered Office: 10 Great Marlborough Street, London W1F 7LP, United 
Kingdom
Registered in England: 3277793
**********************************************************************

P Please consider the environment before printing this e-mail
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-alignof.diff
Type: application/octet-stream
Size: 2490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130712/0c1b08c9/attachment.obj>


More information about the cfe-commits mailing list