Commit graph

202156 commits

Author SHA1 Message Date
GCC Administrator
69d3015ad1 Daily bump. 2023-07-01 00:18:32 +00:00
Patrick Palka
db38b285ba c++: fix up caching of level lowered ttps
Due to level/depth mismatches between the template parameters of a level
lowered ttp and the original ttp, the ttp comparison check added by
r14-418-g0bc2a1dc327af9 never actually holds outside of erroneous cases.
Moreover, it'd be good to also cache the overall TEMPLATE_TEMPLATE_PARM
instead of only the TEMPLATE_PARM_INDEX.

It's tricky to cache all level lowered ttps since the result of level
lowering may depend on more than just the depth of the arguments, e.g.
for TT in

  template<class T>
  struct A {
    template<template<T> class TT> void f();
  }

the substitution T=int yields a different level-lowered ttp than T=char.
But these kinds of ttps seem to be rare in practice, and "simple" ttps
that don't depend on outer template parameters are easy enough to cache
like so.  Unfortunately, this means we're back to expecting a duplicate
error in nontype12.C again since the ttp in question isn't "simple" so
caching of the (erroneous) lowered ttp doesn't happen.

gcc/cp/ChangeLog:

	* cp-tree.h (TEMPLATE_PARM_DESCENDANTS): Harden.
	(TEMPLATE_TYPE_DESCENDANTS): Define.
	(TEMPLATE_TEMPLATE_PARM_SIMPLE_P): Define.
	* pt.cc (reduce_template_parm_level): Revert
	r14-418-g0bc2a1dc327af9 change.
	(process_template_parm): Set TEMPLATE_TEMPLATE_PARM_SIMPLE_P
	appropriately.
	(uses_outer_template_parms): Determine the outer depth of
	a template template parm without relying on DECL_CONTEXT.
	(tsubst) <case TEMPLATE_TEMPLATE_PARM>: Cache lowering a
	simple template template parm.  Consistently use 'code'.

gcc/testsuite/ChangeLog:

	* g++.dg/template/nontype12.C: Refine and XFAIL the dg-bogus
	duplicate diagnostic check.
2023-06-30 15:05:22 -04:00
Qing Zhao
e050ce7c3a Use TYPE_INCLUDES_FLEXARRAY in __builtin_object_size [PR tree-optimization/101832]
__builtin_object_size should treat struct with TYPE_INCLUDES_FLEXARRAY as
flexible size.

gcc/ChangeLog:

	PR tree-optimization/101832
	* tree-object-size.cc (addr_object_size): Handle structure/union type
	when it has flexible size.

gcc/testsuite/ChangeLog:

	PR tree-optimization/101832
	* gcc.dg/builtin-object-size-pr101832.c: New test.
2023-06-30 18:24:34 +00:00
Eric Botcazou
db5d70632a Fix couple of endianness issues in fold_ctor_reference
fold_ctor_reference attempts to use a recursive local processing in order
to call native_encode_expr on the leaf nodes of the constructor, before
falling back to calling native_encode_initializer if this fails.

There are a couple of issues related to endianness present in it:
  1) it does not specifically handle integral bit-fields; now these are left
justified on big-endian platforms so cannot be treated like ordinary fields.
  2) it does not check that the constructor uses the native storage order.

gcc/
	* gimple-fold.cc (fold_array_ctor_reference): Fix head comment.
	(fold_nonarray_ctor_reference): Likewise.  Specifically deal
	with integral bit-fields.
	(fold_ctor_reference): Make sure that the constructor uses the
	native storage order.

gcc/testsuite/
	* gcc.c-torture/execute/20230630-1.c: New test.
	* gcc.c-torture/execute/20230630-2.c: Likewise.
	* gcc.c-torture/execute/20230630-3.c: Likewise
	* gcc.c-torture/execute/20230630-4.c: Likewise
2023-06-30 18:12:21 +02:00
David Malcolm
c3c0ba5436 jit.exp: handle dwarf version mismatch in jit-check-debug-info [PR110466]
gcc/testsuite/ChangeLog:
	PR jit/110466
	* jit.dg/jit.exp (jit-check-debug-info): Gracefully handle too
	early versions of gdb that don't support our dwarf version, via
	"unsupported".

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-06-30 11:20:02 -04:00
David Malcolm
6735d66083 jit: avoid using __vector in testcase [PR110466]
r13-4531-gd2e782cb99c311 added test coverage to libgccjit's vector
support, but used __vector, which doesn't work on Power.  Additionally
the size param to gcc_jit_type_get_vector was wrong.

Fixed thusly.

gcc/testsuite/ChangeLog:
	PR jit/110466
	* jit.dg/test-expressions.c (run_test_of_comparison): Fix size
	param to gcc_jit_type_get_vector.
	(verify_comparisons): Use a typedef rather than __vector.

Co-authored-by: Marek Polacek <polacek@redhat.com>
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-06-30 11:20:02 -04:00
Jonathan Wakely
fe2651affa libstdc++: Fix iostream init for Clang on darwin [PR110432]
The __has_attribute(init_priority) check in <iostream> is true for Clang
on darwin, which means that user code including <iostream> thinks the
library will initialize the global streams. However, when libstdc++ is
built by GCC on darwin, the __has_attribute(init_priority) check is
false, which means that the library thinks that user code will do the
initialization when <iostream> is included. This means that the
initialization is never done.

Add an autoconf check so that the header and the library both make their
decision based on the static properties of GCC at build time, with a
consistent outcome.

As a belt and braces check, also do the initialization in <iostream> if
the compiler including that header doesn't support the attribute (even
if the library also containers the initialization). This might result in
redundant initialization done in <iostream>, but ensures the
initialization happens somewhere if there's any doubt about the
attribute working correctly due to missing linker support.

libstdc++-v3/ChangeLog:

	PR libstdc++/110432
	* acinclude.m4 (GLIBCXX_CHECK_INIT_PRIORITY): New.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Use GLIBCXX_CHECK_INIT_PRIORITY.
	* include/std/iostream: Use new autoconf macro as well as
	__has_attribute.
	* src/c++98/ios_base_init.h: Use new autoconf macro instead of
	__has_attribute.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2023-06-30 15:35:02 +01:00
