Skip to content
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

[sanitizer_common] Suppress warning of cast from SignalHandlerType to sa_sigaction_t #86046

Merged
merged 1 commit into from
Mar 21, 2024

Conversation

thurstond
Copy link
Contributor

@thurstond thurstond commented Mar 20, 2024

Some buildbots (e.g., https://lab.llvm.org/buildbot/#/builders/18/builds/16061/steps/10/logs/stdio) have recently started complaining about

cast from 'SignalHandlerType' (aka 'void (*)(int, void *, void *)') to 'sa_sigaction_t' (aka 'void (*)(int, siginfo_t *, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
  219 |   sigact.sa_sigaction = (sa_sigaction_t)handler;

This patch does an intermediate cast to '(void (*) (void))' to suppress the warning.

N.B. SignalHandlerType has 'void*' instead of 'siginfo_t*' because it is typedef'ed in sanitizer_common/sanitizer_common.h, which does not have access to the header (signal.h) that defines siginfo_t; we therefore cannot fix SignalHandlerType.

… sa_sigaction_t

Some buildbots have recently started complaining about "cast from 'SignalHandlerType' (aka 'void (*)(int, void *, void *)') to 'sa_sigaction_t' (aka 'void (*)(int, siginfo_t *, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]"
  219 |   sigact.sa_sigaction = (sa_sigaction_t)handler;
This patch does an intermediate cast to '(void (*) (void))' to suppress the warning.

N.B. SignalHandlerType has 'void*' instead of 'siginfo_t*' because it is typedef'ed in sanitizer_common/sanitizer_common.h, which does not have access to the header (signal.h) that defines siginfo_t; we therefore cannot fix SignalHandlerType.
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 20, 2024

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

Author: Thurston Dang (thurstond)

Changes

Some buildbots have recently started complaining about "cast from 'SignalHandlerType' (aka 'void (*)(int, void *, void )') to 'sa_sigaction_t' (aka 'void ()(int, siginfo_t *, void )') converts to incompatible function type [-Werror,-Wcast-function-type-strict]"
219 | sigact.sa_sigaction = (sa_sigaction_t)handler;
This patch does an intermediate cast to '(void (
) (void))' to suppress the warning.

N.B. SignalHandlerType has 'void*' instead of 'siginfo_t*' because it is typedef'ed in sanitizer_common/sanitizer_common.h, which does not have access to the header (signal.h) that defines siginfo_t; we therefore cannot fix SignalHandlerType.


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp (+1-1)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
index ece2d7d63dd619..48daa2ed25c144 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
@@ -216,7 +216,7 @@ static void MaybeInstallSigaction(int signum,
 
   struct sigaction sigact;
   internal_memset(&sigact, 0, sizeof(sigact));
-  sigact.sa_sigaction = (sa_sigaction_t)handler;
+  sigact.sa_sigaction = (sa_sigaction_t)(void (*)(void))handler;
   // Do not block the signal from being received in that signal's handler.
   // Clients are responsible for handling this correctly.
   sigact.sa_flags = SA_SIGINFO | SA_NODEFER;

@thurstond thurstond merged commit 71defe4 into llvm:main Mar 21, 2024
7 checks passed
@thurstond
Copy link
Contributor Author

I reverted it in 0e3fbfd because it didn't actually suppress the warning

"Split -Wcast-function-type into a separate group" (by AaronBallman; #86131) will prevent the warning, though we should figure out a way to fix the cast in the longer term.

chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
… sa_sigaction_t (llvm#86046)

Some buildbots (e.g.,
https://lab.llvm.org/buildbot/#/builders/18/builds/16061/steps/10/logs/stdio)
have recently started complaining about
```
cast from 'SignalHandlerType' (aka 'void (*)(int, void *, void *)') to 'sa_sigaction_t' (aka 'void (*)(int, siginfo_t *, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
  219 |   sigact.sa_sigaction = (sa_sigaction_t)handler;
  ```
This patch does an intermediate cast to `'(void (*) (void))'` to suppress the warning.

N.B. SignalHandlerType has `'void*'` instead of `'siginfo_t*'` because it is typedef'ed in sanitizer_common/sanitizer_common.h, which does not have access to the header (signal.h) that defines siginfo_t; we therefore cannot fix SignalHandlerType.
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.

None yet

3 participants