diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-05-13 23:18:27 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-05-13 23:18:27 +0000 |
commit | 9fd8b6856867c2dfdfd308816af0fe4f23e3c358 (patch) | |
tree | 1e1897b5f9f1d5b6ef2208c8fbecee9cc1658768 /clang/lib/CodeGen | |
parent | dd7406e65c9153c4dce5ea8cc70514975eddc45e (diff) | |
download | bcm5719-llvm-9fd8b6856867c2dfdfd308816af0fe4f23e3c358.tar.gz bcm5719-llvm-9fd8b6856867c2dfdfd308816af0fe4f23e3c358.zip |
Add codegen support for block-level compound literals.
llvm-svn: 51081
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 20 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 5 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 2 |
3 files changed, 23 insertions, 4 deletions
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<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/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); |