Jonathan Wakely
d083c8c808 libstdc++: Fix unused warning for new variable
This newly-introduced variable isn't used on all paths, so add the
[[maybe_unused]] attribute.

libstdc++-v3/ChangeLog:

	* src/c++11/random.cc (random_device::_M_init): Add maybe_unused
	attribute.
2023-06-30 15:29:51 +01:00
Jan Hubicka
eab57b825b Fix handling of __builtin_expect_with_probability and improve first-match heuristics
While looking into the std::vector _M_realloc_insert codegen I noticed that
call of __throw_bad_alloc is predicted with 10% probability. This is because
the conditional guarding it has __builtin_expect (cond, 0) on it.  This
incorrectly takes precedence over more reliable heuristics predicting that call
to cold noreturn is likely not going to happen.

So I reordered the predictors so __builtin_expect_with_probability comes first
after predictors that never makes a mistake (so user can use it to always
specify the outcome by hand).  I also downgraded malloc predictor since I do
think user-defined malloc functions & new operators may behave funny ways and
moved usual __builtin_expect after the noreturn cold predictor.

This triggered latent bug in expr_expected_value_1 where

	  if (*predictor < predictor2)
 	    *predictor = predictor2;

should be:

 	  if (predictor2 < *predictor)
 	    *predictor = predictor2;

which eventually triggered an ICE on combining heuristics.  This made me notice
that we can do slightly better while combining expected values in case only
one of the parameters (such as in a*b when we expect a==0) can determine
overall result.

Note that the new code may pick weaker heuristics in case that both values are
predicted.  Not sure if this scenario is worth the extra CPU time: there is
not correct way to combine the probabilities anyway since we do not know if
the predictions are independent, so I think users should not rely on it.

Fixing this issue uncovered another problem.  In 2018 Martin Liska added
code predicting that MALLOC returns non-NULL but instead of that he predicts
that it returns true (boolean 1).  This sort of works for testcase testing
 malloc (10) != NULL
but, for example, we will predict
 malloc (10) == malloc (10)
as true, which is not right and such comparsion may happen in real code

I think proper way is to update expr_expected_value_1 to work with value
ranges, but that needs greater surgery so I decided to postpone this and
only add FIXME and fill PR110499.

gcc/ChangeLog:

	PR middle-end/109849
	* predict.cc (estimate_bb_frequencies): Turn to static function.
	(expr_expected_value_1): Fix handling of binary expressions with
	predicted values.
	* predict.def (PRED_MALLOC_NONNULL): Move later in the priority queue.
	(PRED_BUILTIN_EXPECT_WITH_PROBABILITY): Move to almost top of the priority
	queue.
	* predict.h (estimate_bb_frequencies): No longer declare it.

gcc/testsuite/ChangeLog:

	PR middle-end/109849
	* gcc.dg/predict-18.c: Improve testcase.
2023-06-30 16:27:27 +02:00
Iain Sandoe
ef4ea6e087 modula-2: Amend the handling of failed select() calls in RTint [PR108835].
When we make a select() that fails, there is an attempt to (a) diagnose
why and (b) make a fallback.  These actions are causing some tests to
hang on some Darwin versions, this is because the first action that is
tried to assist in diagnosis/fallback handling is to replace the set
timeout with NIL (which causes select to wait forever, modulo other
reasons it might complete).

To fix this, call select with a zero timeout when checking for error
conditions.  Also, as we check the possible failure conditions, if we
find a change that succeeds, then stop looking for errors.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

	PR testsuite/108835

gcc/m2/ChangeLog:

	* gm2-libs/RTint.mod: Do not use NIL timeout setting on select,
	test failures sequentially, finishing on the first success.
2023-06-30 15:15:35 +01:00
Jonathan Wakely
d6a6a4ea08 libstdc++: Make std::random_device throw more std::system_error [PR105081]
In r14-289-gf9412cedd6c0e7 I made the std::random_device constructor
throw std::system_error for unrecognized tokens. But it still throws
std::runtime_error for a token such as "rdseed" that is recognized but
not supported at runtime by the CPU the program is running on.

With this change we throw std::system_error for those cases too. This
fixes the following failures on Intel CPUs withour rdseed support:

FAIL: 26_numerics/random/random_device/94087.cc execution test
FAIL: 26_numerics/random/random_device/cons/token.cc execution test
FAIL: 26_numerics/random/random_device/entropy.cc execution test

libstdc++-v3/ChangeLog:

	PR libstdc++/105081
	* src/c++11/random.cc (random_device::_M_init): Throw
	std::system_error when the requested device is a valid token but
	not available at runtime.
2023-06-30 15:09:17 +01:00
Uros Bizjak
ca15abc0ff fold-const+optabs: Change return type of predicate functions from int to bool
Also change some internal variables and function argument from int to bool.

gcc/ChangeLog:

	* fold-const.h (multiple_of_p): Change return type from int to bool.
	* fold-const.cc (split_tree): Change negl_p, neg_litp_p,
	neg_conp_p and neg_var_p variables to bool.
	(const_binop): Change sat_p variable to bool.
	(merge_ranges): Change no_overlap variable to bool.
	(extract_muldiv_1): Change same_p variable to bool.
	(tree_swap_operands_p): Update function body for bool return type.
	(fold_truth_andor): Change commutative variable to bool.
	(multiple_of_p): Change return type
	from int to void and adjust function body accordingly.
	* optabs.h (expand_twoval_unop): Change return type from int to bool.
	(expand_twoval_binop): Ditto.
	(can_compare_p): Ditto.
	(have_add2_insn): Ditto.
	(have_addptr3_insn): Ditto.
	(have_sub2_insn): Ditto.
	(have_insn_for): Ditto.
	* optabs.cc (add_equal_note): Ditto.
	(widen_operand): Change no_extend argument from int to bool.
	(expand_binop): Ditto.
	(expand_twoval_unop): Change return type
	from int to void and adjust function body accordingly.
	(expand_twoval_binop): Ditto.
	(can_compare_p): Ditto.
	(have_add2_insn): Ditto.
	(have_addptr3_insn): Ditto.
	(have_sub2_insn): Ditto.
	(have_insn_for): Ditto.
