================
@@ -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());
----------------
erichkeane wrote:

It seems to me that the only thing that should be in the if/else here is:

unions: the call to `getFieldIndex`/init of `fieldIndex`
Non-unions: assert for `PeservedAccessIndexRegion`/layout init, `fieldIndex` 
init.

The `addr` creation and the `emitAddrOfFieldStorage` are both identical, so it 
seems that the we could make sure these stay in sync better by taking them out 
of the conditional.

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

Reply via email to