Commit Graph

171114 Commits

Author SHA1 Message Date
Jakub Jelinek bd1562be91 c++: Fix handling of decls with flexible array members initialized with side-effects [PR88578]
> > Note, if the flexible array member is initialized only with non-constant
> > initializers, we have a worse bug that this patch doesn't solve, the
> > splitting of initializers into constant and dynamic initialization removes
> > the initializer and we don't have just wrong DECL_*SIZE, but nothing is
> > emitted when emitting those vars into assembly either and so the dynamic
> > initialization clobbers other vars that may overlap the variable.
> > I think we need keep an empty CONSTRUCTOR elt in DECL_INITIAL for the
> > flexible array member in that case.
>
> Makes sense.

So, the following patch fixes that.

The typeck2.c change makes sure we keep those CONSTRUCTORs around (although
they should be empty because all their elts had side-effects/was
non-constant if it was removed earlier), and the varasm.c change is to avoid
ICEs on those as well as ICEs on other flex array members that had some
initializers without side-effects, but not on the last array element.

The code was already asserting that the (index of the last elt in the
CONSTRUCTOR + 1) times elt size is equal to TYPE_SIZE_UNIT of the local->val
type, which is true for C flex arrays or for C++ if they don't have any
side-effects or the last elt doesn't have side-effects, this patch changes
that to assertion that the TYPE_SIZE_UNIT is greater than equal to the
offset of the end of last element in the CONSTRUCTOR and uses TYPE_SIZE_UNIT
(int_size_in_bytes) in the code later on.

2021-09-15  Jakub Jelinek  <jakub@redhat.com>

	PR c++/88578
	PR c++/102295
gcc/
	* varasm.c (output_constructor_regular_field): Instead of assertion
	that array_size_for_constructor result is equal to size of
	TREE_TYPE (local->val) in bytes, assert that the type size is greater
	or equal to array_size_for_constructor result and use type size as
	fieldsize.
gcc/cp/
	* typeck2.c (split_nonconstant_init_1): Don't throw away empty
	initializers of flexible array members if they have non-zero type
	size.
gcc/testsuite/
	* g++.dg/ext/flexary39.C: New test.
	* g++.dg/ext/flexary40.C: New test.

(cherry picked from commit e5d1af8a07)
2022-05-11 07:58:29 +02:00
Jakub Jelinek e13a79211a c++: Update DECL_*SIZE for objects with flexible array members with initializers [PR102295]
The C FE updates DECL_*SIZE for vars which have initializers for flexible
array members for many years, but C++ FE kept DECL_*SIZE the same as the
type size (i.e. as if there were zero elements in the flexible array
member).  This results e.g. in ELF symbol sizes being too small.

Note, if the flexible array member is initialized only with non-constant
initializers, we have a worse bug that this patch doesn't solve, the
splitting of initializers into constant and dynamic initialization removes
the initializer and we don't have just wrong DECL_*SIZE, but nothing is
emitted when emitting those vars into assembly either and so the dynamic
initialization clobbers other vars that may overlap the variable.
I think we need keep an empty CONSTRUCTOR elt in DECL_INITIAL for the
flexible array member in that case.

2021-09-14  Jakub Jelinek  <jakub@redhat.com>

	PR c++/102295
	* decl.c (layout_var_decl): For aggregates ending with a flexible
	array member, add the size of the initializer for that member to
	DECL_SIZE and DECL_SIZE_UNIT.

	* g++.target/i386/pr102295.C: New test.

(cherry picked from commit 818c505188)
2022-05-11 07:58:28 +02:00
Jakub Jelinek edb57ecb1b c++: Fix __is_*constructible/assignable for templates [PR102305]
is_xible_helper returns error_mark_node (i.e. false from the traits)
for abstract classes by testing ABSTRACT_CLASS_TYPE_P (to) early.
Unfortunately, as the testcase shows, that doesn't work on class templates
that haven't been instantiated yet, ABSTRACT_CLASS_TYPE_P for them is false
until it is instantiated, which is done when the routine later constructs
a dummy object with that type.

The following patch fixes this by calling complete_type first, so that
ABSTRACT_CLASS_TYPE_P test will work properly, while keeping the handling
of arrays with unknown bounds, or incomplete types where it is done
currently.

2021-09-14  Jakub Jelinek  <jakub@redhat.com>

	PR c++/102305
	* method.c (is_xible_helper): Call complete_type on to.

	* g++.dg/cpp0x/pr102305.C: New test.

(cherry picked from commit f008fd3a48)
2022-05-11 07:58:28 +02:00
Jakub Jelinek 45579f2901 i386: Fix up @xorsign<mode>3_1 [PR102224]
As the testcase shows, we miscompile @xorsign<mode>3_1 if both input
operands are in the same register, because the splitter overwrites op1
before with op1 & mask before using op0.

For dest = xorsign op0, op0 we can actually simplify it from
dest = (op0 & mask) ^ op0 to dest = op0 & ~mask (aka abs).

The expander change is an optimization improvement, if we at expansion
time know it is xorsign op0, op0, we can emit abs right away and get better
code through that.

The @xorsign<mode>3_1 is a fix for the case where xorsign wouldn't be known
to have same operands during expansion, but during RTL optimizations they
would appear.  We need to use earlyclobber, we require dest and op1 to be
the same but op0 must be different because we overwrite
op1 first.

2021-09-08  Jakub Jelinek  <jakub@redhat.com>

	PR target/102224
	* config/i386/i386.md (xorsign<mode>3): If operands[1] is equal to
	operands[2], emit abs<mode>2 instead.
	(@xorsign<mode>3_1): Add early-clobber for output operand.

	* gcc.dg/pr102224.c: New test.
	* gcc.target/i386/avx-pr102224.c: New test.

(cherry picked from commit a7b626d98a)
2022-05-11 07:58:28 +02:00
Jakub Jelinek 6aa2e07b41 dwarf2out: Emit DW_AT_location for global register vars during early dwarf [PR101905]
The following patch emits DW_AT_location for global register variables
already during early dwarf, since usually late_global_decl hook isn't even
called for those, as nothing needs to be emitted for them.

2021-08-23  Jakub Jelinek  <jakub@redhat.com>

	PR debug/101905
	* dwarf2out.c (gen_variable_die): Add DW_AT_location for global
	register variables already during early_dwarf if possible.

	* gcc.dg/guality/pr101905.c: New test.

(cherry picked from commit b284053bb7)
2022-05-11 07:58:27 +02:00
Jakub Jelinek cbf39efadb ubsan: Fix ICEs with DECL_REGISTER tests [PR101624]
The following testcase ICEs, because the base is a CONST_DECL for
the Fortran parameter, and ubsan/sanopt uses DECL_REGISTER macro on it.
 /* In VAR_DECL and PARM_DECL nodes, nonzero means declared `register'.  */
 #define DECL_REGISTER(NODE) (DECL_WRTL_CHECK (NODE)->decl_common.decl_flag_0)
while CONST_DECL doesn't satisfy DECL_WRTL_CHECK.

The following patch checks explicitly for VAR_DECL/PARM_DECL/RESULT_DECL
only before using DECL_REGISTER, assumes other decls aren't DECL_REGISTER.
Not really sure about RESULT_DECL but it at least satisfies DECL_WRTL_CHECK...

2021-07-28  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/101624
	* ubsan.c (maybe_instrument_pointer_overflow,
	instrument_object_size): Only test DECL_REGISTER on VAR_DECLs,
	PARM_DECLs or RESULT_DECLs.
	* sanopt.c (maybe_optimize_ubsan_ptr_ifn): Likewise.

	* gfortran.dg/ubsan/ubsan.exp: New file.
	* gfortran.dg/ubsan/pr101624.f90: New test.

(cherry picked from commit 49e28c02a9)
2022-05-11 07:58:26 +02:00
Jakub Jelinek f7200dd273 expmed: Fix store_integral_bit_field [PR101562]
Our documentation says that paradoxical subregs shouldn't appear
in strict_low_part:
'(strict_low_part (subreg:M (reg:N R) 0))'
     This expression code is used in only one context: as the
     destination operand of a 'set' expression.  In addition, the
     operand of this expression must be a non-paradoxical 'subreg'
     expression.
but on the testcase below that triggers UB at runtime
store_integral_bit_field emits exactly that.

The following patch fixes it by ensuring the requirement is satisfied.

2021-07-23  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/101562
	* expmed.c (store_integral_bit_field): Only use movstrict_optab
	if the operand isn't paradoxical.

	* gcc.c-torture/compile/pr101562.c: New test.

(cherry picked from commit 8408d34570)
2022-05-11 07:58:26 +02:00
Jakub Jelinek 3155bb8e47 openmp: Fix up omp_check_private [PR101535]
The target data construct shouldn't affect omp_check_private, unless
the decl there is privatized (use_device_* clauses).  The routine
had some code for that, but it just did continue; in a loop that looped
only if the region type is one of selected 4 kinds, so effectively resulted
in return false; instead of looping again.  And not diagnosing lastprivate
(or reduction etc.) on a variable that is private to containing parallel
results in ICEs later on, as there is no original list item to which store
the last result.
The target construct is unclear as it has an implicit parallel region
and it is not obvious if the data privatization clauses on the construct
shall be treated as data privatization on the implicit parallel or just
on the target.  For now treat those as privatization on the implicit
parallel, but treat map clauses as shared on the implicit parallel.

2021-07-21  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/101535
	* gimplify.c (omp_check_private): Properly skip ORT_TARGET_DATA
	contexts in which decl isn't privatized and for ORT_TARGET return
	false if decl is mapped.

	* c-c++-common/gomp/pr101535-1.c: New test.
	* c-c++-common/gomp/pr101535-2.c: New test.

(cherry picked from commit b136b7a787)
2022-05-11 07:58:26 +02:00
Jakub Jelinek 36eef10e03 c++: Ensure OpenMP reduction with reference type references complete type [PR101516]
The following testcase ICEs because we haven't verified if reduction decl
has reference type that TREE_TYPE of the reference is a complete type,
require_complete_type on the decl doesn't ensure that.

2021-07-21  Jakub Jelinek  <jakub@redhat.com>

	PR c++/101516
	* semantics.c (finish_omp_reduction_clause): Also call
	complete_type_or_else and return true if it fails.

	* g++.dg/gomp/pr101516.C: New test.

(cherry picked from commit aea199f96c)
2022-05-11 07:58:25 +02:00
Jakub Jelinek 883690ff6b rs6000: Fix up easy_vector_constant_msb handling [PR101384]
The following gcc.dg/pr101384.c testcase is miscompiled on
powerpc64le-linux.
easy_altivec_constant has code to try construct vector constants with
different element sizes, perhaps different from CONST_VECTOR's mode.  But as
written, that works fine for vspltis[bhw] cases, but not for the vspltisw
x,-1; vsl[bhw] x,x,x case, because that creates always a V16QImode, V8HImode
or V4SImode constant containing broadcasted constant with just the MSB set.
The vspltis_constant function etc. expects the vspltis[bhw] instructions
where the small [-16..15] or even [-32..30] constant is sign-extended to the
remaining step bytes, but that is not the case for the 0x80...00 constants,
with step 1 we can't handle e.g.
{ 0x80, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff }
vectors but do want to handle e.g.
{ 0, 0, 0, 0x80, 0, 0, 0, 0x80, 0, 0, 0, 0x80, 0, 0, 0, 0x80 }
and similarly with copies 1 we do want to handle e.g.
{ 0x80808080, 0x80808080, 0x80808080, 0x80808080 }.

This is a simpler version of the fix for backports, which limits the EASY_VECTOR_MSB case
matching to step == 1 && copies == 1, because that is the only case the
splitter handles correctly.

2021-07-20  Jakub Jelinek  <jakub@redhat.com>

	PR target/101384
	* config/rs6000/rs6000.c (vspltis_constant): Accept EASY_VECTOR_MSB
	only if step and copies are equal to 1.

	* gcc.dg/pr101384.c: New test.

(cherry picked from commit dc386b0208)
2022-05-11 07:58:25 +02:00
Jakub Jelinek 26c58b164f openmp - Fix up && and || reductions [PR94366]
As the testcase shows, the special treatment of && and || reduction combiners
where we expand them as omp_out = (omp_out != 0) && (omp_in != 0) (or with ||)
is not needed just for &&/|| on floating point or complex types, but for all
&&/|| reductions - when expanded as omp_out = omp_out && omp_in (not in C but
GENERIC) it is actually gimplified into NOP_EXPRs to bool from both operands,
which turns non-zero values multiple of 2 into 0 rather than 1.

This patch just treats all &&/|| the same and furthermore uses bool type
instead of int for the comparisons.

2021-07-01  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/94366
gcc/
	* omp-low.c (lower_rec_input_clauses): Rename is_fp_and_or to
	is_truth_op, set it for TRUTH_*IF_EXPR regardless of new_var's type,
	use boolean_type_node instead of integer_type_node as NE_EXPR type.
	(lower_reduction_clauses): Likewise.
libgomp/
	* testsuite/libgomp.c-c++-common/pr94366.c: New test.

(cherry picked from commit 91c771ec8a)
2022-05-11 07:58:25 +02:00
Tobias Burnus f1b95ed55a OpenMP: Support complex/float in && and || reduction
C/C++ permit logical AND and logical OR also with floating-point or complex
arguments by doing an unequal zero comparison; the result is an 'int' with
value one or zero.  Hence, those are also permitted as reduction variable,
even though it is not the most sensible thing to do.

gcc/c/ChangeLog:

	* c-typeck.c (c_finish_omp_clauses): Accept float + complex
	for || and && reductions.

gcc/cp/ChangeLog:

	* semantics.c (finish_omp_reduction_clause): Accept float + complex
	for || and && reductions.

gcc/ChangeLog:

	* omp-low.c (lower_rec_input_clauses, lower_reduction_clauses): Handle
	&& and || with floating-point and complex arguments.

gcc/testsuite/ChangeLog:

	* gcc.dg/gomp/clause-1.c: Use 'reduction(&:..)' instead of '...(&&:..)'.

libgomp/ChangeLog:

	* testsuite/libgomp.c-c++-common/reduction-1.c: New test.
	* testsuite/libgomp.c-c++-common/reduction-2.c: New test.
	* testsuite/libgomp.c-c++-common/reduction-3.c: New test.

(cherry picked from commit 1580fc7644)
2022-05-11 07:58:25 +02:00
Jakub Jelinek c910d79195 c++: Optimize away NULLPTR_TYPE comparisons [PR101443]
Comparisons of NULLPTR_TYPE operands cause all kinds of problems in the
middle-end and in fold-const.c, various optimizations assume that if they
see e.g. a non-equality comparison with one of the operands being
INTEGER_CST and it is not INTEGRAL_TYPE_P (which has TYPE_{MIN,MAX}_VALUE),
they can build_int_cst (type, 1) to find a successor.

The following patch fixes it by making sure they don't appear in the IL,
optimize them away at cp_fold time as all can be folded.

Though, I've just noticed that clang++ rejects the non-equality comparisons
instead, foo () > 0 with
invalid operands to binary expression ('decltype(nullptr)' (aka 'nullptr_t') and 'int')
and foo () > nullptr with
invalid operands to binary expression ('decltype(nullptr)' (aka 'nullptr_t') and 'nullptr_t')

Shall we reject those too, in addition or instead of parts of this patch?
If so, wouldn't this patch be still useful for backports, I bet we don't
want to start reject it on the release branches when we used to accept it.

2021-07-15  Jakub Jelinek  <jakub@redhat.com>

	PR c++/101443
	* cp-gimplify.c (cp_fold): For comparisons with NULLPTR_TYPE
	operands, fold them right away to true or false.

	* g++.dg/cpp0x/nullptr46.C: New test.

(cherry picked from commit 7094a69bd6)
2022-05-11 07:58:24 +02:00
Jakub Jelinek eb253e4148 godump: Fix -fdump-go-spec= reproduceability issue [PR101407]
pot_dummy_types is a hash_set from whose traversal the code prints some type
lines.  hash_set normally uses default_hash_traits which for pointer types
(the hash set hashes const char *) uses pointer_hash which hashes the
addresses of the pointers except of the least significant 3 bits.
With address space randomization, that results in non-determinism in the
-fdump-go-specs= generated file, each invocation can have different order of
the lines emitted from pot_dummy_types traversal.

This patch fixes it by hashing the string contents instead to make the
hashes reproduceable.

2021-07-14  Jakub Jelinek  <jakub@redhat.com>

	PR go/101407
	* godump.c (godump_str_hash): New type.
	(godump_container::pot_dummy_types): Use string_hash instead of
	ptr_hash in the hash_set.

(cherry picked from commit 3be762c2ed)
2022-05-11 07:58:24 +02:00
Jakub Jelinek 120182aa1e libgomp: Don't include limits.h instead of hidden visibility block
sem.h is included in between # pragma GCC visibility push(hidden)
and # pragma GCC visibility pop and includes limits.h there, which
since the introduction of sysconf declaration in recent glibcs
in there causes trouble.  libgomp assumes it is compiled by gcc,
so we don't really need to include limits.h there and can use
-__INT_MAX__ - 1 instead (which clang and icc support too for years).

2021-07-13  Jakub Jelinek  <jakub@redhat.com>
	    Florian Weimer  <fweimer@redhat.com>

	* config/linux/sem.h: Don't include limits.h.
	(SEM_WAIT): Define to -__INT_MAX__ - 1 instead of INT_MIN.
	* config/linux/affinity.c: Include limits.h.

(cherry picked from commit 42f10ba5b5)
2022-05-11 07:58:24 +02:00
Jakub Jelinek 1df7b899cd dwarf2out: Handle COMPOUND_LITERAL_EXPR in loc_list_from_tree_1 [PR101266]
In this case dwarf2out_decl is called from the FEs with GENERIC but not
yet gimplified expressions in it.

As loc_list_from_tree_1 has an exhaustive list of tree codes it wants to
handle and for checking asserts no other codes makes it in, we should
handle even GENERIC trees that shouldn't be valid in GIMPLE.

The following patch handles COMPOUND_LITERAL_EXPR by hnadling it like the
underlying VAR_DECL temporary.

Verified the emitted DWARF is correct (but unoptimized, we emit
DW_OP_lit1 DW_OP_lit1 DW_OP_minus for the upper bound).

2021-07-01  Jakub Jelinek  <jakub@redhat.com>

	PR debug/101266
	* dwarf2out.c (loc_list_from_tree_1): Handle COMPOUND_LITERAL_EXPR.

	* gcc.dg/pr101266.c: New test.

(cherry picked from commit b0ab968999)
2022-05-11 07:58:23 +02:00
Jakub Jelinek 57aeb7f535 match.pd: Avoid (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST opt in GENERIC when sanitizing [PR101210]
When we have (intptr_t) x == cst where x has REFERENCE_TYPE, this
optimization creates x == cst out of it where cst has REFERENCE_TYPE.
If it is done in GENERIC folding, it can results in ubsan failures
where the INTEGER_CST with REFERENCE_TYPE is instrumented.

Fixed by deferring it to GIMPLE folding in this case.

2021-06-29  Jakub Jelinek  <jakub@redhat.com>

	PR c++/101210
	* match.pd ((intptr_t)x eq/ne CST to x eq/ne (typeof x) CST): Don't
	perform the optimization in GENERIC when sanitizing and x has a
	reference type.

	* g++.dg/ubsan/pr101210.C: New test.

(cherry picked from commit 53fd7544af)
2022-05-11 07:58:23 +02:00
Jakub Jelinek d8e3b3434d c: Fix up c_parser_has_attribute_expression [PR101176]
This function keeps src_range member of the result uninitialized, which at
least under valgrind can show up later when those uninitialized location_t's
can make it into the IL or location_t hash tables.

2021-06-24  Jakub Jelinek  <jakub@redhat.com>

	PR c/101176
	* c-parser.c (c_parser_has_attribute_expression): Set source range for
	the result.

(cherry picked from commit 178fb8df93)
2022-05-11 07:58:21 +02:00
Jakub Jelinek be5f5f6ea3 c: Fix C cast error-recovery [PR101171]
The following testcase ICEs during error-recovery, as build_c_cast calls
note_integer_operands on error_mark_node and that wraps it into
C_MAYBE_CONST_EXPR which is unexpected and causes ICE later on.
Seems most other callers of note_integer_operands check early if something
is error_mark_node and return before calling note_integer_operands on it.

The following patch fixes it by not calling on error_mark_node, another
possibility would be to handle error_mark_node in note_integer_operands and
just return it.

2021-06-24  Jakub Jelinek  <jakub@redhat.com>

	PR c/101171
	* c-typeck.c (build_c_cast): Don't call note_integer_operands on
	error_mark_node.

	* gcc.dg/pr101171.c: New test.

(cherry picked from commit fdc5522fb0)
2022-05-11 07:58:21 +02:00
Jakub Jelinek 7ce8cb98ef openmp: Fix up *_reduction clause handling with UDRs on PARM_DECLs [PR101167]
The following testcase FAILs, because the UDR combiner is invoked incorrectly.
lower_omp_rec_clauses expects that when it sets
DECL_VALUE_EXPR/DECL_HAS_VALUE_EXPR_P
for both the placeholder and the var that everything will be properly
regimplified, but as the variable in question is a PARM_DECL rather than
VAR_DECL, lower_omp_regimplify_p doesn't say that it should be regimplified
and so it is not.

2021-06-23  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/101167
	* omp-low.c (lower_omp_regimplify_p): Regimplify also PARM_DECLs
	and RESULT_DECLs that have DECL_HAS_VALUE_EXPR_P set.

	* testsuite/libgomp.c-c++-common/task-reduction-15.c: New test.

(cherry picked from commit 679506c383)
2022-05-11 07:58:20 +02:00
Jakub Jelinek 21a95d88fe inline-asm: Fix ICE with bitfields in "m" operands [PR100785]
Bitfields, while they live in memory, aren't something inline-asm can easily
operate on.
For C and "=m" or "+m", we were diagnosing bitfields in the past in the
FE, where c_mark_addressable had:
      case COMPONENT_REF:
        if (DECL_C_BIT_FIELD (TREE_OPERAND (x, 1)))
          {
            error
              ("cannot take address of bit-field %qD", TREE_OPERAND (x, 1));
            return false;
          }
but that check got moved in GCC 6 to build_unary_op instead and now we
emit an error during expansion and ICE afterwards (i.e. error-recovery).
For "m" it used to be diagnosed in c_mark_addressable too, but since
GCC 6 it is ice-on-invalid.
For C++, this was never diagnosed in the FE, but used to be diagnosed
in the gimplifier and/or during expansion before 4.8.

The following patch does multiple things:
1) diagnoses it in the FEs
2) simplifies during expansion the inline asm if any errors have been
   reported (similarly how e.g. vregs pass if it detects errors on
   inline-asm either deletes them or simplifies to bare minimum -
   just labels), so that we don't have error-recovery ICEs there

2021-06-11  Jakub Jelinek  <jakub@redhat.com>

	PR inline-asm/100785
gcc/
	* cfgexpand.c (expand_asm_stmt): If errors are emitted,
	remove all inputs, outputs and clobbers from the asm and
	set template to "".
gcc/c/
	* c-typeck.c (c_mark_addressable): Diagnose trying to make
	bit-fields addressable.
gcc/cp/
	* typeck.c (cxx_mark_addressable): Diagnose trying to make
	bit-fields addressable.
gcc/testsuite/
	* c-c++-common/pr100785.c: New test.

