@@ -317,20 +317,21 @@ LValue CIRGenFunction::emitLValueForField(LValue base, const FieldDecl *field) {
317317 }
318318
319319 unsigned recordCVR = base.getVRQualifiers ();
320- if (rec->isUnion ()) {
321- cgm.errorNYI (field->getSourceRange (), " emitLValueForField: union" );
322- return LValue ();
323- }
324320
325- assert (!cir::MissingFeatures::preservedAccessIndexRegion ());
326321 llvm::StringRef fieldName = field->getName ();
327- const CIRGenRecordLayout &layout =
328- cgm.getTypes ().getCIRGenRecordLayout (field->getParent ());
329- unsigned fieldIndex = layout.getCIRFieldNo (field);
330-
322+ unsigned fieldIndex;
331323 assert (!cir::MissingFeatures::lambdaFieldToName ());
332324
325+ if (rec->isUnion ())
326+ fieldIndex = field->getFieldIndex ();
327+ else {
328+ const CIRGenRecordLayout &layout =
329+ cgm.getTypes ().getCIRGenRecordLayout (field->getParent ());
330+ fieldIndex = layout.getCIRFieldNo (field);
331+ }
332+
333333 addr = emitAddrOfFieldStorage (addr, field, fieldName, fieldIndex);
334+ assert (!cir::MissingFeatures::preservedAccessIndexRegion ());
334335
335336 // If this is a reference field, load the reference right now.
336337 if (fieldType->isReferenceType ()) {
@@ -439,7 +440,13 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
439440 cgm.errorNYI (e->getSourceRange (), " emitDeclRefLValue: static local" );
440441 }
441442
442- return makeAddrLValue (addr, ty, AlignmentSource::Type);
443+ // Drill into reference types.
444+ LValue lv =
445+ vd->getType ()->isReferenceType ()
446+ ? emitLoadOfReferenceLValue (addr, getLoc (e->getSourceRange ()),
447+ vd->getType (), AlignmentSource::Decl)
448+ : makeAddrLValue (addr, ty, AlignmentSource::Decl);
449+ return lv;
443450 }
444451
445452 cgm.errorNYI (e->getSourceRange (), " emitDeclRefLValue: unhandled decl type" );
@@ -1065,6 +1072,45 @@ mlir::Value CIRGenFunction::emitAlloca(StringRef name, mlir::Type ty,
10651072 return addr;
10661073}
10671074
1075+ RValue CIRGenFunction::emitReferenceBindingToExpr (const Expr *e) {
1076+ // Emit the expression as an lvalue.
1077+ LValue lv = emitLValue (e);
1078+ assert (lv.isSimple ());
1079+ mlir::Value value = lv.getPointer ();
1080+
1081+ assert (!cir::MissingFeatures::sanitizers ());
1082+
1083+ return RValue::get (value);
1084+ }
1085+
1086+ Address CIRGenFunction::emitLoadOfReference (LValue refLVal, mlir::Location loc,
1087+ LValueBaseInfo *pointeeBaseInfo) {
1088+ if (refLVal.isVolatile ())
1089+ cgm.errorNYI (loc, " load of volatile reference" );
1090+
1091+ cir::LoadOp load =
1092+ builder.create <cir::LoadOp>(loc, refLVal.getAddress ().getElementType (),
1093+ refLVal.getAddress ().getPointer ());
1094+
1095+ assert (!cir::MissingFeatures::opTBAA ());
1096+
1097+ QualType pointeeType = refLVal.getType ()->getPointeeType ();
1098+ CharUnits align = cgm.getNaturalTypeAlignment (pointeeType, pointeeBaseInfo);
1099+ return Address (load, convertTypeForMem (pointeeType), align);
1100+ }
1101+
1102+ LValue CIRGenFunction::emitLoadOfReferenceLValue (Address refAddr,
1103+ mlir::Location loc,
1104+ QualType refTy,
1105+ AlignmentSource source) {
1106+ LValue refLVal = makeAddrLValue (refAddr, refTy, LValueBaseInfo (source));
1107+ LValueBaseInfo pointeeBaseInfo;
1108+ assert (!cir::MissingFeatures::opTBAA ());
1109+ Address pointeeAddr = emitLoadOfReference (refLVal, loc, &pointeeBaseInfo);
1110+ return makeAddrLValue (pointeeAddr, refLVal.getType ()->getPointeeType (),
1111+ pointeeBaseInfo);
1112+ }
1113+
10681114mlir::Value CIRGenFunction::createDummyValue (mlir::Location loc,
10691115 clang::QualType qt) {
10701116 mlir::Type t = convertType (qt);
0 commit comments