]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE caused by TypeCheckBase::parse_repr_options
authorYap Zhi Heng <yapzhhg@gmail.com>
Tue, 24 Mar 2026 13:23:24 +0000 (21:23 +0800)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 14 Apr 2026 21:48:53 +0000 (23:48 +0200)
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 <yapzhhg@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-base.cc
gcc/testsuite/rust/compile/issue-3550.rs [new file with mode: 0644]

index 835e8ca790cc9c835d8451cfb2b318abf90cb68f..6c3cb4054b1c2a50fba49be634f6e1ed6d29dfa8 100644 (file)
@@ -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 %<repr%> attribute");
              continue;
            }
-         const auto &option = static_cast<const AST::DelimTokenTree &> (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<const AST::DelimTokenTree &> (input);
+             meta_items = option.parse_to_meta_item ();
+           }
+         else
+           { // is_meta_item is true
+             const auto &option
+               = static_cast<const AST::AttrInputMetaItemContainer &> (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 (file)
index 0000000..50b8bbd
--- /dev/null
@@ -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