diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-08-03 17:24:14 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:00:29 +0100 |
commit | 1e288d66cb4f0a25a249c0c6dacc2efbf9e44dc8 (patch) | |
tree | 8a8c17589d63dea70c4f6cc2143b9026cda8ee41 /gcc/rust/rust-session-manager.cc | |
parent | fa6bba6f220882a29b7a9e020c49043a3a7e869b (diff) | |
download | gcc-1e288d66cb4f0a25a249c0c6dacc2efbf9e44dc8.zip gcc-1e288d66cb4f0a25a249c0c6dacc2efbf9e44dc8.tar.gz gcc-1e288d66cb4f0a25a249c0c6dacc2efbf9e44dc8.tar.bz2 |
gccrs: macro-expand: Keep optional references to last_{def, invoc}
This avoids a use-after-free when reaching the recursion limit.
gcc/rust/ChangeLog:
* expand/rust-macro-expand.h: Keep optional references for last_def
and last_invoc.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Store
optional references.
* rust-session-manager.cc (Session::expansion): Use tl::optional's APIs
for better checking.
Diffstat (limited to 'gcc/rust/rust-session-manager.cc')
-rw-r--r-- | gcc/rust/rust-session-manager.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 55f6ec5..bb6cf4c 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -898,10 +898,10 @@ Session::expansion (AST::Crate &crate) if (iterations == cfg.recursion_limit) { - auto last_invoc = expander.get_last_invocation (); - auto last_def = expander.get_last_definition (); + auto &last_invoc = expander.get_last_invocation (); + auto &last_def = expander.get_last_definition (); - rust_assert (last_def && last_invoc); + rust_assert (last_def.has_value () && last_invoc.has_value ()); rich_location range (line_table, last_invoc->get_locus ()); range.add_range (last_def->get_locus ()); |