Skip to content

WASI/Wasm: withVaList(_:) produces a va_list with the wrong type #72398

Open
@grynspan

Description

@grynspan

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

No one assigned

    Labels

    WebAssemblyPlatform: WebAssemblybugA deviation from expected or documented behavior. Also: expected but undesirable behavior.clang importerArea → compiler: The clang importerstandard libraryArea: Standard library umbrella

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions