From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x42f.google.com with SMTP id o4so6220319wrq.6 for ; Fri, 04 Nov 2022 02:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=7vpfzUqeF3ZkpAh4f/ZbAPTSG57a50t22pgtlmBSFo8=; b=WS8oM14m50fwhHlEZE87vKqrjKadHy4dRjTnV7uiIB5wErdIUAE1nL50frm+zxW0o0 S6baaljao+o9BxMJJmtrmrdgB2fmkh5qoqRykPKYFWkt67e8GDqJwRl3FfTNgmmJSrmy k4tm0pOm44AbqDA4NtAApMGDa/X6lmFus7JPt5uVE+5ebheWL4f6rDVS1jFgDklWaY0S tzcSarbyKTzGwaRknNW+4jzJHfcGLOfdd7uqztPxosPF5c4wKb/ohpYTm25ohfRCecuB auPqplt7bT5Q+0H3Lm1cHnadflkmALrCAFwWwP+MmmtdTlZrF7iz+Wrm8oiCUMcDPcef mwNg== 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-Google-Smtp-Source: AMsMyM5Ftti2hqmpzwftOQEBheXAabt1sAE+uKFyEqfBRZ+fPOrvP0/6VWVnOsJ7b2vQo9NeNO/ypg== 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) From: Eric Botcazou 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 Content-Type: multipart/mixed; boundary="nextPart3700742.kQq0lBPeGt" Content-Transfer-Encoding: 7Bit 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 List-Id: This is a multi-part message in MIME format. --nextPart3700742.kQq0lBPeGt Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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. -- Eric Botcazou --nextPart3700742.kQq0lBPeGt Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="p.diff" 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; --nextPart3700742.kQq0lBPeGt Content-Disposition: attachment; filename="opt99.adb" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="UTF-8"; name="opt99.adb" -- { dg-do run } -- { dg-options "-O" } with Opt99_Pkg1; use Opt99_Pkg1; procedure Opt99 is C : constant My_Character := (D => True, C => ' '); D : Derived; begin Set (D, C, C); if not D.C2.D then raise Program_Error; end if; end; --nextPart3700742.kQq0lBPeGt Content-Disposition: attachment; filename="opt99_pkg1.adb" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="UTF-8"; name="opt99_pkg1.adb" package body Opt99_Pkg1 is procedure Set (D: in out Derived; C1, C2 : My_Character) is begin D.I := 0; D.C1 := C1; D.C2 := C2; end; end Opt99_Pkg1; --nextPart3700742.kQq0lBPeGt Content-Disposition: attachment; filename="opt99_pkg2.ads" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="UTF-8"; name="opt99_pkg2.ads" package Opt99_Pkg2 is function Get_Max return Positive is (4); C : constant Positive := Get_Max; type Arr is array (1 .. C) of Integer; type Root is tagged record Data : Arr; end record; end Opt99_Pkg2; --nextPart3700742.kQq0lBPeGt Content-Disposition: attachment; filename="opt99_pkg1.ads" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="UTF-8"; name="opt99_pkg1.ads" with Opt99_Pkg2; package Opt99_Pkg1 is type My_Character (D : Boolean := False) is record case D is when False => null; when True => C : Character; end case; end record; type Derived is new Opt99_Pkg2.Root with record I : Integer; C1, C2 : My_Character; end record; procedure Set (D: in out Derived; C1, C2 : My_Character); end Opt99_Pkg1; --nextPart3700742.kQq0lBPeGt--