Skip to content

Serialization,Frontend: more aggressively preserve clang signatures for 32-bit Windows - #92492

Open
compnerd wants to merge 2 commits into
swiftlang:mainfrom
compnerd:com-clang-function-types
Open

compnerd wants to merge 2 commits into
swiftlang:mainfrom
compnerd:com-clang-function-types

Conversation

@compnerd

Copy link
Copy Markdown
Member

This pull request improves the handling and preservation of C calling conventions, particularly the stdcall convention, in Swift's function type system and serialization/deserialization logic. The changes ensure that calling conventions from imported Win32 COM function types are correctly maintained across module boundaries, even when modules are built with different settings. Several new and updated tests are included to verify this behavior, especially on Windows x86 targets.

Language and Compiler Logic Improvements

  • Updated CompilerInvocation.cpp to automatically enable Clang function types for imported Win32 COM functions using the Microsoft COM interop model on Windows x86, ensuring the stdcall convention is preserved.
  • Enhanced SIL function type deserialization in Deserialization.cpp to reconstruct Clang function types from SIL signatures when required, while preserving non-default calling conventions during deserialization.

Testing and Verification

  • Added/updated tests to ensure correct preservation and reconstruction of calling conventions:
    • New test for stdcall convention preservation across SIL serialization/deserialization on Windows x86 (clang-function-types-stdcall.sil).
    • New test verifying COM interop and stdcall/cdecl conventions in cross-module scenarios (com-clang-function-types-x86.swift).
    • New tests for reconstructing Clang function types during cross-module SIL deserialization (clang-function-type-skew-sil.swift and clang-function-type-skew-block.swift). [1] [2]
    • Updated existing test to cover Microsoft COM interop model with Clang function types (c-function-calling-convention.sil).

These changes collectively improve ABI stability and interop correctness when dealing with C function pointers and calling conventions in Swift, especially for Windows COM scenarios.

A client using Clang function types can load serialized SIL from a module
built without them. Deserializing a C function or block then reaches the
SIL function type invariant without the Clang type required by the client.

Reconstruct missing types from the serialized SIL signature before forming
the function type. Keep this compatibility handling in deserialization so
other callers still have to satisfy the invariant, and preserve stored
Clang types carrying non-default calling conventions.
Microsoft COM function pointers use stdcall on 32-bit Windows. Without
stored Clang function types, SIL lowering erases the imported convention
and indirect calls use the platform C convention.

Enable Clang function types for Microsoft COM on x86 Windows so imported
calling conventions survive SIL lowering and module serialization.
@compnerd

Copy link
Copy Markdown
Member Author

@swift-ci please smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant