Skip to content

Commit ed132a3

Browse files
committed
Implement TypeSystemSwiftTypeRef::GetPointerByteSize() (NFC)
for per-module contexts. (cherry picked from commit e9d37d3)
1 parent 9b68d05 commit ed132a3

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
@@ -1118,6 +1118,16 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
11181118

11191119
// This can be removed once the transition is complete.
11201120
#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+
11211131
#define VALIDATE_AND_RETURN(IMPL, REFERENCE, TYPE, ARGS) \
11221132
do { \
11231133
auto result = IMPL(); \
@@ -1133,11 +1143,8 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
11331143
return result; \
11341144
} while (0)
11351145
#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()
11411148
#endif
11421149

11431150
CompilerType
@@ -1385,7 +1392,21 @@ bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
13851392
}
13861393
// AST related queries
13871394
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);
13891410
}
13901411
// Accessors
13911412
ConstString TypeSystemSwiftTypeRef::GetTypeName(opaque_compiler_type_t type) {

0 commit comments

Comments
 (0)