[llvm-dev] Why Clang is unpacking my StructType Function arguments

Zhang via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 18 01:06:38 PDT 2018


Hi:
We are currently building an internal solution based on LLVM/Clang technologies which involves generating LLVM IR based on Bitcode generated by Clang from C codes.
We have a C function which prototype looks like the following:
typedef struct {
    int (*allocFunction)(void* x, void* y);
    void* YY;
} Type4;

int bar (Type1 *x, Type2 *y, Type3 *z, Type4 bar)





When we compile this code uses Clang 6 into x86_64-apple-macos, the generated function in IR has the type:


; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @bar(%struct.Type1*, %struct.Type2*, %struct.Type3*,i32 (i8*, i8*)*, i8*)



Which basically split the two members of Type4 into two arguments, strange, but still understandable.


However when we are compiling this exact same piece of code into thumbv7-none-linux-android , things gets even stranger:
define i32 @bar(%struct.Type1*, %struct.Type2*, %struct.Type3*,[2 x i32])


and when caller is using this function, an alloca with type Type4 is bitcasted to [2 x i32]*, loaded and then passed as argument.


It would be great if someone could tell me how to tell clang from unpacking my arguments and if that's not possible , the correct way to handle this diffrence.




Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180718/f88e453a/attachment.html>


More information about the llvm-dev mailing list