[LLVMdev] StructLayout

David Greene dag at cray.com
Tue Sep 22 13:27:03 PDT 2009


How are bitfields handled in StructLayout?  In LLVM 2.5 the
struct is unambiguously size by:

    StructSize += TD.getTypePaddedSize(Ty); // Consume space for this data

In LLVM 2.6 it's getTypeAllocSize, which does the same thing.

Unfortunately, this is not correct for bitfields.  For example,
LLVM reports this struct:

typedef struct test1 {
	short f0 :  10;
	char f1 :  5;
	long f2 :  1;
	long f3 :  45;
} test1_t; 

which in LLVM is:

%test1 = type { i10, i5, i1, i45 }

to have size 12 on x86-64 whien it should have size 8.

I don't know how to work around this since the original bitfield type has been 
lost by the time we translate to LLVM.

Does this need to be handled in the frontend, to munge the struct type
and add the necessary masking and shifting so it works correctly?

What does llvm-gcc do with something like this?

                                   -Dave



More information about the llvm-dev mailing list