On 2/12/26 00:05, Joseph Myers wrote:
The sanitizer tests have logic to set ASAN_OPTIONS and UBSAN_OPTIONS
to color=never to avoid problems checking against output patterns, in
test configurations where the output is otherwise coloured by default.
This does not however cover all sanitizer tests with issues in such
configurations. There is no corresponding logic to set TSAN_OPTIONS
for tsan tests, and environment variable settings in
dg-set-target-env-var override the globally set color=never.
Add logic to set TSAN_OPTIONS similarly (following the UBSAN_OPTIONS
logic, that saves and restores any previous setting or lack thereof,
rather than the ASAN_OPTIONS logic, that just sets ASAN_OPTIONS in the
environment so that it remains set for all the rest of the possibly
unrelated tests included in the same runtest execution). Also add
color=never to dg-set-target-env-var in two such tests where I've seen
coloured output causing failures (but not for other tests where I
haven't seen the default producing such fallures).
Tested for x86_64-pc-linux-gnu, and with a cross to aarch64-linux
(together with other testsuite fixes) in a configuration where I
previously saw failures related to colour output from sanitizer tests.
* lib/tsan-dg.exp (orig_tsan_options_saved, orig_tsan_options):
New global variables.
(tsan_init): Save TSAN_OPTIONS and set it to color=never.
(tsan_finish): Restore TSAN_OPTIONS.
* c-c++-common/asan/pr64820.c: Include color=never in
ASAN_OPTIONS.
* c-c++-common/asan/use-after-return-1.c: Likewise.
diff --git a/gcc/testsuite/c-c++-common/asan/pr64820.c
b/gcc/testsuite/c-c++-common/asan/pr64820.c
index a00debf35883..b675ef21b275 100644
--- a/gcc/testsuite/c-c++-common/asan/pr64820.c
+++ b/gcc/testsuite/c-c++-common/asan/pr64820.c
@@ -1,7 +1,7 @@
/* { dg-do run } */
/* { dg-require-effective-target fstack_protector } */
/* { dg-options "-fstack-protector-strong" } */
-/* { dg-set-target-env-var ASAN_OPTIONS "detect_stack_use_after_return=1" } */
+/* { dg-set-target-env-var ASAN_OPTIONS "color=never
detect_stack_use_after_return=1" } */
I thought that ASAN_OPTIONS where supposed to be colon-separated, and
least that what the examples in the doc use.
I suppose it works, though, since the tests we have in
asan/pointer-compare* and asan/pointer-subtract* are using both.
/* { dg-shouldfail "asan" } */
__attribute__((noinline))
diff --git a/gcc/testsuite/c-c++-common/asan/use-after-return-1.c
b/gcc/testsuite/c-c++-common/asan/use-after-return-1.c
index e1bb18a57431..557a687e0e32 100644
--- a/gcc/testsuite/c-c++-common/asan/use-after-return-1.c
+++ b/gcc/testsuite/c-c++-common/asan/use-after-return-1.c
@@ -1,5 +1,5 @@
/* { dg-do run } */
-/* { dg-set-target-env-var ASAN_OPTIONS "detect_stack_use_after_return=1" } */
+/* { dg-set-target-env-var ASAN_OPTIONS "color=never
detect_stack_use_after_return=1" } */
/* { dg-shouldfail "asan" } */
#include <stdio.h>
diff --git a/gcc/testsuite/lib/tsan-dg.exp b/gcc/testsuite/lib/tsan-dg.exp
index 916c8737807e..6379d18e6b54 100644
--- a/gcc/testsuite/lib/tsan-dg.exp
+++ b/gcc/testsuite/lib/tsan-dg.exp
@@ -81,6 +81,9 @@ proc tsan_link_flags { paths } {
return "$flags"
}
+set orig_tsan_options_saved 0
+set orig_tsan_options 0
+
#
# tsan_init -- called at the start of each subdir of tests
#
@@ -93,6 +96,17 @@ proc tsan_init { args } {
global tsan_saved_ALWAYS_CXXFLAGS
global dg-do-what-default
global tsan_saved_dg-do-what-default
+ global orig_tsan_options_saved
+ global orig_tsan_options
+
+ if { $orig_tsan_options_saved == 0 } {
+ # Save the original environment.
+ if [info exists env(TSAN_OPTIONS)] {
+ set orig_tsan_options "$env(TSAN_OPTIONS)"
+ set orig_tsan_options_saved 1
+ }
+ }
+ setenv TSAN_OPTIONS color=never
set link_flags ""
if ![is_remote host] {
@@ -134,6 +148,14 @@ proc tsan_finish { args } {
global tsan_saved_dg-do-what-default
global tsan_saved_library_path
global ld_library_path
+ global orig_tsan_options_saved
+ global orig_tsan_options
+
+ if { $orig_tsan_options_saved } {
+ setenv TSAN_OPTIONS "$orig_tsan_options"
+ } elseif [info exists env(TSAN_OPTIONS)] {
+ unsetenv TSAN_OPTIONS
+ }
Is it OK that we don't reset $orig_tsan_options_saved to 0?
(I noticed that ubsan_finish does not do it either)
if [info exists tsan_saved_ALWAYS_CXXFLAGS ] {
set ALWAYS_CXXFLAGS $tsan_saved_ALWAYS_CXXFLAGS