https://gcc.gnu.org/g:ea833107f96d51550f04e639edf3e728b0e7ff6f

commit r16-4894-gea833107f96d51550f04e639edf3e728b0e7ff6f
Author: Yap Zhi Heng <[email protected]>
Date:   Sat Oct 18 12:42:32 2025 +0800

    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 <[email protected]>

Diff:
---
 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(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index cdbaa69cd776..f87872029021 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 %<repr%> 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 %<repr%> attribute");
+             continue;
+           }
          const auto &option = static_cast<const AST::DelimTokenTree &> (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 000000000000..4629baa93d5d
--- /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
+}

Reply via email to