From: Yap Zhi Heng Date: Tue, 24 Mar 2026 13:23:24 +0000 (+0800) Subject: gccrs: Fix ICE caused by TypeCheckBase::parse_repr_options X-Git-Tag: basepoints/gcc-17~159 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff2fd8ffc28846038ea7edd424de872dbeabfd76;p=thirdparty%2Fgcc.git gccrs: Fix ICE caused by TypeCheckBase::parse_repr_options Fixes Rust-GCC/gccrs#3550. Previously parse_repr_options assumes that all attrs in its params are token trees, but it is possible that already-parsed meta items can be passed as params as well due to expansion of cfg_attr. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): Allow parsing of AttrInputMetaItemContainer. Signed-off-by: Yap Zhi Heng --- diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index 835e8ca790c..6c3cb4054b1 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -421,14 +421,27 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, location_t locus) const AST::AttrInput &input = attr.get_attr_input (); bool is_token_tree = input.get_attr_input_type () == AST::AttrInput::AttrInputType::TOKEN_TREE; - if (!is_token_tree) + bool is_meta_item = input.get_attr_input_type () + == AST::AttrInput::AttrInputType::META_ITEM; + if (!is_token_tree && !is_meta_item) { rust_error_at (attr.get_locus (), "malformed % attribute"); continue; } - const auto &option = static_cast (input); - AST::AttrInputMetaItemContainer *meta_items - = option.parse_to_meta_item (); + + const AST::AttrInputMetaItemContainer *meta_items = nullptr; + if (is_token_tree) + { + const auto &option + = static_cast (input); + meta_items = option.parse_to_meta_item (); + } + else + { // is_meta_item is true + const auto &option + = static_cast (input); + meta_items = new AST::AttrInputMetaItemContainer (option); + } if (meta_items == nullptr) { diff --git a/gcc/testsuite/rust/compile/issue-3550.rs b/gcc/testsuite/rust/compile/issue-3550.rs new file mode 100644 index 00000000000..50b8bbd4105 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3550.rs @@ -0,0 +1,7 @@ +#![feature(no_core)] +#![no_core] + +#[cfg_attr(not(wrong = "32"), repr(i32))] +enum Eu64 { + Au64 = 0, +} \ No newline at end of file