platform/upstream/gcc.git
22 months agoOpenMP 5.0: Clause ordering for OpenMP 5.0 (topological sorting by base pointer)
Julian Brown [Fri, 30 Jul 2021 16:15:18 +0000 (09:15 -0700)]
OpenMP 5.0: Clause ordering for OpenMP 5.0 (topological sorting by base pointer)

This patch reimplements the omp_target_reorder_clauses function in
anticipation of supporting "deeper" struct mappings (that is, with
several structure dereference operators, or similar).

The idea is that in place of the (possibly quadratic) algorithm in
omp_target_reorder_clauses that greedily moves clauses containing
addresses that are subexpressions of other addresses before those other
addresses, we employ a topological sort algorithm to calculate a proper
order for map clauses. This should run in linear time, and hopefully
handles degenerate cases where multiple "levels" of indirect accesses
are present on a given directive.

The new method also takes care to keep clause groups together, addressing
the concerns raised in:

  https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570501.html

To figure out if some given clause depends on a base pointer in another
clause, we strip off the outer layers of the address expression, and check
(via a tree_operand_hash hash table we have built) if the result is a
"base pointer" as defined in OpenMP 5.0 (1.2.6 Data Terminology). There
are some subtleties involved, however:

 - We must treat MEM_REF with zero offset the same as INDIRECT_REF.
   This should probably be fixed in the front ends instead so we always
   use a canonical form (probably INDIRECT_REF). The following patch
   shows one instance of the problem, but there may be others:

   https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571382.html

 - Mapping a whole struct implies mapping each of that struct's
   elements, which may be base pointers. Because those base pointers
   aren't necessarily explicitly referenced in the directive in question,
   we treat the whole-struct mapping as a dependency instead.

2022-09-13  Julian Brown  <julian@codesourcery.com>

gcc/
* gimplify.cc (is_or_contains_p, omp_target_reorder_clauses): Delete
functions.
(omp_tsort_mark): Add enum.
(omp_mapping_group): Add struct.
(debug_mapping_group, omp_get_base_pointer, omp_get_attachment,
omp_group_last, omp_gather_mapping_groups, omp_group_base,
omp_index_mapping_groups, omp_containing_struct,
omp_tsort_mapping_groups_1, omp_tsort_mapping_groups,
omp_segregate_mapping_groups, omp_reorder_mapping_groups): New
functions.
(gimplify_scan_omp_clauses): Call above functions instead of
omp_target_reorder_clauses, unless we've seen an error.
* omp-low.cc (scan_sharing_clauses): Avoid strict test if we haven't
sorted mapping groups.

gcc/testsuite/
* g++.dg/gomp/target-lambda-1.C: Adjust expected output.
* g++.dg/gomp/target-this-3.C: Likewise.
* g++.dg/gomp/target-this-4.C: Likewise.

22 months agotestsuite/s390: Add -mzarch to ifcvt test cases.
Robin Dapp [Tue, 6 Sep 2022 06:56:04 +0000 (08:56 +0200)]
testsuite/s390: Add -mzarch to ifcvt test cases.

Add missing -mzarch to ifcvt test cases.

gcc/testsuite/ChangeLog:

* gcc.target/s390/ifcvt-one-insn-bool.c: Add -mzarch.
* gcc.target/s390/ifcvt-one-insn-char.c: Dito.
* gcc.target/s390/ifcvt-two-insns-bool.c: Dito.
* gcc.target/s390/ifcvt-two-insns-int.c: Dito.
* gcc.target/s390/ifcvt-two-insns-long.c: Add -mzarch and change
long into long long.

22 months agotestsuite/s390: Fix vperm-rev testcases.
Robin Dapp [Wed, 31 Aug 2022 07:21:45 +0000 (09:21 +0200)]
testsuite/s390: Fix vperm-rev testcases.

Add -save-temps and tabs for matching.

gcc/testsuite/ChangeLog:

* gcc.target/s390/vector/vperm-rev-z14.c: Add -save-temps.
* gcc.target/s390/vector/vperm-rev-z15.c: Likewise.

22 months agoDisallow pointer operands for |, ^ and partly & [PR106878]
Jakub Jelinek [Wed, 14 Sep 2022 10:36:36 +0000 (12:36 +0200)]
Disallow pointer operands for |, ^ and partly & [PR106878]

My change to match.pd (that added the two simplifications this patch
touches) results in more |/^/& assignments with pointer arguments,
but since r12-1608 we reject pointer operands for BIT_NOT_EXPR.

Disallowing them for BIT_NOT_EXPR and allowing for BIT_{IOR,XOR,AND}_EXPR
leads to a match.pd maintainance nightmare (see one of the patches in the
PR), so either we want to allow pointer operand on BIT_NOT_EXPR (but then
we run into issues e.g. with the ranger which expects it can emulate
BIT_NOT_EXPR ~X as - 1 - X which doesn't work for pointers which don't
support MINUS_EXPR), or the following patch disallows pointer arguments
for all of BIT_{IOR,XOR,AND}_EXPR with the exception of BIT_AND_EXPR
with INTEGER_CST last operand (for simpler pointer realignment).
I had to tweak one reassoc optimization and the two match.pd
simplifications.

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

PR tree-optimization/106878
* tree-cfg.cc (verify_gimple_assign_binary): Disallow pointer,
reference or OFFSET_TYPE BIT_IOR_EXPR, BIT_XOR_EXPR or, unless
the second argument is INTEGER_CST, BIT_AND_EXPR.
* match.pd ((type) X op CST -> (type) (X op ((type-x) CST)),
(type) (((type2) X) op Y) -> (X op (type) Y)): Punt for
POINTER_TYPE_P or OFFSET_TYPE.
* tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): For
pointers cast them to pointer sized integers first.

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

22 months agotree-optimization/106934 - avoid BIT_FIELD_REF of bitfields
Richard Biener [Wed, 14 Sep 2022 07:00:35 +0000 (09:00 +0200)]
tree-optimization/106934 - avoid BIT_FIELD_REF of bitfields

The following avoids creating BIT_FIELD_REF of bitfields in
update-address-taken.  The patch doesn't implement punning to
a full precision integer type but leaves a comment according to
that.

PR tree-optimization/106934
* tree-ssa.cc (non_rewritable_mem_ref_base): Avoid BIT_FIELD_REFs
of bitfields.
(maybe_rewrite_mem_ref_base): Likewise.

* gfortran.dg/pr106934.f90: New testcase.

22 months agoCheck another epilog variable peeling case in vectorizable_nonlinear_induction.
liuhongt [Tue, 13 Sep 2022 05:25:24 +0000 (13:25 +0800)]
Check another epilog variable peeling case in vectorizable_nonlinear_induction.

in vectorizable_nonlinear_induction, r13-2503-gc13223b790bbc5 prevent variable peeling by
only checking LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo). But when
"!vect_use_loop_mask_for_alignment_p (loop_vinfo) &&
LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0", vectorizer will
still do variable peeling for epilog, and it hits gcc_assert in
vect_peel_nonlinear_iv_init.

gcc/ChangeLog:

PR tree-optimization/106905
* tree-vect-loop.cc (vectorizable_nonlinear_induction): Return
false when !vect_use_loop_mask_for_alignment_p (loop_vinfo) &&
LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr106905.c: New test.
* gcc.target/ia64/pr106905.c: New test.

22 months agotestsuite: gluefile file need to be prefixed
Torbjörn SVENSSON [Wed, 14 Sep 2022 05:22:27 +0000 (07:22 +0200)]
testsuite: gluefile file need to be prefixed

When the status wrapper is used, the gluefile need to be prefixed with
-Wl, in order for the test cases to have the dump files with the
expected names.

2022-09-14  Torbjörn SVENSSON  <torbjorn.svensson@foss.st.com>

gcc/testsuite/
PR target/95720
* lib/g++.exp: Moved gluefile block to after flags have been
  prefixed for the target_compile call.
* lib/gcc.exp: Likewise.
* lib/wrapper.exp: Reset adjusted state flag.

Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
22 months agoDaily bump.
GCC Administrator [Wed, 14 Sep 2022 00:18:07 +0000 (00:18 +0000)]
Daily bump.

22 months agoPR target/106877: Robustify reg-stack to malformed asm.
Roger Sayle [Tue, 13 Sep 2022 18:49:20 +0000 (19:49 +0100)]
PR target/106877: Robustify reg-stack to malformed asm.

This patch resolves PR target/106877 an ICE-on-invalid inline-asm
regression.  An innocent upstream change means that the test case
from PR inline-asm/84683 now hits a different assert in reg-stack.cc's
move_for_stack_reg.  Fixed by duplicating Jakub's solution to PR 84683
https://gcc.gnu.org/pipermail/gcc-patches/2018-March/495193.html at
this second (similar) gcc_assert.

2022-09-13  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR target/106877
* reg-stack.cc (move_for_stack_reg): Check for any_malformed_asm
in gcc_assert.

gcc/testsuite/ChangeLog
PR target/106877
* g++.dg/ext/pr106877.C: New test case.

22 months agolibgomp: Appease some static analyzers [PR106906]
Jakub Jelinek [Tue, 13 Sep 2022 17:00:02 +0000 (19:00 +0200)]
libgomp: Appease some static analyzers [PR106906]

While icv_addr[1] = false; assignments where icv_addr has void *
element type is correct and matches how it is used (in those cases
the void * pointer is then cast to bool and used that way), there is no
reason not to add explicit (void *) casts there which are there already
for (void *) true.  And, there is in fact even no point in actually
doing those stores at all because we set that pointer to NULL a few
lines earlier.  So, this patch adds the explicit casts and then
comments those out to show intent.

2022-09-13  Jakub Jelinek  <jakub@redhat.com>

PR libgomp/106906
* env.c (get_icv_member_addr): Cast false to void * before assigning
it to icv_addr[1], and comment the whole assignment out.

22 months agolibstdc++: Implement ranges::slide_view from P2442R1
Patrick Palka [Tue, 13 Sep 2022 15:18:16 +0000 (11:18 -0400)]
libstdc++: Implement ranges::slide_view from P2442R1

This also implements the LWG 3711 and 3712 changes to slide_view.

libstdc++-v3/ChangeLog:

* include/std/ranges (__detail::__slide_caches_nothing): Define.
(__detail::__slide_caches_last): Define.
(__detail::__slide_caches_first): Define.
(slide_view): Define.
(enable_borrowed_range<slide_view>): Define.
(slide_view::_Iterator): Define.
(slide_view::_Sentinel): Define.
(views::__detail::__can_slide_view): Define.
(views::_Slide, views::slide): Define.
* testsuite/std/ranges/adaptors/slide/1.cc: New test.

22 months agolibstdc++: Implement ranges::chunk_view from P2442R1
Patrick Palka [Tue, 13 Sep 2022 15:18:14 +0000 (11:18 -0400)]
libstdc++: Implement ranges::chunk_view from P2442R1

This also implements the LWG 3707, 3710 and 3712 changes to chunk_view.

libstdc++-v3/ChangeLog:

* include/std/ranges (__detail::__div_ceil): Define.
(chunk_view): Define.
(chunk_view::_OuterIter): Define.
(chunk_view::_OuterIter::value_type): Define.
(chunk_view::_InnerIter): Define.
(chunk_view<_Vp>): Define partial specialization for forward
ranges.
(enable_borrowed_range<chunk_view>): Define.
(chunk_view<_Vp>::_Iterator): Define.
(views::__detail::__can_chunk_view): Define.
(views::_Chunk, views::chunk): Define.
* testsuite/std/ranges/adaptors/chunk/1.cc: New test.

22 months agolibstdc++: Implement LWG 3569 changes to join_view::_Iterator
Patrick Palka [Tue, 13 Sep 2022 15:18:07 +0000 (11:18 -0400)]
libstdc++: Implement LWG 3569 changes to join_view::_Iterator

libstdc++-v3/ChangeLog:

* include/std/ranges (join_view::_Iterator::_M_satisfy):
Adjust resetting _M_inner as per LWG 3569.
(join_view::_Iterator::_M_inner): Wrap in std::optional
as per LWG 3569.
(join_view::_Iterator::_Iterator): Relax constraints as
per LWG 3569.
(join_view::_Iterator::operator*): Adjust as per LWG 3569.
(join_view::_Iterator::operator->): Likewise.
(join_view::_Iterator::operator++): Likewise.
(join_view::_Iterator::operator--): Likewise.
(join_view::_Iterator::iter_move): Likewise.
(join_view::_Iterator::iter_swap): Likewise.
* testsuite/std/ranges/adaptors/join.cc (test14): New test.

22 months agolibstdc++: Avoid -Wparentheses warning with debug iterators
Patrick Palka [Tue, 13 Sep 2022 14:41:47 +0000 (10:41 -0400)]
libstdc++: Avoid -Wparentheses warning with debug iterators

I noticed compiling e.g. std/ranges/adaptors/join.cc with
-D_GLIBCXX_DEBUG -Wsystem-headers -Wall gives the warning:

  gcc/libstdc++-v3/include/debug/safe_iterator.h:477:9: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]

libstdc++-v3/ChangeLog:

