diff --git a/lib/Interpreter/IncrementalParser.cpp b/lib/Interpreter/IncrementalParser.cpp index a4f23a7f..f95f6c24 100644 --- a/lib/Interpreter/IncrementalParser.cpp +++ b/lib/Interpreter/IncrementalParser.cpp @@ -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 diff --git a/lib/Interpreter/IncrementalParser.h b/lib/Interpreter/IncrementalParser.h index c23ef1b9..2124cc15 100644 --- a/lib/Interpreter/IncrementalParser.h +++ b/lib/Interpreter/IncrementalParser.h @@ -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. diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index 81f37ae1..e087b5ee 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -230,7 +230,7 @@ namespace cling { setCallbacks(std::move(AutoLoadCB)); } - m_IncrParser->setTransformers(isChildInterp); + m_IncrParser->SetTransformers(isChildInterp); } ///\brief Constructor for the child Interpreter. diff --git a/lib/Interpreter/NullDerefProtectionTransformer.cpp b/lib/Interpreter/NullDerefProtectionTransformer.cpp index 1672e001..e2837a32 100644 --- a/lib/Interpreter/NullDerefProtectionTransformer.cpp +++ b/lib/Interpreter/NullDerefProtectionTransformer.cpp @@ -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(FD->getBody()); - if (CS) - VisitStmt(CS); - } - return true; - } - - bool VisitCXXMethodDecl(CXXMethodDecl* FD) { - if (!FD->isConstexpr()) { - CompoundStmt* CS = dyn_cast_or_null(FD->getBody()); - if (CS) - VisitStmt(CS); - } - return true; - } - bool TraverseFunctionDecl(FunctionDecl* FD) { - if (!FD->isConstexpr()) { - CompoundStmt* CS = dyn_cast_or_null(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(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; } diff --git a/lib/Utils/Validation.cpp b/lib/Utils/Validation.cpp index bd9e02b5..d0ae5dc7 100644 --- a/lib/Utils/Validation.cpp +++ b/lib/Utils/Validation.cpp @@ -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;