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 336263858D3C for ; Thu, 24 Mar 2022 15:40:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 336263858D3C Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-321-SIbVidLjMyStaMsqKTRTfw-1; Thu, 24 Mar 2022 11:40:14 -0400 X-MC-Unique: SIbVidLjMyStaMsqKTRTfw-1 Received: by mail-qt1-f198.google.com with SMTP id o15-20020ac8698f000000b002e1db0c88d0so3950443qtq.17 for ; Thu, 24 Mar 2022 08:40:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=2cPE3ORN/gqB91L1K1cb0iNxcSuIZSmBlbI2JAZSg+0=; b=sytpvBBOLhOJMmIco89egTPTq3GeeVjQh2nbcGeWILGoeibPSIGuD+/p8tK2JslI9d moyiYzLMsBZ//qDu2Mwh7M1UcIqiY2k+n6xjUtPMGz30Om6h2RAfmgKLrqxzOKn3U+8/ 1ToTPZMNNMRPWW/37e8OUa9PqV80NCXn7OjbWAWMCHpW37uXrYl/OqbMtnKoFpvheN5D kms9NI6lArO1IJvjlujCadN3OLbK6hb7F+xBnMTjd1oE+xHKZNJVPPnLjltwT4b5eQF4 83ViuH/6mfVZmRrTNmy4KFtwBlrfLzpkGMdSgylRd/nAAM6PtEV3JhjBRgD0lfX9y1iF D8xw== X-Gm-Message-State: AOAM533jWQDUDBG9ff3jc5M28t7Y9CUvDHBhJHnJG4m71k092+9rZptw Ms1yotG0fg/UZ15C4PMd9JMvuf/6Xqw56QHZ4gv4f0FYkZUjbPc/vIEObVYPIB/2fvc4d5qMh5D bKcc49tBtK9auVGlT6Q== X-Received: by 2002:a05:622a:594:b0:2e1:d59e:68ed with SMTP id c20-20020a05622a059400b002e1d59e68edmr5248677qtb.204.1648136413452; Thu, 24 Mar 2022 08:40:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFT/SSYwlLY1sy0oh9zga7r8fFLJZZ9+0iV5HYN5zWRlSqT+WqkIFk67Hn7JxvuAgVSA33Sw== X-Received: by 2002:a05:622a:594:b0:2e1:d59e:68ed with SMTP id c20-20020a05622a059400b002e1d59e68edmr5248649qtb.204.1648136413066; Thu, 24 Mar 2022 08:40:13 -0700 (PDT) Received: from [192.168.1.149] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id o21-20020ac85a55000000b002e16389b501sm2620884qta.96.2022.03.24.08.40.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Mar 2022 08:40:12 -0700 (PDT) Message-ID: <4bc3f576-c238-2559-197e-3a51b3722505@redhat.com> Date: Thu, 24 Mar 2022 11:40:11 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v2] c++: ICE with template code in constexpr [PR104284] To: Marek Polacek Cc: GCC Patches References: <20220310220459.91301-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: 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=-7.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Mar 2022 15:40:19 -0000 On 3/18/22 17:55, Marek Polacek wrote: > On Fri, Mar 11, 2022 at 06:46:42PM -0500, Jason Merrill wrote: >> On 3/10/22 18:04, Marek Polacek wrote: >>> Since r9-6073 cxx_eval_store_expression preevaluates the value to >>> be stored, and that revealed a crash where a template code (here, >>> code=IMPLICIT_CONV_EXPR) leaks into cxx_eval*. >>> >>> It happens because we're performing build_vec_init while processing >>> a template >> >> Hmm, that seems like the bug. Where's that call coming from? > > From build_aggr_init. So we're handling e.g. > > template > constexpr void g () { > constexpr S s2[]{{'a'}}; > } > > cp_finish_decl (decl=s2, init={{'a'}}) sees we're in processing_template_decl, > but also that we have a constexpr var which is not dependent, nor is its > initializer: > > else if (init > && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl)) > && !TYPE_REF_P (type) > && decl_maybe_constant_var_p (decl) > && !(dep_init = value_dependent_init_p (init))) > { > /* This variable seems to be a non-dependent constant, so process > its initializer. If check_initializer returns non-null the > initialization wasn't constant after all. */ > tree init_code; > cleanups = make_tree_vector (); > init_code = check_initializer (decl, init, flags, &cleanups); > > so we call check_initializer, where we go down this path: > > init_code = build_aggr_init_full_exprs (decl, init, flags); > > build_aggr_init sees that the type of 's2' is ARRAY_TYPE, so it calls > build_vec_init. > > I now recall that we've discussed build_vec_init in a template in the > past, for example in the context of c++/93676. So I agree we ought to > make an effort to avoid calling build_vec_init in a template. Perhaps > like this: use an INIT_EXPR. With that, we should call build_vec_init > if needed while instantiating. Does that make any sense? Hmm. If we do that, then we get back to > if (TREE_CODE (init_code) == INIT_EXPR) in check_initializer, and pull out the same init again, and set LOOKUP_ALREADY_DIGESTED. But I think that's wrong, we haven't digested it yet. Maybe we could avoid entering the below block of check_initializer at all in this situation? > if (((type_build_ctor_call (type) || CLASS_TYPE_P (type)) > && !(flags & LOOKUP_ALREADY_DIGESTED) > && !(init && BRACE_ENCLOSED_INITIALIZER_P (init) > && CP_AGGREGATE_TYPE_P (type) > && (CLASS_TYPE_P (type) Maybe by adding || processing_template_decl here? > || !TYPE_NEEDS_CONSTRUCTING (type) > || type_has_extended_temps (type)))) > || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE)) Jason