llvm-project/lldb/unittests/Symbol
Raphael Isemann b8567559cf [lldb] Make the ClassTemplateDecl merging logic in TypeSystemClang respect template parameters
DWARF doesn't describe templates itself but only actual template instantiations.
Because of that LLDB has to infer the parameters of the class template
declarations from the actual instantiations when creating the internal Clang AST
from debug info

Because there is no dedicated DIE for the class template, LLDB also creates the
`ClassTemplateDecl` implicitly when parsing a template instantiation. To avoid
creating one ClassTemplateDecls for every instantiation,
`TypeSystemClang::CreateClassTemplateDecl` will check if there is already a
`ClassTemplateDecl` in the requested `DeclContext` and will reuse a found
fitting declaration.

The logic that checks if a found class template fits to an instantiation is
currently just comparing the name of the template. So right now we map
`template<typename T> struct S;` to an instantiation with the values `S<1, 2,
3>` even though they clearly don't belong together.

This causes crashes later on when for example the Itanium mangler's
`TemplateArgManglingInfo::needExactType` method tries to find fitting the class
template parameter that fits to an instantiation value. In the example above it
will try to find the parameter for the value `2` but will just trigger a
boundary check when retrieving the parameter with index 1 from the class
template.

There are two ways we can end up with an instantiation that doesn't fit to a
class template with the same name:

1. We have two TUs with two templates that have the same name and internal
   linkage.
2. A forward declared template instantiation is emitted by GCC and Clang
   without an empty list of parameter values.

This patch makes the check for whether a class template declaration can be
reused more sophisticated by also comparing whether the parameter values can fit
to the found class template. If we can't find a fitting class template we
justcreate a second class template with the fitting parameters.

Fixes rdar://76592821

Reviewed By: kastiglione

Differential Revision: https://reviews.llvm.org/D100662
2021-06-15 19:25:07 +02:00
..
Inputs [DWARFYAML] Make the include_directories, file_names and opcodes fields of the line table optional. 2020-09-18 20:21:11 +08:00
CMakeLists.txt [lldb] Move clang-based files out of Symbol 2020-01-31 12:20:10 -08:00
LocateSymbolFileTest.cpp [lldb] Make Reproducer compatbile with SubsystemRAII (NFC) 2020-08-25 13:00:04 -07:00
PostfixExpressionTest.cpp fix lldb for recent libDebugInfoDWARF API change 2020-10-23 19:20:38 -07:00
TestClangASTImporter.cpp [lldb] Fix typos. NFC. 2021-05-31 06:48:57 +07:00
TestDWARFCallFrameInfo.cpp [lldb/Module] Allow for the creation of memory-only modules 2020-07-14 08:45:44 -07:00
TestLineEntry.cpp [lldb] Refactor argument group by SourceLocationSpec (NFCI) 2021-05-04 23:04:31 +00:00
TestType.cpp [lldb][NFC] Fix all formatting errors in .cpp file headers 2020-01-24 08:52:55 +01:00
TestTypeSystemClang.cpp [lldb] Make the ClassTemplateDecl merging logic in TypeSystemClang respect template parameters 2021-06-15 19:25:07 +02:00