libclang: Execute clang_codeCompleteAt() inside a crash recovery context.

- Test case is disabled for now, because something isn't write with file
   remapping.

llvm-svn: 111581
This commit is contained in:
Daniel Dunbar 2010-08-19 23:44:10 +00:00
parent 186f74215f
commit 77af1c564e
4 changed files with 71 additions and 13 deletions

View File

@ -0,0 +1,12 @@
// RUN: echo env CINDEXTEST_EDITING=1 \
// RUN: not c-index-test -test-load-source-reparse 1 local \
// RUN: -remap-file="%s;%S/Inputs/crash-recovery-code-complete-remap.c" \
// RUN: %s 2> %t.err
// RUN: FileCheck < %t.err -check-prefix=CHECK-CODE-COMPLETE-CRASH %s
// CHECK-CODE-COMPLETE-CRASH: Unable to reparse translation unit
//
// XFAIL: win32
#warning parsing original file
#pragma clang __debug crash

View File

@ -0,0 +1,11 @@
// RUN: echo env CINDEXTEST_EDITING=1 \
// RUN: not c-index-test -code-completion-at=%s:20:1 \
// RUN: -remap-file="%s;%S/Inputs/crash-recovery-code-complete-remap.c" \
// RUN: %s 2> %t.err
// RUN: FileCheck < %t.err -check-prefix=CHECK-CODE-COMPLETE-CRASH %s
// CHECK-CODE-COMPLETE-CRASH: Unable to reparse translation unit
//
// XFAIL: win32
// XFAIL: *
#warning parsing original file

View File

@ -1221,7 +1221,7 @@ struct ParseTranslationUnitInfo {
unsigned options;
CXTranslationUnit result;
};
void clang_parseTranslationUnit_Impl(void *UserData) {
static void clang_parseTranslationUnit_Impl(void *UserData) {
ParseTranslationUnitInfo *PTUI =
static_cast<ParseTranslationUnitInfo*>(UserData);
CXIndex CIdx = PTUI->CIdx;
@ -1491,7 +1491,7 @@ CXTranslationUnit clang_parseTranslationUnit(CXIndex CIdx,
llvm::CrashRecoveryContext CRC;
if (!CRC.RunSafely(clang_parseTranslationUnit_Impl, &PTUI)) {
// FIXME: Find a way to report the crash.
fprintf(stderr, "libclang: crash detected during parsing");
return 0;
}
@ -1532,7 +1532,7 @@ struct ReparseTranslationUnitInfo {
unsigned options;
int result;
};
void clang_reparseTranslationUnit_Impl(void *UserData) {
static void clang_reparseTranslationUnit_Impl(void *UserData) {
ReparseTranslationUnitInfo *RTUI =
static_cast<ReparseTranslationUnitInfo*>(UserData);
CXTranslationUnit TU = RTUI->TU;
@ -1567,7 +1567,7 @@ int clang_reparseTranslationUnit(CXTranslationUnit TU,
llvm::CrashRecoveryContext CRC;
if (!CRC.RunSafely(clang_reparseTranslationUnit_Impl, &RTUI)) {
// FIXME: Find a way to report the crash.
fprintf(stderr, "libclang: crash detected during reparsing\n");
static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
return 1;
}

View File

@ -22,6 +22,7 @@
#include "clang/Sema/CodeCompleteConsumer.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
@ -568,13 +569,27 @@ namespace {
}
extern "C" {
CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
const char *complete_filename,
unsigned complete_line,
unsigned complete_column,
struct CXUnsavedFile *unsaved_files,
unsigned num_unsaved_files,
unsigned options) {
struct CodeCompleteAtInfo {
CXTranslationUnit TU;
const char *complete_filename;
unsigned complete_line;
unsigned complete_column;
struct CXUnsavedFile *unsaved_files;
unsigned num_unsaved_files;
unsigned options;
CXCodeCompleteResults *result;
};
void clang_codeCompleteAt_Impl(void *UserData) {
CodeCompleteAtInfo *CCAI = static_cast<CodeCompleteAtInfo*>(UserData);
CXTranslationUnit TU = CCAI->TU;
const char *complete_filename = CCAI->complete_filename;
unsigned complete_line = CCAI->complete_line;
unsigned complete_column = CCAI->complete_column;
struct CXUnsavedFile *unsaved_files = CCAI->unsaved_files;
unsigned num_unsaved_files = CCAI->num_unsaved_files;
unsigned options = CCAI->options;
CCAI->result = 0;
#ifdef UDP_CODE_COMPLETION_LOGGER
#ifdef UDP_CODE_COMPLETION_LOGGER_PORT
const llvm::TimeRecord &StartTime = llvm::TimeRecord::getCurrentTime();
@ -585,7 +600,7 @@ CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
ASTUnit *AST = static_cast<ASTUnit *>(TU);
if (!AST)
return 0;
return;
// Perform the remapping of source files.
llvm::SmallVector<ASTUnit::RemappedFile, 4> RemappedFiles;
@ -697,7 +712,27 @@ CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
}
#endif
#endif
return Results;
CCAI->result = Results;
}
CXCodeCompleteResults *clang_codeCompleteAt(CXTranslationUnit TU,
const char *complete_filename,
unsigned complete_line,
unsigned complete_column,
struct CXUnsavedFile *unsaved_files,
unsigned num_unsaved_files,
unsigned options) {
CodeCompleteAtInfo CCAI = { TU, complete_filename, complete_line,
complete_column, unsaved_files, num_unsaved_files,
options, 0 };
llvm::CrashRecoveryContext CRC;
if (!CRC.RunSafely(clang_codeCompleteAt_Impl, &CCAI)) {
fprintf(stderr, "libclang: crash detected in code completion\n");
static_cast<ASTUnit *>(TU)->setUnsafeToFree(true);
return 0;
}
return CCAI.result;
}
unsigned clang_defaultCodeCompleteOptions(void) {