From 9449c935b39d963f62be2a41df91671fc163685b Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 3 Feb 2025 15:14:01 +0000 Subject: 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 --- gcc/rust/typecheck/rust-tyty.cc | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 116c1ab..193217b 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 % lang item"); + return; + } + if (!fn_once_output_lookup) + { + rust_fatal_error (UNKNOWN_LOCATION, + "Missing required % 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 (); -- cgit v1.1