]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: respect cfg_attr expansion
authorlenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
Fri, 19 Dec 2025 12:34:45 +0000 (12:34 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 23 Dec 2025 11:16:49 +0000 (12:16 +0100)
Fix cfg_attr expansion and feature gate attribute handling

Fixes Rust-GCC#4245

gcc/rust/ChangeLog:

* checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Added
handling for META_ITEM type attributes to properly process feature gates.
* expand/rust-cfg-strip.cc (expand_cfg_attrs): Fixed a bug where
newly inserted cfg_attr attributes wheren't being reprocessed,
and cleaned up the loop increment logic.

Signed-off-by: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
gcc/rust/checks/errors/feature/rust-feature-gate.cc
gcc/rust/expand/rust-cfg-strip.cc

index 9df822b7e1c723467510867034fee2afd9b26600..e5170b77808b6cf4b773b5eca3b93ce9b994747c 100644 (file)
@@ -69,6 +69,22 @@ FeatureGate::visit (AST::Crate &crate)
                    valid_lib_features.emplace (name_str, item->get_locus ());
                }
            }
+         else if (type == AST::AttrInput::AttrInputType::META_ITEM)
+           {
+             const auto &meta_item
+               = static_cast<const AST::AttrInputMetaItemContainer &> (
+                 attr_input);
+             for (const auto &item : meta_item.get_items ())
+               {
+                 const auto &name_str = item->as_string ();
+
+                 // TODO: detect duplicates
+                 if (auto tname = Feature::as_name (name_str))
+                   valid_lang_features.insert (tname.value ());
+                 else
+                   valid_lib_features.emplace (name_str, item->get_locus ());
+               }
+           }
        }
     }
 
index 3c5e74e7aae661718880cb2710d9a2e165dc4168..e8c6c3789421691a539b6f634f392408b5927e03 100644 (file)
@@ -124,6 +124,12 @@ expand_cfg_attrs (AST::AttrVec &attrs)
              attrs.insert (attrs.begin () + i,
                            std::make_move_iterator (new_attrs.begin ()),
                            std::make_move_iterator (new_attrs.end ()));
+
+             /* Decrement i so that the for loop's i++ will bring us back to
+              * position i, allowing us to reprocess the newly inserted
+              * attribute (in case it's also a cfg_attr that needs expansion)
+              */
+             i--;
            }
 
          /* do something - if feature (first token in tree) is in fact enabled,
@@ -133,10 +139,6 @@ expand_cfg_attrs (AST::AttrVec &attrs)
           * recursive, so check for expanded attributes being recursive and
           * possibly recursively call the expand_attrs? */
        }
-      else
-       {
-         i++;
-       }
     }
   attrs.shrink_to_fit ();
 }