[libc++][test] Enhance ADDITIONAL_COMPILE_FLAGS, use TEST_MEOW_DIAGNOSTIC_IGNORED sparingly (#75317)

This is the last PR that's needed (for now) to get libc++'s tests
working with MSVC's STL.

The ADDITIONAL_COMPILE_FLAGS machinery is very useful, but also very
problematic for MSVC, as it doesn't understand most of Clang's compiler
options. We've been dealing with this by simply marking anything that
uses ADDITIONAL_COMPILE_FLAGS as FAIL or SKIPPED, but that creates
significant gaps in test coverage.

Fortunately, ADDITIONAL_COMPILE_FLAGS also supports "features", which
can be slightly enhanced to send Clang-compatible and MSVC-compatible
options to the right compilers.

This patch adds the gcc-style-warnings and cl-style-warnings Lit features,
and uses that to pass the appropriate warning flags to tests. It also uses
TEST_MEOW_DIAGNOSTIC_IGNORED for a few local suppressions of MSVC
warnings.
This commit is contained in:
Stephan T. Lavavej 2023-12-14 14:38:27 -08:00 committed by GitHub
parent 4070dffd34
commit 64addd6521
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 96 additions and 42 deletions

View File

@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//
// MSVC warning C4244: 'argument': conversion from 'const _Ty2' to 'T', possible loss of data
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4244
// <algorithm>
// UNSUPPORTED: c++03, c++11, c++14, c++17

View File

@ -19,7 +19,11 @@
// equal(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
// We test the cartesian product, so we sometimes compare differently signed types
// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-sign-compare
// MSVC warning C4242: 'argument': conversion from 'int' to 'const _Ty', possible loss of data
// MSVC warning C4244: 'argument': conversion from 'wchar_t' to 'const _Ty', possible loss of data
// MSVC warning C4389: '==': signed/unsigned mismatch
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4242 /wd4244 /wd4389
#include <algorithm>
#include <cassert>
@ -58,6 +62,10 @@ struct Test {
struct TestNarrowingEqualTo {
template <class UnderlyingType>
TEST_CONSTEXPR_CXX20 void operator()() {
TEST_DIAGNOSTIC_PUSH
// MSVC warning C4310: cast truncates constant value
TEST_MSVC_DIAGNOSTIC_IGNORED(4310)
UnderlyingType a[] = {
UnderlyingType(0x1000),
UnderlyingType(0x1001),
@ -71,6 +79,8 @@ struct TestNarrowingEqualTo {
UnderlyingType(0x1603),
UnderlyingType(0x1604)};
TEST_DIAGNOSTIC_POP
assert(std::equal(a, a + 5, b, std::equal_to<char>()));
#if TEST_STD_VER >= 14
assert(std::equal(a, a + 5, b, b + 5, std::equal_to<char>()));

View File

@ -6,7 +6,9 @@
//
//===----------------------------------------------------------------------===//
// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-sign-compare
// MSVC warning C4389: '==': signed/unsigned mismatch
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4389
// <algorithm>

View File

@ -10,7 +10,10 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// ADDITIONAL_COMPILE_FLAGS: -Wno-sign-compare
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-sign-compare
// MSVC warning C4242: 'argument': conversion from 'const _Ty' to 'ElementT', possible loss of data
// MSVC warning C4244: 'argument': conversion from 'const _Ty' to 'ElementT', possible loss of data
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4242 /wd4244
// template<input_iterator I, sentinel_for<I> S, class T, class Proj = identity>
// requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>

View File

@ -74,9 +74,15 @@ void test() {
TEST_IGNORE_NODISCARD a.is_lock_free();
TEST_DIAGNOSTIC_PUSH
// MSVC warning C4197: 'volatile std::atomic<operator_hijacker>': top-level volatile in cast is ignored
TEST_MSVC_DIAGNOSTIC_IGNORED(4197)
TEST_IGNORE_NODISCARD T();
TEST_IGNORE_NODISCARD T(v);
TEST_DIAGNOSTIC_POP
TEST_IGNORE_NODISCARD a.load();
TEST_IGNORE_NODISCARD static_cast<typename T::value_type>(a);
a.store(v);

View File

@ -98,8 +98,16 @@ void test() {
a.store(v);
a = v;
TEST_DIAGNOSTIC_PUSH
// MSVC warning C4197: 'volatile std::atomic<operator_hijacker *>': top-level volatile in cast is ignored
TEST_MSVC_DIAGNOSTIC_IGNORED(4197)
TEST_IGNORE_NODISCARD T();
TEST_IGNORE_NODISCARD T(v);
TEST_DIAGNOSTIC_POP
TEST_IGNORE_NODISCARD a.load();
TEST_IGNORE_NODISCARD static_cast<typename T::value_type>(a);
TEST_IGNORE_NODISCARD* a;

View File

@ -10,7 +10,7 @@
// We voluntarily use std::default_initializable on types that have redundant
// or ignored cv-qualifiers -- don't warn about it.
// ADDITIONAL_COMPILE_FLAGS: -Wno-ignored-qualifiers
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-ignored-qualifiers
// template<class T>
// concept default_initializable = constructible_from<T> &&

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-missing-field-initializers
// <map>

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-missing-field-initializers
// <map>

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-missing-field-initializers
// <set>

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-missing-field-initializers
// <set>

View File

@ -11,7 +11,7 @@
// template <size_t I, class T, size_t N> T& get(array<T, N>& a);
// Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify.
// ADDITIONAL_COMPILE_FLAGS: -Wno-array-bounds
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-array-bounds
#include <array>
#include <cassert>

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-missing-field-initializers
// <unordered_map>

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-missing-field-initializers
// <unordered_map>

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-missing-field-initializers
// <set>

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
// ADDITIONAL_COMPILE_FLAGS: -Wno-missing-field-initializers
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-missing-field-initializers
// <set>

View File

@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// ADDITIONAL_COMPILE_FLAGS: -Wno-ctad-maybe-unsupported
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-ctad-maybe-unsupported
// <mdspan>

View File

@ -7,6 +7,9 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// MSVC warning C4244: 'initializing': conversion from '_Ty' to '_Ty', possible loss of data
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4244
// <mdspan>
// template<class OtherElementType, class OtherExtents,

View File

@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//
// MSVC warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4611
// test <setjmp.h>
//
// Even though <setjmp.h> is not provided by libc++, we still test that

View File

@ -8,7 +8,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// ADDITIONAL_COMPILE_FLAGS: -Wno-unused-value
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-unused-value
#include <limits>

View File

@ -7,6 +7,9 @@
//===----------------------------------------------------------------------===//
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT
// MSVC warning C4242: '+=': conversion from 'const _Ty' to 'size_t', possible loss of data
// MSVC warning C4244: 'argument': conversion from 'std::streamsize' to 'size_t', possible loss of data
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4242 /wd4244
// UNSUPPORTED: c++03
// <fstream>

View File

@ -7,6 +7,9 @@
//===----------------------------------------------------------------------===//
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_CODECVT
// MSVC warning C4242: '+=': conversion from 'const _Ty' to 'size_t', possible loss of data
// MSVC warning C4244: 'argument': conversion from 'std::streamsize' to 'size_t', possible loss of data
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4242 /wd4244
// UNSUPPORTED: c++03
// <fstream>

View File

@ -27,7 +27,7 @@
// <TODO:Remove brackets> below
// Make sure we catch forced conversions to the difference_type if they happen.
// ADDITIONAL_COMPILE_FLAGS<TODO:Remove brackets>: -Wsign-conversion
// ADDITIONAL_COMPILE_FLAGS<TODO:Remove brackets>(gcc-style-warnings): -Wsign-conversion
#include <iterator>
#include <cassert>

View File

@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//
// MSVC warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4611
// test <csetjmp>
#include <csetjmp>

View File

@ -8,6 +8,9 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
// This is a compile-only test, so "inline function is not defined" warnings are irrelevant.
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-undefined-inline
// template<input_range V, forward_range Pattern>
// requires view<V> && view<Pattern> &&
// indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&

View File

@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//
// MSVC warning C4244: 'argument': conversion from '_Ty' to 'int', possible loss of data
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd4244
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// template<class C, input_range R, class... Args> requires (!view<C>)

View File

@ -10,7 +10,7 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// To silence a GCC warning-turned-error re. `BadAlloc::value_type`.
// ADDITIONAL_COMPILE_FLAGS: -Wno-unused-local-typedefs
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-unused-local-typedefs
// template<ranges::input_range R,
// class Allocator = allocator<ranges::range_value_t<R>>>

View File

@ -35,6 +35,10 @@
int condition_variable_lock_skipped_counter = 0;
TEST_DIAGNOSTIC_PUSH
// MSVC warning C4583: 'X::cv_': destructor is not implicitly called
TEST_MSVC_DIAGNOSTIC_IGNORED(4583)
union X {
X() : cv_() {}
~X() {}
@ -42,6 +46,8 @@ union X {
unsigned char bytes_[sizeof(std::condition_variable)];
};
TEST_DIAGNOSTIC_POP
void test()
{
constexpr int N = 3;

View File

@ -10,7 +10,7 @@
// UNSUPPORTED: libcpp-has-no-experimental-stop_token
// UNSUPPORTED: c++03, c++11, c++14, c++17
// XFAIL: availability-synchronization_library-missing
// ADDITIONAL_COMPILE_FLAGS: -Wno-self-move
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-self-move
// jthread& operator=(jthread&&) noexcept;

View File

@ -23,9 +23,10 @@
// Ignore warnings about volatile in parameters being deprecated.
// We know it is, but we still have to test it.
#if defined(TEST_COMPILER_GCC)
# pragma GCC diagnostic ignored "-Wvolatile"
#endif
TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-volatile")
TEST_GCC_DIAGNOSTIC_IGNORED("-Wvolatile")
// MSVC warning C5215: a function parameter with a volatile qualified type is deprecated in C++20
TEST_MSVC_DIAGNOSTIC_IGNORED(5215)
struct wat
{
@ -65,9 +66,6 @@ void test_result_of_imp()
#endif
}
// Do not warn on deprecated uses of 'volatile' below.
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
int main(int, char**)
{
{
@ -184,5 +182,3 @@ int main(int, char**)
return 0;
}
_LIBCPP_SUPPRESS_DEPRECATED_POP

View File

@ -11,7 +11,9 @@
// UNSUPPORTED: c++03, c++11
// ignore deprecated volatile return types
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated-volatile
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-deprecated-volatile
// MSVC warning C5216: 'volatile int' a volatile qualified return type is deprecated in C++20
// ADDITIONAL_COMPILE_FLAGS(cl-style-warnings): /wd5216
#include <type_traits>
#include <utility>

View File

@ -9,7 +9,7 @@
// UNSUPPORTED: c++03
// Self assignment post-conditions are tested.
// ADDITIONAL_COMPILE_FLAGS: -Wno-self-move
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-self-move
// <memory>

View File

@ -16,8 +16,8 @@
// We make sure that it is not ill-formed, however we still produce a warning for
// this one because explicit construction from a variant using CTAD is ambiguous
// (in the sense that the programer intent is not clear).
// ADDITIONAL_COMPILE_FLAGS: -Wno-ctad-maybe-unsupported
// (in the sense that the programmer intent is not clear).
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-ctad-maybe-unsupported
#include <variant>

View File

@ -104,14 +104,4 @@ const AssertionDialogAvoider assertion_dialog_avoider{};
#define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
#ifdef __clang__
# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
#else // ^^^ clang / MSVC vvv
# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
__pragma(warning(push)) __pragma(warning(disable : 4996)) __pragma(warning(disable : 5215))
# define _LIBCPP_SUPPRESS_DEPRECATED_POP __pragma(warning(pop))
#endif // __clang__
#endif // SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H

View File

@ -13,9 +13,13 @@ import shutil
import subprocess
import sys
_isClang = lambda cfg: "__clang__" in compilerMacros(cfg) and "__apple_build_version__" not in compilerMacros(cfg)
_isAnyClang = lambda cfg: "__clang__" in compilerMacros(cfg)
_isAppleClang = lambda cfg: "__apple_build_version__" in compilerMacros(cfg)
_isGCC = lambda cfg: "__GNUC__" in compilerMacros(cfg) and "__clang__" not in compilerMacros(cfg)
_isAnyGCC = lambda cfg: "__GNUC__" in compilerMacros(cfg)
_isClang = lambda cfg: _isAnyClang(cfg) and not _isAppleClang(cfg)
_isGCC = lambda cfg: _isAnyGCC(cfg) and not _isAnyClang(cfg)
_isAnyClangOrGCC = lambda cfg: _isAnyClang(cfg) or _isAnyGCC(cfg)
_isClExe = lambda cfg: not _isAnyClangOrGCC(cfg)
_isMSVC = lambda cfg: "_MSC_VER" in compilerMacros(cfg)
_msvcVersion = lambda cfg: (int(compilerMacros(cfg)["_MSC_VER"]) // 100, int(compilerMacros(cfg)["_MSC_VER"]) % 100)
@ -61,6 +65,9 @@ def _getAndroidDeviceApi(cfg):
# Lit features are evaluated in order. Some checks may require the compiler detection to have
# run first in order to work properly.
DEFAULT_FEATURES = [
# gcc-style-warnings detects compilers that understand -Wno-meow flags, unlike MSVC's compiler driver cl.exe.
Feature(name="gcc-style-warnings", when=_isAnyClangOrGCC),
Feature(name="cl-style-warnings", when=_isClExe),
Feature(name="apple-clang", when=_isAppleClang),
Feature(
name=lambda cfg: "apple-clang-{__clang_major__}".format(**compilerMacros(cfg)),