* include/debug/safe_iterator.h (_GLIBCXX_DEBUG_VERIFY_OPERANDS):
Add parentheses to avoid -Wparentheses warning.

22 months agoc++: remove single-parameter version of mark_used
Patrick Palka [Tue, 13 Sep 2022 14:18:58 +0000 (10:18 -0400)]
c++: remove single-parameter version of mark_used

gcc/cp/ChangeLog:

* cp-tree.h (mark_used): Remove single-parameter overload.  Add
default argument to the two-parameter overload.
* decl2.cc (mark_used): Likewise.

22 months agoc++: two-parameter version of cxx_constant_value
Patrick Palka [Tue, 13 Sep 2022 14:01:29 +0000 (10:01 -0400)]
c++: two-parameter version of cxx_constant_value

Since some callers need the complain parameter but not the object
parameter, let's introduce and use an overload of cxx_constant_value
that omits the latter.

gcc/cp/ChangeLog:

* cp-tree.h (cxx_constant_value): Define two-parameter version
that omits the object parameter.
* decl.cc (build_explicit_specifier): Omit NULL_TREE object
argument to cxx_constant_value.
* except.cc (build_noexcept_spec): Likewise.
* pt.cc (expand_integer_pack): Likewise.
(fold_targs_r): Likewise.
* semantics.cc (finish_if_stmt_cond): Likewise.

22 months agoc++: some missing-SFINAE fixes
Patrick Palka [Tue, 13 Sep 2022 13:48:04 +0000 (09:48 -0400)]
c++: some missing-SFINAE fixes

It looks like we aren't respecting SFINAE for:

  * an invalid/non-constant conditional explicit-specifier
  * a non-constant conditional noexcept-specifier
  * a non-constant argument to __integer_pack

This patch fixes these in the usual way, by passing complain and
propagating error_mark_node appropriately.

gcc/cp/ChangeLog:

* decl.cc (build_explicit_specifier): Pass complain to
cxx_constant_value.
* except.cc (build_noexcept_spec): Likewise.
* pt.cc (expand_integer_pack): Likewise.
(tsubst_function_decl): Propagate error_mark_node returned
from build_explicit_specifier.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/noexcept-type26.C: New test.
* g++.dg/cpp2a/explicit19.C: New test.
* g++.dg/ext/integer-pack6.C: New test.

22 months agoRevert "xtensa: Implement new target hook: TARGET_CONSTANT_OK_FOR_CPROP_P"
Max Filippov [Tue, 13 Sep 2022 11:28:16 +0000 (04:28 -0700)]
Revert "xtensa: Implement new target hook: TARGET_CONSTANT_OK_FOR_CPROP_P"

This reverts commit 936efcac733fe49e5ea9e636403e5941f24ff1b3.

22 months agors6000: Fix the check of bif argument number [PR104482]
Kewen Lin [Tue, 13 Sep 2022 09:14:23 +0000 (04:14 -0500)]
rs6000: Fix the check of bif argument number [PR104482]

As PR104482 shown, it's one regression about the handlings when
the argument number is more than the one of built-in function
prototype.  The new bif support only catches the case that the
argument number is less than the one of function prototype, but
it misses the case that the argument number is more than the one
of function prototype.  Because it uses "n != expected_args",
n is updated in

   for (n = 0; !VOID_TYPE_P (TREE_VALUE (fnargs)) && n < nargs;
        fnargs = TREE_CHAIN (fnargs), n++)

, it's restricted to be less than or equal to expected_args with
the guard !VOID_TYPE_P (TREE_VALUE (fnargs)), so it's wrong.

The fix is to use nargs instead, also move the checking hunk's
location ahead to avoid useless further scanning when the counts
mismatch.

PR target/104482

gcc/ChangeLog:

* config/rs6000/rs6000-c.cc (altivec_resolve_overloaded_builtin): Fix
the equality check for argument number, and move this hunk ahead.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr104482.c: New test.

22 months agors6000: Handle unresolved overloaded builtin [PR105485]
Kewen.Lin [Tue, 13 Sep 2022 09:13:59 +0000 (04:13 -0500)]
rs6000: Handle unresolved overloaded builtin [PR105485]

PR105485 exposes that new builtin function framework doesn't handle
unresolved overloaded builtin function well.  With new builtin
function support, we don't have builtin info for any overloaded
rs6000_gen_builtins enum, since they are expected to be resolved to
one specific instance.  So when function rs6000_gimple_fold_builtin
faces one unresolved overloaded builtin, the access for builtin info
becomes out of bound and gets ICE then.

We should not try to fold one unresolved overloaded builtin there
and as the previous support we should emit one error message during
expansion phase like "unresolved overload for builtin ...".

PR target/105485

gcc/ChangeLog:

* config/rs6000/rs6000-builtin.cc (rs6000_gimple_fold_builtin): Add
the handling for unresolved overloaded builtin function.
(rs6000_expand_builtin): Likewise.

gcc/testsuite/ChangeLog:

* g++.target/powerpc/pr105485.C: New test.

22 months agors6000: Suggest unroll factor for loop vectorization
Kewen Lin [Tue, 13 Sep 2022 09:13:10 +0000 (04:13 -0500)]
rs6000: Suggest unroll factor for loop vectorization

Commit r12-6679-g7ca1582ca60dc8 made vectorizer accept one
unroll factor to be applied to vectorization factor when
vectorizing the main loop, it would be suggested by target
when doing costing.

This patch introduces function determine_suggested_unroll_factor
for rs6000 port, to make it be able to suggest the unroll factor
for a given loop being vectorized.  Referring to aarch64 port
and basing on the analysis on SPEC2017 performance evaluation
results, it mainly considers these aspects:
  1) unroll option and pragma which can disable unrolling for the
     given loop;
  2) simple hardware resource model with issued non memory access
     vector insn per cycle;
  3) aggressive heuristics when iteration count is unknown:
     - reduction case to break cross iteration dependency;
     - emulated gather load;
  4) estimated iteration count when iteration count is unknown;

With this patch, SPEC2017 performance evaluation results on
Power8/9/10 are listed below (speedup pct.):

  * Power10
    - O2: all are neutral (excluding some noises);
    - Ofast: 510.parest_r +6.67%, the others are neutral
             (use ... for the followings);
    - Ofast + unroll: 510.parest_r +5.91%, ...
    - Ofast + LTO + PGO: 510.parest_r +3.00%, ...
    - Ofast + cheap vect cost: 510.parest_r +6.23%, ...
    - Ofast + very-cheap vect cost: all are neutral;

  * Power9
    - Ofast: 510.parest_r +8.73%, 538.imagick_r +11.18%
             (likely noise), 500.perlbench_r +1.84%, ...

  * Power8
    - Ofast: 510.parest_r +5.43%, ...;

This patch also introduces one documented parameter
rs6000-vect-unroll-limit= similar to what aarch64 proposes,
by evaluating on P8/P9/P10, the default value 4 is slightly
better than the other choices like 2 and 8.

It also parameterizes two other values as undocumented
parameters for future tweaking.  One parameter is
rs6000-vect-unroll-issue, it's to simply model hardware
resource for non memory access vector instructions to avoid
excessive unrolling, initially I tried to use the value in
the hook rs6000_issue_rate, but the evaluation showed it's
bad, so I evaluated different values 2/4/6/8 on P8/P9/P10 at
Ofast, the results showed the default value 4 is good enough
on these different architectures.  For a record, choice 8
could make 510.parest_r's gain become smaller or gone on
P8/P9/P10; choice 6 could make 503.bwaves_r degrade by more
than 1% on P8/P10; and choice 2 could make 538.imagick_r
degrade by 3.8%.  The other parameter is
rs6000-vect-unroll-reduc-threshold.  It's mainly inspired by
510.parest_r and tweaked as it, evaluating with different
values 0/1/2/3 for the threshold, it showed value 1 is the
best choice.  For a record, choice 0 could make 525.x264_r
degrade by 2% and 527.cam4_r degrade by 2.95% on P10,
548.exchange2_r degrade by 1.41% and 527.cam4_r degrade by
2.54% on P8; choice 2 and bigger values could make
510.parest_r's gain become smaller.

gcc/ChangeLog:

* config/rs6000/rs6000.cc (class rs6000_cost_data): Add new members
m_nstores, m_reduc_factor, m_gather_load and member function
determine_suggested_unroll_factor.
(rs6000_cost_data::update_target_cost_per_stmt): Update for m_nstores,
m_reduc_factor and m_gather_load.
(rs6000_cost_data::determine_suggested_unroll_factor): New function.
(rs6000_cost_data::finish_cost): Use determine_suggested_unroll_factor.
* config/rs6000/rs6000.opt (rs6000-vect-unroll-limit): New parameter.
(rs6000-vect-unroll-issue): Likewise.
(rs6000-vect-unroll-reduc-threshold): Likewise.
* doc/invoke.texi (rs6000-vect-unroll-limit): Document new parameter.

22 months agomiddle-end/106909 - CTRL altering flag after folding
Richard Biener [Tue, 13 Sep 2022 06:59:41 +0000 (08:59 +0200)]
middle-end/106909 - CTRL altering flag after folding

The following makes sure to clear the CTRL altering flag when
folding emits a __builitin_unreachable in place of a virtual call
which now might become a trap.

PR middle-end/106909
* gimple-fold.cc (gimple_fold_call): Clear the ctrl-altering
flag of a unreachable call.

22 months agotree-optimization/106913 - ICE with -da and -Wuninitialized
Richard Biener [Tue, 13 Sep 2022 06:46:51 +0000 (08:46 +0200)]
tree-optimization/106913 - ICE with -da and -Wuninitialized

The following avoids setting and not clearing an auto_bb_flag
on EXIT_BLOCK which we don't verify for such stale flags but
dump_bb_info still asserts on them.

PR tree-optimization/106913
* tree-ssa-uninit.cc (warn_uninitialized_vars): Do not set
ft_reachable on EXIT_BLOCK.

22 months agoaarch64: Vector move fixes for +nosimd
Richard Sandiford [Tue, 13 Sep 2022 08:28:49 +0000 (09:28 +0100)]
aarch64: Vector move fixes for +nosimd

This patch fixes various issues around the handling of vectors
and (particularly) vector structures with +nosimd.  Previously,
passing and returning structures would trigger an ICE, since:

* we didn't allow the structure modes to be stored in FPRs

* we didn't provide +nosimd move patterns

* splitting the moves into word-sized pieces (the default
  strategy without move patterns) doesn't work because the
  registers are doubleword sized.

The patch is a bit of a hodge-podge since a lot of the handling of
moves, register costs, and register legitimacy is so interconnected.
It didn't seem feasible to split things further.

Some notes:

* The patch recognises vector and tuple modes based on TARGET_FLOAT
  rather than TARGET_SIMD, and instead adds TARGET_SIMD to places
  that really do need the vector ISA.  This is necessary for the
  modes to be handled correctly in register arguments and returns.

* The 64-bit (DREG) STP peephole required TARGET_SIMD but the
  LDP peephole didn't.  I think the LDP one is right, since
  DREG moves could involve GPRs as well as FPRs.

* The patch keeps the existing choices of instructions for
  TARGET_SIMD, just in case they happen to be better than FMOV
  on some uarches.

* Before the patch, +nosimd Q<->Q moves of 128-bit scalars went via
  a GPR, thanks to a secondary reload pattern.  This approach might
  not be ideal, but there's no reason that 128-bit vectors should
  behave differently from 128-bit scalars.  The patch therefore
  extends the current scalar approach to vectors.

* Multi-vector LD1 and ST1 require TARGET_SIMD, so the TARGET_FLOAT
  structure moves need to use LDP/STP and LDR/STR combinations
  instead.  That's also what we do for big-endian even with
  TARGET_SIMD, so most of the code was already there.  The patterns
  for structures of 64-bit vectors are identical, but the patterns
  for structures of 128-bit vectors need to cope with the lack of
  128-bit Q<->Q moves.

  It isn't feasible to move multi-vector tuples via GPRs, so the
  patch moves them via memory instead.  This contaminates the port
  with its first secondary memory reload.

gcc/

