diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-04-22 10:24:46 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-04-22 10:24:46 +0100 |
commit | 7915329a0c552245488710d7561a6a76f784c0a7 (patch) | |
tree | 2d96d02b9907a9b28273d60b91c6e10dd58f6ffd | |
parent | 243ef0dfe713a9fc8d4d80feb488a58b2639f39f (diff) | |
download | gcc-7915329a0c552245488710d7561a6a76f784c0a7.zip gcc-7915329a0c552245488710d7561a6a76f784c0a7.tar.gz gcc-7915329a0c552245488710d7561a6a76f784c0a7.tar.bz2 |
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
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-base.cc | 8 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-1152.rs | 8 |
3 files changed, 18 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index a924866..4e8fa26 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 5db00a4..630eb60 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 0000000..18eee9e --- /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 } +} |