From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 5AB3F3839DF9 for ; Tue, 31 Jan 2023 13:22:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5AB3F3839DF9 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wm1-x32d.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so12447456wmb.2 for ; Tue, 31 Jan 2023 05:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AFvZFbUs5U//ovzAzjQFRpHxvIm/fi10sOUbRQhwOFg=; b=gqIu8iS7pUmYJ6SPAC6GJZmY7HOusN81GHhv1IUnsjp1U1tDxqn/SEWOpa2J7waMBT blieKylqmhnAU3nAkz5olqtzmSPRMtux2zxDhObmYIsuMsMadZPX9lLpKFsPYjqNDjmb oI3tggfMdvmJTyZZ8e/3OWlRV7oWJB+ncKj5P3FJGDMxHQNQkKGslScmQS9pv2poWO1P TYj8utgauS0wyEP1N3mc1diXI2ckelsEIG4TS7XT6VYkitKqDtNbmQ6LpBd7RJ2av4HJ PiBmO8DtLNQQQIZmhckHfYKOksh0yhUofzNV+D+gubN6ajqVslIOMCz39vVmOdrcV2tA fNXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AFvZFbUs5U//ovzAzjQFRpHxvIm/fi10sOUbRQhwOFg=; b=ljKcQM5XMEPyCKRvRDpqVbkHBdavznhYrM0DXrBPoRNgRjdcQN8Q4iUYZrX08Q8CqV KLWjnrJz9SY8V/wepHs2UCjJE5cvIkDd8956NVG1FfNCWyQVG65ZRnhe+Zy6neTSIKLu umhTtahGEu+IFfyd0cDVUr39Zp2PouMisE4t1YKP9w7TOJD7CuoarpM00ycLL92xoZfh 6iApROWPGpeJiSO8WYM7OQYS3L7aN5lOvcQVwWUKYL434+D5SJgQ7VbnyvWIc2jLIrQ4 qLxHDib5qwv3aHxR9A+g5iaBWqNDJsEunHcD+Hefiad2ot9i0dme5QO0Mp49sNwYq/mI oiyw== X-Gm-Message-State: AO0yUKUWDEv7ghMqwwZwghPJzWr6el7feSM1Lu4rit0MAIJWbyhhS3Jw U6DCHuZgUC7CcTgYAV0GPSrjJc4euyY/GWURmw== X-Google-Smtp-Source: AK7set8zZogidpObxnZUHwkr73QFP/KZVFFzddIeVxMH3/AGNBy5vU06eMC+jEBbZwDJUf/sJdicNQ== X-Received: by 2002:a05:600c:1c97:b0:3dd:1c45:d592 with SMTP id k23-20020a05600c1c9700b003dd1c45d592mr3055446wms.19.1675171359235; Tue, 31 Jan 2023 05:22:39 -0800 (PST) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.gmail.com with ESMTPSA id l16-20020a7bc350000000b003d9aa76dc6asm22404787wmj.0.2023.01.31.05.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:22:38 -0800 (PST) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [COMMITTED] gccrs: Static Items must be const evaluated Date: Tue, 31 Jan 2023 14:26:24 +0100 Message-Id: <20230131132624.663288-1-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Philip Herron 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. Tested on x86_64-pc-linux-gnu, committed on master. --- 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); -- 2.39.1