From a2086a7439effa9e484f7d2d3bbb0c04903921fd Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Tue, 16 Dec 2025 14:47:40 -0800 Subject: [PATCH 1/3] [CxxInterop] use [[msvc::no_unique_address]] on Windows (NFC) This test case used [[no_unique_address]], which is not supported on Windows. Use [[msvc::no_unique_address]] instead. Resolves https://github.com/swiftlang/swift/issues/86095 --- .../Cxx/class/Inputs/member-variables.h | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/Interop/Cxx/class/Inputs/member-variables.h b/test/Interop/Cxx/class/Inputs/member-variables.h index 198ab68913540..850506cce4ec6 100644 --- a/test/Interop/Cxx/class/Inputs/member-variables.h +++ b/test/Interop/Cxx/class/Inputs/member-variables.h @@ -5,6 +5,12 @@ #include #include +#if defined(_WIN32) || defined(_WIN64) +#define NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] +#else +#define NO_UNIQUE_ADDRESS [[no_unique_address]] +#endif + class MyClass { public: const int const_member = 23; @@ -17,11 +23,11 @@ struct Empty { struct HasZeroSizedField { int a; - [[no_unique_address]] Empty b; + NO_UNIQUE_ADDRESS Empty b; short c; - [[no_unique_address]] Empty d; + NO_UNIQUE_ADDRESS Empty d; int* e; - [[no_unique_address]] Empty f; + NO_UNIQUE_ADDRESS Empty f; int get_a() const { return a; } short get_c() const { return c; } @@ -29,7 +35,7 @@ struct HasZeroSizedField { }; struct ReuseOptionalFieldPadding { - [[no_unique_address]] std::optional a = {2}; + NO_UNIQUE_ADDRESS std::optional a = {2}; char c; char get_c() const { return c; } void set_c(char c) { this->c = c; } @@ -40,7 +46,7 @@ struct ReuseOptionalFieldPadding { using OptInt = std::optional; struct ReuseOptionalFieldPaddingWithTypedef { - [[no_unique_address]] OptInt a; + NO_UNIQUE_ADDRESS OptInt a; char c; char get_c() const { return c; } void set_c(char c) { this->c = c; } @@ -59,7 +65,7 @@ struct NonStandardLayoutClass { static_assert(std::is_standard_layout_v> == false); struct ReuseNonStandardLayoutFieldPadding { - [[no_unique_address]] NonStandardLayoutClass a; + NO_UNIQUE_ADDRESS NonStandardLayoutClass a; char c; char get_c() const { return c; } void set_c(char c) { this->c = c; } @@ -69,7 +75,7 @@ struct ReuseNonStandardLayoutFieldPadding { template struct ReuseDependentFieldPadding { - [[no_unique_address]] struct { private: T x; public: char pad_me; } a; + NO_UNIQUE_ADDRESS struct { private: T x; public: char pad_me; } a; char c; char get_c() const { return c; } void set_c(char c) { this->c = c; } @@ -94,7 +100,7 @@ struct EmptyNotImported { struct LastFieldNoUniqueAddress { char c; - [[no_unique_address]] EmptyNotImported p0; + NO_UNIQUE_ADDRESS EmptyNotImported p0; LastFieldNoUniqueAddress(const LastFieldNoUniqueAddress &other) {} LastFieldNoUniqueAddress(LastFieldNoUniqueAddress &&other) {} From a8a1a2e19fce6cac13d235f96b63afa259f5386e Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Wed, 17 Dec 2025 12:12:19 -0800 Subject: [PATCH 2/3] Apply suggestion from @compnerd Co-authored-by: Saleem Abdulrasool --- test/Interop/Cxx/class/Inputs/member-variables.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Interop/Cxx/class/Inputs/member-variables.h b/test/Interop/Cxx/class/Inputs/member-variables.h index 850506cce4ec6..e724b34b84b82 100644 --- a/test/Interop/Cxx/class/Inputs/member-variables.h +++ b/test/Interop/Cxx/class/Inputs/member-variables.h @@ -5,7 +5,7 @@ #include #include -#if defined(_WIN32) || defined(_WIN64) +#if defined(_MSC_VER) #define NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] #else #define NO_UNIQUE_ADDRESS [[no_unique_address]] From fa574bae084e2047d601fe71779ae8e671f2a089 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Wed, 17 Dec 2025 12:30:19 -0800 Subject: [PATCH 3/3] don't share MemberVariables module when testing diagnostics This header is shared by 3 tests, one of which checks diagnostics. If that test picks up an already built module from the module cache, it won't pick up diagnostics in the header. This duplicates the header as two separate modules rather than specifying an explicit module cache, to avoid rebuilding CxxStdlib. --- test/Interop/Cxx/class/Inputs/module.modulemap | 10 +++++++++- .../Cxx/class/member-variables-module-interface.swift | 2 +- .../Cxx/class/member-variables-typechecker.swift | 2 +- test/Interop/Cxx/class/zero-sized-field.swift | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/Interop/Cxx/class/Inputs/module.modulemap b/test/Interop/Cxx/class/Inputs/module.modulemap index ab8bb3e04e78c..8dccb9e43da38 100644 --- a/test/Interop/Cxx/class/Inputs/module.modulemap +++ b/test/Interop/Cxx/class/Inputs/module.modulemap @@ -48,7 +48,15 @@ module MemoryLayout { requires cplusplus } -module MemberVariables { +// This header is shared between 3 test cases. It's built with -verify in +// test/Interop/Cxx/class/member-variables-typechecker.swift, which is defeated +// if the test just picks up a cached module. We could set the module cache path +// explicitly, but that would rebuild CxxStdlib which is really slow. +module MemberVariablesNoDiagnostics { + header "member-variables.h" + requires cplusplus +} +module MemberVariablesDiagnostics { header "member-variables.h" requires cplusplus } diff --git a/test/Interop/Cxx/class/member-variables-module-interface.swift b/test/Interop/Cxx/class/member-variables-module-interface.swift index ed3bbb861942b..542f8ffb54176 100644 --- a/test/Interop/Cxx/class/member-variables-module-interface.swift +++ b/test/Interop/Cxx/class/member-variables-module-interface.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-ide-test -print-module -module-to-print=MemberVariables -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s +// RUN: %target-swift-ide-test -print-module -module-to-print=MemberVariablesNoDiagnostics -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s // CHECK: struct MyClass { // CHECK-NEXT: init() diff --git a/test/Interop/Cxx/class/member-variables-typechecker.swift b/test/Interop/Cxx/class/member-variables-typechecker.swift index bd4ff0541acc5..25fe37a94cce9 100644 --- a/test/Interop/Cxx/class/member-variables-typechecker.swift +++ b/test/Interop/Cxx/class/member-variables-typechecker.swift @@ -1,6 +1,6 @@ // RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-experimental-cxx-interop -import MemberVariables +import MemberVariablesDiagnostics var s = MyClass() s.const_member = 42 // expected-error {{cannot assign to property: 'const_member' setter is inaccessible}} diff --git a/test/Interop/Cxx/class/zero-sized-field.swift b/test/Interop/Cxx/class/zero-sized-field.swift index 04403422e4e2b..fe71e1a964411 100644 --- a/test/Interop/Cxx/class/zero-sized-field.swift +++ b/test/Interop/Cxx/class/zero-sized-field.swift @@ -4,7 +4,7 @@ // REQUIRES: executable_test import StdlibUnittest -import MemberVariables +import MemberVariablesNoDiagnostics var FieldsTestSuite = TestSuite("Generating code with zero sized fields")