2023-06-30 16:04:02 +02:00
Oluwatamilore Adebayo
900945f663 AArch64: New RTL for ABDL
This patch adds new RTL for ABDL (sabdl, sabdl2, uabdl, uabdl2).

gcc/ChangeLog:

	* config/aarch64/aarch64-simd.md
	(vec_widen_<su>abdl_lo_<mode>, vec_widen_<su>abdl_hi_<mode>):
	Expansions for abd vec widen optabs.
	(aarch64_<su>abdl<mode>_insn): VQW based abdl RTL.
	* config/aarch64/iterators.md (USMAX_EXT): Code attributes
	that give the appropriate extend RTL for the max RTL.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/abd_2.c: Added ABDL testcases.
	* gcc.target/aarch64/abd_3.c: Added ABDL testcases.
	* gcc.target/aarch64/abd_4.c: Added ABDL testcases.
	* gcc.target/aarch64/abd_none_2.c: Added ABDL testcases.
	* gcc.target/aarch64/abd_none_3.c: Added ABDL testcases.
	* gcc.target/aarch64/abd_none_4.c: Added ABDL testcases.
	* gcc.target/aarch64/abd_run_1.c: Added ABDL testcases.
	* gcc.target/aarch64/sve/abd_1.c: Added ABDL testcases.
	* gcc.target/aarch64/sve/abd_2.c: Added ABDL testcases.
	* gcc.target/aarch64/sve/abd_none_1.c: Added ABDL testcases.
	* gcc.target/aarch64/sve/abd_none_2.c: Added ABDL testcases.
2023-06-30 12:28:45 +01:00
Oluwatamilore Adebayo
aec90c8bf3 Mid engine setup [SU]ABDL
This updates vect_recog_abd_pattern to recognize the widening
variant of absolute difference (ABDL, ABDL2).

gcc/ChangeLog:

	* internal-fn.def (VEC_WIDEN_ABD): New internal hilo optab.
	* optabs.def (vec_widen_sabd_optab,
	vec_widen_sabd_hi_optab, vec_widen_sabd_lo_optab,
	vec_widen_sabd_odd_even, vec_widen_sabd_even_optab,
	vec_widen_uabd_optab,
	vec_widen_uabd_hi_optab, vec_widen_uabd_lo_optab,
	vec_widen_uabd_odd_even, vec_widen_uabd_even_optab):
	New optabs.
	* doc/md.texi: Document them.
	* tree-vect-patterns.cc (vect_recog_abd_pattern): Update to
	to build a VEC_WIDEN_ABD call if the input precision is smaller
	than the precision of the output.
	(vect_recog_widen_abd_pattern): Should an ABD expression be
	found preceeding an extension, replace the two with a
	VEC_WIDEN_ABD.
2023-06-30 12:28:45 +01:00
Martin Jambor
80f312154e
Regenrate lto-plugin/Makefile.in
Commit regenerated lto-plugin/Makefile.in in order to reflect changes
introduction of --enable-host-pie.

lto-plugin/ChangeLog:

2023-06-30  Martin Jambor  <mjambor@suse.cz>

	* Makefile.in: Regenerate.
2023-06-30 13:27:15 +02:00
Pan Li
1cde8e5d45 RISC-V: Refactor vxrm_mode attr for type attr equal
This patch would like to refactor the vxrm_mode attr for duplicated
eq_attr condition. The common condition of attr is extraced to one
place instead of many places.

Signed-off-by: Pan Li <pan2.li@intel.com>

gcc/ChangeLog:

	* config/riscv/vector.md: Refactor the common condition.
2023-06-30 19:12:22 +08:00
Richard Biener
4f8e31e01b tree-optimization/110496 - TYPE_PRECISION issue with store-merging
When store-merging looks for bswap opportunities we also handle
BIT_FIELD_REFs where we verify the refed object is of scalar
type but we don't check for the result type we eventually use.
That's done later but after we eventually query TYPE_PRECISION.
The following re-orders this.

	PR tree-optimization/110496
	* gimple-ssa-store-merging.cc (find_bswap_or_nop_1): Re-order
	verifying and TYPE_PRECISION query for the BIT_FIELD_REF case.

	* gcc.dg/pr110496.c: New testcase.
2023-06-30 12:59:36 +02:00
rsh-raj
50cb9df720 MAINTAINERS file: Added myself to Write After Approval and DCO
ChangeLog:

2023-06-30  Rishi Raj  <rishiraj45035@gmail.com>

	* MAINTAINERS: Added myself to Write After Approval and DCO
2023-06-30 16:04:48 +05:30
Richard Biener
18e5aeaef2 middle-end/110489 - avoid useless work on statistics
When we call statistics_fini_pass we unconditionally allocate
the statistics hash and traverse it.  When a TU has many small
functions this can take considerable time.  The following avoids
this by never allocating the hash from this function.

	PR middle-end/110489
	* statistics.cc (curr_statistics_hash): Add argument
	indicating whether we should allocate the hash.
	(statistics_fini_pass): If the hash isn't allocated
	only print the summary header.
2023-06-30 10:38:14 +02:00
Segher Boessenkool
f7e3123638 Flip the nvptx port to LRA
... understanding that "turn on LRA" is an exaggeration here, given that nvptx
isn't actually doing register allocation ('TARGET_NO_REGISTER_ALLOCATION').

	gcc/
	* config/nvptx/nvptx.cc (TARGET_LRA_P): Remove.

Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
2023-06-30 09:07:45 +02:00
Richard Biener
c0439218eb tree-optimization/110381 - fix testcase
This adds a missing check_vect () to the execute testcase.

	PR tree-optimization/110381
	* gcc.dg/vect/pr110381.c: Add check_vect ().
2023-06-30 08:35:31 +02:00
Hans-Peter Nilsson
b22cf5f032 libstdc++: Re-apply PR108672 fix (avoid use of naked int32_t in unseq_backend_simd.h)
The fix was overwritten by r14-2109-g3162ca09dbdc2e "libstdc++:
Synchronize PSTL with upstream".

libstdc++-v3:

	PR libstdc++/108672
	* include/pstl/unseq_backend_simd.h (__simd_or): Re-apply using
	__INT32_TYPE__ instead of int32_t.
2023-06-30 05:26:51 +02:00
Jovan Dmitrovic
e20abdb749 mips: Fix overaligned function arguments [PR109435]
This patch changes alignment for typedef types when passed as
arguments, making the alignment equal to the alignment of
original (aliased) types.

This change makes it impossible for a typedef type to have
alignment that is less than its size.

2023-06-27  Jovan Dmitrović  <jovan.dmitrovic@syrmia.com>

gcc/ChangeLog:

	PR target/109435
	* config/mips/mips.cc (mips_function_arg_alignment): Returns
	the alignment of function argument. In case of typedef type,
	it returns the aligment of the aliased type.
	(mips_function_arg_boundary): Relocated calculation of the
	aligment of function arguments.

gcc/testsuite/ChangeLog:

	* gcc.target/mips/align-1-n64.c: New test.
	* gcc.target/mips/align-1-o32.c: New test.
2023-06-30 11:20:43 +08:00
GCC Administrator
14bfda6084 Daily bump. 2023-06-30 00:17:51 +00:00
benjamin priour
1eb90f46c1 analyzer: Fix regression bug after r14-1632-g9589a46ddadc8b [PR110198]
g++.dg/analyzer/PR100244.C was failing after a patch of PR109439.
The reason was a spurious preemptive return of get_store_value upon
out-of-bounds read that was preventing further checks. Now instead,
a boolean value check_poisoned goes to false when a OOB is detected,
and is later on given to get_or_create_initial_value.

gcc/analyzer/ChangeLog:
	PR analyzer/110198
	* region-model-manager.cc
	(region_model_manager::get_or_create_initial_value): Take an
	optional boolean value to bypass poisoning checks
	* region-model-manager.h: Update declaration of the above function.
	* region-model.cc (region_model::get_store_value): No longer returns
	on OOB, but rather gives a boolean to get_or_create_initial_value.
	(region_model::check_region_access): Update docstring.
	(region_model::check_region_for_write): Update docstring.

Signed-off-by: benjamin priour <priour.be@gmail.com>
2023-06-30 01:32:47 +02:00
Jan Hubicka
9dc18fca43 Compute ipa-predicates for conditionals involving __builtin_expect_p
std::vector allocator looks as follows:

__attribute__((nodiscard))
struct pair * std::__new_allocator<std::pair<unsigned int, unsigned int> >::allocate (struct __new_allocator * const this, size_type __n, const void * D.27753)
{
  bool _1;
  long int _2;
  long int _3;
  long unsigned int _5;
  struct pair * _9;

  <bb 2> [local count: 1073741824]:
  _1 = __n_7(D) > 1152921504606846975;
  _2 = (long int) _1;
  _3 = __builtin_expect (_2, 0);
  if (_3 != 0)
    goto <bb 3>; [10.00%]
  else
    goto <bb 6>; [90.00%]

  <bb 3> [local count: 107374184]:
  if (__n_7(D) > 2305843009213693951)
    goto <bb 4>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 4> [local count: 53687092]:
  std::__throw_bad_array_new_length ();

  <bb 5> [local count: 53687092]:
  std::__throw_bad_alloc ();

  <bb 6> [local count: 966367641]:
  _5 = __n_7(D) * 8;
  _9 = operator new (_5);
  return _9;
}

So there is check for allocated block size being greater than max_size which is
wrapper in __builtin_expect.  This makes ipa-fnsummary to give up analyzing
predicates and it will miss the fact that the two different calls to __throw
will be optimized out if __n is larady smaller than 1152921504606846975 which
it is after _M_check_len.

This patch extends ipa-fnsummary to understand functions that return their
parameter.

gcc/ChangeLog:

	PR tree-optimization/109849
	* ipa-fnsummary.cc (decompose_param_expr): Skip
	functions returning its parameter.
	(set_cond_stmt_execution_predicate): Return early
	if predicate was constructed.

gcc/testsuite/ChangeLog:

	PR tree-optimization/109849
	* gcc.dg/ipa/pr109849.c: New test.
2023-06-29 22:46:20 +02:00
Marek Polacek
94c71750cd testsuite: Use -fno-report-bug in gcc.dg/plugin/
Certain downstream compilers (for example, in Fedora) default to
-freport-bug.  The extra output breaks the following tests.  We can use
-fno-report-bug to fix that.  Patch verified with:

$ make check RUNTESTFLAGS='--target_board=unix\{,-freport-bug\} plugin.exp'

gcc/testsuite/ChangeLog:

	* gcc.dg/plugin/crash-test-ice-sarif.c: Use -fno-report-bug.  Adjust
	scan-sarif-file.
	* gcc.dg/plugin/crash-test-ice-stderr.c: Use -fno-report-bug.
	* gcc.dg/plugin/crash-test-write-though-null-sarif.c: Use
	-fno-report-bug.  Adjust scan-sarif-file.
	* gcc.dg/plugin/crash-test-write-though-null-stderr.c: Use
	-fno-report-bug.
2023-06-29 16:28:42 -04:00
Marek Polacek
7599b4fb1c i386: add -fno-stack-protector to two tests
These tests fail when the testsuite is executed with -fstack-protector-strong.
To avoid this, this patch adds -fno-stack-protector to dg-options.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr104610.c: Use -fno-stack-protector.
	* gcc.target/i386/pr69482-1.c: Likewise.
2023-06-29 16:15:06 -04:00
Patrick Palka
9479da4515 c++: NSDMI instantiation during overload resolution [PR110468]
Here we find ourselves instantiating the NSDMI for A<1>::m when
computing argument conversions during overload resolution, and
thus tf_conv is set.  The flag causes mark_used for the constructor
used in the NSDMI to exit early and not instantiate its noexcept-spec,
which eventually leads to an ICE from nothrow_spec_p.

This patch fixes this by clearing any special tsubst flags during
instantiation of an NSDMI, since the result should be independent of
the context that requires the instantiation.

	PR c++/110468

gcc/cp/ChangeLog:

	* init.cc (maybe_instantiate_nsdmi_init): Mask out all
	tsubst flags except for tf_warning_or_error.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/noexcept79.C: New test.
