[clang] [CIR] Record how far a bit-field's declared types reach on x86_64 (PR #220069)
Adam Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 2 05:46:36 PDT 2026
https://github.com/adams381 updated https://github.com/llvm/llvm-project/pull/220069
>From 3d9891fa0d5f36f0fb052ac2391b3474616f2325 Mon Sep 17 00:00:00 2001
From: Adam Smith <adams at nvidia.com>
Date: Mon, 31 Aug 2026 12:27:03 -0700
Subject: [PATCH 1/2] [CIR] Record how far a bit-field's declared types reach
on x86_64
A bit-field access unit is as wide as the compiler chooses, which can be
narrower than the types declared in it. The x86_64 ABI reads how far those
declarations reach to tell the bytes after a unit from padding, and CIR had no
way to record it, so the bridge refused any padded record holding a named unit.
CIRGen now records that reach as a zero-length member beside the unit, the
shape a zero-width bit-field uses. With the fact in the type, the bridge
drops the reject. It also stops refusing unions like `union { int x : 3; }`,
where no member on its own is as wide as the union.
Assisted-by: Cursor / claude-opus-5
---
.../include/clang/CIR/Dialect/IR/CIRTypes.td | 6 +-
.../CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp | 63 ++++-
clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 32 ++-
.../Transforms/CallConvLoweringPass.cpp | 133 +++++-----
.../CIR/CodeGen/aapcs-volatile-bitfields.c | 12 +-
.../test/CIR/CodeGen/anonymous-nested-init.c | 11 +-
clang/test/CIR/CodeGen/bitfield-init-values.c | 52 ++--
clang/test/CIR/CodeGen/bitfields.c | 28 +-
clang/test/CIR/CodeGen/bitfields.cpp | 14 +-
clang/test/CIR/CodeGen/bitfields_be.c | 4 +-
...ll-conv-lowering-x86_64-bitfield-reach.cpp | 250 ++++++++++++++++++
.../call-conv-lowering-x86_64-packed.c | 10 +-
clang/test/CIR/CodeGen/constant-inits.cpp | 40 +--
clang/test/CIR/CodeGen/dumb-record.cpp | 4 +-
.../CIR/CodeGen/finegrain-bitfield-access.cpp | 28 +-
.../test/CIR/CodeGen/paren-list-agg-init.cpp | 19 +-
clang/test/CIR/CodeGen/record-member-kinds.c | 12 +-
.../test/CIR/CodeGen/record-member-kinds.cpp | 28 +-
.../CIR/CodeGen/record-zero-init-padding.c | 6 +-
clang/test/CIR/CodeGen/struct-init.cpp | 8 +-
clang/test/CIR/CodeGen/union-agg-init.c | 5 +-
.../abi-lowering/x86_64-aggregate-nyi.cir | 51 ----
.../abi-lowering/x86_64-bitfield-reach.cir | 80 ++++++
23 files changed, 624 insertions(+), 272 deletions(-)
create mode 100644 clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-reach.cpp
create mode 100644 clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-reach.cir
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index 26c0f7689d97b..58e1e2e72aeb5 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -959,8 +959,10 @@ def CIR_UnionType : CIR_Type<"Union", "union", [
/// the storage type when lowering to LLVM IR). Returns a null type for
/// empty unions.
mlir::Type getUnionStorageType(const mlir::DataLayout &dataLayout) const;
- static mlir::Type getUnionStorageType(const mlir::DataLayout &dataLayout,
- llvm::ArrayRef<mlir::Type> members);
+ static mlir::Type getUnionStorageType(
+ const mlir::DataLayout &dataLayout,
+ llvm::ArrayRef<mlir::Type> members,
+ llvm::ArrayRef<RecordMemberKind> kinds);
void complete(llvm::ArrayRef<mlir::Type> members, bool packed,
mlir::Type padding,
diff --git a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
index 7451bf6fbd4aa..d98e23700a00e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
@@ -79,6 +79,24 @@ struct CIRRecordLowering final {
cir::ArrayType::get(cirGenTypes.convertTypeForMem(field->getType()), 0),
cir::RecordMemberKind::BitField);
}
+
+ /// A member recording that declared types reach \p excessInBits past where
+ /// it sits. An access unit's width is the compiler's choice, so it can be
+ /// narrower than the types declared in it, and the ABI reads that reach to
+ /// tell the bytes after the unit from padding. A zero-length array holds
+ /// no storage, and `isZeroWidthBitField` answers true for it as well as for
+ /// a zero-width bit-field, so the layout walks pass over both.
+ ///
+ /// The bits counted are those past the member, not past the unit: a
+ /// zero-sized member reports the offset where the storage ahead of it ends,
+ /// so a caller measuring from anywhere else claims bytes twice.
+ MemberInfo makeDeclaredReachInfo(CharUnits offset, uint64_t excessInBits) {
+ unsigned charBits = astContext.getCharWidth();
+ CharUnits excess = bitsToCharUnits(excessInBits + charBits - 1);
+ return makeStorageInfo(offset,
+ cir::ArrayType::get(getByteArrayType(excess), 0),
+ cir::RecordMemberKind::BitField);
+ }
// The constructor.
CIRRecordLowering(CIRGenTypes &cirGenTypes, const RecordDecl *recordDecl,
bool packed);
@@ -644,14 +662,30 @@ CIRRecordLowering::accumulateBitFields(RecordDecl::field_iterator field,
const size_t storageIdx = members.size();
members.push_back(
makeStorageInfo(beginOffset, type, cir::RecordMemberKind::Empty));
+ uint64_t declaredEndBits = 0;
for (; begin != bestEnd; ++begin) {
if (!begin->isUnnamedBitField())
members[storageIdx].memberKind = cir::RecordMemberKind::BitField;
+ // An unnamed bit-field supplies no eightbyte class, but the bytes
+ // its declared type covers still hold user data, so every bit-field
+ // in the unit counts toward the reach.
+ declaredEndBits = std::max(
+ declaredEndBits, getFieldBitOffset(*begin) +
+ astContext.getTypeSize(begin->getType()));
if (!begin->isZeroLengthBitField())
members.push_back(MemberInfo(beginOffset,
MemberInfo::InfoKind::Field, nullptr,
cir::RecordMemberKind::Data, *begin));
}
+ // Only the furthest declaration matters, so one member covers the
+ // unit. Emit it only when that declaration outruns the unit's own
+ // width, since otherwise the unit already claims those bytes. The
+ // member sits at the unit's end, so it records the excess from there.
+ uint64_t unitEndBits =
+ astContext.toBits(beginOffset) + astContext.toBits(accessSize);
+ if (declaredEndBits > unitEndBits)
+ members.push_back(makeDeclaredReachInfo(
+ beginOffset + accessSize, declaredEndBits - unitEndBits));
}
// Reset to start a new span.
field = bestEnd;
@@ -990,6 +1024,8 @@ void CIRRecordLowering::lowerUnion(bool nonVirtualBaseType) {
// storage type and padding is.
// First, accumulate all the types.
+ uint64_t declaredReachBits = 0;
+ uint64_t widestMemberBits = 0;
for (const FieldDecl *field : recordDecl->fields()) {
mlir::Type fieldType;
if (field->isBitField()) {
@@ -997,14 +1033,24 @@ void CIRRecordLowering::lowerUnion(bool nonVirtualBaseType) {
continue;
fieldType = getBitfieldStorageType(field->getBitWidthValue());
setBitFieldInfo(field, CharUnits::Zero(), fieldType);
+ declaredReachBits =
+ std::max(declaredReachBits, astContext.getTypeSize(field->getType()));
} else {
fieldType = getStorageType(field);
}
+ widestMemberBits = std::max<uint64_t>(
+ widestMemberBits, dataLayout.layout.getTypeSizeInBits(fieldType));
fieldIdxMap[field->getCanonicalDecl()] = 0;
addField(fieldType, getFieldMemberKind(field));
}
+ // A union's members all start at offset zero, so one member holding the
+ // furthest declared reach speaks for the whole union. Record it only when
+ // it says something no member already does, which is when a bit-field's
+ // declared type outruns every member's storage.
+ bool reachOutrunsMembers = declaredReachBits > widestMemberBits;
+
// Compute zero-initializable status.
// This union might not be zero initialized: it may contain a pointer to
// data member which might have some exotic initialization sequence.
@@ -1034,14 +1080,25 @@ void CIRRecordLowering::lowerUnion(bool nonVirtualBaseType) {
return;
}
- mlir::Type storageType =
- cir::UnionType::getUnionStorageType(dataLayout.layout, getFieldTypes());
+ mlir::Type storageType = cir::UnionType::getUnionStorageType(
+ dataLayout.layout, getFieldTypes(), getFieldKinds());
// If our storage size was bigger than our required size (can happen in the
// case of packed bitfields on Itanium) then just use an I8 array.
if (layoutSize < getSize(storageType))
storageType = getByteArrayType(layoutSize);
+ // The member records only the bits past where it sits, and what precedes it
+ // differs by layout: the base subobject below is built as a struct, so the
+ // storage type comes first, while in a union proper every member is at zero.
+ auto addDeclaredReach = [&](uint64_t claimedBits) {
+ if (!reachOutrunsMembers || declaredReachBits <= claimedBits)
+ return;
+ MemberInfo reach = makeDeclaredReachInfo(bitsToCharUnits(claimedBits),
+ declaredReachBits - claimedBits);
+ addField(reach.data, reach.memberKind);
+ };
+
// The base-subobject record is built as a struct from fieldTypes, so add
// the storage type and any trailing padding as ordinary fields rather than
// routing padding through the union's single tail-padding slot.
@@ -1058,10 +1115,12 @@ void CIRRecordLowering::lowerUnion(bool nonVirtualBaseType) {
cir::isBitFieldAccessUnit));
clearFields();
addField(storageType, storageKind);
+ addDeclaredReach(astContext.toBits(getSize(storageType)));
CharUnits padding = layoutSize - getSize(storageType);
if (!padding.isZero())
addField(getByteArrayType(padding), cir::RecordMemberKind::Pad);
} else {
+ addDeclaredReach(/*claimedBits=*/0);
// Else we just add padding normally.
appendPaddingBytes(layoutSize - getSize(storageType));
}
diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index 897063171e76a..2d75d855c3cee 100644
--- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
@@ -572,21 +572,27 @@ void UnionType::complete(ArrayRef<Type> members, bool packed,
mlir::Type
UnionType::getUnionStorageType(const mlir::DataLayout &dataLayout) const {
- return getUnionStorageType(dataLayout, getMembers());
+ return getUnionStorageType(dataLayout, getMembers(), getMemberKinds());
}
-mlir::Type UnionType::getUnionStorageType(const mlir::DataLayout &dataLayout,
- llvm::ArrayRef<mlir::Type> members) {
- if (members.empty())
- return {};
- return *std::max_element(
- members.begin(), members.end(), [&](mlir::Type lhs, mlir::Type rhs) {
- return dataLayout.getTypeABIAlignment(lhs) <
- dataLayout.getTypeABIAlignment(rhs) ||
- (dataLayout.getTypeABIAlignment(lhs) ==
- dataLayout.getTypeABIAlignment(rhs) &&
- dataLayout.getTypeSize(lhs) < dataLayout.getTypeSize(rhs));
- });
+mlir::Type
+UnionType::getUnionStorageType(const mlir::DataLayout &dataLayout,
+ llvm::ArrayRef<mlir::Type> members,
+ llvm::ArrayRef<RecordMemberKind> kinds) {
+ // A member occupying no storage cannot be the storage.
+ mlir::Type storage;
+ for (auto [memberTy, kind] : llvm::zip_equal(members, kinds)) {
+ if (isZeroWidthBitField(memberTy, kind))
+ continue;
+ if (!storage ||
+ dataLayout.getTypeABIAlignment(storage) <
+ dataLayout.getTypeABIAlignment(memberTy) ||
+ (dataLayout.getTypeABIAlignment(storage) ==
+ dataLayout.getTypeABIAlignment(memberTy) &&
+ dataLayout.getTypeSize(storage) < dataLayout.getTypeSize(memberTy)))
+ storage = memberTy;
+ }
+ return storage;
}
bool UnionType::isLayoutIdentical(const UnionType &other) {
diff --git a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
index dbcf19da5c826..4f33004c8e4f8 100644
--- a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
@@ -76,12 +76,12 @@ namespace {
// Integer (including `_BitInt` up to 128 bits) / pointer / vtable pointer /
// bool / floating-point scalars are handled, as are struct / union / array
// aggregates, `_Complex`, and a fixed-width vector whose width is a power
-// of two. Other vectors, a padded record reached through a named bit-field
-// access unit, a record holding an empty-for-ABI member that occupies bytes
-// or a zero-sized one off its own alignment, a union no member of which spans
-// its declared size, and a union with a bit-field access unit no spanning
-// member of which supplies data are reported NYI by classifyX86_64Function
-// so an unsupported signature fails the pass instead of being misclassified.
+// of two. Other vectors, a record holding an empty-for-ABI member that
+// occupies bytes or a zero-sized one off its own alignment, a union no member
+// of which spans its declared size, and a union with a bit-field access unit
+// no spanning member of which supplies data or records a declared reach are
+// reported NYI by classifyX86_64Function so an unsupported signature fails
+// the pass instead of being misclassified.
//===----------------------------------------------------------------------===//
/// Whether a struct's declared argument-passing kind (from the module's
@@ -118,24 +118,6 @@ static llvm::Align recordDeclaredAlign(ModuleOp modOp, cir::RecordType recTy,
return llvm::Align(layout.getRecordAlign());
}
-/// Whether \p ty reaches a bit-field access unit holding a named bit-field,
-/// looking through member records and array element types.
-static bool reachesNamedBitFieldUnit(mlir::Type ty) {
- if (auto arrTy = dyn_cast<cir::ArrayType>(ty))
- return reachesNamedBitFieldUnit(arrTy.getElementType());
- auto recTy = dyn_cast<cir::RecordType>(ty);
- if (!recTy)
- return false;
- // A zero-length array under the bit-field mark is a zero-width bit-field, not
- // an access unit, and it carries its declared type rather than a unit width.
- for (auto [memberTy, kind] :
- llvm::zip_equal(recTy.getMembers(), recTy.getMemberKinds()))
- if (cir::isBitFieldAccessUnit(kind) &&
- !cir::isZeroWidthBitField(memberTy, kind))
- return true;
- return llvm::any_of(recTy.getMembers(), reachesNamedBitFieldUnit);
-}
-
/// Whether \p ty, or an aggregate member/element reached by value (never
/// through a pointer), is an incomplete record. Such a record has no known
/// layout, so no eightbyte classification can be built for it.
@@ -241,31 +223,39 @@ static bool isSupportedType(mlir::Type ty, const DataLayout &dl) {
if (recordBits > 128)
return false;
} else {
- auto spansRecord = [&](mlir::Type m) {
- return dl.getTypeSizeInBits(m).getFixedValue() == recordBits;
+ // A member recording a bit-field's declared reach occupies no storage
+ // of its own, so its element type is what covers the union's bytes.
+ // That reach can outrun the union, which a real member never does,
+ // hence the comparison is not an equality.
+ llvm::ArrayRef<cir::RecordMemberKind> kinds = recTy.getMemberKinds();
+ auto spansRecord = [&](mlir::Type m, cir::RecordMemberKind k) {
+ if (cir::isZeroWidthBitField(m, k))
+ m = cast<cir::ArrayType>(m).getElementType();
+ return dl.getTypeSizeInBits(m).getFixedValue() >= recordBits;
};
- if (!llvm::any_of(members, spansRecord))
+ if (!llvm::any_of(llvm::zip_equal(members, kinds),
+ [&](const auto &pair) {
+ auto [memberTy, kind] = pair;
+ return spansRecord(memberTy, kind);
+ }))
return false;
// A bit-field access unit's width may not match the bits it actually
- // stores, so some member (the unit itself or another one) must both
- // match the union's size and hold data.
- llvm::ArrayRef<cir::RecordMemberKind> kinds = recTy.getMemberKinds();
+ // stores, so some member (the unit itself or another one) must match
+ // the union's size and either hold data or record how far the
+ // declared types in it reach.
if (llvm::any_of(kinds, cir::isBitFieldAccessUnit) &&
!llvm::any_of(llvm::zip_equal(members, kinds),
[&](const auto &pair) {
auto [memberTy, kind] = pair;
- return spansRecord(memberTy) &&
- cir::holdsDataForABI(memberTy, kind) &&
+ if (!spansRecord(memberTy, kind))
+ return false;
+ if (cir::isZeroWidthBitField(memberTy, kind))
+ return true;
+ return cir::holdsDataForABI(memberTy, kind) &&
!memberIsEmptyRecord(memberTy);
}))
return false;
}
- } else if (recTy.getPadded() && reachesNamedBitFieldUnit(recTy)) {
- // A named access unit can be narrower than the type its bit-fields were
- // declared with, and that declared type is what classic CodeGen coerces
- // from. CIR does not record it, so classifying here would coerce to the
- // unit's width instead.
- return false;
}
// An `empty` member that occupies bytes is later read as an unnamed access
// unit. One that is itself an empty-for-ABI record can occupy bytes by
@@ -412,34 +402,14 @@ static const llvm::abi::Type *mapCIRType(mlir::Type type,
SmallVector<llvm::abi::FieldInfo> fields;
fields.reserve(recTy.getMembers().size());
- // The size passed here spans the tail padding, so an eightbyte covers
- // the whole union rather than just the member the classifier reduces
- // it to.
- if (recTy.isUnion()) {
- // Classify only the members that hold data for the ABI. A member
- // that holds none, such as an unnamed bit-field's storage, is
- // skipped so it does not appear as a spurious argument.
- for (auto [fieldTy, kind] :
- llvm::zip_equal(recTy.getMembers(), recTy.getMemberKinds()))
- if (cir::holdsDataForABI(fieldTy, kind))
- fields.push_back(llvm::abi::FieldInfo(
- mapCIRType(fieldTy, typeMapper, dl, modOp)));
- return tb.getUnionType(fields, sizeBits, align,
- llvm::abi::StructPacking::Default, flags);
- }
-
- // Padding is dropped, so the eightbyte rules see its bytes as holding
- // nothing, while the record's full size set above still spans them. An
- // unnamed bit-field access unit is flagged rather than dropped, since
- // classic CodeGen ignores it when assigning eightbyte classes but
- // counts it when choosing the coerce type, and a member's presence
- // alone cannot say both.
- for (auto [idx, fieldTy, kind] :
- llvm::enumerate(recTy.getMembers(), recTy.getMemberKinds())) {
- if (kind == cir::RecordMemberKind::Pad)
- continue;
- // A zero-width bit-field occupies nothing, so its declared type is
- // what the ABI counts, and that is the element type it carries.
+ // An unnamed bit-field access unit is flagged rather than dropped: the
+ // classifier passes a flagged member over when assigning eightbyte
+ // classes and still counts its bytes when choosing the coerce type,
+ // and a member's presence alone cannot say both.
+ auto addMember = [&](mlir::Type fieldTy, cir::RecordMemberKind kind,
+ uint64_t offsetBits) {
+ // A zero-width bit-field and a declared reach occupy nothing, so
+ // what the ABI counts is the element type they carry.
mlir::Type countedTy = fieldTy;
bool isUnnamedUnit = kind == cir::RecordMemberKind::Empty;
if (cir::isZeroWidthBitField(fieldTy, kind)) {
@@ -448,7 +418,7 @@ static const llvm::abi::Type *mapCIRType(mlir::Type type,
}
uint64_t widthBits = dl.getTypeSizeInBits(countedTy).getFixedValue();
if (isUnnamedUnit && widthBits == 0)
- continue;
+ return;
assert((!isUnnamedUnit || !memberIsEmptyRecord(countedTy)) &&
"an empty-for-ABI member must not reach the classifier as an "
"unnamed bit-field");
@@ -458,10 +428,35 @@ static const llvm::abi::Type *mapCIRType(mlir::Type type,
// a bit-field, which may sit at any offset.
bool isAccessUnit = isUnnamedUnit || cir::isBitFieldAccessUnit(kind);
fields.push_back(llvm::abi::FieldInfo(
- mapCIRType(countedTy, typeMapper, dl, modOp),
- recTy.getElementOffset(dl, idx) * 8,
+ mapCIRType(countedTy, typeMapper, dl, modOp), offsetBits,
/*IsBitField=*/isAccessUnit, isAccessUnit ? widthBits : 0,
/*IsUnnamedBitField=*/isUnnamedUnit));
+ };
+
+ // The size passed here spans the tail padding, so an eightbyte covers
+ // the whole union rather than just the member the classifier reduces
+ // it to.
+ if (recTy.isUnion()) {
+ // Classify only the members that hold data for the ABI, plus one
+ // recording a declared reach. A member that does neither, such as
+ // an unnamed bit-field's storage, is skipped so it does not appear
+ // as a spurious argument. A union's members all sit at offset zero.
+ for (auto [fieldTy, kind] :
+ llvm::zip_equal(recTy.getMembers(), recTy.getMemberKinds()))
+ if (cir::holdsDataForABI(fieldTy, kind) ||
+ cir::isZeroWidthBitField(fieldTy, kind))
+ addMember(fieldTy, kind, /*offsetBits=*/0);
+ return tb.getUnionType(fields, sizeBits, align,
+ llvm::abi::StructPacking::Default, flags);
+ }
+
+ // Padding is dropped, so the eightbyte rules see its bytes as holding
+ // nothing, while the record's full size set above still spans them.
+ for (auto [idx, fieldTy, kind] :
+ llvm::enumerate(recTy.getMembers(), recTy.getMemberKinds())) {
+ if (kind == cir::RecordMemberKind::Pad)
+ continue;
+ addMember(fieldTy, kind, recTy.getElementOffset(dl, idx) * 8);
}
return tb.getRecordType(
diff --git a/clang/test/CIR/CodeGen/aapcs-volatile-bitfields.c b/clang/test/CIR/CodeGen/aapcs-volatile-bitfields.c
index b9fc29d0f3087..2ce7a1f83bdff 100644
--- a/clang/test/CIR/CodeGen/aapcs-volatile-bitfields.c
+++ b/clang/test/CIR/CodeGen/aapcs-volatile-bitfields.c
@@ -118,7 +118,7 @@ int check_load_exception(st3 *s3) {
// CIR: cir.func {{.*}} @check_load_exception
// CIR: [[LOAD:%.*]] = cir.load align(8) {{.*}} : !cir.ptr<!cir.ptr<!rec_st3>>, !cir.ptr<!rec_st3>
-// CIR: [[MEMBER:%.*]] = cir.get_member [[LOAD]][3] {name = "b"} : !cir.ptr<!rec_st3> -> !cir.ptr<!u8i>
+// CIR: [[MEMBER:%.*]] = cir.get_member [[LOAD]][4] {name = "b"} : !cir.ptr<!rec_st3> -> !cir.ptr<!u8i>
// CIR: [[BITFI:%.*]] = cir.get_bitfield align(4) (#bfi_b1, [[MEMBER]] {is_volatile} : !cir.ptr<!u8i>) -> !u32i
// CIR: [[CAST:%.*]] = cir.cast integral [[BITFI]] : !u32i -> !s32i
// CIR: cir.store [[CAST]], [[RETVAL:%.*]] : !s32i, !cir.ptr<!s32i>
@@ -127,7 +127,7 @@ int check_load_exception(st3 *s3) {
// LLVM:define dso_local i32 @check_load_exception
// LLVM: [[LOAD:%.*]] = load ptr, ptr {{.*}}, align 8
-// LLVM: [[MEMBER:%.*]] = getelementptr inbounds nuw %struct.st3, ptr [[LOAD]], i32 0, i32 3
+// LLVM: [[MEMBER:%.*]] = getelementptr inbounds nuw %struct.st3, ptr [[LOAD]], i32 0, i32 4
// LLVM: [[LOADVOL:%.*]] = load volatile i8, ptr [[MEMBER]], align 4
// LLVM: [[CLEAR:%.*]] = and i8 [[LOADVOL]], 31
// LLVM: [[CAST:%.*]] = zext i8 [[CLEAR]] to i32
@@ -213,13 +213,13 @@ void check_store_exception(st3 *s3) {
// CIR: cir.func {{.*}} @check_store_exception
// CIR: [[CONST:%.*]] = cir.const #cir.int<2> : !u32i
// CIR: [[LOAD:%.*]] = cir.load align(8) {{.*}} : !cir.ptr<!cir.ptr<!rec_st3>>, !cir.ptr<!rec_st3>
-// CIR: [[MEMBER:%.*]] = cir.get_member [[LOAD]][3] {name = "b"} : !cir.ptr<!rec_st3> -> !cir.ptr<!u8i>
+// CIR: [[MEMBER:%.*]] = cir.get_member [[LOAD]][4] {name = "b"} : !cir.ptr<!rec_st3> -> !cir.ptr<!u8i>
// CIR: [[SETBF:%.*]] = cir.set_bitfield align(4) (#bfi_b1, [[MEMBER]] : !cir.ptr<!u8i>, [[CONST]] : !u32i) {is_volatile} -> !u32i
// CIR: cir.return
// LLVM:define dso_local void @check_store_exception
// LLVM: [[LOAD:%.*]] = load ptr, ptr {{.*}}, align 8
-// LLVM: [[MEMBER:%.*]] = getelementptr inbounds nuw %struct.st3, ptr [[LOAD]], i32 0, i32 3
+// LLVM: [[MEMBER:%.*]] = getelementptr inbounds nuw %struct.st3, ptr [[LOAD]], i32 0, i32 4
// LLVM: [[LOADVOL:%.*]] = load volatile i8, ptr [[MEMBER]], align 4
// LLVM: [[CLEAR:%.*]] = and i8 [[LOADVOL]], -32
// LLVM: [[SET:%.*]] = or i8 [[CLEAR]], 2
@@ -264,12 +264,12 @@ void check_store_second_member (st4 *s4) {
// CIR: cir.func {{.*}} @check_store_second_member
// CIR: [[ONE:%.*]] = cir.const #cir.int<1> : !u64i
// CIR: [[LOAD:%.*]] = cir.load align(8) {{.*}} : !cir.ptr<!cir.ptr<!rec_st4>>, !cir.ptr<!rec_st4>
-// CIR: [[MEMBER:%.*]] = cir.get_member [[LOAD]][2] {name = "b"} : !cir.ptr<!rec_st4> -> !cir.ptr<!u16i>
+// CIR: [[MEMBER:%.*]] = cir.get_member [[LOAD]][3] {name = "b"} : !cir.ptr<!rec_st4> -> !cir.ptr<!u16i>
// CIR: cir.set_bitfield align(8) (#bfi_b2, [[MEMBER]] : !cir.ptr<!u16i>, [[ONE]] : !u64i) {is_volatile} -> !u64i
// LLVM: define dso_local void @check_store_second_member
// LLVM: [[LOAD:%.*]] = load ptr, ptr {{.*}}, align 8
-// LLVM: [[MEMBER:%.*]] = getelementptr inbounds nuw %struct.st4, ptr [[LOAD]], i32 0, i32 2
+// LLVM: [[MEMBER:%.*]] = getelementptr inbounds nuw %struct.st4, ptr [[LOAD]], i32 0, i32 3
// LLVM: [[VAL:%.*]] = load volatile i64, ptr [[MEMBER]], align 8
// LLVM: [[CLEAR:%.*]] = and i64 [[VAL]], -65536
// LLVM: [[SET:%.*]] = or i64 [[CLEAR]], 1
diff --git a/clang/test/CIR/CodeGen/anonymous-nested-init.c b/clang/test/CIR/CodeGen/anonymous-nested-init.c
index fa88e12b71732..8eca4c0534355 100644
--- a/clang/test/CIR/CodeGen/anonymous-nested-init.c
+++ b/clang/test/CIR/CodeGen/anonymous-nested-init.c
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
-// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefixes=LLVM,LLVMCIR
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
-// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
+// RUN: FileCheck --input-file=%t.ll %s -check-prefixes=LLVM,OGCG
// Anonymous struct as a field.
struct StructWithAnon {
@@ -31,5 +31,8 @@ struct StructWithAnonBitfields {
};
struct StructWithAnonBitfields g_anon_bits = { 7, {0xA, 0x5}, 9 };
-// CIR: cir.global external @g_anon_bits = #cir.const_record<{#cir.int<7> : !s32i, #cir.const_record<{#cir.int<90> : !u8i, #cir.zero : !cir.array<!u8i x 3>}> : !rec_anon2E2, #cir.int<9> : !s32i}> : !rec_StructWithAnonBitfields
-// LLVM: @g_anon_bits = global %struct.StructWithAnonBitfields { i32 7, %struct.anon{{.*}} { i8 90, [3 x i8] zeroinitializer }, i32 9 }
+// CIR: cir.global external @g_anon_bits = #cir.const_record<{#cir.int<7> : !s32i, #cir.const_record<{#cir.int<90> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.zero : !cir.array<!u8i x 3>}> : !rec_anon2E2, #cir.int<9> : !s32i}> : !rec_StructWithAnonBitfields
+// The zero-length member carrying the bit-field's declared reach has no
+// counterpart in classic CodeGen.
+// LLVMCIR: @g_anon_bits = global %struct.StructWithAnonBitfields { i32 7, %struct.anon{{.*}} { i8 90, [0 x i8] zeroinitializer, [3 x i8] zeroinitializer }, i32 9 }
+// OGCG: @g_anon_bits = global %struct.StructWithAnonBitfields { i32 7, %struct.anon{{.*}} { i8 90, [3 x i8] zeroinitializer }, i32 9 }
diff --git a/clang/test/CIR/CodeGen/bitfield-init-values.c b/clang/test/CIR/CodeGen/bitfield-init-values.c
index e1d7ced493ef6..93fadd770156f 100644
--- a/clang/test/CIR/CodeGen/bitfield-init-values.c
+++ b/clang/test/CIR/CodeGen/bitfield-init-values.c
@@ -5,54 +5,58 @@
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIRBE
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
-// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVMLE,LLVMCIRLE
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVMCIRLE
//
// RUN: %clang_cc1 -triple aarch64_be-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
-// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVMBE,LLVMCIRBE
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVMCIRBE
//
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
-// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVMLE,OGCGLE
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCGLE
//
// RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm %s -o %t.ll
-// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVMBE,OGCGBE
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCGBE
struct B1 { unsigned int a : 3; unsigned int b : 5; };
struct B1 b1 = { 0b101, 0b01111 };
-// CIRLE: cir.global external @b1 = #cir.const_record<{#cir.int<125> : !u8i, #cir.zero : !cir.array<!u8i x 3>}> : !rec_B1
-// CIRBE: cir.global external @b1 = #cir.const_record<{#cir.int<175> : !u8i, #cir.zero : !cir.array<!u8i x 3>}> : !rec_B1
-// LLVMLE: @b1 = global %struct.B1 { i8 125, [3 x i8] zeroinitializer }
-// LLVMBE: @b1 = global %struct.B1 { i8 -81, [3 x i8] zeroinitializer }
+// CIRLE: cir.global external @b1 = #cir.const_record<{#cir.int<125> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.zero : !cir.array<!u8i x 3>}> : !rec_B1
+// CIRBE: cir.global external @b1 = #cir.const_record<{#cir.int<175> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.zero : !cir.array<!u8i x 3>}> : !rec_B1
+// LLVMCIRLE: @b1 = global %struct.B1 { i8 125, [0 x i8] zeroinitializer, [3 x i8] zeroinitializer }, align 4
+// OGCGLE: @b1 = global %struct.B1 { i8 125, [3 x i8] zeroinitializer }, align 4
+// LLVMCIRBE: @b1 = global %struct.B1 { i8 -81, [0 x i8] zeroinitializer, [3 x i8] zeroinitializer }, align 4
+// OGCGBE: @b1 = global %struct.B1 { i8 -81, [3 x i8] zeroinitializer }, align 4
struct B2 { unsigned int a : 8; unsigned int b : 8; unsigned int c : 16; };
struct B2 b2 = { 0xAA, 0xBB, 0xCCDD };
-// CIRLE: cir.global external @b2 = #cir.const_record<{#cir.int<3437083562> : !u32i}> : !rec_B2
-// CIRBE: cir.global external @b2 = #cir.const_record<{#cir.int<2864434397> : !u32i}> : !rec_B2
-// LLVMCIRLE: @b2 = global %struct.B2 { i32 -857883734 }
-// LLVMCIRBE: @b2 = global %struct.B2 { i32 -1430532899 }
+// CIRLE: cir.global external @b2 = #cir.const_record<{#cir.int<3437083562> : !u32i, #cir.zero : !cir.array<!cir.array<!u8i x 2> x 0>}> : !rec_B2
+// CIRBE: cir.global external @b2 = #cir.const_record<{#cir.int<2864434397> : !u32i, #cir.zero : !cir.array<!cir.array<!u8i x 2> x 0>}> : !rec_B2
+// LLVMCIRLE: @b2 = global %struct.B2 { i32 -857883734, [0 x i8] zeroinitializer }, align 4
+// LLVMCIRBE: @b2 = global %struct.B2 { i32 -1430532899, [0 x i8] zeroinitializer }, align 4
// OGCGLE: @b2 = global { i8, i8, i8, i8 } { i8 -86, i8 -69, i8 -35, i8 -52 }
// OGCGBE: @b2 = global { i8, i8, i8, i8 } { i8 -86, i8 -69, i8 -52, i8 -35 }
struct BP { unsigned int a : 3; unsigned int b : 5; int c; };
struct BP bp = { 1, 2, 99 };
-// CIRLE: cir.global external @bp = #cir.const_record<{#cir.int<17> : !u8i, #cir.int<99> : !s32i}> : !rec_BP
-// CIRBE: cir.global external @bp = #cir.const_record<{#cir.int<34> : !u8i, #cir.int<99> : !s32i}> : !rec_BP
-// LLVMCIRLE: @bp = global %struct.BP { i8 17, i32 99 }
-// LLVMCIRBE: @bp = global %struct.BP { i8 34, i32 99 }
+// CIRLE: cir.global external @bp = #cir.const_record<{#cir.int<17> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.int<99> : !s32i}> : !rec_BP
+// CIRBE: cir.global external @bp = #cir.const_record<{#cir.int<34> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.int<99> : !s32i}> : !rec_BP
+// LLVMCIRLE: @bp = global %struct.BP { i8 17, [0 x i8] zeroinitializer, i32 99 }, align 4
+// LLVMCIRBE: @bp = global %struct.BP { i8 34, [0 x i8] zeroinitializer, i32 99 }, align 4
// OGCGLE: @bp = global { i8, [3 x i8], i32 } { i8 17, [3 x i8] zeroinitializer, i32 99 }
// OGCGBE: @bp = global { i8, [3 x i8], i32 } { i8 34, [3 x i8] zeroinitializer, i32 99 }
struct BS { int a : 4; int b : 4; };
struct BS bs = { -1, 3 };
-// CIRLE: cir.global external @bs = #cir.const_record<{#cir.int<63> : !u8i, #cir.zero : !cir.array<!u8i x 3>}> : !rec_BS
-// CIRBE: cir.global external @bs = #cir.const_record<{#cir.int<243> : !u8i, #cir.zero : !cir.array<!u8i x 3>}> : !rec_BS
-// LLVMLE: @bs = global %struct.BS { i8 63, [3 x i8] zeroinitializer }
-// LLVMBE: @bs = global %struct.BS { i8 -13, [3 x i8] zeroinitializer }
+// CIRLE: cir.global external @bs = #cir.const_record<{#cir.int<63> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.zero : !cir.array<!u8i x 3>}> : !rec_BS
+// CIRBE: cir.global external @bs = #cir.const_record<{#cir.int<243> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.zero : !cir.array<!u8i x 3>}> : !rec_BS
+// LLVMCIRLE: @bs = global %struct.BS { i8 63, [0 x i8] zeroinitializer, [3 x i8] zeroinitializer }, align 4
+// OGCGLE: @bs = global %struct.BS { i8 63, [3 x i8] zeroinitializer }, align 4
+// LLVMCIRBE: @bs = global %struct.BS { i8 -13, [0 x i8] zeroinitializer, [3 x i8] zeroinitializer }, align 4
+// OGCGBE: @bs = global %struct.BS { i8 -13, [3 x i8] zeroinitializer }, align 4
struct BA { int a : 24; char c; };
struct BA ba = { 0x123456, 7 };
-// CIRLE: cir.global external @ba = #cir.const_record<{#cir.const_array<[#cir.int<86> : !u8i, #cir.int<52> : !u8i, #cir.int<18> : !u8i]> : !cir.array<!u8i x 3>, #cir.int<7> : !s8i}> : !rec_BA
-// CIRBE: cir.global external @ba = #cir.const_record<{#cir.const_array<[#cir.int<18> : !u8i, #cir.int<52> : !u8i, #cir.int<86> : !u8i]> : !cir.array<!u8i x 3>, #cir.int<7> : !s8i}> : !rec_BA
-// LLVMCIRLE: @ba = global %struct.BA { [3 x i8] c"V4\12", i8 7 }
-// LLVMCIRBE: @ba = global %struct.BA { [3 x i8] c"\124V", i8 7 }
+// CIRLE: cir.global external @ba = #cir.const_record<{#cir.const_array<[#cir.int<86> : !u8i, #cir.int<52> : !u8i, #cir.int<18> : !u8i]> : !cir.array<!u8i x 3>, #cir.zero : !cir.array<!u8i x 0>, #cir.int<7> : !s8i}> : !rec_BA
+// CIRBE: cir.global external @ba = #cir.const_record<{#cir.const_array<[#cir.int<18> : !u8i, #cir.int<52> : !u8i, #cir.int<86> : !u8i]> : !cir.array<!u8i x 3>, #cir.zero : !cir.array<!u8i x 0>, #cir.int<7> : !s8i}> : !rec_BA
+// LLVMCIRLE: @ba = global %struct.BA { [3 x i8] c"V4\12", [0 x i8] zeroinitializer, i8 7 }, align 4
+// LLVMCIRBE: @ba = global %struct.BA { [3 x i8] c"\124V", [0 x i8] zeroinitializer, i8 7 }, align 4
// OGCGLE: @ba = global { i8, i8, i8, i8 } { i8 86, i8 52, i8 18, i8 7 }
// OGCGBE: @ba = global { i8, i8, i8, i8 } { i8 18, i8 52, i8 86, i8 7 }
diff --git a/clang/test/CIR/CodeGen/bitfields.c b/clang/test/CIR/CodeGen/bitfields.c
index d4bd980a057d2..5f9dc77cb2a6d 100644
--- a/clang/test/CIR/CodeGen/bitfields.c
+++ b/clang/test/CIR/CodeGen/bitfields.c
@@ -12,9 +12,9 @@ typedef struct {
unsigned still_more_bits : 7;
} A;
-// CIR-DAG: !rec_A = !cir.struct<"A" packed {data !s8i, data !s8i, data !s8i, bitfield !u16i, pad !cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_A = !cir.struct<"A" packed {data !s8i, data !s8i, data !s8i, bitfield !u16i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, pad !cir.array<!u8i x 3>}>
// CIR-DAG: #bfi_more_bits = #cir.bitfield_info<name = "more_bits", storage_type = !u16i, size = 4, offset = 3, is_signed = false>
-// LLVM-DAG: %struct.A = type <{ i8, i8, i8, i16, [3 x i8] }>
+// LLVM-DAG: %struct.A = type <{ i8, i8, i8, i16, [0 x i8], [3 x i8] }>
// OGCG-DAG: %struct.A = type <{ i8, i8, i8, i16, [3 x i8] }>
typedef struct {
@@ -23,8 +23,8 @@ typedef struct {
int c;
} D;
-// CIR-DAG: !rec_D = !cir.struct<"D" {bitfield !u16i, data !s32i}>
-// LLVM-DAG: %struct.D = type { i16, i32 }
+// CIR-DAG: !rec_D = !cir.struct<"D" {bitfield !u16i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, data !s32i}>
+// LLVM-DAG: %struct.D = type { i16, [0 x i8], i32 }
// OGCG-DAG: %struct.D = type { i16, i32 }
typedef struct {
@@ -36,8 +36,8 @@ typedef struct {
unsigned f; // type other than int above, not a bitfield
} S;
// CIR-DAG: #bfi_c = #cir.bitfield_info<name = "c", storage_type = !u64i, size = 17, offset = 32, is_signed = true>
-// CIR-DAG: !rec_S = !cir.struct<"S" {bitfield !u64i, bitfield !u16i, data !u32i}>
-// LLVM-DAG: %struct.S = type { i64, i16, i32 }
+// CIR-DAG: !rec_S = !cir.struct<"S" {bitfield !u64i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, bitfield !u16i, bitfield !cir.array<!cir.array<!u8i x 2> x 0>, data !u32i}>
+// LLVM-DAG: %struct.S = type { i64, [0 x i8], i16, [0 x i8], i32 }
// OGCG-DAG: %struct.S = type { i64, i16, i32 }
typedef struct {
@@ -45,8 +45,8 @@ typedef struct {
unsigned b;
} T;
-// CIR-DAG: !rec_T = !cir.struct<"T" {bitfield !u8i, data !u32i}>
-// LLVM-DAG: %struct.T = type { i8, i32 }
+// CIR-DAG: !rec_T = !cir.struct<"T" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, data !u32i}>
+// LLVM-DAG: %struct.T = type { i8, [0 x i8], i32 }
// OGCG-DAG: %struct.T = type { i8, i32 }
typedef struct {
@@ -67,8 +67,8 @@ typedef struct {
int l: 14;
} U;
-// CIR-DAG: !rec_U = !cir.struct<"U" packed {data !s8i, data !s8i, data !s8i, bitfield !u8i, bitfield !u64i}>
-// LLVM-DAG: %struct.U = type <{ i8, i8, i8, i8, i64 }>
+// CIR-DAG: !rec_U = !cir.struct<"U" packed {data !s8i, data !s8i, data !s8i, bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>, bitfield !u64i, bitfield !cir.array<!cir.array<!u8i x 2> x 0>}>
+// LLVM-DAG: %struct.U = type <{ i8, i8, i8, i8, [0 x i8], i64, [0 x i8] }>
// OGCG-DAG: %struct.U = type <{ i8, i8, i8, i8, i64 }>
typedef struct{
@@ -77,8 +77,8 @@ typedef struct{
int c: 30;
} Clip;
-// CIR-DAG: !rec_Clip = !cir.struct<"Clip" {bitfield !cir.array<!u8i x 3>, data !s8i, bitfield !u32i}>
-// LLVM-DAG: %struct.Clip = type { [3 x i8], i8, i32 }
+// CIR-DAG: !rec_Clip = !cir.struct<"Clip" {bitfield !cir.array<!u8i x 3>, bitfield !cir.array<!u8i x 0>, data !s8i, bitfield !u32i}>
+// LLVM-DAG: %struct.Clip = type { [3 x i8], [0 x i8], i8, i32 }
// OGCG-DAG: %struct.Clip = type { [3 x i8], i8, i32 }
void def() {
@@ -153,12 +153,12 @@ void store_field() {
// CIR: cir.func {{.*@store_field}}
// CIR: [[TMP0:%.*]] = cir.alloca {{.*}} : !cir.ptr<!rec_S>
// CIR: [[TMP1:%.*]] = cir.const #cir.int<3> : !s32i
-// CIR: [[TMP2:%.*]] = cir.get_member [[TMP0]][1] {name = "e"} : !cir.ptr<!rec_S> -> !cir.ptr<!u16i>
+// CIR: [[TMP2:%.*]] = cir.get_member [[TMP0]][2] {name = "e"} : !cir.ptr<!rec_S> -> !cir.ptr<!u16i>
// CIR: cir.set_bitfield align(4) (#bfi_e, [[TMP2]] : !cir.ptr<!u16i>, [[TMP1]] : !s32i)
// LLVM: define dso_local void @store_field()
// LLVM: [[TMP0:%.*]] = alloca %struct.S, align 4
-// LLVM: [[TMP1:%.*]] = getelementptr inbounds nuw %struct.S, ptr [[TMP0]], i32 0, i32 1
+// LLVM: [[TMP1:%.*]] = getelementptr inbounds nuw %struct.S, ptr [[TMP0]], i32 0, i32 2
// LLVM: [[TMP2:%.*]] = load i16, ptr [[TMP1]], align 4
// LLVM: [[TMP3:%.*]] = and i16 [[TMP2]], -32768
// LLVM: [[TMP4:%.*]] = or i16 [[TMP3]], 3
diff --git a/clang/test/CIR/CodeGen/bitfields.cpp b/clang/test/CIR/CodeGen/bitfields.cpp
index 8aec3cf99a66a..36451b95b22c5 100644
--- a/clang/test/CIR/CodeGen/bitfields.cpp
+++ b/clang/test/CIR/CodeGen/bitfields.cpp
@@ -1,8 +1,6 @@
-// TODO(cir): drop -fno-clangir-call-conv-lowering once CallConvLowering
-// supports padded, packed, and over-aligned record shapes.
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -fno-clangir-call-conv-lowering -emit-cir %s -o %t.cir
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
-// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -fno-clangir-call-conv-lowering -emit-llvm %s -o %t-cir.ll
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
@@ -15,9 +13,9 @@ typedef struct {
int e : 15;
unsigned f; // type other than int above, not a bitfield
} S;
-// CIR-DAG: !rec_S = !cir.struct<"S" {bitfield !u64i, bitfield !u16i, data !u32i}>
+// CIR-DAG: !rec_S = !cir.struct<"S" {bitfield !u64i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, bitfield !u16i, bitfield !cir.array<!cir.array<!u8i x 2> x 0>, data !u32i}>
// CIR-DAG: #bfi_c = #cir.bitfield_info<name = "c", storage_type = !u64i, size = 17, offset = 32, is_signed = true>
-// LLVM-DAG: %struct.S = type { i64, i16, i32 }
+// LLVM-DAG: %struct.S = type { i64, [0 x i8], i16, [0 x i8], i32 }
// OGCG-DAG: %struct.S = type { i64, i16, i32 }
typedef struct {
@@ -25,8 +23,8 @@ typedef struct {
unsigned b;
} T;
-// CIR-DAG: !rec_T = !cir.struct<"T" {bitfield !u8i, data !u32i}>
-// LLVM-DAG: %struct.T = type { i8, i32 }
+// CIR-DAG: !rec_T = !cir.struct<"T" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, data !u32i}>
+// LLVM-DAG: %struct.T = type { i8, [0 x i8], i32 }
// OGCG-DAG: %struct.T = type { i8, i32 }
union U { int x : 3; };
diff --git a/clang/test/CIR/CodeGen/bitfields_be.c b/clang/test/CIR/CodeGen/bitfields_be.c
index 0ed234a362068..8da705a69c862 100644
--- a/clang/test/CIR/CodeGen/bitfields_be.c
+++ b/clang/test/CIR/CodeGen/bitfields_be.c
@@ -11,8 +11,8 @@ typedef struct {
int c : 17;
} S;
-// CIR: !rec_S = !cir.struct<"S" {bitfield !u32i}>
-// LLVM: %struct.S = type { i32 }
+// CIR: !rec_S = !cir.struct<"S" {bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 2> x 0>}>
+// LLVM: %struct.S = type { i32, [0 x i8] }
// OGCG: %struct.S = type { i32 }
void def() {
S s;
diff --git a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-reach.cpp b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-reach.cpp
new file mode 100644
index 0000000000000..7ad13d657fd6b
--- /dev/null
+++ b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-reach.cpp
@@ -0,0 +1,250 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --check-prefixes=LLVM,LLVM-CIR --input-file=%t-cir.ll %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -emit-llvm %s -o %t.ll
+// RUN: FileCheck --check-prefixes=LLVM,LLVM-OGCG --input-file=%t.ll %s
+
+struct Bits {
+ unsigned x : 3;
+};
+
+struct Inner {
+ unsigned x : 3;
+};
+
+struct OuterNest {
+ Inner i;
+};
+
+struct WideInner {
+ long long b : 1;
+};
+
+struct ArrNest {
+ WideInner a[1];
+} __attribute__((aligned(16)));
+
+struct Nested {
+ unsigned w : 16;
+ unsigned l : 13;
+};
+
+struct Wrap {
+ int a;
+ Nested n;
+} __attribute__((aligned(16)));
+
+struct UnnamedPastUnit {
+ int a : 8;
+ int : 16;
+} __attribute__((aligned(8)));
+
+struct UnnamedWide {
+ unsigned char a : 3;
+ unsigned long long : 5;
+} __attribute__((aligned(8)));
+
+struct NarrowUnit {
+ unsigned x : 32;
+} __attribute__((aligned(16)));
+
+struct WideUnit {
+ long long x : 32;
+} __attribute__((aligned(16)));
+
+struct NamedZeroWidth {
+ unsigned x : 3;
+ unsigned : 0;
+ int y;
+};
+
+struct __attribute__((packed, aligned(8))) PackedBits {
+ unsigned b : 3;
+ int x;
+};
+
+struct SpillsPastUnit {
+ int a : 4;
+ int b : 27;
+ int c : 17;
+ int d : 2;
+ int e;
+} __attribute__((aligned(8)));
+
+struct UnnamedOnly {
+ int : 8;
+};
+
+union UUnnamedOnly {
+ int : 8;
+};
+
+struct Sema {
+ unsigned w : 16;
+ unsigned l : 13;
+ bool s : 1;
+};
+
+struct Holder {
+ long long v;
+ Sema sema;
+};
+
+union UBits {
+ unsigned a : 1;
+ unsigned b : 1;
+};
+
+union UBytes {
+ unsigned char c, d;
+};
+
+union UWideBits {
+ unsigned long long w : 3;
+ char pad[4];
+};
+
+// A unit narrower than the type declared in it carries the declared reach as a
+// zero-length member, which is what widens the coercion from the unit's own i8
+// to the eightbyte the declaration covers.
+// CIR-DAG: !rec_Bits = !cir.struct<"Bits" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, pad !cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_Sema = !cir.struct<"Sema" {bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 2> x 0>}>
+// CIR-DAG: !rec_UBits = !cir.union<"UBits" {bitfield !u8i, bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>}, padding = {!cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_UWideBits = !cir.union<"UWideBits" {bitfield !u8i, data !cir.array<!s8i x 4>, bitfield !cir.array<!cir.array<!u8i x 8> x 0>}, padding = {!cir.array<!u8i x 4>}>
+// CIR-DAG: !rec_WideUnit = !cir.struct<"WideUnit" {bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>, pad !cir.array<!u8i x 12>}>
+// CIR-DAG: !rec_PackedBits = !cir.struct<"PackedBits" packed {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, data !s32i, pad !cir.array<!u8i x 3>}>
+
+// A reach and a zero-width bit-field sit in one record without conflating.
+// CIR-DAG: !rec_NamedZeroWidth = !cir.struct<"NamedZeroWidth" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, pad !cir.array<!u8i x 3>, bitfield !cir.array<!u32i x 0>, data !s32i}>
+
+// A reach naming bytes past the record that holds it. Nested in Wrap those
+// bytes fall in the second eightbyte, which stays padding all the same.
+// CIR-DAG: !rec_Nested = !cir.struct<"Nested" {bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 2> x 0>}>
+// CIR-DAG: !rec_WideInner = !cir.struct<"WideInner" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 7> x 0>, pad !cir.array<!u8i x 7>}>
+
+// A unit whose declarations stop at its own end carries no reach member. An
+// unnamed bit-field records one all the same, since the bytes its declared
+// type covers hold user data even though it supplies no eightbyte class.
+// CIR-DAG: !rec_UnnamedPastUnit = !cir.struct<"UnnamedPastUnit" {bitfield !u32i, bitfield !cir.array<!u8i x 0>, pad !cir.array<!u8i x 4>}>
+// CIR-DAG: !rec_UnnamedWide = !cir.struct<"UnnamedWide" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 8> x 0>, pad !cir.array<!u8i x 7>}>
+// CIR-DAG: !rec_NarrowUnit = !cir.struct<"NarrowUnit" {bitfield !u32i, pad !cir.array<!u8i x 12>}>
+// CIR-DAG: !rec_SpillsPastUnit = !cir.struct<"SpillsPastUnit" {bitfield !u64i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, data !s32i}>
+// CIR-DAG: !rec_UnnamedOnly = !cir.struct<"UnnamedOnly" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>}>
+// CIR-DAG: !rec_UUnnamedOnly = !cir.union<"UUnnamedOnly" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>}>
+
+// A union of plain bytes has no declaration to reach past its storage, so it
+// keeps the narrow coercion.
+// CIR-DAG: !rec_UBytes = !cir.union<"UBytes" {data !u8i, data !u8i}>
+
+void take_bits(Bits v) {}
+
+// CIR: cir.func {{.*}}@_Z9take_bits4Bits(%arg0: !u32i
+// LLVM: define {{.*}}void @_Z9take_bits4Bits(i32 %{{.+}})
+
+Bits return_bits(Bits v) { return v; }
+
+// CIR: cir.func {{.*}}@_Z11return_bits4Bits(%arg0: !u32i{{.*}}) -> !u32i
+// LLVM: define {{.*}}i32 @_Z11return_bits4Bits(i32 %{{.+}})
+
+void take_outer(OuterNest v) {}
+
+// CIR: cir.func {{.*}}@_Z10take_outer9OuterNest(%arg0: !u32i
+// LLVM: define {{.*}}void @_Z10take_outer9OuterNest(i32 %{{.+}})
+
+void take_holder(Holder v) {}
+
+// CIR: cir.func {{.*}}@_Z11take_holder6Holder(%arg0: !s64i{{.*}}, %arg1: !u32i
+// LLVM: define {{.*}}void @_Z11take_holder6Holder(i64 %{{.+}}, i32 %{{.+}})
+
+// The reach also travels through an array element. The element's unit is one
+// byte, so without the reach the eightbyte would narrow to i8.
+void take_arr_nest(ArrNest v) {}
+
+// CIR: cir.func {{.*}}@_Z13take_arr_nest7ArrNest(%arg0: !u64i
+// LLVM: define {{.*}}void @_Z13take_arr_nest7ArrNest(i64 %{{.+}})
+
+// A reach may run past the end of the record that records it. The bytes it
+// names there belong to the enclosing record, and the classifier stops at the
+// inner record's own size, so the eightbyte holding them stays padding.
+void take_wrap(Wrap v) {}
+
+// CIR: cir.func {{.*}}@_Z9take_wrap4Wrap(%arg0: !u64i
+// LLVM: define {{.*}}void @_Z9take_wrap4Wrap(i64 %{{.+}})
+
+// An unnamed bit-field supplies no eightbyte class, but the bytes its declared
+// type covers are user data, so its reach counts. Leaving it out would narrow
+// these two to i32 and i8.
+void take_unnamed_past_unit(UnnamedPastUnit v) {}
+void take_unnamed_wide(UnnamedWide v) {}
+
+// CIR: cir.func {{.*}}@_Z22take_unnamed_past_unit15UnnamedPastUnit(%arg0: !u64i
+// LLVM: define {{.*}}void @_Z22take_unnamed_past_unit15UnnamedPastUnit(i64 %{{.+}})
+
+// CIR: cir.func {{.*}}@_Z17take_unnamed_wide11UnnamedWide(%arg0: !u64i
+// LLVM: define {{.*}}void @_Z17take_unnamed_wide11UnnamedWide(i64 %{{.+}})
+
+// These two records differ only in the type their bit-field is declared with,
+// so the reach is what widens the second coercion to the eightbyte it covers.
+void take_narrow_unit(NarrowUnit v) {}
+void take_wide_unit(WideUnit v) {}
+
+// CIR: cir.func {{.*}}@_Z16take_narrow_unit10NarrowUnit(%arg0: !u32i
+// LLVM: define {{.*}}void @_Z16take_narrow_unit10NarrowUnit(i32 %{{.+}})
+
+// CIR: cir.func {{.*}}@_Z14take_wide_unit8WideUnit(%arg0: !u64i
+// LLVM: define {{.*}}void @_Z14take_wide_unit8WideUnit(i64 %{{.+}})
+
+// A reach and a zero-width bit-field in one record, which share a shape.
+void take_named_zero_width(NamedZeroWidth v) {}
+
+// CIR: cir.func {{.*}}@_Z21take_named_zero_width14NamedZeroWidth(%arg0: !u64i
+// LLVM: define {{.*}}void @_Z21take_named_zero_width14NamedZeroWidth(i64 %{{.+}})
+
+// The int here sits at an offset its own alignment does not divide, which
+// sends the record to memory whatever the unit before it reaches.
+void take_packed_bits(PackedBits v) {}
+
+// CIR: cir.func {{.*}}@_Z16take_packed_bits10PackedBits(%arg0: !cir.ptr<!rec_PackedBits>
+// LLVM-CIR: define {{.*}}void @_Z16take_packed_bits10PackedBits(ptr noalias noundef byval(%struct.PackedBits) align 8 %{{.+}})
+// LLVM-OGCG: define {{.*}}void @_Z16take_packed_bits10PackedBits(ptr noundef byval(%struct.PackedBits) align 8 %{{.+}})
+
+// The reach is measured from where the member sits, which is the unit's end.
+// Measuring it from the unit's start instead would claim a further eightbyte
+// of user data and widen the second half to i64.
+void take_spills_past_unit(SpillsPastUnit v) {}
+
+// CIR: cir.func {{.*}}@_Z21take_spills_past_unit14SpillsPastUnit(%arg0: !u64i{{.*}}, %arg1: !s32i
+// LLVM: define {{.*}}void @_Z21take_spills_past_unit14SpillsPastUnit(i64 %{{.+}}, i32 %{{.+}})
+
+// A unit of unnamed bit-fields records a reach without supplying data, which
+// leaves the record empty for the ABI and drops the argument.
+void take_unnamed_only(UnnamedOnly v) {}
+void take_uunnamed_only(UUnnamedOnly v) {}
+
+// CIR: cir.func {{.*}}@_Z17take_unnamed_only11UnnamedOnly()
+// LLVM: define {{.*}}void @_Z17take_unnamed_only11UnnamedOnly()
+
+// CIR: cir.func {{.*}}@_Z18take_uunnamed_only12UUnnamedOnly()
+// LLVM: define {{.*}}void @_Z18take_uunnamed_only12UUnnamedOnly()
+
+void take_ubits(UBits v) {}
+
+// CIR: cir.func {{.*}}@_Z10take_ubits5UBits(%arg0: !u32i
+// LLVM: define {{.*}}void @_Z10take_ubits5UBits(i32 %{{.+}})
+
+void take_ubytes(UBytes v) {}
+
+// CIR: cir.func {{.*}}@_Z11take_ubytes6UBytes(%arg0: !u8i
+// LLVM: define {{.*}}void @_Z11take_ubytes6UBytes(i8 %{{.+}})
+
+// A union holding both a data member and a bit-field whose declared type
+// outruns it, so the reach rather than the widest member sizes the coercion.
+void take_uwide_bits(UWideBits v) {}
+UWideBits ret_uwide_bits(void) { UWideBits u; u.w = 1; return u; }
+
+// CIR: cir.func {{.*}}@_Z15take_uwide_bits9UWideBits(%arg0: !u64i
+// LLVM: define {{.*}}void @_Z15take_uwide_bits9UWideBits(i64 %{{.+}})
+
+// CIR: cir.func {{.*}}@_Z14ret_uwide_bitsv() -> !u64i
+// LLVM: define {{.*}}i64 @_Z14ret_uwide_bitsv()
diff --git a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-packed.c b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-packed.c
index 540e02d1db7f5..b9b53a71d8e99 100644
--- a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-packed.c
+++ b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-packed.c
@@ -31,8 +31,8 @@ typedef struct { char c; int i; } PragmaPacked;
// CIR-DAG: !rec_CharInt = !cir.struct<"CharInt" packed {data !s8i, data !s32i}>
// CIR-DAG: !rec_CharIntBF = !cir.struct<"CharIntBF" packed {data !s8i, bitfield !u32i}>
// CIR-DAG: !rec_CharWideBF = !cir.struct<"CharWideBF" packed {data !s8i, bitfield !u64i}>
-// CIR-DAG: !rec_CharMultipleBFInt = !cir.struct<"CharMultipleBFInt" {data !s8i, bitfield !cir.array<!u8i x 6>}>
-// CIR-DAG: !rec_CharUndersizedIntBF = !cir.struct<"CharUndersizedIntBF" {data !s8i, bitfield !cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_CharMultipleBFInt = !cir.struct<"CharMultipleBFInt" {data !s8i, bitfield !cir.array<!u8i x 6>, bitfield !cir.array<!cir.array<!u8i x 4> x 0>}>
+// CIR-DAG: !rec_CharUndersizedIntBF = !cir.struct<"CharUndersizedIntBF" {data !s8i, bitfield !cir.array<!u8i x 3>, bitfield !cir.array<!u8i x 0>}>
// CIR-DAG: !rec_BFDouble = !cir.struct<"BFDouble" packed {data !s8i, bitfield !u32i, data !cir.array<!s8i x 3>, data !cir.double}>
// CIR-DAG: !rec_Nine = !cir.struct<"Nine" packed {data !s32i, data !s32i, data !s8i}>
// CIR-DAG: !rec_FiveShort = !cir.struct<"FiveShort" packed {data !s16i, data !s16i, data !s8i}>
@@ -134,9 +134,9 @@ FiveShort ret_five_short(short x) { FiveShort v = {0, x, 0}; return v; }
// LLVM: define dso_local i32 @take_five_short(i40 %{{.+}})
// LLVM: define dso_local i40 @ret_five_short(i16 noundef signext %{{.+}})
-// A named access unit is only ambiguous where padding lets classic read the
-// declared type through the gap, so a packed record whose every byte holds
-// data is classified rather than refused by the unit-width rule.
+// The char bit-field here is declared no wider than the byte its unit
+// occupies, so the unit records no reach and every byte of the record holds
+// data.
int take_ninebf(NineBF v) { return v.b; }
// CIR: cir.func{{.*}} @take_ninebf(%arg0: !u64i{{.*}}, %arg1: !u8i{{.*}}) -> !s32i
diff --git a/clang/test/CIR/CodeGen/constant-inits.cpp b/clang/test/CIR/CodeGen/constant-inits.cpp
index dfd724b2d1665..12ad5b0fcc53f 100644
--- a/clang/test/CIR/CodeGen/constant-inits.cpp
+++ b/clang/test/CIR/CodeGen/constant-inits.cpp
@@ -115,32 +115,32 @@ void function() {
// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE9paa_array = #cir.const_array<[#cir.const_record<{#cir.int<1> : !s16i, #cir.int<2> : !s8i, #cir.fp<3.000000e+00> : !cir.float, #cir.int<0> : !u8i}> : !rec_packed_and_aligned], trailing_zeros> : !cir.array<!rec_packed_and_aligned x 2>
-// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE6ba_bf1 = #cir.const_record<{#cir.int<305441535> : !u32i}> : !rec_byte_aligned_bitfields
-// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE6ba_bf2 = #cir.const_record<{#cir.int<32767> : !u16i, #cir.zero : !cir.array<!u8i x 2>}> : !rec_signed_byte_aligned_bitfields
+// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE6ba_bf1 = #cir.const_record<{#cir.int<305441535> : !u32i, #cir.zero : !cir.array<!cir.array<!u8i x 2> x 0>}> : !rec_byte_aligned_bitfields
+// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE6ba_bf2 = #cir.const_record<{#cir.int<32767> : !u16i, #cir.zero : !cir.array<!cir.array<!u8i x 3> x 0>, #cir.zero : !cir.array<!u8i x 2>}> : !rec_signed_byte_aligned_bitfields
// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE6ba_bf3 = #cir.const_record<{#cir.int<42> : !u8i}> : !rec_single_byte_bitfield
-// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE5p_bf1 = #cir.const_record<{#cir.int<785> : !u16i, #cir.zero : !cir.array<!u8i x 2>}> : !rec_partial_bitfields
-// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE5p_bf2 = #cir.const_record<{#cir.int<127> : !u8i, #cir.zero : !cir.array<!u8i x 3>}> : !rec_signed_partial_bitfields
-// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE5p_bf3 = #cir.const_record<{#cir.int<125> : !u8i}> : !rec_mixed_partial_bitfields
+// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE5p_bf1 = #cir.const_record<{#cir.int<785> : !u16i, #cir.zero : !cir.array<!cir.array<!u8i x 3> x 0>, #cir.zero : !cir.array<!u8i x 2>}> : !rec_partial_bitfields
+// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE5p_bf2 = #cir.const_record<{#cir.int<127> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.zero : !cir.array<!u8i x 3>}> : !rec_signed_partial_bitfields
+// CIR-DAG: cir.global "private" constant internal dso_local @_ZZ8functionvE5p_bf3 = #cir.const_record<{#cir.int<125> : !u8i, #cir.zero : !cir.array<!u8i x 0>}> : !rec_mixed_partial_bitfields
// CIR-LABEL: cir.func {{.*}} @_Z8functionv()
// CIR: cir.return
-// LLVM-DAG: @_ZZ8functionvE12packed_array = internal constant [2 x %struct.packed] [%struct.packed <{ i8 123, i32 456 }>, %struct.packed <{ i8 123, i32 456 }>]
-// LLVM-DAG: @_ZZ8functionvE12simple_array = internal constant [3 x %struct.simple] [%struct.simple { i32 0, i32 -1 }, %struct.simple { i32 1111, i32 2222 }, %struct.simple { i32 0, i32 -1 }]
-// LLVM-DAG: @_ZZ8functionvE1e = internal constant %struct.empty zeroinitializer
-// LLVM-DAG: @_ZZ8functionvE1s = internal constant %struct.simple { i32 0, i32 -1 }
-// LLVM-DAG: @_ZZ8functionvE2p1 = internal constant %struct.Point { i32 10, i32 20, [3 x i8] c"cXM", i32 40 }
-// LLVM-DAG: @_ZZ8functionvE2p2 = internal constant %struct.packed <{ i8 123, i32 456 }>
-// LLVM-DAG: @_ZZ8functionvE3paa = internal constant %struct.packed_and_aligned <{ i16 1, i8 2, float 3.000000e+00, i8 0 }>
-// LLVM-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 }]
-// LLVM-DAG: @_ZZ8functionvE9paa_array = internal constant [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]
-// LLVM-DAG: @_ZZ8functionvE6ba_bf1 = internal constant %struct.byte_aligned_bitfields { i32 305441535 }
-// LLVM-dAG: @_ZZ8functionvE6ba_bf2 = internal constant %struct.signed_byte_aligned_bitfields { i16 32767, [2 x i8] zeroinitializer }
-// LLVM-DAG: @_ZZ8functionvE6ba_bf3 = internal constant %struct.single_byte_bitfield { i8 42 }
-// LLVM-DAG: @_ZZ8functionvE5p_bf1 = internal constant %struct.partial_bitfields { i16 785, [2 x i8] zeroinitializer }
-// LLVM-DAG: @_ZZ8functionvE5p_bf2 = internal constant %struct.signed_partial_bitfields { i8 127, [3 x i8] zeroinitializer }
-// LLVM-DAG: @_ZZ8functionvE5p_bf3 = internal constant %struct.mixed_partial_bitfields { i8 125 }
+// LLVM-DAG: @_ZZ8functionvE12packed_array = internal constant [2 x %struct.packed] [%struct.packed <{ i8 123, i32 456 }>, %struct.packed <{ i8 123, i32 456 }>], align 1
+// LLVM-DAG: @_ZZ8functionvE12simple_array = internal constant [3 x %struct.simple] [%struct.simple { i32 0, i32 -1 }, %struct.simple { i32 1111, i32 2222 }, %struct.simple { i32 0, i32 -1 }], align 16
+// LLVM-DAG: @_ZZ8functionvE1e = internal constant %struct.empty zeroinitializer, align 1
+// LLVM-DAG: @_ZZ8functionvE1s = internal constant %struct.simple { i32 0, i32 -1 }, align 4
+// LLVM-DAG: @_ZZ8functionvE2p1 = internal constant %struct.Point { i32 10, i32 20, [3 x i8] c"cXM", i32 40 }, align 4
+// LLVM-DAG: @_ZZ8functionvE2p2 = internal constant %struct.packed <{ i8 123, i32 456 }>, align 1
+// LLVM-DAG: @_ZZ8functionvE3paa = internal constant %struct.packed_and_aligned <{ i16 1, i8 2, float 3.000000e+00, i8 0 }>, align 8
+// LLVM-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 }], align 16
+// LLVM-DAG: @_ZZ8functionvE9paa_array = internal constant [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], align 16
+// LLVM-DAG: @_ZZ8functionvE6ba_bf1 = internal constant %struct.byte_aligned_bitfields { i32 305441535, [0 x i8] zeroinitializer }, align 4
+// LLVM-DAG: @_ZZ8functionvE6ba_bf2 = internal constant %struct.signed_byte_aligned_bitfields { i16 32767, [0 x i8] zeroinitializer, [2 x i8] zeroinitializer }, align 4
+// LLVM-DAG: @_ZZ8functionvE6ba_bf3 = internal constant %struct.single_byte_bitfield { i8 42 }, align 1
+// LLVM-DAG: @_ZZ8functionvE5p_bf1 = internal constant %struct.partial_bitfields { i16 785, [0 x i8] zeroinitializer, [2 x i8] zeroinitializer }, align 4
+// LLVM-DAG: @_ZZ8functionvE5p_bf2 = internal constant %struct.signed_partial_bitfields { i8 127, [0 x i8] zeroinitializer, [3 x i8] zeroinitializer }, align 4
+// LLVM-DAG: @_ZZ8functionvE5p_bf3 = internal constant %struct.mixed_partial_bitfields { i8 125, [0 x i8] zeroinitializer }, align 1
// LLVM-LABEL: define{{.*}} void @_Z8functionv
// LLVM: ret void
diff --git a/clang/test/CIR/CodeGen/dumb-record.cpp b/clang/test/CIR/CodeGen/dumb-record.cpp
index 0d8c898415108..d798a8ad0e93d 100644
--- a/clang/test/CIR/CodeGen/dumb-record.cpp
+++ b/clang/test/CIR/CodeGen/dumb-record.cpp
@@ -30,8 +30,8 @@ struct BitfieldsInOrder {
} bitfield_order;
// CHECK: Layout: <CIRecordLayout
-// CHECK: CIR Type:!cir.struct<"BitfieldsInOrder" {data !cir.int<s, 8>, bitfield !cir.int<u, 8>, bitfield !cir.int<u, 32>}>
-// CHECK: NonVirtualBaseCIRType:!cir.struct<"BitfieldsInOrder" {data !cir.int<s, 8>, bitfield !cir.int<u, 8>, bitfield !cir.int<u, 32>}>
+// CHECK: CIR Type:!cir.struct<"BitfieldsInOrder" {data !cir.int<s, 8>, bitfield !cir.int<u, 8>, bitfield !cir.array<!cir.array<!cir.int<u, 8> x 3> x 0>, bitfield !cir.int<u, 32>, bitfield !cir.array<!cir.array<!cir.int<u, 8> x 3> x 0>}>
+// CHECK: NonVirtualBaseCIRType:!cir.struct<"BitfieldsInOrder" {data !cir.int<s, 8>, bitfield !cir.int<u, 8>, bitfield !cir.array<!cir.array<!cir.int<u, 8> x 3> x 0>, bitfield !cir.int<u, 32>, bitfield !cir.array<!cir.array<!cir.int<u, 8> x 3> x 0>}>
// CHECK: IsZeroInitializable:1
// CHECK: BitFields:[
// CHECK-NEXT: <CIRBitFieldInfo name:bit offset:0 size:8 isSigned:0 storageSize:8 storageOffset:1 volatileOffset:0 volatileStorageSize:0 volatileStorageOffset:0>
diff --git a/clang/test/CIR/CodeGen/finegrain-bitfield-access.cpp b/clang/test/CIR/CodeGen/finegrain-bitfield-access.cpp
index 7b9db8fd5358d..001d7ba69cbe8 100644
--- a/clang/test/CIR/CodeGen/finegrain-bitfield-access.cpp
+++ b/clang/test/CIR/CodeGen/finegrain-bitfield-access.cpp
@@ -13,8 +13,8 @@ struct S1 {
unsigned f5:8;
};
-// CIR-DAG: !rec_S1 = !cir.struct<"S1" {bitfield !u8i, bitfield !u8i, bitfield !u16i}>
-// LLVM-DAG: %struct.S1 = type { i8, i8, i16 }
+// CIR-DAG: !rec_S1 = !cir.struct<"S1" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>, bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, bitfield !u16i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>}>
+// LLVM-DAG: %struct.S1 = type { i8, [0 x i8], i8, [0 x i8], i16, [0 x i8] }
// OGCG-DAG: %struct.S1 = type { i8, i8, i16 }
struct S2 {
@@ -23,8 +23,8 @@ struct S2 {
unsigned long f3:6;
};
-// CIR-DAG: !rec_S2 = !cir.struct<"S2" {bitfield !u16i, bitfield !u16i, bitfield !u8i, pad !cir.array<!u8i x 3>}>
-// LLVM-DAG: %struct.S2 = type { i16, i16, i8, [3 x i8] }
+// CIR-DAG: !rec_S2 = !cir.struct<"S2" {bitfield !u16i, bitfield !cir.array<!cir.array<!u8i x 6> x 0>, bitfield !u16i, bitfield !cir.array<!cir.array<!u8i x 6> x 0>, bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 7> x 0>, pad !cir.array<!u8i x 3>}>
+// LLVM-DAG: %struct.S2 = type { i16, [0 x i8], i16, [0 x i8], i8, [0 x i8], [3 x i8] }
// OGCG-DAG: %struct.S2 = type { i16, i16, i8, [3 x i8] }
struct S3 {
@@ -33,8 +33,8 @@ struct S3 {
unsigned long f3:32;
};
-// CIR-DAG: !rec_S3 = !cir.struct<"S3" {bitfield !u32i, bitfield !u32i}>
-// LLVM-DAG: %struct.S3 = type { i32, i32 }
+// CIR-DAG: !rec_S3 = !cir.struct<"S3" {bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 6> x 0>, bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>}>
+// LLVM-DAG: %struct.S3 = type { i32, [0 x i8], i32, [0 x i8] }
// OGCG-DAG: %struct.S3 = type { i32, i32 }
S1 a1;
@@ -46,7 +46,7 @@ unsigned read8_1() {
}
// CIR-LABEL: @_Z7read8_1v
-// CIR: [[MEMBER:%.*]] = cir.get_member %1[1] {name = "f3"} : !cir.ptr<!rec_S1> -> !cir.ptr<!u8i>
+// CIR: [[MEMBER:%.*]] = cir.get_member %1[2] {name = "f3"} : !cir.ptr<!rec_S1> -> !cir.ptr<!u8i>
// CIR: [[BITFI:%.*]] = cir.get_bitfield align(1) (#bfi_f3, [[MEMBER]] : !cir.ptr<!u8i>) -> !u32i
// CIR: cir.store [[BITFI]], {{.*}} : !u32i, !cir.ptr<!u32i>
// CIR: [[RET:%.*]] = cir.load {{.*}} : !cir.ptr<!u32i>, !u32i
@@ -70,7 +70,7 @@ void write8_1() {
// CIR-LABEL: @_Z8write8_1v
// CIR: [[CONST3:%.*]] = cir.const #cir.int<3> : !u32i
-// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[1] {name = "f3"} : !cir.ptr<!rec_S1> -> !cir.ptr<!u8i>
+// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[2] {name = "f3"} : !cir.ptr<!rec_S1> -> !cir.ptr<!u8i>
// CIR: cir.set_bitfield align(1) (#bfi_f3, [[MEMBER]] : !cir.ptr<!u8i>, [[CONST3]] : !u32i) -> !u32i
// LLVM-LABEL: @_Z8write8_1v
@@ -87,7 +87,7 @@ unsigned read8_2() {
}
// CIR-LABEL: @_Z7read8_2v
-// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[2] {name = "f5"} : !cir.ptr<!rec_S1> -> !cir.ptr<!u16i>
+// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[4] {name = "f5"} : !cir.ptr<!rec_S1> -> !cir.ptr<!u16i>
// CIR: [[BITFI:%.*]] = cir.get_bitfield align(2) (#bfi_f5, [[MEMBER]] : !cir.ptr<!u16i>) -> !u32i
// CIR: cir.store [[BITFI]], {{.*}} : !u32i, !cir.ptr<!u32i>
// CIR: [[RET:%.*]] = cir.load {{.*}} : !cir.ptr<!u32i>, !u32i
@@ -115,7 +115,7 @@ void write8_2() {
// CIR-LABEL: @_Z8write8_2v
// CIR: [[CONST3:%.*]] = cir.const #cir.int<3> : !u32i
-// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[2] {name = "f5"} : !cir.ptr<!rec_S1> -> !cir.ptr<!u16i>
+// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[4] {name = "f5"} : !cir.ptr<!rec_S1> -> !cir.ptr<!u16i>
// CIR: cir.set_bitfield align(2) (#bfi_f5, [[MEMBER]] : !cir.ptr<!u16i>, [[CONST3]] : !u32i) -> !u32i
// LLVM-LABEL: @_Z8write8_2v
@@ -163,7 +163,7 @@ unsigned read16_2() {
}
// CIR-LABEL: @_Z8read16_2v
-// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[1] {name = "f2"} : !cir.ptr<!rec_S2> -> !cir.ptr<!u16i>
+// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[2] {name = "f2"} : !cir.ptr<!rec_S2> -> !cir.ptr<!u16i>
// CIR: [[BITFI:%.*]] = cir.get_bitfield align(2) (#bfi_f2, [[MEMBER]] : !cir.ptr<!u16i>) -> !u64i
// CIR: [[BFCAST:%.*]] = cir.cast integral [[BITFI]] : !u64i -> !u32i
// CIR: cir.store [[BFCAST]], {{.*}} : !u32i, !cir.ptr<!u32i>
@@ -209,7 +209,7 @@ void write16_2() {
// CIR-LABEL: @_Z9write16_2v
// CIR: [[CONST5:%.*]] = cir.const #cir.int<5> : !u64i
-// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[1] {name = "f2"} : !cir.ptr<!rec_S2> -> !cir.ptr<!u16i>
+// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[2] {name = "f2"} : !cir.ptr<!rec_S2> -> !cir.ptr<!u16i>
// CIR: cir.set_bitfield align(2) (#bfi_f2, [[MEMBER]] : !cir.ptr<!u16i>, [[CONST5]] : !u64i) -> !u64i
// CIR: cir.return
@@ -226,7 +226,7 @@ unsigned read32_1() {
return a3.f3;
}
// CIR-LABEL: @_Z8read32_1v
-// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[1] {name = "f3"} : !cir.ptr<!rec_S3> -> !cir.ptr<!u32i>
+// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[2] {name = "f3"} : !cir.ptr<!rec_S3> -> !cir.ptr<!u32i>
// CIR: [[BITFI:%.*]] = cir.get_bitfield align(4) (#bfi_f3_1, [[MEMBER]] : !cir.ptr<!u32i>) -> !u64i
// CIR: [[BFCAST:%.*]] = cir.cast integral [[BITFI]] : !u64i -> !u32i
// CIR: cir.store [[BFCAST]], {{.*}} : !u32i, !cir.ptr<!u32i>
@@ -253,7 +253,7 @@ void write32_1() {
// CIR-LABEL: @_Z9write32_1v
// CIR: [[CONST5:%.*]] = cir.const #cir.int<5> : !u64i
-// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[1] {name = "f3"} : !cir.ptr<!rec_S3> -> !cir.ptr<!u32i>
+// CIR: [[MEMBER:%.*]] = cir.get_member {{.*}}[2] {name = "f3"} : !cir.ptr<!rec_S3> -> !cir.ptr<!u32i>
// CIR: cir.set_bitfield align(4) (#bfi_f3_1, [[MEMBER]] : !cir.ptr<!u32i>, [[CONST5]] : !u64i) -> !u64i
// CIR: cir.return
diff --git a/clang/test/CIR/CodeGen/paren-list-agg-init.cpp b/clang/test/CIR/CodeGen/paren-list-agg-init.cpp
index 72bcf2c2e7ac1..ad91b1af0598f 100644
--- a/clang/test/CIR/CodeGen/paren-list-agg-init.cpp
+++ b/clang/test/CIR/CodeGen/paren-list-agg-init.cpp
@@ -41,8 +41,9 @@ struct C : public B, public A {
int c;
};
-// LLVM-DAG: [[STRUCT_D:%.*]] = type { [[STRUCT_A]], [[STRUCT_A]], i8, [[STRUCT_A]] }
-// CIR-DAG: ![[STRUCT_D:.*]] = !cir.struct<"D" {data ![[STRUCT_A]], data ![[STRUCT_A]], empty !u8i, data ![[STRUCT_A]]}>
+// LLVMCIR-DAG: [[STRUCT_D:%.*]] = type { [[STRUCT_A]], [[STRUCT_A]], i8, [0 x i8], [[STRUCT_A]] }
+// OGCG-DAG: [[STRUCT_D:%.*]] = type { [[STRUCT_A]], [[STRUCT_A]], i8, [[STRUCT_A]] }
+// CIR-DAG: ![[STRUCT_D:.*]] = !cir.struct<"D" {data ![[STRUCT_A]], data ![[STRUCT_A]], empty !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, data ![[STRUCT_A]]}>
struct D {
A a;
A b = A{2, 2.0};
@@ -143,9 +144,9 @@ constexpr C c1(b1, a1);
// LLVM-DAG: [[U1:@.*]] = internal constant {{.*}} { [[STRUCT_A]] { i8 1, double 1.000000e+00 } }, align 8
// CIR-DAG: cir.global "private" constant internal dso_local @_ZL2u1 = #cir.const_record<{#cir.const_record<{#cir.int<1> : !s8i, #cir.fp<1.000000e+00> : !cir.double}> : ![[STRUCT_A]]}> : !{{.*}}{alignment = 8 : i64}
constexpr U u1(A(1, 1));
-// LLVMCIR-DAG: [[D1:@.*d1.*]] = internal constant [[STRUCT_D]] { [[STRUCT_A]] { i8 2, double 2.000000e+00 }, [[STRUCT_A]] { i8 2, double 2.000000e+00 }, i8 0, [[STRUCT_A]] zeroinitializer }, align 8
+// LLVMCIR-DAG: [[D1:@.*d1.*]] = internal constant [[STRUCT_D]] { [[STRUCT_A]] { i8 2, double 2.000000e+00 }, [[STRUCT_A]] { i8 2, double 2.000000e+00 }, i8 0, [0 x i8] zeroinitializer, [[STRUCT_A]] zeroinitializer }, align 8
// OGCG-DAG: [[D1:@.*d1.*]] = internal constant { [[STRUCT_A]], [[STRUCT_A]], [8 x i8], [[STRUCT_A]] } { [[STRUCT_A]] { i8 2, double 2.000000e+00 }, [[STRUCT_A]] { i8 2, double 2.000000e+00 }, [8 x i8] {{.*}}, [[STRUCT_A]] zeroinitializer }, align 8
-// CIR-DAG: cir.global "private" constant internal dso_local @_ZL2d1 = #cir.const_record<{#cir.const_record<{#cir.int<2> : !s8i, #cir.fp<2.000000e+00> : !cir.double}> : ![[STRUCT_A]], #cir.const_record<{#cir.int<2> : !s8i, #cir.fp<2.000000e+00> : !cir.double}> : ![[STRUCT_A]], #cir.int<0> : !u8i, #cir.zero : ![[STRUCT_A]]}> : !rec_D {alignment = 8 : i64} loc(#loc284)
+// CIR-DAG: cir.global "private" constant internal dso_local @_ZL2d1 = #cir.const_record<{#cir.const_record<{#cir.int<2> : !s8i, #cir.fp<2.000000e+00> : !cir.double}> : ![[STRUCT_A]], #cir.const_record<{#cir.int<2> : !s8i, #cir.fp<2.000000e+00> : !cir.double}> : ![[STRUCT_A]], #cir.int<0> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 3> x 0>, #cir.zero : ![[STRUCT_A]]}> : !rec_D {alignment = 8 : i64} loc(#loc284)
constexpr D d1(A(2, 2));
// LLVM-DAG: [[ARR1:@.*arr1.*]] = internal constant [3 x i32] [i32 1, i32 2, i32 0], align 4
// CIR-DAG: cir.global "private" constant internal dso_local @_ZL4arr1 = #cir.const_array<[#cir.int<1> : !s32i, #cir.int<2> : !s32i], trailing_zeros> : !cir.array<!s32i x 3> {alignment = 4 : i64}
@@ -278,7 +279,8 @@ U foo6(A a) {
// LLVM-NEXT: store i8 11, ptr [[I1]], align 8
// LLVM-NEXT: [[J2:%.*]] = getelementptr {{.*}}[[STRUCT_A]], ptr [[B]], i32 0, i32 1
// LLVM-NEXT: store double 1.100000e+01, ptr [[J2]], align 8
-// LLVM-NEXT: [[C:%.*]] = getelementptr {{.*}}[[STRUCT_D]], ptr [[D]], i32 0, i32 3
+// LLVMCIR-NEXT: [[C:%.*]] = getelementptr {{.*}}[[STRUCT_D]], ptr [[D]], i32 0, i32 4
+// OGCG-NEXT: [[C:%.*]] = getelementptr {{.*}}[[STRUCT_D]], ptr [[D]], i32 0, i32 3
// LLVM-NEXT: [[I3:%.*]] = getelementptr {{.*}}[[STRUCT_A]], ptr [[C]], i32 0, i32 0
// LLVM-NEXT: store i8 111, ptr [[I3]], align 8
// LLVM-NEXT: [[J4:%.*]] = getelementptr {{.*}}[[STRUCT_A]], ptr [[C]], i32 0, i32 1
@@ -302,7 +304,7 @@ U foo6(A a) {
// CIR: %[[ELEVEN:.*]] = cir.const #cir.int<11> : !s32i
// CIR: %[[ELEVEN_F:.*]] = cir.cast int_to_float %[[ELEVEN]] : !s32i -> !cir.double
// CIR: cir.store align(8) %[[ELEVEN_F]], %[[GET_J]] : !cir.double, !cir.ptr<!cir.double>
-// CIR: %[[GET_C:.*]] = cir.get_member %[[D_ALLOCA]][3] {name = "c"} : !cir.ptr<![[STRUCT_D]]> -> !cir.ptr<![[STRUCT_A]]>
+// CIR: %[[GET_C:.*]] = cir.get_member %[[D_ALLOCA]][4] {name = "c"} : !cir.ptr<![[STRUCT_D]]> -> !cir.ptr<![[STRUCT_A]]>
// CIR: %[[GET_I:.*]] = cir.get_member %[[GET_C]][0] {name = "i"} : !cir.ptr<![[STRUCT_A]]> -> !cir.ptr<!s8i>
// CIR: %[[ONE_ELEVEN:.*]] = cir.const #cir.int<111> : !s8i
// CIR: cir.store align(8) %[[ONE_ELEVEN]], %[[GET_I]] : !s8i, !cir.ptr<!s8i>
@@ -336,7 +338,8 @@ D foo8() {
// LLVM-NEXT: store i8 2, ptr [[I1]], align 8
// LLVM-NEXT: [[J2:%.*]] = getelementptr {{.*}}[[STRUCT_A]], ptr [[B]], i32 0, i32 1
// LLVM-NEXT: store double 2.000000e+00, ptr [[J2]], align 8
-// LLVM-NEXT: [[C:%.*]] = getelementptr {{.*}}[[STRUCT_D]], ptr [[D]], i32 0, i32 3
+// LLVMCIR-NEXT: [[C:%.*]] = getelementptr {{.*}}[[STRUCT_D]], ptr [[D]], i32 0, i32 4
+// OGCG-NEXT: [[C:%.*]] = getelementptr {{.*}}[[STRUCT_D]], ptr [[D]], i32 0, i32 3
// CIR-LABEL: cir.func no_inline dso_local @_Z4foo9v()
// CIR: %[[D_ALLOCA:.*]] = cir.alloca "d" align(8) init : !cir.ptr<![[STRUCT_D]]>
// CIR: %[[GET_A:.*]] = cir.get_member %[[D_ALLOCA]][0] {name = "a"} : !cir.ptr<![[STRUCT_D]]> -> !cir.ptr<![[STRUCT_A]]>
@@ -354,7 +357,7 @@ D foo8() {
// CIR: %[[GET_J:.*]] = cir.get_member %[[GET_B]][1] {name = "j"} : !cir.ptr<![[STRUCT_A]]> -> !cir.ptr<!cir.double>
// CIR: %[[FP_2:.*]] = cir.const #cir.fp<2
// CIR: cir.store align(8) %[[FP_2]], %[[GET_J]] : !cir.double, !cir.ptr<!cir.double>
-// CIR: %[[GET_C:.*]] = cir.get_member %[[D_ALLOCA]][3] {name = "c"} : !cir.ptr<![[STRUCT_D]]> -> !cir.ptr<![[STRUCT_A]]>
+// CIR: %[[GET_C:.*]] = cir.get_member %[[D_ALLOCA]][4] {name = "c"} : !cir.ptr<![[STRUCT_D]]> -> !cir.ptr<![[STRUCT_A]]>
// CIR: %[[ZERO:.*]] = cir.const #cir.zero : ![[STRUCT_A]]
// CIR: cir.store align(8) %[[ZERO]], %[[GET_C]] : ![[STRUCT_A]], !cir.ptr<![[STRUCT_A]]>
void foo9() {
diff --git a/clang/test/CIR/CodeGen/record-member-kinds.c b/clang/test/CIR/CodeGen/record-member-kinds.c
index 3155896137225..1823aca53c522 100644
--- a/clang/test/CIR/CodeGen/record-member-kinds.c
+++ b/clang/test/CIR/CodeGen/record-member-kinds.c
@@ -35,15 +35,15 @@ struct ZeroLenOfEmpty { struct E e; struct E a[0]; };
// CIR-DAG: !rec_ZeroLenOfEmpty = !cir.struct<"ZeroLenOfEmpty" {empty !rec_E, empty !cir.array<!rec_E x 0>}>
struct UnnamedBitOnly { int : 8; };
-// CIR-DAG: !rec_UnnamedBitOnly = !cir.struct<"UnnamedBitOnly" {empty !u8i}>
+// CIR-DAG: !rec_UnnamedBitOnly = !cir.struct<"UnnamedBitOnly" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>}>
struct UnnamedBitThenField { int : 8; int f; };
-// CIR-DAG: !rec_UnnamedBitThenField = !cir.struct<"UnnamedBitThenField" {empty !u8i, data !s32i}>
+// CIR-DAG: !rec_UnnamedBitThenField = !cir.struct<"UnnamedBitThenField" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, data !s32i}>
// The trailing unit is narrower than its bit-field's declared type and is not
// pad, so it stays in the data size.
struct NamedFieldThenUnnamedBit { char c; int : 24; };
-// CIR-DAG: !rec_NamedFieldThenUnnamedBit = !cir.struct<"NamedFieldThenUnnamedBit" {data !s8i, empty !cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_NamedFieldThenUnnamedBit = !cir.struct<"NamedFieldThenUnnamedBit" {data !s8i, empty !cir.array<!u8i x 3>, bitfield !cir.array<!u8i x 0>}>
// The discrete ms_struct path allocates a unit per formal type. A unit whose
// only occupant is unnamed holds no data.
@@ -79,7 +79,7 @@ struct MsZeroWidthSplit2 { int : 3; int : 0; int b : 3; } __attribute__((ms_stru
// CIR-DAG: !rec_MsZeroWidthSplit2 = !cir.struct<"MsZeroWidthSplit2" {empty !s32i, bitfield !cir.array<!s32i x 0>, bitfield !s32i}>
union UnnamedBitUnion { int : 8; };
-// CIR-DAG: !rec_UnnamedBitUnion = !cir.union<"UnnamedBitUnion" {empty !u8i}>
+// CIR-DAG: !rec_UnnamedBitUnion = !cir.union<"UnnamedBitUnion" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>}>
union ContainsEmptyUnion { struct E e; };
// CIR-DAG: !rec_ContainsEmptyUnion = !cir.union<"ContainsEmptyUnion" {empty !rec_E}>
@@ -87,13 +87,13 @@ union ContainsEmptyUnion { struct E e; };
// The two pairs that follow are byte-identical apart from their marks, in a
// struct and in a union alike.
struct BitWideUnit { long long x : 32; } __attribute__((aligned(16)));
-// CIR-DAG: !rec_BitWideUnit = !cir.struct<"BitWideUnit" {bitfield !u32i, pad !cir.array<!u8i x 12>}>
+// CIR-DAG: !rec_BitWideUnit = !cir.struct<"BitWideUnit" {bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>, pad !cir.array<!u8i x 12>}>
struct UIntOverAligned { unsigned x; } __attribute__((aligned(16)));
// CIR-DAG: !rec_UIntOverAligned = !cir.struct<"UIntOverAligned" {data !u32i, pad !cir.array<!u8i x 12>}>
union BitUnit { unsigned a : 1; unsigned b : 1; };
-// CIR-DAG: !rec_BitUnit = !cir.union<"BitUnit" {bitfield !u8i, bitfield !u8i}, padding = {!cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_BitUnit = !cir.union<"BitUnit" {bitfield !u8i, bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>}, padding = {!cir.array<!u8i x 3>}>
union UCharOverAligned { unsigned char c, d; } __attribute__((aligned(4)));
// CIR-DAG: !rec_UCharOverAligned = !cir.union<"UCharOverAligned" {data !u8i, data !u8i}, padding = {!cir.array<!u8i x 3>}>
diff --git a/clang/test/CIR/CodeGen/record-member-kinds.cpp b/clang/test/CIR/CodeGen/record-member-kinds.cpp
index 0ee7ac407d240..c2206f221fa36 100644
--- a/clang/test/CIR/CodeGen/record-member-kinds.cpp
+++ b/clang/test/CIR/CodeGen/record-member-kinds.cpp
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -emit-cir %s -o - | FileCheck %s --check-prefix=CIR
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -emit-llvm %s -o - | FileCheck %s --check-prefix=LLVM
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -emit-llvm %s -o - | FileCheck %s --check-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -emit-llvm %s -o - | FileCheck %s --check-prefixes=LLVM,LLVMCIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -emit-llvm %s -o - | FileCheck %s --check-prefixes=LLVM,OGCG
struct Empty {};
// CIR-DAG: !rec_Empty = !cir.struct<"Empty" {pad !u8i}>
@@ -38,7 +38,7 @@ union NuaDerivesNonEmptyUnion { [[no_unique_address]] DerivesNonEmpty d; int i;
// A base holding only unnamed bit-fields is laid out but carries no ABI data,
// which CXXRecordDecl::isEmpty() does not report.
struct BitFieldBase { int : 3; };
-// CIR-DAG: !rec_BitFieldBase = !cir.struct<"BitFieldBase" {empty !u8i}>
+// CIR-DAG: !rec_BitFieldBase = !cir.struct<"BitFieldBase" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>}>
struct DerivesBitFieldBase : BitFieldBase { int i; };
// CIR-DAG: !rec_DerivesBitFieldBase = !cir.struct<"DerivesBitFieldBase" {empty !rec_BitFieldBase, data !s32i}>
@@ -67,7 +67,7 @@ struct AlignasTail { char c; alignas(8) int i; };
// An unnamed bit-field unit is declared storage that holds no ABI data.
struct OnlyUnnamedBit { int : 24; };
-// CIR-DAG: !rec_OnlyUnnamedBit = !cir.struct<"OnlyUnnamedBit" {empty !cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_OnlyUnnamedBit = !cir.struct<"OnlyUnnamedBit" {empty !cir.array<!u8i x 3>, bitfield !cir.array<!u8i x 0>}>
// A unit with a named occupant holds data, whichever order the occupants come
// in, and however the storage is spelled.
@@ -75,19 +75,19 @@ struct NamedClipped { int i; int j : 24; };
// CIR-DAG: !rec_NamedClipped = !cir.struct<"NamedClipped" {data !s32i, bitfield !u32i}>
struct NamedFirst { int a : 8; int : 16; };
-// CIR-DAG: !rec_NamedFirst = !cir.struct<"NamedFirst" {bitfield !u32i}>
+// CIR-DAG: !rec_NamedFirst = !cir.struct<"NamedFirst" {bitfield !u32i, bitfield !cir.array<!u8i x 0>}>
struct UnnamedFirst { int : 16; int a : 8; };
-// CIR-DAG: !rec_UnnamedFirst = !cir.struct<"UnnamedFirst" {bitfield !u32i}>
+// CIR-DAG: !rec_UnnamedFirst = !cir.struct<"UnnamedFirst" {bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 2> x 0>}>
// A zero-length bit-field separates one span into two units and becomes a
// member of its own. A record can carry a data unit and an empty unit at
// once, in either order.
struct SpanMixed { int a : 3; int : 0; int : 3; };
-// CIR-DAG: !rec_SpanMixed = !cir.struct<"SpanMixed" {bitfield !u8i, pad !cir.array<!u8i x 3>, bitfield !cir.array<!s32i x 0>, empty !u8i, pad !cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_SpanMixed = !cir.struct<"SpanMixed" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, pad !cir.array<!u8i x 3>, bitfield !cir.array<!s32i x 0>, empty !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, pad !cir.array<!u8i x 3>}>
struct SpanEmptyFirst { int : 3; int : 0; int b : 3; };
-// CIR-DAG: !rec_SpanEmptyFirst = !cir.struct<"SpanEmptyFirst" {empty !u8i, pad !cir.array<!u8i x 3>, bitfield !cir.array<!s32i x 0>, bitfield !u8i, pad !cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_SpanEmptyFirst = !cir.struct<"SpanEmptyFirst" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, pad !cir.array<!u8i x 3>, bitfield !cir.array<!s32i x 0>, bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, pad !cir.array<!u8i x 3>}>
// One unit covering both of these would need more than one register, so they
// split into two units that are marked independently.
@@ -101,7 +101,7 @@ struct WideSpanAllEmpty { unsigned long : 64; unsigned long : 64; };
// CIR-DAG: !rec_WideSpanAllEmpty = !cir.struct<"WideSpanAllEmpty" {empty !u64i, empty !u64i}>
union UnnamedBitUnion { int : 8; };
-// CIR-DAG: !rec_UnnamedBitUnion = !cir.union<"UnnamedBitUnion" {empty !u8i}>
+// CIR-DAG: !rec_UnnamedBitUnion = !cir.union<"UnnamedBitUnion" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>}>
union NoMemberUnion {};
// CIR-DAG: !rec_NoMemberUnion = !cir.union<"NoMemberUnion" {}, padding = {!u8i}>
@@ -119,15 +119,17 @@ struct HasNearlyEmptyVBase : virtual NearlyEmptyVBase { int i; };
// Only the pad member is reusable, so the unit stays in the base subobject type
// while the byte after it does not. A named unit stays the same way.
struct Clipped { Clipped(const Clipped &); int i; int : 24; };
-// CIR-DAG: !rec_Clipped = !cir.struct<"Clipped" packed {data !s32i, empty !cir.array<!u8i x 3>, pad !u8i}>
-// CIR-DAG: !rec_Clipped2Ebase = !cir.struct<"Clipped.base" packed {data !s32i, empty !cir.array<!u8i x 3>}>
+// CIR-DAG: !rec_Clipped = !cir.struct<"Clipped" packed {data !s32i, empty !cir.array<!u8i x 3>, bitfield !cir.array<!u8i x 0>, pad !u8i}>
+// CIR-DAG: !rec_Clipped2Ebase = !cir.struct<"Clipped.base" packed {data !s32i, empty !cir.array<!u8i x 3>, bitfield !cir.array<!u8i x 0>}>
struct NamedClippedTail { NamedClippedTail(const NamedClippedTail &); int i; int j : 24; };
-// CIR-DAG: !rec_NamedClippedTail = !cir.struct<"NamedClippedTail" packed {data !s32i, bitfield !cir.array<!u8i x 3>, pad !u8i}>
+// CIR-DAG: !rec_NamedClippedTail = !cir.struct<"NamedClippedTail" packed {data !s32i, bitfield !cir.array<!u8i x 3>, bitfield !cir.array<!u8i x 0>, pad !u8i}>
struct DerivedClipped : Clipped { char c; };
// CIR-DAG: !rec_DerivedClipped = !cir.struct<"DerivedClipped" {data !rec_Clipped2Ebase, data !s8i}>
-// LLVM-DAG: %struct.Clipped.base = type <{ i32, [3 x i8] }>
+// A declared reach lowers to a zero-length member with no classic counterpart.
+// LLVMCIR-DAG: %struct.Clipped.base = type <{ i32, [3 x i8], [0 x i8] }>
+// OGCG-DAG: %struct.Clipped.base = type <{ i32, [3 x i8] }>
// LLVM-DAG: %struct.DerivedClipped = type { %struct.Clipped.base, i8 }
// Name every record so that its CIR type reaches the output.
diff --git a/clang/test/CIR/CodeGen/record-zero-init-padding.c b/clang/test/CIR/CodeGen/record-zero-init-padding.c
index 97ea5087c3746..eba99f95d06fa 100644
--- a/clang/test/CIR/CodeGen/record-zero-init-padding.c
+++ b/clang/test/CIR/CodeGen/record-zero-init-padding.c
@@ -35,7 +35,7 @@ void test_zero_init_padding(void) {
}
// Type definitions for anonymous structs with padding
-// CIR-DAG: !rec_bitfield_with_padding = !cir.struct<"bitfield_with_padding" {bitfield !u8i, data !s32i}>
+// CIR-DAG: !rec_bitfield_with_padding = !cir.struct<"bitfield_with_padding" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>, data !s32i}>
// CIR-DAG: !rec_multiple_padding = !cir.struct<"multiple_padding" {data !s8i, data !s16i, data !s64i}>
// CIR-DAG: !rec_padding_after_field = !cir.struct<"padding_after_field" {data !s8i, data !s32i}>
// CIR-DAG: !rec_tail_padding = !cir.struct<"tail_padding" {data !s32i, data !s8i}>
@@ -44,7 +44,7 @@ void test_zero_init_padding(void) {
// CIR-DAG: cir.global "private" constant internal dso_local @test_zero_init_padding.paf = #cir.const_record<{#cir.int<1> : !s8i, #cir.int<42> : !s32i}> : !rec_padding_after_field
// bfp: unsigned bitfield byte + 3 bytes padding + int
-// CIR-DAG: cir.global "private" constant internal dso_local @test_zero_init_padding.bfp = #cir.const_record<{#cir.int<17> : !u8i, #cir.int<99> : !s32i}> : !rec_bitfield_with_padding
+// CIR-DAG: cir.global "private" constant internal dso_local @test_zero_init_padding.bfp = #cir.const_record<{#cir.int<17> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.int<99> : !s32i}> : !rec_bitfield_with_padding
// tp: int + char + 3 bytes tail padding
// CIR-DAG: cir.global "private" constant internal dso_local @test_zero_init_padding.tp = #cir.const_record<{#cir.int<10> : !s32i, #cir.int<20> : !s8i}> : !rec_tail_padding
@@ -56,7 +56,7 @@ void test_zero_init_padding(void) {
// CIR: cir.return
// LLVM-DAG: @test_zero_init_padding.paf = internal constant %struct.padding_after_field { i8 1, i32 42 }
-// LLVM-DAG: @test_zero_init_padding.bfp = internal constant %struct.bitfield_with_padding { i8 17, i32 99 }
+// LLVM-DAG: @test_zero_init_padding.bfp = internal constant %struct.bitfield_with_padding { i8 17, [0 x i8] zeroinitializer, i32 99 }
// LLVM-DAG: @test_zero_init_padding.tp = internal constant %struct.tail_padding { i32 10, i8 20 }
// LLVM-DAG: @test_zero_init_padding.mp = internal constant %struct.multiple_padding { i8 5, i16 10, i64 100 }
diff --git a/clang/test/CIR/CodeGen/struct-init.cpp b/clang/test/CIR/CodeGen/struct-init.cpp
index d602b928a7734..aebde4506e322 100644
--- a/clang/test/CIR/CodeGen/struct-init.cpp
+++ b/clang/test/CIR/CodeGen/struct-init.cpp
@@ -19,8 +19,8 @@ BitfieldStruct overlapping_init = { 3, 2, 1 };
// This is unintuitive. The bitfields are initialized using a struct of constants
// that maps to the bitfields but splits the value into bytes.
-// CIR: cir.global external @overlapping_init = #cir.const_record<{#cir.int<262179> : !u32i}> : !rec_BitfieldStruct
-// LLVM: @overlapping_init = global %struct.BitfieldStruct { i32 262179 }
+// CIR: cir.global external @overlapping_init = #cir.const_record<{#cir.int<262179> : !u32i, #cir.zero : !cir.array<!cir.array<!u8i x 3> x 0>}> : !rec_BitfieldStruct
+// LLVM: @overlapping_init = global %struct.BitfieldStruct { i32 262179, [0 x i8] zeroinitializer }
// OGCG: @overlapping_init = global { i8, i8, i8, i8 } { i8 35, i8 0, i8 4, i8 0 }
struct S {
@@ -56,8 +56,8 @@ StructWithFieldInitFromConst swfifc = {};
StructWithFieldInitFromConst swfifc2 = { 2 };
-// CIR: cir.global external @swfifc2 = #cir.const_record<{#cir.int<2> : !u16i, #cir.int<2> : !s32i}> : !rec_StructWithFieldInitFromConst
-// LLVM: @swfifc2 = global %struct.StructWithFieldInitFromConst { i16 2, i32 2 }, align 4
+// CIR: cir.global external @swfifc2 = #cir.const_record<{#cir.int<2> : !u16i, #cir.zero : !cir.array<!cir.array<!u8i x 2> x 0>, #cir.int<2> : !s32i}> : !rec_StructWithFieldInitFromConst
+// LLVM: @swfifc2 = global %struct.StructWithFieldInitFromConst { i16 2, [0 x i8] zeroinitializer, i32 2 }, align 4
// OGCG: @swfifc2 = global { i8, i8, i32 } { i8 2, i8 0, i32 2 }, align 4
diff --git a/clang/test/CIR/CodeGen/union-agg-init.c b/clang/test/CIR/CodeGen/union-agg-init.c
index e2de285a85124..c5d5027ab3d5d 100644
--- a/clang/test/CIR/CodeGen/union-agg-init.c
+++ b/clang/test/CIR/CodeGen/union-agg-init.c
@@ -43,8 +43,9 @@ struct Anon anon = { 101, 1 };
struct Bitfields { int a : 3; int b : 4; union PtrToIntUnion u; };
struct Bitfields bitfields = { 1, 2, { 9 } };
-// CIR-DAG: cir.global external @bitfields = #cir.const_record<{#cir.int<17> : !u8i, #cir.const_record<{#cir.int<9> : !s32i}> : !rec_PtrToIntUnion}> : !rec_Bitfields {alignment = 8 : i64} loc(#loc42)
-// LLVM-DAG: @bitfields = global { i8, [7 x i8], { i32, [4 x i8] } } { i8 17, [7 x i8] zeroinitializer, { i32, [4 x i8] } { i32 9, [4 x i8] zeroinitializer } }
+// CIR-DAG: cir.global external @bitfields = #cir.const_record<{#cir.int<17> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.const_record<{#cir.int<9> : !s32i}> : !rec_PtrToIntUnion}> : !rec_Bitfields {alignment = 8 : i64} loc(#loc42)
+// LLVMCIR-DAG: @bitfields = global { i8, [0 x i8], [7 x i8], { i32, [4 x i8] } } { i8 17, [0 x i8] zeroinitializer, [7 x i8] zeroinitializer, { i32, [4 x i8] } { i32 9, [4 x i8] zeroinitializer } }
+// OGCG-DAG: @bitfields = global { i8, [7 x i8], { i32, [4 x i8] } } { i8 17, [7 x i8] zeroinitializer, { i32, [4 x i8] } { i32 9, [4 x i8] zeroinitializer } }
struct FamUnion { int n; union PtrToIntUnion u; char fam[]; };
struct FamUnion fam_union = { 3, { 7 }, { 'a','b','c' } };
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir
index 7da3a76abc494..12df6ccf41281 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-aggregate-nyi.cir
@@ -11,12 +11,7 @@
!rec_UByteBlobs = !cir.union<"UByteBlobs" {data !u8i, data !u8i}, padding = {!cir.array<!u8i x 3>}>
!rec_SWrapsOverAligned = !cir.struct<"SWrapsOverAligned" {data !cir.double, data !rec_UOverAligned}>
!rec_UEmptyLarge = !cir.union<"UEmptyLarge" {}, padding = {!cir.array<!u8i x 32>}>
-!rec_BFPad = !cir.struct<"BFPad" packed {bitfield !u8i, data !s32i, pad !cir.array<!u8i x 3>}>
!rec_ZeroLenArr = !cir.struct<"ZeroLenArr" packed {data !s8i, empty !cir.array<!s32i x 0>}>
-!rec_NamedPlusZeroWidth =
- !cir.struct<"NamedPlusZeroWidth" {bitfield !u8i, pad !cir.array<!u8i x 3>,
- bitfield !cir.array<!s32i x 0>,
- data !s32i, pad !cir.array<!u8i x 8>}>
!rec_UPadByte = !cir.union<"UPadByte" {data !u8i}, padding = {!cir.array<!u8i x 3>}>
!rec_E = !cir.struct<"E" {pad !u8i}>
!rec_UBitEmpty = !cir.union<"UBitEmpty" {data !cir.array<!rec_E x 4>, bitfield !u8i}>
@@ -26,10 +21,6 @@
!rec_UEmptyNarrow = !cir.union<"UEmptyNarrow" {data !rec_E, data !s16i}, padding = {!cir.array<!u8i x 2>}>
!rec_S1 = !cir.struct<"S1" {data !s16i, data !s16i, data !s16i}>
!rec_AtomicWrapper = !cir.struct<{data !rec_S1, pad !cir.array<!s8i x 2>}>
-!rec_BitPad = !cir.struct<"BitPad" {bitfield !u8i, pad !cir.array<!u8i x 15>}>
-!rec_InnerBits = !cir.struct<"InnerBits" {bitfield !u32i}>
-!rec_OuterBitPad = !cir.struct<"OuterBitPad" {data !rec_InnerBits, pad !cir.array<!u8i x 12>}>
-!rec_ArrBitPad = !cir.struct<"ArrBitPad" {data !cir.array<!rec_InnerBits x 2>, pad !cir.array<!u8i x 8>}>
!rec_HoldsAllPad = !cir.struct<"HoldsAllPad" {data !s32i, empty !rec_E}>
!rec_EBits = !cir.struct<"EBits" {empty !u32i}>
!rec_HoldsEmptyBits = !cir.struct<"HoldsEmptyBits" {empty !rec_EBits, data !s32i}>
@@ -88,16 +79,6 @@ module attributes {
// CHECK: not yet implemented for type '!cir.union<"UEmptyLarge"
- // The unit-width rule keys on the padding rather than the packing, so a
- // packed record still hits it once a pad member gives classic a gap to read
- // the declared type through. Classic sends this one to memory, so the
- // rejection is conservative rather than a divergence avoided.
- cir.func @take_bf_pad(%arg0: !rec_BFPad) {
- cir.return
- }
-
- // CHECK: not yet implemented for type '!cir.struct<"BFPad" packed
-
// A zero-sized member is dropped before classification, so its offset never
// reaches the rule sending a record with a member off its own alignment to
// memory. Only packing can put one at such an offset.
@@ -154,30 +135,6 @@ module attributes {
// CHECK: not yet implemented for type '!cir.union<"UEmptyNarrow"
- // A bit-field access unit is narrower than the declaration it holds, so
- // classifying around this record's padding would coerce to i8 where classic
- // CodeGen widens to i64.
- cir.func @take_bit_pad(%arg0: !rec_BitPad) {
- cir.return
- }
-
- // CHECK: not yet implemented for type '!cir.struct<"BitPad" {bitfield
-
- // The reject reaches through a member record. Classic coerces this one to
- // i32, so the rejection is conservative rather than a divergence avoided.
- cir.func @take_outer_bit_pad(%arg0: !rec_OuterBitPad) {
- cir.return
- }
-
- // CHECK: not yet implemented for type '!cir.struct<"OuterBitPad" {data
-
- // And through an array element.
- cir.func @take_arr_bit_pad(%arg0: !rec_ArrBitPad) {
- cir.return
- }
-
- // CHECK: not yet implemented for type '!cir.struct<"ArrBitPad" {data
-
// The all-pad reject also has to hold when the record is reached as a member,
// which is the shape a C++ empty class produces.
cir.func @take_holds_all_pad(%arg0: !rec_HoldsAllPad) {
@@ -249,14 +206,6 @@ module attributes {
// CHECK: not yet implemented for type '!cir.vector<2 x !cir.long_double<!cir.f80>>
- // A zero-width bit-field no longer refuses a padded record, but a named
- // access unit still does, and one record can carry both.
- cir.func @take_named_plus_zero_width(%arg0: !rec_NamedPlusZeroWidth) {
- cir.return
- }
-
- // CHECK: not yet implemented for type '!cir.struct<"NamedPlusZeroWidth"
-
// A definition (unlike a declaration) is refused: no incomplete-by-value
// definition can arise from valid C++, so this stays a hard reject rather
// than the declaration-only skip in x86_64-incomplete-record-declaration.cir.
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-reach.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-reach.cir
new file mode 100644
index 0000000000000..91efeefc9dac8
--- /dev/null
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-reach.cir
@@ -0,0 +1,80 @@
+// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
+
+!u8i = !cir.int<u, 8>
+!u32i = !cir.int<u, 32>
+!u64i = !cir.int<u, 64>
+
+// A unit whose declarations stop at its own end.
+!rec_UnitOnly = !cir.struct<"UnitOnly" {bitfield !u32i, pad !cir.array<!u8i x 12>}>
+
+// The same shape, with the declared reach carried past the unit.
+!rec_Reach = !cir.struct<"Reach" {bitfield !u32i,
+ bitfield !cir.array<!cir.array<!u8i x 8> x 0>,
+ pad !cir.array<!u8i x 12>}>
+
+// Over two eightbytes, so memory whatever the reach says.
+!rec_BigReach = !cir.struct<"BigReach" {data !u64i, data !u64i, bitfield !u8i,
+ bitfield !cir.array<!cir.array<!u8i x 4> x 0>,
+ pad !cir.array<!u8i x 7>}>
+
+// A union whose storage is narrower than the declaration it holds.
+!rec_UnionReach = !cir.union<"UnionReach" {bitfield !u8i,
+ bitfield !cir.array<!cir.array<!u8i x 4> x 0>},
+ padding = {!cir.array<!u8i x 3>}>
+
+module attributes {
+ dlti.dl_spec = #dlti.dl_spec<
+ #dlti.dl_entry<i32, dense<32>: vector<2xi64>>,
+ #dlti.dl_entry<i64, dense<64>: vector<2xi64>>,
+ #dlti.dl_entry<f32, dense<32>: vector<2xi64>>,
+ #dlti.dl_entry<f64, dense<64>: vector<2xi64>>,
+ #dlti.dl_entry<"dlti.endianness", "little">
+ >,
+ cir.triple = "x86_64-unknown-linux-gnu"
+} {
+ // With nothing reaching past the unit, the bytes after it are padding and
+ // the coercion is the unit's own width.
+ cir.func @take_unit_only(%arg0: !rec_UnitOnly) {
+ cir.return
+ }
+
+ // CHECK: cir.func{{.*}} @take_unit_only(%arg0: !u32i)
+
+ // The declared reach makes those same bytes user data, which widens the
+ // coercion to the eightbyte holding them.
+ cir.func @take_reach(%arg0: !rec_Reach) {
+ cir.return
+ }
+
+ // CHECK: cir.func{{.*}} @take_reach(%arg0: !u64i)
+
+ cir.func @return_reach(%arg0: !rec_Reach) -> !rec_Reach {
+ %0 = cir.alloca "a" align(16) : !cir.ptr<!rec_Reach>
+ cir.store %arg0, %0 : !rec_Reach, !cir.ptr<!rec_Reach>
+ %1 = cir.load %0 : !cir.ptr<!rec_Reach>, !rec_Reach
+ cir.return %1 : !rec_Reach
+ }
+
+ // CHECK: cir.func{{.*}} @return_reach(%arg0: !u64i) -> !u64i
+
+ cir.func @take_big_reach(%arg0: !rec_BigReach) {
+ cir.return
+ }
+
+ // CHECK: cir.func{{.*}} @take_big_reach(%arg0: !cir.ptr<!rec_BigReach> {llvm.align = 8 : i64, llvm.byval = !rec_BigReach, llvm.noalias, llvm.noundef})
+
+ cir.func @return_big_reach(%arg0: !rec_BigReach) -> !rec_BigReach {
+ %0 = cir.alloca "a" align(8) : !cir.ptr<!rec_BigReach>
+ cir.store %arg0, %0 : !rec_BigReach, !cir.ptr<!rec_BigReach>
+ %1 = cir.load %0 : !cir.ptr<!rec_BigReach>, !rec_BigReach
+ cir.return %1 : !rec_BigReach
+ }
+
+ // CHECK: cir.func{{.*}} @return_big_reach(%arg0: !cir.ptr<!rec_BigReach> {llvm.align = 8 : i64, llvm.dead_on_unwind, llvm.noalias, llvm.sret = !rec_BigReach, llvm.writable}, %arg1: !cir.ptr<!rec_BigReach> {llvm.align = 8 : i64, llvm.byval = !rec_BigReach, llvm.noalias, llvm.noundef})
+
+ cir.func @take_union_reach(%arg0: !rec_UnionReach) {
+ cir.return
+ }
+
+ // CHECK: cir.func{{.*}} @take_union_reach(%arg0: !u32i)
+}
>From 107b13f8aae31afce2a991c89acf6ae9255502d6 Mon Sep 17 00:00:00 2001
From: Adam Smith <adams at nvidia.com>
Date: Wed, 2 Sep 2026 05:43:53 -0700
Subject: [PATCH 2/2] [CIR][NFC] Clarify comments and replace reach with extent
Assisted-by: Cursor / claude-opus-5
---
.../CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp | 49 ++++++------
.../Transforms/CallConvLoweringPass.cpp | 12 +--
.../test/CIR/CodeGen/anonymous-nested-init.c | 2 +-
...-conv-lowering-x86_64-bitfield-extent.cpp} | 33 ++++----
.../call-conv-lowering-x86_64-packed.c | 2 +-
.../test/CIR/CodeGen/record-member-kinds.cpp | 2 +-
.../abi-lowering/x86_64-bitfield-extent.cir | 80 +++++++++++++++++++
.../abi-lowering/x86_64-bitfield-reach.cir | 80 -------------------
8 files changed, 132 insertions(+), 128 deletions(-)
rename clang/test/CIR/CodeGen/{call-conv-lowering-x86_64-bitfield-reach.cpp => call-conv-lowering-x86_64-bitfield-extent.cpp} (88%)
create mode 100644 clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-extent.cir
delete mode 100644 clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-reach.cir
diff --git a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
index d98e23700a00e..10f49580da1d9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp
@@ -80,17 +80,18 @@ struct CIRRecordLowering final {
cir::RecordMemberKind::BitField);
}
- /// A member recording that declared types reach \p excessInBits past where
- /// it sits. An access unit's width is the compiler's choice, so it can be
- /// narrower than the types declared in it, and the ABI reads that reach to
- /// tell the bytes after the unit from padding. A zero-length array holds
- /// no storage, and `isZeroWidthBitField` answers true for it as well as for
- /// a zero-width bit-field, so the layout walks pass over both.
+ /// An access unit can be narrower than the types its bit-fields were
+ /// declared with, so the unit's extent does not say how far the declared
+ /// data runs. This member carries the difference: the declared extent ends
+ /// \p excessInBits past \p offset. It holds no storage, taking the same
+ /// zero-length-array shape as a zero-width bit-field so the record layout
+ /// walks skip it.
///
- /// The bits counted are those past the member, not past the unit: a
- /// zero-sized member reports the offset where the storage ahead of it ends,
- /// so a caller measuring from anywhere else claims bytes twice.
- MemberInfo makeDeclaredReachInfo(CharUnits offset, uint64_t excessInBits) {
+ /// \p excessInBits is measured from \p offset, not from the start of the
+ /// access unit. A zero-sized member takes the offset where the preceding
+ /// storage ends, so measuring from the unit's start would count the unit's
+ /// own bytes twice.
+ MemberInfo makeDeclaredExtentInfo(CharUnits offset, uint64_t excessInBits) {
unsigned charBits = astContext.getCharWidth();
CharUnits excess = bitsToCharUnits(excessInBits + charBits - 1);
return makeStorageInfo(offset,
@@ -668,7 +669,7 @@ CIRRecordLowering::accumulateBitFields(RecordDecl::field_iterator field,
members[storageIdx].memberKind = cir::RecordMemberKind::BitField;
// An unnamed bit-field supplies no eightbyte class, but the bytes
// its declared type covers still hold user data, so every bit-field
- // in the unit counts toward the reach.
+ // in the unit counts toward the declared extent.
declaredEndBits = std::max(
declaredEndBits, getFieldBitOffset(*begin) +
astContext.getTypeSize(begin->getType()));
@@ -684,7 +685,7 @@ CIRRecordLowering::accumulateBitFields(RecordDecl::field_iterator field,
uint64_t unitEndBits =
astContext.toBits(beginOffset) + astContext.toBits(accessSize);
if (declaredEndBits > unitEndBits)
- members.push_back(makeDeclaredReachInfo(
+ members.push_back(makeDeclaredExtentInfo(
beginOffset + accessSize, declaredEndBits - unitEndBits));
}
// Reset to start a new span.
@@ -1024,7 +1025,7 @@ void CIRRecordLowering::lowerUnion(bool nonVirtualBaseType) {
// storage type and padding is.
// First, accumulate all the types.
- uint64_t declaredReachBits = 0;
+ uint64_t declaredExtentBits = 0;
uint64_t widestMemberBits = 0;
for (const FieldDecl *field : recordDecl->fields()) {
mlir::Type fieldType;
@@ -1033,8 +1034,8 @@ void CIRRecordLowering::lowerUnion(bool nonVirtualBaseType) {
continue;
fieldType = getBitfieldStorageType(field->getBitWidthValue());
setBitFieldInfo(field, CharUnits::Zero(), fieldType);
- declaredReachBits =
- std::max(declaredReachBits, astContext.getTypeSize(field->getType()));
+ declaredExtentBits = std::max(declaredExtentBits,
+ astContext.getTypeSize(field->getType()));
} else {
fieldType = getStorageType(field);
}
@@ -1046,10 +1047,10 @@ void CIRRecordLowering::lowerUnion(bool nonVirtualBaseType) {
}
// A union's members all start at offset zero, so one member holding the
- // furthest declared reach speaks for the whole union. Record it only when
+ // furthest declared extent speaks for the whole union. Record it only when
// it says something no member already does, which is when a bit-field's
// declared type outruns every member's storage.
- bool reachOutrunsMembers = declaredReachBits > widestMemberBits;
+ bool extentOutrunsMembers = declaredExtentBits > widestMemberBits;
// Compute zero-initializable status.
// This union might not be zero initialized: it may contain a pointer to
@@ -1091,12 +1092,12 @@ void CIRRecordLowering::lowerUnion(bool nonVirtualBaseType) {
// The member records only the bits past where it sits, and what precedes it
// differs by layout: the base subobject below is built as a struct, so the
// storage type comes first, while in a union proper every member is at zero.
- auto addDeclaredReach = [&](uint64_t claimedBits) {
- if (!reachOutrunsMembers || declaredReachBits <= claimedBits)
+ auto addDeclaredExtent = [&](uint64_t claimedBits) {
+ if (!extentOutrunsMembers || declaredExtentBits <= claimedBits)
return;
- MemberInfo reach = makeDeclaredReachInfo(bitsToCharUnits(claimedBits),
- declaredReachBits - claimedBits);
- addField(reach.data, reach.memberKind);
+ MemberInfo extent = makeDeclaredExtentInfo(
+ bitsToCharUnits(claimedBits), declaredExtentBits - claimedBits);
+ addField(extent.data, extent.memberKind);
};
// The base-subobject record is built as a struct from fieldTypes, so add
@@ -1115,12 +1116,12 @@ void CIRRecordLowering::lowerUnion(bool nonVirtualBaseType) {
cir::isBitFieldAccessUnit));
clearFields();
addField(storageType, storageKind);
- addDeclaredReach(astContext.toBits(getSize(storageType)));
+ addDeclaredExtent(astContext.toBits(getSize(storageType)));
CharUnits padding = layoutSize - getSize(storageType);
if (!padding.isZero())
addField(getByteArrayType(padding), cir::RecordMemberKind::Pad);
} else {
- addDeclaredReach(/*claimedBits=*/0);
+ addDeclaredExtent(/*claimedBits=*/0);
// Else we just add padding normally.
appendPaddingBytes(layoutSize - getSize(storageType));
}
diff --git a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
index 4f33004c8e4f8..314744d059e6b 100644
--- a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
@@ -79,7 +79,7 @@ namespace {
// of two. Other vectors, a record holding an empty-for-ABI member that
// occupies bytes or a zero-sized one off its own alignment, a union no member
// of which spans its declared size, and a union with a bit-field access unit
-// no spanning member of which supplies data or records a declared reach are
+// no spanning member of which supplies data or records a declared extent are
// reported NYI by classifyX86_64Function so an unsupported signature fails
// the pass instead of being misclassified.
//===----------------------------------------------------------------------===//
@@ -223,9 +223,9 @@ static bool isSupportedType(mlir::Type ty, const DataLayout &dl) {
if (recordBits > 128)
return false;
} else {
- // A member recording a bit-field's declared reach occupies no storage
+ // A member recording a bit-field's declared extent occupies no storage
// of its own, so its element type is what covers the union's bytes.
- // That reach can outrun the union, which a real member never does,
+ // That extent can outrun the union, which a real member never does,
// hence the comparison is not an equality.
llvm::ArrayRef<cir::RecordMemberKind> kinds = recTy.getMemberKinds();
auto spansRecord = [&](mlir::Type m, cir::RecordMemberKind k) {
@@ -242,7 +242,7 @@ static bool isSupportedType(mlir::Type ty, const DataLayout &dl) {
// A bit-field access unit's width may not match the bits it actually
// stores, so some member (the unit itself or another one) must match
// the union's size and either hold data or record how far the
- // declared types in it reach.
+ // declared types in it extend.
if (llvm::any_of(kinds, cir::isBitFieldAccessUnit) &&
!llvm::any_of(llvm::zip_equal(members, kinds),
[&](const auto &pair) {
@@ -408,7 +408,7 @@ static const llvm::abi::Type *mapCIRType(mlir::Type type,
// and a member's presence alone cannot say both.
auto addMember = [&](mlir::Type fieldTy, cir::RecordMemberKind kind,
uint64_t offsetBits) {
- // A zero-width bit-field and a declared reach occupy nothing, so
+ // A zero-width bit-field and a declared extent occupy nothing, so
// what the ABI counts is the element type they carry.
mlir::Type countedTy = fieldTy;
bool isUnnamedUnit = kind == cir::RecordMemberKind::Empty;
@@ -438,7 +438,7 @@ static const llvm::abi::Type *mapCIRType(mlir::Type type,
// it to.
if (recTy.isUnion()) {
// Classify only the members that hold data for the ABI, plus one
- // recording a declared reach. A member that does neither, such as
+ // recording a declared extent. A member that does neither, such as
// an unnamed bit-field's storage, is skipped so it does not appear
// as a spurious argument. A union's members all sit at offset zero.
for (auto [fieldTy, kind] :
diff --git a/clang/test/CIR/CodeGen/anonymous-nested-init.c b/clang/test/CIR/CodeGen/anonymous-nested-init.c
index 8eca4c0534355..2a071248c80a5 100644
--- a/clang/test/CIR/CodeGen/anonymous-nested-init.c
+++ b/clang/test/CIR/CodeGen/anonymous-nested-init.c
@@ -32,7 +32,7 @@ struct StructWithAnonBitfields {
struct StructWithAnonBitfields g_anon_bits = { 7, {0xA, 0x5}, 9 };
// CIR: cir.global external @g_anon_bits = #cir.const_record<{#cir.int<7> : !s32i, #cir.const_record<{#cir.int<90> : !u8i, #cir.zero : !cir.array<!cir.array<!u8i x 4> x 0>, #cir.zero : !cir.array<!u8i x 3>}> : !rec_anon2E2, #cir.int<9> : !s32i}> : !rec_StructWithAnonBitfields
-// The zero-length member carrying the bit-field's declared reach has no
+// The zero-length member carrying the bit-field's declared extent has no
// counterpart in classic CodeGen.
// LLVMCIR: @g_anon_bits = global %struct.StructWithAnonBitfields { i32 7, %struct.anon{{.*}} { i8 90, [0 x i8] zeroinitializer, [3 x i8] zeroinitializer }, i32 9 }
// OGCG: @g_anon_bits = global %struct.StructWithAnonBitfields { i32 7, %struct.anon{{.*}} { i8 90, [3 x i8] zeroinitializer }, i32 9 }
diff --git a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-reach.cpp b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-extent.cpp
similarity index 88%
rename from clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-reach.cpp
rename to clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-extent.cpp
index 7ad13d657fd6b..f67e24c2dee62 100644
--- a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-reach.cpp
+++ b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-bitfield-extent.cpp
@@ -105,7 +105,7 @@ union UWideBits {
char pad[4];
};
-// A unit narrower than the type declared in it carries the declared reach as a
+// A unit narrower than the type declared in it carries the declared extent as a
// zero-length member, which is what widens the coercion from the unit's own i8
// to the eightbyte the declaration covers.
// CIR-DAG: !rec_Bits = !cir.struct<"Bits" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, pad !cir.array<!u8i x 3>}>
@@ -115,15 +115,17 @@ union UWideBits {
// CIR-DAG: !rec_WideUnit = !cir.struct<"WideUnit" {bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>, pad !cir.array<!u8i x 12>}>
// CIR-DAG: !rec_PackedBits = !cir.struct<"PackedBits" packed {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, data !s32i, pad !cir.array<!u8i x 3>}>
-// A reach and a zero-width bit-field sit in one record without conflating.
+// A declared extent and a zero-width bit-field sit in one record without
+// conflating.
// CIR-DAG: !rec_NamedZeroWidth = !cir.struct<"NamedZeroWidth" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>, pad !cir.array<!u8i x 3>, bitfield !cir.array<!u32i x 0>, data !s32i}>
-// A reach naming bytes past the record that holds it. Nested in Wrap those
+// A declared extent naming bytes past the record that holds it. Nested in Wrap
+// those
// bytes fall in the second eightbyte, which stays padding all the same.
// CIR-DAG: !rec_Nested = !cir.struct<"Nested" {bitfield !u32i, bitfield !cir.array<!cir.array<!u8i x 2> x 0>}>
// CIR-DAG: !rec_WideInner = !cir.struct<"WideInner" {bitfield !u8i, bitfield !cir.array<!cir.array<!u8i x 7> x 0>, pad !cir.array<!u8i x 7>}>
-// A unit whose declarations stop at its own end carries no reach member. An
+// A unit whose declarations stop at its own end carries no extent member. An
// unnamed bit-field records one all the same, since the bytes its declared
// type covers hold user data even though it supplies no eightbyte class.
// CIR-DAG: !rec_UnnamedPastUnit = !cir.struct<"UnnamedPastUnit" {bitfield !u32i, bitfield !cir.array<!u8i x 0>, pad !cir.array<!u8i x 4>}>
@@ -133,7 +135,7 @@ union UWideBits {
// CIR-DAG: !rec_UnnamedOnly = !cir.struct<"UnnamedOnly" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 3> x 0>}>
// CIR-DAG: !rec_UUnnamedOnly = !cir.union<"UUnnamedOnly" {empty !u8i, bitfield !cir.array<!cir.array<!u8i x 4> x 0>}>
-// A union of plain bytes has no declaration to reach past its storage, so it
+// A union of plain bytes has no declaration extending past its storage, so it
// keeps the narrow coercion.
// CIR-DAG: !rec_UBytes = !cir.union<"UBytes" {data !u8i, data !u8i}>
@@ -157,14 +159,15 @@ void take_holder(Holder v) {}
// CIR: cir.func {{.*}}@_Z11take_holder6Holder(%arg0: !s64i{{.*}}, %arg1: !u32i
// LLVM: define {{.*}}void @_Z11take_holder6Holder(i64 %{{.+}}, i32 %{{.+}})
-// The reach also travels through an array element. The element's unit is one
-// byte, so without the reach the eightbyte would narrow to i8.
+// The declared extent also travels through an array element. The element's unit
+// is one byte, so without it the eightbyte would narrow to i8.
void take_arr_nest(ArrNest v) {}
// CIR: cir.func {{.*}}@_Z13take_arr_nest7ArrNest(%arg0: !u64i
// LLVM: define {{.*}}void @_Z13take_arr_nest7ArrNest(i64 %{{.+}})
-// A reach may run past the end of the record that records it. The bytes it
+// A declared extent may run past the end of the record that records it. The
+// bytes it
// names there belong to the enclosing record, and the classifier stops at the
// inner record's own size, so the eightbyte holding them stays padding.
void take_wrap(Wrap v) {}
@@ -173,7 +176,7 @@ void take_wrap(Wrap v) {}
// LLVM: define {{.*}}void @_Z9take_wrap4Wrap(i64 %{{.+}})
// An unnamed bit-field supplies no eightbyte class, but the bytes its declared
-// type covers are user data, so its reach counts. Leaving it out would narrow
+// type covers are user data, so its extent counts. Leaving it out would narrow
// these two to i32 and i8.
void take_unnamed_past_unit(UnnamedPastUnit v) {}
void take_unnamed_wide(UnnamedWide v) {}
@@ -185,7 +188,7 @@ void take_unnamed_wide(UnnamedWide v) {}
// LLVM: define {{.*}}void @_Z17take_unnamed_wide11UnnamedWide(i64 %{{.+}})
// These two records differ only in the type their bit-field is declared with,
-// so the reach is what widens the second coercion to the eightbyte it covers.
+// so the extent is what widens the second coercion to the eightbyte it covers.
void take_narrow_unit(NarrowUnit v) {}
void take_wide_unit(WideUnit v) {}
@@ -195,21 +198,21 @@ void take_wide_unit(WideUnit v) {}
// CIR: cir.func {{.*}}@_Z14take_wide_unit8WideUnit(%arg0: !u64i
// LLVM: define {{.*}}void @_Z14take_wide_unit8WideUnit(i64 %{{.+}})
-// A reach and a zero-width bit-field in one record, which share a shape.
+// A declared extent and a zero-width bit-field in one record, sharing a shape.
void take_named_zero_width(NamedZeroWidth v) {}
// CIR: cir.func {{.*}}@_Z21take_named_zero_width14NamedZeroWidth(%arg0: !u64i
// LLVM: define {{.*}}void @_Z21take_named_zero_width14NamedZeroWidth(i64 %{{.+}})
// The int here sits at an offset its own alignment does not divide, which
-// sends the record to memory whatever the unit before it reaches.
+// sends the record to memory whatever the unit before it declares.
void take_packed_bits(PackedBits v) {}
// CIR: cir.func {{.*}}@_Z16take_packed_bits10PackedBits(%arg0: !cir.ptr<!rec_PackedBits>
// LLVM-CIR: define {{.*}}void @_Z16take_packed_bits10PackedBits(ptr noalias noundef byval(%struct.PackedBits) align 8 %{{.+}})
// LLVM-OGCG: define {{.*}}void @_Z16take_packed_bits10PackedBits(ptr noundef byval(%struct.PackedBits) align 8 %{{.+}})
-// The reach is measured from where the member sits, which is the unit's end.
+// The extent is measured from where the member sits, which is the unit's end.
// Measuring it from the unit's start instead would claim a further eightbyte
// of user data and widen the second half to i64.
void take_spills_past_unit(SpillsPastUnit v) {}
@@ -217,7 +220,7 @@ void take_spills_past_unit(SpillsPastUnit v) {}
// CIR: cir.func {{.*}}@_Z21take_spills_past_unit14SpillsPastUnit(%arg0: !u64i{{.*}}, %arg1: !s32i
// LLVM: define {{.*}}void @_Z21take_spills_past_unit14SpillsPastUnit(i64 %{{.+}}, i32 %{{.+}})
-// A unit of unnamed bit-fields records a reach without supplying data, which
+// A unit of unnamed bit-fields records an extent without supplying data, which
// leaves the record empty for the ABI and drops the argument.
void take_unnamed_only(UnnamedOnly v) {}
void take_uunnamed_only(UUnnamedOnly v) {}
@@ -239,7 +242,7 @@ void take_ubytes(UBytes v) {}
// LLVM: define {{.*}}void @_Z11take_ubytes6UBytes(i8 %{{.+}})
// A union holding both a data member and a bit-field whose declared type
-// outruns it, so the reach rather than the widest member sizes the coercion.
+// outruns it, so the extent rather than the widest member sizes the coercion.
void take_uwide_bits(UWideBits v) {}
UWideBits ret_uwide_bits(void) { UWideBits u; u.w = 1; return u; }
diff --git a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-packed.c b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-packed.c
index b9b53a71d8e99..22979459e34c5 100644
--- a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-packed.c
+++ b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-packed.c
@@ -135,7 +135,7 @@ FiveShort ret_five_short(short x) { FiveShort v = {0, x, 0}; return v; }
// LLVM: define dso_local i40 @ret_five_short(i16 noundef signext %{{.+}})
// The char bit-field here is declared no wider than the byte its unit
-// occupies, so the unit records no reach and every byte of the record holds
+// occupies, so the unit records no extent and every byte of the record holds
// data.
int take_ninebf(NineBF v) { return v.b; }
diff --git a/clang/test/CIR/CodeGen/record-member-kinds.cpp b/clang/test/CIR/CodeGen/record-member-kinds.cpp
index c2206f221fa36..115f51616d21e 100644
--- a/clang/test/CIR/CodeGen/record-member-kinds.cpp
+++ b/clang/test/CIR/CodeGen/record-member-kinds.cpp
@@ -127,7 +127,7 @@ struct NamedClippedTail { NamedClippedTail(const NamedClippedTail &); int i; int
struct DerivedClipped : Clipped { char c; };
// CIR-DAG: !rec_DerivedClipped = !cir.struct<"DerivedClipped" {data !rec_Clipped2Ebase, data !s8i}>
-// A declared reach lowers to a zero-length member with no classic counterpart.
+// A declared extent lowers to a zero-length member with no classic counterpart.
// LLVMCIR-DAG: %struct.Clipped.base = type <{ i32, [3 x i8], [0 x i8] }>
// OGCG-DAG: %struct.Clipped.base = type <{ i32, [3 x i8] }>
// LLVM-DAG: %struct.DerivedClipped = type { %struct.Clipped.base, i8 }
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-extent.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-extent.cir
new file mode 100644
index 0000000000000..20ca4a21a7f9e
--- /dev/null
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-extent.cir
@@ -0,0 +1,80 @@
+// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
+
+!u8i = !cir.int<u, 8>
+!u32i = !cir.int<u, 32>
+!u64i = !cir.int<u, 64>
+
+// A unit whose declarations stop at its own end.
+!rec_UnitOnly = !cir.struct<"UnitOnly" {bitfield !u32i, pad !cir.array<!u8i x 12>}>
+
+// The same shape, with the declared extent carried past the unit.
+!rec_Extent = !cir.struct<"Extent" {bitfield !u32i,
+ bitfield !cir.array<!cir.array<!u8i x 8> x 0>,
+ pad !cir.array<!u8i x 12>}>
+
+// Over two eightbytes, so memory whatever the declared extent says.
+!rec_BigExtent = !cir.struct<"BigExtent" {data !u64i, data !u64i, bitfield !u8i,
+ bitfield !cir.array<!cir.array<!u8i x 4> x 0>,
+ pad !cir.array<!u8i x 7>}>
+
+// A union whose storage is narrower than the declaration it holds.
+!rec_UnionExtent = !cir.union<"UnionExtent" {bitfield !u8i,
+ bitfield !cir.array<!cir.array<!u8i x 4> x 0>},
+ padding = {!cir.array<!u8i x 3>}>
+
+module attributes {
+ dlti.dl_spec = #dlti.dl_spec<
+ #dlti.dl_entry<i32, dense<32>: vector<2xi64>>,
+ #dlti.dl_entry<i64, dense<64>: vector<2xi64>>,
+ #dlti.dl_entry<f32, dense<32>: vector<2xi64>>,
+ #dlti.dl_entry<f64, dense<64>: vector<2xi64>>,
+ #dlti.dl_entry<"dlti.endianness", "little">
+ >,
+ cir.triple = "x86_64-unknown-linux-gnu"
+} {
+ // With nothing declared past the unit, the bytes after it are padding and
+ // the coercion is the unit's own width.
+ cir.func @take_unit_only(%arg0: !rec_UnitOnly) {
+ cir.return
+ }
+
+ // CHECK: cir.func{{.*}} @take_unit_only(%arg0: !u32i)
+
+ // The declared extent makes those same bytes user data, which widens the
+ // coercion to the eightbyte holding them.
+ cir.func @take_extent(%arg0: !rec_Extent) {
+ cir.return
+ }
+
+ // CHECK: cir.func{{.*}} @take_extent(%arg0: !u64i)
+
+ cir.func @return_extent(%arg0: !rec_Extent) -> !rec_Extent {
+ %0 = cir.alloca "a" align(16) : !cir.ptr<!rec_Extent>
+ cir.store %arg0, %0 : !rec_Extent, !cir.ptr<!rec_Extent>
+ %1 = cir.load %0 : !cir.ptr<!rec_Extent>, !rec_Extent
+ cir.return %1 : !rec_Extent
+ }
+
+ // CHECK: cir.func{{.*}} @return_extent(%arg0: !u64i) -> !u64i
+
+ cir.func @take_big_extent(%arg0: !rec_BigExtent) {
+ cir.return
+ }
+
+ // CHECK: cir.func{{.*}} @take_big_extent(%arg0: !cir.ptr<!rec_BigExtent> {llvm.align = 8 : i64, llvm.byval = !rec_BigExtent, llvm.noalias, llvm.noundef})
+
+ cir.func @return_big_extent(%arg0: !rec_BigExtent) -> !rec_BigExtent {
+ %0 = cir.alloca "a" align(8) : !cir.ptr<!rec_BigExtent>
+ cir.store %arg0, %0 : !rec_BigExtent, !cir.ptr<!rec_BigExtent>
+ %1 = cir.load %0 : !cir.ptr<!rec_BigExtent>, !rec_BigExtent
+ cir.return %1 : !rec_BigExtent
+ }
+
+ // CHECK: cir.func{{.*}} @return_big_extent(%arg0: !cir.ptr<!rec_BigExtent> {llvm.align = 8 : i64, llvm.dead_on_unwind, llvm.noalias, llvm.sret = !rec_BigExtent, llvm.writable}, %arg1: !cir.ptr<!rec_BigExtent> {llvm.align = 8 : i64, llvm.byval = !rec_BigExtent, llvm.noalias, llvm.noundef})
+
+ cir.func @take_union_extent(%arg0: !rec_UnionExtent) {
+ cir.return
+ }
+
+ // CHECK: cir.func{{.*}} @take_union_extent(%arg0: !u32i)
+}
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-reach.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-reach.cir
deleted file mode 100644
index 91efeefc9dac8..0000000000000
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-bitfield-reach.cir
+++ /dev/null
@@ -1,80 +0,0 @@
-// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
-
-!u8i = !cir.int<u, 8>
-!u32i = !cir.int<u, 32>
-!u64i = !cir.int<u, 64>
-
-// A unit whose declarations stop at its own end.
-!rec_UnitOnly = !cir.struct<"UnitOnly" {bitfield !u32i, pad !cir.array<!u8i x 12>}>
-
-// The same shape, with the declared reach carried past the unit.
-!rec_Reach = !cir.struct<"Reach" {bitfield !u32i,
- bitfield !cir.array<!cir.array<!u8i x 8> x 0>,
- pad !cir.array<!u8i x 12>}>
-
-// Over two eightbytes, so memory whatever the reach says.
-!rec_BigReach = !cir.struct<"BigReach" {data !u64i, data !u64i, bitfield !u8i,
- bitfield !cir.array<!cir.array<!u8i x 4> x 0>,
- pad !cir.array<!u8i x 7>}>
-
-// A union whose storage is narrower than the declaration it holds.
-!rec_UnionReach = !cir.union<"UnionReach" {bitfield !u8i,
- bitfield !cir.array<!cir.array<!u8i x 4> x 0>},
- padding = {!cir.array<!u8i x 3>}>
-
-module attributes {
- dlti.dl_spec = #dlti.dl_spec<
- #dlti.dl_entry<i32, dense<32>: vector<2xi64>>,
- #dlti.dl_entry<i64, dense<64>: vector<2xi64>>,
- #dlti.dl_entry<f32, dense<32>: vector<2xi64>>,
- #dlti.dl_entry<f64, dense<64>: vector<2xi64>>,
- #dlti.dl_entry<"dlti.endianness", "little">
- >,
- cir.triple = "x86_64-unknown-linux-gnu"
-} {
- // With nothing reaching past the unit, the bytes after it are padding and
- // the coercion is the unit's own width.
- cir.func @take_unit_only(%arg0: !rec_UnitOnly) {
- cir.return
- }
-
- // CHECK: cir.func{{.*}} @take_unit_only(%arg0: !u32i)
-
- // The declared reach makes those same bytes user data, which widens the
- // coercion to the eightbyte holding them.
- cir.func @take_reach(%arg0: !rec_Reach) {
- cir.return
- }
-
- // CHECK: cir.func{{.*}} @take_reach(%arg0: !u64i)
-
- cir.func @return_reach(%arg0: !rec_Reach) -> !rec_Reach {
- %0 = cir.alloca "a" align(16) : !cir.ptr<!rec_Reach>
- cir.store %arg0, %0 : !rec_Reach, !cir.ptr<!rec_Reach>
- %1 = cir.load %0 : !cir.ptr<!rec_Reach>, !rec_Reach
- cir.return %1 : !rec_Reach
- }
-
- // CHECK: cir.func{{.*}} @return_reach(%arg0: !u64i) -> !u64i
-
- cir.func @take_big_reach(%arg0: !rec_BigReach) {
- cir.return
- }
-
- // CHECK: cir.func{{.*}} @take_big_reach(%arg0: !cir.ptr<!rec_BigReach> {llvm.align = 8 : i64, llvm.byval = !rec_BigReach, llvm.noalias, llvm.noundef})
-
- cir.func @return_big_reach(%arg0: !rec_BigReach) -> !rec_BigReach {
- %0 = cir.alloca "a" align(8) : !cir.ptr<!rec_BigReach>
- cir.store %arg0, %0 : !rec_BigReach, !cir.ptr<!rec_BigReach>
- %1 = cir.load %0 : !cir.ptr<!rec_BigReach>, !rec_BigReach
- cir.return %1 : !rec_BigReach
- }
-
- // CHECK: cir.func{{.*}} @return_big_reach(%arg0: !cir.ptr<!rec_BigReach> {llvm.align = 8 : i64, llvm.dead_on_unwind, llvm.noalias, llvm.sret = !rec_BigReach, llvm.writable}, %arg1: !cir.ptr<!rec_BigReach> {llvm.align = 8 : i64, llvm.byval = !rec_BigReach, llvm.noalias, llvm.noundef})
-
- cir.func @take_union_reach(%arg0: !rec_UnionReach) {
- cir.return
- }
-
- // CHECK: cir.func{{.*}} @take_union_reach(%arg0: !u32i)
-}
More information about the cfe-commits
mailing list