From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 851453858031; Tue, 31 Jan 2023 13:16:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 851453858031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675170999; bh=+HJDPLU7jJKYsjs5FZ0xWm2zpo2PEUW7y+RI7vM7BDQ=; h=From:To:Subject:Date:From; b=CnOInjS8MgT2LcEonWRhrctptP5uoxu4v1rV5yZksv+KYV7OHP1hIf1MnaqifVZpL wm/AwT104InYz2DNtKXgg7w+xpMQAUThuQc2HZtAabtvVXCzXYqetvb5O1/jYTg1Fw QxhwaMyyme2XKHTxfZLbSWeR/RqEOYS2Gx4oQiz0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5562] gccrs: module lowering: Do not append null pointers as items X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/master X-Git-Oldrev: 739d0509ed55aa650f197618a0902c6e0553b639 X-Git-Newrev: 3736647947b6b776c6d53eddde7538394886ebec Message-Id: <20230131131639.851453858031@sourceware.org> Date: Tue, 31 Jan 2023 13:16:39 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3736647947b6b776c6d53eddde7538394886ebec commit r13-5562-g3736647947b6b776c6d53eddde7538394886ebec Author: Arthur Cohen Date: Wed Sep 14 10:23:46 2022 +0200 gccrs: 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 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. 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 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 (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 (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() {}