Skip to content

Commit e9d37d3

Browse files
committed
Implement TypeSystemSwiftTypeRef::GetPointerByteSize() (NFC)
for per-module contexts.
1 parent 31a2317 commit e9d37d3

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,16 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
11221122

11231123
// This can be removed once the transition is complete.
11241124
#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+
11251135
#define VALIDATE_AND_RETURN(IMPL, REFERENCE, TYPE, ARGS) \
11261136
do { \
11271137
auto result = IMPL(); \
@@ -1137,11 +1147,8 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
11371147
return result; \
11381148
} while (0)
11391149
#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()
11451152
#endif
11461153

11471154
CompilerType
@@ -1387,7 +1394,21 @@ bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
13871394
}
13881395
// AST related queries
13891396
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);
13911412
}
13921413
// Accessors
13931414
ConstString TypeSystemSwiftTypeRef::GetTypeName(opaque_compiler_type_t type) {

0 commit comments

Comments
 (0)