Skip to content

Commit 34def0e

Browse files
authored
Merge pull request #76589 from hjyamauchi/issue74866-3
Ensure that bridged types are indirectly returned on Windows ARM64
2 parents b2cb375 + dedfb9e commit 34def0e

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ class BridgedDeclBaseName {
8181
BridgedIdentifier Ident;
8282

8383
public:
84+
// Ensure that this struct value type will be indirectly returned on
85+
// Windows ARM64
86+
BridgedDeclBaseName() : Ident() {}
87+
8488
#ifdef USED_IN_CPP_SOURCE
8589
BridgedDeclBaseName(swift::DeclBaseName baseName) : Ident(baseName.Ident) {}
8690

@@ -107,6 +111,10 @@ class BridgedDeclNameRef {
107111
void *_Nonnull opaque;
108112

109113
public:
114+
// Ensure that this struct value type will be indirectly returned on
115+
// Windows ARM64
116+
BridgedDeclNameRef() : opaque() {}
117+
110118
#ifdef USED_IN_CPP_SOURCE
111119
BridgedDeclNameRef(swift::DeclNameRef name) : opaque(name.getOpaqueValue()) {}
112120

@@ -163,6 +171,10 @@ class BridgedASTContext {
163171
swift::ASTContext * _Nonnull Ctx;
164172

165173
public:
174+
// Ensure that this struct value type will be indirectly returned on
175+
// Windows ARM64
176+
BridgedASTContext() : Ctx() {}
177+
166178
#ifdef USED_IN_CPP_SOURCE
167179
SWIFT_UNAVAILABLE("Use init(raw:) instead")
168180
BridgedASTContext(swift::ASTContext &ctx) : Ctx(&ctx) {}
@@ -390,6 +402,10 @@ class BridgedDiagnosticArgument {
390402
int64_t storage[3];
391403

392404
public:
405+
// Ensure that this struct value type will be indirectly returned on
406+
// Windows ARM64
407+
BridgedDiagnosticArgument() {}
408+
393409
#ifdef USED_IN_CPP_SOURCE
394410
BridgedDiagnosticArgument(const swift::DiagnosticArgument &arg) {
395411
*reinterpret_cast<swift::DiagnosticArgument *>(&storage) = arg;
@@ -407,6 +423,10 @@ class BridgedDiagnosticFixIt {
407423
int64_t storage[7];
408424

409425
public:
426+
// Ensure that this struct value type will be indirectly returned on
427+
// Windows ARM64
428+
BridgedDiagnosticFixIt() {}
429+
410430
#ifdef USED_IN_CPP_SOURCE
411431
BridgedDiagnosticFixIt(const swift::DiagnosticInfo::FixIt &fixit){
412432
*reinterpret_cast<swift::DiagnosticInfo::FixIt *>(&storage) = fixit;
@@ -1406,6 +1426,10 @@ class BridgedStmtConditionElement {
14061426
void *_Nonnull Raw;
14071427

14081428
public:
1429+
// Ensure that this struct value type will be indirectly returned on
1430+
// Windows ARM64
1431+
BridgedStmtConditionElement() {}
1432+
14091433
#ifdef USED_IN_CPP_SOURCE
14101434
BridgedStmtConditionElement(swift::StmtConditionElement elem)
14111435
: Raw(elem.getOpaqueValue()) {}

include/swift/Basic/BasicBridging.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
// Pure bridging mode does not permit including any C++/llvm/swift headers.
2424
// See also the comments for `BRIDGING_MODE` in the top-level CMakeLists.txt file.
2525
//
26+
//
27+
// Note: On Windows ARM64, how a C++ struct/class value type is
28+
// returned is sensitive to conditions including whether a
29+
// user-defined constructor exists, etc. See
30+
// https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#return-values
31+
// So, if a C++ struct/class type is returned as a value between Swift
32+
// and C++, we need to be careful to match the return convention
33+
// matches between the non-USED_IN_CPP_SOURCE (Swift) side and the
34+
// USE_IN_CPP_SOURCE (C++) side.
2635
#include "swift/Basic/BridgedSwiftObject.h"
2736
#include "swift/Basic/Compiler.h"
2837

@@ -227,6 +236,10 @@ class BridgedOwnedString {
227236
size_t Length;
228237

229238
public:
239+
// Ensure that this struct value type will be indirectly returned on
240+
// Windows ARM64
241+
BridgedOwnedString() {}
242+
230243
#ifdef USED_IN_CPP_SOURCE
231244
BridgedOwnedString(const std::string &stringToCopy);
232245

include/swift/Parse/ParseBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class BridgedLegacyParser {
3030
swift::Parser *_Nonnull const handle;
3131

3232
public:
33+
// Ensure that this struct value type will be indirectly returned on
34+
// Windows ARM64
35+
BridgedLegacyParser() : handle(nullptr) {}
36+
3337
#ifdef USED_IN_CPP_SOURCE
3438
BridgedLegacyParser(swift::Parser &P) : handle(&P) {}
3539

include/swift/SIL/SILBridging.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ struct BridgedResultInfo {
8383
swift::TypeBase * _Nonnull type;
8484
BridgedResultConvention convention;
8585

86+
// Ensure that this struct value type will be indirectly returned on
87+
// Windows ARM64
88+
BridgedResultInfo() {}
89+
8690
#ifdef USED_IN_CPP_SOURCE
8791
inline static BridgedResultConvention
8892
castToResultConvention(swift::ResultConvention convention) {
@@ -100,6 +104,10 @@ struct OptionalBridgedResultInfo {
100104
swift::TypeBase * _Nullable type = nullptr;
101105
BridgedResultConvention convention = BridgedResultConvention::Indirect;
102106

107+
// Ensure that this struct value type will be indirectly returned on
108+
// Windows ARM64
109+
OptionalBridgedResultInfo() {}
110+
103111
#ifdef USED_IN_CPP_SOURCE
104112
OptionalBridgedResultInfo(std::optional<swift::SILResultInfo> resultInfo) {
105113
if (resultInfo) {
@@ -114,6 +122,10 @@ struct OptionalBridgedResultInfo {
114122
struct BridgedResultInfoArray {
115123
BridgedArrayRef resultInfoArray;
116124

125+
// Ensure that this struct value type will be indirectly returned on
126+
// Windows ARM64
127+
BridgedResultInfoArray() {}
128+
117129
#ifdef USED_IN_CPP_SOURCE
118130
BridgedResultInfoArray(llvm::ArrayRef<swift::SILResultInfo> results)
119131
: resultInfoArray(results) {}
@@ -217,6 +229,10 @@ struct BridgedParameterInfo {
217229
struct BridgedParameterInfoArray {
218230
BridgedArrayRef parameterInfoArray;
219231

232+
// Ensure that this struct value type will be indirectly returned on
233+
// Windows ARM64
234+
BridgedParameterInfoArray() {}
235+
220236
#ifdef USED_IN_CPP_SOURCE
221237
BridgedParameterInfoArray(llvm::ArrayRef<swift::SILParameterInfo> parameters)
222238
: parameterInfoArray(parameters) {}
@@ -235,6 +251,10 @@ struct BridgedParameterInfoArray {
235251
struct BridgedYieldInfoArray {
236252
BridgedArrayRef yieldInfoArray;
237253

254+
// Ensure that this struct value type will be indirectly returned on
255+
// Windows ARM64
256+
BridgedYieldInfoArray() {}
257+
238258
#ifdef USED_IN_CPP_SOURCE
239259
BridgedYieldInfoArray(llvm::ArrayRef<swift::SILYieldInfo> yields)
240260
: yieldInfoArray(yields) {}
@@ -255,6 +275,10 @@ struct BridgedLifetimeDependenceInfo {
255275
SwiftUInt targetIndex;
256276
bool immortal;
257277

278+
// Ensure that this struct value type will be indirectly returned on
279+
// Windows ARM64
280+
BridgedLifetimeDependenceInfo() {}
281+
258282
#ifdef USED_IN_CPP_SOURCE
259283
BridgedLifetimeDependenceInfo(swift::LifetimeDependenceInfo info)
260284
: inheritLifetimeParamIndices(info.getInheritIndices()),
@@ -273,6 +297,10 @@ struct BridgedLifetimeDependenceInfo {
273297
struct BridgedLifetimeDependenceInfoArray {
274298
BridgedArrayRef lifetimeDependenceInfoArray;
275299

300+
// Ensure that this struct value type will be indirectly returned on
301+
// Windows ARM64
302+
BridgedLifetimeDependenceInfoArray() {}
303+
276304
#ifdef USED_IN_CPP_SOURCE
277305
BridgedLifetimeDependenceInfoArray(
278306
llvm::ArrayRef<swift::LifetimeDependenceInfo> lifetimeDependenceInfo)
@@ -373,6 +401,10 @@ struct BridgedType {
373401
struct EnumElementIterator {
374402
uint64_t storage[4];
375403

404+
// Ensure that this struct value type will be indirectly returned on
405+
// Windows ARM64
406+
EnumElementIterator() {}
407+
376408
#ifdef USED_IN_CPP_SOURCE
377409
EnumElementIterator(swift::EnumDecl::ElementRange::iterator i) {
378410
static_assert(sizeof(EnumElementIterator) >= sizeof(swift::EnumDecl::ElementRange::iterator));
@@ -386,6 +418,10 @@ struct BridgedType {
386418
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE EnumElementIterator getNext() const;
387419
};
388420

421+
// Ensure that this struct value type will be indirectly returned on
422+
// Windows ARM64
423+
BridgedType() {}
424+
389425
#ifdef USED_IN_CPP_SOURCE
390426
BridgedType(swift::SILType t) : opaqueValue(t.getOpaqueValue()) {}
391427

@@ -573,6 +609,10 @@ enum class BridgedMemoryBehavior {
573609
struct BridgedLocation {
574610
uint64_t storage[3];
575611

612+
// Ensure that this struct value type will be indirectly returned on
613+
// Windows ARM64
614+
BridgedLocation() {}
615+
576616
#ifdef USED_IN_CPP_SOURCE
577617
BridgedLocation(const swift::SILDebugLocation &loc) {
578618
*reinterpret_cast<swift::SILDebugLocation *>(&storage) = loc;
@@ -804,6 +844,10 @@ struct BridgedTypeArray {
804844
struct BridgedSILTypeArray {
805845
BridgedArrayRef typeArray;
806846

847+
// Ensure that this struct value type will be indirectly returned on
848+
// Windows ARM64
849+
BridgedSILTypeArray() {}
850+
807851
#ifdef USED_IN_CPP_SOURCE
808852
BridgedSILTypeArray(llvm::ArrayRef<swift::SILType> silTypes)
809853
: typeArray(silTypes) {}
@@ -826,6 +870,10 @@ struct BridgedGenericSpecializationInformation {
826870
struct OptionalBridgedSILDebugVariable {
827871
uint64_t storage[16];
828872

873+
// Ensure that this struct value type will be indirectly returned on
874+
// Windows ARM64
875+
OptionalBridgedSILDebugVariable() {}
876+
829877
#ifdef USED_IN_CPP_SOURCE
830878
using OptionalSILDebugVariable = std::optional<swift::SILDebugVariable>;
831879

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ struct BridgedCalleeAnalysis {
9494
struct CalleeList {
9595
uint64_t storage[3];
9696

97+
// Ensure that this struct value type will be indirectly returned on
98+
// Windows ARM64
99+
CalleeList() {}
100+
97101
#ifdef USED_IN_CPP_SOURCE
98102
CalleeList(swift::CalleeList list) {
99103
*reinterpret_cast<swift::CalleeList *>(&storage) = list;

0 commit comments

Comments
 (0)