CGDecl.cpp revision 89c49f09b0292dc7c03885f6c765d667a9837597
1//===--- CGDecl.cpp - Emit LLVM Code for declarations ---------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This contains code to emit Decl nodes as LLVM code. 11// 12//===----------------------------------------------------------------------===// 13 14#include "CGDebugInfo.h" 15#include "CodeGenFunction.h" 16#include "CodeGenModule.h" 17#include "clang/AST/ASTContext.h" 18#include "clang/AST/Decl.h" 19#include "clang/AST/DeclObjC.h" 20#include "clang/Basic/SourceManager.h" 21#include "clang/Basic/TargetInfo.h" 22#include "clang/Frontend/CompileOptions.h" 23#include "llvm/GlobalVariable.h" 24#include "llvm/Intrinsics.h" 25#include "llvm/Target/TargetData.h" 26#include "llvm/Type.h" 27using namespace clang; 28using namespace CodeGen; 29 30 31void CodeGenFunction::EmitDecl(const Decl &D) { 32 switch (D.getKind()) { 33 default: assert(0 && "Unknown decl kind!"); 34 case Decl::ParmVar: 35 assert(0 && "Parmdecls should not be in declstmts!"); 36 case Decl::Function: // void X(); 37 case Decl::Record: // struct/union/class X; 38 case Decl::Enum: // enum X; 39 case Decl::EnumConstant: // enum ? { X = ? } 40 case Decl::CXXRecord: // struct/union/class X; [C++] 41 case Decl::UsingDirective: // using X; [C++] 42 // None of these decls require codegen support. 43 return; 44 45 case Decl::Var: { 46 const VarDecl &VD = cast<VarDecl>(D); 47 assert(VD.isBlockVarDecl() && 48 "Should not see file-scope variables inside a function!"); 49 return EmitBlockVarDecl(VD); 50 } 51 52 case Decl::Typedef: { // typedef int X; 53 const TypedefDecl &TD = cast<TypedefDecl>(D); 54 QualType Ty = TD.getUnderlyingType(); 55 56 if (Ty->isVariablyModifiedType()) 57 EmitVLASize(Ty); 58 } 59 } 60} 61 62/// EmitBlockVarDecl - This method handles emission of any variable declaration 63/// inside a function, including static vars etc. 64void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) { 65 if (D.hasAttr<AsmLabelAttr>()) 66 CGM.ErrorUnsupported(&D, "__asm__"); 67 68 switch (D.getStorageClass()) { 69 case VarDecl::None: 70 case VarDecl::Auto: 71 case VarDecl::Register: 72 return EmitLocalBlockVarDecl(D); 73 case VarDecl::Static: 74 return EmitStaticBlockVarDecl(D); 75 case VarDecl::Extern: 76 case VarDecl::PrivateExtern: 77 // Don't emit it now, allow it to be emitted lazily on its first use. 78 return; 79 } 80 81 assert(0 && "Unknown storage class"); 82} 83 84llvm::GlobalVariable * 85CodeGenFunction::CreateStaticBlockVarDecl(const VarDecl &D, 86 const char *Separator, 87 llvm::GlobalValue::LinkageTypes 88 Linkage) { 89 QualType Ty = D.getType(); 90 assert(Ty->isConstantSizeType() && "VLAs can't be static"); 91 92 std::string Name; 93 if (getContext().getLangOptions().CPlusPlus) { 94 Name = CGM.getMangledName(&D); 95 } else { 96 std::string ContextName; 97 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl)) 98 ContextName = CGM.getMangledName(FD); 99 else if (isa<ObjCMethodDecl>(CurFuncDecl)) 100 ContextName = CurFn->getName(); 101 else 102 assert(0 && "Unknown context for block var decl"); 103 104 Name = ContextName + Separator + D.getNameAsString(); 105 } 106 107 const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty); 108 llvm::GlobalVariable *GV = 109 new llvm::GlobalVariable(CGM.getModule(), LTy, 110 Ty.isConstant(getContext()), Linkage, 111 CGM.EmitNullConstant(D.getType()), Name, 0, 112 D.isThreadSpecified(), Ty.getAddressSpace()); 113 GV->setAlignment(getContext().getDeclAlignInBytes(&D)); 114 return GV; 115} 116 117void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) { 118 llvm::Value *&DMEntry = LocalDeclMap[&D]; 119 assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); 120 121 llvm::GlobalVariable *GV = 122 CreateStaticBlockVarDecl(D, ".", llvm::GlobalValue::InternalLinkage); 123 124 // Store into LocalDeclMap before generating initializer to handle 125 // circular references. 126 DMEntry = GV; 127 128 // Make sure to evaluate VLA bounds now so that we have them for later. 129 // 130 // FIXME: Can this happen? 131 if (D.getType()->isVariablyModifiedType()) 132 EmitVLASize(D.getType()); 133 134 if (D.getInit()) { 135 llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), D.getType(), this); 136 137 // If constant emission failed, then this should be a C++ static 138 // initializer. 139 if (!Init) { 140 if (!getContext().getLangOptions().CPlusPlus) 141 CGM.ErrorUnsupported(D.getInit(), "constant l-value expression"); 142 else 143 EmitStaticCXXBlockVarDeclInit(D, GV); 144 } else { 145 // The initializer may differ in type from the global. Rewrite 146 // the global to match the initializer. (We have to do this 147 // because some types, like unions, can't be completely represented 148 // in the LLVM type system.) 149 if (GV->getType() != Init->getType()) { 150 llvm::GlobalVariable *OldGV = GV; 151 152 GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), 153 OldGV->isConstant(), 154 OldGV->getLinkage(), Init, "", 155 0, D.isThreadSpecified(), 156 D.getType().getAddressSpace()); 157 158 // Steal the name of the old global 159 GV->takeName(OldGV); 160 161 // Replace all uses of the old global with the new global 162 llvm::Constant *NewPtrForOldDecl = 163 llvm::ConstantExpr::getBitCast(GV, OldGV->getType()); 164 OldGV->replaceAllUsesWith(NewPtrForOldDecl); 165 166 // Erase the old global, since it is no longer used. 167 OldGV->eraseFromParent(); 168 } 169 170 GV->setInitializer(Init); 171 } 172 } 173 174 // FIXME: Merge attribute handling. 175 if (const AnnotateAttr *AA = D.getAttr<AnnotateAttr>()) { 176 SourceManager &SM = CGM.getContext().getSourceManager(); 177 llvm::Constant *Ann = 178 CGM.EmitAnnotateAttr(GV, AA, 179 SM.getInstantiationLineNumber(D.getLocation())); 180 CGM.AddAnnotation(Ann); 181 } 182 183 if (const SectionAttr *SA = D.getAttr<SectionAttr>()) 184 GV->setSection(SA->getName()); 185 186 if (D.hasAttr<UsedAttr>()) 187 CGM.AddUsedGlobal(GV); 188 189 // We may have to cast the constant because of the initializer 190 // mismatch above. 191 // 192 // FIXME: It is really dangerous to store this in the map; if anyone 193 // RAUW's the GV uses of this constant will be invalid. 194 const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType()); 195 const llvm::Type *LPtrTy = 196 llvm::PointerType::get(LTy, D.getType().getAddressSpace()); 197 DMEntry = llvm::ConstantExpr::getBitCast(GV, LPtrTy); 198 199 // Emit global variable debug descriptor for static vars. 200 CGDebugInfo *DI = getDebugInfo(); 201 if (DI) { 202 DI->setLocation(D.getLocation()); 203 DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(GV), &D); 204 } 205} 206 207unsigned CodeGenFunction::getByRefValueLLVMField(const ValueDecl *VD) const { 208 assert(ByRefValueInfo.count(VD) && "Did not find value!"); 209 210 return ByRefValueInfo.find(VD)->second.second; 211} 212 213/// BuildByRefType - This routine changes a __block variable declared as T x 214/// into: 215/// 216/// struct { 217/// void *__isa; 218/// void *__forwarding; 219/// int32_t __flags; 220/// int32_t __size; 221/// void *__copy_helper; // only if needed 222/// void *__destroy_helper; // only if needed 223/// char padding[X]; // only if needed 224/// T x; 225/// } x 226/// 227const llvm::Type *CodeGenFunction::BuildByRefType(const ValueDecl *D) { 228 std::pair<const llvm::Type *, unsigned> &Info = ByRefValueInfo[D]; 229 if (Info.first) 230 return Info.first; 231 232 QualType Ty = D->getType(); 233 234 std::vector<const llvm::Type *> Types; 235 236 const llvm::PointerType *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext); 237 238 llvm::PATypeHolder ByRefTypeHolder = llvm::OpaqueType::get(VMContext); 239 240 // void *__isa; 241 Types.push_back(Int8PtrTy); 242 243 // void *__forwarding; 244 Types.push_back(llvm::PointerType::getUnqual(ByRefTypeHolder)); 245 246 // int32_t __flags; 247 Types.push_back(llvm::Type::getInt32Ty(VMContext)); 248 249 // int32_t __size; 250 Types.push_back(llvm::Type::getInt32Ty(VMContext)); 251 252 bool HasCopyAndDispose = BlockRequiresCopying(Ty); 253 if (HasCopyAndDispose) { 254 /// void *__copy_helper; 255 Types.push_back(Int8PtrTy); 256 257 /// void *__destroy_helper; 258 Types.push_back(Int8PtrTy); 259 } 260 261 bool Packed = false; 262 unsigned Align = getContext().getDeclAlignInBytes(D); 263 if (Align > Target.getPointerAlign(0) / 8) { 264 // We have to insert padding. 265 266 // The struct above has 2 32-bit integers. 267 unsigned CurrentOffsetInBytes = 4 * 2; 268 269 // And either 2 or 4 pointers. 270 CurrentOffsetInBytes += (HasCopyAndDispose ? 4 : 2) * 271 CGM.getTargetData().getTypeAllocSize(Int8PtrTy); 272 273 // Align the offset. 274 unsigned AlignedOffsetInBytes = 275 llvm::RoundUpToAlignment(CurrentOffsetInBytes, Align); 276 277 unsigned NumPaddingBytes = AlignedOffsetInBytes - CurrentOffsetInBytes; 278 if (NumPaddingBytes > 0) { 279 const llvm::Type *Ty = llvm::Type::getInt8Ty(VMContext); 280 // FIXME: We need a sema error for alignment larger than the minimum of 281 // the maximal stack alignmint and the alignment of malloc on the system. 282 if (NumPaddingBytes > 1) 283 Ty = llvm::ArrayType::get(Ty, NumPaddingBytes); 284 285 Types.push_back(Ty); 286 287 // We want a packed struct. 288 Packed = true; 289 } 290 } 291 292 // T x; 293 Types.push_back(ConvertType(Ty)); 294 295 const llvm::Type *T = llvm::StructType::get(VMContext, Types, Packed); 296 297 cast<llvm::OpaqueType>(ByRefTypeHolder.get())->refineAbstractTypeTo(T); 298 CGM.getModule().addTypeName("struct.__block_byref_" + D->getNameAsString(), 299 ByRefTypeHolder.get()); 300 301 Info.first = ByRefTypeHolder.get(); 302 303 Info.second = Types.size() - 1; 304 305 return Info.first; 306} 307 308/// EmitLocalBlockVarDecl - Emit code and set up an entry in LocalDeclMap for a 309/// variable declaration with auto, register, or no storage class specifier. 310/// These turn into simple stack objects, or GlobalValues depending on target. 311void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) { 312 QualType Ty = D.getType(); 313 bool isByRef = D.hasAttr<BlocksAttr>(); 314 bool needsDispose = false; 315 unsigned Align = 0; 316 317 llvm::Value *DeclPtr; 318 if (Ty->isConstantSizeType()) { 319 if (!Target.useGlobalsForAutomaticVariables()) { 320 321 // All constant structs and arrays should be global if 322 // their initializer is constant and if the element type is POD. 323 if (CGM.getCompileOpts().MergeAllConstants) { 324 if (Ty.isConstant(getContext()) 325 && (Ty->isArrayType() || Ty->isRecordType()) 326 && (D.getInit() 327 && D.getInit()->isConstantInitializer(getContext())) 328 && Ty->isPODType()) { 329 EmitStaticBlockVarDecl(D); 330 return; 331 } 332 } 333 334 // A normal fixed sized variable becomes an alloca in the entry block. 335 const llvm::Type *LTy = ConvertTypeForMem(Ty); 336 Align = getContext().getDeclAlignInBytes(&D); 337 if (isByRef) 338 LTy = BuildByRefType(&D); 339 llvm::AllocaInst *Alloc = CreateTempAlloca(LTy); 340 Alloc->setName(D.getNameAsString().c_str()); 341 342 if (isByRef) 343 Align = std::max(Align, unsigned(Target.getPointerAlign(0) / 8)); 344 Alloc->setAlignment(Align); 345 DeclPtr = Alloc; 346 } else { 347 // Targets that don't support recursion emit locals as globals. 348 const char *Class = 349 D.getStorageClass() == VarDecl::Register ? ".reg." : ".auto."; 350 DeclPtr = CreateStaticBlockVarDecl(D, Class, 351 llvm::GlobalValue 352 ::InternalLinkage); 353 } 354 355 // FIXME: Can this happen? 356 if (Ty->isVariablyModifiedType()) 357 EmitVLASize(Ty); 358 } else { 359 EnsureInsertPoint(); 360 361 if (!DidCallStackSave) { 362 // Save the stack. 363 const llvm::Type *LTy = llvm::Type::getInt8PtrTy(VMContext); 364 llvm::Value *Stack = CreateTempAlloca(LTy, "saved_stack"); 365 366 llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::stacksave); 367 llvm::Value *V = Builder.CreateCall(F); 368 369 Builder.CreateStore(V, Stack); 370 371 DidCallStackSave = true; 372 373 { 374 // Push a cleanup block and restore the stack there. 375 CleanupScope scope(*this); 376 377 V = Builder.CreateLoad(Stack, "tmp"); 378 llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::stackrestore); 379 Builder.CreateCall(F, V); 380 } 381 } 382 383 // Get the element type. 384 const llvm::Type *LElemTy = ConvertTypeForMem(Ty); 385 const llvm::Type *LElemPtrTy = 386 llvm::PointerType::get(LElemTy, D.getType().getAddressSpace()); 387 388 llvm::Value *VLASize = EmitVLASize(Ty); 389 390 // Downcast the VLA size expression 391 VLASize = Builder.CreateIntCast(VLASize, llvm::Type::getInt32Ty(VMContext), 392 false, "tmp"); 393 394 // Allocate memory for the array. 395 llvm::AllocaInst *VLA = 396 Builder.CreateAlloca(llvm::Type::getInt8Ty(VMContext), VLASize, "vla"); 397 VLA->setAlignment(getContext().getDeclAlignInBytes(&D)); 398 399 DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp"); 400 } 401 402 llvm::Value *&DMEntry = LocalDeclMap[&D]; 403 assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); 404 DMEntry = DeclPtr; 405 406 // Emit debug info for local var declaration. 407 if (CGDebugInfo *DI = getDebugInfo()) { 408 assert(HaveInsertPoint() && "Unexpected unreachable point!"); 409 410 DI->setLocation(D.getLocation()); 411 if (Target.useGlobalsForAutomaticVariables()) { 412 DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(DeclPtr), &D); 413 } else 414 DI->EmitDeclareOfAutoVariable(&D, DeclPtr, Builder); 415 } 416 417 // If this local has an initializer, emit it now. 418 const Expr *Init = D.getInit(); 419 420 // If we are at an unreachable point, we don't need to emit the initializer 421 // unless it contains a label. 422 if (!HaveInsertPoint()) { 423 if (!ContainsLabel(Init)) 424 Init = 0; 425 else 426 EnsureInsertPoint(); 427 } 428 429 if (Init) { 430 llvm::Value *Loc = DeclPtr; 431 if (isByRef) 432 Loc = Builder.CreateStructGEP(DeclPtr, getByRefValueLLVMField(&D), 433 D.getNameAsString()); 434 435 bool isVolatile = (getContext().getCanonicalType(D.getType()) 436 .isVolatileQualified()); 437 if (Ty->isReferenceType()) { 438 RValue RV = EmitReferenceBindingToExpr(Init, Ty, /*IsInitializer=*/true); 439 EmitStoreOfScalar(RV.getScalarVal(), Loc, false, Ty); 440 } else if (!hasAggregateLLVMType(Init->getType())) { 441 llvm::Value *V = EmitScalarExpr(Init); 442 EmitStoreOfScalar(V, Loc, isVolatile, D.getType()); 443 } else if (Init->getType()->isAnyComplexType()) { 444 EmitComplexExprIntoAddr(Init, Loc, isVolatile); 445 } else { 446 EmitAggExpr(Init, Loc, isVolatile); 447 } 448 } 449 450 if (isByRef) { 451 const llvm::PointerType *PtrToInt8Ty = llvm::Type::getInt8PtrTy(VMContext); 452 453 EnsureInsertPoint(); 454 llvm::Value *isa_field = Builder.CreateStructGEP(DeclPtr, 0); 455 llvm::Value *forwarding_field = Builder.CreateStructGEP(DeclPtr, 1); 456 llvm::Value *flags_field = Builder.CreateStructGEP(DeclPtr, 2); 457 llvm::Value *size_field = Builder.CreateStructGEP(DeclPtr, 3); 458 llvm::Value *V; 459 int flag = 0; 460 int flags = 0; 461 462 needsDispose = true; 463 464 if (Ty->isBlockPointerType()) { 465 flag |= BLOCK_FIELD_IS_BLOCK; 466 flags |= BLOCK_HAS_COPY_DISPOSE; 467 } else if (BlockRequiresCopying(Ty)) { 468 flag |= BLOCK_FIELD_IS_OBJECT; 469 flags |= BLOCK_HAS_COPY_DISPOSE; 470 } 471 472 // FIXME: Someone double check this. 473 if (Ty.isObjCGCWeak()) 474 flag |= BLOCK_FIELD_IS_WEAK; 475 476 int isa = 0; 477 if (flag&BLOCK_FIELD_IS_WEAK) 478 isa = 1; 479 V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), isa); 480 V = Builder.CreateIntToPtr(V, PtrToInt8Ty, "isa"); 481 Builder.CreateStore(V, isa_field); 482 483 Builder.CreateStore(DeclPtr, forwarding_field); 484 485 V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), flags); 486 Builder.CreateStore(V, flags_field); 487 488 const llvm::Type *V1; 489 V1 = cast<llvm::PointerType>(DeclPtr->getType())->getElementType(); 490 V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 491 (CGM.getTargetData().getTypeStoreSizeInBits(V1) 492 / 8)); 493 Builder.CreateStore(V, size_field); 494 495 if (flags & BLOCK_HAS_COPY_DISPOSE) { 496 BlockHasCopyDispose = true; 497 llvm::Value *copy_helper = Builder.CreateStructGEP(DeclPtr, 4); 498 Builder.CreateStore(BuildbyrefCopyHelper(DeclPtr->getType(), flag, Align), 499 copy_helper); 500 501 llvm::Value *destroy_helper = Builder.CreateStructGEP(DeclPtr, 5); 502 Builder.CreateStore(BuildbyrefDestroyHelper(DeclPtr->getType(), flag, 503 Align), 504 destroy_helper); 505 } 506 } 507 508 // Handle CXX destruction of variables. 509 QualType DtorTy(Ty); 510 while (const ArrayType *Array = getContext().getAsArrayType(DtorTy)) 511 DtorTy = getContext().getBaseElementType(Array); 512 if (const RecordType *RT = DtorTy->getAs<RecordType>()) 513 if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) { 514 if (!ClassDecl->hasTrivialDestructor()) { 515 const CXXDestructorDecl *D = ClassDecl->getDestructor(getContext()); 516 assert(D && "EmitLocalBlockVarDecl - destructor is nul"); 517 518 if (const ConstantArrayType *Array = 519 getContext().getAsConstantArrayType(Ty)) { 520 CleanupScope Scope(*this); 521 QualType BaseElementTy = getContext().getBaseElementType(Array); 522 const llvm::Type *BasePtr = ConvertType(BaseElementTy); 523 BasePtr = llvm::PointerType::getUnqual(BasePtr); 524 llvm::Value *BaseAddrPtr = 525 Builder.CreateBitCast(DeclPtr, BasePtr); 526 EmitCXXAggrDestructorCall(D, Array, BaseAddrPtr); 527 528 // Make sure to jump to the exit block. 529 EmitBranch(Scope.getCleanupExitBlock()); 530 } else { 531 CleanupScope Scope(*this); 532 EmitCXXDestructorCall(D, Dtor_Complete, DeclPtr); 533 } 534 } 535 } 536 537 // Handle the cleanup attribute 538 if (const CleanupAttr *CA = D.getAttr<CleanupAttr>()) { 539 const FunctionDecl *FD = CA->getFunctionDecl(); 540 541 llvm::Constant* F = CGM.GetAddrOfFunction(FD); 542 assert(F && "Could not find function!"); 543 544 CleanupScope scope(*this); 545 546 const CGFunctionInfo &Info = CGM.getTypes().getFunctionInfo(FD); 547 548 // In some cases, the type of the function argument will be different from 549 // the type of the pointer. An example of this is 550 // void f(void* arg); 551 // __attribute__((cleanup(f))) void *g; 552 // 553 // To fix this we insert a bitcast here. 554 QualType ArgTy = Info.arg_begin()->type; 555 DeclPtr = Builder.CreateBitCast(DeclPtr, ConvertType(ArgTy)); 556 557 CallArgList Args; 558 Args.push_back(std::make_pair(RValue::get(DeclPtr), 559 getContext().getPointerType(D.getType()))); 560 561 EmitCall(Info, F, Args); 562 } 563 564 if (needsDispose && CGM.getLangOptions().getGCMode() != LangOptions::GCOnly) { 565 CleanupScope scope(*this); 566 llvm::Value *V = Builder.CreateStructGEP(DeclPtr, 1, "forwarding"); 567 V = Builder.CreateLoad(V, false); 568 BuildBlockRelease(V); 569 } 570} 571 572/// Emit an alloca (or GlobalValue depending on target) 573/// for the specified parameter and set up LocalDeclMap. 574void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg) { 575 // FIXME: Why isn't ImplicitParamDecl a ParmVarDecl? 576 assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) && 577 "Invalid argument to EmitParmDecl"); 578 QualType Ty = D.getType(); 579 CanQualType CTy = getContext().getCanonicalType(Ty); 580 581 llvm::Value *DeclPtr; 582 if (!Ty->isConstantSizeType()) { 583 // Variable sized values always are passed by-reference. 584 DeclPtr = Arg; 585 } else { 586 // A fixed sized single-value variable becomes an alloca in the entry block. 587 const llvm::Type *LTy = ConvertTypeForMem(Ty); 588 if (LTy->isSingleValueType()) { 589 // TODO: Alignment 590 std::string Name = D.getNameAsString(); 591 Name += ".addr"; 592 DeclPtr = CreateTempAlloca(LTy); 593 DeclPtr->setName(Name.c_str()); 594 595 // Store the initial value into the alloca. 596 EmitStoreOfScalar(Arg, DeclPtr, CTy.isVolatileQualified(), Ty); 597 } else { 598 // Otherwise, if this is an aggregate, just use the input pointer. 599 DeclPtr = Arg; 600 } 601 Arg->setName(D.getNameAsString()); 602 } 603 604 llvm::Value *&DMEntry = LocalDeclMap[&D]; 605 assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); 606 DMEntry = DeclPtr; 607 608 // Emit debug info for param declaration. 609 if (CGDebugInfo *DI = getDebugInfo()) { 610 DI->setLocation(D.getLocation()); 611 DI->EmitDeclareOfArgVariable(&D, DeclPtr, Builder); 612 } 613} 614 615