From: Nick Desaulniers Date: Fri, 21 Apr 2023 22:51:29 +0000 (-0700) Subject: [Demangle] replace std::string_view::substr which may throw X-Git-Tag: upstream/17.0.6~10753 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3a30cf212d12cc5013ec67e54530b69ee2cfc7c9;p=platform%2Fupstream%2Fllvm.git [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 --- 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()),