@@ -499,6 +499,9 @@ namespace {
499499 emitFunctionCvtFromExecutionCallerToGlobalActor (FunctionConversionExpr *E,
500500 SGFContext C);
501501
502+ // / Helper to emit a value of arbitrary type in an unreachable codepath.
503+ RValue emitUnreachableValue (SILLocation loc, CanType ty);
504+
502505 RValue visitActorIsolationErasureExpr (ActorIsolationErasureExpr *E,
503506 SGFContext C);
504507 RValue visitExtractFunctionIsolationExpr (ExtractFunctionIsolationExpr *E,
@@ -2136,6 +2139,32 @@ RValue RValueEmitter::emitFunctionCvtFromExecutionCallerToGlobalActor(
21362139 return RValue (SGF, e, destType, result);
21372140}
21382141
2142+ RValue RValueEmitter::emitUnreachableValue (SILLocation loc, CanType ty) {
2143+ ASSERT (!SGF.B .hasValidInsertionPoint () && " Must be unreachable" );
2144+
2145+ // Continue code generation in a block with no predecessors.
2146+ // Whatever code is emitted here is guaranteed to be removed by SIL passes.
2147+ SGF.B .emitBlock (SGF.createBasicBlock ());
2148+
2149+ // Since the type is uninhabited, use a SILUndef of so that we can return
2150+ // some sort of RValue from this API.
2151+ auto &lowering = SGF.getTypeLowering (ty);
2152+ auto loweredTy = lowering.getLoweredType ();
2153+ auto undef = SILUndef::get (SGF.F , loweredTy);
2154+
2155+ // Create an alloc initialized with contents from the undefined addr type.
2156+ // It seems pack addresses do not satisfy isPlusOneOrTrivial, so we need an
2157+ // actual allocation.
2158+ if (loweredTy.isAddress ()) {
2159+ auto resultAddr = SGF.emitTemporaryAllocation (loc, loweredTy);
2160+ SGF.emitSemanticStore (loc, undef, resultAddr, lowering, IsInitialization);
2161+ return RValue (SGF, loc, ty, SGF.emitManagedRValueWithCleanup (resultAddr));
2162+ }
2163+
2164+ // Otherwise, if it's not an address, just emit the undef value itself.
2165+ return RValue (SGF, loc, ty, ManagedValue::forRValueWithoutOwnership (undef));
2166+ }
2167+
21392168RValue RValueEmitter::visitFunctionConversionExpr (FunctionConversionExpr *e,
21402169 SGFContext C) {
21412170 CanAnyFunctionType srcType =
@@ -2660,28 +2689,7 @@ RValue RValueEmitter::visitUnreachableExpr(UnreachableExpr *E, SGFContext C) {
26602689 // Emit the expression, followed by an unreachable.
26612690 SGF.emitIgnoredExpr (E->getSubExpr ());
26622691 SGF.B .createUnreachable (E);
2663-
2664- // Continue code generation in a block with no predecessors.
2665- // Whatever code is emitted here is guaranteed to be removed by SIL passes.
2666- SGF.B .emitBlock (SGF.createBasicBlock ());
2667-
2668- // Since the type is uninhabited, use a SILUndef of so that we can return
2669- // some sort of RValue from this API.
2670- auto &lowering = SGF.getTypeLowering (E->getType ());
2671- auto loweredTy = lowering.getLoweredType ();
2672- auto undef = SILUndef::get (SGF.F , loweredTy);
2673-
2674- // Create an alloc initialized with contents from the undefined addr type.
2675- // It seems pack addresses do not satisfy isPlusOneOrTrivial, so we need an
2676- // actual allocation.
2677- if (loweredTy.isAddress ()) {
2678- auto resultAddr = SGF.emitTemporaryAllocation (E, loweredTy);
2679- SGF.emitSemanticStore (E, undef, resultAddr, lowering, IsInitialization);
2680- return RValue (SGF, E, SGF.emitManagedRValueWithCleanup (resultAddr));
2681- }
2682-
2683- // Otherwise, if it's not an address, just emit the undef value itself.
2684- return RValue (SGF, E, ManagedValue::forRValueWithoutOwnership (undef));
2692+ return emitUnreachableValue (E, E->getType ()->getCanonicalType ());
26852693}
26862694
26872695static SILValue getArrayBuffer (SILValue array, SILGenFunction &SGF, SILLocation loc) {
@@ -3477,7 +3485,21 @@ visitObjectLiteralExpr(ObjectLiteralExpr *E, SGFContext C) {
34773485
34783486RValue RValueEmitter::
34793487visitEditorPlaceholderExpr (EditorPlaceholderExpr *E, SGFContext C) {
3480- return visit (E->getSemanticExpr (), C);
3488+ if (auto *undefinedFn = SGF.getASTContext ().getUndefinedEditorPlaceholder ()) {
3489+ auto args = SGF.emitSourceLocationArgs (E->getLoc (), E);
3490+ SGF.emitApplyOfLibraryIntrinsic (E, undefinedFn, SubstitutionMap (),
3491+ {
3492+ args.filenameStartPointer ,
3493+ args.filenameLength ,
3494+ args.filenameIsAscii ,
3495+ args.line ,
3496+ },
3497+ SGFContext ());
3498+ } else {
3499+ SGF.B .createUnconditionalFail (E, " attempt to evaluate editor placeholder" );
3500+ }
3501+ SGF.B .createUnreachable (E);
3502+ return emitUnreachableValue (E, E->getType ()->getCanonicalType ());
34813503}
34823504
34833505RValue RValueEmitter::visitObjCSelectorExpr (ObjCSelectorExpr *e, SGFContext C) {
0 commit comments