[llvm] 8bb9414 - [Demangle] use std::string_view::data rather than &*std::string_view::begin

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 13 10:20:26 PDT 2023


Author: Nick Desaulniers
Date: 2023-07-13T10:20:09-07:00
New Revision: 8bb9414f1474d6a8caed2e7be5f1d3d999c8bae1

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

LOG: [Demangle] use std::string_view::data rather than &*std::string_view::begin

To fix expensive check builds that were failing when using MSVC's
std::string_view::iterator::operator*, I added a few expressions like
&*std::string_view::begin.  @nico pointed out that this is literally the
same thing and more clearly expressed as std::string_view::data.

Link: https://github.com/llvm/llvm-project/issues/63740

Reviewed By: #libc_abi, ldionne, philnik, MaskRay

Differential Revision: https://reviews.llvm.org/D154876

Added: 
    

Modified: 
    libcxxabi/src/demangle/ItaniumDemangle.h
    llvm/include/llvm/Demangle/ItaniumDemangle.h
    llvm/lib/Demangle/ItaniumDemangle.cpp
    llvm/lib/Demangle/MicrosoftDemangle.cpp

Removed: 
    


################################################################################
diff  --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index e39900ed8cb076..28562f02144670 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -2342,7 +2342,7 @@ template <class Float> class FloatLiteralImpl : public Node {
         Float value;
         char buf[sizeof(Float)];
       };
-      const char *t = &*Contents.begin();
+      const char *t = Contents.data();
       const char *last = t + N;
       char *e = buf;
       for (; t != last; ++t, ++e) {
@@ -3719,7 +3719,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() {
       std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len);
       std::string_view Proto;
       {
-        ScopedOverride<const char *> SaveFirst(First, &*ProtoSourceName.begin()),
+        ScopedOverride<const char *> SaveFirst(First, ProtoSourceName.data()),
             SaveLast(Last, &*ProtoSourceName.rbegin() + 1);
         Proto = parseBareSourceName();
       }

diff  --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 68db8c62a29e51..550e1699b22841 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -2336,7 +2336,7 @@ template <class Float> class FloatLiteralImpl : public Node {
         Float value;
         char buf[sizeof(Float)];
       };
-      const char *t = &*Contents.begin();
+      const char *t = Contents.data();
       const char *last = t + N;
       char *e = buf;
       for (; t != last; ++t, ++e) {
@@ -3714,8 +3714,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() {
       std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len);
       std::string_view Proto;
       {
-        ScopedOverride<const char *> SaveFirst(First,
-                                               &*ProtoSourceName.begin()),
+        ScopedOverride<const char *> SaveFirst(First, ProtoSourceName.data()),
             SaveLast(Last, &*ProtoSourceName.rbegin() + 1);
         Proto = parseBareSourceName();
       }

diff  --git a/llvm/lib/Demangle/ItaniumDemangle.cpp b/llvm/lib/Demangle/ItaniumDemangle.cpp
index f2ce6ebc13132c..d81fb65b0f2f8f 100644
--- a/llvm/lib/Demangle/ItaniumDemangle.cpp
+++ b/llvm/lib/Demangle/ItaniumDemangle.cpp
@@ -79,7 +79,7 @@ struct DumpVisitor {
 
   void printStr(const char *S) { fprintf(stderr, "%s", S); }
   void print(std::string_view SV) {
-    fprintf(stderr, "\"%.*s\"", (int)SV.size(), &*SV.begin());
+    fprintf(stderr, "\"%.*s\"", (int)SV.size(), SV.data());
   }
   void print(const Node *N) {
     if (N)

diff  --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index 593e177fefbc60..cd7ff40d63a492 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -268,7 +268,7 @@ std::string_view Demangler::copyString(std::string_view Borrowed) {
   // This is not a micro-optimization, it avoids UB, should Borrowed be an null
   // buffer.
   if (Borrowed.size())
-    std::memcpy(Stable, &*Borrowed.begin(), Borrowed.size());
+    std::memcpy(Stable, Borrowed.data(), Borrowed.size());
 
   return {Stable, Borrowed.size()};
 }
@@ -792,7 +792,7 @@ SymbolNode *Demangler::demangleMD5Name(std::string_view &MangledName) {
     Error = true;
     return nullptr;
   }
-  const char *Start = &*MangledName.begin();
+  const char *Start = MangledName.data();
   const size_t StartSize = MangledName.size();
   MangledName.remove_prefix(MD5Last + 1);
 
@@ -2382,7 +2382,7 @@ void Demangler::dumpBackReferences() {
     T->output(OB, OF_Default);
 
     std::string_view B = OB;
-    std::printf("  [%d] - %.*s\n", (int)I, (int)B.size(), &*B.begin());
+    std::printf("  [%d] - %.*s\n", (int)I, (int)B.size(), B.data());
   }
   std::free(OB.getBuffer());
 
@@ -2391,7 +2391,7 @@ void Demangler::dumpBackReferences() {
   std::printf("%d name backreferences\n", (int)Backrefs.NamesCount);
   for (size_t I = 0; I < Backrefs.NamesCount; ++I) {
     std::printf("  [%d] - %.*s\n", (int)I, (int)Backrefs.Names[I]->Name.size(),
-                &*Backrefs.Names[I]->Name.begin());
+                Backrefs.Names[I]->Name.data());
   }
   if (Backrefs.NamesCount > 0)
     std::printf("\n");
@@ -2404,8 +2404,7 @@ char *llvm::microsoftDemangle(std::string_view MangledName, size_t *NMangled,
   std::string_view Name{MangledName};
   SymbolNode *AST = D.parse(Name);
   if (!D.Error && NMangled)
-    *NMangled = Name.empty() ? MangledName.size()
-                             : &*Name.begin() - &*MangledName.begin();
+    *NMangled = MangledName.size() - Name.size();
 
   if (Flags & MSDF_DumpBackrefs)
     D.dumpBackReferences();


        


More information about the llvm-commits mailing list