[clang] [CIR] Upstream initial support for union type (PR #137501)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 28 10:53:13 PDT 2025


================
@@ -317,20 +317,25 @@ LValue CIRGenFunction::emitLValueForField(LValue base, const FieldDecl *field) {
   }
 
   unsigned recordCVR = base.getVRQualifiers();
-  if (rec->isUnion()) {
-    cgm.errorNYI(field->getSourceRange(), "emitLValueForField: union");
-    return LValue();
-  }
 
-  assert(!cir::MissingFeatures::preservedAccessIndexRegion());
   llvm::StringRef fieldName = field->getName();
-  const CIRGenRecordLayout &layout =
-      cgm.getTypes().getCIRGenRecordLayout(field->getParent());
-  unsigned fieldIndex = layout.getCIRFieldNo(field);
 
-  assert(!cir::MissingFeatures::lambdaFieldToName());
+  if (rec->isUnion()) {
+    unsigned fieldIndex = field->getFieldIndex();
+    assert(!cir::MissingFeatures::lambdaFieldToName());
----------------
andykaylor wrote:

We probably want the assert for PreservedAccessIndexRegion for both unions and non-unions. The incubator doesn't have that, but there is special handling for that case in the classic codegen. I'm not sure what will need to be do, but I expect we'll need something.

I agree that moving common code out of the if/else is good.

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


More information about the cfe-commits mailing list