* config/aarch64/aarch64.cc (aarch64_classify_vector_mode): Use
TARGET_FLOAT instead of TARGET_SIMD.
(aarch64_vectorize_related_mode): Restrict ADVSIMD handling to
TARGET_SIMD.
(aarch64_hard_regno_mode_ok): Don't allow tuples of 2 64-bit vectors
in GPRs.
(aarch64_classify_address): Treat little-endian structure moves
like big-endian for TARGET_FLOAT && !TARGET_SIMD.
(aarch64_secondary_memory_needed): New function.
(aarch64_secondary_reload): Handle 128-bit Advanced SIMD vectors
in the same way as TF, TI and TD.
(aarch64_rtx_mult_cost): Restrict ADVSIMD handling to TARGET_SIMD.
(aarch64_rtx_costs): Likewise.
(aarch64_register_move_cost): Treat a pair of 64-bit vectors
separately from a single 128-bit vector.  Handle the cost implied
by aarch64_secondary_memory_needed.
(aarch64_simd_valid_immediate): Restrict ADVSIMD handling to
TARGET_SIMD.
(aarch64_expand_vec_perm_const_1): Likewise.
(TARGET_SECONDARY_MEMORY_NEEDED): New macro.
* config/aarch64/iterators.md (VTX): New iterator.
* config/aarch64/aarch64.md (arches): Add fp_q as a synonym of simd.
(arch_enabled): Adjust accordingly.
(@aarch64_reload_mov<TX:mode>): Extend to...
(@aarch64_reload_mov<VTX:mode>): ...this.
* config/aarch64/aarch64-simd.md (mov<mode>): Require TARGET_FLOAT
rather than TARGET_SIMD.
(movmisalign<mode>): Likewise.
(load_pair<DREG:mode><DREG2:mode>): Likewise.
(vec_store_pair<DREG:mode><DREG2:mode>): Likewise.
(load_pair<VQ:mode><VQ2:mode>): Likewise.
(vec_store_pair<VQ:mode><VQ2:mode>): Likewise.
(@aarch64_split_simd_mov<mode>): Likewise.
(aarch64_get_low<mode>): Likewise.
(aarch64_get_high<mode>): Likewise.
(aarch64_get_half<mode>): Likewise.  Canonicalize to a move for
lowpart extracts.
(*aarch64_simd_mov<VDMOV:mode>): Require TARGET_FLOAT rather than
TARGET_SIMD.  Use different w<-w and r<-w instructions for
!TARGET_SIMD.  Disable immediate moves for !TARGET_SIMD but
add an alternative specifically for w<-Z.
(*aarch64_simd_mov<VQMOV:mode>): Require TARGET_FLOAT rather than
TARGET_SIMD.  Likewise for the associated define_splits.  Disable
FPR moves and immediate moves for !TARGET_SIMD but add an alternative
specifically for w<-Z.
(aarch64_simd_mov_from_<mode>high): Require TARGET_FLOAT rather than
TARGET_SIMD.  Restrict the existing alternatives to TARGET_SIMD
but add a new r<-w one for !TARGET_SIMD.
(*aarch64_get_high<mode>): New pattern.
(load_pair_lanes<mode>): Require TARGET_FLOAT rather than TARGET_SIMD.
(store_pair_lanes<mode>): Likewise.
(*aarch64_combine_internal<mode>): Likewise.  Restrict existing
w<-w, w<-r and w<-m alternatives to TARGET_SIMD but add a new w<-r
alternative for !TARGET_SIMD.
(*aarch64_combine_internal_be<mode>): Likewise.
(aarch64_combinez<mode>): Require TARGET_FLOAT rather than TARGET_SIMD.
Remove bogus arch attribute.
(*aarch64_combinez_be<mode>): Likewise.
(@aarch64_vec_concat<mode>): Require TARGET_FLOAT rather than
TARGET_SIMD.
(aarch64_combine<mode>): Likewise.
(aarch64_rev_reglist<mode>): Likewise.
(mov<mode>): Likewise.
(*aarch64_be_mov<VSTRUCT_2D:mode>): Extend to TARGET_FLOAT &&
!TARGET_SIMD, regardless of endianness.  Extend associated
define_splits in the same way, both for this pattern and the
ones below.
(*aarch64_be_mov<VSTRUCT_2Qmode>): Likewise.  Restrict w<-w
alternative to TARGET_SIMD.
(*aarch64_be_movoi): Likewise.
(*aarch64_be_movci): Likewise.
(*aarch64_be_movxi): Likewise.
(*aarch64_be_mov<VSTRUCT_4QD:mode>): Extend to TARGET_FLOAT
&& !TARGET_SIMD, regardless of endianness.  Restrict w<-w alternative
to TARGET_SIMD for tuples of 128-bit vectors.
(*aarch64_be_mov<VSTRUCT_4QD:mode>): Likewise.
* config/aarch64/aarch64-ldpstp.md: Remove TARGET_SIMD condition
from DREG STP peephole.  Change TARGET_SIMD to TARGET_FLOAT in
the VQ and VP_2E LDP and STP peepholes.

gcc/testsuite/
* gcc.target/aarch64/ldp_stp_20.c: New test.
* gcc.target/aarch64/ldp_stp_21.c: Likewise.
* gcc.target/aarch64/ldp_stp_22.c: Likewise.
* gcc.target/aarch64/ldp_stp_23.c: Likewise.
* gcc.target/aarch64/ldp_stp_24.c: Likewise.
* gcc.target/aarch64/movv16qi_1.c (gpr_to_gpr): New function.
* gcc.target/aarch64/movv8qi_1.c (gpr_to_gpr): Likewise.
* gcc.target/aarch64/movv16qi_2.c: New test.
* gcc.target/aarch64/movv16qi_3.c: Likewise.
* gcc.target/aarch64/movv2di_1.c: Likewise.
* gcc.target/aarch64/movv2x16qi_1.c: Likewise.
* gcc.target/aarch64/movv2x8qi_1.c: Likewise.
* gcc.target/aarch64/movv3x16qi_1.c: Likewise.
* gcc.target/aarch64/movv3x8qi_1.c: Likewise.
* gcc.target/aarch64/movv4x16qi_1.c: Likewise.
* gcc.target/aarch64/movv4x8qi_1.c: Likewise.
* gcc.target/aarch64/movv8qi_2.c: Likewise.
* gcc.target/aarch64/movv8qi_3.c: Likewise.
* gcc.target/aarch64/vect_unary_2.c: Likewise.

22 months agoaarch64: Disassociate ls64 from simd
Richard Sandiford [Tue, 13 Sep 2022 08:28:48 +0000 (09:28 +0100)]
aarch64: Disassociate ls64 from simd

The ls64-related move expanders and splits required TARGET_SIMD.
That isn't necessary, since the 64-byte values are stored entirely
in GPRs.  (The associated define_insn was already correct.)

I wondered about moving the patterns to aarch64.md, but it wasn't
clear-cut.

gcc/
* config/aarch64/aarch64-simd.md (movv8di): Remove TARGET_SIMD
condition.  Likewise for the related define_split.  Tweak formatting.

gcc/testsuite/
* gcc.target/aarch64/acle/ls64_asm_2.c: New test.

22 months agolibgomp.texi: move item from gcn to nvptx
Tobias Burnus [Tue, 13 Sep 2022 07:08:57 +0000 (09:08 +0200)]
libgomp.texi: move item from gcn to nvptx

I misplaced one remark into 'gcn' instead of 'nvptx' in
commit r13-2625-g6b43f556f392a7165582aca36a19fe7389d995b2

libgomp/ChangeLog:

* libgomp.texi (gcn): Move misplaced -march=sm_30 remark to ...
(nvptx): ... here.

22 months agoDaily bump.
GCC Administrator [Tue, 13 Sep 2022 00:18:20 +0000 (00:18 +0000)]
Daily bump.

22 months agoc++: remove '_sfinae' suffix from functions
Patrick Palka [Mon, 12 Sep 2022 21:55:53 +0000 (17:55 -0400)]
c++: remove '_sfinae' suffix from functions

The functions

  abstract_virtuals_error
  cxx_constant_value
  get_target_expr
  instantiate_non_dependent_expr
  require_complete_type

are each just a non-SFINAE-enabled wrapper for the corresponding
SFINAE-enabled version that's suffixed by '_sfinae'.  But this suffix is
at best redundant since a 'complain' parameter already broadly conveys
that a function is SFINAE-enabled, and having two such versions of a
function is less concise than just using a default argument for 'complain'
(and arguably no less mistake prone).

So this patch squashes the two versions of each of the above functions
by adding a default 'complain' argument to the SFINAE-enabled version
whose '_sfinae' suffix we then remove.

gcc/cp/ChangeLog:

* call.cc (build_conditional_expr): Adjust calls to
'_sfinae'-suffixed functions.
(build_temp): Likewise.
(convert_like_internal): Likewise.
(convert_arg_to_ellipsis): Likewise.
(build_over_call): Likewise.
(build_cxx_call): Likewise.
(build_new_method_call): Likewise.
* constexpr.cc (cxx_eval_outermost_constant_expr): Likewise.
(cxx_constant_value_sfinae): Rename to ...
(cxx_constant_value): ... this.  Document its default arguments.
(fold_non_dependent_expr): Adjust function comment.
* cp-tree.h (instantiate_non_dependent_expr_sfinae): Rename to ...
(instantiate_non_dependent_expr): ... this.  Give its 'complain'
parameter a default argument.
(get_target_expr_sfinae, get_target_expr): Likewise.
(require_complete_type_sfinae, require_complete_type): Likewise.
(abstract_virtuals_error_sfinae, abstract_virtuals_error):
Likewise.
(cxx_constant_value_sfinae, cxx_constant_value): Likewise.
* cvt.cc (build_up_reference): Adjust calls to '_sfinae'-suffixed
functions.
(ocp_convert): Likewise.
* decl.cc (build_explicit_specifier): Likewise.
* except.cc (build_noexcept_spec): Likewise.
* init.cc (build_new_1): Likewise.
* pt.cc (expand_integer_pack): Likewise.
(instantiate_non_dependent_expr_internal): Adjust function
comment.
(instantiate_non_dependent_expr): Rename to ...
(instantiate_non_dependent_expr_sfinae): ... this.  Document its
default argument.
(tsubst_init): Adjust calls to '_sfinae'-suffixed functions.
(fold_targs_r): Likewise.
* semantics.cc (finish_compound_literal): Likewise.
(finish_decltype_type): Likewise.
(cp_build_bit_cast): Likewise.
* tree.cc (build_cplus_new): Likewise.
(get_target_expr): Rename to ...
(get_target_expr_sfinae): ... this.  Document its default
argument.
* typeck.cc (require_complete_type): Rename to ...
(require_complete_type_sfinae): ... this.  Document its default
argument.
(cp_build_array_ref): Adjust calls to '_sfinae'-suffixed
functions.
(convert_arguments): Likewise.
(cp_build_binary_op): Likewise.
(build_static_cast_1): Likewise.
(cp_build_modify_expr): Likewise.
(convert_for_initialization): Likewise.
* typeck2.cc (abstract_virtuals_error): Rename to ...
(abstract_virtuals_error_sfinae): ... this. Document its default
argument.
(build_functional_cast_1): Adjust calls to '_sfinae'-suffixed
functions.

22 months agoc++: template-id arguments are evaluated [PR101906]
Patrick Palka [Tue, 7 Jun 2022 18:19:53 +0000 (14:19 -0400)]
c++: template-id arguments are evaluated [PR101906]

Here we're neglecting to clear cp_unevaluated_operand when substituting
into the arguments of the alias template-id 'skip<(T(), 0), T>' with T=A,
which means cp_unevaluated_operand remains set during mark_used for
A::A() and so we don't synthesize it.  Later constant evaluation for
the substituted template argument '(A(), 0)' (from coerce_template_parms)
fails with "'constexpr A::A()' used before its definition" since it was
never synthesized.

This doesn't happen with a class template because tsubst_aggr_type
clears cp_unevaluated_operand during substitution thereof.  But since
template arguments are generally manifestly constant-evaluated, which in
turn are evaluated even in an unevaluated operand, we should be clearing
cp_unevaluated_operand more broadly whenever substituting into any set
of template arguments.  To that end this patch makes us clear it during
tsubst_template_args.

PR c++/101906

gcc/cp/ChangeLog:

* pt.cc (tsubst_template_args): Set cp_evaluated here.
(tsubst_aggr_type): Not here.

gcc/testsuite/ChangeLog:

* g++.dg/template/evaluated1.C: New test.
* g++.dg/template/evaluated1a.C: New test.
* g++.dg/template/evaluated1b.C: New test.
* g++.dg/template/evaluated1c.C: New test.

22 months agoc++: auto member function and auto variable [PR106893]
Jason Merrill [Mon, 12 Sep 2022 17:47:34 +0000 (13:47 -0400)]
c++: auto member function and auto variable [PR106893]

As with PR105623, we need to call mark_single_function sooner to
resolve the type of a BASELINK.

PR c++/106893
PR c++/90451

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Call mark_single_function.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/auto-fn65.C: New test.

22 months agoc++: cast to array of unknown bound [PR93259]
Jason Merrill [Mon, 12 Sep 2022 18:14:24 +0000 (14:14 -0400)]
c++: cast to array of unknown bound [PR93259]

We already know to treat a variable of array-of-unknown-bound type as
dependent, we should do the same for arr{}.

PR c++/93259

gcc/cp/ChangeLog:

* pt.cc (type_dependent_expression_p): Treat a compound
literal of array-of-unknown-bound type like a variable.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-array17.C: New test.

22 months agoxtensa: Implement new target hook: TARGET_CONSTANT_OK_FOR_CPROP_P
Takayuki 'January June' Suwa [Sun, 11 Sep 2022 11:51:15 +0000 (20:51 +0900)]
xtensa: Implement new target hook: TARGET_CONSTANT_OK_FOR_CPROP_P

This patch implements new target hook TARGET_CONSTANT_OK_FOR_CPROP_P in
order to exclude CONST_INTs that cannot fit into a MOVI machine instruction
from cprop.

gcc/ChangeLog:

