From patchwork Tue Feb 21 12:00:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59952 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1824228wrn; Tue, 21 Feb 2023 04:06:27 -0800 (PST) X-Google-Smtp-Source: AK7set+oR1F7coKGYqWDG6bXpgfsLAnXcx3CZPjnqQWYmOmmpzCuWCSuGLl8LCMHvChD9elUWdDn X-Received: by 2002:a05:6402:4d:b0:4ac:b32e:b6f with SMTP id f13-20020a056402004d00b004acb32e0b6fmr5834305edu.23.1676981187363; Tue, 21 Feb 2023 04:06:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981187; cv=none; d=google.com; s=arc-20160816; b=nlOBu6PxDl//glZx5+Bim4RzrCxVGfSdbQGkD18g1P6u2ll2lLj3HGMaZ+DZkKEKvl 7MWq0cHcgmHQvfAltDoJghfHyz709Rz3itp8t5tkqVj6sv1NpvD1GtdGiEZxaDpRHcUr iUyxgjuF0lcXyY91UEJCKxN68v2r3xdIvsIWzwwGEeeSR9Dt0Pm6Ou5HiGoqzVKBBgUb ON7jHPbwtTZ7eNJQhP94uhDdBiuJDxmo6BHMgg7RkewQA27p3+u8L/hK8suLKFmdr6sQ 20ZuHe3Wa0S2ZHxbI/P0MSW5Oki1ZrdHnh3+qXn8UGiC8HCWDIWTZC0Ymq+yW92N8xB6 octg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=WvIXClx801McHQjUiEmAWWq+hA6OrhKovqL7/pMpQ6Y=; b=asBR/mg7lpUry7dT6muqBw61PCOo75t/Zq8wF8Robu29raL/0nJkVObU9dv/y9oaLg wGCcoQGZ8JZZM4cbmZnRMvY+U0+rxojUW39zvQh9xUBCecrvKNR1vzfG2fXbyOtvaxEq tVCgNLT7lob1uhJCi7F9g9sjkJzyKPSWcpKL7vDLwg+GID0t/h2ymK4KnkwyOdO9cRNC uhN0JN23tseBzViH62XG/5F9vQqeg4PAmi7D2UKDJxpYK1ShOZfjuhOpeKibUS4psj6/ yTG7abFHHlzENezDRPr/bT3awmUJomvFmiFWZK1Gn+N0CD8DNoMDcMsoG1xy/o5pKzcz hkvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=XaZwtBKb; 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 u22-20020aa7d0d6000000b004ab44dde183si630889edo.281.2023.02.21.04.06.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:06:27 -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=XaZwtBKb; 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 CBA86383FE22 for ; Tue, 21 Feb 2023 12:04:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 0649A385B516 for ; Tue, 21 Feb 2023 12:03:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0649A385B516 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-x42c.google.com with SMTP id j2so3980164wrh.9 for ; Tue, 21 Feb 2023 04:03:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=WvIXClx801McHQjUiEmAWWq+hA6OrhKovqL7/pMpQ6Y=; b=XaZwtBKbN20sOTvkTwLz1cXjGXhvgF4IrGVE8gJT7KoxQ5PNJ+Jz22B6xuIKIPcJjs og7R/19CzZv6fN/qsJpE/5mClW7sBxfg4MyyS3bMmgVhjDB/QbGWs/mwr6dnzzxO2smO FmUxm+8em6HvVufm9WgOuKhs8m8GmnBMPbV+oghIl2mGKlmiRbm8+bSEOeZyLkDyUdrH pYIbxVcBIDQZav8swSKMdEE5cnxwZaD5GUZZpZ80o/Wv3Dz6/tQShNuz947V64nWo7Ov XdTEcQtcfWLo39I9g5FuucUIBJ8fd79NLAx8Gwr2f8JUj8w4sNdrnneM8w6TKYjOMcfX SLhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WvIXClx801McHQjUiEmAWWq+hA6OrhKovqL7/pMpQ6Y=; b=V+CQAgUwdNZVmnsjBa2HoRa8CLhehAoGsfoE0MVh8pKY1cZb8XbOq4y1hd0GiybQw1 ElihRZuTwejXGEizUA4lJSXIaeJhJsKp3ILp6dBxOFoQJ8KslG225y+PGhSmkAdO/ieN /dh50WdBW9TRN67GADV1Q5wYNWRaViCCPEq5jEqX9ZyAjZrBEMrVS0mrJ+tYN7DIw7fu BCqUYx0BrZ+1JQ5onseovC6Dh8O2mHv6baiTYdbVhpSa+/mtPUA8GpMaaKGGWeCgYYph mR3QknXhLVeq2UqLmXx2QW1hz0xY+kf8Y/HY3hOJcti41gFhC6kBLltAd74DldTULID+ 12fQ== X-Gm-Message-State: AO0yUKWhYZc6SeuiaQzxQIU7BdCObp7DPyfy9DleXczYGNwu56YLMAGt Zf6aOqU3gEdgbTw+mJ095d1M2vqC6iAuEivX/w== X-Received: by 2002:adf:fd07:0:b0:2bf:e39d:c8a7 with SMTP id e7-20020adffd07000000b002bfe39dc8a7mr5437063wrr.44.1676980993438; Tue, 21 Feb 2023 04:03:13 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:13 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 001/103] gccrs: Fix missing dead code analysis ICE on local enum definition Date: Tue, 21 Feb 2023 13:00:50 +0100 Message-Id: <20230221120230.596966-2-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.7 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=unavailable 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: , Reply-To: arthur.cohen@embecosm.com 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?1758442225449610547?= X-GMAIL-MSGID: =?utf-8?q?1758442225449610547?= From: Philip Herron When resolving local enum's within a Block the name resolution info is not at the top of the stack so this patch introduces a new mappings class for miscellaneous name resolutions which can be used during path analaysis. Fixes #1272 gcc/rust/ChangeLog: * resolve/rust-name-resolver.h: Add miscellenaous item mappings. * resolve/rust-name-resolver.cc (Resolver::insert_resolved_misc): Use new mappings. (Resolver::lookup_resolved_misc): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): Adapt function to insert into miscelleanous mappings. * checks/lints/rust-lint-marklive.cc (MarkLive::find_ref_node_id): Allow lookup in miscelleanous mappings in mark-live phase. gcc/testsuite/ChangeLog: * rust/compile/issue-1272.rs: New test. --- gcc/rust/checks/lints/rust-lint-marklive.cc | 7 +++++-- gcc/rust/resolve/rust-name-resolver.cc | 20 +++++++++++++++++++ gcc/rust/resolve/rust-name-resolver.h | 6 ++++++ .../typecheck/rust-hir-type-check-path.cc | 5 +++++ gcc/testsuite/rust/compile/issue-1272.rs | 8 ++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-1272.rs diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc index 14115c86f26..c914b549257 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.cc +++ b/gcc/rust/checks/lints/rust-lint-marklive.cc @@ -273,8 +273,11 @@ MarkLive::find_ref_node_id (NodeId ast_node_id, NodeId &ref_node_id) { if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id)) { - bool ok = resolver->lookup_resolved_type (ast_node_id, &ref_node_id); - rust_assert (ok); + if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id)) + { + bool ok = resolver->lookup_resolved_misc (ast_node_id, &ref_node_id); + rust_assert (ok); + } } } diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index 77d98d5f364..b94713d3c30 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -499,5 +499,25 @@ Resolver::lookup_resolved_macro (NodeId refId, NodeId *defId) return true; } +void +Resolver::insert_resolved_misc (NodeId refId, NodeId defId) +{ + auto it = misc_resolved_items.find (refId); + rust_assert (it == misc_resolved_items.end ()); + + misc_resolved_items[refId] = defId; +} + +bool +Resolver::lookup_resolved_misc (NodeId refId, NodeId *defId) +{ + auto it = misc_resolved_items.find (refId); + if (it == misc_resolved_items.end ()) + return false; + + *defId = it->second; + return true; +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 6f4dda06a5c..302b0de15cc 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -126,6 +126,9 @@ public: void insert_resolved_macro (NodeId refId, NodeId defId); bool lookup_resolved_macro (NodeId refId, NodeId *defId); + void insert_resolved_misc (NodeId refId, NodeId defId); + bool lookup_resolved_misc (NodeId refId, NodeId *defId); + // proxy for scoping Scope &get_name_scope () { return name_scope; } Scope &get_type_scope () { return type_scope; } @@ -202,6 +205,9 @@ private: std::map resolved_labels; std::map resolved_macros; + // misc + std::map misc_resolved_items; + // keep track of the current module scope ids std::vector current_module_stack; }; diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index f404ea64bcc..305d73f76f9 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -462,6 +462,11 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, resolver->insert_resolved_type (expr_mappings.get_nodeid (), resolved_node_id); } + else + { + resolver->insert_resolved_misc (expr_mappings.get_nodeid (), + resolved_node_id); + } infered = tyseg; } diff --git a/gcc/testsuite/rust/compile/issue-1272.rs b/gcc/testsuite/rust/compile/issue-1272.rs new file mode 100644 index 00000000000..08adaaf944b --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1272.rs @@ -0,0 +1,8 @@ +fn main() -> i32 { + enum E { + X(u8), + } + let _v = E::X(4); + + 0 +}