[llvm] dad2e92 - Temporarily Revert "[Support] Make UniqueStringSaver wrap a StringSet"

Eric Christopher via llvm-commits llvm-commits at lists.llvm.org
Thu May 14 19:19:08 PDT 2020


Author: Eric Christopher
Date: 2020-05-14T19:18:20-07:00
New Revision: dad2e92eaf531500af5ab9ee3350e3e186944185

URL: https://github.com/llvm/llvm-project/commit/dad2e92eaf531500af5ab9ee3350e3e186944185
DIFF: https://github.com/llvm/llvm-project/commit/dad2e92eaf531500af5ab9ee3350e3e186944185.diff

LOG: Temporarily Revert "[Support] Make UniqueStringSaver wrap a StringSet"
as it's causing asan failures in clangd. Followed up offline
with repro instructions.

This reverts commit 29560a89ddcaf3af9b8a73d98d968a0911d21e27.

Added: 
    

Modified: 
    llvm/include/llvm/Support/StringSaver.h
    llvm/lib/Support/StringSaver.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/StringSaver.h b/llvm/include/llvm/Support/StringSaver.h
index b6b3c054d07d..c54044e3986c 100644
--- a/llvm/include/llvm/Support/StringSaver.h
+++ b/llvm/include/llvm/Support/StringSaver.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_SUPPORT_STRINGSAVER_H
 #define LLVM_SUPPORT_STRINGSAVER_H
 
-#include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Allocator.h"
@@ -36,8 +36,12 @@ class StringSaver final {
 ///
 /// Compared to StringSaver, it does more work but avoids saving the same string
 /// multiple times.
+///
+/// Compared to StringPool, it performs fewer allocations but doesn't support
+/// refcounting/deletion.
 class UniqueStringSaver final {
-  StringSet<BumpPtrAllocator &> Strings;
+  StringSaver Strings;
+  llvm::DenseSet<llvm::StringRef> Unique;
 
 public:
   UniqueStringSaver(BumpPtrAllocator &Alloc) : Strings(Alloc) {}

diff  --git a/llvm/lib/Support/StringSaver.cpp b/llvm/lib/Support/StringSaver.cpp
index 999f37a9a75d..f7ccfb97ea79 100644
--- a/llvm/lib/Support/StringSaver.cpp
+++ b/llvm/lib/Support/StringSaver.cpp
@@ -19,5 +19,8 @@ StringRef StringSaver::save(StringRef S) {
 }
 
 StringRef UniqueStringSaver::save(StringRef S) {
-  return Strings.insert(S).first->getKey();
+  auto R = Unique.insert(S);
+  if (R.second)                 // cache miss, need to actually save the string
+    *R.first = Strings.save(S); // safe replacement with equal value
+  return *R.first;
 }


        


More information about the llvm-commits mailing list