* config/xtensa/xtensa.cc (TARGET_CONSTANT_OK_FOR_CPROP_P):
New macro definition.
(xtensa_constant_ok_for_cprop_p):
Implement the hook as mentioned above.

22 months agolibstdc++: Add already-accepted <ranges> testcase [PR106320]
Patrick Palka [Mon, 12 Sep 2022 19:05:04 +0000 (15:05 -0400)]
libstdc++: Add already-accepted <ranges> testcase [PR106320]

Although PR106320 affected only the 10 and 11 branches, and the testcase
from there is already correctly accepted on trunk and the 12 branch, we
still should add the testcase to trunk/12 too for inter-branch consistency.

PR libstdc++/106320

libstdc++-v3/ChangeLog:

* testsuite/std/ranges/adaptors/join.cc (test13): New test.

22 months agoc++: lambda capture of array with deduced bounds [PR106567]
Jason Merrill [Mon, 12 Sep 2022 16:59:46 +0000 (12:59 -0400)]
c++: lambda capture of array with deduced bounds [PR106567]

We can't use the type of an array variable directly if we haven't deduced
its length yet.

PR c++/106567

gcc/cp/ChangeLog:

* lambda.cc (type_deducible_expression_p): Check
array_of_unknown_bound_p.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-array4.C: New test.

22 months agoc++: Refer to internal linkage for -Wsubobject-linkage [PR86491]
Jonathan Wakely [Thu, 30 Jun 2022 16:53:26 +0000 (17:53 +0100)]
c++: Refer to internal linkage for -Wsubobject-linkage [PR86491]

Since C++11 relaxed the requirement for template arguments to have
external linkage, it's possible to get -Wsubobject-linkage warnings
without using any anonymous namespaces. This confuses users when they
get diagnostics that refer to an anonymous namespace that doesn't exist
in their code.

This changes the diagnostic to say "has internal linkage" for C++11 and
later, if the type isn't actually a member of the anonymous namespace.
Making that distinction involved renaming the current decl_anon_ns_mem_p to
something that better expresses its semantics.

For C++98 template arguments declared with 'static' are ill-formed
anyway, so the only way this warning can arise is via anonymous
namespaces. That means the existing wording is accurate for C++98 and so
we can keep it.

PR c++/86491

gcc/cp/ChangeLog:

* decl2.cc (constrain_class_visibility): Adjust wording of
-Wsubobject-linkage for cases where anonymous
namespaces aren't used.
* tree.cc (decl_anon_ns_mem_p): Now only true for actual anonymous
namespace members, rename old semantics to...
(decl_internal_context_p): ...this.
* cp-tree.h, name-lookup.cc, pt.cc: Adjust.

gcc/testsuite/ChangeLog:

* g++.dg/warn/anonymous-namespace-3.C: Use separate dg-warning
directives for C++98 and everything else.
* g++.dg/warn/Wsubobject-linkage-5.C: New test.

22 months agostdatomic.h: Do not define ATOMIC_VAR_INIT for C2x
Joseph Myers [Mon, 12 Sep 2022 14:34:26 +0000 (14:34 +0000)]
stdatomic.h: Do not define ATOMIC_VAR_INIT for C2x

The <stdatomic.h> macro ATOMIC_VAR_INIT, previously declared obsolete,
is removed completely in C2x; disable it for C2x in GCC's
implementation.  (Although ATOMIC_* are reserved names for this
header, disabling the macro for C2x still seems appropriate.)

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/
* ginclude/stdatomic.h [defined __STDC_VERSION__ &&
__STDC_VERSION__ > 201710L] (ATOMIC_VAR_INIT): Do not define.

gcc/testsuite/
* gcc.dg/atomic/c2x-stdatomic-var-init-1.c: New test.

22 months agonvptx/mkoffload.cc: Warn instead of error when reverse offload is not possible
Tobias Burnus [Mon, 12 Sep 2022 13:25:13 +0000 (15:25 +0200)]
nvptx/mkoffload.cc: Warn instead of error when reverse offload is not possible

Reverse offload requests at least -misa=sm_35; with this patch, a warning
instead of an error is shown, still permitting reverse offload for all
other configured device types. This is achieved by not calling
GOMP_offload_register_ver (and stopping generating pointless 'static const char'
variables, once known.)

The tool_name as progname changes adds "nvptx " and "gcn " to the
"mkoffload: warning/error:" diagnostic.

gcc/ChangeLog:

* config/nvptx/mkoffload.cc (process): Replace a fatal_error by
a warning + not enabling offloading if -misa=sm_30 prevents
reverse offload.
(main): Use tool_name as progname for diagnostic.
* config/gcn/mkoffload.cc (main): Likewise.

libgomp/ChangeLog:

* libgomp.texi (Offload-Target Specifics: nvptx): Document
that reverse offload requires >= -march=sm_35.
* testsuite/libgomp.c-c++-common/requires-4.c: Build for nvptx
with -misa=sm_35.
* testsuite/libgomp.c-c++-common/requires-5.c: Likewise.
* testsuite/libgomp.c-c++-common/requires-6.c: Likewise.
* testsuite/libgomp.c-c++-common/reverse-offload-1.c: Likewise.
* testsuite/libgomp.fortran/reverse-offload-1.f90: Likewise.
* testsuite/libgomp.c/reverse-offload-sm30.c: New test.

22 months agofrange::set_signbit: Avoid changing sign when already in the correct sign.
Aldy Hernandez [Mon, 12 Sep 2022 11:04:02 +0000 (13:04 +0200)]
frange::set_signbit: Avoid changing sign when already in the correct sign.

We should avoid pessimizing the signbit when it's already correct.  In
this particular case we were trying to change the signbit to "unknown",
when it was obviously negative.

This test is actually slated for removal with my upcoming revamp of the
signbit and NAN tracking, per the conversations regarding tristate.  The
signbit will be removed in favor of keeping track of it in the range
itself, and NAN will just be a pair of boolean flags.  However, I don't
plan to disturb the tree until after Cauldron.

Tested on x86-64 Linux including mpfr tests.  Also tested selftests with
-ffinite-math-only on x86-64 as well as on a cross to pdp11-aout.

gcc/ChangeLog:

* value-range.cc (frange::set_signbit): Avoid changing sign when
already in the correct sign.

22 months agoxtensa: gcc: fix builtin_apply return value
Max Filippov [Sun, 11 Sep 2022 00:31:07 +0000 (17:31 -0700)]
xtensa: gcc: fix builtin_apply return value

xtensa may use up to 4 registers to return a value from a function, but
recognition of only one register in the xtensa_function_value_regno_p
and missing untyped_call pattern result in that only one register is
saved by the __builtin_apply and returned by the __builtin_apply_return.

gcc/
* config/xtensa/xtensa.cc (xtensa_function_value_regno_p):
Recognize all 4 return registers.
* config/xtensa/xtensa.h (GP_RETURN_REG_COUNT): New definition.
* config/xtensa/xtensa.md (untyped_call): New pattern.

22 months agolibstdc++: Fix comments in tests to match code
Jonathan Wakely [Mon, 12 Sep 2022 11:02:29 +0000 (12:02 +0100)]
libstdc++: Fix comments in tests to match code

libstdc++-v3/ChangeLog:

* testsuite/19_diagnostics/error_code/cons/lwg3629.cc: Fix
comments.
* testsuite/19_diagnostics/error_condition/cons/lwg3629.cc:
Likewise.

22 months agolibgomp.texi: Impl. status fix/addition
Tobias Burnus [Mon, 12 Sep 2022 10:30:04 +0000 (12:30 +0200)]
libgomp.texi: Impl. status fix/addition

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.1 Impl. Status): Add two new minor items.
(OpenMP 5.2 Impl. Status): Improve omp/omx/ompx wording.

22 months agodoc: Fix typo in documentation of __float128 suffix
Jonathan Wakely [Mon, 12 Sep 2022 09:40:10 +0000 (10:40 +0100)]
doc: Fix typo in documentation of __float128 suffix

gcc/ChangeLog:

* doc/extend.texi (Floating Types): Fix "_float128" typo.

22 months agogcov: Respect triplet when looking for gcov
Torbjörn SVENSSON [Fri, 9 Sep 2022 10:19:27 +0000 (12:19 +0200)]
gcov: Respect triplet when looking for gcov

When testing a cross toolchain outside the build tree, the binary name
for gcov is prefixed with the triplet.

gcc/testsuite/ChangeLog:

* g++.dg/gcov/gcov.exp: Respect triplet when looking for gcov.
* gcc.misc-tests/gcov.exp: Likewise.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
22 months agolibstdc++: Outline the overlapping case of string _M_replace into a separate function...
Jakub Jelinek [Mon, 12 Sep 2022 09:31:11 +0000 (11:31 +0200)]
libstdc++: Outline the overlapping case of string _M_replace into a separate function [PR105329]

The following patch is partially a workaround for bogus warnings
when the compiler isn't able to fold _M_disjunct call into constant
false, but also an optimization attempt - assuming _M_disjunct (__s)
is rare, the patch should shrink code size for the common case and
use library or for non-standard instantiations an out of line
function to handle the rare case.

2022-09-12  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/105329
* acinclude.m4 (libtool_VERSION): Change to 6:31:0.
* config/abi/pre/gnu.ver (GLIBCXX_3.4.21): Don't export
std::basic_string methods with name length of 15.
(GLIBCXX_3.4.31): Export std::basic_string::_M_replace_cold.
* testsuite/util/testsuite_abi.cc (check_version): Handle
GLIBCXX_3.4.31.
* include/bits/basic_string.h (std::basic_string::_M_replace_cold):
Declare.
* include/bits/basic_string.tcc (std::basic_string::_M_replace_cold):
Define and export even for C++20.
(std::basic_string::_M_replace): Use __builtin_expect, outline
the overlapping case to _M_replace_cold.
* configure: Regenerated.

22 months agolibgomp: Fix up icv-6.c [PR106894]
Jakub Jelinek [Mon, 12 Sep 2022 08:48:19 +0000 (10:48 +0200)]
libgomp: Fix up icv-6.c [PR106894]

The thing is,
make check
or
make check RUNTESTFLAGS="c.exp='icv-6.c' c++.exp='icv-6.c'"
in libgomp obj dir work fine, but
make -j32 -k check RUNTESTFLAGS="c.exp='icv-6.c' c++.exp='icv-6.c'"
fails.
The thing is that the testcase as written relies on OMP_NUM_THREADS not being
set in environment (as it takes priority over OMP_NUM_THREADS_ALL for the
host).
So, if either a user has OMP_NUM_THREADS=42 in the environment by himself, or
when doing make check with -jN, we trigger:
          if test $$num_cpus -gt 8 && test -z "$$OMP_NUM_THREADS"; then \
            OMP_NUM_THREADS=8; export OMP_NUM_THREADS; \
            echo @@@ libgomp OMP_NUM_THREADS adjusted to 8 because of parallel
make check and too many CPUs; \
          fi; \
in libgomp/testsuite/Makefile.am and so the test fails.

2022-09-12  Jakub Jelinek  <jakub@redhat.com>

PR libgomp/106894
* testsuite/libgomp.c-c++-common/icv-6.c: Include string.h.
(main): Avoid tests for which corresponding non-_ALL suffixed variable
is in the environment, or for OMP_NUM_TEAMS on the device
OMP_NUM_TEAMS_DEV_?.

22 months ago[Ada] Fix immediate assertion failure with -gnatd.1
Eric Botcazou [Thu, 1 Sep 2022 14:21:07 +0000 (16:21 +0200)]
[Ada] Fix immediate assertion failure with -gnatd.1

The switch enables the front-end unnesting pass.

gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity): Relax assertion when
front-end unnesting is enabled.

22 months ago[Ada] Storage_Error raised analyzing type with call in its range constraint
Justin Squirek [Tue, 6 Sep 2022 14:35:53 +0000 (14:35 +0000)]
[Ada] Storage_Error raised analyzing type with call in its range constraint

This patch corrects a problem in the compiler whereby the determination of
scope levels during the generation of accessibility checks for function calls
within range constraints leads to a compiler crash due to the type not being
fully analyzed at the point in which its scope depth must be obtained.

gcc/ada/

* sem_util.adb
(Innermost_Master_Scope_Depth): Detect and handle case where scope
depth is not set on an enclosing scope.

22 months ago[Ada] Improve CUDA host-side and device-side binder support
Steve Baird [Wed, 7 Sep 2022 21:15:46 +0000 (14:15 -0700)]
[Ada] Improve CUDA host-side and device-side binder support

On the host-side, the binder now generates CUDA_Execute pragmas to
invoke initialization and finalization on the device-side. The
front end's expansion of these pragmas includes references to
entities declared in package CUDA.Internal. Generate a with-clause so
that unit will be available.

gcc/ada/

* bindgen.adb: When the binder is invoked for the host, generate a
"with CUDA.Internal;" with clause.

22 months ago[Ada] Sync documentation of junk names with code
Piotr Trojanek [Tue, 6 Sep 2022 22:19:19 +0000 (00:19 +0200)]
[Ada] Sync documentation of junk names with code

The list of junk entity names for which warnings are suppressed has been
recently modified, so update the documentation accordingly.

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst
(Pragma Unreferenced): Sync description with
Sem_Warn.Has_Junk_Name routine.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

