}
QualType ReturnTy = Ctx.VoidTy;
- QualType FuncionTy = Ctx.getFunctionType(ReturnTy, ArgTys, {});
// The helper function has linkonce_odr linkage to enable the linker to merge
// identical functions. To ensure the merging always happens, 'noinline' is
Fn->addFnAttr(llvm::Attribute::NoInline);
auto NL = ApplyDebugLocation::CreateEmpty(*this);
- IdentifierInfo *II = &Ctx.Idents.get(Name);
- FunctionDecl *FD = FunctionDecl::Create(
- Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), II,
- FuncionTy, nullptr, SC_PrivateExtern, false, false);
- // Avoid generating debug location info for the function.
- FD->setImplicit();
-
- StartFunction(FD, ReturnTy, Fn, FI, Args);
+ StartFunction(GlobalDecl(), ReturnTy, Fn, FI, Args);
// Create a scope with an artificial location for the body of this function.
auto AL = ApplyDebugLocation::CreateArtificial(*this);
F->setVisibility(llvm::GlobalValue::HiddenVisibility);
CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, F, /*IsThunk=*/false);
CGM.SetLLVMFunctionAttributesForDefinition(nullptr, F);
- IdentifierInfo *II = &Ctx.Idents.get(FuncName);
- FunctionDecl *FD = FunctionDecl::Create(
- Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(),
- II, Ctx.getFunctionType(Ctx.VoidTy, llvm::None, {}), nullptr,
- SC_PrivateExtern, false, false);
CodeGenFunction NewCGF(CGM);
setCGF(&NewCGF);
- CGF->StartFunction(FD, Ctx.VoidTy, F, FI, Args);
+ CGF->StartFunction(GlobalDecl(), Ctx.VoidTy, F, FI, Args);
+ auto AL = ApplyDebugLocation::CreateArtificial(*CGF);
std::array<Address, N> Addrs =
getParamAddrs<N>(std::make_index_sequence<N>{}, Alignments, Args, CGF);
asDerived().visitStructFields(QT, CharUnits::Zero(), Addrs);
return GlobalInitOrCleanupFn;
}
-static FunctionDecl *
-createGlobalInitOrCleanupFnDecl(CodeGen::CodeGenModule &CGM, StringRef FnName) {
- ASTContext &Ctx = CGM.getContext();
- QualType FunctionTy = Ctx.getFunctionType(Ctx.VoidTy, llvm::None, {});
- return FunctionDecl::Create(
- Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(),
- &Ctx.Idents.get(FnName), FunctionTy, nullptr, SC_Static, false, false);
-}
-
void CodeGenModule::unregisterGlobalDtorsWithUnAtExit() {
for (const auto &I : DtorsUsingAtExit) {
int Priority = I.first;
llvm::Function *GlobalCleanupFn =
createGlobalInitOrCleanupFn(*this, GlobalCleanupFnName);
- FunctionDecl *GlobalCleanupFD =
- createGlobalInitOrCleanupFnDecl(*this, GlobalCleanupFnName);
-
CodeGenFunction CGF(*this);
- CGF.StartFunction(GlobalDecl(GlobalCleanupFD), getContext().VoidTy,
- GlobalCleanupFn, getTypes().arrangeNullaryFunction(),
- FunctionArgList(), SourceLocation(), SourceLocation());
+ CGF.StartFunction(GlobalDecl(), getContext().VoidTy, GlobalCleanupFn,
+ getTypes().arrangeNullaryFunction(), FunctionArgList(),
+ SourceLocation(), SourceLocation());
+ auto AL = ApplyDebugLocation::CreateArtificial(CGF);
// Get the destructor function type, void(*)(void).
llvm::FunctionType *dtorFuncTy = llvm::FunctionType::get(CGF.VoidTy, false);
std::string("__GLOBAL_init_") + llvm::to_string(Priority);
llvm::Function *GlobalInitFn =
createGlobalInitOrCleanupFn(*this, GlobalInitFnName);
- FunctionDecl *GlobalInitFD =
- createGlobalInitOrCleanupFnDecl(*this, GlobalInitFnName);
CodeGenFunction CGF(*this);
- CGF.StartFunction(GlobalDecl(GlobalInitFD), getContext().VoidTy,
- GlobalInitFn, getTypes().arrangeNullaryFunction(),
- FunctionArgList(), SourceLocation(), SourceLocation());
+ CGF.StartFunction(GlobalDecl(), getContext().VoidTy, GlobalInitFn,
+ getTypes().arrangeNullaryFunction(), FunctionArgList(),
+ SourceLocation(), SourceLocation());
+ auto AL = ApplyDebugLocation::CreateArtificial(CGF);
// Since constructor functions are run in non-descending order of their
// priorities, destructors are registered in non-descending order of their
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=WITHOUTATEXIT %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -fregister-global-dtors-with-atexit -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=CXAATEXIT --check-prefix=WITHATEXIT %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fregister-global-dtors-with-atexit -debug-info-kind=line-tables-only -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=CXAATEXIT --check-prefix=WITHATEXIT %s
// RUN: %clang_cc1 -triple x86_64-apple-darwin -fno-use-cxa-atexit -fregister-global-dtors-with-atexit -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=ATEXIT --check-prefix=WITHATEXIT %s
// WITHOUTATEXIT: global_ctors{{.*}}@A{{.*}}@C
// CHECK: define internal i32 @foo()
// WITHOUTATEXIT-NOT: define
-// WITHATEXIT: define internal void @__GLOBAL_init_123(){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions"
-// CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @E to void (i8*)*), i8* null, i8* @__dso_handle)
+// CXAATEXIT: define internal void @__GLOBAL_init_123(){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions" !dbg ![[GLOBAL_INIT_SP:.*]] {
+// ATEXIT: define internal void @__GLOBAL_init_123(){{.*}}section "__TEXT,__StaticInit,regular,pure_instructions"
+// CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @E to void (i8*)*), i8* null, i8* @__dso_handle) {{.*}}, !dbg ![[GLOBAL_INIT_LOC:.*]]
// CXAATEXIT: call i32 @__cxa_atexit(void (i8*)* bitcast (void ()* @G to void (i8*)*), i8* null, i8* @__dso_handle)
// ATEXIT: call i32 @atexit(void ()* @E)
// ATEXIT: call i32 @atexit(void ()* @G)
int main() {
return 0;
}
+
+// CXAATEXIT: ![[GLOBAL_INIT_SP]] = distinct !DISubprogram(linkageName: "__GLOBAL_init_123",
+// CXAATEXIT: ![[GLOBAL_INIT_LOC]] = !DILocation(line: 0, scope: ![[GLOBAL_INIT_SP]])
// This helper is going to be uniqued, so it should not have a line
// number between file and type.
-// CHECK: distinct !DISubprogram(name: "__os_log_helper_1_0_1_4_0",
+// CHECK: distinct !DISubprogram(linkageName: "__os_log_helper_1_0_1_4_0",
// CHECK-SAME: file: !{{.*}}, type
// CHECK-SAME: flags: DIFlagArtificial
// CHECK: resume
+// CHECK: define{{.*}} void @__destructor_8_w8({{.*}} !dbg ![[DTOR_SP:.*]] {
+// CHECK: load i8**, i8*** {{.*}}, !dbg ![[DTOR_LOC:.*]]
+
Weak genWeak(void);
void calleeWeak(Weak, Weak);
// CHECK-DAG: [[ARTIFICIAL_LOC_1]] = !DILocation(line: 0
// CHECK-DAG: [[ARTIFICIAL_LOC_2]] = !DILocation(line: 0
+// CHECK: ![[DTOR_SP]] = distinct !DISubprogram(linkageName: "__destructor_8_w8",
+// CHECK: ![[DTOR_LOC]] = !DILocation(line: 0, scope: ![[DTOR_SP]])