[lldb][DWARFASTParserClang] Fix handle non-type template parameters in MakeAPValue#186629
Draft
[lldb][DWARFASTParserClang] Fix handle non-type template parameters in MakeAPValue#186629
Conversation
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
4b011cc to
e50fc9c
Compare
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
bb68828 to
5a99f0f
Compare
…e parameters in MakeAPValue
5a99f0f to
e10c34b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MakeAPValue in
DWARFASTParserClang.cppdid not handle pointer-to-member non-type template parameters (e.g.,template <int S::*P>), causing LLDB to silently produce incorrect results or crash.When DWARF encodes a pointer-to-member non-type template parameter, it uses
DW_TAG_template_value_parameterwith aDW_AT_const_valuerepresenting the byte offset of the member within the struct. MakeAPValue is responsible for converting this value into a clang APValue, but it only handled integer/enum and floating-point types. For pointer-to-member types, it returnedstd::nullopt.This caused the caller (
ParseTemplateDIE) to fall back to creating a type-only TemplateArgument (kind=Type) instead of a value-carrying one. When two specializations differ only by which member they point to (e.g.,Data<&S::x>vsData<&S::y>), both produce identical TemplateArguments. Clang's findSpecialization then treats the second as a duplicate, so only one specialization exists in the AST. The second variable becomes unresolvable.(See Debugger Evidence section below)
In more complex cases, this triggers an assertion failure in clang::CXXRecordDecl::setBases(): cast() argument of incompatible type.
Fix
Refactored MakeAPValue to comprehensively handle the Non-Type Template Parameters (NTTPs). Instead of a narrow check for integers and enums, the function now leverages CompilerType specialized queries to treat the following categories as integral values:
By converting these types into distinct clang::APValue objects, we ensure that
ParseTemplateDIEno longer falls back to type-only arguments. This allows the Clang AST to uniquely identify specializations that differ only by constant offsets or addresses.Additionally, the fix replaces the silent failure path with:
Known Limitation
The fix displays pointer-to-member template arguments as integer offsets (e.g., Data<0>, Data<4>) rather than symbolic names (e.g., Data<&S::x>). A follow-up patch will improve the display.
Test Plan
Added lldb/test/API/lang/cpp/non-type-template-param-member-ptr/ with a test that verifies both Data<&S::x> and Data<&S::y> are resolvable as distinct specializations.
Debugger Evidence
Collected at two
DW_TAG_template_value_parameterDIEs during ParseTemplateDIE, both with name="PtrToMember" andtype_class=256(eTypeClassMemberPointer): DIE0xcb: uval64=8; DIE0x1e9 : uval64=24These correspond to two members of Fiber:
Clang's ground truth AST correctly produces TemplateArgument decl (kind=Declaration) with distinct FieldDecl references for each specialization.
Full Paste
lldb prints:
lldb prints: