CGDecl.cpp revision 545d996ec5a3113f046944f11b27cc2d6cb055b4
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/CharUnits.h" 19#include "clang/AST/Decl.h" 20#include "clang/AST/DeclObjC.h" 21#include "clang/Basic/SourceManager.h" 22#include "clang/Basic/TargetInfo.h" 23#include "clang/Frontend/CodeGenOptions.h" 24#include "llvm/GlobalVariable.h" 25#include "llvm/Intrinsics.h" 26#include "llvm/Target/TargetData.h" 27#include "llvm/Type.h" 28using namespace clang; 29using namespace CodeGen; 30 31 32void CodeGenFunction::EmitDecl(const Decl &D) { 33 switch (D.getKind()) { 34 case Decl::TranslationUnit: 35 case Decl::Namespace: 36 case Decl::UnresolvedUsingTypename: 37 case Decl::ClassTemplateSpecialization: 38 case Decl::ClassTemplatePartialSpecialization: 39 case Decl::TemplateTypeParm: 40 case Decl::UnresolvedUsingValue: 41 case Decl::NonTypeTemplateParm: 42 case Decl::CXXMethod: 43 case Decl::CXXConstructor: 44 case Decl::CXXDestructor: 45 case Decl::CXXConversion: 46 case Decl::Field: 47 case Decl::IndirectField: 48 case Decl::ObjCIvar: 49 case Decl::ObjCAtDefsField: 50 case Decl::ParmVar: 51 case Decl::ImplicitParam: 52 case Decl::ClassTemplate: 53 case Decl::FunctionTemplate: 54 case Decl::TypeAliasTemplate: 55 case Decl::TemplateTemplateParm: 56 case Decl::ObjCMethod: 57 case Decl::ObjCCategory: 58 case Decl::ObjCProtocol: 59 case Decl::ObjCInterface: 60 case Decl::ObjCCategoryImpl: 61 case Decl::ObjCImplementation: 62 case Decl::ObjCProperty: 63 case Decl::ObjCCompatibleAlias: 64 case Decl::AccessSpec: 65 case Decl::LinkageSpec: 66 case Decl::ObjCPropertyImpl: 67 case Decl::ObjCClass: 68 case Decl::ObjCForwardProtocol: 69 case Decl::FileScopeAsm: 70 case Decl::Friend: 71 case Decl::FriendTemplate: 72 case Decl::Block: 73 assert(0 && "Declaration should not be in declstmts!"); 74 case Decl::Function: // void X(); 75 case Decl::Record: // struct/union/class X; 76 case Decl::Enum: // enum X; 77 case Decl::EnumConstant: // enum ? { X = ? } 78 case Decl::CXXRecord: // struct/union/class X; [C++] 79 case Decl::Using: // using X; [C++] 80 case Decl::UsingShadow: 81 case Decl::UsingDirective: // using namespace X; [C++] 82 case Decl::NamespaceAlias: 83 case Decl::StaticAssert: // static_assert(X, ""); [C++0x] 84 case Decl::Label: // __label__ x; 85 // None of these decls require codegen support. 86 return; 87 88 case Decl::Var: { 89 const VarDecl &VD = cast<VarDecl>(D); 90 assert(VD.isLocalVarDecl() && 91 "Should not see file-scope variables inside a function!"); 92 return EmitVarDecl(VD); 93 } 94 95 case Decl::Typedef: // typedef int X; 96 case Decl::TypeAlias: { // using X = int; [C++0x] 97 const TypedefNameDecl &TD = cast<TypedefNameDecl>(D); 98 QualType Ty = TD.getUnderlyingType(); 99 100 if (Ty->isVariablyModifiedType()) 101 EmitVariablyModifiedType(Ty); 102 } 103 } 104} 105 106/// EmitVarDecl - This method handles emission of any variable declaration 107/// inside a function, including static vars etc. 108void CodeGenFunction::EmitVarDecl(const VarDecl &D) { 109 switch (D.getStorageClass()) { 110 case SC_None: 111 case SC_Auto: 112 case SC_Register: 113 return EmitAutoVarDecl(D); 114 case SC_Static: { 115 llvm::GlobalValue::LinkageTypes Linkage = 116 llvm::GlobalValue::InternalLinkage; 117 118 // If the function definition has some sort of weak linkage, its 119 // static variables should also be weak so that they get properly 120 // uniqued. We can't do this in C, though, because there's no 121 // standard way to agree on which variables are the same (i.e. 122 // there's no mangling). 123 if (getContext().getLangOptions().CPlusPlus) 124 if (llvm::GlobalValue::isWeakForLinker(CurFn->getLinkage())) 125 Linkage = CurFn->getLinkage(); 126 127 return EmitStaticVarDecl(D, Linkage); 128 } 129 case SC_Extern: 130 case SC_PrivateExtern: 131 // Don't emit it now, allow it to be emitted lazily on its first use. 132 return; 133 } 134 135 assert(0 && "Unknown storage class"); 136} 137 138static std::string GetStaticDeclName(CodeGenFunction &CGF, const VarDecl &D, 139 const char *Separator) { 140 CodeGenModule &CGM = CGF.CGM; 141 if (CGF.getContext().getLangOptions().CPlusPlus) { 142 llvm::StringRef Name = CGM.getMangledName(&D); 143 return Name.str(); 144 } 145 146 std::string ContextName; 147 if (!CGF.CurFuncDecl) { 148 // Better be in a block declared in global scope. 149 const NamedDecl *ND = cast<NamedDecl>(&D); 150 const DeclContext *DC = ND->getDeclContext(); 151 if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) { 152 MangleBuffer Name; 153 CGM.getBlockMangledName(GlobalDecl(), Name, BD); 154 ContextName = Name.getString(); 155 } 156 else 157 assert(0 && "Unknown context for block static var decl"); 158 } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CGF.CurFuncDecl)) { 159 llvm::StringRef Name = CGM.getMangledName(FD); 160 ContextName = Name.str(); 161 } else if (isa<ObjCMethodDecl>(CGF.CurFuncDecl)) 162 ContextName = CGF.CurFn->getName(); 163 else 164 assert(0 && "Unknown context for static var decl"); 165 166 return ContextName + Separator + D.getNameAsString(); 167} 168 169llvm::GlobalVariable * 170CodeGenFunction::CreateStaticVarDecl(const VarDecl &D, 171 const char *Separator, 172 llvm::GlobalValue::LinkageTypes Linkage) { 173 QualType Ty = D.getType(); 174 assert(Ty->isConstantSizeType() && "VLAs can't be static"); 175 176 std::string Name = GetStaticDeclName(*this, D, Separator); 177 178 const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty); 179 llvm::GlobalVariable *GV = 180 new llvm::GlobalVariable(CGM.getModule(), LTy, 181 Ty.isConstant(getContext()), Linkage, 182 CGM.EmitNullConstant(D.getType()), Name, 0, 183 D.isThreadSpecified(), 184 CGM.getContext().getTargetAddressSpace(Ty)); 185 GV->setAlignment(getContext().getDeclAlign(&D).getQuantity()); 186 if (Linkage != llvm::GlobalValue::InternalLinkage) 187 GV->setVisibility(CurFn->getVisibility()); 188 return GV; 189} 190 191/// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the 192/// global variable that has already been created for it. If the initializer 193/// has a different type than GV does, this may free GV and return a different 194/// one. Otherwise it just returns GV. 195llvm::GlobalVariable * 196CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D, 197 llvm::GlobalVariable *GV) { 198 llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), D.getType(), this); 199 200 // If constant emission failed, then this should be a C++ static 201 // initializer. 202 if (!Init) { 203 if (!getContext().getLangOptions().CPlusPlus) 204 CGM.ErrorUnsupported(D.getInit(), "constant l-value expression"); 205 else if (Builder.GetInsertBlock()) { 206 // Since we have a static initializer, this global variable can't 207 // be constant. 208 GV->setConstant(false); 209 210 EmitCXXGuardedInit(D, GV); 211 } 212 return GV; 213 } 214 215 // The initializer may differ in type from the global. Rewrite 216 // the global to match the initializer. (We have to do this 217 // because some types, like unions, can't be completely represented 218 // in the LLVM type system.) 219 if (GV->getType()->getElementType() != Init->getType()) { 220 llvm::GlobalVariable *OldGV = GV; 221 222 GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), 223 OldGV->isConstant(), 224 OldGV->getLinkage(), Init, "", 225 /*InsertBefore*/ OldGV, 226 D.isThreadSpecified(), 227 CGM.getContext().getTargetAddressSpace(D.getType())); 228 GV->setVisibility(OldGV->getVisibility()); 229 230 // Steal the name of the old global 231 GV->takeName(OldGV); 232 233 // Replace all uses of the old global with the new global 234 llvm::Constant *NewPtrForOldDecl = 235 llvm::ConstantExpr::getBitCast(GV, OldGV->getType()); 236 OldGV->replaceAllUsesWith(NewPtrForOldDecl); 237 238 // Erase the old global, since it is no longer used. 239 OldGV->eraseFromParent(); 240 } 241 242 GV->setInitializer(Init); 243 return GV; 244} 245 246void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D, 247 llvm::GlobalValue::LinkageTypes Linkage) { 248 llvm::Value *&DMEntry = LocalDeclMap[&D]; 249 assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); 250 251 llvm::GlobalVariable *GV = CreateStaticVarDecl(D, ".", Linkage); 252 253 // Store into LocalDeclMap before generating initializer to handle 254 // circular references. 255 DMEntry = GV; 256 257 // We can't have a VLA here, but we can have a pointer to a VLA, 258 // even though that doesn't really make any sense. 259 // Make sure to evaluate VLA bounds now so that we have them for later. 260 if (D.getType()->isVariablyModifiedType()) 261 EmitVariablyModifiedType(D.getType()); 262 263 // Local static block variables must be treated as globals as they may be 264 // referenced in their RHS initializer block-literal expresion. 265 CGM.setStaticLocalDeclAddress(&D, GV); 266 267 // If this value has an initializer, emit it. 268 if (D.getInit()) 269 GV = AddInitializerToStaticVarDecl(D, GV); 270 271 GV->setAlignment(getContext().getDeclAlign(&D).getQuantity()); 272 273 // FIXME: Merge attribute handling. 274 if (const AnnotateAttr *AA = D.getAttr<AnnotateAttr>()) { 275 SourceManager &SM = CGM.getContext().getSourceManager(); 276 llvm::Constant *Ann = 277 CGM.EmitAnnotateAttr(GV, AA, 278 SM.getInstantiationLineNumber(D.getLocation())); 279 CGM.AddAnnotation(Ann); 280 } 281 282 if (const SectionAttr *SA = D.getAttr<SectionAttr>()) 283 GV->setSection(SA->getName()); 284 285 if (D.hasAttr<UsedAttr>()) 286 CGM.AddUsedGlobal(GV); 287 288 // We may have to cast the constant because of the initializer 289 // mismatch above. 290 // 291 // FIXME: It is really dangerous to store this in the map; if anyone 292 // RAUW's the GV uses of this constant will be invalid. 293 const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType()); 294 const llvm::Type *LPtrTy = 295 LTy->getPointerTo(CGM.getContext().getTargetAddressSpace(D.getType())); 296 DMEntry = llvm::ConstantExpr::getBitCast(GV, LPtrTy); 297 298 // Emit global variable debug descriptor for static vars. 299 CGDebugInfo *DI = getDebugInfo(); 300 if (DI) { 301 DI->setLocation(D.getLocation()); 302 DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(GV), &D); 303 } 304} 305 306namespace { 307 struct CallArrayDtor : EHScopeStack::Cleanup { 308 CallArrayDtor(const CXXDestructorDecl *Dtor, 309 const ConstantArrayType *Type, 310 llvm::Value *Loc) 311 : Dtor(Dtor), Type(Type), Loc(Loc) {} 312 313 const CXXDestructorDecl *Dtor; 314 const ConstantArrayType *Type; 315 llvm::Value *Loc; 316 317 void Emit(CodeGenFunction &CGF, bool IsForEH) { 318 QualType BaseElementTy = CGF.getContext().getBaseElementType(Type); 319 const llvm::Type *BasePtr = CGF.ConvertType(BaseElementTy); 320 BasePtr = llvm::PointerType::getUnqual(BasePtr); 321 llvm::Value *BaseAddrPtr = CGF.Builder.CreateBitCast(Loc, BasePtr); 322 CGF.EmitCXXAggrDestructorCall(Dtor, Type, BaseAddrPtr); 323 } 324 }; 325 326 struct CallVarDtor : EHScopeStack::Cleanup { 327 CallVarDtor(const CXXDestructorDecl *Dtor, 328 llvm::Value *NRVOFlag, 329 llvm::Value *Loc) 330 : Dtor(Dtor), NRVOFlag(NRVOFlag), Loc(Loc) {} 331 332 const CXXDestructorDecl *Dtor; 333 llvm::Value *NRVOFlag; 334 llvm::Value *Loc; 335 336 void Emit(CodeGenFunction &CGF, bool IsForEH) { 337 // Along the exceptions path we always execute the dtor. 338 bool NRVO = !IsForEH && NRVOFlag; 339 340 llvm::BasicBlock *SkipDtorBB = 0; 341 if (NRVO) { 342 // If we exited via NRVO, we skip the destructor call. 343 llvm::BasicBlock *RunDtorBB = CGF.createBasicBlock("nrvo.unused"); 344 SkipDtorBB = CGF.createBasicBlock("nrvo.skipdtor"); 345 llvm::Value *DidNRVO = CGF.Builder.CreateLoad(NRVOFlag, "nrvo.val"); 346 CGF.Builder.CreateCondBr(DidNRVO, SkipDtorBB, RunDtorBB); 347 CGF.EmitBlock(RunDtorBB); 348 } 349 350 CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete, 351 /*ForVirtualBase=*/false, Loc); 352 353 if (NRVO) CGF.EmitBlock(SkipDtorBB); 354 } 355 }; 356 357 struct CallStackRestore : EHScopeStack::Cleanup { 358 llvm::Value *Stack; 359 CallStackRestore(llvm::Value *Stack) : Stack(Stack) {} 360 void Emit(CodeGenFunction &CGF, bool IsForEH) { 361 llvm::Value *V = CGF.Builder.CreateLoad(Stack, "tmp"); 362 llvm::Value *F = CGF.CGM.getIntrinsic(llvm::Intrinsic::stackrestore); 363 CGF.Builder.CreateCall(F, V); 364 } 365 }; 366 367 struct ExtendGCLifetime : EHScopeStack::Cleanup { 368 const VarDecl &Var; 369 ExtendGCLifetime(const VarDecl *var) : Var(*var) {} 370 371 void Emit(CodeGenFunction &CGF, bool forEH) { 372 // Compute the address of the local variable, in case it's a 373 // byref or something. 374 DeclRefExpr DRE(const_cast<VarDecl*>(&Var), Var.getType(), VK_LValue, 375 SourceLocation()); 376 llvm::Value *value = CGF.EmitLoadOfScalar(CGF.EmitDeclRefLValue(&DRE)); 377 CGF.EmitExtendGCLifetime(value); 378 } 379 }; 380 381 struct CallCleanupFunction : EHScopeStack::Cleanup { 382 llvm::Constant *CleanupFn; 383 const CGFunctionInfo &FnInfo; 384 const VarDecl &Var; 385 386 CallCleanupFunction(llvm::Constant *CleanupFn, const CGFunctionInfo *Info, 387 const VarDecl *Var) 388 : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var) {} 389 390 void Emit(CodeGenFunction &CGF, bool IsForEH) { 391 DeclRefExpr DRE(const_cast<VarDecl*>(&Var), Var.getType(), VK_LValue, 392 SourceLocation()); 393 // Compute the address of the local variable, in case it's a byref 394 // or something. 395 llvm::Value *Addr = CGF.EmitDeclRefLValue(&DRE).getAddress(); 396 397 // In some cases, the type of the function argument will be different from 398 // the type of the pointer. An example of this is 399 // void f(void* arg); 400 // __attribute__((cleanup(f))) void *g; 401 // 402 // To fix this we insert a bitcast here. 403 QualType ArgTy = FnInfo.arg_begin()->type; 404 llvm::Value *Arg = 405 CGF.Builder.CreateBitCast(Addr, CGF.ConvertType(ArgTy)); 406 407 CallArgList Args; 408 Args.add(RValue::get(Arg), 409 CGF.getContext().getPointerType(Var.getType())); 410 CGF.EmitCall(FnInfo, CleanupFn, ReturnValueSlot(), Args); 411 } 412 }; 413} 414 415/// EmitAutoVarWithLifetime - Does the setup required for an automatic 416/// variable with lifetime. 417static void EmitAutoVarWithLifetime(CodeGenFunction &CGF, const VarDecl &var, 418 llvm::Value *addr, 419 Qualifiers::ObjCLifetime lifetime) { 420 switch (lifetime) { 421 case Qualifiers::OCL_None: 422 llvm_unreachable("present but none"); 423 424 case Qualifiers::OCL_ExplicitNone: 425 // nothing to do 426 break; 427 428 case Qualifiers::OCL_Strong: { 429 CGF.PushARCReleaseCleanup(CGF.getARCCleanupKind(), 430 var.getType(), addr, 431 var.hasAttr<ObjCPreciseLifetimeAttr>()); 432 break; 433 } 434 case Qualifiers::OCL_Autoreleasing: 435 // nothing to do 436 break; 437 438 case Qualifiers::OCL_Weak: 439 // __weak objects always get EH cleanups; otherwise, exceptions 440 // could cause really nasty crashes instead of mere leaks. 441 CGF.PushARCWeakReleaseCleanup(NormalAndEHCleanup, var.getType(), addr); 442 break; 443 } 444} 445 446static bool isAccessedBy(const VarDecl &var, const Stmt *s) { 447 if (const Expr *e = dyn_cast<Expr>(s)) { 448 // Skip the most common kinds of expressions that make 449 // hierarchy-walking expensive. 450 s = e = e->IgnoreParenCasts(); 451 452 if (const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(e)) 453 return (ref->getDecl() == &var); 454 } 455 456 for (Stmt::const_child_range children = s->children(); children; ++children) 457 if (isAccessedBy(var, *children)) 458 return true; 459 460 return false; 461} 462 463static bool isAccessedBy(const ValueDecl *decl, const Expr *e) { 464 if (!decl) return false; 465 if (!isa<VarDecl>(decl)) return false; 466 const VarDecl *var = cast<VarDecl>(decl); 467 return isAccessedBy(*var, e); 468} 469 470static void drillIntoBlockVariable(CodeGenFunction &CGF, 471 LValue &lvalue, 472 const VarDecl *var) { 473 lvalue.setAddress(CGF.BuildBlockByrefAddress(lvalue.getAddress(), var)); 474} 475 476void CodeGenFunction::EmitScalarInit(const Expr *init, 477 const ValueDecl *D, 478 LValue lvalue, 479 bool capturedByInit) { 480 Qualifiers::ObjCLifetime lifetime = lvalue.getObjCLifetime(); 481 if (!lifetime) { 482 llvm::Value *value = EmitScalarExpr(init); 483 if (capturedByInit) 484 drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D)); 485 EmitStoreThroughLValue(RValue::get(value), lvalue); 486 return; 487 } 488 489 // If we're emitting a value with lifetime, we have to do the 490 // initialization *before* we leave the cleanup scopes. 491 CodeGenFunction::RunCleanupsScope Scope(*this); 492 if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(init)) 493 init = ewc->getSubExpr(); 494 495 // We have to maintain the illusion that the variable is 496 // zero-initialized. If the variable might be accessed in its 497 // initializer, zero-initialize before running the initializer, then 498 // actually perform the initialization with an assign. 499 bool accessedByInit = false; 500 if (lifetime != Qualifiers::OCL_ExplicitNone) 501 accessedByInit = isAccessedBy(D, init); 502 if (accessedByInit) { 503 LValue tempLV = lvalue; 504 // Drill down to the __block object if necessary. 505 if (capturedByInit) { 506 // We can use a simple GEP for this because it can't have been 507 // moved yet. 508 tempLV.setAddress(Builder.CreateStructGEP(tempLV.getAddress(), 509 getByRefValueLLVMField(cast<VarDecl>(D)))); 510 } 511 512 const llvm::PointerType *ty 513 = cast<llvm::PointerType>(tempLV.getAddress()->getType()); 514 ty = cast<llvm::PointerType>(ty->getElementType()); 515 516 llvm::Value *zero = llvm::ConstantPointerNull::get(ty); 517 518 // If __weak, we want to use a barrier under certain conditions. 519 if (lifetime == Qualifiers::OCL_Weak) 520 EmitARCInitWeak(tempLV.getAddress(), zero); 521 522 // Otherwise just do a simple store. 523 else 524 EmitStoreOfScalar(zero, tempLV); 525 } 526 527 // Emit the initializer. 528 llvm::Value *value = 0; 529 530 switch (lifetime) { 531 case Qualifiers::OCL_None: 532 llvm_unreachable("present but none"); 533 534 case Qualifiers::OCL_ExplicitNone: 535 // nothing to do 536 value = EmitScalarExpr(init); 537 break; 538 539 case Qualifiers::OCL_Strong: { 540 value = EmitARCRetainScalarExpr(init); 541 break; 542 } 543 544 case Qualifiers::OCL_Weak: { 545 // No way to optimize a producing initializer into this. It's not 546 // worth optimizing for, because the value will immediately 547 // disappear in the common case. 548 value = EmitScalarExpr(init); 549 550 if (capturedByInit) drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D)); 551 if (accessedByInit) 552 EmitARCStoreWeak(lvalue.getAddress(), value, /*ignored*/ true); 553 else 554 EmitARCInitWeak(lvalue.getAddress(), value); 555 return; 556 } 557 558 case Qualifiers::OCL_Autoreleasing: 559 value = EmitARCRetainAutoreleaseScalarExpr(init); 560 break; 561 } 562 563 if (capturedByInit) drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D)); 564 565 // If the variable might have been accessed by its initializer, we 566 // might have to initialize with a barrier. We have to do this for 567 // both __weak and __strong, but __weak got filtered out above. 568 if (accessedByInit && lifetime == Qualifiers::OCL_Strong) { 569 llvm::Value *oldValue = EmitLoadOfScalar(lvalue); 570 EmitStoreOfScalar(value, lvalue); 571 EmitARCRelease(oldValue, /*precise*/ false); 572 return; 573 } 574 575 EmitStoreOfScalar(value, lvalue); 576} 577 578/// EmitScalarInit - Initialize the given lvalue with the given object. 579void CodeGenFunction::EmitScalarInit(llvm::Value *init, LValue lvalue) { 580 Qualifiers::ObjCLifetime lifetime = lvalue.getObjCLifetime(); 581 if (!lifetime) 582 return EmitStoreThroughLValue(RValue::get(init), lvalue); 583 584 switch (lifetime) { 585 case Qualifiers::OCL_None: 586 llvm_unreachable("present but none"); 587 588 case Qualifiers::OCL_ExplicitNone: 589 // nothing to do 590 break; 591 592 case Qualifiers::OCL_Strong: 593 init = EmitARCRetain(lvalue.getType(), init); 594 break; 595 596 case Qualifiers::OCL_Weak: 597 // Initialize and then skip the primitive store. 598 EmitARCInitWeak(lvalue.getAddress(), init); 599 return; 600 601 case Qualifiers::OCL_Autoreleasing: 602 init = EmitARCRetainAutorelease(lvalue.getType(), init); 603 break; 604 } 605 606 EmitStoreOfScalar(init, lvalue); 607} 608 609/// canEmitInitWithFewStoresAfterMemset - Decide whether we can emit the 610/// non-zero parts of the specified initializer with equal or fewer than 611/// NumStores scalar stores. 612static bool canEmitInitWithFewStoresAfterMemset(llvm::Constant *Init, 613 unsigned &NumStores) { 614 // Zero and Undef never requires any extra stores. 615 if (isa<llvm::ConstantAggregateZero>(Init) || 616 isa<llvm::ConstantPointerNull>(Init) || 617 isa<llvm::UndefValue>(Init)) 618 return true; 619 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) || 620 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) || 621 isa<llvm::ConstantExpr>(Init)) 622 return Init->isNullValue() || NumStores--; 623 624 // See if we can emit each element. 625 if (isa<llvm::ConstantArray>(Init) || isa<llvm::ConstantStruct>(Init)) { 626 for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) { 627 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i)); 628 if (!canEmitInitWithFewStoresAfterMemset(Elt, NumStores)) 629 return false; 630 } 631 return true; 632 } 633 634 // Anything else is hard and scary. 635 return false; 636} 637 638/// emitStoresForInitAfterMemset - For inits that 639/// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar 640/// stores that would be required. 641static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc, 642 bool isVolatile, CGBuilderTy &Builder) { 643 // Zero doesn't require any stores. 644 if (isa<llvm::ConstantAggregateZero>(Init) || 645 isa<llvm::ConstantPointerNull>(Init) || 646 isa<llvm::UndefValue>(Init)) 647 return; 648 649 if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) || 650 isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) || 651 isa<llvm::ConstantExpr>(Init)) { 652 if (!Init->isNullValue()) 653 Builder.CreateStore(Init, Loc, isVolatile); 654 return; 655 } 656 657 assert((isa<llvm::ConstantStruct>(Init) || isa<llvm::ConstantArray>(Init)) && 658 "Unknown value type!"); 659 660 for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) { 661 llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i)); 662 if (Elt->isNullValue()) continue; 663 664 // Otherwise, get a pointer to the element and emit it. 665 emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), 666 isVolatile, Builder); 667 } 668} 669 670 671/// shouldUseMemSetPlusStoresToInitialize - Decide whether we should use memset 672/// plus some stores to initialize a local variable instead of using a memcpy 673/// from a constant global. It is beneficial to use memset if the global is all 674/// zeros, or mostly zeros and large. 675static bool shouldUseMemSetPlusStoresToInitialize(llvm::Constant *Init, 676 uint64_t GlobalSize) { 677 // If a global is all zeros, always use a memset. 678 if (isa<llvm::ConstantAggregateZero>(Init)) return true; 679 680 681 // If a non-zero global is <= 32 bytes, always use a memcpy. If it is large, 682 // do it if it will require 6 or fewer scalar stores. 683 // TODO: Should budget depends on the size? Avoiding a large global warrants 684 // plopping in more stores. 685 unsigned StoreBudget = 6; 686 uint64_t SizeLimit = 32; 687 688 return GlobalSize > SizeLimit && 689 canEmitInitWithFewStoresAfterMemset(Init, StoreBudget); 690} 691 692 693/// EmitAutoVarDecl - Emit code and set up an entry in LocalDeclMap for a 694/// variable declaration with auto, register, or no storage class specifier. 695/// These turn into simple stack objects, or GlobalValues depending on target. 696void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D) { 697 AutoVarEmission emission = EmitAutoVarAlloca(D); 698 EmitAutoVarInit(emission); 699 EmitAutoVarCleanups(emission); 700} 701 702/// EmitAutoVarAlloca - Emit the alloca and debug information for a 703/// local variable. Does not emit initalization or destruction. 704CodeGenFunction::AutoVarEmission 705CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) { 706 QualType Ty = D.getType(); 707 708 AutoVarEmission emission(D); 709 710 bool isByRef = D.hasAttr<BlocksAttr>(); 711 emission.IsByRef = isByRef; 712 713 CharUnits alignment = getContext().getDeclAlign(&D); 714 emission.Alignment = alignment; 715 716 // If the type is variably-modified, emit all the VLA sizes for it. 717 if (Ty->isVariablyModifiedType()) 718 EmitVariablyModifiedType(Ty); 719 720 llvm::Value *DeclPtr; 721 if (Ty->isConstantSizeType()) { 722 if (!Target.useGlobalsForAutomaticVariables()) { 723 bool NRVO = getContext().getLangOptions().ElideConstructors && 724 D.isNRVOVariable(); 725 726 // If this value is a POD array or struct with a statically 727 // determinable constant initializer, there are optimizations we 728 // can do. 729 // TODO: we can potentially constant-evaluate non-POD structs and 730 // arrays as long as the initialization is trivial (e.g. if they 731 // have a non-trivial destructor, but not a non-trivial constructor). 732 if (D.getInit() && 733 (Ty->isArrayType() || Ty->isRecordType()) && 734 (Ty.isPODType(getContext()) || 735 getContext().getBaseElementType(Ty)->isObjCObjectPointerType()) && 736 D.getInit()->isConstantInitializer(getContext(), false)) { 737 738 // If the variable's a const type, and it's neither an NRVO 739 // candidate nor a __block variable, emit it as a global instead. 740 if (CGM.getCodeGenOpts().MergeAllConstants && Ty.isConstQualified() && 741 !NRVO && !isByRef) { 742 EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage); 743 744 emission.Address = 0; // signal this condition to later callbacks 745 assert(emission.wasEmittedAsGlobal()); 746 return emission; 747 } 748 749 // Otherwise, tell the initialization code that we're in this case. 750 emission.IsConstantAggregate = true; 751 } 752 753 // A normal fixed sized variable becomes an alloca in the entry block, 754 // unless it's an NRVO variable. 755 const llvm::Type *LTy = ConvertTypeForMem(Ty); 756 757 if (NRVO) { 758 // The named return value optimization: allocate this variable in the 759 // return slot, so that we can elide the copy when returning this 760 // variable (C++0x [class.copy]p34). 761 DeclPtr = ReturnValue; 762 763 if (const RecordType *RecordTy = Ty->getAs<RecordType>()) { 764 if (!cast<CXXRecordDecl>(RecordTy->getDecl())->hasTrivialDestructor()) { 765 // Create a flag that is used to indicate when the NRVO was applied 766 // to this variable. Set it to zero to indicate that NRVO was not 767 // applied. 768 llvm::Value *Zero = Builder.getFalse(); 769 llvm::Value *NRVOFlag = CreateTempAlloca(Zero->getType(), "nrvo"); 770 EnsureInsertPoint(); 771 Builder.CreateStore(Zero, NRVOFlag); 772 773 // Record the NRVO flag for this variable. 774 NRVOFlags[&D] = NRVOFlag; 775 emission.NRVOFlag = NRVOFlag; 776 } 777 } 778 } else { 779 if (isByRef) 780 LTy = BuildByRefType(&D); 781 782 llvm::AllocaInst *Alloc = CreateTempAlloca(LTy); 783 Alloc->setName(D.getNameAsString()); 784 785 CharUnits allocaAlignment = alignment; 786 if (isByRef) 787 allocaAlignment = std::max(allocaAlignment, 788 getContext().toCharUnitsFromBits(Target.getPointerAlign(0))); 789 Alloc->setAlignment(allocaAlignment.getQuantity()); 790 DeclPtr = Alloc; 791 } 792 } else { 793 // Targets that don't support recursion emit locals as globals. 794 const char *Class = 795 D.getStorageClass() == SC_Register ? ".reg." : ".auto."; 796 DeclPtr = CreateStaticVarDecl(D, Class, 797 llvm::GlobalValue::InternalLinkage); 798 } 799 } else { 800 EnsureInsertPoint(); 801 802 if (!DidCallStackSave) { 803 // Save the stack. 804 llvm::Value *Stack = CreateTempAlloca(Int8PtrTy, "saved_stack"); 805 806 llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::stacksave); 807 llvm::Value *V = Builder.CreateCall(F); 808 809 Builder.CreateStore(V, Stack); 810 811 DidCallStackSave = true; 812 813 // Push a cleanup block and restore the stack there. 814 // FIXME: in general circumstances, this should be an EH cleanup. 815 EHStack.pushCleanup<CallStackRestore>(NormalCleanup, Stack); 816 } 817 818 llvm::Value *elementCount; 819 QualType elementType; 820 llvm::tie(elementCount, elementType) = getVLASize(Ty); 821 822 const llvm::Type *llvmTy = ConvertTypeForMem(elementType); 823 824 // Allocate memory for the array. 825 llvm::AllocaInst *vla = Builder.CreateAlloca(llvmTy, elementCount, "vla"); 826 vla->setAlignment(alignment.getQuantity()); 827 828 DeclPtr = vla; 829 } 830 831 llvm::Value *&DMEntry = LocalDeclMap[&D]; 832 assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); 833 DMEntry = DeclPtr; 834 emission.Address = DeclPtr; 835 836 // Emit debug info for local var declaration. 837 if (HaveInsertPoint()) 838 if (CGDebugInfo *DI = getDebugInfo()) { 839 DI->setLocation(D.getLocation()); 840 if (Target.useGlobalsForAutomaticVariables()) { 841 DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(DeclPtr), &D); 842 } else 843 DI->EmitDeclareOfAutoVariable(&D, DeclPtr, Builder); 844 } 845 846 return emission; 847} 848 849/// Determines whether the given __block variable is potentially 850/// captured by the given expression. 851static bool isCapturedBy(const VarDecl &var, const Expr *e) { 852 // Skip the most common kinds of expressions that make 853 // hierarchy-walking expensive. 854 e = e->IgnoreParenCasts(); 855 856 if (const BlockExpr *be = dyn_cast<BlockExpr>(e)) { 857 const BlockDecl *block = be->getBlockDecl(); 858 for (BlockDecl::capture_const_iterator i = block->capture_begin(), 859 e = block->capture_end(); i != e; ++i) { 860 if (i->getVariable() == &var) 861 return true; 862 } 863 864 // No need to walk into the subexpressions. 865 return false; 866 } 867 868 for (Stmt::const_child_range children = e->children(); children; ++children) 869 if (isCapturedBy(var, cast<Expr>(*children))) 870 return true; 871 872 return false; 873} 874 875void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) { 876 assert(emission.Variable && "emission was not valid!"); 877 878 // If this was emitted as a global constant, we're done. 879 if (emission.wasEmittedAsGlobal()) return; 880 881 const VarDecl &D = *emission.Variable; 882 QualType type = D.getType(); 883 884 // If this local has an initializer, emit it now. 885 const Expr *Init = D.getInit(); 886 887 // If we are at an unreachable point, we don't need to emit the initializer 888 // unless it contains a label. 889 if (!HaveInsertPoint()) { 890 if (!Init || !ContainsLabel(Init)) return; 891 EnsureInsertPoint(); 892 } 893 894 // Initialize the structure of a __block variable. 895 if (emission.IsByRef) 896 emitByrefStructureInit(emission); 897 898 if (!Init) return; 899 900 CharUnits alignment = emission.Alignment; 901 902 // Check whether this is a byref variable that's potentially 903 // captured and moved by its own initializer. If so, we'll need to 904 // emit the initializer first, then copy into the variable. 905 bool capturedByInit = emission.IsByRef && isCapturedBy(D, Init); 906 907 llvm::Value *Loc = 908 capturedByInit ? emission.Address : emission.getObjectAddress(*this); 909 910 if (!emission.IsConstantAggregate) { 911 LValue lv = MakeAddrLValue(Loc, type, alignment.getQuantity()); 912 lv.setNonGC(true); 913 return EmitExprAsInit(Init, &D, lv, capturedByInit); 914 } 915 916 // If this is a simple aggregate initialization, we can optimize it 917 // in various ways. 918 assert(!capturedByInit && "constant init contains a capturing block?"); 919 920 bool isVolatile = type.isVolatileQualified(); 921 922 llvm::Constant *constant = CGM.EmitConstantExpr(D.getInit(), type, this); 923 assert(constant != 0 && "Wasn't a simple constant init?"); 924 925 llvm::Value *SizeVal = 926 llvm::ConstantInt::get(IntPtrTy, 927 getContext().getTypeSizeInChars(type).getQuantity()); 928 929 const llvm::Type *BP = Int8PtrTy; 930 if (Loc->getType() != BP) 931 Loc = Builder.CreateBitCast(Loc, BP, "tmp"); 932 933 // If the initializer is all or mostly zeros, codegen with memset then do 934 // a few stores afterward. 935 if (shouldUseMemSetPlusStoresToInitialize(constant, 936 CGM.getTargetData().getTypeAllocSize(constant->getType()))) { 937 Builder.CreateMemSet(Loc, llvm::ConstantInt::get(Int8Ty, 0), SizeVal, 938 alignment.getQuantity(), isVolatile); 939 if (!constant->isNullValue()) { 940 Loc = Builder.CreateBitCast(Loc, constant->getType()->getPointerTo()); 941 emitStoresForInitAfterMemset(constant, Loc, isVolatile, Builder); 942 } 943 } else { 944 // Otherwise, create a temporary global with the initializer then 945 // memcpy from the global to the alloca. 946 std::string Name = GetStaticDeclName(*this, D, "."); 947 llvm::GlobalVariable *GV = 948 new llvm::GlobalVariable(CGM.getModule(), constant->getType(), true, 949 llvm::GlobalValue::InternalLinkage, 950 constant, Name, 0, false, 0); 951 GV->setAlignment(alignment.getQuantity()); 952 GV->setUnnamedAddr(true); 953 954 llvm::Value *SrcPtr = GV; 955 if (SrcPtr->getType() != BP) 956 SrcPtr = Builder.CreateBitCast(SrcPtr, BP, "tmp"); 957 958 Builder.CreateMemCpy(Loc, SrcPtr, SizeVal, alignment.getQuantity(), 959 isVolatile); 960 } 961} 962 963/// Emit an expression as an initializer for a variable at the given 964/// location. The expression is not necessarily the normal 965/// initializer for the variable, and the address is not necessarily 966/// its normal location. 967/// 968/// \param init the initializing expression 969/// \param var the variable to act as if we're initializing 970/// \param loc the address to initialize; its type is a pointer 971/// to the LLVM mapping of the variable's type 972/// \param alignment the alignment of the address 973/// \param capturedByInit true if the variable is a __block variable 974/// whose address is potentially changed by the initializer 975void CodeGenFunction::EmitExprAsInit(const Expr *init, 976 const ValueDecl *D, 977 LValue lvalue, 978 bool capturedByInit) { 979 QualType type = D->getType(); 980 981 if (type->isReferenceType()) { 982 RValue rvalue = EmitReferenceBindingToExpr(init, D); 983 if (capturedByInit) 984 drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D)); 985 EmitStoreThroughLValue(rvalue, lvalue); 986 } else if (!hasAggregateLLVMType(type)) { 987 EmitScalarInit(init, D, lvalue, capturedByInit); 988 } else if (type->isAnyComplexType()) { 989 ComplexPairTy complex = EmitComplexExpr(init); 990 if (capturedByInit) 991 drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D)); 992 StoreComplexToAddr(complex, lvalue.getAddress(), lvalue.isVolatile()); 993 } else { 994 // TODO: how can we delay here if D is captured by its initializer? 995 EmitAggExpr(init, AggValueSlot::forLValue(lvalue, true, false)); 996 } 997} 998 999void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) { 1000 assert(emission.Variable && "emission was not valid!"); 1001 1002 // If this was emitted as a global constant, we're done. 1003 if (emission.wasEmittedAsGlobal()) return; 1004 1005 const VarDecl &D = *emission.Variable; 1006 1007 // Handle C++ or ARC destruction of variables. 1008 if (getLangOptions().CPlusPlus) { 1009 QualType type = D.getType(); 1010 QualType baseType = getContext().getBaseElementType(type); 1011 if (const RecordType *RT = baseType->getAs<RecordType>()) { 1012 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(RT->getDecl()); 1013 if (!ClassDecl->hasTrivialDestructor()) { 1014 // Note: We suppress the destructor call when the corresponding NRVO 1015 // flag has been set. 1016 1017 // Note that for __block variables, we want to destroy the 1018 // original stack object, not the possible forwarded object. 1019 llvm::Value *Loc = emission.getObjectAddress(*this); 1020 1021 const CXXDestructorDecl *D = ClassDecl->getDestructor(); 1022 assert(D && "EmitLocalBlockVarDecl - destructor is nul"); 1023 1024 if (type != baseType) { 1025 const ConstantArrayType *Array = 1026 getContext().getAsConstantArrayType(type); 1027 assert(Array && "types changed without array?"); 1028 EHStack.pushCleanup<CallArrayDtor>(NormalAndEHCleanup, 1029 D, Array, Loc); 1030 } else { 1031 EHStack.pushCleanup<CallVarDtor>(NormalAndEHCleanup, 1032 D, emission.NRVOFlag, Loc); 1033 } 1034 } 1035 } 1036 } 1037 1038 if (Qualifiers::ObjCLifetime lifetime 1039 = D.getType().getQualifiers().getObjCLifetime()) { 1040 if (!D.isARCPseudoStrong()) { 1041 llvm::Value *loc = emission.getObjectAddress(*this); 1042 EmitAutoVarWithLifetime(*this, D, loc, lifetime); 1043 } 1044 } 1045 1046 // In GC mode, honor objc_precise_lifetime. 1047 if (getLangOptions().getGCMode() != LangOptions::NonGC && 1048 D.hasAttr<ObjCPreciseLifetimeAttr>()) { 1049 EHStack.pushCleanup<ExtendGCLifetime>(NormalCleanup, &D); 1050 } 1051 1052 // Handle the cleanup attribute. 1053 if (const CleanupAttr *CA = D.getAttr<CleanupAttr>()) { 1054 const FunctionDecl *FD = CA->getFunctionDecl(); 1055 1056 llvm::Constant *F = CGM.GetAddrOfFunction(FD); 1057 assert(F && "Could not find function!"); 1058 1059 const CGFunctionInfo &Info = CGM.getTypes().getFunctionInfo(FD); 1060 EHStack.pushCleanup<CallCleanupFunction>(NormalAndEHCleanup, F, &Info, &D); 1061 } 1062 1063 // If this is a block variable, call _Block_object_destroy 1064 // (on the unforwarded address). 1065 if (emission.IsByRef) 1066 enterByrefCleanup(emission); 1067} 1068 1069namespace { 1070 /// A cleanup to perform a release of an object at the end of a 1071 /// function. This is used to balance out the incoming +1 of a 1072 /// ns_consumed argument when we can't reasonably do that just by 1073 /// not doing the initial retain for a __block argument. 1074 struct ConsumeARCParameter : EHScopeStack::Cleanup { 1075 ConsumeARCParameter(llvm::Value *param) : Param(param) {} 1076 1077 llvm::Value *Param; 1078 1079 void Emit(CodeGenFunction &CGF, bool IsForEH) { 1080 CGF.EmitARCRelease(Param, /*precise*/ false); 1081 } 1082 }; 1083} 1084 1085/// Emit an alloca (or GlobalValue depending on target) 1086/// for the specified parameter and set up LocalDeclMap. 1087void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg, 1088 unsigned ArgNo) { 1089 // FIXME: Why isn't ImplicitParamDecl a ParmVarDecl? 1090 assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) && 1091 "Invalid argument to EmitParmDecl"); 1092 1093 Arg->setName(D.getName()); 1094 1095 // Use better IR generation for certain implicit parameters. 1096 if (isa<ImplicitParamDecl>(D)) { 1097 // The only implicit argument a block has is its literal. 1098 if (BlockInfo) { 1099 LocalDeclMap[&D] = Arg; 1100 1101 if (CGDebugInfo *DI = getDebugInfo()) { 1102 DI->setLocation(D.getLocation()); 1103 DI->EmitDeclareOfBlockLiteralArgVariable(*BlockInfo, Arg, Builder); 1104 } 1105 1106 return; 1107 } 1108 } 1109 1110 QualType Ty = D.getType(); 1111 1112 llvm::Value *DeclPtr; 1113 // If this is an aggregate or variable sized value, reuse the input pointer. 1114 if (!Ty->isConstantSizeType() || 1115 CodeGenFunction::hasAggregateLLVMType(Ty)) { 1116 DeclPtr = Arg; 1117 } else { 1118 // Otherwise, create a temporary to hold the value. 1119 DeclPtr = CreateMemTemp(Ty, D.getName() + ".addr"); 1120 1121 bool doStore = true; 1122 1123 Qualifiers qs = Ty.getQualifiers(); 1124 1125 if (Qualifiers::ObjCLifetime lt = qs.getObjCLifetime()) { 1126 // We honor __attribute__((ns_consumed)) for types with lifetime. 1127 // For __strong, it's handled by just skipping the initial retain; 1128 // otherwise we have to balance out the initial +1 with an extra 1129 // cleanup to do the release at the end of the function. 1130 bool isConsumed = D.hasAttr<NSConsumedAttr>(); 1131 1132 // 'self' is always formally __strong, but if this is not an 1133 // init method then we don't want to retain it. 1134 if (D.isARCPseudoStrong()) { 1135 const ObjCMethodDecl *method = cast<ObjCMethodDecl>(CurCodeDecl); 1136 assert(&D == method->getSelfDecl()); 1137 assert(lt == Qualifiers::OCL_Strong); 1138 assert(qs.hasConst()); 1139 assert(method->getMethodFamily() != OMF_init); 1140 (void) method; 1141 lt = Qualifiers::OCL_ExplicitNone; 1142 } 1143 1144 if (lt == Qualifiers::OCL_Strong) { 1145 if (!isConsumed) 1146 // Don't use objc_retainBlock for block pointers, because we 1147 // don't want to Block_copy something just because we got it 1148 // as a parameter. 1149 Arg = EmitARCRetainNonBlock(Arg); 1150 } else { 1151 // Push the cleanup for a consumed parameter. 1152 if (isConsumed) 1153 EHStack.pushCleanup<ConsumeARCParameter>(getARCCleanupKind(), Arg); 1154 1155 if (lt == Qualifiers::OCL_Weak) { 1156 EmitARCInitWeak(DeclPtr, Arg); 1157 doStore = false; // The weak init is a store, no need to do two 1158 } 1159 } 1160 1161 // Enter the cleanup scope. 1162 EmitAutoVarWithLifetime(*this, D, DeclPtr, lt); 1163 } 1164 1165 // Store the initial value into the alloca. 1166 if (doStore) { 1167 LValue lv = MakeAddrLValue(DeclPtr, Ty, 1168 getContext().getDeclAlign(&D).getQuantity()); 1169 EmitStoreOfScalar(Arg, lv); 1170 } 1171 } 1172 1173 llvm::Value *&DMEntry = LocalDeclMap[&D]; 1174 assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); 1175 DMEntry = DeclPtr; 1176 1177 // Emit debug info for param declaration. 1178 if (CGDebugInfo *DI = getDebugInfo()) 1179 DI->EmitDeclareOfArgVariable(&D, DeclPtr, ArgNo, Builder); 1180} 1181