From: Timm Bäder Date: Fri, 23 Sep 2022 13:15:09 +0000 (+0200) Subject: [clang][Interp][NFC] Pass Function* pointers around as const X-Git-Tag: upstream/17.0.6~30582 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=55c7ad31aacb6cdef19a7296fda56cc8b177e2b4;p=platform%2Fupstream%2Fllvm.git [clang][Interp][NFC] Pass Function* pointers around as const --- diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index aa4396f..0638a68 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -105,7 +105,7 @@ template bool EvalEmitter::emitRet(const SourceInfo &Info) { template bool EvalEmitter::emitCall(const Function *Func, const SourceInfo &Info) { - S.Current = new InterpFrame(S, const_cast(Func), {}); + S.Current = new InterpFrame(S, Func, {}); // Result of call will be on the stack and needs to be handled by the caller. return Interpret(S, Result); } @@ -114,7 +114,7 @@ bool EvalEmitter::emitCallVoid(const Function *Func, const SourceInfo &Info) { APValue VoidResult; InterpFrame *before = S.Current; (void)before; - S.Current = new InterpFrame(S, const_cast(Func), {}); + S.Current = new InterpFrame(S, Func, {}); bool Success = Interpret(S, VoidResult); assert(VoidResult.isAbsent()); assert(S.Current == before); diff --git a/clang/lib/AST/Interp/EvalEmitter.h b/clang/lib/AST/Interp/EvalEmitter.h index 94c58ec..560ce6f 100644 --- a/clang/lib/AST/Interp/EvalEmitter.h +++ b/clang/lib/AST/Interp/EvalEmitter.h @@ -71,7 +71,7 @@ protected: Local createLocal(Descriptor *D); /// Returns the source location of the current opcode. - SourceInfo getSource(Function *F, CodePtr PC) const override { + SourceInfo getSource(const Function *F, CodePtr PC) const override { return F ? F->getSource(PC) : CurrentSource; } diff --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h index 1fc27ee..bb99ea7 100644 --- a/clang/lib/AST/Interp/Function.h +++ b/clang/lib/AST/Interp/Function.h @@ -43,7 +43,7 @@ public: Scope(LocalVectorTy &&Descriptors) : Descriptors(std::move(Descriptors)) {} - llvm::iterator_range locals() { + llvm::iterator_range locals() const { return llvm::make_range(Descriptors.begin(), Descriptors.end()); } @@ -102,18 +102,21 @@ public: bool hasRVO() const { return HasRVO; } /// Range over the scope blocks. - llvm::iterator_range::iterator> scopes() { + llvm::iterator_range::const_iterator> + scopes() const { return llvm::make_range(Scopes.begin(), Scopes.end()); } /// Range over argument types. - using arg_reverse_iterator = SmallVectorImpl::reverse_iterator; - llvm::iterator_range args_reverse() { + using arg_reverse_iterator = + SmallVectorImpl::const_reverse_iterator; + llvm::iterator_range args_reverse() const { return llvm::make_range(ParamTypes.rbegin(), ParamTypes.rend()); } /// Returns a specific scope. Scope &getScope(unsigned Idx) { return Scopes[Idx]; } + const Scope &getScope(unsigned Idx) const { return Scopes[Idx]; } /// Returns the source information at a given PC. SourceInfo getSource(CodePtr PC) const; diff --git a/clang/lib/AST/Interp/InterpFrame.cpp b/clang/lib/AST/Interp/InterpFrame.cpp index fb8e5cf..a2320f0 100644 --- a/clang/lib/AST/Interp/InterpFrame.cpp +++ b/clang/lib/AST/Interp/InterpFrame.cpp @@ -18,8 +18,8 @@ using namespace clang; using namespace clang::interp; -InterpFrame::InterpFrame(InterpState &S, Function *Func, InterpFrame *Caller, - CodePtr RetPC, Pointer &&This) +InterpFrame::InterpFrame(InterpState &S, const Function *Func, + InterpFrame *Caller, CodePtr RetPC, Pointer &&This) : Caller(Caller), S(S), Func(Func), This(std::move(This)), RetPC(RetPC), ArgSize(Func ? Func->getArgSize() : 0), Args(static_cast(S.Stk.top())), FrameOffset(S.Stk.size()) { @@ -36,7 +36,7 @@ InterpFrame::InterpFrame(InterpState &S, Function *Func, InterpFrame *Caller, } } -InterpFrame::InterpFrame(InterpState &S, Function *Func, CodePtr RetPC) +InterpFrame::InterpFrame(InterpState &S, const Function *Func, CodePtr RetPC) : Caller(S.Current), S(S), Func(Func), RetPC(RetPC), ArgSize(Func ? Func->getArgSize() : 0), Args(static_cast(S.Stk.top())), FrameOffset(S.Stk.size()) { diff --git a/clang/lib/AST/Interp/InterpFrame.h b/clang/lib/AST/Interp/InterpFrame.h index 3cc894c..ecbe697 100644 --- a/clang/lib/AST/Interp/InterpFrame.h +++ b/clang/lib/AST/Interp/InterpFrame.h @@ -32,13 +32,13 @@ public: InterpFrame *Caller; /// Creates a new frame for a method call. - InterpFrame(InterpState &S, Function *Func, InterpFrame *Caller, + InterpFrame(InterpState &S, const Function *Func, InterpFrame *Caller, CodePtr RetPC, Pointer &&This); /// Creates a new frame with the values that make sense. /// I.e., the caller is the current frame of S, /// and the This() pointer is the current Pointer on the top of S's stack, - InterpFrame(InterpState &S, Function *Func, CodePtr RetPC); + InterpFrame(InterpState &S, const Function *Func, CodePtr RetPC); /// Destroys the frame, killing all live pointers to stack slots. ~InterpFrame(); @@ -62,7 +62,7 @@ public: const FunctionDecl *getCallee() const override; /// Returns the current function. - Function *getFunction() const { return Func; } + const Function *getFunction() const { return Func; } /// Returns the offset on the stack at which the frame starts. size_t getFrameOffset() const { return FrameOffset; } @@ -136,7 +136,7 @@ private: /// Reference to the interpreter state. InterpState &S; /// Reference to the function being executed. - Function *Func; + const Function *Func; /// Current object pointer for methods. Pointer This; /// Return address. diff --git a/clang/lib/AST/Interp/InterpState.h b/clang/lib/AST/Interp/InterpState.h index 57e36c4..72f6dd0 100644 --- a/clang/lib/AST/Interp/InterpState.h +++ b/clang/lib/AST/Interp/InterpState.h @@ -81,7 +81,7 @@ public: void deallocate(Block *B); /// Delegates source mapping to the mapper. - SourceInfo getSource(Function *F, CodePtr PC) const override { + SourceInfo getSource(const Function *F, CodePtr PC) const override { return M ? M->getSource(F, PC) : F->getSource(PC); } diff --git a/clang/lib/AST/Interp/Source.cpp b/clang/lib/AST/Interp/Source.cpp index 4bec878..467cde1 100644 --- a/clang/lib/AST/Interp/Source.cpp +++ b/clang/lib/AST/Interp/Source.cpp @@ -28,12 +28,12 @@ const Expr *SourceInfo::asExpr() const { return nullptr; } -const Expr *SourceMapper::getExpr(Function *F, CodePtr PC) const { +const Expr *SourceMapper::getExpr(const Function *F, CodePtr PC) const { if (const Expr *E = getSource(F, PC).asExpr()) return E; llvm::report_fatal_error("missing source expression"); } -SourceLocation SourceMapper::getLocation(Function *F, CodePtr PC) const { +SourceLocation SourceMapper::getLocation(const Function *F, CodePtr PC) const { return getSource(F, PC).getLoc(); } diff --git a/clang/lib/AST/Interp/Source.h b/clang/lib/AST/Interp/Source.h index 0d9780c..de4ae55 100644 --- a/clang/lib/AST/Interp/Source.h +++ b/clang/lib/AST/Interp/Source.h @@ -91,12 +91,12 @@ public: virtual ~SourceMapper() {} /// Returns source information for a given PC in a function. - virtual SourceInfo getSource(Function *F, CodePtr PC) const = 0; + virtual SourceInfo getSource(const Function *F, CodePtr PC) const = 0; /// Returns the expression if an opcode belongs to one, null otherwise. - const Expr *getExpr(Function *F, CodePtr PC) const; + const Expr *getExpr(const Function *F, CodePtr PC) const; /// Returns the location from which an opcode originates. - SourceLocation getLocation(Function *F, CodePtr PC) const; + SourceLocation getLocation(const Function *F, CodePtr PC) const; }; } // namespace interp