Skip to content

Conversation

@Michael137
Copy link
Member

@Michael137 Michael137 commented Nov 19, 2025

The test was failing on Darwin for two reasons:

  1. -fdebug-type-sections is not a recognized flag on Darwin
  2. We fail to reconstitute a name if the template parameter has a type that has a preferred_name. With LLDB tuning the type of such a parameter is a typedef, i.e., the preferred name. Without tuning it would be the canonical type that the typedef (possibly through a chain of typedefs) points to.

This patch addresses (1) by splitting the -fdebug-type-sections tests into a separate file (and only mark that one UNSUPPORTED). Which means we can at least XFAIL the non-type-sections tests on Darwin.

To fix (2) we might need to make the DWARFTypePrinter aware of non-canonical DW_AT_types of template parameters.

@dwblaikie
Copy link
Collaborator

Ah, I see the preferred name thing in more detail https://godbolt.org/z/Tjhrx5x6n

DW_TAG_structure_type [4] * (0x0000000b)
  DW_AT_name [DW_FORM_strp]	( .debug_str[0x000000af] = "t1<t7<int> >")
...

  DW_TAG_template_type_parameter [5]   (0x0000007c)
    DW_AT_type [DW_FORM_ref4]	(cu + 0x0042 => {0x00000042} "t7i")

Yeah, so we should plumb through the preferred name into the type rendering (presumably it's already plumbed through as an option - the whole point is for it to be used in type printing in diagnostics, so we probably just have to set the right printing policy from CGDebugInfo.cpp based on whatever condition we use (looks like lldb debugger tuning) to decide whether to use the preferred type in the DIType of the DITemplateTypeParameter)

(aside: I think someone filed this bug recently, or I saw it going around, so you're probably already aware of it - but that preferred type t7i only gets used if it's emitted for some other reason into the DWARF - if you remove the should_be_unnecessary variable from the godbolt example above, the template's type parameter goes from t7i to t7<int> - I don't think that shouldn't happen, we should emit/use the typedef here even if it's the only use)

@Michael137 Michael137 merged commit 8f91d9f into llvm:main Nov 19, 2025
11 checks passed
@Michael137 Michael137 deleted the llvm/simplified-template-names-preferred-name branch November 19, 2025 17:24
@Michael137
Copy link
Member Author

(aside: I think someone filed this bug recently, or I saw it going around, so you're probably already aware of it - but that preferred type t7i only gets used if it's emitted for some other reason into the DWARF - if you remove the should_be_unnecessary variable from the godbolt example above, the template's type parameter goes from t7i to t7<int> - I don't think that shouldn't happen, we should emit/use the typedef here even if it's the only use)

Yea I looked into it briefly here: #164730 (comment)

Looks like it falls out of how we walk the AST and canonicalize/create types in CGDebugInfo. But I forget the details. Yea would be good to fix. I guess we'd have to force creation of the alias before we unwrap it (or something like that)

Michael137 added a commit that referenced this pull request Nov 20, 2025
…econstructing DIE names (#168734)

Depends on: 
* #168725

When compiling with `-glldb`, we repoint the `DW_AT_type` of a DIE to be
a typedef that refers to the `preferred_name`. I.e.,:
```
template <typename T> structure t7;
using t7i = t7<int>;
template <typename T> struct __attribute__((__preferred_name__(t7i))) t7 {};
template <typename... Ts> void f1()

int main() { f1<t7i>(); }
```
would produce following (minified) DWARF:
```
DW_TAG_subprogram
  DW_AT_name      ("_STN|f1|<t7<int> >")
  DW_TAG_template_type_parameter
    DW_AT_type  (0x0000299c "t7i")
...
DW_TAG_typedef
  DW_AT_type      (0x000029a7 "t7<int>")
  DW_AT_name      ("t7i")
```

Note how the `DW_AT_type` of the template parameter is a typedef itself
(instead of the canonical type). The `DWARFTypePrinter` would take the
`DW_AT_name` of this typedef when reconstructing the name of `f1`, so we
would end up with a verifier failure:
```
error: Simplified template DW_AT_name could not be reconstituted:
         original: f1<t7<int> >
    reconstituted: f1<t7i>
```

Fixing this allows us to un-XFAIL the `simplified-template-names.cpp`
test in `cross-project-tests`. Unfortunately this is only tested on
Darwin, where LLDB tuning is the default. AFAIK, there is no other case
where the template parameter type wouldn't be canonical.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Nov 20, 2025
…defs when reconstructing DIE names (#168734)

Depends on:
* llvm/llvm-project#168725

When compiling with `-glldb`, we repoint the `DW_AT_type` of a DIE to be
a typedef that refers to the `preferred_name`. I.e.,:
```
template <typename T> structure t7;
using t7i = t7<int>;
template <typename T> struct __attribute__((__preferred_name__(t7i))) t7 {};
template <typename... Ts> void f1()

int main() { f1<t7i>(); }
```
would produce following (minified) DWARF:
```
DW_TAG_subprogram
  DW_AT_name      ("_STN|f1|<t7<int> >")
  DW_TAG_template_type_parameter
    DW_AT_type  (0x0000299c "t7i")
...
DW_TAG_typedef
  DW_AT_type      (0x000029a7 "t7<int>")
  DW_AT_name      ("t7i")
```

Note how the `DW_AT_type` of the template parameter is a typedef itself
(instead of the canonical type). The `DWARFTypePrinter` would take the
`DW_AT_name` of this typedef when reconstructing the name of `f1`, so we
would end up with a verifier failure:
```
error: Simplified template DW_AT_name could not be reconstituted:
         original: f1<t7<int> >
    reconstituted: f1<t7i>
```

Fixing this allows us to un-XFAIL the `simplified-template-names.cpp`
test in `cross-project-tests`. Unfortunately this is only tested on
Darwin, where LLDB tuning is the default. AFAIK, there is no other case
where the template parameter type wouldn't be canonical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants