Skip to content

Commit 155f6a9

Browse files
braw-leeCohenArthur
authored andcommitted
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 <[email protected]>
1 parent 812c534 commit 155f6a9

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ ExprStmtBuilder::visit (HIR::ReturnExpr &ret)
485485
push_assignment (RETURN_VALUE_PLACE,
486486
move_place (visit_expr (*ret.get_expr ()),
487487
ret.get_expr ()->get_locus ()),
488-
ret.get_locus ());
488+
ret.get_expr ()->get_locus ());
489489
}
490490
unwind_until (ROOT_SCOPE);
491-
ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN);
491+
push_return (ret.get_locus ());
492492
translated = INVALID_PLACE;
493493
}
494494

gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ class AbstractBuilder
303303
place);
304304
}
305305

306+
void push_return (location_t location)
307+
{
308+
ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN,
309+
INVALID_PLACE, location);
310+
}
311+
306312
PlaceId borrow_place (PlaceId place_id, TyTy::BaseType *ty,
307313
location_t location)
308314
{

gcc/rust/checks/errors/borrowck/rust-bir-builder.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ class Builder final : public AbstractBuilder
154154
ctx.place_db[RETURN_VALUE_PLACE].tyty),
155155
body.get_end_locus ());
156156
}
157-
ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN);
157+
auto return_location = body.has_expr ()
158+
? body.get_final_expr ()->get_locus ()
159+
: body.get_end_locus ();
160+
push_return (return_location);
158161
}
159162
}
160163
};

gcc/rust/checks/errors/borrowck/rust-bir.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class Statement
7878
std::unique_ptr<AbstractExpr> expr;
7979
TyTy::BaseType *type;
8080
// stores location of the actual expression from source code
81-
// currently only available when kind == Kind::ASSIGNMENT
82-
// FIXME: Add location for Statements other than ASSIGNMENT
81+
// currently only available when kind is ASSIGNMENT | RETURN
82+
// FIXME: Add location for other statement kinds
8383
location_t location;
8484

8585
public:
@@ -88,9 +88,8 @@ class Statement
8888
{}
8989

9090
explicit Statement (Kind kind, PlaceId place = INVALID_PLACE,
91-
AbstractExpr *expr = nullptr,
9291
location_t location = UNKNOWN_LOCATION)
93-
: kind (kind), place (place), expr (expr), location (location)
92+
: kind (kind), place (place), location (location)
9493
{}
9594

9695
explicit Statement (Kind kind, PlaceId place, TyTy::BaseType *type,

0 commit comments

Comments
 (0)