From patchwork Thu Mar 16 11:39:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 70745 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp430216wrt; Thu, 16 Mar 2023 04:40:24 -0700 (PDT) X-Google-Smtp-Source: AK7set/5aFYrv/mM03BZ8zPf48v/vNxD8yA3dAzD0JxmI5yhuzA9kVykYBnEfBbk68vC/5ToIJGr X-Received: by 2002:a05:6402:656:b0:4fb:ec6a:2357 with SMTP id u22-20020a056402065600b004fbec6a2357mr5740917edx.34.1678966824579; Thu, 16 Mar 2023 04:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678966824; cv=none; d=google.com; s=arc-20160816; b=IaSTZt8MYO/JjzGmhTOvi9jHa+G+OwItBgJAik2NL55P6t+HjYvrFDMo1pM1KY+XVu kKiKp72xGACZDq61fvV4cFNsbXkCUufQZLF6B9izd7NLt5TpCuTNmFLTJEpHHfSG9WIb vv30NNniTeObxMxHLiwgKHSQB9fB6tUTFVSzyiYyy7blWkXyxEK47W8T7C1x3elECCka RLpyl3ooHmUGDk5qUjnBSE30PruTeXqZfIgK7TGgvGDFYYB3dDwsEEip+6bzlHyD6xy8 QD87ZX31p39m7+l1RJ6RaL9nnGOD1BEeYjGf+ac0NyMjzpI+9Gx1et0LU0ea5QdH8PFM 0TbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=S4XKDPm17t22m06M2gwz7w/IzRv0cuRhFem3C4UIfbc=; b=fgNsr3NgxGm247lc6R83fGXxXvvrhoT8VJhYrD0Td0+4dmm++zEfDKBDMU9pyU4yfy mG7YpP/NqV8J3wI09M7AuJikTbvxXZLNkizSc0ui+KVdfy59RVn039sWpLFIjVXCbCGP BDy2T5Dmhn93rjJIzGwjTRB+MW3H04t52ptP16EkFZDQlZ5U1f5ZzTsh/0kW3bxhkZR8 driShJch5ADbmil5DasQeJVLr3PxAa1uiRZ5ugF12T1kBjf8LsmSrldyZdk9OPS3X6u+ WquDgwyWMXTHuTzYXKEyhgpn10CH2+QIBx50KfAC2kkv7ydtxliwvJeiN9Lp9tZgJpH/ BbYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Izstb56V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y6-20020aa7c246000000b004fefeece418si2384097edo.284.2023.03.16.04.40.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 04:40:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Izstb56V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC3A6385B516 for ; Thu, 16 Mar 2023 11:40:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC3A6385B516 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678966822; bh=S4XKDPm17t22m06M2gwz7w/IzRv0cuRhFem3C4UIfbc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Izstb56VR9cqn+C8jrte4mdLdJej2fF2v0itxVOUE4Dia6jn+K8ZpfcMtqm0qIYNG TGa16bQGyiaOMXJz2NEzdwYgT4nqWmjGPSXtw1KHg+yu2VE+4ZbG1V3/tyhKlySoNO RQFnKfw2Aud+8Su+son4a3TD/Te1zV3447NFAd8g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by sourceware.org (Postfix) with ESMTPS id E7E8B3858D35 for ; Thu, 16 Mar 2023 11:39:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E7E8B3858D35 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4Pclfd2MKlz9sV3; Thu, 16 Mar 2023 12:39:37 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: Fix closure fields don't get same alignment as local variable [PR109144] Date: Thu, 16 Mar 2023 12:39:35 +0100 Message-Id: <20230316113935.325393-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4Pclfd2MKlz9sV3 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760524317082379138?= X-GMAIL-MSGID: =?utf-8?q?1760524317082379138?= Hi, Local variables with both non-local references and explicit alignment did not propagate their alignment to either the closure field or closure frame type, resulting in the closure being misaligned. This is now correctly set-up when building the frame type. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, committed to mainline and backported to releases/gcc-12. I did have a look at backporting to gcc-11 too, however the D front-end does not correctly set the alignment of local variables, so although the code generation pass is doing the right thing, the alignment for the local variable is never set in the first place. Regards, Iain. --- PR d/109144 gcc/d/ChangeLog: * d-codegen.cc (build_frame_type): Set frame field and type alignment. gcc/testsuite/ChangeLog: * gdc.dg/torture/pr109144.d: New test. --- gcc/d/d-codegen.cc | 5 +++++ gcc/testsuite/gdc.dg/torture/pr109144.d | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 gcc/testsuite/gdc.dg/torture/pr109144.d diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 5a041927ec9..5c6c300ecec 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -2706,6 +2706,11 @@ build_frame_type (tree ffi, FuncDeclaration *fd) TREE_ADDRESSABLE (field) = TREE_ADDRESSABLE (vsym); DECL_NONADDRESSABLE_P (field) = !TREE_ADDRESSABLE (vsym); TREE_THIS_VOLATILE (field) = TREE_THIS_VOLATILE (vsym); + SET_DECL_ALIGN (field, DECL_ALIGN (vsym)); + + /* Update alignment for frame record type. */ + if (TYPE_ALIGN (frame_rec_type) < DECL_ALIGN (field)) + SET_TYPE_ALIGN (frame_rec_type, DECL_ALIGN (field)); if (DECL_LANG_NRVO (vsym)) { diff --git a/gcc/testsuite/gdc.dg/torture/pr109144.d b/gcc/testsuite/gdc.dg/torture/pr109144.d new file mode 100644 index 00000000000..32d3af7cd45 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/pr109144.d @@ -0,0 +1,9 @@ +// { dg-do run } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +void main() +{ + align(128) byte var; + assert((cast(size_t) &var) % 128 == 0); + var = 73; + assert((() => var)() == 73); +}