[cfe-commits] r46480 - in /cfe/trunk: CodeGen/CGExprConstant.cpp CodeGen/CGExprScalar.cpp test/CodeGen/globalinit.c test/CodeGen/init.c

Anders Carlsson andersca at mac.com
Mon Jan 28 17:15:49 PST 2008


Author: andersca
Date: Mon Jan 28 19:15:48 2008
New Revision: 46480

URL: http://llvm.org/viewvc/llvm-project?rev=46480&view=rev
Log:
Correctly handle scalars in braces.

Added:
    cfe/trunk/test/CodeGen/init.c
Modified:
    cfe/trunk/CodeGen/CGExprConstant.cpp
    cfe/trunk/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGen/globalinit.c

Modified: cfe/trunk/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprConstant.cpp?rev=46480&r1=46479&r2=46480&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/CodeGen/CGExprConstant.cpp Mon Jan 28 19:15:48 2008
@@ -68,26 +68,18 @@
   }
   
   llvm::Constant *VisitInitListExpr(InitListExpr *ILE) {
-    if (ILE->getType()->isVoidType()) {
-      // FIXME: Remove this when sema of initializers is finished (and the code
-      // below).
-      CGM.WarnUnsupported(ILE, "initializer");
-      return 0;
+    const llvm::CompositeType *CType = 
+      dyn_cast<llvm::CompositeType>(ConvertType(ILE->getType()));
+
+    if (!CType) {
+        // We have a scalar in braces. Just use the first element.
+        return Visit(ILE->getInit(0));
     }
-    
-    assert((ILE->getType()->isArrayType() || ILE->getType()->isStructureType() ||
-            ILE->getType()->isVectorType()) &&
-           "Bad type for init list!");
-    CodeGenTypes& Types = CGM.getTypes();
-    
+      
     unsigned NumInitElements = ILE->getNumInits();
     unsigned NumInitableElts = NumInitElements;
-    
-    const llvm::CompositeType *CType = 
-    cast<llvm::CompositeType>(Types.ConvertType(ILE->getType()));
-    assert(CType);
     std::vector<llvm::Constant*> Elts;    
-    
+      
     // Initialising an array requires us to automatically initialise any 
     // elements that have not been initialised explicitly
     const llvm::ArrayType *AType = 0; 

Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=46480&r1=46479&r2=46480&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Mon Jan 28 19:15:48 2008
@@ -130,7 +130,11 @@
     unsigned NumInitElements = E->getNumInits();
     
     const llvm::VectorType *VType = 
-      cast<llvm::VectorType>(ConvertType(E->getType()));
+      dyn_cast<llvm::VectorType>(ConvertType(E->getType()));
+    
+    // We have a scalar in braces. Just use the first element.
+    if (!VType) 
+      return Visit(E->getInit(0));
     
     unsigned NumVectorElements = VType->getNumElements();
     const llvm::Type *ElementType = VType->getElementType();

Modified: cfe/trunk/test/CodeGen/globalinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/globalinit.c?rev=46480&r1=46479&r2=46480&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/globalinit.c (original)
+++ cfe/trunk/test/CodeGen/globalinit.c Mon Jan 28 19:15:48 2008
@@ -32,3 +32,6 @@
   static _Bool booltest3 = 4;
 }
 
+// Braces in a scalar
+int a = { 1 };
+int b = { 1, 2 };

Added: cfe/trunk/test/CodeGen/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/init.c?rev=46480&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/init.c (added)
+++ cfe/trunk/test/CodeGen/init.c Mon Jan 28 19:15:48 2008
@@ -0,0 +1,7 @@
+// RUN: clang -emit-llvm %s
+void f1()
+{
+	// Braces in a scalar
+	int a = { 1 };
+	int b = { 1, 2 };
+}
\ No newline at end of file





More information about the cfe-commits mailing list