From patchwork Tue Jun 14 15:26:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1643332 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=ZHfjrVvW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LMskF25KTz9tkV for ; Wed, 15 Jun 2022 01:27:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D311385C32E for ; Tue, 14 Jun 2022 15:27:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from antelope.elm.relay.mailchannels.net (antelope.elm.relay.mailchannels.net [23.83.212.4]) by sourceware.org (Postfix) with ESMTPS id 1CA97385C306 for ; Tue, 14 Jun 2022 15:26:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1CA97385C306 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 491CC6A2877; Tue, 14 Jun 2022 15:26:56 +0000 (UTC) Received: from pdx1-sub0-mail-a304.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A2E5F6A277F; Tue, 14 Jun 2022 15:26:55 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1655220415; a=rsa-sha256; cv=none; b=xo52avRotoIedw5SgH6FgxMkTg8FCU1UaAgutbifAb9alD63ef7ervN/5zBpOR8ZVnojRZ NloojmQh33OGYpVA8hBqTH/p5eDtFVxJvIz012XHKN7cw0k0Hn14OndvA8vuO1P3wr2sNh LaKy59ZbFWUsHsjhnsZ3mzG23YMI08B86ZWPCJ+JNA7gEzPhZ59KlChapFgaBTH0z2mrG0 V+s5CxvOkshLzQX8DnhslXZNxwB9n5QwPruVVzqqqj2r0m7/N//2SPYHAGgNooI2Rt4Sdp 6bAx27ChRAWj6dzhzERoA/TZhPY7NQylEDSuEu7QyRZgKL6jQG+29a8Cv0EjaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1655220415; 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=A2aO0e1YjgcLDumhjZDUia/Q1qz7iuaQO9at/bf9g/4=; b=3ozpabphJhVS95/tUXnnNlTnphnRrPWJ3GjitVKNYWO3rxhT3fAqUdPIWPE7gtkj5iMwep AnPjIZgKMvOfau2YtQoqY3YA7Jg9XaN2Zy5d66wwWwzGx5LsAaz6OeDWdEPZa2qQXnKqPB rgnbuIDM9rxVP8phU1enL8Tzj9LVZhWJBBzTwOZKHVt/hOuzcMWe33dNhlMd+vsykPiE7r yxo8Dp5bxPumu+viFxhMrkzA0fABzbT1zrxihRPqdNN4b1Y23MVEI+kZO7migxV7QGP5Bd o0JYP6n6ccVdz//U/MwABFknCOz6aefysAJ3Atu2jrxbnhP8Uv1dQMSZNo1yBg== ARC-Authentication-Results: i=1; rspamd-848669fb87-s5wqc; 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-Skirt-Drop: 1722b645255cf20f_1655220416087_3873340111 X-MC-Loop-Signature: 1655220416087:369095570 X-MC-Ingress-Time: 1655220416087 Received: from pdx1-sub0-mail-a304.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.115.45.51 (trex/6.7.1); Tue, 14 Jun 2022 15:26:55 +0000 Received: from rhbox.redhat.com (unknown [1.186.122.115]) (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-a304.dreamhost.com (Postfix) with ESMTPSA id 4LMsjn5RCKz4r; Tue, 14 Jun 2022 08:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1655220415; bh=A2aO0e1YjgcLDumhjZDUia/Q1qz7iuaQO9at/bf9g/4=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=ZHfjrVvWJ1+LPygwjlQadfb1KbxHAPe3HvD1NPAtZ0awAWc4FesisVu6KKCU5OFEC 89LIzd3yG8548f3Zh+U2YCy03pSxBAOy51frNevbfMyRtJC4UaTPw6Ag13sjcTIBp7 i6LCjNugjQOva6l0DA4jUH8zo65K4+LpYIebFu6Rsnx4LRMmb9pIlWv0gRxYibxMCq Vw9gbp+yUjozLrpPgnQthm8OgbblM2As9/ZMyTivYkFXyWBSYhEM1cpgmAmJV5h6vu 7Eq3HGt0qRh/OAonOzitw7nozGUomCTGz5vhQnxWDUC/DIf9ReAjtbsEH9ysaZR282 bpedXFxxmeVRQ== From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/105736: Don't let error_mark_node escape for ADDR_EXPR Date: Tue, 14 Jun 2022 20:56:46 +0530 Message-Id: <20220614152646.357680-1-siddhesh@gotplt.org> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-3037.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , Cc: jakub@redhat.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The addr_expr computation does not check for error_mark_node before returning the size expression. This used to work in the constant case because the conversion to uhwi would end up causing it to return size_unknown, but that won't work for the dynamic case. Modify the control flow to explicitly return size_unknown if the offset computation returns an error_mark_node. gcc/ChangeLog: PR tree-optimization/105736 * tree-object-size.cc (addr_object_size): Return size_unknown when object offset computation returns an error. gcc/testsuite/ChangeLog: PR tree-optimization/105736 * gcc.dg/builtin-dynamic-object-size-0.c (TV4, val3, test_pr105736): New struct declaration, variable and function to test PR. (main): Use them. Signed-off-by: Siddhesh Poyarekar --- Tested: - x86_64 bootstrap and test - --with-build-config=bootstrap-ubsan build May I also backport this to gcc12? .../gcc.dg/builtin-dynamic-object-size-0.c | 19 ++++++++++++++++++ gcc/tree-object-size.cc | 20 ++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) 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 b5b0b3a677c..90f303ef40e 100644 --- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c +++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c @@ -479,6 +479,20 @@ test_loop (int *obj, size_t sz, size_t start, size_t end, int incr) return __builtin_dynamic_object_size (ptr, 0); } +/* Other tests. */ + +struct TV4 +{ + __attribute__((vector_size (sizeof (int) * 4))) int v; +}; + +struct TV4 val3; +int * +test_pr105736 (struct TV4 *a) +{ + return &a->v[0]; +} + unsigned nfails = 0; #define FAIL() ({ \ @@ -633,6 +647,11 @@ main (int argc, char **argv) FAIL (); if (test_loop (arr, 42, 20, 52, 1) != 0) FAIL (); + /* pr105736. */ + int *t = test_pr105736 (&val3); + if (__builtin_dynamic_object_size (t, 0) != -1) + __builtin_abort (); + if (nfails > 0) __builtin_abort (); diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc index 5ca87ae3504..12bc0868b77 100644 --- a/gcc/tree-object-size.cc +++ b/gcc/tree-object-size.cc @@ -695,19 +695,21 @@ addr_object_size (struct object_size_info *osi, const_tree ptr, var_size = pt_var_size; bytes = compute_object_offset (TREE_OPERAND (ptr, 0), var); if (bytes != error_mark_node) - bytes = size_for_offset (var_size, bytes); - if (var != pt_var - && pt_var_size - && TREE_CODE (pt_var) == MEM_REF - && bytes != error_mark_node) { - tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0), pt_var); - if (bytes2 != error_mark_node) + bytes = size_for_offset (var_size, bytes); + if (var != pt_var && pt_var_size && TREE_CODE (pt_var) == MEM_REF) { - bytes2 = size_for_offset (pt_var_size, bytes2); - bytes = size_binop (MIN_EXPR, bytes, bytes2); + tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0), + pt_var); + if (bytes2 != error_mark_node) + { + bytes2 = size_for_offset (pt_var_size, bytes2); + bytes = size_binop (MIN_EXPR, bytes, bytes2); + } } } + else + bytes = size_unknown (object_size_type); wholebytes = object_size_type & OST_SUBOBJECT ? var_size : pt_var_wholesize;