(cherry picked from commit 644c2cc5f2)
2022-05-11 07:58:20 +02:00
Jakub Jelinek 80f194b25f stor-layout: Don't create DECL_BIT_FIELD_REPRESENTATIVE for QUAL_UNION_TYPE [PR101062]
> The following patch does create them, but treats all such bitfields as if
> they were in a structure where the particular bitfield is the only field.

While the patch passed bootstrap/regtest on the trunk, when trying to
backport it to 11 branch the bootstrap failed with
atree.ads:3844:34: size for "Node_Record" too small
errors.  Turns out the error is not about size being too small, but actually
about size being non-constant, and comes from:
 /* In a FIELD_DECL of a RECORD_TYPE, this is a pointer to the storage
    representative FIELD_DECL.  */
 #define DECL_BIT_FIELD_REPRESENTATIVE(NODE) \
   (FIELD_DECL_CHECK (NODE)->field_decl.qualifier)

 /* For a FIELD_DECL in a QUAL_UNION_TYPE, records the expression, which
    if nonzero, indicates that the field occupies the type.  */
  #define DECL_QUALIFIER(NODE) (FIELD_DECL_CHECK (NODE)->field_decl.qualifier)
so by setting up DECL_BIT_FIELD_REPRESENTATIVE in QUAL_UNION_TYPE we
actually set or modify DECL_QUALIFIER and then construct size as COND_EXPRs
with those bit field representatives (e.g. with array type) as conditions
which doesn't fold into constant.

The following patch fixes it by not creating DECL_BIT_FIELD_REPRESENTATIVEs
for QUAL_UNION_TYPE as there is nowhere to store them,

Shall we change tree.h to document that DECL_BIT_FIELD_REPRESENTATIVE
is valid also on UNION_TYPE?
I see:
tree-ssa-alias.c-  if (TREE_CODE (type1) == RECORD_TYPE
tree-ssa-alias.c:      && DECL_BIT_FIELD_REPRESENTATIVE (field1))
tree-ssa-alias.c:    field1 = DECL_BIT_FIELD_REPRESENTATIVE (field1);
tree-ssa-alias.c-  if (TREE_CODE (type2) == RECORD_TYPE
tree-ssa-alias.c:      && DECL_BIT_FIELD_REPRESENTATIVE (field2))
tree-ssa-alias.c:    field2 = DECL_BIT_FIELD_REPRESENTATIVE (field2);
Shall we change that to || == UNION_TYPE or do we assume all fields
are overlapping in a UNION_TYPE already?
At other spots (asan, ubsan, expr.c) it is unclear what will happen
if they see a QUAL_UNION_TYPE with a DECL_QUALIFIER (or does the Ada FE
lower that somehow)?

2021-06-18  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/101062
	* stor-layout.c (finish_bitfield_layout): Don't add bitfield
	representatives in QUAL_UNION_TYPE.

(cherry picked from commit 3587c2c241)
2022-05-11 07:58:20 +02:00
Jakub Jelinek d0b1d8d3b8 stor-layout: Create DECL_BIT_FIELD_REPRESENTATIVE even for bitfields in unions [PR101062]
The following testcase is miscompiled on x86_64-linux, the bitfield store
is implemented as a RMW 64-bit operation at d+24 when the d variable has
size of only 28 bytes and scheduling moves in between the R and W part
a store to a different variable that happens to be right after the d
variable.

The reason for this is that we weren't creating
DECL_BIT_FIELD_REPRESENTATIVEs for bitfields in unions.

The following patch does create them, but treats all such bitfields as if
they were in a structure where the particular bitfield is the only field.

2021-06-16  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/101062
	* stor-layout.c (finish_bitfield_representative): For fields in unions
	assume nextf is always NULL.
	(finish_bitfield_layout): Compute bit field representatives also in
	unions, but handle it as if each bitfield was the only field in the
	aggregate.

	* gcc.dg/pr101062.c: New test.

(cherry picked from commit b4b50bf286)
2022-05-11 07:58:19 +02:00
Jakub Jelinek 878cfeb7ff testsuite: Use noipa attribute instead of noinline, noclone
I've noticed this test now on various arches sometimes FAILs, sometimes
PASSes (the line 12 test in particular).

The problem is that a = 0; initialization in the caller no longer happens
before the f(&a) call as what the argument points to is only used in
debug info.

Making the function noipa forces the caller to initialize it and still
tests what the test wants to test, namely that we don't consider *p as
valid location for the c variable at line 18 (after it has been overwritten
with *p = 1;).

2021-06-16  Jakub Jelinek  <jakub@redhat.com>

	* gcc.dg/guality/pr49888.c (f): Use noipa attribute instead of
	noinline, noclone.

(cherry picked from commit a490b1dc0b)
2022-05-11 07:58:19 +02:00
Jakub Jelinek 37be80af29 libffi: Fix up x86_64 classify_argument
As the following testcase shows, libffi didn't handle properly
classify_arguments of structures at byte offsets not divisible by
UNITS_PER_WORD.  The following patch adjusts it to match what
config/i386/ classify_argument does for that and also ports the
PR38781 fix there (the second chunk).

This has been committed to upstream libffi already:
5651bea284

2021-06-16  Jakub Jelinek  <jakub@redhat.com>

	* src/x86/ffi64.c (classify_argument): For FFI_TYPE_STRUCT set words
	to number of words needed for type->size + byte_offset bytes rather
	than just type->size bytes.  Compute pos before the loop and check
	total size of the structure.
	* testsuite/libffi.call/nested_struct12.c: New test.

(cherry picked from commit 041f741770)
2022-05-11 07:58:19 +02:00
Jakub Jelinek 2f682080c1 expr: Fix up VEC_PACK_TRUNC_EXPR expansion [PR101046]
The following testcase ICEs, because we have a mode mismatch.
VEC_PACK_TRUNC_EXPR's operands have different modes from the result
(same vector mode size but twice as large element),
but we were passing non-NULL subtarget with the mode of the result
to the expansion of its arguments, so the VEC_PERM_EXPR in one of the
operands which had V8SImode operands and result had V16HImode target.

