platform/upstream/gcc.git
18 months agoc++: Fix up handling of non-dependent subscript with static operator[] [PR108437]
Jakub Jelinek [Thu, 19 Jan 2023 22:31:15 +0000 (23:31 +0100)]
c++: Fix up handling of non-dependent subscript with static operator[] [PR108437]

As the following testcases shows, when adding static operator[]
support I've missed that the 2 build_min_non_dep_op_overload functions
need to be adjusted.  The first one we only use for the single index
case, but as cp_tree_code_length (ARRAY_REF) is 2, we were running
into an assertion there which compared nargs and expected_nargs.
For ARRAY_REF, the operator[] is either a non-static member or newly
static member, never out of class and for the static member case
if user uses single index the operator[] needs to have a single
argument as well, but the function is called with 2 - the object
it is invoked on and the index.  We need to evaluate side-effects
of the object and use just a single argument in the call - the index.
The other build_min_non_dep_op_overload overload has been added
solely for ARRAY_REF - CALL_EXPR is the other operator that accepts
variable number of operands but that one goes through different
routines.  There we asserted it is a METHOD_TYPE, so again
we shouldn't assert that but handle the case when it is not one
by making sure object's side-effects are evaluated if needed and
passing all the index arguments to the static operator[].

2023-01-19  Jakub Jelinek  <jakub@redhat.com>

PR c++/108437
* cp-tree.h (keep_unused_object_arg): Declare.
* call.cc (keep_unused_object_arg): No longer static.
* tree.cc (build_min_non_dep_op_overload): Handle ARRAY_REF
with overload being static member function.

* g++.dg/cpp23/subscript12.C: New test.
* g++.dg/cpp23/subscript13.C: New test.

18 months agoc++: Fix up handling of references to anon union members in initializers [PR53932]
Jakub Jelinek [Thu, 19 Jan 2023 22:27:34 +0000 (23:27 +0100)]
c++: Fix up handling of references to anon union members in initializers [PR53932]

For anonymous union members we create artificial VAR_DECLs which
have DECL_VALUE_EXPR for the actual COMPONENT_REF.  That works
just fine inside of functions (including global dynamic constructors),
because during gimplification such VAR_DECLs are gimplified as
their DECL_VALUE_EXPR.  This is also done during regimplification.

But references to these artificial vars in DECL_INITIAL expressions
aren't ever replaced by the DECL_VALUE_EXPRs, so we end up either
with link failures like on the testcase below, or worse ICEs with
LTO.

The following patch fixes those during cp_fully_fold_init where we
already walk all the trees (!data->genericize means that
function rather than cp_fold_function).

2023-01-19  Jakub Jelinek  <jakub@redhat.com>

PR c++/53932
* cp-gimplify.cc (cp_fold_r): During cp_fully_fold_init replace
DECL_ANON_UNION_VAR_P VAR_DECLs with their corresponding
DECL_VALUE_EXPR.

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

18 months agovalue-relation: Fix up relation_union [PR108447]
Jakub Jelinek [Thu, 19 Jan 2023 22:26:35 +0000 (23:26 +0100)]
value-relation: Fix up relation_union [PR108447]

While looking at the PR, I've noticed one row in rr_union_table
is wrong.  relation_union should be commutative, but due to that
bug is not.  The following patch adds a self-test for that
property (fails without the first hunk) and fixes that line.

The actual floating point relation problem isn't fixed by this patch
though.

2023-01-19  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/108447
* value-relation.cc (rr_union_table): Fix VREL_UNDEFINED row order.
(relation_tests): Add self-tests for relation_{intersect,union}
commutativity.
* selftest.h (relation_tests): Declare.
* function-tests.cc (test_ranges): Call it.

18 months agox86: Check invalid third argument to __builtin_ia32_prefetch
H.J. Lu [Wed, 18 Jan 2023 19:08:14 +0000 (11:08 -0800)]
x86: Check invalid third argument to __builtin_ia32_prefetch

Check invalid third argument to __builtin_ia32_prefetch when expaning
__builtin_ia32_prefetch to avoid ICE later.

gcc/

PR target/108436
* config/i386/i386-expand.cc (ix86_expand_builtin): Check
invalid third argument to __builtin_ia32_prefetch.

gcc/testsuite/

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

18 months agoopenmp: Fix up OpenMP expansion of non-rectangular loops [PR108459]
Jakub Jelinek [Thu, 19 Jan 2023 20:00:08 +0000 (21:00 +0100)]
openmp: Fix up OpenMP expansion of non-rectangular loops [PR108459]

expand_omp_for_init_counts was using for the case where collapse(2)
inner loop has init expression dependent on non-constant multiple of
the outer iterator and the condition upper bound expression doesn't
depend on the outer iterator fold_unary (NEGATE_EXPR, ...).  This
will just return NULL if it can't be folded, we need fold_build1
instead.

2023-01-19  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/108459
* omp-expand.cc (expand_omp_for_init_counts): Use fold_build1 rather
than fold_unary for NEGATE_EXPR.

* testsuite/libgomp.c/pr108459.c: New test.

18 months agoanalyzer: use dominator info in -Wanalyzer-deref-before-check [PR108455]
David Malcolm [Thu, 19 Jan 2023 18:51:16 +0000 (13:51 -0500)]
analyzer: use dominator info in -Wanalyzer-deref-before-check [PR108455]

My integration testing [1] of -fanalyzer in GCC 13 is showing a lot of
diagnostics from the new -Wanalyzer-deref-before-check warning on
real-world C projects, and most of these seem to be false positives.

This patch updates the warning to make it much less likely to fire:
- only intraprocedural cases are now reported
- reject cases in which there are control flow paths to the check
  that didn't come through the dereference, by looking at BB dominator
  information.  This fixes a false positive seen in git-2.39.0's
  pack-revindex.c: load_revindex_from_disk (PR analyzer/108455), in
  which a shared "cleanup:" section checks "data" for NULL, and
  depending on how much of the function is executed "data" might or
  might not have already been dereferenced.

The counts of -Wanalyzer-deref-before-check diagnostics in [1]
before/after this patch show this improvement:
  Known false positives:    6 ->  0  (-6)
  Known true positives:     1 ->  1
  Unclassified positives: 123 -> 63 (-60)

[1] https://github.com/davidmalcolm/gcc-analyzer-integration-tests

gcc/analyzer/ChangeLog:
PR analyzer/108455
* analyzer.h (class checker_event): New forward decl.
(class state_change_event): Indent.
(class warning_event): New forward decl.
* checker-event.cc (state_change_event::state_change_event): Add
"enode" param.
(warning_event::get_desc): Update for new param of
evdesc::final_event ctor.
* checker-event.h (state_change_event::state_change_event): Add
"enode" param.
(state_change_event::get_exploded_node): New accessor.
(state_change_event::m_enode): New field.
(warning_event::warning_event): New "enode" param.
(warning_event::get_exploded_node): New accessor.
(warning_event::m_enode): New field.
* diagnostic-manager.cc
(state_change_event_creator::on_global_state_change): Pass
src_node to state_change_event ctor.
(state_change_event_creator::on_state_change): Likewise.
(null_assignment_sm_context::set_next_state): Pass NULL for
new param of state_change_event ctor.
* infinite-recursion.cc
(infinite_recursion_diagnostic::add_final_event): Update for new
param of warning_event ctor.
* pending-diagnostic.cc (pending_diagnostic::add_final_event):
Pass enode to warning_event ctor.
* pending-diagnostic.h (evdesc::final_event): Add reference to
warning_event.
* sm-malloc.cc: Include "analyzer/checker-event.h" and
"analyzer/exploded-graph.h".
(deref_before_check::deref_before_check): Initialize new fields.
(deref_before_check::emit): Reject warnings in which we were
unable to determine the enodes of the dereference and the check.
Reject warnings interprocedural warnings. Reject warnings in which
the dereference doesn't dominate the check.
(deref_before_check::describe_state_change): Set m_deref_enode.
(deref_before_check::describe_final_event): Set m_check_enode.
(deref_before_check::m_deref_enode): New field.
(deref_before_check::m_check_enode): New field.

gcc/testsuite/ChangeLog:
PR analyzer/108455
* gcc.dg/analyzer/deref-before-check-1.c: Add test coverage
involving dominance.
* gcc.dg/analyzer/deref-before-check-pr108455-1.c: New test.
* gcc.dg/analyzer/deref-before-check-pr108455-git-pack-revindex.c:
New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
18 months agoFortran: error recovery for invalid CLASS component [PR108434]
Harald Anlauf [Wed, 18 Jan 2023 21:13:29 +0000 (22:13 +0100)]
Fortran: error recovery for invalid CLASS component [PR108434]

gcc/fortran/ChangeLog:

PR fortran/108434
* expr.cc (class_allocatable): Prevent NULL pointer dereference
or invalid read.
(class_pointer): Likewise.

gcc/testsuite/ChangeLog:

PR fortran/108434
* gfortran.dg/pr108434.f90: New test.

18 months agomodula-2, testsuite: Make libs and interfaces consistent.
Iain Sandoe [Sat, 14 Jan 2023 19:33:52 +0000 (19:33 +0000)]
modula-2, testsuite: Make libs and interfaces consistent.

In some case the libraries list was being set before gm2_init_xxx was
called.  In some cases it was omitted - this could lead to a difference
between the link libs and the interfaces (the effect of this would be
dependent on the order in which the .exps were run, which makes it also
depend on the -j and the system).

To avoid a mismatch between the module include paths and the added libs
we now make sure that they are both added in the gm_init_xxxx functions
(if finer control over granularity is needed, then we should as a TODO
add a generic gm_init_xxx that takes a library list and ensures that the
imports and libs are matched in the same order).

Also we cannot use a default variable in tcl if the source for that
variable could be absent, but something else follows, there is no way
to put an empty placeholder in.

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

* gm2/complex/run/pass/complex-run-pass.exp: Remove gm2_link_lib.
* gm2/iso/run/pass/iso-run-pass.exp: Likewise.
* gm2/link/externalscaffold/pass/link-externalscaffold-pass.exp:
* gm2/pimlib/logitech/run/pass/pimlib-logitech-run-pass.exp: Likewise.
* gm2/pimlib/run/pass/pimlib-run-pass.exp: Likewise.
* gm2/projects/iso/run/pass/halma/projects-iso-run-pass-halma.exp:
Likewise.
* gm2/projects/iso/run/pass/hello/projects-iso-run-pass-hello.exp:
Likewise.
* gm2/projects/pim/run/pass/hello/projects-pim-run-pass-hello.exp:
Likewise.
* gm2/sets/run/pass/sets-run-pass.exp: Likewise.
* gm2/switches/none/run/pass/gm2-none.exp: Likewise.
* gm2/switches/pic/run/pass/switches-pic-run-pass.exp: Likewise.
* gm2/projects/pim/run/pass/random/projects-pim-run-pass-random.exp:
Likewise, and also ensure that the -g option is appended to avoid it
being taken as a path.
* lib/gm2.exp: Ensure for each gm2_init_xxxx function that the set of
libraries added matches the set of -I and -L options.

18 months agoPR-108373 Update contrib/gcc_update:files_and_dependencies for Modula-2
Gaius Mulley [Thu, 19 Jan 2023 15:00:19 +0000 (15:00 +0000)]
PR-108373 Update contrib/gcc_update:files_and_dependencies for Modula-2

This patch adds the dependencies for automatically generated files used
by the Modula-2 front end.

contrib/ChangeLog:

* gcc_update (files_and_dependencies): Add dependencies for
gcc/m2/gm2config.h.in, gcc/m2/configure,
gcc/m2/gm2-libs/config-host, libgm2/Makefile.in,
libgm2/aclocal.m4, libgm2/libm2cor/Makefile.in,
libgm2/libm2pim/Makefile.in, libgm2/libm2iso/Makefile.in,
libgm2/libm2log/Makefile.in and libgm2/libm2min/Makefile.in.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
18 months agoaarch64: add -fno-stack-protector to some tests [PR108411]
Christophe Lyon [Tue, 17 Jan 2023 13:10:10 +0000 (13:10 +0000)]
aarch64: add -fno-stack-protector to some tests [PR108411]

