Skip to content
Snippets Groups Projects
Commit 3191d740 authored by Jakub Jelinek's avatar Jakub Jelinek Committed by Jakub Jelinek
Browse files

c++: Fix up reshape_* RAW_DATA_CST handling [PR118214]

The embed-17.C testcase is miscompiled and pr118214.C testcase used to be
miscompiled on the trunk before I've temporarily reverted the
r15-6339 C++ large initializer speed-up commit in r15-6448.
The problem is that reshape_* is only sometimes allowed to modify the given
CONSTRUCTOR in place (when reuse is true, so
                first_initializer_p
                && (complain & tf_error)
                && !CP_AGGREGATE_TYPE_P (elt_type)
                && !TREE_SIDE_EFFECTS (first_initializer_p)
) and at other times is not allowed to change it.  But the RAW_DATA_CST
handling was modifying those in place always, by peeling off whatever
was needed for the processing of the current element or set of elements
and leaving the rest in the original CONSTRUCTOR_ELTS, either as
RAW_DATA_CST with adjusted RAW_DATA_POINTER/RAW_DATA_LENGTH, or turning
it into INTEGER_CST if it would be a RAW_DATA_LENGTH == 1 RAW_DATA_CST.

The following patch fixes that by adding raw_idx member into
struct reshape_iter where we for the RAW_DATA_CST current elements track
offset into the current RAW_DATA_CST (how many elements were processed
from it already) and modifying the original CONSTRUCTOR_ELTS only if reuse
is true and we used the whole RAW_DATA_CST (with zero raw_idx); which means
just modifying its type in place.

2025-01-16  Jakub Jelinek  <jakub@redhat.com>

	PR c++/118214
	* decl.cc (struct reshape_iter): Add raw_idx member.
	(cp_maybe_split_raw_data): Add inc_cur parameter, set *inc_cur,
	don't modify original CONSTRUCTOR, use d->raw_idx to track index
	into a RAW_DATA_CST d->cur->value.
	(consume_init): Adjust cp_maybe_split_raw_data caller, increment
	d->cur when cur_inc is true.
	(reshape_init_array_1): Don't modify original CONSTRUCTOR when
	handling RAW_DATA_CST d->cur->value and !reuse, instead use
	d->raw_idx to track index into RAW_DATA_CST.
	(reshape_single_init): Initialize iter.raw_idx.
	(reshape_init_class): Adjust for introduction of d->raw_idx,
	adjust cp_maybe_split_raw_data caller, do d->cur++ if inc_cur
	rather than when it returns non-NULL.
	(reshape_init_r): Check for has_designator_problem for second
	half of _Complex earlier, also check for
	error_operand_p (d->cur->value).  Use consume_init instead of
	cp_maybe_split_raw_data with later conditional d->cur++.
	(reshape_init): Initialize d.raw_idx.

	* g++.dg/cpp/embed-17.C: New test.
	* g++.dg/cpp0x/pr118214.C: New test.
parent 03e0bf3f
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment