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-1091] pattern 0...Int.max leads to "fatal error: Range end index has no valid successor" #43704

Closed
swift-ci opened this issue Mar 28, 2016 · 7 comments
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-1091
Radar None
Original Reporter dastrobu (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: f5f5fc1e617431187031186270fef9d2

Issue Description:

The following minimal swift program

#!/usr/bin/env swift

for i in 0...Int8.max
{
}

leads to the fatal error:

fatal error: Range end index has no valid successor

The same behavior can be observed for other int types.
Find the full error message below

fatal error: Range end index has no valid successor
0  swift                    0x0000000107f824eb llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x0000000107f817d6 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x0000000107f82b4f SignalHandler(int) + 287
3  libsystem_platform.dylib 0x00007fff95df852a _sigtramp + 26
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 1780513520
5  libsystem_platform.dylib 0x000000010a2f0088 _sigtramp + 1951366008
6  swift                    0x00000001061f1b31 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 545
7  swift                    0x00000001061f42ff 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*) + 1167
8  swift                    0x00000001060e39ec 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&) + 1916
9  swift                    0x0000000105cd794d performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 14797
10 swift                    0x0000000105cd341d frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2781
11 swift                    0x0000000105ccee3c main + 1932
12 libdyld.dylib            0x00007fff968765ad start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret ./tmp2.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 tmp2
Illegal instruction: 4
@swift-ci
Copy link
Collaborator Author

Comment by Arsen Gasparyan (JIRA)

It works like that because Swift does

_precondition(end.successor() > end, "Range end index has no valid successor")

And for Int8.max.successor() => -128 and -128 > 128 == false.

It does it because `Range` struct works with it `return Range(_start: start, end: end.successor())`.
So if we want to fix it we have to change `Range`. if I understand the code correctly.

@gribozavr could you share your opinion?

@gribozavr
Copy link
Collaborator

This issue is known. It can't be fixed in the current Range representation. @dabrahams has implemented a new representation that fixes it in our branch for the new collections model: https://github.com/apple/swift/tree/swift-3-indexing-model

@swift-ci
Copy link
Collaborator Author

Comment by Daniel Strobusch (JIRA)

Issue seems to be solved for data types up to 32 bit, but not for 64bit data type in swift 3.
This means, the following program still crashes:

    #!/usr/bin/env swift
    for i in (UInt64.max - 1)...UInt64.max
    {
    }

while it works for all smaller data types.

@Dante-Broggi
Copy link
Contributor

I think this was fixed in Swift 3, as such it should be closed.

@swift-ci
Copy link
Collaborator Author

Comment by Daniel Strobusch (JIRA)

As commented earlier, it is not fixed for 64 bit data types.

@xwu
Copy link
Collaborator

xwu commented Mar 21, 2021

dastrobu (JIRA User) This appears to be resolved. Can it be closed?

@swift-ci
Copy link
Collaborator Author

Comment by Daniel Strobusch (JIRA)

retested in Swift 5.3.2. Issue seems to be fixed.

@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

4 participants