]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: FIX ICE for malformed repr attribute
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 28 Mar 2025 17:52:51 +0000 (17:52 +0000)
committerPhilip Herron <philip.herron@embecosm.com>
Fri, 28 Mar 2025 18:34:45 +0000 (18:34 +0000)
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.philip@googlemail.com>
gcc/rust/typecheck/rust-hir-type-check-base.cc
gcc/testsuite/rust/compile/issue-3614.rs [new file with mode: 0644]

index b6d2f035ad444ce5e822718d708b2c563c0fd732..f60b540cd8c100e381ed0ecd8f54e398ee6ae788 100644 (file)
@@ -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 (file)
index 0000000..350a7e4
--- /dev/null
@@ -0,0 +1,3 @@
+#[repr] // { dg-error "malformed .repr. attribute" }
+
+struct _B {}