2023-06-29 16:10:18 -04:00
Patrick Palka
fd8a1be04d c++: unpropagated CONSTRUCTOR_MUTABLE_POISON [PR110463]
Here we're incorrectly accepting the mutable member accesses because
cp_fold neglects to propagate CONSTRUCTOR_MUTABLE_POISON when folding a
CONSTRUCTOR.

	PR c++/110463

gcc/cp/ChangeLog:

	* cp-gimplify.cc (cp_fold) <case CONSTRUCTOR>: Propagate
	CONSTRUCTOR_MUTABLE_POISON.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-mutable6.C: New test.
2023-06-29 16:02:04 -04:00
Qing Zhao
070a6bf0bd Update documentation to clarify a GCC extension [PR c/77650]
on a structure with a C99 flexible array member being nested in
another structure.

"The GCC extension accepts a structure containing an ISO C99 "flexible array
member", or a union containing such a structure (possibly recursively)
to be a member of a structure.

 There are two situations:

   * A structure containing a C99 flexible array member, or a union
     containing such a structure, is the last field of another structure,
     for example:

          struct flex  { int length; char data[]; };
          union union_flex { int others; struct flex f; };

          struct out_flex_struct { int m; struct flex flex_data; };
          struct out_flex_union { int n; union union_flex flex_data; };

     In the above, both 'out_flex_struct.flex_data.data[]' and
     'out_flex_union.flex_data.f.data[]' are considered as flexible
     arrays too.

   * A structure containing a C99 flexible array member, or a union
     containing such a structure, is not the last field of another structure,
     for example:

          struct flex  { int length; char data[]; };

          struct mid_flex { int m; struct flex flex_data; int n; };

     In the above, accessing a member of the array 'mid_flex.flex_data.data[]'
     might have undefined behavior.  Compilers do not handle such a case
     consistently, Any code relying on this case should be modified to ensure
     that flexible array members only end up at the ends of structures.

     Please use the warning option '-Wflex-array-member-not-at-end' to
     identify all such cases in the source code and modify them.  This extension
     is now deprecated.
"

	PR c/77650

gcc/c-family/ChangeLog:

	* c.opt: New option -Wflex-array-member-not-at-end.

gcc/c/ChangeLog:

	* c-decl.cc (finish_struct): Issue warnings for new option.

gcc/ChangeLog:

	* doc/extend.texi: Document GCC extension on a structure containing
	a flexible array member to be a member of another structure.

gcc/testsuite/ChangeLog:

	* gcc.dg/variable-sized-type-flex-array.c: New test.
2023-06-29 17:15:53 +00:00
Qing Zhao
3967da9655 Introduce IR bit TYPE_INCLUDES_FLEXARRAY for the GCC extension
on a structure with a C99 flexible array member being nested in
another structure

GCC extension accepts the case when a struct with a flexible array member
is embedded into another struct or union (possibly recursively) as the last
field.
This patch is to introduce the IR bit TYPE_INCLUDES_FLEXARRAY (reuse the
existing IR bit TYPE_NO_NAMED_ARGS_SATDARG_P), set it correctly in C FE,
stream it correctly in Middle-end, and print it during IR dumping.

gcc/c/ChangeLog:

	* c-decl.cc (finish_struct): Set TYPE_INCLUDES_FLEXARRAY for
	struct/union type.

gcc/lto/ChangeLog:

	* lto-common.cc (compare_tree_sccs_1): Compare bit
	TYPE_NO_NAMED_ARGS_STDARG_P or TYPE_INCLUDES_FLEXARRAY properly
	for its corresponding type.

gcc/ChangeLog:

	* print-tree.cc (print_node): Print new bit type_include_flexarray.
	* tree-core.h (struct tree_type_common): Use bit no_named_args_stdarg_p
	as type_include_flexarray for RECORD_TYPE or UNION_TYPE.
	* tree-streamer-in.cc (unpack_ts_type_common_value_fields): Stream
	in bit no_named_args_stdarg_p properly for its corresponding type.
	* tree-streamer-out.cc (pack_ts_type_common_value_fields): Stream
	out bit no_named_args_stdarg_p properly for its corresponding type.
	* tree.h (TYPE_INCLUDES_FLEXARRAY): New macro TYPE_INCLUDES_FLEXARRAY.
2023-06-29 17:13:09 +00:00
Aldy Hernandez
6a1cf0d0d9 Move maybe_set_nonzero_bits() to its only user.
gcc/ChangeLog:

	* tree-vrp.cc (maybe_set_nonzero_bits): Move from here...
	* tree-ssa-dom.cc (maybe_set_nonzero_bits): ...to here.
	* tree-vrp.h (maybe_set_nonzero_bits): Remove.
2023-06-29 18:49:27 +02:00
Aldy Hernandez
27a0f01417 Tidy up the range normalization code.
There's a few spots where a range is being altered in-place, but we
fail to call normalize the range.  This patch makes sure we always
call normalize_kind(), and that normalize_kind in turn calls
verify_range to make sure verything is canonical.

gcc/ChangeLog:

	* value-range.cc (frange::set): Do not call verify_range.
	(frange::normalize_kind): Verify range.
	(frange::union_nans): Do not call verify_range.
	(frange::union_): Same.
	(frange::intersect): Same.
	(irange::irange_single_pair_union): Call normalize_kind if
	necessary.
	(irange::union_): Same.
	(irange::intersect): Same.
	(irange::set_range_from_nonzero_bits): Verify range.
	(irange::set_nonzero_bits): Call normalize_kind if necessary.
	(irange::get_nonzero_bits): Tweak comment.
	(irange::intersect_nonzero_bits): Call normalize_kind if
	necessary.
	(irange::union_nonzero_bits): Same.
	* value-range.h (irange::normalize_kind): Verify range.
