From 8da71b78ed01bd1e40861b0ab50c1362e03abf15 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 23 Jan 2024 21:47:11 +0100 Subject: [PATCH] [BUILD] Clang-15 warning about `__has_trivial_destructor` (#2502) * Upgrade compiler in CI * Backport abseil fix for clang-15. * More backport for clang-15 * Missed backport bits. * Fixed a new warning. --- .github/workflows/ci.yml | 50 +++++++++---------- .../nostd/internal/absl/base/config.h | 13 +++++ .../nostd/internal/absl/meta/type_traits.h | 22 ++++++++ api/test/common/spinlock_benchmark.cc | 2 +- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e4fc46b58..9772ccc2c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: ./ci/do_ci.sh cmake.test cmake_gcc_maintainer_sync_test: - name: CMake gcc 12 (maintainer mode, sync) + name: CMake gcc 13 (maintainer mode, sync) runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -37,8 +37,8 @@ jobs: submodules: 'recursive' - name: setup env: - CC: /usr/bin/gcc-12 - CXX: /usr/bin/g++-12 + CC: /usr/bin/gcc-13 + CXX: /usr/bin/g++-13 PROTOBUF_VERSION: 21.12 run: | sudo -E ./ci/setup_cmake.sh @@ -46,8 +46,8 @@ jobs: sudo -E ./ci/install_protobuf.sh - name: run cmake gcc (maintainer mode, sync) env: - CC: /usr/bin/gcc-12 - CXX: /usr/bin/g++-12 + CC: /usr/bin/gcc-13 + CXX: /usr/bin/g++-13 run: | ./ci/do_ci.sh cmake.maintainer.sync.test - name: generate test cert @@ -61,7 +61,7 @@ jobs: (cd ./functional/otlp; ./run_test.sh) cmake_gcc_maintainer_async_test: - name: CMake gcc 12 (maintainer mode, async) + name: CMake gcc 13 (maintainer mode, async) runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -69,8 +69,8 @@ jobs: submodules: 'recursive' - name: setup env: - CC: /usr/bin/gcc-12 - CXX: /usr/bin/g++-12 + CC: /usr/bin/gcc-13 + CXX: /usr/bin/g++-13 PROTOBUF_VERSION: 21.12 run: | sudo -E ./ci/setup_cmake.sh @@ -78,8 +78,8 @@ jobs: sudo -E ./ci/install_protobuf.sh - name: run cmake gcc (maintainer mode, async) env: - CC: /usr/bin/gcc-12 - CXX: /usr/bin/g++-12 + CC: /usr/bin/gcc-13 + CXX: /usr/bin/g++-13 run: | ./ci/do_ci.sh cmake.maintainer.async.test - name: generate test cert @@ -93,7 +93,7 @@ jobs: (cd ./functional/otlp; ./run_test.sh) cmake_clang_maintainer_sync_test: - name: CMake clang 14 (maintainer mode, sync) + name: CMake clang 15 (maintainer mode, sync) runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -101,8 +101,8 @@ jobs: submodules: 'recursive' - name: setup env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 + CC: /usr/bin/clang-15 + CXX: /usr/bin/clang++-15 PROTOBUF_VERSION: 21.12 run: | sudo -E ./ci/setup_cmake.sh @@ -110,8 +110,8 @@ jobs: sudo -E ./ci/install_protobuf.sh - name: run cmake clang (maintainer mode, sync) env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 + CC: /usr/bin/clang-15 + CXX: /usr/bin/clang++-15 run: | ./ci/do_ci.sh cmake.maintainer.sync.test - name: generate test cert @@ -125,7 +125,7 @@ jobs: (cd ./functional/otlp; ./run_test.sh) cmake_clang_maintainer_async_test: - name: CMake clang 14 (maintainer mode, async) + name: CMake clang 15 (maintainer mode, async) runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -133,8 +133,8 @@ jobs: submodules: 'recursive' - name: setup env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 + CC: /usr/bin/clang-15 + CXX: /usr/bin/clang++-15 PROTOBUF_VERSION: 21.12 run: | sudo -E ./ci/setup_cmake.sh @@ -142,8 +142,8 @@ jobs: sudo -E ./ci/install_protobuf.sh - name: run cmake clang (maintainer mode, async) env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 + CC: /usr/bin/clang-15 + CXX: /usr/bin/clang++-15 run: | ./ci/do_ci.sh cmake.maintainer.async.test - name: generate test cert @@ -157,7 +157,7 @@ jobs: (cd ./functional/otlp; ./run_test.sh) cmake_clang_maintainer_abiv2_test: - name: CMake clang 14 (maintainer mode, abiv2) + name: CMake clang 15 (maintainer mode, abiv2) runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -165,8 +165,8 @@ jobs: submodules: 'recursive' - name: setup env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 + CC: /usr/bin/clang-15 + CXX: /usr/bin/clang++-15 PROTOBUF_VERSION: 21.12 run: | sudo -E ./ci/setup_cmake.sh @@ -174,8 +174,8 @@ jobs: sudo -E ./ci/install_protobuf.sh - name: run cmake clang (maintainer mode, abiv2) env: - CC: /usr/bin/clang-14 - CXX: /usr/bin/clang++-14 + CC: /usr/bin/clang-15 + CXX: /usr/bin/clang++-15 run: | ./ci/do_ci.sh cmake.maintainer.abiv2.test - name: generate test cert diff --git a/api/include/opentelemetry/nostd/internal/absl/base/config.h b/api/include/opentelemetry/nostd/internal/absl/base/config.h index 5eaeb46367..3f78df3d98 100644 --- a/api/include/opentelemetry/nostd/internal/absl/base/config.h +++ b/api/include/opentelemetry/nostd/internal/absl/base/config.h @@ -172,6 +172,7 @@ static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || #ifdef OTABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE #error OTABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set #elif defined(_LIBCPP_VERSION) || \ + (defined(__clang__) && __clang_major__ >= 15) || \ (!defined(__clang__) && defined(__GNUC__) && defined(__GLIBCXX__) && \ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) || \ defined(_MSC_VER) @@ -194,6 +195,7 @@ static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || #elif defined(OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE) #error OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set #elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \ + (defined(__clang__) && __clang_major__ >= 15) || \ (!defined(__clang__) && defined(__GNUC__) && \ (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 4)) && \ (defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) || \ @@ -202,6 +204,17 @@ static_assert(OTABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || #define OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1 #endif +// OTABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE +// +// Checks whether `std::is_trivially_copyable` is supported. +// +// Notes: Clang 15+ with libc++ supports these features, GCC hasn't been tested. +#if defined(OTABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE) +#error OTABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE cannot be directly set +#elif defined(__clang__) && (__clang_major__ >= 15) +#define OTABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE 1 +#endif + // OTABSL_HAVE_SOURCE_LOCATION_CURRENT // // Indicates whether `absl::SourceLocation::current()` will return useful diff --git a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h index 8430f0087c..00c90f82d1 100644 --- a/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h +++ b/api/include/opentelemetry/nostd/internal/absl/meta/type_traits.h @@ -296,8 +296,12 @@ struct is_function // https://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html#Type-Traits. template struct is_trivially_destructible +#ifdef OTABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE + : std::is_trivially_destructible { +#else : std::integral_constant::value> { +#endif #ifdef OTABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE private: static constexpr bool compliant = std::is_trivially_destructible::value == @@ -345,9 +349,13 @@ struct is_trivially_destructible // Nontrivially destructible types will cause the expression to be nontrivial. template struct is_trivially_default_constructible +#if defined(OTABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) + : std::is_trivially_default_constructible { +#else : std::integral_constant::value && is_trivially_destructible::value> { +#endif #if defined(OTABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \ !defined( \ OTABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION) @@ -379,10 +387,14 @@ struct is_trivially_default_constructible // expression to be nontrivial. template struct is_trivially_move_constructible +#if defined(OTABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) + : std::is_trivially_move_constructible { +#else : std::conditional< std::is_object::value && !std::is_array::value, type_traits_internal::IsTriviallyMoveConstructibleObject, std::is_reference>::type::type { +#endif #if defined(OTABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \ !defined( \ OTABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION) @@ -488,9 +500,13 @@ struct is_trivially_move_assignable // `is_trivially_assignable`. template struct is_trivially_copy_assignable +#ifdef OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE + : std::is_trivially_copy_assignable { +#else : std::integral_constant< bool, __has_trivial_assign(typename std::remove_reference::type) && absl::is_copy_assignable::value> { +#endif #ifdef OTABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE private: static constexpr bool compliant = @@ -521,6 +537,11 @@ namespace type_traits_internal { // destructible. Arrays of trivially copyable types are trivially copyable. // // We expose this metafunction only for internal use within absl. + +#if defined(OTABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE) +template +struct is_trivially_copyable : std::is_trivially_copyable {}; +#else template class is_trivially_copyable_impl { using ExtentsRemoved = typename std::remove_all_extents::type; @@ -546,6 +567,7 @@ template struct is_trivially_copyable : std::integral_constant< bool, type_traits_internal::is_trivially_copyable_impl::kValue> {}; +#endif } // namespace type_traits_internal // ----------------------------------------------------------------------------- diff --git a/api/test/common/spinlock_benchmark.cc b/api/test/common/spinlock_benchmark.cc index 53ea633d16..214644cdae 100644 --- a/api/test/common/spinlock_benchmark.cc +++ b/api/test/common/spinlock_benchmark.cc @@ -24,7 +24,7 @@ inline void SpinThrash(benchmark::State &s, SpinLockType &spinlock, LockF lock, // Value we will increment, fighting over a spinlock. // The contention is meant to be brief, as close to our expected // use cases of "updating pointers" or "pushing an event onto a buffer". - std::int64_t value = 0; + std::int64_t value OPENTELEMETRY_MAYBE_UNUSED = 0; std::vector threads; threads.reserve(num_threads);