Skip to content

Commit 75ab4e6

Browse files
committed
[NFC][LLDB] Make it possible to detect if the compiler used in tests supports -fbounds-safety
This patch makes it possible to detect in LLDB shell and API tests if `-fbounds-safety` is supported by the compiler used for testing. The motivation behind this is to allow upstreaming swiftlang#11835 but with the tests disabled in upstream because the full implementation of -fbounds-safety isn't available in Clang yet. For shell tests when -fbounds-safety is available the `clang-bounds-safety` feature is available which means tests can be annotated with `# REQUIRES: clang-bounds-safety`. API tests that need -fbounds-safety support in the compiler can use the new `@skipUnlessBoundsSafety` decorator. rdar://165225507
1 parent 418204d commit 75ab4e6

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

lldb/packages/Python/lldbsuite/test/decorators.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,15 @@ def is_compiler_with_address_sanitizer():
10581058

10591059
return skipTestIfFn(is_compiler_with_address_sanitizer)(func)
10601060

1061+
def skipUnlessBoundsSafety(func):
1062+
"""Decorate the item to skip test unless Clang -fbounds-safety is supported."""
1063+
1064+
def is_compiler_with_bounds_safety():
1065+
if not _compiler_supports(lldbplatformutil.getCompiler(), "-fbounds-safety"):
1066+
return "Compiler cannot compile with -fbounds-safety"
1067+
return None
1068+
1069+
return skipTestIfFn(is_compiler_with_bounds_safety)(func)
10611070

10621071
def skipIfAsan(func):
10631072
"""Skip this test if the environment is set up to run LLDB *itself* under ASAN."""

lldb/test/Shell/helper/toolchain.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ def use_support_substitutions(config):
277277
required=True,
278278
use_installed=True,
279279
)
280+
if llvm_config.clang_has_bounds_safety():
281+
llvm_config.lit_config.note("clang has -fbounds-safety support")
282+
config.available_features.add("clang-bounds-safety")
280283

281284
if sys.platform == "win32":
282285
_use_msvc_substitutions(config)

llvm/utils/lit/lit/llvm/config.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ def get_process_output(self, command):
293293
except OSError:
294294
self.lit_config.fatal("Could not run process %s" % command)
295295

296+
def check_process_success(self, command):
297+
cp = subprocess.run(command,
298+
stdout=subprocess.DEVNULL,
299+
stderr=subprocess.DEVNULL,
300+
env=self.config.environment)
301+
if cp.returncode == 0:
302+
return True
303+
return False
304+
296305
def feature_config(self, features):
297306
# Ask llvm-config about the specified feature.
298307
arguments = [x for (x, _) in features]
@@ -334,6 +343,25 @@ def get_clang_builtin_include_dir(self, clang):
334343
# Ensure the result is an ascii string, across Python2.5+ - Python3.
335344
return clang_dir
336345

346+
def clang_has_bounds_safety(self, additional_flags=None):
347+
"""
348+
Return True iff `self.config.clang` supports -fbounds-safety
349+
"""
350+
if not self.config.clang:
351+
return False
352+
if not os.path.exists(self.config.clang):
353+
return False
354+
if additional_flags is None:
355+
additional_flags = []
356+
# Invoke the clang driver to see if it supports the `-fbounds-safety`
357+
# flag. Only the downstream implementation has this flag so this is
358+
# a simple way to check if the full implementation is available or not.
359+
cmd = [ self.config.clang ] + additional_flags
360+
cmd += ['-fbounds-safety', '-###']
361+
if self.check_process_success(cmd):
362+
return True
363+
return False
364+
337365
# On macOS, LSan is only supported on clang versions 5 and higher
338366
def get_clang_has_lsan(self, clang, triple):
339367
if not clang:

0 commit comments

Comments
 (0)