]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE for repr attribute malformation
authorYap Zhi Heng <yapzhhg@gmail.com>
Sat, 18 Oct 2025 04:42:32 +0000 (12:42 +0800)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 20:30:58 +0000 (21:30 +0100)
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 <yapzhhg@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-base.cc
gcc/testsuite/rust/compile/issue-4231.rs [new file with mode: 0644]

index cdbaa69cd776c05cff7fd72f62ac806fdb491040..f87872029021c16e87419215a3b9472d201849e2 100644 (file)
@@ -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 (file)
index 0000000..4629baa
--- /dev/null
@@ -0,0 +1,6 @@
+#[repr = ""] // { dg-error "malformed .repr. attribute" }
+struct ThreeInts {
+    first: i16,
+    second: i8,
+    third: i32
+}