Author: Andy Kaylor Date: 2026-09-03T09:00:40-07:00 New Revision: 90d81acaa356aa58a695f121cad2f81b42ec6e47
URL: https://github.com/llvm/llvm-project/commit/90d81acaa356aa58a695f121cad2f81b42ec6e47 DIFF: https://github.com/llvm/llvm-project/commit/90d81acaa356aa58a695f121cad2f81b42ec6e47.diff LOG: [CIR] Fix CIR tests after recent ABI change (#220749) A recent change to unnamed bitfield classification for X86 targets (https://github.com/llvm/llvm-project/pull/216777) broke several CIR tests. This change updates two of the failing tests to reflect the current state. Further cleanup is needed in CIR after the ABI backward compatibility issues are handled. A third test was failing with an assertion because the unnamed bitfield classification change exposed a problem in CIR's type mapper. We were modeling unnamed zero-length bitfields as having the width of their declared type rather than zero width. This triggered an assertion in the ABI library after such bitfields were no longer skipped. This change now reports zero width for such fields. Added: Modified: clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp clang/test/CIR/CodeGen/call-conv-lowering-x86_64-empty.cpp clang/test/CIR/Transforms/abi-lowering/x86_64-struct-padded.cir Removed: ################################################################################ diff --git a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp index dbcf19da5c826..c429aded2ec47 100644 --- a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp +++ b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp @@ -442,7 +442,8 @@ static const llvm::abi::Type *mapCIRType(mlir::Type type, // what the ABI counts, and that is the element type it carries. mlir::Type countedTy = fieldTy; bool isUnnamedUnit = kind == cir::RecordMemberKind::Empty; - if (cir::isZeroWidthBitField(fieldTy, kind)) { + bool isZeroWidth = cir::isZeroWidthBitField(fieldTy, kind); + if (isZeroWidth) { countedTy = cast<cir::ArrayType>(fieldTy).getElementType(); isUnnamedUnit = true; } @@ -457,11 +458,16 @@ static const llvm::abi::Type *mapCIRType(mlir::Type type, // sends a record with an unaligned field to memory does not apply to // 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, - /*IsBitField=*/isAccessUnit, isAccessUnit ? widthBits : 0, - /*IsUnnamedBitField=*/isUnnamedUnit)); + // A zero-width bit-field spans no bits, and a zero width is what the + // classifier reads to leave it out of the eightbyte classes. Its + // declared type stays on the field, since that is what the coerce + // type counts as user data. + uint64_t abiWidthBits = isAccessUnit && !isZeroWidth ? widthBits : 0; + fields.push_back( + llvm::abi::FieldInfo(mapCIRType(countedTy, typeMapper, dl, modOp), + recTy.getElementOffset(dl, idx) * 8, + /*IsBitField=*/isAccessUnit, abiWidthBits, + /*IsUnnamedBitField=*/isUnnamedUnit)); } return tb.getRecordType( diff --git a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-empty.cpp b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-empty.cpp index 30999935ef9d0..e6e36d664335e 100644 --- a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-empty.cpp +++ b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-empty.cpp @@ -87,12 +87,14 @@ int takeNoUniqueOne(NoUniqueOne v, int k) { return k; } int takeUnnamedBits(UnnamedBits v, int k) { return k; } // CIR: cir.func {{.*}}@_Z15takeUnnamedBits11UnnamedBitsi(%arg0: !s32i {{.*}}) -> (!s32i -// LLVM: define dso_local noundef i32 @_Z15takeUnnamedBits11UnnamedBitsi(i32 noundef %{{[^,]+}}) +// LLVM-CIR: define dso_local noundef i32 @_Z15takeUnnamedBits11UnnamedBitsi(i32 noundef %{{[^,]+}}) +// LLVM-OGCG: define dso_local noundef i32 @_Z15takeUnnamedBits11UnnamedBitsi(i8 %{{[^,]+}}, i32 noundef %{{[^,]+}}) int takeReserved(Reserved v, int k) { return k; } // CIR: cir.func {{.*}}@_Z12takeReserved8Reservedi(%arg0: !s32i {{.*}}) -> (!s32i -// LLVM: define dso_local noundef i32 @_Z12takeReserved8Reservedi(i32 noundef %{{[^,]+}}) +// LLVM-CIR: define dso_local noundef i32 @_Z12takeReserved8Reservedi(i32 noundef %{{[^,]+}}) +// LLVM-OGCG: define dso_local noundef i32 @_Z12takeReserved8Reservedi(i32 %{{[^,]+}}, i32 noundef %{{[^,]+}}) // A byte of real data keeps its register. int takeOneByte(OneByte v, int k) { return k; } @@ -164,7 +166,8 @@ Big32 retBig32() { return Big32{}; } int takeUBits(UBits v, int k) { return k; } // CIR: cir.func {{.*}}@_Z9takeUBits5UBitsi(%arg0: !s32i {{.*}}) -> (!s32i -// LLVM: define dso_local noundef i32 @_Z9takeUBits5UBitsi(i32 noundef %{{[^,]+}}) +// LLVM-CIR: define dso_local noundef i32 @_Z9takeUBits5UBitsi(i32 noundef %{{[^,]+}}) +// LLVM-OGCG: define dso_local noundef i32 @_Z9takeUBits5UBitsi(i8 %{{[^,]+}}, i32 noundef %{{[^,]+}}) int takeUNone(UNone v, int k) { return k; } diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-struct-padded.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-struct-padded.cir index ccfd8aa218d6f..ba23be4dadebb 100644 --- a/clang/test/CIR/Transforms/abi-lowering/x86_64-struct-padded.cir +++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-struct-padded.cir @@ -129,13 +129,14 @@ module attributes { // CHECK: cir.func{{.*}} @take_zw_wide(%arg0: !u64i, %arg1: !s8i) - // The unit occupies the four bytes at offset 8. Counting it as data would - // split this into a double and an !u32i. + // The empty field occupies the four bytes at offset 8. It should split into a + // double and an !u32i. cir.func @take_unit_sse(%arg0: !rec_UnitSSE) { cir.return } - // CHECK: cir.func{{.*}} @take_unit_sse(%arg0: !cir.double) + // FIXME: A bug in the ABI library causes the second arg to be misclassified. + // CHECK: cir.func{{.*}} @take_unit_sse(%arg0: !cir.double, %arg1: !u64i) // A record that is padding throughout apart from one byte still coerces to // that byte, at either alignment. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
