Wrong ABI: structs with unnamed bit-fields
ch3root opened this issue · 0 comments
ch3root commented
The second sizeof in the testcase below gives different results in tis-interpreter and in gcc/clang.
Source code:
#include <stdio.h>
int main()
{
printf("%zu %zu %zu\n",
sizeof(struct { char c; int :0; }),
sizeof(struct { char c; int :1; }),
sizeof(struct { char c; char :1; }));
}
tis-interpreter (21f4c7a) output:
[value] Analyzing a complete application starting at main
[value] Computing initial state
[value] Initial state computed
4 4 2
[value] done for function main
gcc (GCC) 7.0.0 20160627 (experimental):
$ gcc -std=c11 -pedantic -Wall -Wextra -O3 -fsanitize=undefined test.c && ./a.out
4 2 2
clang version 3.9.0 (trunk 271312):
$ clang -std=c11 -Weverything -Wno-padded -O3 -fsanitize=undefined test.c && ./a.out
4 2 2
Relevant rule from amd64 abi -- the last sentence in 3.1.2.:
"Unnamed bit-fields’ types do not affect the alignment of a structure or union."
Not sure what doesn it mean for the first sizeof in the testcase...