diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-26 15:29:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-26 15:29:25 +0000 |
commit | 387d69cdf385f6979499ea7e0162ecd929ffbe01 (patch) | |
tree | 6762600966d68447c8fe16712d8dab24fd720eb9 | |
parent | 99bc27d278359be9aec5597504807a6456a88a6c (diff) | |
parent | 5e63d163fe8c398d1953feae503d545e84c798bf (diff) | |
download | gcc-387d69cdf385f6979499ea7e0162ecd929ffbe01.zip gcc-387d69cdf385f6979499ea7e0162ecd929ffbe01.tar.gz gcc-387d69cdf385f6979499ea7e0162ecd929ffbe01.tar.bz2 |
Merge #528
528: Marking live symbols in tuple expr, array expr, grouped expr, type cast expr, lazy boolean expr. r=philberty a=thomasyonug
Marking live symbols in tuple expr, array expr, grouped expr, type cast expr, lazy boolean expr.
Co-authored-by: Thomas Young <wenzhang5800@gmail.com>
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 9 | ||||
-rw-r--r-- | gcc/rust/lint/rust-lint-marklive.h | 37 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/array_function.rs | 8 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/grouped_expr_function.rs | 6 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/lazybooleanexpr_function.rs | 14 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/tuple_function.rs | 6 |
6 files changed, 80 insertions, 0 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 102ab97..f718a61 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -1064,6 +1064,15 @@ public: bool is_unit () const { return tuple_elems.size () == 0; } + void iterate (std::function<bool (Expr *)> cb) + { + for (auto &tuple_elem : tuple_elems) + { + if (!cb (tuple_elem.get ())) + return; + } + } + 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 74cf0d3..67dd76a 100644 --- a/gcc/rust/lint/rust-lint-marklive.h +++ b/gcc/rust/lint/rust-lint-marklive.h @@ -54,6 +54,43 @@ public: expr.get_expr ().get ()->accept_vis (*this); } + void visit (HIR::LazyBooleanExpr &expr) override + { + expr.get_lhs ()->accept_vis (*this); + expr.get_rhs ()->accept_vis (*this); + } + + void visit (HIR::TypeCastExpr &expr) override + { + expr.get_expr ().get ()->accept_vis (*this); + } + + void visit (HIR::GroupedExpr &expr) override + { + expr.get_expr_in_parens ()->accept_vis (*this); + } + + void visit (HIR::ArrayExpr &expr) override + { + expr.get_internal_elements ()->accept_vis (*this); + } + + void visit (HIR::ArrayElemsValues &expr) override + { + expr.iterate ([&] (HIR::Expr *expr) mutable -> bool { + expr->accept_vis (*this); + return true; + }); + } + + void visit (HIR::TupleExpr &expr) override + { + expr.iterate ([&] (HIR::Expr *expr) mutable -> bool { + expr->accept_vis (*this); + return true; + }); + } + void visit (HIR::BlockExpr &expr) override { expr.iterate_stmts ([&] (HIR::Stmt *s) mutable -> bool { diff --git a/gcc/testsuite/rust/compile/torture/array_function.rs b/gcc/testsuite/rust/compile/torture/array_function.rs new file mode 100644 index 0000000..4e2b2e0 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/array_function.rs @@ -0,0 +1,8 @@ +fn foo() -> i32 { + 1 +} + + +fn main() { + let _a: [i32; 1] = [foo()]; +}
\ No newline at end of file diff --git a/gcc/testsuite/rust/compile/torture/grouped_expr_function.rs b/gcc/testsuite/rust/compile/torture/grouped_expr_function.rs new file mode 100644 index 0000000..eca7178 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/grouped_expr_function.rs @@ -0,0 +1,6 @@ +fn foo() {} + + +fn main() { + let _a = (foo()); +}
\ No newline at end of file diff --git a/gcc/testsuite/rust/compile/torture/lazybooleanexpr_function.rs b/gcc/testsuite/rust/compile/torture/lazybooleanexpr_function.rs new file mode 100644 index 0000000..1be5127 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/lazybooleanexpr_function.rs @@ -0,0 +1,14 @@ +fn foo() -> bool { + return true; +} + +fn bar() -> bool { + return false; +} + + + +fn main() { + let _a = true && foo(); + let _b = true || bar(); +}
\ No newline at end of file diff --git a/gcc/testsuite/rust/compile/torture/tuple_function.rs b/gcc/testsuite/rust/compile/torture/tuple_function.rs new file mode 100644 index 0000000..514b586 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/tuple_function.rs @@ -0,0 +1,6 @@ +fn foo() -> i32 { + return 1; +} +fn main() { + let _a = (foo(), 2); +} |