[cfe-commits] r111387 - in /cfe/trunk: test/Index/crash-recovery.c tools/libclang/CIndex.cpp
Daniel Dunbar
daniel at zuster.org
Wed Aug 18 11:43:17 PDT 2010
Author: ddunbar
Date: Wed Aug 18 13:43:17 2010
New Revision: 111387
URL: http://llvm.org/viewvc/llvm-project?rev=111387&view=rev
Log:
libclang: Put clang_parseTranslationUnit inside a crash recovery context.
Added:
cfe/trunk/test/Index/crash-recovery.c
Modified:
cfe/trunk/tools/libclang/CIndex.cpp
Added: cfe/trunk/test/Index/crash-recovery.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/crash-recovery.c?rev=111387&view=auto
==============================================================================
--- cfe/trunk/test/Index/crash-recovery.c (added)
+++ cfe/trunk/test/Index/crash-recovery.c Wed Aug 18 13:43:17 2010
@@ -0,0 +1,7 @@
+// RUN: not c-index-test -test-load-source all %s 2> %t.err
+// RUN: FileCheck < %t.err -check-prefix=CHECK-LOAD-SOURCE-CRASH %s
+// CHECK-LOAD-SOURCE-CRASH: Unable to load translation unit
+//
+// XFAIL: win32
+
+#pragma clang __debug crash
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=111387&r1=111386&r2=111387&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Aug 18 13:43:17 2010
@@ -1209,16 +1209,31 @@
unsaved_files, num_unsaved_files,
CXTranslationUnit_DetailedPreprocessingRecord);
}
+
+struct ParseTranslationUnitInfo {
+ CXIndex CIdx;
+ const char *source_filename;
+ const char **command_line_args;
+ int num_command_line_args;
+ struct CXUnsavedFile *unsaved_files;
+ unsigned num_unsaved_files;
+ unsigned options;
+ CXTranslationUnit result;
+};
+void clang_parseTranslationUnit_Impl(void *UserData) {
+ ParseTranslationUnitInfo *PTUI =
+ static_cast<ParseTranslationUnitInfo*>(UserData);
+ CXIndex CIdx = PTUI->CIdx;
+ const char *source_filename = PTUI->source_filename;
+ const char **command_line_args = PTUI->command_line_args;
+ int num_command_line_args = PTUI->num_command_line_args;
+ struct CXUnsavedFile *unsaved_files = PTUI->unsaved_files;
+ unsigned num_unsaved_files = PTUI->num_unsaved_files;
+ unsigned options = PTUI->options;
+ PTUI->result = 0;
-CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
- const char *source_filename,
- const char **command_line_args,
- int num_command_line_args,
- struct CXUnsavedFile *unsaved_files,
- unsigned num_unsaved_files,
- unsigned options) {
if (!CIdx)
- return 0;
+ return;
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
@@ -1307,7 +1322,8 @@
}
}
- return Unit.take();
+ PTUI->result = Unit.take();
+ return;
}
// Build up the arguments for invoking 'clang'.
@@ -1343,7 +1359,7 @@
std::vector<llvm::sys::Path> TemporaryFiles;
std::vector<std::string> RemapArgs;
if (RemapFiles(num_unsaved_files, unsaved_files, RemapArgs, TemporaryFiles))
- return 0;
+ return;
// The pointers into the elements of RemapArgs are stable because we
// won't be adding anything to RemapArgs after this point.
@@ -1459,7 +1475,26 @@
TemporaryFiles[i].eraseFromDisk();
}
- return ATU;
+ PTUI->result = ATU;
+}
+CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
+ const char *source_filename,
+ const char **command_line_args,
+ int num_command_line_args,
+ struct CXUnsavedFile *unsaved_files,
+ unsigned num_unsaved_files,
+ unsigned options) {
+ ParseTranslationUnitInfo PTUI = { CIdx, source_filename, command_line_args,
+ num_command_line_args, unsaved_files, num_unsaved_files,
+ options, 0 };
+ llvm::CrashRecoveryContext CRC;
+
+ if (!CRC.RunSafely(clang_parseTranslationUnit_Impl, &PTUI)) {
+ // FIXME: Find a way to report the crash.
+ return 0;
+ }
+
+ return PTUI.result;
}
unsigned clang_defaultSaveOptions(CXTranslationUnit TU) {
@@ -1473,7 +1508,7 @@
return static_cast<ASTUnit *>(TU)->Save(FileName);
}
-
+
void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) {
if (CTUnit)
delete static_cast<ASTUnit *>(CTUnit);
More information about the cfe-commits
mailing list