steven_wu created this revision. steven_wu added reviewers: jansvoboda11, akyrtzi, benlangmuir, vsapsai, rnk, dblaikie. Herald added subscribers: ributzka, mgrang. Herald added a project: All. steven_wu requested review of this revision. Herald added a project: clang.
Fix a non-deterministic issue in clang module generation, which the anonymous declaration number from a function context is not deterministic. This is due to the unstable iteration order for decls in scope so the order after moving the decls into function decl context is not deterministic. >From https://reviews.llvm.org/D135118, we can't use a set that preserves the order without the performance penalty. Fix the issue by sorting the decls based on raw encoding of their source location. rdar://104097976 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D141625 Files: clang/lib/Parse/ParseDecl.cpp Index: clang/lib/Parse/ParseDecl.cpp =================================================================== --- clang/lib/Parse/ParseDecl.cpp +++ clang/lib/Parse/ParseDecl.cpp @@ -6986,6 +6986,13 @@ continue; DeclsInPrototype.push_back(ND); } + // Sort DeclsInPrototype based on raw encoding of the source location. This + // provides a stable iterating order in DeclContext, which is important for + // tasks like ASTWriter for deterministic output. + llvm::sort(DeclsInPrototype, [](Decl *D1, Decl *D2) { + return D1->getLocation().getRawEncoding() < + D2->getLocation().getRawEncoding(); + }); } // Remember that we parsed a function type, and remember the attributes.
Index: clang/lib/Parse/ParseDecl.cpp =================================================================== --- clang/lib/Parse/ParseDecl.cpp +++ clang/lib/Parse/ParseDecl.cpp @@ -6986,6 +6986,13 @@ continue; DeclsInPrototype.push_back(ND); } + // Sort DeclsInPrototype based on raw encoding of the source location. This + // provides a stable iterating order in DeclContext, which is important for + // tasks like ASTWriter for deterministic output. + llvm::sort(DeclsInPrototype, [](Decl *D1, Decl *D2) { + return D1->getLocation().getRawEncoding() < + D2->getLocation().getRawEncoding(); + }); } // Remember that we parsed a function type, and remember the attributes.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits