nickdesaulniers updated this revision to Diff 527502.
nickdesaulniers added a comment.

- rebase, reformat for presubmit tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149784/new/

https://reviews.llvm.org/D149784

Files:
  lldb/include/lldb/Utility/ConstString.h
  lldb/source/Core/Mangled.cpp
  llvm/include/llvm/Demangle/Demangle.h
  llvm/lib/Demangle/RustDemangle.cpp
  llvm/tools/llvm-rust-demangle-fuzzer/llvm-rust-demangle-fuzzer.cpp

Index: llvm/tools/llvm-rust-demangle-fuzzer/llvm-rust-demangle-fuzzer.cpp
===================================================================
--- llvm/tools/llvm-rust-demangle-fuzzer/llvm-rust-demangle-fuzzer.cpp
+++ llvm/tools/llvm-rust-demangle-fuzzer/llvm-rust-demangle-fuzzer.cpp
@@ -13,7 +13,7 @@
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   std::string NullTerminatedString((const char *)Data, Size);
-  char *Demangled = llvm::rustDemangle(NullTerminatedString.c_str());
+  char *Demangled = llvm::rustDemangle(NullTerminatedString);
   std::free(Demangled);
   return 0;
 }
Index: llvm/lib/Demangle/RustDemangle.cpp
===================================================================
--- llvm/lib/Demangle/RustDemangle.cpp
+++ llvm/lib/Demangle/RustDemangle.cpp
@@ -20,11 +20,13 @@
 #include <cstdint>
 #include <cstring>
 #include <limits>
+#include <string_view>
 
 using namespace llvm;
 
 using llvm::itanium_demangle::OutputBuffer;
 using llvm::itanium_demangle::ScopedOverride;
+using llvm::itanium_demangle::starts_with;
 
 namespace {
 
@@ -146,17 +148,13 @@
 
 } // namespace
 
-char *llvm::rustDemangle(const char *MangledName) {
-  if (MangledName == nullptr)
-    return nullptr;
-
+char *llvm::rustDemangle(std::string_view MangledName) {
   // Return early if mangled name doesn't look like a Rust symbol.
-  std::string_view Mangled(MangledName);
-  if (!llvm::itanium_demangle::starts_with(Mangled, "_R"))
+  if (MangledName.empty() || !starts_with(MangledName, "_R"))
     return nullptr;
 
   Demangler D;
-  if (!D.demangle(Mangled)) {
+  if (!D.demangle(MangledName)) {
     std::free(D.Output.getBuffer());
     return nullptr;
   }
@@ -196,7 +194,7 @@
   RecursionLevel = 0;
   BoundLifetimes = 0;
 
-  if (!llvm::itanium_demangle::starts_with(Mangled, "_R")) {
+  if (!starts_with(Mangled, "_R")) {
     Error = true;
     return false;
   }
Index: llvm/include/llvm/Demangle/Demangle.h
===================================================================
--- llvm/include/llvm/Demangle/Demangle.h
+++ llvm/include/llvm/Demangle/Demangle.h
@@ -11,6 +11,7 @@
 
 #include <cstddef>
 #include <string>
+#include <string_view>
 
 namespace llvm {
 /// This is a llvm local version of __cxa_demangle. Other than the name and
@@ -54,7 +55,7 @@
                         MSDemangleFlags Flags = MSDF_None);
 
 // Demangles a Rust v0 mangled symbol.
-char *rustDemangle(const char *MangledName);
+char *rustDemangle(std::string_view MangledName);
 
 // Demangles a D mangled symbol.
 char *dlangDemangle(const char *MangledName);
Index: lldb/source/Core/Mangled.cpp
===================================================================
--- lldb/source/Core/Mangled.cpp
+++ lldb/source/Core/Mangled.cpp
@@ -25,6 +25,7 @@
 
 #include <mutex>
 #include <string>
+#include <string_view>
 #include <utility>
 
 #include <cstdlib>
@@ -150,7 +151,7 @@
   return demangled_cstr;
 }
 
-static char *GetRustV0DemangledStr(const char *M) {
+static char *GetRustV0DemangledStr(std::string_view M) {
   char *demangled_cstr = llvm::rustDemangle(M);
 
   if (Log *log = GetLog(LLDBLog::Demangle)) {
@@ -259,7 +260,7 @@
         break;
       }
       case eManglingSchemeRustV0:
-        demangled_name = GetRustV0DemangledStr(mangled_name);
+        demangled_name = GetRustV0DemangledStr(m_mangled);
         break;
       case eManglingSchemeD:
         demangled_name = GetDLangDemangledStr(mangled_name);
Index: lldb/include/lldb/Utility/ConstString.h
===================================================================
--- lldb/include/lldb/Utility/ConstString.h
+++ lldb/include/lldb/Utility/ConstString.h
@@ -14,6 +14,7 @@
 #include "llvm/Support/FormatVariadic.h"
 
 #include <cstddef>
+#include <string_view>
 
 namespace lldb_private {
 class Stream;
@@ -182,6 +183,10 @@
 
   // Implicitly convert \class ConstString instances to \class StringRef.
   operator llvm::StringRef() const { return GetStringRef(); }
+  // Implicitly convert \class ConstString instances to \calss std::string_view.
+  operator std::string_view() const {
+    return std::string_view(m_string, GetLength());
+  }
 
   /// Get the string value as a C string.
   ///
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to