Fixed by clearing the subtarget if we are changing mode.

2021-06-15  Jakub Jelinek  <jakub@redhat.com>

	PR target/101046
	* expr.c (expand_expr_real_2) <case VEC_PACK_FIX_TRUNC_EXPR,
	case VEC_PACK_TRUNC_EXPR>: Clear subtarget when changing mode.

(cherry picked from commit 008153c843)
2022-05-11 07:58:18 +02:00
Jakub Jelinek 97785bcbc6 tree-inline: Fix up __builtin_va_arg_pack handling [PR100898]
The following testcase ICEs, because gimple_call_arg_ptr (..., 0)
asserts that there is at least one argument, while we were using
it even if we didn't copy anything just to get a pointer from/to which
the zero arguments should be copied.

Fixed by guarding the memcpy calls.  Also, the code was calling
gimple_call_num_args too many times - 5 times instead of 2, so the patch
adds two temporaries for those.

2021-06-07  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/100898
	* tree-inline.c (copy_bb): Only use gimple_call_arg_ptr if memcpy
	should copy any arguments.  Don't call gimple_call_num_args
	on id->call_stmt or call_stmt more than once.

	* g++.dg/ext/va-arg-pack-3.C: New test.

(cherry picked from commit d66a703c8b)
2022-05-11 07:58:18 +02:00
Jakub Jelinek e7e1ad9400 x86: Fix ix86_expand_vector_init for V*TImode [PR100887]
We have vec_initv4tiv2ti and vec_initv2titi patterns which call
ix86_expand_vector_init and assume it works for those modes.  For the
case of construction from two half-sized vectors, the code assumes it
will always succeed, but we have only insn patterns with SImode and DImode
element types.  QImode and HImode element types are already handled
by performing it with same sized vectors with SImode elements and the
following patch extends that to V*TImode vectors.

2021-06-04  Jakub Jelinek  <jakub@redhat.com>

	PR target/100887
	* config/i386/i386.c (ix86_expand_vector_init): Handle
	concatenation from half-sized modes with TImode elements.

(cherry picked from commit b7dd2e4eeb)
2022-05-11 07:58:18 +02:00
Jakub Jelinek 6a05023c87 c++: Avoid -Wunused-value false positives on nullptr passed to ellipsis [PR100666]
When passing expressions with decltype(nullptr) type with side-effects to
ellipsis, we pass (void *)0 instead, but for the side-effects evaluate them
on the lhs of a COMPOUND_EXPR.  Unfortunately that means we warn about it
if the expression is a call to nodiscard marked function, even when the
result is really used, just needs to be transformed.

Fixed by adding a warning_sentinel.

2021-05-25  Jakub Jelinek  <jakub@redhat.com>

	PR c++/100666
	* call.c (convert_arg_to_ellipsis): For expressions with NULLPTR_TYPE
	and side-effects, temporarily disable -Wunused-result warning when
	building COMPOUND_EXPR.

	* g++.dg/cpp1z/nodiscard8.C: New test.
	* g++.dg/cpp1z/nodiscard9.C: New test.

(cherry picked from commit ad52d89808)
2022-05-11 07:58:18 +02:00
Jakub Jelinek 8552cfa658 testsuite: Add testcase for already fixed PR
2021-05-14  Jakub Jelinek  <jakub@redhat.com>

	* g++.dg/cpp1y/pr88872.C: New test.

(cherry picked from commit f05627d404)
2022-05-11 07:58:17 +02:00
Jakub Jelinek ba374dfb93 expand: Don't reuse DEBUG_EXPRs with vector type if they have different modes [PR100508]
The inliner doesn't remap DEBUG_EXPR_DECLs, so the same decls can appear
in multiple functions.
Furthermore, expansion reuses corresponding DEBUG_EXPRs too, so they again
can be reused in multiple functions.
Neither of that is a major problem, DEBUG_EXPRs are just magic value holders
and what value they stand for is independent in each function and driven by
what debug stmts or DEBUG_INSNs they are bound to.
Except for DEBUG_EXPR*s with vector types, TYPE_MODE can be either BLKmode
or some vector mode depending on whether current function's enabled ISAs
support that vector mode or not.  On the following testcase, we expand it
first in foo function without AVX2 enabled and so the DEBUG_EXPR is
BLKmode, but later the same DEBUG_EXPR_DECL is used in a simd clone with
AVX2 enabled and expansion ICEs because of a mode mismatch.

The following patch fixes that by forcing recreation of a DEBUG_EXPR if
there is a mode mismatch for vector typed DEBUG_EXPR_DECL, DEBUG_EXPRs
will be still reused in between functions otherwise and within the same
function the mode should be always the same.

2021-05-12  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/100508
	* cfgexpand.c (expand_debug_expr): For DEBUG_EXPR_DECL with vector
	type, don't reuse DECL_RTL if it has different mode, instead force
	creation of a new DEBUG_EXPR.

	* gcc.dg/gomp/pr100508.c: New test.

(cherry picked from commit 19040050aa)
2022-05-11 07:58:17 +02:00
Jakub Jelinek c0844e1058 openmp: Fix up taskloop reduction ICE if taskloop has no iterations [PR100471]
When a taskloop doesn't have any iterations, GOMP_taskloop* takes an early
return, doesn't create any tasks and more importantly, doesn't create
a taskgroup and doesn't register task reductions.  But, the code emitted
in the callers assumes task reductions have been registered and performs
the reduction handling and task reduction unregistration.  The pointer
to the task reduction private variables is reused, on input it is the alignment
and only on output it is the pointer, so in the case taskloop with no iterations
the caller attempts to dereference the alignment value as if it was a pointer
and crashes.  We could in the early returns register the task reductions
only to have them looped over and unregistered in the caller, but I think
it is better to tell the caller there is nothing to task reduce and bypass
all that.

