https://github.com/gbMattN updated 
https://github.com/llvm/llvm-project/pull/182479

>From 709e7e15b20c12b491eedbfa486086fd0eb16fda Mon Sep 17 00:00:00 2001
From: gbMattN <[email protected]>
Date: Fri, 20 Feb 2026 11:27:14 +0000
Subject: [PATCH 1/2] halt_on_error flag for TySan and docs

---
 clang/docs/TypeSanitizer.rst           | 12 ++++++++++++
 compiler-rt/lib/tysan/tysan.cpp        |  5 +++++
 compiler-rt/lib/tysan/tysan_flags.inc  |  2 ++
 compiler-rt/test/tysan/halt_on_error.c | 23 +++++++++++++++++++++++
 4 files changed, 42 insertions(+)
 create mode 100644 compiler-rt/test/tysan/halt_on_error.c

diff --git a/clang/docs/TypeSanitizer.rst b/clang/docs/TypeSanitizer.rst
index 5a98a2547aa87..08cb247aefe3a 100644
--- a/clang/docs/TypeSanitizer.rst
+++ b/clang/docs/TypeSanitizer.rst
@@ -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
 -----------
 
diff --git a/compiler-rt/lib/tysan/tysan.cpp b/compiler-rt/lib/tysan/tysan.cpp
index 1c67adeba0fc5..4861715d53f0b 100644
--- a/compiler-rt/lib/tysan/tysan.cpp
+++ b/compiler-rt/lib/tysan/tysan.cpp
@@ -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
diff --git a/compiler-rt/lib/tysan/tysan_flags.inc 
b/compiler-rt/lib/tysan/tysan_flags.inc
index be65c8e828794..8735b816be29e 100644
--- a/compiler-rt/lib/tysan/tysan_flags.inc
+++ b/compiler-rt/lib/tysan/tysan_flags.inc
@@ -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.")
diff --git a/compiler-rt/test/tysan/halt_on_error.c 
b/compiler-rt/test/tysan/halt_on_error.c
new file mode 100644
index 0000000000000..bd8fa51139e97
--- /dev/null
+++ b/compiler-rt/test/tysan/halt_on_error.c
@@ -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;
+}

>From c72b20983d9b30a164c7e6faf0a32379dc79d3f9 Mon Sep 17 00:00:00 2001
From: gbMattN <[email protected]>
Date: Fri, 20 Feb 2026 11:49:52 +0000
Subject: [PATCH 2/2] Formatting

---
 compiler-rt/lib/tysan/tysan.cpp        |  2 +-
 compiler-rt/lib/tysan/tysan_flags.inc  |  2 +-
 compiler-rt/test/tysan/halt_on_error.c | 28 +++++++++++++-------------
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/compiler-rt/lib/tysan/tysan.cpp b/compiler-rt/lib/tysan/tysan.cpp
index 4861715d53f0b..52f941180b8eb 100644
--- a/compiler-rt/lib/tysan/tysan.cpp
+++ b/compiler-rt/lib/tysan/tysan.cpp
@@ -254,7 +254,7 @@ static void reportError(void *Addr, int Size, 
tysan_type_descriptor *TD,
     Printf("\n");
   }
 
-  if(flags().halt_on_error){
+  if (flags().halt_on_error) {
     Report("ABORTING\n");
     Die();
   }
diff --git a/compiler-rt/lib/tysan/tysan_flags.inc 
b/compiler-rt/lib/tysan/tysan_flags.inc
index 8735b816be29e..f8bd934fc3d82 100644
--- a/compiler-rt/lib/tysan/tysan_flags.inc
+++ b/compiler-rt/lib/tysan/tysan_flags.inc
@@ -19,4 +19,4 @@
 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.")
+           "Crash the program after printing the first error report.")
diff --git a/compiler-rt/test/tysan/halt_on_error.c 
b/compiler-rt/test/tysan/halt_on_error.c
index bd8fa51139e97..6d64eb2bb8959 100644
--- a/compiler-rt/test/tysan/halt_on_error.c
+++ b/compiler-rt/test/tysan/halt_on_error.c
@@ -1,23 +1,23 @@
-// RUN: %clang_tysan %s -o %t 
+// 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 main() {
 
-    int i = 5;
+  int i = 5;
 
-    float *f = (float*)&i;
+  float *f = (float *)&i;
 
-    // CHECK: ERROR: TypeSanitizer: type-aliasing-violation
-    // CHECK: WRITE of size 4
-    // CHECK-HALT: ABORTING
-    *f = 5.0f;
+  // 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;
+  // 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;
+  return 0;
 }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to