-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][ASTImporter] Only reorder fields of RecordDecls #77079
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][ASTImporter] Only reorder fields of RecordDecls #77079
Conversation
Prior to `e9536698720ec524cc8b72599363622bc1a31558` (https://reviews.llvm.org/D154764) we only re-ordered the fields of `RecordDecl`s. The change refactored this logic to make sure `FieldDecl`s are imported before other member decls. However, this change also widened the types of `DeclContext`s we consider for re-ordering from `RecordDecl` to anything that's a `DeclContext`. This seems to have been just a drive-by cleanup. Internally we've seen numerous crashes in LLDB where we try to perform this re-ordering fields of `ObjCInterfaceDecl`s. This patch restores old behaviour where we limit the re-ordering to just `RecordDecl`s.
@llvm/pr-subscribers-clang Author: Michael Buch (Michael137) ChangesPrior to Internally we've seen numerous crashes in LLDB where we try to perform this re-ordering fields of This patch restores old behaviour where we limit the re-ordering to just Full diff: https://github.com/llvm/llvm-project/pull/77079.diff 1 Files Affected:
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 9ffae72346f2af..f03ea6e09e8b7e 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -2034,10 +2034,14 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
return ToDCOrErr.takeError();
}
+ const auto *FromRD = dyn_cast<RecordDecl>(FromDC);
+ if (!FromRD)
+ return ChildErrors;
+
DeclContext *ToDC = *ToDCOrErr;
// Remove all declarations, which may be in wrong order in the
// lexical DeclContext and then add them in the proper order.
- for (auto *D : FromDC->decls()) {
+ for (auto *D : FromRD->decls()) {
if (!MightNeedReordering(D))
continue;
@@ -2055,7 +2059,7 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
}
// Import everything else.
- for (auto *From : FromDC->decls()) {
+ for (auto *From : FromRD->decls()) {
if (MightNeedReordering(From))
continue;
|
Need to sort out some test failures |
I can not check what caused exactly the problems but the change looks correct and in change D154764 there seems to be no reason for re-ordering at non-record objects. As an improvement, some tests could be added that check for re-ordering at |
Agreed it would be nice to get a test for this. We already have a test that checks re-ordering of |
I guess if there's some other type of ObjC decl that could trigger the re-ordering that would be useful. |
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.
Test would be nice, but generally this looks like a reasonable modification.
Tried to find a way to test the "objective-c fields aren't reordered" case. But after talking to some objective-c experts, there doesn't seem to be a good way to force such "incorrect field order", because it's strictly an in-order language. Reducing the LLDB crashes has been tricky because the reproducers require a somewhat complex setup. @balazske If you're ok with it, I'll go ahead and merge it like this, given it's essentially a minor revert. Separately I'll try to see if I can simplify the LLDB reproducer, but that'll take some time |
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.
This reordering is not a significant feature (and may change in the future) and no test existed before, it is enough (if this exists) if there is a GDB test for the crash.
Prior to `e9536698720ec524cc8b72599363622bc1a31558` (https://reviews.llvm.org/D154764) we only re-ordered the fields of `RecordDecl`s. The change refactored this logic to make sure `FieldDecl`s are imported before other member decls. However, this change also widened the types of `DeclContext`s we consider for re-ordering from `RecordDecl` to anything that's a `DeclContext`. This seems to have been just a drive-by cleanup. Internally we've seen numerous crashes in LLDB where we try to perform this re-ordering on fields of `ObjCInterfaceDecl`s. This patch restores old behaviour where we limit the re-ordering to just `RecordDecl`s. rdar://119343184 rdar://119636274 rdar://119832131 (cherry picked from commit 34dbadd)
Prior to `e9536698720ec524cc8b72599363622bc1a31558` (https://reviews.llvm.org/D154764) we only re-ordered the fields of `RecordDecl`s. The change refactored this logic to make sure `FieldDecl`s are imported before other member decls. However, this change also widened the types of `DeclContext`s we consider for re-ordering from `RecordDecl` to anything that's a `DeclContext`. This seems to have been just a drive-by cleanup. Internally we've seen numerous crashes in LLDB where we try to perform this re-ordering on fields of `ObjCInterfaceDecl`s. This patch restores old behaviour where we limit the re-ordering to just `RecordDecl`s. rdar://119343184 rdar://119636274 rdar://119832131
Prior to
e9536698720ec524cc8b72599363622bc1a31558
(https://reviews.llvm.org/D154764) we only re-ordered the fields ofRecordDecl
s. The change refactored this logic to make sureFieldDecl
s are imported before other member decls. However, this change also widened the types ofDeclContext
s we consider for re-ordering fromRecordDecl
to anything that's aDeclContext
. This seems to have been just a drive-by cleanup.Internally we've seen numerous crashes in LLDB where we try to perform this re-ordering on fields of
ObjCInterfaceDecl
s.This patch restores old behaviour where we limit the re-ordering to just
RecordDecl
s.rdar://119343184
rdar://119636274
rdar://119832131