On 09.01.2026 08:04, Herman ten Brugge via Tinycc-devel wrote:
While debugging some i386 code I found some memory alignment differences.
1) The double and long long type differ inside and outside struct.
outside struct (size = 8, align = 8):
double a;
long long b;
inside struct (size = 8 align = 4)
struct {
double a;
long long b;
};
This only happens on x86 (and perhaps on !TCC_ARM_EABI which I cannot test).
I cannot reproduce this. Alignment is 4 in both cases
2) The memory alignment of a struct/array depends on its size.
The memory alignment is 4 for a, 8 for b, 16 for c and 32 for d and e.
int a[1];
int b[2];
int c[4];
int d[8];
int e[16];
I cannot reproduce this either. Alignment is 4 in all cases.
You can check this alignment with compiling above code with gcc -S
and check assemby code for .align/.zero/.space depending on
platform (x86/x86_64/arm/arm64/riscv).
As far as I can tell this happens for all data. So also structs
get this alignment depending on size.
See patch that fixes both problems + testcase update.
The compiler can align objects as it likes as long as it satisfies
the ABI.
GCC may have its priorities, but for TCC the number one priority
is to stay as simple and fast as possible.
-- gr
Herman
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel