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.129.124]) by sourceware.org (Postfix) with ESMTPS id A07463858D33 for ; Fri, 10 Nov 2023 15:28:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A07463858D33 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 A07463858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699630087; cv=none; b=rV+XUI0uDiqICjo5ixRC15d/zDsjEH9WVkPcjUPWwBv4nI0joPDfe3LDnBXHQFuvSNf5GGeJ3IPUboplTzZXbXGBLlToiddRyuLija10/TQlZeFZMI+FRFU3rwyn7SAKoeXM18Tob/lyXhY6OmK27kYqKIl1VcGM45/N0+RI+dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699630087; c=relaxed/simple; bh=JUwZ4RyOVKxMFWmuiQ5NdAaAhcZG5vJe8Z/JunX5PJ8=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=gRhrZegQZCs++SGgu1N0M6WYGUYosq4cInkAwM4jXWCMn6NwvoqCfI5KRkhCJMyDLXmuemelhdBcWxivtFUmPwy/teccbXVnuKpUc9UpSrUfEQVD8td2lYsL7gQUc/CPorEcqcgkqzIkcb6eMcbcghGOou33DkpLFTfO7dIanVo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699630086; 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: in-reply-to:in-reply-to:references:references; bh=u6OVM/Wp4EvWwtyljOZOVA+km7zjLz7WoQFEMa3Tv+Y=; b=Wz8G5OxjAL3HGB25g7//oHsznxfLuA19aM0s3jHRgwqick2eIEcED5RDaUUwkR0nDqYP8b UC5ihqfUrBhnGeIOo1dGjKYzA9t++rGy5kVfrS0pg8SJL3bqIrfKDGhoe1+pO/hMymFFzB uqXLjyTXKhsqDg/hRuLbbRRTzf7mVjI= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-217-fSw8QSLrNlK1x1_IxCiTOQ-1; Fri, 10 Nov 2023 10:28:05 -0500 X-MC-Unique: fSw8QSLrNlK1x1_IxCiTOQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-66d03dcdc6bso24018526d6.1 for ; Fri, 10 Nov 2023 07:28:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699630084; x=1700234884; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u6OVM/Wp4EvWwtyljOZOVA+km7zjLz7WoQFEMa3Tv+Y=; b=Bfq1PcaVG0Ors4i+HMS1aquo37JaHgbPnKrXNzs5MEoq0QUQgrr4CyZ3MgAK4gAWe0 3cplp9RcbwPPMYpuV14kZREpnG9RMTSf3LaqicOLJW6v7sUpp42jJzNQ9AUjAeiTTv5H d/sTRBdP8YtN04kjBIGMAK2QzazgHrPkgZbtsN8MyE0Q6ITFyH5cqquXG0UJYDXfJ0JU /m+2Ty5msTy7w1GB7vAxDPgGdclVVF/1C3vkrjiChqA8cbP12fYV5Qv5p4Qe3oUQD9Rw wWrN8OWlfMdVpnPdxB71/yUIK/YmAjMn6O524UbOLaNO/d1ufMIt9ketxtjkRaf3ayjI Upmw== X-Gm-Message-State: AOJu0YzwpNzsFXNg4dQDY2VbbZf4S0F7HRzsMY+4yXEulI2LfQcOwrGJ eoGZ3OQazfaJAStxL5bWdRhAalmVtDluhioyav21yyqTzEDhgb53WNGzc6vXPYfBBnQJ/z4jo3G JrE/gQbspZ4vzCsFxbg== X-Received: by 2002:a05:6214:2482:b0:66d:93e:8c9d with SMTP id gi2-20020a056214248200b0066d093e8c9dmr9689819qvb.64.1699630084589; Fri, 10 Nov 2023 07:28:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFx5jHcbY9vj1NfKFwwoFbQDS7urnYkCon1AqLdl5aNygyiB1WZdH3q49QGCryVPgYqufeVDg== X-Received: by 2002:a05:6214:2482:b0:66d:93e:8c9d with SMTP id gi2-20020a056214248200b0066d093e8c9dmr9689805qvb.64.1699630084335; Fri, 10 Nov 2023 07:28:04 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id lg13-20020a056214548d00b0066cf06339bcsm2991268qvb.0.2023.11.10.07.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Nov 2023 07:28:04 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 10 Nov 2023 10:28:03 -0500 (EST) To: Patrick Palka cc: Jason Merrill , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: non-dependent .* folding [PR112427] In-Reply-To: Message-ID: <2fb218a2-713a-1a09-3c18-0f37ab359631@idea> References: <20231108215904.2779753-1-ppalka@redhat.com> <375a6726-8998-4b6b-830f-32852ef116b1@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.8 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_H4,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: On Fri, 10 Nov 2023, Patrick Palka wrote: > On Thu, 9 Nov 2023, Jason Merrill wrote: > > > On 11/8/23 16:59, Patrick Palka wrote: > > > 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)); > > > > We shouldn't need to build the POINTER_PLUS_EXPR at all in template context. > > OK with that change. > > Hmm, that seems harmless at first glance, but I noticed > build_min_non_dep (called from build_x_binary_op in this case) is > careful to propagate TREE_SIDE_EFFECTS of the given tree, and so eliding > POINTER_PLUS_EXPR here could potentially mean that the tree we > ultimately return from build_x_binary_op when in a template context has > TREE_SIDE_EFFECTS not set when it used to. Shall we still elide the > POINTER_PLUS_EXPR in a template context despite this? > > (The TREE_SIDE_EFFECTS propagation in build_min_non_dep was added in > r71108 to avoid bogus ahead of time -Wunused-value warnings. But then > r105273 later made us stop issuing -Wunused-value warnings ahead of time > altogether. So perhaps we don't need to maintain the TREE_SIDE_EFFECTS > flag on templated trees at all anymore?) IMO it'd be nice to restore ahead of time -Wunused-value warnings; it seems the original motivation for r105273 / PR8057 was to avoid redundantly issuing a warning twice, once ahead of time and once at instantiation time, which we now could do in a better way with warning_suppressed_p etc. If so, then IIUC eliding the POINTER_PLUS_EXPR could mean we'd incorrectly issue a -Wunused-value warning for e.g. 'a.*f()' in a template context? > > > > > Jason > > > > >