Correct DiagnoseIfInterpreterException in iterpreter.

This commit is contained in:
CristinaCristescu 2016-04-08 15:11:17 +02:00 committed by sftnight
parent 0fb177cbf2
commit 1cb874532b
5 changed files with 25 additions and 66 deletions

View File

@ -820,7 +820,7 @@ namespace cling {
}
}
void IncrementalParser::setTransformers(bool isChildInterpreter) {
void IncrementalParser::SetTransformers(bool isChildInterpreter) {
// Add transformers to the IncrementalParser, which owns them
Sema* TheSema = &m_CI->getSema();
// Register the AST Transformers

View File

@ -224,7 +224,7 @@ namespace cling {
///\brief Add the trnasformers to the Incremental Parser.
///
void setTransformers(bool isChildInterpreter);
void SetTransformers(bool isChildInterpreter);
private:
///\brief Finalizes the consumers (e.g. CodeGen) on a transaction.

View File

@ -230,7 +230,7 @@ namespace cling {
setCallbacks(std::move(AutoLoadCB));
}
m_IncrParser->setTransformers(isChildInterp);
m_IncrParser->SetTransformers(isChildInterp);
}
///\brief Constructor for the child Interpreter.

View File

@ -50,28 +50,20 @@ namespace cling {
PointerCheckInjector(Sema& S) : m_Sema(S), m_Context(S.getASTContext()),
m_clingthrowIfInvalidPointerCache(0) {}
bool VisitStmt(Stmt* S) {
for (auto child: S->children()) {
if (child)
VisitStmt(child);
}
return true;
}
bool VisitUnaryOperator(UnaryOperator* UnOp) {
VisitStmt(UnOp->getSubExpr());
if (UnOp->getOpcode() == UO_Deref)
if (UnOp->getSubExpr()->getType().getTypePtr()->isPointerType())
UnOp->setSubExpr(SynthesizeCheck(UnOp->getSubExpr()));
Expr* SubExpr = UnOp->getSubExpr();
VisitStmt(SubExpr);
if (UnOp->getOpcode() == UO_Deref
&& SubExpr->getType().getTypePtr()->isPointerType())
UnOp->setSubExpr(SynthesizeCheck(SubExpr));
return true;
}
bool VisitMemberExpr(MemberExpr* ME) {
if (!((VarDecl*)(ME->getMemberDecl()))->isStaticDataMember()) {
VisitStmt(ME->getBase());
if (ME->isArrow())
ME->setBase(SynthesizeCheck(ME->getBase()));
}
VisitStmt(ME->getBase());
if (ME->isArrow()
&& ME->getMemberDecl()->isCXXInstanceMember())
ME->setBase(SynthesizeCheck(ME->getBase()));
return true;
}
@ -94,45 +86,17 @@ namespace cling {
return true;
}
bool VisitDecl (Decl* D)
{
printf("%ld\n", *(long*)D);
return true;
}
bool VisitFunctionDecl(FunctionDecl* FD) {
if (!FD->isConstexpr()) {
CompoundStmt* CS = dyn_cast_or_null<CompoundStmt>(FD->getBody());
if (CS)
VisitStmt(CS);
}
return true;
}
bool VisitCXXMethodDecl(CXXMethodDecl* FD) {
if (!FD->isConstexpr()) {
CompoundStmt* CS = dyn_cast_or_null<CompoundStmt>(FD->getBody());
if (CS)
VisitStmt(CS);
}
return true;
}
bool TraverseFunctionDecl(FunctionDecl* FD) {
if (!FD->isConstexpr()) {
CompoundStmt* CS = dyn_cast_or_null<CompoundStmt>(FD->getBody());
if (CS)
TraverseStmt(CS);
}
// We cannot synthesize when there is a const expr.
if (!FD->isConstexpr())
RecursiveASTVisitor::TraverseFunctionDecl(FD);
return true;
}
bool TraverseCXXMethodDecl(CXXMethodDecl* CMD) {
if (!CMD->isConstexpr()){
CompoundStmt* CS = dyn_cast_or_null<CompoundStmt>(CMD->getBody());
if (CS)
TraverseStmt(CS);
}
bool TraverseCXXMethodDecl(CXXMethodDecl* CXXMD) {
// We cannot synthesize when there is a const expr.
if (!CXXMD->isConstexpr())
RecursiveASTVisitor::TraverseCXXMethodDecl(CXXMD);
return true;
}

View File

@ -23,10 +23,8 @@
namespace cling {
namespace utils {
#ifndef LLVM_ON_WIN32
static int getNullDevFileDescriptor() {
#ifdef LLVM_ON_WIN32
return 0;
#else
struct FileDescriptor {
int FD;
const char* file = "/dev/null";
@ -37,12 +35,10 @@ namespace cling {
};
static FileDescriptor nullDev;
return nullDev.FD;
#endif
}
#endif
// Checking whether the pointer points to a valid memory location
// Used for checking of void* output
// Should be moved to earlier stages (ex. IR) in the future
bool isAddressValid(const void *P) {
if (!P || P == (void *) -1)
return false;
@ -55,11 +51,10 @@ namespace cling {
return false;
return true;
#else
// There is a POSIX way of finding whether an address can be accessed for
// reading: write() will return EFAULT if not.
int NBytes = write(getNullDevFileDescriptor(), P, 1/*byte*/);
if (NBytes != 1) {
assert(errno == EFAULT && "unexpected pipe write error");
// There is a POSIX way of finding whether an address
// can be accessed for reading.
if (write(getNullDevFileDescriptor(), P, 1/*byte*/) != 1) {
assert(errno == EFAULT && "unexpected write error at address");
return false;
}
return true;