================
@@ -79,6 +79,35 @@ struct CIRRecordLowering final {
         cir::ArrayType::get(cirGenTypes.convertTypeForMem(field->getType()), 
0),
         cir::RecordMemberKind::BitField);
   }
+
+  /// An access unit can be narrower than the types its bit-fields were
+  /// declared with.  In `struct { int a : 4; int b : 11; int c : 17; }` all
+  /// three share one 4-byte unit, but `c` is declared `int`, so the declared
+  /// data runs 15 bits past the unit:
+  ///
+  ///   |-a-|----b-----|-------c--------|
+  ///   |--------- 4-byte unit ---------|--- extent ---|
+  ///                  |------ c declared as int ------|
+  ///   0   4          15               32             47  bits
----------------
adams381 wrote:

That example explains the concept but not the motivation.  Consider this example

```c
typedef struct { long long x : 32; }                      Wide;
typedef struct { int x : 32; } __attribute__((aligned(8))) Narrow;
```

`Wide` needs: `i64`

`Narrow` needs: `i32`

Currently we generate

```mlir
!rec_Narrow = !cir.struct<"Narrow" {bitfield !u32i, pad !cir.array<!u8i x 4>}>
!rec_Wide   = !cir.struct<"Wide"   {bitfield !u32i, bitfield 
!cir.array<!cir.array<!u8i x 4> x 0>, pad !cir.array<!u8i x 4>}>
```

Without the extent member, the two types are identical.

https://github.com/llvm/llvm-project/pull/220069
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to