]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE during const expr eval on array expressions
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 27 Mar 2025 17:27:56 +0000 (17:27 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 31 Mar 2025 19:07:20 +0000 (21:07 +0200)
Array expressions are still getting turned into VIEW_CONVERT_EXPR's becuase
TYPE_MAIN_VARIANT is not set so then we might as well reuse the type-hasher
to sort this out.

Fixes Rust-GCC#3588

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: only push named types
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): run the type hasher

gcc/testsuite/ChangeLog:

* rust/compile/issue-3588.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-context.h
gcc/rust/backend/rust-compile-type.cc
gcc/testsuite/rust/compile/issue-3588.rs [new file with mode: 0644]

index a44638817dbc3d976bbf090021df610a3a688019..ce81a1d0db2ce86dc94a3fcb60579cb58145dc7f 100644 (file)
@@ -72,7 +72,10 @@ public:
       return it->second;
 
     compiled_type_map.insert ({h, type});
-    push_type (type);
+
+    if (TYPE_NAME (type) != NULL)
+      push_type (type);
+
     return type;
   }
 
index 813e11c47cfe0b1300d6f54b50d882115706d471..83e5756429f5c310673cbc0670f7a0a4cb33c6b2 100644 (file)
@@ -481,6 +481,8 @@ 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);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/issue-3588.rs b/gcc/testsuite/rust/compile/issue-3588.rs
new file mode 100644 (file)
index 0000000..744d967
--- /dev/null
@@ -0,0 +1,5 @@
+const FOO: i32 = if true { [1, 2, 3] } else { [2, 3, 4] }[0];
+
+pub fn test() -> i32 {
+    FOO
+}