[clang] [BPF] Handle aliases in CodeGenModule::EmitExternalDeclaration. Fixes #192365 (PR #192374)
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 17 18:00:28 PDT 2026
================
@@ -5990,12 +5990,21 @@ void CodeGenModule::EmitExternalDeclaration(const DeclaratorDecl *D) {
llvm::Constant *Addr = GetAddrOfGlobal(GD)->stripPointerCasts();
if (const auto *VD = dyn_cast<VarDecl>(D)) {
- DI->EmitExternalVariable(
- cast<llvm::GlobalVariable>(Addr->stripPointerCasts()), VD);
+ if (auto *GV = dyn_cast<llvm::GlobalVariable>(Addr))
+ DI->EmitExternalVariable(GV, VD);
+ else if (auto *GA = dyn_cast<llvm::GlobalAlias>(Addr))
+ DI->EmitGlobalAlias(GA, GD);
+ else
+ llvm_unreachable("Unexpected address for external variable");
} else if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
- llvm::Function *Fn = cast<llvm::Function>(Addr);
- if (!Fn->getSubprogram())
- DI->EmitFunctionDecl(GD, FD->getLocation(), FD->getType(), Fn);
+ if (auto *Fn = dyn_cast<llvm::Function>(Addr)) {
+ if (!Fn->getSubprogram())
+ DI->EmitFunctionDecl(GD, FD->getLocation(), FD->getType(), Fn);
+ } else if (auto *GA = dyn_cast<llvm::GlobalAlias>(Addr)) {
+ DI->EmitGlobalAlias(GA, GD);
+ } else {
+ llvm_unreachable("Unexpected address for external function");
+ }
----------------
alexfh wrote:
I've added a test for a global variable alias and moved the common code out of the two branches.
https://github.com/llvm/llvm-project/pull/192374
More information about the cfe-commits
mailing list