From f606c8d633e288a7d2ac95f7372af374dcab7f39 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 16 May 2016 08:50:27 +0000 Subject: ThinLTO: fix another non-determinism in bitcode writing GlobalVars Refs are initialized from a DenseSet. We can sort them using the value id to recover some determinism during serialization. From: Mehdi Amini llvm-svn: 269635 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index fff15e9..50e4ffe 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3213,8 +3213,15 @@ void ModuleBitcodeWriter::writeModuleLevelReferences( NameVals.push_back(getEncodedGVSummaryFlags(V)); auto *Summary = Index->getGlobalValueSummary(V); GlobalVarSummary *VS = cast(Summary); - for (auto Ref : VS->refs()) - NameVals.push_back(VE.getValueID(Ref.getValue())); + + // Compute refs in a separate vector to be able to sort them for determinism. + std::vector Refs; + Refs.reserve(VS->refs().size()); + for (auto &RI : VS->refs()) + Refs.push_back(VE.getValueID(RI.getValue())); + std::sort(Refs.begin(), Refs.end()); + NameVals.insert(NameVals.end(), Refs.begin(), Refs.end()); + Stream.EmitRecord(bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS, NameVals, FSModRefsAbbrev); NameVals.clear(); -- cgit v1.1