LLVMSwift icon indicating copy to clipboard operation
LLVMSwift copied to clipboard

DIBuilder builds types with wrong size and alignment

Open Snowy1803 opened this issue 3 years ago • 0 comments

All of the buildXXXType methods in DIBuilder use the size of a pointer as a radix:

let radix = UInt32(self.module.dataLayout.intPointerType().width)
...
/* size = */ size.valueInBits(radix: UInt64(radix))
/* alignment = */ alignment.rawValue * radix

Because Size stores sizes in bytes, and that on 64 bit platforms a pointer is 64 bits, instead of emitting a C char as 8 bits, it is emitted as 64 bits, and a 64-bit type is emitted as a 512 bit type.

As LLVM considers 1 byte to always be 8 bits, I don't understand why the size in bytes isn't just multiplied by a constant 8?

I see that in the unit tests an int32_t has an expected size of 512, but clang correctly outputs a size of 32 for it...

Snowy1803 avatar Feb 06 '22 19:02 Snowy1803