2023-06-29 18:49:27 +02:00
Uros Bizjak
c41332abe7 cselib+expr+bitmap: Change return type of predicate functions from int to bool
gcc/ChangeLog:

	* cselib.h (rtx_equal_for_cselib_1):
	Change return type from int to bool.
	(references_value_p): Ditto.
	(rtx_equal_for_cselib_p): Ditto.
	* expr.h (can_store_by_pieces): Ditto.
	(try_casesi): Ditto.
	(try_tablejump): Ditto.
	(safe_from_p): Ditto.
	* sbitmap.h (bitmap_equal_p): Ditto.
	* cselib.cc (references_value_p): Change return type
	from int to void and adjust function body accordingly.
	(rtx_equal_for_cselib_1): Ditto.
	* expr.cc (is_aligning_offset): Ditto.
	(can_store_by_pieces): Ditto.
	(mostly_zeros_p): Ditto.
	(all_zeros_p): Ditto.
	(safe_from_p): Ditto.
	(is_aligning_offset): Ditto.
	(try_casesi): Ditto.
	(try_tablejump): Ditto.
	(store_constructor): Change "need_to_clear" and
	"const_bounds_p" variables to bool.
	* sbitmap.cc (bitmap_equal_p): 	Change return type from int to bool.
2023-06-29 17:29:47 +02:00
Jonathan Wakely
5dfdf0ae4d libstdc++: Fix src/c++20/tzdb.cc for non-constexpr std::mutex
Building libstdc++ reportedly fails for targets without lock-free
std::atomic<T*> which don't define __GTHREAD_MUTEX_INIT:

src/c++20/tzdb.cc:110:21: error: 'constinit' variable 'std::chrono::{anonymous}::list_mutex' does not have a constant initializer
src/c++20/tzdb.cc:110:21: error: call to non-'constexpr' function 'std::mutex::mutex()'

The solution implemented by this commit is to use a local static mutex
when it can't be constinit, so that it's constructed on first use.

With this change, we can also simplify the preprocessor logic for
defining USE_ATOMIC_SHARED_PTR. It now depends on the same conditions as
USE_ATOMIC_LIST_HEAD, so in theory we could have a single macro. Keeping
them separate would allow us to replace the use of atomic<shared_ptr<T>>
with a mutex if that performs better, without having to give up on the
lock-free cache for fast access to the list head.

libstdc++-v3/ChangeLog:

	* src/c++20/tzdb.cc (USE_ATOMIC_SHARED_PTR): Define consistently
	with USE_ATOMIC_LIST_HEAD.
	(list_mutex): Replace global object with function. Use local
	static object when std::mutex constructor isn't constexpr.
2023-06-29 16:17:23 +01:00
Jonathan Wakely
ff29ee6af8 libstdc++: Do not use off64_t in calls to copy_file_range [PR110462]
Although the copy_file_range(2) man page shows the arguments as off64_t*
that is not portable. For musl there is no off64_t type, as off_t is
always 64-bit. Use the loff_t type which is always 64-bit even if off_t
isn't. We could just use off_t because the filesystem library is
compiled with _FILE_OFFSET_BITS=64, but loff_t is the more correct type
for this interface.

libstdc++-v3/ChangeLog:

	PR libstdc++/110462
	* acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check that
	copy_file_range can be called with loff_t* arguments.
	* configure: Regenerate.
	* src/filesystem/ops-common.h (copy_file_copy_file_range):
	Use loff_t for offsets.
2023-06-29 16:17:23 +01:00
Patrick Palka
e972bdce61 c++: cache partial template specialization selection
There's currently no cheap way to obtain the partial template
specialization (and arguments relative to it) that was selected for a
class or variable template specialization.  Our only option is to
compute the result from scratch via most_specialized_partial_spec.

For class templates this isn't really an issue because we usually need
this information just once, upon instantiation.  But for variable
templates we need it upon specialization and also later upon instantiation.
We could implement an ad-hoc cache for variable templates only, but it'd
be nice for this information to be readily available in general.

To that end, this patch adds a TI_PARTIAL_INFO field to TEMPLATE_INFO
that holds another TEMPLATE_INFO consisting of the partial template and
arguments relative to it, which most_specialized_partial_spec then
uses to transparently cache its (now TEMPLATE_INFO) result.

Similarly, there's no easy way to go from the DECL_TEMPLATE_RESULT of a
partial TEMPLATE_DECL back to that TEMPLATE_DECL.  (Our best option is to
walk the DECL_TEMPLATE_SPECIALIZATIONS list of the primary TEMPLATE_DECL.)
So this patch also uses this new field to link these entities in both
directions.

gcc/cp/ChangeLog:

	* cp-tree.h (tree_template_info::partial): New data member.
	(TI_PARTIAL_INFO): New tree accessor.
	(most_specialized_partial_spec): Add defaulted bool parameter.
	* module.cc (trees_out::core_vals) <case TEMPLATE_INFO>: Stream
	TI_PARTIAL_INFO.
	(trees_in::core_vals) <case TEMPLATE_INFO>: Likewise.
	* parser.cc (specialization_of): Adjust after making
	most_specialized_partial_spec return TEMPLATE_INFO instead
	of TREE_LIST.
	* pt.cc (process_partial_specialization): Set TI_PARTIAL_INFO
	of 'decl' to point back to the partial TEMPLATE_DECL.  Likewise
	(and pass rechecking=true to most_specialization_partial_spec).
	(instantiate_class_template): Likewise.
	(instantiate_template): Set TI_PARTIAL_INFO to the result of
	most_specialization_partial_spec after forming a variable
	template specialization.
	(most_specialized_partial_spec): Add 'rechecking' parameter.
	Exit early if the template is not primary.  Use the TI_PARTIAL_INFO
	of the corresponding TEMPLATE_INFO as a cache unless 'rechecking'
	is true.  Don't bother setting TREE_TYPE of each TREE_LIST.
	(instantiate_decl): Adjust after making
	most_specialized_partial_spec return TEMPLATE_INFO instead of
	TREE_LIST.
	* ptree.cc (cxx_print_xnode) <case TEMPLATE_INFO>: Dump
	TI_PARTIAL_INFO.
2023-06-29 09:36:58 -04:00
Tom Tromey
c7ed2ccd59 Relax type-printer regexp in libstdc++ test suite
The libstdc++ test suite checks whether gdb type printers are
available like so:

    set do_whatis_tests [gdb_batch_check "python print(gdb.type_printers)" \
			   "\\\[\\\]"]

This regexp assumes that the list of printers is empty.  However,
sometimes it's convenient to ship a gdb that comes with some default
printers, causing this to erroneously report that gdb is "too old".

I believe the intent of this check is to ensure that gdb.type_printers
exists -- not to check its starting value.  This patch changes the
check to accept any Python list as output.

