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-7220] Tiny code example that crashes recent development snapshots #49768

Closed
jepers opened this issue Mar 18, 2018 · 5 comments
Closed

[SR-7220] Tiny code example that crashes recent development snapshots #49768

jepers opened this issue Mar 18, 2018 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@jepers
Copy link

jepers commented Mar 18, 2018

Previous ID SR-7220
Radar rdar://problem/38624843
Original Reporter @jepers
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @jepers
Priority Medium

md5: 3bae7e3c84e64c7ed6eb3d5392a3be23

Issue Description:

Please see related discussion in this forums thread.

Note that the same issue applies to willSet and set, and that I don't know if the compiler should allow this code or not, only that it shouldn't crash.

// --------------------------------------------------------------------------
// This program compiles with eg the default toolchain of Xcode 9.3 beta 4,
// but crashes recent versions of the compiler (for example dev snapshot
// 2018-02-25, 2018-03-13 and 2018-03-17, have only tested those three).
// --------------------------------------------------------------------------
var a: Int? {
    didSet { print("hello") }
}
a? = 123

// --------------------------------------------------------------------------
// Compiling and running with default toolchain of Xcode 9.3 beta 4:
// --------------------------------------------------------------------------
// › swiftc --version
// Apple Swift version 4.1 (swiftlang-902.0.43 clang-902.0.37.1)
// Target: x86_64-apple-darwin17.4.0
// ›
// › swiftc test.swift
// › ./test
// hello
//
// --------------------------------------------------------------------------
// Compiling and running with development snapshot 2018-03-17:
// --------------------------------------------------------------------------
// › /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-03-17-a.xctoolchain/usr/bin/swiftc --version
// Apple Swift version 4.2-dev (LLVM cef3fe6d75, Clang bdc970d89c, Swift 931d06d1cc)
// Target: x86_64-apple-darwin17.4.0
// ›
// › /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-03-17-a.xctoolchain/usr/bin/swiftc test.swift
// Assertion failed: (value && "No value specified"), function forUnmanaged, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/SILGen/ManagedValue.h, line 91.
// 0  swift                    0x000000010aaee2c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
// 1  swift                    0x000000010aaee9d6 SignalHandler(int) + 694
// 2  libsystem_platform.dylib 0x00007fff6e86df5a _sigtramp + 26
// ...

Below is an additional demonstration of the same issue. But looking at this program, I think I'm pretty sure that I think it should be valid code, which perhaps means that the above example should be considered valid code too.
(so, just to be very clear, this works as expected for def toolchain of Xc9.3b4 but crashes recent compilers):

var x: Int? = 123 {
    willSet {
        print("willSet called:")
        print("    current value: \(String(describing: x))")
        print("        new value: \(String(describing: newValue))")
    }
}
print(String(describing: x))
x?.negate()
print(String(describing: x))
@belkadan
Copy link
Contributor

I expect it would crash 9.3's compiler as well if that compiler had assertions enabled. Thanks for filing!

@belkadan
Copy link
Contributor

@swift-ci create

@jckarter
Copy link
Member

PR for master: #15546

@jckarter
Copy link
Member

and 4.2: #15547

@jckarter
Copy link
Member

jckarter commented Apr 5, 2018

The fix should be merged into future 4.2 and master snapshots now.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants