From f85d98285e8eb6bcf42c2821e3b03abfc22ffac9 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Thu, 26 Mar 2015 08:32:49 +0000 Subject: [Modules] Make "#pragma weak" undeclared identifiers be tracked deterministically. This fixes a latent issue where even Clang's Sema (and diagnostics) were non-deterministic in the face of this pragma. The fix is super simple -- just use a MapVector so we track the order in which these are parsed (or imported). Especially considering how rare they are, this seems like the perfect tradeoff. I've also simplified the client code with judicious use of auto and range based for loops. I've added some pretty hilarious code to my stress test which now survives the binary diff without issue. llvm-svn: 233261 --- clang/lib/Sema/Sema.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'clang/lib/Sema/Sema.cpp') diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index a1a9b9d0b8c..6825dfa41fa 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -524,14 +524,8 @@ void Sema::LoadExternalWeakUndeclaredIdentifiers() { SmallVector, 4> WeakIDs; ExternalSource->ReadWeakUndeclaredIdentifiers(WeakIDs); - for (unsigned I = 0, N = WeakIDs.size(); I != N; ++I) { - llvm::DenseMap::iterator Pos - = WeakUndeclaredIdentifiers.find(WeakIDs[I].first); - if (Pos != WeakUndeclaredIdentifiers.end()) - continue; - - WeakUndeclaredIdentifiers.insert(WeakIDs[I]); - } + for (auto &WeakID : WeakIDs) + WeakUndeclaredIdentifiers.insert(WeakID); } @@ -694,16 +688,13 @@ void Sema::ActOnEndOfTranslationUnit() { } // Check for #pragma weak identifiers that were never declared - // FIXME: This will cause diagnostics to be emitted in a non-determinstic - // order! Iterating over a densemap like this is bad. LoadExternalWeakUndeclaredIdentifiers(); - for (llvm::DenseMap::iterator - I = WeakUndeclaredIdentifiers.begin(), - E = WeakUndeclaredIdentifiers.end(); I != E; ++I) { - if (I->second.getUsed()) continue; + for (auto WeakID : WeakUndeclaredIdentifiers) { + if (WeakID.second.getUsed()) + continue; - Diag(I->second.getLocation(), diag::warn_weak_identifier_undeclared) - << I->first; + Diag(WeakID.second.getLocation(), diag::warn_weak_identifier_undeclared) + << WeakID.first; } if (LangOpts.CPlusPlus11 && -- cgit v1.2.3