|
1 | 1 | Auto generated patch. Do not edit or delete it, even if empty. |
| 2 | +diff -ruN --strip-trailing-cr a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp |
| 3 | +--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp |
| 4 | ++++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp |
| 5 | +@@ -2008,94 +2008,28 @@ |
| 6 | + |
| 7 | + static std::optional<clang::APValue> MakeAPValue(const clang::ASTContext &ast, |
| 8 | + CompilerType clang_type, |
| 9 | +- uint64_t value, |
| 10 | +- const DWARFDIE &die) { |
| 11 | ++ uint64_t value) { |
| 12 | + std::optional<uint64_t> bit_width = |
| 13 | + llvm::expectedToOptional(clang_type.GetBitSize(nullptr)); |
| 14 | + if (!bit_width) |
| 15 | + return std::nullopt; |
| 16 | + |
| 17 | + bool is_signed = false; |
| 18 | ++ const bool is_integral = clang_type.IsIntegerOrEnumerationType(is_signed); |
| 19 | + |
| 20 | +- if (clang_type.IsIntegerOrEnumerationType(is_signed) || |
| 21 | +- clang_type.IsMemberDataPointerType()) { |
| 22 | +- llvm::APSInt apint(*bit_width, !is_signed); |
| 23 | +- apint = value; |
| 24 | ++ llvm::APSInt apint(*bit_width, !is_signed); |
| 25 | ++ apint = value; |
| 26 | ++ |
| 27 | ++ if (is_integral) |
| 28 | + return clang::APValue(apint); |
| 29 | +- } |
| 30 | + |
| 31 | + // FIXME: we currently support a limited set of floating point types. |
| 32 | + // E.g., 16-bit floats are not supported. |
| 33 | +- if (clang_type.IsRealFloatingPointType()) { |
| 34 | +- llvm::APInt apint(*bit_width, value); |
| 35 | +- return clang::APValue(llvm::APFloat( |
| 36 | +- ast.getFloatTypeSemantics(ClangUtil::GetQualType(clang_type)), apint)); |
| 37 | +- } |
| 38 | +- |
| 39 | +- die.GetDWARF()->GetObjectFile()->GetModule()->ReportError( |
| 40 | +- "error: unsupported template value type in die {0:x16}, " |
| 41 | +- "please file a bug", |
| 42 | +- die.GetOffset()); |
| 43 | +- lldbassert(false && "Unsupported type for non-type template parameter"); |
| 44 | +- |
| 45 | +- return std::nullopt; |
| 46 | +-} |
| 47 | +- |
| 48 | +-clang::FieldDecl *DWARFASTParserClang::ResolveMemberDataPointerToFieldDecl( |
| 49 | +- const DWARFDIE &die, uint64_t member_byte_offset) { |
| 50 | +- Log *log = GetLog(DWARFLog::TypeCompletion); |
| 51 | +- |
| 52 | +- DWARFDIE type_die = die.GetReferencedDIE(DW_AT_type); |
| 53 | +- assert(type_die && type_die.Tag() == DW_TAG_ptr_to_member_type && |
| 54 | +- "DW_AT_type of a member data pointer must be " |
| 55 | +- "DW_TAG_ptr_to_member_type"); |
| 56 | +- |
| 57 | +- DWARFDIE containing_die = type_die.GetReferencedDIE(DW_AT_containing_type); |
| 58 | +- if (!containing_die) { |
| 59 | +- LLDB_LOG(log, |
| 60 | +- "ResolveMemberDataPointerToFieldDecl: DIE {0:x16} — " |
| 61 | +- "DW_TAG_ptr_to_member_type {1:x16} has no DW_AT_containing_type", |
| 62 | +- die.GetOffset(), type_die.GetOffset()); |
| 63 | +- return nullptr; |
| 64 | +- } |
| 65 | +- |
| 66 | +- Type *containing_type = die.ResolveTypeUID(containing_die); |
| 67 | +- if (!containing_type) { |
| 68 | +- LLDB_LOG(log, |
| 69 | +- "ResolveMemberDataPointerToFieldDecl: DIE {0:x16} — " |
| 70 | +- "failed to resolve containing type {1:x16}", |
| 71 | +- die.GetOffset(), containing_die.GetOffset()); |
| 72 | +- return nullptr; |
| 73 | +- } |
| 74 | +- |
| 75 | +- CompilerType containing_ct = containing_type->GetFullCompilerType(); |
| 76 | +- auto *record_decl = |
| 77 | +- m_ast.GetAsCXXRecordDecl(containing_ct.GetOpaqueQualType()); |
| 78 | +- if (!record_decl) { |
| 79 | +- LLDB_LOG(log, |
| 80 | +- "ResolveMemberDataPointerToFieldDecl: DIE {0:x16} — " |
| 81 | +- "containing type {1:x16} is not a CXXRecordDecl", |
| 82 | +- die.GetOffset(), containing_die.GetOffset()); |
| 83 | +- return nullptr; |
| 84 | +- } |
| 85 | +- |
| 86 | +- clang::ASTContext &ast = m_ast.getASTContext(); |
| 87 | +- for (auto *field : record_decl->fields()) { |
| 88 | +- if (ast.getFieldOffset(field) / 8 == member_byte_offset) { |
| 89 | +- LLDB_LOG(log, |
| 90 | +- "ResolveMemberDataPointerToFieldDecl: DIE {0:x16} — " |
| 91 | +- "resolved to field '{1}' at byte offset {2} in {3}", |
| 92 | +- die.GetOffset(), field->getName(), member_byte_offset, |
| 93 | +- containing_die.GetName()); |
| 94 | +- return field; |
| 95 | +- } |
| 96 | +- } |
| 97 | ++ if (!clang_type.IsRealFloatingPointType()) |
| 98 | ++ return std::nullopt; |
| 99 | + |
| 100 | +- LLDB_LOG(log, |
| 101 | +- "ResolveMemberDataPointerToFieldDecl: DIE {0:x16} — " |
| 102 | +- "no field found at byte offset {1} in {2}", |
| 103 | +- die.GetOffset(), member_byte_offset, containing_die.GetName()); |
| 104 | +- return nullptr; |
| 105 | ++ return clang::APValue(llvm::APFloat( |
| 106 | ++ ast.getFloatTypeSemantics(ClangUtil::GetQualType(clang_type)), apint)); |
| 107 | + } |
| 108 | + |
| 109 | + bool DWARFASTParserClang::ParseTemplateDIE( |
| 110 | +@@ -2180,24 +2114,7 @@ |
| 111 | + name = nullptr; |
| 112 | + |
| 113 | + if (tag == DW_TAG_template_value_parameter && uval64_valid) { |
| 114 | +- if (auto value = MakeAPValue(ast, clang_type, uval64, die)) { |
| 115 | +- // For pointer-to-member types, try to resolve to the actual FieldDecl |
| 116 | +- if (clang_type.IsMemberDataPointerType()) { |
| 117 | +- if (auto *field = |
| 118 | +- ResolveMemberDataPointerToFieldDecl(die, uval64)) { |
| 119 | +- template_param_infos.InsertArg( |
| 120 | +- name, clang::TemplateArgument( |
| 121 | +- field, ClangUtil::GetQualType(clang_type), |
| 122 | +- is_default_template_arg)); |
| 123 | +- return true; |
| 124 | +- } |
| 125 | +- // Failed to resolve FieldDecl, fall through to integer path |
| 126 | +- die.GetDWARF()->GetObjectFile()->GetModule()->ReportError( |
| 127 | +- "error: failed to resolve member data pointer to FieldDecl " |
| 128 | +- "in die {0:x16}, please file a bug", |
| 129 | +- die.GetOffset()); |
| 130 | +- } |
| 131 | +- |
| 132 | ++ if (auto value = MakeAPValue(ast, clang_type, uval64)) { |
| 133 | + template_param_infos.InsertArg( |
| 134 | + name, clang::TemplateArgument( |
| 135 | + ast, ClangUtil::GetQualType(clang_type), |
| 136 | +diff -ruN --strip-trailing-cr a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h |
| 137 | +--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h |
| 138 | ++++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h |
| 139 | +@@ -185,13 +185,6 @@ |
| 140 | + lldb_private::TypeSystemClang::TemplateParameterInfos |
| 141 | + &template_param_infos); |
| 142 | + |
| 143 | +- /// Given a DW_TAG_template_value_parameter DIE whose type is a |
| 144 | +- /// pointer-to-data-member, follow the DWARF chain to find the FieldDecl |
| 145 | +- /// at the given byte offset within the containing class. |
| 146 | +- clang::FieldDecl *ResolveMemberDataPointerToFieldDecl( |
| 147 | +- const lldb_private::plugin::dwarf::DWARFDIE &die, |
| 148 | +- uint64_t member_byte_offset); |
| 149 | +- |
| 150 | + bool ParseTemplateParameterInfos( |
| 151 | + const lldb_private::plugin::dwarf::DWARFDIE &parent_die, |
| 152 | + lldb_private::TypeSystemClang::TemplateParameterInfos |
| 153 | +diff -ruN --strip-trailing-cr a/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/Makefile b/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/Makefile |
| 154 | +--- a/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/Makefile |
| 155 | ++++ b/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/Makefile |
| 156 | +@@ -1,3 +0,0 @@ |
| 157 | +-CXX_SOURCES := main.cpp |
| 158 | +- |
| 159 | +-include Makefile.rules |
| 160 | +diff -ruN --strip-trailing-cr a/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/TestCppNonTypeTemplateParamPtrToMember.py b/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/TestCppNonTypeTemplateParamPtrToMember.py |
| 161 | +--- a/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/TestCppNonTypeTemplateParamPtrToMember.py |
| 162 | ++++ b/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/TestCppNonTypeTemplateParamPtrToMember.py |
| 163 | +@@ -1,14 +0,0 @@ |
| 164 | +-import lldb |
| 165 | +-from lldbsuite.test.decorators import * |
| 166 | +-from lldbsuite.test.lldbtest import * |
| 167 | +-from lldbsuite.test import lldbutil |
| 168 | +- |
| 169 | +- |
| 170 | +-class TestCase(TestBase): |
| 171 | +- def test_member_data_pointer(self): |
| 172 | +- """Member data pointer NTTPs: MemberData<&S::x> vs MemberData<&S::y>""" |
| 173 | +- self.build() |
| 174 | +- self.dbg.CreateTarget(self.getBuildArtifact("a.out")) |
| 175 | +- # Both must be resolvable as distinct specializations. |
| 176 | +- self.expect_expr("md1", result_type="MemberData<&S::x>") |
| 177 | +- self.expect_expr("md2", result_type="MemberData<&S::y>") |
| 178 | +diff -ruN --strip-trailing-cr a/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/main.cpp b/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/main.cpp |
| 179 | +--- a/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/main.cpp |
| 180 | ++++ b/lldb/test/API/lang/cpp/non-type-template-param-member-ptr/main.cpp |
| 181 | +@@ -1,16 +0,0 @@ |
| 182 | +-struct S { |
| 183 | +- int x; |
| 184 | +- int y; |
| 185 | +-}; |
| 186 | +- |
| 187 | +-// --- Member data pointer NTTP --- |
| 188 | +-template <int S::*P> struct MemberData { |
| 189 | +- int get(S &s) { return s.*P; } |
| 190 | +-}; |
| 191 | +-MemberData<&S::x> md1; |
| 192 | +-MemberData<&S::y> md2; |
| 193 | +- |
| 194 | +-int main() { |
| 195 | +- S s{1, 2}; |
| 196 | +- return md1.get(s) + md2.get(s); |
| 197 | +-} |
0 commit comments