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 73BAA385841B for ; Sat, 22 Jul 2023 04:29:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73BAA385841B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690000145; 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=y9lT5CSJ7XGLlvt98r75F+OsaCirnd8oAZpyvTvSDlk=; b=gyvDZ/IaQhlkNRVf4vVKY2MokdEaCSdqW7Ho6n/pNoayO2pLoC7SH9+TzOgqK7L81YSdam WwRZmkBmiU9x/doSEXY+jG1dRBZs9SxLeOLPopRe5+EMJfeWvXj3m3GiQEY87PAjMX1rDj OhbllxIllicZ7Yg/wgNFdappm132VqE= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-324-7W9VsciSMZmkFdU2PRo4_Q-1; Sat, 22 Jul 2023 00:29:01 -0400 X-MC-Unique: 7W9VsciSMZmkFdU2PRo4_Q-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4053d7854a9so33204551cf.3 for ; Fri, 21 Jul 2023 21:29:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690000141; x=1690604941; 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=y9lT5CSJ7XGLlvt98r75F+OsaCirnd8oAZpyvTvSDlk=; b=A4m4aJzMJo1PF9y91KDV5bUMVQb9qU2CFkK3vA73s+H7LMfstQ0l6KVKrh6WHEHFnR tbu3hlnVcQPT/fR7pvRG9vO+a4R569o//gDw+hxT1Y380MNbJ4uVLYGYy6Sny076gZaB qqLJ6bPIg3qrUEkvx0/n7hQxv0m4ArprtguO7XUIHJL8hNlEXlUfZcOs89qzUHwR0JdH CHPmzL7rimniTygM8ElkAVrnryEiQGzY96dU8F3M36vuxLEZSkPdcSAyfO+tWM0qVlRa jqvVPBezI2p/Ke7/VRvaWgMMKk4HAeSYxd5+epL0KlzjvMRlY+tY+oRJs2ahBNdzNyt+ cSGA== X-Gm-Message-State: ABy/qLbKQU2X9IwDhMBN3nGWhV9dR2WIzPQs5b9qQUY+cIwCL4OAu4So gIdBRXWhqE+Zq0R/m51fSHsIxtW696gMtd4qb2A7z2DbIFa/dyBp0rx8lE3ZiMImdy/IUGfi3j2 2xBrohZxYxLbK0kA9xw== X-Received: by 2002:a05:622a:2c6:b0:403:66f7:ae66 with SMTP id a6-20020a05622a02c600b0040366f7ae66mr2293337qtx.13.1690000141401; Fri, 21 Jul 2023 21:29:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlEJUmrbd4Xr1AtOa4nylHVwzCndrYOAioqsVRrXVGsCTDhnvZOq9SUdiVKcMwRRKeGjxnzabg== X-Received: by 2002:a05:622a:2c6:b0:403:66f7:ae66 with SMTP id a6-20020a05622a02c600b0040366f7ae66mr2293329qtx.13.1690000141075; Fri, 21 Jul 2023 21:29:01 -0700 (PDT) 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 ff20-20020a05622a4d9400b00403f1a7be90sm1756205qtb.88.2023.07.21.21.29.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Jul 2023 21:29:00 -0700 (PDT) Message-ID: <77708a9e-b677-e655-a3cc-a9af6d0b1321@redhat.com> Date: Sat, 22 Jul 2023 00:28:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] c++: fix ICE with constexpr ARRAY_REF [PR110382] To: Marek Polacek , GCC Patches Cc: Patrick Palka References: <20230721223835.630543-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20230721223835.630543-1-polacek@redhat.com> 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=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 7/21/23 18:38, Marek Polacek wrote: > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/13? > > -- >8 -- > > This code in cxx_eval_array_reference has been hard to get right. > In r12-2304 I added some code; in r13-5693 I removed some of it. > > Here the problematic line is "S s = arr[0];" which causes a crash > on the assert in verify_ctor_sanity: > > gcc_assert (!ctx->object || !DECL_P (ctx->object) > || ctx->global->get_value (ctx->object) == ctx->ctor); > > ctx->object is the VAR_DECL 's', which is correct here. The second > line points to the problem: we replaced ctx->ctor in > cxx_eval_array_reference: > > new_ctx.ctor = build_constructor (elem_type, NULL); // #1 ...and this code doesn't also clear(/set) new_ctx.object like everywhere else in constexpr.cc that sets new_ctx.ctor. Fixing that should make the testcase work. > which I think we shouldn't have; the CONSTRUCTOR we created in > cxx_eval_constant_expression/DECL_EXPR > > new_ctx.ctor = build_constructor (TREE_TYPE (r), NULL); > > had the right type. Indeed, and using it rather than building a new one seems like a valid optimization for trunk. I also notice that the DECL_EXPR code calls unshare_constructor, which should be unnecessary if init == ctx->ctor? > We still need #1 though. E.g., in constexpr-96241.C, we never > set ctx.ctor/object before calling cxx_eval_array_reference, so > we have to build a CONSTRUCTOR there. And in constexpr-101371-2.C > we have a ctx.ctor, but it has the wrong type, so we need a new one. > > PR c++/110382 > > gcc/cp/ChangeLog: > > * constexpr.cc (cxx_eval_array_reference): Create a new constructor > only when we don't already have a matching one. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp1y/constexpr-110382.C: New test. > --- > gcc/cp/constexpr.cc | 5 ++++- > gcc/testsuite/g++.dg/cpp1y/constexpr-110382.C | 17 +++++++++++++++++ > 2 files changed, 21 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-110382.C > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > index fb94f3cefcb..518b7c7a2d5 100644 > --- a/gcc/cp/constexpr.cc > +++ b/gcc/cp/constexpr.cc > @@ -4291,7 +4291,10 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, > else > val = build_value_init (elem_type, tf_warning_or_error); > > - if (!SCALAR_TYPE_P (elem_type)) > + if (!SCALAR_TYPE_P (elem_type) > + /* Create a new constructor only if we don't already have one that > + is suitable. */ > + && !(ctx->ctor && same_type_p (elem_type, TREE_TYPE (ctx->ctor)))) We generally use same_type_ignoring_top_level_qualifiers_p in the constexpr code. Jason