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 129E93858D1E for ; Fri, 10 Nov 2023 21:36:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 129E93858D1E 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 129E93858D1E 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=1699652203; cv=none; b=FIz+6OFBOxkrVEMqEj6ekt7NhKek6fhUGTVSEtdfesOrcEHRk9xAG++HTQgrtA4MKoVrLtPScq1O6kHFpd9DnzgRQe3VLIbBcQv9puUPTf2hoDWCAMEMZS7CYXbUElebp1HVy3Fsl7uIbzC45er7zilGP7esnWRGVpI0yfAkNm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699652203; c=relaxed/simple; bh=/amVAylNy9iLcAF3kdVoPGF2KISCmJDNCqDch/3NUjo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Gkc/QPOxMnSUiUuwsJOOzKduksxoLZSW+yuK15j6s/XABuuLOxJyZnFPyA3KfuAR8Hk3b5JY0Ea2A2rlJOaE47AF9NMe4XnWIC7TDHaYRxAUJ7DlJh8yU6saE8We7oVX/QVM7CpjstiDenmtNgV9qDHRfLtBZyTgdawTZPUxLXk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699652201; 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: in-reply-to:in-reply-to:references:references; bh=aga3RfTTHJ3E66LEmRFak7cgDF5qWTmQ89IP6OfYF9E=; b=ZQvzkZamNRXiCST9KIUSUXcmsFgXgmVgs153aAe9i7XcnRi8gFSmwW+DuTkgtUlDL5qWJO 6RvQ2PZd+Kbz1gKEhBj0mowoO1ryVbjfqWMbMcu/viGO0IUWiw8bWCsW63reACVka7XjDH zhWBHWemTpRMLVH0tbqXC++w2wGN4wM= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-214-wrZixIijOK24HN3dhFWP3w-1; Fri, 10 Nov 2023 16:36:40 -0500 X-MC-Unique: wrZixIijOK24HN3dhFWP3w-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-77bc625a8a2so141076185a.0 for ; Fri, 10 Nov 2023 13:36:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699652200; x=1700257000; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aga3RfTTHJ3E66LEmRFak7cgDF5qWTmQ89IP6OfYF9E=; b=jDTPkXTED2hbi3DEBvubbmiItchKlxE9jO2n0mZkcsVdjLbwdRhbZq8J8LJ67bZrk/ X/IFGUaSeUwBvp49iR4HnmO1X/0fKiPrWWGAODlXHRoX+TNEeuTX7XW+pTZ68KGq665s U2tYMZZfZbOuDahcTC2xRTlY7O0Lua3N8LTTL6Ymvn/eLKkRS/O1J9mrzDnMaTQayx0D bTiCIEpolggn/5ZBu8WbTzweE+DqUm/H5fp+FeRu3af1tE8ESF+mdf1J7cXWw8OdEfEs P1FpaigSoj+qJiJkleOaSuQMWmznNGPDYwuToapReYXbqK7RzFKHnji3uAnoIzUvHOat 6Ouw== X-Gm-Message-State: AOJu0Yz5E/qXj0xLBO84Y/eps/AYoyH1qTA1nwyrctK++bbFUptaba/n Rh8oK+fbRZ7MRWSBKHXiitocHpMHntWjuyEd36bQqJdU8Z4dysmFHdLsjQbtBtvwzb9bGIjpn9M WbQLlcPLnhGnSzSbKtg== X-Received: by 2002:a05:620a:424e:b0:774:3436:aa22 with SMTP id w14-20020a05620a424e00b007743436aa22mr512214qko.5.1699652200117; Fri, 10 Nov 2023 13:36:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8NiDN/Le72Zb3nTtQorsbc+uL1Ua1vDK0uxUbO61T3tcNz/sq7sVEH0WQNctieAaPsO/wZg== X-Received: by 2002:a05:620a:424e:b0:774:3436:aa22 with SMTP id w14-20020a05620a424e00b007743436aa22mr512201qko.5.1699652199831; Fri, 10 Nov 2023 13:36:39 -0800 (PST) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id o5-20020a05620a0d4500b0076dacd14484sm98125qkl.83.2023.11.10.13.36.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Nov 2023 13:36:39 -0800 (PST) Message-ID: <8fd05dbf-f08d-441f-90c0-10ac6fe5f7a8@redhat.com> Date: Fri, 10 Nov 2023 16:36:38 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: non-dependent .* folding [PR112427] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20231108215904.2779753-1-ppalka@redhat.com> <375a6726-8998-4b6b-830f-32852ef116b1@redhat.com> <2fb218a2-713a-1a09-3c18-0f37ab359631@idea> From: Jason Merrill In-Reply-To: <2fb218a2-713a-1a09-3c18-0f37ab359631@idea> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.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,RCVD_IN_SORBS_WEB,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 11/10/23 10:28, Patrick Palka wrote: > 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? True, we would need build_min_non_dep to also get TREE_SIDE_EFFECTS from the operands. That might be useful in general for similar situations? I also note that convert_to_ptrofftype uses fold_convert, so the new code could have the same problem if the pointer to member operand is also a COMPONENT_REF. Jason