Resolver: Fix incorrect DenseMap mapping info.
authorRui Ueyama <ruiu@google.com>
Mon, 9 Mar 2015 02:00:54 +0000 (02:00 +0000)
committerRui Ueyama <ruiu@google.com>
Mon, 9 Mar 2015 02:00:54 +0000 (02:00 +0000)
Previously, getEmptyKey and getTombstoneKey return the same value
in the sense of isEqual defined by the same class, although they
need to be distinct values. This could confuse DenseMap.

We didn't see any issue by this wrong code because we don't delete
elements from the symbol table. We only add or replace elements.
But this is a bug and needs to be fixed anyway.

llvm-svn: 231618

lld/include/lld/Core/SymbolTable.h

index f218c6e..683ed65 100644 (file)
@@ -82,11 +82,13 @@ private:
 
   struct StringRefMappingInfo {
     static StringRef getEmptyKey() { return StringRef(); }
-    static StringRef getTombstoneKey() { return StringRef(" ", 0); }
+    static StringRef getTombstoneKey() { return StringRef(" ", 1); }
     static unsigned getHashValue(StringRef const val) {
-                                               return llvm::HashString(val); }
-    static bool isEqual(StringRef const lhs,
-                        StringRef const rhs) { return lhs.equals(rhs); }
+      return llvm::HashString(val);
+    }
+    static bool isEqual(StringRef const lhs, StringRef const rhs) {
+      return lhs.equals(rhs);
+    }
   };
   typedef llvm::DenseMap<StringRef, const Atom *,
                                            StringRefMappingInfo> NameToAtom;