[PATCH] D142617: [clang][Interp] Check This pointer without creating InterpFrame
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 1 07:06:58 PST 2023
tbaeder updated this revision to Diff 501502.
tbaeder added a comment.
Added an `aligned()` assertion and renamed the old `peek(unsigned Offset)` returning a `void*` to `peekData()`, so both `peek` overloads are now public member functions.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142617/new/
https://reviews.llvm.org/D142617
Files:
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpStack.cpp
clang/lib/AST/Interp/InterpStack.h
Index: clang/lib/AST/Interp/InterpStack.h
===================================================================
--- clang/lib/AST/Interp/InterpStack.h
+++ clang/lib/AST/Interp/InterpStack.h
@@ -64,11 +64,16 @@
/// Returns a reference to the value on the top of the stack.
template <typename T> T &peek() const {
- return *reinterpret_cast<T *>(peek(aligned_size<T>()));
+ return *reinterpret_cast<T *>(peekData(aligned_size<T>()));
+ }
+
+ template <typename T> T &peek(size_t Offset) const {
+ assert(aligned(Offset));
+ return *reinterpret_cast<T *>(peekData(Offset));
}
/// Returns a pointer to the top object.
- void *top() const { return Chunk ? peek(0) : nullptr; }
+ void *top() const { return Chunk ? peekData(0) : nullptr; }
/// Returns the size of the stack in bytes.
size_t size() const { return StackSize; }
@@ -90,7 +95,7 @@
/// Grows the stack to accommodate a value and returns a pointer to it.
void *grow(size_t Size);
/// Returns a pointer from the top of the stack.
- void *peek(size_t Size) const;
+ void *peekData(size_t Size) const;
/// Shrinks the stack.
void shrink(size_t Size);
Index: clang/lib/AST/Interp/InterpStack.cpp
===================================================================
--- clang/lib/AST/Interp/InterpStack.cpp
+++ clang/lib/AST/Interp/InterpStack.cpp
@@ -46,7 +46,7 @@
return Object;
}
-void *InterpStack::peek(size_t Size) const {
+void *InterpStack::peekData(size_t Size) const {
assert(Chunk && "Stack is empty!");
StackChunk *Ptr = Chunk;
Index: clang/lib/AST/Interp/Interp.h
===================================================================
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1499,10 +1499,11 @@
}
inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
- auto NewFrame = std::make_unique<InterpFrame>(S, Func, PC);
- Pointer ThisPtr;
if (Func->hasThisPointer()) {
- ThisPtr = NewFrame->getThis();
+ size_t ThisOffset =
+ Func->getArgSize() + (Func->hasRVO() ? primSize(PT_Ptr) : 0);
+ const Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset);
+
if (!CheckInvoke(S, PC, ThisPtr))
return false;
@@ -1513,6 +1514,7 @@
if (!CheckCallable(S, PC, Func))
return false;
+ auto NewFrame = std::make_unique<InterpFrame>(S, Func, PC);
InterpFrame *FrameBefore = S.Current;
S.Current = NewFrame.get();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142617.501502.patch
Type: text/x-patch
Size: 2424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230301/738bbd3a/attachment-0001.bin>
More information about the cfe-commits
mailing list