diff options
author | Kushal Pal <kushalpal109@gmail.com> | 2024-07-19 07:30:03 +0000 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2024-08-02 11:41:15 +0000 |
commit | 155f6a9c80854b2181fdcd9e230ff8359f63fc27 (patch) | |
tree | d0129f123d31c56db4a384c166a59bd3cb945489 | |
parent | 812c5347bc088783ac3587f3ffab709968a7e628 (diff) | |
download | gcc-155f6a9c80854b2181fdcd9e230ff8359f63fc27.zip gcc-155f6a9c80854b2181fdcd9e230ff8359f63fc27.tar.gz gcc-155f6a9c80854b2181fdcd9e230ff8359f63fc27.tar.bz2 |
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>
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 f710765..887b5f6 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 e542c4e..377b047 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 e027837..c0d79a7 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h @@ -154,7 +154,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 a0252b9..851fb71 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, |