public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] const-checker: Add `is_const_extern_fn` helper function Date: Tue, 9 Aug 2022 20:39:30 +0000 (GMT) [thread overview] Message-ID: <20220809203930.61057385AC3C@sourceware.org> (raw) 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
reply other threads:[~2022-08-09 20:39 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220809203930.61057385AC3C@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).