From patchwork Wed Nov 8 21:59:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 163174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp67107vqs; Wed, 8 Nov 2023 13:59:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtT5zBfDWy2G5HSJ06Ctm5sOin4zb89M7PlyEPDYVjbjk8djSVRNMZCeHjWcq1NZWMFAb/ X-Received: by 2002:a1f:12d7:0:b0:4ac:174d:4d3d with SMTP id 206-20020a1f12d7000000b004ac174d4d3dmr3095368vks.2.1699480775642; Wed, 08 Nov 2023 13:59:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699480775; cv=pass; d=google.com; s=arc-20160816; b=kN2gda98Vwq7fYJs1bzDqTys2dYqUXCLetf2Vo61vC5Da85ocagxGrlYtO+z5U5BxB tvebzz5tU7tGie6AMOXlYCUq4kN4UVzDd3yAOWtwvrhKMG0EWlF6dA+OqyHNtFO7IgAn J5R+6KPXtPVd3V1Kfb1jym0w+o8BCPVfLyx4R99ph/TtOaWIWssVAvSqY+E7nri2KzLr /3k2mDV9pq582nZblMkN2ZWqHoLaomI2bgZIg9DqbVafDuvqlRescqxi2hQo2Q3BMN3S OOtk+uEtWXNV7KUnxeUugp4R2bv2J3aJ9CcBexplusQ+L//4Kll4r5j78MeVO2RnY0q7 2/DQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=jKOQ57Hk76j5QJmyYbWbClCHhvJEhi00B4tt7YCJiQE=; fh=1Hi9m88IqcWZGtfSxUrMGG+GBgL26N02X1SANXM6iTs=; b=CmcaaZEp9wAnKkI3lCRqQfXDsBX+2+guLqfe4HVXqym1uWtUxQ4lIqJl/AAUWnMZj5 Iir4KT4ZFqHBUr7NQqyFqiE9YGjjg00KBUYWCstbOR4W/ypqOg8xB014r7z1GUILrkwx 3rGGneFpgNx+tcHl8Ob5NWuzQj8YHN/bsdY/4q6CsUlcgBHGRPWI52P8A1RuXgJrUb/O GxKG+tV1EEByCXQykFD/3PKqBcz8NqQ7lHGOBOcybCz6URoom3mTXH4dg980WZrnuBBO 9KkBntBqvuqOZA/xSGDrrJEfIajQEK5q281Cj3zCVzQACUju6KBtSr/9IpsgtCBIw1UR zjKA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XZnASkAJ; 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 b2-20020ac85bc2000000b004032d91e8b7si1973382qtb.295.2023.11.08.13.59.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 13:59:35 -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=XZnASkAJ; 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 6759E3861938 for ; Wed, 8 Nov 2023 21:59:35 +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 38F313858D1E for ; Wed, 8 Nov 2023 21:59:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 38F313858D1E 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 38F313858D1E 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=1699480751; cv=none; b=OMzyusbBGSe4YlnnZVb/VFrJKb3k8aqrKH9DBy9UWfCB53FCR3deYqEwUr2L+ImHwnDPDcc1Y8+aHB1Q1GaMlIPUzN+9afrxjXIw9iYfc902yR5fl6H/HhOqvJFUyFGoe9e/taXjF++TsNgXDyHKMnstLfA0zIe3Uc9/RfUGNDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699480751; c=relaxed/simple; bh=Y8S3l1oSOkxW47Fs/Fu6OpiVRfSnCk4Xo2tFT0DXAUI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GQu6EoGcERGGXEsuZ/lBe9WgzNDBbIKbIQ2qsd5fnnHX22HjQdxj16+raCDrZ7LDWt7GcFUZ8kefroB+3bBLod8tNn8tqRQyOVUpc0VVoyChMi/gOmicmpYUvx11glXA39x1TeyZ07PMTpnY0RDqFB7letJtfY5Sq84z3kwochc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699480749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jKOQ57Hk76j5QJmyYbWbClCHhvJEhi00B4tt7YCJiQE=; b=XZnASkAJ1iVE8SK3wrN1gx5UK6yjQNGC7D55yIG5MfhbQWaWpFGWun/LNeIhsiIqqneyLJ qo17Pg6GyImZXINSmjdQ+qUjdy79G7kRWdwxAEU1llz7DGi1ujvxm5z9rOSd74JG02jJJ9 ofByqkE4HrT1CGtTX1NdebY5JPlPUcQ= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-eE2ycjlSMjmgd31XynFvmw-1; Wed, 08 Nov 2023 16:59:08 -0500 X-MC-Unique: eE2ycjlSMjmgd31XynFvmw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-66d0b251a6aso2196616d6.2 for ; Wed, 08 Nov 2023 13:59:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699480747; x=1700085547; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jKOQ57Hk76j5QJmyYbWbClCHhvJEhi00B4tt7YCJiQE=; b=koVki7lTcQePATOCCQpNd/cemWcLe5tAZrOeYt+WVG8rGrslGPrWA7ReJfaM8xQFUl NoYClaFjvuTk/rI/cu+HId0k7CDyDrl2QzEnRcqbz9xhhjwc52RzxzM/5F2mt+XaxJwC xtg9BL0Fi5z97GLPpk0e7tiUkybAk27swei1Fr4ePVUxy3dDNIKW2XdLIzZQoYqXvHZF QDlQXwvV0AY+688lUjatFlJGya74GJR85w2jkIdhtsIU3f916iT7uKmjldBK8B0wXRj0 72SIAGgs3fhmae+yC3DYzbOdRSPKHB41JH7ULiLMhD7+EQWrxXtOOBqjOexgSOuTyh5u LzpA== X-Gm-Message-State: AOJu0Yw1Stba7QhscLUzaBt0Z2cpiHYAEZNZgwbnXGkHQW9AVpxRfWcY utyiEIEkVohEjhSDQOZgUz7JXN4Q7HC565TYIobiCAQkO92VeieACYzkR5Sy9g4MPbs0H/MEEeA ZXAZ068r7FIyCkg5zOVCXHLDsIqfa3qTRQvDYAty2JC9C4HEkt0zE9VK1dbo8PqIc8c78gh3oCV o= X-Received: by 2002:a05:622a:494:b0:403:a91f:7b79 with SMTP id p20-20020a05622a049400b00403a91f7b79mr3535593qtx.20.1699480746894; Wed, 08 Nov 2023 13:59:06 -0800 (PST) X-Received: by 2002:a05:622a:494:b0:403:a91f:7b79 with SMTP id p20-20020a05622a049400b00403a91f7b79mr3535583qtx.20.1699480746627; Wed, 08 Nov 2023 13:59:06 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id d9-20020ac86689000000b0041811e71890sm1326416qtp.33.2023.11.08.13.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 13:59:06 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: non-dependent .* folding [PR112427] Date: Wed, 8 Nov 2023 16:59:04 -0500 Message-ID: <20231108215904.2779753-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.rc1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782034753776737062 X-GMAIL-MSGID: 1782034753776737062 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here when building up the non-dependent .* expression, we crash from fold_convert on 'b.a' due to this (templated) COMPONENT_REF having an IDENTIFIER_NODE instead of FIELD_DECL operand that middle-end routines expect. Like in r14-4899-gd80a26cca02587, this patch fixes this by replacing the problematic piecemeal folding with a single call to cp_fully_fold. PR c++/112427 gcc/cp/ChangeLog: * typeck2.cc (build_m_component_ref): Use cp_convert, build2 and cp_fully_fold instead of fold_build_pointer_plus and fold_convert. gcc/testsuite/ChangeLog: * g++.dg/template/non-dependent29.C: New test. --- gcc/cp/typeck2.cc | 5 ++++- gcc/testsuite/g++.dg/template/non-dependent29.C | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/non-dependent29.C diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc index 309903afed8..208004221da 100644 --- a/gcc/cp/typeck2.cc +++ b/gcc/cp/typeck2.cc @@ -2378,7 +2378,10 @@ build_m_component_ref (tree datum, tree component, tsubst_flags_t complain) /* Build an expression for "object + offset" where offset is the value stored in the pointer-to-data-member. */ ptype = build_pointer_type (type); - datum = fold_build_pointer_plus (fold_convert (ptype, datum), component); + datum = cp_convert (ptype, datum, complain); + datum = build2 (POINTER_PLUS_EXPR, ptype, + datum, convert_to_ptrofftype (component)); + datum = cp_fully_fold (datum); datum = cp_build_fold_indirect_ref (datum); if (datum == error_mark_node) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/template/non-dependent29.C b/gcc/testsuite/g++.dg/template/non-dependent29.C new file mode 100644 index 00000000000..41bd11ae6b4 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent29.C @@ -0,0 +1,13 @@ +// PR c++/112427 + +struct A { int m; void f(); }; +struct B { A a; }; + +template +void f(B b) { + int A::*pd = &A::m; + b.a.*pd; + + void (A::*pf)() = &A::f; + (b.a.*pf)(); +}