1#===----------------------------------------------------------------------===## 2# 3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4# See https://llvm.org/LICENSE.txt for license information. 5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6# 7#===----------------------------------------------------------------------===## 8 9from libcxx.test.dsl import * 10from libcxx.test.features import _isMSVC 11import re 12 13_warningFlags = [ 14 '-Werror', 15 '-Wall', 16 '-Wctad-maybe-unsupported', 17 '-Wextra', 18 '-Wshadow', 19 '-Wundef', 20 '-Wunused-template', 21 '-Wno-unused-command-line-argument', 22 '-Wno-attributes', 23 '-Wno-pessimizing-move', 24 '-Wno-c++11-extensions', 25 '-Wno-noexcept-type', 26 '-Wno-aligned-allocation-unavailable', 27 '-Wno-atomic-alignment', 28 29 # GCC warns about places where we might want to add sized allocation/deallocation 30 # functions, but we know better what we're doing/testing in the test suite. 31 '-Wno-sized-deallocation', 32 33 # Turn off warnings about user-defined literals with reserved suffixes. Those are 34 # just noise since we are testing the Standard Library itself. 35 '-Wno-literal-suffix', # GCC 36 '-Wno-user-defined-literals', # Clang 37 38 # GCC warns about this when TEST_IS_CONSTANT_EVALUATED is used on a non-constexpr 39 # function. (This mostely happens in C++11 mode.) 40 # TODO(mordante) investigate a solution for this issue. 41 '-Wno-tautological-compare', 42 43 # -Wstringop-overread and -Wstringop-overflow seem to be a bit buggy currently 44 '-Wno-stringop-overread', 45 '-Wno-stringop-overflow', 46 47 # These warnings should be enabled in order to support the MSVC 48 # team using the test suite; They enable the warnings below and 49 # expect the test suite to be clean. 50 '-Wsign-compare', 51 '-Wunused-variable', 52 '-Wunused-parameter', 53 '-Wunreachable-code', 54 '-Wno-unused-local-typedef', 55] 56 57_allStandards = ['c++03', 'c++11', 'c++14', 'c++17', 'c++20', 'c++2b'] 58def getStdFlag(cfg, std): 59 fallbacks = { 60 'c++11': 'c++0x', 61 'c++14': 'c++1y', 62 'c++17': 'c++1z', 63 'c++20': 'c++2a', 64 } 65 if hasCompileFlag(cfg, '-std='+std): 66 return '-std='+std 67 if std in fallbacks and hasCompileFlag(cfg, '-std='+fallbacks[std]): 68 return '-std='+fallbacks[std] 69 return None 70 71DEFAULT_PARAMETERS = [ 72 Parameter(name='target_triple', type=str, 73 help="The target triple to compile the test suite for. This must be " 74 "compatible with the target that the tests will be run on.", 75 actions=lambda triple: filter(None, [ 76 AddFeature('target={}'.format(triple)), 77 AddFlagIfSupported('--target={}'.format(triple)), 78 AddSubstitution('%{triple}', triple) 79 ])), 80 81 Parameter(name='std', choices=_allStandards, type=str, 82 help="The version of the standard to compile the test suite with.", 83 default=lambda cfg: next(s for s in reversed(_allStandards) if getStdFlag(cfg, s)), 84 actions=lambda std: [ 85 AddFeature(std), 86 AddSubstitution('%{cxx_std}', re.sub('\+','x', std)), 87 AddCompileFlag(lambda cfg: getStdFlag(cfg, std)), 88 ]), 89 90 Parameter(name='enable_modules', choices=[True, False], type=bool, default=False, 91 help="Whether to build the test suite with Clang modules enabled.", 92 actions=lambda modules: [ 93 AddFeature('modules-build'), 94 AddCompileFlag('-fmodules'), 95 AddCompileFlag('-fcxx-modules'), # AppleClang disregards -fmodules entirely when compiling C++. This enables modules for C++. 96 ] if modules else []), 97 98 Parameter(name='enable_modules_lsv', choices=[True, False], type=bool, default=False, 99 help="Whether to enable Local Submodule Visibility in the Modules build.", 100 actions=lambda lsv: [ 101 AddCompileFlag('-Xclang -fmodules-local-submodule-visibility'), 102 ] if lsv else []), 103 104 Parameter(name='enable_exceptions', choices=[True, False], type=bool, default=True, 105 help="Whether to enable exceptions when compiling the test suite.", 106 actions=lambda exceptions: [] if exceptions else [ 107 AddFeature('no-exceptions'), 108 AddCompileFlag('-fno-exceptions') 109 ]), 110 111 Parameter(name='enable_rtti', choices=[True, False], type=bool, default=True, 112 help="Whether to enable RTTI when compiling the test suite.", 113 actions=lambda rtti: [] if rtti else [ 114 AddFeature('no-rtti'), 115 AddCompileFlag('-fno-rtti') 116 ]), 117 118 Parameter(name='stdlib', choices=['llvm-libc++', 'apple-libc++', 'libstdc++', 'msvc'], type=str, default='llvm-libc++', 119 help="""The C++ Standard Library implementation being tested. 120 121 Note that this parameter can also be used to encode different 'flavors' of the same 122 standard library, such as libc++ as shipped by a different vendor, if it has different 123 properties worth testing. 124 125 The Standard libraries currently supported are: 126 - llvm-libc++: The 'upstream' libc++ as shipped with LLVM. 127 - apple-libc++: libc++ as shipped by Apple. This is basically like the LLVM one, but 128 there are a few differences like installation paths, the use of 129 universal dylibs and the existence of availability markup. 130 - libstdc++: The GNU C++ library typically shipped with GCC. 131 - msvc: The Microsoft implementation of the C++ Standard Library. 132 """, 133 actions=lambda stdlib: filter(None, [ 134 AddFeature('stdlib={}'.format(stdlib)), 135 # Also add an umbrella feature 'stdlib=libc++' for all flavors of libc++, to simplify 136 # the test suite. 137 AddFeature('stdlib=libc++') if re.match('.+-libc\+\+', stdlib) else None 138 ])), 139 140 Parameter(name='enable_warnings', choices=[True, False], type=bool, default=True, 141 help="Whether to enable warnings when compiling the test suite.", 142 actions=lambda warnings: [] if not warnings else 143 [AddOptionalWarningFlag(w) for w in _warningFlags] + 144 [AddCompileFlag('-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER')] 145 ), 146 147 Parameter(name='use_sanitizer', choices=['', 'Address', 'HWAddress', 'Undefined', 'Memory', 'MemoryWithOrigins', 'Thread', 'DataFlow', 'Leaks'], type=str, default='', 148 help="An optional sanitizer to enable when building and running the test suite.", 149 actions=lambda sanitizer: filter(None, [ 150 AddFlag('-g -fno-omit-frame-pointer') if sanitizer else None, 151 152 AddFlag('-fsanitize=undefined -fno-sanitize=float-divide-by-zero -fno-sanitize-recover=all') if sanitizer == 'Undefined' else None, 153 AddFeature('ubsan') if sanitizer == 'Undefined' else None, 154 155 AddFlag('-fsanitize=address') if sanitizer == 'Address' else None, 156 AddFeature('asan') if sanitizer == 'Address' else None, 157 158 AddFlag('-fsanitize=hwaddress') if sanitizer == 'HWAddress' else None, 159 AddFeature('hwasan') if sanitizer == 'HWAddress' else None, 160 161 AddFlag('-fsanitize=memory') if sanitizer in ['Memory', 'MemoryWithOrigins'] else None, 162 AddFeature('msan') if sanitizer in ['Memory', 'MemoryWithOrigins'] else None, 163 AddFlag('-fsanitize-memory-track-origins') if sanitizer == 'MemoryWithOrigins' else None, 164 165 AddFlag('-fsanitize=thread') if sanitizer == 'Thread' else None, 166 AddFeature('tsan') if sanitizer == 'Thread' else None, 167 168 AddFlag('-fsanitize=dataflow') if sanitizer == 'DataFlow' else None, 169 AddFlag('-fsanitize=leaks') if sanitizer == 'Leaks' else None, 170 171 AddFeature('sanitizer-new-delete') if sanitizer in ['Address', 'HWAddress', 'Memory', 'MemoryWithOrigins', 'Thread'] else None, 172 ])), 173 174 Parameter(name='enable_experimental', choices=[True, False], type=bool, default=True, 175 help="Whether to enable tests for experimental C++ Library features.", 176 actions=lambda experimental: [ 177 # When linking in MSVC mode via the Clang driver, a -l<foo> 178 # maps to <foo>.lib, so we need to use -llibc++experimental here 179 # to make it link against the static libc++experimental.lib. 180 # We can't check for the feature 'msvc' in available_features 181 # as those features are added after processing parameters. 182 AddFeature('c++experimental'), 183 PrependLinkFlag(lambda cfg: '-llibc++experimental' if _isMSVC(cfg) else '-lc++experimental'), 184 AddCompileFlag('-D_LIBCPP_ENABLE_EXPERIMENTAL'), 185 ] if experimental else [ 186 AddFeature('libcpp-has-no-incomplete-format'), 187 ]), 188 189 Parameter(name='long_tests', choices=[True, False], type=bool, default=True, 190 help="Whether to enable tests that take longer to run. This can be useful when running on a very slow device.", 191 actions=lambda enabled: [] if not enabled else [ 192 AddFeature('long_tests') 193 ]), 194 195 Parameter(name='enable_assertions', choices=[True, False], type=bool, default=False, 196 help="Whether to enable assertions when compiling the test suite. This is only meaningful when " 197 "running the tests against libc++.", 198 actions=lambda assertions: [ 199 AddCompileFlag('-D_LIBCPP_ENABLE_ASSERTIONS=1'), 200 AddFeature('libcpp-has-assertions') 201 ] if assertions else []), 202 203 Parameter(name='additional_features', type=list, default=[], 204 help="A comma-delimited list of additional features that will be enabled when running the tests. " 205 "This should be used sparingly since specifying ad-hoc features manually is error-prone and " 206 "brittle in the long run as changes are made to the test suite.", 207 actions=lambda features: [AddFeature(f) for f in features]), 208 209 Parameter(name='enable_transitive_includes', choices=[True, False], type=bool, default=True, 210 help="Whether to enable backwards-compatibility transitive includes when running the tests. This " 211 "is provided to ensure that the trimmed-down version of libc++ does not bit-rot in between " 212 "points at which we bulk-remove transitive includes.", 213 actions=lambda enabled: [] if enabled else [ 214 AddFeature('transitive-includes-disabled'), 215 AddCompileFlag('-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES') 216 ]), 217] 218