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-10432] Compiler More Strict on Linux than macOS #52832

Open
Mordil opened this issue Apr 9, 2019 · 3 comments
Open

[SR-10432] Compiler More Strict on Linux than macOS #52832

Mordil opened this issue Apr 9, 2019 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@Mordil
Copy link

Mordil commented Apr 9, 2019

Previous ID SR-10432
Radar None
Original Reporter @Mordil
Type Bug

Attachment: Download

Environment

Swift 5 release (macOS)

Swift 5 ubuntu Xenial (https://hub.docker.com/_/swift)

Swift 5 ubuntu Bionic (https://hub.docker.com/_/swift)

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

md5: 05fba745c7ece176e5f51224860a9166

Issue Description:

I have the following code snippet

return stringBuffer.withUnsafeReadableBytes { ptr in
    // ptr is UnsafeRawBufferPointer
    Int(strtoll(ptr.bindMemory(to: Int8.self).baseAddress, nil, 10))
}

On macOS, this builds in both Xcode 10.2 and on the command line in debug & release mode - and all unit tests properly pass.

On Ubuntu Xenial and Bionic, this code gets the following error in both debug & release builds

/root/project/Sources/NIORedis/RESP/RESPDecoder.swift:116:55: error: value of optional type 'UnsafePointer<Int8>?' must be unwrapped to a value of type 'UnsafePointer<Int8>'
            Int(strtoll(ptr.bindMemory(to: Int8.self).baseAddress, nil, 10))
                                                      ^
/root/project/Sources/NIORedis/RESP/RESPDecoder.swift:116:55: note: coalesce using '??' to provide a default when the optional value contains 'nil'
            Int(strtoll(ptr.bindMemory(to: Int8.self).baseAddress, nil, 10))
                                                      ^
                                                                  ?? <#default value#>
/root/project/Sources/NIORedis/RESP/RESPDecoder.swift:116:55: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
            Int(strtoll(ptr.bindMemory(to: Int8.self).baseAddress, nil, 10))
                                                      ^
                                                                 !
@belkadan
Copy link
Contributor

What type is stringBuffer? Do you have a self-contained example you can share?

@Mordil
Copy link
Author

Mordil commented Apr 10, 2019

stringBuffer is an instance of SwiftNIO's ByteBuffer - I'll try to recreate a small repro and attach it to the ticket

@Mordil
Copy link
Author

Mordil commented Apr 10, 2019

I've added a small reproduction project that shows the compiler error difference between platforms - there's also a Dockerfile for quick Linux building

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants