From dad2e92eaf531500af5ab9ee3350e3e186944185 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Thu, 14 May 2020 19:16:45 -0700 Subject: [PATCH] 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. --- llvm/include/llvm/Support/StringSaver.h | 8 ++++++-- llvm/lib/Support/StringSaver.cpp | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) 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 @@ public: /// /// 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 Strings; + StringSaver Strings; + llvm::DenseSet 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; }