From patchwork Fri Sep 20 16:40:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 97769 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E177385C6C7 for ; Fri, 20 Sep 2024 16:41:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from buffalo.birch.relay.mailchannels.net (buffalo.birch.relay.mailchannels.net [23.83.209.24]) by sourceware.org (Postfix) with ESMTPS id 2C1FF385840B; Fri, 20 Sep 2024 16:40:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C1FF385840B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2C1FF385840B Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.209.24 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1726850450; cv=pass; b=SnKL/0Szn3R/NtVKruuPGtF6S87F3qhHU6wm22nm/BC5c3JYlJSDojJ7obI8ekQoKq1/KT675SfMwrluz1Q77Im2xzSdv0IIkFrqnIFoa4MPlQMV6xp5Zv9xVksOsMHKSv0yVeqoavV+4/I+FhkUi9Iyg7PR2rPqV6P5y4jIs1E= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1726850450; c=relaxed/simple; bh=1Trc7CEiHbWZuTP0X1xJwbLWoxBTF+lOiM8XmZ2IgIQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nTkcYDYhL4fAUAh21NqitViOX0jVMY9HqLevM690P7qygp3/ZX9ioh2ZdhWAlL9Xtp3K9gKBgnak53JiLdtWfH/o5a8CdOXnslY/dXLPLsCWaDgzlohWFeS+VrlKECBTipRHfmXks1n4jEpxSVjxr/q0Q3cbNF5+o5xalcuZBqI= ARC-Authentication-Results: i=2; server2.sourceware.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 31CAE16473B; Fri, 20 Sep 2024 16:40:46 +0000 (UTC) Received: from pdx1-sub0-mail-a312.dreamhost.com (trex-9.trex.outbound.svc.cluster.local [100.99.97.159]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id D9BD6164D95; Fri, 20 Sep 2024 16:40:45 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1726850445; a=rsa-sha256; cv=none; b=B2rtGZ1OLZRYC8mKYJJyYq7rNYiHa6wS3ON4nQEcnaghm5wvokUbcOsyS2Lb9qgxP402lr YMo6+N/M2flFhZX5E+heldqmn9JpIld/Km4z7WSlDnJVAqbvjlN6B8pN0XAmrRjU4y/IcV 4Q9PHQmWht1uVY8WzZgljChQsQ1bjfDiWLi9vsKpzPdv9/GLztzhHXGg8DCqJPpOAQs9st 5P3whjhKDJESNbwtlYfXRr5u/OlNM2MRUhpUXss5KoB5tinL8VUlZdLSnyDrdC4YW7xQCa +dFzFFtHmj6qKjr/WaXE+RS93ztobSa26+GzF2Ew6hgIAymHLLF1m3Co1iDA5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1726850445; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xJGGB6Hwxom4go72+H3/PeMKWPHXY41ITwxQ2wEar3g=; b=KLvCzax7xpY7DtwWZv23v00FAZV9RQb0LkZjobTGOYz3oCV+s3cN2Y+n9Z8t5SNgvrDmsn GLp+4w1Ti/yNZG2hFIQt1rRdiqoiQh+3FfvqXmDIA1w1vc5sxU2xSn7dF79884pqq1hrvB G2M5WwXIPCmCTOtho03uc105q0c4UqOKCAyxvrY/lZNK5zePxp1Mskw9CpebjY7YhbmHL8 j+Z1+84APPcvYVpgQaV4cIUHibo+UAjGCEEmbBvqrRaDeYEtR6zro60ok670zMV30nbr9n RJbM8RKIGqCaP2Cp0ai5HU8bVeN1/tuNfkUJ6RO2DKgqllumSrdc6g1vkDyH4A== ARC-Authentication-Results: i=1; rspamd-5b46bcd97f-lhx9s; 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-Desert-Wiry: 11e14d13547b4f25_1726850446105_872672388 X-MC-Loop-Signature: 1726850446105:1526565235 X-MC-Ingress-Time: 1726850446105 Received: from pdx1-sub0-mail-a312.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.99.97.159 (trex/7.0.2); Fri, 20 Sep 2024 16:40:46 +0000 Received: from fedora.redhat.com (bras-base-toroon4859w-grc-66-76-71-1-128.dsl.bell.ca [76.71.1.128]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a312.dreamhost.com (Postfix) with ESMTPSA id 4X9J6P3rpyzTP; Fri, 20 Sep 2024 09:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1726850445; bh=xJGGB6Hwxom4go72+H3/PeMKWPHXY41ITwxQ2wEar3g=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=nFZBIZyMPAw+ve4710aFfo9Ratu8NRlclOrevrLoxWUgQUg8zQ1yr9xpkJ7k1TO0x YudCuv/twEUkxOhK/VtoYoXOayUPKMr9SPWqbvZ4JpII59MNVuQkWGtU3yeObQ/QQj sTWQyzaSKqCEHULJ2dz0Kf3t5TWlplVPsZ2hmCXyr+UvM2bTxFeVA+redBf/BOwLpX x+b9FmAVLB1TMiSKbesx4kkgluPzoA9qEnwbvohsdmyss3/0z9490pWf9j1f/DiMeg lE04oVitAdkY+PJzwi2AEnDCyFpTvOxt/D2FoussIW7Y6ishgJ89qtPPrZhiwlAgRQ hXZRZL6HqZpbA== From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Cc: pinskia@gcc.gnu.org Subject: [PATCH v2 1/4] tree-object-size: use size_for_offset in more cases Date: Fri, 20 Sep 2024 12:40:26 -0400 Message-ID: <20240920164029.63843-2-siddhesh@gotplt.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240920164029.63843-1-siddhesh@gotplt.org> References: <20240914123049.2746225-1-siddhesh@gotplt.org> <20240920164029.63843-1-siddhesh@gotplt.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3036.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org When wholesize != size, there is a reasonable opportunity for static object sizes also to be computed using size_for_offset, so use that. gcc/ChangeLog: * tree-object-size.cc (plus_stmt_object_size): Call SIZE_FOR_OFFSET for some negative offset cases. * testsuite/gcc.dg/builtin-object-size-3.c (test9): Adjust test. * testsuite/gcc.dg/builtin-object-size-4.c (test8): Likewise. --- gcc/testsuite/gcc.dg/builtin-object-size-3.c | 6 +++--- gcc/testsuite/gcc.dg/builtin-object-size-4.c | 6 +++--- gcc/tree-object-size.cc | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-3.c b/gcc/testsuite/gcc.dg/builtin-object-size-3.c index 3f58da3d500..ec2c62c9640 100644 --- a/gcc/testsuite/gcc.dg/builtin-object-size-3.c +++ b/gcc/testsuite/gcc.dg/builtin-object-size-3.c @@ -574,7 +574,7 @@ test9 (unsigned cond) if (__builtin_object_size (&p[-4], 2) != (cond ? 6 : 10)) FAIL (); #else - if (__builtin_object_size (&p[-4], 2) != 0) + if (__builtin_object_size (&p[-4], 2) != 6) FAIL (); #endif @@ -585,7 +585,7 @@ test9 (unsigned cond) if (__builtin_object_size (p, 2) != ((cond ? 2 : 6) + cond)) FAIL (); #else - if (__builtin_object_size (p, 2) != 0) + if (__builtin_object_size (p, 2) != 2) FAIL (); #endif @@ -598,7 +598,7 @@ test9 (unsigned cond) != sizeof (y) - __builtin_offsetof (struct A, c) - 8 + cond) FAIL (); #else - if (__builtin_object_size (p, 2) != 0) + if (__builtin_object_size (p, 2) != sizeof (y) - __builtin_offsetof (struct A, c) - 8) FAIL (); #endif } diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-4.c b/gcc/testsuite/gcc.dg/builtin-object-size-4.c index b3eb36efb74..7bcd24c4150 100644 --- a/gcc/testsuite/gcc.dg/builtin-object-size-4.c +++ b/gcc/testsuite/gcc.dg/builtin-object-size-4.c @@ -482,7 +482,7 @@ test8 (unsigned cond) if (__builtin_object_size (&p[-4], 3) != (cond ? 6 : 10)) FAIL (); #else - if (__builtin_object_size (&p[-4], 3) != 0) + if (__builtin_object_size (&p[-4], 3) != 6) FAIL (); #endif @@ -493,7 +493,7 @@ test8 (unsigned cond) if (__builtin_object_size (p, 3) != ((cond ? 2 : 6) + cond)) FAIL (); #else - if (__builtin_object_size (p, 3) != 0) + if (__builtin_object_size (p, 3) != 2) FAIL (); #endif @@ -505,7 +505,7 @@ test8 (unsigned cond) if (__builtin_object_size (p, 3) != sizeof (y.c) - 8 + cond) FAIL (); #else - if (__builtin_object_size (p, 3) != 0) + if (__builtin_object_size (p, 3) != sizeof (y.c) - 8) FAIL (); #endif } diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc index 6544730e153..f8fae0cbc82 100644 --- a/gcc/tree-object-size.cc +++ b/gcc/tree-object-size.cc @@ -1527,7 +1527,7 @@ plus_stmt_object_size (struct object_size_info *osi, tree var, gimple *stmt) if (size_unknown_p (bytes, 0)) ; else if ((object_size_type & OST_DYNAMIC) - || compare_tree_int (op1, offset_limit) <= 0) + || bytes != wholesize || compare_tree_int (op1, offset_limit) <= 0) bytes = size_for_offset (bytes, op1, wholesize); /* In the static case, with a negative offset, the best estimate for minimum size is size_unknown but for maximum size, the wholesize is a