[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

Abhin P Jose via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 21 05:46:12 PDT 2024


Abhinkop wrote:

> I'm confused as to how this code ever compiled in the first place... In each case, this is C++ code that's failing:
> 
> ```
> /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp:219:25: error: 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]
> 
> /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:437:4: error: cast from 'void (*)()' to 'void (*)(void *)' converts to incompatible function type [-Werror,-Wcast-function-type-strict]
> 
> /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-rhel-test/clang-ppc64le-rhel/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:460:54: error: cast from 'void (*)(void *)' to 'void (*)()' converts to incompatible function type [-Werror,-Wcast-function-type-strict]
> ```
> 
> All of which is being compiled in `-std=c++17` and none of which are valid in C++ and the behavior is the same between Clang 18, trunk, and GCC: https://godbolt.org/z/WY9zvsa8z
> 
> @amy-kwan we may need some help from you with investigating this; but in the meantime, this commit can be reverted to get the bots back to green if that's blocking you.

@AaronBallman There was a forced/explicit typecasting done, and hence the compiler didn't complain. for example, https://godbolt.org/z/G94r7qvxh . When the -Werror flag coupled with -Wextra flag caught this conversion, for example, https://godbolt.org/z/6bMrdfe4n. I hope this might help to provide some context.

https://github.com/llvm/llvm-project/pull/77178


More information about the cfe-commits mailing list