[libcxx-commits] [libcxx] d6e2bac - [libc++] Migrate warning flags to the DSL
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 2 09:25:16 PST 2020
Author: Louis Dionne
Date: 2020-11-02T12:25:05-05:00
New Revision: d6e2bac19554a6f877e36d09547b3686b5d7ddb1
URL: https://github.com/llvm/llvm-project/commit/d6e2bac19554a6f877e36d09547b3686b5d7ddb1
DIFF: https://github.com/llvm/llvm-project/commit/d6e2bac19554a6f877e36d09547b3686b5d7ddb1.diff
LOG: [libc++] Migrate warning flags to the DSL
This makes us closer to running the test suite on platforms where the
legacy test suite configuration doesn't work.
One notable change after this commit is that the tests will be run with
warnings enabled on GCC too, which wasn't the case before. However,
previous commits should have tweaked the test suite to make sure it
passes with warnings enabled on GCC.
Note that warnings can still be disabled with `--param enable_warnings=False`,
as before.
Differential Revision: https://reviews.llvm.org/D90432
Added:
Modified:
libcxx/docs/TestingLibcxx.rst
libcxx/utils/libcxx/test/config.py
libcxx/utils/libcxx/test/dsl.py
libcxx/utils/libcxx/test/params.py
Removed:
################################################################################
diff --git a/libcxx/docs/TestingLibcxx.rst b/libcxx/docs/TestingLibcxx.rst
index b628fee538b8..12edc236ed73 100644
--- a/libcxx/docs/TestingLibcxx.rst
+++ b/libcxx/docs/TestingLibcxx.rst
@@ -63,8 +63,8 @@ Some other common examples include:
# Specify a custom compiler.
$ <build>/bin/llvm-lit -sv libcxx/test/std --param=cxx_under_test=/opt/bin/g++
- # Enable warnings in the test suite
- $ <build>/bin/llvm-lit -sv libcxx/test --param=enable_warnings=true
+ # Disable warnings in the test suite
+ $ <build>/bin/llvm-lit -sv libcxx/test --param=enable_warnings=False
# Use UBSAN when running the tests.
$ <build>/bin/llvm-lit -sv libcxx/test --param=use_sanitizer=Undefined
diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py
index a84ef4a1a22d..f6ff8b153080 100644
--- a/libcxx/utils/libcxx/test/config.py
+++ b/libcxx/utils/libcxx/test/config.py
@@ -131,7 +131,6 @@ def configure(self):
self.configure_link_flags()
self.configure_env()
self.configure_debug_mode()
- self.configure_warnings()
self.configure_sanitizer()
self.configure_coverage()
self.configure_modules()
@@ -335,6 +334,12 @@ def configure_default_compile_flags(self):
if not self.use_system_cxx_lib:
self.cxx.compile_flags += ['-D_LIBCPP_DISABLE_AVAILABILITY']
+ # On GCC, the libc++ headers cause errors due to throw() decorators
+ # on operator new clashing with those from the test suite, so we
+ # don't enable warnings in system headers on GCC.
+ if self.cxx.type != 'gcc':
+ self.cxx.compile_flags += ['-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER']
+
# Add includes for the PSTL headers
pstl_src_root = self.get_lit_conf('pstl_src_root')
pstl_obj_root = self.get_lit_conf('pstl_obj_root')
@@ -505,41 +510,6 @@ def configure_debug_mode(self):
% debug_level)
self.cxx.compile_flags += ['-D_LIBCPP_DEBUG=%s' % debug_level]
- def configure_warnings(self):
- # Turn on warnings by default for Clang based compilers
- default_enable_warnings = self.cxx.type in ['clang', 'apple-clang']
- enable_warnings = self.get_lit_bool('enable_warnings',
- default_enable_warnings)
- self.cxx.useWarnings(enable_warnings)
- self.cxx.warning_flags += ['-Werror', '-Wall', '-Wextra']
- # On GCC, the libc++ headers cause errors due to throw() decorators
- # on operator new clashing with those from the test suite, so we
- # don't enable warnings in system headers on GCC.
- if self.cxx.type != 'gcc':
- self.cxx.warning_flags += ['-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER']
- self.cxx.addWarningFlagIfSupported('-Wshadow')
- self.cxx.addWarningFlagIfSupported('-Wno-unused-command-line-argument')
- self.cxx.addWarningFlagIfSupported('-Wno-attributes')
- self.cxx.addWarningFlagIfSupported('-Wno-pessimizing-move')
- self.cxx.addWarningFlagIfSupported('-Wno-c++11-extensions')
- self.cxx.addWarningFlagIfSupported('-Wno-user-defined-literals')
- self.cxx.addWarningFlagIfSupported('-Wno-noexcept-type')
- self.cxx.addWarningFlagIfSupported('-Wno-aligned-allocation-unavailable')
- self.cxx.addWarningFlagIfSupported('-Wno-atomic-alignment')
-
- # GCC warns about places where we might want to add sized allocation/deallocation
- # functions, but we know better what we're doing/testing in the test suite.
- self.cxx.addWarningFlagIfSupported('-Wno-sized-deallocation')
-
- # These warnings should be enabled in order to support the MSVC
- # team using the test suite; They enable the warnings below and
- # expect the test suite to be clean.
- self.cxx.addWarningFlagIfSupported('-Wsign-compare')
- self.cxx.addWarningFlagIfSupported('-Wunused-variable')
- self.cxx.addWarningFlagIfSupported('-Wunused-parameter')
- self.cxx.addWarningFlagIfSupported('-Wunreachable-code')
- self.cxx.addWarningFlagIfSupported('-Wno-unused-local-typedef')
-
def configure_sanitizer(self):
san = self.get_lit_conf('use_sanitizer', '').strip()
if san:
diff --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py
index 14d3a0eff3c4..5171c7569bb9 100644
--- a/libcxx/utils/libcxx/test/dsl.py
+++ b/libcxx/utils/libcxx/test/dsl.py
@@ -335,6 +335,27 @@ def pretty(self, config, litParams):
return 'add {} to %{{link_flags}}'.format(self._getFlag(config))
+class AddOptionalWarningFlag(ConfigAction):
+ """
+ This action adds the given warning flag to the %{compile_flags} substitution,
+ if it is supported by the compiler.
+
+ The flag can be a string or a callable, in which case it is called with the
+ configuration to produce the actual flag (as a string).
+ """
+ def __init__(self, flag):
+ self._getFlag = lambda config: flag(config) if callable(flag) else flag
+
+ def applyTo(self, config):
+ flag = self._getFlag(config)
+ # Use -Werror to make sure we see an error about the flag being unsupported.
+ if hasCompileFlag(config, '-Werror ' + flag):
+ config.substitutions = _addToSubstitution(config.substitutions, '%{compile_flags}', flag)
+
+ def pretty(self, config, litParams):
+ return 'add {} to %{{compile_flags}}'.format(self._getFlag(config))
+
+
class Feature(object):
"""
Represents a Lit available feature that is enabled whenever it is supported.
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index 8e6e4234d6ed..e9c0f73077fa 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -9,6 +9,33 @@
from libcxx.test.dsl import *
_allStandards = ['c++03', 'c++11', 'c++14', 'c++17', 'c++2a']
+_warningFlags = [
+ '-Werror',
+ '-Wall',
+ '-Wextra',
+ '-Wshadow',
+ '-Wno-unused-command-line-argument',
+ '-Wno-attributes',
+ '-Wno-pessimizing-move',
+ '-Wno-c++11-extensions',
+ '-Wno-user-defined-literals',
+ '-Wno-noexcept-type',
+ '-Wno-aligned-allocation-unavailable',
+ '-Wno-atomic-alignment',
+
+ # GCC warns about places where we might want to add sized allocation/deallocation
+ # functions, but we know better what we're doing/testing in the test suite.
+ '-Wno-sized-deallocation',
+
+ # These warnings should be enabled in order to support the MSVC
+ # team using the test suite; They enable the warnings below and
+ # expect the test suite to be clean.
+ '-Wsign-compare',
+ '-Wunused-variable',
+ '-Wunused-parameter',
+ '-Wunreachable-code',
+ '-Wno-unused-local-typedef',
+]
DEFAULT_PARAMETERS = [
# Core parameters of the test suite
@@ -40,6 +67,12 @@
AddFeature(stdlib)
]),
+ Parameter(name='enable_warnings', choices=[True, False], type=bool, default=True,
+ help="Whether to enable warnings when compiling the test suite.",
+ actions=lambda warnings: [] if not warnings else [
+ AddOptionalWarningFlag(w) for w in _warningFlags
+ ]),
+
# Parameters to enable or disable parts of the test suite
Parameter(name='enable_filesystem', choices=[True, False], type=bool, default=True,
help="Whether to enable tests for the C++ <filesystem> library.",
More information about the libcxx-commits
mailing list