public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] const-checker: Add `is_const_extern_fn` helper function
@ 2022-08-09 20:39 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-08-09 20:39 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4ffd884a69396d828049d4a14d17e6d3f6c8d61f
commit 4ffd884a69396d828049d4a14d17e6d3f6c8d61f
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Tue Aug 9 09:37:41 2022 +0200
const-checker: Add `is_const_extern_fn` helper function
Co-authored-by: philberty <philip.herron@embecosm.com>
Diff:
---
gcc/rust/checks/errors/rust-const-checker.cc | 27 ++++++++++++++++-----------
gcc/rust/checks/errors/rust-const-checker.h | 7 +++++++
2 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc
index bd4c7f19906..ad0a2cfc5c5 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -37,6 +37,21 @@ ConstChecker::go (HIR::Crate &crate)
item->accept_vis (*this);
}
+bool
+ConstChecker::is_const_extern_fn (HIR::ExternalFunctionItem &fn)
+{
+ // FIXME: Is it really how we want to handle `rustc_const_stable`
+ // and `rustc_const_unstable`?
+ // TODO: Add these attributes to the attribute check and handle
+ // `stable` and `unstable` as well
+ return std::any_of (
+ fn.get_outer_attrs ().begin (), fn.get_outer_attrs ().end (),
+ [] (const AST::Attribute &attr) {
+ // `starts_with` in C++11...
+ return attr.get_path ().as_string ().rfind ("rustc_const_", 0) == 0;
+ });
+}
+
void
ConstChecker::visit (IdentifierExpr &ident_expr)
{}
@@ -261,17 +276,7 @@ ConstChecker::check_function_call (HirId fn_id, Location locus)
{
{
auto fn = static_cast<ExternalFunctionItem *> (maybe_extern_item);
- auto is_const_extern = std::any_of (
- fn->get_outer_attrs ().begin (), fn->get_outer_attrs ().end (),
- [] (const AST::Attribute &attr) {
- // `starts_with` in C++11...
- // FIXME: Is it really how we want to handle `rustc_const_stable`
- // and `rustc_const_unstable`?
- // TODO: Add these attributes to the attribute check and handle
- // `stable` and `unstable` as well
- return attr.get_path ().as_string ().rfind ("rustc_const_", 0) == 0;
- });
- if (!is_const_extern)
+ if (!is_const_extern_fn (*fn))
is_error = true;
}
}
diff --git a/gcc/rust/checks/errors/rust-const-checker.h b/gcc/rust/checks/errors/rust-const-checker.h
index a474fc83d10..608ea3e0750 100644
--- a/gcc/rust/checks/errors/rust-const-checker.h
+++ b/gcc/rust/checks/errors/rust-const-checker.h
@@ -33,6 +33,13 @@ public:
void go (HIR::Crate &crate);
+ /**
+ * Check if an item is a const extern item or not
+ * TODO: Move this to a const compilation context class or an attribute
+ * checking class
+ */
+ static bool is_const_extern_fn (HIR::ExternalFunctionItem &fn);
+
private:
/**
* Check that only const functions are called in const contexts
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-09 20:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-09 20:39 [gcc/devel/rust/master] const-checker: Add `is_const_extern_fn` helper function Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).