Skip to content
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

[SR-7805] Compiler crasher, only in release build and only with recent dev snapshot #50344

Closed
jepers opened this issue May 30, 2018 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation regression swift 4.2

Comments

@jepers
Copy link

jepers commented May 30, 2018

Previous ID SR-7805
Radar rdar://problem/40650953
Original Reporter @jepers
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

Xcode 9.4 (9F1027a) with
Swift Development Snapshot 2018-05-29 (a).

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression, OptimizedOnly
Assignee @eeckstein
Priority Medium

md5: 7ba6793946ce636d8f600efba266a88a

Issue Description:

The attached Xcode project is a simple Command Line App with only the following main.swift.

So the compiler crash can also be reproduced by compiling the following program using swiftc of a recent snapshot and -O, as shown in the comments at the end of the program, together with the resulting crash message.

//-----------------------------------------------------------------------------
// This program demonstrates a compiler crash that happens ONLY
// for a release build AND using a recent snapshot.
//-----------------------------------------------------------------------------
// While playing around with the demo program for SR-7023, I noticed a compiler
// crash that turned out to only happen when using a recent dev snapshot AND
// only if doing a release build.
//
// This (unmodified) project is in the crashing state (provided that you use
// a recent dev snapshot of course).
//
// I've reduced the code as far as I could without loosing the compiler crash.
//
// I'm using Xcode 9.4 (9F1027a) and Swift Development Snapshot 2018-05-29 (a).
//-----------------------------------------------------------------------------

extension FixedWidthInteger {
    init<S>(foo: S) where S: FixedWidthInteger {
        if MemoryLayout<S>.size < MemoryLayout<Self>.size {
            self = 0
        } else {
            self = 1
        }
    }
}

func bar() {
    var arr = [Int16](repeating: 0, count: 123)
    var checksum = UInt64(0)
    let count = arr.count
    var i = 0 // There will be a warning for this, but ...
    while i < count {
        let dst = UInt64(foo: arr[i])
        checksum = checksum ^ dst
        // i = i &+ 1 // ... compiler crash goes away if uncommenting this.
    }
    print("  blabla: \(checksum))")
}

bar()

//-----------------------------------------------------------------------------
// Here's what the crash looks like (compiling with swiftc of above snapshot):
//
// $ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-05-29-a.xctoolchain/usr/bin/swiftc -O main.swift
// main.swift:32:9: warning: variable 'i' was never mutated; consider changing to 'let' constant
//     var i = 0 // There will be a warning for this, but ...
//     ~~~ ^
//     let
// 0  swift                    0x000000010eda3dc8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
// 1  swift                    0x000000010eda3037 llvm::sys::RunSignalHandlers() + 39
// 2  swift                    0x000000010eda4442 SignalHandler(int) + 258
// 3  libsystem_platform.dylib 0x00007fff56393f5a _sigtramp + 26
// 4  libsystem_platform.dylib 0x000000011101a080 _sigtramp + 3133694272
// 5  swift                    0x000000010bf47213 swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1475
// 6  swift                    0x000000010bf48163 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 1315
// 7  swift                    0x000000010bf48e24 swift::SILPassManager::execute() + 660
// 8  swift                    0x000000010b75f32b swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 187
// 9  swift                    0x000000010bf50c25 swift::runSILOptimizationPasses(swift::SILModule&) + 117
// 10 swift                    0x000000010b5fa2d0 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13520
// 11 swift                    0x000000010b5f5db1 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3297
// 12 swift                    0x000000010b5b1dad main + 2317
// 13 libdyld.dylib            0x00007fff56085015 start + 1
// 14 libdyld.dylib            0x000000000000000e start + 2851581946
// Stack dump:
// 0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-05-29-a.xctoolchain/usr/bin/swift -frontend -c -primary-file main.swift -target x86_64-apple-darwin17.5.0 -enable-objc-interop -O -color-diagnostics -module-name main -o /var/folders/50/br4kxvjd0t551h0fmtrzkwdw0000gn/T/main-a6eb9c.o
// 1.  While running pass #&#8203;3957 SILFunctionTransform "DCE" on SILFunction "@$S4main3baryyF".
//  for 'bar()' at main.swift:28:1
// <unknown>:0: error: unable to execute command: Segmentation fault: 11
// <unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)
//-----------------------------------------------------------------------------
@atrick
Copy link
Member

atrick commented May 30, 2018

@swift-ci create

@atrick
Copy link
Member

atrick commented May 30, 2018

@eeckstein crash in DCE. I haven't tried to reproduce yet.

@belkadan
Copy link
Contributor

Confused by the provably-infinite loop, perhaps?

@eeckstein
Copy link
Member

Fixed in #16912

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation regression swift 4.2
Projects
None yet
Development

No branches or pull requests

5 participants