]> granicus.if.org Git - clang/commitdiff
Extend getPreferredTypeAlign to handle _Complex double and long long
authorEli Friedman <eli.friedman@gmail.com>
Mon, 25 May 2009 21:27:19 +0000 (21:27 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Mon, 25 May 2009 21:27:19 +0000 (21:27 +0000)
correctly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72401 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
test/Sema/align-x86.c

index ccbea263aa5182a5b586c8c9b1f1f1aa135be769..32adf3ae7353fa663357d6abf2e1c1ea1a4c3c72 100644 (file)
@@ -563,11 +563,14 @@ ASTContext::getTypeInfo(const Type *T) {
 /// a data type.
 unsigned ASTContext::getPreferredTypeAlign(const Type *T) {
   unsigned ABIAlign = getTypeAlign(T);
-  
-  // Doubles should be naturally aligned if possible.
-  if (T->isSpecificBuiltinType(BuiltinType::Double))
-    return std::max(ABIAlign, 64U);
-  
+
+  // Double and long long should be naturally aligned if possible.
+  if (const ComplexType* CT = T->getAsComplexType())
+    T = CT->getElementType().getTypePtr();
+  if (T->isSpecificBuiltinType(BuiltinType::Double) ||
+      T->isSpecificBuiltinType(BuiltinType::LongLong))
+    return std::max(ABIAlign, (unsigned)getTypeSize(T));
+
   return ABIAlign;
 }
 
index f6668ddb327ee32cb698a8754ec9991aafdb7f36..2bc1cc848554fcb5d11ec598b4449cdbb8e22268 100644 (file)
@@ -3,4 +3,12 @@
 // PR3433
 double g1;
 short chk1[__alignof__(g1) == 8 ? 1 : -1]; 
-short chk2[__alignof__(double) == 8 ? 1 : -1]; 
+short chk2[__alignof__(double) == 8 ? 1 : -1];
+
+long long g2;
+short chk1[__alignof__(g2) == 8 ? 1 : -1]; 
+short chk2[__alignof__(long long) == 8 ? 1 : -1];
+
+_Complex double g3;
+short chk1[__alignof__(g3) == 8 ? 1 : -1]; 
+short chk2[__alignof__(_Complex double) == 8 ? 1 : -1];