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: 1731451 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gotplt.org header.i=@gotplt.org header.a=rsa-sha256 header.s=dreamhost header.b=cWVDMOA/; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P1gjk0qlDz23gM for ; Wed, 25 Jan 2023 08:54:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A2B53858439 for ; Tue, 24 Jan 2023 21:54:28 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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;