r175289 - Fixed diagnostic nondeterministic order bug (pr14901).
Enea Zaffanella
zaffanella at cs.unipr.it
Fri Feb 15 12:09:55 PST 2013
Author: enea
Date: Fri Feb 15 14:09:55 2013
New Revision: 175289
URL: http://llvm.org/viewvc/llvm-project?rev=175289&view=rev
Log:
Fixed diagnostic nondeterministic order bug (pr14901).
Added:
cfe/trunk/test/Sema/uninit-det-order.c
Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=175289&r1=175288&r2=175289&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Fri Feb 15 14:09:55 2013
@@ -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;
Added: cfe/trunk/test/Sema/uninit-det-order.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-det-order.c?rev=175289&view=auto
==============================================================================
--- cfe/trunk/test/Sema/uninit-det-order.c (added)
+++ cfe/trunk/test/Sema/uninit-det-order.c Fri Feb 15 14:09:55 2013
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -Wuninitialized -fsyntax-only %s 2>&1 | FileCheck %s
+
+void pr14901(int a) {
+ int b, c;
+ a = b;
+ a = c;
+}
+
+// CHECK: 5:8: warning: variable 'b' is uninitialized when used here
+// CHECK: 4:9: note: initialize the variable 'b' to silence this warning
+// CHECK: 6:8: warning: variable 'c' is uninitialized when used here
+// CHECK: 4:12: note: initialize the variable 'c' to silence this warning
+
More information about the cfe-commits
mailing list