From 8bb9414f1474d6a8caed2e7be5f1d3d999c8bae1 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Thu, 13 Jul 2023 10:10:02 -0700 Subject: [PATCH] [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 --- libcxxabi/src/demangle/ItaniumDemangle.h | 4 ++-- llvm/include/llvm/Demangle/ItaniumDemangle.h | 5 ++--- llvm/lib/Demangle/ItaniumDemangle.cpp | 2 +- llvm/lib/Demangle/MicrosoftDemangle.cpp | 11 +++++------ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h index e39900e..28562f0 100644 --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -2342,7 +2342,7 @@ public: 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::parseQualifiedType() { std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len); std::string_view Proto; { - ScopedOverride SaveFirst(First, &*ProtoSourceName.begin()), + ScopedOverride 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 68db8c6..550e169 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -2336,7 +2336,7 @@ public: 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::parseQualifiedType() { std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len); std::string_view Proto; { - ScopedOverride SaveFirst(First, - &*ProtoSourceName.begin()), + ScopedOverride 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 f2ce6eb..d81fb65 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 593e177..cd7ff40 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(); -- 2.7.4