From patchwork Tue Feb 21 12:02:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60080 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1850665wrn; Tue, 21 Feb 2023 05:06:03 -0800 (PST) X-Google-Smtp-Source: AK7set8CaSfeH4PyKKFwXoxicj/r6fU84N0+OT/y6albDtOBNxVH9qfm+cqH2tfH5YZjIjq8XbpA X-Received: by 2002:a17:906:f1c9:b0:877:7113:71f3 with SMTP id gx9-20020a170906f1c900b00877711371f3mr10270909ejb.25.1676984763080; Tue, 21 Feb 2023 05:06:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984763; cv=none; d=google.com; s=arc-20160816; b=LOQilUIb9NhNty9Gudncgm+ENePcDrsfGPX+rkY4XsL00RAsy5jwC65cUgXGUGFz2r oHhQUMh0EdzwW89JkSvJLOQfO3lHpWpLAiEkxXe414XdsyvZuiZreP835lBZYV/CEKh1 NNDgzfFVKDGNxdZe859dOiWPEXBlCszMGpoXUDjGeUccHcHBF7NTskC9eAp+2HF3d6pY pHMWk4OQK4zwpFtZlRXLTN9rher4BsI7hDwB3lt9cXx6coMmzbxhRKTMuVd1f5BJo2QT bVqYFMMRcB/YipIjObTeeofgQPh0mhQ9iKTsbO039h3HhvTLjvSxwzBVfU9GZAvaO915 L5lA== 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=vSNpzZvOilzKYGsnAcxKb5BlI9LPoMsUF3u+FaUOnzY=; b=Qr13hSeqkEoHdo9i09t6oWTEFMf3pTKzHxi82X2xgSKuXtwJfPjUE+K/S0pY41a4Cx h7NqycotFSHnafUEGZWHLqLZJXlPj3dSXJhPrIkCQIdd5cluhHrRbvbFm+dshBtaFHc5 TUKBjrXVqNHwBVLzE+YTjjBVd8T6EsJRcQLow8m11VaEosFDgSbZ3GAw/YKmd+7ubT7K +i8sgiynuoY4AP8bJxkeXN3LiK9KvpVfOuDuBeXaFJTcvdp+xcRPXIPYXSLlggXq7kQ/ kSFo6Il6yp+dVi+DuNeomVUn4YwvHkEDlkoEe3kDE5tQnr7Yo2IUhjPwhvbI3a7gQKAD f/1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=WcNkBANs; 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 y20-20020a170906519400b008b7eed5fa1bsi13624530ejk.737.2023.02.21.05.06.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:06:03 -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=WcNkBANs; 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 AA0A4389F86F for ; Tue, 21 Feb 2023 12:25:12 +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 727DD382E695 for ; Tue, 21 Feb 2023 12:04:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 727DD382E695 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 t13so4091731wrv.13 for ; Tue, 21 Feb 2023 04:04:41 -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=vSNpzZvOilzKYGsnAcxKb5BlI9LPoMsUF3u+FaUOnzY=; b=WcNkBANsIk8weDdyOyWqyK6jti0OKsy2hSCbA+bU/uYMIxaGaKK5r6R/BcsPrApWEk N0IUQR3g2eApaQiSjTIEyb3dSJDDPpHWSkRqDexPVm++c23pcrtYWYaZhyFwF5MwgjZJ YgbLavybtn0+f5kx8BqOlPr+od6bltjBxd6D5bL1bKOo1c07NHeOIzqxFbXXdEQGq/u7 3mqfw1bHAL9HkpqoGh3P1lc3tdsBy7bbrF4H76p59K070d3M15OEUEzQfzYEHu3BbWyR qnWEHNRYyclSPPk/V/5V5RViU2iVGNW1n5R9aVHG8qMdGmRZO6qSQ0lH40CMi9OSztrH U2iQ== 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=vSNpzZvOilzKYGsnAcxKb5BlI9LPoMsUF3u+FaUOnzY=; b=U4jxGBEtfSoGl6JZfPQq+nrNxhAgHFlIOMEveq5cAnsGufHXOHVLv0hDXF6Q6/xqon ST7IhaCmTINvGqk3ohztjJOsWb7JfGtGllfNu08l+Si0OhciTxXg9cDckQLS4FADnKxR K+1LZgMU5N7mwPnkuaNl1lh/PSak/i1HlPa/3egBHENHttcCqlFUtXawRufL3683BYmo IPGBMFJf8gNqTlRFW5hi062KcXU3Gv5apDejeb7ZJ5Wm9Gm/5HAi4EanBa6nqRVq0xk7 MZlb6i3TCP4cM5EPqn7cj1mrpNPnwzI5zQEVHt3LycvaHi1PrJ6LrXUPQfbAxb7OmYtu SLuw== X-Gm-Message-State: AO0yUKV1BF5EsHsUlS/DIsUkuPGtGXxiSwAohZyPYIIzHygF/kwjc3ij RzejAtTLogXiEYotw5BZmbtNIrgIrVCHLvQCzQ== X-Received: by 2002:adf:fb49:0:b0:2c6:6e35:4414 with SMTP id c9-20020adffb49000000b002c66e354414mr4289681wrs.6.1676981080786; Tue, 21 Feb 2023 04:04:40 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:40 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 098/103] gccrs: Fix undefined behaviour issues on macos Date: Tue, 21 Feb 2023 13:02:28 +0100 Message-Id: <20230221120230.596966-99-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.3 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?1758445975164739384?= X-GMAIL-MSGID: =?utf-8?q?1758445975164739384?= From: Philip Herron This adds missing copy constructors to HIR::PathExprSegment which were wrongly defaulting to empty vectors when apply specified generic arguments to method calls. gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h: Add const `get_method_name`. * hir/tree/rust-hir-full-decls.h (struct GenericArgs): Move from `struct`... (class GenericArgs): ...to `class`. * hir/tree/rust-hir-path.h (struct GenericArgs): Likewise. (class GenericArgs): Clear `type_args` in copy constructor. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Reorder debug print. * typecheck/rust-tyty.h: Add default constructors for `SubstitutionArgumentMappings`. --- gcc/rust/hir/tree/rust-hir-expr.h | 3 +- gcc/rust/hir/tree/rust-hir-full-decls.h | 2 +- gcc/rust/hir/tree/rust-hir-path.h | 37 ++++++++++++++----- .../typecheck/rust-hir-type-check-expr.cc | 5 ++- gcc/rust/typecheck/rust-tyty.h | 4 ++ 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 227bacbe641..cc884420bef 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -1872,7 +1872,8 @@ public: std::unique_ptr &get_receiver () { return receiver; } - PathExprSegment get_method_name () const { return method_name; }; + PathExprSegment &get_method_name () { return method_name; }; + const PathExprSegment &get_method_name () const { return method_name; }; size_t num_params () const { return params.size (); } diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h index 70ee7538298..7870a5497ed 100644 --- a/gcc/rust/hir/tree/rust-hir-full-decls.h +++ b/gcc/rust/hir/tree/rust-hir-full-decls.h @@ -43,7 +43,7 @@ class PathExpr; // rust-path.h class PathIdentSegment; struct GenericArgsBinding; -struct GenericArgs; +class GenericArgs; class PathExprSegment; class PathPattern; class PathInExpression; diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h index fa8347b2cf8..17eedb8d741 100644 --- a/gcc/rust/hir/tree/rust-hir-path.h +++ b/gcc/rust/hir/tree/rust-hir-path.h @@ -140,8 +140,7 @@ private: Location locus; }; -// Generic arguments allowed in each path expression segment - inline? -struct GenericArgs +class GenericArgs { std::vector lifetime_args; std::vector > type_args; @@ -172,6 +171,7 @@ public: : lifetime_args (other.lifetime_args), binding_args (other.binding_args), const_args (other.const_args), locus (other.locus) { + type_args.clear (); type_args.reserve (other.type_args.size ()); for (const auto &e : other.type_args) @@ -188,6 +188,7 @@ public: const_args = other.const_args; locus = other.locus; + type_args.clear (); type_args.reserve (other.type_args.size ()); for (const auto &e : other.type_args) type_args.push_back (e->clone_type ()); @@ -235,26 +236,44 @@ private: Location locus; public: - // Returns true if there are any generic arguments - bool has_generic_args () const { return generic_args.has_generic_args (); } - - // Constructor for segment (from IdentSegment and GenericArgs) PathExprSegment (Analysis::NodeMapping mappings, - PathIdentSegment segment_name, Location locus = Location (), - GenericArgs generic_args = GenericArgs::create_empty ()) + PathIdentSegment segment_name, Location locus, + GenericArgs generic_args) : mappings (std::move (mappings)), segment_name (std::move (segment_name)), generic_args (std::move (generic_args)), locus (locus) {} + PathExprSegment (PathExprSegment const &other) + : mappings (other.mappings), segment_name (other.segment_name), + generic_args (other.generic_args), locus (other.locus) + {} + + PathExprSegment &operator= (PathExprSegment const &other) + { + mappings = other.mappings; + segment_name = other.segment_name; + generic_args = other.generic_args; + locus = other.locus; + + return *this; + } + + // move constructors + PathExprSegment (PathExprSegment &&other) = default; + PathExprSegment &operator= (PathExprSegment &&other) = default; + std::string as_string () const; Location get_locus () const { return locus; } - PathIdentSegment get_segment () const { return segment_name; } + PathIdentSegment &get_segment () { return segment_name; } + const PathIdentSegment &get_segment () const { return segment_name; } GenericArgs &get_generic_args () { return generic_args; } const Analysis::NodeMapping &get_mappings () const { return mappings; } + + bool has_generic_args () const { return generic_args.has_generic_args (); } }; // HIR node representing a pattern that involves a "path" - abstract base class diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 0b0db3296a0..5c43cc8c7b4 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1149,10 +1149,11 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) // apply any remaining generic arguments if (expr.get_method_name ().has_generic_args ()) { - rust_debug_loc (expr.get_method_name ().get_generic_args ().get_locus (), + HIR::GenericArgs &args = expr.get_method_name ().get_generic_args (); + rust_debug_loc (args.get_locus (), "applying generic arguments to method_call: {%s}", lookup->debug_str ().c_str ()); - HIR::GenericArgs &args = expr.get_method_name ().get_generic_args (); + lookup = SubstMapper::Resolve (lookup, expr.get_method_name ().get_locus (), &args); diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index b9a1fdfa5c7..0fd664c8d46 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -699,6 +699,10 @@ public: return *this; } + SubstitutionArgumentMappings (SubstitutionArgumentMappings &&other) = default; + SubstitutionArgumentMappings &operator= (SubstitutionArgumentMappings &&other) + = default; + static SubstitutionArgumentMappings error () { return SubstitutionArgumentMappings ({}, Location (), nullptr, false);