From 3a30cf212d12cc5013ec67e54530b69ee2cfc7c9 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Fri, 21 Apr 2023 15:51:29 -0700 Subject: [PATCH] [Demangle] replace std::string_view::substr which may throw llvm/Demangle copies the implementation from libcxxabi/src/demangle/. libcxxabi/ cannot use potentially-throwing std::string_view::substr, so change llvm/Demangle to avoid these function calls. I ran into linkage failures stemming from the usage of std::string_view::substr. substr does a bounds check and may throw. Fixes: f198e0b594aa ("[StringView] remove dropFront") Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D148959 --- llvm/include/llvm/Demangle/ItaniumDemangle.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h index 07b1097..428f064 100644 --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -1842,7 +1842,7 @@ public: OB += "0"; } else if (Offset[0] == 'n') { OB += "-"; - OB += Offset.substr(1); + OB += std::string_view(Offset.data() + 1, Offset.size() - 1); } else { OB += Offset; } @@ -2270,7 +2270,7 @@ public: OB.printClose(); if (Integer[0] == 'n') - OB << '-' << Integer.substr(1); + OB << '-' << std::string_view(Integer.data() + 1, Integer.size() - 1); else OB << Integer; } @@ -2294,7 +2294,7 @@ public: } if (Value[0] == 'n') - OB << '-' << Value.substr(1); + OB << '-' << std::string_view(Value.data() + 1, Value.size() - 1); else OB += Value; @@ -3713,7 +3713,8 @@ Node *AbstractManglingParser::parseQualifiedType() { // extension ::= U # objc-type if (llvm::itanium_demangle::starts_with(Qual, "objcproto")) { - std::string_view ProtoSourceName = Qual.substr(std::strlen("objcproto")); + constexpr size_t Len = sizeof("objcproto") - 1; + std::string_view ProtoSourceName(Qual.data() + Len, Qual.size() - Len); std::string_view Proto; { ScopedOverride SaveFirst(First, &*ProtoSourceName.begin()), -- 2.7.4