I’ve just seen if (CB->getFunctionType() != F.getFunctionType()) return false;
written in another place and thought I’d ask if we can make that a verifier error instead.
Currently the type of the callee of a call instruction can be different from the type of the function being called. That’s sometimes OK from a codegen perspective, in target dependent fashion, and it’s probably something we can get out of C codegen in some edge cases. I believe the current perspective is roughly:
- The function type indicates what we do with the prolog, where it gets arguments from etc
- The callee type indicates what we do with the call site, where we put arguments etc
So provided they kind of match, it’s alright. E.g. we pass too few arguments, the function reads whatever was in the higher register anyway.
I’m not totally sure that’s the proper semantics for the compiler IR though. We could require an exact match and emit hackery at the call site to paste over divergence, e.g. passing undef for arguments that were missing. I suspect that would mostly show up when devirtualising functions.
Thoughts welcome
There’s good context in Verifier Pass doesn't catch calls with different number of parameters than the definition - #4 by nikic, specifically
IR needs to have a well-formed (but not necessarily well-defined) way to call a function with a signature that differs from its declaration.
^That’s the current state of the system but it’s not clear to me that it’s a feature.