From patchwork Tue Feb 21 12:01:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1825153wrn; Tue, 21 Feb 2023 04:08:28 -0800 (PST) X-Google-Smtp-Source: AK7set8fU7bDS65+zLE6ZRkQRFIf+mrBGCYyxk15XoFhbw6cxb77nOiNiZDjgghMywhxnJUC/eCO X-Received: by 2002:a17:906:4914:b0:8b1:7eaf:4708 with SMTP id b20-20020a170906491400b008b17eaf4708mr15617442ejq.65.1676981308014; Tue, 21 Feb 2023 04:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981308; cv=none; d=google.com; s=arc-20160816; b=tj6U2Ad7DknDqbXzjn1GUKctGqEEUPazynHWU/TgtLl95Cau563G5669HhZNC5ooIl iXjKXz/TWKL4rBtt6q1eeM9m3y9J7HlmAFmhwU8rEXXDc39+flPPL4GDcWt2hFI1PSjE Qr547PXypkEq1vN4EEZLjw5ryBlxopuw5joG0BSWFCV68mq03YtVePxmX5xZSy7L1PMe Be/yYEGjAFrYAzBawsv3jO90qK5J2uOurxRauDAgLaa9dYpIiEcHSJSYF6o3WWC+PCvq WNyx6AfaMWz9Xipa5aQHZxaTT2SoBFF1JTv7PCQLCe+j4FjChQzzyAE/DOvkhfQG2s5I RVpA== 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=bdJtvjW+kVPvmSQZ+NCJb+ySr4zY4gBrlQB15L7NmAc=; b=ZPLzOEbyfMr2N3ux3zm5QPfHlMRQaZuGsu5eBBeZVLqsjyHEJx5HZY4wGzG092bw+U q9RfCu3TSiSujTWdjulRoxsFTrbjyYPTxQLILxcGo25jzSnoMt0Pe5eLrgnBlIx1/oUO Z2Rmlf9i/njEAYVOcJziW16RTd23yEvxwvqHGzF6R+Z8kNBYJKoTZGOBMUjZfQUSlzTu WUN8csNwoWRvyUsjxUpoFti4hSEiu77HtcKYlUJ4TnKw7I1q+1qxMBKq471RDCsE/s1y M6+1mqD9cOxYseWEBfuSd7kbSidrRTIWtIwsEjZ5kO66VI3DrUk1HX4zWVOTAbFC/iC8 z27w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="BW1/hPs1"; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 30-20020a170906005e00b008dd40fa813asi3729970ejg.359.2023.02.21.04.08.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:08:28 -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="BW1/hPs1"; 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 04771388B69C for ; Tue, 21 Feb 2023 12:05:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 3589538654A3 for ; Tue, 21 Feb 2023 12:03:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3589538654A3 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-x436.google.com with SMTP id c12so4161774wrw.1 for ; Tue, 21 Feb 2023 04:03:34 -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=bdJtvjW+kVPvmSQZ+NCJb+ySr4zY4gBrlQB15L7NmAc=; b=BW1/hPs1Rg4+UZbyq1biI3KIh64L89nLH5f1E5SbMGbPnWg1a+PpSFIIB1vygTONrs W2Gkq+gjJCN1pW388AG0Zk0NH/+BhVfVBBZFHd/H6q8DcZfm9tA2qjLRWsuEO12gRMy5 R4S57Q7SYM6TZlEtiQHXTtA1u1jBOPp6dzZpU381eEGQ4ifSAmHd8xB+7i/2WXWucJq5 xqcbSKZGuqOZSz5iDZ9Z5U/K5+XIDRHck4BY+YFWNQjFWBS4WhJkisw0eDOz+iTuNMMM ftnrOZFeMUDhfjGMQVHGNNe4jXWI4VpTe7Ljs0R5gAQdvSSla8q5wlaDLvN/0uffHcEq AFcA== 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=bdJtvjW+kVPvmSQZ+NCJb+ySr4zY4gBrlQB15L7NmAc=; b=eNR8yiAIyfu54gR0brVNuCu5jvZoZS2G8hwvIr4+5aurPqZyaO24i8xu/SnffeY8Rz vyqG0wi2gtSEW+NUJHuau/O8LPt73qyfP7pZ3RwlZnQaXzZdJJhQb92zhXnx242nXwUj ntJQ2AO3dC6zFj99Cu7dqGLV+VwiFoXsBVfIT13faGt2/1fPVu4VRMWbRSaar7XooNS3 +PlrHuhsBk3cx9Dae479wQCAVwjCByROx5a+CvEJ4CiXpD5x9XeqXXgH011AjMW6+AYZ s0ZhWJKdDoe9Le+Q0JF7rtiRvostwtHc8ISNlbZ5cAa8kLLCmoOb+tmUNQLsDZJGMRUy dnZQ== X-Gm-Message-State: AO0yUKVjeHzt49YUeL9X2Y26gjs5f6fx4J8Nci+ZCf6QpAGRHGAex8yn Nqh4aKIHm3fh1jpWcGF6+ivAYPH1rB0OFIJh6g== X-Received: by 2002:a5d:4712:0:b0:2c5:4c6f:27c6 with SMTP id y18-20020a5d4712000000b002c54c6f27c6mr3925758wrq.5.1676981012759; Tue, 21 Feb 2023 04:03:32 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:32 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 011/103] gccrs: Support looking up super traits for trait items Date: Tue, 21 Feb 2023 13:01:01 +0100 Message-Id: <20230221120230.596966-12-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.9 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?1758442351990573149?= X-GMAIL-MSGID: =?utf-8?q?1758442351990573149?= From: Philip Herron When supporting calls to super traits we need to allow lookups based on the super traits as specified on the TraitReferences. Fixes #1555 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-ref.h (lookup_trait_item): Add lookup in super_trait. gcc/testsuite/ChangeLog: * rust/compile/torture/issue-1555.rs: New test. --- gcc/rust/typecheck/rust-hir-trait-ref.h | 19 ++++++++ .../rust/compile/torture/issue-1555.rs | 48 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 gcc/testsuite/rust/compile/torture/issue-1555.rs diff --git a/gcc/rust/typecheck/rust-hir-trait-ref.h b/gcc/rust/typecheck/rust-hir-trait-ref.h index f6a3328c5f6..7eeb3300387 100644 --- a/gcc/rust/typecheck/rust-hir-trait-ref.h +++ b/gcc/rust/typecheck/rust-hir-trait-ref.h @@ -336,6 +336,15 @@ public: return true; } } + + // lookup super traits + for (const auto &super_trait : super_traits) + { + bool found = super_trait->lookup_trait_item (ident, ref); + if (found) + return true; + } + return false; } @@ -351,6 +360,16 @@ public: if (ident.compare (item.get_identifier ()) == 0) return &item; } + + // lookup super traits + for (const auto &super_trait : super_traits) + { + const TraitItemReference *res + = super_trait->lookup_trait_item (ident, type); + if (!res->is_error ()) + return res; + } + return &TraitItemReference::error_node (); } diff --git a/gcc/testsuite/rust/compile/torture/issue-1555.rs b/gcc/testsuite/rust/compile/torture/issue-1555.rs new file mode 100644 index 00000000000..adb48911648 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/issue-1555.rs @@ -0,0 +1,48 @@ +extern "C" { + fn printf(s: *const i8, ...); +} + +struct Foo(i32); +trait Bar { + fn baz(&self); +} + +trait Baz: Bar { + fn qux(&self); +} + +impl Bar for Foo { + fn baz(&self) { + unsafe { + let a = "baz %i\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, self.0); + } + } +} + +impl Baz for Foo { + fn qux(&self) { + unsafe { + let a = "qux %i\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, self.0); + } + } +} + +fn static_dispatch(t: &T) { + t.baz(); + t.qux(); +} + +pub fn main() { + let a; + a = &Foo(123); + + static_dispatch(a); +}