[libclang] Don't crash when saving a PCH from a prefix header

that does not exist.

rdar://11607033

llvm-svn: 158193
This commit is contained in:
Argyrios Kyrtzidis 2012-06-08 05:48:06 +00:00
parent bce6d51a4b
commit 1416e17c89
5 changed files with 19 additions and 6 deletions

View File

@ -188,7 +188,7 @@ public:
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input);
/// Execute - Set the source managers main input file, and run the action.
void Execute();
bool Execute();
/// EndSourceFile - Perform any per-file post processing, deallocate per-file
/// objects, and run statistics and output file cleanup code.

View File

@ -1133,7 +1133,8 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
StoredDiagnostics);
}
Act->Execute();
if (!Act->Execute())
goto error;
transferASTDataFromCompilerInstance(*Clang);
@ -1795,7 +1796,13 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(CompilerInvocation *CI,
AST->getCurrentTopLevelHashValue()));
Clang->setASTConsumer(new MultiplexConsumer(Consumers));
}
Act->Execute();
if (!Act->Execute()) {
AST->transferASTDataFromCompilerInstance(*Clang);
if (OwnAST && ErrAST)
ErrAST->swap(OwnAST);
return 0;
}
// Steal the created target, context, and preprocessor.
AST->transferASTDataFromCompilerInstance(*Clang);

View File

@ -315,7 +315,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
return false;
}
void FrontendAction::Execute() {
bool FrontendAction::Execute() {
CompilerInstance &CI = getCompilerInstance();
// Initialize the main file entry. This needs to be delayed until after PCH
@ -325,7 +325,7 @@ void FrontendAction::Execute() {
getCurrentInput().IsSystem
? SrcMgr::C_System
: SrcMgr::C_User))
return;
return false;
}
if (CI.hasFrontendTimer()) {
@ -333,6 +333,8 @@ void FrontendAction::Execute() {
ExecuteAction();
}
else ExecuteAction();
return true;
}
void FrontendAction::EndSourceFile() {

View File

@ -38,5 +38,7 @@ void foo(void) {
// CHECK-INDEX: [indexEntityReference]: kind: function | name: erroneous
// RUN: %clang -fsyntax-only %s -include %t.h 2>&1 | FileCheck -check-prefix=PCH-ERR %s
// PCH-ERR: error: PCH file contains compiler errors
// RUN: c-index-test -write-pch %t.pch foobar.c 2>&1 | FileCheck -check-prefix=NONEXISTENT %s
// NONEXISTENT: Unable to load translation unit

View File

@ -2692,6 +2692,8 @@ int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName,
ASTUnit *CXXUnit = static_cast<ASTUnit *>(TU->TUData);
ASTUnit::ConcurrencyCheck Check(*CXXUnit);
if (!CXXUnit->hasSema())
return CXSaveError_InvalidTU;
SaveTranslationUnitInfo STUI = { TU, FileName, options, CXSaveError_None };