llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clangir Author: Andy Kaylor (andykaylor) <details> <summary>Changes</summary> CIR had been using a hard-coded 64-bit maximum alignment for _BitInt types, which matches x86-64 targets but not AArch64. This change adds an MLIR data layout entry to record the target's maximum _BitInt alignment so that this value can be retrieved by post-codegen queries. Assisted-by: Cursor / various models --- Patch is 20.98 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/241466.diff 12 Files Affected: - (modified) clang/include/clang/CIR/CIRDataLayoutSpec.h (+11-5) - (modified) clang/include/clang/CIR/Dialect/IR/CIRAttrs.td (+26) - (modified) clang/include/clang/CIR/Dialect/IR/CIRTypes.td (+9-1) - (modified) clang/lib/CIR/CodeGen/CIRDataLayoutSpec.cpp (+9-2) - (modified) clang/lib/CIR/CodeGen/CIRGenerator.cpp (+2-1) - (modified) clang/lib/CIR/Dialect/IR/CIRAttrs.cpp (+15) - (modified) clang/lib/CIR/Dialect/IR/CIRTypes.cpp (+61-4) - (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+9-6) - (added) clang/test/CIR/CodeGen/bitint-max-align.c (+58) - (modified) clang/test/CIR/CodeGen/dlti.c (+1) - (added) clang/test/CIR/IR/bitint-data-layout.cir (+36) - (modified) clang/tools/cir-translate/cir-translate.cpp (+2-1) ``````````diff diff --git a/clang/include/clang/CIR/CIRDataLayoutSpec.h b/clang/include/clang/CIR/CIRDataLayoutSpec.h index c270f6283afe47..80f8b790e14570 100644 --- a/clang/include/clang/CIR/CIRDataLayoutSpec.h +++ b/clang/include/clang/CIR/CIRDataLayoutSpec.h @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// // // This file declares a helper that attaches the DLTI data-layout spec, -// including the CIR-native pointer entry, to a CIR module. +// including the CIR-native pointer and _BitInt entries, to a CIR module. // //===----------------------------------------------------------------------===// #ifndef CLANG_CIR_CIRDATALAYOUTSPEC_H @@ -24,10 +24,16 @@ class ModuleOp; namespace cir { /// Translate \p dl into a DLTI data-layout spec and attach it to \p mod. -/// On top of the plain mlir::translateDataLayout entries this adds a -/// #cir.ptr_spec entry keyed on !cir.ptr, which CIR pointer types read for -/// their size and alignment; without it pointer widths default to 64 bits. -void setMLIRDataLayout(mlir::ModuleOp mod, const llvm::DataLayout &dl); +/// On top of the plain mlir::translateDataLayout entries this adds: +/// +/// - a #cir.ptr_spec entry keyed on !cir.ptr, which CIR pointer types read +/// for their size and alignment. Without it pointer widths default to 64 +/// bits. +/// - a #cir.bitint_spec entry keyed on !cir.int<u, 1, bitint>. +/// \p bitIntMaxAlign is TargetInfo::getBitIntMaxAlign(), in bits. _BitInt +/// ABI alignment clamps to that cap. +void setMLIRDataLayout(mlir::ModuleOp mod, const llvm::DataLayout &dl, + unsigned bitIntMaxAlign); } // namespace cir diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td index 8b25285ae8c516..cee11473423134 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td @@ -1553,6 +1553,32 @@ def CIR_PtrSpecAttr : CIR_Attr<"PtrSpec", "ptr_spec"> { let canHaveIllegalCXXABIType = 0; } +//===----------------------------------------------------------------------===// +// BitIntSpecAttr +//===----------------------------------------------------------------------===// + +def CIR_BitIntSpecAttr : CIR_Attr<"BitIntSpec", "bitint_spec"> { + let summary = "!cir.int _BitInt data layout spec"; + let description = [{ + Upper bound, in bits, on the ABI alignment of a `_BitInt`. This is + `TargetInfo::getBitIntMaxAlign()`. `_BitInt(N)` is aligned to + `min(PowerOf2Ceil(N), max_align)` bits, and at least one byte. + + Used as the value of the `!cir.int<u, 1, bitint>`-keyed data-layout + entry. The key names the `_BitInt` class. Its width is not a layout + input. + + ```mlir + #dlti.dl_spec<!cir.int<u, 1, bitint> = + #cir.bitint_spec<max_align = 64>> + ``` + }]; + let parameters = (ins "uint32_t":$max_align); + let assemblyFormat = "`<` struct(params) `>`"; + let genVerifyDecl = 1; + let canHaveIllegalCXXABIType = 0; +} + //===----------------------------------------------------------------------===// // ConstComplexAttr //===----------------------------------------------------------------------===// diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td index caacdb2bf8de59..8c79ec8a8e64bd 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td @@ -37,7 +37,8 @@ class CIR_Type<string name, string typeMnemonic, list<Trait> traits = [], //===----------------------------------------------------------------------===// def CIR_IntType : CIR_Type<"Int", "int", [ - DeclareTypeInterfaceMethods<DataLayoutTypeInterface>, + DeclareTypeInterfaceMethods<DataLayoutTypeInterface, + ["areCompatible", "verifyEntries"]>, DeclareTypeInterfaceMethods<CIR_SizedTypeInterface>, DeclareTypeInterfaceMethods<CIR_IntTypeInterface>, ]> { @@ -89,6 +90,13 @@ def CIR_IntType : CIR_Type<"Int", "int", [ return isFundamentalUIntType(*this); } + /// Key of the data-layout entry that carries + /// TargetInfo::getBitIntMaxAlign(), in bits. The width is not a layout + /// input. Every _BitInt reads this one entry. + static IntType getBitIntMaxAlignKey(mlir::MLIRContext *ctx) { + return get(ctx, /*width=*/1, /*isSigned=*/false, /*isBitInt=*/true); + } + /// Returns a minimum bitwidth of cir::IntType static unsigned minBitwidth() { return 1; } /// Returns a maximum bitwidth of cir::IntType. diff --git a/clang/lib/CIR/CodeGen/CIRDataLayoutSpec.cpp b/clang/lib/CIR/CodeGen/CIRDataLayoutSpec.cpp index a25fb46da5e8e7..ffc387834a8260 100644 --- a/clang/lib/CIR/CodeGen/CIRDataLayoutSpec.cpp +++ b/clang/lib/CIR/CodeGen/CIRDataLayoutSpec.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// // // This file attaches the DLTI data-layout spec, including the CIR-native -// pointer entry, to a CIR module. +// pointer and _BitInt entries, to a CIR module. // //===----------------------------------------------------------------------===// @@ -22,7 +22,8 @@ #include "clang/CIR/MissingFeatures.h" #include "llvm/IR/DataLayout.h" -void cir::setMLIRDataLayout(mlir::ModuleOp mod, const llvm::DataLayout &dl) { +void cir::setMLIRDataLayout(mlir::ModuleOp mod, const llvm::DataLayout &dl, + unsigned bitIntMaxAlign) { mlir::MLIRContext *mlirContext = mod.getContext(); mlir::DataLayoutSpecInterface dlSpec = mlir::translateDataLayout(dl, mlirContext); @@ -44,6 +45,12 @@ void cir::setMLIRDataLayout(mlir::ModuleOp mod, const llvm::DataLayout &dl) { dlSpec.getEntries().begin(), dlSpec.getEntries().end()); entries.push_back(mlir::DataLayoutEntryAttr::get(ptrKey, ptrSpec)); + // The key names the _BitInt class. max_align is + // TargetInfo::getBitIntMaxAlign(), in bits. + auto bitIntKey = cir::IntType::getBitIntMaxAlignKey(mlirContext); + auto bitIntSpec = cir::BitIntSpecAttr::get(mlirContext, bitIntMaxAlign); + entries.push_back(mlir::DataLayoutEntryAttr::get(bitIntKey, bitIntSpec)); + mod->setAttr(mlir::DLTIDialect::kDataLayoutAttrName, mlir::DataLayoutSpecAttr::get(mlirContext, entries)); } diff --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp b/clang/lib/CIR/CodeGen/CIRGenerator.cpp index d2f1b54e43325c..d623bd27b24f9b 100644 --- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp @@ -67,7 +67,8 @@ void CIRGenerator::Initialize(ASTContext &astContext) { mlir::ModuleOp mod = cgm->getModule(); llvm::DataLayout layout = llvm::DataLayout(astContext.getTargetInfo().getDataLayoutString()); - cir::setMLIRDataLayout(mod, layout); + cir::setMLIRDataLayout(mod, layout, + astContext.getTargetInfo().getBitIntMaxAlign()); } bool CIRGenerator::verifyModule() const { return cgm->verifyModule(); } diff --git a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp index 8f2b1933c6dbba..07d62e3fc95cbd 100644 --- a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp @@ -15,6 +15,7 @@ #include "mlir/IR/Attributes.h" #include "mlir/IR/DialectImplementation.h" +#include "llvm/Support/MathExtras.h" //===-----------------------------------------------------------------===// // RecordMembers @@ -173,6 +174,20 @@ LogicalResult PtrSpecAttr::verify(function_ref<InFlightDiagnostic()> emitError, return success(); } +//===----------------------------------------------------------------------===// +// BitIntSpecAttr definitions +//===----------------------------------------------------------------------===// + +LogicalResult +BitIntSpecAttr::verify(function_ref<InFlightDiagnostic()> emitError, + uint32_t maxAlign) { + // TargetInfo::getBitIntMaxAlign() is a power of two, at least the char + // width. Char width is 8 bits. + if (maxAlign < 8 || !llvm::isPowerOf2_32(maxAlign)) + return emitError() << "max_align must be a power of two of at least 8"; + return success(); +} + //===----------------------------------------------------------------------===// // BitFieldDeclAttr definitions //===----------------------------------------------------------------------===// diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp index 40ba3bb4989776..365e5e475d76b3 100644 --- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp @@ -789,6 +789,22 @@ cir::PtrSpecAttr getPointerSpec(mlir::DataLayoutEntryListRef params, kDefaultPointerAlignment * kBitsInByte, kDefaultPointerSizeBits); } + +// TargetInfo::getBitIntMaxAlign() when the module has no #cir.bitint_spec +// entry. That is LongLongAlign's initial value. +constexpr static uint64_t kDefaultBitIntMaxAlignBits = 64; + +/// The _BitInt alignment cap in bits. The #cir.bitint_spec entry holds +/// TargetInfo::getBitIntMaxAlign(). +uint64_t getBitIntMaxAlignBits(mlir::DataLayoutEntryListRef params) { + for (mlir::DataLayoutEntryInterface entry : params) { + if (!entry.isTypeEntry()) + continue; + if (auto spec = mlir::dyn_cast<cir::BitIntSpecAttr>(entry.getValue())) + return spec.getMaxAlign(); + } + return kDefaultBitIntMaxAlignBits; +} } // namespace llvm::TypeSize @@ -1086,7 +1102,8 @@ unsigned IntType::getStorageTypeWidth(const mlir::DataLayout &dataLayout) const { if (!isBitInt()) return getWidth(); - uint64_t alignBits = getABIAlignment(dataLayout, {}) * 8; + // The cap lives in the data-layout spec, which getTypeABIAlignment reads. + uint64_t alignBits = dataLayout.getTypeABIAlignment(*this) * 8; return static_cast<unsigned>(llvm::alignTo(getWidth(), alignBits)); } @@ -1103,10 +1120,14 @@ uint64_t IntType::getABIAlignment(const mlir::DataLayout &dataLayout, mlir::DataLayoutEntryListRef params) const { unsigned width = getWidth(); if (isBitInt()) { - // _BitInt alignment: min(PowerOf2Ceil(width), 64 bits) in bytes. - // Matches Clang's TargetInfo::getBitIntAlign with default max = 64. + // TargetInfo::getBitIntAlign clamps the power-of-two width to + // getBitIntMaxAlign() and to at least the char width. The cap is the + // #cir.bitint_spec data-layout entry, in bits. The char width is 8 + // bits, so the alignment is at least one byte. + uint64_t maxAlignBits = getBitIntMaxAlignBits(params); uint64_t alignBits = - std::min(llvm::PowerOf2Ceil(width), static_cast<uint64_t>(64)); + std::min(static_cast<uint64_t>(llvm::PowerOf2Ceil(width)), + maxAlignBits); return std::max(alignBits / 8, static_cast<uint64_t>(1)); } // Round up to a power-of-two byte alignment. DataLayout consumers such as @@ -1118,6 +1139,42 @@ uint64_t IntType::getABIAlignment(const mlir::DataLayout &dataLayout, return std::max(alignBits / 8, static_cast<uint64_t>(1)); } +bool IntType::areCompatible( + mlir::DataLayoutEntryListRef oldLayout, + mlir::DataLayoutEntryListRef newLayout, mlir::DataLayoutSpecInterface, + const mlir::DataLayoutIdentifiedEntryMap &) const { + // A nested spec may only repeat the same _BitInt max alignment. + uint64_t oldMax = getBitIntMaxAlignBits(oldLayout); + for (mlir::DataLayoutEntryInterface newEntry : newLayout) { + if (!newEntry.isTypeEntry()) + continue; + auto newSpec = mlir::dyn_cast<cir::BitIntSpecAttr>(newEntry.getValue()); + if (newSpec && newSpec.getMaxAlign() != oldMax) + return false; + } + return true; +} + +llvm::LogicalResult +IntType::verifyEntries(mlir::DataLayoutEntryListRef entries, + mlir::Location loc) const { + cir::IntType keyTy = getBitIntMaxAlignKey(getContext()); + for (mlir::DataLayoutEntryInterface entry : entries) { + if (!entry.isTypeEntry()) + continue; + auto key = mlir::cast<IntType>(mlir::cast<mlir::Type>(entry.getKey())); + if (key != keyTy) + return mlir::emitError(loc) + << "expected _BitInt data layout entry to be keyed on " << keyTy + << ", got " << key; + if (!mlir::isa<cir::BitIntSpecAttr>(entry.getValue())) + return mlir::emitError(loc) + << "expected layout attribute for " << key + << " to be a #cir.bitint_spec attribute"; + } + return mlir::success(); +} + mlir::LogicalResult IntType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError, unsigned width, bool isSigned, bool isBitInt) { diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 8cd0ec6b00eaa7..5292aa93a7e0a6 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -104,7 +104,7 @@ static uint64_t getMemoryFallbackAlignment(mlir::Type cirType, const mlir::DataLayout &dataLayout) { if (auto intTy = mlir::dyn_cast<cir::IntType>(cirType); intTy && intTy.isBitInt()) - return intTy.getABIAlignment(dataLayout, {}); + return dataLayout.getTypeABIAlignment(intTy); return dataLayout.getTypeABIAlignment(llvmMemType); } @@ -5114,15 +5114,18 @@ void ConvertCIRToLLVMPass::runOnOperation() { return; } - // Drop the cir.ptr-keyed data-layout entries: they drove pointer-width - // queries up to this point, but the LLVM IR exporter rejects CIR types. + // Drop CIR-native data-layout entries. They drove pointer-width and + // _BitInt alignment queries up to this point, but the LLVM IR exporter + // rejects CIR types. if (auto dlSpec = mlir::dyn_cast_or_null<mlir::DataLayoutSpecAttr>( module->getAttr(mlir::DLTIDialect::kDataLayoutAttrName))) { llvm::SmallVector<mlir::DataLayoutEntryInterface> kept; for (mlir::DataLayoutEntryInterface entry : dlSpec.getEntries()) { - if (entry.isTypeEntry() && - mlir::isa<cir::PointerType>(mlir::cast<mlir::Type>(entry.getKey()))) - continue; + if (entry.isTypeEntry()) { + mlir::Type key = mlir::cast<mlir::Type>(entry.getKey()); + if (mlir::isa<cir::PointerType, cir::IntType>(key)) + continue; + } kept.push_back(entry); } module->setAttr(mlir::DLTIDialect::kDataLayoutAttrName, diff --git a/clang/test/CIR/CodeGen/bitint-max-align.c b/clang/test/CIR/CodeGen/bitint-max-align.c new file mode 100644 index 00000000000000..e2a72d3f910010 --- /dev/null +++ b/clang/test/CIR/CodeGen/bitint-max-align.c @@ -0,0 +1,58 @@ +// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -fexperimental-max-bitint-width=256 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --check-prefix=A64-CIR --input-file=%t.cir %s +// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -fexperimental-max-bitint-width=256 -fclangir -emit-llvm %s -o %t-cir.ll +// RUN: FileCheck --check-prefixes=A64-LLVM,A64-LLVMCIR --input-file=%t-cir.ll %s +// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -fexperimental-max-bitint-width=256 -emit-llvm %s -o %t.ll +// RUN: FileCheck --check-prefixes=A64-LLVM,A64-OGCG --input-file=%t.ll %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fexperimental-max-bitint-width=256 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --check-prefix=X64-CIR --input-file=%t.cir %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fexperimental-max-bitint-width=256 -fclangir -emit-llvm %s -o %t-cir.ll +// RUN: FileCheck --check-prefix=X64-LLVM --input-file=%t-cir.ll %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fexperimental-max-bitint-width=256 -emit-llvm %s -o %t.ll +// RUN: FileCheck --check-prefix=X64-LLVM --input-file=%t.ll %s + +// The _BitInt alignment cap is TargetInfo::getBitIntMaxAlign(). AArch64 sets +// it to 128 bits, so a _BitInt wider than 64 bits is 16-byte aligned and +// _BitInt(129) is stored as i256. x86_64 leaves the cap at LongLongAlign +// (64 bits), so the same values are 8-byte aligned and _BitInt(129) is 24 +// bytes. + +signed _BitInt(65) g65 = 1; +signed _BitInt(128) g128 = 1; +signed _BitInt(129) g129 = -1; + +// A64-CIR-DAG: !cir.int<u, 1, bitint> = #cir.bitint_spec<max_align = 128> +// A64-CIR-DAG: cir.global external @g65 = #cir.int<1> : !cir.int<s, 65, bitint> align(16) +// A64-CIR-DAG: cir.global external @g128 = #cir.int<1> : !s128i_bitint align(16) +// A64-CIR-DAG: cir.global external @g129 = #cir.int<-1> : !cir.int<s, 129, bitint> align(16) +// A64-LLVM-DAG: @g65 = global i128 1, align 16 +// A64-LLVM-DAG: @g128 = global i128 1, align 16 +// A64-LLVM-DAG: @g129 = global i256 -1, align 16 + +// X64-CIR-DAG: !cir.int<u, 1, bitint> = #cir.bitint_spec<max_align = 64> +// X64-CIR-DAG: cir.global external @g65 = #cir.int<1> : !cir.int<s, 65, bitint> align(8) +// X64-CIR-DAG: cir.global external @g128 = #cir.int<1> : !s128i_bitint align(8) +// X64-CIR-DAG: cir.global external @g129 = #cir.int<-1> : !cir.int<s, 129, bitint> align(8) +// X64-LLVM-DAG: @g65 = global i128 1, align 8 +// X64-LLVM-DAG: @g128 = global i128 1, align 8 +// X64-LLVM-DAG: @g129 = global [24 x i8] c"\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF", align 8 + +struct Has129 { + int i; + signed _BitInt(129) bi; +}; +struct Has129 g_struct = {7, -1}; + +// AArch64: the i256 member is 16-byte aligned. CIR leaves the 12-byte gap +// to LLVM struct layout. Classic codegen writes the padding as an array. +// A64-CIR-DAG: !rec_Has129 = !cir.struct<"Has129" {data !s32i, data !cir.int<s, 129, bitint>}> +// A64-CIR-DAG: cir.global external @g_struct = #cir.const_record<{#cir.int<7> : !s32i, #cir.int<-1> : !cir.int<s, 129, bitint>}> : !rec_Has129 align(16) +// A64-LLVMCIR-DAG: @g_struct = global %struct.Has129 { i32 7, i256 -1 }, align 16 +// A64-OGCG-DAG: @g_struct = global { i32, [12 x i8], i256 } { i32 7, [12 x i8] zeroinitializer, i256 -1 }, align 16 + +// x86_64: 4 bytes of padding bring the 24-byte _BitInt to its 8-byte +// alignment. CIR packs the struct. Classic codegen does not. +// X64-CIR-DAG: !rec_Has129 = !cir.struct<"Has129" packed {data !s32i, pad !cir.array<!u8i x 4>, data !cir.int<s, 129, bitint>}> +// X64-CIR-DAG: cir.global external @g_struct = #cir.const_record<{#cir.int<7> : !s32i, #cir.zero : !cir.array<!u8i x 4>, #cir.int<-1> : !cir.int<s, 129, bitint>}> : !rec_Has129 align(8) +// X64-LLVM-DAG: %struct.Has129 = type {{[<]?}}{ i32, [4 x i8], [24 x i8] }{{[>]?}} +// X64-LLVM-DAG: @g_struct = global %struct.Has129 {{[<]?}}{ i32 7, [4 x i8] zeroinitializer, [24 x i8] c"\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF" }{{[>]?}}, align 8 diff --git a/clang/test/CIR/CodeGen/dlti.c b/clang/test/CIR/CodeGen/dlti.c index 3fa15d2ab584f9..219e02bfa29bf2 100644 --- a/clang/test/CIR/CodeGen/dlti.c +++ b/clang/test/CIR/CodeGen/dlti.c @@ -21,3 +21,4 @@ void foo() {} // LITTLE-DAG: f64 = dense<64> : vector<2xi64>, // LITTLE-DAG: "dlti.stack_alignment" = 128 : i64 // LITTLE-DAG: "dlti.endianness" = "little" +// LITTLE-DAG: !cir.int<u, 1, bitint> = #cir.bitint_spec<max_align = 64> diff --git a/clang/test/CIR/IR/bitint-data-layout.cir b/clang/test/CIR/IR/bitint-data-layout.cir new file mode 100644 index 00000000000000..05a6c222785c12 --- /dev/null +++ b/clang/test/CIR/IR/bitint-data-layout.cir @@ -0,0 +1,36 @@ +// RUN: cir-opt %s -verify-diagnostics -split-input-file + +// A well-formed #cir.bitint_spec entry round-trips without diagnostics. +module attributes {dlti.dl_spec = #dlti.dl_spec< + !cir.int<u, 1, bitint> = #cir.bitint_spec<max_align = 128>>} { +} + +// ----- + +// The entry value must be a #cir.bitint_spec attribute. +// expected-error @below {{expected layout attribute for '!cir.int<u, 1, bitint>' to be a #cir.bitint_spec attribute}} +module attributes {dlti.dl_spec = #dlti.dl_spec< + !cir.int<u, 1, bitint> = 64 : i64>} { +} + +// ----- + +// The entry is keyed on the _BitInt class, not on one width. +// expected-error @below {{expected _BitInt data layout entry to be keyed on '!cir.int<u, 1, bitint>', got '!cir.int<s, 128, bitint>'}} +module attributes {dlti.dl_spec = #dlti.dl_spec< + !cir.int<s, 128, bitint> = #cir.bitint_spec<max_align = 64>>} { +} + +// ----- + +// expected-error @+2 {{max_align must be a power of two of at least ... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/241466 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
