public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] module lowering: Do not append null pointers as items
@ 2022-09-26 11:04 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-09-26 11:04 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d4da06f721577d3eaf2e21d6c6735d32a69d6ac7
commit d4da06f721577d3eaf2e21d6c6735d32a69d6ac7
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Wed Sep 14 10:23:46 2022 +0200
module lowering: Do not append null pointers as items
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
Diff:
---
gcc/rust/hir/rust-ast-lower-item.cc | 5 ++++-
gcc/testsuite/rust/compile/macro44.rs | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc
index fefc938b8e5..336be5bdfaf 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() {}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-09-26 11:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 11:04 [gcc/devel/rust/master] module lowering: Do not append null pointers as items 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).