From: Pierre-Emmanuel Patry <[email protected]>

This attribute shall be accepted/rejected depending on the feature
activation status.

gcc/rust/ChangeLog:

        * checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit):
        Rework visit to avoid multiple iterations. Add check for
        "compiler_builtins" attribute.
        (FeatureGate::check_no_core_attribute): Remove loop.
        * checks/errors/feature/rust-feature-gate.h: Update function prototype.
        * util/rust-attribute-values.h: Add "compiler_builtins" attribute
        value.
        * util/rust-attributes.cc: Add "compiler_builtins" to the list of
        builtin attributes.

gcc/testsuite/ChangeLog:

        * rust/compile/compiler_builtins_gate.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/2ab0ae2496f87eb3b09af94e944a464e1c3cf083

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4488

 .../errors/feature/rust-feature-gate.cc       | 24 ++++++++++++-------
 .../checks/errors/feature/rust-feature-gate.h |  2 +-
 gcc/rust/util/rust-attribute-values.h         |  2 ++
 gcc/rust/util/rust-attributes.cc              |  1 +
 .../rust/compile/compiler_builtins_gate.rs    |  3 +++
 5 files changed, 22 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/compiler_builtins_gate.rs

diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc 
b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
index 7e2105977..8c6d5ba2f 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
@@ -63,7 +63,17 @@ FeatureGate::visit (AST::Crate &crate)
       rust_error_at (locus, ErrorCode::E0635, "unknown feature %qs",
                     feature.c_str ());
     }
-  check_no_core_attribute (crate.inner_attrs);
+  for (const auto &attribute : crate.inner_attrs)
+    {
+      check_no_core_attribute (attribute);
+
+      if (attribute.get_path ().as_string ()
+         == Values::Attributes::COMPILER_BUILTINS)
+       gate (Feature::Name::COMPILER_BUILTINS, attribute.get_locus (),
+             "the #[compiler_builtins] attribute is used to identify the "
+             "compiler_builtins crate which contains compiler-rt intrinsics "
+             "and will never be stable");
+    }
 }
 
 void
@@ -110,15 +120,11 @@ FeatureGate::visit (AST::ExternBlock &block)
 }
 
 void
-FeatureGate::check_no_core_attribute (
-  const std::vector<AST::Attribute> &attributes)
+FeatureGate::check_no_core_attribute (const AST::Attribute &attribute)
 {
-  for (const AST::Attribute &attr : attributes)
-    {
-      if (attr.get_path ().as_string () == Values::Attributes::NO_CORE)
-       gate (Feature::Name::NO_CORE, attr.get_locus (),
-             "no_core is experimental");
-    }
+  if (attribute.get_path ().as_string () == Values::Attributes::NO_CORE)
+    gate (Feature::Name::NO_CORE, attribute.get_locus (),
+         "no_core is experimental");
 }
 
 void
diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.h 
b/gcc/rust/checks/errors/feature/rust-feature-gate.h
index 0675777e0..e8bb61b1f 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.h
@@ -54,7 +54,7 @@ public:
 
 private:
   void gate (Feature::Name name, location_t loc, const std::string &error_msg);
-  void check_no_core_attribute (const std::vector<AST::Attribute> &attributes);
+  void check_no_core_attribute (const AST::Attribute &attribute);
   void check_rustc_attri (const std::vector<AST::Attribute> &attributes);
   void
   check_may_dangle_attribute (const std::vector<AST::Attribute> &attributes);
diff --git a/gcc/rust/util/rust-attribute-values.h 
b/gcc/rust/util/rust-attribute-values.h
index 7f0b5ca78..7743d9091 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -82,6 +82,8 @@ public:
   static constexpr auto &RUSTC_LAYOUT_SCALAR_VALID_RANGE_START
     = "rustc_layout_scalar_valid_range_start";
 
+  static constexpr auto &COMPILER_BUILTINS = "compiler_builtins";
+
   static constexpr auto &MAY_DANGLE = "may_dangle";
   static constexpr auto &PRELUDE_IMPORT = "prelude_import";
   static constexpr auto &TRACK_CALLER = "track_caller";
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 93d71a490..cc898971e 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -122,6 +122,7 @@ static const BuiltinAttrDefinition __definitions[]
      {Attrs::RUSTC_LAYOUT_SCALAR_VALID_RANGE_START, CODE_GENERATION},
      // TODO: be careful about calling functions marked with this?
      {Attrs::RUSTC_ARGS_REQUIRED_CONST, CODE_GENERATION},
+     {Attrs::COMPILER_BUILTINS, CODE_GENERATION},
      {Attrs::PRELUDE_IMPORT, NAME_RESOLUTION},
      {Attrs::RUSTC_DIAGNOSTIC_ITEM, STATIC_ANALYSIS},
      {Attrs::RUSTC_ON_UNIMPLEMENTED, STATIC_ANALYSIS},
diff --git a/gcc/testsuite/rust/compile/compiler_builtins_gate.rs 
b/gcc/testsuite/rust/compile/compiler_builtins_gate.rs
new file mode 100644
index 000000000..3417be025
--- /dev/null
+++ b/gcc/testsuite/rust/compile/compiler_builtins_gate.rs
@@ -0,0 +1,3 @@
+#![feature(no_core)]
+#![no_core]
+#![compiler_builtins] // { dg-error "the ..compiler_builtins. attribute is 
used to identify the compiler_builtins" }

base-commit: 2889c50e2031a865b5704ef60f3463d0f8b05c31
-- 
2.53.0

Reply via email to