[gccrs COMMIT] gccrs: Fix ICE caused by TypeCheckBase::parse_repr_options

gerris.rs@gmail.com gerris.rs@gmail.com
Tue Mar 31 10:40:50 GMT 2026


From: Yap Zhi Heng <yapzhhg@gmail.com>

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>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: https://github.com/Rust-GCC/gccrs/commit/7c402e98b69f2eccc47365cbcec4384c9dff27b3

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4500

 .../typecheck/rust-hir-type-check-base.cc     | 21 +++++++++++++++----
 gcc/testsuite/rust/compile/issue-3550.rs      |  7 +++++++
 2 files changed, 24 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-3550.rs

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 835e8ca79..6c3cb4054 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 %<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
index 000000000..50b8bbd41
--- /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

base-commit: 1dd416791aafc60d40feae798945ab67775d34ab
-- 
2.53.0



More information about the Gcc-rust mailing list