swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-12633] Compiler crash on sorted(by: < ) with array of type not conforming to comparable #55077

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-12633
Radar https://feedbackassistant.apple.com/feedback/7670260
Original Reporter jeremyp (JIRA User)
Type Bug

Attachment: Download

Environment MacOS Catalina 10.15.4 \`swiftc --version\` gives Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51) Target: x86_64-apple-darwin19.4.0
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 1 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: cd7677f6aa5f77894638bf3c086a607d

Issue Description:

Attempting to compile the following code:

struct Foo
{ 
    var a: Int 
    var b: String
}
let fooArray = [Foo(a: 1, b: "String"), Foo(a: 2, b: "String")]
let sorted = fooArray.sorted(by: <)
print("\(sorted)")

with

swiftc crash.swift

the compiler crashes as follows:

Swift.BinaryInteger:1:11: note: candidate requires that 'Foo' conform to 'BinaryInteger' (requirement specified as 'Self' == 'BinaryInteger')
extension BinaryInteger {
          ^
Swift.StringProtocol:1:11: note: candidate requires that 'Foo' conform to 'StringProtocol' (requirement specified as 'Self' == 'StringProtocol')
extension StringProtocol {
          ^
crash.swift:16:9: error: failed to produce diagnostic for expression; please file a bug report
print("\(sorted)")
        ^

I would expect a diagnostic to the effect that the function is not compatible with the type of the array.

swift-ci commented 4 years ago

Comment by Nikhil (JIRA)

Team,

I am getting the same crash for Xcode 11.5, macOS 15.5 and Swift version 5.2.4

Stack Trace:

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_INSTRUCTION (SIGILL)

Exception Codes: 0x0000000000000001, 0x0000000000000000

Exception Note: EXC_CORPSE_NOTIFY

Termination Signal: Illegal instruction: 4

Termination Reason: Namespace SIGNAL, Code 0x4

Terminating Process: exc handler [10615]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

0 swift 0x00000001015de762 swift::ASTVisitor\<(anonymous namespace)::SILGenApply, void, void, void, void, void, void>::visit(swift::Expr*) + 8978

1 swift 0x00000001015dbaa4 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 196

2 swift 0x000000010162e9c3 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional\<swift::SILLocation>) + 131

3 swift 0x0000000101622848 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 280

4 swift 0x00000001015cd88d swift::ASTVisitor\<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 109

5 swift 0x00000001016abb2b swift::ASTVisitor\<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 443

6 swift 0x00000001016aec9e swift::ASTVisitor\<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 13102

7 swift 0x00000001016abab6 swift::ASTVisitor\<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 326

8 swift 0x000000010165e77f swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 799

9 swift 0x00000001015c4959 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 953

10 swift 0x00000001015cdf4c swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1356

11 swift 0x00000001015cffce swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 1438

12 swift 0x00000001011afd51 swift::performFrontend(llvm::ArrayRef\<char const*>, char const*, void*, swift::FrontendObserver*) + 48065

13 swift 0x0000000101127b73 main + 1283

14 libdyld.dylib 0x00007fff70e4ecc9 start + 1

Thread 0 crashed with X86 Thread State (64-bit):

rax: 0x0000000000000217 rbx: 0x00007ffeeeaf36e0 rcx: 0x00000001015de762 rdx: 0x00000001015de764

rdi: 0x00007ffeeeaf1750 rsi: 0x00007f893117d5a0 rbp: 0x00007ffeeeaf1440 rsp: 0x00007ffeeeaf1270

r8: 0x00007ffeeeaf1aa0 r9: 0x0000000000000000 r10: 0x00007f8931964d00 r11: 0x00007ffeeeaf1a78

r12: 0x00007f893117d6dc r13: 0x00007f893117d5a0 r14: 0x00007ffeeeaf1750 r15: 0x00007f893117d678

rip: 0x00000001015de762 rfl: 0x0000000000010213 cr2: 0x0000000105404d20

LucianoPAlmeida commented 4 years ago

jeremyp (JIRA User), srinikhil07 (JIRA User) This seems to be fixed on master, the screenshot below is from 2020-05-22 master snapshot toolchain

Can you please verify? Thanks 🙂