https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98572
Bug ID: 98572 Summary: Unexpected signed extension for unsigned bit fields Product: gcc Version: 8.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: vonchun at gmail dot com Target Milestone: --- Consider the following C code: ============================================================================= #include <stdio.h> #include <stdint.h> //#pragma pack(1) typedef struct { unsigned bits24:24; unsigned _:8; } my_type_t; int main() { uintptr_t p; my_type_t t1; t1.bits24 = 0xfffff; p = t1.bits24 << 12; printf("p=%llx\n", p); uint32_t t2 = 0xfffff; p = t2 << 12; printf("p=%llx\n", p); return 0; } ============================================================================== The output will be: p=fffffffffffff000 p=fffff000 which means signed extension occurrs here: p = t1.bits24 << 12; This signed extension is unexpected since bits24 has been declared as "unsigned". Even if integer promotion happens, it should be promoted as "unsigned int" as well. VERSION information: gcc --version gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5) Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. OS: [localhost test]$ uname -a Linux localhost.localdomain 4.18.0 #1 SMP Thu Jul 23 13:20:43 PDT 2020 x86_64 x86_64 x86_64 GNU/Linux