diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-04-03 15:39:58 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2025-04-03 16:40:47 +0000 |
commit | 314090971a51037bb77e36b46c7a10652b9e6c3f (patch) | |
tree | 06a5d5217c4db2b7b12502fb447885ae186a0968 /gcc/rust/hir | |
parent | 002c349b6d0f8c12d26beaff178785524f155583 (diff) | |
download | gcc-314090971a51037bb77e36b46c7a10652b9e6c3f.zip gcc-314090971a51037bb77e36b46c7a10652b9e6c3f.tar.gz gcc-314090971a51037bb77e36b46c7a10652b9e6c3f.tar.bz2 |
gccrs: Fix ICE on raw reference
This patch adds support for raw references which enforce the pointer
type away from a reference type.
Fixes Rust-GCC#3667
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::address_expression): allow optional type
* backend/rust-compile-base.h: update prototype
* backend/rust-compile-expr.cc (CompileExpr::visit): update borrow expr
* backend/rust-compile-extern.h: remove unused debug
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): update usage
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): lower raw ref
* hir/tree/rust-hir-expr.cc (BorrowExpr::BorrowExpr): add flag for raw ref
* hir/tree/rust-hir-expr.h (class BorrowExpr): add new raw ref field
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): add handle for raw ref
gcc/testsuite/ChangeLog:
* rust/compile/issue-3667.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-expr.cc | 11 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.cc | 4 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 4 |
3 files changed, 9 insertions, 10 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc index d0d004e..575eea6 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -633,9 +633,6 @@ ASTLoweringExpr::visit (AST::ContinueExpr &expr) void ASTLoweringExpr::visit (AST::BorrowExpr &expr) { - if (expr.is_raw_borrow ()) - rust_unreachable (); - HIR::Expr *borrow_lvalue = ASTLoweringExpr::translate (expr.get_borrowed_expr ()); @@ -646,8 +643,8 @@ ASTLoweringExpr::visit (AST::BorrowExpr &expr) auto *borrow_expr = new HIR::BorrowExpr (mapping, std::unique_ptr<HIR::Expr> (borrow_lvalue), - expr.get_mutability (), expr.get_outer_attrs (), - expr.get_locus ()); + expr.get_mutability (), expr.is_raw_borrow (), + expr.get_outer_attrs (), expr.get_locus ()); if (expr.get_is_double_borrow ()) { @@ -659,8 +656,8 @@ ASTLoweringExpr::visit (AST::BorrowExpr &expr) borrow_expr = new HIR::BorrowExpr (mapping, std::unique_ptr<HIR::Expr> (borrow_expr), - expr.get_mutability (), expr.get_outer_attrs (), - expr.get_locus ()); + expr.get_mutability (), expr.is_raw_borrow (), + expr.get_outer_attrs (), expr.get_locus ()); } translated = borrow_expr; diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc b/gcc/rust/hir/tree/rust-hir-expr.cc index 2ded789..bb7ebfb 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.cc +++ b/gcc/rust/hir/tree/rust-hir-expr.cc @@ -81,10 +81,10 @@ OperatorExpr::operator= (OperatorExpr const &other) BorrowExpr::BorrowExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> borrow_lvalue, Mutability mut, - AST::AttrVec outer_attribs, location_t locus) + bool raw, AST::AttrVec outer_attribs, location_t locus) : OperatorExpr (std::move (mappings), std::move (borrow_lvalue), std::move (outer_attribs), locus), - mut (mut) + mut (mut), raw (raw) {} DereferenceExpr::DereferenceExpr (Analysis::NodeMapping mappings, diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 4603927..bd2f9d4 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -199,12 +199,13 @@ public: class BorrowExpr : public OperatorExpr { Mutability mut; + bool raw; public: std::string as_string () const override; BorrowExpr (Analysis::NodeMapping mappings, - std::unique_ptr<Expr> borrow_lvalue, Mutability mut, + std::unique_ptr<Expr> borrow_lvalue, Mutability mut, bool raw, AST::AttrVec outer_attribs, location_t locus); void accept_vis (HIRFullVisitor &vis) override; @@ -212,6 +213,7 @@ public: Mutability get_mut () const { return mut; } bool is_mut () const { return mut == Mutability::Mut; } + bool is_raw_borrow () const { return raw; } protected: /* Use covariance to implement clone function as returning this object rather |