[clang] [CIR] Upstream support for record packing and padding (PR #136036)
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 17 10:42:45 PDT 2025
================
@@ -225,17 +235,108 @@ void RecordType::complete(ArrayRef<Type> members, bool packed, bool padded) {
//===----------------------------------------------------------------------===//
llvm::TypeSize
-RecordType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
- ::mlir::DataLayoutEntryListRef params) const {
- assert(!cir::MissingFeatures::recordTypeLayoutInfo());
- return llvm::TypeSize::getFixed(8);
+RecordType::getTypeSizeInBits(const mlir::DataLayout &dataLayout,
+ mlir::DataLayoutEntryListRef params) const {
+ if (!layoutInfo)
+ computeSizeAndAlignment(dataLayout);
+ return llvm::TypeSize::getFixed(
+ mlir::cast<cir::RecordLayoutAttr>(layoutInfo).getSize() * 8);
}
uint64_t
RecordType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
- assert(!cir::MissingFeatures::recordTypeLayoutInfo());
- return 4;
+ if (!layoutInfo)
+ computeSizeAndAlignment(dataLayout);
+ return mlir::cast<cir::RecordLayoutAttr>(layoutInfo).getAlignment();
+}
+
+void RecordType::computeSizeAndAlignment(
+ const mlir::DataLayout &dataLayout) const {
+ assert(isComplete() && "Cannot get layout of incomplete records");
+ // Do not recompute.
+ if (layoutInfo)
----------------
bcardosolopes wrote:
You might be right, but clangir tests are mostly reduced testcases, I have trouble accepting this as a fact unless you tell me you are running on top of significant C/C++ code. (It's kinda bad that it's not exercised in the tests, you do have a point tho)
https://github.com/llvm/llvm-project/pull/136036
More information about the cfe-commits
mailing list