[PATCH] D148970: [Demangle] replace std::string_view::substr which may throw
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 21 15:49:47 PDT 2023
nickdesaulniers created this revision.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
libcxxabi/src/demangle/ copies the implementation from llvm/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 <https://reviews.llvm.org/rGf198e0b594aa697d5aeacf6abe3399c37b446830> ("[StringView] remove dropFront")
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D148970
Files:
llvm/include/llvm/Demangle/ItaniumDemangle.h
Index: llvm/include/llvm/Demangle/ItaniumDemangle.h
===================================================================
--- llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -1842,7 +1842,7 @@
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 @@
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 @@
}
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 @@
// 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()),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148970.515943.patch
Type: text/x-patch
Size: 1395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230421/9fd4357e/attachment.bin>
More information about the llvm-commits
mailing list