[all-commits] [llvm/llvm-project] b85675: [lldb] Make the ClassTemplateDecl merging logic in...
Raphael Isemann via All-commits
all-commits at lists.llvm.org
Tue Jun 15 10:25:37 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b8567559cf3872d0cc2a0ed24a171da8b1ff400f
https://github.com/llvm/llvm-project/commit/b8567559cf3872d0cc2a0ed24a171da8b1ff400f
Author: Raphael Isemann <teemperor at gmail.com>
Date: 2021-06-15 (Tue, 15 Jun 2021)
Changed paths:
M lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
M lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
A lldb/test/API/lang/cpp/forward-declared-template-specialization/Makefile
A lldb/test/API/lang/cpp/forward-declared-template-specialization/TestCppForwardDeclaredTemplateSpecialization.py
A lldb/test/API/lang/cpp/forward-declared-template-specialization/main.cpp
A lldb/test/API/lang/cpp/incompatible-class-templates/Makefile
A lldb/test/API/lang/cpp/incompatible-class-templates/TestCppIncompatibleClassTemplates.py
A lldb/test/API/lang/cpp/incompatible-class-templates/main.cpp
A lldb/test/API/lang/cpp/incompatible-class-templates/other.cpp
M lldb/unittests/Symbol/TestTypeSystemClang.cpp
Log Message:
-----------
[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
More information about the All-commits
mailing list