Debian Codegraph @

clang/test/Sema/bitint-bitfield-promote.c

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
2
3 // GH87641 noticed that integer promotion of a bit-field of bit-precise integer
4 // type was promoting to int rather than the type of the bit-field.
5 struct 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 is
14 // smaller than the width of the bit-field; that can't happen.
15 struct 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
19 static_assert(
20 _Generic(+(struct S){}.x,
21 int : 0,
22 unsigned _BitInt(7) : 1,
23 unsigned _BitInt(2) : 2
24 ) == 1);
25
26 static_assert(
27 _Generic(+(struct S){}.y,
28 int : 0,
29 unsigned _BitInt(7) : 1,
30 unsigned _BitInt(2) : 2
31 ) == 2);
32
33 static_assert(
34 _Generic(+(struct S){}.z,
35 int : 0,
36 unsigned _BitInt(72) : 1,
37 unsigned _BitInt(28) : 2
38 ) == 1);
39
40 static_assert(
41 _Generic(+(struct S){}.a,
42 int : 0,
43 _BitInt(31) : 1,
44 _BitInt(12) : 2,
45 unsigned _BitInt(31) : 3
46 ) == 1);
47
48 static_assert(
49 _Generic(+(struct S){}.b,
50 int : 0,
51 long long : 1,
52 _BitInt(33) : 2,
53 unsigned _BitInt(33) : 3
54 ) == 2);