From patchwork Thu Jan 25 19:14:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 192259 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp199213dyb; Thu, 25 Jan 2024 11:15:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IF89mUiTr1U0vogZnWFh3c5TGzzzNcn3z4qGPhlRvqCA5PWSSo/KLGHV+cZaFioBEFMYayV X-Received: by 2002:ae9:c216:0:b0:783:bdb3:4e21 with SMTP id j22-20020ae9c216000000b00783bdb34e21mr176454qkg.117.1706210141706; Thu, 25 Jan 2024 11:15:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706210141; cv=pass; d=google.com; s=arc-20160816; b=KvkKdaKexah+OFsE+PEM/zL2vz1WlubmgQXkCpkk7ilHxOTjxSHsbKxY748kS3Ga0b V/bv+6FRa3MUfuLlTBcEE1JKoN+TiZ96M9p7pAgCZ8w72Y2e3TwG08FcegTmDcOH6Gt1 YNm5JsRfpk6vORNAzucRXMBvhz1YDn8jnLXYdsCeGtKztcuMtMgwdlWdGslKaKzqyuM6 mwof5Q8GEo+3bxlZ8hoq/EPZLc1pE7CXFYTMJFq6pDCihXjQSzlLr0PK9l5c+dN+m95e 2RVythrA+gOWvbO6TSy6xYaq0dnZmzYk/70cQ3l+IuUHwq+daaqzTeAdpBGKh29mrdI2 X1GQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=/n3UujiD1150iTuozDQyouNhWbWXNXt01YunXD03dSw=; fh=lVm2NyZN/MZSVbe6vWFZEpN3aGq/JctUZ2qgijG+iGg=; b=CF4ZUKQGs7OHmHKqBLDS9xBoOckORu+jtgLhzX040Jo4vNQN9cQo1HzUeXCXCcRbVa FNo0aqY33+eX1S49QLDOAXqbeccjTA9KcBFHNI9p2mRJBnjxcjFovlu4Czsbb2SExahu 60FysnSOiEVRhks3zlYwFijhvHv3KSv64C3seNx8efCFbfv5GxUOjHFnmNLwXZlOsCHA /qtPXF329lBXarsH2uZDsutjFzA44dfccQE00wmDb+fkZpeJpuviUns3KlwAZKjwWLmw TnKGcqOO7C6JxDxKVJ6dYAuIQ+zmk/2Z8d7nzrhIKY90yQfW8cDD/n8RMBHfFYCjZwEV aQ2A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bi19arhi; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b20-20020a05620a127400b00783ab4cabfesi6354682qkl.150.2024.01.25.11.15.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 11:15:41 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=Bi19arhi; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 658483858436 for ; Thu, 25 Jan 2024 19:15:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B312F3858C52 for ; Thu, 25 Jan 2024 19:15:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B312F3858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B312F3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706210103; cv=none; b=lZxs0xGZY86u+XID/f2B1N1FTUEonCEUfy1nEZAvoybPZuijeHPzLdjLKrmraBsh4r4GFCYhxNy6IgKr38igldezIHc/ulrzM4yOVKWQH/k51BeotZWz3aiwh2HQuHo4XkduS8ndztChpKe1DWqreAosBwa2FbdkbpN3KTeY6Jk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706210103; c=relaxed/simple; bh=tmIeG80/b6AxWiG/TUqYaq2ELAxrQRnHC/2WMG6ATKQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=ZcjummJySHVzuskN7hTrQmmBaqTmoceOXOisjzzdX9p0dvOhBe6xBnPIgt1dd++FQkw+dNVchuqjhW+/RPQ12F7liTbUHYTqt+nRi7bheCL8keFXn9XBUnNfYeXvfKSKUvTn6gj/p0QerG/x8X3+kutWmSaR9LgSmIPkLeCq9m4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706210101; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=/n3UujiD1150iTuozDQyouNhWbWXNXt01YunXD03dSw=; b=Bi19arhinNc7lRtPoaHQ1pPzL9L4nPuv0hAFZbktFjFJ1ldKuYp/OyCXCRPQZ0N3WP9ssl AcnoeknSsrU2iXl5TXujts3RDqcZQ921Pfmhzqs2qFTM1Rc1Lv4AhGIIFEp4T7RX0PTI7J OoJq0VFg8/ros6RbB2WheJs5SIjkDsk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-38-uyIDztneO6CBo_pRdxQweg-1; Thu, 25 Jan 2024 14:14:59 -0500 X-MC-Unique: uyIDztneO6CBo_pRdxQweg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9CE4D3C0BE45 for ; Thu, 25 Jan 2024 19:14:59 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 632E81121306; Thu, 25 Jan 2024 19:14:59 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 40PJEv6C3281125 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 20:14:57 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40PJEuTX3281124; Thu, 25 Jan 2024 20:14:56 +0100 Date: Thu, 25 Jan 2024 20:14:56 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, Patrick Palka Subject: [PATCH] c++: Fix up build_m_component_ref [PR113599] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789091005451524261 X-GMAIL-MSGID: 1789091005451524261 Hi! The following testcase reduced from GDB is miscompiled starting with r14-5503 PR112427 change. The problem is in the build_m_component_ref hunk, which changed - datum = fold_build_pointer_plus (fold_convert (ptype, datum), component); + datum = cp_convert (ptype, datum, complain); + if (!processing_template_decl) + datum = build2 (POINTER_PLUS_EXPR, ptype, + datum, convert_to_ptrofftype (component)); + datum = cp_fully_fold (datum); Component is e, (sizetype) e is 16, offset of c inside of C. ptype is A *, pointer to type of C::c and datum is &d. Now, previously the above created ((A *) &d) p+ (sizetype) e which is correct, but in the new code cp_convert sees that C has A as base class and instead of returning (A *) &d, it returns &d.D.2800 where D.2800 is the FIELD_DECL for the A base at offset 8 into C. So, instead of computing ((A *) &d) p+ (sizetype) e it computes &d.D.2800 p+ (sizetype) e, which is ((A *) &d) p+ 24. The following patch fixes it by using convert instead of cp_convert which eventually calls build_nop (ptype, datum). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-25 Jakub Jelinek PR c++/113599 * typeck2.cc (build_m_component_ref): Use convert instead of cp_convert for pointer conversion. * g++.dg/expr/ptrmem11.C: New test. Jakub --- gcc/cp/typeck2.cc.jj 2024-01-03 12:01:23.672476417 +0100 +++ gcc/cp/typeck2.cc 2024-01-25 14:11:40.656361310 +0100 @@ -2378,7 +2378,7 @@ build_m_component_ref (tree datum, tree /* Build an expression for "object + offset" where offset is the value stored in the pointer-to-data-member. */ ptype = build_pointer_type (type); - datum = cp_convert (ptype, datum, complain); + datum = convert (ptype, datum); if (!processing_template_decl) datum = build2 (POINTER_PLUS_EXPR, ptype, datum, convert_to_ptrofftype (component)); --- gcc/testsuite/g++.dg/expr/ptrmem11.C.jj 2024-01-25 14:13:11.736089567 +0100 +++ gcc/testsuite/g++.dg/expr/ptrmem11.C 2024-01-25 14:18:47.720398222 +0100 @@ -0,0 +1,17 @@ +// PR c++/113599 +// { dg-do run } + +struct A { void *a; }; +struct B { void *b; }; +struct C : public B, public A { A c; }; +static C d; + +int +main () +{ + A C::*e = &C::c; + A *f = &(d.*e); + A *g = &d.c; + if (f != g) + __builtin_abort (); +}