-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lldb][DWARFASTParserClang] Added a check for the specialization existence #154123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[lldb][DWARFASTParserClang] Added a check for the specialization existence #154123
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-lldb @llvm/pr-subscribers-clang Author: None (tgs-sc) Changes
Full diff: https://github.com/llvm/llvm-project/pull/154123.diff 2 Files Affected:
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp
index 6d819031cbef4..93571543f1c7d 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -187,6 +187,8 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() {
// Check the bases.
for (const CXXBaseSpecifier &Base : Class->bases()) {
const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
+ // Assert to prevent infinite recursion.
+ assert(BaseDecl != Class && "Class cannot inherit from itself.");
CharUnits EmptySize;
const ASTRecordLayout &Layout = Context.getASTRecordLayout(BaseDecl);
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index c76d67b47b336..6643751cd237a 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1873,6 +1873,22 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
clang_type =
m_ast.CreateClassTemplateSpecializationType(class_specialization_decl);
+ // Try to find an existing specialization with these template arguments and
+ // template parameter list.
+ void *InsertPos = nullptr;
+ if (!class_template_decl->findSpecialization(template_param_infos.GetArgs(),
+ InsertPos))
+ // Add this specialization to the class template.
+ class_template_decl->AddSpecialization(class_specialization_decl,
+ InsertPos);
+ else {
+ dwarf->GetObjectFile()->GetModule()->ReportError(
+ "SymbolFileDWARF({0:p}) - Specialization for "
+ "clang::ClassTemplateDecl({1:p}) already exists.",
+ static_cast<void *>(this), static_cast<void *>(class_template_decl));
+ return TypeSP();
+ }
+
m_ast.SetMetadata(class_template_decl, metadata);
m_ast.SetMetadata(class_specialization_decl, metadata);
}
|
25d756b
to
835700e
Compare
Hmm yea guarding against incorrect DWARF has been mostly best effort. Can you provide a test-case for this? |
Also, please split out the clang change into a separate PR. The clang maintainers can comment there on whether that's a useful thing to have in place |
Sure. Originally this bug was discovered by debugging llc, but I minimized it to such example: --- b1.cc ---
--- b2.cc ---
Compilation: |
…tence While debugging an application with incorrect dwarf information, where DW_TAG_template_value_parameter was lost, I found that lldb does not check that the corresponding specialization exists. As a result, at the stage when ASTImporter works, the type is completed in such a way that it inherits from itself. And during the calculation of layout, an infinite recursion occurs. To catch this error, I added a corresponding check at the stage of restoring the type from dwarf information.
835700e
to
f19ba13
Compare
Addressed. I made a PR (#154134) to clang with adding assert as seeing backtrace with 16k functions is not very nice. |
@Michael137, is it OK? |
@JDevlieghere, can you also please look at this? |
This is a reproduction in godbolt: https://godbolt.org/z/aKWETszEY. |
Thanks, we will somehow need to turn this into a test. I'll have a more detailed look later in the week |
Uh oh!
There was an error while loading. Please reload this page.