================
@@ -6611,8 +6611,12 @@ void CGDebugInfo::EmitGlobalAlias(const 
llvm::GlobalValue *GV,
     // Fix compiler to generate "newname" as imported_declaration
     // pointing to the DIE of "oldname".
     return;
-  if (!(DI = getDeclarationOrDefinition(
-            AliaseeDecl.getCanonicalDecl().getDecl())))
+  const auto *AliaseeD = AliaseeDecl.getCanonicalDecl().getDecl();
+  // A static local without debug info has no scope to forward-declare it in.
+  if (const auto *VD = dyn_cast<VarDecl>(AliaseeD);
+      VD && VD->isStaticLocal() && !DeclCache.count(VD))
----------------
dzhidzhoev wrote:

When function emission is deferred, `DeclCache.count(VD)` may return 0 for a 
variable whose debug information is generated later.
```c++
constexpr const int *f() {
  static constexpr int s = 1;
  return &s;
}
const int *p = f();
extern const int a __attribute__((alias("_ZZ1fvE1s")));
```
For the example above, before https://github.com/llvm/llvm-project/pull/213153, 
`DIImportedEntity` is emitted in LLVM IR:
```
!14 = !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "a", scope: !9, 
entity: !1, file: !3, line: 6)
```
With this fix, it is missing in the output. (Compiled with `clang test.cpp -o 
test.ll -emit-llvm -S -target bpf -g -std=c++23`).

Would checking for `NoDebugAttr` on `VD` and its parent function be sufficient 
in place of `!DeclCache.count(VD)`?

https://github.com/llvm/llvm-project/pull/243405
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to