aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/AnalysisBasedWarnings.cpp
diff options
context:
space:
mode:
authorEnea Zaffanella <zaffanella@cs.unipr.it>2013-02-15 20:09:55 +0000
committerEnea Zaffanella <zaffanella@cs.unipr.it>2013-02-15 20:09:55 +0000
commit3285c78041f80a26f6a947e2922e15c4af6e00bb (patch)
tree948643ba8bb27e8a497d144d6022df1d081d07d0 /lib/Sema/AnalysisBasedWarnings.cpp
parentdc2efa1c10c4646d692cc57db9fdbbebe3a48255 (diff)
Fixed diagnostic nondeterministic order bug (pr14901).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175289 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/AnalysisBasedWarnings.cpp')
-rw-r--r--lib/Sema/AnalysisBasedWarnings.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp
index c2b54d0280..e9cf7ccd85 100644
--- a/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/lib/Sema/AnalysisBasedWarnings.cpp
@@ -41,6 +41,7 @@
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/ImmutableMap.h"
+#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
@@ -1149,7 +1150,11 @@ struct SLocSort {
class UninitValsDiagReporter : public UninitVariablesHandler {
Sema &S;
typedef SmallVector<UninitUse, 2> UsesVec;
- typedef llvm::DenseMap<const VarDecl *, std::pair<UsesVec*, bool> > UsesMap;
+ typedef std::pair<UsesVec*, bool> MappedType;
+ // Prefer using MapVector to DenseMap, so that iteration order will be
+ // the same as insertion order. This is needed to obtain a deterministic
+ // order of diagnostics when calling flushDiagnostics().
+ typedef llvm::MapVector<const VarDecl *, MappedType> UsesMap;
UsesMap *uses;
public:
@@ -1158,11 +1163,11 @@ public:
flushDiagnostics();
}
- std::pair<UsesVec*, bool> &getUses(const VarDecl *vd) {
+ MappedType &getUses(const VarDecl *vd) {
if (!uses)
uses = new UsesMap();
- UsesMap::mapped_type &V = (*uses)[vd];
+ MappedType &V = (*uses)[vd];
UsesVec *&vec = V.first;
if (!vec)
vec = new UsesVec();
@@ -1181,12 +1186,10 @@ public:
void flushDiagnostics() {
if (!uses)
return;
-
- // FIXME: This iteration order, and thus the resulting diagnostic order,
- // is nondeterministic.
+
for (UsesMap::iterator i = uses->begin(), e = uses->end(); i != e; ++i) {
const VarDecl *vd = i->first;
- const UsesMap::mapped_type &V = i->second;
+ const MappedType &V = i->second;
UsesVec *vec = V.first;
bool hasSelfInit = V.second;