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