From patchwork Mon Jan 9 10:19:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 40787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2074127wrt; Mon, 9 Jan 2023 02:20:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXvA1T+uJlsevEECGfAwEWbLFsloYulGTh9EIWD75zmx3tMPX7ejw/iHLTkepxUWBWNwS8Tb X-Received: by 2002:a17:907:cb84:b0:836:e8a6:f6f5 with SMTP id un4-20020a170907cb8400b00836e8a6f6f5mr56512636ejc.66.1673259605771; Mon, 09 Jan 2023 02:20:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673259605; cv=none; d=google.com; s=arc-20160816; b=ZJSQj/yQIIAjDVUff3NOSW3E3lSQ4nvf2QC/V8Kz5BeTyDcHRbrEhdf9ANwCRdpXqI 4l66Dt2gkGIpB3YRj3nLFGBQfsRPCeSDviLX1YTvg5Xp7xUh1WEytIaMZ2BTA55Fs6hq tKPvz7VPWs9wThovYQW+OQQvdSJsHVUjuOsTHlZJ3OZ+kRAt9yUH97Y+YmuSfHi21V1n RKZNZhdlPjbr4nb15rvWZZrMF+s5r7f95pcx3ChySRX6Mmc0NpZYdTJng9blwYiXyKrU 33KecfNKCUzF8WSsfNxQxmH36uKug5EaveuDxDeZW7QbFkAiX6tftuIdy5G/RmYqSRhZ 3V/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=u4JRa+UpDWgksDItIa9O0/HfD+ULDXsmp5tT68wlO+k=; b=hWgwc47+5UN/xTSWhezMnphgcZQ568L5ZkDg6IxPGbaLWsiCSweMMSlt+UvgQ+RiCL VxSc6g3CRrz2L6u6cCN6F1rf/aYZmb/jNdWBtDK5w/r+UPnMEwbVwB0DVhm1l4qT4S8B 5G1A+DiZ8x7hq3F9UGHRlCzCawreb2g9grLObn77TlsQ+7nARPK4tpy2EAQifP3x49Uo AvZyYnTpRAQR7Ug7Gc9wQjYGAexfcCw4qwxgmq+04YobKuJNLHz+4/7qyt2VrPhZINvW XLiGDqGCrZmYWveBeXntKP1rG9/CXJmLUmTk5YWP1mRKPEp432YXRm46p7qqTVyCqEgU mMpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xud6WExo; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id xg3-20020a170907320300b007d161a8106csi8489954ejb.982.2023.01.09.02.20.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 02:20:05 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xud6WExo; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8FB2C3858426 for ; Mon, 9 Jan 2023 10:20:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FB2C3858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673259604; bh=u4JRa+UpDWgksDItIa9O0/HfD+ULDXsmp5tT68wlO+k=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=xud6WExoT1sovQH+XCEs+oJV/EhCVUmtl7RwNNmcmiErfmsfKrx6daT5dRJ59XFzc BZ+gJVU0bz1Ybsi9YhD0uID4h6vnrBpoc2z3+BNI1TPgoMGDc/y1LjWBNQEp5r926p 5J/BUdMPzFIEwp2O6GhtiJGY+GQOBkzHMSt4jwuY= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 4BE373858D20 for ; Mon, 9 Jan 2023 10:19:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4BE373858D20 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-411-dvqzM0-QNSOUKraOYSfyPw-1; Mon, 09 Jan 2023 05:19:20 -0500 X-MC-Unique: dvqzM0-QNSOUKraOYSfyPw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3154E1C05ACF for ; Mon, 9 Jan 2023 10:19:20 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E29C6492B00; Mon, 9 Jan 2023 10:19:19 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 309AJGtF2666127 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 9 Jan 2023 11:19:17 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 309AJG9Q2666126; Mon, 9 Jan 2023 11:19:16 +0100 Date: Mon, 9 Jan 2023 11:19:15 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Only do maybe_init_list_as_range optimization if !processing_template_decl [PR108047] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754539864433859969?= X-GMAIL-MSGID: =?utf-8?q?1754539864433859969?= Hi! The last testcase in this patch ICEs, because maybe_init_list_as_range -> maybe_init_list_as_array calls maybe_constant_init in: /* Don't do this if the conversion would be constant. */ first = maybe_constant_init (first); if (TREE_CONSTANT (first)) return NULL_TREE; but maybe_constant_init shouldn't be called when processing_template_decl. While we could replace that call with fold_non_dependent_init, my limited understanding is that this is an optimization and even if we don't optimize it when processing_template_decl, build_user_type_conversion_1 will be called again during instantiation with !processing_template_decl if it is every instantiated and we can do the optimization only then. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Or do you want fold_non_dependent_init instead? 2023-01-09 Jakub Jelinek PR c++/105838 PR c++/108047 PR c++/108266 * call.cc (maybe_init_list_as_range): Always return NULL_TREE if processing_template_decl. * g++.dg/tree-ssa/initlist-opt2.C: New test. * g++.dg/tree-ssa/initlist-opt3.C: New test. Jakub --- gcc/cp/call.cc.jj 2022-12-15 09:24:44.265935297 +0100 +++ gcc/cp/call.cc 2023-01-06 11:24:44.837270905 +0100 @@ -4285,7 +4285,8 @@ maybe_init_list_as_array (tree elttype, static tree maybe_init_list_as_range (tree fn, tree expr) { - if (BRACE_ENCLOSED_INITIALIZER_P (expr) + if (!processing_template_decl + && BRACE_ENCLOSED_INITIALIZER_P (expr) && is_list_ctor (fn) && decl_in_std_namespace_p (fn)) { --- gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C.jj 2023-01-06 11:53:13.160432870 +0100 +++ gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C 2023-01-06 11:53:44.561976302 +0100 @@ -0,0 +1,31 @@ +// PR c++/105838 +// { dg-additional-options -fdump-tree-gimple } +// { dg-do compile { target c++11 } } + +// Test that we do range-initialization from const char *. +// { dg-final { scan-tree-dump {_M_range_initialize} "gimple" } } + +#include +#include + +void g (const void *); + +template +void f (const char *p) +{ + std::vector lst = { + "aahing", "aaliis", "aarrgh", "abacas", "abacus", "abakas", "abamps", "abands", "abased", "abaser", "abases", "abasia", + "abated", "abater", "abates", "abatis", "abator", "abattu", "abayas", "abbacy", "abbess", "abbeys", "abbots", "abcees", + "abdabs", "abduce", "abduct", "abears", "abeigh", "abeles", "abelia", "abends", "abhors", "abided", "abider", "abides", + "abject", "abjure", "ablate", "ablaut", "ablaze", "ablest", "ablets", "abling", "ablins", "abloom", "ablush", "abmhos", + "aboard", "aboded", "abodes", "abohms", "abolla", "abomas", "aboral", "abords", "aborne", "aborts", "abound", "abouts", + "aboves", "abrade", "abraid", "abrash", "abrays", "abrazo", "abrege", "abrins", "abroad", "abrupt", "abseil", "absent", + }; + + g(&lst); +} + +void h (const char *p) +{ + f<0> (p); +} --- gcc/testsuite/g++.dg/tree-ssa/initlist-opt3.C.jj 2023-01-06 11:56:36.981469370 +0100 +++ gcc/testsuite/g++.dg/tree-ssa/initlist-opt3.C 2023-01-06 11:56:09.984861898 +0100 @@ -0,0 +1,21 @@ +// PR c++/108266 +// { dg-do compile { target c++11 } } + +#include +#include + +struct S { S (const char *); }; +void bar (std::vector); + +template +void +foo () +{ + bar ({"", ""}); +} + +void +baz () +{ + foo<0> (); +}