Skip to content

Commit 5da7568

Browse files
committed
[clang][ASTImporter] Only reorder fields of RecordDecls (llvm#77079)
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)
1 parent f7efaf5 commit 5da7568

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

clang/lib/AST/ASTImporter.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,23 +1911,25 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
19111911
return ToDCOrErr.takeError();
19121912
}
19131913

1914-
DeclContext *ToDC = *ToDCOrErr;
1915-
// Remove all declarations, which may be in wrong order in the
1916-
// lexical DeclContext and then add them in the proper order.
1917-
for (auto *D : FromDC->decls()) {
1918-
if (!MightNeedReordering(D))
1919-
continue;
1914+
if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
1915+
DeclContext *ToDC = *ToDCOrErr;
1916+
// Remove all declarations, which may be in wrong order in the
1917+
// lexical DeclContext and then add them in the proper order.
1918+
for (auto *D : FromRD->decls()) {
1919+
if (!MightNeedReordering(D))
1920+
continue;
19201921

1921-
assert(D && "DC contains a null decl");
1922-
if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
1923-
// Remove only the decls which we successfully imported.
1924-
assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
1925-
// Remove the decl from its wrong place in the linked list.
1926-
ToDC->removeDecl(ToD);
1927-
// Add the decl to the end of the linked list.
1928-
// This time it will be at the proper place because the enclosing for
1929-
// loop iterates in the original (good) order of the decls.
1930-
ToDC->addDeclInternal(ToD);
1922+
assert(D && "DC contains a null decl");
1923+
if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
1924+
// Remove only the decls which we successfully imported.
1925+
assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
1926+
// Remove the decl from its wrong place in the linked list.
1927+
ToDC->removeDecl(ToD);
1928+
// Add the decl to the end of the linked list.
1929+
// This time it will be at the proper place because the enclosing for
1930+
// loop iterates in the original (good) order of the decls.
1931+
ToDC->addDeclInternal(ToD);
1932+
}
19311933
}
19321934
}
19331935

0 commit comments

Comments
 (0)