From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 4D2B43858028; Tue, 16 Jan 2024 18:08:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D2B43858028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428521; bh=cfLrmtZuTvCjmAgG972YbHl2FRnThUwMEoMDMhxbFuk=; h=From:To:Subject:Date:From; b=ZKey3ISINn2X48XIZocUNFhhEhsIAgH7wXE4j8mSuj/luC6cIgDN0BYtNgpatatFP R6iEPjN5l+aml8lIAUpvto6fXP0Bb1bdd+4ReQ9TYez5deCXE1F982tbRlVeyrx+vB MBvn0WKwZJog6VyBW2gSGi3SE168gbWj/xuqCwQI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-7957] gccrs: Fix invalid call to vector::front in TypeBoundPredicate constructors X-Act-Checkin: gcc X-Git-Author: Owen Avery X-Git-Refname: refs/heads/trunk X-Git-Oldrev: fb14147b9f336d5467b3bb26afeab4ab925dd748 X-Git-Newrev: c00624a6c8b9a08b10674abff7826ac990e9248a Message-Id: <20240116180841.4D2B43858028@sourceware.org> Date: Tue, 16 Jan 2024 18:08:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c00624a6c8b9a08b10674abff7826ac990e9248a commit r14-7957-gc00624a6c8b9a08b10674abff7826ac990e9248a Author: Owen Avery Date: Wed Aug 23 22:49:30 2023 -0400 gccrs: Fix invalid call to vector::front in TypeBoundPredicate constructors gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_fn_trait_call): Add TODO comment. * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): Add assertions, new error constructor. (TypeBoundPredicate::error): Use new error constructor. * typecheck/rust-tyty.h (struct TypeBoundPredicate::mark_is_error): New. (TypeBoundPredicate::TypeBoundPredicate): Add new error constructor. Signed-off-by: Owen Avery Diff: --- gcc/rust/typecheck/rust-hir-type-check-expr.cc | 1 + gcc/rust/typecheck/rust-tyty-bounds.cc | 15 +++++++++++---- gcc/rust/typecheck/rust-tyty.h | 6 ++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index af350ed67d3..f4ffc40fe09 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1826,6 +1826,7 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr, TyTy::BaseType **result) { // we turn this into a method call expr + // TODO: add implicit self argument (?) auto associated_predicate = TyTy::TypeBoundPredicate::error (); HIR::PathIdentSegment method_name = resolve_possible_fn_trait_call_method_name (*receiver_tyty, diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 6239a83f607..6a87c05dbf4 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -310,6 +310,8 @@ TypeBoundPredicate::TypeBoundPredicate ( reference (trait_reference.get_mappings ().get_defid ()), locus (locus), error_flag (false), polarity (polarity) { + rust_assert (!trait_reference.get_trait_substs ().empty ()); + substitutions.clear (); for (const auto &p : trait_reference.get_trait_substs ()) substitutions.push_back (p.clone ()); @@ -326,6 +328,8 @@ TypeBoundPredicate::TypeBoundPredicate ( reference (reference), locus (locus), error_flag (false), polarity (polarity) { + rust_assert (!subst.empty ()); + substitutions.clear (); for (const auto &p : subst) substitutions.push_back (p.clone ()); @@ -335,6 +339,12 @@ TypeBoundPredicate::TypeBoundPredicate ( used_arguments.get_mappings ().push_back (placeholder_self); } +TypeBoundPredicate::TypeBoundPredicate (mark_is_error) + : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()), + reference (UNKNOWN_DEFID), locus (UNDEF_LOCATION), error_flag (true), + polarity (BoundPolarity::RegularBound) +{} + TypeBoundPredicate::TypeBoundPredicate (const TypeBoundPredicate &other) : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()), reference (other.reference), locus (other.locus), @@ -413,10 +423,7 @@ TypeBoundPredicate::operator= (const TypeBoundPredicate &other) TypeBoundPredicate TypeBoundPredicate::error () { - auto p = TypeBoundPredicate (UNKNOWN_DEFID, {}, BoundPolarity::RegularBound, - UNDEF_LOCATION); - p.error_flag = true; - return p; + return TypeBoundPredicate (mark_is_error ()); } std::string diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index fa2c88ccb9a..51bf0b463bd 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -450,6 +450,12 @@ public: bool is_equal (const TypeBoundPredicate &other) const; private: + struct mark_is_error + { + }; + + TypeBoundPredicate (mark_is_error); + DefId reference; location_t locus; bool error_flag;