55 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s2 3// GH87641 noticed that integer promotion of a bit-field of bit-precise integer4// type was promoting to int rather than the type of the bit-field.5struct S {6 unsigned _BitInt(7) x : 2;7 unsigned _BitInt(2) y : 2;8 unsigned _BitInt(72) z : 28;9 _BitInt(31) a : 12;10 _BitInt(33) b : 33;11};12 13// We don't have to worry about promotion cases where the bit-precise type is14// smaller than the width of the bit-field; that can't happen.15struct T {16 unsigned _BitInt(28) oh_no : 72; // expected-error {{width of bit-field 'oh_no' (72 bits) exceeds the width of its type (28 bits)}}17};18 19static_assert(20 _Generic(+(struct S){}.x,21 int : 0,22 unsigned _BitInt(7) : 1,23 unsigned _BitInt(2) : 224 ) == 1);25 26static_assert(27 _Generic(+(struct S){}.y,28 int : 0,29 unsigned _BitInt(7) : 1,30 unsigned _BitInt(2) : 231 ) == 2);32 33static_assert(34 _Generic(+(struct S){}.z,35 int : 0,36 unsigned _BitInt(72) : 1,37 unsigned _BitInt(28) : 238 ) == 1);39 40static_assert(41 _Generic(+(struct S){}.a,42 int : 0,43 _BitInt(31) : 1,44 _BitInt(12) : 2,45 unsigned _BitInt(31) : 346 ) == 1);47 48static_assert(49 _Generic(+(struct S){}.b,50 int : 0,51 long long : 1,52 _BitInt(33) : 2,53 unsigned _BitInt(33) : 354 ) == 2);55