22 months ago[Ada] Reject 'Valid_Scalars on Unchecked_Union regardless of privacy
Piotr Trojanek [Tue, 6 Sep 2022 18:11:35 +0000 (20:11 +0200)]
[Ada] Reject 'Valid_Scalars on Unchecked_Union regardless of privacy

Attribute Valid_Scalars applied to prefix with an unchecked union
component causes a legitimate crash in the backend. It was already
rejected in the frontend for prefixes of a public type; now it is
rejected in the frontend regardless of the type privacy.

gcc/ada/

* sem_attr.adb (Analyze_Attribute [Valid_Scalars]): Move check for
unchecked union before checks for private and public types.

22 months ago[Ada] Improve CUDA host-side and device-side binder support
Steve Baird [Fri, 2 Sep 2022 18:31:26 +0000 (11:31 -0700)]
[Ada] Improve CUDA host-side and device-side binder support

Use switches (one already existing, one newly added here) to indicate to
the binder that CUDA support code is to be generated for either the
host side or for the device side. Add an invocation of Adainit on the
device side from Adainit on the host side; similarly for Adafinal.

gcc/ada/

* bindgen.adb: When the binder is invoked for the host, it
declares imported subprograms corresponding to the Adainit and
Adafinal routines on the device. Declare string constants and
expression functions for the Ada source names and the link names
of these routines. Generate these subprogram declarations (and
accompanying Import pragmas) in Gen_CUDA_Defs. Generate
CUDA_Execute pragmas to call these subprograms from the host in
Gen_Adafinal and Gen_CUDA_Init. When the binder is invoked for the
device, include a CUDA_Global aspect declaration in the
declarations of Adainit and Adafinal and use the aforementioned
link names in the Export pragmas generated for those two routines.
* debug.adb: Update comments about "d_c" and "d_d" switches.
* opt.ads: Declare new Boolean variable,
Enable_CUDA_Device_Expansion. This complements the existing
Enable_CUDA_Expansion variable, which is used to enable host-side
CUDA expansion. The new variable enables device-side CUDA
expansion. It is currently never set during compilation; it is
only set via a binder switch.
* switch-b.adb
(scan_debug_switches): Add new use of the "-d_d" binder switch.
The new switch and the variable Opt.Enabled_CUDA_Device_Expansion
follow the existing pattern of the "-d_c" switch and the variable
Opt.Enabled_CUDA_Expansion. Flag error if both "-d_c" and "-d_d"
are specified.

22 months ago[Ada] Temporary tweak new expansion of contracts
Eric Botcazou [Mon, 5 Sep 2022 15:51:34 +0000 (17:51 +0200)]
[Ada] Temporary tweak new expansion of contracts

In the case of a function, the new expansion of contracts makes use of an
extended return statement to store the result of the function in the return
object while the post-conditions are evaluated.

Unfortunately GNAT does not elide the copy of the return object for extended
return statements for the time being, so this scheme incurs an extra copy of
the return value on the primary or secondary stack, as well as an additional
pair of calls to Adjust/Finalize when the return type needs finalization.

This temporarily changes the expansion to use a block statement containing a
renaming, which does not incur the extra copy provided that it is manually
adjusted to be recognized by the existing "tail call" optimization present
in the Expand_Simple_Function_Return routine.

gcc/ada/

* contracts.adb (uild_Subprogram_Contract_Wrapper): Remove useless
local variable. In the case of a function, replace the extended
return statement by a block statement declaring a renaming of the
call to the local subprogram after removing side effects manually.
(Expand_Subprogram_Contract): Adjust description accordingly.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Rewrite obsolete
comment and do not apply the transformation twice.
* sem_attr.adb (Analyze_Attribute_Old_Result): Now expect a block
statement instead of an extended return statement.

22 months ago[Ada] Special-case printing of SPARK_Mode in error messages
Piotr Trojanek [Mon, 5 Sep 2022 13:12:42 +0000 (15:12 +0200)]
[Ada] Special-case printing of SPARK_Mode in error messages

For error messages with inserted names that include acronyms like SPARK
or CPP, we want to preserve the casing. The list of special-cased named
is currently the same as in gnatpp.

gcc/ada/

* erroutc.adb (Set_Msg_Insertion_Name): Special-case printing with
acronyms.

22 months ago[Ada] Justify false alarm from CodePeer analysis of GNAT
Yannick Moy [Mon, 5 Sep 2022 14:19:36 +0000 (16:19 +0200)]
[Ada] Justify false alarm from CodePeer analysis of GNAT

Branch is determined as dead following a test always False by
CodePeer analysis, which is incorrect. Justify this false alarm
with an appropriate pragma Annotate.

gcc/ada/

* libgnat/s-imagei.adb (Image_Integer): Add justification.

22 months ago[Ada] Cleanup routine for handling SPARK_Mode kinds
Piotr Trojanek [Mon, 5 Sep 2022 12:59:30 +0000 (14:59 +0200)]
[Ada] Cleanup routine for handling SPARK_Mode kinds

Code cleanup; semantics is unaffected.

gcc/ada/

* sem_prag.adb (Get_SPARK_Mode_Type): Fix header box; replace
chained IF with a CASE statement.

22 months ago[Ada] Accept explicit SPARK_Mode Auto as configuration pragma
Yannick Moy [Mon, 5 Sep 2022 10:20:18 +0000 (12:20 +0200)]
[Ada] Accept explicit SPARK_Mode Auto as configuration pragma

An explicit value of Auto is now accepted for a configuration pragma
SPARK_Mode, as a way to exempt a unit from complete adherence to
SPARK rules when using a global configuration pragma file where
SPARK_Mode=>On is specified.

gcc/ada/

* sem_prag.adb (Analyze_Pragma): Accept SPARK_Mode=>Auto as
configuration pragma.
(Get_SPARK_Mode): Make the value for Auto explicit.
* snames.ads-tmpl (Name_Auto): Add name.

22 months ago[Ada] Remove SPARK containers from GNAT documentation
Joffrey Huguet [Fri, 2 Sep 2022 12:38:19 +0000 (14:38 +0200)]
[Ada] Remove SPARK containers from GNAT documentation

This patch removes documentation on the SPARK containers,
now under the spark2014 repository.

gcc/ada/

* doc/gnat_rm/the_gnat_library.rst: Remove paragraphs about SPARK
containers.
* gnat_rm.texi, gnat_ugn.texi: Regenerate.

22 months ago[Ada] Reject use in SPARK of Asm intrinsics for code insertions
Yannick Moy [Fri, 2 Sep 2022 08:40:56 +0000 (10:40 +0200)]
[Ada] Reject use in SPARK of Asm intrinsics for code insertions

SPARK does not allow code insertions. This applies also to
calls to Asm intrinsics defined in System.Machine_Code.

gcc/ada/

* libgnat/s-maccod.ads: Mark package as SPARK_Mode Off.

22 months ago[Ada] Add C declaration for Opt.Unnest_Subprogram_Mode
Eric Botcazou [Thu, 1 Sep 2022 14:15:06 +0000 (16:15 +0200)]
[Ada] Add C declaration for Opt.Unnest_Subprogram_Mode

gcc/ada/

* fe.h (Unnest_Subprogram_Mode): Declare.

22 months ago[Ada] Internal error compiling formal instance of generic with Initial_Condition
Steve Baird [Tue, 30 Aug 2022 23:04:02 +0000 (16:04 -0700)]
[Ada] Internal error compiling formal instance of generic with Initial_Condition

Prevent the compiler from failing with an internal error in some cases involving
an instance of a generic which takes as a formal parameter an instance of a
second generic, where the second generic has an Initial_Condition aspect
specification.

gcc/ada/

* contracts.adb
(Analyze_Package_Contract): Do not analyze the contract of a
temporary package created just to check conformance of an actual
package.

22 months ago[Ada] Replace SPARK containers implementation by Compile_Time_Error
Joffrey Huguet [Tue, 30 Aug 2022 16:00:35 +0000 (18:00 +0200)]
[Ada] Replace SPARK containers implementation by Compile_Time_Error

The SPARK containers are now maintained under the spark2014 repository.
This change replaces the implementation of SPARK containers by a
pragma Compile_Time_Error, pointing the users WITHing the libraries
to their new location.

gcc/ada/

* Makefile.rtl: Remove SPARK containers filenames.
* impunit.adb: Remove SPARK containers packages names.
* libgnat/a-cfdlli.adb, libgnat/a-cfdlli.ads: Remove content and
add pragma Compile_Time_Error with suitable message.
* libgnat/a-cfhama.adb, libgnat/a-cfhama.ads: Likewise.
* libgnat/a-cfhase.adb, libgnat/a-cfhase.ads: Likewise.
* libgnat/a-cfidll.adb, libgnat/a-cfidll.ads: Likewise.
* libgnat/a-cfinse.adb, libgnat/a-cfinse.ads: Likewise.
* libgnat/a-cfinve.adb, libgnat/a-cfinve.ads: Likewise.
* libgnat/a-cforma.adb, libgnat/a-cforma.ads: Likewise.
* libgnat/a-cforse.adb, libgnat/a-cforse.ads: Likewise.
* libgnat/a-cofove.adb, libgnat/a-cofove.ads: Likewise.
* libgnat/a-cofuma.adb, libgnat/a-cofuma.ads: Likewise.
* libgnat/a-cofuse.adb, libgnat/a-cofuse.ads: Likewise.
* libgnat/a-cofuve.adb, libgnat/a-cofuve.ads: Likewise.
* libgnat/a-cofuba.adb, libgnat/a-cofuba.ads: Remove package.

gcc/testsuite/

* gnat.dg/aspect2.adb: Removed.
* gnat.dg/aspect2.ads: Removed.
* gnat.dg/config_pragma1.adb: Removed.
* gnat.dg/config_pragma1_pkg.ads: Removed.
* gnat.dg/equal8.adb: Removed.
* gnat.dg/equal8.ads: Removed.
* gnat.dg/equal8_pkg.ads: Removed.
* gnat.dg/formal_containers.adb: Removed.
* gnat.dg/iter1.adb: Removed.
* gnat.dg/iter1.ads: Removed.

22 months ago[Ada] Fix validity checking on renamed Old attribute prefix
Piotr Trojanek [Mon, 8 Aug 2022 14:10:36 +0000 (16:10 +0200)]
[Ada] Fix validity checking on renamed Old attribute prefix

Prefix of attribute Old is captured either as an object renaming or as
an object declaration. This is now taken into account when applying
validity checks.

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference [Attribute_Old]):
Adapt to object declaration being rewritten into object renaming.

22 months ago[Ada] Tech debt: Expansion of contracts
Justin Squirek [Wed, 31 Aug 2022 14:52:11 +0000 (14:52 +0000)]
[Ada] Tech debt: Expansion of contracts

This patch modifies the expansion of contracts such that the statements
and declarations of a subprogram with post-execution checks get moved to
a local internally generated subprogram which the original subprogram
calls directly followed by the required post-execution checks.

This differs from the current implementation which requires delicate
machinary which coordinates with the finalization process to emulate the
desired behavior within the "at end" procedure.

gcc/ada/

