Skip to content

Commit 7ee878b

Browse files
committed
Prevent crash with -playground when -experimental-skip-non-inlinable-function-bodies-without-types also passed
Skip playground transform for functions that have skipped bodies. This can happen when passing `-emit-module` and `-experimental-skip-non-inlinable-function-bodies-without-types` and also enabling the playground transform. The fix is for the playground transform to check `AbstractFunctionDecl::isBodySkipped()`. rdar://119258854
1 parent 5c83cae commit 7ee878b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Sema/PlaygroundTransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ void swift::performPlaygroundTransform(SourceFile &SF, PlaygroundOptionSet Opts)
925925

926926
PreWalkAction walkToDeclPre(Decl *D) override {
927927
if (auto *FD = dyn_cast<AbstractFunctionDecl>(D)) {
928-
if (!FD->isImplicit()) {
928+
if (!FD->isImplicit() && !FD->isBodySkipped()) {
929929
if (BraceStmt *Body = FD->getBody()) {
930930
const ParameterList *PL = FD->getParameters();
931931
Instrumenter I(ctx, FD, RNG, Options, TmpNameIndex);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -whole-module-optimization -module-name PlaygroundSupport -emit-module-path %t/PlaygroundSupport.swiftmodule -parse-as-library -c -o %t/PlaygroundSupport.o %S/Inputs/SilentPCMacroRuntime.swift %S/Inputs/PlaygroundsRuntime.swift
3+
// RUN: %target-build-swift -emit-module -Xfrontend -experimental-skip-non-inlinable-function-bodies-without-types -Xfrontend -playground -I=%t %s
4+
// REQUIRES: executable_test
5+
6+
import PlaygroundSupport
7+
8+
struct Foo {
9+
func Bar() {
10+
print("hello")
11+
}
12+
}
13+
14+
// This test will cause the frontend to crash without the fix for skipping playground transformation of functions that have skipped type information. If it doesn't crash, it passes.

0 commit comments

Comments
 (0)