diff options
author | Kushal Pal <kushalpal109@gmail.com> | 2024-07-19 07:30:03 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-19 15:32:02 +0100 |
commit | 715b62375c2f2a16a21221246b85c2298906f5f3 (patch) | |
tree | 8e2dfb56b6811272dc478aa2882e4d243cc30d6e /gcc | |
parent | cbb99fedcfcb094371e8db71d741e9dcaa4c47fd (diff) | |
download | gcc-715b62375c2f2a16a21221246b85c2298906f5f3.zip gcc-715b62375c2f2a16a21221246b85c2298906f5f3.tar.gz gcc-715b62375c2f2a16a21221246b85c2298906f5f3.tar.bz2 |
gccrs: Add location to BIR::Statement of kind RETURN
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 <kushalpal109@gmail.com>
Diffstat (limited to 'gcc')
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 49b8301..3515bdf 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 16fcb6a..34726cf 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 4f7d2b0..b7d0651 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 0e0ef66..74c53a6 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<AbstractExpr> 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, |