[Lldb-commits] [lldb] r327908 - [SymbolFilePDB] Remove a few null pointer checks by passing ref
Aaron Smith via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 19 14:14:20 PDT 2018
Author: asmith
Date: Mon Mar 19 14:14:19 2018
New Revision: 327908
URL: http://llvm.org/viewvc/llvm-project?rev=327908&view=rev
Log:
[SymbolFilePDB] Remove a few null pointer checks by passing ref
Reviewers: zturner, rnk, lldb-commits
Reviewed By: zturner
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D44455
Modified:
lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp?rev=327908&r1=327907&r2=327908&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp Mon Mar 19 14:14:19 2018
@@ -94,24 +94,20 @@ lldb::Encoding TranslateEnumEncoding(PDB
}
CompilerType GetBuiltinTypeForPDBEncodingAndBitSize(
- ClangASTContext *clang_ast, const PDBSymbolTypeBuiltin *pdb_type,
+ ClangASTContext &clang_ast, const PDBSymbolTypeBuiltin &pdb_type,
Encoding encoding, uint32_t width) {
- if (!pdb_type)
- return CompilerType();
- if (!clang_ast)
- return CompilerType();
- auto *ast = clang_ast->getASTContext();
+ auto *ast = clang_ast.getASTContext();
if (!ast)
return CompilerType();
- switch (pdb_type->getBuiltinType()) {
+ switch (pdb_type.getBuiltinType()) {
default: break;
case PDB_BuiltinType::None:
return CompilerType();
case PDB_BuiltinType::Void:
- return clang_ast->GetBasicType(eBasicTypeVoid);
+ return clang_ast.GetBasicType(eBasicTypeVoid);
case PDB_BuiltinType::Bool:
- return clang_ast->GetBasicType(eBasicTypeBool);
+ return clang_ast.GetBasicType(eBasicTypeBool);
case PDB_BuiltinType::Long:
if (width == ast->getTypeSize(ast->LongTy))
return CompilerType(ast, ast->LongTy);
@@ -141,15 +137,12 @@ CompilerType GetBuiltinTypeForPDBEncodin
}
// If there is no match on PDB_BuiltinType, fall back to default search
// by encoding and width only
- return clang_ast->GetBuiltinTypeForEncodingAndBitSize(encoding, width);
+ return clang_ast.GetBuiltinTypeForEncodingAndBitSize(encoding, width);
}
-ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin *pdb_type,
+ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin &pdb_type,
CompilerType &compiler_type) {
- if (!pdb_type)
- return compiler_type.GetTypeName();
-
- PDB_BuiltinType kind = pdb_type->getBuiltinType();
+ PDB_BuiltinType kind = pdb_type.getBuiltinType();
switch (kind) {
default: break;
case PDB_BuiltinType::Currency:
@@ -262,7 +255,7 @@ lldb::TypeSP PDBASTParser::CreateLLDBTyp
CompilerType builtin_type;
if (bytes > 0)
builtin_type = GetBuiltinTypeForPDBEncodingAndBitSize(
- &m_ast, underlying_type_up.get(), encoding, bytes * 8);
+ m_ast, *underlying_type_up, encoding, bytes * 8);
else
builtin_type = m_ast.GetBasicType(eBasicTypeInt);
// FIXME: PDB does not have information about scoped enumeration (Enum Class).
@@ -418,7 +411,7 @@ lldb::TypeSP PDBASTParser::CreateLLDBTyp
uint64_t bytes = builtin_type->getLength();
Encoding encoding = TranslateBuiltinEncoding(builtin_kind);
CompilerType builtin_ast_type = GetBuiltinTypeForPDBEncodingAndBitSize(
- &m_ast, builtin_type, encoding, bytes * 8);
+ m_ast, *builtin_type, encoding, bytes * 8);
if (builtin_type->isConstType())
builtin_ast_type = builtin_ast_type.AddConstModifier();
@@ -426,7 +419,7 @@ lldb::TypeSP PDBASTParser::CreateLLDBTyp
if (builtin_type->isVolatileType())
builtin_ast_type = builtin_ast_type.AddVolatileModifier();
- auto type_name = GetPDBBuiltinTypeName(builtin_type, builtin_ast_type);
+ auto type_name = GetPDBBuiltinTypeName(*builtin_type, builtin_ast_type);
return std::make_shared<lldb_private::Type>(
builtin_type->getSymIndexId(), m_ast.GetSymbolFile(), type_name,
Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp?rev=327908&r1=327907&r2=327908&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp Mon Mar 19 14:14:19 2018
@@ -205,15 +205,12 @@ uint32_t SymbolFilePDB::GetNumCompileUni
}
void SymbolFilePDB::GetCompileUnitIndex(
- const llvm::pdb::PDBSymbolCompiland *pdb_compiland,
+ const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
uint32_t &index) {
- if (!pdb_compiland)
- return;
-
auto results_up = m_global_scope_up->findAllChildren<PDBSymbolCompiland>();
if (!results_up)
return;
- auto uid = pdb_compiland->getSymIndexId();
+ auto uid = pdb_compiland.getSymIndexId();
for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) {
auto compiland_up = results_up->getChildAtIndex(cu_idx);
if (!compiland_up)
@@ -266,32 +263,31 @@ SymbolFilePDB::ParseCompileUnitLanguage(
lldb_private::Function *
SymbolFilePDB::ParseCompileUnitFunctionForPDBFunc(
- const PDBSymbolFunc *pdb_func,
+ const PDBSymbolFunc &pdb_func,
const lldb_private::SymbolContext &sc) {
- assert(pdb_func != nullptr);
lldbassert(sc.comp_unit && sc.module_sp.get());
- auto file_vm_addr = pdb_func->getVirtualAddress();
+ auto file_vm_addr = pdb_func.getVirtualAddress();
if (file_vm_addr == LLDB_INVALID_ADDRESS)
return nullptr;
- auto func_length = pdb_func->getLength();
+ auto func_length = pdb_func.getLength();
AddressRange func_range = AddressRange(file_vm_addr,
func_length,
sc.module_sp->GetSectionList());
if (!func_range.GetBaseAddress().IsValid())
return nullptr;
- lldb_private::Type* func_type = ResolveTypeUID(pdb_func->getSymIndexId());
+ lldb_private::Type* func_type = ResolveTypeUID(pdb_func.getSymIndexId());
if (!func_type)
return nullptr;
- user_id_t func_type_uid = pdb_func->getSignatureId();
+ user_id_t func_type_uid = pdb_func.getSignatureId();
Mangled mangled = GetMangledForPDBFunc(pdb_func);
FunctionSP func_sp = std::make_shared<Function>(sc.comp_unit,
- pdb_func->getSymIndexId(),
+ pdb_func.getSymIndexId(),
func_type_uid,
mangled,
func_type,
@@ -315,7 +311,7 @@ size_t SymbolFilePDB::ParseCompileUnitFu
auto func_sp =
sc.comp_unit->FindFunctionByUID(pdb_func_up->getSymIndexId());
if (!func_sp) {
- if (ParseCompileUnitFunctionForPDBFunc(pdb_func_up.get(), sc))
+ if (ParseCompileUnitFunctionForPDBFunc(*pdb_func_up, sc))
++func_added;
}
}
@@ -591,7 +587,7 @@ SymbolFilePDB::ResolveSymbolContext(cons
auto func_uid = pdb_func->getSymIndexId();
sc.function = sc.comp_unit->FindFunctionByUID(func_uid).get();
if (sc.function == nullptr)
- sc.function = ParseCompileUnitFunctionForPDBFunc(pdb_func, sc);
+ sc.function = ParseCompileUnitFunctionForPDBFunc(*pdb_func, sc);
if (sc.function) {
resolved_flags |= eSymbolContextFunction;
if (resolve_scope & eSymbolContextBlock) {
@@ -765,7 +761,7 @@ uint32_t SymbolFilePDB::ResolveSymbolCon
if (sc.function == nullptr) {
auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
assert(pdb_func);
- sc.function = ParseCompileUnitFunctionForPDBFunc(pdb_func, sc);
+ sc.function = ParseCompileUnitFunctionForPDBFunc(*pdb_func, sc);
}
if (sc.function && (resolve_scope & eSymbolContextBlock)) {
Block &block = sc.function->GetBlock(true);
@@ -803,13 +799,11 @@ SymbolFilePDB::FindGlobalVariables(const
return uint32_t();
}
-bool SymbolFilePDB::ResolveFunction(llvm::pdb::PDBSymbolFunc *pdb_func,
+bool SymbolFilePDB::ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func,
bool include_inlines,
lldb_private::SymbolContextList &sc_list) {
- if (!pdb_func)
- return false;
lldb_private::SymbolContext sc;
- auto file_vm_addr = pdb_func->getVirtualAddress();
+ auto file_vm_addr = pdb_func.getVirtualAddress();
if (file_vm_addr == LLDB_INVALID_ADDRESS)
return false;
@@ -825,7 +819,7 @@ bool SymbolFilePDB::ResolveFunction(llvm
auto *func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
assert(func);
- sc.function = ParseCompileUnitFunctionForPDBFunc(func, sc);
+ sc.function = ParseCompileUnitFunctionForPDBFunc(*func, sc);
if (!sc.function)
return false;
@@ -839,7 +833,7 @@ bool SymbolFilePDB::ResolveFunction(uint
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid);
if (!pdb_func_up && !(include_inlines && pdb_func_up->hasInlineAttribute()))
return false;
- return ResolveFunction(pdb_func_up.get(), include_inlines, sc_list);
+ return ResolveFunction(*pdb_func_up, include_inlines, sc_list);
}
void SymbolFilePDB::CacheFunctionNames() {
@@ -1163,14 +1157,11 @@ lldb_private::TypeList *SymbolFilePDB::G
}
void
-SymbolFilePDB::GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol *pdb_symbol,
+SymbolFilePDB::GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol,
uint32_t type_mask,
TypeCollection &type_collection) {
- if (!pdb_symbol)
- return;
-
bool can_parse = false;
- switch (pdb_symbol->getSymTag()) {
+ switch (pdb_symbol.getSymTag()) {
case PDB_SymType::ArrayType:
can_parse = ((type_mask & eTypeClassArray) != 0);
break;
@@ -1192,7 +1183,7 @@ SymbolFilePDB::GetTypesForPDBSymbol(cons
can_parse = ((type_mask & eTypeClassTypedef) != 0);
break;
case PDB_SymType::UDT: {
- auto *udt = llvm::dyn_cast<PDBSymbolTypeUDT>(pdb_symbol);
+ auto *udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&pdb_symbol);
assert(udt);
can_parse = (udt->getUdtKind() != PDB_UdtType::Interface &&
((type_mask & (eTypeClassClass | eTypeClassStruct |
@@ -1202,7 +1193,7 @@ SymbolFilePDB::GetTypesForPDBSymbol(cons
}
if (can_parse) {
- if (auto *type = ResolveTypeUID(pdb_symbol->getSymIndexId())) {
+ if (auto *type = ResolveTypeUID(pdb_symbol.getSymIndexId())) {
auto result =
std::find(type_collection.begin(), type_collection.end(), type);
if (result == type_collection.end())
@@ -1210,9 +1201,9 @@ SymbolFilePDB::GetTypesForPDBSymbol(cons
}
}
- auto results_up = pdb_symbol->findAllChildren();
+ auto results_up = pdb_symbol.findAllChildren();
while (auto symbol_up = results_up->getNext())
- GetTypesForPDBSymbol(symbol_up.get(), type_mask, type_collection);
+ GetTypesForPDBSymbol(*symbol_up, type_mask, type_collection);
}
size_t SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
@@ -1224,13 +1215,15 @@ size_t SymbolFilePDB::GetTypes(lldb_priv
sc_scope->CalculateSymbolContextCompileUnit() : nullptr;
if (cu) {
auto compiland_up = GetPDBCompilandByUID(cu->GetID());
- GetTypesForPDBSymbol(compiland_up.get(), type_mask, type_collection);
+ if (!compiland_up)
+ return 0;
+ GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection);
} else {
for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) {
auto cu_sp = ParseCompileUnitAtIndex(cu_idx);
if (cu_sp.get()) {
- auto compiland_up = GetPDBCompilandByUID(cu_sp->GetID());
- GetTypesForPDBSymbol(compiland_up.get(), type_mask, type_collection);
+ if (auto compiland_up = GetPDBCompilandByUID(cu_sp->GetID()))
+ GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection);
}
}
}
@@ -1306,7 +1299,7 @@ SymbolFilePDB::ParseCompileUnitForUID(ui
m_comp_units.insert(std::make_pair(id, cu_sp));
if (index == UINT32_MAX)
- GetCompileUnitIndex(compiland_up.get(), index);
+ GetCompileUnitIndex(*compiland_up, index);
lldbassert(index != UINT32_MAX);
m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(
index, cu_sp);
@@ -1459,13 +1452,10 @@ lldb::CompUnitSP SymbolFilePDB::GetCompi
}
Mangled
-SymbolFilePDB::GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc *pdb_func) {
+SymbolFilePDB::GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func) {
Mangled mangled;
- if (!pdb_func)
- return mangled;
-
- auto func_name = pdb_func->getName();
- auto func_undecorated_name = pdb_func->getUndecoratedName();
+ auto func_name = pdb_func.getName();
+ auto func_undecorated_name = pdb_func.getUndecoratedName();
std::string func_decorated_name;
// Seek from public symbols for non-static function's decorated name if any.
Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h?rev=327908&r1=327907&r2=327908&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h Mon Mar 19 14:14:19 2018
@@ -188,14 +188,14 @@ private:
typedef std::vector<lldb_private::Type*> TypeCollection;
void
- GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol *pdb_symbol,
+ GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol,
uint32_t type_mask, TypeCollection &type_collection);
lldb_private::Function* ParseCompileUnitFunctionForPDBFunc(
- const llvm::pdb::PDBSymbolFunc *pdb_func,
+ const llvm::pdb::PDBSymbolFunc &pdb_func,
const lldb_private::SymbolContext &sc);
- void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland *pdb_compiland,
+ void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
uint32_t &index);
std::string GetSourceFileNameForPDBCompiland(
@@ -205,9 +205,9 @@ private:
GetPDBCompilandByUID(uint32_t uid);
lldb_private::Mangled
- GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc *pdb_func);
+ GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func);
- bool ResolveFunction(llvm::pdb::PDBSymbolFunc *pdb_func,
+ bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func,
bool include_inlines,
lldb_private::SymbolContextList &sc_list);
More information about the lldb-commits
mailing list