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-578] Crash without error message when converting a UInt32 to UInt8. #43195

Closed
swift-ci opened this issue Jan 19, 2016 · 4 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-578
Radar rdar://problem/23119586
Original Reporter ap (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Noticed this using the swift-2.2-SNAPSHOT-2016-01-11-a-osx.pkg build on OS X 10.11.2.

$ uname -a
Darwin test 15.2.0 Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64
$ swift --version
Apple Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 42591f7cba)
Target: x86_64-apple-macosx10.9
$
Additional Detail from JIRA
Votes 1
Component/s Standard Library
Labels Bug
Assignee ap (JIRA)
Priority Medium

md5: 87b5f8cd29b52c8d77035de756713e7f

Issue Description:

Code:

func test(v: UInt32) -> UInt8 {
    return UInt8(v)
}

test(256)

Result:

$ swift test.swift 
0  swift                    0x000000010df2063b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x000000010df1f8f6 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x000000010df20ce2 SignalHandler(int) + 322
3  libsystem_platform.dylib 0x00007fff95560eaa _sigtramp + 26
4  libswiftCore.dylib       0x00000001107a42c2 guard variable for _swift_stdlib_operatingSystemVersion::version + 11738
5  libswiftCore.dylib       0x000000011047b063 guard variable for _swift_stdlib_operatingSystemVersion::version + 4291664763
6  swift                    0x000000010be16b41 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 1345
7  swift                    0x000000010be19eaf llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 1231
8  swift                    0x000000010bce5760 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 2752
9  swift                    0x000000010b7e6e6e frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 11582
10 swift                    0x000000010b7e01e7 main + 2855
11 libdyld.dylib            0x00007fff988d05ad start + 1
12 libdyld.dylib            0x000000000000000c start + 1735588448
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2016-01-11-a.xctoolchain/usr/bin/swift -frontend -interpret test.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -color-diagnostics -module-name test 
Illegal instruction: 4
$
@belkadan
Copy link
Contributor

FWIW the crash is expected, since "256" doesn't fit in a UInt8. But it should definitely print some kind of error message.

@Dante-Broggi
Copy link
Contributor

Should this be closed? The error message in the Xcode 9.4.1 toolchain is "Fatal error: Not enough bits to represent a signed value".

@belkadan
Copy link
Contributor

cc @moiseev

@moiseev
Copy link
Mannequin

moiseev mannequin commented Jul 17, 2018

The implementation of conversion initializers changed and now uses `_precondition` that is capable of presenting a message even in release builds. So yeah, can be marked as resolved.

@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. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants