public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Add support for isize and usize type-hints
@ 2022-06-08 12:34 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:34 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7915329a0c552245488710d7561a6a76f784c0a7

commit 7915329a0c552245488710d7561a6a76f784c0a7
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Fri Apr 22 10:24:46 2022 +0100

    Add support for isize and usize type-hints
    
    This bug turned out to be that we expected a usize for the array capacity
    but the specified capacity turned out to be an integer inference variable
    which will default to a signed integer. The type resolution was missing
    handling the type-hints of isize and usize
    
    Fixes #1152

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-base.cc | 8 ++++++++
 gcc/rust/typecheck/rust-hir-type-check-expr.h  | 2 ++
 gcc/testsuite/rust/compile/issue-1152.rs       | 8 ++++++++
 3 files changed, 18 insertions(+)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index a9248669979..4e8fa269ca6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -133,6 +133,14 @@ TypeCheckBase::resolve_literal (const Analysis::NodeMapping &expr_mappings,
 	    ok = context->lookup_builtin ("f64", &infered);
 	    break;
 
+	  case CORETYPE_ISIZE:
+	    ok = context->lookup_builtin ("isize", &infered);
+	    break;
+
+	  case CORETYPE_USIZE:
+	    ok = context->lookup_builtin ("usize", &infered);
+	    break;
+
 	  default:
 	    ok = true;
 	    infered
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 5db00a43832..630eb601885 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -619,6 +619,8 @@ public:
 	    = (negated_expr_ty->get_kind () == TyTy::TypeKind::INT)
 	      || (negated_expr_ty->get_kind () == TyTy::TypeKind::UINT)
 	      || (negated_expr_ty->get_kind () == TyTy::TypeKind::FLOAT)
+	      || (negated_expr_ty->get_kind () == TyTy::TypeKind::ISIZE)
+	      || (negated_expr_ty->get_kind () == TyTy::TypeKind::USIZE)
 	      || (negated_expr_ty->get_kind () == TyTy::TypeKind::INFER
 		  && (((TyTy::InferType *) negated_expr_ty)->get_infer_kind ()
 		      == TyTy::InferType::INTEGRAL))
diff --git a/gcc/testsuite/rust/compile/issue-1152.rs b/gcc/testsuite/rust/compile/issue-1152.rs
new file mode 100644
index 00000000000..18eee9e6b4a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1152.rs
@@ -0,0 +1,8 @@
+fn test() {
+    let f = [0; -4_isize];
+    // { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
+    // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
+    let f = [0_usize; -1_isize];
+    // { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
+    // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:34 [gcc/devel/rust/master] Add support for isize and usize type-hints Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).