-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb][TypeSystemClang][NFC] Clean up TypeSystemClang::GetBitSize #100674
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4725,67 +4725,69 @@ TypeSystemClang::GetFloatTypeSemantics(size_t byte_size) { | |
return llvm::APFloatBase::Bogus(); | ||
} | ||
|
||
std::optional<uint64_t> | ||
TypeSystemClang::GetObjCBitSize(QualType qual_type, | ||
ExecutionContextScope *exe_scope) { | ||
assert(qual_type->isObjCObjectOrInterfaceType()); | ||
ExecutionContext exe_ctx(exe_scope); | ||
Process *process = exe_ctx.GetProcessPtr(); | ||
if (process) { | ||
if (ObjCLanguageRuntime *objc_runtime = | ||
ObjCLanguageRuntime::Get(*process)) { | ||
if (std::optional<uint64_t> bit_size = | ||
objc_runtime->GetTypeBitSize(GetType(qual_type))) | ||
return *bit_size; | ||
} | ||
} else { | ||
static bool g_printed = false; | ||
if (!g_printed) { | ||
StreamString s; | ||
DumpTypeDescription(qual_type.getAsOpaquePtr(), s); | ||
|
||
llvm::outs() << "warning: trying to determine the size of type "; | ||
llvm::outs() << s.GetString() << "\n"; | ||
llvm::outs() << "without a valid ExecutionContext. this is not " | ||
"reliable. please file a bug against LLDB.\n"; | ||
llvm::outs() << "backtrace:\n"; | ||
llvm::sys::PrintStackTrace(llvm::outs()); | ||
llvm::outs() << "\n"; | ||
Comment on lines
+4746
to
+4752
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than printing to stdout, this should use the global diagnostics ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I was really tempted to just outright remove this tbh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mind if I keep this as-is for now? To keep this change as NFC as possible? (I'm just moving this code around) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine as long as it gets either fixed or removed eventually. |
||
g_printed = true; | ||
} | ||
} | ||
|
||
return getASTContext().getTypeSize(qual_type) + | ||
getASTContext().getTypeSize(getASTContext().ObjCBuiltinClassTy); | ||
} | ||
|
||
std::optional<uint64_t> | ||
TypeSystemClang::GetBitSize(lldb::opaque_compiler_type_t type, | ||
ExecutionContextScope *exe_scope) { | ||
if (GetCompleteType(type)) { | ||
clang::QualType qual_type(GetCanonicalQualType(type)); | ||
const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | ||
switch (type_class) { | ||
case clang::Type::Record: | ||
if (GetCompleteType(type)) | ||
return getASTContext().getTypeSize(qual_type); | ||
else | ||
return std::nullopt; | ||
break; | ||
if (!GetCompleteType(type)) | ||
return std::nullopt; | ||
|
||
case clang::Type::ObjCInterface: | ||
case clang::Type::ObjCObject: { | ||
ExecutionContext exe_ctx(exe_scope); | ||
Process *process = exe_ctx.GetProcessPtr(); | ||
if (process) { | ||
if (ObjCLanguageRuntime *objc_runtime = | ||
ObjCLanguageRuntime::Get(*process)) { | ||
if (std::optional<uint64_t> bit_size = | ||
objc_runtime->GetTypeBitSize(GetType(qual_type))) | ||
return *bit_size; | ||
} | ||
} else { | ||
static bool g_printed = false; | ||
if (!g_printed) { | ||
StreamString s; | ||
DumpTypeDescription(type, s); | ||
|
||
llvm::outs() << "warning: trying to determine the size of type "; | ||
llvm::outs() << s.GetString() << "\n"; | ||
llvm::outs() << "without a valid ExecutionContext. this is not " | ||
"reliable. please file a bug against LLDB.\n"; | ||
llvm::outs() << "backtrace:\n"; | ||
llvm::sys::PrintStackTrace(llvm::outs()); | ||
llvm::outs() << "\n"; | ||
g_printed = true; | ||
} | ||
} | ||
} | ||
[[fallthrough]]; | ||
default: | ||
const uint32_t bit_size = getASTContext().getTypeSize(qual_type); | ||
if (bit_size == 0) { | ||
if (qual_type->isIncompleteArrayType()) | ||
return getASTContext().getTypeSize( | ||
qual_type->getArrayElementTypeNoTypeQual() | ||
->getCanonicalTypeUnqualified()); | ||
} | ||
if (qual_type->isObjCObjectOrInterfaceType()) | ||
return bit_size + | ||
getASTContext().getTypeSize(getASTContext().ObjCBuiltinClassTy); | ||
// Function types actually have a size of 0, that's not an error. | ||
if (qual_type->isFunctionProtoType()) | ||
return bit_size; | ||
if (bit_size) | ||
return bit_size; | ||
} | ||
clang::QualType qual_type(GetCanonicalQualType(type)); | ||
const clang::Type::TypeClass type_class = qual_type->getTypeClass(); | ||
switch (type_class) { | ||
case clang::Type::FunctionProto: | ||
case clang::Type::Record: | ||
return getASTContext().getTypeSize(qual_type); | ||
case clang::Type::ObjCInterface: | ||
case clang::Type::ObjCObject: | ||
return GetObjCBitSize(qual_type, exe_scope); | ||
case clang::Type::IncompleteArray: { | ||
const uint64_t bit_size = getASTContext().getTypeSize(qual_type); | ||
if (bit_size == 0) | ||
return getASTContext().getTypeSize( | ||
qual_type->getArrayElementTypeNoTypeQual() | ||
->getCanonicalTypeUnqualified()); | ||
|
||
return bit_size; | ||
} | ||
default: | ||
if (const uint64_t bit_size = getASTContext().getTypeSize(qual_type)) | ||
return bit_size; | ||
} | ||
|
||
return std::nullopt; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you could move this into the if right below.