[clang] 55c7ad3 - [clang][Interp][NFC] Pass Function* pointers around as const
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 14 03:31:45 PDT 2022
Author: Timm Bäder
Date: 2022-10-14T12:31:24+02:00
New Revision: 55c7ad31aacb6cdef19a7296fda56cc8b177e2b4
URL: https://github.com/llvm/llvm-project/commit/55c7ad31aacb6cdef19a7296fda56cc8b177e2b4
DIFF: https://github.com/llvm/llvm-project/commit/55c7ad31aacb6cdef19a7296fda56cc8b177e2b4.diff
LOG: [clang][Interp][NFC] Pass Function* pointers around as const
Added:
Modified:
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvalEmitter.h
clang/lib/AST/Interp/Function.h
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpFrame.h
clang/lib/AST/Interp/InterpState.h
clang/lib/AST/Interp/Source.cpp
clang/lib/AST/Interp/Source.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp
index aa4396f135d2..0638a68297ed 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -105,7 +105,7 @@ template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) {
template <PrimType OpType>
bool EvalEmitter::emitCall(const Function *Func, const SourceInfo &Info) {
- S.Current = new InterpFrame(S, const_cast<Function *>(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<Function *>(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 94c58ec11e2b..560ce6f6f470 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -71,7 +71,7 @@ class EvalEmitter : public SourceMapper {
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 1fc27ee60734..bb99ea72a442 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -43,7 +43,7 @@ class Scope final {
Scope(LocalVectorTy &&Descriptors) : Descriptors(std::move(Descriptors)) {}
- llvm::iterator_range<LocalVectorTy::iterator> locals() {
+ llvm::iterator_range<LocalVectorTy::const_iterator> locals() const {
return llvm::make_range(Descriptors.begin(), Descriptors.end());
}
@@ -102,18 +102,21 @@ class Function final {
bool hasRVO() const { return HasRVO; }
/// Range over the scope blocks.
- llvm::iterator_range<llvm::SmallVector<Scope, 2>::iterator> scopes() {
+ llvm::iterator_range<llvm::SmallVector<Scope, 2>::const_iterator>
+ scopes() const {
return llvm::make_range(Scopes.begin(), Scopes.end());
}
/// Range over argument types.
- using arg_reverse_iterator = SmallVectorImpl<PrimType>::reverse_iterator;
- llvm::iterator_range<arg_reverse_iterator> args_reverse() {
+ using arg_reverse_iterator =
+ SmallVectorImpl<PrimType>::const_reverse_iterator;
+ llvm::iterator_range<arg_reverse_iterator> 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 fb8e5cf51a95..a2320f0d2076 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<char *>(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<char *>(S.Stk.top())), FrameOffset(S.Stk.size()) {
diff --git a/clang/lib/AST/Interp/InterpFrame.h b/clang/lib/AST/Interp/InterpFrame.h
index 3cc894cd2334..ecbe697eacdd 100644
--- a/clang/lib/AST/Interp/InterpFrame.h
+++ b/clang/lib/AST/Interp/InterpFrame.h
@@ -32,13 +32,13 @@ class InterpFrame final : public Frame {
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 @@ class InterpFrame final : public Frame {
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 @@ class InterpFrame final : public Frame {
/// 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 57e36c4c63ea..72f6dd09dc2e 100644
--- a/clang/lib/AST/Interp/InterpState.h
+++ b/clang/lib/AST/Interp/InterpState.h
@@ -81,7 +81,7 @@ class InterpState final : public State, public SourceMapper {
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 4bec87812638..467cde116843 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 0d9780ca1c46..de4ae559e4bb 100644
--- a/clang/lib/AST/Interp/Source.h
+++ b/clang/lib/AST/Interp/Source.h
@@ -91,12 +91,12 @@ class SourceMapper {
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
More information about the cfe-commits
mailing list