diff options
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 5 | ||||
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 13 |
2 files changed, 13 insertions, 5 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 5463b7b7b05..c6e2c20df7d 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -696,7 +696,10 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) const { // Walk through any array types while we're at it. T = getBaseElementType(arrayType); } - Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); + if (Target.usePreferredTypeAlign()) + Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); + else + Align = std::max(Align, getTypeAlign(T.getTypePtr())); } // Fields can be subject to extra alignment constraints, like if diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index fdcff0a4daf..1435627562f 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -1592,10 +1592,15 @@ CharUnits IntExprEvaluator::GetAlignOfType(QualType T) { // result shall be the alignment of the referenced type." if (const ReferenceType *Ref = T->getAs<ReferenceType>()) T = Ref->getPointeeType(); - - // __alignof is defined to return the preferred alignment. - return Info.Ctx.toCharUnitsFromBits( - Info.Ctx.getPreferredTypeAlign(T.getTypePtr())); + + // __alignof defaults to returning the preferred alignment, but + // can be overridden by the specific target. + if (Info.Ctx.Target.usePreferredTypeAlign()) + return Info.Ctx.toCharUnitsFromBits( + Info.Ctx.getPreferredTypeAlign(T.getTypePtr())); + else + return Info.Ctx.toCharUnitsFromBits( + Info.Ctx.getTypeAlign(T.getTypePtr())); } CharUnits IntExprEvaluator::GetAlignOfExpr(const Expr *E) { |