Skip to content

Commit 2679294

Browse files
authored
Merge pull request #60093 from hyp/eng/fix-arm64e
[interop][SwiftToCxx] arm64e: authenticate value witness table in C++
2 parents 773e759 + 5b05d3d commit 2679294

15 files changed

+105
-46
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,11 @@ namespace SpecialPointerAuthDiscriminators {
13491349
/// Protocol conformance descriptors.
13501350
const uint16_t ProtocolConformanceDescriptor = 0xc6eb;
13511351

1352+
/// Pointer to value witness table stored in type metadata.
1353+
///
1354+
/// Computed with ptrauth_string_discriminator("value_witness_table_t").
1355+
const uint16_t ValueWitnessTable = 0x2e3f;
1356+
13521357
/// Extended existential type shapes.
13531358
const uint16_t ExtendedExistentialTypeShape = 0x5a3d; // = 23101
13541359
const uint16_t NonUniqueExtendedExistentialTypeShape = 0xe798; // = 59288

lib/PrintAsClang/ClangSyntaxPrinter.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "ClangSyntaxPrinter.h"
14+
#include "swift/ABI/MetadataValues.h"
1415
#include "swift/AST/Module.h"
1516

1617
using namespace swift;
@@ -145,9 +146,22 @@ void ClangSyntaxPrinter::printSwiftTypeMetadataAccessFunctionCall(
145146
os << name << "(0)";
146147
}
147148

148-
void ClangSyntaxPrinter::printValueWitnessTableAccessFromTypeMetadata(
149+
void ClangSyntaxPrinter::printValueWitnessTableAccessSequenceFromTypeMetadata(
149150
StringRef metadataVariable) {
150-
os << "*(reinterpret_cast<";
151+
os << " auto *vwTableAddr = ";
152+
os << "reinterpret_cast<";
151153
printSwiftImplQualifier();
152-
os << "ValueWitnessTable **>(" << metadataVariable << "._0) - 1)";
154+
os << "ValueWitnessTable **>(" << metadataVariable << "._0) - 1;\n";
155+
os << "#ifdef __arm64e__\n";
156+
os << " auto *vwTable = ";
157+
os << "reinterpret_cast<";
158+
printSwiftImplQualifier();
159+
os << "ValueWitnessTable *>(ptrauth_auth_data(";
160+
os << "reinterpret_cast<void *>(*vwTableAddr), "
161+
"ptrauth_key_process_independent_data, ";
162+
os << "ptrauth_blend_discriminator(vwTableAddr, "
163+
<< SpecialPointerAuthDiscriminators::ValueWitnessTable << ")));\n";
164+
os << "#else\n";
165+
os << " auto *vwTable = *vwTableAddr;\n";
166+
os << "#endif\n";
153167
}

lib/PrintAsClang/ClangSyntaxPrinter.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ class ClangSyntaxPrinter {
9090
/// Print the call expression to the Swift type metadata access function.
9191
void printSwiftTypeMetadataAccessFunctionCall(StringRef name);
9292

93-
/// Print the expression to access the value witness table pointer from the
94-
/// given type metadata variable.
95-
void printValueWitnessTableAccessFromTypeMetadata(StringRef metadataVariable);
93+
/// Print the set of statements to access the value witness table pointer
94+
/// ('vwTable') from the given type metadata variable.
95+
void printValueWitnessTableAccessSequenceFromTypeMetadata(
96+
StringRef metadataVariable);
9697

9798
protected:
9899
raw_ostream &os;

lib/PrintAsClang/PrintClangValueType.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ void ClangValueTypePrinter::printValueTypeDecl(
125125
<< "::";
126126
printer.printSwiftTypeMetadataAccessFunctionCall(typeMetadataFuncName);
127127
os << ";\n";
128-
os << " auto *vwTable = ";
129-
printer.printValueWitnessTableAccessFromTypeMetadata("metadata");
130-
os << ";\n";
128+
printer.printValueWitnessTableAccessSequenceFromTypeMetadata("metadata");
131129
os << " vwTable->destroy(_getOpaquePointer(), metadata._0);\n";
132130
os << " }\n";
133131

@@ -140,9 +138,7 @@ void ClangValueTypePrinter::printValueTypeDecl(
140138
<< "::";
141139
printer.printSwiftTypeMetadataAccessFunctionCall(typeMetadataFuncName);
142140
os << ";\n";
143-
os << " auto *vwTable = ";
144-
printer.printValueWitnessTableAccessFromTypeMetadata("metadata");
145-
os << ";\n";
141+
printer.printValueWitnessTableAccessSequenceFromTypeMetadata("metadata");
146142
if (isOpaqueLayout) {
147143
os << " _storage = ";
148144
printer.printSwiftImplQualifier();
@@ -184,11 +180,10 @@ void ClangValueTypePrinter::printValueTypeDecl(
184180
<< "::";
185181
printer.printSwiftTypeMetadataAccessFunctionCall(typeMetadataFuncName);
186182
os << ";\n";
183+
printer.printValueWitnessTableAccessSequenceFromTypeMetadata("metadata");
187184
os << " return ";
188185
printer.printBaseName(typeDecl);
189-
os << "(";
190-
printer.printValueWitnessTableAccessFromTypeMetadata("metadata");
191-
os << ");\n }\n";
186+
os << "(vwTable);\n }\n";
192187
} else {
193188
os << " return ";
194189
printer.printBaseName(typeDecl);
@@ -213,9 +208,7 @@ void ClangValueTypePrinter::printValueTypeDecl(
213208
<< "::";
214209
printer.printSwiftTypeMetadataAccessFunctionCall(typeMetadataFuncName);
215210
os << ";\n";
216-
os << " auto *vwTable = ";
217-
printer.printValueWitnessTableAccessFromTypeMetadata("metadata");
218-
os << ";\n";
211+
printer.printValueWitnessTableAccessSequenceFromTypeMetadata("metadata");
219212
os << " const auto *enumVWTable = reinterpret_cast<";
220213
ClangSyntaxPrinter(os).printSwiftImplQualifier();
221214
os << "EnumValueWitnessTable";

test/Interop/SwiftToCxx/enums/swift-enum-case-functions.swift

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,12 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
184184
// CHECK-NEXT: }
185185
// CHECK: inline int _getEnumTag() const {
186186
// CHECK-NEXT: auto metadata = _impl::$s5Enums9CLikeEnumOMa(0);
187-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
187+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
188+
// CHECK-NEXT: #ifdef __arm64e__
189+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
190+
// CHECK-NEXT: #else
191+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
192+
// CHECK-NEXT: #endif
188193
// CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
189194
// CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
190195
// CHECK-NEXT: }
@@ -210,7 +215,12 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
210215
// CHECK-NEXT: }
211216
// CHECK: inline int _getEnumTag() const {
212217
// CHECK-NEXT: auto metadata = _impl::$s5Enums19CharOrSectionMarkerOMa(0);
213-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
218+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
219+
// CHECK-NEXT: #ifdef __arm64e__
220+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
221+
// CHECK-NEXT: #else
222+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
223+
// CHECK-NEXT: #endif
214224
// CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
215225
// CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
216226
// CHECK-NEXT: }
@@ -228,7 +238,12 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
228238
// CHECK-NEXT: }
229239
// CHECK: inline int _getEnumTag() const {
230240
// CHECK-NEXT: auto metadata = _impl::$s5Enums8DataCaseOMa(0);
231-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
241+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
242+
// CHECK-NEXT: #ifdef __arm64e__
243+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
244+
// CHECK-NEXT: #else
245+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
246+
// CHECK-NEXT: #endif
232247
// CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
233248
// CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
234249
// CHECK-NEXT: }
@@ -254,7 +269,12 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
254269
// CHECK-NEXT: }
255270
// CHECK: inline int _getEnumTag() const {
256271
// CHECK-NEXT: auto metadata = _impl::$s5Enums17IntDoubleOrBignumOMa(0);
257-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
272+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
273+
// CHECK-NEXT: #ifdef __arm64e__
274+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
275+
// CHECK-NEXT: #else
276+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
277+
// CHECK-NEXT: #endif
258278
// CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
259279
// CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
260280
// CHECK-NEXT: }
@@ -280,7 +300,12 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
280300
// CHECK-NEXT: }
281301
// CHECK: inline int _getEnumTag() const {
282302
// CHECK-NEXT: auto metadata = _impl::$s5Enums13IntOrInfinityOMa(0);
283-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
303+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
304+
// CHECK-NEXT: #ifdef __arm64e__
305+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
306+
// CHECK-NEXT: #else
307+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
308+
// CHECK-NEXT: #endif
284309
// CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
285310
// CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
286311
// CHECK-NEXT: }
@@ -318,7 +343,12 @@ public func checkIntDoubleOrBignum(_ x: IntDoubleOrBignum, tag: Int) -> Bool {
318343
// CHECK-NEXT: }
319344
// CHECK: inline int _getEnumTag() const {
320345
// CHECK-NEXT: auto metadata = _impl::$s5Enums12TerminalCharOMa(0);
321-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
346+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
347+
// CHECK-NEXT: #ifdef __arm64e__
348+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
349+
// CHECK-NEXT: #else
350+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
351+
// CHECK-NEXT: #endif
322352
// CHECK-NEXT: const auto *enumVWTable = reinterpret_cast<swift::_impl::EnumValueWitnessTable *>(vwTable);
323353
// CHECK-NEXT: return enumVWTable->getEnumTag(_getOpaquePointer(), metadata._0);
324354
// CHECK-NEXT: }

test/Interop/SwiftToCxx/initializers/init-in-cxx-execution.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// REQUIRES: executable_test
1212

13-
// UNSUPPORTED: CPU=arm64e
14-
1513
#include <assert.h>
1614
#include "inits.h"
1715

test/Interop/SwiftToCxx/methods/method-in-cxx-execution.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// REQUIRES: executable_test
1212

13-
// UNSUPPORTED: CPU=arm64e
14-
1513
#include <assert.h>
1614
#include "methods.h"
1715

test/Interop/SwiftToCxx/methods/mutating-method-in-cxx-execution.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// REQUIRES: executable_test
1212

13-
// UNSUPPORTED: CPU=arm64e
14-
1513
#include <assert.h>
1614
#include "methods.h"
1715

test/Interop/SwiftToCxx/properties/getter-in-cxx-execution.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// REQUIRES: executable_test
1212

13-
// UNSUPPORTED: CPU=arm64e
14-
1513
#include <assert.h>
1614
#include "properties.h"
1715

test/Interop/SwiftToCxx/structs/large-structs-pass-return-indirect-in-cxx-execution.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// REQUIRES: executable_test
1212

13-
// UNSUPPORTED: CPU=arm64e
14-
1513
#include <assert.h>
1614
#include "structs.h"
1715

test/Interop/SwiftToCxx/structs/resilient-struct-in-cxx-execution.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
// REQUIRES: executable_test
1818

19-
// UNSUPPORTED: CPU=arm64e
20-
2119
#include <assert.h>
2220
#include "structs.h"
2321

test/Interop/SwiftToCxx/structs/resilient-struct-in-cxx.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,26 @@ public struct FirstSmallStruct {
2424
// CHECK-NEXT: public:
2525
// CHECK: inline FirstSmallStruct(const FirstSmallStruct &other) {
2626
// CHECK-NEXT: auto metadata = _impl::$s7Structs16FirstSmallStructVMa(0);
27-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
27+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
28+
// CHECK-NEXT: #ifdef __arm64e__
29+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
30+
// CHECK-NEXT: #else
31+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
32+
// CHECK-NEXT: #endif
2833
// CHECK-NEXT: _storage = swift::_impl::OpaqueStorage(vwTable);
2934
// CHECK-NEXT: vwTable->initializeWithCopy(_getOpaquePointer(), const_cast<char *>(other._getOpaquePointer()), metadata._0);
3035
// CHECK-NEXT: }
3136
// CHECK: private:
3237
// CHECK-NEXT: inline FirstSmallStruct(swift::_impl::ValueWitnessTable * _Nonnull vwTable) : _storage(vwTable) {}
3338
// CHECK-NEXT: static inline FirstSmallStruct _make() {
3439
// CHECK-NEXT: auto metadata = _impl::$s7Structs16FirstSmallStructVMa(0);
35-
// CHECK-NEXT: return FirstSmallStruct(*(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1));
40+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
41+
// CHECK-NEXT: #ifdef __arm64e__
42+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
43+
// CHECK-NEXT: #else
44+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
45+
// CHECK-NEXT: #endif
46+
// CHECK-NEXT: return FirstSmallStruct(vwTable);
3647
// CHECK-NEXT: }
3748
// CHECK-NEXT: inline const char * _Nonnull _getOpaquePointer() const { return _storage.getOpaquePointer(); }
3849
// CHECK-NEXT: inline char * _Nonnull _getOpaquePointer() { return _storage.getOpaquePointer(); }
@@ -73,15 +84,26 @@ public struct LargeStruct {
7384
// CHECK-NEXT: public:
7485
// CHECK: inline LargeStruct(const LargeStruct &other) {
7586
// CHECK-NEXT: auto metadata = _impl::$s7Structs11LargeStructVMa(0);
76-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
87+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
88+
// CHECK-NEXT: #ifdef __arm64e__
89+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
90+
// CHECK-NEXT: #else
91+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
92+
// CHECK-NEXT: #endif
7793
// CHECK-NEXT: _storage = swift::_impl::OpaqueStorage(vwTable);
7894
// CHECK-NEXT: vwTable->initializeWithCopy(_getOpaquePointer(), const_cast<char *>(other._getOpaquePointer()), metadata._0);
7995
// CHECK-NEXT: }
8096
// CHECK: private:
8197
// CHECK-NEXT: inline LargeStruct(swift::_impl::ValueWitnessTable * _Nonnull vwTable) : _storage(vwTable) {}
8298
// CHECK-NEXT: static inline LargeStruct _make() {
8399
// CHECK-NEXT: auto metadata = _impl::$s7Structs11LargeStructVMa(0);
84-
// CHECK-NEXT: return LargeStruct(*(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1));
100+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
101+
// CHECK-NEXT: #ifdef __arm64e__
102+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
103+
// CHECK-NEXT: #else
104+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
105+
// CHECK-NEXT: #endif
106+
// CHECK-NEXT: return LargeStruct(vwTable);
85107
// CHECK-NEXT: }
86108
// CHECK-NEXT: inline const char * _Nonnull _getOpaquePointer() const { return _storage.getOpaquePointer(); }
87109
// CHECK-NEXT: inline char * _Nonnull _getOpaquePointer() { return _storage.getOpaquePointer(); }

test/Interop/SwiftToCxx/structs/small-structs-pass-return-direct-in-cxx-execution.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// REQUIRES: executable_test
1212

13-
// UNSUPPORTED: CPU=arm64e
14-
1513
#include <assert.h>
1614
#include "structs.h"
1715

test/Interop/SwiftToCxx/structs/struct-with-refcounted-member-execution.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// REQUIRES: executable_test
1212

13-
// UNSUPPORTED: CPU=arm64e
14-
1513
#include <assert.h>
1614
#include "structs.h"
1715

test/Interop/SwiftToCxx/structs/struct-with-refcounted-member.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,22 @@ public func printBreak(_ x: Int) {
2929
// CHECK-NEXT: public:
3030
// CHECK-NEXT: inline ~StructWithRefcountedMember() {
3131
// CHECK-NEXT: auto metadata = _impl::$s7Structs26StructWithRefcountedMemberVMa(0);
32-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
32+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
33+
// CHECK-NEXT: #ifdef __arm64e__
34+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
35+
// CHECK-NEXT: #else
36+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
37+
// CHECK-NEXT: #endif
3338
// CHECK-NEXT: vwTable->destroy(_getOpaquePointer(), metadata._0);
3439
// CHECK-NEXT: }
3540
// CHECK-NEXT: inline StructWithRefcountedMember(const StructWithRefcountedMember &other) {
3641
// CHECK-NEXT: auto metadata = _impl::$s7Structs26StructWithRefcountedMemberVMa(0);
37-
// CHECK-NEXT: auto *vwTable = *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1);
42+
// CHECK-NEXT: auto *vwTableAddr = reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - 1;
43+
// CHECK-NEXT: #ifdef __arm64e__
44+
// CHECK-NEXT: auto *vwTable = reinterpret_cast<swift::_impl::ValueWitnessTable *>(ptrauth_auth_data(reinterpret_cast<void *>(*vwTableAddr), ptrauth_key_process_independent_data, ptrauth_blend_discriminator(vwTableAddr, 11839)));
45+
// CHECK-NEXT: #else
46+
// CHECK-NEXT: auto *vwTable = *vwTableAddr;
47+
// CHECK-NEXT: #endif
3848
// CHECK-NEXT: vwTable->initializeWithCopy(_getOpaquePointer(), const_cast<char *>(other._getOpaquePointer()), metadata._0);
3949
// CHECK-NEXT: }
4050
// CHECK-NEXT: inline StructWithRefcountedMember(StructWithRefcountedMember &&) = default;

0 commit comments

Comments
 (0)