Skip to content

[compiler-rt] Remove redundant checks. #95753

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 1 commit into from
Jul 2, 2024

Conversation

chestnykh
Copy link
Contributor

Since __sancov_default_options and __asan_default_suppressions are weak definitions, not weak references (declarations) the checks of equality of addresses of these symbols to zero is not needed. So we can completely remove MaybeCallSancovDefaultOptions and use __sancov_default_options instead directly. gcc-14 emits -Waddress warning to such checks.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2024

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

Author: Dmitriy Chestnykh (chestnykh)

Changes

Since __sancov_default_options and __asan_default_suppressions are weak definitions, not weak references (declarations) the checks of equality of addresses of these symbols to zero is not needed. So we can completely remove MaybeCallSancovDefaultOptions and use __sancov_default_options instead directly. gcc-14 emits -Waddress warning to such checks.


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

2 Files Affected:

  • (modified) compiler-rt/lib/asan/asan_suppressions.cpp (+1-2)
  • (modified) compiler-rt/lib/sanitizer_common/sancov_flags.cpp (+1-5)
diff --git a/compiler-rt/lib/asan/asan_suppressions.cpp b/compiler-rt/lib/asan/asan_suppressions.cpp
index e71d231821866..6cee674960395 100644
--- a/compiler-rt/lib/asan/asan_suppressions.cpp
+++ b/compiler-rt/lib/asan/asan_suppressions.cpp
@@ -39,8 +39,7 @@ void InitializeSuppressions() {
   suppression_ctx = new (suppression_placeholder)
       SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
   suppression_ctx->ParseFromFile(flags()->suppressions);
-  if (&__asan_default_suppressions)
-    suppression_ctx->Parse(__asan_default_suppressions());
+  suppression_ctx->Parse(__asan_default_suppressions());
 }
 
 bool IsInterceptorSuppressed(const char *interceptor_name) {
diff --git a/compiler-rt/lib/sanitizer_common/sancov_flags.cpp b/compiler-rt/lib/sanitizer_common/sancov_flags.cpp
index ed46e88acdfc6..43b4bcc76729a 100644
--- a/compiler-rt/lib/sanitizer_common/sancov_flags.cpp
+++ b/compiler-rt/lib/sanitizer_common/sancov_flags.cpp
@@ -37,10 +37,6 @@ static void RegisterSancovFlags(FlagParser *parser, SancovFlags *f) {
 #undef SANCOV_FLAG
 }
 
-static const char *MaybeCallSancovDefaultOptions() {
-  return (&__sancov_default_options) ? __sancov_default_options() : "";
-}
-
 void InitializeSancovFlags() {
   SancovFlags *f = sancov_flags();
   f->SetDefaults();
@@ -48,7 +44,7 @@ void InitializeSancovFlags() {
   FlagParser parser;
   RegisterSancovFlags(&parser, f);
 
-  parser.ParseString(MaybeCallSancovDefaultOptions());
+  parser.ParseString(__sancov_default_options());
   parser.ParseStringFromEnv("SANCOV_OPTIONS");
 
   ReportUnrecognizedFlags();

@chestnykh
Copy link
Contributor Author

@MaskRay @yozhu @vitalybuka

@chestnykh chestnykh force-pushed the remove-redundant-checks branch from 9db4df5 to d252e9d Compare June 17, 2024 08:55
Since `__sancov_default_options` and `__asan_default_suppressions`
are weak definitions, not weak references (declarations) the checks
of equality of addresses of these symbols to zero is not needed.
So we can completely remove `MaybeCallSancovDefaultOptions`
and use `__sancov_default_options` instead directly.
gcc-14 emits `-Waddress` warning to such checks.
@chestnykh
Copy link
Contributor Author

Ping

Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chestnykh
Copy link
Contributor Author

Ping

@vitalybuka vitalybuka merged commit 0330ce9 into llvm:main Jul 2, 2024
6 checks passed
Copy link

github-actions bot commented Jul 2, 2024

@chestnykh Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
Since `__sancov_default_options` and `__asan_default_suppressions` are
weak definitions, not weak references (declarations) the checks of
equality of addresses of these symbols to zero is not needed. So we can
completely remove `MaybeCallSancovDefaultOptions` and use
`__sancov_default_options` instead directly. gcc-14 emits `-Waddress`
warning to such checks.
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
Since `__sancov_default_options` and `__asan_default_suppressions` are
weak definitions, not weak references (declarations) the checks of
equality of addresses of these symbols to zero is not needed. So we can
completely remove `MaybeCallSancovDefaultOptions` and use
`__sancov_default_options` instead directly. gcc-14 emits `-Waddress`
warning to such checks.
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.

4 participants