From 9fd8b6856867c2dfdfd308816af0fe4f23e3c358 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Tue, 13 May 2008 23:18:27 +0000 Subject: Add codegen support for block-level compound literals. llvm-svn: 51081 --- clang/lib/CodeGen/CGExpr.cpp | 20 ++++++++++++++++++++ clang/lib/CodeGen/CGExprScalar.cpp | 5 +---- clang/lib/CodeGen/CodeGenFunction.h | 2 ++ 3 files changed, 23 insertions(+), 4 deletions(-) (limited to 'clang/lib/CodeGen') diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index addd9393485..d6791074c7d 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -106,6 +106,8 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) { case Expr::ExtVectorElementExprClass: return EmitExtVectorElementExpr(cast(E)); case Expr::MemberExprClass: return EmitMemberExpr(cast(E)); + case Expr::CompoundLiteralExprClass: + return EmitCompoundLiteralLValue(cast(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/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index a501145a495..4fb69d045e3 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/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/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index f067a0e2250..0693781bce8 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/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); -- cgit v1.2.3