-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc] -Wcast-function-type in libc/src/signal/linux/signal_utils.h #74617
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
Comments
@llvm/issue-subscribers-libc Author: Nick Desaulniers (nickdesaulniers)
```
[270/361] Building CXX object projects/libc/src/signal/linux/CMakeFiles/libc.src.signal.linux.raise.dir/raise.cpp.o
In file included from /android0/llvm-project/libc/src/signal/linux/raise.cpp:10:
/android0/llvm-project/libc/src/signal/linux/signal_utils.h: In member function ‘__llvm_libc_18_0_0_git::KernelSigaction& __llvm_libc_18_0_0_git::KernelSigaction::operator=(const sigaction&)’:
/android0/llvm-project/libc/src/signal/linux/signal_utils.h:38:20: warning: cast between incompatible function types from ‘void (*)(int, siginfo_t*, void*)’ to ‘void (*)(int)’ [-Wcast-function-type]
38 | sa_handler = reinterpret_cast<HandlerType *>(sa.sa_sigaction);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/android0/llvm-project/libc/src/signal/linux/signal_utils.h: In member function ‘__llvm_libc_18_0_0_git::KernelSigaction::operator sigaction() const’:
/android0/llvm-project/libc/src/signal/linux/signal_utils.h:51:25: warning: cast between incompatible function types from ‘void (*)(int)’ to ‘void (*)(int, siginfo_t*, void*)’ [-Wcast-function-type]
51 | sa.sa_sigaction = reinterpret_cast<SiginfoHandlerType *>(sa_handler);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
I'm trying to get -Werror re-enabled in https://github.com//pull/74506; building with GCC flags the above warning.
|
alludes to the issue that is mentioned near the warning. llvm-project/libc/src/signal/linux/signal_utils.h Lines 21 to 22 in 1f283a6
|
Casting to an intermediate value should suppress the warning. See https://godbolt.org/z/PncMfvfz7 using T0 = void (*)(int, void*, void*);
using T1 = void (*)(int);
T0 test(T1 f) {
return reinterpret_cast<T0>(f);
}
T0 test1(T1 f) {
void * ptr = reinterpret_cast<void *>(f);
return reinterpret_cast<T0>(ptr);
} |
Sure, we can probably get by with laundering the type through a |
Would Casting around void (*a)(int, ...);
void (*b)((int, void*, void*); will just work without warning. Per However, I suppose you are talking about separating them based on implementations rather than figuring out an generic type that just works. |
The GCC build is producing the following diagnostic: llvm-project/libc/src/signal/linux/signal_utils.h: In member function ‘__llvm_libc_18_0_0_git::KernelSigaction& __llvm_libc_18_0_0_git::KernelSigaction::operator=(const sigaction&)’: llvm-project/libc/src/signal/linux/signal_utils.h:38:20: warning: cast between incompatible function types from ‘void (*)(int, siginfo_t*, void*)’ to ‘void (*)(int)’ [-Wcast-function-type] 38 | sa_handler = reinterpret_cast<HandlerType *>(sa.sa_sigaction); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ llvm-project/libc/src/signal/linux/signal_utils.h: In member function ‘__llvm_libc_18_0_0_git::KernelSigaction::operator sigaction() const’: llvm-project/libc/src/signal/linux/signal_utils.h:51:25: warning: cast between incompatible function types from ‘void (*)(int)’ to ‘void (*)(int, siginfo_t*, void*)’ [-Wcast-function-type] 51 | sa.sa_sigaction = reinterpret_cast<SiginfoHandlerType *>(sa_handler); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Two issues here: 1. Clang supports -Wcast-function-type, but not as part of the -Wextra group. 2. The existing implementation tried to work around the oddity that is the kernel's struct sigaction != POSIX via reinterpret_cast in a way that's not compatible with -Wcast-function-type. Just use a union which is well defined (and two function pointers are the same size.) Link: llvm#76872 Fixes: llvm#74617
#76875) The GCC build is producing the following diagnostic: llvm-project/libc/src/signal/linux/signal_utils.h: In member function ‘__llvm_libc_18_0_0_git::KernelSigaction& __llvm_libc_18_0_0_git::KernelSigaction::operator=(const sigaction&)’: llvm-project/libc/src/signal/linux/signal_utils.h:38:20: warning: cast between incompatible function types from ‘void (*)(int, siginfo_t*, void*)’ to ‘void (*)(int)’ [-Wcast-function-type] 38 | sa_handler = reinterpret_cast<HandlerType *>(sa.sa_sigaction); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ llvm-project/libc/src/signal/linux/signal_utils.h: In member function ‘__llvm_libc_18_0_0_git::KernelSigaction::operator sigaction() const’: llvm-project/libc/src/signal/linux/signal_utils.h:51:25: warning: cast between incompatible function types from ‘void (*)(int)’ to ‘void (*)(int, siginfo_t*, void*)’ [-Wcast-function-type] 51 | sa.sa_sigaction = reinterpret_cast<SiginfoHandlerType *>(sa_handler); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Two issues here: 1. Clang supports -Wcast-function-type, but not as part of the -Wextra group. 2. The existing implementation tried to work around the oddity that is the kernel's struct sigaction != POSIX via reinterpret_cast in a way that's not compatible with -Wcast-function-type. Just use a union which is well defined (and two function pointers are the same size.) Link: #76872 Fixes: #74617
I'm trying to get -Werror re-enabled in #74506; building with GCC flags the above warning.
The text was updated successfully, but these errors were encountered: