Index: include/llvm/ADT/StringRef.h =================================================================== --- include/llvm/ADT/StringRef.h +++ include/llvm/ADT/StringRef.h @@ -90,6 +90,11 @@ /*implicit*/ constexpr StringRef(const char *data, size_t length) : Data(data), Length(length) {} + /// Construct a string ref from a pointer to bytes and length. + LLVM_ATTRIBUTE_ALWAYS_INLINE + /*implicit*/ constexpr StringRef(const unsigned char *data, size_t length) + : Data(reinterpret_cast(data)), Length(length) {} + /// Construct a string ref from an std::string. LLVM_ATTRIBUTE_ALWAYS_INLINE /*implicit*/ StringRef(const std::string &Str) Index: test/tools/llvm-strings/negative.test =================================================================== --- test/tools/llvm-strings/negative.test +++ test/tools/llvm-strings/negative.test @@ -0,0 +1 @@ +# RUN: echo -e \x80 | llvm-strings - Index: tools/llvm-strings/llvm-strings.cpp =================================================================== --- tools/llvm-strings/llvm-strings.cpp +++ tools/llvm-strings/llvm-strings.cpp @@ -77,9 +77,10 @@ OS << " " << L << '\n'; }; - const char *B = Contents.begin(); - const char *P = nullptr, *E = nullptr, *S = nullptr; - for (P = Contents.begin(), E = Contents.end(); P < E; ++P) { + const unsigned char *B = Contents.bytes_begin(); + const unsigned char *E = Contents.bytes_end(); + const unsigned char *S = nullptr; + for (const unsigned char *P = B; P < E; ++P) { if (std::isgraph(*P) || std::isblank(*P)) { if (S == nullptr) S = P;