[clang] [CIR] Mark record members as data, pad, or empty in CIRGen (PR #215175)

Adam Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 14 14:10:26 PDT 2026


================
@@ -621,17 +660,34 @@ void CIRRecordLowering::accumulateFields() {
       // problem with taking the address of one of these, so it is in practice
       // not a horrifyingly problematic issue.
       assert(!cir::MissingFeatures::noUniqueAddressLayout());
+      // Dropping the field leaves no member to mark, so its bytes read as
+      // padding.  That is only sound when the field carries no ABI data
+      // either, which isEmptyFieldForLayout does not guarantee.  Report the
+      // gap rather than claim an emptiness the record does not have.  The base
+      // subobject lowering sees the same field, so only the complete object
+      // reports it.
+      if (!isEmptyFieldForABI(astContext, *field)) {
+        if (!nonVirtualBaseType)
+          cirGenTypes.getCGModule().errorNYI(
+              field->getSourceRange(),
+              "[[no_unique_address]] field that is empty for layout but holds "
+              "data for the ABI");
+        droppedFieldHoldingData = true;
----------------
adams381 wrote:

I've deleted it. Deleting it on its own trips the assert on the NYI test, since layout still finishes with a bad state after `errorNYI`.  Both asserts now permit `cgm.getDiags().hasErrorOccurred()` instead. That covers any future NYI in record lowering rather than only this one.

https://github.com/llvm/llvm-project/pull/215175


More information about the cfe-commits mailing list