[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 21 06:39:53 PDT 2024
AaronBallman 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.
Ah! That does provide the context I needed, thank you! And I think I see the issue:
https://github.com/llvm/llvm-project/blob/734026347cca85cf0e242ef5f04896f55e0ac113/clang/include/clang/Basic/DiagnosticGroups.td#L576
`-Wcast-function-type` also includes `-Wcast-function-type-strict`; we don't want the strict warning in `-Wextra`, just the base warning. I'm looking to see if there's a reasonable way to accomplish this.
https://github.com/llvm/llvm-project/pull/77178
More information about the cfe-commits
mailing list