From: Enes Cevik <[email protected]>
This patch registers the 'needs_allocator' attribute, which is required
for compiling the 'alloc' crate.
Currently, it is implemented as a stub that emits a compiler warning
when encountered. The reoson for this temporary stub is that full
handling of 'needs_allocator' strictly depends on the 'global_allocator'
infrastructure and the 'core::alloc::GlobalAlloc' trait. Since gccrs
does not yet have full support for the 'core' crate, a complete
implementation is deferred.
gcc/rust/ChangeLog:
* checks/errors/rust-builtin-attribute-checker.cc
(check_inner_attribute): Add warning for needs_allocator.
* util/rust-attribute-values.h (class Attributes): Add
NEEDS_ALLOCATOR constexpr.
* util/rust-attributes.cc (__definitions): Add
BuiltinAttrDefinition for new attribute.
gcc/testsuite/ChangeLog:
* rust/compile/needs_allocator.rs: New test.
Signed-off-by: Enes Cevik <[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/770bccda8a9ebe771e6d6ecd21deff9d656433a5
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4696
gcc/rust/checks/errors/rust-builtin-attribute-checker.cc | 7 +++++++
gcc/rust/util/rust-attribute-values.h | 2 ++
gcc/rust/util/rust-attributes.cc | 1 +
gcc/testsuite/rust/compile/needs_allocator.rs | 4 ++++
4 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/needs_allocator.rs
diff --git a/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc
b/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc
index fef94f5ea..c1ab0df5e 100644
--- a/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc
+++ b/gcc/rust/checks/errors/rust-builtin-attribute-checker.cc
@@ -38,6 +38,13 @@ check_inner_attribute (const AST::Attribute &attribute)
if (Attributes::valid_outer_attribute (result.name))
rust_error_at (attribute.get_locus (),
"attribute cannot be used at crate level");
+
+ if (result.name == Values::Attributes::NEEDS_ALLOCATOR)
+ {
+ rust_warning_at (attribute.get_locus (), 0,
+ "%<#[%s]%> is not implemented yet and has no effect",
+ attribute.as_string ().c_str ());
+ }
}
/**
diff --git a/gcc/rust/util/rust-attribute-values.h
b/gcc/rust/util/rust-attribute-values.h
index 2b8853c80..4f8860747 100644
--- a/gcc/rust/util/rust-attribute-values.h
+++ b/gcc/rust/util/rust-attribute-values.h
@@ -111,6 +111,8 @@ public:
static constexpr auto &RUSTC_ARGS_REQUIRED_CONST
= "rustc_args_required_const";
+ static constexpr auto &NEEDS_ALLOCATOR = "needs_allocator";
+
static constexpr auto &RUSTC_ALLOCATOR = "rustc_allocator";
static constexpr auto &RUSTC_ALLOCATOR_NOUNWIND = "rustc_allocator_nounwind";
};
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 1b65f7729..97f9edeea 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -95,6 +95,7 @@ static const BuiltinAttrDefinition __definitions[]
{Attrs::NON_EXHAUSTIVE, TYPE_CHECK},
{Attrs::RUSTFMT, EXTERNAL},
{Attrs::TEST, CODE_GENERATION},
+ {Attrs::NEEDS_ALLOCATOR, CODE_GENERATION},
{Attrs::RUSTC_ALLOCATOR, CODE_GENERATION},
{Attrs::RUSTC_ALLOCATOR_NOUNWIND, CODE_GENERATION},
{Attrs::GLOBAL_ALLOCATOR, CODE_GENERATION}};
diff --git a/gcc/testsuite/rust/compile/needs_allocator.rs
b/gcc/testsuite/rust/compile/needs_allocator.rs
new file mode 100644
index 000000000..f39ff2187
--- /dev/null
+++ b/gcc/testsuite/rust/compile/needs_allocator.rs
@@ -0,0 +1,4 @@
+#![feature(no_core)]
+#![no_core]
+
+#![needs_allocator] // { dg-warning "...needs_allocator.. is not implemented
yet and has no effect" }
base-commit: 878be01f1008a0002dca30d8f5cbf7a85451717a
--
2.54.0