diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-02-03 15:14:01 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-24 13:07:01 +0100 |
commit | 0eddc297f03ae2a0830ad444f1f4d2a4264f5ad7 (patch) | |
tree | 0ad4b48a9345e04edd82f87c040c2f0682064f49 /gcc | |
parent | 60aeb7629596f6927c95614d285f75d24b39255c (diff) | |
download | gcc-0eddc297f03ae2a0830ad444f1f4d2a4264f5ad7.zip gcc-0eddc297f03ae2a0830ad444f1f4d2a4264f5ad7.tar.gz gcc-0eddc297f03ae2a0830ad444f1f4d2a4264f5ad7.tar.bz2 |
gccrs: Fix ICE when fn_once and fn_once_output lang item is not defined
We needed to check for the optional has a value here or not it leads to an
ICE.
gcc/rust/ChangeLog:
* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): add checks for lang items
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index f0c967e..02d91b1 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -2226,12 +2226,24 @@ void ClosureType::setup_fn_once_output () const { // lookup the lang items - auto fn_once_lang_item = LangItem::Kind::FN_ONCE; - auto fn_once_output_lang_item = LangItem::Kind::FN_ONCE_OUTPUT; + auto fn_once_lookup = mappings.lookup_lang_item (LangItem::Kind::FN_ONCE); + auto fn_once_output_lookup + = mappings.lookup_lang_item (LangItem::Kind::FN_ONCE_OUTPUT); + if (!fn_once_lookup) + { + rust_fatal_error (UNKNOWN_LOCATION, + "Missing required %<fn_once%> lang item"); + return; + } + if (!fn_once_output_lookup) + { + rust_fatal_error (UNKNOWN_LOCATION, + "Missing required %<fn_once_ouput%> lang item"); + return; + } - DefId &trait_id = mappings.lookup_lang_item (fn_once_lang_item).value (); - DefId &trait_item_id - = mappings.lookup_lang_item (fn_once_output_lang_item).value (); + DefId &trait_id = fn_once_lookup.value (); + DefId &trait_item_id = fn_once_output_lookup.value (); // resolve to the trait HIR::Item *item = mappings.lookup_defid (trait_id).value (); |