[cfe-dev] clang forcing 8-bytes alignment preference for 64-bit type. Why?

Eric Christopher echristo at gmail.com
Mon Apr 22 16:16:57 PDT 2013

On Mon, Apr 22, 2013 at 5:16 PM, Bob Wilson <bob.wilson at apple.com> wrote:
> On Apr 21, 2013, at 10:45 AM, Francois Pichet <pichet2000 at gmail.com> wrote:
>> From ASTContext.cpp
>> unsigned ASTContext::getPreferredTypeAlign(const Type *T) const {
>>   unsigned ABIAlign = getTypeAlign(T);
>>   // Double and long long should be naturally aligned if possible.
>>   if (const ComplexType* CT = T->getAs<ComplexType>())
>>     T = CT->getElementType().getTypePtr();
>>   if (T->isSpecificBuiltinType(BuiltinType::Double) ||
>>       T->isSpecificBuiltinType(BuiltinType::LongLong) ||
>>       T->isSpecificBuiltinType(BuiltinType::ULongLong))
>>     return std::max(ABIAlign, (unsigned)getTypeSize(T));
>>   return ABIAlign;
>> }
>> Why is it necessary for clang to force 8-byte alignment for 8-byte type?
>> That information can already be specified in TargetInfo if the architecture requires such alignment preference.
>> I am asking because I am working on a CPU where 8-byte alignment for 64-bit type is not required (4-bytes is just as fine).
>> I would like to remove that special case forcing for 64-bit type in ASTContext::getPreferredTypeAlign.
>> Any objection?
> Yes, I object, at least until you can make a convincing argument that this is completely safe and won't penalize other targets.  Did you at least look back through the history of that code to see who added it and why?  Setting the alignment in the TargetInfo does not cover all the cases that getPreferredTypeAlign() is used for.

Agreed, though the preferred type alignment should probably be CPU+OS
specific and set there with whatever we'd like to default to in


More information about the cfe-dev mailing list