Skip to content

Commit 906427a

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 7877624 + 9cb7ab1 commit 906427a

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

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
}

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)