I am using LLVM C++ API to generate IR for some structure data.
For example:
struct mystruct {int a:1; int b:2; unsigned long c} = {{1, 2, 3}};
I read the document and tried the demo cgi, it seems the API requires user to handle padding and value combination for the initializer by themselves.
Is there any way to create the struct more simply like this:
fields.push_back(Type::getIntNTy(context, 1));
fields.push_back(Type::getIntNTy(context, 2));
fields.push_back(Type::getIntNTy(context, 64));
structTy.setBody(fields, false /* isPacked*/);
It’s really tough to do layout work and it’s very likely to cause bugs. Combining the values for the initializer is also not easy.
As my understanding, if I tell llvm API that the struct is not packed, it should handle padding automatically, right?
Any comments? Any pointer to references is also appreciated.