[clang][Interp][NFC] Add type checks to InterpStack::peek()
diff --git a/clang/lib/AST/Interp/InterpStack.h b/clang/lib/AST/Interp/InterpStack.h
index 435120d..fa2f9d5 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -44,7 +44,7 @@
assert(ItemTypes.back() == toPrimType<T>());
ItemTypes.pop_back();
#endif
- auto *Ptr = &peek<T>();
+ auto *Ptr = &peekInternal<T>();
auto Value = std::move(*Ptr);
Ptr->~T();
shrink(aligned_size<T>());
@@ -57,14 +57,18 @@
assert(ItemTypes.back() == toPrimType<T>());
ItemTypes.pop_back();
#endif
- auto *Ptr = &peek<T>();
+ auto *Ptr = &peekInternal<T>();
Ptr->~T();
shrink(aligned_size<T>());
}
/// Returns a reference to the value on the top of the stack.
template <typename T> T &peek() const {
- return *reinterpret_cast<T *>(peekData(aligned_size<T>()));
+#ifndef NDEBUG
+ assert(!ItemTypes.empty());
+ assert(ItemTypes.back() == toPrimType<T>());
+#endif
+ return peekInternal<T>();
}
template <typename T> T &peek(size_t Offset) const {
@@ -92,6 +96,11 @@
return ((sizeof(T) + PtrAlign - 1) / PtrAlign) * PtrAlign;
}
+ /// Like the public peek(), but without the debug type checks.
+ template <typename T> T &peekInternal() const {
+ return *reinterpret_cast<T *>(peekData(aligned_size<T>()));
+ }
+
/// 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.