Skip to content

Commit 9492e9d

Browse files
committed
[lldb][NFC] Cleanup ClangASTContext::CompleteTagDeclarationDefinition
Makes this function exit early instead of nesting if statements. Also removed all the if (tag_type->getDecl()) checks. If we created a TagType with a nullptr as a Decl then Clang would have already deferenced that nullptr during TagType creation so there is no point in gracefully handling a nullptr here.
1 parent 5a6eae3 commit 9492e9d

File tree

1 file changed

+52
-57
lines changed

1 file changed

+52
-57
lines changed

lldb/source/Symbol/ClangASTContext.cpp

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7773,70 +7773,65 @@ bool ClangASTContext::StartTagDeclarationDefinition(const CompilerType &type) {
77737773
bool ClangASTContext::CompleteTagDeclarationDefinition(
77747774
const CompilerType &type) {
77757775
clang::QualType qual_type(ClangUtil::GetQualType(type));
7776-
if (!qual_type.isNull()) {
7777-
// Make sure we use the same methodology as
7778-
// ClangASTContext::StartTagDeclarationDefinition() as to how we start/end
7779-
// the definition. Previously we were calling
7780-
const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
7781-
if (tag_type) {
7782-
clang::TagDecl *tag_decl = tag_type->getDecl();
7783-
if (tag_decl) {
7784-
clang::CXXRecordDecl *cxx_record_decl =
7785-
llvm::dyn_cast_or_null<clang::CXXRecordDecl>(tag_decl);
7776+
if (qual_type.isNull())
7777+
return false;
77867778

7787-
if (cxx_record_decl) {
7788-
if (!cxx_record_decl->isCompleteDefinition())
7789-
cxx_record_decl->completeDefinition();
7790-
cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
7791-
cxx_record_decl->setHasExternalLexicalStorage(false);
7792-
cxx_record_decl->setHasExternalVisibleStorage(false);
7793-
return true;
7794-
}
7795-
}
7779+
// Make sure we use the same methodology as
7780+
// ClangASTContext::StartTagDeclarationDefinition() as to how we start/end
7781+
// the definition.
7782+
const clang::TagType *tag_type = qual_type->getAs<clang::TagType>();
7783+
if (tag_type) {
7784+
clang::TagDecl *tag_decl = tag_type->getDecl();
7785+
7786+
if (auto *cxx_record_decl = llvm::dyn_cast<CXXRecordDecl>(tag_decl)) {
7787+
if (!cxx_record_decl->isCompleteDefinition())
7788+
cxx_record_decl->completeDefinition();
7789+
cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
7790+
cxx_record_decl->setHasExternalLexicalStorage(false);
7791+
cxx_record_decl->setHasExternalVisibleStorage(false);
7792+
return true;
77967793
}
7794+
}
77977795

7798-
const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>();
7796+
const clang::EnumType *enutype = qual_type->getAs<clang::EnumType>();
77997797

7800-
if (enutype) {
7801-
clang::EnumDecl *enum_decl = enutype->getDecl();
7798+
if (!enutype)
7799+
return false;
7800+
clang::EnumDecl *enum_decl = enutype->getDecl();
78027801

7803-
if (enum_decl) {
7804-
if (!enum_decl->isCompleteDefinition()) {
7805-
ClangASTContext *lldb_ast =
7806-
llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
7807-
if (lldb_ast == nullptr)
7808-
return false;
7809-
clang::ASTContext &ast = lldb_ast->getASTContext();
7810-
7811-
/// TODO This really needs to be fixed.
7812-
7813-
QualType integer_type(enum_decl->getIntegerType());
7814-
if (!integer_type.isNull()) {
7815-
unsigned NumPositiveBits = 1;
7816-
unsigned NumNegativeBits = 0;
7817-
7818-
clang::QualType promotion_qual_type;
7819-
// If the enum integer type is less than an integer in bit width,
7820-
// then we must promote it to an integer size.
7821-
if (ast.getTypeSize(enum_decl->getIntegerType()) <
7822-
ast.getTypeSize(ast.IntTy)) {
7823-
if (enum_decl->getIntegerType()->isSignedIntegerType())
7824-
promotion_qual_type = ast.IntTy;
7825-
else
7826-
promotion_qual_type = ast.UnsignedIntTy;
7827-
} else
7828-
promotion_qual_type = enum_decl->getIntegerType();
7802+
if (enum_decl->isCompleteDefinition())
7803+
return true;
78297804

7830-
enum_decl->completeDefinition(enum_decl->getIntegerType(),
7831-
promotion_qual_type, NumPositiveBits,
7832-
NumNegativeBits);
7833-
}
7834-
}
7835-
return true;
7836-
}
7837-
}
7805+
ClangASTContext *lldb_ast =
7806+
llvm::dyn_cast<ClangASTContext>(type.GetTypeSystem());
7807+
if (lldb_ast == nullptr)
7808+
return false;
7809+
clang::ASTContext &ast = lldb_ast->getASTContext();
7810+
7811+
/// TODO This really needs to be fixed.
7812+
7813+
QualType integer_type(enum_decl->getIntegerType());
7814+
if (!integer_type.isNull()) {
7815+
unsigned NumPositiveBits = 1;
7816+
unsigned NumNegativeBits = 0;
7817+
7818+
clang::QualType promotion_qual_type;
7819+
// If the enum integer type is less than an integer in bit width,
7820+
// then we must promote it to an integer size.
7821+
if (ast.getTypeSize(enum_decl->getIntegerType()) <
7822+
ast.getTypeSize(ast.IntTy)) {
7823+
if (enum_decl->getIntegerType()->isSignedIntegerType())
7824+
promotion_qual_type = ast.IntTy;
7825+
else
7826+
promotion_qual_type = ast.UnsignedIntTy;
7827+
} else
7828+
promotion_qual_type = enum_decl->getIntegerType();
7829+
7830+
enum_decl->completeDefinition(enum_decl->getIntegerType(),
7831+
promotion_qual_type, NumPositiveBits,
7832+
NumNegativeBits);
78387833
}
7839-
return false;
7834+
return true;
78407835
}
78417836

78427837
clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType(

0 commit comments

Comments
 (0)