Skip to content

Commit e78b801

Browse files
committed
[BPF] Fix issues with external declarations of C++ structor decls
Use GetAddrOfGlobal, which is a more general API that takes a GlobalDecl, and handles declaring C++ destructors and other types in a general way. It's possible we can generalize this to handle external variable declarations. This fixes issues reported on llvm#130674 by @lexi-nadia .
1 parent 0e0a166 commit e78b801

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5837,15 +5837,21 @@ void CodeGenModule::EmitExternalVarDeclaration(const VarDecl *D) {
58375837
}
58385838
}
58395839

5840+
static GlobalDecl getBaseVariantGlobalDecl(const FunctionDecl *FD) {
5841+
if (auto const *CD = dyn_cast<const CXXConstructorDecl>(FD))
5842+
return GlobalDecl(CD, CXXCtorType::Ctor_Base);
5843+
else if (auto const *DD = dyn_cast<const CXXDestructorDecl>(FD))
5844+
return GlobalDecl(DD, CXXDtorType::Dtor_Base);
5845+
return GlobalDecl(FD);
5846+
}
5847+
58405848
void CodeGenModule::EmitExternalFunctionDeclaration(const FunctionDecl *FD) {
58415849
if (CGDebugInfo *DI = getModuleDebugInfo())
58425850
if (getCodeGenOpts().hasReducedDebugInfo()) {
5843-
auto *Ty = getTypes().ConvertType(FD->getType());
5844-
StringRef MangledName = getMangledName(FD);
5845-
auto *Fn = cast<llvm::Function>(
5846-
GetOrCreateLLVMFunction(MangledName, Ty, FD, /* ForVTable */ false));
5851+
GlobalDecl GD = getBaseVariantGlobalDecl(FD);
5852+
auto *Fn = cast<llvm::Function>(GetAddrOfGlobal(GD));
58475853
if (!Fn->getSubprogram())
5848-
DI->EmitFunctionDecl(FD, FD->getLocation(), FD->getType(), Fn);
5854+
DI->EmitFunctionDecl(GD, FD->getLocation(), FD->getType(), Fn);
58495855
}
58505856
}
58515857

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -debug-info-kind=constructor -triple bpf -emit-llvm %s -o - | FileCheck %s
2+
3+
class Foo {
4+
public:
5+
virtual ~Foo() noexcept;
6+
};
7+
8+
class Bar : public Foo {
9+
public:
10+
Bar() noexcept {}
11+
~Bar() noexcept override;
12+
};
13+
14+
// CHECK: declare !dbg !{{[0-9]+}} void @_ZN3FooD2Ev(ptr noundef nonnull align 8 dereferenceable(8))

0 commit comments

Comments
 (0)