"Mahadevan R" <mdevan.foobar at gmail.com> writes:>> You could use llvm-gcc to convert the struct to an LLVM type. >> Otherwise, it wouldn't be too hard to convert the struct by >> hand as long as it doesn't have any exotic types in it. A >> VLA at the end (with element type T) is currently represented >> by placing a field of type T at the end (i.e. just one element). > > But can I assume that both gcc and LLVM will layout the structure > in the same way (member alignment, padding)?llvm-gcc and gcc follows the same platform C ABI. So the answer to your question is "yes". -- Oscar
> > But can I assume that both gcc and LLVM will layout the structure > > in the same way (member alignment, padding)? > > llvm-gcc and gcc follows the same platform C ABI. So the answer to your > question is "yes".That's not entirely true. For example it assumes the user is not using attributes to create types with unusual alignments or sizes. Most of the gcc -> llvm struct type conversion is straightforward but don't forget that gcc already did C -> gcc type conversion (which is also mostly straightforward). As long as you stay in the land of simple types doing the obvious thing should be fine. Ciao, Duncan. PS: Try using llvm-gcc -emit-llvm to see how llvm-gcc is converting things, and to validate your implementation.
Duncan Sands <baldrick at free.fr> writes:>> > But can I assume that both gcc and LLVM will layout the structure >> > in the same way (member alignment, padding)? >> >> llvm-gcc and gcc follows the same platform C ABI. So the answer to your >> question is "yes". > > That's not entirely true. For example it assumes the user is not > using attributes to create types with unusual alignments or sizes.Using attributes means bypassing the platform C ABI and introducing a compiler-specific ABI, right? My point is that if your code does not depend on a specific compiler extensions, llvm-gcc shouldn't behave different wrt data layout. [snip] -- Oscar