Skip to content

Commit e3a433c

Browse files
[3.14] gh-111178: Set function=False by default in support.check_sanitizer() (GH-161640) (GH-161713) (#161720)
[3.15] gh-111178: Set function=False by default in support.check_sanitizer() (GH-161640) (GH-161713) gh-111178: Set function=False by default in support.check_sanitizer() (GH-161640) Update also libregrtest.utils to detect function sanitizer (-fsanitize=function). (cherry picked from commit 39d10e3) (cherry picked from commit 4e10d4f) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 8aa5d65 commit e3a433c

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎Lib/test/libregrtest/utils.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ def get_build_info():
384384
# --with-thread-sanitizer
385385
if support.check_sanitizer(thread=True):
386386
sanitizers.append("TSAN")
387+
# --with-thread-sanitizer
388+
if support.check_sanitizer(function=True):
389+
sanitizers.append("fsanitize=function")
387390
if sanitizers:
388391
build.append('+'.join(sanitizers))
389392

@@ -672,6 +675,7 @@ def display_header(use_resources: dict[str, str | None],
672675
msan = support.check_sanitizer(memory=True)
673676
ubsan = support.check_sanitizer(ub=True)
674677
tsan = support.check_sanitizer(thread=True)
678+
function_san = support.check_sanitizer(function=True)
675679
sanitizers = []
676680
if asan:
677681
sanitizers.append("address")
@@ -681,12 +685,14 @@ def display_header(use_resources: dict[str, str | None],
681685
sanitizers.append("undefined behavior")
682686
if tsan:
683687
sanitizers.append("thread")
688+
if function_san:
689+
sanitizers.append("function")
684690
if sanitizers:
685691
print(f"== sanitizers: {', '.join(sanitizers)}")
686692
for sanitizer, env_var in (
687693
(asan, "ASAN_OPTIONS"),
688694
(msan, "MSAN_OPTIONS"),
689-
(ubsan, "UBSAN_OPTIONS"),
695+
(ubsan or function_san, "UBSAN_OPTIONS"),
690696
(tsan, "TSAN_OPTIONS"),
691697
):
692698
options= os.environ.get(env_var)

‎Lib/test/support/__init__.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,11 @@ def skip_if_buildbot(reason=None):
437437
return unittest.skipIf(isbuildbot, reason)
438438

439439
def check_sanitizer(*, address=False, memory=False, ub=False, thread=False,
440-
function=True):
440+
function=False):
441441
"""Returns True if Python is compiled with sanitizer support"""
442-
if not (address or memory or ub or thread):
443-
raise ValueError('At least one of address, memory, ub or thread must be True')
442+
if not (address or memory or ub or thread or function):
443+
raise ValueError('At least one of address, memory, ub, '
444+
'thread or function must be True')
444445

445446

446447
cflags = sysconfig.get_config_var('CFLAGS') or ''
@@ -485,11 +486,13 @@ def configured_with_sanitizer(name):
485486
)
486487

487488

488-
def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False, thread=False):
489+
def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False,
490+
thread=False, function=False):
489491
"""Decorator raising SkipTest if running with a sanitizer active."""
490492
if not reason:
491493
reason = 'not working with sanitizers active'
492-
skip = check_sanitizer(address=address, memory=memory, ub=ub, thread=thread)
494+
skip = check_sanitizer(address=address, memory=memory, ub=ub,
495+
thread=thread, function=function)
493496
return unittest.skipIf(skip, reason)
494497

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

0 commit comments

Comments
 (0)