aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-27 12:00:22 +0000
committerGitHub <noreply@github.com>2021-06-27 12:00:22 +0000
commit54e0d0171932b7c43e69f685e5fe41d473ddf5bf (patch)
tree4377b51b6e97974561e71d148b73b31cc3fe3426 /gcc
parent51d86210d3dcbbf4dea14149f90ad9087b006f6a (diff)
parent5ff37842fb091ebc79d87b5e7770bc335f2a8591 (diff)
downloadgcc-54e0d0171932b7c43e69f685e5fe41d473ddf5bf.zip
gcc-54e0d0171932b7c43e69f685e5fe41d473ddf5bf.tar.gz
gcc-54e0d0171932b7c43e69f685e5fe41d473ddf5bf.tar.bz2
Merge #529
529: Marking live symbol in break, return, while, whilelet, for expr r=philberty a=thomasyonug Marking live symbol in break, return, while, whilelet, for expr without test case for last two due to unimplemented. Co-authored-by: Thomas Young <wenzhang5800@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/hir/tree/rust-hir-expr.h4
-rw-r--r--gcc/rust/lint/rust-lint-marklive.h35
-rw-r--r--gcc/testsuite/rust/compile/torture/break_function.rs10
-rw-r--r--gcc/testsuite/rust/compile/torture/return_function.rs5
-rw-r--r--gcc/testsuite/rust/compile/torture/while_function.rs10
5 files changed, 64 insertions, 0 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index f718a61..681ccf8 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -3387,6 +3387,8 @@ public:
void accept_vis (HIRVisitor &vis) override;
+ std::unique_ptr<Expr> &get_cond () { return condition; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@@ -3450,6 +3452,8 @@ public:
void accept_vis (HIRVisitor &vis) override;
+ std::unique_ptr<Expr> &get_iterator_expr () { return iterator_expr; }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h
index 67dd76a..d34587d 100644
--- a/gcc/rust/lint/rust-lint-marklive.h
+++ b/gcc/rust/lint/rust-lint-marklive.h
@@ -103,11 +103,46 @@ public:
}
}
+ void visit (HIR::LoopExpr &expr) override
+ {
+ expr.get_loop_block ()->accept_vis (*this);
+ }
+
+ void visit (HIR::BreakExpr &expr) override
+ {
+ if (expr.has_break_expr ())
+ expr.get_expr ()->accept_vis (*this);
+ }
+
+ void visit (HIR::WhileLoopExpr &expr) override
+ {
+ expr.get_loop_block ()->accept_vis (*this);
+ expr.get_predicate_expr ()->accept_vis (*this);
+ }
+
void visit (HIR::Function &function) override
{
function.get_definition ().get ()->accept_vis (*this);
}
+ void visit (HIR::ReturnExpr &expr) override
+ {
+ if (expr.has_return_expr ())
+ expr.get_expr ()->accept_vis (*this);
+ }
+
+ void visit (HIR::WhileLetLoopExpr &expr) override
+ {
+ expr.get_loop_block ()->accept_vis (*this);
+ expr.get_cond ()->accept_vis (*this);
+ }
+
+ void visit (HIR::ForLoopExpr &expr) override
+ {
+ expr.get_loop_block ()->accept_vis (*this);
+ expr.get_iterator_expr ()->accept_vis (*this);
+ }
+
void visit (HIR::ExprStmtWithoutBlock &stmt) override
{
stmt.get_expr ()->accept_vis (*this);
diff --git a/gcc/testsuite/rust/compile/torture/break_function.rs b/gcc/testsuite/rust/compile/torture/break_function.rs
new file mode 100644
index 0000000..043e91c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/break_function.rs
@@ -0,0 +1,10 @@
+fn foo() -> i32 {
+ 1
+}
+
+fn main() {
+ let _a = loop {
+ break foo();
+ };
+}
+ \ No newline at end of file
diff --git a/gcc/testsuite/rust/compile/torture/return_function.rs b/gcc/testsuite/rust/compile/torture/return_function.rs
new file mode 100644
index 0000000..084adaf
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/return_function.rs
@@ -0,0 +1,5 @@
+fn foo() {}
+
+fn main() {
+ return foo();
+}
diff --git a/gcc/testsuite/rust/compile/torture/while_function.rs b/gcc/testsuite/rust/compile/torture/while_function.rs
new file mode 100644
index 0000000..014db90
--- /dev/null
+++ b/gcc/testsuite/rust/compile/torture/while_function.rs
@@ -0,0 +1,10 @@
+fn foo() {}
+fn bar() -> i32 { return 10; }
+
+fn main() {
+ let mut i = 1;
+ while i < bar() {
+ foo();
+ i += 1;
+ }
+}