[llvm] r187866 - YAMLTraits.h: replace DenseMap that used a bad implementation of DenseMapInfo
Dmitri Gribenko
gribozavr at gmail.com
Tue Aug 6 22:51:27 PDT 2013
Author: gribozavr
Date: Wed Aug 7 00:51:27 2013
New Revision: 187866
URL: http://llvm.org/viewvc/llvm-project?rev=187866&view=rev
Log:
YAMLTraits.h: replace DenseMap that used a bad implementation of DenseMapInfo
for StringRef with a StringMap
The bug is that the empty key compares equal to the tombstone key.
Also added an assertion to DenseMap to catch similar bugs in future.
Modified:
llvm/trunk/include/llvm/ADT/DenseMap.h
llvm/trunk/include/llvm/Support/YAMLTraits.h
llvm/trunk/lib/Object/YAML.cpp
llvm/trunk/lib/Support/YAMLTraits.cpp
Modified: llvm/trunk/include/llvm/ADT/DenseMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMap.h?rev=187866&r1=187865&r2=187866&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/DenseMap.h (original)
+++ llvm/trunk/include/llvm/ADT/DenseMap.h Wed Aug 7 00:51:27 2013
@@ -606,6 +606,9 @@ public:
}
void init(unsigned InitBuckets) {
+ assert(!KeyInfoT::isEqual(this->getEmptyKey(), this->getTombstoneKey()) &&
+ "Bad implementation of KeyInfoT: empty key and tombstone key "
+ "should be different");
if (allocateBuckets(InitBuckets)) {
this->BaseT::initEmpty();
} else {
Modified: llvm/trunk/include/llvm/Support/YAMLTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLTraits.h?rev=187866&r1=187865&r2=187866&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/YAMLTraits.h (original)
+++ llvm/trunk/include/llvm/Support/YAMLTraits.h Wed Aug 7 00:51:27 2013
@@ -14,7 +14,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
@@ -760,15 +760,7 @@ private:
}
static inline bool classof(const MapHNode *) { return true; }
- struct StrMappingInfo {
- static StringRef getEmptyKey() { return StringRef(); }
- static StringRef getTombstoneKey() { return StringRef(" ", 0); }
- static unsigned getHashValue(StringRef const val) {
- return llvm::HashString(val); }
- static bool isEqual(StringRef const lhs,
- StringRef const rhs) { return lhs.equals(rhs); }
- };
- typedef llvm::DenseMap<StringRef, HNode*, StrMappingInfo> NameToNode;
+ typedef llvm::StringMap<HNode*> NameToNode;
bool isValidKey(StringRef key);
Modified: llvm/trunk/lib/Object/YAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/YAML.cpp?rev=187866&r1=187865&r2=187866&view=diff
==============================================================================
--- llvm/trunk/lib/Object/YAML.cpp (original)
+++ llvm/trunk/lib/Object/YAML.cpp Wed Aug 7 00:51:27 2013
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Object/YAML.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
Modified: llvm/trunk/lib/Support/YAMLTraits.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/YAMLTraits.cpp?rev=187866&r1=187865&r2=187866&view=diff
==============================================================================
--- llvm/trunk/lib/Support/YAMLTraits.cpp (original)
+++ llvm/trunk/lib/Support/YAMLTraits.cpp Wed Aug 7 00:51:27 2013
@@ -127,8 +127,8 @@ void Input::endMapping() {
return;
for (MapHNode::NameToNode::iterator i = MN->Mapping.begin(),
End = MN->Mapping.end(); i != End; ++i) {
- if (!MN->isValidKey(i->first)) {
- setError(i->second, Twine("unknown key '") + i->first + "'");
+ if (!MN->isValidKey(i->first())) {
+ setError(i->second, Twine("unknown key '") + i->first() + "'");
break;
}
}
More information about the llvm-commits
mailing list