@@ -30,21 +30,41 @@ struct simple {
3030 int a, b;
3131};
3232
33- struct Bitfields {
33+ // Byte-aligned bitfields
34+ struct byte_aligned_bitfields {
3435 unsigned int a : 8 ;
3536 unsigned int b : 8 ;
3637 unsigned int c : 16 ;
3738};
3839
39- struct SignedBitfields {
40+ struct signed_byte_aligned_bitfields {
4041 int x : 8 ;
4142 int y : 8 ;
4243};
4344
44- struct ByteBitfields {
45+ struct single_byte_bitfield {
4546 unsigned char a : 8 ;
4647};
4748
49+ // Partial bitfields (sub-byte)
50+ struct partial_bitfields {
51+ unsigned int a : 3 ;
52+ unsigned int b : 5 ;
53+ unsigned int c : 8 ;
54+ };
55+
56+ struct signed_partial_bitfields {
57+ int x : 4 ;
58+ int y : 4 ;
59+ };
60+
61+ struct mixed_partial_bitfields {
62+ unsigned char a : 1 ;
63+ unsigned char b : 1 ;
64+ unsigned char c : 1 ;
65+ unsigned char d : 5 ;
66+ };
67+
4868void function () {
4969 constexpr static empty e;
5070
@@ -70,9 +90,15 @@ void function() {
7090 s, {1111 , 2222 }, s
7191 };
7292
73- constexpr static Bitfields bf1 = {0xFF , 0xAA , 0x1234 };
74- constexpr static SignedBitfields bf2 = {-1 , 127 };
75- constexpr static ByteBitfields bf3 = {42 };
93+ // Byte-aligned bitfield tests
94+ constexpr static byte_aligned_bitfields ba_bf1 = {0xFF , 0xAA , 0x1234 };
95+ constexpr static signed_byte_aligned_bitfields ba_bf2 = {-1 , 127 };
96+ constexpr static single_byte_bitfield ba_bf3 = {42 };
97+
98+ // Partial bitfield tests
99+ constexpr static partial_bitfields p_bf1 = {1 , 2 , 3 };
100+ constexpr static signed_partial_bitfields p_bf2 = {-1 , 7 };
101+ constexpr static mixed_partial_bitfields p_bf3 = {1 , 0 , 1 , 15 };
76102}
77103
78104// CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE1e = #cir.zero : !rec_empty
@@ -102,9 +128,15 @@ void function() {
102128// CIR-DAG-SAME: #cir.zero : !rec_packed_and_aligned
103129// CIR-DAG-SAME: ]> : !cir.array<!rec_packed_and_aligned x 2>
104130
105- // CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE3bf1 = #cir.const_record<{#cir.int<255> : !u8i, #cir.int<170> : !u8i, #cir.int<52> : !u8i, #cir.int<18> : !u8i}> : !rec_anon_struct
106- // CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE3bf2 = #cir.const_record<{#cir.int<255> : !u8i, #cir.int<127> : !u8i, #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 2>}> : !rec_anon_struct
107- // CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE3bf3 = #cir.const_record<{#cir.int<42> : !u8i}> : !rec_ByteBitfields
131+ // Byte-aligned bitfield checks
132+ // CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE6ba_bf1 = #cir.const_record<{#cir.int<255> : !u8i, #cir.int<170> : !u8i, #cir.int<52> : !u8i, #cir.int<18> : !u8i}> : !rec_anon_struct
133+ // CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE6ba_bf2 = #cir.const_record<{#cir.int<255> : !u8i, #cir.int<127> : !u8i, #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 2>}> : !rec_anon_struct
134+ // CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE6ba_bf3 = #cir.const_record<{#cir.int<42> : !u8i}> : !rec_single_byte_bitfield
135+
136+ // Partial bitfield checks
137+ // CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE5p_bf1 = #cir.const_record<{#cir.int<17> : !u8i, #cir.int<3> : !u8i, #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 2>}> : !rec_anon_struct
138+ // CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE5p_bf2 = #cir.const_record<{#cir.int<127> : !u8i, #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 3>}> : !rec_signed_partial_bitfields
139+ // CIR-DAG: cir.global "private" internal dso_local @_ZZ8functionvE5p_bf3 = #cir.const_record<{#cir.int<125> : !u8i}> : !rec_mixed_partial_bitfields
108140
109141// CIR-LABEL: cir.func dso_local @_Z8functionv()
110142// CIR: cir.return
@@ -119,9 +151,12 @@ void function() {
119151// LLVM-DAG: @_ZZ8functionvE3paa = internal global %struct.packed_and_aligned <{ i16 1, i8 2, float 3.000000e+00, i8 0 }>
120152// LLVM-DAG: @_ZZ8functionvE5array = internal global [2 x %struct.Point] [%struct.Point { i32 123, i32 456, [3 x i8] c"\0B\16!", i32 789 }, %struct.Point { i32 10, i32 20, [3 x i8] zeroinitializer, i32 40 }]
121153// LLVM-DAG: @_ZZ8functionvE9paa_array = internal global [2 x %struct.packed_and_aligned] [%struct.packed_and_aligned <{ i16 1, i8 2, float 3.000000e+00, i8 0 }>, %struct.packed_and_aligned zeroinitializer]
122- // LLVM-DAG: @_ZZ8functionvE3bf1 = internal global { i8, i8, i8, i8 } { i8 -1, i8 -86, i8 52, i8 18 }
123- // LLVM-DAG: @_ZZ8functionvE3bf2 = internal global { i8, i8, [2 x i8] } { i8 -1, i8 127, [2 x i8] zeroinitializer }
124- // LLVM-DAG: @_ZZ8functionvE3bf3 = internal global %struct.ByteBitfields { i8 42 }
154+ // LLVM-DAG: @_ZZ8functionvE6ba_bf1 = internal global { i8, i8, i8, i8 } { i8 -1, i8 -86, i8 52, i8 18 }
155+ // LLVM-DAG: @_ZZ8functionvE6ba_bf2 = internal global { i8, i8, [2 x i8] } { i8 -1, i8 127, [2 x i8] zeroinitializer }
156+ // LLVM-DAG: @_ZZ8functionvE6ba_bf3 = internal global %struct.single_byte_bitfield { i8 42 }
157+ // LLVM-DAG: @_ZZ8functionvE5p_bf1 = internal global { i8, i8, [2 x i8] } { i8 17, i8 3, [2 x i8] zeroinitializer }
158+ // LLVM-DAG: @_ZZ8functionvE5p_bf2 = internal global %struct.signed_partial_bitfields { i8 127, [3 x i8] zeroinitializer }
159+ // LLVM-DAG: @_ZZ8functionvE5p_bf3 = internal global %struct.mixed_partial_bitfields { i8 125 }
125160
126161// LLVM-LABEL: define{{.*}} void @_Z8functionv
127162// LLVM: ret void
@@ -136,9 +171,12 @@ void function() {
136171// OGCG-DAG: @_ZZ8functionvE3paa = internal constant %struct.packed_and_aligned <{ i16 1, i8 2, float 3.000000e+00, i8 undef }>
137172// OGCG-DAG: @_ZZ8functionvE5array = internal constant [2 x %struct.Point] [%struct.Point { i32 123, i32 456, [3 x i8] c"\0B\16!", i32 789 }, %struct.Point { i32 10, i32 20, [3 x i8] zeroinitializer, i32 40 }]
138173// OGCG-DAG: @_ZZ8functionvE9paa_array = internal constant [2 x %struct.packed_and_aligned] [%struct.packed_and_aligned <{ i16 1, i8 2, float 3.000000e+00, i8 undef }>, %struct.packed_and_aligned <{ i16 0, i8 0, float 0.000000e+00, i8 undef }>]
139- // OGCG-DAG: @_ZZ8functionvE3bf1 = internal constant { i8, i8, i8, i8 } { i8 -1, i8 -86, i8 52, i8 18 }
140- // OGCG-DAG: @_ZZ8functionvE3bf2 = internal constant { i8, i8, [2 x i8] } { i8 -1, i8 127, [2 x i8] undef }
141- // OGCG-DAG: @_ZZ8functionvE3bf3 = internal constant %struct.ByteBitfields { i8 42 }
174+ // OGCG-DAG: @_ZZ8functionvE6ba_bf1 = internal constant { i8, i8, i8, i8 } { i8 -1, i8 -86, i8 52, i8 18 }
175+ // OGCG-DAG: @_ZZ8functionvE6ba_bf2 = internal constant { i8, i8, [2 x i8] } { i8 -1, i8 127, [2 x i8] undef }
176+ // OGCG-DAG: @_ZZ8functionvE6ba_bf3 = internal constant %struct.single_byte_bitfield { i8 42 }
177+ // OGCG-DAG: @_ZZ8functionvE5p_bf1 = internal constant { i8, i8, [2 x i8] } { i8 17, i8 3, [2 x i8] undef }
178+ // OGCG-DAG: @_ZZ8functionvE5p_bf2 = internal constant %struct.signed_partial_bitfields { i8 127, [3 x i8] undef }
179+ // OGCG-DAG: @_ZZ8functionvE5p_bf3 = internal constant %struct.mixed_partial_bitfields { i8 125 }
142180
143181// OGCG-LABEL: define{{.*}} void @_Z8functionv
144182// OGCG: ret void
0 commit comments