From patchwork Tue Jan 24 21:54:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 47909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2390039wrn; Tue, 24 Jan 2023 13:54:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXuSOyGuJtAx+jwRmJ5txdkRIRLThCFlXWk0OMRGJInbAxws9Ce00g0phnfTxBAhFpK7fDh5 X-Received: by 2002:a17:907:2bdd:b0:857:b916:94c2 with SMTP id gv29-20020a1709072bdd00b00857b91694c2mr26853715ejc.35.1674597286108; Tue, 24 Jan 2023 13:54:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674597286; cv=pass; d=google.com; s=arc-20160816; b=YlRAUx2Bl+3XMwDwW9/X2X0HBbPKj3tI/2QN8FN0prZbMCG/noFl1EpO4MYSY/7gIn 6m5JbbnMU6b80pCdS0AtLxKroK+aY7Nn7NEtOJ+JInskan+O8pR7nP4F2KJzDnWN8Ijs CjKQgUjrlhwXXYKMSjCtKqJQdzPOKWNVCarB2Cw9mS/dw8etAtB9Tp1E4mJ3PkPm/AZL kr+Q8Lsn8uDjwqLdCpBLCg7hYD841Ie1Do713PHDxpdVycS85+gZfcy+zYONonU9EnEM 9PhMK2RifS2oasWXMaWOuquGsp2Gw4myWiI8BTqnYmZpbV+Bxtz82aTsk2e8Bg9lvZhB vYBQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=a5MO3K76a32GvlGkB41MohB9DKCvghGvk4SzbgJzEAY=; b=MI4HjWD0BD589skXpdhC+Rc/hcJJ7+y+VSGIzPUuHxWBOsre2gaxTay9AI9HaIrece q3Bm2fGXUGscpNTcuzafTSSiKJx15eYMxU646QOk9bL2um8p/b/CClgxm3aXjC8X6s4+ DZQQM6L0pH0nYzaWvrh0QJxh8237rF/YaKDbmkbEAMXblDRKV+gM9LKT0m6speZkvl7E SjOBwg9Fmp0J2YSoqgnQGs58VepYxZSabSLDdXthd3UQW/WkpQ0tEH2vAjtCGGKx65R6 aV/if3dJfMRzkgsrZPTk05uZuSUiTtm4NqR99hDCES3yZJr+k48ZEngDoIEViga5Svhp 0zwA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gotplt.org header.s=dreamhost header.b="cWVDMOA/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f10-20020a05640214ca00b00499c02e381esi4167104edx.157.2023.01.24.13.54.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 13:54:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gotplt.org header.s=dreamhost header.b="cWVDMOA/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F33263858284 for ; Tue, 24 Jan 2023 21:54:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cyan.ash.relay.mailchannels.net (cyan.ash.relay.mailchannels.net [23.83.222.47]) by sourceware.org (Postfix) with ESMTPS id 579913858D1E for ; Tue, 24 Jan 2023 21:54:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 579913858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id EDA40201A41; Tue, 24 Jan 2023 21:54:10 +0000 (UTC) Received: from pdx1-sub0-mail-a306.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 80820201A62; Tue, 24 Jan 2023 21:54:10 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1674597250; a=rsa-sha256; cv=none; b=dIBX9IKeCU1BMu+CHvLMA02eX/qKGidg1IUvnpIVvLsaqAr8WIDScvJHPxWXLQ2isGJ2Rk ud6JqIb/0z5hI3vOECGJ7BUg2xc7D9GgEmeKHUwpeEwS9nLOypyHZWXQMcx5PAylhzfO9A +Xh+//Ttw3BB3Q4wBlwonbFdIsQ12wOSD4Ietp79oCRQngEGPW/NPZ+2XbnetcYS9YP002 tx5TKpu+itAUmSIPhBozL5ygv03SkDC7vgBB8/ksaF5TLDtYFwUOh3NZv1GDau+TQOAa92 n3zw7ltkXCOBBwIcSZLjfi8TA8KKs/BvrEWTYBu73ssMl8WfbTx6SSryOvoftQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1674597250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:dkim-signature; bh=a5MO3K76a32GvlGkB41MohB9DKCvghGvk4SzbgJzEAY=; b=BvxGvr1AtqwVG98bkP/Kix7ZxY9lmIspOVcExE15KvKKAczG5x4KYcDH4W5O59Z4d/X8Nk oj1vGiNKtUU3l1QllYqpSFeSYwkL7JfSaTb/Mfm0xrlckRHVskvSqYSEEgZH5xReYTiIfL FicomyhfC0NydogQnMSSugaOcJ3dJXuRkvN4lpzxo5Z0g4JO8F23a0F4pXtDwe0VWsaWDV g0Yoql/jRFyWwJbll6h6ce+bl9+kSWF88GxKkX2IMXLWX2HsoiYgJvkR9IzgUD/YwLpy01 J051EfDLsMhySHHStOglr7e/R2AhWgDBYnPFjDBKIChyxu32TY2coGa/WglrBA== ARC-Authentication-Results: i=1; rspamd-55978756d7-w5djg; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Obese-Fumbling: 5cc9f74e13b954b1_1674597250790_3190524840 X-MC-Loop-Signature: 1674597250790:3575255973 X-MC-Ingress-Time: 1674597250790 Received: from pdx1-sub0-mail-a306.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.196.199 (trex/6.7.1); Tue, 24 Jan 2023 21:54:10 +0000 Received: from fedora.redhat.com (bras-base-toroon4834w-grc-23-76-68-24-147.dsl.bell.ca [76.68.24.147]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a306.dreamhost.com (Postfix) with ESMTPSA id 4P1gjG07RjzDB; Tue, 24 Jan 2023 13:54:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1674597250; bh=a5MO3K76a32GvlGkB41MohB9DKCvghGvk4SzbgJzEAY=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=cWVDMOA/TgIaa5ColH2tOQjLatWfewY6PbQPVyRKQ0xXNWg8SVpcruaxpQoNBO3pQ 1BEyFQBKaxXLuOofs1ye8h0oA6R8daSqgpUHjedkeK13CGOjOrYtNSTJEJNhSs2Jjj EmQF+zpnS7VinIbhZYMQ3kweNvJW6j2SfNsEpmtYeiwmINM4u4DlgPqlnPg7zgrrrA POCD3XuA06MFi83meTpKvK0Z+GdV9XHPnwfPdqo+FhgJV0e9C7UvjBTQNHcEiVd1/f xSgXsTTzCtIxSv2SOCxOLWKEihdzKpZ9rBmF5cnQ9I5jdt7Bpjtsk6BLLdCf79H1gz b5b29p/jT2DoA== From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com Subject: [PATCH] tree-optimization/108522 Use COMPONENT_REF offset when available Date: Tue, 24 Jan 2023 16:54:00 -0500 Message-Id: <20230124215400.1345220-1-siddhesh@gotplt.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3037.1 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 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: , 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?1755942523708642221?= X-GMAIL-MSGID: =?utf-8?q?1755942523708642221?= Use the offset in TREE_OPERAND(component_ref, 2) when available instead of DECL_FIELD_OFFSET when trying to compute offset for a COMPONENT_REF. OK for gcc 13 and gcc 12? Co-authored-by: Jakub Jelinek gcc/ChangeLog: PR tree-optimization/108522 * tree-object-size.cc (compute_object_offset): Use TREE_OPERAND(ref, 2) for COMPONENT_REF when available. gcc/testsuite/ChangeLog: PR tree-optimization/108522 * builtin-dynamic-object-size-0.c (test_dynarray_struct_member): new test. (main): Call it. Signed-off-by: Siddhesh Poyarekar --- Testing: - Bootstrapped on x86_64, I'm checking to confirm if a couple of seemingly unrelated failures are in fact unrelated. - ubsan config bootstrap and i686 tests in progress .../gcc.dg/builtin-dynamic-object-size-0.c | 16 ++++++++++++++++ gcc/tree-object-size.cc | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c index f9047a037d9..569c0a87722 100644 --- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c +++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c @@ -314,6 +314,20 @@ test_dynarray_struct_subobj2 (size_t sz, size_t off, size_t *objsz) return __builtin_dynamic_object_size (&bin.c[off], 1); } +/* See pr #108522. */ +size_t +__attribute__ ((noinline)) +test_dynarray_struct_member (size_t sz) +{ + struct + { + char a[sz]; + char b; + } s; + + return __builtin_dynamic_object_size (&s.b, 0); +} + size_t __attribute__ ((noinline)) test_substring (size_t sz, size_t off) @@ -619,6 +633,8 @@ main (int argc, char **argv) if (test_dynarray_struct_subobj2 (42, 4, &objsz) != objsz - 4 - sizeof (long) - sizeof (int)) FAIL (); + if (test_dynarray_struct_member (42) != sizeof (char)) + FAIL (); if (test_substring_ptrplus (128, 4) != (128 - 4) * sizeof (int)) FAIL (); if (test_substring_ptrplus (128, 142) != 0) diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc index 356591c22cc..de93ffad9c9 100644 --- a/gcc/tree-object-size.cc +++ b/gcc/tree-object-size.cc @@ -412,7 +412,9 @@ compute_object_offset (const_tree expr, const_tree var) return base; t = TREE_OPERAND (expr, 1); - off = size_binop (PLUS_EXPR, DECL_FIELD_OFFSET (t), + off = size_binop (PLUS_EXPR, + (TREE_OPERAND (expr, 2) ? TREE_OPERAND (expr, 2) + : DECL_FIELD_OFFSET (t)), size_int (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (t)) / BITS_PER_UNIT)); break;