From: Philip Herron <herron.phi...@googlemail.com> Fixes Rust-GCC#3660
gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): reuse GCC's build_array_type gcc/testsuite/ChangeLog: * rust/compile/const_generics_3.rs: * rust/compile/issue-3660.rs: New test. Signed-off-by: Philip Herron <herron.phi...@googlemail.com> --- gcc/rust/backend/rust-compile-type.cc | 13 ++++++++----- gcc/testsuite/rust/compile/const_generics_3.rs | 2 +- gcc/testsuite/rust/compile/issue-3660.rs | 3 +++ 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-3660.rs diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index 00b21fbbf95..7e56a0f4e1b 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -17,11 +17,11 @@ // <http://www.gnu.org/licenses/>. #include "rust-compile-type.h" -#include "rust-compile-expr.h" #include "rust-constexpr.h" -#include "rust-gcc.h" +#include "rust-compile-base.h" #include "tree.h" +#include "fold-const.h" #include "stor-layout.h" namespace Rust { @@ -480,9 +480,12 @@ TyTyResolveCompile::visit (const TyTy::ArrayType &type) tree folded_capacity_expr = fold_expr (capacity_expr); - translated = Backend::array_type (element_type, folded_capacity_expr); - if (translated != error_mark_node) - translated = ctx->insert_compiled_type (translated); + // build_index_type takes the maximum index, which is one less than + // the length. + tree index_type_tree = build_index_type ( + fold_build2 (MINUS_EXPR, sizetype, folded_capacity_expr, size_one_node)); + + translated = build_array_type (element_type, index_type_tree, false); } void diff --git a/gcc/testsuite/rust/compile/const_generics_3.rs b/gcc/testsuite/rust/compile/const_generics_3.rs index 524d48d5bcf..bd917294984 100644 --- a/gcc/testsuite/rust/compile/const_generics_3.rs +++ b/gcc/testsuite/rust/compile/const_generics_3.rs @@ -1,4 +1,4 @@ -// { dg-additional-options "-w -frust-name-resolution-2.0" } +// { dg-additional-options "-w -frust-name-resolution-2.0 -frust-compile-until=compilation" } #[lang = "sized"] trait Sized {} diff --git a/gcc/testsuite/rust/compile/issue-3660.rs b/gcc/testsuite/rust/compile/issue-3660.rs new file mode 100644 index 00000000000..1f1c583cb5b --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3660.rs @@ -0,0 +1,3 @@ +pub static A: [u32; 2] = [1, 2]; + +pub static B: [u8; 2] = [3, 4]; -- 2.49.0