[COMMITTED 017/144] gccrs: Add location to BIR::Statement of kind RETURN
From: Kushal Pal This commit adds location_t to BIR::Statement where type is RETURN. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Add location parameter. * checks/errors/borrowck/rust-bir-builder.h: Likewise. * checks/errors/borrowck/rust-bir-builder-internal.h: Add helper function for pushing return statements. * checks/errors/borrowck/rust-bir.h: Remove `expr` parameter as it is only needed for ASSIGNMENT statements, for which we already have a constructor. Signed-off-by: Kushal Pal --- .../checks/errors/borrowck/rust-bir-builder-expr-stmt.cc | 4 ++-- .../checks/errors/borrowck/rust-bir-builder-internal.h | 6 ++ gcc/rust/checks/errors/borrowck/rust-bir-builder.h | 5 - gcc/rust/checks/errors/borrowck/rust-bir.h | 7 +++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc index 49b830124d7..3515bdf030b 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc @@ -485,10 +485,10 @@ ExprStmtBuilder::visit (HIR::ReturnExpr &ret) push_assignment (RETURN_VALUE_PLACE, move_place (visit_expr (*ret.get_expr ()), ret.get_expr ()->get_locus ()), - ret.get_locus ()); + ret.get_expr ()->get_locus ()); } unwind_until (ROOT_SCOPE); - ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN); + push_return (ret.get_locus ()); translated = INVALID_PLACE; } diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h index 16fcb6abca7..34726cf4840 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h @@ -303,6 +303,12 @@ protected: // Helpers to add BIR statements place); } + void push_return (location_t location) + { +ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN, + INVALID_PLACE, location); + } + PlaceId borrow_place (PlaceId place_id, TyTy::BaseType *ty, location_t location) { diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h index 4f7d2b07475..b7d0651fcdd 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h @@ -155,7 +155,10 @@ private: ctx.place_db[RETURN_VALUE_PLACE].tyty), body.get_end_locus ()); } - ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN); + auto return_location = body.has_expr () +? body.get_final_expr ()->get_locus () +: body.get_end_locus (); + push_return (return_location); } } }; diff --git a/gcc/rust/checks/errors/borrowck/rust-bir.h b/gcc/rust/checks/errors/borrowck/rust-bir.h index 0e0ef6643f5..74c53a68a02 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir.h @@ -78,8 +78,8 @@ private: std::unique_ptr expr; TyTy::BaseType *type; // stores location of the actual expression from source code - // currently only available when kind == Kind::ASSIGNMENT - // FIXME: Add location for Statements other than ASSIGNMENT + // currently only available when kind is ASSIGNMENT | RETURN + // FIXME: Add location for other statement kinds location_t location; public: @@ -88,9 +88,8 @@ public: {} explicit Statement (Kind kind, PlaceId place = INVALID_PLACE, - AbstractExpr *expr = nullptr, location_t location = UNKNOWN_LOCATION) -: kind (kind), place (place), expr (expr), location (location) +: kind (kind), place (place), location (location) {} explicit Statement (Kind kind, PlaceId place, TyTy::BaseType *type, -- 2.45.2
☠ Buildbot (Sourceware): gccrust - failed '! grep ...' (failure) (master)
A failed build has been detected on builder gccrust-bootstrap-debian-amd64 while building gccrust. Full details are available at: https://builder.sourceware.org/buildbot/#/builders/107/builds/816 Build state: failed '! grep ...' (failure) Revision: 75ef9fd3ffc6ef0759cf9fa359c94bfa4fde1235 Worker: x3d1 Build Reason: (unknown) Blamelist: Antoni Boucher , Arthur Cohen , Benjamin Thos , CohenArthur , Dylan Gardner , GS-GOAT <86884129+gs-g...@users.noreply.github.com>, Jarkko Sakkinen , Jason Merrill , Liam Naddell , Marc Poulhiès , Nobel , Om Swaroop Nayak <96killera...@gmail.com>, Owen Avery , Philip Herron , Pierre-Emmanuel Patry , Prajwal S N , Ryutaro Okada <1015ry...@gmail.com>, Sam James , Sri Ganesh Thota , badumbatish , benjamin.thos , lishin , liushuyu Steps: - 0: worker_preparation ( success ) - 1: git checkout ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/1/logs/stdio - 2: rm -rf gccrs-build ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/2/logs/stdio - 3: configure ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/3/logs/stdio - config.log: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/3/logs/config_log - 4: make ( warnings ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/4/logs/stdio - warnings (34): https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/4/logs/warnings__34_ - 5: make check ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/5/logs/stdio - rust.sum: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/5/logs/rust_sum - rust.log: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/5/logs/rust_log - 6: grep FAIL or unexpected rust.sum ( failure ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/6/logs/stdio - 7: prep ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/7/logs/stdio - 8: build bunsen.cpio.gz ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/8/logs/stdio - 9: fetch bunsen.cpio.gz ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/9/logs/stdio - 10: unpack bunsen.cpio.gz ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/10/logs/stdio - 11: pass .bunsen.source.* ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/11/logs/stdio - 12: upload to bunsen ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/12/logs/stdio - 13: clean up ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/13/logs/stdio - 14: rm -rf gccrs-build_1 ( success ) Logs: - stdio: https://builder.sourceware.org/buildbot/#/builders/107/builds/816/steps/14/logs/stdio
[COMMITTED 001/146] gccrs: Fix bad recursive operator overload call
From: Philip Herron When we are typechecking the impl block for DerefMut for &mut T the implementation follows the usual operator overload check but this ended up just resolving directly to the Trait definition which ends up being recursive which we usually handle. The issue we had is that a dereference call can be for either the DEREF or DEREF_MUT lang item here it was looking for a recurisve call to the DEREF lang item but we were in the DEREF_MUT lang item so this case was not accounted for. Fixes #3032 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.h: new get locus helper * typecheck/rust-hir-trait-resolve.cc (AssociatedImplTrait::get_locus): implemention * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_operator_overload): fix overload gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-3032-1.rs: New test. * rust/compile/issue-3032-2.rs: New test. Signed-off-by: Philip Herron --- gcc/rust/typecheck/rust-hir-trait-reference.h | 2 + gcc/rust/typecheck/rust-hir-trait-resolve.cc | 6 ++ .../typecheck/rust-hir-type-check-expr.cc | 21 +-- gcc/testsuite/rust/compile/issue-3032-1.rs| 58 +++ gcc/testsuite/rust/compile/issue-3032-2.rs| 49 gcc/testsuite/rust/compile/nr2/exclude| 4 +- 6 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-3032-1.rs create mode 100644 gcc/testsuite/rust/compile/issue-3032-2.rs diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h b/gcc/rust/typecheck/rust-hir-trait-reference.h index bdfd9879111..41970335375 100644 --- a/gcc/rust/typecheck/rust-hir-trait-reference.h +++ b/gcc/rust/typecheck/rust-hir-trait-reference.h @@ -246,6 +246,8 @@ public: HIR::ImplBlock *get_impl_block (); + location_t get_locus () const; + TyTy::BaseType *get_self (); const TyTy::BaseType *get_self () const; diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index ec331cf6e95..91842df85b2 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -669,6 +669,12 @@ AssociatedImplTrait::reset_associated_types () trait->clear_associated_types (); } +location_t +AssociatedImplTrait::get_locus () const +{ + return impl->get_locus (); +} + Analysis::NodeMapping TraitItemReference::get_parent_trait_mappings () const { diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index ba22eaff441..dfdf85a141d 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1822,10 +1822,20 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type, HIR::ImplBlock *parent = impl_item.first; HIR::Function *fn = impl_item.second; - if (parent->has_trait_ref () - && fn->get_function_name ().as_string ().compare ( - associated_item_name) - == 0) + bool is_deref = lang_item_type == LangItem::Kind::DEREF + || lang_item_type == LangItem::Kind::DEREF_MUT; + bool is_deref_match = fn->get_function_name ().as_string ().compare ( + LangItem::ToString (LangItem::Kind::DEREF)) + == 0 + || fn->get_function_name ().as_string ().compare ( +LangItem::ToString (LangItem::Kind::DEREF_MUT)) +== 0; + + bool is_recursive_op + = fn->get_function_name ().as_string ().compare (associated_item_name) + == 0 + || (is_deref && is_deref_match); + if (parent->has_trait_ref () && is_recursive_op) { TraitReference *trait_reference = TraitResolver::Lookup (*parent->get_trait_ref ().get ()); @@ -1842,7 +1852,8 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type, bool is_lang_item_impl = trait_reference->get_mappings ().get_defid () - == respective_lang_item_id; + == respective_lang_item_id + || (is_deref && is_deref_match); bool self_is_lang_item_self = fntype->get_self_type ()->is_equal (*adjusted_self); bool recursive_operator_overload diff --git a/gcc/testsuite/rust/compile/issue-3032-1.rs b/gcc/testsuite/rust/compile/issue-3032-1.rs new file mode 100644 index 000..e9eb02794ce --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3032-1.rs @@ -0,0 +1,58 @@ +#![feature(negative_impls)] + +#[lang = "sized"] +trait Sized {} + +#[lang = "deref"] +pub trait Deref { +/// The resulting type after dereferencing. +#[stable(feature = "rust1", since = "1.0.0")] +// #[rustc_diagnostic_item = "deref_targe