Enable Baozeng Ding's NullDeref protection for ROOT; use exceptions.

The function HandleInterpreterException catches the NullDerefException.
Remove pre-exception longjmp code.
This commit is contained in:
CristinaCristescu 2015-11-16 17:52:57 +01:00 committed by sftnight
parent 96b189e8d7
commit 8ab37ec3d6
7 changed files with 17 additions and 43 deletions

View File

@ -18,9 +18,6 @@
#include <memory>
#include <string>
// FIXME: workaround until JIT supports exceptions
#include <setjmp.h>
namespace llvm {
class raw_ostream;
struct GenericValue;
@ -182,9 +179,6 @@ 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();
@ -638,8 +632,6 @@ namespace cling {
llvm::raw_ostream* logs = 0) const;
friend class runtime::internal::LifetimeHandler;
// FIXME: workaround until JIT supports exceptions
static jmp_buf*& getNullDerefJump() { return m_JumpBuf; }
};
namespace internal {

View File

@ -23,8 +23,6 @@
#ifdef __cplusplus
#include "cling/Interpreter/RuntimeException.h"
#include <new>
namespace cling {

View File

@ -192,8 +192,8 @@ namespace cling {
std::vector<WTPtr_t> WrapperTransformers;
WrapperTransformers.emplace_back(new ValuePrinterSynthesizer(TheSema, 0));
WrapperTransformers.emplace_back(new DeclExtractor(TheSema));
WrapperTransformers.emplace_back(new ValueExtractionSynthesizer(TheSema));
WrapperTransformers.emplace_back(new NullDerefProtectionTransformer(TheSema));
WrapperTransformers.emplace_back(new ValueExtractionSynthesizer(TheSema));
WrapperTransformers.emplace_back(new CheckEmptyTransactionTransformer(TheSema));
m_Consumer->SetTransformers(std::move(ASTTransformers),

View File

@ -72,8 +72,6 @@ namespace {
} // unnamed namespace
namespace cling {
// FIXME: workaround until JIT supports exceptions
jmp_buf* Interpreter::m_JumpBuf;
Interpreter::PushTransactionRAII::PushTransactionRAII(const Interpreter* i)
: m_Interpreter(i) {

View File

@ -191,27 +191,26 @@ namespace cling {
return result;
}
NodeContext VisitCXXMemberCallExpr(CXXMemberCallExpr* CME) {
NodeContext result(CME);
Expr* Callee = CME->getCallee();
if (isa<MemberExpr>(Callee)) {
NodeContext ME = Visit(Callee);
if (!ME.isSingleStmt())
result.prepend(ME.getStmts()[0]);
}
return result;
}
private:
Stmt* SynthesizeCheck(SourceLocation Loc, Expr* Arg) {
assert(Arg && "Cannot call with Arg=0");
ASTContext& Context = m_Sema.getASTContext();
//copied from DynamicLookup.cpp
// Lookup Sema type
CXXRecordDecl* SemaRD
= dyn_cast<CXXRecordDecl>(utils::Lookup::Named(&m_Sema, "Sema",
utils::Lookup::Namespace(&m_Sema, "clang")));
QualType SemaRDTy = Context.getTypeDeclType(SemaRD);
Expr* VoidSemaArg = utils::Synthesize::CStyleCastPtrExpr(&m_Sema,SemaRDTy,
Expr* VoidSemaArg = utils::Synthesize::CStyleCastPtrExpr(&m_Sema,Context.VoidPtrTy,
(uint64_t)&m_Sema);
// Lookup Expr type
CXXRecordDecl* ExprRD
= dyn_cast<CXXRecordDecl>(utils::Lookup::Named(&m_Sema, "Expr",
utils::Lookup::Namespace(&m_Sema, "clang")));
QualType ExprRDTy = Context.getTypeDeclType(ExprRD);
Expr* VoidExprArg = utils::Synthesize::CStyleCastPtrExpr(&m_Sema,ExprRDTy,
Expr* VoidExprArg = utils::Synthesize::CStyleCastPtrExpr(&m_Sema,Context.VoidPtrTy,
(uint64_t)Arg);
Expr *args[] = {VoidSemaArg, VoidExprArg};
@ -224,7 +223,8 @@ namespace cling {
LookupResult R(m_Sema, Name, noLoc, Sema::LookupOrdinaryName,
Sema::ForRedeclaration);
m_Sema.LookupQualifiedName(R, Context.getTranslationUnitDecl());
assert(!R.empty() && "Cannot find valuePrinterInternal::Select(...)");
assert(!R.empty() &&
"Cannot find cling__runtime__internal__throwNullDerefException");
CXXScopeSpec CSS;
Expr* UnresolvedLookup

View File

@ -10,7 +10,6 @@
#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"
@ -19,12 +18,7 @@ extern "C" {
void cling__runtime__internal__throwNullDerefException(void* Sema, void* Expr) {
clang::Sema* S = (clang::Sema*)Sema;
clang::Expr* E = (clang::Expr*)Expr;
// 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);
throw cling::runtime::NullDerefException(S, E);
}
}

View File

@ -120,14 +120,6 @@ 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();