[cfe-commits] r51081 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprScalar.cpp lib/CodeGen/CodeGenFunction.h test/CodeGen/compound-literal.c

Eli Friedman eli.friedman at gmail.com
Tue May 13 16:18:27 PDT 2008


Author: efriedma
Date: Tue May 13 18:18:27 2008
New Revision: 51081

URL: http://llvm.org/viewvc/llvm-project?rev=51081&view=rev
Log:
Add codegen support for block-level compound literals.


Added:
    cfe/trunk/test/CodeGen/compound-literal.c
Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=51081&r1=51080&r2=51081&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue May 13 18:18:27 2008
@@ -106,6 +106,8 @@
   case Expr::ExtVectorElementExprClass:
     return EmitExtVectorElementExpr(cast<ExtVectorElementExpr>(E));
   case Expr::MemberExprClass: return EmitMemberExpr(cast<MemberExpr>(E));
+  case Expr::CompoundLiteralExprClass:
+    return EmitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E));
   }
 }
 
@@ -563,6 +565,24 @@
                               Field->getType()->isSignedIntegerType());
 }
 
+LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr* E) {
+  const llvm::Type *LTy = ConvertType(E->getType());
+  llvm::Value *DeclPtr = CreateTempAlloca(LTy, ".compoundliteral");
+
+  const Expr* InitExpr = E->getInitializer();
+  LValue Result = LValue::MakeAddr(DeclPtr);
+
+  if (E->getType()->isComplexType()) {
+    EmitComplexExprIntoAddr(InitExpr, DeclPtr, false);
+  } else if (hasAggregateLLVMType(E->getType())) {
+    EmitAnyExpr(InitExpr, DeclPtr, false);
+  } else {
+    EmitStoreThroughLValue(EmitAnyExpr(InitExpr), Result, E->getType());
+  }
+
+  return Result;
+}
+
 //===--------------------------------------------------------------------===//
 //                             Expression Emission
 //===--------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue May 13 18:18:27 2008
@@ -129,6 +129,7 @@
   Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E);
   Value *VisitMemberExpr(Expr *E)           { return EmitLoadOfLValue(E); }
   Value *VisitExtVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); }
+  Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { return EmitLoadOfLValue(E); }
   Value *VisitStringLiteral(Expr *E)  { return EmitLValue(E).getAddress(); }
   Value *VisitPreDefinedExpr(Expr *E) { return EmitLValue(E).getAddress(); }
 
@@ -165,10 +166,6 @@
     
     return V;
   }
-
-  Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
-    return Visit(E->getInitializer());
-  }
   
   Value *VisitImplicitCastExpr(const ImplicitCastExpr *E);
   Value *VisitCastExpr(const CastExpr *E) { 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=51081&r1=51080&r2=51081&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue May 13 18:18:27 2008
@@ -69,6 +69,7 @@
   class ObjCStringLiteral;
   class ObjCIvarRefExpr;
   class MemberExpr;
+  class CompoundLiteralExpr;
 
   class VarDecl;
   class EnumConstantDecl;
@@ -431,6 +432,7 @@
   LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
   LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
   LValue EmitMemberExpr(const MemberExpr *E);
+  LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
 
   LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
                             bool isUnion);

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

==============================================================================
--- cfe/trunk/test/CodeGen/compound-literal.c (added)
+++ cfe/trunk/test/CodeGen/compound-literal.c Tue May 13 18:18:27 2008
@@ -0,0 +1,13 @@
+// RUN: clang < %s -emit-llvm
+
+int* a = &(int){1};
+struct s {int a, b, c;} * b = &(struct s) {1, 2, 3};
+// Not working; complex constants are broken
+// _Complex double * x = &(_Complex double){1.0f};
+
+int xxx() {
+int* a = &(int){1};
+struct s {int a, b, c;} * b = &(struct s) {1, 2, 3};
+_Complex double * x = &(_Complex double){1.0f};
+_Complex double * y = &(_Complex double){};
+}





More information about the cfe-commits mailing list