diff options
-rw-r--r-- | include/clang/Basic/TargetInfo.h | 7 | ||||
-rw-r--r-- | lib/AST/ASTContext.cpp | 5 | ||||
-rw-r--r-- | lib/AST/ExprConstant.cpp | 13 | ||||
-rw-r--r-- | lib/Basic/TargetInfo.cpp | 3 | ||||
-rw-r--r-- | lib/Basic/Targets.cpp | 6 | ||||
-rw-r--r-- | test/Sema/align-arm-apcs-gnu.c | 12 |
6 files changed, 39 insertions, 7 deletions
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index e09098ea05..a8d12ce446 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -88,6 +88,7 @@ protected: unsigned HasAlignMac68kSupport : 1; unsigned RealTypeUsesObjCFPRet : 3; + unsigned UsePreferredTypeAlign : 1; // TargetInfo Constructor. Default initializes all fields. TargetInfo(const std::string &T); @@ -272,6 +273,12 @@ public: return HasAlignMac68kSupport; } + /// usePreferredTypeAlign - Check whether this target uses minimum alignment + /// defined by ABI or some other preferred alignment. + bool usePreferredTypeAlign() const { + return UsePreferredTypeAlign; + } + /// getTypeName - Return the user string for the specified integer type enum. /// For example, SignedShort -> "short". static const char *getTypeName(IntType T); diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 5463b7b7b0..c6e2c20df7 100644 --- a/lib/AST/ASTContext.cpp +++ b/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/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index fdcff0a4da..1435627562 100644 --- a/lib/AST/ExprConstant.cpp +++ b/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) { diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 7ea51467c1..c7a87b20eb 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -65,6 +65,9 @@ TargetInfo::TargetInfo(const std::string &T) : Triple(T) { // Default to no types using fpret. RealTypeUsesObjCFPRet = 0; + // Default to using preferred type alignment. + UsePreferredTypeAlign = true; + // Default to using the Itanium ABI. CXXABI = CXXABI_Itanium; diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 3aebc41d71..53f5c0abaf 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -1978,11 +1978,13 @@ public: "v64:32:64-v128:32:128-a0:0:32-n32"); } - // FIXME: Override "preferred align" for double and long long. + // Default to using minimum alignment, not preferred. + UsePreferredTypeAlign = false; } else if (Name == "aapcs") { // FIXME: Enumerated types are variable width in straight AAPCS. + } else if (Name == "aapcs-linux") { - ; + } else return false; diff --git a/test/Sema/align-arm-apcs-gnu.c b/test/Sema/align-arm-apcs-gnu.c index a1a0f0e013..575cf72bd4 100644 --- a/test/Sema/align-arm-apcs-gnu.c +++ b/test/Sema/align-arm-apcs-gnu.c @@ -2,3 +2,15 @@ struct s0 { double f0; int f1; }; char chk0[__alignof__(struct s0) == 4 ? 1 : -1]; + +double g1; +short chk1[__alignof__(g1) == 4 ? 1 : -1]; +short chk2[__alignof__(double) == 4 ? 1 : -1]; + +long long g2; +short chk1[__alignof__(g2) == 4 ? 1 : -1]; +short chk2[__alignof__(long long) == 4 ? 1 : -1]; + +_Complex double g3; +short chk1[__alignof__(g3) == 4 ? 1 : -1]; +short chk2[__alignof__(_Complex double) == 4 ? 1 : -1]; |