platform/upstream/gcc.git
21 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.

21 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.

21 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.

21 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.

21 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.

21 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.

21 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.

21 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.

21 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.

21 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.

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

21 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.

21 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.

21 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.

21 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.

21 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.

21 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.

21 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>
21 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.

21 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.

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

21 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>
21 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>
21 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.

21 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.

21 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.

21 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.

21 months ago[aarch64] Fold ldr+dup to ld1rq for little endian targets.
Prathamesh Kulkarni [Sat, 14 Jan 2023 17:51:55 +0000 (23:21 +0530)]
[aarch64] Fold ldr+dup to ld1rq for little endian targets.

gcc/ChangeLog:
* config/aarch64/aarch64-sve.md (aarch64_vec_duplicate_vq<mode>_le):
Change to define_insn_and_split to fold ldr+dup to ld1rq.
* config/aarch64/predicates.md (aarch64_sve_dup_ld1rq_operand): New.

gcc/testsuite/ChangeLog:
* gcc.target/aarch64/sve/acle/general/pr96463-2.c: Adjust.

21 months agolibstdc++: Fix ostream insertion operators for calendar types
Jonathan Wakely [Sat, 14 Jan 2023 15:41:58 +0000 (15:41 +0000)]
libstdc++: Fix ostream insertion operators for calendar types

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (operator<<): Fix syntax errors.
* testsuite/std/time/month_day/io.cc: New test.
* testsuite/std/time/month_day_last/io.cc: New test.
* testsuite/std/time/month_weekday/io.cc: New test.
* testsuite/std/time/month_weekday_last/io.cc: New test.
* testsuite/std/time/weekday_indexed/io.cc: New test.
* testsuite/std/time/weekday_last/io.cc: New test.
* testsuite/std/time/year_month/io.cc: New test.
* testsuite/std/time/year_month_day_last/io.cc: New test.
* testsuite/std/time/year_month_weekday/io.cc: New test.
* testsuite/std/time/year_month_weekday_last/io.cc: New test.

21 months agolibstdc++: [_GLIBCXX_INLINE_VERSION] Add to_chars/from_chars symbols export
François Dumont [Sat, 26 Nov 2022 07:51:58 +0000 (08:51 +0100)]
libstdc++: [_GLIBCXX_INLINE_VERSION] Add to_chars/from_chars symbols export

libstdc++-v3/ChangeLog

* include/std/format [_GLIBCXX_INLINE_VERSION](to_chars): Adapt __asm symbol
specifications.
* config/abi/pre/gnu-versioned-namespace.ver: Add to_chars/from_chars symbols
export.

21 months agoc++: Avoid incorrect shortening of divisions [PR108365]
Jakub Jelinek [Sat, 14 Jan 2023 09:17:14 +0000 (10:17 +0100)]
c++: Avoid incorrect shortening of divisions [PR108365]

The following testcase is miscompiled, because we shorten the division
in a case where it should not be shortened.
Divisions (and modulos) can be shortened if it is unsigned division/modulo,
or if it is signed division/modulo where we can prove the dividend will
not be the minimum signed value or divisor will not be -1, because e.g.
on sizeof(long long)==sizeof(int)*2 && __INT_MAX__ == 0x7fffffff targets
(-2147483647 - 1) / -1 is UB
but
(int) (-2147483648LL / -1LL) is not, it is -2147483648.
The primary aim of both the C and C++ FE division/modulo shortening I assume
was for the implicit integral promotions of {,signed,unsigned} {char,short}
and because at this point we have no VRP information etc., the shortening
is done if the integral promotion is from unsigned type for the divisor
or if the dividend is an integer constant other than -1.
This works fine for char/short -> int promotions when char/short have
smaller precision than int - unsigned char -> int or unsigned short -> int
will always be a positive int, so never the most negative.

Now, the C FE checks whether orig_op0 is TYPE_UNSIGNED where op0 is either
the same as orig_op0 or that promoted to int, I think that works fine,
if it isn't promoted, either the division/modulo common type will have the
same precision as op0 but then the division/modulo is unsigned and so
without UB, or it will be done in wider precision (e.g. because op1 has
wider precision), but then op0 can't be minimum signed value.  Or it has
been promoted to int, but in that case it was again from narrower type and
so never minimum signed int.

But the C++ FE was checking if op0 is a NOP_EXPR from TYPE_UNSIGNED.
First of all, not sure if the operand of NOP_EXPR couldn't be non-integral
type where TYPE_UNSIGNED wouldn't be meaningful, but more importantly,
even if it is a cast from unsigned integral type, we only know it can't be
minimum signed value if it is a widening cast, if it is same precision or
narrowing cast, we know nothing.

So, the following patch for the NOP_EXPR cases checks just in case that
it is from integral type and more importantly checks it is a widening
conversion, and then next to it also allows op0 to be just unsigned,
promoted or not, as that is what the C FE will do for those cases too
and I believe it must work - either the division/modulo common type
will be that unsigned type, then we can shorten and don't need to worry
about UB, or it will be some wider signed type but then it can't be most
negative value of the wider type.
And changes both the C and C++ FEs to do the same thing, using a helper
function in c-family.

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

PR c++/108365
* c-common.h (may_shorten_divmod): New static inline function.

* c-typeck.cc (build_binary_op): Use may_shorten_divmod for integral
division or modulo.

* typeck.cc (cp_build_binary_op): Use may_shorten_divmod for integral
division or modulo.

* c-c++-common/pr108365.c: New test.
* g++.dg/opt/pr108365.C: New test.
* g++.dg/warn/pr108365.C: New test.

21 months agohash table: enforce testing is_empty before is_deleted
Alexandre Oliva [Sat, 14 Jan 2023 00:15:44 +0000 (21:15 -0300)]
hash table: enforce testing is_empty before is_deleted

Existing hash_table traits that use the same representation for empty
and deleted slots reject marking slots as deleted, and to not pass
is_deleted for slots that pass is_empty.

Nevertheless, nearly everywhere, we only test for is_deleted after
checking that !is_empty first.  The one exception was the copy
constructor, that would fail if traits recognized is_empty slots as
is_deleted, but then refused to mark_deleted.

This asymmetry is neither necessary nor desirable, and there is a
theoretical risk that traits might not only fail to refuse to
mark_deleted, but also return is_deleted for is_empty slots.

This patch introduces checks that detect these potentially problematic
situations, and reorders the tests in the copy constructor so as to
use the conventional testing order and thus avoid them.

for  gcc/ChangeLog

* hash-table.h (is_deleted): Precheck !is_empty.
(mark_deleted): Postcheck !is_empty.
(copy constructor): Test is_empty before is_deleted.

21 months ago[PR42093] [arm] [thumb2] disable tree-dce for test
Alexandre Oliva [Sat, 14 Jan 2023 00:15:42 +0000 (21:15 -0300)]
[PR42093] [arm] [thumb2] disable tree-dce for test

CD-DCE introduces blocks to share common PHI nodes, which replaces a
backwards branch that used to prevent the thumb2 jump table shortening
that PR42093 tested for.  In order to keep on testing that the
backward branch prevents the jumptable shortening, disable tree-dce.

for  gcc/testsuite/ChangeLog

PR target/42093
* gcc.target/arm/pr42093.c: Disable tree-dce.

21 months ago[PR40457] [arm] expand SI-aligned movdi into pair of movsi
Alexandre Oliva [Sat, 14 Jan 2023 00:15:41 +0000 (21:15 -0300)]
[PR40457] [arm] expand SI-aligned movdi into pair of movsi

When expanding a misaligned DImode move, emit aligned SImode moves if
the parts are sufficiently aligned.  This enables neighboring stores
to be peephole-combined into stm, as expected by the PR40457 testcase,
even after SLP vectorizes the originally aligned SImode stores into a
misaligned DImode store.

for  gcc/ChangeLog

PR target/40457
* config/arm/arm.md (movmisaligndi): Prefer aligned SImode
moves.

21 months agoanalyzer: add heuristics for switch on enum type [PR105273]
David Malcolm [Fri, 13 Jan 2023 22:51:26 +0000 (17:51 -0500)]
analyzer: add heuristics for switch on enum type [PR105273]

Assume that switch on an enum doesn't follow an implicit default
skipping all cases when all enum values are covered by cases.

Fixes various false positives from -Wanalyzer-use-of-uninitialized-value
such as this one seen in Doom:

p_maputl.c: In function 'P_BoxOnLineSide':
p_maputl.c:151:8: warning: use of uninitialized value 'p1' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
  151 |     if (p1 == p2)
      |        ^
  'P_BoxOnLineSide': events 1-5
    |
    |  115 |     int         p1;
    |      |                 ^~
    |      |                 |
    |      |                 (1) region created on stack here
    |      |                 (2) capacity: 4 bytes
    |......
    |  118 |     switch (ld->slopetype)
    |      |     ~~~~~~
    |      |     |
    |      |     (3) following 'default:' branch...
    |......
    |  151 |     if (p1 == p2)
    |      |        ~
    |      |        |
    |      |        (4) ...to here
    |      |        (5) use of uninitialized value 'p1' here
    |

where "ld->slopetype" is a "slopetype_t" enum, and for every value of
that enum the switch has a case that initializes "p1".

gcc/analyzer/ChangeLog:
PR analyzer/105273
* region-model.cc (has_nondefault_case_for_value_p): New.
(has_nondefault_cases_for_all_enum_values_p): New.
(region_model::apply_constraints_for_gswitch): Skip
implicitly-created "default" when switching on an enum
and all enum values have non-default cases.
(rejected_default_case::dump_to_pp): New.
* region-model.h (region_model_context::possibly_tainted_p): New
decl.
(class rejected_default_case): New.
* sm-taint.cc (region_model_context::possibly_tainted_p): New.
* supergraph.cc (switch_cfg_superedge::dump_label_to_pp): Dump
when implicitly_created_default_p.
(switch_cfg_superedge::implicitly_created_default_p): New.
* supergraph.h
(switch_cfg_superedge::implicitly_created_default_p): New decl.

gcc/testsuite/ChangeLog:
PR analyzer/105273
* gcc.dg/analyzer/switch-enum-1.c: New test.
* gcc.dg/analyzer/switch-enum-2.c: New test.
* gcc.dg/analyzer/switch-enum-pr105273-git-vreportf-2.c: New test.
* gcc.dg/analyzer/switch-enum-taint-1.c: New test.
* gcc.dg/analyzer/switch-wrong-enum.c: New test.
* gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_floor.c: New
test.
* gcc.dg/analyzer/torture/switch-enum-pr105273-doom-p_maputl.c:
New test.
* gcc.dg/analyzer/torture/switch-enum-pr105273-git-vreportf-1.c:
New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
21 months agoSmall fix for -fdump-ada-spec
Eric Botcazou [Fri, 13 Jan 2023 21:11:32 +0000 (22:11 +0100)]
Small fix for -fdump-ada-spec

This is needed to support the _Float32 and _Float64 types.

gcc/c-family/
* c-ada-spec.cc (is_float32): New function.
(is_float64): Likewise.
(is_float128): Tweak.
(dump_ada_node) <REAL_TYPE>: Call them to recognize more types.

21 months agoFix PR rtl-optimization/108274
Eric Botcazou [Fri, 13 Jan 2023 21:05:28 +0000 (22:05 +0100)]
Fix PR rtl-optimization/108274

Unlike other IPA passes, the ICF pass can be run at -O0 and some testcases
rely on this in the testsuite.  Now it effectively creates a tail call so
the DF information needs be updated in this case after epilogue creation.

gcc/
PR rtl-optimization/108274
* function.cc (thread_prologue_and_epilogue_insns): Also update the
DF information for calls in a few more cases.

21 months agomodula-2: Handle pass '-v' option to the compiler.
Iain Sandoe [Thu, 12 Jan 2023 23:50:53 +0000 (23:50 +0000)]
modula-2: Handle pass '-v' option to the compiler.

Somehow this setting had been missed, and we really need the verbose
flag to enable useful debug output.

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

* gm2-gcc/m2options.h (M2Options_SetVerbose): Export the
function.
* gm2-lang.cc: Handle OPT_v, passing it to the compiler.
* lang-specs.h: Pass -v to cc1gm2.

21 months agoFix support for atomic loads and stores on hppa.
John David Anglin [Fri, 13 Jan 2023 19:22:49 +0000 (19:22 +0000)]
Fix support for atomic loads and stores on hppa.

This change updates the atomic libcall support to fix the following
issues:

1) A internal compiler error with -fno-sync-libcalls.
2) When sync libcalls are disabled, we don't generate libcalls for
   libatomic.
3) There is no sync libcall support for targets other than linux.
   As a result, non-atomic stores are silently emitted for types
   smaller or equal to the word size.  There are now a few atomic
   libcalls in the libgcc code, so we need sync support on all
   targets.

2023-01-13  John David Anglin  <danglin@gcc.gnu.org>

gcc/ChangeLog:

* config/pa/pa-linux.h (TARGET_SYNC_LIBCALL): Delete define.
* config/pa/pa.cc (pa_init_libfuncs): Use MAX_SYNC_LIBFUNC_SIZE
define.
* config/pa/pa.h (TARGET_SYNC_LIBCALLS): Use flag_sync_libcalls.
(MAX_SYNC_LIBFUNC_SIZE): Define.
(TARGET_CPU_CPP_BUILTINS): Define __SOFTFP__ when soft float is
enabled.
* config/pa/pa.md (atomic_storeqi): Emit __atomic_exchange_1
libcall when sync libcalls are disabled.
(atomic_storehi, atomic_storesi, atomic_storedi): Likewise.
(atomic_loaddi): Emit __atomic_load_8 libcall when sync libcalls
are disabled on 32-bit target.
* config/pa/pa.opt (matomic-libcalls): New option.
* doc/invoke.texi (HPPA Options): Update.

libgcc/ChangeLog:

* config.host (hppa*64*-*-linux*): Adjust tmake_file to use
pa/t-pa64-linux.
(hppa*64*-*-hpux11*): Adjust tmake_file to use pa/t-pa64-hpux
instead of pa/t-hpux and pa/t-pa64.
* config/pa/linux-atomic.c: Define u32 type.
(ATOMIC_LOAD): Define new macro to implement atomic_load_1,
atomic_load_2, atomic_load_4 and atomic_load_8.  Update sync
defines to use atomic_load calls for type.
(SYNC_LOCK_LOAD_2): New macro to implement __sync_lock_load_8.
* config/pa/sync-libfuncs.c: New file.
* config/pa/t-netbsd (LIB2ADD_ST): Define.
* config/pa/t-openbsd (LIB2ADD_ST): Define.
* config/pa/t-pa64-hpux: New file.
* config/pa/t-pa64-linux: New file.

21 months agosched-deps: do not schedule pseudos across calls [PR108117]
Alexander Monakov [Fri, 13 Jan 2023 18:04:02 +0000 (21:04 +0300)]
sched-deps: do not schedule pseudos across calls [PR108117]

Scheduling across calls in the pre-RA scheduler is problematic: we do
not take liveness info into account, and are thus prone to extending
lifetime of a pseudo over the loop, requiring a callee-saved hardreg
or causing a spill.

If current function called a setjmp, lifting an assignment over a call
may be incorrect if a longjmp would happen before the assignment.

Thanks to Jose Marchesi for testing on AArch64.

gcc/ChangeLog:

PR rtl-optimization/108117
PR rtl-optimization/108132
* sched-deps.cc (deps_analyze_insn): Do not schedule across
calls before reload.

gcc/testsuite/ChangeLog:

PR rtl-optimization/108117
PR rtl-optimization/108132
* gcc.dg/pr108117.c: New test.

21 months agolibstdc++: Add <errno.h> to <bits/std_mutex.h>
Jonathan Wakely [Fri, 13 Jan 2023 16:37:57 +0000 (16:37 +0000)]
libstdc++: Add <errno.h> to <bits/std_mutex.h>

This needs to be included explicitly now that we don't include all of
<system_error> here.

libstdc++-v3/ChangeLog:

* include/bits/std_mutex.h: Include <errno.h>.

21 months agoc++: Avoid some false positive -Wfloat-conversion warnings with extended precision...
Jakub Jelinek [Fri, 13 Jan 2023 17:23:57 +0000 (18:23 +0100)]
c++: Avoid some false positive -Wfloat-conversion warnings with extended precision [PR108285]

On the following testcase trunk emits a false positive warning on ia32.
convert_like_internal is there called with type of double and
expr EXCESS_PRECISION_EXPR with float type with long double operand
2.L * (long double) x.
Now, for the code generation we do the right thing, cp_convert
to double from that 2.L * (long double) x, but we call even
cp_convert_and_check with that and that emits the -Wfloat-conversion
warning.  Looking at what the C FE does in this case, it calls
convert_and_check with the EXCESS_PRECISION_EXPR expression rather
than its operand, and essentially uses the operand for code generation
and EXCESS_PRECISION_EXPR itself for warnings.

The following patch does that too for the C++ FE.

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

PR c++/108285
* cvt.cc (cp_convert_and_check): For EXCESS_PRECISION_EXPR
use its operand except that for warning purposes use the original
EXCESS_PRECISION_EXPR.
* call.cc (convert_like_internal): Only look through
EXCESS_PRECISION_EXPR when calling cp_convert, not when calling
cp_convert_and_check.

* g++.dg/warn/pr108285.C: New test.

21 months agoRecalibrate the timeouts for the larger code tests
Gaius Mulley [Fri, 13 Jan 2023 17:17:36 +0000 (17:17 +0000)]
Recalibrate the timeouts for the larger code tests

Some of the larger code tests timeout when -O3 is given.
This patch increase the map and pimlib-base-run-pass tests.

gcc/testsuite/ChangeLog:

* gm2/examples/map/pass/examples-map-pass.exp:
Call gm2_push_timeout 30 before foreach testcase.
Call gm2_pop_timeout after the foreach statement.
* gm2/pimlib/base/run/pass/pimlib-base-run-pass.exp:
Call gm2_push_timeout 20 before foreach testcase.
Call gm2_pop_timeout after the foreach statement.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
21 months agotestsuite: Add another testcase from PR107131
Jakub Jelinek [Fri, 13 Jan 2023 16:37:52 +0000 (17:37 +0100)]
testsuite: Add another testcase from PR107131

This one is hand reduced to problematic code from optimized dump
that used to be miscompiled during combine starting with
r12-303 and fixed with r13-3530 aka PR107172 fix.

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

PR target/107131
* gcc.c-torture/execute/pr107131.c: New test.

21 months agoPR-108136 Add return statement to mc-boot-ch/RTco.cc pge-boot/GRTco.cc
Gaius Mulley [Fri, 13 Jan 2023 16:29:21 +0000 (16:29 +0000)]
PR-108136 Add return statement to mc-boot-ch/RTco.cc pge-boot/GRTco.cc

Clang found an exit path from function with non-void return type
that has missing return statement [missingReturn].

gcc/m2/ChangeLog:

* mc-boot-ch/GRTco.c (RTco_select): Add return 0.
* pge-boot/GRTco.c (RTco_select): Add return 0.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
21 months agoarm: Add cde feature support for Cortex-M55 CPU.
Srinath Parvathaneni [Fri, 13 Jan 2023 15:36:49 +0000 (15:36 +0000)]
arm: Add cde feature support for Cortex-M55 CPU.

This patch adds cde feature (optional) support for Cortex-M55 CPU, please refer
[1] for more details. To use this feature we need to specify +cdecpN
(e.g. -mcpu=cortex-m55+cdecp<N>), where N is the coprocessor number 0 to 7.

gcc/ChangeLog:

2023-01-13  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>

* common/config/arm/arm-common.cc (arm_canon_arch_option_1): Ignore cde
options for -mlibarch.
* config/arm/arm-cpus.in (begin cpu cortex-m55): Add cde options.
* doc/invoke.texi (CDE): Document options for Cortex-M55 CPU.

gcc/testsuite/ChangeLog:

2023-01-13  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>

* gcc.target/arm/multilib.exp: Add multilib tests for Cortex-M55 CPU.

21 months agoReplace flag_strict_flex_arrays with DECL_NOT_FLEXARRAY in middle-end.
Qing Zhao [Fri, 13 Jan 2023 15:08:00 +0000 (15:08 +0000)]
Replace flag_strict_flex_arrays with DECL_NOT_FLEXARRAY in middle-end.

We should not directly check flag_strict_flex_arrays in the
middle end. Instead, check DECL_NOT_FLEXARRAY(array_field_decl) which is set
by C/C++ FEs according to -fstrict-flex-arrays and the corresponding
attribute attached to the array_field.

As a result, We will lose the LEVEL information of -fstrict-flex-arrays in
the middle end. -Wstrict-flex-arrays will not be able to issue such
information. update the testing cases accordingly.

gcc/ChangeLog:

* attribs.cc (strict_flex_array_level_of): Move this function to ...
* attribs.h (strict_flex_array_level_of): Remove the declaration.
* gimple-array-bounds.cc (array_bounds_checker::check_array_ref):
replace the referece to strict_flex_array_level_of with
DECL_NOT_FLEXARRAY.
* tree.cc (component_ref_size): Likewise.

gcc/c/ChangeLog:

* c-decl.cc (strict_flex_array_level_of): ... here.

gcc/testsuite/ChangeLog:

* gcc.dg/Warray-bounds-flex-arrays-1.c: Delete the level information
from the message issued by -Wstrict-flex-arrays.
* gcc.dg/Warray-bounds-flex-arrays-2.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-3.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-4.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-5.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-6.c: Likewise.
* gcc.dg/Wstrict-flex-arrays-2.c: Likewise.
* gcc.dg/Wstrict-flex-arrays-3.c: Likewise.
* gcc.dg/Wstrict-flex-arrays.c: Likewise.

21 months agolibstdc++: Fix a few !HOSTED test regressions
Arsen Arsenović [Tue, 10 Jan 2023 10:03:05 +0000 (11:03 +0100)]
libstdc++: Fix a few !HOSTED test regressions

libstdc++-v3/ChangeLog:

* testsuite/20_util/to_chars/version.cc: Mark hosted-only.
* testsuite/20_util/uses_allocator/lwg3677.cc: Ditto.
* testsuite/20_util/weak_ptr/cons/self_move.cc: Ditto.
* testsuite/std/ranges/adaptors/as_rvalue/1.cc: Replace usage of
std::make_unique with a freestanding-compatible wrapper around
unique_ptr.
* testsuite/21_strings/basic_string_view/operations/contains/char.cc:
Don't test for presence of __cpp_lib_string_contains on !HOSTED.
* testsuite/21_strings/basic_string_view/operations/contains/char/2.cc:
Ditto.
* testsuite/std/ranges/version_c++23.cc: Don't test for presence
of __cpp_lib_ranges in !HOSTED.

21 months agolibstdc++: Enable string_view in freestanding
Arsen Arsenović [Tue, 10 Jan 2023 10:03:04 +0000 (11:03 +0100)]
libstdc++: Enable string_view in freestanding

This enables the default contract handler in freestanding environments,
and, of course, provides freestanding users with string_view.

libstdc++-v3/ChangeLog:

* include/Makefile.am: Install bits/char_traits.h,
std/string_view
* include/Makefile.in: Regenerate.
* include/bits/char_traits.h: Gate hosted-only, wchar-only and
mbstate-only bits behind appropriate #ifs.
* include/std/string_view: Gate <iostream> functionality behind
HOSTED.
* include/std/version: Enable __cpp_lib_constexpr_string_view
and __cpp_lib_starts_ends_with in !HOSTED.
* include/std/ranges: Re-enable __is_basic_string_view on
freestanding, include <string_view> directly.
* include/precompiled/stdc++.h: Include <string_view> when
!HOSTED too.
* testsuite/20_util/function_objects/searchers.cc: Skip testing
boyer_moore searchers on freestanding
* testsuite/21_strings/basic_string_view/capacity/1.cc: Guard
<string>-related tests behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/cons/char/1.cc: Ditto.
* testsuite/21_strings/basic_string_view/cons/char/2.cc: Remove
unused <stdexcept> include.
* testsuite/21_strings/basic_string_view/cons/char/3.cc: Remove
unused <vector> include.
* testsuite/21_strings/basic_string_view/cons/char/range.cc:
Guard <string> related testing behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc:
Guard <stdexcept> related tests behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/element_access/char/1.cc:
Ditto.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc:
Guard <stdexcept> tests behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/operations/contains/char/2.cc:
Enable test on freestanding, guard <stdexcept> bits behind
__STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/operations/substr/char.cc:
Guard <stdexcept> bits behind __STDC_HOSTED__.
* testsuite/21_strings/basic_string_view/operations/substr/wchar_t.cc:
Ditto.

21 months agolibstdc++: Fix Unicode codecvt and add tests [PR86419]
Dimitrij Mijoski [Tue, 10 Jan 2023 12:58:59 +0000 (13:58 +0100)]
libstdc++: Fix Unicode codecvt and add tests [PR86419]

Fixes the conversion from UTF-8 to UTF-16 to properly return partial
instead ok.
Fixes the conversion from UTF-16 to UTF-8 to properly return partial
instead ok.
Fixes the conversion from UTF-8 to UCS-2 to properly return partial
instead error.
Fixes the conversion from UTF-8 to UCS-2 to treat 4-byte UTF-8 sequences
as error just by seeing the leading byte.
Fixes UTF-8 decoding for all codecvts so they detect error at the end of
the input range when the last code point is also incomplete.

libstdc++-v3/ChangeLog:

PR libstdc++/86419
* src/c++11/codecvt.cc (read_utf8_code_point): Correctly detect
errors in incomplete multibyte sequences.
(utf16_in): Remove surrogates parameter. Fix conditions for
returning partial.
(utf16_out): Fix condition for returning partial.
(ucs2_in): Do not pass surrogates argument to utf16_in.
* testsuite/22_locale/codecvt/codecvt_unicode.cc: New test.
* testsuite/22_locale/codecvt/codecvt_unicode.h: New header for
tests.
* testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc: New
test.

21 months agolibstdc++: Fix unintended layout change to std::basic_filebuf [PR108331]
Jonathan Wakely [Thu, 12 Jan 2023 10:40:49 +0000 (10:40 +0000)]
libstdc++: Fix unintended layout change to std::basic_filebuf [PR108331]

GCC 13 has a new implementation of gthr-win32.h which supports C++11
mutexes, threads etc. but this causes an unintended ABI break. The
__gthread_mutex_t type is always used in std::basic_filebuf even in
C++98, so independent of whether C++11 sync primitives work or not.
Because that type changed for the win32 thread model, we have a layout
change in std::basic_filebuf. The member is completely unused, it just
gets passed to the std::__basic_file constructor and ignored. So we
don't need that mutex to actually work, we just need its layout to not
change.

Introduce a new __gthr_win32_legacy_mutex_t struct in gthr-win32.h with
the old layout, and conditionally use that in std::basic_filebuf.

PR libstdc++/108331

libgcc/ChangeLog:

* config/i386/gthr-win32.h (__gthr_win32_legacy_mutex_t): New
struct matching the previous __gthread_mutex_t struct.
(__GTHREAD_LEGACY_MUTEX_T): Define.

libstdc++-v3/ChangeLog:

* config/io/c_io_stdio.h (__c_lock): Define as a typedef for
__GTHREAD_LEGACY_MUTEX_T if defined.

21 months agoarm: unified syntax for libgcc clear_cache
Seija Kijin [Fri, 13 Jan 2023 13:00:39 +0000 (13:00 +0000)]
arm: unified syntax for libgcc clear_cache

The patch to convert all thumb1 code in libgcc to unified syntax
omitted changing all swi instructions to the current name: svc.

libgcc/ChangeLog:

* config/arm/lib1funcs.S (clear_cache): Use SVC to conform to
unified syntax.

21 months agoarm: Don't add crtfastmath.o for -shared
Richard Biener [Fri, 13 Jan 2023 07:51:10 +0000 (08:51 +0100)]
arm: 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/arm/linux-eabi.h (ENDFILE_SPEC): Don't add
crtfastmath.o for -shared.
* config/arm/unknown-elf.h (STARTFILE_SPEC): Likewise.

21 months agoaarch64: Don't add crtfastmath.o for -shared
Richard Biener [Fri, 13 Jan 2023 07:47:59 +0000 (08:47 +0100)]
aarch64: 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/aarch64/aarch64-elf-raw.h (ENDFILE_SPEC): Don't add
crtfastmath.o for -shared.
* config/aarch64/aarch64-freebsd.h (GNU_USER_TARGET_MATHFILE_SPEC):
Likewise.
* config/aarch64/aarch64-linux.h (GNU_USER_TARGET_MATHFILE_SPEC):
Likewise.

21 months agotestsuite: Add testcase for PR that went latent in GCC 13 [PR107131]
Jakub Jelinek [Fri, 13 Jan 2023 10:13:22 +0000 (11:13 +0100)]
testsuite: Add testcase for PR that went latent in GCC 13 [PR107131]

The following testcase is probably latent since r13-3217-gc4d15dddf6b9e.
Adding testcase so that it doesn't silently reappear.

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

PR target/107131
* gcc.dg/pr107131.c: New test.

21 months agoaarch64: Fix DWARF frame register sizes for predicates
Richard Sandiford [Fri, 13 Jan 2023 10:01:32 +0000 (10:01 +0000)]
aarch64: Fix DWARF frame register sizes for predicates

Jakub pointed out that __builtin_init_dwarf_reg_size_table
set the size of predicate registers to their current runtime
size when compiled with +sve, but to 8 bytes otherwise.
As explained in the comment, both behaviours are wrong.
Predicates change size with VL and should never need to be
restored during unwinding.

In contrast, the call-saved FP&SIMD frame registers are 8 bytes
(even though the hardware registers are at least 16 bytes) and
the call-clobbered registers have zero size.  A zero size seems
correct for predicates too.

gcc/
* config/aarch64/aarch64.cc (aarch64_dwarf_frame_reg_mode): New
function.
(TARGET_DWARF_FRAME_REG_MODE): Define.

gcc/testsuite/
* gcc.target/aarch64/dwarf_reg_size_1.c: New test.
* gcc.target/aarch64/dwarf_reg_size_2.c: Likewise.

21 months agoaarch64: Don't update EH info when folding [PR107209]
Richard Biener [Fri, 13 Jan 2023 10:01:32 +0000 (10:01 +0000)]
aarch64: Don't update EH info when folding [PR107209]

The AArch64 folders tried to update EH info on the fly, bypassing
the folder's attempts to remove dead EH edges later.  This triggered
an ICE when folding a potentially-trapping call to a constant.

gcc/
PR target/107209
* config/aarch64/aarch64.cc (aarch64_gimple_fold_builtin): Don't
update EH info on the fly.

gcc/testsuite/
* gcc.target/aarch64/pr107209.c: New test.

Co-Authored-By: Richard Biener <rguenther@suse.de>
21 months agotree-optimization/108387 - ICE with VN handling of x << C as x * (1<<C)
Richard Biener [Fri, 13 Jan 2023 07:37:24 +0000 (08:37 +0100)]
tree-optimization/108387 - ICE with VN handling of x << C as x * (1<<C)

The following fixes unexpected simplification of x << C as
x * (1<<C) to a constant.

PR tree-optimization/108387
* tree-ssa-sccvn.cc (visit_nary_op): Check for SSA_NAME
value before inserting expression into the tables.

* gcc.dg/pr108387.c: New testcase.

21 months agoSync LTO type_for_mode with c-family/
Richard Biener [Fri, 13 Jan 2023 07:11:53 +0000 (08:11 +0100)]
Sync LTO type_for_mode with c-family/

The following adds _FloatN mode support to the LTO copy of
c_common_type_for_mode and also implements the fix for PR94072.

gcc/lto/
* lto-lang.cc (lto_type_for_mode): Sync with
c_common_type_for_mode.

21 months agotestsuite: extend timeout into all gm2 tests
Gaius Mulley [Fri, 13 Jan 2023 01:08:43 +0000 (01:08 +0000)]
testsuite: extend timeout into all gm2 tests

Add timeout capability to gm2-torture.exp.  Also add a simple
gm2_push_timeout/gm2_pop timeout facility and calibrate all
tests to use the default of 10 seconds.  15 seconds (for the
coroutine tests) and 60 seconds for whole program optimization.

gcc/testsuite/ChangeLog:

* gm2/coroutines/pim/run/pass/coroutines-pim-run-pass.exp
(timeout-dg.exp): Load.
Call gm2_push_timeout 15.
Call gm2_pop_timeout at the end.
* gm2/link/min/pass/link-min-pass.exp: Set path
argument to "".
* gm2/switches/whole-program/pass/run/switches-whole-program-pass-run.exp:
Call gm2_push_timeout 60.
Call gm2_pop_timeout at the end.
* lib/gm2-torture.exp (gm2_previous_timeout): Set to 10 or
individual_timeout.
Configure dejagnu to timeout for 10 seconds.
(gm2_push_timeout): New proc.
(gm2_pop_timeout): New proc.
* lib/gm2.exp (gm2_previous_timeout): Set to 10 or
individual_timeout.
Configure dejagnu to timeout for 10 seconds.
(gm2_push_timeout): New proc.
(gm2_pop_timeout): New proc.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
21 months agoDaily bump.
GCC Administrator [Fri, 13 Jan 2023 00:17:18 +0000 (00:17 +0000)]
Daily bump.

21 months agolibstdc++: Fix exports for IEEE128 versions of __try_use_facet [PR108327]
Jonathan Wakely [Thu, 12 Jan 2023 22:35:30 +0000 (22:35 +0000)]
libstdc++: Fix exports for IEEE128 versions of __try_use_facet [PR108327]

The new symbols need to be exported, as well as some of the
std::locale::facet::id globals, which are not new but were presumably
not needed by any inline functions before now.

libstdc++-v3/ChangeLog:

PR libstdc++/108327
* config/os/gnu-linux/ldbl-extra.ver (GLIBCXX_LDBL_3.4.31):
Export __try_use_facet specializations for facets in namespace
__gnu_cxx_ldbl128.
* config/os/gnu-linux/ldbl-ieee128-extra.ver
(GLIBCXX_IEEE128_3.4.31): Likewise for facets in namespace
__gnu_cxx_ieee128.
* testsuite/util/testsuite_abi.cc: Add to lists of known and
latest versions.

21 months agolibstdc++: Do not include <system_error> in concurrency headers
Jonathan Wakely [Thu, 12 Jan 2023 13:03:01 +0000 (13:03 +0000)]
libstdc++: Do not include <system_error> in concurrency headers

The <condition_variable>, <mutex>, and <shared_mutex> headers use
std::errc constants, but don't use std::system_error itself. They only
use the __throw_system_error(int) function, which is defined in
<bits/functexcept.h>.

By including the header for the errc constants instead of the whole of
<system_error> we avoid depending on the whole std::string definition.

libstdc++-v3/ChangeLog:

* include/bits/std_mutex.h: Remove <system_error> include.
* include/std/condition_variable: Add <bits/error_constants.h>
include.
* include/std/mutex: Likewise.
* include/std/shared_mutex: Likewise.

21 months agoTestsuite: use same timeout for gm2 as other front-ends
Gaius Mulley [Thu, 12 Jan 2023 23:48:48 +0000 (23:48 +0000)]
Testsuite: use same timeout for gm2 as other front-ends

Committing a patch authored by: Jason Merrill <jason@redhat.com>
which enables timeouts in the gm2 regression script library gm2.exp.

gcc/testsuite/ChangeLog:

* lib/gm2.exp: Use timeout.exp.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
21 months agoAdd -fno-exceptions to gcc/testsuite/lib/gm2.exp
Gaius Mulley [Thu, 12 Jan 2023 23:15:04 +0000 (23:15 +0000)]
Add -fno-exceptions to gcc/testsuite/lib/gm2.exp

The gm2 minimal libraries do not have exception handler
capability.  Therefore we want the front end to suppress
generation of runtime exception code.

gcc/testsuite/ChangeLog:

* lib/gm2.exp (gm2_init_min): Append -fno-exceptions
to args.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
21 months agoPR tree-optimization/92342: Optimize b & -(a==c) in match.pd
Roger Sayle [Thu, 12 Jan 2023 21:47:40 +0000 (21:47 +0000)]
PR tree-optimization/92342: Optimize b & -(a==c) in match.pd

This patch is an update/tweak of Andrew Pinski's two patches for
PR tree-optimization/92342, that were originally posted by in November:
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585111.html
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585112.html

Technically, the first of those was approved by Richard Biener, though
never committed, and my first thought was to simply push it for Andrew,
but the review of the second piece expressed concerns over comparisons
in non-integral modes, where the result may not be zero-one valued.
Indeed both transformations misbehave in the presence of vector mode
comparisons (these transformations are already implemented for
vec_cond elsewhere in match.pd), so my minor contribution is to limit
these new transformations to scalars, by testing that both the operands
and results are INTEGRAL_TYPE_P.

2023-01-12  Andrew Pinski  <apinski@marvell.com>
    Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog:
PR tree-optimization/92342
* match.pd ((m1 CMP m2) * d -> (m1 CMP m2) ? d : 0):
Use tcc_comparison and :c for the multiply.
(b & -(a CMP c) -> (a CMP c)?b:0): New pattern.

gcc/testsuite/ChangeLog:
PR tree-optimization/92342
* gcc.dg/tree-ssa/andnegcmp-1.c: New test.
* gcc.dg/tree-ssa/andnegcmp-2.c: New test.
* gcc.dg/tree-ssa/multcmp-1.c: New test.
* gcc.dg/tree-ssa/multcmp-2.c: New test.

21 months agolibstdc++: Extend max_align_t special case to 64-bit HP-UX [PR77691]
Jonathan Wakely [Thu, 12 Jan 2023 10:58:13 +0000 (10:58 +0000)]
libstdc++: Extend max_align_t special case to 64-bit HP-UX [PR77691]

GCC's std::max_align_t doesn't agree with the system malloc on HP-UX, so
generalize the current hack for Solaris to apply to that target too.

libstdc++-v3/ChangeLog:

PR libstdc++/77691
* include/experimental/memory_resource
(_GLIBCXX_MAX_ALIGN_MATCHES_MALLOC): Define.
(do_allocate, do_deallocate): Check it.
* testsuite/experimental/memory_resource/new_delete_resource.cc:
Relax expected behaviour for 64-bit hppa-hp-hpux11.11.

21 months agolibstdc++: Update shared library version history in manual
Jonathan Wakely [Thu, 12 Jan 2023 10:39:28 +0000 (10:39 +0000)]
libstdc++: Update shared library version history in manual

libstdc++-v3/ChangeLog:

* doc/xml/manual/abi.xml: Add latest library versions.
* doc/html/manual/abi.html: Regenerate.

21 months agolibstdc++: Remove _Alloc_node instance in _Rb_tree [PR107189]
François Dumont [Wed, 12 Oct 2022 17:34:01 +0000 (19:34 +0200)]
libstdc++: Remove _Alloc_node instance in _Rb_tree [PR107189]

libstdc++-v3/ChangeLog:

PR libstdc++/107189
* include/bits/stl_tree.h (_Rb_tree<>::_M_insert_range_equal): Remove
unused _Alloc_node instance.

21 months agoaarch64: Fix bit-field alignment in param passing [PR105549]
Christophe Lyon [Fri, 25 Nov 2022 13:35:11 +0000 (13:35 +0000)]
aarch64: Fix bit-field alignment in param passing [PR105549]

While working on enabling DFP for AArch64, I noticed new failures in
gcc.dg/compat/struct-layout-1.exp (t028) which were not actually
caused by DFP types handling. These tests are generated during 'make
check' and enabling DFP made generation different (not sure if new
non-DFP tests are generated, or if existing ones are generated
differently, the tests in question are huge and difficult to compare).

Anyway, I reduced the problem to what I attach at the end of the new
gcc.target/aarch64/aapcs64/va_arg-17.c test and rewrote it in the same
scheme as other va_arg* AArch64 tests.  Richard Sandiford further
reduced this to a non-vararg function, added as a second testcase.

This is a tough case mixing bit-fields and alignment, where
aarch64_function_arg_alignment did not follow what its descriptive
comment says: we want to use the natural alignment of the bit-field
type only if the user didn't reduce the alignment for the bit-field
itself.

The patch also adds a comment and assert that would help someone who
has to look at this area again.

The fix would be very small, except that this introduces a new ABI
break, and we have to warn about that.  Since this actually fixes a
problem introduced in GCC 9.1, we keep the old computation to detect
when we now behave differently.

This patch adds two new tests (va_arg-17.c and
pr105549.c). va_arg-17.c contains the reduced offending testcase from
struct-layout-1.exp for reference.  We update some tests introduced by
the previous patch, where parameters with bit-fields and packed
attribute now emit a different warning.

2022-11-28  Christophe Lyon  <christophe.lyon@arm.com>
    Richard Sandiford  <richard.sandiford@arm.com>

gcc/
PR target/105549
* config/aarch64/aarch64.cc (aarch64_function_arg_alignment):
Check DECL_PACKED for bitfield.
(aarch64_layout_arg): Warn when parameter passing ABI changes.
(aarch64_function_arg_boundary): Do not warn here.
(aarch64_gimplify_va_arg_expr): Warn when parameter passing ABI
changes.

gcc/testsuite/
PR target/105549
* gcc.target/aarch64/bitfield-abi-warning-align16-O2.c: Update.
* gcc.target/aarch64/bitfield-abi-warning-align16-O2-extra.c: Update.
* gcc.target/aarch64/bitfield-abi-warning-align32-O2.c: Update.
* gcc.target/aarch64/bitfield-abi-warning-align32-O2-extra.c: Update.
* gcc.target/aarch64/aapcs64/va_arg-17.c: New test.
* gcc.target/aarch64/pr105549.c: New test.
* g++.target/aarch64/bitfield-abi-warning-align16-O2.C: Update.
* g++.target/aarch64/bitfield-abi-warning-align16-O2-extra.C: Update.
* g++.target/aarch64/bitfield-abi-warning-align32-O2.C: Update.
* g++.target/aarch64/bitfield-abi-warning-align32-O2-extra.C: Update.

21 months agoaarch64: fix warning emission for ABI break since GCC 9.1
Christophe Lyon [Tue, 14 Jun 2022 21:08:33 +0000 (21:08 +0000)]
aarch64: fix warning emission for ABI break since GCC 9.1

While looking at PR 105549, which is about fixing the ABI break
introduced in GCC 9.1 in parameter alignment with bit-fields, we
noticed that the GCC 9.1 warning is not emitted in all the cases where
it should be.  This patch fixes that and the next patch in the series
fixes the GCC 9.1 break.

We split this into two patches since patch #2 introduces a new ABI
break starting with GCC 13.1.  This way, patch #1 can be back-ported
to release branches if needed to fix the GCC 9.1 warning issue.

The main idea is to add a new global boolean that indicates whether
we're expanding the start of a function, so that aarch64_layout_arg
can emit warnings for callees as well as callers.  This removes the
need for aarch64_function_arg_boundary to warn (with its incomplete
information).  However, in the first patch there are still cases where
we emit warnings were we should not; this is fixed in patch #2 where
we can distinguish between GCC 9.1 and GCC.13.1 ABI breaks properly.

The fix in aarch64_function_arg_boundary (replacing & with &&) looks
like an oversight of a previous commit in this area which changed
'abi_break' from a boolean to an integer.

We also take the opportunity to fix the comment above
aarch64_function_arg_alignment since the value of the abi_break
parameter was changed in a previous commit, no longer matching the
description.

2022-11-28  Christophe Lyon  <christophe.lyon@arm.com>
    Richard Sandiford  <richard.sandiford@arm.com>

gcc/ChangeLog:

* config/aarch64/aarch64.cc (aarch64_function_arg_alignment): Fix
comment.
(aarch64_layout_arg): Factorize warning conditions.
(aarch64_function_arg_boundary): Fix typo.
* function.cc (currently_expanding_function_start): New variable.
(expand_function_start): Handle
currently_expanding_function_start.
* function.h (currently_expanding_function_start): Declare.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/bitfield-abi-warning-align16-O2.c: New test.
* gcc.target/aarch64/bitfield-abi-warning-align16-O2-extra.c: New
test.
* gcc.target/aarch64/bitfield-abi-warning-align32-O2.c: New test.
* gcc.target/aarch64/bitfield-abi-warning-align32-O2-extra.c: New
test.
* gcc.target/aarch64/bitfield-abi-warning-align8-O2.c: New test.
* gcc.target/aarch64/bitfield-abi-warning.h: New test.
* g++.target/aarch64/bitfield-abi-warning-align16-O2.C: New test.
* g++.target/aarch64/bitfield-abi-warning-align16-O2-extra.C: New
test.
* g++.target/aarch64/bitfield-abi-warning-align32-O2.C: New test.
* g++.target/aarch64/bitfield-abi-warning-align32-O2-extra.C: New
test.
* g++.target/aarch64/bitfield-abi-warning-align8-O2.C: New test.
* g++.target/aarch64/bitfield-abi-warning.h: New test.

21 months agotree-optimization/99412 - reassoc and reduction chains
Richard Biener [Thu, 12 Jan 2023 10:18:22 +0000 (11:18 +0100)]
tree-optimization/99412 - reassoc and reduction chains

With -ffast-math we end up associating reduction chains and break
them - this is because of old code that tries to rectify reductions
into a shape likened by the vectorizer.  Nowadays the rank compute
produces correct association for reduction chains and the vectorizer
has robust support to fall back to a regular reductions (via
reduction path) when it turns out to be not a proper reduction chain.

So this patch removes the special code in reassoc which makes
the TSVC s352 vectorized with -Ofast (it is already without
-ffast-math).

PR tree-optimization/99412
* tree-ssa-reassoc.cc (is_phi_for_stmt): Remove.
(swap_ops_for_binary_stmt): Remove reduction handling.
(rewrite_expr_tree_parallel): Adjust.
(reassociate_bb): Likewise.
* tree-parloops.cc (build_new_reduction): Handle MINUS_EXPR.

* gcc.dg/vect/pr99412.c: New testcase.
* gcc.dg/tree-ssa/reassoc-47.c: Adjust comment.
* gcc.dg/tree-ssa/reassoc-48.c: Remove.

21 months agoxtensa: Optimize ctzsi2 and ffssi2 a bit
Takayuki 'January June' Suwa [Thu, 12 Jan 2023 04:26:42 +0000 (13:26 +0900)]
xtensa: Optimize ctzsi2 and ffssi2 a bit

This patch saves one byte when the Code Density Option is enabled,

gcc/ChangeLog:

* config/xtensa/xtensa.md (ctzsi2, ffssi2):
Rearrange the emitting codes.

21 months agoxtensa: Tune "*btrue" insn pattern
Takayuki 'January June' Suwa [Thu, 12 Jan 2023 04:25:58 +0000 (13:25 +0900)]
xtensa: Tune "*btrue" insn pattern

This branch instruction has short encoding if EQ/NE comparison against
immediate zero when the Code Density Option is enabled, but its "length"
attribute was only for normal encoding.  This patch fixes it.

This patch also prevents undesireable replacement the comparison immediate
zero of the instruction (short encoding, as mentioned above) with a
register that has value of zero (normal encoding) by the postreload pass.

gcc/ChangeLog:

* config/xtensa/xtensa.md (*btrue):
Correct value of the attribute "length" that depends on
TARGET_DENSITY and operands, and add '?' character to the register
constraint of the compared operand.

21 months agolibstdc++: Use lock-free type for __platform_wait_t
Jonathan Wakely [Thu, 5 Jan 2023 20:23:26 +0000 (20:23 +0000)]
libstdc++: Use lock-free type for __platform_wait_t

For non-futex targets the __platform_wait_t type is currently uint64_t,
but that requires a lock in libatomic for some 32-bit targets. We don't
really need a 64-bit type, so use unsigned long if that is lock-free,
and int otherwise. This should mean it's lock-free on a wider set of
targets.

libstdc++-v3/ChangeLog:

* include/bits/atomic_wait.h (__detail::__platform_wait_t):
Define as unsigned long if always lock-free, and unsigned int
otherwise.

21 months agoFortran/OpenMP: Reject non-scalar 'holds' expr in 'omp assume(s)' [PR107706]
Tobias Burnus [Thu, 12 Jan 2023 10:43:37 +0000 (11:43 +0100)]
Fortran/OpenMP: Reject non-scalar 'holds' expr in 'omp assume(s)' [PR107706]

gcc/fortran/ChangeLog:

PR fortran/107706
* openmp.cc (gfc_resolve_omp_assumptions): Reject nonscalars.

gcc/testsuite/ChangeLog:

PR fortran/107706
* gfortran.dg/gomp/assume-2.f90: Update dg-error.
* gfortran.dg/gomp/assumes-2.f90: Likewise.
* gfortran.dg/gomp/assume-5.f90: New test.

21 months agocheck hash table counts at expand
Alexandre Oliva [Thu, 12 Jan 2023 03:29:33 +0000 (00:29 -0300)]
check hash table counts at expand

Add cheap verification of element and deleted entry counts during
expand and hash verify.

for  gcc/ChangeLog

* hash-table.h (expand): Check elements and deleted counts.
(verify): Likewise.

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

21 months agoconfig-list.mk: Remove obsolete FreeBSD targets
Gerald Pfeifer [Thu, 12 Jan 2023 00:00:40 +0000 (01:00 +0100)]
config-list.mk: Remove obsolete FreeBSD targets

ia64-freebsd is officially dead, and sparc64-freebsd has not been able
to build GCC for half a dozen years (or so) and is essentially end of
life.

The default per gcc/config/i386/freebsd.h has been i586 for a while,
so i486-freebsd can go as well. (We still have i686-freebsd.)

contrib/ChangeLog:

* config-list.mk: Remove i486-freebsd4, ia64-freebsd6, and
sparc64-freebsd6.

21 months agopreprocessor: Don't register pragmas in directives-only mode [PR108244]
Lewis Hyatt [Thu, 29 Dec 2022 21:55:21 +0000 (16:55 -0500)]
preprocessor: Don't register pragmas in directives-only mode [PR108244]

libcpp's directives-only mode does not expect deferred pragmas to be
registered, but to date the c-family registration process has not checked for
this case. That issue became more visible since r13-1544, which added the
commonly used GCC diagnostic pragmas to the set of those registered in
preprocessing modes. Fix it by checking for directives-only mode in
c-family/c-pragma.cc.

gcc/c-family/ChangeLog:

PR preprocessor/108244
* c-pragma.cc (c_register_pragma_1): Don't attempt to register any
deferred pragmas if -fdirectives-only.
(init_pragma): Likewise.

gcc/testsuite/ChangeLog:

* c-c++-common/cpp/pr108244-1.c: New test.
* c-c++-common/cpp/pr108244-2.c: New test.
* c-c++-common/gomp/pr108244-3.c: New test.

21 months agoanalyzer: fix leak false positives on "*UNKNOWN = PTR;" [PR108252]
David Malcolm [Wed, 11 Jan 2023 21:27:06 +0000 (16:27 -0500)]
analyzer: fix leak false positives on "*UNKNOWN = PTR;" [PR108252]

PR analyzer/108252 reports a false positive from -Wanalyzer-malloc-leak on
code like this:

  *ptr_ptr = strdup(EXPR);

where ptr_ptr is an UNKNOWN_VALUE.

When we handle:
  *UNKNOWN = PTR;
store::set_value normally marks *PTR as having escaped, and this means
we don't report PTR as leaking when the last usage of PTR is lost.

However this only works for cases where PTR is a region_svalue.
In the example in the bug, it's a conjured_svalue, rather than a
region_svalue.  A similar problem can arise for FDs, which aren't
pointers.

This patch fixes the bug by updating store::set_value to mark any
values stored via *UNKNOWN = VAL as not leaking.

Additionally, sm-malloc.cc's known_allocator_p hardcodes strdup and
strndup as allocators (and thus transitioning their result to
"unchecked"), but we don't implement known_functions for these, leading
to the LHS being a CONJURED_SVALUE, rather than a region_svalue to a
heap-allocated region.  A similar issue happens with functions marked
with __attribute__((malloc)).  As part of a "belt and braces" fix, the
patch also updates the handling of these functions, so that they use
heap-allocated regions.

gcc/analyzer/ChangeLog:
PR analyzer/108252
* kf.cc (class kf_strdup): New.
(class kf_strndup): New.
(register_known_functions): Register them.
* region-model.cc (region_model::on_call_pre): Use
&HEAP_ALLOCATED_REGION for the default result of an external
function with the "malloc" attribute, rather than CONJURED_SVALUE.
(region_model::get_or_create_region_for_heap_alloc): Allow
"size_in_bytes" to be NULL.
* store.cc (store::set_value): When handling *UNKNOWN = VAL,
mark VAL as "maybe bound".

gcc/testsuite/ChangeLog:
PR analyzer/108252
* gcc.dg/analyzer/attr-malloc-pr108252.c: New test.
* gcc.dg/analyzer/fd-leak-pr108252.c: New test.
* gcc.dg/analyzer/flex-with-call-summaries.c: Remove xfail from
warning false +ve directives.
* gcc.dg/analyzer/pr103217-2.c: Add -Wno-analyzer-too-complex.
* gcc.dg/analyzer/pr103217-3.c: Likewise.
* gcc.dg/analyzer/strdup-pr108252.c: New test.
* gcc.dg/analyzer/strndup-pr108252.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
21 months agoc: Don't emit DEBUG_BEGIN_STMTs for K&R function argument declarations [PR105972]
Jakub Jelinek [Wed, 11 Jan 2023 21:18:42 +0000 (22:18 +0100)]
c: Don't emit DEBUG_BEGIN_STMTs for K&R function argument declarations [PR105972]

K&R function parameter declarations are handled by calling
recursively c_parser_declaration_or_fndef in a loop, where each such
call will add_debug_begin_stmt at the start.
Now, if the K&R function definition is not a nested function,
building_stmt_list_p () is false and so we don't emit the DEBUG_BEGIN_STMTs
anywhere, but if it is a nested function, we emit it in the containing
function at the point of the nested function definition.
As the following testcase shows, it can cause ICEs if the containing
function has var-tracking disabled but nested function has them enabled,
as the DEBUG_BEGIN_STMTs are added to the containing function which
shouldn't have them but MAY_HAVE_DEBUG_MARKER_STMTS is checked already
for the nested function, or just wrong experience in the debugger.

The following patch ensures we don't emit any such DEBUG_BEGIN_STMTs for the
K&R function parameter declarations even in nested functions.

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

PR c/105972
* c-parser.cc (c_parser_declaration_or_fndef): Disable debug non-bind
markers for K&R function parameter declarations of nested functions.

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

21 months agoPR tree-optimization/71343: Value number X<<2 as X*4.
Roger Sayle [Wed, 11 Jan 2023 16:54:58 +0000 (16:54 +0000)]
PR tree-optimization/71343: Value number X<<2 as X*4.

This patch is the second part of a fix for PR tree-optimization/71343,
that implements Richard Biener's suggestion of using tree-ssa's value
numbering instead of match.pd.  The change is that when assigning a
value number for the expression X<<C, we actually look-up or insert
the value number for the multiplication X*(1<<C).  This elegantly
handles the fact that we (intentionally) don't canonicalize these as
equivalent in GIMPLE, and the optimization/equivalence in PR 71343 now
happens by (tree-ssa SCCVN) magic.

2023-01-11  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR tree-optimization/71343
* tree-ssa-sccvn.cc (visit_nary_op) <case LSHIFT_EXPR>: Make
the value number of the expression X << C the same as the value
number for the multiplication X * (1<<C).

gcc/testsuite/ChangeLog
PR tree-optimization/71343
* gcc.dg/pr71343-2.c: New test case.

21 months agobpf: correct bpf_print_operand for floats [PR108293]
David Faust [Tue, 10 Jan 2023 18:53:12 +0000 (10:53 -0800)]
bpf: correct bpf_print_operand for floats [PR108293]

The existing logic in bpf_print_operand was only correct for integral
CONST_DOUBLEs, and emitted garbage for floating point modes. Fix it so
floating point mode operands are correctly handled.

PR target/108293

gcc/

* config/bpf/bpf.cc (bpf_print_operand): Correct handling for
floating point modes.

gcc/testsuite/

* gcc.target/bpf/double-1.c: New test.
* gcc.target/bpf/double-2.c: New test.
* gcc.target/bpf/float-1.c: New test.

21 months agoFix problematic interaction between bitfields, unions, SSO and SRA
Eric Botcazou [Wed, 11 Jan 2023 14:58:47 +0000 (15:58 +0100)]
Fix problematic interaction between bitfields, unions, SSO and SRA

The handling of bitfields by the SRA pass is peculiar and this must be taken
into account to support the scalar_storage_order attribute.

gcc/
PR tree-optimization/108199
* tree-sra.cc (sra_modify_expr): Deal with reverse storage order
for bit-field references.

gcc/testsuite/
* gcc.dg/sso-17.c: New test.

21 months agors6000/test: Make ppc-fortran.exp only available for PowerPC target
Kewen Lin [Wed, 11 Jan 2023 12:59:24 +0000 (06:59 -0600)]
rs6000/test: Make ppc-fortran.exp only available for PowerPC target

When testing one patch which adds a fortran test case into
test bucket powerpc/ppc-fortran/, I found one unexpected
failure on a non-PowerPC target.  It's due to that
ppc-fortran.exp does not exit early if the testing target
isn't a PowerPC target.  This patch is to make it exit
immediately if the testing target isn't a PowerPC target.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/ppc-fortran/ppc-fortran.exp: Exit immediately if
the testing target isn't a PowerPC target.

21 months agors6000: Make P10_FUSION honour tuning setting
Kewen Lin [Wed, 11 Jan 2023 12:59:08 +0000 (06:59 -0600)]
rs6000: Make P10_FUSION honour tuning setting

We noticed this issue when Segher reviewed the patch for
PR104024.  When there is no explicit setting for option
-mpower10-fusion, we enable OPTION_MASK_P10_FUSION for
TARGET_POWER10.  But it's not right, it should honour
tuning setting instead.

This patch is to fix it accordingly, it's bootstrapped
, and regtested on powerpc64-linux-gnu P8 and
powerpc64le-linux-gnu P9.

But on powerpc64le-linux-gnu P10 it had one regression
failure against the test case gcc.target/powerpc/pr105586.c.
I looked into it and confirmed that a latent bug was
exposed and filed one separated bug PR108273 instead.

gcc/ChangeLog:

* config/rs6000/rs6000.cc (rs6000_option_override_internal): Make
OPTION_MASK_P10_FUSION implicit setting honour Power10 tuning setting.
* config/rs6000/rs6000-cpus.def (ISA_3_1_MASKS_SERVER): Remove
OPTION_MASK_P10_FUSION.

21 months agotree-optimization/107767 - not profitable switch conversion
Richard Biener [Mon, 9 Jan 2023 08:42:22 +0000 (09:42 +0100)]
tree-optimization/107767 - not profitable switch conversion

When the CFG has not merged equal PHI defs in a switch stmt the
cost model from switch conversion gets off and we prefer a
jump table over branches.  The following fixes that by recording
cases that will be merged later and more appropriately counting
unique values.

PR tree-optimization/107767
* tree-cfgcleanup.cc (phi_alternatives_equal): Export.
* tree-cfgcleanup.h (phi_alternatives_equal): Declare.
* tree-switch-conversion.cc (switch_conversion::collect):
Count unique non-default targets accounting for later
merging opportunities.

* gcc.dg/tree-ssa/pr107767.c: New testcase.

21 months agotestsuite: Enable pr108308.c test on all int32 targets [PR108308]
Jakub Jelinek [Wed, 11 Jan 2023 12:06:14 +0000 (13:06 +0100)]
testsuite: Enable pr108308.c test on all int32 targets [PR108308]

This test seems to rely on 32-bit int (and uses a wider constant
which shouldn't fit into int), I've initially enabled it on ilp32+lp64
target, but apparently it works on llp64 too, so I've changed it to
int32.

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

PR target/108308
* gcc.dg/pr108308.c: Use int32 target rather than { ilp32 || lp64 }.

21 months agoswitch expansion: limit JT growth param values
Martin Liska [Wed, 28 Dec 2022 08:11:40 +0000 (09:11 +0100)]
switch expansion: limit JT growth param values

Currently, one can request a huge jump table creation which
leads to a non-sensual huge output. Moreover, use auto_vec rather
than a stack-allocated array.

PR middle-end/107976

gcc/ChangeLog:

* params.opt: Limit JT params.
* stmt.cc (emit_case_dispatch_table): Use auto_vec.

21 months agotree-optimization/108352 - FSM threads creating irreducible loops
Richard Biener [Wed, 11 Jan 2023 11:07:16 +0000 (12:07 +0100)]
tree-optimization/108352 - FSM threads creating irreducible loops

The following relaxes a heuristic that prevents creating irreducible
loops from FSM threads not covering multi-way branches.  Instead of
allowing threads that adhere to

      && (n_insns * (unsigned) param_fsm_scale_path_stmts
          > (m_path.length () *
             (unsigned) param_fsm_scale_path_blocks))

with reasoning "We also consider it worth creating an irreducible inner loop if
the number of copied statement is low relative to the length of the path --
in that case there's little the traditional loop optimizer would have done
anyway, so an irreducible loop is not so bad." that I cannot make much
sense of the following patch changes that to only allow those after
loop optimization and when they are (scaled) short:

      && (!(cfun->curr_properties & PROP_loop_opts_done)
          || (m_n_insns * param_fsm_scale_path_stmts
              >= param_max_jump_thread_duplication_stmts)))

This allows us to get rid of --param fsm-scale-path-blocks which
previous to the bisected revision allowed an enlarged path covering
the original allowance (but we do not consider that enlarged path
now because enlarging it doesn't add any information).

PR tree-optimization/108352
* tree-ssa-threadbackward.cc
(back_threader_profitability::profitable_path_p): Adjust
heuristic that allows non-multi-way branch threads creating
irreducible loops.
* doc/invoke.texi (--param fsm-scale-path-blocks): Remove.
(--param fsm-scale-path-stmts): Adjust.
* params.opt (--param=fsm-scale-path-blocks=): Remove.
(-param=fsm-scale-path-stmts=): Adjust description.

* gcc.dg/tree-ssa/ssa-thread-21.c: New testcase.
* gcc.dg/tree-ssa/vrp46.c: Remove --param fsm-scale-path-blocks=1.

21 months agotree-optimization/108353 - copyprop iteration order
Richard Biener [Wed, 11 Jan 2023 08:32:36 +0000 (09:32 +0100)]
tree-optimization/108353 - copyprop iteration order

After recent improvements to copyprop to catch more constants
it shows that the current iteration order prefering forward
progress over iterating doesn't make much sense for an SSA
propagator.  The following instead first iterates cycles which
makes sure to not start with optimistically constant PHIs out
of cycles that optimistically do not exit.

PR tree-optimization/108353
* tree-ssa-propagate.cc (cfg_blocks_back, ssa_edge_worklist_back):
Remove.
(add_ssa_edge): Simplify.
(add_control_edge): Likewise.
(ssa_prop_init): Likewise.
(ssa_prop_fini): Likewise.
(ssa_propagation_engine::ssa_propagate): Likewise.

* gcc.dg/tree-ssa/ssa-copyprop-3.c: New testcase.

21 months agoIBM zSystems: Use NAND instruction to implement bit not
Andreas Krebbel [Wed, 11 Jan 2023 10:17:42 +0000 (11:17 +0100)]
IBM zSystems: Use NAND instruction to implement bit not

gcc/ChangeLog:

* config/s390/s390.md (*not<mode>): New pattern.

gcc/testsuite/ChangeLog:

* gcc.target/s390/not.c: New test.

21 months agofortran: Fix up function types for realloc and sincos{,f,l} builtins [PR108349]
Jakub Jelinek [Wed, 11 Jan 2023 09:40:54 +0000 (10:40 +0100)]
fortran: Fix up function types for realloc and sincos{,f,l} builtins [PR108349]

As reported in the PR, the FUNCTION_TYPE for __builtin_realloc in the
Fortran FE is wrong since r0-100026-gb64fca63690ad which changed
-  tmp = tree_cons (NULL_TREE, pvoid_type_node, void_list_node);
-  tmp = tree_cons (NULL_TREE, size_type_node, tmp);
-  ftype = build_function_type (pvoid_type_node, tmp);
+  ftype = build_function_type_list (pvoid_type_node,
+                                    size_type_node, pvoid_type_node,
+                                    NULL_TREE);
   gfc_define_builtin ("__builtin_realloc", ftype, BUILT_IN_REALLOC,
                      "realloc", false);
The return type is correct, void *, but the first argument should be
void * too and only second one size_t, while the above change changed
realloc to be void *__builtin_realloc (size_t, void *);
I went through all other changes from that commit and found that
__builtin_sincos{,f,l} got broken as well, instead of the former
void __builtin_sincos{,f,l} (ftype, ftype *, ftype *);
where ftype is {double,float,long double} it is now incorrectly
void __builtin_sincos{,f,l} (ftype *, ftype *);

The following patch fixes that, plus some formatting issues around
the spots I've changed.

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

PR fortran/108349
* f95-lang.cc (gfc_init_builtin_function): Fix up function types
for BUILT_IN_REALLOC and BUILT_IN_SINCOS{F,,L}.  Formatting fixes.

21 months agotree-optimization/106293 - fix testcase
Richard Biener [Wed, 11 Jan 2023 07:02:52 +0000 (08:02 +0100)]
tree-optimization/106293 - fix testcase

The following removes a problematic initializer which causes
excess diagnostics with -m32 and isn't actually required.

PR tree-optimization/106293
* gcc.dg/tree-ssa/ssa-dse-46.c: Remove long initializer.

21 months agoxtensa: Make instruction cost estimation for size more accurate
Takayuki 'January June' Suwa [Tue, 10 Jan 2023 03:34:01 +0000 (12:34 +0900)]
xtensa: Make instruction cost estimation for size more accurate

Until now, we applied COSTS_N_INSNS() (multiplying by 4) after dividing
the instruction length by 3, so we couldn't express the difference less
than modulo 3 in insn cost for size (e.g. 11 Bytes and 12 bytes cost the
same).

This patch fixes that.

;; 2 bytes
addi.n a2, a2, -1 ; cost 3

;; 3 bytes
addmi a2, a2, 1024 ; cost 4

;; 4 bytes
movi.n a3, 80 ; cost 5
bnez.n a2, a3, .L4

;; 5 bytes
srli a2, a3, 1 ; cost 7
add.n a2, a2, a2

;; 6 bytes
ssai 8 ; cost 8
src a4, a2, a3

:: 3 + 4 bytes
l32r a2, .L5 ; cost 9

;; 11 bytes ; cost 15
;; 12 bytes ; cost 16

gcc/ChangeLog:

* config/xtensa/xtensa.cc (xtensa_insn_cost):
Let insn cost for size be obtained by applying COSTS_N_INSNS()
to instruction length and then dividing by 3.

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

21 months agoMAINTAINERS: Add myself as Rust front-end maintainer
Philip Herron [Tue, 10 Jan 2023 21:58:09 +0000 (21:58 +0000)]
MAINTAINERS: Add myself as Rust front-end maintainer

Update MAINTAINERS file.

ChangeLog:

* MAINTAINERS: Add Philip Herron as Rust front-end maintainer

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
21 months agoFortran: frontend passes do_subscript leaks gmp memory [PR97345]
Harald Anlauf [Tue, 10 Jan 2023 21:41:17 +0000 (22:41 +0100)]
Fortran: frontend passes do_subscript leaks gmp memory [PR97345]

gcc/fortran/ChangeLog:

PR fortran/97345
* frontend-passes.cc (do_subscript): Clear used gmp variables.

21 months agoAdding missing dependencies to gcc/m2/Make-lang.in
Gaius Mulley [Tue, 10 Jan 2023 18:49:03 +0000 (18:49 +0000)]
Adding missing dependencies to gcc/m2/Make-lang.in

The dependency m2/gm2-libs/gm2-libs-host.h is missing from
two m2/mc-boot rules.

gcc/m2/ChangeLog:

* Make-lang.in (m2/mc-boot/$(SRC_PREFIX)%.o): Add
m2/gm2-libs/gm2-libs-host.h dependency.
(m2/mc-boot-ch/$(SRC_PREFIX)%.o): Add
m2/gm2-libs/gm2-libs-host.h dependency.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>