Skip to content

Commit 7563531

Browse files
[CIR] Add test for parsing bitfield_info attribute (#147628)
This PR adds a test for parsing the bitfield_info attribute. Additionally, it updates the `storage_type` and `is_signed` fields to match the style used in the incubator ASM format guide.
1 parent 2546c6d commit 7563531

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,28 +489,28 @@ def BitfieldInfoAttr : CIR_Attr<"BitfieldInfo", "bitfield_info"> {
489489
is 4 bits wide, starts at offset 0, and is signed.
490490
}];
491491
let parameters = (ins "mlir::StringAttr":$name,
492-
"mlir::Type":$storageType,
492+
"mlir::Type":$storage_type,
493493
"uint64_t":$size,
494494
"uint64_t":$offset,
495-
"bool":$isSigned);
495+
"bool":$is_signed);
496496

497497
let assemblyFormat = [{`<` struct($name,
498-
$storageType,
498+
$storage_type,
499499
$size,
500500
$offset,
501-
$isSigned)
501+
$is_signed)
502502
`>`
503503
}];
504504

505505
let builders = [
506506
AttrBuilder<(ins "llvm::StringRef":$name,
507-
"mlir::Type":$storageType,
507+
"mlir::Type":$storage_type,
508508
"uint64_t":$size,
509509
"uint64_t":$offset,
510-
"bool":$isSigned
510+
"bool":$is_signed
511511
), [{
512-
return $_get($_ctxt, mlir::StringAttr::get($_ctxt, name), storageType,
513-
size, offset, isSigned);
512+
return $_get($_ctxt, mlir::StringAttr::get($_ctxt, name), storage_type,
513+
size, offset, is_signed);
514514
}]>
515515
];
516516
}

clang/test/CIR/CodeGen/bitfields.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef struct {
1313
} A;
1414

1515
// CIR-DAG: !rec_A = !cir.record<struct "A" packed padded {!s8i, !s8i, !s8i, !u16i, !cir.array<!u8i x 3>}>
16-
// CIR-DAG: #bfi_more_bits = #cir.bitfield_info<name = "more_bits", storageType = !u16i, size = 4, offset = 3, isSigned = false>
16+
// CIR-DAG: #bfi_more_bits = #cir.bitfield_info<name = "more_bits", storage_type = !u16i, size = 4, offset = 3, is_signed = false>
1717
// LLVM-DAG: %struct.A = type <{ i8, i8, i8, i16, [3 x i8] }>
1818
// OGCG-DAG: %struct.A = type <{ i8, i8, i8, i16, [3 x i8] }>
1919

@@ -35,7 +35,7 @@ typedef struct {
3535
int e : 15;
3636
unsigned f; // type other than int above, not a bitfield
3737
} S;
38-
// CIR-DAG: #bfi_c = #cir.bitfield_info<name = "c", storageType = !u64i, size = 17, offset = 32, isSigned = true>
38+
// CIR-DAG: #bfi_c = #cir.bitfield_info<name = "c", storage_type = !u64i, size = 17, offset = 32, is_signed = true>
3939
// CIR-DAG: !rec_S = !cir.record<struct "S" {!u64i, !u16i, !u32i}>
4040
// LLVM-DAG: %struct.S = type { i64, i16, i32 }
4141
// OGCG-DAG: %struct.S = type { i64, i16, i32 }

clang/test/CIR/CodeGen/bitfields.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ typedef struct {
1414
unsigned f; // type other than int above, not a bitfield
1515
} S;
1616
// CIR-DAG: !rec_S = !cir.record<struct "S" {!u64i, !u16i, !u32i}>
17-
// CIR-DAG: #bfi_c = #cir.bitfield_info<name = "c", storageType = !u64i, size = 17, offset = 32, isSigned = true>
17+
// CIR-DAG: #bfi_c = #cir.bitfield_info<name = "c", storage_type = !u64i, size = 17, offset = 32, is_signed = true>
1818
// LLVM-DAG: %struct.S = type { i64, i16, i32 }
1919
// OGCG-DAG: %struct.S = type { i64, i16, i32 }
2020

clang/test/CIR/IR/bitfield_info.cir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: cir-opt %s | FileCheck %s
2+
3+
!s32i = !cir.int<s, 32>
4+
!u32i = !cir.int<u, 32>
5+
6+
7+
!rec_S = !cir.record<struct "S" {!u32i}>
8+
#bfi_c = #cir.bitfield_info<name = "c", storage_type = !u32i, size = 17, offset = 15, is_signed = true>
9+
10+
// CHECK: #bfi_c = #cir.bitfield_info<name = "c", storage_type = !u32i, size = 17, offset = 15, is_signed = true>
11+
12+
// Use bitfield to enforce printing the attribute
13+
cir.func dso_local @init(%arg0: !cir.ptr<!rec_S> ){
14+
%0 = cir.alloca !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>, ["s", init] {alignment = 8 : i64}
15+
cir.store %arg0, %0 : !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>
16+
%1 = cir.load align(8) %0 : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>
17+
%2 = cir.get_member %1[0] {name = "c"} : !cir.ptr<!rec_S> -> !cir.ptr<!u32i>
18+
%3 = cir.get_bitfield(#bfi_c, %2 : !cir.ptr<!u32i>) -> !s32i
19+
cir.return
20+
}

0 commit comments

Comments
 (0)