[cfe-commits] r84833 - in /cfe/trunk: lib/AST/ASTContext.cpp test/Sema/vector-init.c

Chris Lattner sabre at nondot.org
Wed Oct 21 22:17:16 PDT 2009


Author: lattner
Date: Thu Oct 22 00:17:15 2009
New Revision: 84833

URL: http://llvm.org/viewvc/llvm-project?rev=84833&view=rev
Log:
fix PR5265: the size of a float3 should be rounded up to its alignment.  
This ensures that arrays of float3 are correctly padded.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/Sema/vector-init.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=84833&r1=84832&r2=84833&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Oct 22 00:17:15 2009
@@ -582,14 +582,16 @@
   }
   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 @@
     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();

Modified: cfe/trunk/test/Sema/vector-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vector-init.c?rev=84833&r1=84832&r2=84833&view=diff

==============================================================================
--- cfe/trunk/test/Sema/vector-init.c (original)
+++ cfe/trunk/test/Sema/vector-init.c Thu Oct 22 00:17:15 2009
@@ -21,3 +21,10 @@
 __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)];
+





More information about the cfe-commits mailing list