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

Bob Wilson bob.wilson at apple.com
Mon Apr 22 09:16:07 PDT 2013


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.



More information about the cfe-dev mailing list