diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-25 09:16:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-25 09:16:59 +0000 |
commit | 08e3ae7fce360db23bceb45c1b16718ee21deb91 (patch) | |
tree | 60ebc714d84b5bc4b341bfe2c37e80b52d87dd11 | |
parent | 07b7486e2c27a83e5809b246b8c9797c5e69ae72 (diff) | |
parent | b111e6305ad3dee5b599918bee892ff2bbe2c11f (diff) | |
download | gcc-08e3ae7fce360db23bceb45c1b16718ee21deb91.zip gcc-08e3ae7fce360db23bceb45c1b16718ee21deb91.tar.gz gcc-08e3ae7fce360db23bceb45c1b16718ee21deb91.tar.bz2 |
Merge #525
525: Support BorrowExpr, DereferenceExpr, NegationExpr in marking live symbols and corresponding test cases. r=philberty a=thomasyonug
Support BorrowExpr, DereferenceExpr, NegationExpr in marking live symbols and corresponding test cases.
Co-authored-by: Thomas Young <wenzhang5800@gmail.com>
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 2 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 2 | ||||
-rw-r--r-- | gcc/rust/lint/rust-lint-marklive.h | 16 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-const-fold.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 3 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/borrow_function.rs | 5 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/deref_function.rs | 10 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/torture/negation_function.rs | 7 |
8 files changed, 42 insertions, 5 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 5a224e2..8391bc4 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -354,7 +354,7 @@ public: void visit (HIR::NegationExpr &expr) override { auto op = expr.get_expr_type (); - auto negated_expr = CompileExpr::Compile (expr.get_expr (), ctx); + auto negated_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx); auto location = expr.get_locus (); translated diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 7a5227a..102ab97 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -300,8 +300,6 @@ public: void accept_vis (HIRVisitor &vis) override; - Expr *get_expr () { return main_or_left_expr.get (); } - 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 f6d4b09..74cf0d3 100644 --- a/gcc/rust/lint/rust-lint-marklive.h +++ b/gcc/rust/lint/rust-lint-marklive.h @@ -39,6 +39,21 @@ public: void visit (HIR::PathInExpression &expr) override; void visit (HIR::IdentifierExpr &expr) override; + void visit (HIR::BorrowExpr &expr) override + { + expr.get_expr ().get ()->accept_vis (*this); + } + + void visit (HIR::DereferenceExpr &expr) override + { + expr.get_expr ().get ()->accept_vis (*this); + } + + void visit (HIR::NegationExpr &expr) override + { + expr.get_expr ().get ()->accept_vis (*this); + } + void visit (HIR::BlockExpr &expr) override { expr.iterate_stmts ([&] (HIR::Stmt *s) mutable -> bool { @@ -50,6 +65,7 @@ public: expr.get_final_expr ().get ()->accept_vis (*this); } } + void visit (HIR::Function &function) override { function.get_definition ().get ()->accept_vis (*this); diff --git a/gcc/rust/typecheck/rust-hir-const-fold.h b/gcc/rust/typecheck/rust-hir-const-fold.h index c134d51..90ea595 100644 --- a/gcc/rust/typecheck/rust-hir-const-fold.h +++ b/gcc/rust/typecheck/rust-hir-const-fold.h @@ -341,7 +341,7 @@ public: void visit (HIR::NegationExpr &expr) override { - auto negated_expr = ConstFoldExpr::fold (expr.get_expr ()); + auto negated_expr = ConstFoldExpr::fold (expr.get_expr ().get ()); if (negated_expr == nullptr) return; diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index ba984f8..236c7b9 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -619,7 +619,8 @@ public: void visit (HIR::NegationExpr &expr) override { - auto negated_expr_ty = TypeCheckExpr::Resolve (expr.get_expr (), false); + auto negated_expr_ty + = TypeCheckExpr::Resolve (expr.get_expr ().get (), false); // https://doc.rust-lang.org/reference/expressions/operator-expr.html#negation-operators switch (expr.get_expr_type ()) diff --git a/gcc/testsuite/rust/compile/torture/borrow_function.rs b/gcc/testsuite/rust/compile/torture/borrow_function.rs new file mode 100644 index 0000000..98c6f99 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/borrow_function.rs @@ -0,0 +1,5 @@ +fn foo() {} + +fn main() { + let _a = &foo; +}
\ No newline at end of file diff --git a/gcc/testsuite/rust/compile/torture/deref_function.rs b/gcc/testsuite/rust/compile/torture/deref_function.rs new file mode 100644 index 0000000..b1c5ff6 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/deref_function.rs @@ -0,0 +1,10 @@ +fn foo() {} + + +fn main() { + let _c = *{ + let _a = foo; + let b = &1; + b + }; +}
\ No newline at end of file diff --git a/gcc/testsuite/rust/compile/torture/negation_function.rs b/gcc/testsuite/rust/compile/torture/negation_function.rs new file mode 100644 index 0000000..b592f9c --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/negation_function.rs @@ -0,0 +1,7 @@ +fn ret1() -> i32 { + return 1; +} + +fn main() { + let _a = -ret1(); +}
\ No newline at end of file |