@@ -323,6 +323,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenLValue
323323 LValue visitKeyPathApplicationExpr (KeyPathApplicationExpr *e,
324324 SGFAccessKind accessKind,
325325 LValueOptions options);
326+ LValue visitABISafeConversionExpr (ABISafeConversionExpr *e,
327+ SGFAccessKind accessKind,
328+ LValueOptions options);
326329
327330 // Expressions that wrap lvalues
328331
@@ -2200,6 +2203,29 @@ namespace {
22002203 OS.indent (indent) << " PhysicalKeyPathApplicationComponent\n " ;
22012204 }
22022205 };
2206+
2207+ // / A physical component which performs an unchecked_addr_cast
2208+ class ABISafeConversionComponent final : public PhysicalPathComponent {
2209+ public:
2210+ ABISafeConversionComponent (LValueTypeData typeData)
2211+ : PhysicalPathComponent(typeData, ABISafeConversionKind,
2212+ /* actorIsolation=*/ None) {}
2213+
2214+ ManagedValue project (SILGenFunction &SGF, SILLocation loc,
2215+ ManagedValue base) && override {
2216+ auto toType = SGF.getLoweredType (getTypeData ().SubstFormalType )
2217+ .getAddressType ();
2218+
2219+ if (base.getType () == toType)
2220+ return base; // nothing to do
2221+
2222+ return SGF.B .createUncheckedAddrCast (loc, base, toType);
2223+ }
2224+
2225+ void dump (raw_ostream &OS, unsigned indent) const override {
2226+ OS.indent (indent) << " ABISafeConversionComponent\n " ;
2227+ }
2228+ };
22032229} // end anonymous namespace
22042230
22052231RValue
@@ -3709,6 +3735,17 @@ LValue SILGenLValue::visitInOutExpr(InOutExpr *e, SGFAccessKind accessKind,
37093735 return visitRec (e->getSubExpr (), accessKind, options);
37103736}
37113737
3738+ LValue SILGenLValue::visitABISafeConversionExpr (ABISafeConversionExpr *e,
3739+ SGFAccessKind accessKind,
3740+ LValueOptions options) {
3741+ LValue lval = visitRec (e->getSubExpr (), accessKind, options);
3742+ auto typeData = getValueTypeData (SGF, accessKind, e);
3743+
3744+ lval.add <ABISafeConversionComponent>(typeData);
3745+
3746+ return lval;
3747+ }
3748+
37123749// / Emit an lvalue that refers to the given property. This is
37133750// / designed to work with ManagedValue 'base's that are either +0 or +1.
37143751LValue SILGenFunction::emitPropertyLValue (SILLocation loc, ManagedValue base,
0 commit comments