https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129249
Bug ID: 129249
Summary: wrong code at -O0: __builtin_clear_padding changes a
reverse-storage-order bit-field value
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
#include <stdio.h>
struct __attribute__((scalar_storage_order("big-endian"))) S {
unsigned a : 3;
unsigned b : 3;
};
int main(void)
{
struct S s = { 7, 7 };
#ifndef SKIP_CLEAR_PADDING
__builtin_clear_padding(&s);
#endif
printf("%u %u\n", s.a, s.b);
}
godbolt: https://godbolt.org/z/s1Gv8aPeG
At -O0 -DSKIP_CLEAR_PADDING the program prints "7 7", while at -O0 it prints "1
7". __builtin_clear_padding must not affect the value representation, so "7 7"
is the correct output.