diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h --- a/libcxxabi/src/demangle/ItaniumDemangle.h +++ b/libcxxabi/src/demangle/ItaniumDemangle.h @@ -9,6 +9,7 @@ // Generic itanium demangler library. // There are two copies of this file in the source tree. The one under // libcxxabi is the original and the one under llvm is the copy. Use +// TODO // cp-to-llvm.sh to update the copy. See README.txt for more details. // //===----------------------------------------------------------------------===// diff --git a/libcxxabi/src/demangle/README.txt b/libcxxabi/src/demangle/README.txt --- a/libcxxabi/src/demangle/README.txt +++ b/libcxxabi/src/demangle/README.txt @@ -34,6 +34,7 @@ identical between both copies to simplify development and testing. If you're working on the generic library, then do the work first in +TODO libcxxabi, then run the cp-to-llvm.sh script in src/demangle. This script takes as an optional argument the path to llvm, and copies the changes you made to libcxxabi over. Note that this script just diff --git a/libcxxabi/src/demangle/StringView.h b/libcxxabi/src/demangle/StringView.h --- a/libcxxabi/src/demangle/StringView.h +++ b/libcxxabi/src/demangle/StringView.h @@ -9,6 +9,7 @@ // FIXME: Use std::string_view instead when we support C++17. // There are two copies of this file in the source tree. The one under // libcxxabi is the original and the one under llvm is the copy. Use +// TODO // cp-to-llvm.sh to update the copy. See README.txt for more details. // //===----------------------------------------------------------------------===// diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h --- a/libcxxabi/src/demangle/Utility.h +++ b/libcxxabi/src/demangle/Utility.h @@ -8,6 +8,7 @@ // // Provide some utility classes for use in the demangler. // There are two copies of this file in the source tree. The one in libcxxabi +// TODO // is the original and the one in llvm is the copy. Use cp-to-llvm.sh to update // the copy. See README.txt for more details. // diff --git a/libcxxabi/src/demangle/cp-to-llvm.sh b/libcxxabi/src/demangle/cp-to-llvm.sh deleted file mode 100755 --- a/libcxxabi/src/demangle/cp-to-llvm.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# Copies the 'demangle' library, excluding 'DemangleConfig.h', to llvm. If no -# llvm directory is specified, then assume a monorepo layout. - -set -e - -cd $(dirname $0) -HDRS="ItaniumDemangle.h ItaniumNodes.def StringView.h Utility.h" -LLVM_DEMANGLE_DIR=$1 - -if [[ -z "$LLVM_DEMANGLE_DIR" ]]; then - LLVM_DEMANGLE_DIR="../../../llvm/include/llvm/Demangle" -fi - -if [[ ! -d "$LLVM_DEMANGLE_DIR" ]]; then - echo "No such directory: $LLVM_DEMANGLE_DIR" >&2 - exit 1 -fi - -read -p "This will overwrite the copies of $FILES in $LLVM_DEMANGLE_DIR; are you sure? [y/N]" -n 1 -r ANSWER -echo - -if [[ $ANSWER =~ ^[Yy]$ ]]; then - cp -f README.txt $LLVM_DEMANGLE_DIR - chmod -w $LLVM_DEMANGLE_DIR/README.txt - for I in $HDRS ; do - rm -f $LLVM_DEMANGLE_DIR/$I - dash=$(echo "$I---------------------------" | cut -c -27 |\ - sed 's|[^-]*||') - sed -e '1s|^//=*-* .*\..* -*.*=*// *$|//===--- '"$I $dash"'-*- mode:c++;eval:(read-only-mode) -*-===//|' \ - -e '2s|^// *$|// Do not edit! See README.txt.|' \ - $I >$LLVM_DEMANGLE_DIR/$I - chmod -w $LLVM_DEMANGLE_DIR/$I - done -fi diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h --- a/llvm/include/llvm/Demangle/ItaniumDemangle.h +++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h @@ -8,8 +8,7 @@ // // Generic itanium demangler library. // There are two copies of this file in the source tree. The one under -// libcxxabi is the original and the one under llvm is the copy. Use -// cp-to-llvm.sh to update the copy. See README.txt for more details. +// libcxxabi doesn't use string_view. // //===----------------------------------------------------------------------===// diff --git a/llvm/include/llvm/Demangle/README.txt b/llvm/include/llvm/Demangle/README.txt --- a/llvm/include/llvm/Demangle/README.txt +++ b/llvm/include/llvm/Demangle/README.txt @@ -27,23 +27,13 @@ on Windows), and b) may not be up-to-date on the latest language features. -The copy of the demangler in LLVM has some extra stuff that aren't -needed in libcxxabi (ie, the MSVC demangler, ItaniumPartialDemangler), -which depend on the shared generic components. Despite these -differences, we want to keep the "core" generic demangling library -identical between both copies to simplify development and testing. - -If you're working on the generic library, then do the work first in -libcxxabi, then run the cp-to-llvm.sh script in src/demangle. This -script takes as an optional argument the path to llvm, and copies the -changes you made to libcxxabi over. Note that this script just -blindly overwrites all changes to the generic library in llvm, so be -careful. - -Because the core demangler needs to work in libcxxabi, everything -needs to be declared in an anonymous namespace (see -DEMANGLE_NAMESPACE_BEGIN), and you can't introduce any code that -depends on the libcxx dylib. +The copy of the demangler in LLVM has some extra stuff that aren't needed in +libcxxabi (ie, the MSVC demangler, ItaniumPartialDemangler), which depend on +the shared generic components, and makes use of std::string_view. + +Because the core demangler needs to work in libcxxabi, everything needs to be +declared in an anonymous namespace (see DEMANGLE_NAMESPACE_BEGIN), and you +can't introduce any code that depends on the libcxx dylib. FIXME: Now that LLVM is a monorepo, it should be possible to de-duplicate this code, and have both LLVM and libcxxabi depend on a diff --git a/llvm/include/llvm/Demangle/StringView.h b/llvm/include/llvm/Demangle/StringView.h deleted file mode 100644 --- a/llvm/include/llvm/Demangle/StringView.h +++ /dev/null @@ -1,98 +0,0 @@ -//===--- StringView.h ----------------*- mode:c++;eval:(read-only-mode) -*-===// -// Do not edit! See README.txt. -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// FIXME: Use std::string_view instead when we support C++17. -// There are two copies of this file in the source tree. The one under -// libcxxabi is the original and the one under llvm is the copy. Use -// cp-to-llvm.sh to update the copy. See README.txt for more details. -// -//===----------------------------------------------------------------------===// - -#ifndef DEMANGLE_STRINGVIEW_H -#define DEMANGLE_STRINGVIEW_H - -#include "DemangleConfig.h" -#include -#include - -DEMANGLE_NAMESPACE_BEGIN - -class StringView { - const char *First; - const char *Last; - -public: - static const size_t npos = ~size_t(0); - - template - StringView(const char (&Str)[N]) : First(Str), Last(Str + N - 1) {} - StringView(const char *First_, size_t Len) - : First(First_), Last(First_ + Len) {} - StringView(const char *Str) : First(Str), Last(Str + std::strlen(Str)) {} - StringView() : First(nullptr), Last(nullptr) {} - - StringView substr(size_t Pos, size_t Len = npos) const { - assert(Pos <= size()); - if (Len > size() - Pos) - Len = size() - Pos; - return StringView(begin() + Pos, Len); - } - - size_t find(char C, size_t From = 0) const { - // Avoid calling memchr with nullptr. - if (From < size()) { - // Just forward to memchr, which is faster than a hand-rolled loop. - if (const void *P = ::memchr(First + From, C, size() - From)) - return size_t(static_cast(P) - First); - } - return npos; - } - - void remove_prefix(size_t N) { - assert(size() >= N); - First += N; - } - void remove_suffix(size_t N) { - assert(size() >= N); - Last -= N; - } - - char front() const { - assert(!empty()); - return *begin(); - } - - char back() const { - assert(!empty()); - return *(end() - 1); - } - - bool startsWith(char C) const { return !empty() && *begin() == C; } - - bool startsWith(StringView Str) const { - if (Str.size() > size()) - return false; - return std::strncmp(Str.begin(), begin(), Str.size()) == 0; - } - - const char &operator[](size_t Idx) const { return *(begin() + Idx); } - - const char *begin() const { return First; } - const char *end() const { return Last; } - size_t size() const { return static_cast(Last - First); } - bool empty() const { return First == Last; } -}; - -inline bool operator==(const StringView &LHS, const StringView &RHS) { - return LHS.size() == RHS.size() && - std::strncmp(LHS.begin(), RHS.begin(), LHS.size()) == 0; -} - -DEMANGLE_NAMESPACE_END - -#endif diff --git a/llvm/include/llvm/Demangle/Utility.h b/llvm/include/llvm/Demangle/Utility.h --- a/llvm/include/llvm/Demangle/Utility.h +++ b/llvm/include/llvm/Demangle/Utility.h @@ -8,8 +8,7 @@ // // Provide some utility classes for use in the demangler. // There are two copies of this file in the source tree. The one in libcxxabi -// is the original and the one in llvm is the copy. Use cp-to-llvm.sh to update -// the copy. See README.txt for more details. +// doesn't use string_view. // //===----------------------------------------------------------------------===// diff --git a/llvm/unittests/Demangle/CMakeLists.txt b/llvm/unittests/Demangle/CMakeLists.txt --- a/llvm/unittests/Demangle/CMakeLists.txt +++ b/llvm/unittests/Demangle/CMakeLists.txt @@ -10,5 +10,4 @@ OutputBufferTest.cpp PartialDemangleTest.cpp RustDemangleTest.cpp - StringViewTest.cpp ) diff --git a/llvm/unittests/Demangle/StringViewTest.cpp b/llvm/unittests/Demangle/StringViewTest.cpp deleted file mode 100644 --- a/llvm/unittests/Demangle/StringViewTest.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//===- llvm/unittest/StringViewTest.cpp - StringView unit tests -----------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "llvm/Demangle/StringView.h" -#include "gtest/gtest.h" - -using namespace llvm; -using llvm::itanium_demangle::StringView; - -namespace llvm { -namespace itanium_demangle { - -std::ostream &operator<<(std::ostream &OS, const StringView &S) { - return OS.write(S.begin(), S.size()); -} - -} // namespace itanium_demangle -} // namespace llvm - -TEST(StringViewTest, EmptyInitializerList) { - StringView S = {}; - EXPECT_TRUE(S.empty()); - - S = {}; - EXPECT_TRUE(S.empty()); -} - -TEST(StringViewTest, Substr) { - StringView S("abcdef"); - - EXPECT_EQ("abcdef", S.substr(0)); - EXPECT_EQ("f", S.substr(5)); - EXPECT_EQ("", S.substr(6)); - - EXPECT_EQ("", S.substr(0, 0)); - EXPECT_EQ("a", S.substr(0, 1)); - EXPECT_EQ("abcde", S.substr(0, 5)); - EXPECT_EQ("abcdef", S.substr(0, 6)); - EXPECT_EQ("abcdef", S.substr(0, 7)); - - EXPECT_EQ("f", S.substr(5, 100)); - EXPECT_EQ("", S.substr(6, 100)); -}