@@ -1118,6 +1118,16 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
1118
1118
1119
1119
// This can be removed once the transition is complete.
1120
1120
#ifndef NDEBUG
1121
+ #define VALIDATE_AND_RETURN_STATIC (IMPL, REFERENCE ) \
1122
+ do { \
1123
+ auto result = IMPL (); \
1124
+ if (!m_swift_ast_context) \
1125
+ return result; \
1126
+ assert ((result == m_swift_ast_context->REFERENCE ()) && \
1127
+ " TypeSystemSwiftTypeRef diverges from SwiftASTContext" ); \
1128
+ return result; \
1129
+ } while (0 )
1130
+
1121
1131
#define VALIDATE_AND_RETURN (IMPL, REFERENCE, TYPE, ARGS ) \
1122
1132
do { \
1123
1133
auto result = IMPL (); \
@@ -1133,11 +1143,8 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
1133
1143
return result; \
1134
1144
} while (0 )
1135
1145
#else
1136
- #define VALIDATE_AND_RETURN (IMPL, REFERENCE, TYPE, ARGS ) \
1137
- do { \
1138
- auto result = IMPL (); \
1139
- return result; \
1140
- } while (0 )
1146
+ #define VALIDATE_AND_RETURN_STATIC (IMPL, REFERENCE ) return IMPL()
1147
+ #define VALIDATE_AND_RETURN (IMPL, REFERENCE, TYPE, ARGS ) return IMPL()
1141
1148
#endif
1142
1149
1143
1150
CompilerType
@@ -1385,7 +1392,21 @@ bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
1385
1392
}
1386
1393
// AST related queries
1387
1394
uint32_t TypeSystemSwiftTypeRef::GetPointerByteSize () {
1388
- return m_swift_ast_context->GetPointerByteSize ();
1395
+ auto impl = [&]() -> uint32_t {
1396
+ if (auto *module = GetModule ()) {
1397
+ auto &triple = module ->GetArchitecture ().GetTriple ();
1398
+ if (triple.isArch64Bit ())
1399
+ return 8 ;
1400
+ if (triple.isArch32Bit ())
1401
+ return 4 ;
1402
+ if (triple.isArch16Bit ())
1403
+ return 2 ;
1404
+ }
1405
+ // An expression context has no module. Since it's for expression
1406
+ // evaluation we might as well defer to the SwiftASTContext.
1407
+ return m_swift_ast_context->GetPointerByteSize ();
1408
+ };
1409
+ VALIDATE_AND_RETURN_STATIC (impl, GetPointerByteSize);
1389
1410
}
1390
1411
// Accessors
1391
1412
ConstString TypeSystemSwiftTypeRef::GetTypeName (opaque_compiler_type_t type) {
0 commit comments