llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Debug info for template variables don't have unique names

Open pogo59 opened this issue 11 years ago • 6 comments

Bugzilla Link 22119
Version unspecified
OS Windows NT
CC @dwblaikie,@ormris

Extended Description

Use -g -std=c++14 to compile this source:

template <typename T> T crazy = T();
int foo() {
  crazy<int> = 5;
  crazy<short> = 10;
  return crazy<int> + crazy<short>;
}

The names of the two local variables get correct types and mangled names, but DW_AT_name = "crazy" for both.

Probably they should be crazy<int> and crazy<short> to disambiguate. And maybe have child template-parameter DIEs too. :-P

pogo59 avatar Jan 07 '15 20:01 pogo59

A partial fix was committed as r343706 and r343707. Adding template parameters to DW_AT_name will have to wait until LLDB can parse them.

ormris avatar Oct 03 '18 21:10 ormris

Paul - want to try writing a patch for this? Shouldn't be too hard.

+Larisse, in case she wants to dive into this.

I won't mind if somebody else gets to it first, but it would be convenient to have this done before the 3.6 branch. I'll put it on my list.

pogo59 avatar Jan 07 '15 21:01 pogo59

Paul - want to try writing a patch for this? Shouldn't be too hard.

+Larisse, in case she wants to dive into this.

dwblaikie avatar Jan 07 '15 20:01 dwblaikie

Things have improved in Clang 21.0: https://godbolt.org/z/d5hqeedb3 DW_AT_names are still the same, but DW_AT_types and DW_AT_linkage_names differ. Also, they have attached DW_TAG_template_type_parameter. I wonder if this is good enough. CC @dwblaikie

Endilll avatar Apr 26 '25 21:04 Endilll

@llvm/issue-subscribers-debuginfo

Author: Paul T Robinson (pogo59)

| | | | --- | --- | | Bugzilla Link | [22119](https://llvm.org/bz22119) | | Version | unspecified | | OS | Windows NT | | CC | @dwblaikie,@ormris |

Extended Description

Use -g -std=c++14 to compile this source:

template &lt;typename T&gt; T crazy = T();
int foo() {
  crazy&lt;int&gt; = 5;
  crazy&lt;short&gt; = 10;
  return crazy&lt;int&gt; + crazy&lt;short&gt;;
}

The names of the two local variables get correct types and mangled names, but DW_AT_name = "crazy" for both.

Probably they should be crazy&lt;int&gt; and crazy&lt;short&gt; to disambiguate. And maybe have child template-parameter DIEs too. :-P

llvmbot avatar Apr 26 '25 21:04 llvmbot

Things have improved in Clang 21.0: https://godbolt.org/z/d5hqeedb3 DW_AT_names are still the same, but DW_AT_types and DW_AT_linkage_names differ. Also, they have attached DW_TAG_template_type_parameter. I wonder if this is good enough. CC @dwblaikie

I don't think it is sufficient, unfortunately - at least for now, in my exploration of Simplified Template Names ( https://groups.google.com/g/llvm-dev/c/ekLMllbLIZg/m/-dhJ0hO1AAAJ ) there are several cases where Clang's structured DWARF output isn't sufficiently descriptive to roundtrip/reproduce the textual name of the template specialization.

Check CGDebugInfo::HasReconstitutableArgs for examples of problems.

dwblaikie avatar Apr 28 '25 16:04 dwblaikie