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]>
---
.../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 7e21059776b..8c6d5ba2f56 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 0675777e0f5..e8bb61b1f61 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 7f0b5ca7866..7743d9091c8 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 93d71a490d2..cc898971eb9 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 00000000000..3417be025d8
--- /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" }
--
2.50.1