From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 9E6DB385700E; Tue, 31 Jan 2023 13:16:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E6DB385700E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675171004; bh=RC2+YWjhrR7OHj/3/uZQgg0Ai2q5zzH0M4DUQezNMiA=; h=From:To:Subject:Date:From; b=OlOyhogyzZP9pIbNDYzzQWbqWNTmh+KriVFRU14PJwwe7GAbAFTStwvMukzBRahtn qWfyWSPfFgSn75n5bbTlg+Ibh8S+CCb9Kj/ZYRjhrkISkZG0pyvdVRe2kYy+pTSTOs ZkUHg3/dCngHWYVY2/2kMX9LPkCJy5n9g/OIICGQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5563] gccrs: Static Items must be const evaluated X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/master X-Git-Oldrev: 3736647947b6b776c6d53eddde7538394886ebec X-Git-Newrev: 70fc174b78a2df9cd31fb1ec054d9d8c641b78af Message-Id: <20230131131644.9E6DB385700E@sourceware.org> Date: Tue, 31 Jan 2023 13:16:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:70fc174b78a2df9cd31fb1ec054d9d8c641b78af commit r13-5563-g70fc174b78a2df9cd31fb1ec054d9d8c641b78af Author: Philip Herron Date: Sat Sep 17 10:04:49 2022 +0100 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. Diff: --- gcc/rust/backend/rust-compile-item.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc index 634b983a771..d1cdc3b6698 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);