@@ -439,7 +439,13 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
439439 cgm.errorNYI (e->getSourceRange (), " emitDeclRefLValue: static local" );
440440 }
441441
442- return makeAddrLValue (addr, ty, AlignmentSource::Type);
442+ // Drill into reference types.
443+ LValue lv =
444+ vd->getType ()->isReferenceType ()
445+ ? emitLoadOfReferenceLValue (addr, getLoc (e->getSourceRange ()),
446+ vd->getType (), AlignmentSource::Decl)
447+ : makeAddrLValue (addr, ty, AlignmentSource::Decl);
448+ return lv;
443449 }
444450
445451 cgm.errorNYI (e->getSourceRange (), " emitDeclRefLValue: unhandled decl type" );
@@ -1065,6 +1071,45 @@ mlir::Value CIRGenFunction::emitAlloca(StringRef name, mlir::Type ty,
10651071 return addr;
10661072}
10671073
1074+ RValue CIRGenFunction::emitReferenceBindingToExpr (const Expr *e) {
1075+ // Emit the expression as an lvalue.
1076+ LValue lv = emitLValue (e);
1077+ assert (lv.isSimple ());
1078+ mlir::Value value = lv.getPointer ();
1079+
1080+ assert (!cir::MissingFeatures::sanitizers ());
1081+
1082+ return RValue::get (value);
1083+ }
1084+
1085+ Address CIRGenFunction::emitLoadOfReference (LValue refLVal, mlir::Location loc,
1086+ LValueBaseInfo *pointeeBaseInfo) {
1087+ if (refLVal.isVolatile ())
1088+ cgm.errorNYI (loc, " load of volatile reference" );
1089+
1090+ cir::LoadOp load =
1091+ builder.create <cir::LoadOp>(loc, refLVal.getAddress ().getElementType (),
1092+ refLVal.getAddress ().getPointer ());
1093+
1094+ assert (!cir::MissingFeatures::opTBAA ());
1095+
1096+ QualType pointeeType = refLVal.getType ()->getPointeeType ();
1097+ CharUnits align = cgm.getNaturalTypeAlignment (pointeeType, pointeeBaseInfo);
1098+ return Address (load, convertTypeForMem (pointeeType), align);
1099+ }
1100+
1101+ LValue CIRGenFunction::emitLoadOfReferenceLValue (Address refAddr,
1102+ mlir::Location loc,
1103+ QualType refTy,
1104+ AlignmentSource source) {
1105+ LValue refLVal = makeAddrLValue (refAddr, refTy, LValueBaseInfo (source));
1106+ LValueBaseInfo pointeeBaseInfo;
1107+ assert (!cir::MissingFeatures::opTBAA ());
1108+ Address pointeeAddr = emitLoadOfReference (refLVal, loc, &pointeeBaseInfo);
1109+ return makeAddrLValue (pointeeAddr, refLVal.getType ()->getPointeeType (),
1110+ pointeeBaseInfo);
1111+ }
1112+
10681113mlir::Value CIRGenFunction::createDummyValue (mlir::Location loc,
10691114 clang::QualType qt) {
10701115 mlir::Type t = convertType (qt);
0 commit comments