diff --git a/clang/lib/AST/Interp/InterpStack.h b/clang/lib/AST/Interp/InterpStack.h index 435120d0e4414..fa2f9d5b242de 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()); ItemTypes.pop_back(); #endif - auto *Ptr = &peek(); + auto *Ptr = &peekInternal(); auto Value = std::move(*Ptr); Ptr->~T(); shrink(aligned_size()); @@ -57,14 +57,18 @@ class InterpStack final { assert(ItemTypes.back() == toPrimType()); ItemTypes.pop_back(); #endif - auto *Ptr = &peek(); + auto *Ptr = &peekInternal(); Ptr->~T(); shrink(aligned_size()); } /// Returns a reference to the value on the top of the stack. template T &peek() const { - return *reinterpret_cast(peekData(aligned_size())); +#ifndef NDEBUG + assert(!ItemTypes.empty()); + assert(ItemTypes.back() == toPrimType()); +#endif + return peekInternal(); } template 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 T &peekInternal() const { + return *reinterpret_cast(peekData(aligned_size())); + } + /// 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.