From patchwork Tue Jan 31 13:26:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 50928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2813280wrn; Tue, 31 Jan 2023 07:26:07 -0800 (PST) X-Google-Smtp-Source: AK7set8aJXW/Y/aoSArrUZrVIheBAobju4GCfOIR6r1ZdDX8gE/zHnvD3m31SRg7aKHiIwYz0kG9 X-Received: by 2002:a17:906:1913:b0:888:7ac8:c416 with SMTP id a19-20020a170906191300b008887ac8c416mr7970546eje.35.1675178767068; Tue, 31 Jan 2023 07:26:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675178767; cv=none; d=google.com; s=arc-20160816; b=TvNZqdrFsZamsfP+Bv6YAIGMBnwDGhjbr08M/mRNDEwV9xcCY0wNbgE+nkVm9TKhz6 jjVXHNDha8fFwKvsun1C1/YOf9K1V2lIgnzNF4PeQv8vQmAxHLSRTDC9fs2DjWR10fvv pEV3evC2LWW3jVjKJdYDTEz0tdmc3pL/kZ/nvlyYbd/CPhLL8gHq8vvu/SFWI2nG0aRB TtGik0KrAVucOFiLUhGhD+C/QdiTO0o4VPgFnMynj4vyG7Q2pfXoQRLijvBarrrpUrD0 BA6uARhwGFVqoZFFNxJGRELWjFuihw3yuWw83O6tfyPIi3Q75cb7JHjE8ihB6G4+jLsS C93Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=v/VdTPx3r20svo2AHvibauqJtMKfXuDvZZGm141XdYg=; b=ocC3OcFTcMmywrQdtTTKZz5iLJYwl4y6xKsr6b9/mPDav0F718GeZIHNPdbkUIxwYe 1vXR+XlJJaDCO/b+GcXIiCv1J4Ugdi6Z1QyMrZFnZ4BcIiJpkWqsk4Ra2fAFGRQ41Z3H DGRs1Dixeu6MbqbpmO46HqdNBysIpi5zG7RpkOrXhEaop1/JnKpgqLN4AwY4y02PBev+ 5JxzCmxVgXx+XlcFPjY/ZMr+/40H4jEYsjaBr5GOVVVDoAmPRtHKroUISjHMGraF7YGC r6cEa/PhtcHshR3K2r14Tdl3pQM4siIZnNtUIRbvseUsqGQxf4yzYaJdHT70TFH8JeX3 nCBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=caW157AE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fb17-20020a1709073a1100b0088d52f894c1si46744ejc.861.2023.01.31.07.26.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 07:26:07 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=caW157AE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 010EF384232C for ; Tue, 31 Jan 2023 13:26:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 68D9C38493E4 for ; Tue, 31 Jan 2023 13:22:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68D9C38493E4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42e.google.com with SMTP id d14so14177466wrr.9 for ; Tue, 31 Jan 2023 05:22:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=v/VdTPx3r20svo2AHvibauqJtMKfXuDvZZGm141XdYg=; b=caW157AEhpvdEhkg/Ba1KjIoD7Kitxqw1pkD0KjYcnoElP6EzAuEb7Q5aDqtFn27kd OfIAf/r0i5xvEIdUQLUHA62t38cmfGd+ffzM1Dy6dx78MrIaMdKmAJFSM/GknobHhsZw gTcy8n8LR2rPcfjUlrOqg8UpqSPmU1v8Qcu3awXRIzJrL/aJ7CLRa9GMHKhci2kz8+8I RojEPS727uu7eJCBfSPnZL5O/QVrO8ngVJgbSl1jVn2G5SpqhF/2c3HPpmmm7Xt74wWl 1+dqgO9EU04+SfVo6cTLb0yVBLMZ7GFau3P1Qz2LvsKWVV4D3OPKmx7zZnYFTnQGbrnp /EDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v/VdTPx3r20svo2AHvibauqJtMKfXuDvZZGm141XdYg=; b=nlmTYAw5gDSfqF/57Cm3Pz64QjgtznjcGjd00gfKgA0SKRAiCWsavBbVAOTEaKvEZy zrP1hehQwcGTBWxaUfTAksOOHSqLwS9jL1wF2RpMXHcGvVWy1pXeaU9P3h0boCfhRN6d DKeyOzox1py+U8lvzP64jMKqfGnnnoAVdfmDdgc28xuXpIEYqWznJ8+LST1w3KNWRdvQ 8cSpgq8KJbyUSkgyBuWCQHC0PljcjokIZD+63V4OKO/kjx7zdK7UFORrMKAcvhHwnBqI uwz0YNqGzBeTvC814nZx0DTkq0P58qi+9nI+0mQR0BfRgH5fuyOps2gxv0h3SQ1oQQiy CsHQ== X-Gm-Message-State: AO0yUKXJEVq6W6b+zGwu0gHpJ0qK3e2BmYU3ORr87vUrMgV+zPOu47yB /5yGozB7W1oUMNcIQXVsBNu6NC7FVQ+XzAkFSw== X-Received: by 2002:adf:f14b:0:b0:2bf:e552:6b0 with SMTP id y11-20020adff14b000000b002bfe55206b0mr9785649wro.36.1675171355771; Tue, 31 Jan 2023 05:22:35 -0800 (PST) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.gmail.com with ESMTPSA id m15-20020a056000024f00b002bfae16ee2fsm15274988wrz.111.2023.01.31.05.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:22:35 -0800 (PST) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED] gccrs: module lowering: Do not append null pointers as items Date: Tue, 31 Jan 2023 14:26:20 +0100 Message-Id: <20230131132620.663213-1-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756552250886944238?= X-GMAIL-MSGID: =?utf-8?q?1756552250886944238?= 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 (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() {}