From f59e129c3b842a376ffe5f3e2bfd8814b70feed2 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Fri, 16 Dec 2011 22:34:14 +0000 Subject: [PATCH] Add the value of "suitably aligned" from the C++11 standard to Basic/TargetInfo. This is equal to alignof(std::max_align_t) on the platform and equal to the alignment provided by malloc. (Platform owners please double-check your platform's value.) llvm-svn: 146762 --- clang/include/clang/Basic/TargetInfo.h | 5 +++++ clang/lib/Basic/TargetInfo.cpp | 1 + clang/lib/Basic/Targets.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 39d4fe9c0219..e9b9d14daf6b 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -76,6 +76,7 @@ protected: unsigned char LargeArrayMinWidth, LargeArrayAlign; unsigned char LongWidth, LongAlign; unsigned char LongLongWidth, LongLongAlign; + unsigned char SuitableAlign; unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth; const char *DescriptionString; const char *UserLabelPrefix; @@ -212,6 +213,10 @@ public: unsigned getLongLongWidth() const { return LongLongWidth; } unsigned getLongLongAlign() const { return LongLongAlign; } + /// getSuitableAlign - Return the alignment that is suitable for storing any + /// object with a fundamental alignment requirement. + unsigned getSuitableAlign() const { return SuitableAlign; } + /// getWCharWidth/Align - Return the size of 'wchar_t' for this target, in /// bits. unsigned getWCharWidth() const { return getTypeWidth(WCharType); } diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 694121545ad3..66274f11fc14 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -34,6 +34,7 @@ TargetInfo::TargetInfo(const std::string &T) : Triple(T) { IntWidth = IntAlign = 32; LongWidth = LongAlign = 32; LongLongWidth = LongLongAlign = 64; + SuitableAlign = 64; HalfWidth = 16; HalfAlign = 16; FloatWidth = 32; diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 1cb20dc97774..6c38408c752b 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -2049,6 +2049,7 @@ public: DoubleAlign = LongLongAlign = 32; LongDoubleWidth = 96; LongDoubleAlign = 32; + SuitableAlign = 32; DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" "a0:0:64-f80:32:32-n8:16:32-S128"; @@ -2098,6 +2099,7 @@ public: DarwinTargetInfo(triple) { LongDoubleWidth = 128; LongDoubleAlign = 128; + SuitableAlign = 128; SizeType = UnsignedLong; IntPtrType = SignedLong; DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" @@ -2290,6 +2292,7 @@ public: LongDoubleAlign = 128; LargeArrayMinWidth = 128; LargeArrayAlign = 128; + SuitableAlign = 128; IntMaxType = SignedLong; UIntMaxType = UnsignedLong; Int64Type = SignedLong; @@ -2498,7 +2501,7 @@ public: // FIXME: We need support for -meabi... we could just mangle it into the // name. if (Name == "apcs-gnu") { - DoubleAlign = LongLongAlign = LongDoubleAlign = 32; + DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 32; SizeType = UnsignedLong; // Revert to using SignedInt on apcs-gnu to comply with existing behaviour. @@ -3087,6 +3090,7 @@ namespace { LongWidth = 32; LongLongWidth = 64; LongAlign = LongLongAlign = 16; PointerWidth = 16; PointerAlign = 16; + SuitableAlign = 16; SizeType = UnsignedInt; IntMaxType = SignedLong; UIntMaxType = UnsignedLong; @@ -3168,6 +3172,7 @@ namespace { IntAlign = 32; LongAlign = LongLongAlign = 32; PointerAlign = 32; + SuitableAlign = 32; SizeType = UnsignedInt; IntMaxType = SignedLong; UIntMaxType = UnsignedLong; @@ -3397,6 +3402,7 @@ public: PointerWidth = PointerAlign = 64; LongDoubleWidth = LongDoubleAlign = 128; LongDoubleFormat = &llvm::APFloat::IEEEquad; + SuitableAlign = 128; } virtual bool setABI(const std::string &Name) { SetDescriptionString(Name);