aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-05-27 13:47:04 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2025-08-05 16:36:46 +0200
commit82fabf7c9ceba3cdab835352c0dbfc218198865c (patch)
tree5cb9e9383496fa63893fb11fa4c806ac3dfbead1 /gcc
parent4351f509956836393b45e3b88878c353c4b20d96 (diff)
downloadgcc-82fabf7c9ceba3cdab835352c0dbfc218198865c.zip
gcc-82fabf7c9ceba3cdab835352c0dbfc218198865c.tar.gz
gcc-82fabf7c9ceba3cdab835352c0dbfc218198865c.tar.bz2
gccrs: Fix bad type canonicalization on ARRAY_TYPES
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.philip@googlemail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-type.cc13
-rw-r--r--gcc/testsuite/rust/compile/const_generics_3.rs2
-rw-r--r--gcc/testsuite/rust/compile/issue-3660.rs3
3 files changed, 12 insertions, 6 deletions
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc
index 00b21fb..7e56a0f 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 524d48d..bd91729 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 0000000..1f1c583
--- /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];