aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-05-13 23:18:27 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-05-13 23:18:27 +0000
commit06e863f2902b8ba55b056308875c19f7ba3dab25 (patch)
tree5d22471220749909a9297f5148aed4dc1bc4a17c
parentc4777f1928913423234d8d534898f22e9792ae52 (diff)
Add codegen support for block-level compound literals.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51081 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExpr.cpp20
-rw-r--r--lib/CodeGen/CGExprScalar.cpp5
-rw-r--r--lib/CodeGen/CodeGenFunction.h2
-rw-r--r--test/CodeGen/compound-literal.c13
4 files changed, 36 insertions, 4 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index addd939348..d6791074c7 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -106,6 +106,8 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
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 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
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
//===--------------------------------------------------------------------===//
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index a501145a49..4fb69d045e 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -129,6 +129,7 @@ public:
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 @@ public:
return V;
}
-
- Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
- return Visit(E->getInitializer());
- }
Value *VisitImplicitCastExpr(const ImplicitCastExpr *E);
Value *VisitCastExpr(const CastExpr *E) {
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index f067a0e225..0693781bce 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -69,6 +69,7 @@ namespace clang {
class ObjCStringLiteral;
class ObjCIvarRefExpr;
class MemberExpr;
+ class CompoundLiteralExpr;
class VarDecl;
class EnumConstantDecl;
@@ -431,6 +432,7 @@ public:
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);
diff --git a/test/CodeGen/compound-literal.c b/test/CodeGen/compound-literal.c
new file mode 100644
index 0000000000..bc185b24dc
--- /dev/null
+++ b/test/CodeGen/compound-literal.c
@@ -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){};
+}