]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add location to BIR::Statement of kind RETURN
authorKushal Pal <kushalpal109@gmail.com>
Fri, 19 Jul 2024 07:30:03 +0000 (07:30 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 19 Mar 2025 14:32:02 +0000 (15:32 +0100)
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 49b830124d75d9bf836c4accd413349ace75ab57..3515bdf030b6f93230e0bca462d73fe22e907e50 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 16fcb6abca73169f09f735234ce88b808eecb599..34726cf4840ce38ca9645c7576ede65e89b45e43 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 4f7d2b074757b0c66b2236841108b842529b59b6..b7d0651fcddb69e90b7a65050437fea51914ec5d 100644 (file)
@@ -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);
       }
   }
 };
index 0e0ef6643f526484e369b39e569205aa56b4d07a..74c53a68a026347bf01c15c8584b6a907af8cea7 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,