Don't crash if we load a file with an architecture we don't support and try to parse some DWARF.

The ClangASTContext::getTargetInfo() will return NULL in this case and could cause us to crash if we don't check.

<rdar://problem/20543554> 

llvm-svn: 236681
This commit is contained in:
Greg Clayton 2015-05-07 00:07:44 +00:00
parent d528112b41
commit 28eb7bf406
1 changed files with 8 additions and 4 deletions

View File

@ -403,8 +403,12 @@ ClangASTContext::getASTContext()
*getBuiltinContext()));
m_ast_ap->getDiagnostics().setClient(getDiagnosticConsumer(), false);
m_ast_ap->InitBuiltinTypes(*getTargetInfo());
// This can be NULL if we don't know anything about the architecture or if the
// target for an architecture isn't enabled in the llvm/clang that we built
TargetInfo *target_info = getTargetInfo();
if (target_info)
m_ast_ap->InitBuiltinTypes(*target_info);
if ((m_callback_tag_decl || m_callback_objc_decl) && m_callback_baton)
{
@ -906,7 +910,7 @@ ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name
{
if (streq(type_name, "wchar_t") &&
QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy) &&
TargetInfo::isTypeSigned (getTargetInfo()->getWCharType()))
(getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType())))
return ClangASTType (ast, ast->WCharTy.getAsOpaquePtr());
if (streq(type_name, "void") &&
QualTypeMatchesBitSize (bit_size, ast, ast->VoidTy))
@ -967,7 +971,7 @@ ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name
{
if (QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy))
{
if (!TargetInfo::isTypeSigned (getTargetInfo()->getWCharType()))
if (!(getTargetInfo() && TargetInfo::isTypeSigned (getTargetInfo()->getWCharType())))
return ClangASTType (ast, ast->WCharTy.getAsOpaquePtr());
}
}