Note that the patch doesn't look for the trailing "]".  I tried this
but in my case the output was too long for expect.  It seemed fine to
just check the start, as the point really is to reject the case where
the command prints an error message.

libstdc++-v3/ChangeLog

	* testsuite/lib/gdb-test.exp (gdb-test): Relax type-printer
	regexp.
2023-06-29 07:10:04 -06:00
Robin Dapp
16e4f09a59 tree-ssa-math-opts: Use element_precision.
The recent TYPE_PRECISION changes to detect improper usage
cause an ICE in divmod_candidate_p for RVV when called with
a vector type.  Therefore, use element_precision instead.

gcc/ChangeLog:

	* tree-ssa-math-opts.cc (divmod_candidate_p): Use
	element_precision.
2023-06-29 13:02:19 +02:00
Roger Sayle
2b31dc28c7 [Committed] Add -mmove-max=128 -mstore-max=128 to pieces-memcmp-2.c
Adding -mmove-max=128 and -mstore-max=128 to the dg-options of the
recently added gcc.target/i386/pieces-memcmp-2.c avoids changing the
intent of this testcase when adding -march=cascadelake to RUNTESTFLAGS.
Committed as obvious.

2023-06-29  Roger Sayle  <roger@nextmovesoftware.com>

gcc/testsuite/ChangeLog
	* gcc.target/i386/pieces-memcmp-2.c: Specify that 128-bit
	comparisons are desired, to see if 256-bit instructions are
	generated inappropriately (fixes test on -march=cascadelake).
2023-06-29 11:44:04 +01:00
Richard Biener
cd23ed2119 tree-optimization/110460 - fend off vector types from vectorizer
The following makes fending off existing vector types from vectorization
also apply to word_mode vector types.  I've chosen to add a positive
list of allowed scalar types here for clarity.

	PR tree-optimization/110460
	* tree-vect-stmts.cc (get_related_vectype_for_scalar_type):
	Only allow integral, pointer and scalar float type scalar_type.
2023-06-29 11:54:05 +02:00
Lili Cui
4633e38cd2 Avoid adding loop-carried ops to long chains
Avoid adding loop-carried ops to long chains, otherwise the whole chain will
have dependencies across the loop iteration. Just keep loop-carried ops in a
separate chain.
   E.g.
   x_1 = phi(x_0, x_2)
   y_1 = phi(y_0, y_2)

   a + b + c + d + e + x1 + y1

   SSA1 = a + b;
   SSA2 = c + d;
   SSA3 = SSA1 + e;
   SSA4 = SSA3 + SSA2;
   SSA5 = x1 + y1;
   SSA6 = SSA4 + SSA5;

With the patch applied, these test cases improved by 32%~100%.

S242:
for (int i = 1; i < LEN_1D; ++i) {
    a[i] = a[i - 1] + s1 + s2 + b[i] + c[i] + d[i];}

Case 1:
for (int i = 1; i < LEN_1D; ++i) {
    a[i] = a[i - 1] + s1 + s2 + b[i] + c[i] + d[i] + e[i];}

Case 2:
for (int i = 1; i < LEN_1D; ++i) {
    a[i] = a[i - 1] + b[i - 1] + s1 + s2 + b[i] + c[i] + d[i] + e[i];}

The value is the execution time
A: original version
B: with FMA patch g:e5405f065bace0685cb3b8878d1dfc7a6e7ef409(base on A)
C: with current patch(base on B)

	  A 	  B 	  C 	B/A	        C/A
s242	2.859	5.152	2.859	1.802028681	1
case 1	5.489	5.488	3.511	0.999818	0.64
case 2	7.216	7.499	4.885	1.039218	0.68

gcc/ChangeLog:

	PR tree-optimization/110148
	* tree-ssa-reassoc.cc (rewrite_expr_tree_parallel): Handle loop-carried
	ops in this function.
2023-06-29 09:30:19 +00:00
Alexandre Oliva
dc93a0f633 [testsuite] tolerate enabled but missing language frontends
When a language is enabled but we run the testsuite against a tree in
which the frontend compiler is not present, help.exp fails.  It
recognizes the output pattern for a disabled language, but not a
missing frontend.  Extend the pattern so that it covers both cases.


for  gcc/testsuite/ChangeLog

	* lib/options.exp (check_for_options_with_filter): Handle
	missing frontend compiler like disabled language.
2023-06-29 06:03:24 -03:00
Richard Biener
6d2eddf456 middle-end/110452 - bad code generation with AVX512 mask splat
The following adds an alternate way of expanding a uniform
mask vector constructor like

  _55 = _2 ? -1 : 0;
  vect_cst__56 = {_55, _55, _55, _55, _55, _55, _55, _55};

when the mask mode is a scalar int mode like for AVX512 or GCN.
Instead of piecewise building the result via shifts and ors
we can take advantage of uniformity and signedness of the
component and simply sign-extend to the result.

Instead of

        cmpl    $3, %edi
        sete    %cl
        movl    %ecx, %esi
        leal    (%rsi,%rsi), %eax
        leal    0(,%rsi,4), %r9d
        leal    0(,%rsi,8), %r8d
        orl     %esi, %eax
        orl     %r9d, %eax
        movl    %ecx, %r9d
        orl     %r8d, %eax
        movl    %ecx, %r8d
        sall    $4, %r9d
        sall    $5, %r8d
        sall    $6, %esi
        orl     %r9d, %eax
        orl     %r8d, %eax
        movl    %ecx, %r8d
        orl     %esi, %eax
        sall    $7, %r8d
        orl     %r8d, %eax
        kmovb   %eax, %k1

we then get

        cmpl    $3, %edi
        sete    %cl
	negl    %ecx
	kmovb   %ecx, %k1

Code generation for non-uniform masks remains bad, but at least
I see no easy way out for the most general case here.

	PR middle-end/110452
	* expr.cc (store_constructor): Handle uniform boolean
	vectors with integer mode specially.
