]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add location to BIR::Statement of kind RETURN
authorKushal Pal <kushalpal109@gmail.com>
Fri, 19 Jul 2024 07:30:03 +0000 (07:30 +0000)
committerCohenArthur <arthur.cohen@embecosm.com>
Fri, 2 Aug 2024 11:41:15 +0000 (11:41 +0000)
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>
gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
gcc/rust/checks/errors/borrowck/rust-bir-builder.h
gcc/rust/checks/errors/borrowck/rust-bir.h

index f7107652ad187ed0122ce773d707c9045af7bb9b..887b5f68d1e3be0eb8796db5f82d81f27c75c92b 100644 (file)
@@ -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;
 }
 
index e542c4ebb18dc4e3516efcb0d99472d1f9bd365b..377b0479da9001ab7d1112fd7255c3797d54a108 100644 (file)
@@ -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)
   {
index e027837427d15f56174b4b810520f0f8d893f2f0..c0d79a7380ae0f95b5c5ba1c5c601fb7749753d5 100644 (file)
@@ -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);
       }
   }
 };
index a0252b974ce19cb0491295d011af0f64037210ce..851fb71485949170628927767b9c4efffa572609 100644 (file)
@@ -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,