From: Arthur Cohen <arthur.cohen@embecosm.com>
To: gcc-patches@gcc.gnu.org
Cc: gcc-rust@gcc.gnu.org, Arthur Cohen <arthur.cohen@embecosm.com>
Subject: [COMMITTED] gccrs: module lowering: Do not append null pointers as items
Date: Tue, 31 Jan 2023 14:26:20 +0100 [thread overview]
Message-ID: <20230131132620.663213-1-arthur.cohen@embecosm.com> (raw)
Some module items do not need to get lowered to HIR such as `macro_rules!` definitions. Hence, module lowering should act the same as crate lowering: Only emplace back the lowered item if it is a valid pointer
gcc/rust/ChangeLog:
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Do not lower
null items within modules.
gcc/testsuite/ChangeLog:
* rust/compile/macro44.rs: New test.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/rust/hir/rust-ast-lower-item.cc | 5 +++-
gcc/testsuite/rust/compile/macro44.rs | 34 +++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/rust/compile/macro44.rs
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc
index 8aec68d9458..411cc4be855 100644
--- a/gcc/rust/hir/rust-ast-lower-item.cc
+++ b/gcc/rust/hir/rust-ast-lower-item.cc
@@ -59,7 +59,10 @@ ASTLoweringItem::visit (AST::Module &module)
for (auto &item : module.get_items ())
{
auto transitem = translate (item.get ());
- items.push_back (std::unique_ptr<Item> (transitem));
+ // The item may be null if it doesn't need to live in the HIR - for
+ // example, macro rules definitions
+ if (transitem)
+ items.push_back (std::unique_ptr<Item> (transitem));
}
// should be lowered/copied from module.get_in/outer_attrs()
diff --git a/gcc/testsuite/rust/compile/macro44.rs b/gcc/testsuite/rust/compile/macro44.rs
new file mode 100644
index 00000000000..84b2cdbb506
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macro44.rs
@@ -0,0 +1,34 @@
+mod foo {
+ mod bar {
+ mod baz {
+ macro_rules! baz {
+ () => {{}};
+ }
+ }
+ }
+
+ macro_rules! foo {
+ () => {{}};
+ }
+
+ fn foo_f() { // { dg-warning "function is never used" }
+ foo!();
+ }
+
+ fn bar_f() { // { dg-warning "function is never used" }
+ baz!();
+ }
+}
+
+mod foo2 {
+ #[macro_export]
+ macro_rules! bar1 {
+ () => {};
+ }
+
+ macro_rules! bar2 {
+ () => {};
+ }
+}
+
+fn main() {}
--
2.39.1
reply other threads:[~2023-01-31 13:22 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=20230131132620.663213-1-arthur.cohen@embecosm.com \
--to=arthur.cohen@embecosm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gcc-rust@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: link
Be 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).