Why does Clang coerce struct parameters to ints

后端 未结 1 1830
旧时难觅i
旧时难觅i 2020-12-30 10:38

When using struct parameters in a function, clang will change the function signature. Instead of using a struct type, the signature will be a coerced int of equal size. In m

1条回答
  •  一生所求
    2020-12-30 11:25

    Two month ago there was a thread in llvmdev: [LLVMdev] "Struct parameters being converted to other types" by Jaymie Strecker, Jan 14 19:50:04 CST 2013. She encountered similar problem: "When a function with a struct parameter or return type is compiled with clang -O0 -emit-llvm, the resulting bitcode varies greatly depending on the type of struct.", and clang turned struct into pointer, vector, passed it as several doubles, or merged into single i64 type. Anton Korobeynikov replied at Jan 15 00:41:43 CST 2013:

    The struct is lowered to something which corresponds to C/C++ ABI on your platform for passing the struct in proper way.

    So, clang does struct passing according to the way used by your OS, libs and native compiler. This is done to allow you build modules, which will work with local libraries. I think that your compiler project uses wrong ABI.

    You can fix your compiler project to use platform ABI (convert structs like it was done by clang), OR you can define your own ABI and tune clang to use it.

    0 讨论(0)
提交回复
热议问题