Skip to content

Commit 4e10d4f

Browse files
authored
gh-111178: Set function=False by default in support.check_sanitizer() (#161640)
Update also libregrtest.utils to detect function sanitizer (-fsanitize=function).
1 parent b4201c7 commit 4e10d4f

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎Lib/test/libregrtest/utils.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ def get_build_info():
414414
# --with-thread-sanitizer
415415
if support.check_sanitizer(thread=True):
416416
sanitizers.append("TSAN")
417+
# --with-thread-sanitizer
418+
if support.check_sanitizer(function=True):
419+
sanitizers.append("fsanitize=function")
417420
if sanitizers:
418421
build.append('+'.join(sanitizers))
419422

@@ -701,6 +704,7 @@ def display_header(use_resources: dict[str, str | None],
701704
msan = support.check_sanitizer(memory=True)
702705
ubsan = support.check_sanitizer(ub=True)
703706
tsan = support.check_sanitizer(thread=True)
707+
function_san = support.check_sanitizer(function=True)
704708
sanitizers = []
705709
if asan:
706710
sanitizers.append("address")
@@ -710,12 +714,14 @@ def display_header(use_resources: dict[str, str | None],
710714
sanitizers.append("undefined behavior")
711715
if tsan:
712716
sanitizers.append("thread")
717+
if function_san:
718+
sanitizers.append("function")
713719
if sanitizers:
714720
print(f"== sanitizers: {', '.join(sanitizers)}")
715721
for sanitizer, env_var in (
716722
(asan, "ASAN_OPTIONS"),
717723
(msan, "MSAN_OPTIONS"),
718-
(ubsan, "UBSAN_OPTIONS"),
724+
(ubsan or function_san, "UBSAN_OPTIONS"),
719725
(tsan, "TSAN_OPTIONS"),
720726
):
721727
options= os.environ.get(env_var)

‎Lib/test/support/__init__.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ def skip_if_buildbot(reason=None):
462462
return unittest.skipIf(isbuildbot, reason)
463463

464464
def check_sanitizer(*, address=False, hwaddress=False, memory=False, ub=False,
465-
thread=False, function=True):
465+
thread=False, function=False):
466466
"""Returns True if Python is compiled with sanitizer support"""
467-
if not (address or hwaddress or memory or ub or thread):
468-
raise ValueError('At least one of address, hwaddress, memory, ub or '
469-
'thread must be True')
467+
if not (address or hwaddress or memory or ub or thread or function):
468+
raise ValueError('At least one of address, hwaddress, memory, ub, '
469+
'thread or function must be True')
470470

471471

472472
cflags = sysconfig.get_config_var('CFLAGS') or ''
@@ -517,11 +517,13 @@ def configured_with_sanitizer(name):
517517
)
518518

519519

520-
def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False, thread=False):
520+
def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False,
521+
thread=False, function=False):
521522
"""Decorator raising SkipTest if running with a sanitizer active."""
522523
if not reason:
523524
reason = 'not working with sanitizers active'
524-
skip = check_sanitizer(address=address, memory=memory, ub=ub, thread=thread)
525+
skip = check_sanitizer(address=address, memory=memory, ub=ub,
526+
thread=thread, function=function)
525527
return unittest.skipIf(skip, reason)
526528

527529
# gh-89363: True if fork() can hang if Python is built with Address Sanitizer

0 commit comments

Comments
 (0)