From 1d8a4548b347da39fc3f7cf4426f2791fc0344f9 Mon Sep 17 00:00:00 2001 From: Andres Salamanca Date: Tue, 8 Jul 2025 19:40:01 -0500 Subject: [PATCH] [CIR] Add test for parsing bitfield_info attribute --- .../include/clang/CIR/Dialect/IR/CIRAttrs.td | 16 +++++++-------- clang/test/CIR/CodeGen/bitfields.c | 4 ++-- clang/test/CIR/CodeGen/bitfields.cpp | 2 +- clang/test/CIR/IR/bitfield_info.cir | 20 +++++++++++++++++++ 4 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 clang/test/CIR/IR/bitfield_info.cir diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td index 75650beec0c6d..785478abb0778 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td @@ -489,28 +489,28 @@ def BitfieldInfoAttr : CIR_Attr<"BitfieldInfo", "bitfield_info"> { is 4 bits wide, starts at offset 0, and is signed. }]; let parameters = (ins "mlir::StringAttr":$name, - "mlir::Type":$storageType, + "mlir::Type":$storage_type, "uint64_t":$size, "uint64_t":$offset, - "bool":$isSigned); + "bool":$is_signed); let assemblyFormat = [{`<` struct($name, - $storageType, + $storage_type, $size, $offset, - $isSigned) + $is_signed) `>` }]; let builders = [ AttrBuilder<(ins "llvm::StringRef":$name, - "mlir::Type":$storageType, + "mlir::Type":$storage_type, "uint64_t":$size, "uint64_t":$offset, - "bool":$isSigned + "bool":$is_signed ), [{ - return $_get($_ctxt, mlir::StringAttr::get($_ctxt, name), storageType, - size, offset, isSigned); + return $_get($_ctxt, mlir::StringAttr::get($_ctxt, name), storage_type, + size, offset, is_signed); }]> ]; } diff --git a/clang/test/CIR/CodeGen/bitfields.c b/clang/test/CIR/CodeGen/bitfields.c index 6eb753c5cc3d2..ee69db22b4a20 100644 --- a/clang/test/CIR/CodeGen/bitfields.c +++ b/clang/test/CIR/CodeGen/bitfields.c @@ -13,7 +13,7 @@ typedef struct { } A; // CIR-DAG: !rec_A = !cir.record}> -// CIR-DAG: #bfi_more_bits = #cir.bitfield_info +// CIR-DAG: #bfi_more_bits = #cir.bitfield_info // LLVM-DAG: %struct.A = type <{ i8, i8, i8, i16, [3 x i8] }> // OGCG-DAG: %struct.A = type <{ i8, i8, i8, i16, [3 x i8] }> @@ -35,7 +35,7 @@ typedef struct { int e : 15; unsigned f; // type other than int above, not a bitfield } S; -// CIR-DAG: #bfi_c = #cir.bitfield_info +// CIR-DAG: #bfi_c = #cir.bitfield_info // CIR-DAG: !rec_S = !cir.record // LLVM-DAG: %struct.S = type { i64, i16, i32 } // OGCG-DAG: %struct.S = type { i64, i16, i32 } diff --git a/clang/test/CIR/CodeGen/bitfields.cpp b/clang/test/CIR/CodeGen/bitfields.cpp index a4d58b5cadcec..7372acaeb9e06 100644 --- a/clang/test/CIR/CodeGen/bitfields.cpp +++ b/clang/test/CIR/CodeGen/bitfields.cpp @@ -14,7 +14,7 @@ typedef struct { unsigned f; // type other than int above, not a bitfield } S; // CIR-DAG: !rec_S = !cir.record -// CIR-DAG: #bfi_c = #cir.bitfield_info +// CIR-DAG: #bfi_c = #cir.bitfield_info // LLVM-DAG: %struct.S = type { i64, i16, i32 } // OGCG-DAG: %struct.S = type { i64, i16, i32 } diff --git a/clang/test/CIR/IR/bitfield_info.cir b/clang/test/CIR/IR/bitfield_info.cir new file mode 100644 index 0000000000000..682e0903fd552 --- /dev/null +++ b/clang/test/CIR/IR/bitfield_info.cir @@ -0,0 +1,20 @@ +// RUN: cir-opt %s | FileCheck %s + +!s32i = !cir.int +!u32i = !cir.int + + +!rec_S = !cir.record +#bfi_c = #cir.bitfield_info + +// CHECK: #bfi_c = #cir.bitfield_info + +// Use bitfield to enforce printing the attribute +cir.func dso_local @init(%arg0: !cir.ptr ){ + %0 = cir.alloca !cir.ptr, !cir.ptr>, ["s", init] {alignment = 8 : i64} + cir.store %arg0, %0 : !cir.ptr, !cir.ptr> + %1 = cir.load align(8) %0 : !cir.ptr>, !cir.ptr + %2 = cir.get_member %1[0] {name = "c"} : !cir.ptr -> !cir.ptr + %3 = cir.get_bitfield(#bfi_c, %2 : !cir.ptr) -> !s32i + cir.return +}