From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id DE8D9384D3E7; Mon, 12 Dec 2022 22:46:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE8D9384D3E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670885207; bh=Pgyhk856nSvTLE2TJOi1ce5QMLSOAAdlbHpvSOPHy9Y=; h=From:To:Subject:Date:From; b=pixVW/5Il85vq/Nu7HhR5QSIHemO/Uhaj/P+V3rc8ZR7Gmif0hD/TP8DHYwwMwkOq 1aqhesKg8GMdmpC74yq2IML5lC0EIKKWAoc5Rw1jDiQeAnYA5CqY1kq2ctaylOg7x/ yS1Bet1bI+9Hdu5+x6DfhxYtTVpL1wxvNPC0wITA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4625] Revert "c++: build initializer_list in a loop [PR105838]" X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: 11c72cd3c8b06f057ce16c95966331ded692fd4e X-Git-Newrev: 77ebee2bd04cc727161875869b135675d035c66e Message-Id: <20221212224647.DE8D9384D3E7@sourceware.org> Date: Mon, 12 Dec 2022 22:46:47 +0000 (GMT) List-Id: https://gcc.gnu.org/g:77ebee2bd04cc727161875869b135675d035c66e commit r13-4625-g77ebee2bd04cc727161875869b135675d035c66e Author: Jason Merrill Date: Mon Dec 12 17:41:39 2022 -0500 Revert "c++: build initializer_list in a loop [PR105838]" This patch broke a couple of different patterns; reverting while I work on a fix. PR c++/108701 This reverts commit bd0485f20f4794f9787237706a6308473a8e9415. Diff: --- gcc/cp/call.cc | 11 +---------- gcc/cp/constexpr.cc | 6 +++--- gcc/cp/init.cc | 13 ++----------- gcc/cp/tree.cc | 2 ++ gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C | 24 ------------------------ 5 files changed, 8 insertions(+), 48 deletions(-) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 14aa96dd328..33b5e7f87f5 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -8501,16 +8501,7 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum, unsigned len = CONSTRUCTOR_NELTS (expr); tree array; - if (tree init = maybe_init_list_as_array (elttype, expr)) - { - elttype = cp_build_qualified_type - (elttype, cp_type_quals (elttype) | TYPE_QUAL_CONST); - array = build_array_of_n_type (elttype, len); - array = build_vec_init_expr (array, init, complain); - array = get_target_expr (array); - array = cp_build_addr_expr (array, complain); - } - else if (len) + if (len) { tree val; unsigned ix; diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 3f7892aa88a..e43d92864f5 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -5255,12 +5255,12 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, else { /* Copying an element. */ + gcc_assert (same_type_ignoring_top_level_qualifiers_p + (atype, TREE_TYPE (init))); eltinit = cp_build_array_ref (input_location, init, idx, complain); if (!lvalue_p (init)) eltinit = move (eltinit); - eltinit = (perform_implicit_conversion_flags - (elttype, eltinit, complain, - LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING)); + eltinit = force_rvalue (eltinit, complain); eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval, non_constant_p, overflow_p); } diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 1ccde7cf8ad..428fac5621c 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -4420,9 +4420,7 @@ build_vec_init (tree base, tree maxindex, tree init, /* Look through the TARGET_EXPR around a compound literal. */ if (init && TREE_CODE (init) == TARGET_EXPR && TREE_CODE (TARGET_EXPR_INITIAL (init)) == CONSTRUCTOR - && from_array != 2 - && (same_type_ignoring_top_level_qualifiers_p - (TREE_TYPE (init), atype))) + && from_array != 2) init = TARGET_EXPR_INITIAL (init); if (tree vi = get_vec_init_expr (init)) @@ -4548,14 +4546,7 @@ build_vec_init (tree base, tree maxindex, tree init, { if (lvalue_kind (init) & clk_rvalueref) xvalue = true; - if (TREE_CODE (init) == TARGET_EXPR) - { - /* Avoid error in decay_conversion. */ - base2 = decay_conversion (TARGET_EXPR_SLOT (init), complain); - base2 = cp_build_compound_expr (init, base2, tf_none); - } - else - base2 = decay_conversion (init, complain); + base2 = decay_conversion (init, complain); if (base2 == error_mark_node) return error_mark_node; itype = TREE_TYPE (base2); diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index a600178239c..33bde16f128 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -785,6 +785,8 @@ build_vec_init_elt (tree type, tree init, tsubst_flags_t complain) releasing_vec argvec; if (init && !BRACE_ENCLOSED_INITIALIZER_P (init)) { + gcc_assert (same_type_ignoring_top_level_qualifiers_p + (type, TREE_TYPE (init))); tree init_type = strip_array_types (TREE_TYPE (init)); tree dummy = build_dummy_object (init_type); if (!lvalue_p (init)) diff --git a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C deleted file mode 100644 index fc928bb5405..00000000000 --- a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C +++ /dev/null @@ -1,24 +0,0 @@ -// PR c++/105838 -// { dg-additional-options -fdump-tree-gimple } -// { dg-do compile { target c++11 } } - -// Check that we call the basic_string constructor once (and define it once). -// { dg-final { scan-tree-dump-times {>::basic_string} 2 "gimple" } } - -#include - -void g (const void *); - -void f (const char *p) -{ - std::initializer_list 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); -}