-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[clang][AST] Added assert to prevent infinite recursion in computing layout #154134
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
[clang][AST] Added assert to prevent infinite recursion in computing layout #154134
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-clang Author: None (tgs-sc) ChangesWhile computing class layout, I met with infinite recursion. This happened while executing user expression in lldb as record type was incorrectly received from dwarf. This assert will replace the infinite recursion with an error and will simplify further debugging of such cases. Full diff: https://github.com/llvm/llvm-project/pull/154134.diff 1 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);
|
@fhahn, @AaronBallman, can you please look at his? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this can be hit by user-written expressions, I think an assert is actually the wrong fix; we should handle it gracefully. Otherwise, in asserts builds this is effectively a crash and in non-asserts builds it's still an infinite recursion.
CC @JDevlieghere @Michael137 for other opinions on the lldb side
Does infinite recursion mean that we are building the ill-formed AST for the expression entered by the user? |
The user expression only triggered parsing the part of dwarf that was incorrectly created.
Yes, that's exactly the reason why i want to add this assert here. Simply because it works better than infinite recursion. This is an original PR, this patch was created from: |
We have an error handling & assert policy for LLDB. If this can be triggered by user input then it should not be an assert. |
Personally i think the assert makes sense here (if a user can't ever create an AST like that, which IIUC they can't). Although it is true that we try not to assert on user input as Jonas mentioned, this was a bug in LLDB's AST creation. Malformed DWARF can already cause all sorts of Clang assertions to trigger anyway, so rejecting adding an assert into Clang just because LLDB may create an incorrect AST out of it seems counter-productive |
@fhahn, @AaronBallman, can you please give your opinion on this situation? |
I think @AaronBallman is currently OOO until the end of the month. I'll go ahead and LGTM it, but please give @cor3ntin (or another maintainer) some time to interject. |
…layout While computing class layout, I met with infinite recursion. This happened while executing user expression in lldb as record type was incorrectly received from dwarf. This assert will replace the infinite recursion with an error and will simplify further debugging of such cases.
0e76183
to
207f702
Compare
@tgs-sc Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
While computing class layout, I met with infinite recursion. This happened while executing user expression in lldb as record type was incorrectly received from dwarf. This assert will replace the infinite recursion with an error and will simplify further debugging of such cases.