Chris Lattner | 566b6ce | 2007-08-24 02:22:53 +0000 | [diff] [blame] | 1 | //===--- CGExprAgg.cpp - Emit LLVM Code from Aggregate Expressions --------===// |
Chris Lattner | af6f528 | 2007-08-10 20:13:28 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | af6f528 | 2007-08-10 20:13:28 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code to emit Aggregate Expr nodes as LLVM code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CodeGenFunction.h" |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 15 | #include "CodeGenModule.h" |
| 16 | #include "clang/AST/AST.h" |
| 17 | #include "llvm/Constants.h" |
| 18 | #include "llvm/Function.h" |
Devang Patel | 636c3d0 | 2007-10-26 17:44:44 +0000 | [diff] [blame] | 19 | #include "llvm/GlobalVariable.h" |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Compiler.h" |
Chris Lattner | af6f528 | 2007-08-10 20:13:28 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | using namespace CodeGen; |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 23 | |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 24 | //===----------------------------------------------------------------------===// |
| 25 | // Aggregate Expression Emitter |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
| 28 | namespace { |
| 29 | class VISIBILITY_HIDDEN AggExprEmitter : public StmtVisitor<AggExprEmitter> { |
| 30 | CodeGenFunction &CGF; |
Devang Patel | 50c9034 | 2007-10-09 19:49:58 +0000 | [diff] [blame] | 31 | llvm::LLVMFoldingBuilder &Builder; |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 32 | llvm::Value *DestPtr; |
| 33 | bool VolatileDest; |
| 34 | public: |
| 35 | AggExprEmitter(CodeGenFunction &cgf, llvm::Value *destPtr, bool volatileDest) |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 36 | : CGF(cgf), Builder(CGF.Builder), |
| 37 | DestPtr(destPtr), VolatileDest(volatileDest) { |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Chris Lattner | ee755f9 | 2007-08-21 04:59:27 +0000 | [diff] [blame] | 40 | //===--------------------------------------------------------------------===// |
| 41 | // Utilities |
| 42 | //===--------------------------------------------------------------------===// |
| 43 | |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 44 | /// EmitAggLoadOfLValue - Given an expression with aggregate type that |
| 45 | /// represents a value lvalue, this method emits the address of the lvalue, |
| 46 | /// then loads the result into DestPtr. |
| 47 | void EmitAggLoadOfLValue(const Expr *E); |
| 48 | |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 49 | void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, |
| 50 | QualType EltTy); |
Chris Lattner | ee755f9 | 2007-08-21 04:59:27 +0000 | [diff] [blame] | 51 | |
| 52 | //===--------------------------------------------------------------------===// |
| 53 | // Visitor Methods |
| 54 | //===--------------------------------------------------------------------===// |
| 55 | |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 56 | void VisitStmt(Stmt *S) { |
Chris Lattner | dc4d280 | 2007-12-02 01:49:16 +0000 | [diff] [blame] | 57 | CGF.WarnUnsupported(S, "aggregate expression"); |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 58 | } |
| 59 | void VisitParenExpr(ParenExpr *PE) { Visit(PE->getSubExpr()); } |
| 60 | |
| 61 | // l-values. |
Seo Sanghyeon | 9b73b39 | 2007-12-14 02:04:12 +0000 | [diff] [blame] | 62 | void VisitDeclRefExpr(DeclRefExpr *DRE) { EmitAggLoadOfLValue(DRE); } |
| 63 | void VisitMemberExpr(MemberExpr *ME) { EmitAggLoadOfLValue(ME); } |
| 64 | void VisitUnaryDeref(UnaryOperator *E) { EmitAggLoadOfLValue(E); } |
Seo Sanghyeon | ad6ebd6 | 2007-12-23 03:11:58 +0000 | [diff] [blame] | 65 | void VisitStringLiteral(StringLiteral *E) { EmitAggLoadOfLValue(E); } |
Seo Sanghyeon | 9b73b39 | 2007-12-14 02:04:12 +0000 | [diff] [blame] | 66 | |
| 67 | void VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 68 | EmitAggLoadOfLValue(E); |
| 69 | } |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 70 | |
| 71 | // Operators. |
| 72 | // case Expr::UnaryOperatorClass: |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 73 | // case Expr::CastExprClass: |
Anders Carlsson | e4707ff | 2008-01-14 06:28:57 +0000 | [diff] [blame] | 74 | void VisitImplicitCastExpr(ImplicitCastExpr *E); |
Anders Carlsson | 148fe67 | 2007-10-31 22:04:46 +0000 | [diff] [blame] | 75 | void VisitCallExpr(const CallExpr *E); |
Chris Lattner | b2d963f | 2007-08-31 22:54:14 +0000 | [diff] [blame] | 76 | void VisitStmtExpr(const StmtExpr *E); |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 77 | void VisitBinaryOperator(const BinaryOperator *BO); |
Chris Lattner | 03d6fb9 | 2007-08-21 04:43:17 +0000 | [diff] [blame] | 78 | void VisitBinAssign(const BinaryOperator *E); |
Nate Begeman | 796ef3d | 2008-01-31 05:38:29 +0000 | [diff] [blame] | 79 | void VisitOverloadExpr(const OverloadExpr *E); |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 80 | |
| 81 | |
| 82 | void VisitConditionalOperator(const ConditionalOperator *CO); |
Devang Patel | 636c3d0 | 2007-10-26 17:44:44 +0000 | [diff] [blame] | 83 | void VisitInitListExpr(InitListExpr *E); |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 84 | // case Expr::ChooseExprClass: |
Lauro Ramos Venancio | 305762c | 2008-02-18 22:44:02 +0000 | [diff] [blame] | 85 | |
| 86 | private: |
| 87 | |
Lauro Ramos Venancio | 305762c | 2008-02-18 22:44:02 +0000 | [diff] [blame] | 88 | void EmitNonConstInit(Expr *E, llvm::Value *Dest, const llvm::Type *DestType); |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 89 | }; |
| 90 | } // end anonymous namespace. |
| 91 | |
Chris Lattner | ee755f9 | 2007-08-21 04:59:27 +0000 | [diff] [blame] | 92 | //===----------------------------------------------------------------------===// |
| 93 | // Utilities |
| 94 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 95 | |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 96 | void AggExprEmitter::EmitAggregateCopy(llvm::Value *DestPtr, |
| 97 | llvm::Value *SrcPtr, QualType Ty) { |
| 98 | assert(!Ty->isComplexType() && "Shouldn't happen for complex"); |
| 99 | |
| 100 | // Aggregate assignment turns into llvm.memcpy. |
Christopher Lamb | ddc23f3 | 2007-12-17 01:11:20 +0000 | [diff] [blame] | 101 | const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 102 | if (DestPtr->getType() != BP) |
| 103 | DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp"); |
| 104 | if (SrcPtr->getType() != BP) |
| 105 | SrcPtr = Builder.CreateBitCast(SrcPtr, BP, "tmp"); |
| 106 | |
| 107 | // Get size and alignment info for this aggregate. |
| 108 | std::pair<uint64_t, unsigned> TypeInfo = |
| 109 | CGF.getContext().getTypeInfo(Ty, SourceLocation()); |
| 110 | |
| 111 | // FIXME: Handle variable sized types. |
| 112 | const llvm::Type *IntPtr = llvm::IntegerType::get(CGF.LLVMPointerWidth); |
| 113 | |
| 114 | llvm::Value *MemCpyOps[4] = { |
| 115 | DestPtr, SrcPtr, |
Devang Patel | 636c3d0 | 2007-10-26 17:44:44 +0000 | [diff] [blame] | 116 | // TypeInfo.first describes size in bits. |
| 117 | llvm::ConstantInt::get(IntPtr, TypeInfo.first/8), |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 118 | llvm::ConstantInt::get(llvm::Type::Int32Ty, TypeInfo.second) |
| 119 | }; |
| 120 | |
| 121 | Builder.CreateCall(CGF.CGM.getMemCpyFn(), MemCpyOps, MemCpyOps+4); |
| 122 | } |
| 123 | |
| 124 | |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 125 | /// EmitAggLoadOfLValue - Given an expression with aggregate type that |
| 126 | /// represents a value lvalue, this method emits the address of the lvalue, |
| 127 | /// then loads the result into DestPtr. |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 128 | void AggExprEmitter::EmitAggLoadOfLValue(const Expr *E) { |
| 129 | LValue LV = CGF.EmitLValue(E); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 130 | assert(LV.isSimple() && "Can't have aggregate bitfield, vector, etc"); |
| 131 | llvm::Value *SrcPtr = LV.getAddress(); |
| 132 | |
| 133 | // If the result is ignored, don't copy from the value. |
| 134 | if (DestPtr == 0) |
| 135 | // FIXME: If the source is volatile, we must read from it. |
| 136 | return; |
| 137 | |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 138 | EmitAggregateCopy(DestPtr, SrcPtr, E->getType()); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Chris Lattner | ee755f9 | 2007-08-21 04:59:27 +0000 | [diff] [blame] | 141 | //===----------------------------------------------------------------------===// |
| 142 | // Visitor Methods |
| 143 | //===----------------------------------------------------------------------===// |
| 144 | |
Anders Carlsson | e4707ff | 2008-01-14 06:28:57 +0000 | [diff] [blame] | 145 | void AggExprEmitter::VisitImplicitCastExpr(ImplicitCastExpr *E) |
| 146 | { |
| 147 | QualType STy = E->getSubExpr()->getType().getCanonicalType(); |
| 148 | QualType Ty = E->getType().getCanonicalType(); |
Eli Friedman | ff6e2b7 | 2008-02-11 01:09:17 +0000 | [diff] [blame] | 149 | |
| 150 | assert(CGF.getContext().typesAreCompatible( |
| 151 | STy.getUnqualifiedType(), Ty.getUnqualifiedType()) |
| 152 | && "Implicit cast types must be compatible"); |
Anders Carlsson | e4707ff | 2008-01-14 06:28:57 +0000 | [diff] [blame] | 153 | |
| 154 | Visit(E->getSubExpr()); |
| 155 | } |
| 156 | |
Anders Carlsson | 148fe67 | 2007-10-31 22:04:46 +0000 | [diff] [blame] | 157 | void AggExprEmitter::VisitCallExpr(const CallExpr *E) |
| 158 | { |
| 159 | RValue RV = CGF.EmitCallExpr(E); |
| 160 | assert(RV.isAggregate() && "Return value must be aggregate value!"); |
| 161 | |
| 162 | // If the result is ignored, don't copy from the value. |
| 163 | if (DestPtr == 0) |
| 164 | // FIXME: If the source is volatile, we must read from it. |
| 165 | return; |
| 166 | |
| 167 | EmitAggregateCopy(DestPtr, RV.getAggregateAddr(), E->getType()); |
| 168 | } |
| 169 | |
Nate Begeman | 796ef3d | 2008-01-31 05:38:29 +0000 | [diff] [blame] | 170 | void AggExprEmitter::VisitOverloadExpr(const OverloadExpr *E) |
| 171 | { |
| 172 | RValue RV = CGF.EmitCallExpr(E->getFn(), E->arg_begin(), |
| 173 | E->getNumArgs(CGF.getContext())); |
| 174 | assert(RV.isAggregate() && "Return value must be aggregate value!"); |
| 175 | |
| 176 | // If the result is ignored, don't copy from the value. |
| 177 | if (DestPtr == 0) |
| 178 | // FIXME: If the source is volatile, we must read from it. |
| 179 | return; |
| 180 | |
| 181 | EmitAggregateCopy(DestPtr, RV.getAggregateAddr(), E->getType()); |
| 182 | } |
| 183 | |
Chris Lattner | b2d963f | 2007-08-31 22:54:14 +0000 | [diff] [blame] | 184 | void AggExprEmitter::VisitStmtExpr(const StmtExpr *E) { |
| 185 | CGF.EmitCompoundStmt(*E->getSubStmt(), true, DestPtr, VolatileDest); |
| 186 | } |
| 187 | |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 188 | void AggExprEmitter::VisitBinaryOperator(const BinaryOperator *E) { |
Chris Lattner | dc4d280 | 2007-12-02 01:49:16 +0000 | [diff] [blame] | 189 | CGF.WarnUnsupported(E, "aggregate binary expression"); |
Chris Lattner | ee755f9 | 2007-08-21 04:59:27 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Chris Lattner | 03d6fb9 | 2007-08-21 04:43:17 +0000 | [diff] [blame] | 192 | void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) { |
Eli Friedman | ff6e2b7 | 2008-02-11 01:09:17 +0000 | [diff] [blame] | 193 | // For an assignment to work, the value on the right has |
| 194 | // to be compatible with the value on the left. |
| 195 | assert(CGF.getContext().typesAreCompatible( |
| 196 | E->getLHS()->getType().getUnqualifiedType(), |
| 197 | E->getRHS()->getType().getUnqualifiedType()) |
| 198 | && "Invalid assignment"); |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 199 | LValue LHS = CGF.EmitLValue(E->getLHS()); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 200 | |
| 201 | // Codegen the RHS so that it stores directly into the LHS. |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 202 | CGF.EmitAggExpr(E->getRHS(), LHS.getAddress(), false /*FIXME: VOLATILE LHS*/); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 203 | |
Eli Friedman | ff6e2b7 | 2008-02-11 01:09:17 +0000 | [diff] [blame] | 204 | if (DestPtr == 0) |
| 205 | return; |
| 206 | |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 207 | // If the result of the assignment is used, copy the RHS there also. |
Eli Friedman | ff6e2b7 | 2008-02-11 01:09:17 +0000 | [diff] [blame] | 208 | EmitAggregateCopy(DestPtr, LHS.getAddress(), E->getType()); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 211 | void AggExprEmitter::VisitConditionalOperator(const ConditionalOperator *E) { |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 212 | llvm::BasicBlock *LHSBlock = new llvm::BasicBlock("cond.?"); |
| 213 | llvm::BasicBlock *RHSBlock = new llvm::BasicBlock("cond.:"); |
| 214 | llvm::BasicBlock *ContBlock = new llvm::BasicBlock("cond.cont"); |
| 215 | |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 216 | llvm::Value *Cond = CGF.EvaluateExprAsBool(E->getCond()); |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 217 | Builder.CreateCondBr(Cond, LHSBlock, RHSBlock); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 218 | |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 219 | CGF.EmitBlock(LHSBlock); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 220 | |
| 221 | // Handle the GNU extension for missing LHS. |
| 222 | assert(E->getLHS() && "Must have LHS for aggregate value"); |
| 223 | |
Chris Lattner | c748f27 | 2007-08-21 05:02:10 +0000 | [diff] [blame] | 224 | Visit(E->getLHS()); |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 225 | Builder.CreateBr(ContBlock); |
| 226 | LHSBlock = Builder.GetInsertBlock(); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 227 | |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 228 | CGF.EmitBlock(RHSBlock); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 229 | |
Chris Lattner | c748f27 | 2007-08-21 05:02:10 +0000 | [diff] [blame] | 230 | Visit(E->getRHS()); |
Chris Lattner | bfc0c1a | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 231 | Builder.CreateBr(ContBlock); |
| 232 | RHSBlock = Builder.GetInsertBlock(); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 233 | |
Chris Lattner | 9c03356 | 2007-08-21 04:25:47 +0000 | [diff] [blame] | 234 | CGF.EmitBlock(ContBlock); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 235 | } |
Chris Lattner | ee755f9 | 2007-08-21 04:59:27 +0000 | [diff] [blame] | 236 | |
Lauro Ramos Venancio | 305762c | 2008-02-18 22:44:02 +0000 | [diff] [blame] | 237 | void AggExprEmitter::EmitNonConstInit(Expr *E, llvm::Value *DestPtr, |
| 238 | const llvm::Type *DestType) { |
| 239 | |
| 240 | if (const llvm::ArrayType *AType = dyn_cast<llvm::ArrayType>(DestType)) { |
| 241 | unsigned NumInitElements = 0; |
| 242 | InitListExpr *InitList = NULL; |
| 243 | |
| 244 | if (E) { |
| 245 | InitList = cast<InitListExpr>(E); |
| 246 | NumInitElements = InitList->getNumInits(); |
| 247 | } |
| 248 | |
| 249 | llvm::Value *Idxs[] = { |
| 250 | llvm::Constant::getNullValue(llvm::Type::Int32Ty), |
| 251 | NULL |
| 252 | }; |
| 253 | llvm::Value *NextVal = NULL; |
| 254 | unsigned i; |
| 255 | for (i = 0; i != NumInitElements; ++i) { |
| 256 | Idxs[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i); |
| 257 | NextVal = Builder.CreateGEP(DestPtr, Idxs, Idxs + 2,".array"); |
| 258 | EmitNonConstInit(InitList->getInit(i), NextVal, AType->getElementType()); |
| 259 | } |
| 260 | |
| 261 | // Emit remaining default initializers |
| 262 | unsigned NumArrayElements = AType->getNumElements(); |
| 263 | for (/*Do not initialize i*/; i < NumArrayElements; ++i) { |
| 264 | Idxs[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i); |
| 265 | NextVal = Builder.CreateGEP(DestPtr, Idxs, Idxs + 2,".array"); |
| 266 | EmitNonConstInit(NULL, NextVal, AType->getElementType()); |
| 267 | } |
| 268 | |
| 269 | } else { |
| 270 | llvm::Value *V; |
| 271 | if (E) |
| 272 | V = CGF.EmitScalarExpr(E); |
| 273 | else |
| 274 | V = llvm::Constant::getNullValue(DestType); |
| 275 | Builder.CreateStore(V, DestPtr); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { |
Devang Patel | 636c3d0 | 2007-10-26 17:44:44 +0000 | [diff] [blame] | 280 | |
Lauro Ramos Venancio | 145cd89 | 2008-02-19 19:27:31 +0000 | [diff] [blame^] | 281 | if (E->isConstantExpr(CGF.CGM.getContext(), NULL)) { |
| 282 | llvm::Constant *V = CGF.CGM.EmitConstantExpr(E); |
Devang Patel | 636c3d0 | 2007-10-26 17:44:44 +0000 | [diff] [blame] | 283 | // Create global value to hold this array. |
Lauro Ramos Venancio | 305762c | 2008-02-18 22:44:02 +0000 | [diff] [blame] | 284 | V = new llvm::GlobalVariable(V->getType(), true, |
Devang Patel | 636c3d0 | 2007-10-26 17:44:44 +0000 | [diff] [blame] | 285 | llvm::GlobalValue::InternalLinkage, |
Lauro Ramos Venancio | 305762c | 2008-02-18 22:44:02 +0000 | [diff] [blame] | 286 | V, ".array", |
Devang Patel | 636c3d0 | 2007-10-26 17:44:44 +0000 | [diff] [blame] | 287 | &CGF.CGM.getModule()); |
Lauro Ramos Venancio | 305762c | 2008-02-18 22:44:02 +0000 | [diff] [blame] | 288 | |
Devang Patel | 636c3d0 | 2007-10-26 17:44:44 +0000 | [diff] [blame] | 289 | EmitAggregateCopy(DestPtr, V , E->getType()); |
| 290 | return; |
Lauro Ramos Venancio | 145cd89 | 2008-02-19 19:27:31 +0000 | [diff] [blame^] | 291 | } else { |
| 292 | if (!E->getType()->isArrayType()) { |
| 293 | CGF.WarnUnsupported(E, "aggregate init-list expression"); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | const llvm::PointerType *APType = |
| 298 | cast<llvm::PointerType>(DestPtr->getType()); |
| 299 | const llvm::ArrayType *AType = |
| 300 | cast<llvm::ArrayType>(APType->getElementType()); |
| 301 | |
Lauro Ramos Venancio | 305762c | 2008-02-18 22:44:02 +0000 | [diff] [blame] | 302 | EmitNonConstInit(E, DestPtr, AType); |
Lauro Ramos Venancio | 145cd89 | 2008-02-19 19:27:31 +0000 | [diff] [blame^] | 303 | } |
Devang Patel | 636c3d0 | 2007-10-26 17:44:44 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Chris Lattner | ee755f9 | 2007-08-21 04:59:27 +0000 | [diff] [blame] | 306 | //===----------------------------------------------------------------------===// |
| 307 | // Entry Points into this File |
| 308 | //===----------------------------------------------------------------------===// |
| 309 | |
| 310 | /// EmitAggExpr - Emit the computation of the specified expression of |
| 311 | /// aggregate type. The result is computed into DestPtr. Note that if |
| 312 | /// DestPtr is null, the value of the aggregate expression is not needed. |
| 313 | void CodeGenFunction::EmitAggExpr(const Expr *E, llvm::Value *DestPtr, |
| 314 | bool VolatileDest) { |
| 315 | assert(E && hasAggregateLLVMType(E->getType()) && |
| 316 | "Invalid aggregate expression to emit"); |
| 317 | |
| 318 | AggExprEmitter(*this, DestPtr, VolatileDest).Visit(const_cast<Expr*>(E)); |
| 319 | } |