https://gcc.gnu.org/g:87b9661250fcf029fa5eb1c9173c56bfea5246da

commit r16-5347-g87b9661250fcf029fa5eb1c9173c56bfea5246da
Author: Lucas Ly Ba <[email protected]>
Date:   Thu Nov 6 14:57:45 2025 +0000

    gccrs: fix segfault with empty cfg attribute
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast.cc (Attribute::check_cfg_predicate): add cfg path in 
condition
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-4261.rs: New test.
    
    Signed-off-by: Lucas Ly Ba <[email protected]>

Diff:
---
 gcc/rust/ast/rust-ast.cc                 | 7 ++++---
 gcc/testsuite/rust/compile/issue-4261.rs | 3 +++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 5bced483adb4..7c6a1d215af8 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4179,10 +4179,11 @@ Attribute::check_cfg_predicate (const Session &session) 
const
 
   auto &meta_item = static_cast<AttrInputMetaItemContainer &> (*attr_input);
   if (meta_item.get_items ().empty ()
-      && string_path == Values::Attributes::CFG_ATTR)
+      && (string_path == Values::Attributes::CFG
+         || string_path == Values::Attributes::CFG_ATTR))
     {
-      rust_error_at (path.get_locus (),
-                    "malformed %<cfg_attr%> attribute input");
+      rust_error_at (path.get_locus (), "malformed %<%s%> attribute input",
+                    string_path.c_str ());
       return false;
     }
 
diff --git a/gcc/testsuite/rust/compile/issue-4261.rs 
b/gcc/testsuite/rust/compile/issue-4261.rs
new file mode 100644
index 000000000000..32beafade547
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4261.rs
@@ -0,0 +1,3 @@
+#[cfg()]
+// { dg-error "malformed .cfg. attribute input" "" { target *-*-* } .-1 }
+fn a() {}

Reply via email to