summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-04 01:54:10 +0000
committerChris Lattner <sabre@nondot.org>2009-02-04 01:54:10 +0000
commit4715f6395ef152fd92c9b74d5f3e62e2cff29d27 (patch)
tree494b6a0b387a23152253f4fd7d1f6421e28792a6 /include
parente20e790074f6a8274f5c8ad607ed3fbd1c6626c6 (diff)
downloadllvm-4715f6395ef152fd92c9b74d5f3e62e2cff29d27.tar.gz
llvm-4715f6395ef152fd92c9b74d5f3e62e2cff29d27.tar.bz2
llvm-4715f6395ef152fd92c9b74d5f3e62e2cff29d27.tar.xz
fix a pretty serious bug in StringMap where GetOrCreate(strstart,strend, z)
would not set new values to Z. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63707 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/StringMap.h25
1 files changed, 16 insertions, 9 deletions
diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h
index aec84a9503..08418ee3c1 100644
--- a/include/llvm/ADT/StringMap.h
+++ b/include/llvm/ADT/StringMap.h
@@ -34,6 +34,7 @@ class StringMapEntryInitializer {
public:
template <typename InitTy>
static void Initialize(StringMapEntry<ValueTy> &T, InitTy InitVal) {
+ T.second = InitVal;
}
};
@@ -195,7 +196,7 @@ public:
}
static StringMapEntry *Create(const char *KeyStart, const char *KeyEnd) {
- return Create(KeyStart, KeyEnd, 0);
+ return Create(KeyStart, KeyEnd, ValueTy());
}
/// GetStringMapEntryFromValue - Given a value that is known to be embedded
@@ -240,6 +241,17 @@ public:
StringMap() : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {}
explicit StringMap(unsigned InitialSize)
: StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))) {}
+ explicit StringMap(const StringMap &RHS)
+ : StringMapImpl(static_cast<unsigned>(sizeof(MapEntryTy))) {
+ assert(RHS.empty() &&
+ "Copy ctor from non-empty stringmap not implemented yet!");
+ }
+ void operator=(const StringMap &RHS) {
+ assert(RHS.empty() &&
+ "assignment from non-empty stringmap not implemented yet!");
+ clear();
+ }
+
AllocatorTy &getAllocator() { return Allocator; }
const AllocatorTy &getAllocator() const { return Allocator; }
@@ -292,13 +304,11 @@ public:
}
ValueTy& operator[](const char *Key) {
- value_type& entry = GetOrCreateValue(Key, Key + strlen(Key));
- return entry.getValue();
+ return GetOrCreateValue(Key, Key + strlen(Key)).getValue();
}
ValueTy& operator[](const std::string &Key) {
const char* key_start = (Key.empty() ? NULL : &Key[0]);
- value_type& entry = GetOrCreateValue(key_start, key_start + Key.size());
- return entry.getValue();
+ return GetOrCreateValue(key_start, key_start + Key.size()).getValue();
}
size_type count(const char *KeyStart, const char *KeyEnd) const {
@@ -378,7 +388,7 @@ public:
StringMapEntry<ValueTy> &GetOrCreateValue(const char *KeyStart,
const char *KeyEnd) {
- return GetOrCreateValue(KeyStart, KeyEnd, 0);
+ return GetOrCreateValue(KeyStart, KeyEnd, ValueTy());
}
/// remove - Remove the specified key/value pair from the map, but do not
@@ -411,9 +421,6 @@ public:
clear();
free(TheTable);
}
-private:
- StringMap(const StringMap &); // FIXME: Implement.
- void operator=(const StringMap &); // FIXME: Implement.
};