From: Kushal Pal <kushalpal...@gmail.com>

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 <kushalpal...@gmail.com>
---
 .../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<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,
-- 
2.45.2

Reply via email to