diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-12-05 02:17:18 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-12-05 02:17:18 +0000 |
commit | 942209729a70af6230af2c6f0436bb77d2f6891c (patch) | |
tree | 6d3c7220a11ac33aa67a38d339d59d22fb206e36 | |
parent | e0c4d895ffe4320aa4e29485711ad7d154f2cc2b (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90643 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | test/Index/cindex-on-invalid.m | 8 | ||||
-rw-r--r-- | tools/CIndex/CIndex.cpp | 18 |
2 files changed, 22 insertions, 4 deletions
diff --git a/test/Index/cindex-on-invalid.m b/test/Index/cindex-on-invalid.m new file mode 100644 index 0000000000..651c40a335 --- /dev/null +++ b/test/Index/cindex-on-invalid.m @@ -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 diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 12c3935ca1..9259818e0e 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -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(), - CXXIdx->getDiags(), "<clang>", MainAddr, - CXXIdx->getOnlyLocalDecls(), - /* UseBumpAllocator = */ true); + + 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)); + + // 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'. |