Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "TypeSystemClang.h"

#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/ExprCXX.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/Support/Casting.h"
Expand Down Expand Up @@ -3650,6 +3651,15 @@ bool TypeSystemClang::IsPolymorphicClass(lldb::opaque_compiler_type_t type) {
return false;
}

/// Returns 'true' if \ref decl has been allocated a definition
/// *and* the definition was marked as completed. There are currently
/// situations in which LLDB marks a definition as `isCompleteDefinition`
/// while no definition was allocated. This function guards against those
/// situations.
static bool HasCompleteDefinition(clang::CXXRecordDecl *decl) {
return decl && decl->hasDefinition() && decl->isCompleteDefinition();
}

bool TypeSystemClang::IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
CompilerType *dynamic_pointee_type,
bool check_cplusplus,
Expand Down Expand Up @@ -3732,8 +3742,9 @@ bool TypeSystemClang::IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
if (check_cplusplus) {
clang::CXXRecordDecl *cxx_record_decl =
pointee_qual_type->getAsCXXRecordDecl();

if (cxx_record_decl) {
bool is_complete = cxx_record_decl->isCompleteDefinition();
bool is_complete = HasCompleteDefinition(cxx_record_decl);

if (is_complete)
success = cxx_record_decl->isDynamicClass();
Expand All @@ -3742,7 +3753,9 @@ bool TypeSystemClang::IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
if (metadata)
success = metadata->GetIsDynamicCXXType();
else {
is_complete = GetType(pointee_qual_type).GetCompleteType();
// Make sure completion has actually completed the type.
is_complete = GetType(pointee_qual_type).GetCompleteType() &&
HasCompleteDefinition(cxx_record_decl);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which action could have changed the result of HasCompleteDefinition(cxx_record_decl) since line 3747?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the call to GetCompleteType (which does much more than the name suggests)

if (is_complete)
success = cxx_record_decl->isDynamicClass();
else
Expand Down Expand Up @@ -5478,8 +5491,12 @@ TypeSystemClang::GetNumChildren(lldb::opaque_compiler_type_t type,
llvm::cast<clang::RecordType>(qual_type.getTypePtr());
const clang::RecordDecl *record_decl = record_type->getDecl();
assert(record_decl);

// CXXBaseSpecifiers are stored on the definition. If we don't have
// one at this point that means we "completed" the type without actually
// having allocated a definition.
const clang::CXXRecordDecl *cxx_record_decl =
llvm::dyn_cast<clang::CXXRecordDecl>(record_decl);
llvm::dyn_cast<clang::CXXRecordDecl>(record_decl)->getDefinition();
if (cxx_record_decl) {
if (omit_empty_base_classes) {
// Check each base classes to see if it or any of its base classes
Expand Down