[PATCH] D149675: [Demangle] convert itaniumDemangle and nonMicrosoftDemangle to use std::string_view

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 2 15:51:29 PDT 2023


nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.

In D149675#4313939 <https://reviews.llvm.org/D149675#4313939>, @MaskRay wrote:

>> Is c_str2 NUL-terminated? Good question. It depends on whether c_str was NUL-terminated. When s in the above example is a std::string, then it doesn't matter whether c_str is NUL-terminated or not, c_str2 ALWAYS will be.
>
> I am still confused... Is the bug in lld/wasm or llvm/lib/Demangle?

llvm/lib/Demangle

> If the former it seems that we need a patch fixing just that part. Changing the signature of `llvm::itaniumDemangle` is useful but can be a separate patch.

False.  Passing a c_str that may not be null terminated without passing the length then calling std::strlen on it gives bonkers results.  The interface of `llvm::itaniumDemangle` must be changed to pass the size, such as by passing a `std::string_view`.

> If the latter, which `const char *` variable points a non-NUL-terminated string that leads to the lld/test/wasm failure?

The std::string_view's data() in llvm::demangle is passed to llvm::itaniumDemangle which calls std::strlen.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149675



More information about the llvm-commits mailing list