diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-04-28 14:42:15 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-04-28 14:43:08 +0100 |
commit | 7fe6bc1ba1a8d296262e1e06ac067190c8ab3ebb (patch) | |
tree | c50e88cbab503b66d537b7450f9dde9d69a6ace3 /gcc | |
parent | 1ada076b9324982fd6f49aea6456e99613e394a8 (diff) | |
download | gcc-7fe6bc1ba1a8d296262e1e06ac067190c8ab3ebb.zip gcc-7fe6bc1ba1a8d296262e1e06ac067190c8ab3ebb.tar.gz gcc-7fe6bc1ba1a8d296262e1e06ac067190c8ab3ebb.tar.bz2 |
Add an assertion to avoid peeking when the stack is empty
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index de9d03f..d17034b 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -254,7 +254,11 @@ public: bool in_fn () { return fn_stack.size () != 0; } // Note: it is undefined behavior to call peek_fn () if fn_stack is empty. - fncontext peek_fn () { return fn_stack.back (); } + fncontext peek_fn () + { + rust_assert (!fn_stack.empty ()); + return fn_stack.back (); + } void push_type (tree t) { type_decls.push_back (t); } void push_var (::Bvariable *v) { var_decls.push_back (v); } |