Open Quuxplusone opened 4 years ago
Bugzilla Link | PR46394 |
Status | CONFIRMED |
Importance | P enhancement |
Reported by | Carlos Alberto Enciso (international.phantom@gmail.com) |
Reported on | 2020-06-18 22:11:53 -0700 |
Last modified on | 2020-09-09 12:45:52 -0700 |
Version | trunk |
Hardware | PC All |
CC | dblaikie@gmail.com, greg.bedwell@sony.com, jdevlieghere@apple.com, jeremy.morse.llvm@gmail.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, orlando.hyams@sony.com, paul_robinson@playstation.sony.com, rnk@google.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
This is the output from llvm-diva (Sony's tool under development).
llvm-diva --print=scopes,symbols,types test_dw.c test_cv.o test_ms.o --
attribute=level,format
DWARF Logical View: (Clang)
---------------------------
Logical View:
[000] {File} 'test_dw.o' -> elf64-x86-64
[001] {CompileUnit} 'test.cpp'
[002] {Producer} 'clang version 11.0.0'
[002] 13 {Struct} 'Struct_A'
[003] 17 {Member} public 'Member_SA' -> 'Struct_B'
[003] 14 {Struct} 'Struct_B'
[004] 15 {Member} public 'Member_SB' -> 'char'
[002] 6 {Struct} 'Template_A<int>'
[003] 8 {Member} public 'Member_TA' -> 'Template_B<char>'
[003] 7 {Struct} 'Template_B<char>'
[004] 7 {Member} public 'Member_TB' -> 'char'
[002] 20 {Variable} extern 'MyClass' -> 'Struct_A'
[002] 11 {Variable} extern 'MyTemplate' -> 'Template_A<int>'
CodeView Logical View: (Clang)
------------------------------
Logical View:
[000] {File} 'test_cv.o' -> COFF-x86-64
[001] {CompileUnit} 'test.cpp'
[002] {Producer} 'clang version 11.0.0'
[002] 13 {Struct} 'Struct_A'
[003] {Member} public 'Member_SA' -> 'Struct_B'
[003] 14 {Struct} 'Struct_B'
[004] {Member} public 'Member_SB' -> 'char'
[002] 6 {Struct} 'Template_A<int>'
[003] {Member} public 'Member_TA' ->
'Template_A<int>::Template_B<char>'
[002] {Variable} extern 'MyClass' -> 'Struct_A'
[002] {Variable} extern 'MyTemplate' -> 'Template_A<int>'
CodeView Logical View: (MSVC)
-----------------------------
Logical View:
[000] {File} 'test_ms.o' -> COFF-i386
[001] {CompileUnit} 'test.cpp'
[002] {Producer} 'Microsoft (R) Optimizing Compiler'
[002] 13 {Struct} 'Struct_A'
[003] {Member} public 'Member_SA' -> 'Struct_B'
[003] 14 {Struct} 'Struct_B'
[004] {Member} public 'Member_SB' -> 'char'
[002] 11 {Struct} 'Template_A<int>'
[003] {Member} public 'Member_TA' -> 'Template_B<char>'
[003] 8 {Struct} 'Template_B<char>'
[004] {Member} public 'Member_TB' -> 'char'
[002] {Variable} extern 'MyClass' -> 'Struct_A'
[002] {Variable} extern 'MyTemplate' -> 'Template_A<int>'
DWARF Logical View: (Clang)
---------------------------
Logical View:
[002] 6 {Struct} 'Template_A<int>'
[003] 7 {Struct} 'Template_B<char>'
CodeView Logical View: (Clang)
------------------------------
[002] 6 {Struct} 'Template_A<int>'
CodeView Logical View: (MSVC)
-----------------------------
[002] 11 {Struct} 'Template_A<int>'
[003] 8 {Struct} 'Template_B<char>'
The logical view for Clang (Codeview) does not show the nested
'Template_B<char>'.
Thanks. This raises an interesting issue. If we include template instantiations
of any kind in the list of members of a class, the class definition may be
different across different TUs. Consider:
struct Foo {
template <typename U> struct Template_B { U Member_TB; };
Template_B<char> Member_TA;
};
Foo MyTemplate;
// Only in one TU
Foo::Template_B<int> MyInnerThing;
Some TUs will produce a field list containing Foo::Template_B<int> and some
will not. I suppose MSVC does this, and Visual Studio copes with it just fine.
We shouldn't change the IR to include the nested template in the member list.
We should do what DWARF does in the backend.
Some context:
Clang doesn't put any TU-variable members in the class's member list in the
LLVM IR debug info metadata. Those members still refer to the class as their
scope - so they can be found/attached to the class, but they don't come in the
member list. This keeps class definitions identical across translation units
with no merging requirements (this makes LLVM IR linking simpler, and makes
DWARF type units similarly simpler to implement).
Things that can vary:
1) template members (static member variable templates, static and non-static
member function templates, etc)
2) nested types of any kind (template or otherwise) - because they may be only
declared sometimes but declared-and-defined in other TUs, etc
3) implicit special members (copy/move ctor/assignment operator/dtor, default
ctor)
Those are the cases I'm aware of/there might be others, might be bugs/places
where it's not implemented that way. (I think maybe on the Windows side the
implicit special members have already had different handling applied? Some
attempt to instantiate them even in TUs that don't cause an instantiation in
their source?)