[PATCH] D148959: [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 14:01:08 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.
The "upstream" source of this file is in libcxxabi/src/demangle/. As I
was "upstreaming" recent changes I made downstream (accidentally)
(https://reviews.llvm.org/D148566) I ran into linkage failures stemming
from the usage of std::string_view::substr. substr does a bounds check
and may throw. If we guard such accesses with
std::string_view::starts_with, then we can manually do what
std::string_view::substr does without the bounds check that may throw.
This allows us to share the downstream copy with something upstream may
link.
Fixes: f198e0b594aa <https://reviews.llvm.org/rGf198e0b594aa697d5aeacf6abe3399c37b446830> ("[StringView] remove dropFront")
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D148959
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: D148959.515907.patch
Type: text/x-patch
Size: 1395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230421/61f12f1d/attachment.bin>
More information about the llvm-commits
mailing list