diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-04-02 21:59:50 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-04-04 11:54:57 +0000 |
commit | b99448f4b02957c71ceb1adc3fb8cfa2a7602ab9 (patch) | |
tree | 973b8e4bb64ba6d442b0de58a78a8926f4965a5d /gcc/rust | |
parent | 011eb78b3531b27fd68aa89a50860564f44f8319 (diff) | |
download | gcc-b99448f4b02957c71ceb1adc3fb8cfa2a7602ab9.zip gcc-b99448f4b02957c71ceb1adc3fb8cfa2a7602ab9.tar.gz gcc-b99448f4b02957c71ceb1adc3fb8cfa2a7602ab9.tar.bz2 |
gccrs: Fix ICE using constructors for intilizers in statics
We are getting constant expressions for the initilizers for static items
this hits an assertion in the GCC middle-end which is looking for a
constructor so we need to unwrap the constant expression using DECL_INITIAL
as the initilizer to the global static.
Fixes #2080
gcc/rust/ChangeLog:
* backend/rust-compile-item.cc (CompileItem::visit): unwrap the constant expression
gcc/testsuite/ChangeLog:
* rust/execute/torture/issue-2080.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/backend/rust-compile-item.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc index b2e9b3f..e1e2bb6 100644 --- a/gcc/rust/backend/rust-compile-item.cc +++ b/gcc/rust/backend/rust-compile-item.cc @@ -18,9 +18,7 @@ #include "rust-compile-item.h" #include "rust-compile-implitem.h" -#include "rust-compile-expr.h" #include "rust-compile-extern.h" -#include "rust-constexpr.h" namespace Rust { namespace Compile { @@ -66,7 +64,9 @@ CompileItem::visit (HIR::StaticItem &var) = ctx->get_backend ()->global_variable (name, asm_name, type, is_external, is_hidden, in_unique_section, var.get_locus ()); - ctx->get_backend ()->global_variable_set_init (static_global, value); + + tree init = value == error_mark_node ? error_mark_node : DECL_INITIAL (value); + ctx->get_backend ()->global_variable_set_init (static_global, init); ctx->insert_var_decl (var.get_mappings ().get_hirid (), static_global); ctx->push_var (static_global); |