Workaround broken JIT exceptions, use longjmp instead.

This commit is contained in:
Axel Naumann 2013-10-03 09:47:56 +02:00 committed by sftnight
parent 84b49183f3
commit 5706d4bdef
4 changed files with 28 additions and 1 deletions

View File

@ -15,6 +15,9 @@
#include <string>
#include <cstdlib>
// FIXME: workaround until JIT supports exceptions
#include <setjmp.h>
namespace llvm {
class raw_ostream;
struct GenericValue;
@ -171,6 +174,9 @@ namespace cling {
///
mutable std::vector<ClangInternalState*> m_StoredStates;
///\brief: FIXME: workaround until JIT supports exceptions
static jmp_buf* m_JumpBuf;
///\brief Processes the invocation options.
///
void handleFrontendOptions();
@ -581,6 +587,9 @@ namespace cling {
friend int runtime::internal::local_cxa_atexit(void (*func) (void*),
void* arg, void* dso,
void* interp);
// FIXME: workaround until JIT supports exceptions
static jmp_buf*& getNullDerefJump() { return m_JumpBuf; }
};
namespace internal {

View File

@ -81,6 +81,10 @@ namespace cling {
namespace cling {
// FIXME: workaround until JIT supports exceptions
jmp_buf* Interpreter::m_JumpBuf;
#if (!_WIN32)
// "Declared" to the JIT in RuntimeUniverse.h
namespace runtime {

View File

@ -7,6 +7,7 @@
#include "cling/Interpreter/RuntimeException.h"
#include "cling/Interpreter/Interpreter.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaDiagnostic.h"
@ -15,7 +16,12 @@ extern "C" {
void cling__runtime__internal__throwNullDerefException(void* Sema, void* Expr) {
clang::Sema* S = (clang::Sema*)Sema;
clang::Expr* E = (clang::Expr*)Expr;
throw cling::runtime::NullDerefException(S, E);
// FIXME: workaround until JIT supports exceptions
//throw cling::runtime::NullDerefException(S, E);
S->Diag(E->getLocStart(), clang::diag::warn_null_arg) << E->getSourceRange();
if (cling::Interpreter::getNullDerefJump())
longjmp(*cling::Interpreter::getNullDerefJump(), 1);
}
}

View File

@ -111,6 +111,14 @@ namespace cling {
TI.SetPrompt("[cling]$ ");
std::string line;
jmp_buf env;
int val = setjmp(env);
if (!val) {
Interpreter::getNullDerefJump() = &env;
} else {
llvm::errs() << "LongJmp occurred. Recovering...\n";
}
while (true) {
try {
m_MetaProcessor->getOuts().flush();