halt_on_error flag for TySan and docs (#182479)

This commit is contained in:
Matthew Nagy 2026-03-09 15:42:25 +00:00 committed by GitHub
parent ce227964cc
commit 2a9372ff02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 0 deletions

View File

@ -180,6 +180,18 @@ violation reports in the specified source files or functions. Like
with other methods of ignoring instrumentation, this can result in false
positives/ false-negatives.
Runtime Options
---------------
Similar to other sanitizers, you can modify TypeSanitizers runtime behaviour by
using an environment variable. These flags should be provided as a colon separated
list. For example, ``TYSAN_OPTIONS=print_stacktrace=1:halt_on_error=1``
* ``print_stacktrace`` when true will tell the sanitizer to emit more lengthy
and detailed stack traces on error.
* ``halt_on_error`` when true will make the instrumented program abort after
the first type violation detected.
Limitations
-----------

View File

@ -253,6 +253,11 @@ static void reportError(void *Addr, int Size, tysan_type_descriptor *TD,
} else {
Printf("\n");
}
if (flags().halt_on_error) {
Report("ABORTING\n");
Die();
}
}
ALWAYS_INLINE

View File

@ -18,3 +18,5 @@
TYSAN_FLAG(bool, print_stacktrace, false,
"Include full stacktrace into an error report")
TYSAN_FLAG(bool, halt_on_error, false,
"Crash the program after printing the first error report.")

View File

@ -0,0 +1,23 @@
// RUN: %clang_tysan %s -o %t
// RUN: %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-CONTINUE %s
// RUN: %env_tysan_opts=halt_on_error=1 not %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-HALT %s
int main() {
int i = 5;
float *f = (float *)&i;
// CHECK: ERROR: TypeSanitizer: type-aliasing-violation
// CHECK: WRITE of size 4
// CHECK-HALT: ABORTING
*f = 5.0f;
// CHECK-CONTINUE: ERROR: TypeSanitizer: type-aliasing-violation
// CHECK-CONTINUE: READ of size 4
// CHECK-HALT-NOT: ERROR: TypeSanitizer: type-aliasing-violation
// CHECK-HALT-NOT: READ of size 4
i = *f;
return 0;
}