2023-06-29 10:31:17 +02:00
Richard Biener
1e6f1659bd middle-end/110461 - pattern applying wrongly to vectors
The following guards a match.pd pattern that wasn't supposed to
apply to vectors and thus runs into TYPE_PRECISION checking.  For
vector support the constant case is lacking and the pattern would
have missing optab support checking for the result operation.

	PR middle-end/110461
	* match.pd (bitop (convert@2 @0) (convert?@3 @1)): Disable
	for VECTOR_TYPE_P.

	* gcc.dg/pr110461.c: New testcase.
2023-06-29 10:10:51 +02:00
Richard Biener
d81c7a2536 c/110454 - ICE with bogus TYPE_PRECISION use
The following sinks TYPE_PRECISION to properly guarded use places.

	PR c/110454
gcc/c/
	* c-typeck.cc (convert_argument): Sink formal_prec compute
	to where TYPE_PRECISION is valid to use.

gcc/testsuite/
	* gcc.dg/Wtraditional-conversion-3.c: New testcase.
2023-06-29 10:10:44 +02:00
Richard Sandiford
4e9f6c1428 A couple of va_gc_atomic tweaks
The only current user of va_gc_atomic is Ada's:

    vec<Entity_Id, va_gc_atomic>

It uses the generic gt_pch_nx routines (with gt_pch_nx being the
“note pointers” hooks), such as:

    template<typename T, typename A>
    void
    gt_pch_nx (vec<T, A, vl_embed> *v)
    {
      extern void gt_pch_nx (T &);
      for (unsigned i = 0; i < v->length (); i++)
	gt_pch_nx ((*v)[i]);
    }

It then defines gt_pch_nx routines for Entity_Id &.

The problem is that if we wanted to take the same approach for
an array of unsigned ints, we'd need to define:

    inline void gt_pch_nx (unsigned int &) { }

which would then be ambiguous with:

    inline void gt_pch_nx (unsigned int) { }

The point of va_gc_atomic is that the elements don't need to be GCed,
and so we have:

    template<typename T>
    void
    gt_ggc_mx (vec<T, va_gc_atomic, vl_embed> *v ATTRIBUTE_UNUSED)
    {
      /* Nothing to do.  Vectors of atomic types wrt GC do not need to
	 be traversed.  */
    }

I think it's therefore reasonable to assume that no pointers will
need to be processed for PCH either.

The patch also relaxes the array_slice constructor for vec<T, va_gc> *
so that it handles all embedded vectors.

gcc/
	* vec.h (gt_pch_nx): Add overloads for va_gc_atomic.
	(array_slice): Relax va_gc constructor to handle all vectors
	with a vl_embed layout.

gcc/ada/
	* gcc-interface/decl.cc (gt_pch_nx): Remove overloads for Entity_Id.
2023-06-29 08:48:17 +01:00
Pan Li
e714af12e3 RISC-V: Support vfadd static rounding mode by mode switching
This patch would like to support the vfadd static round mode similar to
the fixed-point. Then the related fsrm instructions will be inserted
correlatively.

Please *NOTE* this PATCH doesn't cover anything about FRM dynamic mode,
it will be implemented in the underlying PATCH(s).

Signed-off-by: Pan Li <pan2.li@intel.com>

gcc/ChangeLog:

	* config/riscv/riscv.cc (riscv_emit_mode_set): Add emit for FRM.
	(riscv_mode_needed): Likewise.
	(riscv_entity_mode_after): Likewise.
	(riscv_mode_after): Likewise.
	(riscv_mode_entry): Likewise.
	(riscv_mode_exit): Likewise.
	* config/riscv/riscv.h (NUM_MODES_FOR_MODE_SWITCHING): Add number
	for FRM.
	* config/riscv/riscv.md: Add FRM register.
	* config/riscv/vector-iterators.md: Add FRM type.
	* config/riscv/vector.md (frm_mode): Define new attr for FRM mode.
	(fsrm): Define new insn for fsrm instruction.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/base/float-point-frm-insert-1.c: New test.
	* gcc.target/riscv/rvv/base/float-point-frm-insert-2.c: New test.
	* gcc.target/riscv/rvv/base/float-point-frm-insert-3.c: New test.
	* gcc.target/riscv/rvv/base/float-point-frm-insert-4.c: New test.
	* gcc.target/riscv/rvv/base/float-point-frm-insert-5.c: New test.
2023-06-29 12:13:26 +08:00
Pan Li
4d1e97f583 RISC-V: Allow rounding mode control for RVV floating-point add
According to the doc as below, we need to support the rounding mode of
the RVV floating-point, both the static and dynamice frm.

https://github.com/riscv-non-isa/rvv-intrinsic-doc/pull/226

For tracking and development friendly, We will take some steps to support
all rounding modes for the RVV floating-point rounding modes.

1. Allow rounding mode control by one intrinsic (aka this patch), vfadd.
2. Support static rounding mode control by mode switch, like fixed-point.
3. Support dynamice round mode control by mode switch.
4. Support the rest floating-point instructions for frm.

Please *NOTE* this patch only allow the rounding mode control for the
vfadd intrinsic API, and the related frm will be coverred by step 2.

Signed-off-by: Pan Li <pan2.li@intel.com>
Co-Authored by: Juzhe-Zhong <juzhe.zhong@rivai.ai>

gcc/ChangeLog:

	* config/riscv/riscv-protos.h (enum floating_point_rounding_mode):
	Add macro for static frm min and max.
	* config/riscv/riscv-vector-builtins-bases.cc
	(class binop_frm): New class for floating-point with frm.
	(BASE): Add vfadd for frm.
	* config/riscv/riscv-vector-builtins-bases.h: Likewise.
	* config/riscv/riscv-vector-builtins-functions.def
	(vfadd_frm): Likewise.
	* config/riscv/riscv-vector-builtins-shapes.cc
	(struct alu_frm_def): New struct for alu with frm.
	(SHAPE): Add alu with frm.
	* config/riscv/riscv-vector-builtins-shapes.h: Likewise.
	* config/riscv/riscv-vector-builtins.cc
	(function_checker::report_out_of_range_and_not): New function
	for report out of range and not val.
	(function_checker::require_immediate_range_or): New function
	for checking in range or one val.
	* config/riscv/riscv-vector-builtins.h: Add function decl.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/base/float-point-frm-error.c: New test.
	* gcc.target/riscv/rvv/base/float-point-frm.c: New test.
2023-06-29 12:13:04 +08:00