aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Demangle/ItaniumDemangle.cpp
diff options
context:
space:
mode:
authorNick Desaulniers <ndesaulniers@google.com>2023-06-02 14:53:46 -0700
committerNick Desaulniers <ndesaulniers@google.com>2023-06-02 14:53:49 -0700
commit61e1c3d80db6e94e8b5b83b3819afefeec4d357b (patch)
treeda734d13540b240a385abf5746732140ef12a502 /llvm/lib/Demangle/ItaniumDemangle.cpp
parentfa98bdbd95d14959d3c6c09a4c29ba0d974883dd (diff)
downloadllvm-61e1c3d80db6e94e8b5b83b3819afefeec4d357b.zip
llvm-61e1c3d80db6e94e8b5b83b3819afefeec4d357b.tar.gz
llvm-61e1c3d80db6e94e8b5b83b3819afefeec4d357b.tar.bz2
[Demangle] convert itaniumDemangle and nonMicrosoftDemangle to use std::string_view
D149104 converted llvm::demangle to use std::string_view. Enabling "expensive checks" (via -DLLVM_ENABLE_EXPENSIVE_CHECKS=ON) causes lld/test/wasm/why-extract.s to fail. The reason for this is obscure: Reason #10007 why std::string_view is dangerous: Consider the following pattern: std::string_view s = ...; const char *c = s.data(); std::strlen(c); Is c a NUL-terminated C style string? It depends; but if it's not then it's not safe to call std::strlen on the std::string_view::data(). std::string_view::length() should be used instead. Fixing this fixes the one lone test that caught this. microsoftDemangle, rustDemangle, and dlangDemangle should get this same treatment, too. I will do that next. Reviewed By: MaskRay, efriedma Differential Revision: https://reviews.llvm.org/D149675
Diffstat (limited to 'llvm/lib/Demangle/ItaniumDemangle.cpp')
-rw-r--r--llvm/lib/Demangle/ItaniumDemangle.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Demangle/ItaniumDemangle.cpp b/llvm/lib/Demangle/ItaniumDemangle.cpp
index b1a8832..f2ce6eb 100644
--- a/llvm/lib/Demangle/ItaniumDemangle.cpp
+++ b/llvm/lib/Demangle/ItaniumDemangle.cpp
@@ -365,11 +365,12 @@ public:
using Demangler = itanium_demangle::ManglingParser<DefaultAllocator>;
-char *llvm::itaniumDemangle(const char *MangledName) {
- if (!MangledName)
+char *llvm::itaniumDemangle(std::string_view MangledName) {
+ if (MangledName.empty())
return nullptr;
- Demangler Parser(MangledName, MangledName + std::strlen(MangledName));
+ Demangler Parser(MangledName.data(),
+ MangledName.data() + MangledName.length());
Node *AST = Parser.parse();
if (!AST)
return nullptr;