[cfe-commits] r135940 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/AST/ASTContext.cpp lib/AST/ExprConstant.cpp lib/Basic/TargetInfo.cpp lib/Basic/Targets.cpp test/Sema/align-arm-apcs-gnu.c
Chad Rosier
mcrosier at apple.com
Mon Jul 25 12:39:39 PDT 2011
Author: mcrosier
Date: Mon Jul 25 14:39:39 2011
New Revision: 135940
URL: http://llvm.org/viewvc/llvm-project?rev=135940&view=rev
Log:
Allow target to specify about using minimum alignment vs preferred. Takes care of
FIXME: Override "preferred align" for double and long long for ARM apcs-gnu ABI.
Also part of rdar://9802874
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/Sema/align-arm-apcs-gnu.c
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=135940&r1=135939&r2=135940&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Mon Jul 25 14:39:39 2011
@@ -88,6 +88,7 @@
unsigned HasAlignMac68kSupport : 1;
unsigned RealTypeUsesObjCFPRet : 3;
+ unsigned UsePreferredTypeAlign : 1;
// TargetInfo Constructor. Default initializes all fields.
TargetInfo(const std::string &T);
@@ -272,6 +273,12 @@
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);
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=135940&r1=135939&r2=135940&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Jul 25 14:39:39 2011
@@ -696,7 +696,10 @@
// 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
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=135940&r1=135939&r2=135940&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jul 25 14:39:39 2011
@@ -1592,10 +1592,15 @@
// 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) {
Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=135940&r1=135939&r2=135940&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Mon Jul 25 14:39:39 2011
@@ -65,6 +65,9 @@
// 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;
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=135940&r1=135939&r2=135940&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Mon Jul 25 14:39:39 2011
@@ -1978,11 +1978,13 @@
"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;
Modified: cfe/trunk/test/Sema/align-arm-apcs-gnu.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/align-arm-apcs-gnu.c?rev=135940&r1=135939&r2=135940&view=diff
==============================================================================
--- cfe/trunk/test/Sema/align-arm-apcs-gnu.c (original)
+++ cfe/trunk/test/Sema/align-arm-apcs-gnu.c Mon Jul 25 14:39:39 2011
@@ -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];
More information about the cfe-commits
mailing list