]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 years agoconfigure, Darwin: Set appropriate defaults for host-shared.
Iain Sandoe [Fri, 12 Nov 2021 17:05:13 +0000 (17:05 +0000)] 
configure, Darwin: Set appropriate defaults for host-shared.

Darwin x86_64 and aarch64 platforms are PIC (shared) by default,
and user-space code must be built in this mode.  The patch
ensures that this is set correctly and applies a default when
--enable-host-shared is not set.

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

* configure: Regenerate.
* configure.ac: Ensure that PIC (shared) defaults are set
correctly for Darwin.

2 years agoPCH: Make the save and restore diagnostics more robust.
Iain Sandoe [Sat, 13 Nov 2021 12:26:16 +0000 (12:26 +0000)] 
PCH: Make the save and restore diagnostics more robust.

When saving, if we cannot obtain a suitable memory segment there
is no point in continuing, so exit with an error.

When reading in the PCH, we have a situation that the read-in
data will replace the line tables used by the diagnostics output.
However, the state of the read-oin line tables is indeterminate
at some points where diagnostics might be needed.

To make this more robust, we save the existing line tables at
the start and, once we have read in the pointer to the new one,
put that to one side and restore the original table.  This
avoids compiler hangs if the read or memory acquisition code
issues an assert, fatal_error, segv etc.

Once the read is complete, we swap in the new line table that
came from the PCH.

If the read-in PCH is corrupted then we still have a broken
compilation w.r.t any future diagnostics - but there is little
that can be done about that without more careful validation of
the file.

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

* ggc-common.c (gt_pch_save): If we cannot find a suitable
memory segment for save, then error-out, do not try to
continue.
(gt_pch_restore): Save the existing line table, and when
the replacement is being read, use that when constructing
diagnostics.

2 years agors6000: MMA test case emits wrong code when building a vector pair [PR102976]
Peter Bergner [Tue, 16 Nov 2021 18:14:22 +0000 (12:14 -0600)] 
rs6000: MMA test case emits wrong code when building a vector pair [PR102976]

PR102976 shows a test case where we generate wrong code when building
a vector pair from 2 vector registers.  The bug here is that with unlucky
register assignments, we can clobber one of the input operands before
we write both registers of the output operand.  The solution is to use
early-clobbers in the assemble pair and accumulator patterns.

2021-11-16  Peter Bergner  <bergner@linux.ibm.com>

gcc/
PR target/102976
* config/rs6000/mma.md (*vsx_assemble_pair): Add early-clobber for
output operand.
(*mma_assemble_acc): Likewise.

gcc/testsuite/
PR target/102976
* gcc.target/powerpc/pr102976.c: New test.

2 years agofortran: Identify arguments by their names
Mikael Morin [Sun, 7 Nov 2021 13:40:36 +0000 (14:40 +0100)] 
fortran: Identify arguments by their names

This provides a new function to get the name of a dummy argument,
so that identifying an argument can be made using just its name
instead of a mix of name matching (for keyword actual arguments)
and argument counting (for other actual arguments).

gcc/fortran/ChangeLog:
* interface.c (gfc_dummy_arg_get_name): New function.
* gfortran.h (gfc_dummy_arg_get_name): Declare it.
* trans-array.c (arg_evaluated_for_scalarization): Pass a dummy
argument wrapper as argument instead of an actual argument
and an index number.  Check it’s non-NULL.  Use its name
to identify it.
(gfc_walk_elemental_function_args): Update call to
arg_evaluated for scalarization.  Remove argument counting.

2 years agofortran: Delete redundant missing_arg_type field
Mikael Morin [Sun, 7 Nov 2021 13:40:24 +0000 (14:40 +0100)] 
fortran: Delete redundant missing_arg_type field

Now that we can get information about an actual arg's associated
dummy using the associated_dummy attribute, the field missing_arg_type
contains redundant information.
This removes it.

gcc/fortran/ChangeLog:
* gfortran.h (gfc_actual_arglist::missing_arg_type): Remove.
* interface.c (gfc_compare_actual_formal): Remove
missing_arg_type initialization.
* intrinsic.c (sort_actual): Ditto.
* trans-expr.c (gfc_conv_procedure_call): Use associated_dummy
and gfc_dummy_arg_get_typespec to get the dummy argument type.

2 years agofortran: simplify elemental arguments walking
Mikael Morin [Sun, 7 Nov 2021 13:40:11 +0000 (14:40 +0100)] 
fortran: simplify elemental arguments walking

This adds two functions working with the wrapper struct gfc_dummy_arg
and makes usage of them to simplify a bit the walking of elemental
procedure arguments for scalarization.  As information about dummy arguments
can be obtained from the actual argument through the just-introduced
associated_dummy field, there is no need to carry around the procedure
interface and walk dummy arguments manually together with actual arguments.

gcc/fortran/ChangeLog:
* interface.c (gfc_dummy_arg_get_typespec,
gfc_dummy_arg_is_optional): New functions.
* gfortran.h (gfc_dummy_arg_get_typespec,
gfc_dummy_arg_is_optional): Declare them.
* trans.h (gfc_ss_info::dummy_arg): Use the wrapper type
as declaration type.
* trans-array.c (gfc_scalar_elemental_arg_saved_as_reference):
use gfc_dummy_arg_get_typespec function to get the type.
(gfc_walk_elemental_function_args): Remove proc_ifc argument.
Get info about the dummy arg using the associated_dummy field.
* trans-array.h (gfc_walk_elemental_function_args): Update declaration.
* trans-intrinsic.c (gfc_walk_intrinsic_function):
Update call to gfc_walk_elemental_function_args.
* trans-stmt.c (gfc_trans_call): Ditto.
(get_proc_ifc_for_call): Remove.

2 years agofortran: Reverse actual vs dummy argument mapping
Mikael Morin [Sun, 7 Nov 2021 13:39:59 +0000 (14:39 +0100)] 
fortran: Reverse actual vs dummy argument mapping

There was originally no way from an actual argument to get
to the corresponding dummy argument, even if the job of sorting
and matching actual with dummy arguments was done.
The closest was a field named actual in gfc_intrinsic_arg that was
used as scratch data when sorting arguments of one specific call.
However that value was overwritten later on as arguments of another
call to the same procedure were sorted and matched.

This change removes that field from gfc_intrinsic_arg and adds instead
a new field associated_dummy in gfc_actual_arglist.

The new field has as type a new wrapper struct gfc_dummy_arg that provides
a common interface to both dummy arguments of user-defined procedures
(which have type gfc_formal_arglist) and dummy arguments of intrinsic procedures
(which have type gfc_intrinsic_arg).

As the removed field was used in the code sorting and matching arguments,
that code has to be updated.  Two local vectors with matching indices
are introduced for respectively dummy and actual arguments, and the
loops are modified to use indices and update those argument vectors.

gcc/fortran/ChangeLog:
* gfortran.h (gfc_dummy_arg_kind, gfc_dummy_arg): New.
(gfc_actual_arglist): New field associated_dummy.
(gfc_intrinsic_arg): Remove field actual.
* interface.c (get_nonintrinsic_dummy_arg): New.
(gfc_compare_actual): Initialize associated_dummy.
* intrinsic.c (get_intrinsic_dummy_arg): New.
(sort_actual):  Add argument vectors.
Use loops with indices on argument vectors.
Initialize associated_dummy.

2 years agofortran: Tiny sort_actual internal refactoring
Mikael Morin [Sun, 7 Nov 2021 13:39:47 +0000 (14:39 +0100)] 
fortran: Tiny sort_actual internal refactoring

Preliminary refactoring to make further changes more obvious.
No functional change.

gcc/fortran/ChangeLog:
* intrinsic.c (sort_actual): initialise variable and use it earlier.

2 years agolibstdc++: Merge latest Ryu sources
Patrick Palka [Tue, 16 Nov 2021 17:23:27 +0000 (12:23 -0500)] 
libstdc++: Merge latest Ryu sources

libstdc++-v3/ChangeLog:

* src/c++17/ryu/MERGE: Update the commit hash.
* src/c++17/ryu/d2s_intrinsics.h: Merge from Ryu's master
branch.

Signed-off-by: Patrick Palka <ppalka@redhat.com>
2 years agolibstdc++: Implement constexpr std::basic_string for C++20
Michael de Lang [Wed, 26 Feb 2020 22:43:45 +0000 (23:43 +0100)] 
libstdc++: Implement constexpr std::basic_string for C++20

This is only supported for the cxx11 ABI, not for COW strings.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (basic_string, operator""s): Add
constexpr for C++20.
(basic_string::basic_string(basic_string&&)): Only copy
initialized portion of the buffer.
(basic_string::basic_string(basic_string&&, const Alloc&)):
Likewise.
* include/bits/basic_string.tcc (basic_string): Add constexpr
for C++20.
(basic_string::swap(basic_string&)): Only copy initialized
portions of the buffers.
(basic_string::_M_replace): Add constexpr implementation that
doesn't depend on pointer comparisons.
* include/bits/cow_string.h: Adjust comment.
* include/ext/type_traits.h (__is_null_pointer): Add constexpr.
* include/std/string (erase, erase_if): Add constexpr.
* include/std/version (__cpp_lib_constexpr_string): Update
value.
* testsuite/21_strings/basic_string/cons/char/constexpr.cc:
New test.
* testsuite/21_strings/basic_string/cons/wchar_t/constexpr.cc:
New test.
* testsuite/21_strings/basic_string/literals/constexpr.cc:
New test.
* testsuite/21_strings/basic_string/modifiers/constexpr.cc: New test.
* testsuite/21_strings/basic_string/modifiers/swap/char/constexpr.cc:
New test.
* testsuite/21_strings/basic_string/modifiers/swap/wchar_t/constexpr.cc:
New test.
* testsuite/21_strings/basic_string/version.cc: New test.

2 years agolibstdc++: Use hidden friends for vector<bool>::reference swap overloads
Jonathan Wakely [Thu, 11 Nov 2021 20:51:15 +0000 (20:51 +0000)] 
libstdc++: Use hidden friends for vector<bool>::reference swap overloads

These swap overloads are non-standard, but are needed to make swap work
for vector<bool>::reference rvalues. They don't need to be called
explicitly, only via ADL, so hide them from normal lookup. This is what
I've proposed as the resolution to LWG 3638.

libstdc++-v3/ChangeLog:

* include/bits/stl_bvector.h (swap(_Bit_reference, _Bit_reference))
(swap(_Bit_reference, bool&), swap(bool&, _Bit_reference)):
Define as hidden friends of _Bit_reference.

2 years agoAvoid assuming maximum string length is constant [PR102960].
Martin Sebor [Tue, 16 Nov 2021 16:18:25 +0000 (09:18 -0700)] 
Avoid assuming maximum string length is constant [PR102960].

Resolves:
PR tree-optimization/102960 - ICE: in sign_mask, at wide-int.h:855 in GCC 10.3.0

gcc/ChangeLog:

PR tree-optimization/102960
* gimple-fold.c (get_range_strlen): Take bitmap as an argument rather
than a pointer to it.
(get_range_strlen_tree): Same.  Remove bitmap allocation.  Use
an auto_bitmap.
(get_maxval_strlen): Use an auto_bitmap.
* tree-ssa-strlen.c (get_range_strlen_dynamic): Factor out PHI
handling...
(get_range_strlen_phi): ...into this function.
Avoid assuming maximum string length is constant
(printf_strlen_execute): Dump pointer query cache contents when
details are requisted.

gcc/testsuite/ChangeLog:

PR tree-optimization/102960
* gcc.dg/Wstringop-overflow-84.c: New test.

2 years agoshrn-combine-10: update test to current codegen.
Tamar Christina [Tue, 16 Nov 2021 15:39:28 +0000 (15:39 +0000)] 
shrn-combine-10: update test to current codegen.

When the rshrn commit was reverted I missed this testcase.
This now updates it.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/shrn-combine-10.c: Use shrn.

2 years agosignbit-2: make test check for scalar or vector versions
Tamar Christina [Tue, 16 Nov 2021 15:38:28 +0000 (15:38 +0000)] 
signbit-2: make test check for scalar or vector versions

This updates the signbit-2 test to check for
the scalar optimization if the target does not
support vectorization.

gcc/testsuite/ChangeLog:

* gcc.dg/signbit-2.c: CHeck vect or scalar.

2 years agoanalyzer: fix overeager sharing of bounded_range instances [PR102662]
David Malcolm [Mon, 15 Nov 2021 21:12:37 +0000 (16:12 -0500)] 
analyzer: fix overeager sharing of bounded_range instances [PR102662]

This was leading to an assertion failure ICE on a switch stmt when using
-fstrict-enums, due to erroneously reusing a range involving one enum
with a range involving a different enum.

gcc/analyzer/ChangeLog:
PR analyzer/102662
* constraint-manager.cc (bounded_range::operator==): Require the
types to be the same for equality.

gcc/testsuite/ChangeLog:
PR analyzer/102662
* g++.dg/analyzer/pr102662.C: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoc++: improve print_node of PTRMEM_CST
Jason Merrill [Fri, 29 Oct 2021 20:39:01 +0000 (16:39 -0400)] 
c++: improve print_node of PTRMEM_CST

It's been inconvenient that pretty-printing of PTRMEM_CST didn't display
what member the constant refers to.

Adding that is complicated by the absence of a langhook for CONSTANT_CLASS_P
nodes; the simplest fix for that is to use the tcc_exceptional hook for
tcc_constant as well.

gcc/cp/ChangeLog:

* ptree.c (cxx_print_xnode): Handle PTRMEM_CST.

gcc/ChangeLog:

* langhooks.h (struct lang_hooks): Adjust comment.
* print-tree.c (print_node): Also call print_xnode hook for
tcc_constant class.

2 years agotree-optimization: [PR103218] Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit
Andrew Pinski [Sat, 13 Nov 2021 04:16:55 +0000 (04:16 +0000)] 
tree-optimization: [PR103218] Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit

This folds Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit inside match.pd.
This was already handled in fold-cost by:
/* A < 0 ? <sign bit of A> : 0 is simply (A & <sign bit of A>).  */
I have not removed as we only simplify "a ? POW2 : 0" at the gimple level to "a << CST1"
and fold actually does the reverse of folding "(a<0)<<CST" into "(a<0) ? 1<<CST : 0".

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/103218

gcc/ChangeLog:

* match.pd: New pattern for "((type)(a<0)) << SIGNBITOFA".

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr103218-1.c: New test.

2 years agolibstdc++: Fix out-of-bound array accesses in testsuite
Jonathan Wakely [Thu, 21 Jul 2016 19:38:51 +0000 (20:38 +0100)] 
libstdc++: Fix out-of-bound array accesses in testsuite

I fixed some undefined behaviour in string tests in r238609, but I only
fixed the narrow char versions. This applies the same fixes to the
wchar_t ones. These problems were found when testing a patch to make
std::basic_string usable in constexpr.

libstdc++-v3/ChangeLog:

* testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc:
Fix reads past the end of strings.
* testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc:
Likewise.
* testsuite/experimental/string_view/operations/compare/wchar_t/1.cc:
Likewise.

2 years agolibstdc++: Fix typos in tests
Jonathan Wakely [Mon, 15 Nov 2021 20:37:04 +0000 (20:37 +0000)] 
libstdc++: Fix typos in tests

libstdc++-v3/ChangeLog:

* testsuite/21_strings/basic_string/allocator/71964.cc: Fix
typo.
* testsuite/23_containers/set/allocator/71964.cc: Likewise.

2 years agoarc: Update (u)maddhisi4 patterns
Claudiu Zissulescu [Tue, 16 Nov 2021 10:07:02 +0000 (12:07 +0200)] 
arc: Update (u)maddhisi4 patterns

The (u)maddsihi4 patterns are using the ARC's VMAC2H(U)
instruction with null destination, however, VMAC2H(U) doesn't
rewrite the accumulator.  This patch solves the destination issue
of VMAC2H by replacing it with DMACH(U) instruction.

gcc/

* config/arc/arc.md (maddhisi4): Use a single move to accumulator.
(umaddhisi4): Likewise.
(machi): Update pattern.
(umachi): Likewise.

gcc/testsuite/

* gcc.target/arc/tmac-4.c: New test.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2 years agotree-optimization/102880 - improve CD-DCE
Richard Biener [Fri, 12 Nov 2021 09:21:22 +0000 (10:21 +0100)] 
tree-optimization/102880 - improve CD-DCE

The PR shows a missed control-dependent DCE caused by CFG cleanup
merging a forwarder resulting in a partially degenerate PHI node.
With control-dependent DCE we need to mark control dependences
of incoming edges into PHIs as necessary but that is unnecessarily
conservative for the case when two edges have the same value.
There is no easy way to mark only a subset of control dependences
of both edges necessary so the fix is to produce forwarder blocks
where then the control dependence captures the requirements more
precisely.

For gcc.dg/tree-ssa/ssa-dom-thread-7.c the number of edges in the
CFG decrease as we have commonized PHI arguments which in turn
results in different threadings.  The testcase is too complex
and the dump scanning too simple to do anything meaningful here
but to adjust the number of expected threads.

The same CFG massaging could be useful at RTL expansion time to
reduce the number of copies we need to insert on edges.

FAIL: gcc.dg/tree-ssa/ssa-hoist-4.c scan-tree-dump-times optimized "MAX_EXPR" 1

2021-11-12  Richard Biener  <rguenther@suse.de>

PR tree-optimization/102880
* tree-ssa-dce.c (sort_phi_args): New function.
(make_forwarders_with_degenerate_phis): Likewise.
(perform_tree_ssa_dce): Call
make_forwarders_with_degenerate_phis.

* gcc.dg/tree-ssa/pr102880.c: New testcase.
* gcc.dg/tree-ssa/pr69270-3.c: Robustify.
* gcc.dg/tree-ssa/ssa-dom-thread-7.c: Change the number of
expected threadings.

2 years agotree-optimization/102880 - make PHI-OPT recognize more CFGs
Richard Biener [Mon, 15 Nov 2021 14:19:36 +0000 (15:19 +0100)] 
tree-optimization/102880 - make PHI-OPT recognize more CFGs

This allows extra edges into the middle BB for the PHI-OPT
transforms using replace_phi_edge_with_variable that do not
end up moving stmts from that middle BB.  This avoids regressing
gcc.dg/tree-ssa/ssa-hoist-4.c with the actual fix for PR102880
where CFG cleanup has the choice to remove two forwarders and
picks "the wrong" leading to

   if (a > b) /
       /\    /
      /  <BB>
     /    |
  # PHI <a, b>

rather than

   if (a > b)  |
       /\      |
    <BB> \     |
     /    \    |
  # PHI <a, b, b>

but it's relatively straight-forward to support extra edges
into the middle-BB in paths ending in replace_phi_edge_with_variable
and that do not require moving stmts.  That's because we really
only want to remove the edge from the condition to the middle BB.
Of course actually doing that means updating dominators in non-trival
ways which is why I kept the original code for the single edge
case and simply defer to CFG cleanup by adjusting the condition for
the complicated case.

The testcase needs to be a GIMPLE one since it's quite unreliable
to produce the desired CFG.

2021-11-15  Richard Biener  <rguenther@suse.de>

PR tree-optimization/102880
* tree-ssa-phiopt.c (tree_ssa_phiopt_worker): Push
single_pred (bb1) condition to places that really need it.
(match_simplify_replacement): Likewise.
(value_replacement): Likewise.
(replace_phi_edge_with_variable): Deal with extra edges
into the middle BB.

* gcc.dg/tree-ssa/phi-opt-26.c: New testcase.

2 years agoarc: Update arc specific tests
Claudiu Zissulescu [Tue, 16 Nov 2021 09:41:16 +0000 (11:41 +0200)] 
arc: Update arc specific tests

Update assembly output test pattern. Take into consideration also for
which platform we do execute the test (baremetal or linux).

gcc/testsuite/ChangeLog:

* gcc.target/arc/add_n-combine.c: Update test patterns.
* gcc.target/arc/builtin_eh.c: Update test for linux platforms.
* gcc.target/arc/mul64-1.c: Disable this test while running on
linux.
* gcc.target/arc/tls-gd.c: Update matching patterns.
* gcc.target/arc/tls-ie.c: Likewise.
* gcc.target/arc/tls-ld.c: Likewise.
* gcc.target/arc/uncached-8.c: Likewise.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2 years agoReplace more DEBUG_EXPR_DECL creations with build_debug_expr_decl
Martin Jambor [Tue, 16 Nov 2021 09:44:54 +0000 (10:44 +0100)] 
Replace more DEBUG_EXPR_DECL creations with build_debug_expr_decl

As discussed on the mailing list, this patch replaces all but one
remaining open coded constructions of DEBUG_EXPR_DECL with calls to
build_debug_expr_decl, even if - in order not to introduce any
functional change - the mode of the constructed decl is then
overwritten.

It is not clear if changing the mode has any effect in practice and
therefore I have added a FIXME note to code which does it, as
requested.

After this patch, DEBUG_EXPR_DECLs are created only by
build_debug_expr_decl and make_debug_expr_from_rtl which looks like
it should be left alone.

gcc/ChangeLog:

2021-11-11  Martin Jambor  <mjambor@suse.cz>

* cfgexpand.c (expand_gimple_basic_block): Use build_debug_expr_decl,
add a fixme note about the mode assignment perhaps being unnecessary.
* ipa-param-manipulation.c (ipa_param_adjustments::modify_call):
Likewise.
(ipa_param_body_adjustments::mark_dead_statements): Likewise.
(ipa_param_body_adjustments::reset_debug_stmts): Likewise.
* tree-inline.c (remap_ssa_name): Likewise.
(tree_function_versioning): Likewise.
* tree-into-ssa.c (rewrite_debug_stmt_uses): Likewise.
* tree-ssa-loop-ivopts.c (remove_unused_ivs): Likewise.
* tree-ssa.c (insert_debug_temp_for_var_def): Likewise.

2 years agoipa-sra: Testcase that removing a "returns_nonnull" retval works
Martin Jambor [Tue, 16 Nov 2021 09:44:53 +0000 (10:44 +0100)] 
ipa-sra: Testcase that removing a "returns_nonnull" retval works

Since we can now remove return values of functions with return_nonnull
type attribute, I'll feel a bit safer if we can test this does not ICE
when someone attempts to access a non-existent call LHS.  Eventually
we should probably drop the attribute when this happens.

gcc/testsuite/ChangeLog:

2021-11-15  Martin Jambor  <mjambor@suse.cz>

* gcc.dg/ipa/ipa-sra-ret-nonull.c: New test.

2 years agolibgomp: Mark thread_limit clause to target construct as implemented
Jakub Jelinek [Tue, 16 Nov 2021 09:21:56 +0000 (10:21 +0100)] 
libgomp: Mark thread_limit clause to target construct as implemented

After the Fortran changes we can mark it as implemented...

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

* libgomp.texi (OpenMP 5.1): Mark thread_limit clause to target
construct as implemented.

2 years agoopenmp: Regimplify operands of GIMPLE_COND in a few more places [PR103208]
Jakub Jelinek [Tue, 16 Nov 2021 09:19:22 +0000 (10:19 +0100)] 
openmp: Regimplify operands of GIMPLE_COND in a few more places [PR103208]

As the testcase shows, the non-rectangular loop expansion code didn't
try to regimplify operands of GIMPLE_CONDs it built in some cases.
I have added a helper function which does that and used it in some places
that were regimplifying already to simplify those spots, plus added it
in a couple of other places where it was needed.

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

PR tree-optimization/103208
* omp-expand.c (expand_omp_build_cond): New function.
(expand_omp_for_init_counts, expand_omp_for_init_vars,
expand_omp_for_static_nochunk, expand_omp_for_static_chunk): Use it.

* c-c++-common/gomp/loop-11.c: New test.

2 years agowaccess: Fix up pass_waccess::check_alloc_size_call [PR102009]
Jakub Jelinek [Tue, 16 Nov 2021 09:18:25 +0000 (10:18 +0100)] 
waccess: Fix up pass_waccess::check_alloc_size_call [PR102009]

This function punts if the builtins have no arguments, but as can be seen
on the testcase, even if it has some arguments but alloc_size attribute's
arguments point to arguments that aren't passed, we get a warning earlier
from the FE but should punt rather than ICE on it.
Other users of alloc_size attribute e.g. in
tree-object-size.c (alloc_object_size) punt similarly and similarly
even in the same TU maybe_warn_nonstring_arg correctly verifies calls have
enough arguments.

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

PR tree-optimization/102009
* gimple-ssa-warn-access.cc (pass_waccess::check_alloc_size_call):
Punt if any of alloc_size arguments is out of bounds vs. number of
call arguments.

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

2 years agox86_64: Avoid rorx rotation instructions with -Os.
Roger Sayle [Tue, 16 Nov 2021 08:55:21 +0000 (08:55 +0000)] 
x86_64: Avoid rorx rotation instructions with -Os.

This patch teaches the i386 backend to avoid using BMI2's rorx
instructions when optimizing for size.  The benefits are shown
with the following example:

unsigned int ror1(unsigned int x) { return (x >> 1) | (x << 31); }
unsigned int ror2(unsigned int x) { return (x >> 2) | (x << 30); }
unsigned int rol2(unsigned int x) { return (x >> 30) | (x << 2); }
unsigned int rol1(unsigned int x) { return (x >> 31) | (x << 1); }

which currently with -Os -march=cascadelake generates:

ror1: rorx    $1, %edi, %eax // 6 bytes
        ret
ror2: rorx    $2, %edi, %eax // 6 bytes
        ret
rol2: rorx    $30, %edi, %eax // 6 bytes
        ret
rol1: rorx    $31, %edi, %eax // 6 bytes
        ret

but with this patch now generates:

ror1: movl    %edi, %eax // 2 bytes
        rorl    %eax // 2 bytes
        ret
ror2: movl    %edi, %eax // 2 bytes
        rorl    $2, %eax // 3 bytes
        ret
rol2: movl    %edi, %eax // 2 bytes
        roll    $2, %eax // 3 bytes
        ret
rol1: movl    %edi, %eax // 2 bytes
        roll    %eax // 2 bytes
        ret

I've confirmed that this patch is a win on the CSiBE benchmark,
even though rotations are rare, where for example libmspack/test/md5.o
shrinks from 5824 bytes to 5632 bytes.

2021-11-16  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/i386/i386.md (*bmi2_rorx<mode3>_1): Make conditional
on !optimize_function_for_size_p.
(*<any_rotate><mode>3_1): Add preferred_for_size attribute.
(define_splits): Conditionalize on !optimize_function_for_size_p.
(*bmi2_rorxsi3_1_zext): Likewise.
(*<any_rotate>si2_1_zext): Add preferred_for_size attribute.
(define_splits): Conditionalize on !optimize_function_for_size_p.

2 years agoFix uninitialized access in merge_call_side_effects
Jan Hubicka [Tue, 16 Nov 2021 08:15:39 +0000 (09:15 +0100)] 
Fix uninitialized access in merge_call_side_effects

gcc/ChangeLog:

PR ipa/103262
* ipa-modref.c (merge_call_side_effects): Fix uninitialized
access.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/modref-dse-5.c: New test.

2 years agotree-optimization: [PR103245] Improve detection of abs pattern using multiplication
Andrew Pinski [Mon, 15 Nov 2021 22:55:09 +0000 (22:55 +0000)] 
tree-optimization: [PR103245] Improve detection of abs pattern using multiplication

So while working on PR 103228 (and a few others), I noticed the testcase for PR 94785
was failing. The problem is that the nop_convert moved from being inside the IOR to be
outside of it. I also noticed the patch for PR 103228 was not needed to reproduce the
issue either.
This patch combines the two patterns together for the abs match when using multiplication
and adds a few places where nop_convert are optional.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/103245

gcc/ChangeLog:

* match.pd: Combine the abs pattern matching using multiplication.
Adding optional nop_convert too.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr103245-1.c: New test.

2 years agoAdd a missing return when transforming atomic bit test and operations
H.J. Lu [Tue, 16 Nov 2021 01:37:10 +0000 (17:37 -0800)] 
Add a missing return when transforming atomic bit test and operations

When failing to transform equivalent, but slighly different cases of
atomic bit test and operations to their canonical forms, return
immediately.

gcc/

PR middle-end/103268
* tree-ssa-ccp.c (optimize_atomic_bit_test_and): Add a missing
return.

gcc/testsuite/

PR middle-end/103268
* gcc.dg/pr103268-1.c: New test.
* gcc.dg/pr103268-2.c: Likewise.

2 years agoUpdate my email address.
Jim Wilson [Tue, 16 Nov 2021 01:02:40 +0000 (17:02 -0800)] 
Update my email address.

* MAINTAINERS: Update my address.

2 years agoDaily bump.
GCC Administrator [Tue, 16 Nov 2021 00:16:31 +0000 (00:16 +0000)] 
Daily bump.

2 years agoc++: Add -fimplicit-constexpr
Jason Merrill [Wed, 13 Oct 2021 15:47:25 +0000 (11:47 -0400)] 
c++: Add -fimplicit-constexpr

With each successive C++ standard the restrictions on the use of the
constexpr keyword for functions get weaker and weaker; it recently occurred
to me that it is heading toward the same fate as the C register keyword,
which was once useful for optimization but became obsolete.  Similarly, it
seems to me that we should be able to just treat inlines as constexpr
functions and not make people add the extra keyword everywhere.

There were a lot of testcase changes needed; many disabling errors about
non-constexpr functions that are now constexpr, and many disabling implicit
constexpr so that the tests can check the same thing as before, whether
that's mangling or whatever.

gcc/c-family/ChangeLog:

* c.opt: Add -fimplicit-constexpr.
* c-cppbuiltin.c: Define __cpp_implicit_constexpr.
* c-opts.c (c_common_post_options): Disable below C++14.

gcc/cp/ChangeLog:

* cp-tree.h (struct lang_decl_fn): Add implicit_constexpr.
(decl_implicit_constexpr_p): New.
* class.c (type_maybe_constexpr_destructor): Use
TYPE_HAS_TRIVIAL_DESTRUCTOR and maybe_constexpr_fn.
(finalize_literal_type_property): Simplify.
* constexpr.c (is_valid_constexpr_fn): Check for dtor.
(maybe_save_constexpr_fundef): Try to set DECL_DECLARED_CONSTEXPR_P
on inlines.
(cxx_eval_call_expression): Use maybe_constexpr_fn.
(maybe_constexpr_fn): Handle flag_implicit_constexpr.
(var_in_maybe_constexpr_fn): Use maybe_constexpr_fn.
(potential_constant_expression_1): Likewise.
(decl_implicit_constexpr_p): New.
* decl.c (validate_constexpr_redeclaration): Allow change with
-fimplicit-constexpr.
(grok_special_member_properties): Use maybe_constexpr_fn.
* error.c (dump_function_decl): Don't print 'constexpr'
if it's implicit.
* Make-lang.in (check-c++-all): Update.

libstdc++-v3/ChangeLog:

* testsuite/20_util/to_address/1_neg.cc: Adjust error.
* testsuite/26_numerics/random/concept.cc: Adjust asserts.

gcc/testsuite/ChangeLog:

* lib/g++-dg.exp: Handle "impcx".
* lib/target-supports.exp
(check_effective_target_implicit_constexpr): New.
* g++.dg/abi/abi-tag16.C:
* g++.dg/abi/abi-tag18a.C:
* g++.dg/abi/guard4.C:
* g++.dg/abi/lambda-defarg1.C:
* g++.dg/abi/mangle26.C:
* g++.dg/cpp0x/constexpr-diag3.C:
* g++.dg/cpp0x/constexpr-ex1.C:
* g++.dg/cpp0x/constexpr-ice5.C:
* g++.dg/cpp0x/constexpr-incomplete2.C:
* g++.dg/cpp0x/constexpr-memfn1.C:
* g++.dg/cpp0x/constexpr-neg3.C:
* g++.dg/cpp0x/constexpr-specialization.C:
* g++.dg/cpp0x/inh-ctor19.C:
* g++.dg/cpp0x/inh-ctor30.C:
* g++.dg/cpp0x/lambda/lambda-mangle3.C:
* g++.dg/cpp0x/lambda/lambda-mangle5.C:
* g++.dg/cpp1y/auto-fn12.C:
* g++.dg/cpp1y/constexpr-loop5.C:
* g++.dg/cpp1z/constexpr-lambda7.C:
* g++.dg/cpp2a/constexpr-dtor3.C:
* g++.dg/cpp2a/constexpr-new13.C:
* g++.dg/cpp2a/constinit11.C:
* g++.dg/cpp2a/constinit12.C:
* g++.dg/cpp2a/constinit14.C:
* g++.dg/cpp2a/constinit15.C:
* g++.dg/cpp2a/spaceship-constexpr1.C:
* g++.dg/cpp2a/spaceship-eq3.C:
* g++.dg/cpp2a/udlit-class-nttp-neg2.C:
* g++.dg/debug/dwarf2/auto1.C:
* g++.dg/debug/dwarf2/cdtor-1.C:
* g++.dg/debug/dwarf2/lambda1.C:
* g++.dg/debug/dwarf2/pr54508.C:
* g++.dg/debug/dwarf2/pubnames-2.C:
* g++.dg/debug/dwarf2/pubnames-3.C:
* g++.dg/ext/is_literal_type3.C:
* g++.dg/ext/visibility/template7.C:
* g++.dg/gcov/gcov-12.C:
* g++.dg/gcov/gcov-2.C:
* g++.dg/ipa/devirt-35.C:
* g++.dg/ipa/devirt-36.C:
* g++.dg/ipa/devirt-37.C:
* g++.dg/ipa/devirt-44.C:
* g++.dg/ipa/imm-devirt-1.C:
* g++.dg/lookup/builtin5.C:
* g++.dg/lto/inline-crossmodule-1_0.C:
* g++.dg/modules/enum-1_a.C:
* g++.dg/modules/fn-inline-1_c.C:
* g++.dg/modules/pmf-1_b.C:
* g++.dg/modules/used-1_c.C:
* g++.dg/tls/thread_local11.C:
* g++.dg/tls/thread_local11a.C:
* g++.dg/tm/pr46653.C:
* g++.dg/ubsan/pr70035.C:
* g++.old-deja/g++.other/delete6.C:
* g++.dg/modules/pmf-1_a.H:
Adjust for implicit constexpr.

2 years agoc++: split_nonconstant_init and flexarrays
Jason Merrill [Mon, 15 Nov 2021 17:59:08 +0000 (12:59 -0500)] 
c++: split_nonconstant_init and flexarrays

split_nonconstant_init was doing the wrong thing for both the initialization
and cleanup here; we know the size from the initializer, and we can pass it
along.  This doesn't make the testcase work, since the y destructor is still
broken, but it removes the wrong error for the aggregate initialization.

gcc/cp/ChangeLog:

* typeck2.c (split_nonconstant_init_1): Handle flexarrays better.

gcc/testsuite/ChangeLog:

* g++.dg/ext/flexary37.C: Remove expected error.

2 years agogimple-fold: Use ranges to simplify strncat and snprintf
Siddhesh Poyarekar [Mon, 15 Nov 2021 17:33:15 +0000 (23:03 +0530)] 
gimple-fold: Use ranges to simplify strncat and snprintf

Use ranges for lengths and object sizes in strncat and snprintf to
determine if they can be transformed into simpler operations.

gcc/ChangeLog:

* gimple-fold.c (gimple_fold_builtin_strncat): Use ranges to
determine if it is safe to transform to strcat.
(gimple_fold_builtin_snprintf): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/fold-stringops-2.c: Define size_t.
(safe1): Adjust.
(safe4): New test.
* gcc.dg/fold-stringops-3.c: New test.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
2 years agogimple-fold: Use ranges to simplify _chk calls
Siddhesh Poyarekar [Mon, 15 Nov 2021 17:33:14 +0000 (23:03 +0530)] 
gimple-fold: Use ranges to simplify _chk calls

Instead of comparing LEN and SIZE only if they are constants, use their
ranges to decide if LEN will always be lower than or same as SIZE.

This change ends up putting the stringop-overflow warning line number
against the strcpy implementation, so adjust the warning check to be
line number agnostic.

gcc/ChangeLog:

* gimple-fold.c (known_lower): New function.
(gimple_fold_builtin_strncat_chk,
gimple_fold_builtin_memory_chk, gimple_fold_builtin_stxcpy_chk,
gimple_fold_builtin_stxncpy_chk,
gimple_fold_builtin_snprintf_chk,
gimple_fold_builtin_sprintf_chk): Use it.

gcc/testsuite/ChangeLog:

* gcc.dg/Wobjsize-1.c: Make warning change line agnostic.
* gcc.dg/fold-stringops-2.c: New test.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
2 years agogimple-fold: Transform stp*cpy_chk to str*cpy directly
Siddhesh Poyarekar [Mon, 15 Nov 2021 17:33:13 +0000 (23:03 +0530)] 
gimple-fold: Transform stp*cpy_chk to str*cpy directly

Avoid going through another folding cycle and use the ignore flag to
directly transform BUILT_IN_STPCPY_CHK to BUILT_IN_STRCPY when set,
likewise for BUILT_IN_STPNCPY_CHK to BUILT_IN_STPNCPY.

Dump the transformation in dump_file so that we can verify in tests that
the direct transformation actually happened.

gcc/ChangeLog:

* gimple-fold.c (dump_transformation): New function.
(gimple_fold_builtin_stxcpy_chk,
gimple_fold_builtin_stxncpy_chk): Use it.  Simplify to
BUILT_IN_STRNCPY if return value is not used.

gcc/testsuite/ChangeLog:

* gcc.dg/fold-stringops-1.c: New test.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
2 years agoCheck optab before transforming atomic bit test and operations
H.J. Lu [Fri, 12 Nov 2021 15:21:43 +0000 (07:21 -0800)] 
Check optab before transforming atomic bit test and operations

Check optab before transforming equivalent, but slighly different cases
of atomic bit test and operations to their canonical forms.

gcc/

PR middle-end/103184
* tree-ssa-ccp.c (optimize_atomic_bit_test_and): Check optab
before transforming equivalent, but slighly different cases to
their canonical forms.

gcc/testsuite/

PR middle-end/103184
* gcc.dg/pr103184-1.c: New test.
* gcc.dg/pr103184-2.c: Likewise.

2 years agoIPA: Provide a mechanism to register static DTORs via cxa_atexit.
Iain Sandoe [Thu, 4 Nov 2021 09:37:14 +0000 (09:37 +0000)] 
IPA: Provide a mechanism to register static DTORs via cxa_atexit.

For at least one target (Darwin) the platform convention is to
register static destructors (i.e. __attribute__((destructor)))
with __cxa_atexit rather than placing them into a list that is
run by some other mechanism.

This patch provides a target hook that allows a target to opt
into this and handling for the process in ipa_cdtor_merge ().

When the mode is enabled (dtors_from_cxa_atexit is set) we:

 * Generate new CTORs to register static destructors with
   __cxa_atexit and add them to the existing list of CTORs;
   we then process the revised CTORs list.

 * We sort the DTORs into priority and then TU order, this
   means that they are registered in that order with
   __cxa_atexit () and therefore will be run in the reverse
   order.

 * Likewise, CTORs are sorted into priority and then TU order,
   which means that they will run in that order.

This matches the behavior of using init/fini (or
mod_init_func/mod_term_func) sections.

This also fixes a bug where Fortran needs a DTOR to be run to
close IO.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR fortran/102992

gcc/ChangeLog:

* config/darwin.h (TARGET_DTORS_FROM_CXA_ATEXIT): New.
* doc/tm.texi: Regenerated.
* doc/tm.texi.in: Add TARGET_DTORS_FROM_CXA_ATEXIT hook.
* ipa.c (cgraph_build_static_cdtor_1): Return the built
function decl.
(build_cxa_atexit_decl): New.
(build_dso_handle_decl): New.
(build_cxa_dtor_registrations): New.
(compare_cdtor_tu_order): New.
(build_cxa_atexit_fns): New.
(ipa_cdtor_merge): If dtors_from_cxa_atexit is set,
process the DTORs/CTORs accordingly.
(pass_ipa_cdtor_merge::gate): Also run if
dtors_from_cxa_atexit is set.
* target.def (dtors_from_cxa_atexit): New hook.

2 years agoconfigure, Darwin: Check ld64 support for -platform-version.
Iain Sandoe [Fri, 12 Nov 2021 17:03:09 +0000 (17:03 +0000)] 
configure, Darwin: Check ld64 support for -platform-version.

Newer versions of ld64 allow specifiying the OS target (e.g.
macos or ios) the version and the SDK version all in a single
command.  This checks the availability of the command for the
current toolchain.

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

* config.in: Regenerate.
* configure: Regenerate.
* configure.ac: Test ld64 for -platform-version support.

2 years agotestsuite, Darwin: In tsvc.h, use malloc for Darwin <= 9.
Iain Sandoe [Sat, 13 Nov 2021 11:58:09 +0000 (11:58 +0000)] 
testsuite, Darwin: In tsvc.h, use malloc for Darwin <= 9.

Earlier Darwin versions fdo not have posix_memalign() but the
malloc implementation is guaranteed to produce memory suitably
aligned for the largest vector type.

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

* gcc.dg/vect/tsvc/tsvc.h: Use malloc for Darwin 9 and
earlier.

2 years agoAda, Darwin : Use DSYMUTIL_FOR_TARGET in libgnat/gnarl builds.
Iain Sandoe [Fri, 12 Nov 2021 16:36:25 +0000 (16:36 +0000)] 
Ada, Darwin : Use DSYMUTIL_FOR_TARGET in libgnat/gnarl builds.

Most of the time we get away with using the dsymutil that is
installed with the latest Xcode, however for some cross-compilation
cases that does not work.

We now have the ability to specify the correct dsymutil to use for
the toolchain (--with-dsymutil=) and we should use that specified
tool for debug link.  Fixes cross-compilers from x86-64 to powerpc.

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

* gcc-interface/Makefile.in: Use DSYMUTIL_FOR_TARGET in
libgnat/libgnarl recipies.

2 years agolibstdc++: Unordered containers merge re-use hash code
François Dumont [Mon, 25 Oct 2021 13:59:35 +0000 (15:59 +0200)] 
libstdc++: Unordered containers merge re-use hash code

When merging 2 unordered containers with same hasher we can re-use the hash code from
the cache if any.

Also in the context of the merge operation on multi-container use previous insert iterator as a hint
for the next insert.

libstdc++-v3/ChangeLog:

* include/bits/hashtable_policy.h:
(_Hash_code_base<>::_M_hash_code(const _Hash&, const _Hash_node_value<_Value, true>&)): New.
(_Hash_code_base<>::_M_hash_code<_H2>(const _H2&, const _Hash_node_value<>&)): New.
* include/bits/hashtable.h (_Hashtable<>::_M_merge_unique): Use latter.
(_Hashtable<>::_M_merge_multi): Likewise.
* testsuite/23_containers/unordered_multiset/modifiers/merge.cc (test05): New test.
* testsuite/23_containers/unordered_set/modifiers/merge.cc (test04): New test.

2 years agoUse 'location_hash' for 'gcc/diagnostic-spec.h:nowarn_map'
Thomas Schwinge [Tue, 31 Aug 2021 21:35:15 +0000 (23:35 +0200)] 
Use 'location_hash' for 'gcc/diagnostic-spec.h:nowarn_map'

Instead of hard-coded '0'/'UINT_MAX', we now use the 'RESERVED_LOCATION_P'
values 'UNKNOWN_LOCATION'/'BUILTINS_LOCATION' as spare values for
'Empty'/'Deleted', and generally simplify the code.

gcc/
* diagnostic-spec.h (typedef xint_hash_t)
(typedef xint_hash_map_t): Replace with...
(typedef nowarn_map_t): ... this.
(nowarn_map): Adjust.
* diagnostic-spec.c (nowarn_map, suppress_warning_at): Likewise.

2 years agoUse 'location_hash' for 'seen_locations' in 'gcc/profile.c:branch_prob'
Thomas Schwinge [Tue, 31 Aug 2021 21:34:23 +0000 (23:34 +0200)] 
Use 'location_hash' for 'seen_locations' in 'gcc/profile.c:branch_prob'

Follow-up to commit 102fcf94e625a2016a65829c73a42bd6c2420376
"Fix GCOV CFG related issues": considering the current
'int_hash <location_t, 0, 2>', per 'libcpp/include/line-map.h':

      Actual     | Value                         | Meaning
      -----------+-------------------------------+-------------------------------
      0x00000000 | UNKNOWN_LOCATION (gcc/input.h)| Unknown/invalid location.
      -----------+-------------------------------+-------------------------------
      0x00000001 | BUILTINS_LOCATION             | The location for declarations
                 |   (gcc/input.h)               | in "<built-in>"
      -----------+-------------------------------+-------------------------------
      0x00000002 | RESERVED_LOCATION_COUNT       | The first location to be
                 | (also                         | handed out, and the
                 |  ordmap[0]->start_location)   | first line in ordmap 0

... this currently uses value '0' ('UNKNOWN_LOCATION') as spare values for
'Empty', and value '2' ('RESERVED_LOCATION_COUNT') as spare values for
'Deleted', which is questionable?

What actually does get put into 'seen_locations' is (mostly...)
restricted/gated by '!RESERVED_LOCATION_P' (which is true unless
'UNKNOWN_LOCATION' or 'BUILTINS_LOCATION'), thus we may simply use
'location_hash'.

gcc/
* profile.c (branch_prob): Use 'location_hash' for
'seen_locations'.

2 years agoDrop tree overflow in irange setter.
Aldy Hernandez [Sat, 13 Nov 2021 11:16:40 +0000 (12:16 +0100)] 
Drop tree overflow in irange setter.

Drop meaningless overflow that may creep into the IL.

gcc/ChangeLog:

PR tree-optimization/103207
* value-range.cc (irange::set): Drop overflow.

gcc/testsuite/ChangeLog:

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

2 years agoFortran: openmp: Add support for thread_limit clause on target
Tobias Burnus [Mon, 15 Nov 2021 14:44:11 +0000 (15:44 +0100)] 
Fortran: openmp: Add support for thread_limit clause on target

gcc/fortran/ChangeLog:

* openmp.c (OMP_TARGET_CLAUSES): Add thread_limit.
* trans-openmp.c (gfc_split_omp_clauses): Add thread_limit also to
teams.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/thread-limit-1.f90: New test.

2 years agotestsuite: Add testcase for already fixed PR [PR100469]
Jakub Jelinek [Mon, 15 Nov 2021 13:47:44 +0000 (14:47 +0100)] 
testsuite: Add testcase for already fixed PR [PR100469]

This bug introduced in r11-7448-gff92ede8d269375f800e1b347a48f4698874b4a3
has been fixed already by r12-1354-g2d2ed777b23ab6503027039e0adbfe1162f52b2f
aka PR100852 fix.

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

PR debug/100469
* g++.dg/opt/pr100469.C: New test.

2 years agox86: Add gcc.target/i386/pr103205-2.c
H.J. Lu [Mon, 15 Nov 2021 13:17:55 +0000 (05:17 -0800)] 
x86: Add gcc.target/i386/pr103205-2.c

PR target/103205
* gcc.target/i386/pr103205-2.c: New test.

2 years agolibffi: Update LOCAL_PATCHES
H.J. Lu [Mon, 15 Nov 2021 12:56:05 +0000 (04:56 -0800)] 
libffi: Update LOCAL_PATCHES

Add

commit a91f844ef449d0dd1cf2e0e47b0ade0d8a6304e1
Author: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Date:   Mon Nov 15 10:24:27 2021 +0100

    libffi: Use #define instead of .macro in  src/x86/win64.S [PR102874]

to LOCAL_PATCHES.

* LOCAL_PATCHES: Add commit a91f844ef44.

2 years agoopenmp: Add support for thread_limit clause on target
Jakub Jelinek [Mon, 15 Nov 2021 12:20:53 +0000 (13:20 +0100)] 
openmp: Add support for thread_limit clause on target

OpenMP 5.1 says that thread_limit clause can also appear on target,
and similarly to teams should affect the thread-limit-var ICV.
On combined target teams, the clause goes to both.

We actually passed thread_limit internally on target already before,
but only used it for gcn/ptx offloading to hint how many threads should be
created and for ptx didn't set thread_limit_var in that case.
Similarly for host fallback.
Also, I found that we weren't copying the args array that contains encoded
thread_limit and num_teams clause for target (etc.) for async target.

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

gcc/
* gimplify.c (optimize_target_teams): Only add OMP_CLAUSE_THREAD_LIMIT
to OMP_TARGET_CLAUSES if it isn't there already.
gcc/c-family/
* c-omp.c (c_omp_split_clauses) <case OMP_CLAUSE_THREAD_LIMIT>:
Duplicate to both OMP_TARGET and OMP_TEAMS.
gcc/c/
* c-parser.c (OMP_TARGET_CLAUSE_MASK): Add
PRAGMA_OMP_CLAUSE_THREAD_LIMIT.
gcc/cp/
* parser.c (OMP_TARGET_CLAUSE_MASK): Add
PRAGMA_OMP_CLAUSE_THREAD_LIMIT.
libgomp/
* task.c (gomp_create_target_task): Copy args array as well.
* target.c (gomp_target_fallback): Add args argument.
Set gomp_icv (true)->thread_limit_var if thread_limit is present.
(GOMP_target): Adjust gomp_target_fallback caller.
(GOMP_target_ext): Likewise.
(gomp_target_task_fn): Likewise.
* config/nvptx/team.c (gomp_nvptx_main): Set
gomp_global_icv.thread_limit_var.
* testsuite/libgomp.c-c++-common/thread-limit-1.c: New test.

2 years agoFix PHI ordering problems in the path solver.
Aldy Hernandez [Mon, 15 Nov 2021 08:56:56 +0000 (09:56 +0100)] 
Fix PHI ordering problems in the path solver.

After auditing the PHI range calculations, I'm not convinced we've
caught all the corner cases.  They haven't shown up in the wild (yet),
but better safe than sorry.

We shouldn't write anything to the cache or trigger additional
lookups while calculating a PHI, as this may cause ordering problems.
We should resolve the PHI with either the cache as it stands, or by
asking for ranges on entry to the path.  I've documented this.

There was one dubious case where we called fold_range in
ssa_range_in_phi, which mostly by luck wasn't triggering lookups,
because fold_range solves a PHI by calling range_on_edge, which is set
to pick up global ranges by default in path_range_query.  This is
fragile, so I've rewritten the call to explicitly use cached or global
ranges.

Also, the cache should be avoided in ssa_range_in_phi when the arg is
defined in the PHI's block, as not doing so could create an ordering
problem.  We have a similar check when calculating relations in PHIs.

Tested on x86-64 & ppc64le Linux.

gcc/ChangeLog:

* gimple-range-path.cc (path_range_query::internal_range_of_expr):
Remove useless code.
(path_range_query::ssa_defined_in_bb): New.
(path_range_query::ssa_range_in_phi): Avoid fold_range call that
could trigger additional lookups.
Do not use the cache for ARGs defined in this block.
(path_range_query::compute_ranges_in_block): Use ssa_defined_in_bb.
(path_range_query::maybe_register_phi_relation): Same.
(path_range_query::range_of_stmt): Adjust comment.
* gimple-range-path.h (ssa_defined_in_bb): New.

2 years agopath solver: Default to global range if nothing found.
Aldy Hernandez [Mon, 15 Nov 2021 08:56:48 +0000 (09:56 +0100)] 
path solver: Default to global range if nothing found.

This has been a long time coming, but we weren't able to make the
change because of some unrelated regressions.

Tested on x86-64 & ppc64le Linux.

gcc/ChangeLog:

* gimple-range-path.cc (path_range_query::internal_range_of_expr):
Default to global range if nothing found.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/pr31146-2.C: Add -fno-thread-jumps.

2 years agotree-optimization/103237 - avoid vectorizing unhandled double reductions
Richard Biener [Mon, 15 Nov 2021 10:37:56 +0000 (11:37 +0100)] 
tree-optimization/103237 - avoid vectorizing unhandled double reductions

Double reductions which have multiple LC PHIs in the inner loop
are not handled correctly during transformation since those PHIs
are not properly classified as reduction.  The following disables
vectorizing them.

2021-11-15  Richard Biener  <rguenther@suse.de>

PR tree-optimization/103237
* tree-vect-loop.c (vect_is_simple_reduction): Fail for
double reductions with multiple inner loop LC PHI nodes.

* gcc.dg/torture/pr103237.c: New testcase.

2 years agoPR target/103069: Relax cmpxchg loop for x86 target
Hongyu Wang [Fri, 12 Nov 2021 02:50:46 +0000 (10:50 +0800)] 
PR target/103069: Relax cmpxchg loop for x86 target

From the CPU's point of view, getting a cache line for writing is more
expensive than reading.  See Appendix A.2 Spinlock in:

https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/
xeon-lock-scaling-analysis-paper.pdf

The full compare and swap will grab the cache line exclusive and causes
excessive cache line bouncing.

The atomic_fetch_{or,xor,and,nand} builtins generates cmpxchg loop under
-march=x86-64 like:

movl v(%rip), %eax
.L2:
movl %eax, %ecx
movl %eax, %edx
orl $1, %ecx
lock cmpxchgl %ecx, v(%rip)
jne .L2
movl %edx, %eax
andl $1, %eax
ret

To relax above loop, GCC should first emit a normal load, check and jump to
.L2 if cmpxchgl may fail. Before jump to .L2, PAUSE should be inserted to
yield the CPU to another hyperthread and to save power, so the code is
like

.L84:
        movl    (%rdi), %ecx
        movl    %eax, %edx
        orl     %esi, %edx
        cmpl    %eax, %ecx
        jne     .L82
        lock cmpxchgl   %edx, (%rdi)
        jne     .L84
.L82:
        rep nop
        jmp     .L84

This patch adds corresponding atomic_fetch_op expanders to insert load/
compare and pause for all the atomic logic fetch builtins. Add flag
-mrelax-cmpxchg-loop to control whether to generate relaxed loop.

gcc/ChangeLog:

PR target/103069
* config/i386/i386-expand.c (ix86_expand_atomic_fetch_op_loop):
New expand function.
* config/i386/i386-options.c (ix86_target_string): Add
-mrelax-cmpxchg-loop flag.
(ix86_valid_target_attribute_inner_p): Likewise.
* config/i386/i386-protos.h (ix86_expand_atomic_fetch_op_loop):
New expand function prototype.
* config/i386/i386.opt: Add -mrelax-cmpxchg-loop.
* config/i386/sync.md (atomic_fetch_<logic><mode>): New expander
for SI,HI,QI modes.
(atomic_<logic>_fetch<mode>): Likewise.
(atomic_fetch_nand<mode>): Likewise.
(atomic_nand_fetch<mode>): Likewise.
(atomic_fetch_<logic><mode>): New expander for DI,TI modes.
(atomic_<logic>_fetch<mode>): Likewise.
(atomic_fetch_nand<mode>): Likewise.
(atomic_nand_fetch<mode>): Likewise.
* doc/invoke.texi: Document -mrelax-cmpxchg-loop.

gcc/testsuite/ChangeLog:

PR target/103069
* gcc.target/i386/pr103069-1.c: New test.
* gcc.target/i386/pr103069-2.c: Ditto.

2 years agotree-optimization/103219 - avoid ICE in unroll-and-jam
Richard Biener [Mon, 15 Nov 2021 10:07:55 +0000 (11:07 +0100)] 
tree-optimization/103219 - avoid ICE in unroll-and-jam

For no particularly good reason unroll-and-jam uses single_dom_exit
to determine the exit for the region it wants to run VN on.  That
happens to ICE because of the dominance restriction.  Use single_exit
instead.

2021-11-15  Richard Biener  <rguenther@suse.de>

PR tree-optimization/103219
* gimple-loop-jam.c (tree_loop_unroll_and_jam): Use single_exit
to determine the exit for the VN region.

* gcc.dg/torture/pr103219.c: New testcase.

2 years ago[tree-vectorizer.c] Merge pass_vectorize::execute with vectorize_loops and replace...
Prathamesh Kulkarni [Mon, 15 Nov 2021 10:07:36 +0000 (15:37 +0530)] 
[tree-vectorizer.c] Merge pass_vectorize::execute with vectorize_loops and replace occurences of cfun with function param.

gcc/ChangeLog:
* tree-ssa-loop.c (pass_vectorize): Move to tree-vectorizer.c.
(pass_data_vectorize): Likewise.
(make_pass_vectorize): Likewise.
* tree-vectorizer.c (vectorize_loops): Merge with
pass_vectorize::execute and replace cfun occurences with fun param.
(adjust_simduid_builtins): Add fun param, replace cfun occurences with
fun, and adjust callers approrpiately.
(note_simd_array_uses): Likewise.
(vect_loop_dist_alias_call): Likewise.
(set_uid_loop_bbs): Likewise.
(vect_transform_loops): Likewise.
(try_vectorize_loop_1): Likewise.
(try_vectorize_loop): Likewise.

2 years agolibffi: Use #define instead of .macro in src/x86/win64.S [PR102874]
Rainer Orth [Mon, 15 Nov 2021 09:24:27 +0000 (10:24 +0100)] 
libffi: Use #define instead of .macro in  src/x86/win64.S [PR102874]

The libffi 3.4.2 import badly broke Solaris/x86 bootstrap with the native
assembler:

Assembler:
        "/vol/gcc/src/hg/master/local/libffi/src/x86/win64.S", line 88 :
Illegal mnemonic
        Near line: ".macro epilogue"
        "/vol/gcc/src/hg/master/local/libffi/src/x86/win64.S", line 88 : Syntax
error
        Near line: ".macro epilogue"
        "/vol/gcc/src/hg/master/local/libffi/src/x86/win64.S", line 95 :
Illegal mnemonic
        Near line: ".endm"
        "/vol/gcc/src/hg/master/local/libffi/src/x86/win64.S", line 95 : Syntax
error
        Near line: ".endm"
        "/vol/gcc/src/hg/master/local/libffi/src/x86/win64.S", line 100 :
Illegal mnemonic
        Near line: " epilogue"
        "/vol/gcc/src/hg/master/local/libffi/src/x86/win64.S", line 100 :
Syntax error
        Near line: "epilogue"

Solaris as doesn't support .macro/.endm.

Fixed by using #define instead of the unportable .macro.

Tested on i386-pc-solaris2.11 and x86_64-pc-linux-gnu.

