diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/AST/ASTContext.h | 4 | ||||
| -rw-r--r-- | clang/include/clang/Basic/TargetInfo.h | 7 | ||||
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Basic/TargetInfo.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Basic/Targets.cpp | 1 | ||||
| -rw-r--r-- | clang/test/Sema/struct-packed-align.c | 7 | ||||
| -rw-r--r-- | clang/utils/TableGen/ClangAttrEmitter.cpp | 9 |
7 files changed, 29 insertions, 7 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 48e3451f257..b6f8c735cc8 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1691,6 +1691,10 @@ public: /// beneficial for performance to overalign a data type. unsigned getPreferredTypeAlign(const Type *T) const; + /// \brief Return the default alignment for __attribute__((aligned)) on + /// this target, to be used if no alignment value is specified. + unsigned getTargetDefaultAlignForAttributeAligned(void) const; + /// \brief Return the alignment in bits that should be given to a /// global variable with type \p T. unsigned getAlignOfGlobalVar(QualType T) const; diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 1d6485a56e9..8406205c7fd 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -66,6 +66,7 @@ protected: unsigned char LongWidth, LongAlign; unsigned char LongLongWidth, LongLongAlign; unsigned char SuitableAlign; + unsigned char DefaultAlignForAttributeAligned; unsigned char MinGlobalAlign; unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth; unsigned short MaxVectorAlign; @@ -314,6 +315,12 @@ public: /// object with a fundamental alignment requirement. unsigned getSuitableAlign() const { return SuitableAlign; } + /// \brief Return the default alignment for __attribute__((aligned)) on + /// this target, to be used if no alignment value is specified. + unsigned getDefaultAlignForAttributeAligned() const { + return DefaultAlignForAttributeAligned; + } + /// getMinGlobalAlign - Return the minimum alignment of a global variable, /// unless its alignment is explicitly reduced via attributes. unsigned getMinGlobalAlign() const { return MinGlobalAlign; } diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index c54a006d26a..4d6a51bf192 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1817,6 +1817,13 @@ unsigned ASTContext::getPreferredTypeAlign(const Type *T) const { return ABIAlign; } +/// getTargetDefaultAlignForAttributeAligned - Return the default alignment +/// for __attribute__((aligned)) on this target, to be used if no alignment +/// value is specified. +unsigned ASTContext::getTargetDefaultAlignForAttributeAligned(void) const { + return getTargetInfo().getDefaultAlignForAttributeAligned(); +} + /// getAlignOfGlobalVar - Return the alignment in bits that should be given /// to a global variable of the specified type. unsigned ASTContext::getAlignOfGlobalVar(QualType T) const { diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 871bbd5ef43..330258b025b 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -36,6 +36,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) { LongWidth = LongAlign = 32; LongLongWidth = LongLongAlign = 64; SuitableAlign = 64; + DefaultAlignForAttributeAligned = 128; MinGlobalAlign = 0; HalfWidth = 16; HalfAlign = 16; diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 1f81bcd46d4..047cf0d5b5c 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -5521,6 +5521,7 @@ public: LongDoubleWidth = 128; LongDoubleAlign = 64; LongDoubleFormat = &llvm::APFloat::IEEEquad; + DefaultAlignForAttributeAligned = 64; MinGlobalAlign = 16; DescriptionString = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"; MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; diff --git a/clang/test/Sema/struct-packed-align.c b/clang/test/Sema/struct-packed-align.c index 291de6762cd..417c30308ca 100644 --- a/clang/test/Sema/struct-packed-align.c +++ b/clang/test/Sema/struct-packed-align.c @@ -55,13 +55,16 @@ struct __attribute__((aligned(8))) as1 { extern int e1[sizeof(struct as1) == 8 ? 1 : -1]; extern int e2[__alignof(struct as1) == 8 ? 1 : -1]; -// FIXME: Will need to force arch once max usable alignment isn't hard -// coded. struct __attribute__((aligned)) as1_2 { char c; }; +#ifdef __s390x__ +extern int e1_2[sizeof(struct as1_2) == 8 ? 1 : -1]; +extern int e2_2[__alignof(struct as1_2) == 8 ? 1 : -1]; +#else extern int e1_2[sizeof(struct as1_2) == 16 ? 1 : -1]; extern int e2_2[__alignof(struct as1_2) == 16 ? 1 : -1]; +#endif struct as2 { char c; diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index c1d1a1dbe6d..58857b91a9a 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -413,15 +413,14 @@ namespace { // FIXME: Do not do the calculation here // FIXME: Handle types correctly // A null pointer means maximum alignment - // FIXME: Load the platform-specific maximum alignment, rather than - // 16, the x86 max. OS << "unsigned " << getAttrName() << "Attr::get" << getUpperName() << "(ASTContext &Ctx) const {\n"; OS << " assert(!is" << getUpperName() << "Dependent());\n"; OS << " if (is" << getLowerName() << "Expr)\n"; - OS << " return (" << getLowerName() << "Expr ? " << getLowerName() - << "Expr->EvaluateKnownConstInt(Ctx).getZExtValue() : 16)" - << "* Ctx.getCharWidth();\n"; + OS << " return " << getLowerName() << "Expr ? " << getLowerName() + << "Expr->EvaluateKnownConstInt(Ctx).getZExtValue()" + << " * Ctx.getCharWidth() : " + << "Ctx.getTargetDefaultAlignForAttributeAligned();\n"; OS << " else\n"; OS << " return 0; // FIXME\n"; OS << "}\n"; |

