CIndex: For the time being, don't return translation units if we encounter an error during parsing.

- We need to be more careful in the rest of CIndex if we are to handle
   possibly-invalid ASTs, and don't have much experience with this yet.

llvm-svn: 90643
This commit is contained in:
Daniel Dunbar 2009-12-05 02:17:18 +00:00
parent 4fb3d9fcd7
commit 72fe5b1bcc
2 changed files with 22 additions and 4 deletions

View File

@ -0,0 +1,8 @@
// RUN: not c-index-test -test-load-source local %s > %t 2> %t.err
// RUN: FileCheck %s < %t.err
// CHECK: error: expected identifier or '('
// CHECK: Unable to load translation unit!
int foo;
int

View File

@ -508,10 +508,20 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
command_line_args + num_command_line_args);
void *MainAddr = (void *)(uintptr_t)clang_createTranslationUnit;
return ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
unsigned NumErrors = CXXIdx->getDiags().getNumErrors();
llvm::OwningPtr<ASTUnit> Unit(
ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
CXXIdx->getDiags(), "<clang>", MainAddr,
CXXIdx->getOnlyLocalDecls(),
/* UseBumpAllocator = */ true);
/* UseBumpAllocator = */ true));
// FIXME: Until we have broader testing, just drop the entire AST if we
// encountered an error.
if (NumErrors != CXXIdx->getDiags().getNumErrors())
return 0;
return Unit.take();
}
// Build up the arguments for invoking 'clang'.