Documentation of bitcasts in calls

Dear all,

I just stumbled over the following instruction in the LLVM IR of a C
program compiled with clang:

%26 = call i32 (...)* bitcast (i32 (i32, i32, i32, i32, i32)*
@KeWaitForSingleObject to i32 (...)*)(i32 %23, i32 %24, i32 %25, i32 0,
i32 0)

Since our LLVM Parser choked on this instruction, I tried to check the
documentation, but did not find anything about such nested bitcasts
within calls. What is the exact syntax and semantics (while I can guess
the latter, especially the former is interesting for me when building a
parser for LLVM IR) for such instructions and/or where is this
documented? In particular, the parantheses around the arguments of the
bitcast are confusing me.

Alternatively, is there a way to tell clang not to inline such bitcasts,
but have them in a separate instruction before and use the result in the
call?

Best regards,

  Thomas

Textual LLVM IR is not guaranteed to be stable between versions. Even LLVM’s parser is not guaranteed to be backwards compatible.

There was/is a move afoot to remove types from pointers, so explicit bitcasts are no longer required or used. Instead each instruction that uses a pointer will also take a type parameter for that pointer.

Casts that don’t change the value, don’t result in machine instructions anyway.

Hi Thomas,

That syntax is expressing a ConstantExpr of type BitCast.

I echo Jeremy’s comment that the textual IR isn’t meant to be parsed by non-LLVM tools - you’d have much better stability using bitcode instead, which has a backwards-compatibility guarantee.

Cheers,

James

Hi Thomas,

was clang generates as call target here is a constant bitcast expression: http://llvm.org/docs/LangRef.html#constant-expressions

Cheers,
Clemens

Dear James and Jeremy,

Thanks for the quick help!
While I found the documentation for the textual IR, I didn't find any
for the bitcode. Could you point me to some documentation about its
syntax and semantics?

Best regards,

  Thomas