2021-05-11  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/100471
	* omp-low.c (lower_omp_task_reductions): For OMP_TASKLOOP, if data
	is 0, bypass the reduction loop including
	GOMP_taskgroup_reduction_unregister call.

	* taskloop.c (GOMP_taskloop): If GOMP_TASK_FLAG_REDUCTION and not
	GOMP_TASK_FLAG_NOGROUP, when doing early return clear the task
	reduction pointer.
	* testsuite/libgomp.c/task-reduction-4.c: New test.

(cherry picked from commit 98acbb3111)
2022-05-11 07:58:17 +02:00
GCC Administrator 36fad8d7cf Daily bump. 2022-05-11 00:20:59 +00:00
Eric Botcazou 666d0884e1 Fix internal error with vectorization on SPARC
This is a regression present since the 10.x series, but the underlying issue
has been there since the TARGET_VEC_PERM_CONST hook was implemented, in the
form of an ICE when expanding a constant VEC_PERM_EXPR in V4QI, while the
back-end only supports V8QI constant VEC_PERM_EXPRs.

gcc/
	PR target/105292
	* config/sparc/sparc.c (sparc_vectorize_vec_perm_const): Return
	true only for 8-byte vector modes.

gcc/testsuite/
	* gcc.target/sparc/20220510-1.c: New test.
2022-05-10 09:48:19 +02:00
GCC Administrator 3c50572093 Daily bump. 2022-05-10 00:20:31 +00:00
Jonathan Wakely b005000525 libstdc++: Fix deserialization for std::normal_distribution [PR105502]
This fixes a regression in std::normal_distribution deserialization that
caused the object to be left unchanged if the __state_avail value read
from the stream was false.

libstdc++-v3/ChangeLog:

	PR libstdc++/105502
	* include/bits/random.tcc
	(operator>>(basic_istream<C,T>&, normal_distribution<R>&)):
	Update state when __state_avail is false.
	* testsuite/26_numerics/random/normal_distribution/operators/serialize.cc:
	Check that deserialized object equals serialized one.

(cherry picked from commit 909ef4e272)
2022-05-09 17:42:57 +01:00
Jonathan Wakely d6f5b5d949 libstdc++: Fix test that fails for C++98 mode
When I backported r11-2760 as r10-8644 I simplified it and didn't add
the new _GLIBCXX11_DEPRECATED macro. That means that the macro used on
the old iostream members does nothing for C++98 mode, and so the test
fails. This adjusts the test to only expect warnigns for C++11 and
later.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/types/1.cc: Add c++11 target selector to
	warnings.

(cherry picked from commit 4e1b821ca3)
2022-05-09 17:38:44 +01:00
Jonathan Wakely a1667b7a7b libstdc++: Remove un-implementable noexcept from Filesystem TS operations
LWG 3014 removed these incorrect noexcept specifications from the C++17
std::filesystem operations. They are also incorrect on the experimental
TS versions and should be removed from them too.

libstdc++-v3/ChangeLog:

	* include/experimental/bits/fs_ops.h (fs::copy_file): Remove
	noexcept.
	(fs::create_directories): Likewise.
	(fs::remove_all): Likewise.
	* src/filesystem/ops.cc (fs::copy_file): Remove noexcept.
	(fs::create_directories): Likewise.
	(fs::remove_all): Likewise.

(cherry picked from commit da72e0fd20)
2022-05-09 17:37:49 +01:00
Jonathan Wakely 93a6219916 libstdc++: Fix std::exception_ptr regressions [PR103630]
This restores support for std::make_exception_ptr<E&> and for using
std::exception_ptr in C++98.

Because the new non-throwing implementation needs to use std::decay to
handle references the original throwing implementation is used for
C++98.

We also need to change the typeid expression so it doesn't yield the
dynamic type when the function parameter is a reference to a polymorphic
type. Otherwise the new exception object could be caught by any handler
matching the dynamic type, even though the actual exception object is
only a copy of the base class, sliced to the static type.

libstdc++-v3/ChangeLog:

	PR libstdc++/103630
	* libsupc++/exception_ptr.h (make_exception_ptr): Decay the
	template parameter. Use typeid of the static type.
	* testsuite/18_support/exception_ptr/103630.cc: New test.

(cherry picked from commit a1ca039fc0)
2022-05-09 17:37:49 +01:00
Jonathan Wakely 740e1ae177 libstdc++: Test errno macros directly for all targets [PR 93151]
This applies the same changes to the djgpp and mingw versions of
error_constants.h as r11-6137 did for the generic version.

All of these constants are defined as macros by <errno.h> on these
targets, so we can just test the macro directly instead of checking for
it at configure time.

libstdc++-v3/ChangeLog:

	PR libstdc++/93151
	* config/os/djgpp/error_constants.h: Test POSIX errno macros
	directly, instead of corresponding _GLIBCXX_HAVE_EXXX macros.
	* config/os/mingw32-w64/error_constants.h: Likewise.
	* config/os/mingw32/error_constants.h: Likewise.

(cherry picked from commit 217d5beaff)
2022-05-09 17:37:22 +01:00
Jonathan Wakely 4b5211c85a libstdc++: Test errno macros directly, not via autoconf [PR 93151]
This fixes a bug caused by a mismatch between the macros defined by
<errno.h> when GCC is built and the macros defined by <errno.h> when
users include <system_error>. If the user code is compiled with
_XOPEN_SOURCE defined to 500 or 600, Darwin suppresses the
ENOTRECOVERABLE and EOWNERDEAD macros, which are not defined by SUSv3
(aka POSIX.1-2001).

Since POSIX requires the errno macros to be macros (and not variables or
enumerators) we can just test for them directly using the preprocessor.
That means that <system_error> will match what is actually defined when
it's included, not what was defined when GCC was built. With that change
there is no need for the GLIBCXX_CHECK_SYSTEM_ERROR configure checks and
they can be removed.

