]> granicus.if.org Git - clang/commitdiff
fix PR5265: the size of a float3 should be rounded up to its alignment.
authorChris Lattner <sabre@nondot.org>
Thu, 22 Oct 2009 05:17:15 +0000 (05:17 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 22 Oct 2009 05:17:15 +0000 (05:17 +0000)
This ensures that arrays of float3 are correctly padded.

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

lib/AST/ASTContext.cpp
test/Sema/vector-init.c

index 442714a5a6491331486a674d07285195eb1f9e36..7d9bc0f47255377982c9e61ff10e2f3d84a2724f 100644 (file)
@@ -582,14 +582,16 @@ ASTContext::getTypeInfo(const Type *T) {
   }
   case Type::ExtVector:
   case Type::Vector: {
-    std::pair<uint64_t, unsigned> EltInfo =
-      getTypeInfo(cast<VectorType>(T)->getElementType());
-    Width = EltInfo.first*cast<VectorType>(T)->getNumElements();
+    const VectorType *VT = cast<VectorType>(T);
+    std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(VT->getElementType());
+    Width = EltInfo.first*VT->getNumElements();
     Align = Width;
     // If the alignment is not a power of 2, round up to the next power of 2.
     // This happens for non-power-of-2 length vectors.
-    // FIXME: this should probably be a target property.
-    Align = 1 << llvm::Log2_32_Ceil(Align);
+    if (VT->getNumElements() & (VT->getNumElements()-1)) {
+      Align = llvm::NextPowerOf2(Align);
+      Width = llvm::RoundUpToAlignment(Width, Align);
+    }
     break;
   }
 
@@ -748,14 +750,13 @@ ASTContext::getTypeInfo(const Type *T) {
     break;
   }
 
-  case Type::SubstTemplateTypeParm: {
+  case Type::SubstTemplateTypeParm:
     return getTypeInfo(cast<SubstTemplateTypeParmType>(T)->
                        getReplacementType().getTypePtr());
-  }
 
-  case Type::Elaborated: {
-    return getTypeInfo(cast<ElaboratedType>(T)->getUnderlyingType().getTypePtr());
-  }
+  case Type::Elaborated:
+    return getTypeInfo(cast<ElaboratedType>(T)->getUnderlyingType()
+                         .getTypePtr());
 
   case Type::Typedef: {
     const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl();
index 6eab32425adf17b5ee6ea16cf82fa2409aac88c5..523d23f32a3304db7052a0f2d36aa7858bd37f2a 100644 (file)
@@ -21,3 +21,10 @@ float4 array3[2] = { {1.0, 2.0, 3.0}, 5.0, 6.0, 7.0, 8.0,
 __attribute__((vector_size(16))) // expected-error {{unsupported type 'float (void)' for vector_size attribute, please use on typedef}}
 float f1(void) {
 }
+
+
+
+// PR5265
+typedef float __attribute__((ext_vector_type (3))) float3;
+int test2[(sizeof(float3) == sizeof(float3)*2-1)];
+