Skip to content

Commit f1f55bb

Browse files
authored
Merge pull request #86098 from swiftlang/member-var-windows
[CxxInterop] use [[msvc::no_unique_address]] on Windows (NFC)
2 parents fb3f044 + fa574ba commit f1f55bb

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

test/Interop/Cxx/class/Inputs/member-variables.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
#include <type_traits>
66
#include <optional>
77

8+
#if defined(_MSC_VER)
9+
#define NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
10+
#else
11+
#define NO_UNIQUE_ADDRESS [[no_unique_address]]
12+
#endif
13+
814
class MyClass {
915
public:
1016
const int const_member = 23;
@@ -17,19 +23,19 @@ struct Empty {
1723

1824
struct HasZeroSizedField {
1925
int a;
20-
[[no_unique_address]] Empty b;
26+
NO_UNIQUE_ADDRESS Empty b;
2127
short c;
22-
[[no_unique_address]] Empty d;
28+
NO_UNIQUE_ADDRESS Empty d;
2329
int* e;
24-
[[no_unique_address]] Empty f;
30+
NO_UNIQUE_ADDRESS Empty f;
2531

2632
int get_a() const { return a; }
2733
short get_c() const { return c; }
2834
void set_c(short c) { this->c = c; }
2935
};
3036

3137
struct ReuseOptionalFieldPadding {
32-
[[no_unique_address]] std::optional<int> a = {2};
38+
NO_UNIQUE_ADDRESS std::optional<int> a = {2};
3339
char c;
3440
char get_c() const { return c; }
3541
void set_c(char c) { this->c = c; }
@@ -40,7 +46,7 @@ struct ReuseOptionalFieldPadding {
4046
using OptInt = std::optional<int>;
4147

4248
struct ReuseOptionalFieldPaddingWithTypedef {
43-
[[no_unique_address]] OptInt a;
49+
NO_UNIQUE_ADDRESS OptInt a;
4450
char c;
4551
char get_c() const { return c; }
4652
void set_c(char c) { this->c = c; }
@@ -59,7 +65,7 @@ struct NonStandardLayoutClass {
5965
static_assert(std::is_standard_layout_v<NonStandardLayoutClass<int>> == false);
6066

6167
struct ReuseNonStandardLayoutFieldPadding {
62-
[[no_unique_address]] NonStandardLayoutClass<int> a;
68+
NO_UNIQUE_ADDRESS NonStandardLayoutClass<int> a;
6369
char c;
6470
char get_c() const { return c; }
6571
void set_c(char c) { this->c = c; }
@@ -69,7 +75,7 @@ struct ReuseNonStandardLayoutFieldPadding {
6975

7076
template<typename T>
7177
struct ReuseDependentFieldPadding {
72-
[[no_unique_address]] struct { private: T x; public: char pad_me; } a;
78+
NO_UNIQUE_ADDRESS struct { private: T x; public: char pad_me; } a;
7379
char c;
7480
char get_c() const { return c; }
7581
void set_c(char c) { this->c = c; }
@@ -94,7 +100,7 @@ struct EmptyNotImported {
94100

95101
struct LastFieldNoUniqueAddress {
96102
char c;
97-
[[no_unique_address]] EmptyNotImported p0;
103+
NO_UNIQUE_ADDRESS EmptyNotImported p0;
98104

99105
LastFieldNoUniqueAddress(const LastFieldNoUniqueAddress &other) {}
100106
LastFieldNoUniqueAddress(LastFieldNoUniqueAddress &&other) {}

test/Interop/Cxx/class/Inputs/module.modulemap

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ module MemoryLayout {
4848
requires cplusplus
4949
}
5050

51-
module MemberVariables {
51+
// This header is shared between 3 test cases. It's built with -verify in
52+
// test/Interop/Cxx/class/member-variables-typechecker.swift, which is defeated
53+
// if the test just picks up a cached module. We could set the module cache path
54+
// explicitly, but that would rebuild CxxStdlib which is really slow.
55+
module MemberVariablesNoDiagnostics {
56+
header "member-variables.h"
57+
requires cplusplus
58+
}
59+
module MemberVariablesDiagnostics {
5260
header "member-variables.h"
5361
requires cplusplus
5462
}

test/Interop/Cxx/class/member-variables-module-interface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-ide-test -print-module -module-to-print=MemberVariables -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=MemberVariablesNoDiagnostics -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
22

33
// CHECK: struct MyClass {
44
// CHECK-NEXT: init()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-experimental-cxx-interop
22

3-
import MemberVariables
3+
import MemberVariablesDiagnostics
44

55
var s = MyClass()
66
s.const_member = 42 // expected-error {{cannot assign to property: 'const_member' setter is inaccessible}}

test/Interop/Cxx/class/zero-sized-field.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// REQUIRES: executable_test
55

66
import StdlibUnittest
7-
import MemberVariables
7+
import MemberVariablesNoDiagnostics
88

99
var FieldsTestSuite = TestSuite("Generating code with zero sized fields")
1010

0 commit comments

Comments
 (0)