pingcap / tiflash

The analytical engine for TiDB and TiDB Cloud. Try free: https://tidbcloud.com/free-trial
https://docs.pingcap.com/tidb/stable/tiflash-overview
Apache License 2.0
936 stars 409 forks source link

Clang 15 support #5265

Closed SchrodingerZhu closed 1 year ago

SchrodingerZhu commented 2 years ago

Enhancement

release notes: https://releases.llvm.org/download.html

LIBCPP Highlists

New Features

There’s support for the C++20 header <format>. Some parts are still missing, most notably the compile-time format string validation. Some functions are known to be inefficient, both in memory usage and performance. The implementation isn’t API- or ABI-stable and therefore considered experimental. (Some not-yet-implemented papers require an API-break.) As a result, it is disabled by default, however vendors can enable the header by using -DLIBCXX_ENABLE_INCOMPLETE_FEATURES=ON when configuring their build.

More parts of <ranges> have been implemented. Since we still expect to make some API and ABI breaking changes, those are disabled by default. However, vendors that wish to enable <ranges> in their distribution may do so by defining -DLIBCXX_ENABLE_INCOMPLETE_FEATURES=ON when configuring their build.

There’s a new CMake option LIBCXX_ENABLE_UNICODE to disable Unicode support in the <format> header. This only affects the estimation of the output width of the format functions.

Support for building libc++ on top of a C Standard Library that does not support wchar_t was added. This is useful for building libc++ in an embedded setting, and it adds itself to the various freestanding-friendly options provided by libc++.

Defining _LIBCPP_DEBUG to 1 enables the randomization of unspecified behavior in standard algorithms (e.g. the ordering of equal elements in std::sort, or the ordering of both sides of the partition in std::nth_element).

Floating-point support for std::to_chars support has been added. Thanks to Stephan T. Lavavej and Microsoft for providing their implementation to libc++.

The C++20 <coroutine> implementation has been completed.

