[llvm] 3a30cf2 - [Demangle] replace std::string_view::substr which may throw
Nick Desaulniers via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 21 15:57:43 PDT 2023
Author: Nick Desaulniers
Date: 2023-04-21T15:56:55-07:00
New Revision: 3a30cf212d12cc5013ec67e54530b69ee2cfc7c9
URL: https://github.com/llvm/llvm-project/commit/3a30cf212d12cc5013ec67e54530b69ee2cfc7c9
DIFF: https://github.com/llvm/llvm-project/commit/3a30cf212d12cc5013ec67e54530b69ee2cfc7c9.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/Demangle/ItaniumDemangle.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 07b1097d4b5b0..428f0646d90ee 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -1842,7 +1842,7 @@ class SubobjectExpr : public Node {
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 @@ class EnumLiteral : public Node {
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 @@ class IntegerLiteral : public Node {
}
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<Derived, Alloc>::parseQualifiedType() {
// extension ::= U <objc-name> <objc-type> # objc-type<identifier>
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<const char *> SaveFirst(First, &*ProtoSourceName.begin()),
More information about the llvm-commits
mailing list