Skip to content

[IRGen] Rewrite dead method test in StdlibUnittest #2305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions test/IRGen/Inputs/report_dead_method_call/main.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// The StdlibUnittest test suite is placed here because it contains
// expressions that are only allowed at the top level in files named
// "main.swift".

import StdlibUnittest

@inline(never)
func testProto(_ c: Container) {
Expand Down Expand Up @@ -27,16 +31,22 @@ func testPublicClass(_ c: PublicBase) {
c.ghi()
}

switch Process.argc {
case 1:
callClass()
let ReportDeadMethodCallTestSuite = TestSuite("ReportDeadMethodCall")

case 2:
callProto()
ReportDeadMethodCallTestSuite.test("Call class") {
expectCrashLater()
callClass()
}

case 3:
callPublicClass()
ReportDeadMethodCallTestSuite.test("Call proto") {
expectCrashLater()
callProto()
}

default:
break
ReportDeadMethodCallTestSuite.test("Call public class") {
expectCrashLater()
callPublicClass()
}

runAllTests()

20 changes: 10 additions & 10 deletions test/IRGen/report_dead_method_call.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: %target-build-swift %S/Inputs/report_dead_method_call/main.swift %s -O -Xfrontend -disable-access-control -o %t/a.out
// RUN: %target-run %t/a.out 2> %t/err1.log; FileCheck %s < %t/err1.log
// RUN: %target-run %t/a.out p1 2> %t/err2.log; FileCheck %s < %t/err2.log
// RUN: %target-run %t/a.out p1 p2 2> %t/err3.log; FileCheck %s < %t/err3.log
// REQUIRES: executable_test

// RUN: rm -rf %t
// RUN: mkdir -p %t

// The -disable-access-control option let us "call" methods, which are removed
// by dead method elimination.
// We compile with -O (optimizations) and -disable-access-control (which
// allows use to "call" methods that are removed by dead code elimination).
// RUN: %target-build-swift %S/Inputs/report_dead_method_call/main.swift %s -O -Xfrontend -disable-access-control -o %t/report_dead_method_call

// CHECK: fatal error: call of deleted method
// The private, unused methods are optimized away. The test calls these
// methods anyway (since it has overridden the access control), so we
// expect them to produce "fatal error: call of deleted method" when run.
// RUN: %target-run %t/report_dead_method_call
// REQUIRES: executable_test

private protocol PrivateProto {
func abc()
Expand Down