More C++20 features have been implemented. [libc++ C++20 Status](https://releases.llvm.org/14.0.0/projects/libcxx/docs/Status/Cxx20.html) has the full overview of libc++’s C++20 implementation status.

More C++2b features have been implemented. [libc++ C++2b Status](https://releases.llvm.org/14.0.0/projects/libcxx/docs/Status/Cxx2b.html) has the full overview of libc++’s C++2b implementation status.

16-bit wchar_t handling added for codecvt_utf8, codecvt_utf16 and codecvt_utf8_utf16.

Clang Highlights

clang-format

Option AllowShortEnumsOnASingleLine: false has been improved, it now correctly places the opening brace according to BraceWrapping.AfterEnum.

Option AlignAfterOpenBracket: BlockIndent has been added. If set, it will always break after an open bracket, if the parameters don’t fit on a single line. Closing brackets will be placed on a new line.

Option QualifierAlignment has been added in order to auto-arrange the positioning of specifiers/qualifiers const volatile static inline constexpr restrict in variable and parameter declarations to be either Right aligned or Left aligned or Custom using QualifierOrder.

Option QualifierOrder has been added to allow the order const volatile static inline constexpr restrict to be controlled relative to the type.

Option RemoveBracesLLVM has been added to remove optional braces of control statements for the LLVM style.

Option SeparateDefinitionBlocks has been added to insert or remove empty lines between definition blocks including functions, classes, structs, enums, and namespaces.

Add a Custom style to SpaceBeforeParens, to better configure the space before parentheses. The custom options can be set using SpaceBeforeParensOptions.

The command line argument -style=<string> has been extended so that a specific format file at location <format_file_path> can be selected. This is supported via the syntax: -style=file:<format_file_path>.

Improved C++20 Modules and Coroutines support.

Option AfterOverloadedOperator has been added in SpaceBeforeParensOptions to allow space between overloaded operator and opening parentheses.

LLVM Highlights

Changes to the AArch64 Backend

Added support for the Armv9-A, Armv9.1-A and Armv9.2-A architectures.

The compiler now recognises the “tune-cpu” function attribute to support the use of the -mtune frontend flag. This allows certain scheduling features and optimisations to be enabled independently of the architecture. If the “tune-cpu” attribute is absent it tunes according to the “target-cpu”.

Fixed relocations against temporary symbols (e.g. in jump tables and constant pools) in large COFF object files.

Auto-vectorization now targets SVE by default when available.

Changes to the X86 Target

Support for AVX512-FP16 instructions has been added.

Removed incomplete support for Intel MPX. ([D111517](https://reviews.llvm.org/D111517))
JaySon-Huang commented 1 year ago

Update it to be clang-15 support as 15.0.1 was released at Sep 20th

JaySon-Huang commented 1 year ago

Mark: we disable clang-analyzer-cplusplus.NewDeleteLeaks now as there is a false positive on boost::is_any_of. We need to add it back after upgraded to clang-15 https://github.com/pingcap/tiflash/pull/5955#discussion_r975974355

SchrodingerZhu commented 1 year ago

I am curious of what the plan is now? Could you reveal more details?

JaySon-Huang commented 1 year ago

@SchrodingerZhu I tried to build LLVM 15.0.1, but met two bugs when compiling compiler-rt, openmp. However, tiflash seems not depend on these two libs. https://github.com/pingcap/tiflash/pull/5264/files#diff-7882039fe139a7dd13da211a9e31d4d4df7f3e6117f5b48032b176596246ab08R42-R43

What really block me is that I can not build tiflash-proxy with clang 15.0.1 in our server environment. Seems it is not related to clang 15.0.1, but other components make it fail on our environment. I have to resolve them before pushing this forward.

breezewish commented 1 year ago

Some error related with Clang 15:

In file included from /workspace/tiflash/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp:31:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string.hpp:23:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string/split.hpp:16:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string/iter_find.hpp:27:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string/find_iterator.hpp:24:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string/detail/find_iterator.hpp:18:
In file included from /workspace/tiflash/contrib/boost/boost/function.hpp:30:
In file included from /workspace/tiflash/contrib/boost/boost/function/detail/prologue.hpp:17:
In file included from /workspace/tiflash/contrib/boost/boost/function/function_base.hpp:22:
/workspace/tiflash/contrib/boost/boost/type_traits/has_trivial_copy.hpp:34:4: error: builtin __has_trivial_copy is deprecated; use __is_trivially_copyable instead [-Werror,-Wdeprecated-builtins]
   BOOST_HAS_TRIVIAL_COPY(T) BOOST_TT_TRIVIAL_CONSTRUCT_FIX
   ^
/workspace/tiflash/contrib/boost/boost/type_traits/intrinsics.hpp:190:41: note: expanded from macro 'BOOST_HAS_TRIVIAL_COPY'
#     define BOOST_HAS_TRIVIAL_COPY(T) (__has_trivial_copy(T) && !is_reference<T>::value)
                                        ^
In file included from /workspace/tiflash/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp:31:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string.hpp:23:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string/split.hpp:16:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string/iter_find.hpp:27:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string/find_iterator.hpp:24:
In file included from /workspace/tiflash/contrib/boost/boost/algorithm/string/detail/find_iterator.hpp:18:
In file included from /workspace/tiflash/contrib/boost/boost/function.hpp:30:
In file included from /workspace/tiflash/contrib/boost/boost/function/detail/prologue.hpp:17:
In file included from /workspace/tiflash/contrib/boost/boost/function/function_base.hpp:23:
/workspace/tiflash/contrib/boost/boost/type_traits/has_trivial_destructor.hpp:30:86: error: builtin __has_trivial_destructor is deprecated; use __is_trivially_destructible instead [-Werror,-Wdeprecated-builtins]
template <typename T> struct has_trivial_destructor : public integral_constant<bool, BOOST_HAS_TRIVIAL_DESTRUCTOR(T)>{};
                                                                                     ^
/workspace/tiflash/contrib/boost/boost/type_traits/intrinsics.hpp:196:47: note: expanded from macro 'BOOST_HAS_TRIVIAL_DESTRUCTOR'
#     define BOOST_HAS_TRIVIAL_DESTRUCTOR(T) (__has_trivial_destructor(T)  && is_destructible<T>::value)
                                              ^
2 errors generated.
[44/223] Building CXX object dbms/CMake...ests/gtest_funtions_decimal_arith.cpp.o
ninja: build stopped: subcommand failed.
make: *** [dev] Error 1

May be better to migrate to new compiler-builtins, instead of just mute the warning I guess.

fuzhe1989 commented 1 year ago

@breezewish do you mean contribute to boost?

breezewish commented 1 year ago

@breezewish do you mean contribute to boost?

No, may be we could try to review whether a newer boost resolves it?

However, upgrading the boost may bring more issues. So I'm not sure about it.

JaySon-Huang commented 1 year ago

Not only boost, but many other third-party libs could throw warnings under clang-15. For example, https://github.com/tikv/rocksdb/pull/315

Maybe using the target_no_warning in cmake or a wrapper file to ignore is the easier way to fix the warnings from third-party libraries

fuzhe1989 commented 1 year ago

@JaySon-Huang could target_no_warning suppress warnings from included header files? @breezewish Even Boost 1.80 hasn't fixed these issues.

breezewish commented 1 year ago

Closed by #6936

JaySon-Huang commented 1 year ago

reopen because we do not support clang 15 in CI by now https://ci.pingcap.net/blue/organizations/jenkins/tiflash-build-common/detail/tiflash-build-common/20561/pipeline

JaySon-Huang commented 1 year ago

reopen because we do not support clang 15 in CI by now https://ci.pingcap.net/blue/organizations/jenkins/tiflash-build-common/detail/tiflash-build-common/20561/pipeline