[compiler-rt] [compiler-rt][nsan] Make nsan output more user-friendly (PR #98798)

Dmitriy Chestnykh via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 13 23:40:00 PDT 2024


https://github.com/chestnykh created https://github.com/llvm/llvm-project/pull/98798

Currently NSAN prints reports that are entirely red and the terminal prompt after the program exits is red too. With this change we make red only `WARNING` summary and the rest of the report isn't colored
This behaviour is similar to the behavior of other sanitizers reports like asan, ubsan etc

![nsan](https://github.com/user-attachments/assets/5796e46d-b88a-48e7-afad-c3c946a11570)
![nsan_pretty](https://github.com/user-attachments/assets/c1e1ded0-ba7e-4b53-a8e7-7c2417757139)


>From 5b22bddfa370677828331ae3769e72adf15dad04 Mon Sep 17 00:00:00 2001
From: Dmitry Chestnykh <dm.chestnykh at gmail.com>
Date: Sun, 14 Jul 2024 09:22:38 +0300
Subject: [PATCH] [compiler-rt][nsan] Make nsan output more user-friendly

Currently NSAN prints reports that are entirely red
and the terminal prompt after the program exits is red too.
With this change we make red only `WARNING` summary
and the rest of the report isn't colored
This behaviour is similar to the behavior of other
sanitizers reports like asan, ubsan etc
---
 compiler-rt/lib/nsan/nsan.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/nsan/nsan.cpp b/compiler-rt/lib/nsan/nsan.cpp
index 7a5f013579dfb..e5a9b7a036e0e 100644
--- a/compiler-rt/lib/nsan/nsan.cpp
+++ b/compiler-rt/lib/nsan/nsan.cpp
@@ -513,6 +513,8 @@ int32_t checkFT(const FT value, ShadowFT Shadow, CheckTypeT CheckType,
     }
     using ValuePrinter = FTPrinter<FT>;
     using ShadowPrinter = FTPrinter<ShadowFT>;
+    Printf("%s", D.Default());
+
     Printf("\n"
            "%-12s precision  (native): dec: %s  hex: %s\n"
            "%-12s precision  (shadow): dec: %s  hex: %s\n"
@@ -638,8 +640,9 @@ void fCmpFailFT(const FT Lhs, const FT Rhs, ShadowFT LhsShadow,
   const char *const PredicateName = GetPredicateName(Predicate);
   Printf("%s", D.Warning());
   Printf("WARNING: NumericalStabilitySanitizer: floating-point comparison "
-         "results depend on precision\n"
-         "%-12s precision dec (native): %s %s %s (%s)\n"
+         "results depend on precision\n");
+  Printf("%s", D.Default());
+  Printf("%-12s precision dec (native): %s %s %s (%s)\n"
          "%-12s precision dec (shadow): %s %s %s (%s)\n"
          "%-12s precision hex (native): %s %s %s (%s)\n"
          "%-12s precision hex (shadow): %s %s %s (%s)\n"
@@ -658,7 +661,6 @@ void fCmpFailFT(const FT Lhs, const FT Rhs, ShadowFT LhsShadow,
          FTInfo<ShadowFT>::kCppTypeName, ShadowPrinter::hex(LhsShadow).Buffer,
          PredicateName, ShadowPrinter::hex(RhsShadow).Buffer,
          GetTruthValueName(ShadowResult), D.End());
-  Printf("%s", D.Default());
   stack.Print();
   if (flags().halt_on_error) {
     Printf("Exiting\n");



More information about the llvm-commits mailing list