As discussed in the PR, these recently added tests fail when the
testsuite is executed with -fstack-protector-strong.  To avoid this,
this patch adds -fno-stack-protector to dg-options.

PR target/108411
gcc/testsuite
* g++.target/aarch64/bitfield-abi-warning-align16-O2-extra.C: Add
-fno-stack-protector.
* g++.target/aarch64/bitfield-abi-warning-align16-O2.C: Likewise.
* g++.target/aarch64/bitfield-abi-warning-align32-O2-extra.C: Likewise.
* g++.target/aarch64/bitfield-abi-warning-align32-O2.C: Likewise.
* g++.target/aarch64/bitfield-abi-warning-align8-O2.C: Likewise.
* gcc.target/aarch64/bitfield-abi-warning-align16-O2-extra.c: Likewise.
* gcc.target/aarch64/bitfield-abi-warning-align16-O2.c: Likewise.
* gcc.target/aarch64/bitfield-abi-warning-align32-O2-extra.c: Likewise.
* gcc.target/aarch64/bitfield-abi-warning-align32-O2.c: Likewise.
* gcc.target/aarch64/bitfield-abi-warning-align8-O2.c: Likewise.

18 months agoaarch64: fix ICE in aarch64_layout_arg [PR108411]
Christophe Lyon [Mon, 16 Jan 2023 17:48:25 +0000 (17:48 +0000)]
aarch64: fix ICE in aarch64_layout_arg [PR108411]

The previous patch added an assert which should not be applied to PST
types (Pure Scalable Types) because alignment does not matter in this
case.  This patch moves the assert after the PST case is handled to
avoid the ICE.

PR target/108411
gcc/
* config/aarch64/aarch64.cc (aarch64_layout_arg): Improve
comment. Move assert about alignment a bit later.

18 months agomodula2/108144 - fix --enable-version-specific-runtime-libs
Richard Biener [Thu, 19 Jan 2023 11:15:14 +0000 (12:15 +0100)]
modula2/108144 - fix --enable-version-specific-runtime-libs

The following fixes --enable-version-specific-runtime-libs for
the modula2 target libraries.  The issue is that the install
happens via for example

toolexeclib_LTLIBRARIES = libm2cor.la

and toolexeclibdir is set to $(toolexecdir)/$(gcc_version)$(MULTISUBDIR)
but the Makefile.am do not define $(gcc_version) but instead
$(version) which is used locally to define libsubdir.  The fix
is to consistently define and use $(gcc_version), also properly
supporting --with-gcc-major-version-only

PR modula2/108144
libgm2/
* configure.ac: Add GCC_BASE_VER.
* configure: Re-generate.
* Makefile.am: Use @get_gcc_base_ver@ for gcc_version.
* libm2cor/Makefile.am: Likewise.  Use gcc_version instead
of version.
* libm2iso/Makefile.am: Likewise.
* libm2log/Makefile.am: Likewise.
* libm2min/Makefile.am: Likewise.
* libm2pim/Makefile.am: Likewise.
* Makefile.in: Re-generate.
* libm2cor/Makefile.in: Likewise.
* libm2iso/Makefile.in: Likewise.
* libm2log/Makefile.in: Likewise.
* libm2min/Makefile.in: Likewise.
* libm2pim/Makefile.in: Likewise.

18 months agoforwprop: Further fixes for simplify_rotate [PR108440]
Jakub Jelinek [Thu, 19 Jan 2023 09:00:51 +0000 (10:00 +0100)]
forwprop: Further fixes for simplify_rotate [PR108440]

As mentioned in the simplify_rotate comment, for e.g.
   ((T) ((T2) X << (Y & (B - 1)))) | ((T) ((T2) X >> ((-Y) & (B - 1))))
we already emit
   X r<< (Y & (B - 1))
as replacement.  This PR is about the
   ((T) ((T2) X << Y)) OP ((T) ((T2) X >> (B - Y)))
   ((T) ((T2) X << (int) Y)) OP ((T) ((T2) X >> (int) (B - Y)))
forms if T2 is wider than T.  Unlike e.g.
   (X << Y) OP (X >> (B - Y))
which is valid just for Y in [1, B - 1], the above 2 forms are actually
valid and do the rotates for Y in [0, B] - for Y 0 the X value is preserved
by the left shift and right logical shift by B adds just zeros (but because
the shift is in wider precision B is still valid shift count), while for
Y equal to B X is preserved through the latter shift and the former adds
just zeros.
Now, it is unclear if we in the middle-end treat rotates with rotate count
equal or larger than precision as UB or not, unlike shifts there are less
reasons to do so, but e.g. expansion of X r<< Y if there is no rotate optab
for the mode is emitted as (X << Y) | (((unsigned) X) >> ((-Y) & (B - 1)))
and so with UB on Y == B.

The following patch does multiple things:
1) for the above 2, asks the ranger if Y could be equal to B and if so,
   instead of using X r<< Y uses X r<< (Y & (B - 1))
2) for the
   ((T) ((T2) X << Y)) | ((T) ((T2) X >> ((-Y) & (B - 1))))
   ((T) ((T2) X << (int) Y)) | ((T) ((T2) X >> (int) ((-Y) & (B - 1))))
   forms that were fixed 2 days ago it only punts if Y might be in the
   [B,B2-1] range but isn't known to be in the
   [0,B][2*B,2*B][3*B,3*B]... range.  Because for Y which is a multiple
   of B but smaller than B2 it acts as a rotate too, left shift provides
   0 and (-Y) & (B - 1) is 0 and so preserves X.  Though, for the cases
   where Y is not known to be in [0,B-1] the patch also uses
   X r<< (Y & (B - 1)) rather than X r<< Y
3) as discussed with Aldy, instead of using global ranger it uses a pass
   specific copy but lazily created on first simplify_rotate that needs it;
   this e.g. handles rotate inside of if body where the guarding condition
   limits the shift count to some range which will not work with the
   global ranger (unless there is some SSA_NAME to attach the range to).

Note, e.g. on x86 X r<< (Y & (B - 1)) and X r<< Y actually emit the
same assembly because rotates work the same even for larger rotate counts,
but that is handled only during combine.

2023-01-19  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/108440
* tree-ssa-forwprop.cc: Include gimple-range.h.
(simplify_rotate): For the forms with T2 wider than T and shift counts of
Y and B - Y add & (B - 1) masking for the rotate count if Y could be equal
to B.  For the forms with T2 wider than T and shift counts of
Y and (-Y) & (B - 1), don't punt if range could be [B, B2], but only if
range doesn't guarantee Y < B or Y = N * B.  If range doesn't guarantee
Y < B, also add & (B - 1) masking for the rotate count.  Use lazily created
pass specific ranger instead of get_global_range_query.
(pass_forwprop::execute): Disable that ranger at the end of pass if it has
been created.

* c-c++-common/rotate-10.c: New test.
* c-c++-common/rotate-11.c: New test.

18 months ago[aarch64] Use exact_log2 (INTVAL (operands[2])) >= 0 to gate for vec_merge patterns.
Prathamesh Kulkarni [Thu, 19 Jan 2023 07:13:55 +0000 (12:43 +0530)]
[aarch64] Use exact_log2 (INTVAL (operands[2])) >= 0 to gate for vec_merge patterns.

gcc/ChangeLog:
* config/aarch64/aarch64-simd.md (aarch64_simd_vec_set<mode>): Use
exact_log2 (INTVAL (operands[2])) >= 0 as condition for gating
the pattern.
(aarch64_simd_vec_copy_lane<mode>): Likewise.
(aarch64_simd_vec_copy_lane_<vswap_width_name><mode>): Likewise.

18 months ago[PR106746] drop cselib addr lookup in debug insn mem
Alexandre Oliva [Thu, 19 Jan 2023 04:09:15 +0000 (01:09 -0300)]
[PR106746] drop cselib addr lookup in debug insn mem

The testcase used to get scheduled differently depending on the
presence of debug insns with MEMs.  It's not clear to me why those
MEMs affected scheduling, but the cselib pre-canonicalization of the
MEM address is not used at all when analyzing debug insns, so the
memory allocation and lookup are pure waste.  Somehow, avoiding that
waste fixes the problem, or makes it go latent.

for  gcc/ChangeLog

PR debug/106746
* sched-deps.cc (sched_analyze_2): Skip cselib address lookup
within debug insns.

for  gcc/testsuite/ChangeLog

PR debug/106746
* gcc.target/i386/pr106746.c: New.

18 months agoDaily bump.
GCC Administrator [Thu, 19 Jan 2023 00:17:35 +0000 (00:17 +0000)]
Daily bump.

18 months agolibfortran: Fix execute_command_line for Windows
Tobias Burnus [Wed, 18 Jan 2023 22:31:41 +0000 (23:31 +0100)]
libfortran: Fix execute_command_line for Windows

On Windows, 'system' is called - that fails with -1 if the command
interpreter could not be started; on POSIX systems, if the child
process could not be started by the shell, exit(127)/_exit(127) is
called/returned. On Windows, cmd.exe (and also the PowerShell) return
errorlevel 9009.

libgfortran/ChangeLog:

* intrinsics/execute_command_line.c (execute_command_line): On
Windows, regard system()'s return value of 9009 as EXEC_INVALIDCOMMAND.

18 months agoc: ICE with nullptr as case expression [PR108424]
Marek Polacek [Wed, 18 Jan 2023 19:51:59 +0000 (14:51 -0500)]
c: ICE with nullptr as case expression [PR108424]

In this ICE-on-invalid, we crash on

  gcc_assert (INTEGRAL_TYPE_P (type));

in perform_integral_promotions, because a nullptr is an INTEGER_CST,
but not INTEGRAL_TYPE_P, and check_case_value is only checking the
former.  In the test I'm testing other "shall be an integral constant
expression" contexts as well.

PR c/108424

gcc/c-family/ChangeLog:

* c-common.cc (check_case_value): Check INTEGRAL_TYPE_P.

gcc/testsuite/ChangeLog:

* gcc.dg/c2x-nullptr-6.c: New test.

18 months agolibstdc++: Deprecate std::filesystem::u8path for C++20
Jonathan Wakely [Wed, 18 Jan 2023 14:27:55 +0000 (14:27 +0000)]
libstdc++: Deprecate std::filesystem::u8path for C++20

P0482R6 deprecated these functions for C++20. There was a ballot comment
on the C++23 CD saying to un-deprecate it, but LEWG just rejected that,
so let's add attributes to deprecate them.

libstdc++-v3/ChangeLog:

* include/bits/fs_path.h (u8path): Add deprecated attribute.
* testsuite/27_io/filesystem/path/construct/90281.cc: Add
-Wno-deprecated-declarations for C++20 and later.
* testsuite/27_io/filesystem/path/factory/u8path-char8_t.cc:
Likewise.
* testsuite/27_io/filesystem/path/factory/u8path.cc: Likewise.
* testsuite/27_io/filesystem/path/native/string.cc: Likewise.
* testsuite/27_io/filesystem/path/factory/u8path-depr.cc: New test.

18 months agolibstdc++: Fix std::random_device::entropy() for non-posix targets
Jonathan Wakely [Wed, 18 Jan 2023 13:09:10 +0000 (13:09 +0000)]
libstdc++: Fix std::random_device::entropy() for non-posix targets

Since the r12-4515-g58f339fc5eaae7 change std::random_device::entropy()
returns non-zero for hardware sources such as RDRAND. However, the call
to the underlying _M_getentropy function is conditionally compiled
according to #if _GLIBCXX_USE_DEV_RANDOM which means it only happens for
targets that support /dev/random and /dev/urandom. This means entropy()
always returns zero for x86 Windows, even though the RDRAND and RDSEED
sources work there.

The _M_getentropy() function is always compiled into the library, it
just doesn't get called for targets without /dev/random. We can change
that just by removing the #if conditional. This is not an ABI change,
because new code will just start calling the existing _M_getentropy
function, old code that has inlined entropy() will not call it.

