From 2a2bb1855a23b5415d3f6d0e1699c3c37c12ad28 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 10 Feb 2009 22:28:19 +0000 Subject: [PATCH] make -dM emit macros in a deterministic (sorted) order instead of random hash table order, I don't like non-determinstic output. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64248 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/PrintPreprocessedOutput.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Driver/PrintPreprocessedOutput.cpp b/Driver/PrintPreprocessedOutput.cpp index 7aceb7a750..3df6a82b9e 100644 --- a/Driver/PrintPreprocessedOutput.cpp +++ b/Driver/PrintPreprocessedOutput.cpp @@ -583,7 +583,6 @@ static void PrintMacroDefinition(IdentifierInfo &II, const MacroInfo &MI, OS << ' '; llvm::SmallVector SpellingBuffer; - for (MacroInfo::tokens_iterator I = MI.tokens_begin(), E = MI.tokens_end(); I != E; ++I) { if (I->hasLeadingSpace()) @@ -599,6 +598,14 @@ static void PrintMacroDefinition(IdentifierInfo &II, const MacroInfo &MI, OS << "\n"; } +namespace { + struct SortMacrosByID { + typedef std::pair id_macro_pair; + bool operator()(const id_macro_pair &LHS, const id_macro_pair &RHS) const { + return strcmp(LHS.first->getName(), RHS.first->getName()) < 0; + } + }; +} /// DoPrintPreprocessedInput - This implements -E mode. /// @@ -629,9 +636,14 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, do PP.Lex(Tok); while (Tok.isNot(tok::eof)); + std::vector > MacrosByID; for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end(); I != E; ++I) - PrintMacroDefinition(*I->first, *I->second, PP, OS); + MacrosByID.push_back(*I); + std::sort(MacrosByID.begin(), MacrosByID.end(), SortMacrosByID()); + + for (unsigned i = 0, e = MacrosByID.size(); i != e; ++i) + PrintMacroDefinition(*MacrosByID[i].first, *MacrosByID[i].second, PP, OS); } else { PrintPPOutputPPCallbacks *Callbacks; -- 2.40.0