https://gcc.gnu.org/g:5d6467f637273418535316b051491e0ad594a194

commit r15-9105-g5d6467f637273418535316b051491e0ad594a194
Author: Philip Herron <herron.phi...@googlemail.com>
Date:   Fri Mar 28 17:52:51 2025 +0000

    gccrs: FIX ICE for malformed repr attribute
    
    Fixes Rust-GCC#3614
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-type-check-base.cc 
(TypeCheckBase::parse_repr_options): check for input
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-3614.rs: New test.
    
    Signed-off-by: Philip Herron <herron.phi...@googlemail.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-base.cc | 6 ++++++
 gcc/testsuite/rust/compile/issue-3614.rs       | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 8f2471d54d55..7fc6467e8aee 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -305,6 +305,12 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec 
&attrs, location_t locus)
   for (const auto &attr : attrs)
     {
       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");
+         continue;
+       }
+
       if (is_repr)
        {
          const AST::AttrInput &input = attr.get_attr_input ();
diff --git a/gcc/testsuite/rust/compile/issue-3614.rs 
b/gcc/testsuite/rust/compile/issue-3614.rs
new file mode 100644
index 000000000000..350a7e43ba8e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3614.rs
@@ -0,0 +1,3 @@
+#[repr] // { dg-error "malformed .repr. attribute" }
+
+struct _B {}

Reply via email to