1 //===--- CGDeclCXX.cpp - Emit LLVM Code for C++ 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 dealing with code generation of C++ declarations 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "CodeGenFunction.h" 15 #include "CGCXXABI.h" 16 #include "CGObjCRuntime.h" 17 #include "clang/Frontend/CodeGenOptions.h" 18 #include "llvm/ADT/StringExtras.h" 19 #include "llvm/IR/Intrinsics.h" 20 #include "llvm/Support/Path.h" 21 22 using namespace clang; 23 using namespace CodeGen; 24 25 static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D, 26 llvm::Constant *DeclPtr) { 27 assert(D.hasGlobalStorage() && "VarDecl must have global storage!"); 28 assert(!D.getType()->isReferenceType() && 29 "Should not call EmitDeclInit on a reference!"); 30 31 ASTContext &Context = CGF.getContext(); 32 33 CharUnits alignment = Context.getDeclAlign(&D); 34 QualType type = D.getType(); 35 LValue lv = CGF.MakeAddrLValue(DeclPtr, type, alignment); 36 37 const Expr *Init = D.getInit(); 38 switch (CGF.getEvaluationKind(type)) { 39 case TEK_Scalar: { 40 CodeGenModule &CGM = CGF.CGM; 41 if (lv.isObjCStrong()) 42 CGM.getObjCRuntime().EmitObjCGlobalAssign(CGF, CGF.EmitScalarExpr(Init), 43 DeclPtr, D.getTLSKind()); 44 else if (lv.isObjCWeak()) 45 CGM.getObjCRuntime().EmitObjCWeakAssign(CGF, CGF.EmitScalarExpr(Init), 46 DeclPtr); 47 else 48 CGF.EmitScalarInit(Init, &D, lv, false); 49 return; 50 } 51 case TEK_Complex: 52 CGF.EmitComplexExprIntoLValue(Init, lv, /*isInit*/ true); 53 return; 54 case TEK_Aggregate: 55 CGF.EmitAggExpr(Init, AggValueSlot::forLValue(lv,AggValueSlot::IsDestructed, 56 AggValueSlot::DoesNotNeedGCBarriers, 57 AggValueSlot::IsNotAliased)); 58 return; 59 } 60 llvm_unreachable("bad evaluation kind"); 61 } 62 63 /// Emit code to cause the destruction of the given variable with 64 /// static storage duration. 65 static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D, 66 llvm::Constant *addr) { 67 CodeGenModule &CGM = CGF.CGM; 68 69 // FIXME: __attribute__((cleanup)) ? 70 71 QualType type = D.getType(); 72 QualType::DestructionKind dtorKind = type.isDestructedType(); 73 74 switch (dtorKind) { 75 case QualType::DK_none: 76 return; 77 78 case QualType::DK_cxx_destructor: 79 break; 80 81 case QualType::DK_objc_strong_lifetime: 82 case QualType::DK_objc_weak_lifetime: 83 // We don't care about releasing objects during process teardown. 84 assert(!D.getTLSKind() && "should have rejected this"); 85 return; 86 } 87 88 llvm::Constant *function; 89 llvm::Constant *argument; 90 91 // Special-case non-array C++ destructors, where there's a function 92 // with the right signature that we can just call. 93 const CXXRecordDecl *record = nullptr; 94 if (dtorKind == QualType::DK_cxx_destructor && 95 (record = type->getAsCXXRecordDecl())) { 96 assert(!record->hasTrivialDestructor()); 97 CXXDestructorDecl *dtor = record->getDestructor(); 98 99 function = CGM.getAddrOfCXXStructor(dtor, StructorType::Complete); 100 argument = llvm::ConstantExpr::getBitCast( 101 addr, CGF.getTypes().ConvertType(type)->getPointerTo()); 102 103 // Otherwise, the standard logic requires a helper function. 104 } else { 105 function = CodeGenFunction(CGM) 106 .generateDestroyHelper(addr, type, CGF.getDestroyer(dtorKind), 107 CGF.needsEHCleanup(dtorKind), &D); 108 argument = llvm::Constant::getNullValue(CGF.Int8PtrTy); 109 } 110 111 CGM.getCXXABI().registerGlobalDtor(CGF, D, function, argument); 112 } 113 114 /// Emit code to cause the variable at the given address to be considered as 115 /// constant from this point onwards. 116 static void EmitDeclInvariant(CodeGenFunction &CGF, const VarDecl &D, 117 llvm::Constant *Addr) { 118 // Don't emit the intrinsic if we're not optimizing. 119 if (!CGF.CGM.getCodeGenOpts().OptimizationLevel) 120 return; 121 122 // Grab the llvm.invariant.start intrinsic. 123 llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start; 124 llvm::Constant *InvariantStart = CGF.CGM.getIntrinsic(InvStartID); 125 126 // Emit a call with the size in bytes of the object. 127 CharUnits WidthChars = CGF.getContext().getTypeSizeInChars(D.getType()); 128 uint64_t Width = WidthChars.getQuantity(); 129 llvm::Value *Args[2] = { llvm::ConstantInt::getSigned(CGF.Int64Ty, Width), 130 llvm::ConstantExpr::getBitCast(Addr, CGF.Int8PtrTy)}; 131 CGF.Builder.CreateCall(InvariantStart, Args); 132 } 133 134 void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D, 135 llvm::Constant *DeclPtr, 136 bool PerformInit) { 137 138 const Expr *Init = D.getInit(); 139 QualType T = D.getType(); 140 141 if (!T->isReferenceType()) { 142 if (PerformInit) 143 EmitDeclInit(*this, D, DeclPtr); 144 if (CGM.isTypeConstant(D.getType(), true)) 145 EmitDeclInvariant(*this, D, DeclPtr); 146 else 147 EmitDeclDestroy(*this, D, DeclPtr); 148 return; 149 } 150 151 assert(PerformInit && "cannot have constant initializer which needs " 152 "destruction for reference"); 153 unsigned Alignment = getContext().getDeclAlign(&D).getQuantity(); 154 RValue RV = EmitReferenceBindingToExpr(Init); 155 EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, Alignment, T); 156 } 157 158 /// Create a stub function, suitable for being passed to atexit, 159 /// which passes the given address to the given destructor function. 160 llvm::Constant *CodeGenFunction::createAtExitStub(const VarDecl &VD, 161 llvm::Constant *dtor, 162 llvm::Constant *addr) { 163 // Get the destructor function type, void(*)(void). 164 llvm::FunctionType *ty = llvm::FunctionType::get(CGM.VoidTy, false); 165 SmallString<256> FnName; 166 { 167 llvm::raw_svector_ostream Out(FnName); 168 CGM.getCXXABI().getMangleContext().mangleDynamicAtExitDestructor(&VD, Out); 169 } 170 llvm::Function *fn = CGM.CreateGlobalInitOrDestructFunction(ty, FnName.str()); 171 172 CodeGenFunction CGF(CGM); 173 174 CGF.StartFunction(&VD, CGM.getContext().VoidTy, fn, 175 CGM.getTypes().arrangeNullaryFunction(), FunctionArgList()); 176 177 llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr); 178 179 // Make sure the call and the callee agree on calling convention. 180 if (llvm::Function *dtorFn = 181 dyn_cast<llvm::Function>(dtor->stripPointerCasts())) 182 call->setCallingConv(dtorFn->getCallingConv()); 183 184 CGF.FinishFunction(); 185 186 return fn; 187 } 188 189 /// Register a global destructor using the C atexit runtime function. 190 void CodeGenFunction::registerGlobalDtorWithAtExit(const VarDecl &VD, 191 llvm::Constant *dtor, 192 llvm::Constant *addr) { 193 // Create a function which calls the destructor. 194 llvm::Constant *dtorStub = createAtExitStub(VD, dtor, addr); 195 196 // extern "C" int atexit(void (*f)(void)); 197 llvm::FunctionType *atexitTy = 198 llvm::FunctionType::get(IntTy, dtorStub->getType(), false); 199 200 llvm::Constant *atexit = 201 CGM.CreateRuntimeFunction(atexitTy, "atexit"); 202 if (llvm::Function *atexitFn = dyn_cast<llvm::Function>(atexit)) 203 atexitFn->setDoesNotThrow(); 204 205 EmitNounwindRuntimeCall(atexit, dtorStub); 206 } 207 208 void CodeGenFunction::EmitCXXGuardedInit(const VarDecl &D, 209 llvm::GlobalVariable *DeclPtr, 210 bool PerformInit) { 211 // If we've been asked to forbid guard variables, emit an error now. 212 // This diagnostic is hard-coded for Darwin's use case; we can find 213 // better phrasing if someone else needs it. 214 if (CGM.getCodeGenOpts().ForbidGuardVariables) 215 CGM.Error(D.getLocation(), 216 "this initialization requires a guard variable, which " 217 "the kernel does not support"); 218 219 CGM.getCXXABI().EmitGuardedInit(*this, D, DeclPtr, PerformInit); 220 } 221 222 llvm::Function * 223 CodeGenModule::CreateGlobalInitOrDestructFunction(llvm::FunctionType *FTy, 224 const Twine &Name, bool TLS) { 225 llvm::Function *Fn = 226 llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage, 227 Name, &getModule()); 228 if (!getLangOpts().AppleKext && !TLS) { 229 // Set the section if needed. 230 if (const char *Section = getTarget().getStaticInitSectionSpecifier()) 231 Fn->setSection(Section); 232 } 233 234 Fn->setCallingConv(getRuntimeCC()); 235 236 if (!getLangOpts().Exceptions) 237 Fn->setDoesNotThrow(); 238 239 if (!getSanitizerBlacklist().isIn(*Fn)) { 240 if (getLangOpts().Sanitize.Address) 241 Fn->addFnAttr(llvm::Attribute::SanitizeAddress); 242 if (getLangOpts().Sanitize.Thread) 243 Fn->addFnAttr(llvm::Attribute::SanitizeThread); 244 if (getLangOpts().Sanitize.Memory) 245 Fn->addFnAttr(llvm::Attribute::SanitizeMemory); 246 } 247 248 return Fn; 249 } 250 251 /// Create a global pointer to a function that will initialize a global 252 /// variable. The user has requested that this pointer be emitted in a specific 253 /// section. 254 void CodeGenModule::EmitPointerToInitFunc(const VarDecl *D, 255 llvm::GlobalVariable *GV, 256 llvm::Function *InitFunc, 257 InitSegAttr *ISA) { 258 llvm::GlobalVariable *PtrArray = new llvm::GlobalVariable( 259 TheModule, InitFunc->getType(), /*isConstant=*/true, 260 llvm::GlobalValue::PrivateLinkage, InitFunc, "__cxx_init_fn_ptr"); 261 PtrArray->setSection(ISA->getSection()); 262 addUsedGlobal(PtrArray); 263 264 // If the GV is already in a comdat group, then we have to join it. 265 llvm::Comdat *C = GV->getComdat(); 266 267 // LinkOnce and Weak linkage are lowered down to a single-member comdat group. 268 // Make an explicit group so we can join it. 269 if (!C && (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage())) { 270 C = TheModule.getOrInsertComdat(GV->getName()); 271 GV->setComdat(C); 272 } 273 if (C) 274 PtrArray->setComdat(C); 275 } 276 277 void 278 CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, 279 llvm::GlobalVariable *Addr, 280 bool PerformInit) { 281 llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false); 282 SmallString<256> FnName; 283 { 284 llvm::raw_svector_ostream Out(FnName); 285 getCXXABI().getMangleContext().mangleDynamicInitializer(D, Out); 286 } 287 288 // Create a variable initialization function. 289 llvm::Function *Fn = CreateGlobalInitOrDestructFunction(FTy, FnName.str()); 290 291 auto *ISA = D->getAttr<InitSegAttr>(); 292 CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D, Addr, 293 PerformInit); 294 295 llvm::GlobalVariable *Key = supportsCOMDAT() ? Addr : nullptr; 296 297 if (D->getTLSKind()) { 298 // FIXME: Should we support init_priority for thread_local? 299 // FIXME: Ideally, initialization of instantiated thread_local static data 300 // members of class templates should not trigger initialization of other 301 // entities in the TU. 302 // FIXME: We only need to register one __cxa_thread_atexit function for the 303 // entire TU. 304 CXXThreadLocalInits.push_back(Fn); 305 CXXThreadLocalInitVars.push_back(Addr); 306 } else if (PerformInit && ISA) { 307 EmitPointerToInitFunc(D, Addr, Fn, ISA); 308 DelayedCXXInitPosition.erase(D); 309 } else if (auto *IPA = D->getAttr<InitPriorityAttr>()) { 310 OrderGlobalInits Key(IPA->getPriority(), PrioritizedCXXGlobalInits.size()); 311 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn)); 312 DelayedCXXInitPosition.erase(D); 313 } else if (D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization && 314 D->getTemplateSpecializationKind() != TSK_Undeclared) { 315 // C++ [basic.start.init]p2: 316 // Definitions of explicitly specialized class template static data 317 // members have ordered initialization. Other class template static data 318 // members (i.e., implicitly or explicitly instantiated specializations) 319 // have unordered initialization. 320 // 321 // As a consequence, we can put them into their own llvm.global_ctors entry. 322 // 323 // In addition, put the initializer into a COMDAT group with the global 324 // being initialized. On most platforms, this is a minor startup time 325 // optimization. In the MS C++ ABI, there are no guard variables, so this 326 // COMDAT key is required for correctness. 327 AddGlobalCtor(Fn, 65535, Key); 328 DelayedCXXInitPosition.erase(D); 329 } else if (D->hasAttr<SelectAnyAttr>()) { 330 // SelectAny globals will be comdat-folded. Put the initializer into a COMDAT 331 // group associated with the global, so the initializers get folded too. 332 AddGlobalCtor(Fn, 65535, Key); 333 DelayedCXXInitPosition.erase(D); 334 } else { 335 llvm::DenseMap<const Decl *, unsigned>::iterator I = 336 DelayedCXXInitPosition.find(D); 337 if (I == DelayedCXXInitPosition.end()) { 338 CXXGlobalInits.push_back(Fn); 339 } else { 340 assert(CXXGlobalInits[I->second] == nullptr); 341 CXXGlobalInits[I->second] = Fn; 342 DelayedCXXInitPosition.erase(I); 343 } 344 } 345 } 346 347 void CodeGenModule::EmitCXXThreadLocalInitFunc() { 348 getCXXABI().EmitThreadLocalInitFuncs( 349 *this, CXXThreadLocals, CXXThreadLocalInits, CXXThreadLocalInitVars); 350 351 CXXThreadLocalInits.clear(); 352 CXXThreadLocalInitVars.clear(); 353 CXXThreadLocals.clear(); 354 } 355 356 void 357 CodeGenModule::EmitCXXGlobalInitFunc() { 358 while (!CXXGlobalInits.empty() && !CXXGlobalInits.back()) 359 CXXGlobalInits.pop_back(); 360 361 if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty()) 362 return; 363 364 llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false); 365 366 367 // Create our global initialization function. 368 if (!PrioritizedCXXGlobalInits.empty()) { 369 SmallVector<llvm::Function *, 8> LocalCXXGlobalInits; 370 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(), 371 PrioritizedCXXGlobalInits.end()); 372 // Iterate over "chunks" of ctors with same priority and emit each chunk 373 // into separate function. Note - everything is sorted first by priority, 374 // second - by lex order, so we emit ctor functions in proper order. 375 for (SmallVectorImpl<GlobalInitData >::iterator 376 I = PrioritizedCXXGlobalInits.begin(), 377 E = PrioritizedCXXGlobalInits.end(); I != E; ) { 378 SmallVectorImpl<GlobalInitData >::iterator 379 PrioE = std::upper_bound(I + 1, E, *I, GlobalInitPriorityCmp()); 380 381 LocalCXXGlobalInits.clear(); 382 unsigned Priority = I->first.priority; 383 // Compute the function suffix from priority. Prepend with zeroes to make 384 // sure the function names are also ordered as priorities. 385 std::string PrioritySuffix = llvm::utostr(Priority); 386 // Priority is always <= 65535 (enforced by sema). 387 PrioritySuffix = std::string(6-PrioritySuffix.size(), '0')+PrioritySuffix; 388 llvm::Function *Fn = CreateGlobalInitOrDestructFunction( 389 FTy, "_GLOBAL__I_" + PrioritySuffix); 390 391 for (; I < PrioE; ++I) 392 LocalCXXGlobalInits.push_back(I->second); 393 394 CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, LocalCXXGlobalInits); 395 AddGlobalCtor(Fn, Priority); 396 } 397 } 398 399 SmallString<128> FileName; 400 SourceManager &SM = Context.getSourceManager(); 401 if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { 402 // Include the filename in the symbol name. Including "sub_" matches gcc and 403 // makes sure these symbols appear lexicographically behind the symbols with 404 // priority emitted above. 405 FileName = llvm::sys::path::filename(MainFile->getName()); 406 } else { 407 FileName = SmallString<128>("<null>"); 408 } 409 410 for (size_t i = 0; i < FileName.size(); ++i) { 411 // Replace everything that's not [a-zA-Z0-9._] with a _. This set happens 412 // to be the set of C preprocessing numbers. 413 if (!isPreprocessingNumberBody(FileName[i])) 414 FileName[i] = '_'; 415 } 416 417 llvm::Function *Fn = CreateGlobalInitOrDestructFunction( 418 FTy, llvm::Twine("_GLOBAL__sub_I_", FileName)); 419 420 CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, CXXGlobalInits); 421 AddGlobalCtor(Fn); 422 423 CXXGlobalInits.clear(); 424 PrioritizedCXXGlobalInits.clear(); 425 } 426 427 void CodeGenModule::EmitCXXGlobalDtorFunc() { 428 if (CXXGlobalDtors.empty()) 429 return; 430 431 llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false); 432 433 // Create our global destructor function. 434 llvm::Function *Fn = CreateGlobalInitOrDestructFunction(FTy, "_GLOBAL__D_a"); 435 436 CodeGenFunction(*this).GenerateCXXGlobalDtorsFunc(Fn, CXXGlobalDtors); 437 AddGlobalDtor(Fn); 438 } 439 440 /// Emit the code necessary to initialize the given global variable. 441 void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, 442 const VarDecl *D, 443 llvm::GlobalVariable *Addr, 444 bool PerformInit) { 445 // Check if we need to emit debug info for variable initializer. 446 if (D->hasAttr<NoDebugAttr>()) 447 DebugInfo = nullptr; // disable debug info indefinitely for this function 448 449 StartFunction(GlobalDecl(D), getContext().VoidTy, Fn, 450 getTypes().arrangeNullaryFunction(), 451 FunctionArgList(), D->getLocation(), 452 D->getInit()->getExprLoc()); 453 454 // Use guarded initialization if the global variable is weak. This 455 // occurs for, e.g., instantiated static data members and 456 // definitions explicitly marked weak. 457 if (Addr->hasWeakLinkage() || Addr->hasLinkOnceLinkage()) { 458 EmitCXXGuardedInit(*D, Addr, PerformInit); 459 } else { 460 EmitCXXGlobalVarDeclInit(*D, Addr, PerformInit); 461 } 462 463 FinishFunction(); 464 } 465 466 void 467 CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn, 468 ArrayRef<llvm::Function *> Decls, 469 llvm::GlobalVariable *Guard) { 470 { 471 ArtificialLocation AL(*this, Builder); 472 StartFunction(GlobalDecl(), getContext().VoidTy, Fn, 473 getTypes().arrangeNullaryFunction(), FunctionArgList()); 474 // Emit an artificial location for this function. 475 AL.Emit(); 476 477 llvm::BasicBlock *ExitBlock = nullptr; 478 if (Guard) { 479 // If we have a guard variable, check whether we've already performed 480 // these initializations. This happens for TLS initialization functions. 481 llvm::Value *GuardVal = Builder.CreateLoad(Guard); 482 llvm::Value *Uninit = Builder.CreateIsNull(GuardVal, 483 "guard.uninitialized"); 484 // Mark as initialized before initializing anything else. If the 485 // initializers use previously-initialized thread_local vars, that's 486 // probably supposed to be OK, but the standard doesn't say. 487 Builder.CreateStore(llvm::ConstantInt::get(GuardVal->getType(),1), Guard); 488 llvm::BasicBlock *InitBlock = createBasicBlock("init"); 489 ExitBlock = createBasicBlock("exit"); 490 Builder.CreateCondBr(Uninit, InitBlock, ExitBlock); 491 EmitBlock(InitBlock); 492 } 493 494 RunCleanupsScope Scope(*this); 495 496 // When building in Objective-C++ ARC mode, create an autorelease pool 497 // around the global initializers. 498 if (getLangOpts().ObjCAutoRefCount && getLangOpts().CPlusPlus) { 499 llvm::Value *token = EmitObjCAutoreleasePoolPush(); 500 EmitObjCAutoreleasePoolCleanup(token); 501 } 502 503 for (unsigned i = 0, e = Decls.size(); i != e; ++i) 504 if (Decls[i]) 505 EmitRuntimeCall(Decls[i]); 506 507 Scope.ForceCleanup(); 508 509 if (ExitBlock) { 510 Builder.CreateBr(ExitBlock); 511 EmitBlock(ExitBlock); 512 } 513 } 514 515 FinishFunction(); 516 } 517 518 void CodeGenFunction::GenerateCXXGlobalDtorsFunc(llvm::Function *Fn, 519 const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> > 520 &DtorsAndObjects) { 521 { 522 ArtificialLocation AL(*this, Builder); 523 StartFunction(GlobalDecl(), getContext().VoidTy, Fn, 524 getTypes().arrangeNullaryFunction(), FunctionArgList()); 525 // Emit an artificial location for this function. 526 AL.Emit(); 527 528 // Emit the dtors, in reverse order from construction. 529 for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) { 530 llvm::Value *Callee = DtorsAndObjects[e - i - 1].first; 531 llvm::CallInst *CI = Builder.CreateCall(Callee, 532 DtorsAndObjects[e - i - 1].second); 533 // Make sure the call and the callee agree on calling convention. 534 if (llvm::Function *F = dyn_cast<llvm::Function>(Callee)) 535 CI->setCallingConv(F->getCallingConv()); 536 } 537 } 538 539 FinishFunction(); 540 } 541 542 /// generateDestroyHelper - Generates a helper function which, when 543 /// invoked, destroys the given object. 544 llvm::Function *CodeGenFunction::generateDestroyHelper( 545 llvm::Constant *addr, QualType type, Destroyer *destroyer, 546 bool useEHCleanupForArray, const VarDecl *VD) { 547 FunctionArgList args; 548 ImplicitParamDecl dst(getContext(), nullptr, SourceLocation(), nullptr, 549 getContext().VoidPtrTy); 550 args.push_back(&dst); 551 552 const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( 553 getContext().VoidTy, args, FunctionType::ExtInfo(), /*variadic=*/false); 554 llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI); 555 llvm::Function *fn = 556 CGM.CreateGlobalInitOrDestructFunction(FTy, "__cxx_global_array_dtor"); 557 558 StartFunction(VD, getContext().VoidTy, fn, FI, args); 559 560 emitDestroy(addr, type, destroyer, useEHCleanupForArray); 561 562 FinishFunction(); 563 564 return fn; 565 } 566