From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 35CC9382E686 for ; Tue, 21 Feb 2023 12:04:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35CC9382E686 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-x42b.google.com with SMTP id v3so4087063wrp.2 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=D+5rgfNws6zqGvct2TZli3qS1pjn0hmoPgFBHhVdvb86JgIClXRqR6ojeF/oihSmnM 7liij8uw0TuQ1qmdTB6ZIQfN4tzBmFX1D5bfJXafGruPvWzXCA+2Xi1tqPxJVNe4VWOP vPcOeDs3NBxMSxHsRT+5874djdYBFVYyIrTR8PsRXCZEjLJ8HEPBy7uSD5/DCeq/wCPV JqKatBt+BT8RUPk8vRyNcZvvyMxkbY8dcUw9m7pu9697wcbdsZM/mDWRH9KGD1XCfbyk FfO3SbQkM6gLYFbfzt8iAeK692ywqMldkbMjqemZ3+0SbBX5xhg7P6bmFyY2fgm//fEq R4zQ== X-Gm-Message-State: AO0yUKXYMc8PAJ433SXReK9f3fzU6xHeV9fOxFYC0X65d7aS57Uat5YS hHdRUiYCaVqeSB7p7HCARomjXnsg8uQJl2qR0A== X-Google-Smtp-Source: AK7set/R1KmnEGmoQIdESnADPez6m9w582L8NnondH0nJSAZvFkkR17D8QIS2Yd3z1tZgmjRtHEzsw== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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); -- 2.39.1