Skip to content

Commit 056440f

Browse files
committed
---
yaml --- r: 319447 b: refs/heads/master-rebranch c: 906427a h: refs/heads/master i: 319445: b72acc6 319443: 4be0bc5 319439: b020d8d
1 parent b84ede0 commit 056440f

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,4 +1457,4 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14571457
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14581458
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14591459
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1460-
refs/heads/master-rebranch: 78776242c5e05218fd575430940108adcf0b1dfa
1460+
refs/heads/master-rebranch: 906427af1bb27b123a7ce42d08ac79a6f0595d62

branches/master-rebranch/lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,20 @@ static bool simplifyBlocksWithCallsToNoReturn(SILBasicBlock &BB,
529529
// Diagnose the unreachable code within the same block as the call to
530530
// noreturn.
531531
if (isUserCode(CurrentInst) && !DiagnosedUnreachableCode) {
532-
if (NoReturnCall->getLoc().is<RegularLocation>()) {
533-
if (!NoReturnCall->getLoc().isASTNode<ExplicitCastExpr>()) {
534-
diagnose(BB.getModule().getASTContext(),
535-
CurrentInst->getLoc().getSourceLoc(),
536-
diag::unreachable_code);
537-
diagnose(BB.getModule().getASTContext(),
538-
NoReturnCall->getLoc().getSourceLoc(),
539-
diag::call_to_noreturn_note);
540-
DiagnosedUnreachableCode = true;
532+
// If we have an instruction that is an end_borrow, ignore it. This
533+
// happens when passing a guaranteed argument through generic code paths
534+
// to no return functions.
535+
if (!isa<EndBorrowInst>(CurrentInst)) {
536+
if (NoReturnCall->getLoc().is<RegularLocation>()) {
537+
if (!NoReturnCall->getLoc().isASTNode<ExplicitCastExpr>()) {
538+
diagnose(BB.getModule().getASTContext(),
539+
CurrentInst->getLoc().getSourceLoc(),
540+
diag::unreachable_code);
541+
diagnose(BB.getModule().getASTContext(),
542+
NoReturnCall->getLoc().getSourceLoc(),
543+
diag::call_to_noreturn_note);
544+
DiagnosedUnreachableCode = true;
545+
}
541546
}
542547
}
543548
}

branches/master-rebranch/test/Runtime/crash_without_backtrace_optimized.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,21 @@
2323

2424
import Swift
2525

26+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
27+
import Darwin
28+
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
29+
import Glibc
30+
#elseif os(Windows)
31+
import MSVCRT
32+
#else
33+
#error("Unsupported platform")
34+
#endif
35+
2636
func foo() -> Int {
2737
return UnsafePointer<Int>(bitPattern: 0)!.pointee
2838
}
2939

40+
// Give FileCheck something to look at to keep it happy. It fails on
41+
// empty output even if the only directive is a CHECK-NOT.
42+
fputs("Running test.\n", stderr)
3043
foo()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend %s -enable-ownership-stripping-after-serialization -emit-sil -verify
2+
3+
class TuringMachine {
4+
func halt() -> Never {
5+
repeat { } while true
6+
}
7+
}
8+
9+
func diagnose_missing_return_no_error_after_noreturn_method() -> Int {
10+
TuringMachine().halt()
11+
} // no error
12+
13+
func testUnreachableAfterNoReturnMethod() -> Int {
14+
TuringMachine().halt(); // expected-note{{a call to a never-returning function}}
15+
return 0; // expected-warning {{will never be executed}}
16+
}
17+

0 commit comments

Comments
 (0)