[llvm-dev] About mismatching calling conventions

serge guelton via llvm-dev llvm-dev at lists.llvm.org
Thu Nov 16 00:35:37 PST 2017

Hi llvm-dev,

Every now and then, when building a direct ``CallInst`` either from IRBuilder
or through ``Create*``, I have a latent bug because the calling
convention (CC) expected by the function is not set on the call, and I need
to manually call ``setCallingConv``.

Now, from LangRef#calling-conventions,

    The calling convention of any pair of dynamic caller/callee must
    match, or the behavior of the program is undefined.

So the behavior is correctly defined, as emphasised by the check in
``InstCombineCalls`` that turns mismatching convention into an ``undef``.

This is however very error-prone. Maybe we should either:

- update the API to enforce the CC when building a ``CallInst``

- update LangRef to state that mismatching CC in static call
  is an error (note that LangRef is unclear about static call, the quote
  only references indirect calls)

- add an optional setting in the ``CreateCall`` that enforces CC
  (and let it default to yes?)

Any thoughts on that?


More information about the llvm-dev mailing list