Skip to content

Commit 7fe6bc1

Browse files
committed
Add an assertion to avoid peeking when the stack is empty
1 parent 1ada076 commit 7fe6bc1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

gcc/rust/backend/rust-compile-context.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ class Context
254254
bool in_fn () { return fn_stack.size () != 0; }
255255

256256
// Note: it is undefined behavior to call peek_fn () if fn_stack is empty.
257-
fncontext peek_fn () { return fn_stack.back (); }
257+
fncontext peek_fn ()
258+
{
259+
rust_assert (!fn_stack.empty ());
260+
return fn_stack.back ();
261+
}
258262

259263
void push_type (tree t) { type_decls.push_back (t); }
260264
void push_var (::Bvariable *v) { var_decls.push_back (v); }

0 commit comments

Comments
 (0)