From e1aedf6ec7d30d957c96e8ac1e2eb1c7d1384242 Mon Sep 17 00:00:00 2001 From: Thomas Young Date: Sat, 3 Jul 2021 21:42:12 +0800 Subject: mark live symbol in if expr family except if let expr --- gcc/rust/lint/rust-lint-marklive.h | 20 ++++++++++++++++++++ gcc/testsuite/rust/compile/torture/if.rs | 19 +++++++++++++++++++ gcc/testsuite/rust/compile/torture/if_elif.rs | 20 ++++++++++++++++++++ gcc/testsuite/rust/compile/torture/if_else.rs | 19 +++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 gcc/testsuite/rust/compile/torture/if.rs create mode 100644 gcc/testsuite/rust/compile/torture/if_elif.rs create mode 100644 gcc/testsuite/rust/compile/torture/if_else.rs (limited to 'gcc') diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h index 72274d0..5bc23e3 100644 --- a/gcc/rust/lint/rust-lint-marklive.h +++ b/gcc/rust/lint/rust-lint-marklive.h @@ -182,6 +182,26 @@ public: expr.visit_rhs (*this); } + void visit (HIR::IfExpr &expr) override + { + expr.get_if_condition ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); + } + + void visit (HIR::IfExprConseqElse &expr) override + { + expr.get_if_condition ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); + expr.get_else_block ()->accept_vis (*this); + } + + void visit (HIR::IfExprConseqIf &expr) override + { + expr.get_if_condition ()->accept_vis (*this); + expr.get_if_block ()->accept_vis (*this); + expr.get_conseq_if_expr ()->accept_vis (*this); + } + void visit (HIR::TraitItemFunc &item) override { item.get_block_expr ()->accept_vis (*this); diff --git a/gcc/testsuite/rust/compile/torture/if.rs b/gcc/testsuite/rust/compile/torture/if.rs new file mode 100644 index 0000000..bcd520f --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/if.rs @@ -0,0 +1,19 @@ +fn foo() -> bool { + true +} + +fn bar() {} + +struct Foo1 { + one: i32 +} + + +fn main() { + if foo() { + bar(); + let a = Foo1{one: 1}; + a.one + } + +} \ No newline at end of file diff --git a/gcc/testsuite/rust/compile/torture/if_elif.rs b/gcc/testsuite/rust/compile/torture/if_elif.rs new file mode 100644 index 0000000..a89ad5e --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/if_elif.rs @@ -0,0 +1,20 @@ +fn foo() -> bool { + true +} + +fn bar() -> bool { + false +} + +struct Foo1 { + one: i32 +} + + +fn main() { + if foo() { + } else if bar() { + let a = Foo1{one: 1}; + a.one; + } +} \ No newline at end of file diff --git a/gcc/testsuite/rust/compile/torture/if_else.rs b/gcc/testsuite/rust/compile/torture/if_else.rs new file mode 100644 index 0000000..09aecae --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/if_else.rs @@ -0,0 +1,19 @@ +fn foo() -> bool { + true +} + +fn bar() {} + +struct Foo1 { + one: i32 +} + + +fn main() { + if foo() { + bar(); + } else { + let a = Foo1{one: 1}; + a.one; + } +} \ No newline at end of file -- cgit v1.1