[cfe-commits] r90643 - in /cfe/trunk: test/Index/cindex-on-invalid.m tools/CIndex/CIndex.cpp
Daniel Dunbar
daniel at zuster.org
Fri Dec 4 18:17:18 PST 2009
Author: ddunbar
Date: Fri Dec 4 20:17:18 2009
New Revision: 90643
URL: http://llvm.org/viewvc/llvm-project?rev=90643&view=rev
Log:
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.
Added:
cfe/trunk/test/Index/cindex-on-invalid.m
Modified:
cfe/trunk/tools/CIndex/CIndex.cpp
Added: cfe/trunk/test/Index/cindex-on-invalid.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/cindex-on-invalid.m?rev=90643&view=auto
==============================================================================
--- cfe/trunk/test/Index/cindex-on-invalid.m (added)
+++ cfe/trunk/test/Index/cindex-on-invalid.m Fri Dec 4 20:17:18 2009
@@ -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
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=90643&r1=90642&r2=90643&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Fri Dec 4 20:17:18 2009
@@ -508,10 +508,20 @@
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'.
More information about the cfe-commits
mailing list