]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix segfault with empty cfg attribute
authorLucas Ly Ba <lucas.ly-ba@outlook.com>
Thu, 6 Nov 2025 14:57:45 +0000 (14:57 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Nov 2025 14:58:18 +0000 (15:58 +0100)
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 <lucas.ly-ba@outlook.com>
gcc/rust/ast/rust-ast.cc
gcc/testsuite/rust/compile/issue-4261.rs [new file with mode: 0644]

index 5bced483adb47a8a0e0c7259ab397bc7a8442650..7c6a1d215af8e91b309160743f451cc4b3bd35c1 100644 (file)
@@ -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 (file)
index 0000000..32beafa
--- /dev/null
@@ -0,0 +1,3 @@
+#[cfg()]
+// { dg-error "malformed .cfg. attribute input" "" { target *-*-* } .-1 }
+fn a() {}