* contracts.adb, contracts.ads
(Analyze_Pragmas_In_Declarations): Added to aid in the new
expansion model so that pragmas relating to contracts can get
processed early before the rest of the subprogram containing them.
(Build_Subprogram_Contract_Wrapper): Created to do the majority of
expansion for postconditions. It builds a local wrapper with the
statements and declarations within a given subprogram.
(Is_Prologue_Renaming): Moved out from Process_Preconditions to be
used generally within the contracts package.
(Build_Entry_Contract_Wrapper): Moved from exp_ch7.
(Expand_Subprogram_Contract): Add new local variable Decls to
store expanded declarations needed for evaluation of contracts.
Call new wrapper building procedure and modify comments to match
new expansion model.
(Get_Postcond_Enabled): Deleted.
(Get_Result_Object_For_Postcond): Deleted.
(Get_Return_Success_For_Postcond): Deleted.
(Process_Contract_Cases): Add new parameter to store declarations.
(Process_Postconditions): Add new parameter to store declarations.
(Process_Preconditions): Add new parameter to store declarations.
Add code to move entry-call prologue renamings
* einfo.ads: Document new field Wrapped_Statements and modify
comment for Postconditions_Proc.
* exp_attr.adb
(Analyze_Attribute): Modify expansion of the 'Old attribute to
recognize new expansion model and use Wrapped_Statements instead
of Postconditions_Proc.
* exp_ch6.adb
(Add_Return): Remove special expansion for postconditions.
(Expand_Call): Modify condition checking for calls to access
subprogram wrappers to handle new expansion models.
(Expand_Call_Helper): Remove special expansion for postconditions.
(Expand_Non_Function_Return): Remove special expansion for
postconditions.
(Expand_Simple_Function_Return): Remove special expansion for
postconditions.
* exp_ch7.adb
(Build_Finalizer): Deleted, but replaced by code in
Build_Finalizer_Helper
(Build_Finalizer_Helper): Renamed to Build_Finalizer, and special
handling of 'Old objects removed.
* exp_ch9.adb
(Build_Contract_Wrapper): Renamed and moved to contracts package.
* exp_prag.adb
(Expand_Pragma_Contract_Cases): Delay analysis of contracts since
they now instead get analyzed as part of the wrapper generation
instead of after analysis of their corresponding subprogram's
body.
(Expand_Pragma_Check): Label expanded if-statements which come
from the expansion of assertion statements as
Comes_From_Check_Or_Contract.
* freeze.adb
(Freeze_Entity): Add special case to avoid freezing when a freeze
node gets generated as part of the expansion of a postcondition
check.
* gen_il-gen-gen_nodes.adb: Add new flag
Comes_From_Check_Or_Contract.
* gen_il-fields.ads: Add new field Wrapped_Statements. Add new
flag Comes_From_Check_Or_Contract.
* gen_il-gen-gen_entities.adb: Add new field Wrapped_Statements.
* ghost.adb
(Is_OK_Declaration): Replace Name_uPostconditions with
Name_uWrapped_Statements.
(Is_OK_Statement): Simplify condition due to the loss of
Original_Node as a result of the new expansion model of contracts
and use new flag Comes_From_Check_Or_Contract in its place.
* inline.adb
(Declare_Postconditions_Result): Replace Name_uPostconditions with
Name_uWrapped_Statements.
(Expand_Inlined_Call): Replace Name_uPostconditions with
Name_uWrapped_Statements.
* lib.adb, lib.ads
(ipu): Created to aid in debugging.
* lib-xref.adb
(Generate_References): Remove special handling for postcondition
procedures.
* sem_attr.adb
(Analyze_Attribute_Old_Result): Add new context in which 'Old can
appear due to the changes in expansion. Replace
Name_uPostconditions with Name_uWrapped_Statements.
(Result): Replace Name_uPostconditions with
Name_uWrapped_Statements.
* sem_ch11.adb
(Analyze_Handled_Statements): Remove check to exclude warnings on
useless assignments within postcondition procedures since
postconditions no longer get isolated into separate subprograms.
* sem_ch6.adb
(Analyze_Generic_Subprogram_Body): Modify expansion of generic
subprogram bodies so that contracts (and their associated pragmas)
get analyzed first.
(Analyze_Subprogram_Body_Helper): Remove global HSS variable due
to the HSS of the body potentially changing during the expansion
of contracts. In cases where it was used instead directly call
Handled_Statement_Sequence. Modify expansion of subprogram bodies
so that contracts (and their associated pragmas) get analyzed
first.
(Check_Missing_Return): Create local HSS variable instead of using
a global one.
(Move_Pragmas): Use new pragma table instead of an explicit list.
* sem_elab.adb
(Is_Postconditions_Proc): Deleted since the new scheme of
expansion no longer divides postcondition checks to a separate
subprogram and so cannot be easily identified (similar to
pre-condition checks).
(Info_Call): Remove info printing for _Postconditions subprograms.
(Is_Assertion_Pragma_Target): Remove check for postconditions
procedure
(Is_Bridge_Target): Remove check for postconditions procedure.
(Get_Invocation_Attributes): Remove unneeded local variables and
check for postconditions procedure.
(Output_Call): Remove info printing for _Postconditions
subprograms.
* sem_prag.adb, sem_prag.ads: Add new Pragma table for pragmas
significant to subprograms, along with tech-debt comment.
(Check_Arg_Is_Local_Name): Modified to recognize the new
_Wrapped_Statements internal subprogram and the new expansion
model.
(Relocate_Pragmas_To_Body): Replace Name_uPostconditions with
Name_uWrapped_Statements.
* sem_res.adb
(Resolve_Entry_Call): Add conditional to detect both contract
based wrappers of entries, but also wrappers generated as part of
general contract expansion (e.g. local postconditions
subprograms).
* sem_util.adb
(Accessibility_Level): Verify 'Access is not taken based on a
component of a function result.
(Has_Significant_Contracts): Replace Name_uPostconditions with
Name_uWrapped_Statements.
(Same_Or_Aliased_Subprogram): Add conditional to detect and obtain
the original subprogram based on the new concept of
"postcondition" wrappers.
* sinfo.ads: Add documentation for new flag
Comes_From_Check_Or_Contract.
* snames.ads-tmpl: Remove Name_uPostconditions and add
Name_uWrapped_Statements

22 months ago[Ada] Fix oversight in implementation of unnesting
Eric Botcazou [Wed, 31 Aug 2022 12:39:08 +0000 (14:39 +0200)]
[Ada] Fix oversight in implementation of unnesting

The pass would traverse generic subprogram bodies, which are not expanded,
thus stumbling on unexpected nodes.

gcc/ada/

* exp_unst.adb (Unnest_Subprograms.Search_Subprograms): Skip the
subprogram bodies that are not to be unnested.

22 months ago[Ada] Syntax error in Ada 2022 array aggregate causes bug box
Steve Baird [Mon, 29 Aug 2022 21:55:14 +0000 (14:55 -0700)]
[Ada] Syntax error in Ada 2022 array aggregate causes bug box

Check for the case where a user writes "in" instead of "of" in an
aggregate like "[for E in Some_Array when Some_Filter (E) => E]".

gcc/ada/

* sem_aggr.adb
(Resolve_Array_Aggregate): Generate an appropriate error message
in the case where an error in the source code leads to an
N_Iterated_Element_Association node in a bad context.

22 months ago[Ada] Initialize a local variable to avoid a CodePeer warning
Steve Baird [Mon, 29 Aug 2022 22:33:45 +0000 (15:33 -0700)]
[Ada] Initialize a local variable to avoid a CodePeer warning

gcc/ada/

* sem_ch4.adb
(Analyze_Selected_Component): Initialize the local variable Comp
to avoid having CodePeer generate an uninitialized variable
warning.

22 months ago[Ada] bugbox referencing INOX prefixed view of primitive op of modular type
Steve Baird [Mon, 29 Aug 2022 20:26:30 +0000 (13:26 -0700)]
[Ada] bugbox referencing INOX prefixed view of primitive op of modular type

The -gnatX switch enables naming a prefixed view of a subprogram with an
untagged prefix. Compiling such a reference where the prefix is of a modular
type could result in an internal compiler error.

gcc/ada/

* sem_ch4.adb
(Analyze_Selected_Component): Avoid initializing the local
variable Comp if the variable is not going to be subsequently
referenced. This is a correctness issue because the call to
First_Entity can fail.

22 months ago[Ada] Lock_Free aspect takes precedence over Ceiling_Locking locking policy
Steve Baird [Thu, 25 Aug 2022 21:56:55 +0000 (14:56 -0700)]
[Ada] Lock_Free aspect takes precedence over Ceiling_Locking locking policy

Allow the Lock_Free aspect of a protected type to be True (but only by
explicit specification) if Ceiling_Locking locking policy has been specified.
Clarify that the Lock_Free aspect takes precedence over the Ceiling_Locking
policy in that case.

gcc/ada/

* sem_ch9.adb
(Satisfies_Lock_Free_Requirements): If Ceiling_Locking locking
policy has been specified, then either return False (if Lock_Free
was not explicitly specified) or generate a warning that ceiling
locking will not be implemented for this protected unit (if
Lock_Free was explicitly specified). Generate an error message (in
addition to returning False) if an explicit Lock_Free aspect
specification is rejected because atomic primitives are not
supported on the given target.
* doc/gnat_rm/implementation_defined_pragmas.rst: Clarify that the
Lock_Free aspect for a protected unit takes precedence over the
Ceiling_Locking locking policy in the case where both apply.
* gnat_rm.texi: Regenerate.

22 months ago[Ada] Do not mark user parameters of protected subprograms as artificial
Eric Botcazou [Wed, 24 Aug 2022 19:52:32 +0000 (21:52 +0200)]
[Ada] Do not mark user parameters of protected subprograms as artificial

This occurs because protected subprograms are not translated directly into
object code but first rewritten as a pair of subprograms by the front-end.

gcc/ada/

* exp_ch9.adb (Build_Protected_Spec): Tidy up and propagate the
Comes_From_Source flag onto the new formal parameters.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Do not check
references for subprograms generated for protected subprograms.

22 months ago[Ada] Fix issues with compiling ACATS test for user-defined literals
Gary Dismukes [Fri, 19 Aug 2022 22:40:05 +0000 (18:40 -0400)]
[Ada] Fix issues with compiling ACATS test for user-defined literals

The draft ACATS test (which we developed) for the Ada 2022 feature of
user-defined literals has compile-time problems that are fixed with this
set of changes.  Two of these involve the resolution of named numbers
in the context where an implicit literal conversion can occur, and for
equality when a literal or named number is an operand. Furthermore,
the compiler can hang in some cases when a numeric literal is used
in a context where the expected type is a type derived two levels
down from a tagged type that specifies a literal aspect.

gcc/ada/

* sem_res.adb
(Resolve_Equality_Op): Add handling for equality ops with
user-defined literal operands.
* sem_util.ads
(Is_User_Defined_Literal): Update spec comment to indicate
inclusion of named number cases.
* sem_util.adb
(Corresponding_Primitive_Op): Rather than following the chain of
ancestor subprograms via Alias and Overridden_Operation links, we
check for matching profiles between primitive subprograms of the
descendant type and the ancestor subprogram (by calling a new
nested function Profile_Matches_Ancestor). This prevents the
compiler from hanging due to circular linkages via those fields
that can occur between inherited and overriding subprograms
(which might indicate a latent bug, but one that may be rather
delicate to resolve).
(Profile_Matches_Ancestor): New nested subprogram to compare the
profile of a primitive subprogram with the profile of a candidate
ancestor subprogram.
(Is_User_Defined_Literal): Also return True in cases where the
node N denotes a named number (E_Name_Integer and E_Named_Real).

22 months ago[Ada] Remove a no-longer-correct comment
Steve Baird [Wed, 24 Aug 2022 16:11:02 +0000 (09:11 -0700)]
[Ada] Remove a no-longer-correct comment

Remove a comment about the former use of the -gnatd9 switch (that switch is
now unused).

gcc/ada/

* debug.adb: remove a comment.

22 months ago[Ada] Fix bugs in check-related warnings.
Bob Duff [Tue, 23 Aug 2022 16:51:01 +0000 (12:51 -0400)]
[Ada] Fix bugs in check-related warnings.

Make sure warnings about wrong-length aggregates don't get
suppressed. Such a warning (in a with-ed unit) can be the only
explanation for an error about No_Elaboration_Code violations.

Avoid passing a bogus "#" to Error_Msg. We really should never
construct message templates by concatenating strings that can
come from input data, but there are too many cases of that to
clean up. The message template parameters should really be
of a type other than String, to avoid these kinds of bugs,
but again, that's too much work to clean up now.

gcc/ada/

