Skip to content

[compiler-rt] add check-cmp flag for nsan #108707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 24, 2024
Merged

Conversation

c8ef
Copy link
Contributor

@c8ef c8ef commented Sep 14, 2024

Closes #108435.

@llvmbot
Copy link
Member

llvmbot commented Sep 14, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: None (c8ef)

Changes

Fixes #108435.


Full diff: https://github.com/llvm/llvm-project/pull/108707.diff

2 Files Affected:

  • (modified) compiler-rt/lib/nsan/nsan.cpp (+2-2)
  • (modified) compiler-rt/lib/nsan/nsan_flags.inc (+4-1)
diff --git a/compiler-rt/lib/nsan/nsan.cpp b/compiler-rt/lib/nsan/nsan.cpp
index 4679bcd589eb45..1c06340549acae 100644
--- a/compiler-rt/lib/nsan/nsan.cpp
+++ b/compiler-rt/lib/nsan/nsan.cpp
@@ -25,7 +25,7 @@
 //          on the runtime configuration. The middle part indicates the type of
 //          the application value, the suffix (f,d,l) indicates the type of the
 //          shadow, and depends on the instrumentation configuration.
-//        * __nsan_fcmp_fail_* emits a warning for an fcmp instruction whose
+//        * __nsan_fcmp_fail_* emits a warning for a fcmp instruction whose
 //          corresponding shadow fcmp result differs.
 //
 //===----------------------------------------------------------------------===//
@@ -682,7 +682,7 @@ void fCmpFailFT(const FT Lhs, const FT Rhs, ShadowFT LhsShadow,
   if (flags().enable_warning_stats)
     nsan_stats->AddWarning(CheckTypeT::kFcmp, pc, bp, 0.0);
 
-  if (flags().disable_warnings)
+  if (flags().disable_warnings || !flags().check_cmp)
     return;
 
   // FIXME: ideally we would print the shadow value as FP128. Right now because
diff --git a/compiler-rt/lib/nsan/nsan_flags.inc b/compiler-rt/lib/nsan/nsan_flags.inc
index 7c9e579d91fc33..760973295a8a50 100644
--- a/compiler-rt/lib/nsan/nsan_flags.inc
+++ b/compiler-rt/lib/nsan/nsan_flags.inc
@@ -49,4 +49,7 @@ NSAN_FLAG(bool, enable_loadtracking_stats, false,
 NSAN_FLAG(bool, poison_in_free, true, "")
 NSAN_FLAG(bool, print_stats_on_exit, false, "If true, print stats on exit.")
 NSAN_FLAG(bool, check_nan, false,
-          "If true, check the floating-point number is nan")
\ No newline at end of file
+          "If true, check the floating-point number is nan")
+NSAN_FLAG(bool, check_cmp, true,
+          "If true, emit a warning for a fcmp instruction whose "
+          "corresponding shadow fcmp result differs.")

@c8ef
Copy link
Contributor Author

c8ef commented Sep 15, 2024

Hi @vitalybuka, could you please take a look at this patch?

@alexander-shaposhnikov
Copy link
Collaborator

The patch needs tests

@MaskRay
Copy link
Member

MaskRay commented Sep 17, 2024

Add a test? We typically reserve "fix ..." to mean bug fixes. Implementing a feature can use Close ...

@c8ef
Copy link
Contributor Author

c8ef commented Sep 17, 2024

Add a test? We typically reserve "fix ..." to mean bug fixes. Implementing a feature can use Close ...

Test case added.

@c8ef
Copy link
Contributor Author

c8ef commented Sep 18, 2024

Dear reviewers, could you kindly review this patch again? 🥰
@MaskRay @alexander-shaposhnikov

@c8ef
Copy link
Contributor Author

c8ef commented Sep 21, 2024

Ping. @alexander-shaposhnikov @MaskRay

@alexander-shaposhnikov
Copy link
Collaborator

Thanks for the update, I'll come back to this soon

@alexander-shaposhnikov
Copy link
Collaborator

LGTM with some minor nits
(the checks in the test need some reorganization, I'll commit it as a follow-up)

@alexander-shaposhnikov alexander-shaposhnikov merged commit 86c6403 into llvm:main Sep 24, 2024
7 checks passed
@c8ef c8ef deleted the nsan branch September 24, 2024 02:14
@c8ef
Copy link
Contributor Author

c8ef commented Sep 24, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[compiler-rt][nsan] Add an option to enable/disable comparison checking
4 participants