public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Add an assertion to avoid peeking when the stack is empty
@ 2022-06-08 12:40 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:40 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7fe6bc1ba1a8d296262e1e06ac067190c8ab3ebb

commit 7fe6bc1ba1a8d296262e1e06ac067190c8ab3ebb
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Thu Apr 28 14:42:15 2022 +0100

    Add an assertion to avoid peeking when the stack is empty

Diff:
---
 gcc/rust/backend/rust-compile-context.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index de9d03f6d9d..d17034b51df 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); }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:40 [gcc/devel/rust/master] Add an assertion to avoid peeking when the stack is empty Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).