From patchwork Fri Nov 4 09:27:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 15434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp274496wru; Fri, 4 Nov 2022 02:29:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM508eIjG5AbqPF18RKYWd1AydhLdR884n3H9JOoLP7jRS9VsrTRomPSBH+3YgReOlX5/LHQ X-Received: by 2002:a17:907:728c:b0:78e:2856:7fed with SMTP id dt12-20020a170907728c00b0078e28567fedmr34060800ejc.2.1667554159115; Fri, 04 Nov 2022 02:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667554159; cv=none; d=google.com; s=arc-20160816; b=SgXZ1KHW/ZFhY7VhpniiPUemqWSZ5ZfQiudc1/WrdiaiTAc0bI/4xZYMYBGwX0CNfJ wC4tP4uJ1Q61ISUmEuYznL1hrBgoEbQpOnwbRFdf23KROXp6AOZCMmkKBS2xOc8vSDBv cDH4U6DKP5HF5mv/pWl6LwyjkGiqTyvLi9qHzjTXHr1g9LjY412RF3jbawpeyyz9Ia46 UOXOWRqzFJzPtdNk+rkYBIuOiVYBYD53E7oxnXoV1K2sJGIuvLRD7B4gWmnEKq/IGSEW JMIQcviTdOfBM6/ze1MyizQCayVD5yykcoM1lJJbQjUjOhO/QP00ivLko6QQqFX9WBmz /deg== 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:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=7vpfzUqeF3ZkpAh4f/ZbAPTSG57a50t22pgtlmBSFo8=; b=IuwdnpPVl6hn8MIdEgnxM5erEgJzAuF4EjH36ojVbbjWvZYF4yHLxrj7cTbaMkwQfA JTTV30Q7nxbR8WmzW65Nz6FR4T43ZqMP3z3dV1PahaAKu+KZggeAzTIf6zsTj3zapnr7 xPHwnZoNAS/jLYAvDqsKZR2z+a7Ub0NZ7Z07nM+QJTLbhDFk+S1/1Qkmrt0MomR1DrCn GxVuOrnDePhbXWq5/tzMPGhxrNfTZi8X9lP9goJZYXwP8WY2MKVd3dheCAVYlPfPAdEo BbOuZiW08tHO3jB+bG+NZk/7hUou9BsSEz5cMvA1a/49P1ErmBAaHyJ97LDGsszoCmJh VDzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QyQzqe5R; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h30-20020a0564020e9e00b00461ebe2a168si4075247eda.447.2022.11.04.02.29.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 02:29:19 -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=QyQzqe5R; 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 A21A8385802A for ; Fri, 4 Nov 2022 09:29:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A21A8385802A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667554148; bh=7vpfzUqeF3ZkpAh4f/ZbAPTSG57a50t22pgtlmBSFo8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QyQzqe5RQNOtHzXx25ky9s+gIkPSRLsMu2gxlBoptLDH4qGGYMwBvhl1mTpyz2eFg ZoSCO71vUST6EhKnOpw4qyDJYiv1df16HxiS7Pl5gh3I3S4kwnIopuL0gBgRpPeK/O 4En1nsoTrjc2YYBETV4E+6xUf9SUK/pRuIDg3z3Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 00C2F385843F for ; Fri, 4 Nov 2022 09:28:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 00C2F385843F Received: by mail-wr1-x42f.google.com with SMTP id o4so6220319wrq.6 for ; Fri, 04 Nov 2022 02:28:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7vpfzUqeF3ZkpAh4f/ZbAPTSG57a50t22pgtlmBSFo8=; b=4F7xGV0d7154xmsN72+DFai34LRHVt8iYgyKGHa5u/FyCE9vlKC8EXIxhMdMer1nkY bScYQxEdTOUeOa4GkhTyFUFqoR1qy/5YJZXa0GXYCW+uixY9By/46f3bEhUCv4E42boz tYhPzM4gAWbg1/coKcnoTPPF0InXSZcMjVqp9XaX1IRCtfU5ETcgJem8f9g1Tp+xQ3ct V2B0DGrI2ZjGPyQ+ExCaqTZQgH15LXxiZghA5mQZZTjxUkP8vIEaECHLfUXSwSoWwYLY Q45ys2MsqLtl5EZB5CCX1O+nuNHSPXKXAGQ1Avv8H0uJTQypLb7YuoT8EKM8Jz1LSmUz I4vg== X-Gm-Message-State: ACrzQf1GHg7biNgJwjPpA2vQOHFskALSkFjUydnJaT3uTS8qy+wUZagO 0edD0sroQ+RrsxWbnJKDFW/NwDpPgdChQA== X-Received: by 2002:a05:6000:16c8:b0:236:c60d:22b9 with SMTP id h8-20020a05600016c800b00236c60d22b9mr18026369wrf.526.1667554100658; Fri, 04 Nov 2022 02:28:20 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id by13-20020a056000098d00b002383edcde09sm3034231wrb.59.2022.11.04.02.28.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 02:28:19 -0700 (PDT) X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix recent thinko in operand_equal_p Date: Fri, 04 Nov 2022 10:27:23 +0100 Message-ID: <7447720.EvYhyI6sBW@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 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: , X-Patchwork-Original-From: Eric Botcazou via Gcc-patches From: Eric Botcazou Reply-To: Eric Botcazou 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?1748557270121108945?= X-GMAIL-MSGID: =?utf-8?q?1748557270121108945?= Hi, there is a thinko in the recent improvement by Jan: 2020-11-19 Jan Hubicka * fold-const.c (operand_compare::operand_equal_p): Fix thinko in COMPONENT_REF handling and guard types_same_for_odr by virtual_method_call_p. (operand_compare::hash_operand): Likewise. where the code just looks at operand 2 of COMPONENT_REF, if it is present, to compare addresses. That's wrong because operand 2 contains the number of DECL_OFFSET_ALIGN-bit-sized words so, when DECL_OFFSET_ALIGN > 8, not all the bytes are included and some of them are in DECL_FIELD_BIT_OFFSET instead, see get_inner_reference for the model computation. In other words, you would need to compare operand 2 and DECL_OFFSET_ALIGN and DECL_FIELD_BIT_OFFSET in this situation, but I'm not sure this is worth the hassle in practice so the attached fix just removes this alternate handling. Tested on x86-64/Linux, OK for mainline, 12 and 11 branches? 2022-11-04 Eric Botcazou * fold-const.cc (operand_compare::operand_equal_p) : Do not take into account operand 2. (operand_compare::hash_operand) : Likewise. 2022-11-04 Eric Botcazou * gnat.dg/opt99.adb: New test. * gnat.dg/opt99_pkg1.ads, gnat.dg/opt99_pkg1.adb: New helper. * gnat.dg/opt99_pkg2.ads: Likewise. diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 9f7beae14e5..e7a9d5215a5 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -3351,9 +3351,6 @@ operand_compare::operand_equal_p (const_tree arg0, const_tree arg1, if (compare_address && (flags & OEP_ADDRESS_OF_SAME_FIELD) == 0) { - if (TREE_OPERAND (arg0, 2) - || TREE_OPERAND (arg1, 2)) - return OP_SAME_WITH_NULL (2); tree field0 = TREE_OPERAND (arg0, 1); tree field1 = TREE_OPERAND (arg1, 1); @@ -3864,17 +3861,10 @@ operand_compare::hash_operand (const_tree t, inchash::hash &hstate, if (sflags & OEP_ADDRESS_OF) { hash_operand (TREE_OPERAND (t, 0), hstate, flags); - if (TREE_OPERAND (t, 2)) - hash_operand (TREE_OPERAND (t, 2), hstate, - flags & ~OEP_ADDRESS_OF); - else - { - tree field = TREE_OPERAND (t, 1); - hash_operand (DECL_FIELD_OFFSET (field), - hstate, flags & ~OEP_ADDRESS_OF); - hash_operand (DECL_FIELD_BIT_OFFSET (field), - hstate, flags & ~OEP_ADDRESS_OF); - } + hash_operand (DECL_FIELD_OFFSET (TREE_OPERAND (t, 1)), + hstate, flags & ~OEP_ADDRESS_OF); + hash_operand (DECL_FIELD_BIT_OFFSET (TREE_OPERAND (t, 1)), + hstate, flags & ~OEP_ADDRESS_OF); return; } break;