-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
WebAssemblyPlatform: WebAssemblyPlatform: WebAssemblybugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.clang importerArea → compiler: The clang importerArea → compiler: The clang importerstandard libraryArea: Standard library umbrellaArea: Standard library umbrella
Description
Description
swift-testing uses withVaList(_:)
in one spot and, when building for WASI/Wasm, runs into this error:
/swift-testing/Sources/Testing/Events/TimeValue.swift:87:79: error: cannot convert value of type 'CVaListPointer' to expected argument type '__isoc_va_list?' (aka 'Optional<UnsafeMutableRawPointer>')
_ = vsnprintf(buffer.baseAddress!, buffer.count, "%lld.%03d seconds", args)
Looks like either CVaListPointer
is typealiased incorrectly or needs to be implemented.
Reproduction
Try to build the following code for WASI/Wasm:
let string = withUnsafeTemporaryAllocation(of: CChar.self, capacity: 512) { buffer in
withVaList([CInt(123)]) { args in
_ = vsnprintf(buffer.baseAddress!, buffer.count, "%d", args)
}
return String(cString: buffer.baseAddress!)
}
print(string)
Expected behavior
Prints 123
.
Environment
SwiftWasm Swift version 5.10-dev (LLVM 5dc9d563e5a6cd2, Swift 3aaeb1a91e1c0a5)
Target: arm64-apple-darwin23.4.0
Additional information
No response
Metadata
Metadata
Assignees
Labels
WebAssemblyPlatform: WebAssemblyPlatform: WebAssemblybugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.clang importerArea → compiler: The clang importerArea → compiler: The clang importerstandard libraryArea: Standard library umbrellaArea: Standard library umbrella
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]WASI/WASM: `withVaList(_:)` produces a va_list with the wrong type[/-][+]WASI/Wasm: `withVaList(_:)` produces a va_list with the wrong type[/+]MaxDesiatov commentedon Mar 18, 2024
cc @kateinoigakukun
kateinoigakukun commentedon Mar 18, 2024
We might need to re-consider #31692
MaxDesiatov commentedon Mar 18, 2024
I'm curious if @al45tair has seen this with Musl previously?
grynspan commentedon Mar 18, 2024
Is it just a matter of adding a mapping here? https://github.com/apple/swift/blob/main/lib/ClangImporter/MappedTypes.def#L131
MaxDesiatov commentedon Mar 18, 2024
That's what my previous attempt to fix it was about https://github.com/apple/swift/pull/31692/files#diff-794a8ab7c1a5c80032405934f97c0e1e0d6b6acabd9a308c61c4dbd563dff48d. But I couldn't get the test passing on x86_64 macOS, even though it passed on all other platforms.
grynspan commentedon Mar 18, 2024
Looks like the runs have been purged from CI… might be worth trying again just to get an up-to-date CI failure.
al45tair commentedon Mar 22, 2024
I haven't, but then I haven't really tried using C varargs functions and I would imagine there isn't that much Swift code out there that does. It's entirely possible that this is broken in the fully static SDK too.
grynspan commentedon Mar 25, 2024
I worked around the issue in my case, but it'd be nice to not have to.
turbolent commentedon May 11, 2024
@grynspan How did you work around the issue?
grynspan commentedon May 13, 2024
Our particular use case was for custom formatting of time intervals as strings, so we just used
String(describing:)
instead and traded the custom format for the default one on WASI. This is probably not a general solution.