Skip to content

Commit 9a8083d

Browse files
committed
Remove validation from GetTypeBitAlign.
This method doesn't use VALIDATE_AND_RETURN because except for fixed-size types the SwiftASTContext implementation forwards to SwiftLanguageRuntime anyway and for some fixed-size types the fixed layout still returns an incorrect default alignment of 0.
1 parent bb018f4 commit 9a8083d

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

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

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,48 +2091,46 @@ bool TypeSystemSwiftTypeRef::IsPointerOrReferenceType(
20912091
llvm::Optional<size_t>
20922092
TypeSystemSwiftTypeRef::GetTypeBitAlign(opaque_compiler_type_t type,
20932093
ExecutionContextScope *exe_scope) {
2094-
auto impl = [&]() -> llvm::Optional<size_t> {
2095-
// Clang types can be resolved even without a process.
2096-
if (CompilerType clang_type = GetAsClangTypeOrNull(type)) {
2097-
// Swift doesn't know pointers: return the size alignment of the
2098-
// object pointer instead of the underlying object.
2099-
if (Flags(clang_type.GetTypeInfo()).AllSet(eTypeIsObjC | eTypeIsClass))
2100-
return GetPointerByteSize() * 8;
2101-
return clang_type.GetTypeBitAlign(exe_scope);
2102-
}
2103-
if (!exe_scope) {
2104-
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
2105-
"Couldn't compute alignment of type %s without an execution "
2106-
"context.",
2107-
AsMangledName(type));
2108-
return {};
2109-
}
2110-
if (auto *runtime =
2111-
SwiftLanguageRuntime::Get(exe_scope->CalculateProcess())) {
2112-
if (auto result = runtime->GetBitAlignment({this, type}, exe_scope))
2113-
return result;
2114-
// If this is an expression context, perhaps the type was
2115-
// defined in the expression. In that case we don't have debug
2116-
// info for it, so defer to SwiftASTContext.
2117-
if (llvm::isa<SwiftASTContextForExpressions>(m_swift_ast_context))
2118-
return ReconstructType({this, type}).GetTypeBitAlign(exe_scope);
2119-
}
2120-
2121-
// If there is no process, we can still try to get the static
2122-
// alignment information out of DWARF. Because it is stored in the
2123-
// Type object we need to look that up by name again.
2124-
if (TypeSP type_sp = LookupTypeInModule(type))
2125-
return type_sp->GetLayoutCompilerType().GetTypeBitAlign(exe_scope);
2094+
// This method doesn't use VALIDATE_AND_RETURN because except for
2095+
// fixed-size types the SwiftASTContext implementation forwards to
2096+
// SwiftLanguageRuntime anyway and for many fixed-size types the
2097+
// fixed layout still returns an incorrect default alignment of 0.
2098+
//
2099+
// Clang types can be resolved even without a process.
2100+
if (CompilerType clang_type = GetAsClangTypeOrNull(type)) {
2101+
// Swift doesn't know pointers: return the size alignment of the
2102+
// object pointer instead of the underlying object.
2103+
if (Flags(clang_type.GetTypeInfo()).AllSet(eTypeIsObjC | eTypeIsClass))
2104+
return GetPointerByteSize() * 8;
2105+
return clang_type.GetTypeBitAlign(exe_scope);
2106+
}
2107+
if (!exe_scope) {
21262108
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
2127-
"Couldn't compute alignment of type %s without a process.",
2109+
"Couldn't compute alignment of type %s without an execution "
2110+
"context.",
21282111
AsMangledName(type));
21292112
return {};
2130-
};
2131-
if (exe_scope && exe_scope->CalculateProcess())
2132-
VALIDATE_AND_RETURN(impl, GetTypeBitAlign, type,
2133-
(ReconstructType(type), exe_scope));
2134-
else
2135-
return impl();
2113+
}
2114+
if (auto *runtime =
2115+
SwiftLanguageRuntime::Get(exe_scope->CalculateProcess())) {
2116+
if (auto result = runtime->GetBitAlignment({this, type}, exe_scope))
2117+
return result;
2118+
// If this is an expression context, perhaps the type was
2119+
// defined in the expression. In that case we don't have debug
2120+
// info for it, so defer to SwiftASTContext.
2121+
if (llvm::isa<SwiftASTContextForExpressions>(m_swift_ast_context))
2122+
return ReconstructType({this, type}).GetTypeBitAlign(exe_scope);
2123+
}
2124+
2125+
// If there is no process, we can still try to get the static
2126+
// alignment information out of DWARF. Because it is stored in the
2127+
// Type object we need to look that up by name again.
2128+
if (TypeSP type_sp = LookupTypeInModule(type))
2129+
return type_sp->GetLayoutCompilerType().GetTypeBitAlign(exe_scope);
2130+
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
2131+
"Couldn't compute alignment of type %s without a process.",
2132+
AsMangledName(type));
2133+
return {};
21362134
}
21372135
bool TypeSystemSwiftTypeRef::IsTypedefType(opaque_compiler_type_t type) {
21382136
return m_swift_ast_context->IsTypedefType(ReconstructType(type));

0 commit comments

Comments
 (0)