Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lldb/packages/Python/lldbsuite/test/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,15 @@ def is_compiler_with_address_sanitizer():

return skipTestIfFn(is_compiler_with_address_sanitizer)(func)

def skipUnlessBoundsSafety(func):
"""Decorate the item to skip test unless Clang -fbounds-safety is supported."""

def is_compiler_with_bounds_safety():
if not _compiler_supports(lldbplatformutil.getCompiler(), "-fbounds-safety"):
return "Compiler cannot compile with -fbounds-safety"
return None

return skipTestIfFn(is_compiler_with_bounds_safety)(func)

def skipIfAsan(func):
"""Skip this test if the environment is set up to run LLDB *itself* under ASAN."""
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/Shell/helper/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ def use_support_substitutions(config):
required=True,
use_installed=True,
)
if llvm_config.clang_has_bounds_safety():
llvm_config.lit_config.note("clang has -fbounds-safety support")
config.available_features.add("clang-bounds-safety")

if sys.platform == "win32":
_use_msvc_substitutions(config)
Expand Down
28 changes: 28 additions & 0 deletions llvm/utils/lit/lit/llvm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ def get_process_output(self, command):
except OSError:
self.lit_config.fatal("Could not run process %s" % command)

def check_process_success(self, command):
cp = subprocess.run(command,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
env=self.config.environment)
if cp.returncode == 0:
return True
return False

def feature_config(self, features):
# Ask llvm-config about the specified feature.
arguments = [x for (x, _) in features]
Expand Down Expand Up @@ -334,6 +343,25 @@ def get_clang_builtin_include_dir(self, clang):
# Ensure the result is an ascii string, across Python2.5+ - Python3.
return clang_dir

def clang_has_bounds_safety(self, additional_flags=None):
"""
Return True iff `self.config.clang` supports -fbounds-safety
"""
if not self.config.clang:
return False
if not os.path.exists(self.config.clang):
return False
if additional_flags is None:
additional_flags = []
# Invoke the clang driver to see if it supports the `-fbounds-safety`
# flag. Only the downstream implementation has this flag so this is
# a simple way to check if the full implementation is available or not.
cmd = [ self.config.clang ] + additional_flags
cmd += ['-fbounds-safety', '-###']
if self.check_process_success(cmd):
return True
return False

# On macOS, LSan is only supported on clang versions 5 and higher
def get_clang_has_lsan(self, clang, triple):
if not clang:
Expand Down