================
@@ -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)
----------------
andykaylor wrote:

The fact that the condition isn't met here didn't surprise me, because all the 
places that call this function have also checked it and only call this function 
if layoutInfo is null. What did surprise me is that it's always null in the 
callers too. This is explained by what @xlauko said above about the cache being 
local to the RecordType instance.

I verified that even with a simple test case 
(clang/test/CIR/CodeGen/struct.cpp) we recompute the layout multiple times for 
the same type. This just isn't working the way it was intended.

https://github.com/llvm/llvm-project/pull/136036
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to