]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix cfg attribute without parentheses error
authorLucas Ly Ba <lucas.ly-ba@outlook.com>
Thu, 6 Nov 2025 15:37:52 +0000 (15:37 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 25 Nov 2025 22:00:51 +0000 (23:00 +0100)
gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::check_cfg_predicate): Make error when attribute has no input.

gcc/testsuite/ChangeLog:

* rust/compile/issue-4262.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-4262.rs [new file with mode: 0644]

index f3ad2fe5da05fa4d588914c1a3e361bb579b6e6b..d8713071c4c3d8c7d29d1403555724583393a7e6 100644 (file)
@@ -4163,16 +4163,10 @@ Attribute::check_cfg_predicate (const Session &session) const
   auto string_path = path.as_string ();
   /* assume that cfg predicate actually can exist, i.e. attribute has cfg or
    * cfg_attr path */
-  if (!has_attr_input ()
-      || (string_path != Values::Attributes::CFG
-         && string_path != Values::Attributes::CFG_ATTR))
+  if (!has_attr_input ())
     {
-      // DEBUG message
-      rust_debug (
-       "tried to check cfg predicate on attr that either has no input "
-       "or invalid path. attr: '%s'",
-       as_string ().c_str ());
-
+      rust_error_at (path.get_locus (), "%qs is not followed by parentheses",
+                    string_path.c_str ());
       return false;
     }
 
@@ -4181,9 +4175,7 @@ Attribute::check_cfg_predicate (const Session &session) const
     return false;
 
   auto &meta_item = static_cast<AttrInputMetaItemContainer &> (*attr_input);
-  if (meta_item.get_items ().empty ()
-      && (string_path == Values::Attributes::CFG
-         || string_path == Values::Attributes::CFG_ATTR))
+  if (meta_item.get_items ().empty ())
     {
       rust_error_at (path.get_locus (), "malformed %<%s%> attribute input",
                     string_path.c_str ());
diff --git a/gcc/testsuite/rust/compile/issue-4262.rs b/gcc/testsuite/rust/compile/issue-4262.rs
new file mode 100644 (file)
index 0000000..2ce1cb4
--- /dev/null
@@ -0,0 +1,3 @@
+#[cfg]
+// { dg-error ".cfg. is not followed by parentheses" "" { target *-*-* } .-1 }
+fn a() {}