Skip to content

Commit 898d55a

Browse files
committed
gccrs: Fix ICE during const expr eval on array expressions
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 #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>
1 parent 08bfb35 commit 898d55a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

gcc/rust/backend/rust-compile-context.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ class Context
7272
return it->second;
7373

7474
compiled_type_map.insert ({h, type});
75-
push_type (type);
75+
76+
if (TYPE_NAME (type) != NULL)
77+
push_type (type);
78+
7679
return type;
7780
}
7881

gcc/rust/backend/rust-compile-type.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ TyTyResolveCompile::visit (const TyTy::ArrayType &type)
481481
tree folded_capacity_expr = fold_expr (capacity_expr);
482482

483483
translated = Backend::array_type (element_type, folded_capacity_expr);
484+
if (translated != error_mark_node)
485+
translated = ctx->insert_compiled_type (translated);
484486
}
485487

486488
void
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const FOO: i32 = if true { [1, 2, 3] } else { [2, 3, 4] }[0];
2+
3+
pub fn test() -> i32 {
4+
FOO
5+
}

0 commit comments

Comments
 (0)