[clang] c442912 - [clang][Interp][NFC] Add type checks to InterpStack::peek()
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 30 02:03:14 PDT 2023
Author: Timm Bäder
Date: 2023-06-30T11:02:25+02:00
New Revision: c442912d736946703b8a9278cb2e323c51dbefcb
URL: https://github.com/llvm/llvm-project/commit/c442912d736946703b8a9278cb2e323c51dbefcb
DIFF: https://github.com/llvm/llvm-project/commit/c442912d736946703b8a9278cb2e323c51dbefcb.diff
LOG: [clang][Interp][NFC] Add type checks to InterpStack::peek()
Added:
Modified:
clang/lib/AST/Interp/InterpStack.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/InterpStack.h b/clang/lib/AST/Interp/InterpStack.h
index 435120d0e44140..fa2f9d5b242de9 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -44,7 +44,7 @@ class InterpStack final {
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 @@ class InterpStack final {
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 @@ class InterpStack final {
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.
More information about the cfe-commits
mailing list