platform/upstream/gcc.git
2 years ago[Ada] Restore hiding of predefined "=" operator through class-wide type
Eric Botcazou [Wed, 20 Apr 2022 22:03:59 +0000 (00:03 +0200)]
[Ada] Restore hiding of predefined "=" operator through class-wide type

The previous change introduced a backward incompatibility in the handling
of a user-defined "=" operator for a class-wide type of a tagged type: it
would previously hide the predefined "=" operator of the tagged type in
the private case, but it no longer does in this case, while it still does
in the nonprivate case.

This hiding is a non-portability, but is fundamentally what the compiler
implements, instead of the RM rule which requires homographs.  The reason
lies in the implementation of the "=" operator in GNAT: internally, there
is not a "=" predefined operator for every nonlimited type, but instead
there is a single, universal "=" predefined operator for all the nonlimited
types.  The consequence is that the hiding rule implemented in GNAT for "="
is effectively that a user-declared symmetrical "=" operator returning
boolean hides the predefined "=" operator of any type that is covered by
the user-declared operator.

Whether it is desirable to implement the exact RM rule in GNAT is to be
discussed, but existing code relies on the non-portability and would thus
need to be changed.

gcc/ada/

* sem_ch6.adb (New_Overloaded_Entity): Deal specifically with the
overriding of the "=" operator for tagged types.

2 years ago[Ada] Do not freeze profiles for dispatch tables
Eric Botcazou [Wed, 20 Apr 2022 07:54:49 +0000 (09:54 +0200)]
[Ada] Do not freeze profiles for dispatch tables

When static dispatch tables are built for library-level tagged types, the
primitives (the subprogram themselves) are frozen; that's necessary because
their address is taken.  However, their profile, i.e. all the types present
therein, is also frozen, which is not necessary after AI05-019 and is also
inconsistent with the handling of attribute references.

The change also removes a couple of pragma Inline on subprograms that are
too large for inlining to bring any benefit.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Adjust call to Make_DT.
* exp_disp.ads (Building_Static_DT): Remove pragma Inline.
(Building_Static_Secondary_DT): Likewise.
(Convert_Tag_To_Interface): Likewise.
(Make_DT): Remove second parameter.
* exp_disp.adb (Make_DT): Likewise.
(Check_Premature_Freezing): Delete.
Pass Do_Freeze_Profile as False in call to Freeze_Entity.
* freeze.ads (Freezing_Library_Level_Tagged_Type): Delete.
* freeze.adb (Freeze_Profile): Remove obsolete code.
(Freeze_Entity): Tweak comment.

2 years ago[Ada] Adapt proof of runtime unit s-arit32
Yannick Moy [Wed, 20 Apr 2022 09:39:11 +0000 (09:39 +0000)]
[Ada] Adapt proof of runtime unit s-arit32

After changes in GNATprove, adapt proof. Simply move an assertion up
before it is first needed here.

gcc/ada/

* libgnat/s-arit32.adb (Scaled_Divide32): Move assertion up.

2 years ago[Ada] PR ada/105303 Fix use of Assertion_Policy in internal generics unit
Yannick Moy [Tue, 19 Apr 2022 12:37:58 +0000 (14:37 +0200)]
[Ada] PR ada/105303 Fix use of Assertion_Policy in internal generics unit

The internal unit System.Generic_Array_Operations defines only generic
subprograms. Thus, pragma Assertion_Policy inside the spec has no
effect, as each instantiation is only subject to the assertion policy at
the program point of the instantiation. Remove this confusing pragma,
and add the pragma inside each generic body making use of additional
assertions or ghost code, so that running time of instantiations is not
impacted by assertions meant for formal verification.

gcc/ada/

PR ada/105303
* libgnat/s-gearop.adb: Add pragma Assertion_Policy in generic
bodies making use of additional assertions or ghost code.
* libgnat/s-gearop.ads: Remove confusing Assertion_Policy.

2 years ago[Ada] Delete no-longer-used Convert_To_Return_False flag
Steve Baird [Fri, 15 Apr 2022 20:30:34 +0000 (13:30 -0700)]
[Ada] Delete no-longer-used Convert_To_Return_False flag

As a result of other recent changes, the Convert_To_Return_False flag
is never set. The flag can be therefore be deleted.

gcc/ada/

* exp_ch11.adb (Expand_N_Raise_Expression): Remove
Convert_To_Return_False test.
* gen_il-fields.ads: Remove Convert_To_Return_False field.
* gen_il-gen-gen_nodes.adb: Remove use of
Convert_To_Return_False field.
* sinfo.ads: Remove comment describing Convert_To_Return_False
flag.

2 years ago[Ada] Add empty constructors to the functional containers
Julien Bortolussi [Thu, 14 Apr 2022 14:09:30 +0000 (16:09 +0200)]
[Ada] Add empty constructors to the functional containers

This patch adds empty constructors to the functional containers so that
we can use them in expression functions.

gcc/ada/

* libgnat/a-cofuma.ads, libgnat/a-cofuma.adb,
libgnat/a-cofuse.ads, libgnat/a-cofuse.adb,
libgnat/a-cofuve.ads, libgnat/a-cofuve.adb: Add empty
constructors.

2 years ago[Ada] Fix new CUDA kernel registration scheme
Ghjuvan Lacambre [Tue, 19 Apr 2022 08:01:49 +0000 (10:01 +0200)]
[Ada] Fix new CUDA kernel registration scheme

Removal of the previous kernel registration scheme unearthed mistakes in
the new one, which were:
- The new kernel registration code relied on the binder expansion phase,
  which didn't happen because the registration code was already
  generated by the binder.
- The kernel handle passed to CUDA_Register_Function was the first eight
  bytes of the code of the host-side procedure representing the kernel
  rather than its address.

gcc/ada/

* bindgen.adb (Gen_CUDA_Init): Remove code generating CUDA
definitions.
(Gen_CUDA_Defs): New function, generating definitions
initialized by Gen_CUDA_Init.
(Gen_Output_File_Ada): Call Gen_CUDA_Defs instead of
Gen_CUDA_Init.
(Gen_Adainit): Call Gen_CUDA_Init.

2 years ago[ARM] Fix prototype for vec_perm_const hook.
Prathamesh Kulkarni [Mon, 30 May 2022 07:53:50 +0000 (13:23 +0530)]
[ARM] Fix prototype for vec_perm_const hook.

gcc/ChangeLog:

* config/arm/arm.cc (arm_vectorize_vec_perm_const): Adjust prototype.

2 years agoRISC-V/testsuite: constraint some of tests to hard_float
Vineet Gupta [Fri, 27 May 2022 02:36:36 +0000 (19:36 -0700)]
RISC-V/testsuite: constraint some of tests to hard_float

Commit 9ddd44b58649d1d ("RISC-V: Provide `fmin'/`fmax' RTL pattern") added
tests which check for hard float instructions which obviously fails on
soft-float ABI builds.

And my recent commit b646d7d279ae ("RISC-V: Inhibit FP <--> int register
moves via tune param") is guilty of same crime.

So constraint with "dg-require-effective-target hard_float"

This reduces bunch of new RV failures.

|               ========= Summary of gcc testsuite =========
|                            | # of unexpected case / # of unique unexpected case
|                            |          gcc |          g++ |     gfortran |
|   rv64imac/   lp64/ medlow |  134 /    22 |    0 /     0 |            - |  BEFORE
|   rv64imac/   lp64/ medlow |   22 /     9 |    0 /     0 |            - |  AFTER
|

gcc/testsuite/Changelog:
* gcc.target/riscv/fmax.c: Add dg-require-effective-target hard_float.
* gcc.target/riscv/fmaxf.c: Ditto.
* gcc.target/riscv/fmin.c: Ditto.
* gcc.target/riscv/fminf.c: Ditto.
* gcc.target/riscv/smax-ieee.c: Ditto.
* gcc.target/riscv/smax.c: Ditto.
* gcc.target/riscv/smaxf-ieee.c: Ditto.
* gcc.target/riscv/smaxf.c: Ditto.
* gcc.target/riscv/smin-ieee.c: Ditto.
* gcc.target/riscv/smin.c: Ditto.
* gcc.target/riscv/sminf-ieee.c: Ditto.
* gcc.target/riscv/sminf.c: Ditto.
* gcc.target/riscv/pr105666.c: Ditto.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
2 years agoDaily bump.
GCC Administrator [Mon, 30 May 2022 00:16:21 +0000 (00:16 +0000)]
Daily bump.

2 years agolibcpp: Ignore CPP_PADDING tokens in _cpp_parse_expr [PR105732]
Jakub Jelinek [Sun, 29 May 2022 19:57:51 +0000 (21:57 +0200)]
libcpp: Ignore CPP_PADDING tokens in _cpp_parse_expr [PR105732]

The first part of the following testcase (m1-m3 macros and its use)
regressed with my PR89971 fix, but as the m1,m4-m5 and its use part shows,
the problem isn't new, we can emit a CPP_PADDING token to avoid it from
being adjacent to whatever comes after the __VA_OPT__ (in this case there
is nothing afterwards, true).

In most cases these CPP_PADDING tokens don't matter, all other
callers of cpp_get_token_with_location either ignore CPP_PADDING tokens
completely (e.g. c_lex_with_flags) or they just remember them and
take them into account when printing stuff whether there should be
added whitespace or not (scan_translation_unit + token_streamer::stream).
So, I think we should just ignore CPP_PADDING tokens the same way in
_cpp_parse_expr.

2022-05-27  Jakub Jelinek  <jakub@redhat.com>

PR preprocessor/105732
* expr.cc (_cpp_parse_expr): Handle CPP_PADDING by just another
token.

* c-c++-common/cpp/va-opt-10.c: New test.

2 years agoDarwin: Fix empty g++ command lines [PR105599].
Iain Sandoe [Sun, 29 May 2022 15:14:32 +0000 (16:14 +0100)]
Darwin: Fix empty g++ command lines [PR105599].

An empty g++ command line should produce a diagnostic that there are no
inputs.  The PR is that currently Darwin produces a dignostic about missing
link items instead - this is because (errnoeously), for this driver, we are
creating a link job for empty command lines.

The problem occurs in four stages:

 The g++ driver appends -shared-libgcc to the command line.

 The Darwin driver_init code in the backend does not see this (it sees an
 empty command line).

 When the back end driver code driver sees an empty command line, it does not
 add any supplementary flags (e.g. asm-macosx-version-min) - precisely to
 avoid anything being claimed as an input_file and therefore triggering a link
 line.

 Since we do not have a value for asm-macosx-version-min when processing the
 driver specs, we unconditionally inject 'multiply_defined suppress' which is
 used with shared libgcc (but only intended on very old Darwin).  This then
 causes the generation of a link job.

The solution, for the present, is to move version-specific link params to the
LINK_SPEC so that they are only processed when a link job has already been
decided.

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

gcc/ChangeLog:

* config/darwin.h: Move versions-specific handling of multiply_defined
from SUBTARGET_DRIVER_SELF_SPECS to LINK_SPEC.

2 years agosourcebuild.texi: Document toplevel directories
Eric Gallager [Sun, 29 May 2022 04:57:05 +0000 (00:57 -0400)]
sourcebuild.texi: Document toplevel directories

Fixes PR82383

gcc/ChangeLog:

PR other/82383
* doc/sourcebuild.texi: Add entries for the c++tools,
gotools, libbacktrace, libcc1, libcody, liboffloadmic,
and libsanitizer directories. Remove entry for boehm-gc.
Fix alphabetization for libquadmath.

2 years agoDaily bump.
GCC Administrator [Sun, 29 May 2022 00:16:31 +0000 (00:16 +0000)]
Daily bump.

2 years ago[PATCH 1/2] avr: Added AVR-DA and DB MCU series
Joel Holdsworth [Sat, 28 May 2022 19:16:01 +0000 (13:16 -0600)]
[PATCH 1/2] avr: Added AVR-DA and DB MCU series

gcc/
* config/avr/avr-mcus.def: Add device definitions.
* doc/avr-mmcu.texi: Corresponding changes.
* config/avr/gen-avr-mmcu-texi.cc: Added support for avr
device prefix.
* config/avr/gen-avr-mmcu-specs.cc: Prevent -mmcu=avr* flags
from leaking into cc1.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2 years agoOpenMP/Fortran: Add support for enter clause on declare target
Tobias Burnus [Sat, 28 May 2022 18:42:38 +0000 (20:42 +0200)]
OpenMP/Fortran: Add support for enter clause on declare target

Fortran version to C/C++ commit r13-797-g0ccba4ed8571c18c7015413441e971

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_clauses): Handle OMP_LIST_ENTER.
* gfortran.h: Add OMP_LIST_ENTER.
* openmp.cc (enum omp_mask2, OMP_DECLARE_TARGET_CLAUSES): Add
OMP_CLAUSE_ENTER.
(gfc_match_omp_clauses, gfc_match_omp_declare_target,
resolve_omp_clauses): Handle 'enter' clause.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.2): Mark 'enter' clause as supported.
* testsuite/libgomp.fortran/declare-target-1.f90: Extend to test
explicit 'to' and 'enter' clause.
* testsuite/libgomp.fortran/declare-target-2.f90: Update accordingly.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/declare-target-2.f90: Add 'enter' clause test.
* gfortran.dg/gomp/declare-target-4.f90: Likewise.

2 years agoFix ICE on sh
Vladimir Makarov [Sat, 28 May 2022 18:08:38 +0000 (12:08 -0600)]
Fix ICE on sh

gcc/
PR target/103722
* config/sh/sh.cc (sh_register_move_cost): Avoid cost "2" (which
is special) for various scenarios.

2 years agoVim swap files not ignored
Bruce Korb [Sat, 28 May 2022 15:36:10 +0000 (09:36 -0600)]
Vim swap files not ignored

ChangeLog:

* .gitignore: Ignore vim swap files

2 years agolibbacktrace: update README
Ian Lance Taylor [Sat, 28 May 2022 14:57:32 +0000 (07:57 -0700)]
libbacktrace: update README

PR libbacktrace/105721
* README: Update.

2 years agoDarwin: Amend REAL_LIBGCC_SPEC comment [NFC].
Iain Sandoe [Sat, 28 May 2022 10:55:00 +0000 (11:55 +0100)]
Darwin: Amend REAL_LIBGCC_SPEC comment [NFC].

This comment had got out of sync with reality, partly due to merging
of patches.  Updated to reflect the current implementation.

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

* config/darwin.h (REAL_LIBGCC_SPEC): Update the comment block
describing this macro.

2 years agoRename OSCONS_CC to GCC_FOR_ADA_RTS
Alexandre Oliva [Sat, 28 May 2022 06:50:17 +0000 (03:50 -0300)]
Rename OSCONS_CC to GCC_FOR_ADA_RTS

Several gnatlib* targets perform, with a subshell and sed, the same
GCC_FOR_TARGET pathname transformation that OSCONS_CC performs with
make subst macros.  Rename OSCONS_CC to a more general name, and use
it for gnatlib as well.

for  gcc/ada/ChangeLog

* gcc-interface/Makefile.in (OSCONS_CC): Rename to...
(GCC_FOR_ADA_RTS): ... this.  Adjust users.
(gnatlib): Pass it down as CC.
(gnatlib-shared-default): Likewise.
(gnatlib-shared-win32, gnatlib-shared-darwin): Likewise.

2 years agolibgomp: Don't define GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC for _aligned_malloc [PR105745]
Jakub Jelinek [Sat, 28 May 2022 06:30:47 +0000 (08:30 +0200)]
libgomp: Don't define GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC for _aligned_malloc [PR105745]

since apparently _aligned_malloc requires freeing with _aligned_free and:
 /* Defined if gomp_aligned_alloc doesn't use fallback version
    and free can be used instead of gomp_aligned_free.  */
 #define GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC 1
so the second condition isn't satisfied.  For uses inside of the OpenMP
allocators we can still use _aligned_malloc but we need to call _aligned_free
in gomp_aligned_free.

2022-05-28  Jakub Jelinek  <jakub@redhat.com>

PR libgomp/105745
* libgomp.h (GOMP_HAVE_EFFICIENT_ALIGNED_ALLOC): Don't define for
defined(HAVE__ALIGNED_MALLOC) case.
* alloc.c (gomp_aligned_alloc): Move defined(HAVE__ALIGNED_MALLOC)
handling as last option before fallback instead of first.
(gomp_aligned_free): For defined(HAVE__ALIGNED_MALLOC) call
_aligned_free.

2 years agoopenmp: Adjust diagnostics about same variable in link and to/enter clauses
Jakub Jelinek [Sat, 28 May 2022 06:26:57 +0000 (08:26 +0200)]
openmp: Adjust diagnostics about same variable in link and to/enter clauses

On Fri, May 27, 2022 at 04:52:17PM +0200, Tobias Burnus wrote:
> The 'TO'/'ENTER' usage is first stored in a linked list – and
> then as attribute to the symbol. I am not sure how to handle it best.

This reminds me I've left the C/C++ FE diagnostics about mixing link and
to/enter on the same variable in separate directives as is, so it always
talked about mixing link and to clauses.

This patch adjusts it, so that if link is first, it talks about the
clause actually used and if link is later, uses to or enter together
in the wording.

2022-05-28  Jakub Jelinek  <jakub@redhat.com>

gcc/c/
* c-parser.cc (c_parser_omp_declare_target): If OMP_CLAUSE_LINK was
seen first, use "%<to%>" or "%<enter%>" depending on
OMP_CLAUSE_ENTER_TO of the current clause, otherwise use
"%<to%> or %<enter%>" wording.
gcc/cp/
* parser.cc (handle_omp_declare_target_clause): If OMP_CLAUSE_LINK was
seen first, use "%<to%>" or "%<enter%>" depending on
OMP_CLAUSE_ENTER_TO of the current clause, otherwise use
"%<to%> or %<enter%>" wording.
gcc/testsuite/
* c-c++-common/gomp/declare-target-2.c: Add further tests for mixing of
link and to/enter clauses on separate directives.

2 years agoc++: lambda in concept [PR105652]
Jason Merrill [Fri, 27 May 2022 02:43:05 +0000 (22:43 -0400)]
c++: lambda in concept [PR105652]

We currently check satisfaction in the context of the constrained
declaration (which may be wrong, see PR104111).  When checking C<int>
for S<int>, we currently substitute into the lambda in the context of
S<T> (rather than S<int>, which seems wrong if the above isn't wrong), so
the new closure type thinks its context is S<T>, which confuses debug
output.  For the moment, let's work around all of this by overriding the
context of the closure.

PR c++/105652

gcc/cp/ChangeLog:

* pt.cc (tsubst_lambda_expr): Don't let a namespace-scope lambda
instantiate into a class-scope lambda.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-lambda20.C: New test.

2 years agoDaily bump.
GCC Administrator [Sat, 28 May 2022 00:16:40 +0000 (00:16 +0000)]
Daily bump.

2 years agod: Merge upstream dmd 4d07f22f2, druntime f89da313, phobos d46814c86.
Iain Buclaw [Fri, 27 May 2022 17:36:06 +0000 (19:36 +0200)]
d: Merge upstream dmd 4d07f22f2, druntime f89da313, phobos d46814c86.

D front-end changes:

    - `scope' semantics are now enforced in `@safe' code on pointers to
      stack memory, but only as deprecation warnings.
    - Overriding virtual functions are now marked with the `override'
      and `final' in the generated headers of `-fdump-c++-spec='.
    - `-fpreview=fiximmmutableconv` has been added that disallows
      implicitly converting a return value with indirections to
      immutable if it determines the result must be unique.

D runtime changes:

    - Posix (excluding Darwin): Switch default GC signals from SIGUSR1/2
      to SIGRTMIN/SIGRTMIN+1

Phobos changes:

    - Import latest bug fixes to mainline.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd 4d07f22f2
* d-lang.cc (d_handle_option): Handle OPT_fpreview_fiximmutableconv.
* lang.opt (fpreview=fiximmutableconv): New option.
* runtime.def (ARRAYAPPENDT): Remove.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime f89da313.
* src/MERGE: Merge upstream phobos d46814c86.

Signed-off-by: Iain Buclaw <ibuclaw@gdcproject.org>
2 years agoc++: Fix ICE with -Wmismatched-tags [PR105725]
Marek Polacek [Fri, 27 May 2022 14:51:30 +0000 (10:51 -0400)]
c++: Fix ICE with -Wmismatched-tags [PR105725]

Here we ICE with -Wmismatched-tags on something like

  template <class T>
  bool B<T, enable_if_t<is_class_v<class T::foo>>>;

Specifically, the "class T::foo" bit.  There, class_decl_loc_t::add gets
a TYPENAME_TYPE as TYPE, rather than a class/union type, so checking
TYPE_BEING_DEFINED will crash.  I think it's OK to allow a TYPENAME_TYPE to
slip into that function; we just shouldn't consider the 'class' tag redundant
(which works as a 'typename').  In fact, every other compiler *requires* it.

PR c++/105725

gcc/cp/ChangeLog:

* parser.cc (class_decl_loc_t::add): Check CLASS_TYPE_P.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wmismatched-tags-10.C: New test.

2 years agoc-family: fix attribute constructor ICE [PR90658]
Marek Polacek [Thu, 26 May 2022 22:59:44 +0000 (18:59 -0400)]
c-family: fix attribute constructor ICE [PR90658]

Here the C compiler crashes because a FUNCTION_DECL got into
get_priority -> default_conversion, and the C FE's version of d_c
specifically asserts that it doesn't get a FUNCTION_DECL.  All uses
of default_conversion in c-attribs.cc are guarded by != IDENTIFIER_NODE
&& != FUNCTION_DECL, but get_priority was only checking IDENTIFIER_NODE.

PR c/90658

gcc/c-family/ChangeLog:

* c-attribs.cc (get_priority): Check FUNCTION_DECL.

gcc/testsuite/ChangeLog:

* c-c++-common/attr-cdtor-1.c: New test.

2 years agolibstdc++: Mark non-exported function always_inline [PR105671]
Jonathan Wakely [Fri, 27 May 2022 11:43:18 +0000 (12:43 +0100)]
libstdc++: Mark non-exported function always_inline [PR105671]

This new function was added for gcc 11.1 but is not exported from the
shared library. Depending on inlining decisions, its callers might get
inlined but an external definition be needed for this function. That
then fails to link.

Since we can't add the export to the gcc-11 release branch now, mark it
always_inline. We can consider exporting it for gcc-13 if/when we bump
the shared library version (and maybe also for gcc-12 which is currently
at the same version as trunk). For now, the attribute will solve the
problem on all affected branches. The function is small enough that
force-inlining it shouldn't cause problems.

libstdc++-v3/ChangeLog:

PR libstdc++/105671
* include/std/sstream (basic_stringbuf::_M_high_mark): Add
always_inline attribute.

2 years agoFortran: Fix OpenMP clause name in error message
Tobias Burnus [Fri, 27 May 2022 11:12:45 +0000 (13:12 +0200)]
Fortran: Fix OpenMP clause name in error message

gcc/fortran/ChangeLog:

* openmp.cc (gfc_check_omp_requires): Fix clause name in error.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/requires-4.f90: Update dg-error.
* gfortran.dg/gomp/requires-8.f90: Update dg-error.

Co-authored-by: Chung-Lin Tang <cltang@codesourcery.com>
2 years agoAvoid shift in get_ref_base_and_extent
Richard Biener [Fri, 27 May 2022 12:07:03 +0000 (14:07 +0200)]
Avoid shift in get_ref_base_and_extent

This avoids one instance of a shift from bytes to bits in
get_ref_base_and_extent by using TYPE_SIZE instead of TYPE_SIZE_UNIT.

* tree-dfa.cc (get_ref_base_and_extent): Avoid shift.

2 years agoipa: Check cst type when propagating controled uses info
Martin Jambor [Fri, 27 May 2022 11:05:40 +0000 (13:05 +0200)]
ipa: Check cst type when propagating controled uses info

PR 105639 shows that code with type-mismatches can trigger an assert
after runnning into a branch that was inteded only for references to
variables - as opposed to references to functions.  Fixed by moving
the condition from the assert to the guarding if statement.

gcc/ChangeLog:

2022-05-25  Martin Jambor  <mjambor@suse.cz>

PR ipa/105639
* ipa-prop.cc (propagate_controlled_uses): Check type of the
constant before adding a LOAD reference.

gcc/testsuite/ChangeLog:

2022-05-25  Martin Jambor  <mjambor@suse.cz>

PR ipa/105639
* gcc.dg/ipa/pr105639.c: New test.

2 years agoopenmp: Add support for enter clause on declare target
Jakub Jelinek [Fri, 27 May 2022 10:48:48 +0000 (12:48 +0200)]
openmp: Add support for enter clause on declare target

OpenMP 5.1 and earlier had 2 different uses of to clause, one for target
update construct with one semantics, and one for declare target directive
with a different semantics.
Under the hood we were using OMP_CLAUSE_TO_DECLARE to represent the latter.
OpenMP 5.2 renamed the declare target clause to to enter, the old one is
kept as a deprecated alias.

As we are far from having full OpenMP 5.2 support, this patch adds support
for the enter clause (and renames OMP_CLAUSE_TO_DECLARE to OMP_CLAUSE_ENTER
with a flag to tell the spelling of the clause for better diagnostics),
but doesn't deprecate the to clause on declare target just yet (that
should be done as one of the last steps in 5.2 support).

2022-05-27  Jakub Jelinek  <jakub@redhat.com>

gcc/
* tree-core.h (enum omp_clause_code): Rename OMP_CLAUSE_TO_DECLARE
to OMP_CLAUSE_ENTER.
* tree.h (OMP_CLAUSE_ENTER_TO): Define.
* tree.cc (omp_clause_num_ops, omp_clause_code_name): Rename
OMP_CLAUSE_TO_DECLARE to OMP_CLAUSE_ENTER.
* tree-pretty-print.cc (dump_omp_clause): Handle OMP_CLAUSE_ENTER
instead of OMP_CLAUSE_TO_DECLARE, if OMP_CLAUSE_ENTER_TO, print
"to" instead of "enter".
* tree-nested.cc (convert_nonlocal_omp_clauses,
convert_local_omp_clauses): Handle OMP_CLAUSE_ENTER instead of
OMP_CLAUSE_TO_DECLARE.
gcc/c-family/
* c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_ENTER.
gcc/c/
* c-parser.cc (c_parser_omp_clause_name): Parse enter clause.
(c_parser_omp_all_clauses): For to clause on declare target, use
OMP_CLAUSE_ENTER clause with OMP_CLAUSE_ENTER_TO instead of
OMP_CLAUSE_TO_DECLARE clause.  Handle PRAGMA_OMP_CLAUSE_ENTER.
(OMP_DECLARE_TARGET_CLAUSE_MASK): Add enter clause.
(c_parser_omp_declare_target): Use OMP_CLAUSE_ENTER instead of
OMP_CLAUSE_TO_DECLARE.
* c-typeck.cc (c_finish_omp_clauses): Handle OMP_CLAUSE_ENTER instead
of OMP_CLAUSE_TO_DECLARE, to OMP_CLAUSE_ENTER_TO use "to" as clause
name in diagnostics instead of
omp_clause_code_name[OMP_CLAUSE_CODE (c)].
gcc/cp/
* parser.cc (cp_parser_omp_clause_name): Parse enter clause.
(cp_parser_omp_all_clauses): For to clause on declare target, use
OMP_CLAUSE_ENTER clause with OMP_CLAUSE_ENTER_TO instead of
OMP_CLAUSE_TO_DECLARE clause.  Handle PRAGMA_OMP_CLAUSE_ENTER.
(OMP_DECLARE_TARGET_CLAUSE_MASK): Add enter clause.
(cp_parser_omp_declare_target): Use OMP_CLAUSE_ENTER instead of
OMP_CLAUSE_TO_DECLARE.
* semantics.cc (finish_omp_clauses): Handle OMP_CLAUSE_ENTER instead
of OMP_CLAUSE_TO_DECLARE, to OMP_CLAUSE_ENTER_TO use "to" as clause
name in diagnostics instead of
omp_clause_code_name[OMP_CLAUSE_CODE (c)].
gcc/testsuite/
* c-c++-common/gomp/clauses-3.c: Add tests with enter clause instead
of to or modify some existing to clauses to enter.
* c-c++-common/gomp/declare-target-1.c: Likewise.
* c-c++-common/gomp/declare-target-2.c: Likewise.
* c-c++-common/gomp/declare-target-3.c: Likewise.
* g++.dg/gomp/attrs-9.C: Likewise.
* g++.dg/gomp/declare-target-1.C: Likewise.
libgomp/
* testsuite/libgomp.c-c++-common/target-40.c: Modify some existing to
clauses to enter.
* testsuite/libgomp.c/target-41.c: Likewise.

2 years agotree-optimization/105726 - adjust array bound heuristic
Richard Biener [Wed, 25 May 2022 09:49:03 +0000 (11:49 +0200)]
tree-optimization/105726 - adjust array bound heuristic

There's heuristic to detect ptr[1].a[...] out of bound accesses
reasoning that if ptr points to an array of aggregates a trailing
incomplete array has to have size zero.  The following more
thoroughly constrains the cases this applies to avoid false
positive diagnostics.

2022-05-25  Richard Biener  <rguenther@suse.de>

PR tree-optimization/105726
* gimple-ssa-warn-restrict.cc (builtin_memref::set_base_and_offset):
Constrain array-of-flexarray case more.

* g++.dg/warn/Warray-bounds-27.C: New testcase.

2 years agofold-const: Fix up -fsanitize=null in C++ [PR105729]
Jakub Jelinek [Fri, 27 May 2022 09:40:42 +0000 (11:40 +0200)]
fold-const: Fix up -fsanitize=null in C++ [PR105729]

The following testcase triggers a false positive UBSan binding a reference
to null diagnostics.
In the FE we instrument conversions from pointer to reference type
to diagnose at runtime if the operand of such a conversion is 0.
The problem is that a GENERIC folding folds
((const struct Bar *) ((const struct Foo *) this)->data) + (sizetype) range_check (x)
conversion to const struct Bar & by converting to that the first
operand of the POINTER_PLUS_EXPR.  But that changes when the -fsanitize=null
binding to reference runtime check occurs.  Without the optimization,
it is invoked on the result of the POINTER_PLUS_EXPR, and as range_check
call throws, that means it never triggers in the testcase.
With the optimization, it checks whether this->data is NULL and it is.

The following patch avoids that optimization during GENERIC folding when
-fsanitize=null is enabled and it is a cast from non-REFERENCE_TYPE to
REFERENCE_TYPE.

2022-05-27  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/105729
* fold-const.cc (fold_unary_loc): Don't optimize (X &) ((Y *) z + w)
to (X &) z + w if -fsanitize=null during GENERIC folding.

* g++.dg/ubsan/pr105729.C: New test.

2 years agolibgomp.texi: Add more to-be-implemented OpenMP 5.2 features
Tobias Burnus [Fri, 27 May 2022 08:09:10 +0000 (10:09 +0200)]
libgomp.texi: Add more to-be-implemented OpenMP 5.2 features

libgomp/
* libgomp.texi (Other new OpenMP 5.1 features): Add
'begin declare target'.
(Other new OpenMP 5.2 features): New.

2 years agoCanonicalize X&-Y as X*Y in match.pd when Y is [0,1].
Roger Sayle [Fri, 27 May 2022 07:57:46 +0000 (08:57 +0100)]
Canonicalize X&-Y as X*Y in match.pd when Y is [0,1].

"For every pessimization, there's an equal and opposite optimization".

In the review of my original patch for PR middle-end/98865, Richard
Biener pointed out that match.pd shouldn't be transforming X*Y into
X&-Y as the former is considered cheaper by tree-ssa's cost model
(operator count).  A corollary of this is that we should instead be
transforming X&-Y into the cheaper X*Y as a preferred canonical form
(especially as RTL expansion now intelligently selects the appropriate
implementation based on the target's costs).

With this patch we now generate identical code for:
int foo(int x, int y) { return -(x&1) & y; }
int bar(int x, int y) { return (x&1) * y; }

specifically on x86_64-pc-linux-gnu both use and/neg/and with -O2,
but both use and/mul with -Os.

One minor wrinkle/improvement is that this patch includes three
additional optimizations (that account for the change in canonical
form) to continue to optimize PR92834 and PR94786.

2022-05-27  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* match.pd (match_zero_one_valued_p): New predicate.
(mult @0 @1): Use zero_one_valued_p for optimization to the
expression "bit_and @0 @1".
(bit_and (negate zero_one_valued_p@0) @1): Optimize to MULT_EXPR.
(plus @0 (mult (minus @1 @0) zero_one_valued_p@2)): New transform.
(minus @0 (mult (minus @0 @1) zero_one_valued_p@2)): Likewise.
(bit_xor @0 (mult (bit_xor @0 @1) zero_one_valued_p@2)): Likewise.
Remove three redundant transforms obsoleted by the three above.

gcc/testsuite/ChangeLog
* gcc.dg/pr98865.c: New test case.

2 years agoPre-reload splitter to transform and;cmp into not;test on x86.
Roger Sayle [Fri, 27 May 2022 07:52:03 +0000 (08:52 +0100)]
Pre-reload splitter to transform and;cmp into not;test on x86.

A common idiom for testing if a specific set of bits is set in a value
is to use "(X & Y) == Y", which on x86 results in an AND followed by a
CMP.  A slightly improved implementation is to instead use (~X & Y)==0,
that uses a NOT and a TEST (or ANDN where available); still two "fast"
instructions, but typically shorter especially if Y is an immediate
constant.  Because the above transformation would require more gimple
statements in SSA, and may only be a win on targets with flags registers,
it isn't performed by the middle-end, instead leaving this choice to
the backend.

As an example, here's the change in code generation for pr91400-1.c
[which now requires a tweak to its dg-final clauses].

Before:
        movl    __cpu_model+12(%rip), %eax
        andl    $68, %eax // 3 bytes
        cmpl    $68, %eax // 3 bytes
        sete    %al
        ret

After:
        movl    __cpu_model+12(%rip), %eax
        notl    %eax // 2 bytes
        testb   $68, %al // 2 bytes
        sete    %al
        ret

2022-05-27  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/i386/i386.md (*test<mode>_not): New define_insn_and_split
to split a combined "and;cmp" sequence into "not;test".

gcc/testsuite/ChangeLog
* gcc.target/i386/pr91400-1.c: Update for improved code generation.
* gcc.target/i386/pr91400-2.c: Likewise.
* gcc.target/i386/testnot-1.c: New test case.
* gcc.target/i386/testnot-2.c: Likewise.

2 years agoClose gcc-9 branch
Richard Biener [Fri, 27 May 2022 07:04:32 +0000 (09:04 +0200)]
Close gcc-9 branch

This removes gcc-9 from getting DATESTAMP updates.

gcc/contrib/
* gcc-changelog/git_update_version.py (active_refs): Remove
releases/gcc-9.

2 years agoxtensa: Improve bswap[sd]i2 insn patterns
Takayuki 'January June' Suwa [Fri, 13 May 2022 13:33:59 +0000 (22:33 +0900)]
xtensa: Improve bswap[sd]i2 insn patterns

This patch makes bswap[sd]i2 better register allocation, and reconstructs
bswapsi2 in order to take advantage of GIMPLE manual byte-swapping
recognition.

gcc/ChangeLog:

* config/xtensa/xtensa.md (bswapsi2): New expansion pattern.
(bswapsi2_internal): Revise the template and condition, and add
detection code for preceding the same insn in order to omit a
"SSAI 8" instruction of the latter.
(bswapdi2): Suppress built-in insn expansion with the corresponding
library call when optimizing for size.

gcc/testsuite/ChangeLog:

* gcc.target/xtensa/bswap.c: Remove test.
* gcc.target/xtensa/bswap-O1.c: New.
* gcc.target/xtensa/bswap-O2.c: Ditto.
* gcc.target/xtensa/bswap-Os.c: Ditto.

2 years agoxtensa: Add setmemsi insn pattern
Takayuki 'January June' Suwa [Mon, 23 May 2022 15:52:44 +0000 (00:52 +0900)]
xtensa: Add setmemsi insn pattern

This patch introduces setmemsi insn pattern of two kinds, unrolled loop and
small loop, for fixed small length and constant initialization value.

gcc/ChangeLog:

* config/xtensa/xtensa-protos.h
(xtensa_expand_block_set_unrolled_loop,
xtensa_expand_block_set_small_loop): New prototypes.
* config/xtensa/xtensa.cc (xtensa_sizeof_MOVI,
xtensa_expand_block_set_unrolled_loop,
xtensa_expand_block_set_small_loop): New functions.
* config/xtensa/xtensa.md (setmemsi): New expansion pattern.
* config/xtensa/xtensa.opt (mlongcalls): Add target mask.

2 years agoDaily bump.
GCC Administrator [Fri, 27 May 2022 00:16:19 +0000 (00:16 +0000)]
Daily bump.

2 years agolibstdc++: Fix narrowing conversions for 16-bit size_t [PR105681]
Jonathan Wakely [Thu, 26 May 2022 20:32:55 +0000 (21:32 +0100)]
libstdc++: Fix narrowing conversions for 16-bit size_t [PR105681]

On a 16-bit target such as msp430 we get errors about narrowing long
values to size_t, which is only 16-bit. When --enable-libstdcxx-pch is
used the <bits/extc++.h> header breaks the build because of these
narrowing errors.

libstdc++-v3/ChangeLog:

PR libstdc++/105681
* include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp:
Limit ga_sizes array to values that fit in size_t.
* include/ext/random [__SIZE_WIDTH < 32] (sfmt86243)
(sfmt86243_64, sfmt132049, sfmt132049_64, sfmt216091)
(sfmt216091_64): Do not declare.

2 years agolibstdc++: Fix atomic and error_code printers for versioned namespace
Jonathan Wakely [Thu, 26 May 2022 14:44:08 +0000 (15:44 +0100)]
libstdc++: Fix atomic and error_code printers for versioned namespace

This fixes the printers to work with std::__8::atomic and
std::__v8::ios_errc and std::__v8::future_errc.

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (StdErrorCodePrinter): Make
lookup for ios_errc and future_errc check versioned namespace.
(StdAtomicPrinter): Strip versioned namespace from typename.

2 years agolibstdc++: Move std::iostream_category() definition to new file
Jonathan Wakely [Thu, 26 May 2022 14:42:50 +0000 (15:42 +0100)]
libstdc++: Move std::iostream_category() definition to new file

This fixes a missing symbol when the dual ABI is disabled, e.g. for the
versioned namespace build.

libstdc++-v3/ChangeLog:

* src/c++11/Makefile.am: Add new source file.
* src/c++11/Makefile.in: Regenerate.
* src/c++11/cxx11-ios_failure.cc (iostream_category):
Move to ...
* src/c++11/ios_errcat.cc: New file.
* testsuite/27_io/ios_base/failure/error_code.cc: Check that
std::iostream_category() is defined and used for std::io_errc.

2 years agoc++: improve -Waddress warnings with *_cast [PR105569]
Marek Polacek [Wed, 11 May 2022 18:38:49 +0000 (14:38 -0400)]
c++: improve -Waddress warnings with *_cast [PR105569]

This patch improves the diagnostic for -Waddress when it warns for

  if (dynamic_cast<A*>(&ref))
    // ...

where 'ref' is a reference, which cannot be null.  In particular, it
changes
warning: comparing the result of pointer addition '(((A*)ref) + ((sizetype)(*(long int*)((& ref)->B::_vptr.B + -24))))' and NULL
to
warning: the compiler can assume that the address of 'ref' will never be NULL

PR c++/105569

gcc/cp/ChangeLog:

* typeck.cc (warn_for_null_address): Improve the warning when
the POINTER_PLUS_EXPR's base is of reference type.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Waddress-9.C: New test.

2 years agoxtensa: Fix instruction counting regarding block move expansion
Takayuki 'January June' Suwa [Fri, 13 May 2022 13:29:22 +0000 (22:29 +0900)]
xtensa: Fix instruction counting regarding block move expansion

This patch makes counting the number of instructions of the remainder
(modulo 4) part more accurate.

gcc/ChangeLog:

* config/xtensa/xtensa.cc (xtensa_expand_block_move):
Make instruction counting more accurate, and simplify emitting insns.

2 years agoxtensa: Make use of IN_RANGE macro where appropriate
Takayuki 'January June' Suwa [Fri, 13 May 2022 13:27:36 +0000 (22:27 +0900)]
xtensa: Make use of IN_RANGE macro where appropriate

No functional changes.

gcc/ChangeLog:

* config/xtensa/constraints.md (M, O): Use the macro.
* config/xtensa/predicates.md (addsubx_operand, extui_fldsz_operand,
sext_fldsz_operand): Ditto.
* config/xtensa/xtensa.cc (xtensa_simm8, xtensa_simm8x256,
xtensa_simm12b, xtensa_uimm8, xtensa_uimm8x2, xtensa_uimm8x4,
xtensa_mask_immediate, smalloffset_mem_p, printx, xtensa_call_save_reg,
xtensa_expand_prologue): Ditto.
* config/xtensa/xtensa.h (FUNCTION_ARG_REGNO_P): Ditto.

2 years agoxtensa: Simplify EXTUI instruction maskimm validations
Takayuki 'January June' Suwa [Fri, 13 May 2022 13:26:30 +0000 (22:26 +0900)]
xtensa: Simplify EXTUI instruction maskimm validations

No functional changes.

gcc/ChangeLog:

* config/xtensa/predicates.md (extui_fldsz_operand): Simplify.
* config/xtensa/xtensa.cc (xtensa_mask_immediate, print_operand):
Ditto.

2 years agolibstdc++: Add constexpr to std::counted_iterator post-increment (LWG 3643)
Jonathan Wakely [Thu, 26 May 2022 11:41:03 +0000 (12:41 +0100)]
libstdc++: Add constexpr to std::counted_iterator post-increment (LWG 3643)

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator.h (counted_iterator::operator++(int)):
Add 'constexpr' as per LWG 3643.
* testsuite/24_iterators/counted_iterator/lwg3643.cc: New test.

2 years agoc++: constrained partial spec forward decl [PR96363]
Patrick Palka [Thu, 26 May 2022 13:43:14 +0000 (09:43 -0400)]
c++: constrained partial spec forward decl [PR96363]

Here during cp_parser_single_declaration for #2, we were calling
associate_classtype_constraints for TPL<T> (the primary template type)
before maybe_process_partial_specialization could get a chance to
notice that we're in fact declaring a distinct constrained partial
spec and not redeclaring the primary template.  This caused us to
emit a bogus error about differing constraints b/t the primary template
and #2's constraints.  This patch fixes this by moving the call to
associate_classtype_constraints after the call to shadow_tag (which
calls maybe_process_partial_specialization) and adjusting shadow_tag to
use the return value of m_p_p_s.

Moreover, if we later try to define a constrained partial specialization
that's been declared earlier (as in the third testcase), then
maybe_new_partial_specialization correctly notices it's a redeclaration
and returns NULL_TREE.  But in this case we also need to update TYPE to
point to the redeclared partial spec (it'll otherwise continue pointing
to the primary template type, eventually leading to a bogus error).

PR c++/96363

gcc/cp/ChangeLog:

* decl.cc (shadow_tag): Use the return value of
maybe_process_partial_specialization.
* parser.cc (cp_parser_single_declaration): Call shadow_tag
before associate_classtype_constraints.
* pt.cc (maybe_new_partial_specialization): Change return type
to bool.  Take 'type' argument by mutable reference.  Set 'type'
to point to the correct constrained specialization when
appropriate.
(maybe_process_partial_specialization): Adjust accordingly.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-partial-spec12.C: New test.
* g++.dg/cpp2a/concepts-partial-spec12a.C: New test.
* g++.dg/cpp2a/concepts-partial-spec13.C: New test.

2 years agolibstdc++: Refactor includes for unordered containers
Jonathan Wakely [Tue, 24 May 2022 11:17:01 +0000 (12:17 +0100)]
libstdc++: Refactor includes for unordered containers

This moves some #include directives to the relevant place. For example,
<bits/hashtable_policy.h> needs <bits/stl_pair.h> so should include it
directly instead of relying on <unordered_map> and <unordered_set> to do
so first.

libstdc++-v3/ChangeLog:

* include/bits/functional_hash.h (__is_fast_hash): Add doxygen
comment.
* include/bits/hashtable.h: Do not include <bits/stl_function.h>
here.
* include/bits/hashtable_policy.h: Include <bits/stl_pair.h> and
<bits/functional_hash.h>.
* include/bits/unordered_map.h: Include required headers.
* include/bits/unordered_set.h: Likewise.
* include/std/unordered_map: Do not include headers for indirect
dependencies.
* include/std/unordered_set: Likewise.

2 years agolibstdc++: Remove some unnecessary includes
Jonathan Wakely [Tue, 24 May 2022 11:15:00 +0000 (12:15 +0100)]
libstdc++: Remove some unnecessary includes

These headers do not use anything in <bits/stl_iterator_base_types.h>
directly, and it's included by <bits/stl_iterator_base_funcs.h> and
<bits/stl_iterator.h> anyway, because they do need it.

libstdc++-v3/ChangeLog:

* include/bits/ranges_algobase.h: Do not include
<bits/stl_iterator_base_types.h>.
* include/std/string: Likewise.
* include/std/variant: Likewise.

2 years agolibstdc++: Make headers include their prerequisites
Nathan Sidwell [Tue, 24 May 2022 09:17:18 +0000 (10:17 +0100)]
libstdc++: Make headers include their prerequisites

These headers were relying on their includers having already included
some prerequisites.  That makes them unsuitable to be header-units.

So directly include the needed headers.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* include/bits/hashtable.h: Include required headers.
* include/bits/hashtable_policy.h: Likewise.
* include/bits/stl_heap.h: Likewise.
* include/bits/stl_iterator_base_funcs.h: Likewise.

2 years agolibstdc++: Fix printing of std::span for versioned namespace
François Dumont [Wed, 25 May 2022 20:05:48 +0000 (22:05 +0200)]
libstdc++: Fix printing of std::span for versioned namespace

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (StdSpanPrinter.__init__):
Strip typename from version namespace.

2 years agolibstdc++: Fix printing of std::atomic<shared_ptr<T>> for versioned namespace
Jonathan Wakely [Thu, 26 May 2022 08:49:40 +0000 (09:49 +0100)]
libstdc++: Fix printing of std::atomic<shared_ptr<T>> for versioned namespace

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (SharedPointerPrinter): Strip
versioned namespace from the template argument too.

2 years agolibstdc++: Rename tests like .../wchar_t/1.cc to .../wchar_t.cc
Jonathan Wakely [Fri, 20 May 2022 09:41:53 +0000 (10:41 +0100)]
libstdc++: Rename tests like .../wchar_t/1.cc to .../wchar_t.cc

There's no need to have directories containing a single test file, we
can rename the files to the directory names and remove the directories.

The dejagnu proc that filters out wchar_t tests just checks for
"wchar_t" anywhere in the path, so will work just as well on wchar_t.cc
or constexpr-wchar_t.cc paths.

libstdc++-v3/ChangeLog:

* testsuite/21_strings/basic_string/modifiers/pop_back/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string/modifiers/pop_back/char.cc:
...here.
* testsuite/21_strings/basic_string/modifiers/pop_back/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/modifiers/pop_back/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string/modifiers/swap/wchar_t/constexpr.cc:
Moved to...
* testsuite/21_strings/basic_string/modifiers/swap/constexpr-wchar_t.cc:
...here.
* testsuite/21_strings/basic_string/modifiers/swap/char/constexpr.cc:
Moved to...
* testsuite/21_strings/basic_string/modifiers/swap/constexpr.cc:
...here.
* testsuite/21_strings/basic_string/operations/contains/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/contains/char.cc:
...here.
* testsuite/21_strings/basic_string/operations/contains/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/contains/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string/operations/data/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/data/char.cc:
...here.
* testsuite/21_strings/basic_string/operations/data/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/data/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string/operations/ends_with/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/ends_with/char.cc:
...here.
* testsuite/21_strings/basic_string/operations/ends_with/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string/operations/starts_with/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/starts_with/char.cc:
...here.
* testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string/operations/substr/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/substr/char.cc:
...here.
* testsuite/21_strings/basic_string/operations/substr/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/operations/substr/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string/range_access/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string/range_access/char.cc:
...here.
* testsuite/21_strings/basic_string/range_access/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/range_access/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/char.cc:
...here.
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/char.cc:
...here.
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/modifiers/swap/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/modifiers/swap/char.cc:
...here.
* testsuite/21_strings/basic_string_view/modifiers/swap/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/modifiers/swap/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/contains/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/contains/char.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/contains/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/contains/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/data/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/data/char.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/data/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/data/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/ends_with/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/ends_with/char.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/ends_with/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/starts_with/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/starts_with/char.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/starts_with/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/substr/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/substr/char.cc:
...here.
* testsuite/21_strings/basic_string_view/operations/substr/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/operations/substr/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/range_access/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/range_access/char.cc:
...here.
* testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/range_access/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/char.cc:
...here.
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t.cc:
...here.
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t.cc:
...here.
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t.cc:
...here.
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/1.cc:
Moved to...
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/int.cc:
...here.
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t.cc:
...here.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char.cc:
...here.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char16_t.cc:
...here.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char32_t.cc:
...here.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char8_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char8_t.cc:
...here.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/int.cc:
...here.
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/wchar_t.cc:
...here.
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/char/1.cc:
Moved to...
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/char.cc:
...here.
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/char16_t/1.cc:
Moved to...
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/char16_t.cc:
...here.
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/char32_t/1.cc:
Moved to...
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/char32_t.cc:
...here.
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/char8_t/1.cc:
Moved to...
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/char8_t.cc:
...here.
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/short/1.cc:
Moved to...
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/short.cc:
...here.
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/wchar_t/1.cc:
Moved to...
* testsuite/21_strings/char_traits/requirements/explicit_instantiation/wchar_t.cc:
...here.

2 years agolibstdc++: Remove redundancy in test pathnames
Jonathan Wakely [Fri, 20 May 2022 09:26:07 +0000 (10:26 +0100)]
libstdc++: Remove redundancy in test pathnames

Repeating "explicit_instantiation" in these long pathnames is not
necessary.

libstdc++-v3/ChangeLog:

* testsuite/20_util/duration/requirements/explicit_instantiation/explicit_instantiation.cc:
Moved to...
* testsuite/20_util/duration/requirements/explicit_instantiation.cc: ...here.
* testsuite/20_util/time_point/requirements/explicit_instantiation/explicit_instantiation.cc:
Moved to...
* testsuite/20_util/time_point/requirements/explicit_instantiation.cc: ...here.
* testsuite/20_util/unique_ptr/requirements/explicit_instantiation/explicit_instantiation.cc:
Moved to...
* testsuite/20_util/unique_ptr/requirements/explicit_instantiation.cc: ...here.

2 years agoDaily bump.
GCC Administrator [Thu, 26 May 2022 00:16:30 +0000 (00:16 +0000)]
Daily bump.

2 years agoc++: fix ICE on invalid attributes [PR96637]
Marek Polacek [Thu, 28 Apr 2022 17:21:41 +0000 (13:21 -0400)]
c++: fix ICE on invalid attributes [PR96637]

When chaining attributes, attr_chainon should be used rather than plain
chainon, so that we don't end up with a TREE_LIST where one of the elements
is error_mark_node, which causes problems.  parser.cc has already been
fixed to use attr_chainon, but decl.cc has not.  Until now.

PR c++/96637

gcc/cp/ChangeLog:

* cp-tree.h (attr_chainon): Declare.
* decl.cc (start_decl): Use attr_chainon.
(grokdeclarator): Likewise.
* parser.cc (cp_parser_statement): No longer static.

gcc/testsuite/ChangeLog:

* g++.dg/parse/error64.C: New test.

2 years agoc++: CTAD with alias and nested template [PR105655]
Jason Merrill [Wed, 25 May 2022 16:38:58 +0000 (12:38 -0400)]
c++: CTAD with alias and nested template [PR105655]

Here, alias_ctad_tweaks expect tsubst_decl of a FUNCTION_DECL to return a
FUNCTION_DECL.  A reasonable expectation, but in this case we were replacing
the template args of the class-scope deduction guide with equivalent args,
so looking in the hash table we found the partial instantiation stored when
instantiating A<int>, which is a TEMPLATE_DECL.  It's fine for that to be
what is stored, but tsubst_function_decl should never return it.

PR c++/105655

gcc/cp/ChangeLog:

* pt.cc (build_template_decl): Add assert.
(tsubst_function_decl): Don't return a template.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/class-deduction-alias13.C: New test.

2 years agoc++: deduction from auto fn [PR105623]
Jason Merrill [Tue, 24 May 2022 21:37:58 +0000 (17:37 -0400)]
c++: deduction from auto fn [PR105623]

Since my patch for PR90451, we defer mark_used of single functions as late
as possible.  And since my r12-1273, we keep BASELINK from lookup around
rather than reconstruct it later.  These both made us try to instantiate g
with a function type that still had 'auto' as its return type.

PR c++/105623

gcc/cp/ChangeLog:

* decl2.cc (mark_used): Copy type from fn to BASELINK.
* pt.cc (unify_one_argument): Call mark_single_function.

gcc/testsuite/ChangeLog:

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

2 years agoc++: constexpr returning deallocated ptr
Jason Merrill [Tue, 24 May 2022 03:48:20 +0000 (23:48 -0400)]
c++: constexpr returning deallocated ptr

In constexpr-new3.C, the f7 function returns a deleted pointer, which we
were happily caching because the new and delete are balanced.  Don't.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_call_expression): Check for
heap vars in the result.

2 years agoc++: strict constexpr and local vars
Jason Merrill [Sun, 22 May 2022 19:04:33 +0000 (15:04 -0400)]
c++: strict constexpr and local vars

A change I was working on made constexpr_searcher.cc start to fail, and when
I looked at it I wondered why it had been accepted before.  This turned out
to be because we try to be more flexible about constant-evaluation of static
initializers, as allowed, but we were wrongly doing the same for non-static
initializers as well.

gcc/cp/ChangeLog:

* constexpr.cc (maybe_constant_init_1): Only pass false for
strict when initializing a variable of static duration.

libstdc++-v3/ChangeLog:

* testsuite/20_util/function_objects/constexpr_searcher.cc: Add
constexpr.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/constexpr-local4.C: New test.

2 years agoc++: ICE with temporary of class type in DMI [PR100252]
Marek Polacek [Tue, 26 Apr 2022 19:52:00 +0000 (15:52 -0400)]
c++: ICE with temporary of class type in DMI [PR100252]

Consider

  struct A {
    int x;
    int y = x;
  };

  struct B {
    int x = 0;
    int y = A{x}.y; // #1
  };

where for #1 we end up with

  {.x=(&<PLACEHOLDER_EXPR struct B>)->x, .y=(&<PLACEHOLDER_EXPR struct A>)->x}

that is, two PLACEHOLDER_EXPRs for different types on the same level in
a {}.  This crashes because our CONSTRUCTOR_PLACEHOLDER_BOUNDARY mechanism to
avoid replacing unrelated PLACEHOLDER_EXPRs cannot deal with it.

Here's why we wound up with those PLACEHOLDER_EXPRs: When we're performing
cp_parser_late_parsing_nsdmi for "int y = A{x}.y;" we use finish_compound_literal
on type=A, compound_literal={((struct B *) this)->x}.  When digesting this
initializer, we call get_nsdmi which creates a PLACEHOLDER_EXPR for A -- we don't
have any object to refer to yet.  After digesting, we have

  {.x=((struct B *) this)->x, .y=(&<PLACEHOLDER_EXPR struct A>)->x}

and since we've created a PLACEHOLDER_EXPR inside it, we marked the whole ctor
CONSTRUCTOR_PLACEHOLDER_BOUNDARY.  f_c_l creates a TARGET_EXPR and returns

  TARGET_EXPR <D.2384, {.x=((struct B *) this)->x, .y=(&<PLACEHOLDER_EXPR struct A>)->x}>

Then we get to

  B b = {};

and call store_init_value, which digests the {}, which produces

  {.x=NON_LVALUE_EXPR <0>, .y=(TARGET_EXPR <D.2395, {.x=(&<PLACEHOLDER_EXPR struct B>)->x, .y=(&<PLACEHOLDER_EXPR struct A>)->x}>).y}

lookup_placeholder in constexpr won't find an object to replace the
PLACEHOLDER_EXPR for B, because ctx->object will be D.2395 of type A, and we
cannot search outward from D.2395 to find 'b'.

The call to replace_placeholders in store_init_value will not do anything:
we've marked the inner { } CONSTRUCTOR_PLACEHOLDER_BOUNDARY, and it's only
a sub-expression, so replace_placeholders does nothing, so the <P_E struct B>
stays even though now is the perfect time to replace it because we have an
object for it: 'b'.

Later, in cp_gimplify_init_expr the *expr_p is

  D.2395 = {.x=(&<PLACEHOLDER_EXPR struct B>)->x, .y=(&<PLACEHOLDER_EXPR struct A>)->x}

where D.2395 is of type A, but we crash because we hit <P_E struct B>, which
has a different type.

My idea was to replace <P_E struct A> with D.2384 after creating the
TARGET_EXPR because that means we have an object we can refer to.
Then clear CONSTRUCTOR_PLACEHOLDER_BOUNDARY because we no longer have
a PLACEHOLDER_EXPR in the {}.  Then store_init_value will be able to
replace <P_E struct B> with 'b', and we should be good to go.  We must
be careful not to break guaranteed copy elision, so this replacement
happens in digest_nsdmi_init where we can see the whole initializer,
and avoid replacing any placeholders in TARGET_EXPRs used in the context
of initialization/copy elision.  This is achieved via the new function
called potential_prvalue_result_of.

While fixing this problem, I found PR105550, thus the FIXMEs in the
tests.

PR c++/100252

gcc/cp/ChangeLog:

* typeck2.cc (potential_prvalue_result_of): New.
(replace_placeholders_for_class_temp_r): New.
(digest_nsdmi_init): Call it.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/nsdmi-aggr14.C: New test.
* g++.dg/cpp1y/nsdmi-aggr15.C: New test.
* g++.dg/cpp1y/nsdmi-aggr16.C: New test.
* g++.dg/cpp1y/nsdmi-aggr17.C: New test.
* g++.dg/cpp1y/nsdmi-aggr18.C: New test.
* g++.dg/cpp1y/nsdmi-aggr19.C: New test.

2 years agoAArch64: Prioritise init_have_lse_atomics constructor [PR 105708]
Wilco Dijkstra [Wed, 25 May 2022 13:29:03 +0000 (14:29 +0100)]
AArch64: Prioritise init_have_lse_atomics constructor [PR 105708]

Increase the priority of the init_have_lse_atomics constructor so it runs
before other constructors. This improves chances that rr works when LSE
atomics are supported.

libgcc/
PR libgcc/105708
* config/aarch64/lse-init.c: Increase constructor priority.

2 years agoTweak comments.
Andrew MacLeod [Wed, 25 May 2022 14:39:31 +0000 (10:39 -0400)]
Tweak comments.

Adjust some mispellings in comments.

* gimple-range-cache.cc: Adjust comments.
* gimple-range-infer.cc: Adjust comments.
* gimple-range-infer.h: Adjust comments.
* gimple-range.cc: Adjust comments.

2 years agoUse infer instead of side-effect for ranges.
Andrew MacLeod [Tue, 24 May 2022 15:32:42 +0000 (11:32 -0400)]
Use infer instead of side-effect for ranges.

Rename the files and classes to reflect the term infer rather than side-effect.

* Makefile.in (OBJS): Use gimple-range-infer.o.
* gimple-range-cache.cc (ranger_cache::fill_block_cache): Change msg.
(ranger_cache::range_from_dom): Rename var side_effect to infer.
(ranger_cache::apply_inferred_ranges): Rename from apply_side_effects.
* gimple-range-cache.h: Include gimple-range-infer.h.
(class ranger_cache): Adjust prototypes, use infer_range_manager.
* gimple-range-infer.cc: Rename from gimple-range-side-effects.cc.
(gimple_infer_range::*): Rename from stmt_side_effects.
(infer_range_manager::*): Rename from side_effect_manager.
* gimple-range-side-effect.cc: Rename.
* gimple-range-side-effect.h: Rename.
* gimple-range-infer.h: Rename from gimple-range-side-effects.h.
(class gimple_infer_range): Rename from stmt_side_effects.
(class infer_range_manager): Rename from side_effect_manager.
* gimple-range.cc (gimple_ranger::register_inferred_ranges): Rename
from register_side_effects.
* gimple-range.h (register_inferred_ranges): Adjust prototype.
* range-op.h: Adjust comment.
* tree-vrp.cc (rvrp_folder::pre_fold_bb): Use register_inferred_ranges.
(rvrp_folder::post_fold_bb): Use register_inferred_ranges.

2 years agoRISC-V: Don't unconditionally add m,a,f,d in arch-canonicalize
Simon Cook [Wed, 25 May 2022 13:25:43 +0000 (14:25 +0100)]
RISC-V: Don't unconditionally add m,a,f,d in arch-canonicalize

This solves an issue where rv32i, etc. are canonicalized to rv32imafd
since the g->i addition of 'm', 'a', 'f', 'd' is not actually gated by
whether the input was rv32g/rv64g.

gcc/ChangeLog:

* config/riscv/arch-canonicalize: Only add mafd extension if
base was rv32/rv64g.

2 years agoGCN: Add gfx908/gfx90a to -march/-mtune in invoke.texi
Tobias Burnus [Wed, 25 May 2022 12:36:31 +0000 (14:36 +0200)]
GCN: Add gfx908/gfx90a to -march/-mtune in invoke.texi

gcc/
* doc/invoke.texi (AMD GCN Options): Add gfx908/gfx90a.

2 years agoc: Improve build_component_ref diagnostics [PR91134]
Jakub Jelinek [Wed, 25 May 2022 12:21:54 +0000 (14:21 +0200)]
c: Improve build_component_ref diagnostics [PR91134]

On the following testcase (the first dg-error line) we emit a weird
diagnostics and even fixit on pointerpointer->member
where pointerpointer is pointer to pointer to struct and we say
'pointerpointer' is a pointer; did you mean to use '->'?
The first part is indeed true, but suggesting -> when the code already
does use -> is confusing.
The following patch adjusts callers so that they tell it if it is from
. parsing or from -> parsing and in the latter case suggests to dereference
the left operand instead by adding (* before it and ) after it (before ->).
Or would a suggestion to add [0] before -> be better?

2022-05-25  Jakub Jelinek  <jakub@redhat.com>

PR c/91134
gcc/c/
* c-tree.h (build_component_ref): Add ARROW_LOC location_t argument.
* c-typeck.cc (build_component_ref): Likewise.  If DATUM is
INDIRECT_REF and ARROW_LOC isn't UNKNOWN_LOCATION, print a different
diagnostic and fixit hint if DATUM has pointer type.
* c-parser.cc (c_parser_postfix_expression,
c_parser_omp_variable_list): Adjust build_component_ref callers.
* gimple-parser.cc (c_parser_gimple_postfix_expression_after_primary):
Likewise.
gcc/objc/
* objc-act.cc (objc_build_component_ref): Adjust build_component_ref
caller.
gcc/testsuite/
* gcc.dg/pr91134.c: New test.

2 years agod: add more 'final' and 'override' to gcc/d/*.cc 'visit' impls
Iain Buclaw [Wed, 25 May 2022 10:33:34 +0000 (12:33 +0200)]
d: add more 'final' and 'override' to gcc/d/*.cc 'visit' impls

The first round of adding these missed several more cases in other
files where the Visitor pattern is used in the D front-end.

gcc/d/ChangeLog:

* expr.cc: Add "final" and "override" to all "visit" vfunc decls
as appropriate.
* imports.cc: Likewise.
* typeinfo.cc: Likewise.

Signed-off-by: Iain Buclaw <ibuclaw@gdcproject.org>
2 years agoFix misspelled default
Richard Biener [Wed, 25 May 2022 10:55:15 +0000 (12:55 +0200)]
Fix misspelled default

This fixes misspelled defaut: in switch statements in three
new testcases.

2022-05-25  Richard Biener  <rguenther@suse.de>

* gcc.dg/loop-unswitch-10.c: Fix misspelled defaut:
* gcc.dg/loop-unswitch-11.c: Likewise.
* gcc.dg/loop-unswitch-14.c: Likewise.

2 years agoasan: Fix up instrumentation of assignments which are both loads and stores [PR105714]
Jakub Jelinek [Wed, 25 May 2022 10:05:08 +0000 (12:05 +0200)]
asan: Fix up instrumentation of assignments which are both loads and stores [PR105714]

On the following testcase with -Os asan pass sees:
  <bb 6> [local count: 354334800]:
  # h_21 = PHI <h_15(6), 0(5)>
  *c.3_5 = *d.2_4;
  h_15 = h_21 + 1;
  if (h_15 != 3)
    goto <bb 6>; [75.00%]
  else
    goto <bb 7>; [25.00%]

  <bb 7> [local count: 118111600]:
  *c.3_5 = MEM[(struct a *)&b + 12B];
  _13 = c.3_5->x;
  return _13;
It instruments the
  *c.3_5 = *d.2_4;
assignment by adding
  .ASAN_CHECK (7, c.3_5, 4, 4);
  .ASAN_CHECK (6, d.2_4, 4, 4);
before it (which later lowers to checking the corresponding shadow
memory).  But when considering instrumentation of
  *c.3_5 = MEM[(struct a *)&b + 12B];
it doesn't instrument anything, because it sees that *c.3_5 store is
already instrumented in a dominating block and so there is no need
to instrument *c.3_5 store again (i.e. add another
  .ASAN_CHECK (7, c.3_5, 4, 4);
).  That is true, but misses the fact that we still want to
instrument the MEM[(struct a *)&b + 12B] load.

The following patch fixes that by changing has_stmt_been_instrumented_p
to consider both store and load in the assignment if it does both
(returning true iff both have been instrumented).
That matches how we handle e.g. builtin calls, where we also perform AND
of all the memory locs involved in the call.

I've verified that we still don't add the redundant
  .ASAN_CHECK (7, c.3_5, 4, 4);
call but just add
  _18 = &MEM[(struct a *)&b + 12B];
  .ASAN_CHECK (6, _18, 4, 4);
to instrument the load.

2022-05-25  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/105714
* asan.cc (has_stmt_been_instrumented_p): For assignments which
are both stores and loads, return true only if both destination
and source have been instrumented.

* gcc.dg/asan/pr105714.c: New test.

2 years agolibgomp: Fix occassional hangs with taskwait nowait depend
Jakub Jelinek [Wed, 25 May 2022 09:10:41 +0000 (11:10 +0200)]
libgomp: Fix occassional hangs with taskwait nowait depend

Richi reported occassional hangs with taskwait-depend-nowait-1.*
tests and I've finally manged to reproduce.  The problem is if
taskwait depend without nowait is encountered soon after
taskwait depend nowait and the former depends on the latter and there
is no other work to do, the taskwait depend without nowait is put
to sleep, but the empty_task optimization in
gomp_task_run_post_handle_dependers wouldn't wake it up in that
case.  gomp_task_run_post_handle_dependers normally does some wakeups
because it schedules more work (another task), which is not the
case of empty_task, but we need to do the wakeups that would be done
upon task completion so that we awake sleeping threads when the
last child is done.
So, the taskwait-depend-nowait-1.* testcase is fixed with the
else if (__builtin_expect (task->parent_depends_on, 0) part of
the patch.
The new testcase can hang on another problem, if the empty task
is the last task of a taskgroup, we need to use atomic store
like elsewhere to decrease the counter to 0, and wake up taskgroup
end if needed.
Yet another spot which can sleep is normal taskwait (without depend),
but I believe nothing needs to be done for that - in that case we
await solely until the children's queue has no tasks, tasks still
waiting for dependencies aren't accounted in that, but the reason
is that if taskwait should wait for something, there needs to be at least
one active child doing something (in the children queue), which then
possibly awakes some of its siblings when the dependencies are met,
or in the empty task case awakes further dependencies, but in any
case the child that finished is still handled as active child and
will awake taskwait at the end if there is nothing further to
do.
Last sleeping case are barriers, but that is handled by ++ret and
awaking the barrier.

2022-05-25  Jakub Jelinek  <jakub@redhat.com>

* task.c (gomp_task_run_post_handle_dependers): If empty_task
is the last task taskwait depend depends on, wake it up.
Similarly if it is the last child of a taskgroup, use atomic
store instead of decrement and awak taskgroup wait if any.
* testsuite/libgomp.c-c++-common/taskwait-depend-nowait-2.c: New test.

2 years agoAdd GIMPLE switch support to loop unswitching
Martin Liska [Mon, 22 Nov 2021 12:54:20 +0000 (13:54 +0100)]
Add GIMPLE switch support to loop unswitching

This patch adds support to unswitch loops with switch statements
based on invariant index.  It furthermore reworks the cost model
to allow an overall budget of statements to be created per original
loop by all unswitching opportunities in the loop.  Compared to
the original all unswitching opportunities in a loop are
pre-evaluated before the first transform which will allow future
changes to select the most profitable candidates first.

To efficiently support switch statements the pass now uses
ranger to simplify switch statements and conditions in loop
copies based on ranges extracted from the recorded set of
predicates unswitched.

gcc/ChangeLog:

* dbgcnt.def (DEBUG_COUNTER): Add loop_unswitch counter.
* params.opt (max-unswitch-level): Remove.
* doc/invoke.texi (max-unswitch-level): Likewise.
* tree-cfg.cc (gimple_lv_add_condition_to_bb): Support not
gimplified expressions.
* tree-ssa-loop-unswitch.cc (struct unswitch_predicate): New.
(tree_may_unswitch_on): Rename to ...
(find_unswitching_predicates_for_bb): ... this and handle
switch statements.
(get_predicates_for_bb): Likewise.
(set_predicates_for_bb): Likewise.
(init_loop_unswitch_info): Likewise.
(tree_ssa_unswitch_loops): Prepare stuff before calling
tree_unswitch_single_loop.
(tree_unswitch_single_loop): Rework the function using
pre-computed predicates and with a per original loop cost model.
(merge_last): New.
(add_predicate_to_path): Likewise.
(find_range_for_lhs): Likewise.
(simplify_using_entry_checks): Rename to ...
(evaluate_control_stmt_using_entry_checks): ... this, handle
switch statements and improve simplifications using ranger.
(simplify_loop_version): Rework using
evaluate_control_stmt_using_entry_checks.
(evaluate_bbs): New.
(evaluate_loop_insns_for_predicate): Likewise.
(tree_unswitch_loop): Adjust to allow switch statements and
pass in the edge to unswitch.
(clean_up_after_unswitching): New.
(pass_tree_unswitch::execute): Pass down fun.

gcc/testsuite/ChangeLog:

* gcc.dg/loop-unswitch-7.c: New test.
* gcc.dg/loop-unswitch-8.c: New test.
* gcc.dg/loop-unswitch-9.c: New test.
* gcc.dg/loop-unswitch-10.c: New test.
* gcc.dg/loop-unswitch-11.c: New test.
* gcc.dg/loop-unswitch-12.c: New test.
* gcc.dg/loop-unswitch-13.c: New test.
* gcc.dg/loop-unswitch-14.c: New test.
* gcc.dg/loop-unswitch-15.c: New test.
* gcc.dg/loop-unswitch-16.c: New test.
* gcc.dg/loop-unswitch-17.c: New test.
* gcc.dg/torture/20220518-1.c: New test.
* gcc.dg/torture/20220518-2.c: New test.
* gcc.dg/torture/20220525-1.c: New test.
* gcc.dg/alias-10.c: Adjust.
* gcc.dg/tree-ssa/loop-6.c: Likewise.
* gcc.dg/loop-unswitch-1.c: Likewise.

Co-authored-by: Richard Biener <rguenther@suse.de>
2 years agoaarch64: Fix pac-ret with unusual dwarf in libgcc unwinder [PR104689]
Szabolcs Nagy [Thu, 10 Feb 2022 17:42:56 +0000 (17:42 +0000)]
aarch64: Fix pac-ret with unusual dwarf in libgcc unwinder [PR104689]

The RA_SIGN_STATE dwarf pseudo-register is normally only set using the
DW_CFA_AARCH64_negate_ra_state (== DW_CFA_window_save) operation which
toggles the return address signedness state (the default state is 0).
(It may be set by remember/restore_state CFI too, those save/restore
the state of all registers.)

However RA_SIGN_STATE can be set directly via DW_CFA_val_expression too.
GCC does not generate such CFI but some other compilers reportedly do.

Note: the toggle operation must not be mixed with other dwarf register
rule CFI within the same CIE and FDE.

In libgcc we assume REG_UNSAVED means the RA_STATE is set using toggle
operations, otherwise we assume its value is set by other CFI.

libgcc/ChangeLog:

PR target/104689
* config/aarch64/aarch64-unwind.h (aarch64_frob_update_context):
Handle the !REG_UNSAVED case.
* unwind-dw2.c (execute_cfa_program): Fail toggle if !REG_UNSAVED.

gcc/testsuite/ChangeLog:

PR target/104689
* gcc.target/aarch64/pr104689.c: New test.

2 years agoDaily bump.
GCC Administrator [Wed, 25 May 2022 00:17:06 +0000 (00:17 +0000)]
Daily bump.

2 years agoFix profile count maintenance in vectorizer peeling.
Eugene Rozenfeld [Tue, 26 Apr 2022 21:28:16 +0000 (14:28 -0700)]
Fix profile count maintenance in vectorizer peeling.

This patch changes the code to save/restore profile counts for
the epliog loop (when not using scalar loop in the epilog)
instead of scaling them down and then back up, which may lead
to problems if we scale down to 0.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:

* tree-vect-loop-manip.cc (vect_do_peeling): Save/restore profile
counts for the epilog loop.

2 years agoPR middle-end/105604 - ICE: in tree_to_shwi with vla in struct and sprintf
Martin Sebor [Tue, 24 May 2022 22:01:12 +0000 (16:01 -0600)]
PR middle-end/105604 - ICE: in tree_to_shwi with vla in struct and sprintf

gcc/ChangeLog:

PR middle-end/105604
* gimple-ssa-sprintf.cc (set_aggregate_size_and_offset): Add comments.
(get_origin_and_offset_r): Remove null handling.  Handle variable array
sizes.
(get_origin_and_offset): Handle null argument here.  Simplify.
(alias_offset): Update comment.
* pointer-query.cc (field_at_offset): Update comment.  Handle members
of variable-length types.

gcc/testsuite/ChangeLog:

PR middle-end/105604
* gcc.dg/Wrestrict-24.c: New test.
* gcc.dg/Wrestrict-25.c: New test.
* gcc.dg/Wrestrict-26.c: New test.

Co-authored-by: Richard Biener <rguenther@suse.de>
2 years agoc++: *this folding in constexpr call
Jason Merrill [Fri, 20 May 2022 17:32:10 +0000 (13:32 -0400)]
c++: *this folding in constexpr call

The code in cxx_eval_call_expression to fold *this was doing the wrong thing
for array decay; we can use cxx_fold_indirect_ref instead.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_fold_indirect_ref): Add default arg.
(cxx_eval_call_expression): Call it.
(cxx_fold_indirect_ref_1): Handle null empty_base.

2 years agogcc.misc-tests/outputs.exp: Use link test to check for -gsplit-dwarf support
Joel Brobecker [Tue, 24 May 2022 19:51:42 +0000 (12:51 -0700)]
gcc.misc-tests/outputs.exp: Use link test to check for -gsplit-dwarf support

We have noticed that, when running the GCC testsuite on AArch64
RTEMS 6, we have about 150 tests failing due to a link failure.
When investigating, we found that all the tests were failing
due to the use of -gsplit-dwarf.

On this platform, using -gsplit-dwarf currently causes an error
during the link:

    | /[...]/ld: a.out section `.unexpected_sections' will not fit
    |    in region `UNEXPECTED_SECTIONS'
    | /[...]/ld: region `UNEXPECTED_SECTIONS' overflowed by 56 bytes

The error is a bit cryptic, but the source of the issue is that
the linker does not currently support the sections generated
by -gsplit-dwarf (.debug_gnu_pubnames, .debug_gnu_pubtypes).
This means that the -gsplit-dwarf feature itself really isn't
supported on this platform, at least for the moment.

This commit enhances the -gsplit-dwarf support check to be
a compile-and-link check, rather than just a compile check.
This allows it to properly detect that this feature isn't
supported on platforms such as AArch64 RTEMS where the compilation
works, but not the link.

Tested on aarch64-rtems, where a little over 150 tests are now
passing, instead of failing, as well as on x86_64-linux, where
the results are identical, and where the .log file was also manually
inspected to make sure that the use of the -gsplit-dwarf option
was preserved.

gcc/testsuite/ChangeLog:

* gcc.misc-tests/outputs.exp: Make the -gsplit-dwarf test
a compile-and-link test rather than a compile-only test.

2 years agoc++: discarded-value and constexpr
Jason Merrill [Thu, 19 May 2022 16:24:33 +0000 (12:24 -0400)]
c++: discarded-value and constexpr

I've been thinking for a while that the 'lval' parameter needed a third
value for discarded-value expressions; most importantly,
cxx_eval_store_expression does extra work for an lvalue result, and we also
don't want to do the l->r conversion.

Mostly this is pretty mechanical.  Apart from the _store_ fix, I also use
vc_discard for substatements of a STATEMENT_LIST other than a stmt-expr
result, and avoid building _REFs to be ignored in a few other places.

gcc/cp/ChangeLog:

* constexpr.cc (enum value_cat): New. Change all 'lval' parameters
from int to value_cat.  Change most false to vc_prvalue, most true
to vc_glvalue, cases where the return value is ignored to
vc_discard.
(cxx_eval_statement_list): Only vc_prvalue for stmt-expr result.
(cxx_eval_store_expression): Only build _REF for vc_glvalue.
(cxx_eval_array_reference, cxx_eval_component_reference)
(cxx_eval_indirect_ref, cxx_eval_constant_expression): Likewise.

2 years agoc++: constexpr empty base redux [PR105622]
Jason Merrill [Fri, 20 May 2022 20:16:25 +0000 (16:16 -0400)]
c++: constexpr empty base redux [PR105622]

Here calling the constructor for s.__size_ had ctx->ctor for s itself
because cxx_eval_store_expression doesn't create a ctor for the empty field.
Then cxx_eval_call_expression returned the s initializer, and my empty base
overhaul in r13-160 got confused because the type of init is not an empty
class.  But that's OK, we should be checking the type of the original LHS
instead.  We also want to use initialized_type in the condition, in case
init is an AGGR_INIT_EXPR.

I spent quite a while working on more complex solutions before coming back
to this simple one.

PR c++/105622

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_store_expression): Adjust assert.
Use initialized_type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/no_unique_address14.C: New test.

2 years agoAdd new parameter to vec_perm_const hook for specifying operand mode.
Prathamesh Kulkarni [Tue, 24 May 2022 18:56:28 +0000 (00:26 +0530)]
Add new parameter to vec_perm_const hook for specifying operand mode.

The rationale of the patch is to support vec_perm_expr of the form:
lhs = vec_perm_expr<rhs, mask>
where lhs and rhs are vector types with different lengths but have
same element type. For example, lhs is SVE vector and rhs
is corresponding AdvSIMD vector.

It would also allow to express extract even/odd and interleave operations
with a VEC_PERM_EXPR.  The interleave currently has the issue that we have
to artificially widen the inputs with "dont-care" elements.

gcc/ChangeLog:

* target.def (vec_perm_const): Define new parameter op_mode and
update doc.
* doc/tm.texi: Regenerate.
* config/aarch64/aarch64.cc (aarch64_vectorize_vec_perm_const): Adjust
vec_perm_const hook to add new parameter op_mode and return false
if result and operand modes do not match.
* config/arm/arm.cc (arm_vectorize_vec_perm_const): Likewise.
* config/gcn/gcn.cc (gcn_vectorize_vec_perm_const): Likewise.
* config/ia64/ia64.cc (ia64_vectorize_vec_perm_const): Likewise.
* config/mips/mips.cc (mips_vectorize_vec_perm_const): Likewise.
* config/rs6000/rs6000.cc (rs6000_vectorize_vec_perm_const): Likewise
* config/s390/s390.cc (s390_vectorize_vec_perm_const): Likewise.
* config/sparc/sparc.cc (sparc_vectorize_vec_perm_const): Likewise.
* config/i386/i386-expand.cc (ix86_vectorize_vec_perm_const): Likewise.
* config/i386/i386-expand.h (ix86_vectorize_vec_perm_const): Adjust
prototype.
* config/i386/sse.md (ashrv4di3): Adjust call to vec_perm_const hook.
(ashrv2di3): Likewise.
* optabs.cc (expand_vec_perm_const): Likewise.
* optabs-query.h (can_vec_perm_const_p): Adjust prototype.
* optabs-query.cc (can_vec_perm_const_p): Define new parameter
op_mode and pass it to vec_perm_const hook.
(can_mult_highpart_p): Adjust call to can_vec_perm_const_p.
* match.pd (vec_perm X Y CST): Likewise.
* tree-ssa-forwprop.cc (simplify_vector_constructor): Likewise.
* tree-vect-data-refs.cc (vect_grouped_store_supported): Likewise.
(vect_grouped_load_supported): Likewise.
(vect_shift_permute_load_chain): Likewise.
* tree-vect-generic.cc (lower_vec_perm): Likewise.
* tree-vect-loop-manip.cc (interleave_supported_p): Likewise.
* tree-vect-loop.cc (have_whole_vector_shift): Likewise.
* tree-vect-patterns.cc (vect_recog_rotate_pattern): Likewise.
* tree-vect-slp.cc (can_duplicate_and_interleave_p): Likewise.
(vect_transform_slp_perm_load): Likewise.
(vectorizable_slp_permutation): Likewise.
* tree-vect-stmts.cc (perm_mask_for_reverse): Likewise.
(vectorizable_bswap): Likewise.
(scan_store_can_perm_p): Likewise.
(vect_gen_perm_mask_checked): Likewise.

2 years agox86: Document -mcet-switch
H.J. Lu [Fri, 11 Mar 2022 20:51:34 +0000 (12:51 -0800)]
x86: Document -mcet-switch

When -fcf-protection=branch is used, the compiler will generate jump
tables for switch statements where the indirect jump is prefixed with
the NOTRACK prefix, so it can jump to non-ENDBR targets.  Since the
indirect jump targets are generated by the compiler and stored in
read-only memory, this does not result in a direct loss of hardening.
But if the jump table index is attacker-controlled, the indirect jump
may not be constrained by CET.

Document -mcet-switch to generate jump tables for switch statements with
ENDBR and skip the NOTRACK prefix for indirect jump.  This option should
be used when the NOTRACK prefix is disabled.

PR target/104816
* config/i386/i386.opt: Remove Undocumented.
* doc/invoke.texi: Document -mcet-switch.

2 years agoamdgcn: Add gfx90a support
Andrew Stubbs [Thu, 24 Feb 2022 17:16:13 +0000 (17:16 +0000)]
amdgcn: Add gfx90a support

This adds architecture options and multilibs for the AMD GFX90a GPUs.
It also tidies up some of the ISA selection code, and corrects a few small
mistake in the gfx908 naming.

gcc/ChangeLog:

* config.gcc (amdgcn): Accept --with-arch=gfx908 and gfx90a.
* config/gcn/gcn-opts.h (enum gcn_isa): New.
(TARGET_GCN3): Use enum gcn_isa.
(TARGET_GCN3_PLUS): Likewise.
(TARGET_GCN5): Likewise.
(TARGET_GCN5_PLUS): Likewise.
(TARGET_CDNA1): New.
(TARGET_CDNA1_PLUS): New.
(TARGET_CDNA2): New.
(TARGET_CDNA2_PLUS): New.
(TARGET_M0_LDS_LIMIT): New.
(TARGET_PACKED_WORK_ITEMS): New.
* config/gcn/gcn.cc (gcn_isa): Change to enum gcn_isa.
(gcn_option_override): Recognise CDNA ISA variants.
(gcn_omp_device_kind_arch_isa): Support gfx90a.
(gcn_expand_prologue): Make m0 init optional.
Add support for packed work items.
(output_file_start): Support gfx90a.
(gcn_hsa_declare_function_name): Support gfx90a metadata.
* config/gcn/gcn.h (TARGET_CPU_CPP_BUILTINS):Add __CDNA1__ and
__CDNA2__.
* config/gcn/gcn.md (<su>mulsi3_highpart): Use TARGET_GCN5_PLUS.
(<su>mulsi3_highpart_imm): Likewise.
(<su>mulsidi3): Likewise.
(<su>mulsidi3_imm): Likewise.
* config/gcn/gcn.opt (gpu_type): Add gfx90a.
* config/gcn/mkoffload.cc (EF_AMDGPU_MACH_AMDGCN_GFX90a): New.
(main): Support gfx90a.
* config/gcn/t-gcn-hsa: Add gfx90a multilib.
* config/gcn/t-omp-device: Add gfx90a isa.

libgomp/ChangeLog:

* plugin/plugin-gcn.c (EF_AMDGPU_MACH): Add
EF_AMDGPU_MACH_AMDGCN_GFX90a.
(gcn_gfx90a_s): New.
(isa_hsa_name): Support gfx90a.
(isa_code): Likewise.

2 years agoamdgcn: Remove LLVM 9 assembler/linker support
Andrew Stubbs [Tue, 15 Feb 2022 15:33:53 +0000 (15:33 +0000)]
amdgcn: Remove LLVM 9 assembler/linker support

The minimum required LLVM version is now 13.0.1, and is enforced by configure.

gcc/ChangeLog:

* config.in: Regenerate.
* config/gcn/gcn-hsa.h (X_FIJI): Delete.
(X_900): Delete.
(X_906): Delete.
(X_908): Delete.
(S_FIJI): Delete.
(S_900): Delete.
(S_906): Delete.
(S_908): Delete.
(NO_XNACK): New macro.
(NO_SRAM_ECC): New macro.
(SRAMOPT): Keep only v4 variant.
(HSACO3_SELECT_OPT): Delete.
(DRIVER_SELF_SPECS): Delete.
(ASM_SPEC): Remove LLVM 9 support.
* config/gcn/gcn-valu.md
(gather<mode>_insn_2offsets<exec>): Remove assembler bug workaround.
(scatter<mode>_insn_2offsets<exec_scatter>): Likewise.
* config/gcn/gcn.cc (output_file_start): Remove LLVM 9 support.
(print_operand_address): Remove assembler bug workaround.
* config/gcn/mkoffload.cc (EF_AMDGPU_XNACK_V3): Delete.
(EF_AMDGPU_SRAM_ECC_V3): Delete.
(SET_XNACK_ON): Delete v3 variants.
(SET_XNACK_OFF): Delete v3 variants.
(TEST_XNACK): Delete v3 variants.
(SET_SRAM_ECC_ON): Delete v3 variants.
(SET_SRAM_ECC_ANY): Delete v3 variants.
(SET_SRAM_ECC_OFF): Delete v3 variants.
(SET_SRAM_ECC_UNSUPPORTED): Delete v3 variants.
(TEST_SRAM_ECC_ANY): Delete v3 variants.
(TEST_SRAM_ECC_ON): Delete v3 variants.
(copy_early_debug_info): Remove v3 support.
(main): Remove v3 support.
* configure: Regenerate.
* configure.ac: Replace all GCN feature checks with a version check.

2 years agolibiberty: remove FINAL and OVERRIDE from ansidecl.h
David Malcolm [Tue, 24 May 2022 14:22:37 +0000 (10:22 -0400)]
libiberty: remove FINAL and OVERRIDE from ansidecl.h

libiberty's ansidecl.h provides macros FINAL and OVERRIDE to allow
virtual functions to be labelled with the C++11 "final" and "override"
specifiers, but with empty implementations on pre-C++11 C++ compilers.

We've used the macros in many places in GCC, but as of as of GCC 11
onwards GCC has required a C++11 compiler, such as GCC 4.8 or later.
On the assumption that any such compiler correctly implements "final"
and "override", I've simplified GCC's codebase by replacing all uses of
the FINAL and OVERRIDE macros in GCC's source tree with the lower-case
specifiers (via commits r13-690-gff171cb13df671 and
r13-716-g8473ef7be60443)

The macros are reportedly not used anywhere in binutils-gdb.

This patch completes this transition for GCC by eliminating the macros
from ansidecl.h.

include/ChangeLog:
* ansidecl.h: Drop macros OVERRIDE and FINAL.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoOptimize double word negation of zero extended values on x86.
Roger Sayle [Tue, 24 May 2022 14:18:56 +0000 (15:18 +0100)]
Optimize double word negation of zero extended values on x86.

It's not uncommon for GCC to convert between a (zero or one) Boolean
value and a (zero or all ones) mask value, possibly of a wider type,
using negation.

Currently on x86_64, the following simple test case:
__int128 foo(unsigned long x) { return -(__int128)x; }

compiles with -O2 to:

        movq    %rdi, %rax
        xorl    %edx, %edx
        negq    %rax
        adcq    $0, %rdx
        negq    %rdx
        ret

with this patch, which adds an additional peephole2 to i386.md,
we instead generate the improved:

        movq    %rdi, %rax
        negq    %rax
        sbbq    %rdx, %rdx
        ret

[and likewise for the (DImode) long long version using -m32.]
A peephole2 is appropriate as the double word negation and the
operation providing the xor are typically only split after combine.

In fact, the new peephole2 sequence:
;; Convert:
;;   xorl %edx, %edx
;;   negl %eax
;;   adcl $0, %edx
;;   negl %edx
;; to:
;;   negl %eax
;;   sbbl %edx, %edx    // *x86_mov<mode>cc_0_m1

is nearly identical to (and placed immediately after) the existing:
;; Convert:
;;   mov %esi, %edx
;;   negl %eax
;;   adcl $0, %edx
;;   negl %edx
;; to:
;;   xorl %edx, %edx
;;   negl %eax
;;   sbbl %esi, %edx

One potential objection/concern is that "sbb? %reg,%reg" may possibly be
incorrectly perceived as a false register dependency on older hardware,
much like "xor? %reg,%reg" may be perceived as a false dependency on
really old hardware.  This doesn't currently appear to be a concern
for the i386 backend's *x86_move<mode>cc_0_m1 as shown by the following
test code:

int bar(unsigned int x, unsigned int y) {
  return x > y ? -1 : 0;
}

which currently generates a "naked" sbb:
        cmp     esi, edi
        sbb     eax, eax
        ret

If anyone does potentially encounter a stall, it would easy to add
a splitter or peephole2 controlled by a tuning flag to insert an additional
xor to break the false dependency chain (when not optimizing for size),
but I don't believe this is required on recent microarchitectures.

2022-05-24 Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/i386/i386.md (peephole2): Convert xor;neg;adc;neg,
i.e. a double word negation of a zero extended operand, to
neg;sbb.

gcc/testsuite/ChangeLog
* gcc.target/i386/neg-zext-1.c: New test case for -m32.
* gcc.target/i386/neg-zext-2.c: New test case for -m64.

2 years agoPR tree-optimization/105668: Provide vcond_mask_v1tiv1ti pattern.
Roger Sayle [Tue, 24 May 2022 14:15:12 +0000 (15:15 +0100)]
PR tree-optimization/105668: Provide vcond_mask_v1tiv1ti pattern.

This patch is an alternate/supplementary fix to PR tree-optimization/105668
that provides a vcond_mask_v1titi optab/define_expand to the i386 backend.
An undocumented feature/bug of GCC's vectorization is that any target that
provides a vec_cmpeq<mode><mode> has to also provide a matching
vcond_mask<mode><mode>.  This backend patch preserves the status quo,
rather than fixes the underlying problem.

One aspect of this clean-up is that ix86_expand_sse_movcc provides
fallback implementations using pand/pandn/por that effectively make
V2DImode and V1TImode vcond_mask available on any TARGET_SSE2, not
just TARGET_SSE4_2.  This allows a simplification as V2DI mode can
be handled by using a VI_128 mode iterator instead of a VI124_128
mode iterator, and instead this define_expand is effectively renamed
to provide a V1TImode vcond_mask expander (as V1TI isn't in VI_128).

2022-05-24  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR tree-optimization/105668
* config/i386/i386-expand.cc (ix86_expand_sse_movcc): Support
V1TImode, just like V2DImode.
* config/i386/sse.md (vcond_mask_<mode><sseintvecmodelower>):
Use VI_128 mode iterator instead of VI124_128 to include V2DI.
(vcond_mask_v2div2di): Delete.
(vcond_mask_v1tiv1ti): New define_expand.

gcc/testsuite/ChangeLog
PR tree-optimization/105668
* gcc.target/i386/pr105668.c: New test case.

2 years agoMinor improvement to genpreds.cc
Roger Sayle [Tue, 24 May 2022 13:29:27 +0000 (14:29 +0100)]
Minor improvement to genpreds.cc

This simple patch implements Richard Biener's suggestion in comment #6
of PR tree-optimization/52171 (from February 2013) that the insn-preds
code generated by genpreds can avoid using strncmp when matching constant
strings of length one.

The effect of this patch is best explained by the diff of insn-preds.cc:
<       if (!strncmp (str + 1, "g", 1))
---
>       if (str[1] == 'g')
3104c3104
<       if (!strncmp (str + 1, "m", 1))
---
>       if (str[1] == 'm')
3106c3106
<       if (!strncmp (str + 1, "c", 1))
---
>       if (str[1] == 'c')
...

The equivalent optimization is performed by GCC (but perhaps not by the
host compiler), but generating simpler/smaller code may encourage further
optimizations (such as use of a switch statement).

2022-05-24  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* genpreds.cc (write_lookup_constraint_1): Avoid generating a call
to strncmp for strings of length one.

2 years agoc++: set TYPE_CANONICAL for more template types
Patrick Palka [Tue, 24 May 2022 13:27:39 +0000 (09:27 -0400)]
c++: set TYPE_CANONICAL for more template types

When forming a class template specialization, lookup_template_class
uses structural equality for the specialized type whenever one of its
template arguments uses structural equality.  This is the sensible thing
to do in a vacuum, but given that we already effectively deduplicate class
specializations via the type_specializations table, we ought to be able
to safely assume that each class specialization is unique and therefore
canonical, regardless of the canonicity of the template arguments.

To that end this patch makes us use the canonical type machinery for all
type specializations, except for the case where a PARM_DECL appears in
the template arguments (this special case was recently added by
r12-3766-g72394d38d929c7).

Additionally, this patch makes us use the canonical type machinery for
TEMPLATE_TEMPLATE_PARMs and BOUND_TEMPLATE_TEMPLATE_PARMs, by extending
canonical_type_parameter appropriately.  A comment in tsubst says it's
unsafe to set TYPE_CANONICAL for a lowered TEMPLATE_TEMPLATE_PARM, but
I'm not sure this is true anymore.  According to Jason, this comment
(from r120341) became obsolete when later that year r129844 started to
substitute the template parms of ttps.  Note that r10-7817-ga6f400239d792d
recently changed process_template_parm to clear TYPE_CANONICAL for
TEMPLATE_TEMPLATE_PARM consistent with the tsubst comment; this patch
changes both functions to set instead of clear TYPE_CANONICAL for ttps.

These changes improve compile time of template-heavy code by around 10%
for me (with a release compiler).  For instance, compile time for the
libstdc++ test std/ranges/adaptors/all.cc drops from 1.45s to 1.25s, and
for the range-v3 test test/view/zip.cpp from 5.38s to 4.88s.  The total
number of calls to structural_comptypes for the latter test drops from
10.5M to 1.8M.  Memory use is unaffected (as expected).

The new testcase verifies we check the r12-3766 PARM_DECL special case
in bind_template_template_parm too.

gcc/cp/ChangeLog:

* cp-tree.h (any_template_arguments_need_structural_equality_p):
Declare.
* pt.cc (struct ctp_hasher): Define.
(ctp_table): Define.
(canonical_type_parameter): Use it.
(process_template_parm): Set TYPE_CANONICAL for
TEMPLATE_TEMPLATE_PARM too.
(lookup_template_class_1): Remove now outdated comment for the
any_template_arguments_need_structural_equality_p test.
(tsubst) <case TEMPLATE_TEMPLATE_PARM, etc>: Don't specifically
clear TYPE_CANONICAL for ttps.  Set TYPE_CANONICAL on the
substituted type later.
(any_template_arguments_need_structural_equality_p): Return
true for any_targ_node.  Don't return true just because a
template argument uses structural equality.  Add comment for
the PARM_DECL special case.
(rewrite_template_parm): Set TYPE_CANONICAL on the rewritten
parm's type later.
* tree.cc (bind_template_template_parm): Set TYPE_CANONICAL
when safe to do so.
* typeck.cc (structural_comptypes) [check_alias]: Increment
processing_template_decl before checking
dependent_alias_template_spec_p.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-52830a.C: New test.

2 years agod: add 'final' and 'override' to gcc/d/*.cc 'visit' impls
David Malcolm [Tue, 24 May 2022 13:07:22 +0000 (09:07 -0400)]
d: add 'final' and 'override' to gcc/d/*.cc 'visit' impls

gcc/d/ChangeLog:
* decl.cc: Add "final" and "override" to all "visit" vfunc decls
as appropriate.
* expr.cc: Likewise.
* toir.cc: Likewise.
* typeinfo.cc: Likewise.
* types.cc: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoRISC-V: Cache Management Operation instructions testcases
ShiYulong [Tue, 10 May 2022 03:25:26 +0000 (11:25 +0800)]
RISC-V: Cache Management Operation instructions testcases

This commit adds testcases about CMO instructions.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/cmo-zicbom-1.c: New test.
* gcc.target/riscv/cmo-zicbom-2.c: New test.
* gcc.target/riscv/cmo-zicbop-1.c: New test.
* gcc.target/riscv/cmo-zicbop-2.c: New test.
* gcc.target/riscv/cmo-zicboz-1.c: New test.
* gcc.target/riscv/cmo-zicboz-2.c: New test.

2 years agoRISC-V: Cache Management Operation instructions
ShiYulong [Tue, 10 May 2022 03:25:25 +0000 (11:25 +0800)]
RISC-V: Cache Management Operation instructions

This commit adds cbo.clea, cbo.flush, cbo.inval, cbo.zero, prefetch.i,
prefetch.r and prefetch.w instructions.

diff with the previous version:
We use unspec_volatile instead of unspec for those cache operations.
We use UNSPECV instead of UNSPEC and move them to unspecv.

gcc/ChangeLog:

* config/riscv/predicates.md (imm5_operand): Add a new operand type for
prefetch instructions.
* config/riscv/riscv-builtins.cc (AVAIL): Add new AVAILs for CMO ISA
Extensions.
(RISCV_ATYPE_SI): New.
(RISCV_ATYPE_DI): New.
* config/riscv/riscv-ftypes.def (0): New.
(1): New.
* config/riscv/riscv.md (riscv_clean_<mode>): New.
(riscv_flush_<mode>): New.
(riscv_inval_<mode>): New.
(riscv_zero_<mode>): New.
(prefetch): New.
(riscv_prefetchi_<mode>): New.
* config/riscv/riscv-cmo.def: New file.

2 years agoRISC-V: Add mininal support for Zicbo[mzp]
ShiYulong [Tue, 10 May 2022 03:25:24 +0000 (11:25 +0800)]
RISC-V: Add mininal support for Zicbo[mzp]

This commit adds minimal support for 'Zicbom','Zicboz' and 'Zicbop' extensions.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc: Add zicbom, zicboz, zicbop extensions.
* config/riscv/riscv-opts.h (MASK_ZICBOZ): New.
(MASK_ZICBOM): New.
(MASK_ZICBOP): New.
(TARGET_ZICBOZ): New.
(TARGET_ZICBOM): New.
(TARGET_ZICBOP): New.
* config/riscv/riscv.opt (riscv_zicmo_subext): New.

2 years agotree-vect-slp-patterns.cc: add 'final' and 'override' to vect_pattern::build impls
David Malcolm [Tue, 24 May 2022 12:53:30 +0000 (08:53 -0400)]
tree-vect-slp-patterns.cc: add 'final' and 'override' to vect_pattern::build impls

gcc/ChangeLog:
* tree-vect-slp-patterns.cc: Add "final" and "override" to
vect_pattern::build impls as appropriate.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoipa: add 'final' and 'override' to call_summary_base vfunc impls
David Malcolm [Tue, 24 May 2022 12:51:00 +0000 (08:51 -0400)]
ipa: add 'final' and 'override' to call_summary_base vfunc impls

gcc/ChangeLog:
* ipa-cp.cc: Add "final" and "override" to call_summary_base vfunc
implementations, removing redundant "virtual" as appropriate.
* ipa-fnsummary.h: Likewise.
* ipa-modref.cc: Likewise.
* ipa-param-manipulation.cc: Likewise.
* ipa-profile.cc: Likewise.
* ipa-prop.h: Likewise.
* ipa-pure-const.cc: Likewise.
* ipa-reference.cc: Likewise.
* ipa-sra.cc: Likewise.
* symbol-summary.h: Likewise.
* symtab-thunks.cc: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoRevert "Mitigate -Wmaybe-uninitialized in expmed.cc."
Martin Liska [Tue, 24 May 2022 11:30:00 +0000 (13:30 +0200)]
Revert "Mitigate -Wmaybe-uninitialized in expmed.cc."

This reverts commit c5c523723149112d117a6d3b259dfd95b032a545.