* checks.adb
(Selected_Length_Checks): In the message for an aggregate that has
too few or too many elements, add "!!" to make sure the warning
gets printed in with'ed units. Note that we have to put "!!"
before the "??", because Compile_Time_Constraint_Error detects
warnings by comparing the last character of the message with '?'
(which is bit dubious, but we're not changing that here).
(Length_Mismatch_Info_Message): Use Unat for some things that
can't be negative. Specify Decimal instead of Auto in calls to
UI_Image.
* sem_util.adb
(Compile_Time_Constraint_Error): Minor.
* uintp.adb
(Image_Uint): It's always better to initialize objects on their
declaration.

22 months ago[Ada] Disable Support_Atomic_Primitives on x86_64 VxWorks
Patrick Bernardi [Wed, 24 Aug 2022 14:02:21 +0000 (10:02 -0400)]
[Ada] Disable Support_Atomic_Primitives on x86_64 VxWorks

The current configuration of the x86-64 VxWorks runtimes does not support
atomic primitives. x86-64 VxWorks was missed from the previous patch.

gcc/ada/

* libgnat/system-vxworks7-x86_64-kernel.ads: Set
Support_Atomic_Primitives to false.
* libgnat/system-vxworks7-x86_64-rtp-smp.ads: Ditto.

22 months ago[Ada] Disable Support_Atomic_Primitives on QNX and VxWorks targets
Patrick Bernardi [Tue, 23 Aug 2022 14:36:06 +0000 (10:36 -0400)]
[Ada] Disable Support_Atomic_Primitives on QNX and VxWorks targets

The current configuration of the QNX and VxWorks runtimes does not support
atomic primitives.

gcc/ada/

* libgnat/system-qnx-arm.ads: Set Support_Atomic_Primitives to
false.
* libgnat/system-vxworks7-aarch64.ads: Ditto.
* libgnat/system-vxworks7-aarch64-rtp-smp.ads: Ditto.
* libgnat/system-vxworks7-arm.ads: Ditto.
* libgnat/system-vxworks7-arm-rtp-smp.ads: Ditto.
* libgnat/system-vxworks7-x86-kernel.ads: Ditto.
* libgnat/system-vxworks7-x86-rtp-smp.ads: Ditto.

22 months ago[Ada] Parser and lexer cleanup
Bob Duff [Wed, 17 Aug 2022 16:50:42 +0000 (12:50 -0400)]
[Ada] Parser and lexer cleanup

This patch makes various minor cleanup changes to the parser.
No change in behavior.

gcc/ada/

* par-tchk.adb, par-util.adb, prep.adb, prepcomp.adb, scng.adb:
Use "in" instead of chains of "=" connected with "or else".
Likewise for "not in", "/=", "and then". Misc cleanup.
* par-ch10.adb, par-ch12.adb, par-ch13.adb, par-ch4.adb: Likewise.
* par-ch8.adb, par-ch9.adb, par-endh.adb, par-sync.adb: Likewise.
* par.adb
(Pf_Rec): Remove filler, which was added August 25, 1993 to get
around a compiler limitation that no longer exists. Minor cleanup.
Remove useless qualfications.
* par-ch3.adb: Remove redundant return statements.
(Component_Scan_Loop): Remove loop name; there are no nested
loops, so it's unnecessary and possibly misleading, and it causes
too-long lines.
* par-ch5.adb: DRY: Remove comments that repeat the comments in
par.adb.
(P_Sequence_Of_Statements): It is better to initialize things on
the declaration. And constants are better than variables.
(Test_Statement_Required): Remove unnecessary insertion of a null
statement.
* par-ch6.adb, par-ch7.adb: DRY: Remove comments that repeat the
comments in par.adb.

22 months ago[Ada] Revert "Enforce matching of extra formals"
Javier Miranda [Tue, 23 Aug 2022 11:28:43 +0000 (11:28 +0000)]
[Ada] Revert "Enforce matching of extra formals"

This reverts commit 51abc0cc8691daecd7cec8372e4988e9f3f1913c.

22 months agoChangeLog: fix PR entry
Martin Liska [Mon, 12 Sep 2022 07:52:31 +0000 (09:52 +0200)]
ChangeLog: fix PR entry

gcc/testsuite/ChangeLog:

* ChangeLog: Fix PR reference.

22 months agoanalyzer: remove unused fields
Martin Liska [Mon, 12 Sep 2022 07:12:37 +0000 (09:12 +0200)]
analyzer: remove unused fields

Fixes:
gcc/analyzer/region-model.cc:5918:8: warning: private field 'm_record_type' is not used [-Wunused-private-field]
gcc/analyzer/region-model.cc:6305:25: warning: private field 'm_mgr' is not used [-Wunused-private-field]

gcc/analyzer/ChangeLog:

* region-model.cc (region_model::maybe_complain_about_infoleak):
  Remove unused fields.

22 months agoDaily bump.
GCC Administrator [Mon, 12 Sep 2022 00:17:04 +0000 (00:17 +0000)]
Daily bump.

22 months agoanalyzer: consider empty ranges and zero byte accesses [PR106845]
Tim Lange [Sat, 10 Sep 2022 21:53:48 +0000 (23:53 +0200)]
analyzer: consider empty ranges and zero byte accesses [PR106845]

This patch adds handling of empty ranges in bit_range and byte_range and
adds an assertion to member functions that assume a positive size.
Further, the patch fixes an ICE caused by an empty byte_range passed to
byte_range::exceeds_p.

Regression-tested on Linux x86_64.

2022-09-10  Tim Lange  <mail@tim-lange.me>

gcc/analyzer/ChangeLog:

PR analyzer/106845
* region-model.cc (region_model::check_region_bounds):
Bail out if 0 bytes were accessed.
* store.cc (byte_range::dump_to_pp):
Add special case for empty ranges.
(byte_range::exceeds_p): Restrict to non-empty ranges.
(byte_range::falls_short_of_p): Restrict to non-empty ranges.
* store.h (bit_range::empty_p): New function.
(bit_range::get_last_byte_offset): Restrict to non-empty ranges.
(byte_range::empty_p): New function.
(byte_range::get_last_byte_offset): Restrict to non-empty ranges.

gcc/testsuite/ChangeLog:

PR analyzer/106845
* gcc.dg/analyzer/out-of-bounds-zero.c: New test.
* gcc.dg/analyzer/pr106845.c: New test.

22 months agoDaily bump.
GCC Administrator [Sun, 11 Sep 2022 00:16:56 +0000 (00:16 +0000)]
Daily bump.

22 months agoxtensa: constantsynth: Add new 3-insns synthesis pattern
Takayuki 'January June' Suwa [Sat, 10 Sep 2022 09:29:45 +0000 (18:29 +0900)]
xtensa: constantsynth: Add new 3-insns synthesis pattern

This patch adds a new 3-instructions constant synthesis pattern:

- A value that can fit into a signed 12-bit after a number of either bitwise
  left or right rotations:
    => "MOVI(.N) Ax, simm12" + "SSAI (1 ... 11) or (21 ... 31)"
+ "SRC Ax, Ax, Ax"

gcc/ChangeLog:

* config/xtensa/xtensa.cc (xtensa_constantsynth):
Add new pattern for the abovementioned case.

gcc/testsuite/ChangeLog:

* gcc.target/xtensa/constsynth_3insns.c (test_4):
Add new test function.

22 months agors6000: Make an "if" statement more regular
Segher Boessenkool [Sat, 10 Sep 2022 15:13:40 +0000 (15:13 +0000)]
rs6000: Make an "if" statement more regular

As Akari noticed, we have an unusual "if" statement without parentheses
around the condition.  The condition is a macro that expands to
something with parentheses in the right spot, but, let's make the code a
little less surprising :-)

2022-09-10  Akari Takahashi  <akaritakahashioss@gmail.com>
    Segher Boessenkool  <segher@kernel.crashing.org>

* config/rs6000/rs6000.cc (get_memref_parts): Regularize some code.

22 months agolibgomp: Use libiberty environ.h to declare the environment pointer.
Iain Sandoe [Sat, 10 Sep 2022 07:54:37 +0000 (08:54 +0100)]
libgomp: Use libiberty environ.h to declare the environment pointer.

This allows for target-specific mechanisms for finding the pointer.

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

* env.c (initialize_env): Include libiberty environ.h.

22 months agofortran: Add IEEE_SIGNBIT and IEEE_FMA functions
Francois-Xavier Coudert [Wed, 31 Aug 2022 13:22:50 +0000 (15:22 +0200)]
fortran: Add IEEE_SIGNBIT and IEEE_FMA functions

The functions are added to the IEEE_ARITHMETIC module, but
are entirely expanded in the front-end, using GCC built-ins.

2022-08-31  Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>

PR fortran/95644

gcc/fortran/
* f95-lang.cc (gfc_init_builtin_functions): Declare FMA
built-ins.
* mathbuiltins.def: Declare FMA built-ins.
* trans-intrinsic.cc (conv_intrinsic_ieee_fma): New function.
(conv_intrinsic_ieee_signbit): New function.
(gfc_build_intrinsic_lib_fndecls): Add cases for FMA and
SIGNBIT.

gcc/testsuite/
* gfortran.dg/ieee/fma_1.f90: New test.
* gfortran.dg/ieee/signbit_1.f90: New test.

libgfortran/
* ieee/ieee_arithmetic.F90: Add IEEE_SIGNBIT and IEEE_FMA.

22 months agoDaily bump.
GCC Administrator [Sat, 10 Sep 2022 00:17:21 +0000 (00:17 +0000)]
Daily bump.

22 months agoxtensa: Make complex hard register clobber elimination more robust and accurate
Takayuki 'January June' Suwa [Thu, 1 Sep 2022 05:49:13 +0000 (14:49 +0900)]
xtensa: Make complex hard register clobber elimination more robust and accurate

This patch eliminates all clobbers for complex hard registers that will
be overwritten entirely afterwards (supersedence of
3867d414bd7d9e5b6fb2a51b1fb3d9e9e1eae9).

gcc/ChangeLog:

* config/xtensa/xtensa.md: Rewrite the split pattern that performs
the abovementioned process so that insns that overwrite clobbered
register no longer need to be contiguous.
(DSC): Remove as no longer needed.

22 months agoxtensa: Eliminate unused stack frame allocation/freeing
Takayuki 'January June' Suwa [Thu, 8 Sep 2022 21:16:31 +0000 (06:16 +0900)]
xtensa: Eliminate unused stack frame allocation/freeing

In the example below, 'x' is once placed on the stack frame and then read
into registers as the argument value of bar():

    /* example */
    struct foo {
      int a, b;
    };
    extern struct foo bar(struct foo);
    struct foo test(void) {
      struct foo x = { 0, 1 };
      return bar(x);
    }

Thanks to the dead store elimination, the initialization of 'x' turns into
merely loading the immediates to registers, but corresponding stack frame
growth is not rolled back.  As a result:

    ;; prereq: the CALL0 ABI
    ;; before
    test:
addi sp, sp, -16 // unused stack frame allocation/freeing
movi.n a2, 0
movi.n a3, 1
addi sp, sp, 16 // because no instructions that refer to
j.l bar, a9 // the stack pointer between the two

This patch eliminates such unused stack frame allocation/freeing:

    ;; after
    test:
movi.n a2, 0
movi.n a3, 1
j.l bar, a9

gcc/ChangeLog:

* config/xtensa/xtensa.cc (machine_function): New boolean member as
a flag that controls whether to emit the insns for stack pointer
adjustment inside of the pro/epilogue.
(xtensa_emit_adjust_stack_ptr): New function to share the common
codes and to emit insns if not inhibited.
(xtensa_expand_epilogue): Change to use the function mentioned
above when using the CALL0 ABI.
(xtensa_expand_prologue): Ditto.
And also change to set the inhibit flag used by
xtensa_emit_adjust_stack_ptr() to true if the stack pointer is only
used for its own adjustment.

22 months agoanalyzer: implement trust boundaries via a plugin for Linux kernel
David Malcolm [Fri, 9 Sep 2022 21:13:04 +0000 (17:13 -0400)]
analyzer: implement trust boundaries via a plugin for Linux kernel

This is a less ambitious version of:
  [PATCH 0/6] RFC: adding support to GCC for detecting trust boundaries
    https://gcc.gnu.org/pipermail/gcc-patches/2021-November/584372.html

Earlier versions of this patch attempted:
(a) various ways of identifying "untrusted" memory regions
(b) providing a way to support the Linux kernel's "__user" annotation,
    either via type attributes, or via custom address spaces
(c) enough attributes to identify "copy_from_user" and "copy_to_user",
(d) wiring all of the above together to detect infoleaks and taint

This patch adds a new -Wanalyzer-exposure-through-uninit-copy, emitted
by -fanalyzer if it detects copying of uninitialized data through
a pointer to an untrusted region, but requires a plugin to tell it when
a copy crosses a trust boundary.

This patch adds a proof-of-concept gcc plugin for the analyzer for use
with the Linux kernel that special-cases calls to "copy_from_user" and
calls to "copy_to_user": calls to copy_to_user are checked for
-Wanalyzer-exposure-through-uninit-copy, and data copied via
copy_from_user is marked as tainted when -fanalyzer-checker=taint is
active.

This is very much just a proof-of-concept.  A big limitation is that the
copy_{from,to}_user special-casing only happens if these functions have
no body in the TU being analyzed, which isn't the case for a normal
kernel build.  I'd much prefer to provide a more general mechanism for
handling such behavior without resorting to plugins (e.g. via attributes
or custom address spaces), but in the interest of not "letting perfect
be the enemy of the good" this patch at least allows parts of this
"trust boundaries" code to be merged for experimentation with the idea.

The -Wanalyzer-exposure-through-uninit-copy diagnostic uses notes to
express what fields and padding within a struct have not been initialized.
For example:

infoleak-CVE-2011-1078-2.c: In function 'test_1':
infoleak-CVE-2011-1078-2.c:32:9: warning: potential exposure of sensitive
  information by copying uninitialized data from stack across trust
  boundary [CWE-200] [-Wanalyzer-exposure-through-uninit-copy]
   32 |         copy_to_user(optval, &cinfo, sizeof(cinfo));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  'test_1': events 1-3
    |
    |   25 |         struct sco_conninfo cinfo;
    |      |                             ^~~~~
    |      |                             |
    |      |                             (1) region created on stack here
    |      |                             (2) capacity: 6 bytes
    |......
    |   32 |         copy_to_user(optval, &cinfo, sizeof(cinfo));
    |      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |         |
    |      |         (3) uninitialized data copied from stack here
    |
infoleak-CVE-2011-1078-2.c:32:9: note: 1 byte is uninitialized
   32 |         copy_to_user(optval, &cinfo, sizeof(cinfo));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
infoleak-CVE-2011-1078-2.c:18:15: note: padding after field 'dev_class'
  is uninitialized (1 byte)
   18 |         __u8  dev_class[3];
      |               ^~~~~~~~~
infoleak-CVE-2011-1078-2.c:25:29: note: suggest forcing
  zero-initialization by providing a '{0}' initializer
   25 |         struct sco_conninfo cinfo;
      |                             ^~~~~
      |                                   = {0}

For taint-detection, the patch includes a series of reproducers for
detecting CVE-2011-0521.  Unfortunately the analyzer doesn't yet detect
the issue until the code has been significantly simplified from its
original form: currently only in -5.c and -6.c in the series of test
(see notes in the individual cases), such as:

