diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-09-17 10:04:49 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-01-31 14:16:51 +0100 |
commit | 70fc174b78a2df9cd31fb1ec054d9d8c641b78af (patch) | |
tree | 2519416f16e3bb7fb9f8310b97b26d4b4f69775a | |
parent | 3736647947b6b776c6d53eddde7538394886ebec (diff) | |
download | gcc-70fc174b78a2df9cd31fb1ec054d9d8c641b78af.zip gcc-70fc174b78a2df9cd31fb1ec054d9d8c641b78af.tar.gz gcc-70fc174b78a2df9cd31fb1ec054d9d8c641b78af.tar.bz2 |
gccrs: Static Items must be const evaluated
Statics like constants need to have a singular value they are not functions
to be lazy evaluated. So to evaluate a block expr we can just reuse our
const code to resolve this to a singular value.
gcc/rust/ChangeLog:
* backend/rust-compile-item.cc (CompileItem::visit): Const evaluate
static item expressions.
-rw-r--r-- | gcc/rust/backend/rust-compile-item.cc | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc index 634b983..d1cdc3b 100644 --- a/gcc/rust/backend/rust-compile-item.cc +++ b/gcc/rust/backend/rust-compile-item.cc @@ -43,13 +43,18 @@ CompileItem::visit (HIR::StaticItem &var) rust_assert (ok); tree type = TyTyResolveCompile::compile (ctx, resolved_type); - tree value = CompileExpr::Compile (var.get_expr (), ctx); const Resolver::CanonicalPath *canonical_path = nullptr; ok = ctx->get_mappings ()->lookup_canonical_path ( var.get_mappings ().get_nodeid (), &canonical_path); rust_assert (ok); + HIR::Expr *const_value_expr = var.get_expr (); + ctx->push_const_context (); + tree value = compile_constant_item (ctx, resolved_type, canonical_path, + const_value_expr, var.get_locus ()); + ctx->pop_const_context (); + std::string name = canonical_path->get (); std::string asm_name = ctx->mangle_item (resolved_type, *canonical_path); |