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-3429] va_list parameter in block definition has different optionality depending on target #46017

Open
swift-ci opened this issue Dec 15, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3429
Radar None
Original Reporter fabiorodella (JIRA User)
Type Bug
Environment

mac OS 10.12.1 (16B2657), XCode Version 8.2 (8C38), Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)

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

md5: 79c1be2adbdd057a045342fddea235c6

Issue Description:

I recently added the RZBluetooth library (https://github.com/Raizlabs/RZBluetooth) in a Swift 3 project, and the library has a function defined as:

FOUNDATION_EXPORT void RZBSetLogHandler(RZBLogHandler);

and RZBLogHandler is a typedef

typedef void(^RZBLogHandler)(RZBLogLevel logLevel, NSString *format, va_list args);

However, depending on the chosen target, the optionality for the args parameter in the Swift mapped typealias is different. It looks like this when using a device target:

public typealias RZBLogHandler = (RZBLogLevel, String?, CVaListPointer?) -> Swift.Void

but changes to this when using a simulator target

public typealias RZBLogHandler = (RZBLogLevel, String?, CVaListPointer) -> Swift.Void

As a result I have code that will not compile depending on the chosen target.
I'm not sure if this was happening before the upgrade to Version 8.2 (8C38) because unfortunately I hadn't tried to run the app in the simulator yet.

@swift-ci
Copy link
Collaborator Author

Comment by ​​ (JIRA)

A workaround is required to handle the optionality differences when building for iOS Simulator architectures (i.e. x86_64) vs. real iOS device architectures (i.e. arm64):

  1. Building for iOS Simulator, the optionality for a `CVaListPointer` parameter is non-optional.
  2. Building for real iOS device, the optionality for a `CVaListPointer` parameter is optional.

`va_list` is an array type for x86_64 and a pointer type for arm64, so the optionality differences between the archs appears correct.

Is this working as intended or should the Swift compiler try to handle the C to Swift bridging for arm64 so that the optionality is consistent with x86_64?


Other links:

  1. `CVaListPointer` definition (

    /// A wrapper around a C `va_list` pointer.
    ).

  2. MappedTypes note about special handling for platforms where `va_list` is an array (

    // Note: this does not catch va_list on platforms where va_list is an array.
    ).

  3. `VisitDecayedType(...)` workaround mentioned in MappedTypes (

    ImportResult VisitDecayedType(const clang::DecayedType *type) {
    ).

  4. `adjustTypeForConcreteImport(...)` code for handling null-unspecified `va_list` parameters (

    // Treat va_list specially: null-unspecified va_list parameters should be
    ).

@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

1 participant