Skip to content

Commit

Permalink
ndk-sysroot-gcc-compact: fix various compile error
Browse files Browse the repository at this point in the history
Closes #650
  • Loading branch information
licy183 committed Oct 24, 2023
1 parent eefa703 commit 48848dc
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Since commit [1], libcxx assumed that gcc has fully supported `__has_builtin`,
and dropped special-casing for GCC-provided builtins, but `__has_builtin` isn't
supported by gcc-9.

[1]: https://github.com/llvm/llvm-project/commit/2040fde9097ae7753531c9c58332a933cbaaa43c

--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_trivially_destructible.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_trivially_destructible.h
@@ -24,7 +24,7 @@
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
: public integral_constant<bool, __is_trivially_destructible(_Tp)> {};

-#elif __has_builtin(__has_trivial_destructor)
+#elif __has_builtin(__has_trivial_destructor) || defined(_LIBCPP_COMPILER_GCC)

template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
: public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Since commit [1], libcxx assumes that gcc has builtin `__is_same`, but it
doesn't exists in gcc-9.

[1]: https://github.com/llvm/llvm-project/commit/5c0ea7488bc051453ad07135f32145465f502a84

--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_same.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_same.h
@@ -18,6 +18,8 @@

_LIBCPP_BEGIN_NAMESPACE_STD

+#if __has_builtin(__is_same)
+
template <class _Tp, class _Up>
struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> { };

@@ -39,6 +41,24 @@
template <class _Tp, class _Up>
using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;

+#else
+
+template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {};
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {};
+
+#if _LIBCPP_STD_VER > 14
+template <class _Tp, class _Up>
+inline constexpr bool is_same_v = is_same<_Tp, _Up>::value;
+#endif
+
+template <class _Tp, class _Up>
+using _IsSame = _BoolConstant<is_same<_Tp, _Up>::value>;
+
+template <class _Tp, class _Up>
+using _IsNotSame = _BoolConstant<!is_same<_Tp, _Up>::value>;
+
+#endif // __has_builtin(__is_same)
+
_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___TYPE_TRAITS_IS_SAME_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
Since commit [1], libcxx assumes that gcc has builtin `__is_nothrow_assignable` and
`__is_nothrow_constructible`, but they don't exists in gcc-9 and gcc-10.

[1]: https://github.com/llvm/llvm-project/commit/a13822b35d11cb6afa759fa0672fbc0b6ef295d0

--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_nothrow_assignable.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_nothrow_assignable.h
@@ -18,13 +18,39 @@

_LIBCPP_BEGIN_NAMESPACE_STD

+#if __has_builtin(__is_nothrow_assignable)
+
template <class _Tp, class _Arg>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
: public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};

+#else
+
+template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
+
+template <class _Tp, class _Arg>
+struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
+ : public false_type
+{
+};
+
+template <class _Tp, class _Arg>
+struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
+ : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Arg>()) >
+{
+};
+
+template <class _Tp, class _Arg>
+struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
+ : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
+{
+};
+
+#endif // __has_builtin(__is_nothrow_assignable)
+
#if _LIBCPP_STD_VER > 14
template <class _Tp, class _Arg>
-inline constexpr bool is_nothrow_assignable_v = __is_nothrow_assignable(_Tp, _Arg);
+inline constexpr bool is_nothrow_assignable_v = is_nothrow_assignable<_Tp, _Arg>::value;
#endif

_LIBCPP_END_NAMESPACE_STD
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_nothrow_copy_assignable.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_nothrow_copy_assignable.h
@@ -20,6 +20,8 @@

_LIBCPP_BEGIN_NAMESPACE_STD

+#if __has_builtin(__is_nothrow_assignable)
+
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
: public integral_constant<
@@ -28,6 +30,14 @@
__add_lvalue_reference_t<_Tp>,
__add_lvalue_reference_t<typename add_const<_Tp>::type>)> {};

+#else
+
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
+ : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
+ typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
+
+#endif
+
#if _LIBCPP_STD_VER > 14
template <class _Tp>
inline constexpr bool is_nothrow_copy_assignable_v = is_nothrow_copy_assignable<_Tp>::value;
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_nothrow_default_constructible.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_nothrow_default_constructible.h
@@ -11,6 +11,7 @@

#include <__config>
#include <__type_traits/integral_constant.h>
+#include <__type_traits/is_nothrow_constructible.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -18,13 +19,23 @@

_LIBCPP_BEGIN_NAMESPACE_STD

+#if __has_builtin(__is_nothrow_constructible)
+
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
: public integral_constant<bool, __is_nothrow_constructible(_Tp)>
{};

+#else
+
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
+ : public is_nothrow_constructible<_Tp>
+ {};
+
+#endif
+
#if _LIBCPP_STD_VER > 14
template <class _Tp>
-inline constexpr bool is_nothrow_default_constructible_v = __is_nothrow_constructible(_Tp);
+inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<_Tp>::value;
#endif

_LIBCPP_END_NAMESPACE_STD
--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_nothrow_move_assignable.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__type_traits/is_nothrow_move_assignable.h
@@ -13,6 +13,7 @@
#include <__type_traits/add_lvalue_reference.h>
#include <__type_traits/add_rvalue_reference.h>
#include <__type_traits/integral_constant.h>
+#include <__type_traits/is_nothrow_assignable.h>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -20,6 +21,8 @@

_LIBCPP_BEGIN_NAMESPACE_STD

+#if __has_builtin(__is_nothrow_assignable)
+
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
: public integral_constant<
@@ -27,6 +30,15 @@
__is_nothrow_assignable(__add_lvalue_reference_t<_Tp>, __add_rvalue_reference_t<_Tp>)> {
};

+#else
+
+template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
+ : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
+ typename add_rvalue_reference<_Tp>::type>
+ {};
+
+#endif
+
#if _LIBCPP_STD_VER > 14
template <class _Tp>
inline constexpr bool is_nothrow_move_assignable_v = is_nothrow_move_assignable<_Tp>::value;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Since commit [1], libcxx implements LWG 3629 for `system_error` header,
but this breaks compile on gcc-9, gcc-10 and gcc-11.

[1]: https://github.com/llvm/llvm-project/commit/ef843c8271027b89419d07ffc2aaa3abf91438ef

--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/system_error
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/system_error
@@ -259,8 +259,13 @@
namespace __adl_only {
// Those cause ADL to trigger but they are not viable candidates,
// so they are never actually selected.
+#if defined(__GNUC__) && __GNUC__ < 12
+ void make_error_condition();
+ void make_error_code();
+#else
void make_error_condition() = delete;
void make_error_code() = delete;
+#endif
} // namespace __adl_only

class _LIBCPP_TYPE_VIS error_condition
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
GCC doesn't have proper support for CWG 1315 until commit [2], which is landed in GCC
12. I don't want to cherry-pick this commit for every GCC toolchain, so I implement
`has_specialization` with SFINAE. Hopefully there aren't many bugs...

[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96555
[2]: https://github.com/gcc-mirror/gcc/commit/9b94785dedb08b006419bec1a402614d9241317a

--- a/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__iterator/segmented_iterator.h
+++ b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/__iterator/segmented_iterator.h
@@ -65,12 +65,24 @@
};
*/

+#if defined(__GNUC__) && __GNUC__ < 12
+
+template <class _Tp, class = void>
+struct __has_specialization : false_type {};
+
+template <class _Tp>
+struct __has_specialization<_Tp, __void_t<decltype(_Tp())>> : true_type {};
+
+#else
+
template <class _Tp, size_t = 0>
struct __has_specialization : false_type {};

template <class _Tp>
struct __has_specialization<_Tp, sizeof(_Tp) * 0> : true_type {};

+#endif
+
template <class _Iterator>
using __is_segmented_iterator = __has_specialization<__segmented_iterator_traits<_Iterator> >;

1 change: 1 addition & 0 deletions tur/ndk-sysroot-gcc-compact/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TERMUX_PKG_MAINTAINER="@licy183"
# Version should be equal to TERMUX_NDK_{VERSION_NUM,REVISION} in
# scripts/properties.sh
TERMUX_PKG_VERSION=26b
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://dl.google.com/android/repository/android-ndk-r${TERMUX_PKG_VERSION}-linux.zip
TERMUX_PKG_SHA256=ad73c0370f0b0a87d1671ed2fd5a9ac9acfd1eb5c43a7fbfbd330f85d19dd632
# This package has taken over <pty.h> from the previous libutil-dev
Expand Down

0 comments on commit 48848dc

Please sign in to comment.