Similarly, the std::random_device destructor doesn't call the underlying
_M_fini function unless _GLIBCXX_USE_DEV_RANDOM is defined. That's less
of a problem because it's still true that the only resources that need
to be freed are when one of /dev/random or /dev/urandom has been opened
for reading, which is only possible when _GLIBCXX_USE_DEV_RANDOM is
defined. The _M_fini function does also destroy a random engine object
if a std::linear_congruential_engine object is used, but that destructor
is trivial and so no resources are leaked if it's not called. Remove the
preprocessor condition in the destructor too, so that we always call the
_M_fini function even if it doesn't have side effects. This makes the
destructor non-trivial for Windows and bare metal targets, but as the
class is non-copyable that shouldn't cause any ABI change in practice.

libstdc++-v3/ChangeLog:

* include/bits/random.h (random_device) [!_GLIBCXX_USE_DEV_RANDOM]:
Always call _M_fini and _M_getentropy.

18 months agolibstdc++: Minor updates to Policy Based Data Structures: Biblio
Gerald Pfeifer [Wed, 18 Jan 2023 18:59:26 +0000 (19:59 +0100)]
libstdc++: Minor updates to Policy Based Data Structures: Biblio

libstdc++-v3/ChangeLog:

2023-01-18  Gerald Pfeifer  <gerald@pfeifer.com>

* doc/xml/manual/policy_data_structures_biblio.xml: Adjust links
to www.open-std.org to use https.
(COM: Component Model Object Technologies): Rename from...
(The Component Object Model): ...to.
* doc/html/manual/policy_data_structures.html: Regenerate.

18 months agolibstdc++: testsuite: Simplify codecvt_unicode
Dimitrij Mijoski [Tue, 17 Jan 2023 21:12:12 +0000 (22:12 +0100)]
libstdc++: testsuite: Simplify codecvt_unicode

Stop using unique_ptr, create some objects directly.

libstdc++-v3/ChangeLog:

* testsuite/22_locale/codecvt/codecvt_unicode.cc: Simplify.
* testsuite/22_locale/codecvt/codecvt_unicode.h: Simplify.
* testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc: Simplify.

18 months agoanalyzer: add SARD testsuite 81
David Malcolm [Wed, 18 Jan 2023 16:41:47 +0000 (11:41 -0500)]
analyzer: add SARD testsuite 81

A 2013 paper [1] proposed 5 simple tests for evaluating the
effectiveness of static analysis tools at detecting
CWE-121 ("Stack-based Buffer Overflow").

The tests can be found in:
  https://samate.nist.gov/SARD/test-suites/81

This patch adds theses 5 tests to -fanalyzer's testsuite, lightly
modified to add DejaGnu directives.

This is for unit-testing; for broader testing of -fanalyzer I'm working
on a separate integration testing suite that builds various real-world C
projects with -fanalyzer, currently here:
  https://github.com/davidmalcolm/gcc-analyzer-integration-tests

[1] Black, P. , Koo, H. and Irish, T. (2013), A Basic CWE-121 Buffer Overflow Effectiveness Test Suite, Proc. 6th Latin-American Symposium on Dependable Computing, Rio de Janeiro, -1, [online], https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=913117 (Accessed January 17, 2023)

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/SARD-tc117-basic-00001-min.c: New test, adapted
from https://samate.nist.gov/SARD/test-suites/81.
* gcc.dg/analyzer/SARD-tc1909-stack_overflow_loop.c: Likewise.
* gcc.dg/analyzer/SARD-tc249-basic-00034-min.c: Likewise.
* gcc.dg/analyzer/SARD-tc293-basic-00045-min.c: Likewise.
* gcc.dg/analyzer/SARD-tc841-basic-00182-min.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
18 months agoipa: Release body more carefully when removing nodes (PR 107944)
Martin Jambor [Wed, 18 Jan 2023 14:29:54 +0000 (15:29 +0100)]
ipa: Release body more carefully when removing nodes (PR 107944)

The code removing function bodies when the last call graph clone of a
node is removed is too aggressive when there are nodes up the
clone_of chain which still need them.  Fixed by expanding the check.

gcc/ChangeLog:

2023-01-18  Martin Jambor  <mjambor@suse.cz>

PR ipa/107944
* cgraph.cc (cgraph_node::remove): Check whether nodes up the
lcone_of chain also do not need the body.

18 months agolto/108445 - avoid LTO decl wrapping being confused by tree sharing
Richard Biener [Wed, 18 Jan 2023 13:54:33 +0000 (14:54 +0100)]
lto/108445 - avoid LTO decl wrapping being confused by tree sharing

r13-4743 exposed more tree sharing which runs into a latent issue
with LTO decl wrapping during streaming.  The following adds a
testcase triggering the issue.

PR lto/108445
* gcc.dg/lto/pr108445_0.c: New testcase.
* gcc.dg/lto/pr108445_1.c: Likewise.

18 months agoRevert "middle-end/108086 - avoid unshare_expr when remapping SSA names"
Richard Biener [Wed, 18 Jan 2023 13:54:06 +0000 (14:54 +0100)]
Revert "middle-end/108086 - avoid unshare_expr when remapping SSA names"

This reverts commit da85bfc75024a92b97e60e4436863dd5789786ec.

18 months agolibgcc: Fix uninitialized RA signing on AArch64 [PR107678]
Wilco Dijkstra [Tue, 3 Jan 2023 15:57:46 +0000 (15:57 +0000)]
libgcc: Fix uninitialized RA signing on AArch64 [PR107678]

A recent change only initializes the regs.how[] during Dwarf unwinding
which resulted in an uninitialized offset used in return address signing
and random failures during unwinding.  The fix is to encode the return
address signing state in REG_UNSAVED and a new state REG_UNSAVED_ARCHEXT.

libgcc/
PR target/107678
* unwind-dw2.h (REG_UNSAVED_ARCHEXT): Add new enum.
* unwind-dw2.c (uw_update_context_1): Add REG_UNSAVED_ARCHEXT case.
* unwind-dw2-execute_cfa.h: Use REG_UNSAVED_ARCHEXT/REG_UNSAVED to
encode the return address signing state.
* config/aarch64/aarch64-unwind.h (aarch64_demangle_return_addr)
Check current return address signing state.
(aarch64_frob_update_contex): Remove.

18 months agoarm: fix __arm_vld1q_z* and __arm_vst1q_p* intrinsics [PR108442]
Murray Steele [Wed, 22 Dec 2021 15:55:58 +0000 (15:55 +0000)]
arm: fix __arm_vld1q_z* and __arm_vst1q_p* intrinsics [PR108442]

The MVE ACLE allows for __ARM_MVE_PRESERVE_USER_NAMESPACE to be defined,
which removes definitions for intrinsic functions without the __arm_
prefix. __arm_vld1q_z* and __arm_vst1q_p* are currently implemented via
calls to vldr* and vstr*, which results in several compile-time errors when
__ARM_MVE_PRESERVE_USER_NAMESPACE is defined. This patch replaces these
with calls to their prefixed counterparts, __arm_vldr* and __arm_str*,
and adds a test covering the definition of __ARM_MVE_PRESERVE_USER_NAMESPACE.

gcc/ChangeLog:

PR target/108442
* config/arm/arm_mve.h (__arm_vst1q_p_u8): Use prefixed intrinsic
function.
(__arm_vst1q_p_s8): Likewise.
(__arm_vld1q_z_u8): Likewise.
(__arm_vld1q_z_s8): Likewise.
(__arm_vst1q_p_u16): Likewise.
(__arm_vst1q_p_s16): Likewise.
(__arm_vld1q_z_u16): Likewise.
(__arm_vld1q_z_s16): Likewise.
(__arm_vst1q_p_u32): Likewise.
(__arm_vst1q_p_s32): Likewise.
(__arm_vld1q_z_u32): Likewise.
(__arm_vld1q_z_s32): Likewise.
(__arm_vld1q_z_f16): Likewise.
(__arm_vst1q_p_f16): Likewise.
(__arm_vld1q_z_f32): Likewise.
(__arm_vst1q_p_f32): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/arm/mve/general/preserve_user_namespace_1.c: New test.

18 months agoxtensa: Optimize inversion of the MSB
Takayuki 'January June' Suwa [Wed, 18 Jan 2023 05:43:13 +0000 (14:43 +0900)]
xtensa: Optimize inversion of the MSB

Such operation can be done either bitwise-XOR or addition with -2147483648,
but the latter is one byte less if TARGET_DENSITY.

gcc/ChangeLog:

* config/xtensa/xtensa.md (xorsi3_internal):
Rename from the original of "xorsi3".
(xorsi3): New expansion pattern that emits addition rather than
bitwise-XOR when the second source is a constant of -2147483648
if TARGET_DENSITY.

18 months agors6000: Fix typo on vec_vsubcuq in rs6000-overload.def [PR108396]
Kewen Lin [Wed, 18 Jan 2023 08:34:25 +0000 (02:34 -0600)]
rs6000: Fix typo on vec_vsubcuq in rs6000-overload.def [PR108396]

As Andrew pointed out in PR108396, there is one typo in
rs6000-overload.def on built-in function vec_vsubcuq:

  [VEC_VSUBCUQ, vec_vsubcuqP, __builtin_vec_vsubcuq]

"vec_vsubcuqP" should be "vec_vsubcuq", this typo caused
us to define vec_vsubcuqP in rs6000-vecdefines.h instead
of vec_vsubcuq, so that compiler is not able to realize
the built-in function name vec_vsubcuq any more.

Co-authored-By: Andrew Pinski <apinski@marvell.com>
PR target/108396

gcc/ChangeLog:

* config/rs6000/rs6000-overload.def (VEC_VSUBCUQ): Fix typo
vec_vsubcuqP with vec_vsubcuq.

gcc/testsuite/ChangeLog:

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

18 months agors6000: Teach rs6000_opaque_type_invalid_use_p about gcall [PR108348]
Kewen Lin [Wed, 18 Jan 2023 08:34:19 +0000 (02:34 -0600)]
rs6000: Teach rs6000_opaque_type_invalid_use_p about gcall [PR108348]

PR108348 shows one special case that MMA opaque types are
used in function arguments and treated as pass by reference,
it results in one copying from argument to a temp variable,
since this copying happens before rs6000_function_arg check,
it can cause ICE without MMA support then.  This patch is to
teach function rs6000_opaque_type_invalid_use_p to check if
any function argument in a gcall stmt has the invalid use of
MMA opaque types.

btw, I checked the handling on return value, it doesn't have
this kind of issue as its checking and error emission is quite
early, so this doesn't handle function return value.

PR target/108348

gcc/ChangeLog:

* config/rs6000/rs6000.cc (rs6000_opaque_type_invalid_use_p): Add the
support for invalid uses of MMA opaque type in function arguments.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr108348-1.c: New test.
* gcc.target/powerpc/pr108348-2.c: New test.

18 months agoDon't add crtfastmath.o for -shared.
liuhongt [Fri, 13 Jan 2023 08:19:47 +0000 (16:19 +0800)]
Don't add crtfastmath.o for -shared.

Patches [1] and [2] fixed PR55522 for x86-linux but left all other x86
targets unfixed (x86-cygwin, x86-darwin and x86-mingw32).
This patch applies a similar change to other specs using crtfastmath.o.

[1] https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608528.html
[2] https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608529.html

gcc/ChangeLog:

PR target/55522
* config/i386/cygwin.h (ENDFILE_SPEC): Link crtfastmath.o
whenever -mdaz-ftz is specified. Don't link crtfastmath.o when
-share or -mno-daz-ftz is specified.
* config/i386/darwin.h (ENDFILE_SPEC): Ditto.
* config/i386/mingw32.h (ENDFILE_SPEC): Ditto.

18 months agoFix bug number reference in Changelogs
Jerry DeLisle [Wed, 18 Jan 2023 01:30:49 +0000 (17:30 -0800)]
Fix bug number reference in Changelogs

18 months agoDaily bump.
GCC Administrator [Wed, 18 Jan 2023 00:17:21 +0000 (00:17 +0000)]
Daily bump.

18 months agoFortran: fix ICE in get_expr_storage_size [PR108421]
Harald Anlauf [Mon, 16 Jan 2023 20:30:56 +0000 (21:30 +0100)]
Fortran: fix ICE in get_expr_storage_size [PR108421]

gcc/fortran/ChangeLog:

PR fortran/108421
* interface.cc (get_expr_storage_size): Check that we actually have
an integer value before trying to extract it with mpz_get_si.

gcc/testsuite/ChangeLog:

PR fortran/108421
* gfortran.dg/pr108421.f90: New test.

18 months agogo: define two builtin functions used by middle-end
Ian Lance Taylor [Tue, 17 Jan 2023 17:02:49 +0000 (09:02 -0800)]
go: define two builtin functions used by middle-end

PR go/108426
* go-gcc.cc (Gcc_backend::Gcc_backend): Define __builtin_ctzl and
__builtin_clzl.  Patch by Andrew Pinski.

18 months agobpf: disable -fstack-protector in BPF
Jose E. Marchesi [Tue, 17 Jan 2023 16:16:32 +0000 (17:16 +0100)]
bpf: disable -fstack-protector in BPF

The stack protector is not supported in BPF.  This patch disables
-fstack-protector in bpf-* targets, along with the emission of a note
indicating that the feature is not supported in this platform.

Regtested in bpf-unknown-none.

gcc/ChangeLog:

* config/bpf/bpf.cc (bpf_option_override): Disable
-fstack-protector.

18 months agoObfuscate the copyright text in gcc/m2/mc/mcOptions.mod
Gaius Mulley [Tue, 17 Jan 2023 15:39:59 +0000 (15:39 +0000)]
Obfuscate the copyright text in gcc/m2/mc/mcOptions.mod

Obfuscate the copyright text in gcc/m2/mc/mcOptions.mod so that the
year change script does not attempt to modify the text.  The year
is determined at runtime and therefore the text requires
no modification.  The middle printf (C) can be replaced by
a unicode character in the future.

gcc/m2/ChangeLog:

* mc-boot/GM2RTS.c: Rebuilt.
* mc-boot/GM2RTS.h: Rebuilt.
* mc-boot/Gdecl.c: Rebuilt.
* mc-boot/GmcOptions.c: Rebuilt.
* mc/mcOptions.mod (displayVersion):
Split first printf into three components

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
18 months agolibstdc++: Fix configuration of default zoneinfo dir on linux
Jonathan Wakely [Tue, 17 Jan 2023 11:47:11 +0000 (11:47 +0000)]
libstdc++: Fix configuration of default zoneinfo dir on linux

The config for --with-libstdcxx-zoneinfo=yes was comparing the target
triplet to "gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu" which is only
the last component of the triplet, so failed to match and always used
the zoneinfo_dir=none default. Check $target_os instead.

There was also an error in the check for native builds that tzdata.zi is
actually present in the configured directory. That meant a warning was
printed even when the file was present:

configure: zoneinfo data directory: /usr/share/zoneinfo
configure: WARNING: "/usr/share/zoneinfo does not contain tzdata.zi file"
configure: static tzdata.zi file will be compiled into the library

libstdc++-v3/ChangeLog:

* acinclude.m4 (GLIBCXX_ZONEINFO_DIR): Check $target_os instead
of $host. Fix check for file being present during native build.
* configure: Regenerate.

18 months agoPR-108404 M2RTS_Halt fails with a segv
Gaius Mulley [Tue, 17 Jan 2023 13:27:42 +0000 (13:27 +0000)]
PR-108404 M2RTS_Halt fails with a segv

PR-108404 occurs because the C prototype does not match the Modula-2
procedure M2RTS_Halt.  This patch provides a new procedure M2RTS_HaltC
which avoids the C/C++ code from having to fabricate a Modula-2 string.

gcc/m2/ChangeLog:

* gm2-libs-iso/M2RTS.def (Halt): Parameter file renamed to filename.
(HaltC): New procedure declaration.
(ErrorMessage): Parameter file renamed to filename.
* gm2-libs-iso/M2RTS.mod (Halt): Parameter file renamed to
filename.
(HaltC): New procedure implementation.
(ErrorStringC): New procedure implementation.
(ErrorMessageC): New procedure implementation.
* gm2-libs/M2RTS.def (Halt): Parameter file renamed to filename.
(HaltC): New procedure declaration.
(ErrorMessage): Parameter file renamed to filename.
* gm2-libs/M2RTS.mod (Halt): Parameter file renamed to filename.
(HaltC): New procedure implementation.
(ErrorStringC): New procedure implementation.
(ErrorMessageC): New procedure implementation.

libgm2/ChangeLog:

* libm2iso/RTco.cc (_M2_RTco_fini): Call M2RTS_HaltC.
(newSem): Call M2RTS_HaltC.
(currentThread): Call M2RTS_HaltC.
(never): Call M2RTS_HaltC.
(defined): Call M2RTS_HaltC.
(initThread): Call M2RTS_HaltC.
(RTco_transfer): Call M2RTS_HaltC.
* libm2iso/m2rts.h (M2RTS_Halt): Provide parameter names.
(M2RTS_HaltC): New procedure declaration.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
18 months agoIgnore test_patches.txt in update-copyright.py.
Martin Liska [Tue, 17 Jan 2023 13:01:24 +0000 (14:01 +0100)]
Ignore test_patches.txt in update-copyright.py.

contrib/ChangeLog:

* update-copyright.py: Ignore test_patches.txt.

18 months agocontrib: revert removal of CR character
Martin Liska [Tue, 17 Jan 2023 11:55:43 +0000 (12:55 +0100)]
contrib: revert removal of CR character

contrib/ChangeLog:

* gcc-changelog/test_patches.txt: The CR character was removed
with ./contrib/update-copyright.py which I'm going to change.

18 months agoRegenerate Makefile.in files.
Martin Liska [Tue, 17 Jan 2023 11:19:37 +0000 (12:19 +0100)]
Regenerate Makefile.in files.

libbacktrace/ChangeLog:

* Makefile.in: Regenerate.

libgomp/ChangeLog:

* Makefile.in: Regenerate.
* configure: Regenerate.

libphobos/ChangeLog:

* Makefile.in: Regenerate.
* libdruntime/Makefile.in: Regenerate.

libstdc++-v3/ChangeLog:

* src/libbacktrace/Makefile.in: Regenerate.

18 months agoforwprop: Fix up rotate pattern matching [PR106523]
Jakub Jelinek [Tue, 17 Jan 2023 11:14:25 +0000 (12:14 +0100)]
forwprop: Fix up rotate pattern matching [PR106523]

The comment above simplify_rotate roughly describes what patterns
are matched into what:
   We are looking for X with unsigned type T with bitsize B, OP being
   +, | or ^, some type T2 wider than T.  For:
   (X << CNT1) OP (X >> CNT2)                           iff CNT1 + CNT2 == B
   ((T) ((T2) X << CNT1)) OP ((T) ((T2) X >> CNT2))     iff CNT1 + CNT2 == B

   transform these into:
   X r<< CNT1

   Or for:
   (X << Y) OP (X >> (B - Y))
   (X << (int) Y) OP (X >> (int) (B - Y))
   ((T) ((T2) X << Y)) OP ((T) ((T2) X >> (B - Y)))
   ((T) ((T2) X << (int) Y)) OP ((T) ((T2) X >> (int) (B - Y)))
   (X << Y) | (X >> ((-Y) & (B - 1)))
   (X << (int) Y) | (X >> (int) ((-Y) & (B - 1)))
   ((T) ((T2) X << Y)) | ((T) ((T2) X >> ((-Y) & (B - 1))))
   ((T) ((T2) X << (int) Y)) | ((T) ((T2) X >> (int) ((-Y) & (B - 1))))

   transform these into (last 2 only if ranger can prove Y < B):
   X r<< Y

   Or for:
   (X << (Y & (B - 1))) | (X >> ((-Y) & (B - 1)))
   (X << (int) (Y & (B - 1))) | (X >> (int) ((-Y) & (B - 1)))
   ((T) ((T2) X << (Y & (B - 1)))) | ((T) ((T2) X >> ((-Y) & (B - 1))))
   ((T) ((T2) X << (int) (Y & (B - 1)))) \
     | ((T) ((T2) X >> (int) ((-Y) & (B - 1))))

   transform these into:
   X r<< (Y & (B - 1))

The following testcase shows that 2 of these are problematic.
If T2 is wider than T, then the 2 which yse (-Y) & (B - 1) on one
of the shift counts but Y on the can do something different from
rotate.  E.g.:
__attribute__((noipa)) unsigned char
f7 (unsigned char x, unsigned int y)
{
  unsigned int t = x;
  return (t << y) | (t >> ((-y) & 7));
}
if y is [0, 7], then it is a normal rotate, and if y is in [32, ~0U]
then it is UB, but for y in [9, 31] the left shift in this case
will never leave any bits in the result, while in a rotate they are
left there.  Say for y 5 and x 0xaa the expression gives
0x55 which is the same thing as rotate, while for y 19 and x 0xaa
0x5, which is different.
Now, I believe the
   ((T) ((T2) X << Y)) OP ((T) ((T2) X >> (B - Y)))
   ((T) ((T2) X << (int) Y)) OP ((T) ((T2) X >> (int) (B - Y)))
forms are ok, because B - Y still needs to be a valid shift count,
and if Y > B then B - Y should be either negative or very large
positive (for unsigned types).
And similarly the last 2 cases above which use & (B - 1) on both
shift operands are definitely ok.

The following patch disables the
   ((T) ((T2) X << Y)) | ((T) ((T2) X >> ((-Y) & (B - 1))))
   ((T) ((T2) X << (int) Y)) | ((T) ((T2) X >> (int) ((-Y) & (B - 1))))
unless ranger says Y is not in [B, B2 - 1] range.

And, looking at it again this morning, actually the Y equal to B
case is still fine, if Y is equal to 0, then it is
(T) (((T2) X << 0) | ((T2) X >> 0))
and so X, for Y == B it is
(T) (((T2) X << B) | ((T2) X >> 0))
which is the same as
(T) (0 | ((T2) X >> 0))
which is also X.  So instead of the [B, B2 - 1] range we could use
[B + 1, B2 - 1].  And, if we wanted to go further, even multiplies
of B are ok if they are smaller than B2, so we could construct a detailed
int_range_max if we wanted.

2023-01-17  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/106523
* tree-ssa-forwprop.cc (simplify_rotate): For the
patterns with (-Y) & (B - 1) in one operand's shift
count and Y in another, if T2 has wider precision than T,
punt if Y could have a value in [B, B2 - 1] range.

* c-c++-common/rotate-2.c (f5, f6, f7, f8, f13, f14, f15, f16,
f37, f38, f39, f40, f45, f46, f47, f48): Add assertions using
__builtin_unreachable about shift count.
* c-c++-common/rotate-2b.c: New test.
* c-c++-common/rotate-4.c (f5, f6, f7, f8, f13, f14, f15, f16,
f37, f38, f39, f40, f45, f46, f47, f48): Add assertions using
__builtin_unreachable about shift count.
* c-c++-common/rotate-4b.c: New test.
* gcc.c-torture/execute/pr106523.c: New test.

18 months agolibsanitizer: Fix asan SEGVs with gld on Solaris
Rainer Orth [Tue, 17 Jan 2023 09:56:20 +0000 (10:56 +0100)]
libsanitizer: Fix asan SEGVs with gld on Solaris

When using GNU ld on Solaris, a large number of asan tests SEGV, while
Solaris ld is fine.  This happens inside the __tls_get_addr interceptor,
which is highly glibc-specific.  Therefore this patch disables that
interceptor.

Posted upstream at https://reviews.llvm.org/D141385.

Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11.

2023-01-17  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

libsanitizer:
* sanitizer_common/sanitizer_platform_interceptors.h: Cherry-pick
llvm-project revision 951cf656b2faaf6fc0baa867293c0cb0ab131951.

18 months agoDaily bump.
GCC Administrator [Tue, 17 Jan 2023 00:18:06 +0000 (00:18 +0000)]
Daily bump.

18 months agoRemove reference to Solaris 9 in comment of add_options_for_tls
Andrew Pinski [Mon, 16 Jan 2023 23:53:33 +0000 (23:53 +0000)]
Remove reference to Solaris 9 in comment of add_options_for_tls

Since r5-172-gd9f069ab4f6450, the code no longer matches the
comment as the code for Solaris 9 support was removed.
This just updates the comment to reference AIX only as
the code does.

Committed as obvious.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (add_options_for_tls): Remove
reference to Solaris 9 in comments.

18 months agoAdd cpplib ka.po
Joseph Myers [Mon, 16 Jan 2023 22:43:24 +0000 (22:43 +0000)]
Add cpplib ka.po

* ka.po: New.

18 months agox86: Disable -mforce-indirect-call for PIC in 32-bit mode
H.J. Lu [Mon, 16 Jan 2023 18:45:41 +0000 (10:45 -0800)]
x86: Disable -mforce-indirect-call for PIC in 32-bit mode

-mforce-indirect-call generates invalid instruction in 32-bit MI thunk
since there are no available scratch registers in 32-bit PIC mode.
Disable -mforce-indirect-call for PIC in 32-bit mode when generating
MI thunk.

gcc/

PR target/105980
* config/i386/i386.cc (x86_output_mi_thunk): Disable
-mforce-indirect-call for PIC in 32-bit mode.

gcc/testsuite/

PR target/105980
* g++.target/i386/pr105980.C: New test.

18 months agoRemove YEAR const from mcOptions.mod and use result from time
Gaius Mulley [Mon, 16 Jan 2023 18:45:52 +0000 (18:45 +0000)]
Remove YEAR const from mcOptions.mod and use result from time

This patch removes the hard coded constant YEAR and replaces
its use by a call to a new procedure function getYear.
It also emits a GPL v3 boilerplate.

gcc/m2/ChangeLog:

* mc-boot-ch/Glibc.c (libc_time): New function.
(libc_localtime): New function.
* mc-boot/GDynamicStrings.c: Regenerate.
* mc-boot/GFIO.c: Regenerate.
* mc-boot/GFormatStrings.c: Regenerate.
* mc-boot/GIndexing.c: Regenerate.
* mc-boot/GM2Dependent.c: Regenerate.
* mc-boot/GM2EXCEPTION.c: Regenerate.
* mc-boot/GPushBackInput.c: Regenerate.
* mc-boot/GRTExceptions.c: Regenerate.
* mc-boot/GRTint.c: Regenerate.
* mc-boot/GStdIO.c: Regenerate.
* mc-boot/GStringConvert.c: Regenerate.
* mc-boot/GSysStorage.c: Regenerate.
* mc-boot/Gdecl.c: Regenerate.
* mc-boot/GmcComment.c: Regenerate.
* mc-boot/GmcComp.c: Regenerate.
* mc-boot/GmcDebug.c: Regenerate.
* mc-boot/GmcMetaError.c: Regenerate.
* mc-boot/GmcOptions.c: Regenerate.
* mc-boot/GmcStack.c: Regenerate.
* mc-boot/GnameKey.c: Regenerate.
* mc-boot/GsymbolKey.c: Regenerate.
* mc-boot/Gkeyc.c: Regenerate.
* mc/decl.mod (putFieldRecord): Change NulName to NulKey
and fix type comparision.
* mc/mcOptions.mod (YEAR): Remove.
(getYear): New procedure function.
(displayVersion): Use result from getYear instead of YEAR.
Emit boilerplate for GPL v3.
(gplBody): Use result from getYear instead of YEAR.
(glplBody): Use result from getYear instead of YEAR.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
18 months agoDetect errors when dereferencing an undeclared variable.
Gaius Mulley [Mon, 16 Jan 2023 18:09:04 +0000 (18:09 +0000)]
Detect errors when dereferencing an undeclared variable.

Attempting to dereference an undeclared variable will cause an ICE.
Also attempting to pass an undeclared variable as an array of type
will also cause an ICE.  This patch detects both conditions and
generates an appropriate error.

gcc/m2/ChangeLog:

* gm2-compiler/M2Quads.mod (AssignUnboundedVar): Check Type
against NulSym and call MetaErrorT1 if necessary.
(AssignUnboundedNonVar): Check Type against NulSym and
call MetaErrorT1 if necessary.
(BuildDesignatorPointer): Check Type1 against NulSym and
call MetaErrorT1 if necessary.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
18 months agoFix wrong code issues with ipa-sra
Jan Hubicka [Mon, 16 Jan 2023 17:14:45 +0000 (18:14 +0100)]
Fix wrong code issues with ipa-sra

Fix wrong code issues in ipa-sra where we are trying to prove that on every
execution of a given function a call to other function will happen.  The code
uses post dominators and makes a wrong query (which passes only for first BB in
function). Hoever post-dominators are only valid if fake edges for every
possible reason for fuction execution to terminate are added.

Fixing this using postdominators is somewhat costy since one needs to walk
whole body and add a lot of fake edges. I ended up implementing a special
purpose function for this which is also useful in ipa-modref and other places
that does similar analysis.  One does not need to modify CFG to use it and
moreover for complex functions it usually stops on first unanalyzed function
call and ends up being relatively cheap.

Bootstrapped/regtested x86_64-linux, plan to commit it shortly.

gcc/ChangeLog:

2023-01-16  Jan Hubicka  <hubicka@ucw.cz>

PR ipa/106077
* ipa-modref.cc (modref_access_analysis::analyze): Use
find_always_executed_bbs.
* ipa-sra.cc (process_scan_results): Likewise.
* ipa-utils.cc (stmt_may_terminate_function_p): New function.
(find_always_executed_bbs): New function.
* ipa-utils.h (stmt_may_terminate_function_p): Declare.
(find_always_executed_bbs): Declare.

gcc/testsuite/ChangeLog:

2023-01-16  Jan Hubicka  <hubicka@ucw.cz>

* g++.dg/tree-ssa/pr106077.C: New test.

18 months agolibstdc++: Fix --with-default-libstdcxx-abi=gcc4-compatible build
Jonathan Wakely [Mon, 16 Jan 2023 15:52:20 +0000 (15:52 +0000)]
libstdc++: Fix --with-default-libstdcxx-abi=gcc4-compatible build

When building src/c++20/tzdb.cc we currently get a build error for
--with-default-libstdcxx-abi=gcc4-compatible because std::chrono::tzdb
and related types are not declared for the gcc4-compatible ABI (unless
--disable-libstdcxx-dual-abi is also used, so that the gcc4-compatible
ABI is the only one built).

Define _GLIBCXX_USE_CXX11_ABI in tzdb.cc so that for a dual-abi build we
always build it for the cxx11 ABI.

libstdc++-v3/ChangeLog:

* src/c++20/tzdb.cc (_GLIBCXX_USE_CXX11_ABI): Define to 1.

18 months agoada: Update copyright years.
Marc Poulhiès [Thu, 5 Jan 2023 10:38:43 +0000 (11:38 +0100)]
ada: Update copyright years.

gcc/ada/

* gcc-interface/Make-lang.in: Update copyright years.
* gcc-interface/Makefile.in: Likewise.
* gcc-interface/ada-builtin-types.def: Likewise.
* gcc-interface/ada-builtins.def: Likewise.
* gcc-interface/ada-tree.def: Likewise.
* gcc-interface/ada-tree.h: Likewise.
* gcc-interface/ada.h: Likewise.
* gcc-interface/config-lang.in: Likewise.
* gcc-interface/cuintp.cc: Likewise.
* gcc-interface/decl.cc: Likewise.
* gcc-interface/gadaint.h: Likewise.
* gcc-interface/gigi.h: Likewise.
* gcc-interface/lang-specs.h: Likewise.
* gcc-interface/lang.opt: Likewise.
* gcc-interface/misc.cc: Likewise.
* gcc-interface/system.ads: Likewise.
* gcc-interface/targtyps.cc: Likewise.
* gcc-interface/trans.cc: Likewise.
* gcc-interface/utils.cc: Likewise.
* gcc-interface/utils2.cc: Likewise.

18 months agoada: Fix typo in comment
Eric Botcazou [Fri, 13 Jan 2023 07:53:06 +0000 (08:53 +0100)]
ada: Fix typo in comment

gcc/ada/

* exp_ch3.adb (Make_Allocator_For_Return): Fix typo in comment.

18 months agoada: Fix latent bug exposed by recent work on extended return statements
Eric Botcazou [Thu, 12 Jan 2023 23:55:51 +0000 (00:55 +0100)]
ada: Fix latent bug exposed by recent work on extended return statements

When the type of the return object is a constrained array, there may be an
implicit sliding that needs to be preserved during the expansion.

gcc/ada/

* exp_ch3.adb (Make_Allocator_For_Return): Convert the expression
to the return object's type in the constrained array case as well.

18 months agoada: Fix pessimization of some CW objects initialized with function call
Eric Botcazou [Tue, 10 Jan 2023 15:09:44 +0000 (16:09 +0100)]
ada: Fix pessimization of some CW objects initialized with function call

The recent removal of the unconditional call to Remove_Side_Effects on the
expression of an object declaration or an allocator with a class-wide type
has introduced a pessimization in the former case for function calls that
return a specific tagged type, because the object ultimately created on the
primary stack has changed from being of a specific tagged type to being of
the class-wide type, the latter type always formally requiring finalization.

With the current finalization machinery, this means that a dispatching call
to the Deep_Finalize routine is generated, which is unnecessary.  Although
this is a generic finalization issue with class-wide objects, this restores
the previous behavior in this case to fix the pessimization for now.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): For a class-wide non-
interface stand-alone object initialized by a function call, call
Remove_Side_Effects on the expression to capture the result.

18 months agoada: Use static references to tag in more cases for interface objects
Eric Botcazou [Sat, 7 Jan 2023 21:05:58 +0000 (22:05 +0100)]
ada: Use static references to tag in more cases for interface objects

This extends the use of static references to the interface tag in more cases
for (class-wide) interface objects, e.g. for initialization expressions that
are qualified aggregates or nondispatching calls returning a specific tagged
type implementing the interface.

gcc/ada/

* exp_util.ads (Has_Tag_Of_Type): Declare.
* exp_util.adb (Has_Tag_Of_Type): Move to package level.  Recurse on
qualified expressions.
* exp_ch3.adb (Expand_N_Object_Declaration): Use a static reference
to the interface tag in more cases for class-wide interface objects.

18 months agoada: Fix benign pasto in new predicate
Eric Botcazou [Sat, 7 Jan 2023 13:39:19 +0000 (14:39 +0100)]
ada: Fix benign pasto in new predicate

gcc/ada/

* exp_util.adb (Make_CW_Equivalent_Type.Has_Tag_Of_Type): Fix pasto.

18 months agoada: Fix premature finalization of temporaries for interface objects
Eric Botcazou [Fri, 6 Jan 2023 12:24:18 +0000 (13:24 +0100)]
ada: Fix premature finalization of temporaries for interface objects

This restores the proper finalization of temporaries for interface objects
in the case where the initializing expression is not of an interface type.

It turns out that neither Is_Temporary_For_Interface_Object nor its previous
incarnation are sufficient to catch all the various cases, so it is replaced
by a small enhancement to Is_Aliased, which is more robust.

gcc/ada/

* exp_util.adb (Is_Temporary_For_Interface_Object): Delete.
(Is_Finalizable_Transient.Is_Aliased): Deal with the specific case
of temporaries generated for interface objects.

18 months agoada: Further optimize interface objects initialized with function calls
Eric Botcazou [Wed, 4 Jan 2023 07:41:52 +0000 (08:41 +0100)]
ada: Further optimize interface objects initialized with function calls

This further optimizes the usual case of (class-wide) interface objects that
are initialized with calls to functions whose result type is the type of the
objects (this is not necessary as any result type implementing the interface
would do) by avoiding a back-and-forth displacement of the objects' address.

This exposed a latent issue whereby the displacement was missing in the case
of a simple return statement whose expression is a call to a function whose
result type is a specific tagged type that needs finalization.

And, in order to avoid pessimizing the expanded code, this in turn required
avoiding to create temporaries for allocators by calling Remove_Side_Effects
up front, in the common cases when they are not necessary.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Do not generate a back-
and-forth displacement of the object's address when using a renaming
for an interface object with an expression of the same type.
* exp_ch4.adb (Expand_Allocator_Expression): Do not remove the side
effects of the expression up front for the simple allocators. Do not
call the Adjust primitive if the expression is a function call.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Do not expand the call
unnecessarily for a special return object.
(Expand_Simple_Function_Return): Restore the displacement of the
return object's address in the case where the expression is the call
to a function whose result type is a type that needs finalization.
* exp_util.adb (Expand_Subtype_From_Expr): Do not remove the side
effects of the expression before calling Make_Subtype_From_Expr.
(Make_CW_Equivalent_Type): If the expression has the tag of its type
and this type has a uniform size, use 'Object_Size of this type in
lieu of 'Size of the expression to compute the expression's size.

18 months agoada: Put back conversion to interface in more cases
Eric Botcazou [Tue, 3 Jan 2023 07:20:30 +0000 (08:20 +0100)]
ada: Put back conversion to interface in more cases

This needs to be done for all expressions with class-wide type.

gcc/ada/

* exp_ch3.adb (Make_Allocator_For_Return): Put back an interface
conversion for expressions with non-interface class-wide type.

18 months agoada: Lift restriction on optimization of aliased objects
Eric Botcazou [Mon, 2 Jan 2023 22:11:21 +0000 (23:11 +0100)]
ada: Lift restriction on optimization of aliased objects

It turns out that the only blocking case is an aliased object whose nominal
subtype is an unconstrained array because the bounds must be allocated.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Also optimize aliased
objects if their nominal subtype is not an unconstrained array.

18 months agoada: Optimize interface objects initialized with function calls
Eric Botcazou [Wed, 28 Dec 2022 16:36:32 +0000 (17:36 +0100)]
ada: Optimize interface objects initialized with function calls

This optimizes the implementation of (class-wide) interface objects that are
initialized with function calls, by avoiding an unnecessary copy operation.
This also removes useless access checks generated by the expansion of return
statements involving class-wide types.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Factor out conditions
needed for an initializating expression that is a function call to
be renamable into the Is_Renamable_Function_Call predicate.
Use it to implement the renaming in the case of class-wide interface
objects.  Remove an interface conversion on all paths, separate and
optimize the renaming path in the special expansion for interfaces.
(Is_Renamable_Function_Call): New predicate.
(Make_Allocator_For_Return): Put back an interface conversion.
* exp_ch6.adb (Apply_CW_Accessibility_Check): Remove useless access
checks on RE_Tag_Ptr.

18 months agoDisable gather/scatter for zen4
Jan Hubicka [Mon, 16 Jan 2023 14:40:45 +0000 (15:40 +0100)]
Disable gather/scatter for zen4

this patch adds more tunes for zen4:
 - new tunes for avx512 scater instructions.
   In micro benchmarks these seems consistent loss compared to open-coded coe
 - disable use of gather for zen4
   While these are win for a micro benchmarks (based on TSVC), enabling gather
   is a loss for parest. So for now it seems safe to keep it off.
 - disable pass to avoid FMA chains for znver4 since fmadd was optimized and does not seem
   to cause regressions.

* config/i386/i386.cc (ix86_vectorize_builtin_scatter): Guard scatter
by TARGET_USE_SCATTER.
* config/i386/i386.h (TARGET_USE_SCATTER_2PARTS,
TARGET_USE_SCATTER_4PARTS, TARGET_USE_SCATTER): New macros.
* config/i386/x86-tune.def (TARGET_USE_SCATTER_2PARTS,
TARGET_USE_SCATTER_4PARTS, TARGET_USE_SCATTER): New tunes.
(X86_TUNE_AVOID_256FMA_CHAINS, X86_TUNE_AVOID_512FMA_CHAINS): Disable
for znver4.  (X86_TUNE_USE_GATHER): Disable for zen4.

18 months agosolaris2: Don't add crtfastmath.o for -shared
Richard Biener [Fri, 13 Jan 2023 07:56:28 +0000 (08:56 +0100)]
solaris2: Don't add crtfastmath.o for -shared

Don't add crtfastmath.o for -shared to avoid altering the FP
environment when loading a shared library.

PR target/55522
* config/sol2.h (ENDFILE_SPEC): Don't add crtfastmath.o for -shared.

18 months agoarm: Split up MVE _Generic associations to prevent type clashes [PR107515]
Stam Markianos-Wright [Mon, 16 Jan 2023 11:40:40 +0000 (11:40 +0000)]
arm: Split up MVE _Generic associations to prevent type clashes [PR107515]

With these previous patches:
https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606586.html
https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606587.html
we enabled the MVE overloaded _Generic associations to handle more
scalar types, however at PR 107515 we found a new regression that
wasn't detected in our testing:

With glibc's posix/types.h:
```
typedef signed int __int32_t;
...
typedef __int32_t int32_t;
```
We would get a `error: '_Generic' specifies two compatible types`
from `__ARM_mve_coerce3` because of `type: param`, when `type` is
`int` and `int32_t: param` both being the same under the hood.

The same did not happen with Newlib's header sys/_stdint.h:
```
typedef long int __int32_t;
...
typedef __int32_t int32_t ;
```
which worked fine, because it uses `long int`.

The same could feasibly happen in `__ARM_mve_coerce2` between
`__fp16` and `float16_t`.

The solution here is to break the _Generic down so that the similar
types don't appear at the same level, as is done in `__ARM_mve_typeid`

gcc/ChangeLog:
PR target/96795
PR target/107515
* config/arm/arm_mve.h (__ARM_mve_coerce2): Split types.
(__ARM_mve_coerce3): Likewise.

gcc/testsuite/ChangeLog:
PR target/96795
PR target/107515
* gcc.target/arm/mve/intrinsics/mve_intrinsic_type_overloads-fp.c: New test.
* gcc.target/arm/mve/intrinsics/mve_intrinsic_type_overloads-int.c: New test.

18 months agoBump BASE-VER to 13.0.1 now that we are in stage4.
Richard Biener [Mon, 16 Jan 2023 11:43:21 +0000 (12:43 +0100)]
Bump BASE-VER to 13.0.1 now that we are in stage4.

* BASE-VER: Bump to 13.0.1.

18 months agoUpdate gcc/m2/mc/mcOptions.mod copyright and dates
Gaius Mulley [Mon, 16 Jan 2023 11:33:25 +0000 (11:33 +0000)]
Update gcc/m2/mc/mcOptions.mod copyright and dates

Annual update of dates.  Also change the GPL boilerplate
emitted to GPL v3.

gcc/m2/ChangeLog:

* mc/mcOptions.mod (displayVersion): Change GPLv2 to GPLv3.
(YEAR) set to 2023.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
18 months agoUpdate copyright years.
Jakub Jelinek [Mon, 16 Jan 2023 10:50:43 +0000 (11:50 +0100)]
Update copyright years.

18 months agoAllow build_popcount_expr to use an IFN
Andrew Carlotti [Thu, 22 Dec 2022 02:09:51 +0000 (02:09 +0000)]
Allow build_popcount_expr to use an IFN

gcc/ChangeLog:

* tree-ssa-loop-niter.cc (build_popcount_expr): Add IFN support.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/pr86544.C: Add .POPCOUNT to tree scan regex.
* gcc.dg/tree-ssa/popcount.c: Likewise.
* gcc.dg/tree-ssa/popcount2.c: Likewise.
* gcc.dg/tree-ssa/popcount3.c: Likewise.
* gcc.target/aarch64/popcount4.c: Likewise.
* gcc.target/i386/pr95771.c: Likewise, and...
* gcc.target/i386/pr95771-2.c: ...split int128 test from above,
since this would emit just a single IFN if a TI optab is added.

18 months agoAdd c[lt]z idiom recognition
Andrew Carlotti [Thu, 22 Dec 2022 02:14:06 +0000 (02:14 +0000)]
Add c[lt]z idiom recognition

This recognises the patterns of the form:
  while (n & 1) { n >>= 1 }

Unfortunately there are currently two issues relating to this patch.

Firstly, simplify_using_initial_conditions does not recognise that
(n != 0) and ((n & 1) == 0) implies that ((n >> 1) != 0).

This preconditions arise following the loop copy-header pass, and the
assumptions returned by number_of_iterations_exit_assumptions then
prevent final value replacement from using the niter result.

I'm not sure what is the best way to fix this - one approach could be to
modify simplify_using_initial_conditions to handle this sort of case,
but it seems that it basically wants the information that ranger could
give anway, so would something like that be a better option?

The second issue arises in the vectoriser, which is able to determine
that the niter->assumptions are always true.
When building with -march=armv8.4-a+sve -S -O3, we get this codegen:

foo (unsigned int b) {
    int c = 0;

    if (b == 0)
      return PREC;

    while (!(b & (1 << (PREC - 1)))) {
        b <<= 1;
        c++;
    }

    return c;
}

foo:
.LFB0:
        .cfi_startproc
        cmp     w0, 0
        cbz     w0, .L6
        blt     .L7
        lsl     w1, w0, 1
        clz     w2, w1
        cmp     w2, 14
        bls     .L8
        mov     x0, 0
        cntw    x3
        add     w1, w2, 1
        index   z1.s, #0, #1
        whilelo p0.s, wzr, w1
.L4:
        add     x0, x0, x3
        mov     p1.b, p0.b
        mov     z0.d, z1.d
        whilelo p0.s, w0, w1
        incw    z1.s
        b.any   .L4
        add     z0.s, z0.s, #1
        lastb   w0, p1, z0.s
        ret
        .p2align 2,,3
.L8:
        mov     w0, 0
        b       .L3
        .p2align 2,,3
.L13:
        lsl     w1, w1, 1
.L3:
        add     w0, w0, 1
        tbz     w1, #31, .L13
        ret
        .p2align 2,,3
.L6:
        mov     w0, 32
        ret
        .p2align 2,,3
.L7:
        mov     w0, 0
        ret
        .cfi_endproc

In essence, the vectoriser uses the niter information to determine
exactly how many iterations of the loop it needs to run. It then uses
SVE whilelo instructions to run this number of iterations. The original
loop counter is also vectorised, despite only being used in the final
iteration, and then the final value of this counter is used as the
return value (which is the same as the number of iterations it computed
in the first place).

This vectorisation is obviously bad, and I think it exposes a latent
bug in the vectoriser, rather than being an issue caused by this
specific patch.

gcc/ChangeLog:

* tree-ssa-loop-niter.cc (number_of_iterations_cltz): New.
(number_of_iterations_bitcount): Add call to the above.
(number_of_iterations_exit_assumptions): Add EQ_EXPR case for
c[lt]z idiom recognition.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/cltz-max.c: New test.
* gcc.dg/tree-ssa/clz-char.c: New test.
* gcc.dg/tree-ssa/clz-int.c: New test.
* gcc.dg/tree-ssa/clz-long-long.c: New test.
* gcc.dg/tree-ssa/clz-long.c: New test.
* gcc.dg/tree-ssa/ctz-char.c: New test.
* gcc.dg/tree-ssa/ctz-int.c: New test.
* gcc.dg/tree-ssa/ctz-long-long.c: New test.
* gcc.dg/tree-ssa/ctz-long.c: New test.

18 months agodocs: Add popcount, clz and ctz target attributes
Andrew Carlotti [Mon, 12 Dec 2022 13:54:47 +0000 (13:54 +0000)]
docs: Add popcount, clz and ctz target attributes

gcc/ChangeLog:

* doc/sourcebuild.texi: Add missing target attributes.

18 months agoAdd cltz_complement idiom recognition
Andrew Carlotti [Thu, 10 Nov 2022 15:56:51 +0000 (15:56 +0000)]
Add cltz_complement idiom recognition

This recognises patterns of the form:
while (n) { n >>= 1 }

This patch results in improved (but still suboptimal) codegen:

foo (unsigned int b) {
    int c = 0;

    while (b) {
        b >>= 1;
        c++;
    }

    return c;
}

foo:
.LFB11:
        .cfi_startproc
        cbz     w0, .L3
        clz     w1, w0
        tst     x0, 1
        mov     w0, 32
        sub     w0, w0, w1
        csel    w0, w0, wzr, ne
        ret

The conditional is unnecessary. phiopt could recognise a redundant csel
(using cond_removal_in_builtin_zero_pattern) when one of the inputs is a
clz call, but it cannot recognise the redunancy when the input is (e.g.)
(32 - clz).

I could perhaps extend this function to recognise this pattern in a later
patch, if this is a good place to recognise more patterns.

gcc/ChangeLog:

PR tree-optimization/94793
* tree-scalar-evolution.cc (expression_expensive_p): Add checks
for c[lt]z optabs.
* tree-ssa-loop-niter.cc (build_cltz_expr): New.
(number_of_iterations_cltz_complement): New.
(number_of_iterations_bitcount): Add call to the above.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_effective_target_clz)
(check_effective_target_clzl, check_effective_target_clzll)
(check_effective_target_ctz, check_effective_target_clzl)
(check_effective_target_ctzll): New.
* gcc.dg/tree-ssa/cltz-complement-max.c: New test.
* gcc.dg/tree-ssa/clz-complement-char.c: New test.
* gcc.dg/tree-ssa/clz-complement-int.c: New test.
* gcc.dg/tree-ssa/clz-complement-long-long.c: New test.
* gcc.dg/tree-ssa/clz-complement-long.c: New test.
* gcc.dg/tree-ssa/ctz-complement-char.c: New test.
* gcc.dg/tree-ssa/ctz-complement-int.c: New test.
* gcc.dg/tree-ssa/ctz-complement-long-long.c: New test.
* gcc.dg/tree-ssa/ctz-complement-long.c: New test.

18 months agocontrib: Yet another update-copyright.py tweak [PR108413]
Jakub Jelinek [Mon, 16 Jan 2023 10:38:33 +0000 (11:38 +0100)]
contrib: Yet another update-copyright.py tweak [PR108413]

Ignore __builtins.di like object.d is already ignored.

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

PR other/108413
* update-copyright.py (LibPhobosFilter): Add __builtins.di to
skipped files.

18 months agolibstdc++: Fix copyright notice to use usual form [PR108413]
Jonathan Wakely [Mon, 16 Jan 2023 10:15:41 +0000 (10:15 +0000)]
libstdc++: Fix copyright notice to use usual form [PR108413]

libstdc++-v3/ChangeLog:

PR libstdc++/108413
* include/c_compatibility/stdatomic.h: Change copyright line to
be consistent with other headers contributed under DCO terms.
* include/std/expected: Add full stop to copyright line.
* src/c++20/tzdb.cc: Likewise.

18 months agodoc: Fix grammar typo in description of malloc attribute
Jonathan Wakely [Mon, 16 Jan 2023 09:56:58 +0000 (09:56 +0000)]
doc: Fix grammar typo in description of malloc attribute

gcc/ChangeLog:

* doc/extend.texi (Common Function Attributes): Fix grammar.

18 months agolibatomic: Use config/mingw/lock.c for --enable-threads=single
Jonathan Wakely [Fri, 13 Jan 2023 13:13:55 +0000 (13:13 +0000)]
libatomic: Use config/mingw/lock.c for --enable-threads=single

Without this change bootstrap fails for x86_64-w64-mingw32 with
--disable-threads=single because there is no lock.c file chosen by
libatomic's configure.

libatomic/ChangeLog:

* configure.tgt (config_path) [target_thread_file=single]:
Use 'mingw' config.

18 months agoriscv: Fix up Copyright lines [PR108413]
Jakub Jelinek [Mon, 16 Jan 2023 10:22:09 +0000 (11:22 +0100)]
riscv: Fix up Copyright lines [PR108413]

These 2 files had incorrectly formatted Copyright lines (no space between
Copyright and (C)) which makes update-copyright.py upset.

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

PR other/108413
* config/riscv/riscv-vsetvl.h: Add space in between Copyright and (C).
* config/riscv/riscv-vsetvl.cc: Likewise.

18 months agocontrib: Partial fix for failed update-copyright --this year [PR108413]
Jakub Jelinek [Mon, 16 Jan 2023 10:03:30 +0000 (11:03 +0100)]
contrib: Partial fix for failed update-copyright --this year [PR108413]

As mentioned on IRC or in PR108413, the last update-copyright.py --this year
failed and that is why we are in a strange state where some copyrights have
been updated and others have not.
The full list of errors I got was I think:
gcc/m2/mc-boot/GmcOptions.c: unrecognised copyright: comment (f, (const char *) "Copyright (C) ''2021'' Free Software Foundation, Inc.", 53);
gcc/m2/mc-boot/GmcOptions.c: unrecognised copyright: comment (f, (const char *) "Copyright (C) ''2021'' Free Software Foundation, Inc.", 53);
gcc/testsuite/gm2/switches/pedantic-params/pass/Strings.mod: unrecognised copyright holder: Faculty of Information Technology,
gcc/testsuite/gm2/switches/pedantic-params/pass/Strings2.mod: unrecognised copyright holder: Faculty of Information Technology,
libphobos/libdruntime/__builtins.di: unrecognised copyright: * Copyright: Copyright Digital Mars 2022
libstdc++-v3/src/c++17/fast_float/fast_float.h: unrecognised copyright holder: The fast_float authors
libstdc++-v3/include/c_compatibility/stdatomic.h: unrecognised copyright holder: The GCC developers

The following patch deals with the gcc/testsuite/gm2 ones and
with the fast_float.h one, ok for trunk?

Not really sure what we should do in the GmcOptions.c case
(perhaps obfuscate it in the source somehow by splitting
the string literals into different substrings
Perhaps "Copy" "right (" "C) ''..." would do it?  Or do we want
to bump there each year (manually or by the script)?
E.g. in gcc.cc we have
      printf ("Copyright %s 2023 Free Software Foundation, Inc.\n",
              _("(C)"));
which also prints (C) nicer in Unicode if possible and is updated
by hand each year.

I have no idea about the libphobos case, we have tons of
libphobos/src/std/format/spec.d:Copyright: Copyright The D Language Foundation 2000-2013.
libphobos/src/std/random.d:Copyright: Copyright Andrei Alexandrescu 2008 - 2009, Joseph Rushton Wakeling 2012.
etc. lines and those aren't reported as errors.

And the last one is that I think for The GCC developers we should treat it
similarly like FSF and bump copyright on it.
Would
        canon_gcc = 'The GCC developers'
        self.add_package_author ('The GCC developers', canon_gcc)
        self.add_package_author ('The GCC Developers', canon_gcc)
or something similar do the trick?

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

PR other/108413
* update-copyright.py (TestsuiteFilter): Add .mod and .rs extensions.
(GCCCopyright): Add 'The fast_float authors' as external author.

18 months agox86: Avoid -Wuninitialized warnings on _mm*_undefined_* in C++ [PR105593]
Jakub Jelinek [Mon, 16 Jan 2023 08:41:38 +0000 (09:41 +0100)]
x86: Avoid -Wuninitialized warnings on _mm*_undefined_* in C++ [PR105593]

In https://gcc.gnu.org/pipermail/gcc-patches/2023-January/609844.html
I've posted a patch to allow ignoring -Winit-self using GCC diagnostic
pragmas, such that one can mark self-initialization as intentional
disabling of -Wuninitialized warnings.

The following incremental patch uses that in the x86 intrinsic
headers.

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

PR c++/105593
gcc/
* config/i386/xmmintrin.h (_mm_undefined_ps): Temporarily
disable -Winit-self using pragma GCC diagnostic ignored.
* config/i386/emmintrin.h (_mm_undefined_pd, _mm_undefined_si128):
Likewise.
* config/i386/avxintrin.h (_mm256_undefined_pd, _mm256_undefined_ps,
_mm256_undefined_si256): Likewise.
* config/i386/avx512fintrin.h (_mm512_undefined_pd,
_mm512_undefined_ps, _mm512_undefined_epi32): Likewise.
* config/i386/avx512fp16intrin.h (_mm_undefined_ph,
_mm256_undefined_ph, _mm512_undefined_ph): Likewise.
gcc/testsuite/
* g++.target/i386/pr105593.C: New test.

18 months agoc, c++: Allow ignoring -Winit-self through pragmas [PR105593]
Jakub Jelinek [Mon, 16 Jan 2023 08:40:14 +0000 (09:40 +0100)]
c, c++: Allow ignoring -Winit-self through pragmas [PR105593]

As mentioned in the PR, various x86 intrinsics need to return
an uninitialized vector.  Currently they use self initialization
to avoid -Wuninitialized warnings, which works fine in C, but
doesn't work in C++ where -Winit-self is enabled in -Wall.
We don't have an attribute to mark a variable as knowingly
uninitialized (the uninitialized attribute exists but means
something else, only in the -ftrivial-auto-var-init context),
and trying to suppress either -Wuninitialized or -Winit-self
inside of the _mm_undefined_ps etc. intrinsic definitions
doesn't work, one needs to currently disable through pragmas
-Wuninitialized warning at the point where _mm_undefined_ps etc.
result is actually used, but that goes against the intent of
those intrinsics.

The -Winit-self warning option actually doesn't do any warning,
all we do is record a suppression for -Winit-self if !warn_init_self
on the decl definition and later look that up in uninit pass.

The following patch changes those !warn_init_self tests which
are true only based on the command line option setting, not based
on GCC diagnostic pragma overrides to
!warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self)
such that it takes them into account.

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

PR c++/105593
gcc/c/
* c-parser.cc (c_parser_initializer): Check warning_enabled_at
at the DECL_SOURCE_LOCATION (decl) for OPT_Winit_self instead
of warn_init_self.
gcc/cp/
* decl.cc (cp_finish_decl): Check warning_enabled_at
at the DECL_SOURCE_LOCATION (decl) for OPT_Winit_self instead
of warn_init_self.
gcc/testsuite/
* c-c++-common/Winit-self3.c: New test.
* c-c++-common/Winit-self4.c: New test.
* c-c++-common/Winit-self5.c: New test.

18 months agors6000: Teach rs6000_opaque_type_invalid_use_p about inline asm [PR108272]
Kewen Lin [Mon, 16 Jan 2023 08:15:39 +0000 (02:15 -0600)]
rs6000: Teach rs6000_opaque_type_invalid_use_p about inline asm [PR108272]

As PR108272 shows, there are some invalid uses of MMA opaque
types in inline asm statements.  This patch is to teach the
function rs6000_opaque_type_invalid_use_p for inline asm,
check and error any invalid use of MMA opaque types in input
and output operands.

PR target/108272

gcc/ChangeLog:

* config/rs6000/rs6000.cc (rs6000_opaque_type_invalid_use_p): Add the
support for invalid uses in inline asm, factor out the checking and
erroring to lambda function check_and_error_invalid_use.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr108272-1.c: New test.
* gcc.target/powerpc/pr108272-2.c: New test.
* gcc.target/powerpc/pr108272-3.c: New test.
* gcc.target/powerpc/pr108272-4.c: New test.

18 months agoDaily bump.
GCC Administrator [Mon, 16 Jan 2023 00:17:33 +0000 (00:17 +0000)]
Daily bump.

18 months agolibstdc++: Move www.open-std.org in status part of manual to https
Gerald Pfeifer [Sun, 15 Jan 2023 22:34:54 +0000 (23:34 +0100)]
libstdc++: Move open-std.org in status part of manual to https

libstdc++-v3/ChangeLog:

2023-01-15  Gerald Pfeifer  <gerald@pfeifer.com>

* doc/xml/manual/status_cxx2014.xml: Switch www.open-std.org to
https.
* doc/xml/manual/status_cxx2017.xml: Ditto.
* doc/xml/manual/status_cxx2020.xml: Ditto.
* doc/xml/manual/status_cxx2023.xml: Ditto.
* doc/html/manual/status.html: Regenerate.

18 months agolibstdc++: Remove dg-xfail-run-if in std/time/tzdb_list/1.cc
Jonathan Wakely [Sun, 15 Jan 2023 16:36:34 +0000 (16:36 +0000)]
libstdc++: Remove dg-xfail-run-if in std/time/tzdb_list/1.cc

Use the global override_used to tell whether the target supports the
override functionality that the test_reload and test_erase functions
rely on.

libstdc++-v3/ChangeLog:

* testsuite/std/time/tzdb_list/1.cc: Remove dg-xfail-run-if
and fail gracefully if defining the weak symbol doesn't work.

18 months agolibstdc++: [_GLIBCXX_DEBUG] Complete deadlock fix on safe iterators [PR108288]
François Dumont [Mon, 9 Jan 2023 17:48:30 +0000 (18:48 +0100)]
libstdc++: [_GLIBCXX_DEBUG] Complete deadlock fix on safe iterators [PR108288]

Complete fix on all _Safe_iterator post-increment and post-decrement implementations
and on _Safe_local_iterator.

libstdc++-v3/ChangeLog:

PR libstdc++/108288
* include/debug/safe_iterator.h (_Safe_iterator<>::operator++(int)): Extend deadlock
fix to other iterator category.
(_Safe_iterator<>::operator--(int)): Likewise.
* include/debug/safe_local_iterator.h (_Safe_local_iterator<>::operator++(int)):
Fix deadlock.
* testsuite/util/debug/unordered_checks.h (invalid_local_iterator_pre_increment): New.
(invalid_local_iterator_post_increment): New.
* testsuite/23_containers/unordered_map/debug/invalid_local_iterator_post_increment_neg.cc:
New test.
* testsuite/23_containers/unordered_map/debug/invalid_local_iterator_pre_increment_neg.cc:
New test.

18 months ago[PR107608] [range-ops] Avoid folding into INF when flag_trapping_math.
Aldy Hernandez [Tue, 10 Jan 2023 09:57:16 +0000 (10:57 +0100)]
[PR107608] [range-ops] Avoid folding into INF when flag_trapping_math.

As discussed in the PR, for trapping math, do not fold overflowing
operations into +-INF as doing so could elide a trap.

There is a minor adjustment to known_isinf() where it was mistakenly
returning true for an [infinity U NAN], whereas it should only return
true when the range is exclusively +INF or -INF.  This is benign, as
there were no users of known_isinf up to now.

Tested on x86-64 Linux.

I also ran the glibc testsuite (git sources) on x86-64 and this patch
fixes:

-FAIL: math/test-double-lgamma
-FAIL: math/test-double-log1p
-FAIL: math/test-float-lgamma
-FAIL: math/test-float-log1p
-FAIL: math/test-float128-catan
-FAIL: math/test-float128-catanh
-FAIL: math/test-float128-lgamma
-FAIL: math/test-float128-log
-FAIL: math/test-float128-log1p
-FAIL: math/test-float128-y0
-FAIL: math/test-float128-y1
-FAIL: math/test-float32-lgamma
-FAIL: math/test-float32-log1p
-FAIL: math/test-float32x-lgamma
-FAIL: math/test-float32x-log1p
-FAIL: math/test-float64-lgamma
-FAIL: math/test-float64-log1p
-FAIL: math/test-float64x-lgamma
-FAIL: math/test-ldouble-lgamma

PR tree-optimization/107608

gcc/ChangeLog:

* range-op-float.cc (range_operator_float::fold_range): Avoid
folding into INF when flag_trapping_math.
* value-range.h (frange::known_isinf): Return false for possible NANs.

18 months agolibstdc++: Remove unconditional -pthread from test options
Jonathan Wakely [Sun, 15 Jan 2023 13:49:44 +0000 (13:49 +0000)]
libstdc++: Remove unconditional -pthread from test options

This shouldn't be in the common options, it's already added for the
relevant targets using dg-additional-options.

libstdc++-v3/ChangeLog:

* testsuite/30_threads/jthread/jthread.cc: Remove -pthread from
dg-options.

18 months agoconfig-list.mk: Modernize FreeBSD targets towards version 13
Gerald Pfeifer [Sun, 15 Jan 2023 13:36:16 +0000 (14:36 +0100)]
config-list.mk: Modernize FreeBSD targets towards version 13

contrib/ChangeLog:

2023-01-15  Gerald Pfeifer  <gerald@pfeifer.com>

* config-list.mk: Update FreeBSD targets to version 13.
Add aarch64-freebsd13.

18 months agoBugfix to allow testsuite/gm2/pim/pass/arraybool.mod to compile on ppc64le
Gaius Mulley [Sun, 15 Jan 2023 13:13:40 +0000 (13:13 +0000)]
Bugfix to allow testsuite/gm2/pim/pass/arraybool.mod to compile on ppc64le

This bug is exposed on the ppc64le platform.  The expression
parser P3Build.bnf (and PHBuild.bnf) BuiltNot omitted to record
the current token position on the quad stack.  The patch changes
all occurances of NEW to newBoolFrame to ensure that the tokenno
recorded in the bool frame is set to a sensible value.
BuildNot is fixed and improved to generate a virtual token
recording the position of the subexpression.

gcc/m2/ChangeLog:

* gm2-compiler/M2LexBuf.mod (isSrcToken): Add block comment.
Remove dead code.
* gm2-compiler/M2Quads.def (BuildNot): Add notTokPos parameter.
* gm2-compiler/M2Quads.mod (BuildNot): Add notTokPos parameter.
Create and push virtual token.
(PopBooltok): New procedure.
(PushBooltok): New procedure.
(PushBool): Re-implement using PushBooltok.
(PopBool): Re-implement using PopBooltok.
* gm2-compiler/P3Build.bnf (ConstFactor): Record token
position of NOT.
(Factor): Record token position of NOT.
* gm2-compiler/PHBuild.bnf (ConstFactor): Record token
position of NOT.
(Relation): Push token position.
(UnaryOrConstTerm): Push token position.
(AddOperator): Push token position.
(MulOperator): Push token position.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
18 months agolibstdc++: Fix narrowing conversion in std/time/clock/utc/io.cc
Jonathan Wakely [Sun, 15 Jan 2023 12:38:31 +0000 (12:38 +0000)]
libstdc++: Fix narrowing conversion in std/time/clock/utc/io.cc

For a port with signed char and unsigned wchar_t initializing a wchar_t
array with a char is a narrowing conversion. The code is wrong for
assuming that (int)'a' == (int)L'a' anyway, so fix it properly by using
ctype<wchar_t>::widen(char).

libstdc++-v3/ChangeLog:

* testsuite/std/time/clock/utc/io.cc: Use ctype to widen char.

18 months agoC-SKY: Support --with-float=softfp in configuration.
Xianmiao Qu [Sun, 15 Jan 2023 02:04:35 +0000 (10:04 +0800)]
C-SKY: Support --with-float=softfp in configuration.

Missed it before, it needs to be used when compiling non-multilib.

gcc/
* config.gcc (csky-*-*): Support --with-float=softfp.

18 months agoDaily bump.
GCC Administrator [Sun, 15 Jan 2023 00:17:49 +0000 (00:17 +0000)]
Daily bump.

18 months agolibstdc++: enable <stacktrace> on windows
Björn Schäpers [Mon, 12 Dec 2022 17:27:49 +0000 (18:27 +0100)]
libstdc++: enable <stacktrace> on windows

libstdc++-v3/Changelog

* acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): Add check for
windows.h. Add pecoff as FORMAT_FILE.
* config.h.in: Regenerate.
* configure: Regenerate.
* src/libbacktrace/Makefile.am: Regenerate.
* src/libbacktrace/Makefile.in: Add pecoff.c as FORMAT_FILE.

Signed-off-by: Björn Schäpers <bjoern@hazardy.de>
18 months agolibstdc++: Deliver names of C functions in <stacktrace>
Björn Schäpers [Tue, 13 Dec 2022 21:02:47 +0000 (22:02 +0100)]
libstdc++: Deliver names of C functions in <stacktrace>

__cxa_demangle is only to demangle C++ names, for all C functions,
extern "C" functions, and including main it returns -2, in that case
just adapt the given name. Otherwise it's kept empty, which doesn't look
nice in the stacktrace.

libstdc++-v3/ChangeLog:

* include/std/stacktrace (stacktrace_entry::_S_demangle): Use
raw __name if __cxa_demangle could not demangle it.

Signed-off-by: Björn Schäpers <bjoern@hazardy.de>
18 months agolibstdc++: Implement std::chrono::current_zone() for AIX [PR108409]
Jonathan Wakely [Sat, 14 Jan 2023 20:13:32 +0000 (20:13 +0000)]
libstdc++: Implement std::chrono::current_zone() for AIX [PR108409]

libstdc++-v3/ChangeLog:

PR libstdc++/108409
* src/c++20/tzdb.cc (current_zone()) [_AIX]: Use TZ environment
variable.

18 months agolibstdc++: Disable unwanted code for --with-libstdcxx-zoneinfo=no
Jonathan Wakely [Sat, 14 Jan 2023 13:39:48 +0000 (13:39 +0000)]
libstdc++: Disable unwanted code for --with-libstdcxx-zoneinfo=no

This allows most of the tzdb functionality to be disabled by
configuring with --with-libstdcxx-zoneinfo=no. This might be desirable
for small targets that don't need the time zone support.

libstdc++-v3/ChangeLog:

* src/c++20/tzdb.cc (TZDB_DISABLED): Disable all code for
loading tzdb.
* testsuite/std/time/tzdb/leap_seconds.cc: Require tzdb
effective target.
* testsuite/std/time/tzdb_list/1.cc: Likewise.

18 months agolibstdc++: Embed a static copy of tzdata.zi
Jonathan Wakely [Sat, 14 Jan 2023 13:33:58 +0000 (13:33 +0000)]
libstdc++: Embed a static copy of tzdata.zi

This adds a copy of the tzdata.zi file to the library, and allows
configuring to use it instead of a copy read from disk at runtime.
The content of the file is in the public domain, but will need to be
updated to the latest upstream file before making GCC releases.

libstdc++-v3/ChangeLog:

* acinclude.m4 (GLIBCXX_ZONEINFO_DIR): Replace the
--with-libstdcxx-zoneinfo-dir configure option with
--with-libstdcxx-zoneinfo with yes/no/static choices as well as
a directory.
* config.h.in: Regenerate.
* configure: Regenerate.
* doc/xml/manual/configure.xml: Document configure option.
* doc/html/manual/configure.html: Regenerate.
* src/c++20/Makefile.am: Generate tzdata.zi.h header.
* src/c++20/Makefile.in: Regenerate.
* src/c++20/tzdb.cc (__gnu_cxx::zoneinfo_dir_override): Return a
null pointer if no directory is configured.
(zoneinfo_dir): Replace with ...
(zoneinfo_file): New function.
(tzdata_stream): New istream class.
(remote_version, reload_tzdb): Use tzdata_stream.
* testsuite/lib/libstdc++.exp (check_effective_target_tzdb):
Check new _GLIBCXX_STATIC_TZDATA macro and ignore presence of
tzdata.zi file in default location.
* src/c++20/tzdata.zi: New file.

18 months agoxtensa: Remove old broken tweak for leaf function
Takayuki 'January June' Suwa [Sat, 14 Jan 2023 05:03:55 +0000 (14:03 +0900)]
xtensa: Remove old broken tweak for leaf function

In the before-IRA era, ORDER_REGS_FOR_LOCAL_ALLOC was called for each
function in Xtensa, and there was register allocation table reordering
for leaf functions to compensate for the poor performance of local-alloc.

Today the adjustment hook is still called via its alternative
ADJUST_REG_ALLOC_ORDER, but it is only called once at the start of the IRA,
and leaf_function_p() erroneously returns true and also gives no argument
count.

That straightforwardly misleads register allocation that all functions are
always leaves with no arguments, which leads to inefficiencies in allocation
results.

Fortunately, IRA is smart enough than local-alloc to not need such assistance.

This patch does away with the antiquated by removing the wreckage that no
longer works.

gcc/ChangeLog:

* config/xtensa/xtensa-protos.h (order_regs_for_local_alloc):
Rename to xtensa_adjust_reg_alloc_order.
* config/xtensa/xtensa.cc (xtensa_adjust_reg_alloc_order):
Ditto.  And also remove code to reorder register numbers for
leaf functions, rename the tables, and adjust the allocation
order for the call0 ABI to use register A0 more.
(xtensa_leaf_regs): Remove.
* config/xtensa/xtensa.h (REG_ALLOC_ORDER): Cosmetics.
(order_regs_for_local_alloc): Rename as the above.
(LEAF_REGISTERS, LEAF_REG_REMAP, leaf_function): Remove.