Index: clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h =================================================================== --- clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h +++ clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h @@ -61,6 +61,14 @@ // conflict if they have overlapping source ranges. bool anyConflict(const llvm::SmallVectorImpl &FixIts, const SourceManager &SM); + +// Compares AST nodes by source locations. +template struct CompareNode { + bool operator()(const NodeTy *N1, const NodeTy *N2) const { + return N1->getBeginLoc().getRawEncoding() < + N2->getBeginLoc().getRawEncoding(); + } +}; } // namespace internal } // end namespace clang Index: clang/lib/Analysis/UnsafeBufferUsage.cpp =================================================================== --- clang/lib/Analysis/UnsafeBufferUsage.cpp +++ clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -661,7 +661,11 @@ } struct WarningGadgetSets { - std::map>> byVar; + std::map>, + // To keep keys sorted by their locations in the map so that the + // order is deterministic: + clang::internal::CompareNode> + byVar; // These Gadgets are not related to pointer variables (e. g. temporaries). llvm::SmallVector, 16> noVar; }; Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp =================================================================== --- clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp +++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-local-var-span.cpp @@ -1,4 +1,3 @@ -// REQUIRES: !system-windows // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s typedef int * Int_ptr_t; typedef int Int_t;