taint-CVE-2011-0521-6.c:33:48: warning: use of attacker-controlled value
  '*info.num' in array lookup without bounds checking [CWE-129]
  [-Wanalyzer-tainted-array-index]
   33 |             av7110->ci_slot[info->num].num = info->num;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
  'test_1': events 1-3
    |
    |   19 |    if (copy_from_user(&sbuf, (void __user *)arg, sizeof(sbuf)) != 0)
    |      |        ^
    |      |        |
    |      |        (1) following 'false' branch...
    |......
    |   23 |             struct dvb_device *dvbdev = file->private_data;
    |      |                                ~~~~~~
    |      |                                |
    |      |                                (2) ...to here
    |......
    |   33 |             av7110->ci_slot[info->num].num = info->num;
    |      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                                            |
    |      |                                            (3) use of attacker-controlled value '*info.num' in array lookup without bounds checking
    |

The patch also includes various infoleak and taint cases from my
antipatterns.ko kernel module:
  https://github.com/davidmalcolm/antipatterns.ko

gcc/analyzer/ChangeLog:
* analyzer.opt (Wanalyzer-exposure-through-uninit-copy): New.
* checker-path.cc (region_creation_event::region_creation_event):
Add "capacity" and "kind" params.
(region_creation_event::get_desc): Generalize to different kinds
of event.
(checker_path::add_region_creation_event): Convert to...
(checker_path::add_region_creation_events): ...this.
* checker-path.h (enum rce_kind): New.
(region_creation_event::region_creation_event): Add "capacity" and
"kind" params.
(region_creation_event::m_capacity): New field.
(region_creation_event::m_rce_kind): New field.
(checker_path::add_region_creation_event): Convert to...
(checker_path::add_region_creation_events): ...this.
* diagnostic-manager.cc (diagnostic_manager::build_emission_path):
Update for multiple region creation events.
(diagnostic_manager::add_event_on_final_node): Likewise.
(diagnostic_manager::add_events_for_eedge): Likewise.
* region-model-impl-calls.cc (call_details::get_logger): New.
* region-model.cc: Define INCLUDE_MEMORY before including
"system.h".  Include "gcc-rich-location.h".
(class record_layout): New.
(class exposure_through_uninit_copy): New.
(contains_uninit_p): New.
(region_model::maybe_complain_about_infoleak): New.
* region-model.h (call_details::get_logger): New decl.
(region_model::maybe_complain_about_infoleak): New decl.
(region_model::mark_as_tainted): New decl.
* sm-taint.cc (region_model::mark_as_tainted): New.

gcc/ChangeLog:
* doc/invoke.texi (Static Analyzer Options): Add
-Wanalyzer-exposure-through-uninit-copy.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_kernel_plugin.c: New test.
* gcc.dg/plugin/copy_from_user-1.c: New test.
* gcc.dg/plugin/infoleak-1.c: New test.
* gcc.dg/plugin/infoleak-2.c: New test.
* gcc.dg/plugin/infoleak-3.c: New test.
* gcc.dg/plugin/infoleak-CVE-2011-1078-1.c: New test.
* gcc.dg/plugin/infoleak-CVE-2011-1078-2.c: New test.
* gcc.dg/plugin/infoleak-CVE-2014-1446-1.c: New test.
* gcc.dg/plugin/infoleak-CVE-2017-18549-1.c: New test.
* gcc.dg/plugin/infoleak-CVE-2017-18550-1.c: New test.
* gcc.dg/plugin/infoleak-antipatterns-1.c: New test.
* gcc.dg/plugin/infoleak-fixit-1.c: New test.
* gcc.dg/plugin/infoleak-net-ethtool-ioctl.c: New test.
* gcc.dg/plugin/infoleak-vfio_iommu_type1.c: New test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
analyzer_kernel_plugin.c and the new test cases.
* gcc.dg/plugin/taint-CVE-2011-0521-1-fixed.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521-1.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521-2-fixed.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521-2.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521-3-fixed.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521-3.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521-4.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521-5-fixed.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521-5.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521-6.c: New test.
* gcc.dg/plugin/taint-CVE-2011-0521.h: New test.
* gcc.dg/plugin/taint-antipatterns-1.c: New test.
* gcc.dg/plugin/test-uaccess.h: New header for tests.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
22 months agoanalyzer: add support for plugin-supplied known function behaviors
David Malcolm [Fri, 9 Sep 2022 21:11:42 +0000 (17:11 -0400)]
analyzer: add support for plugin-supplied known function behaviors

This patch adds the ability for plugins to register "known functions"
with the analyzer, identified by name.  If -fanalyzer sees a call to
such a function (with no body), it will use a plugin-provided subclass
of the new known_function abstract base class to model the possible
outcomes of the function call.

gcc/ChangeLog:
* Makefile.in (ANALYZER_OBJS): Add
analyzer/known-function-manager.o.

gcc/analyzer/ChangeLog:
* analyzer.h (class known_function_manager): New forward decl.
(class known_function): New.
(plugin_analyzer_init_iface::register_known_function): New.
* engine.cc: Include "analyzer/known-function-manager.h".
(plugin_analyzer_init_impl::plugin_analyzer_init_impl): Add
known_fn_mgr param.
(plugin_analyzer_init_impl::register_state_machine): Add
LOC_SCOPE.
(plugin_analyzer_init_impl::register_known_function): New.
(plugin_analyzer_init_impl::m_known_fn_mgr): New.
(impl_run_checkers): Update plugin callback invocation to use
eng's known_function_manager.
* known-function-manager.cc: New file.
* known-function-manager.h: New file.
* region-model-manager.cc
(region_model_manager::region_model_manager): Pass logger to
m_known_fn_mgr's ctor.
* region-model.cc (region_model::update_for_zero_return): New.
(region_model::update_for_nonzero_return): New.
(maybe_simplify_upper_bound): New.
(region_model::maybe_get_copy_bounds): New.
(region_model::get_known_function): New.
(region_model::on_call_pre): Handle plugin-supplied known
functions.
* region-model.h: Include "analyzer/known-function-manager.h".
(region_model_manager::get_known_function_manager): New.
(region_model_manager::m_known_fn_mgr): New.
(call_details::get_model): New accessor.
(region_model::maybe_get_copy_bounds): New decl.
(region_model::update_for_zero_return): New decl.
(region_model::update_for_nonzero_return): New decl.
(region_model::get_known_function): New decl.
(region_model::get_known_function_manager): New.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_known_fns_plugin.c: New test plugin.
* gcc.dg/plugin/known-fns-1.c: New test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the new plugin
and test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
22 months agoanalyzer: add test coverage for flexible array members [PR98247]
David Malcolm [Fri, 9 Sep 2022 21:10:08 +0000 (17:10 -0400)]
analyzer: add test coverage for flexible array members [PR98247]

gcc/testsuite/ChangeLog:
PR analyzer/98247
* gcc.dg/analyzer/flexible-array-member-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
22 months agolibstdc++: Rename parameter to avoid darwin __weak qualifier
Jonathan Wakely [Fri, 9 Sep 2022 20:03:58 +0000 (21:03 +0100)]
libstdc++: Rename parameter to avoid darwin __weak qualifier

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (__atomic_impl::__compare_exchange):
Rename __weak to __is_weak.
* testsuite/17_intro/names.cc: Add __weak and __strong.

22 months agolibstdc++: Fix return type of empty zip_/adjacent_transform [PR106803]
Patrick Palka [Fri, 9 Sep 2022 18:59:14 +0000 (14:59 -0400)]
libstdc++: Fix return type of empty zip_/adjacent_transform [PR106803]

PR libstdc++/106803

libstdc++-v3/ChangeLog:

* include/std/ranges (views::_ZipTransform::operator()): Correct
return type in the empty case.
(views::_AdjacentTransform::operator()): Likewise.

22 months agolibstdc++: Fix typo in adjacent_view::_Iterator [PR106798]
Patrick Palka [Fri, 9 Sep 2022 18:56:37 +0000 (14:56 -0400)]
libstdc++: Fix typo in adjacent_view::_Iterator [PR106798]

PR libstdc++/106798

libstdc++-v3/ChangeLog:

* include/std/ranges (adjacent_view::_Iterator::_Iterator): Fix
typo.
* testsuite/std/ranges/adaptors/adjacent/1.cc (test04): New test.

22 months agolibstdc++: Fix zip_view's operator- for integer-class difference type [PR106766]
Patrick Palka [Fri, 9 Sep 2022 18:56:32 +0000 (14:56 -0400)]
libstdc++: Fix zip_view's operator- for integer-class difference type [PR106766]

The difference type of an underlying iterator could be an integer-class
type, which make_unsigned_t doesn't handle, so we need to use the more
general __make_unsigned_like_t / __to_unsigned_like here instead.

PR libstdc++/106766

libstdc++-v3/ChangeLog:

* include/std/ranges (zip_view::_Iterator::operator-): Use
__to_unsigned_like instead of make_unsigned_t.
(zip_view::_Sentinel::operator-): Likewise.
* testsuite/std/ranges/zip/1.cc (test04): New test.

22 months agonvptx: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup
Tobias Burnus [Fri, 9 Sep 2022 15:58:02 +0000 (17:58 +0200)]
nvptx: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup

Add support to nvptx for reverse lookup of function name to prepare for
'omp target device(ancestor:1)'.

gcc/ChangeLog:

* config/nvptx/mkoffload.cc (struct id_map): Add 'dim' member.
(record_id): Store func name without quotes, store dim separately.
(process): For GOMP_REQUIRES_REVERSE_OFFLOAD, check that -march is
at least sm_35, create '$offload_func_table' global array and init
with reverse-offload function addresses.
* config/nvptx/nvptx.cc (write_fn_proto_1, write_fn_proto): New
force_public attribute to force .visible.
(nvptx_declare_function_name): For "omp target
device_ancestor_nohost" attribut, force .visible/TREE_PUBLIC.

libgomp/ChangeLog:

* plugin/plugin-nvptx.c (GOMP_OFFLOAD_load_image): Read offload
function address table '$offload_func_table' if rev_fn_table
is not NULL.

22 months agoGCN: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup
Tobias Burnus [Fri, 9 Sep 2022 15:43:12 +0000 (17:43 +0200)]
GCN: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup

Add support to GCN for reverse lookup of function name to prepare for
'omp target device(ancestor:1)'.

gcc/ChangeLog:

* config/gcn/mkoffload.cc (process_asm): Create .offload_func_table,
similar to pre-existing .offload_var_table.

libgomp/ChangeLog:

* plugin/plugin-gcn.c (GOMP_OFFLOAD_load_image): Read
.offload_func_table to populate rev_fn_table when requested.

22 months agolibgomp: Prepare for reverse offload fn lookup
Tobias Burnus [Fri, 9 Sep 2022 15:37:09 +0000 (17:37 +0200)]
libgomp: Prepare for reverse offload fn lookup

Prepare for reverse-offloading function-pointer lookup by passing
a rev_fn_table argument to GOMP_OFFLOAD_load_image.

The argument will be NULL, unless GOMP_REQUIRES_REVERSE_OFFLOAD is
requested and devices not supported it, are filtered out.
(Up to and including this commit, no non-host device claims such
support and the caller currently always passes NULL.)

libgomp/ChangeLog:

* libgomp-plugin.h (GOMP_OFFLOAD_load_image): Add
'uint64_t **rev_fn_table' argument.
* oacc-host.c (host_load_image): Likewise.
* plugin/plugin-gcn.c (GOMP_OFFLOAD_load_image): Likewise;
currently unused.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_load_image): Likewise.
* target.c (gomp_load_image_to_device): Update call but pass
NULL for now.

liboffloadmic/ChangeLog:

* plugin/libgomp-plugin-intelmic.cpp (GOMP_OFFLOAD_load_image):
Add (unused) uint64_t **rev_fn_table argument.

22 months agostddef.h: Add C2x unreachable macro
Joseph Myers [Fri, 9 Sep 2022 14:11:21 +0000 (14:11 +0000)]
stddef.h: Add C2x unreachable macro

C2x adds a macro unreachable to stddef.h, with the same semantics as
__builtin_unreachable.  Define this macro accordingly.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/
* ginclude/stddef.h [__STDC_VERSION__ > 201710L] (unreachable):
New macro.

gcc/testsuite/
* gcc.dg/c11-unreachable-1.c, gcc.dg/c2x-unreachable-1.c: New
tests.

22 months agoHandle OPAQUE_TYPE specially in verify_type [PR106833]
Kewen Lin [Fri, 9 Sep 2022 13:17:21 +0000 (08:17 -0500)]
Handle OPAQUE_TYPE specially in verify_type [PR106833]

As PR106833 shows, cv-qualified opaque type can cause ICE
during LTO.  It exposes that we missd to handle OPAQUE_TYPE
well in type verification.  As Richi pointed out, also
assuming that target will always define TYPE_MAIN_VARIANT
TYPE_CANONICAL for opaque type, this patch is to check
both are OPAQUE_TYPE_P and their modes are of MODE_OPAQUE
class.  Besides, it also checks the only available size
and alignment information.

PR middle-end/106833

gcc/ChangeLog:

* tree.cc (verify_opaque_type): New function.
(verify_type): Call verify_opaque_type for OPAQUE_TYPE.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr106833.c: New test.