The bug has been reported upstream
(https://github.com/libffi/libffi/issues/665); a corresponding pull
request is also pending (https://github.com/libffi/libffi/pull/669).

2021-10-21  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

libffi:
PR libffi/102874
* src/x86/win64.S (epilogue): Use #define instead of .macro.

2 years agotestsuite: i386: Require dfp in gcc.target/i386/pr101346.c
Rainer Orth [Mon, 15 Nov 2021 09:00:14 +0000 (10:00 +0100)] 
testsuite: i386: Require dfp in gcc.target/i386/pr101346.c

gcc.target/i386/pr101346.c currently FAILs on Solaris/x86:

FAIL: gcc.target/i386/pr101346.c (test for excess errors)

Excess errors:
/vol/gcc/src/hg/master/local/gcc/testsuite/gcc.target/i386/pr101346.c:6:1:
error: decimal floating-point not supported for this target
/vol/gcc/src/hg/master/local/gcc/testsuite/gcc.target/i386/pr101346.c:7:6:
error: decimal floating-point not supported for this target
/vol/gcc/src/hg/master/local/gcc/testsuite/gcc.target/i386/pr101346.c:9:12:
warning: implicit declaration of function '__builtin_fabsd128'; did you
mean '__builtin_fabsf128'? [-Wimplicit-function-declaration]

Fixed by requiring dfp support.  Tested on i386-pc-solaris2.11 and
x86_64-pc-linux-gnu.

2021-10-20  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
* gcc.target/i386/pr101346.c: Require dfp support.

2 years agoi386: Fix up x86 atomic_bit_test* expanders for !TARGET_HIMODE_MATH [PR103205]
Jakub Jelinek [Mon, 15 Nov 2021 08:30:08 +0000 (09:30 +0100)] 
i386: Fix up x86 atomic_bit_test* expanders for !TARGET_HIMODE_MATH [PR103205]

With !TARGET_HIMODE_MATH, the OPTAB_DIRECT expand_simple_binop fail and so
we ICE.  We don't really care if they are done promoted in SImode instead.

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

PR target/103205
* config/i386/sync.md (atomic_bit_test_and_set<mode>,
atomic_bit_test_and_complement<mode>,
atomic_bit_test_and_reset<mode>): Use OPTAB_WIDEN instead of
OPTAB_DIRECT.

* gcc.target/i386/pr103205.c: New test.

2 years agolibgomp, nvptx: Honor OpenMP 5.1 num_teams lower bound
Jakub Jelinek [Mon, 15 Nov 2021 08:20:52 +0000 (09:20 +0100)] 
libgomp, nvptx: Honor OpenMP 5.1 num_teams lower bound

Here is a PTX implementation of what I was talking about, that for
num_teams_upper 0 or whenever num_teams_lower <= num_blocks, the current
implementation is fine but if the user explicitly asks for more
teams than we can provide in hardware, we need to stop assuming that
omp_get_team_num () is equal to the hw team id, but instead need to use some
team specific memory (it is .shared for PTX), or if none is
provided, array indexed by the hw team id and run some teams serially within
the same hw thread.

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

* config/nvptx/team.c (__gomp_team_num): Define as
__attribute__((shared)) var.
(gomp_nvptx_main): Initialize __gomp_team_num to 0.
* config/nvptx/target.c (__gomp_team_num): Declare as
extern __attribute__((shared)) var.
(GOMP_teams4): Use __gomp_team_num as the team number instead of
%ctaid.x.  If first, initialize it to %ctaid.x.  If num_teams_lower
is bigger than num_blocks, use num_teams_lower teams and arrange for
bumping of __gomp_team_num if !first and returning false once we run
out of teams.
* config/nvptx/teams.c (__gomp_team_num): Declare as
extern __attribute__((shared)) var.
(omp_get_team_num): Return __gomp_team_num value instead of %ctaid.x.

2 years agolibgomp: Add a testcase for omp_get_num_teams inside of target inside of host teams
Jakub Jelinek [Mon, 15 Nov 2021 07:54:52 +0000 (08:54 +0100)] 
libgomp: Add a testcase for omp_get_num_teams inside of target inside of host teams

This is https://github.com/OpenMP/spec/issues/3183
There is an agreement that we should return 1 team inside of target,
even if that target is inside of host teams.  We were doing that
when offloading and not during host fallback, r12-5151 should fix that
even for host fallback.

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

* testsuite/libgomp.c/teams-5.c: New test.

2 years agoc++: location of lambda object and conversion call
Jason Merrill [Mon, 15 Nov 2021 04:18:19 +0000 (23:18 -0500)] 
c++: location of lambda object and conversion call

Two things that had poor location info: we weren't giving the TARGET_EXPR
for a lambda object any location, and the call to a conversion function was
getting whatever input_location happened to be.

gcc/cp/ChangeLog:

* call.c (perform_implicit_conversion_flags): Use the location of
the argument.
* lambda.c (build_lambda_object): Set location on the TARGET_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-switch.C: Adjust expected location.

2 years agoc++: check constexpr constructor body
Jason Merrill [Sat, 13 Nov 2021 21:59:31 +0000 (16:59 -0500)] 
c++: check constexpr constructor body

The implicit constexpr patch revealed that our checks for constexpr
constructors that could possibly produce a constant value (which
otherwise are IFNDR) was failing to look at most of the function body.
Fixing that required some library tweaks.

gcc/cp/ChangeLog:

* constexpr.c (maybe_save_constexpr_fundef): Also check whether the
body of a constructor is potentially constant.

libstdc++-v3/ChangeLog:

* src/c++17/memory_resource.cc: Add missing constexpr.
* include/experimental/internet: Only mark copy constructor
as constexpr with __cpp_constexpr_dynamic_alloc.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/constexpr-89285-2.C: Expect error.
* g++.dg/cpp1y/constexpr-89285.C: Adjust error.

2 years agoc++: is_this_parameter and coroutines proxies
Jason Merrill [Sat, 13 Nov 2021 22:16:46 +0000 (17:16 -0500)] 
c++: is_this_parameter and coroutines proxies

Compiling coroutines/pr95736.C with the implicit constexpr patch broke
because is_this_parameter didn't recognize the coroutines proxy for 'this'.

gcc/cp/ChangeLog:

* semantics.c (is_this_parameter): Check DECL_HAS_VALUE_EXPR_P
instead of is_capture_proxy.

2 years agoc++: c++20 constexpr default ctor and array init
Jason Merrill [Fri, 12 Nov 2021 03:03:53 +0000 (22:03 -0500)] 
c++: c++20 constexpr default ctor and array init

The implicit constexpr patch revealed that marking the constructor in the
PR70690 testcase as constexpr made the bug reappear, because build_vec_init
assumed that a constexpr default constructor initialized the whole object,
so it was equivalent to value-initialization.  But this is no longer true in
C++20.

PR c++/70690

gcc/cp/ChangeLog:

* init.c (build_vec_init): Check default_init_uninitialized_part in
C++20.

gcc/testsuite/ChangeLog:

* g++.dg/init/array41a.C: New test.

2 years agoc++: don't do constexpr folding in unevaluated context
Jason Merrill [Fri, 5 Nov 2021 04:08:53 +0000 (00:08 -0400)] 
c++: don't do constexpr folding in unevaluated context

The implicit constexpr patch revealed that we were doing constant evaluation
of arbitrary expressions in unevaluated contexts, leading to failure when we
tried to evaluate e.g. a call to declval.  This is wrong more generally;
only manifestly-constant-evaluated expressions should be evaluated within
an unevaluated operand.

Making this change revealed a case we were failing to mark as manifestly
constant-evaluated.

gcc/cp/ChangeLog:

* constexpr.c (maybe_constant_value): Don't evaluate
in an unevaluated operand unless manifestly const-evaluated.
(fold_non_dependent_expr_template): Likewise.
* decl.c (compute_array_index_type_loc): This context is
manifestly constant-evaluated.

2 years agoc++: constexpr virtual and vbase thunk
Jason Merrill [Wed, 10 Nov 2021 21:42:04 +0000 (16:42 -0500)] 
c++: constexpr virtual and vbase thunk

C++20 allows virtual functions to be constexpr.  I don't think that calling
through a pointer to a vbase subobject is supposed to work in a constant
expression, since an object with virtual bases can't be constant, but the
call shouldn't ICE.

gcc/cp/ChangeLog:

* constexpr.c (cxx_eval_thunk_call): Error instead of ICE
on vbase thunk to constexpr function.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constexpr-virtual20.C: New test.

2 years agogcc.dg/uninit-pred-9_b.c: Correct last adjustment for cris-elf
Hans-Peter Nilsson [Mon, 15 Nov 2021 06:50:44 +0000 (07:50 +0100)] 
gcc.dg/uninit-pred-9_b.c: Correct last adjustment for cris-elf

The change at r12-4790 should have done the same change for
CRIS as was done for powerpc64*-*-*.  (Probably MMIX too but
that may have to wait until the next weekend.)

gcc/testsuite:
* gcc.dg/uninit-pred-9_b.c: Correct last adjustment, for CRIS.

2 years agoVAX: Implement the `-mlra' command-line option
Maciej W. Rozycki [Mon, 15 Nov 2021 03:14:31 +0000 (03:14 +0000)] 
VAX: Implement the `-mlra' command-line option

Add the the `-mlra' command-line option for the VAX target, with the
usual semantics of enabling Local Register Allocation, off by default.

LRA remains unstable with the VAX target, with numerous ICEs throughout
the testsuite and worse code produced overall where successful, however
the presence of a command line option to enable it makes it easier to
experiment with it as the compiler does not have to be rebuilt to flip
between the old reload and LRA.

gcc/
* config/vax/vax.c (vax_lra_p): New prototype and function.
(TARGET_LRA_P): Wire it.
* config/vax/vax.opt (mlra): New option.
* doc/invoke.texi (Option Summary, VAX Options): Document the
new option.

2 years agoDaily bump.
GCC Administrator [Mon, 15 Nov 2021 00:16:20 +0000 (00:16 +0000)] 
Daily bump.

2 years ago[Commmitted] Move some testcases to torture from tree-ssa
Andrew Pinski [Sun, 14 Nov 2021 23:54:32 +0000 (23:54 +0000)] 
[Commmitted] Move some testcases to torture from tree-ssa

While writing up some testcases, I noticed some newer testcases
just had "dg-do compile/run" on them with dg-options of either -O1
or -O2. Since it is always better to run them over all optimization
levels I put them in gcc.c-torture/compile or gcc.c-torture/execute.

Committed after testing to make sure the testcases pass.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr100278.c: Move to ...
* gcc.c-torture/compile/pr100278.c: Here.
Remove dg-do and dg-options.
* gcc.dg/tree-ssa/pr101189.c: Move to ...
* gcc.c-torture/compile/pr101189.c: Here.
Remove dg-do and dg-options.
* gcc.dg/tree-ssa/pr100453.c: Move to ...
* gcc.c-torture/execute/pr100453.c: Here.
Remove dg-do and dg-options.
* gcc.dg/tree-ssa/pr101335.c: Move to ...
* gcc.c-torture/execute/pr101335.c: Here
Remove dg-do and dg-options.

2 years agoTrack nondeterminism and interposable calls in ipa-modref
Jan Hubicka [Sun, 14 Nov 2021 23:10:06 +0000 (00:10 +0100)] 
Track nondeterminism and interposable calls in ipa-modref

Adds tracking of two new flags in ipa-modref: nondeterministic and
calls_interposable.  First is set when function does something that is not
guaranteed to be the same if run again (volatile memory access, volatile asm or
external function call).  Second is set if function calls something that
does not bind to current def.

nondeterministic enables ipa-modref to discover looping pure/const functions
and it now discovers 138 of them during cc1plus link (which about doubles
number of such functions detected late).  We however can do more

 1) We can extend FRE to eliminate redundant calls.
    I filled a PR103168 for that.
    A common case are inline functions that are not autodetected as ECF_CONST
    just becuase they do not bind to local def and can be easily handled.
    More tricky is to use modref summary to check what memory locations are
    read.
 2) DSE can eliminate redundant stores

The calls_interposable flag currently also improves tree-ssa-structalias
on functions that are not binds_to_current_def since reads_global_memory
is now not cleared by interposable functions.

gcc/ChangeLog:

* ipa-modref.h (struct modref_summary): Add nondeterministic
and calls_interposable flags.
* ipa-modref.c (modref_summary::modref_summary): Initialize new flags.
(modref_summary::useful_p): Check new flags.
(struct modref_summary_lto): Add nondeterministic and
calls_interposable flags.
(modref_summary_lto::modref_summary_lto): Initialize new flags.
(modref_summary_lto::useful_p): Check new flags.
(modref_summary::dump): Dump new flags.
(modref_summary_lto::dump): Dump new flags.
(ignore_nondeterminism_p): New function.
(merge_call_side_effects): Merge new flags.
(process_fnspec): Likewise.
(analyze_load): Volatile access is nondeterministic.
(analyze_store): Liekwise.
(analyze_stmt): Volatile ASM is nondeterministic.
(analyze_function): Clear new flags.
(modref_summaries::duplicate): Duplicate new flags.
(modref_summaries_lto::duplicate): Duplicate new flags.
(modref_write): Stream new flags.
(read_section): Stream new flags.
(propagate_unknown_call): Update new flags.
(modref_propagate_in_scc): Propagate new flags.
* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Check
calls_interposable.
* tree-ssa-structalias.c (determine_global_memory_access):
Likewise.

2 years agoVAX: Add the `setmemhi' instruction
Maciej W. Rozycki [Sun, 14 Nov 2021 21:01:51 +0000 (21:01 +0000)] 
VAX: Add the `setmemhi' instruction

The MOVC5 machine instruction has `memset' semantics if encoded with a
zero source length[1]:

"4. MOVC5 with a zero source length operand is the preferred way
    to fill a block of memory with the fill character."

Use that instruction to implement the `setmemhi' instruction then.  Use
the AP register in the register deferred mode for the source address to
yield the shortest possible encoding of the otherwise unused operand,
observing that the address is never dereferenced if the source length is
zero.

The use of this instruction yields steadily better performance, at least
with the Mariah VAX implementation, for a variable-length `memset' call
expanded inline as a single MOVC5 operation compared to an equivalent
libcall invocation:

Length:   1, time elapsed:  0.971789 (builtin),  2.847303 (libcall)
Length:   2, time elapsed:  0.907904 (builtin),  2.728259 (libcall)
Length:   3, time elapsed:  1.038311 (builtin),  2.917245 (libcall)
Length:   4, time elapsed:  0.775305 (builtin),  2.686088 (libcall)
Length:   7, time elapsed:  1.112331 (builtin),  2.992968 (libcall)
Length:   8, time elapsed:  0.856882 (builtin),  2.764885 (libcall)
Length:  15, time elapsed:  1.256086 (builtin),  3.096660 (libcall)
Length:  16, time elapsed:  1.001962 (builtin),  2.888131 (libcall)
Length:  31, time elapsed:  1.590456 (builtin),  3.774164 (libcall)
Length:  32, time elapsed:  1.288909 (builtin),  3.629622 (libcall)
Length:  63, time elapsed:  3.430285 (builtin),  5.269789 (libcall)
Length:  64, time elapsed:  3.265147 (builtin),  5.113156 (libcall)
Length: 127, time elapsed:  6.438772 (builtin),  8.268305 (libcall)
Length: 128, time elapsed:  6.268991 (builtin),  8.114557 (libcall)
Length: 255, time elapsed: 12.417338 (builtin), 14.259678 (libcall)

(times given in seconds per 1000000 `memset' invocations for the given
length made in a loop).  It is clear from these figures that hardware
does data coalescence for consecutive bytes rather than naively copying
them one by one, as for lengths that are powers of 2 the figures are
consistently lower than ones for their respective next lower lengths.

The use of MOVC5 also requires at least 4 bytes less in terms of machine
code as it avoids encoding the address of `memset' needed for the CALLS
instruction used to make a libcall, as well as extra PUSHL instructions
needed to pass arguments to the call as those can be encoded directly as
the respective operands of the MOVC5 instruction.

It is perhaps worth noting too that for constant lengths we prefer to
emit up to 5 individual MOVx instructions rather than a single MOVC5
instruction to clear memory and for consistency we copy this behavior
here for filling memory with another value too, even though there may be
a performance advantage with a string copy in comparison to a piecemeal
copy, e.g.:

Length:  40, time elapsed:  2.183192 (string),   2.638878 (piecemeal)

But this is something for another change as it will have to be carefully
evaluated.

[1] DEC STD 032-0 "VAX Architecture Standard", Digital Equipment
    Corporation, A-DS-EL-00032-00-0 Rev J, December 15, 1989, Section
    3.10 "Character-String Instructions", p. 3-163

gcc/
* config/vax/vax.h (SET_RATIO): New macro.
* config/vax/vax.md (UNSPEC_SETMEM_FILL): New constant.
(setmemhi): New expander.
(setmemhi1): New insn and splitter.
(*setmemhi1): New insn.

gcc/testsuite/
* gcc.target/vax/setmem.c: New test.

2 years agolibstdc++: [_GLIBCXX_DEBUG] Remove _Safe_container<>::_M_safe()
François Dumont [Fri, 12 Nov 2021 06:26:33 +0000 (07:26 +0100)] 
libstdc++: [_GLIBCXX_DEBUG] Remove _Safe_container<>::_M_safe()

_GLIBCXX_DEBUG container code cleanup to get rid of _Safe_container<>::_M_safe() and just
use _Safe:: calls which use normal inheritance. Also remove several usages of _M_base()
which can be most of the time ommitted and sometimes replace with explicit _Base::
calls.

libstdc++-v3/ChangeLog:

* include/debug/safe_container.h (_Safe_container<>::_M_safe): Remove.
* include/debug/deque (deque::operator=(initializer_list<>)): Replace
_M_base() call with _Base:: call.
(deque::operator[](size_type)): Likewise.
* include/debug/forward_list (forward_list(forward_list&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(forward_list::operator=(initializer_list<>)): Remove _M_base() calls.
(forward_list::splice_after, forward_list::merge): Likewise.
* include/debug/list (list(list&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(list::operator=(initializer_list<>)): Remove _M_base() calls.
(list::splice, list::merge): Likewise.
* include/debug/map.h (map(map&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(map::operator=(initializer_list<>)): Remove _M_base() calls.
* include/debug/multimap.h (multimap(multimap&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(multimap::operator=(initializer_list<>)): Remove _M_base() calls.
* include/debug/set.h (set(set&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(set::operator=(initializer_list<>)): Remove _M_base() calls.
* include/debug/multiset.h (multiset(multiset&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(multiset::operator=(initializer_list<>)): Remove _M_base() calls.
* include/debug/string (basic_string(basic_string&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(basic_string::operator=(initializer_list<>)): Remove _M_base() call.
(basic_string::operator=(const _CharT*), basic_string::operator=(_CharT)): Likewise.
(basic_string::operator[](size_type), basic_string::operator+=(const basic_string&)):
Likewise.
(basic_string::operator+=(const _Char*), basic_string::operator+=(_CharT)): Likewise.
* include/debug/unordered_map (unordered_map(unordered_map&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(unordered_map::operator=(initializer_list<>), unordered_map::merge):
Remove _M_base() calls.
(unordered_multimap(unordered_multimap&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(unordered_multimap::operator=(initializer_list<>), unordered_multimap::merge):
Remove _M_base() calls.
* include/debug/unordered_set (unordered_set(unordered_set&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(unordered_set::operator=(initializer_list<>), unordered_set::merge):
Remove _M_base() calls.
(unordered_multiset(unordered_multiset&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(unordered_multiset::operator=(initializer_list<>), unordered_multiset::merge):
Remove _M_base() calls.
* include/debug/vector (vector(vector&&, const allocator_type&)):
Remove _M_safe() and _M_base() calls.
(vector::operator=(initializer_list<>)): Remove _M_base() calls.
(vector::operator[](size_type)): Likewise.

2 years agoExtend modref to track kills
Jan Hubicka [Sun, 14 Nov 2021 17:49:15 +0000 (18:49 +0100)] 
Extend modref to track kills

This patch adds kill tracking to ipa-modref.  This is representd by array
of accesses to memory locations that are known to be overwritten by the
function.

gcc/ChangeLog:

2021-11-14  Jan Hubicka  <hubicka@ucw.cz>

* ipa-modref-tree.c (modref_access_node::update_for_kills): New
member function.
(modref_access_node::merge_for_kills): Likewise.
(modref_access_node::insert_kill): Likewise.
* ipa-modref-tree.h (modref_access_node::update_for_kills,
modref_access_node::merge_for_kills, modref_access_node::insert_kill):
Declare.
(modref_access_node::useful_for_kill): New member function.
* ipa-modref.c (modref_summary::useful_p): Release useless kills.
(lto_modref_summary): Add kills.
(modref_summary::dump): Dump kills.
(record_access): Add mdoref_access_node parameter.
(record_access_lto): Likewise.
(merge_call_side_effects): Merge kills.
(analyze_call): Add ALWAYS_EXECUTED param and pass it around.
(struct summary_ptrs): Add always_executed filed.
(analyze_load): Update.
(analyze_store): Update; record kills.
(analyze_stmt): Add always_executed; record kills in clobbers.
(analyze_function): Track always_executed.
(modref_summaries::duplicate): Duplicate kills.
(update_signature): Release kills.
* ipa-modref.h (struct modref_summary): Add kills.
* tree-ssa-alias.c (alias_stats): Add kill stats.
(dump_alias_stats): Dump kill stats.
(store_kills_ref_p): Break out from ...
(stmt_kills_ref_p): Use it; handle modref info based kills.

gcc/testsuite/ChangeLog:

2021-11-14  Jan Hubicka  <hubicka@ucw.cz>

* gcc.dg/tree-ssa/modref-dse-3.c: New test.

2 years agoRemove gcc.dg/pr103229.c
Aldy Hernandez [Sun, 14 Nov 2021 15:17:36 +0000 (16:17 +0100)] 
Remove gcc.dg/pr103229.c

gcc/testsuite/ChangeLog:

* gcc.dg/pr103229.c: Removed.

2 years agoDo not pass NULL to memset in ssa_global_cache.
Aldy Hernandez [Sun, 14 Nov 2021 10:27:32 +0000 (11:27 +0100)] 
Do not pass NULL to memset in ssa_global_cache.

The code computing ranges in PHIs in the path solver reuses the
temporary ssa_global_cache by calling its clear method.  Calling it on
an empty cache causes us to call memset with NULL.

Tested on x86-64 Linux.

gcc/ChangeLog:

PR tree-optimization/103229
* gimple-range-cache.cc (ssa_global_cache::clear): Do not pass
null value to memset.

gcc/testsuite/ChangeLog:

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

2 years agotsan: remove not needed -ldl in options
Martin Liska [Sun, 14 Nov 2021 12:54:32 +0000 (13:54 +0100)] 
tsan: remove not needed -ldl in options

gcc/testsuite/ChangeLog:

* c-c++-common/tsan/free_race.c: Remove unnecessary -ldl.
* c-c++-common/tsan/free_race2.c: Likewise.

2 years agoCleanup tree-ssa-alias and tree-ssa-dse use of modref summary
Jan Hubicka [Sun, 14 Nov 2021 11:01:41 +0000 (12:01 +0100)] 
Cleanup tree-ssa-alias and tree-ssa-dse use of modref summary

Move code getting tree op from access_node and stmt to a common place.  I also
commonized logic to build ao_ref. While I was on it I also replaced FOR_EACH_*
by range for since they reads better.

gcc/ChangeLog:

2021-11-14  Jan Hubicka  <hubicka@ucw.cz>

* ipa-modref-tree.c (modref_access_node::get_call_arg): New member
function.
(modref_access_node::get_ao_ref): Likewise.
* ipa-modref-tree.h (modref_access_node::get_call_arg): Declare.
(modref_access_node::get_ao_ref): Declare.
* tree-ssa-alias.c (modref_may_conflict): Use new accessors.
* tree-ssa-dse.c (dse_optimize_call): Use new accessors.

gcc/testsuite/ChangeLog:

2021-11-14  Jan Hubicka  <hubicka@ucw.cz>

* c-c++-common/asan/null-deref-1.c: Update template.
* c-c++-common/tsan/free_race.c: Update template.
* c-c++-common/tsan/free_race2.c: Update template.
* gcc.dg/ipa/ipa-sra-4.c: Update template.

2 years agoDaily bump.
GCC Administrator [Sun, 14 Nov 2021 00:16:23 +0000 (00:16 +0000)] 
Daily bump.

2 years agoFix bug in ipa-pure-const and add debug counters
Jan Hubicka [Sat, 13 Nov 2021 23:48:32 +0000 (00:48 +0100)] 
Fix bug in ipa-pure-const and add debug counters

gcc/ChangeLog:

PR lto/103211
* dbgcnt.def (ipa_attr): New counters.
* ipa-pure-const.c: Include dbgcnt.c
(ipa_make_function_const): Use debug counter.
(ipa_make_function_pure): Likewise.
(propagate_pure_const): Fix bug in my previous change.

2 years agoMore ipa-modref-tree.h cleanups
Jan Hubicka [Sat, 13 Nov 2021 22:18:38 +0000 (23:18 +0100)] 
More ipa-modref-tree.h cleanups

Move access dumping to member function and cleanup formating.

gcc/ChangeLog:

2021-11-13  Jan Hubicka  <hubicka@ucw.cz>

* ipa-modref-tree.c (modref_access_node::range_info_useful_p):
Offline from ipa-modref-tree.h.
(modref_access_node::dump): Move from ipa-modref.c; make member
function.
* ipa-modref-tree.h (modref_access_node::range_info_useful_p.
modref_access_node::dump): Declare.
* ipa-modref.c (dump_access): Remove.
(dump_records): Update.
(dump_lto_records): Update.
(record_access): Update.
(record_access_lto): Update.

2 years agoImplement DSE of dead functions calls storing memory.
Jan Hubicka [Sat, 13 Nov 2021 21:25:23 +0000 (22:25 +0100)] 
Implement DSE of dead functions calls storing memory.

gcc/ChangeLog:

2021-11-13  Jan Hubicka  <hubicka@ucw.cz>

* ipa-modref.c (modref_summary::modref_summary): Clear new flags.
(modref_summary::dump): Dump try_dse.
(modref_summary::finalize): Add FUN attribute; compute try-dse.
(analyze_function): Update.
(read_section): Update.
(update_signature): Update.
(pass_ipa_modref::execute): Update.
* ipa-modref.h (struct modref_summary):
* tree-ssa-alias.c (ao_ref_init_from_ptr_and_range): Export.
* tree-ssa-alias.h (ao_ref_init_from_ptr_and_range): Declare.
* tree-ssa-dse.c (dse_optimize_call): New function.
(dse_optimize_stmt): Use it.

gcc/testsuite/ChangeLog:

2021-11-13  Jan Hubicka  <hubicka@ucw.cz>

* g++.dg/cpp1z/inh-ctor23.C: Fix template
* g++.dg/ipa/ipa-icf-4.C: Fix template
* gcc.dg/tree-ssa/modref-dse-1.c: New test.
* gcc.dg/tree-ssa/modref-dse-2.c: New test.

2 years agoFix checking disabled build.
Jan Hubicka [Sat, 13 Nov 2021 19:43:55 +0000 (20:43 +0100)] 
Fix checking disabled build.

gcc/ChangeLog:

2021-11-13  Jan Hubicka  <hubicka@ucw.cz>

* ipa-modref-tree.c: Move #if CHECKING_P to proper place.

2 years agofixincludes: simplify handling for access() failure [PR21283, PR80047]
Xi Ruoyao [Tue, 9 Nov 2021 13:40:04 +0000 (21:40 +0800)] 
fixincludes: simplify handling for access() failure [PR21283, PR80047]

POSIX says:

    On some implementations, if buf is a null pointer, getcwd() may obtain
    size bytes of memory using malloc(). In this case, the pointer returned
    by getcwd() may be used as the argument in a subsequent call to free().
    Invoking getcwd() with buf as a null pointer is not recommended in
    conforming applications.

This produces an error building GCC with --enable-werror-always:

    ../../../fixincludes/fixincl.c: In function ‘process’:
    ../../../fixincludes/fixincl.c:1356:7: error: argument 1 is null but
    the corresponding size argument 2 value is 4096 [-Werror=nonnull]

It's suggested by POSIX to call getcwd() with progressively larger
buffers until it does not give an [ERANGE] error. However, it's highly
unlikely that this error-handling route is ever used.

So we can simplify it instead of writting too much code.  We give up to
use getcwd(), because `make` will output a `Leaving directory ...` message
containing the path to cwd when we call abort().

fixincludes/ChangeLog:

PR other/21823
PR bootstrap/80047
* fixincl.c (process): Simplify the handling for highly
  unlikely access() failure, to avoid using non-standard
  extensions.

2 years agomodref_access_node cleanup
Jan Hubicka [Sat, 13 Nov 2021 17:27:18 +0000 (18:27 +0100)] 
modref_access_node cleanup

move member functions of modref_access_node from ipa-modref-tree.h to
ipa-modref-tree.c since they become long and not fitting for inlines anyway.  I
also cleaned up the interface by making static insert method (which handles
inserting accesses into a vector and optimizing them) which makes it possible
to hide most of the interface handling interval merging private.

Honza

gcc/ChangeLog:

* ipa-modref-tree.h
(struct modref_access_node): Move longer member functions to
ipa-modref-tree.c
(modref_ref_node::try_merge_with): Turn into modreef_acces_node member
function.
* ipa-modref-tree.c (modref_access_node::contains): Move here
from ipa-modref-tree.h.
(modref_access_node::update): Likewise.
(modref_access_node::merge): Likewise.
(modref_access_node::closer_pair_p): Likewise.
(modref_access_node::forced_merge): Likewise.
(modref_access_node::update2): Likewise.
(modref_access_node::combined_offsets): Likewise.
(modref_access_node::try_merge_with): Likewise.
(modref_access_node::insert): Likewise.

2 years agoAdd finalize method to modref summary.
Jan Hubicka [Sat, 13 Nov 2021 17:21:12 +0000 (18:21 +0100)] 
Add finalize method to modref summary.

gcc/ChangeLog:

* ipa-modref.c (modref_summary::global_memory_read_p): Remove.
(modref_summary::global_memory_written_p): Remove.
(modref_summary::dump): Dump new flags.
(modref_summary::finalize): New member function.
(analyze_function): Call it.
(read_section): Call it.
(update_signature): Call it.
(pass_ipa_modref::execute): Call it.
* ipa-modref.h (struct modref_summary): Remove
global_memory_read_p and global_memory_written_p.
Add global_memory_read, global_memory_written.
* tree-ssa-structalias.c (determine_global_memory_access):
Update.

2 years agoWhitelity type attributes for function signature change
Jan Hubicka [Sat, 13 Nov 2021 14:46:57 +0000 (15:46 +0100)] 
Whitelity type attributes for function signature change

gcc/ChangeLog:

* ipa-fnsummary.c (compute_fn_summary): Use type_attribut_allowed_p
* ipa-param-manipulation.c
(ipa_param_adjustments::type_attribute_allowed_p):
New member function.
(drop_type_attribute_if_params_changed_p): New function.
(build_adjusted_function_type): Use it.
* ipa-param-manipulation.h: Add type_attribute_allowed_p.

2 years agoanalyzer: add four new taint-based warnings
David Malcolm [Wed, 26 May 2021 19:47:23 +0000 (15:47 -0400)] 
analyzer: add four new taint-based warnings

The initial commit of the analyzer in GCC 10 had a single warning,
  -Wanalyzer-tainted-array-index
and required manually enabling the taint checker with
-fanalyzer-checker=taint (due to scaling issues).

This patch extends the taint detection to add four new taint-based
warnings:

  -Wanalyzer-tainted-allocation-size
     for e.g. attacker-controlled malloc/alloca
  -Wanalyzer-tainted-divisor
     for detecting where an attacker can inject a divide-by-zero
  -Wanalyzer-tainted-offset
     for attacker-controlled pointer offsets
  -Wanalyzer-tainted-size
     for e.g. attacker-controlled memset

and rewords all the warnings to talk about "attacker-controlled" values
rather than "tainted" values.

Unfortunately I haven't yet addressed the scaling issues, so all of
these still require -fanalyzer-checker=taint (in addition to -fanalyzer).

gcc/analyzer/ChangeLog:
* analyzer.opt (Wanalyzer-tainted-allocation-size): New.
(Wanalyzer-tainted-divisor): New.
(Wanalyzer-tainted-offset): New.
(Wanalyzer-tainted-size): New.
* engine.cc (impl_region_model_context::get_taint_map): New.
* exploded-graph.h (impl_region_model_context::get_taint_map):
New decl.
* program-state.cc (sm_state_map::get_state): Call
alt_get_inherited_state.
(sm_state_map::impl_set_state): Modify states within
compound svalues.
(program_state::impl_call_analyzer_dump_state): Undo casts.
(selftest::test_program_state_1): Update for new context param of
create_region_for_heap_alloc.
(selftest::test_program_state_merging): Likewise.
* region-model-impl-calls.cc (region_model::impl_call_alloca):
Likewise.
(region_model::impl_call_calloc): Likewise.
(region_model::impl_call_malloc): Likewise.
(region_model::impl_call_operator_new): Likewise.
(region_model::impl_call_realloc): Likewise.
* region-model.cc (region_model::check_region_access): Call
check_region_for_taint.
(region_model::get_representative_path_var_1): Handle binops.
(region_model::create_region_for_heap_alloc): Add "ctxt" param and
pass it to set_dynamic_extents.
(region_model::create_region_for_alloca): Likewise.
(region_model::set_dynamic_extents): Add "ctxt" param and use it
to call check_dynamic_size_for_taint.
(selftest::test_state_merging): Update for new context param of
create_region_for_heap_alloc.
(selftest::test_malloc_constraints): Likewise.
(selftest::test_malloc): Likewise.
(selftest::test_alloca): Likewise for create_region_for_alloca.
* region-model.h (region_model::create_region_for_heap_alloc): Add
"ctxt" param.
(region_model::create_region_for_alloca): Likewise.
(region_model::set_dynamic_extents): Likewise.
(region_model::check_dynamic_size_for_taint): New decl.
(region_model::check_region_for_taint): New decl.
(region_model_context::get_taint_map): New vfunc.
(noop_region_model_context::get_taint_map): New.
* sm-taint.cc: Remove include of "diagnostic-event-id.h"; add
includes of "gimple-iterator.h", "tristate.h", "selftest.h",
"ordered-hash-map.h", "cgraph.h", "cfg.h", "digraph.h",
"analyzer/supergraph.h", "analyzer/call-string.h",
"analyzer/program-point.h", "analyzer/store.h",
"analyzer/region-model.h", and "analyzer/program-state.h".
(enum bounds): Move to top of file.
(class taint_diagnostic): New.
(class tainted_array_index): Convert to subclass of taint_diagnostic.
(tainted_array_index::emit): Add CWE-129.  Reword warning to use
"attacker-controlled" rather than "tainted".
(tainted_array_index::describe_state_change): Move to
taint_diagnostic::describe_state_change.
(tainted_array_index::describe_final_event): Reword to use
"attacker-controlled" rather than "tainted".
(class tainted_offset): New.
(class tainted_size): New.
(class tainted_divisor): New.
(class tainted_allocation_size): New.
(taint_state_machine::alt_get_inherited_state): New.
(taint_state_machine::on_stmt): In assignment handling, remove
ARRAY_REF handling in favor of check_region_for_taint.  Add
detection of tainted divisors.
(taint_state_machine::get_taint): New.
(taint_state_machine::combine_states): New.
(region_model::check_region_for_taint): New.
(region_model::check_dynamic_size_for_taint): New.
* sm.h (state_machine::alt_get_inherited_state): New.

gcc/ChangeLog:
* doc/invoke.texi (Static Analyzer Options): Add
-Wno-analyzer-tainted-allocation-size,
-Wno-analyzer-tainted-divisor, -Wno-analyzer-tainted-offset, and
-Wno-analyzer-tainted-size to list.  Add
-Wanalyzer-tainted-allocation-size, -Wanalyzer-tainted-divisor,
-Wanalyzer-tainted-offset, and -Wanalyzer-tainted-size to list
of options effectively enabled by -fanalyzer.
(-Wanalyzer-tainted-allocation-size): New.
(-Wanalyzer-tainted-array-index): Tweak wording; add link to CWE.
(-Wanalyzer-tainted-divisor): New.
(-Wanalyzer-tainted-offset): New.
(-Wanalyzer-tainted-size): New.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/pr93382.c: Tweak expected wording.
* gcc.dg/analyzer/taint-alloc-1.c: New test.
* gcc.dg/analyzer/taint-alloc-2.c: New test.
* gcc.dg/analyzer/taint-divisor-1.c: New test.
* gcc.dg/analyzer/taint-1.c: Rename to...
* gcc.dg/analyzer/taint-read-index-1.c: ...this.  Tweak expected
wording.  Mark some events as xfail.
* gcc.dg/analyzer/taint-read-offset-1.c: New test.
* gcc.dg/analyzer/taint-size-1.c: New test.
* gcc.dg/analyzer/taint-write-index-1.c: New test.
* gcc.dg/analyzer/taint-write-offset-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoRemember fnspec based EAF flags in modref summary.
Jan Hubicka [Sat, 13 Nov 2021 14:20:00 +0000 (15:20 +0100)] 
Remember fnspec based EAF flags in modref summary.

gcc/ChangeLog:

* attr-fnspec.h (attr_fnspec::arg_eaf_flags): Break out from ...
* gimple.c (gimple_call_arg_flags): ... here.
* ipa-modref.c (analyze_parms): Record flags known from fnspec.
(modref_merge_call_site_flags): Use arg_eaf_flags.

2 years agopath solver: Compute all PHI ranges simultaneously.
Aldy Hernandez [Sat, 13 Nov 2021 11:37:25 +0000 (12:37 +0100)] 
path solver: Compute all PHI ranges simultaneously.

PHIs must be resolved simulatenously, otherwise we may not pick up the
ranges incoming to the block.

For example.  If we put p3_7 in the cache before all PHIs have been
computed, we will pick up the wrong p3_7 value for p2_17:

    # p3_7 = PHI <1(2), 0(5)>
    # p2_17 = PHI <1(2), p3_7(5)>

This patch delays updating the cache until all PHIs have been
analyzed.

gcc/ChangeLog:

PR tree-optimization/103222
* gimple-range-path.cc (path_range_query::compute_ranges_in_phis):
New.
(path_range_query::compute_ranges_in_block): Call
compute_ranges_in_phis.
* gimple-range-path.h (path_range_query::compute_ranges_in_phis):
New.

gcc/testsuite/ChangeLog:

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

2 years agolibsanitizer: Update LOCAL_PATCHES
H.J. Lu [Sat, 13 Nov 2021 13:17:14 +0000 (05:17 -0800)] 
libsanitizer: Update LOCAL_PATCHES

* LOCAL_PATCHES: Update to the corresponding revision.

2 years agolibsanitizer: Apply local patches
H.J. Lu [Tue, 20 Jul 2021 17:46:51 +0000 (10:46 -0700)] 
libsanitizer: Apply local patches

2 years agolibsanitizer: Merge with upstream
H.J. Lu [Sat, 13 Nov 2021 06:23:45 +0000 (22:23 -0800)] 
libsanitizer: Merge with upstream

Merged revision: 82bc6a094e85014f1891ef9407496f44af8fe442

with the fix for PR sanitizer/102911

2 years agolibstdc++: Implement std::spanstream for C++23
Jonathan Wakely [Fri, 12 Nov 2021 18:45:32 +0000 (18:45 +0000)] 
libstdc++: Implement std::spanstream for C++23

This implements the <spanstream> header, as proposed for C++23 by P0448R4.

libstdc++-v3/ChangeLog:

* include/Makefile.am: Add spanstream header.
* include/Makefile.in: Regenerate.
* include/precompiled/stdc++.h: Add spanstream header.
* include/std/version (__cpp_lib_spanstream): Define.
* include/std/spanstream: New file.
* testsuite/27_io/spanstream/1.cc: New test.
* testsuite/27_io/spanstream/version.cc: New test.

2 years agoEnable ipa-sra with fnspec attributes
Jan Hubicka [Sat, 13 Nov 2021 11:13:42 +0000 (12:13 +0100)] 
Enable ipa-sra with fnspec attributes

Enable some ipa-sra on fortran by allowing signature changes on functions
with "fn spec" attribute when ipa-modref is enabled.  This is possible since ipa-modref
knows how to preserve things we trace in fnspec and fnspec generated by fortran forntend
are quite simple and can be analysed automatically now.  To be sure I will also add
code that merge fnspec to parameters.

This unfortunately hits bug in ipa-param-manipulation when we remove parameter
that specifies size of variable length parameter. For this reason I added a hack
that prevent signature changes on such functions and will handle it incrementally.

I tried creating C testcase but it is blocked by another problem that we punt ipa-sra
on access attribute.  This is optimization regression we ought to fix so I filled
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103223.

As a followup I will add code classifying the type attributes (we have just few) and
get stats on access attribute.

gcc/ChangeLog:

* ipa-fnsummary.c (compute_fn_summary): Do not give up on signature
changes on "fn spec" attribute; give up on varadic types.
* ipa-param-manipulation.c: Include attribs.h.
(build_adjusted_function_type): New parameter ARG_MODIFIED; if it is
true remove "fn spec" attribute.
(ipa_param_adjustments::build_new_function_type): Update.
(ipa_param_body_adjustments::modify_formal_parameters): update.
* ipa-sra.c: Include attribs.h.
(ipa_sra_preliminary_function_checks): Do not check for TYPE_ATTRIBUTES.

2 years agopath solver: Merge path_range_query constructors.
Aldy Hernandez [Fri, 12 Nov 2021 08:06:55 +0000 (09:06 +0100)] 
path solver: Merge path_range_query constructors.

There's no need for two constructors, when we can do it all with one
that defaults to the common behavior:

path_range_query (bool resolve = true, gimple_ranger *ranger = NULL);

Tested on x86-64 Linux.

gcc/ChangeLog:

* gimple-range-path.cc (path_range_query::path_range_query): Merge
ctors.
(path_range_query::import_p): Move from header file.
(path_range_query::~path_range_query): Adjust for combined ctors.
* gimple-range-path.h: Merge ctors.
(path_range_query::import_p): Move to .cc file.