[clang] [CIR] Handle FunctionToPointerDecay casts (#153657) (PR #154060)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 19 16:05:48 PDT 2025


andykaylor wrote:

> On a C level, what is the expected behaviour when you cast a function pointer declared as taking no parameters void f(void) to one taking one int param and call it?

I'm pretty sure that's undefined behavior. In general, the compiler tolerates a lot of things like this because a lot of old C code plays very fast and loose with pointers, and code like that in your example, while technically undefined, is often expected to work (in whatever way it always has).

It appears that clang has decided to be more tolerant of this than GCC, though you can get a warning for it if you explicitly add `-Wcast-function-type`.

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


More information about the cfe-commits mailing list