libstdc++-v3/ChangeLog:

	PR libstdc++/93151
	* acinclude.m4 (GLIBCXX_CHECK_SYSTEM_ERROR): Remove.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (GLIBCXX_CHECK_SYSTEM_ERROR): Do not use.
	* config/os/generic/error_constants.h: Test POSIX errno macros
	directly, instead of corresponding _GLIBCXX_HAVE_EXXX macros.
	* testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc:
	Likewise.
	* testsuite/19_diagnostics/headers/system_error/93151.cc: New
	test.

(cherry picked from commit a2c2eec183)
2022-05-09 17:37:21 +01:00
Jonathan Wakely 47c48fcfbe libstdc++: Fix undefined behaviour in std::string
This fixes a ubsan error when constructing a string with a null pointer:

bits/basic_string.h:534:21: runtime error: applying non-zero offset 18446744073709551615 to null pointer

The _M_construct function only cares whether the second pointer is
non-null, so create a non-null value without undefined arithmetic.

We can also pass the random_access_iterator_tag directly to the
_M_construct function, to avoid going via the tag dispatching
_M_construct_aux, because we know we have pointers not integers here.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (basic_string(const CharT*, const A&)):
	Do not do arithmetic on null pointer.

(cherry picked from commit 789c57bc5f)
2022-05-09 17:37:21 +01:00
Jonathan Wakely 5ed333b076 libstdc++: Add additional overload of std::lerp [PR101870]
The [cmath.syn] p1 wording about additional overloads sufficient to
handle any arithmetic types also applies to std::lerp. This adds a new
overload of std::lerp that does the required promotions to support
arguments of arbitrary arithmetic types.

A new __promoted_t alias template is added, which the C++17 function
templates std::hypot and std::lerp can use to avoid instantiating the
__promote_3 class template.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	PR libstdc++/101870
	* include/c_global/cmath (hypot): Use __promoted_t.
	(lerp): Add new overload accepting any arithmetic types.
	* include/ext/type_traits.h (__promoted_t): New alias template.
	* testsuite/26_numerics/lerp.cc: Moved to...
	* testsuite/26_numerics/lerp/1.cc: ...here.
	* testsuite/26_numerics/lerp/constexpr.cc: New test.
	* testsuite/26_numerics/lerp/version.cc: New test.

(cherry picked from commit 9017326e19)
2022-05-09 17:37:21 +01:00
Jonathan Wakely b4a170bf3a libstdc++: Do not allocate a zero-size vector<bool> [PR 100153]
The vector<bool>::shrink_to_fit() implementation will allocate new
storage even if the vector is empty. That then leads to the
end-of-storage pointer being non-null and equal to the _M_start._M_p
pointer, which means that _M_end_addr() has undefined behaviour.

The fix is to stop doing a useless zero-sized allocation in
shrink_to_fit(), so that _M_start._M_p and _M_end_of_storage are both
null after an empty vector shrinks.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	PR libstdc++/100153
	* include/bits/vector.tcc (vector<bool>::_M_shrink_to_fit()):
	When size() is zero just deallocate and reset.

(cherry picked from commit 681707ec28)
2022-05-09 17:37:21 +01:00
Jonathan Wakely a5ae767c18 libstdc++: Add missing header to test
We need to include <iterator> (or one of the containers) to get a
definition for std::begin.

libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/is_permutation/2.cc: Include <iterator>.

(cherry picked from commit 94311bf347)
2022-05-09 17:37:21 +01:00
Pavel I. Kryukov 79b7b82434 libstdc++: Add self-merge check to std::forward_list::merge [PR103853]
This implements the proposed resolution of LWG 3088, so that x.merge(x)
is a no-op, consistent with std::list::merge.

Signed-off-by: Pavel I. Kryukov <pavel.kryukov@phystech.edu>

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	PR libstdc++/103853
	* include/bits/forward_list.tcc (forward_list::merge): Check for
	self-merge.
	* testsuite/23_containers/forward_list/operations/merge.cc: New test.

(cherry picked from commit 52ebc2be09)
2022-05-09 17:37:20 +01:00
Jonathan Wakely 756d1581d1 libstdc++: Initialize member in std::match_results [PR103549]
This fixes a -Wuninitialized warning for std::cmatch m1, m2; m1=m2;

Also name the template parameters in the forward declaration, to get rid
of the <template-parameter-1-1> noise in diagnostics.

libstdc++-v3/ChangeLog:

	PR libstdc++/103549
	* include/bits/regex.h (match_results): Give names to template
	parameters in first declaration.
	(match_results::_M_begin): Add default member-initializer.

(cherry picked from commit 87710ec7b2)
2022-05-09 17:37:20 +01:00
Jonathan Wakely dae73190d4 libstdc++: Fix example preprocessor command in FAQ [PR103877]
libstdc++-v3/ChangeLog:

	PR libstdc++/103877
	* doc/xml/faq.xml: Add '-x c++' to preprocessor command.
	* doc/html/faq.html: Regenerate.

(cherry picked from commit cebe875f6f)
2022-05-09 17:37:20 +01:00
Jonathan Wakely de3549eb7b libstdc++: Rename non-reserved macros in config header [PR103650]
libstdc++-v3/ChangeLog:

	PR libstdc++/103650
	* include/Makefile.am: Rename LT_OBJDIR and STDC_HEADERS.
	* include/Makefile.in: Regenerate.
	* testsuite/17_intro/headers/c++1998/103650.cc: New test.

(cherry picked from commit fa092570fb)
2022-05-09 17:37:20 +01:00
Jonathan Wakely 7240bd42bf libstdc++: Fix mismatched noexcept-specifiers in Filesystem TS
The copy_file fix should have been part of r12-7063-gda72e0fd20f87b.

The path::begin() fix should have been part of r12-3930-gf2b7f56a15d9cb.
Thanks to Timm Bäder for reporting this one.

libstdc++-v3/ChangeLog:

	* include/experimental/bits/fs_fwd.h (copy_file): Remove
	incorrect noexcept from declaration.
	* include/experimental/bits/fs_path.h (path::begin, path::end):
	Add noexcept to declarations, to match definitions.

(cherry picked from commit 944da70a5d)
2022-05-09 17:37:20 +01:00