[llvm] [AsmPrinter][DebugNames] Implement DW_IDX_parent entries (PR #77457)

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 15:20:11 PST 2024


felipepiovezan wrote:

> One question: This won't cause a forward declaration to show up in the .debug_names will it? I was thinking about this scenario, not sure if it can happen, but:
> 
> ```
> class A { // Forward decl only for 'A'
>   class B { // full definition for class 'B'
>   ...
>   };
> };
> ```
> 
> I want to make sure that if we enable this, it is fine to have an accelerator entry for `class A`, but it shouldn't be included in the name lookup if `class A` is just a forward declaration. We will need to point to an entry for `class A` for in the parent index in the entry for `class B`, but we shouldn't have an entry for `class A` that allows it to be found as a top level search as we don't want to try and lookup this class and find a class that is only a declaration.

This patch is not adding anything to the accelerator table that wasn't previously there, so it shouldn't be a problem.

>  it is fine to have an accelerator entry for `class A`, but it shouldn't be included in the name lookup if `class A` is just a forward declaration.

Forward declarations are never part of the accel table, the spec requires that:

>  All non-defining declarations (that is, debugging information entries with a DW_AT_declaration attribute) are excluded.

Is your concern that somehow some translation unit forward declares class A and then attempts to define a class B inside of A? There is no syntactical mechanism to do so in C++; note that, in your example, we are _defining_ A. I believe it is literally impossible to type a program that does this in C++.

I'm not sure about other languages; based on the way the DWARF spec is written, it doesn't even acknowledge this possibility (because of the clause I quoted above). If other languages allow this type of thing, their compiler should probably not use IDX_Parents, because a parent that is only a forward declaration is forbidden from being inserted in the table, so the chain would be broken.

https://github.com/llvm/llvm-project/pull/77457


More information about the llvm-commits mailing list