From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 7234A3856240; Wed, 11 May 2022 06:26:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7234A3856240 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-10150] c++: Fix up CONSTRUCTOR_PLACEHOLDER_BOUNDARY handling [PR105256] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: 14407aba9fc03b3b29d3ffdf713369cc6a572431 X-Git-Newrev: 30895a25ea94e0ba47f97803137f2a0a42af848c Message-Id: <20220511062641.7234A3856240@sourceware.org> Date: Wed, 11 May 2022 06:26:41 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2022 06:26:41 -0000 https://gcc.gnu.org/g:30895a25ea94e0ba47f97803137f2a0a42af848c commit r9-10150-g30895a25ea94e0ba47f97803137f2a0a42af848c Author: Jakub Jelinek Date: Tue Apr 19 18:27:41 2022 +0200 c++: Fix up CONSTRUCTOR_PLACEHOLDER_BOUNDARY handling [PR105256] The CONSTRUCTOR_PLACEHOLDER_BOUNDARY bit is supposed to separate PLACEHOLDER_EXPRs that should be replaced by one object or subobjects of it (variable, TARGET_EXPR slot, ...) from other PLACEHOLDER_EXPRs that should be replaced by different objects or subobjects. The bit is set when finding PLACEHOLDER_EXPRs inside of a CONSTRUCTOR, not looking into nested CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctors, and we prevent elision of TARGET_EXPRs (through TARGET_EXPR_NO_ELIDE) whose initializer is a CONSTRUCTOR_PLACEHOLDER_BOUNDARY ctor. The following testcase ICEs though, we don't replace the placeholders in there at all, because CONSTRUCTOR_PLACEHOLDER_BOUNDARY isn't set on the TARGET_EXPR_INITIAL ctor, but on a ctor nested in such a ctor. replace_placeholders should be run on the whole TARGET_EXPR slot. So, the following patch fixes it by moving the CONSTRUCTOR_PLACEHOLDER_BOUNDARY bit from nested CONSTRUCTORs to the CONSTRUCTOR containing those (but only if it is closely nested, if there is some other tree sandwiched in between, it doesn't do it). 2022-04-19 Jakub Jelinek PR c++/105256 * typeck2.c (process_init_constructor_array, process_init_constructor_record, process_init_constructor_union): Move CONSTRUCTOR_PLACEHOLDER_BOUNDARY flag from CONSTRUCTOR elements to the containing CONSTRUCTOR. * g++.dg/cpp0x/pr105256.C: New test. (cherry picked from commit eb03e424598d30fed68801af6d6ef6236d32e32e) Diff: --- gcc/cp/typeck2.c | 31 +++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/pr105256.C | 18 ++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index a7ef373fe08..e7e85337d76 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1438,6 +1438,14 @@ process_init_constructor_array (tree type, tree init, int nested, int flags, strip_array_types (TREE_TYPE (ce->value))))); picflags |= picflag_from_initializer (ce->value); + /* Propagate CONSTRUCTOR_PLACEHOLDER_BOUNDARY to outer + CONSTRUCTOR. */ + if (TREE_CODE (ce->value) == CONSTRUCTOR + && CONSTRUCTOR_PLACEHOLDER_BOUNDARY (ce->value)) + { + CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init) = 1; + CONSTRUCTOR_PLACEHOLDER_BOUNDARY (ce->value) = 0; + } } /* No more initializers. If the array is unbounded, we are done. Otherwise, @@ -1472,6 +1480,14 @@ process_init_constructor_array (tree type, tree init, int nested, int flags, if (next) { picflags |= picflag_from_initializer (next); + /* Propagate CONSTRUCTOR_PLACEHOLDER_BOUNDARY to outer + CONSTRUCTOR. */ + if (TREE_CODE (next) == CONSTRUCTOR + && CONSTRUCTOR_PLACEHOLDER_BOUNDARY (next)) + { + CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init) = 1; + CONSTRUCTOR_PLACEHOLDER_BOUNDARY (next) = 0; + } if (len > i+1 && (initializer_constant_valid_p (next, TREE_TYPE (next)) == null_pointer_node)) @@ -1678,6 +1694,13 @@ process_init_constructor_record (tree type, tree init, int nested, int flags, if (type != TREE_TYPE (field)) next = cp_convert_and_check (TREE_TYPE (field), next, complain); picflags |= picflag_from_initializer (next); + /* Propagate CONSTRUCTOR_PLACEHOLDER_BOUNDARY to outer CONSTRUCTOR. */ + if (TREE_CODE (next) == CONSTRUCTOR + && CONSTRUCTOR_PLACEHOLDER_BOUNDARY (next)) + { + CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init) = 1; + CONSTRUCTOR_PLACEHOLDER_BOUNDARY (next) = 0; + } CONSTRUCTOR_APPEND_ELT (v, field, next); } @@ -1831,6 +1854,14 @@ process_init_constructor_union (tree type, tree init, int nested, int flags, ce->value = massage_init_elt (TREE_TYPE (ce->index), ce->value, nested, flags, complain); + /* Propagate CONSTRUCTOR_PLACEHOLDER_BOUNDARY to outer CONSTRUCTOR. */ + if (ce->value + && TREE_CODE (ce->value) == CONSTRUCTOR + && CONSTRUCTOR_PLACEHOLDER_BOUNDARY (ce->value)) + { + CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init) = 1; + CONSTRUCTOR_PLACEHOLDER_BOUNDARY (ce->value) = 0; + } return picflag_from_initializer (ce->value); } diff --git a/gcc/testsuite/g++.dg/cpp0x/pr105256.C b/gcc/testsuite/g++.dg/cpp0x/pr105256.C new file mode 100644 index 00000000000..a97949d796a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr105256.C @@ -0,0 +1,18 @@ +// PR c++/105256 +// { dg-do compile { target c++11 } } + +int bar (int &); + +struct S { + struct T { + struct U { + int i = bar (i); + } u; + }; +}; + +void +foo (S::T *p) +{ + *p = {}; +}