From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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 (); +} Jakub