Bunch of cleanups for warnings found by the llvm static analyzer.

llvm-svn: 165808
This commit is contained in:
Jim Ingham 2012-10-12 17:34:26 +00:00
parent e87f41f43e
commit 28eb57114d
30 changed files with 161 additions and 136 deletions

View File

@ -50,11 +50,6 @@ public:
lldb::VariableSP
FindVariable (const ConstString& name);
// Find the argument variable that represents the language specific
// object pointer ("this" in C++, or "self" in Objective C).
lldb::VariableSP
FindArtificialObjectVariable (lldb::LanguageType language) const;
uint32_t
FindVariableIndex (const lldb::VariableSP &var_sp);

View File

@ -4544,7 +4544,6 @@
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
@ -4562,7 +4561,6 @@
CURRENT_PROJECT_VERSION = 168;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
@ -4580,7 +4578,6 @@
CURRENT_PROJECT_VERSION = 168;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
@ -4604,7 +4601,6 @@
HEADER_SEARCH_PATHS = /usr/include/libxml2;
LD_DYLIB_INSTALL_NAME = "$(DEVELOPER_DIR)/Library/PrivateFrameworks/LLDB.framework/Resources/lldb-core.a";
MACH_O_TYPE = staticlib;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_CPLUSPLUSFLAGS = (
"-fno-rtti",
"-Wglobal-constructors",
@ -4635,7 +4631,6 @@
HEADER_SEARCH_PATHS = /usr/include/libxml2;
LD_DYLIB_INSTALL_NAME = "$(DEVELOPER_DIR)/Library/PrivateFrameworks/LLDB.framework/Resources/lldb-core.a";
MACH_O_TYPE = staticlib;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_CPLUSPLUSFLAGS = (
"-fno-rtti",
"-Wglobal-constructors",
@ -4666,7 +4661,6 @@
HEADER_SEARCH_PATHS = /usr/include/libxml2;
LD_DYLIB_INSTALL_NAME = "$(DEVELOPER_DIR)/Library/PrivateFrameworks/LLDB.framework/Resources/lldb-core.a";
MACH_O_TYPE = staticlib;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_CPLUSPLUSFLAGS = (
"-fno-rtti",
"-Wglobal-constructors",
@ -5363,7 +5357,6 @@
HEADER_SEARCH_PATHS = /usr/include/libxml2;
LD_DYLIB_INSTALL_NAME = "$(DEVELOPER_DIR)/Library/PrivateFrameworks/LLDB.framework/Resources/lldb-core.a";
MACH_O_TYPE = staticlib;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_CPLUSPLUSFLAGS = (
"-fno-rtti",
"-Wglobal-constructors",
@ -5532,7 +5525,6 @@
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";

View File

@ -116,6 +116,8 @@ SBTypeNameSpecifier::IsEqualTo (lldb::SBTypeNameSpecifier &rhs)
if (IsRegex() != rhs.IsRegex())
return false;
if (GetName() == NULL || rhs.GetName() == NULL)
return false;
return (strcmp(GetName(), rhs.GetName()) == 0);
}

View File

@ -233,7 +233,7 @@ SBTypeSummary::IsEqualTo (lldb::SBTypeSummary &rhs)
if (IsFunctionName() != rhs.IsFunctionName())
return false;
if ( strcmp(GetData(), rhs.GetData()) )
if ( GetData() == NULL || rhs.GetData() == NULL || strcmp(GetData(), rhs.GetData()) )
return false;
return GetOptions() == rhs.GetOptions();

View File

@ -1227,7 +1227,7 @@ DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t
static void
DumpModuleUUID (Stream &strm, Module *module)
{
if (module->GetUUID().IsValid())
if (module && module->GetUUID().IsValid())
module->GetUUID().Dump (&strm);
else
strm.PutCString(" ");
@ -2720,8 +2720,14 @@ protected:
}
else
{
module->GetFileSpec().GetPath (path, sizeof(path));
FileSpec *module_spec_file = module_spec.GetFileSpecPtr();
if (module_spec_file)
{
module_spec_file->GetPath (path, sizeof(path));
result.AppendErrorWithFormat ("invalid module '%s'.\n", path);
}
else
result.AppendError ("no module spec");
result.SetStatus (eReturnStatusFailed);
}
}
@ -3033,6 +3039,12 @@ protected:
PrintModule (Target *target, Module *module, uint32_t idx, int indent, Stream &strm)
{
if (module == NULL)
{
strm.PutCString("Null module");
return;
}
bool dump_object_name = false;
if (m_options.m_format_array.empty())
{

View File

@ -117,13 +117,15 @@ ClangExpressionDeclMap::DidParse()
++entity_index)
{
ClangExpressionVariableSP var_sp(m_found_entities.GetVariableAtIndex(entity_index));
if (var_sp &&
var_sp->m_parser_vars.get() &&
if (var_sp)
{
if (var_sp->m_parser_vars.get() &&
var_sp->m_parser_vars->m_lldb_value)
delete var_sp->m_parser_vars->m_lldb_value;
var_sp->DisableParserVars();
}
}
for (size_t pvar_index = 0, num_pvars = m_parser_vars->m_persistent_vars->GetSize();
pvar_index < num_pvars;
@ -2706,7 +2708,7 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context,
append,
sc_list);
}
else if (!namespace_decl)
else if (target && !namespace_decl)
{
const bool include_symbols = true;

View File

@ -755,6 +755,7 @@ ClangExpressionParser::DisassembleFunction (Stream &stream, ExecutionContext &ex
{
ret.SetErrorToGenericError();
ret.SetErrorString("Couldn't find the target");
return ret;
}
lldb::DataBufferSP buffer_sp(new DataBufferHeap(func_range.second, 0));

View File

@ -552,7 +552,7 @@ ClangUserExpression::Execute (Stream &error_stream,
if (m_jit_start_addr != LLDB_INVALID_ADDRESS)
{
lldb::addr_t struct_address;
lldb::addr_t struct_address = LLDB_INVALID_ADDRESS;
lldb::addr_t object_ptr = 0;
lldb::addr_t cmd_ptr = 0;

View File

@ -78,11 +78,14 @@ static std::string
PrintValue(const Value *value, bool truncate = false)
{
std::string s;
if (value)
{
raw_string_ostream rso(s);
value->print(rso);
rso.flush();
if (truncate)
s.resize(s.length() - 1);
}
return s;
}
@ -238,7 +241,7 @@ IRForTarget::GetFunctionAddress (llvm::Function *fun,
// Check for an alternate mangling for "std::basic_string<char>"
// that is part of the itanium C++ name mangling scheme
const char *name_cstr = name.GetCString();
if (strncmp(name_cstr, "_ZNKSbIcE", strlen("_ZNKSbIcE")) == 0)
if (name_cstr && strncmp(name_cstr, "_ZNKSbIcE", strlen("_ZNKSbIcE")) == 0)
{
std::string alternate_mangling("_ZNKSs");
alternate_mangling.append (name_cstr + strlen("_ZNKSbIcE"));
@ -492,6 +495,9 @@ IRForTarget::MaybeSetCastResult (lldb_private::TypeFromParser type)
}
}
if (!original_load)
return;
Value *loaded_value = original_load->getPointerOperand();
GlobalVariable *loaded_global = dyn_cast<GlobalVariable>(loaded_value);

View File

@ -55,6 +55,7 @@ CommandObjectScript::DoExecute
{
result.AppendError("no script interpreter");
result.SetStatus (eReturnStatusFailed);
return false;
}
DataVisualization::ForceUpdate(); // script might change Python code we use for formatting.. make sure we keep up to date with it

View File

@ -439,6 +439,7 @@ Options::GenerateOptionUsage
// Different option sets may require different args.
StreamString args_str;
if (cmd)
cmd->GetFormattedCommandArguments(args_str, opt_set_mask);
// First go through and print all options that take no arguments as
@ -569,7 +570,8 @@ Options::GenerateOptionUsage
}
}
if (cmd->WantsRawCommandString() &&
if (cmd &&
cmd->WantsRawCommandString() &&
arguments_str.GetSize() > 0)
{
strm.PutChar('\n');

View File

@ -618,9 +618,8 @@ ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueOb
unsigned char buffer[16];
ByteOrder byte_order = data.GetByteOrder();
uint32_t return_bytes;
return_bytes = data.CopyByteOrderedData (0, num_bytes, buffer, 16, byte_order);
data.CopyByteOrderedData (0, num_bytes, buffer, 16, byte_order);
xmm0_value.SetBytes(buffer, 16, byte_order);
reg_ctx->WriteRegister(xmm0_info, xmm0_value);
set_it_simple = true;

View File

@ -178,11 +178,15 @@ InstructionLLVM::CalculateMnemonicOperandsAndComment (const ExecutionContext* ex
uint32_t addr_nibble_size = 8;
addr_t base_addr = LLDB_INVALID_ADDRESS;
Target *target = exe_ctx ? exe_ctx->GetTargetPtr() : NULL;
if (target && !target->GetSectionLoadList().IsEmpty())
if (target)
{
addr_nibble_size = target->GetArchitecture().GetAddressByteSize() * 2;
if (!target->GetSectionLoadList().IsEmpty())
base_addr = GetAddress().GetLoadAddress (target);
}
if (base_addr == LLDB_INVALID_ADDRESS)
base_addr = GetAddress().GetFileAddress ();
addr_nibble_size = target->GetArchitecture().GetAddressByteSize() * 2;
lldb::addr_t PC = base_addr + EDInstByteSize(m_inst);

View File

@ -446,7 +446,7 @@ DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded()
}
}
if (m_kernel.IsLoaded())
if (m_kernel.IsLoaded() && m_kernel.module_sp)
{
static ConstString kext_summary_symbol ("gLoadedKextSummaries");
const Symbol *symbol = m_kernel.module_sp->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData);

View File

@ -3570,6 +3570,8 @@ ObjectFileMachO::GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &th
GetNumThreadContexts ();
const FileRangeArray::Entry *thread_context_file_range = m_thread_context_offsets.GetEntryAtIndex (idx);
if (thread_context_file_range)
{
DataExtractor data (m_data,
thread_context_file_range->GetRangeBase(),
@ -3590,6 +3592,7 @@ ObjectFileMachO::GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &th
break;
}
}
}
return reg_ctx_sp;
}

View File

@ -779,7 +779,7 @@ RegisterContextLLDB::GetFullUnwindPlanForFrame ()
// right thing. It'd be nice if there was a way to ask the eh_frame directly if it is asynchronous
// (can be trusted at every instruction point) or synchronous (the normal case - only at call sites).
// But there is not.
if (process->GetDynamicLoader() && process->GetDynamicLoader()->AlwaysRelyOnEHUnwindInfo (m_sym_ctx))
if (process && process->GetDynamicLoader() && process->GetDynamicLoader()->AlwaysRelyOnEHUnwindInfo (m_sym_ctx))
{
unwind_plan_sp = func_unwinders_sp->GetUnwindPlanAtCallSite (m_current_offset_backed_up_one);
if (unwind_plan_sp && unwind_plan_sp->PlanValidAtAddress (m_current_pc))

View File

@ -175,7 +175,7 @@ UnwindLLDB::AddOneMoreFrame (ABI *abi)
{
if (m_frames.back()->cfa == cursor_sp->cfa)
goto unwind_done; // Infinite loop where the current cursor is the same as the previous one...
else if (abi->StackUsesFrames())
else if (abi && abi->StackUsesFrames())
{
// We might have a CFA that is not using the frame pointer and
// we want to validate that the frame pointer is valid.

View File

@ -386,7 +386,9 @@ DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data,
// down.
const bool clear_dies = ExtractDIEsIfNeeded (false) > 1;
DIE()->BuildAddressRangeTable(dwarf2Data, this, debug_aranges);
const DWARFDebugInfoEntry* die = DIE();
if (die)
die->BuildAddressRangeTable(dwarf2Data, this, debug_aranges);
// Keep memory down by clearing DIEs if this generate function
// caused them to be parsed
@ -410,7 +412,9 @@ DWARFCompileUnit::GetFunctionAranges ()
"DWARFCompileUnit::GetFunctionAranges() for compile unit at .debug_info[0x%8.8x]",
GetOffset());
}
DIE()->BuildFunctionAddressRangeTable (m_dwarf2Data, this, m_func_aranges_ap.get());
const DWARFDebugInfoEntry* die = DIE();
if (die)
die->BuildFunctionAddressRangeTable (m_dwarf2Data, this, m_func_aranges_ap.get());
const bool minimize = false;
m_func_aranges_ap->Sort(minimize);
}

View File

@ -117,6 +117,7 @@ DWARFDebugAranges::Dump (Log *log) const
for (size_t i=0; i<num_entries; ++i)
{
const RangeToDIE::Entry *entry = m_aranges.GetEntryAtIndex(i);
if (entry)
log->Printf ("0x%8.8x: [0x%llx - 0x%llx)",
entry->data,
entry->GetRangeBase(),

View File

@ -701,7 +701,10 @@ DWARFDebugInfo::Dump (Stream *s, const uint32_t die_offset, const uint32_t recur
{
const DWARFCompileUnitSP& cu_sp = *pos;
DumpCallback(m_dwarf2Data, (DWARFCompileUnitSP&)cu_sp, NULL, 0, curr_depth, &dumpInfo);
cu_sp->DIE()->Dump(m_dwarf2Data, cu_sp.get(), *s, recurse_depth);
const DWARFDebugInfoEntry* die = cu_sp->DIE();
if (die)
die->Dump(m_dwarf2Data, cu_sp.get(), *s, recurse_depth);
}
}

View File

@ -1035,6 +1035,7 @@ DWARFDebugInfoEntry::DumpAttribute
{
bool verbose = s.GetVerbose();
bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
const DataExtractor* debug_str_data = dwarf2Data ? &dwarf2Data->get_debug_str_data() : NULL;
if (verbose)
s.Offset (*offset_ptr);
@ -1158,6 +1159,7 @@ DWARFDebugInfoEntry::DumpAttribute
form_value.Dump(s, debug_str_data, cu);
uint32_t ranges_offset = form_value.Unsigned();
dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
if (dwarf2Data)
DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(), &ranges_offset, base_addr);
}
break;
@ -1509,6 +1511,9 @@ DWARFDebugInfoEntry::GetPubname
) const
{
const char* name = NULL;
if (!dwarf2Data)
return name;
DWARFFormValue form_value;
if (GetAttributeValue(dwarf2Data, cu, DW_AT_MIPS_linkage_name, form_value))
@ -1546,6 +1551,12 @@ DWARFDebugInfoEntry::GetName
Stream &s
)
{
if (dwarf2Data == NULL)
{
s.PutCString("NULL");
return false;
}
DWARFDebugInfoEntry die;
uint32_t offset = die_offset;
if (die.Extract(dwarf2Data, cu, &offset))
@ -1589,6 +1600,12 @@ DWARFDebugInfoEntry::AppendTypeName
Stream &s
)
{
if (dwarf2Data == NULL)
{
s.PutCString("NULL");
return false;
}
DWARFDebugInfoEntry die;
uint32_t offset = die_offset;
if (die.Extract(dwarf2Data, cu, &offset))
@ -1610,6 +1627,9 @@ DWARFDebugInfoEntry::AppendTypeName
bool result = true;
const DWARFAbbreviationDeclaration* abbrevDecl = die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
if (abbrevDecl == NULL)
return false;
switch (abbrevDecl->Tag())
{
case DW_TAG_array_type: break; // print out a "[]" after printing the full type of the element below
@ -2142,6 +2162,8 @@ DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data,
const DWARFCompileUnit *cu,
dw_offset_t &offset) const
{
if (dwarf2Data)
{
offset = GetOffset();
const DWARFAbbreviationDeclaration* abbrev_decl = cu->GetAbbreviations()->GetAbbreviationDeclaration (m_abbr_idx);
@ -2160,6 +2182,7 @@ DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data,
(uint32_t)abbrev_decl->Code(),
(uint32_t)abbrev_code);
}
}
offset = DW_INVALID_OFFSET;
return NULL;
}

View File

@ -34,6 +34,7 @@ DWARFLocationList::Dump(Stream &s, const DWARFCompileUnit* cu, const DataExtract
s.PutCString("\n ");
s.Indent();
if (cu)
s.AddressRange (start_addr + base_addr,
end_addr + base_addr,
cu->GetAddressByteSize(),

View File

@ -921,10 +921,13 @@ SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
if (dwarf_cu)
{
const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
if (die)
{
const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
if (language)
return (lldb::LanguageType)language;
}
}
return eLanguageTypeUnknown;
}

View File

@ -316,6 +316,7 @@ ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl)
void
ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl)
{
assert (decl);
ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
const DeclContext *parent_context = decl->getDeclContext();

View File

@ -343,7 +343,9 @@ void
Function::GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
{
Type* func_type = GetType();
*s << "id = " << (const UserID&)*this << ", name = \"" << func_type->GetName() << "\", range = ";
const char *name = func_type ? func_type->GetName().AsCString() : "<unknown>";
*s << "id = " << (const UserID&)*this << ", name = \"" << name << "\", range = ";
Address::DumpStyle fallback_style;
if (level == eDescriptionLevelVerbose)
@ -493,10 +495,14 @@ Function::GetType() const
clang_type_t
Function::GetReturnClangType ()
{
clang::QualType clang_type (clang::QualType::getFromOpaquePtr(GetType()->GetClangFullType()));
Type *type = GetType();
if (type)
{
clang::QualType clang_type (clang::QualType::getFromOpaquePtr(type->GetClangFullType()));
const clang::FunctionType *function_type = llvm::dyn_cast<clang::FunctionType> (clang_type);
if (function_type)
return function_type->getResultType().getAsOpaquePtr();
}
return NULL;
}

View File

@ -178,41 +178,3 @@ VariableList::Dump(Stream *s, bool show_context) const
(*pos)->Dump(s, show_context);
}
}
lldb::VariableSP
VariableList::FindArtificialObjectVariable (lldb::LanguageType language) const
{
lldb::VariableSP object_variable_sp;
ConstString object_variable_name;
switch (language)
{
case eLanguageTypeC_plus_plus:
object_variable_name.SetCString("this");
break;
case eLanguageTypeObjC:
case eLanguageTypeObjC_plus_plus:
object_variable_name.SetCString("self");
break;
default:
break;
}
if (object_variable_name)
{
const_iterator pos, end = m_variables.end();
for (pos = m_variables.begin(); pos != end; ++pos)
{
Variable *variable = pos->get();
if (variable->IsArtificial() &&
variable->GetScope() == eValueTypeVariableArgument &&
variable->GetName() == object_variable_name)
{
object_variable_sp = *pos;
break;
}
}
}
return object_variable_sp;
}

View File

@ -274,8 +274,6 @@ StackFrameList::GetFramesUpTo(uint32_t end_idx)
if (end_idx > 0)
end_idx += inlined_depth;
}
else
inlined_depth = 0;
}
StackFrameSP unwind_frame_sp;

View File

@ -1451,6 +1451,7 @@ Thread::ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return
if (!abi)
{
return_error.SetErrorString("Could not find ABI to set return value.");
return return_error;
}
SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction);

View File

@ -72,9 +72,12 @@ ThreadPlanTracer::Log()
bool show_fullpaths = false;
Stream *stream = GetLogStream();
if (stream)
{
m_thread.GetStackFrameAtIndex(0)->Dump (stream, show_frame_index, show_fullpaths);
stream->Printf("\n");
stream->Flush();
}
}

View File

@ -89,7 +89,7 @@ class AbbreviationsTestCase(TestBase):
patterns = [ "Current executable set to .*a.out.*" ])
# By default, the setting interpreter.expand-regex-aliases is false.
self.expect("_regexp-b product", matching=False,
self.expect("_regexp-br product", matching=False,
substrs = [ "breakpoint set --name" ])
match_object = lldbutil.run_break_set_command (self, "br s -n sum")