From da2119e315f22b31ed3785189d0776080c4c47ea Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 11 Sep 2025 07:22:22 +0000 Subject: [PATCH 1/2] [wasm] Fix `@_expose(wasm)` serialization crash https://github.com/swiftlang/swift/pull/82616 added a new exposure kind for the `@_expose` attribute, but did not update the serialization format to account for the new kind. This caused a crash when serializing a module that used `@_expose(wasm)`. --- lib/Serialization/ModuleFormat.h | 2 +- test/Serialization/attr-expose.swift | 31 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/Serialization/attr-expose.swift diff --git a/lib/Serialization/ModuleFormat.h b/lib/Serialization/ModuleFormat.h index b5c13d1708a59..8d344ef71bbd0 100644 --- a/lib/Serialization/ModuleFormat.h +++ b/lib/Serialization/ModuleFormat.h @@ -2526,7 +2526,7 @@ namespace decls_block { >; using ExposeDeclAttrLayout = BCRecordLayout, // exposure kind + BCFixed<2>, // exposure kind BCFixed<1>, // implicit flag BCBlob // declaration name >; diff --git a/test/Serialization/attr-expose.swift b/test/Serialization/attr-expose.swift new file mode 100644 index 0000000000000..b57b6f5f87cb8 --- /dev/null +++ b/test/Serialization/attr-expose.swift @@ -0,0 +1,31 @@ +// RUN: %empty-directory(%t) +// RUN: %target-swift-frontend -module-name attr_expose -emit-module -parse-as-library -o %t %s +// RUN: %target-sil-opt -enable-sil-verify-all %t/attr_expose.swiftmodule | %FileCheck %s + +// @_expose +// ----------------------------------------------------------------------------- + +// CHECK: @_expose(Cxx) +// CHECK-NEXT: func exposeToCxx() +@_expose(Cxx) +func exposeToCxx() -> Int { return 42 } + +// CHECK: @_expose(Cxx, "custom_name") +// CHECK-NEXT: func exposeToCxxWithName() +@_expose(Cxx, "custom_name") +func exposeToCxxWithName() -> Int { return 24 } + +// CHECK: @_expose(!Cxx) +// CHECK-NEXT: func dontExposeToCxx() +@_expose(!Cxx) +func dontExposeToCxx() -> Int { return 13 } + +// CHECK: @_expose(wasm) +// CHECK-NEXT: func exposeToWasm() +@_expose(wasm) +func exposeToWasm() -> Int { return 99 } + +// CHECK: @_expose(wasm, "wasm_custom") +// CHECK-NEXT func exposeToWasmWithName() +@_expose(wasm, "wasm_custom") +func exposeToWasmWithName() -> Int { return 88 } From 66902410f0f7c1f67705ae3a36d041c29c5e3a71 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 23 Sep 2025 00:46:00 +0000 Subject: [PATCH 2/2] [6.2][ModuleFormat] Bump module format version --- lib/Serialization/ModuleFormat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Serialization/ModuleFormat.h b/lib/Serialization/ModuleFormat.h index 8d344ef71bbd0..838324c766302 100644 --- a/lib/Serialization/ModuleFormat.h +++ b/lib/Serialization/ModuleFormat.h @@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0; /// describe what change you made. The content of this comment isn't important; /// it just ensures a conflict if two people change the module format. /// Don't worry about adhering to the 80-column limit for this line. -const uint16_t SWIFTMODULE_VERSION_MINOR = 947; // @preEnumExtensibility attribute +const uint16_t SWIFTMODULE_VERSION_MINOR = 948; // @_expose kind /// A standard hash seed used for all string hashes in a serialized module. ///