aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-macro-expand.h
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-05-10 15:10:59 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2022-05-10 15:15:21 +0200
commit2959ff8e7dd8b06bee76636af84c5aee06971397 (patch)
tree947ce9f45a069b8c0c6e844bcd5bec51311d0d9b /gcc/rust/expand/rust-macro-expand.h
parent140f6a698b4d7157e6a33cd7b41c27b39ecbf76e (diff)
downloadgcc-2959ff8e7dd8b06bee76636af84c5aee06971397.zip
gcc-2959ff8e7dd8b06bee76636af84c5aee06971397.tar.gz
gcc-2959ff8e7dd8b06bee76636af84c5aee06971397.tar.bz2
macro: Add assertion to avoid undefined behavior
This also fixes the undefined behavior. Once again we are hurt by `std::vector<T>::back()` returning references and not pointers/`std::optional<T>`s! The cause of the bug was some overzealous popping from the context vector in block expressions. The amount of calls to `pop_context` is now the same as the amount of calls to `push_context`
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.h')
-rw-r--r--gcc/rust/expand/rust-macro-expand.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h
index 3c53d8d..a582524 100644
--- a/gcc/rust/expand/rust-macro-expand.h
+++ b/gcc/rust/expand/rust-macro-expand.h
@@ -275,8 +275,11 @@ struct MacroExpander
ContextType pop_context ()
{
+ rust_assert (!context.empty ());
+
ContextType t = context.back ();
context.pop_back ();
+
return t;
}