From a0628a62ad2a9024872b2ae1eb67a8c873cc80c6 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Mon, 2 Aug 2021 14:18:24 +0200 Subject: Handle 'UnsafeBlockExpr' in liveness analysis We may then remove the '{ dg-options "-w" }' as discussed in and #601. --- gcc/rust/lint/rust-lint-marklive.h | 5 +++++ gcc/testsuite/rust/compile/torture/forward_decl_3-unsafe.rs | 13 +++++++++++++ gcc/testsuite/rust/compile/torture/union.rs | 3 --- gcc/testsuite/rust/compile/torture/unsafe4.rs | 12 ++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/rust/compile/torture/forward_decl_3-unsafe.rs create mode 100644 gcc/testsuite/rust/compile/torture/unsafe4.rs (limited to 'gcc') diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h index 742175b..062bb96 100644 --- a/gcc/rust/lint/rust-lint-marklive.h +++ b/gcc/rust/lint/rust-lint-marklive.h @@ -107,6 +107,11 @@ public: } } + void visit (HIR::UnsafeBlockExpr &expr) override + { + expr.get_block_expr ()->accept_vis (*this); + } + void visit (HIR::LoopExpr &expr) override { expr.get_loop_block ()->accept_vis (*this); diff --git a/gcc/testsuite/rust/compile/torture/forward_decl_3-unsafe.rs b/gcc/testsuite/rust/compile/torture/forward_decl_3-unsafe.rs new file mode 100644 index 0000000..0493586 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/forward_decl_3-unsafe.rs @@ -0,0 +1,13 @@ +fn main() { + unsafe { + let struct_test = Foo { one: 1, two: 2 }; + // { dg-warning "unused name" "" { target *-*-* } .-1 } + }; +} + +struct Foo { + one: i32, + // { dg-warning "field is never read" "" { target *-*-* } .-1 } + two: i32, + // { dg-warning "field is never read" "" { target *-*-* } .-1 } +} diff --git a/gcc/testsuite/rust/compile/torture/union.rs b/gcc/testsuite/rust/compile/torture/union.rs index 393e591..7241688 100644 --- a/gcc/testsuite/rust/compile/torture/union.rs +++ b/gcc/testsuite/rust/compile/torture/union.rs @@ -1,6 +1,3 @@ -// { dg-do compile } -// { dg-options "-w" } - union U { f1: u8 diff --git a/gcc/testsuite/rust/compile/torture/unsafe4.rs b/gcc/testsuite/rust/compile/torture/unsafe4.rs new file mode 100644 index 0000000..6fe3101 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/unsafe4.rs @@ -0,0 +1,12 @@ +struct SS { + one: i32, + two: i32, +} +struct TS(i32, i32); + +fn main() { + unsafe { + let ss = SS { one: 1, two: 2 }; + let _ts = TS(ss.one, ss.two); + }; +} -- cgit v1.1