Skip to content

Commit 34dbadd

Browse files
authored
[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
1 parent 036e48e commit 34dbadd

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
@@ -2034,23 +2034,25 @@ ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
20342034
return ToDCOrErr.takeError();
20352035
}
20362036

2037-
DeclContext *ToDC = *ToDCOrErr;
2038-
// Remove all declarations, which may be in wrong order in the
2039-
// lexical DeclContext and then add them in the proper order.
2040-
for (auto *D : FromDC->decls()) {
2041-
if (!MightNeedReordering(D))
2042-
continue;
2037+
if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2038+
DeclContext *ToDC = *ToDCOrErr;
2039+
// Remove all declarations, which may be in wrong order in the
2040+
// lexical DeclContext and then add them in the proper order.
2041+
for (auto *D : FromRD->decls()) {
2042+
if (!MightNeedReordering(D))
2043+
continue;
20432044

2044-
assert(D && "DC contains a null decl");
2045-
if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2046-
// Remove only the decls which we successfully imported.
2047-
assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2048-
// Remove the decl from its wrong place in the linked list.
2049-
ToDC->removeDecl(ToD);
2050-
// Add the decl to the end of the linked list.
2051-
// This time it will be at the proper place because the enclosing for
2052-
// loop iterates in the original (good) order of the decls.
2053-
ToDC->addDeclInternal(ToD);
2045+
assert(D && "DC contains a null decl");
2046+
if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2047+
// Remove only the decls which we successfully imported.
2048+
assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2049+
// Remove the decl from its wrong place in the linked list.
2050+
ToDC->removeDecl(ToD);
2051+
// Add the decl to the end of the linked list.
2052+
// This time it will be at the proper place because the enclosing for
2053+
// loop iterates in the original (good) order of the decls.
2054+
ToDC->addDeclInternal(ToD);
2055+
}
20542056
}
20552057
}
20562058

0 commit comments

Comments
 (0)