[llvm] [NVPTX] Convert calls to indirect when call signature mismatches function signature (PR #107644)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 02:17:05 PDT 2024


nikic wrote:

@Artem-B At a high level, calls with mismatching function types are *usually* undefined behavior, but not malformed, as they may legally occur in dead code. Generating an error for such calls is not appropriate (at least normally, maybe the PTX programming model is different).

When it comes to the details, it's a bit more complicated and we don't actually know what the *precise* semantics are. If the called function is a declaration, the declaration may not match the actual definition. This may be UB in some cases, but there are at least some carve-outs, in particular calling an "unprototyped" `void @fn()` declaration should always be well-defined. There may also be benign ABI mismatches, where two signatures that differ at the LLVM IR level result in the same lowering to assembly. Two frontends may chose two different ways to encode the same call ABI, and these may come into contact through cross-language LTO. I don't know if that part is applicable to NVPTX.

Generally treating mismatches between call and function function type as indirect calls is a good baseline behavior, which is also why CallBase->getCalledFunction() returns null in such cases, so you usually get that behavior by default.

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


More information about the llvm-commits mailing list