From ea833107f96d51550f04e639edf3e728b0e7ff6f Mon Sep 17 00:00:00 2001 From: Yap Zhi Heng Date: Sat, 18 Oct 2025 12:42:32 +0800 Subject: [PATCH] gccrs: Fix ICE for repr attribute malformation gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (parse_repr_options): Changed TOKEN_TREE assert into error, update malformed repr attribute error message to be inline with other attribute error messages. Signed-off-by: Yap Zhi Heng --- gcc/rust/typecheck/rust-hir-type-check-base.cc | 8 ++++++-- gcc/testsuite/rust/compile/issue-4231.rs | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-4231.rs diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index cdbaa69cd77..f8787202902 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -412,7 +412,7 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, location_t locus) bool is_repr = attr.get_path ().as_string () == Values::Attributes::REPR; if (is_repr && !attr.has_attr_input ()) { - rust_error_at (attr.get_locus (), "malformed %qs attribute", "repr"); + rust_error_at (attr.get_locus (), "malformed % attribute"); continue; } @@ -421,7 +421,11 @@ 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; - rust_assert (is_token_tree); + if (!is_token_tree) + { + rust_error_at (attr.get_locus (), "malformed % attribute"); + continue; + } const auto &option = static_cast (input); AST::AttrInputMetaItemContainer *meta_items = option.parse_to_meta_item (); diff --git a/gcc/testsuite/rust/compile/issue-4231.rs b/gcc/testsuite/rust/compile/issue-4231.rs new file mode 100644 index 00000000000..4629baa93d5 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4231.rs @@ -0,0 +1,6 @@ +#[repr = ""] // { dg-error "malformed .repr. attribute" } +struct ThreeInts { + first: i16, + second: i8, + third: i32 +} -- 2.47.3