Author: James Y Knight Date: 2026-03-21T23:11:29-04:00 New Revision: 3258d361cbc5d57e5e507004706eb36acf120066
URL: https://github.com/llvm/llvm-project/commit/3258d361cbc5d57e5e507004706eb36acf120066 DIFF: https://github.com/llvm/llvm-project/commit/3258d361cbc5d57e5e507004706eb36acf120066.diff LOG: [Clang] Use stable_sort in VerifyDiagnosticsConsumer. (#187827) The new code introduced for `-verify-directives` in PR #179835 enforces that the order of diagnostics matches the order of the directives. However, before checking this, it sorts the directives by SourceLocation. Perhaps non-obviously, all directives which appear inside a single comment are given the same SourceLocation, pointing to the beginning of the comment. While these are added in order they appear in the comment, the non-stable std::sort may non-detministically misorder them. Switching to stable_sort ensures the correct order is verified. This was observed as a random test failure on the checks in clang/test/CXX/drs/cwg25xx.cpp lines 250 and 264, in some builds of Clang. Note that those lines end in backslashes, and thus, despite appearances, the directives on the following lines are also within the same single comment. Added: Modified: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp Removed: ################################################################################ diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index d58492b09b537..1bfe644b2525a 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -1178,7 +1178,7 @@ static unsigned CheckResultsAreInOrder(DiagnosticsEngine &Diags, std::vector<const Directive *> Ordered(Unordered.size()); std::transform(Unordered.cbegin(), Unordered.cend(), Ordered.begin(), [](const std::unique_ptr<Directive> &D) { return &*D; }); - std::sort(Ordered.begin(), Ordered.end(), directiveComparator); + std::stable_sort(Ordered.begin(), Ordered.end(), directiveComparator); return Ordered; }; std::vector<const Directive *> OrderedErrors = sortDirectives(ED.Errors); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
