[libcxx-commits] [libcxx] 31bcdb6 - [libc++] Translate the test suite sanitizer support to the DSL
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 20 12:29:50 PDT 2021
Author: Louis Dionne
Date: 2021-05-20T15:30:48-04:00
New Revision: 31bcdb66357c019614403bddb4fc629b3b97d217
URL: https://github.com/llvm/llvm-project/commit/31bcdb66357c019614403bddb4fc629b3b97d217
DIFF: https://github.com/llvm/llvm-project/commit/31bcdb66357c019614403bddb4fc629b3b97d217.diff
LOG: [libc++] Translate the test suite sanitizer support to the DSL
Differential Revision: https://reviews.llvm.org/D102108
Added:
Modified:
libcxx/utils/libcxx/test/config.py
libcxx/utils/libcxx/test/params.py
Removed:
################################################################################
diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py
index 106d228948bf0..c7ce00af74214 100644
--- a/libcxx/utils/libcxx/test/config.py
+++ b/libcxx/utils/libcxx/test/config.py
@@ -129,7 +129,6 @@ def configure(self):
self.configure_compile_flags()
self.configure_link_flags()
self.configure_env()
- self.configure_sanitizer()
self.configure_coverage()
self.configure_modules()
self.configure_substitutions()
@@ -463,67 +462,6 @@ def configure_extra_library_flags(self):
self.cxx.link_flags += ['-lc++external_threads']
self.target_info.add_cxx_link_flags(self.cxx.link_flags)
- def configure_sanitizer(self):
- san = self.get_lit_conf('use_sanitizer', '').strip()
- if san:
- # Search for llvm-symbolizer along the compiler path first
- # and then along the PATH env variable.
- symbolizer_search_paths = os.environ.get('PATH', '')
- cxx_path = libcxx.util.which(self.cxx.path)
- if cxx_path is not None:
- symbolizer_search_paths = (
- os.path.dirname(cxx_path) +
- os.pathsep + symbolizer_search_paths)
- llvm_symbolizer = libcxx.util.which('llvm-symbolizer',
- symbolizer_search_paths)
-
- def add_ubsan():
- self.cxx.flags += ['-fsanitize=undefined',
- '-fno-sanitize=float-divide-by-zero',
- '-fno-sanitize-recover=all']
- self.exec_env['UBSAN_OPTIONS'] = 'print_stacktrace=1'
- self.config.available_features.add('ubsan')
-
- # Setup the sanitizer compile flags
- self.cxx.flags += ['-g', '-fno-omit-frame-pointer']
- if san == 'Address' or san == 'Address;Undefined' or san == 'Undefined;Address':
- self.cxx.flags += ['-fsanitize=address']
- if llvm_symbolizer is not None:
- self.exec_env['ASAN_SYMBOLIZER_PATH'] = llvm_symbolizer
- self.config.available_features.add('asan')
- self.config.available_features.add('sanitizer-new-delete')
- self.cxx.compile_flags += ['-O1']
- if san == 'Address;Undefined' or san == 'Undefined;Address':
- add_ubsan()
- elif san == 'Memory' or san == 'MemoryWithOrigins':
- self.cxx.flags += ['-fsanitize=memory']
- if san == 'MemoryWithOrigins':
- self.cxx.compile_flags += [
- '-fsanitize-memory-track-origins']
- if llvm_symbolizer is not None:
- self.exec_env['MSAN_SYMBOLIZER_PATH'] = llvm_symbolizer
- self.config.available_features.add('msan')
- self.config.available_features.add('sanitizer-new-delete')
- self.cxx.compile_flags += ['-O1']
- elif san == 'Undefined':
- add_ubsan()
- self.cxx.compile_flags += ['-O2']
- elif san == 'Thread':
- self.cxx.flags += ['-fsanitize=thread']
- self.config.available_features.add('tsan')
- self.config.available_features.add('sanitizer-new-delete')
- elif san == 'DataFlow':
- self.cxx.flags += ['-fsanitize=dataflow']
- elif san == 'Leaks':
- self.cxx.link_flags += ['-fsanitize=leaks']
- else:
- self.lit_config.fatal('unsupported value for '
- 'use_sanitizer: {0}'.format(san))
- san_lib = self.get_lit_conf('sanitizer_library')
- if san_lib:
- self.cxx.link_flags += [
- san_lib, '-Wl,-rpath,%s' % os.path.dirname(san_lib)]
-
def configure_coverage(self):
self.generate_coverage = self.get_lit_bool('generate_coverage', False)
if self.generate_coverage:
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index 6ed31d6c1994a..068bfcef2df57 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -110,6 +110,30 @@ def getStdFlag(cfg, std):
AddCompileFlag('-D_LIBCPP_DEBUG={}'.format(debugLevel))
]),
+ Parameter(name='use_sanitizer', choices=['', 'Address', 'Undefined', 'Memory', 'MemoryWithOrigins', 'Thread', 'DataFlow', 'Leaks'], type=str, default='',
+ help="An optional sanitizer to enable when building and running the test suite.",
+ actions=lambda sanitizer: filter(None, [
+ AddFlag('-g -fno-omit-frame-pointer') if sanitizer else None,
+
+ AddFlag('-fsanitize=undefined -fno-sanitize=float-divide-by-zero -fno-sanitize-recover=all') if sanitizer == 'Undefined' else None,
+ AddFeature('ubsan') if sanitizer == 'Undefined' else None,
+
+ AddFlag('-fsanitize=address') if sanitizer == 'Address' else None,
+ AddFeature('asan') if sanitizer == 'Address' else None,
+
+ AddFlag('-fsanitize=memory') if sanitizer in ['Memory', 'MemoryWithOrigins'] else None,
+ AddFeature('msan') if sanitizer in ['Memory', 'MemoryWithOrigins'] else None,
+ AddFlag('-fsanitize-memory-track-origins') if sanitizer == 'MemoryWithOrigins' else None,
+
+ AddFlag('-fsanitize=thread') if sanitizer == 'Thread' else None,
+ AddFeature('tsan') if sanitizer == 'Thread' else None,
+
+ AddFlag('-fsanitize=dataflow') if sanitizer == 'DataFlow' else None,
+ AddFlag('-fsanitize=leaks') if sanitizer == 'Leaks' else None,
+
+ AddFeature('sanitizer-new-delete') if sanitizer in ['Address', 'Memory', 'MemoryWithOrigins', 'Thread'] else None,
+ ])),
+
# Parameters to enable or disable parts of the test suite
Parameter(name='enable_experimental', choices=[True, False], type=bool, default=False,
help="Whether to enable tests for experimental C++ libraries (typically Library Fundamentals TSes).",
More information about the libcxx-commits
mailing list