platform/upstream/gcc.git
2 years agors6000: Add Power10 optimization for _mm_blendv*
Paul A. Clarke [Thu, 21 Oct 2021 01:34:06 +0000 (20:34 -0500)]
rs6000: Add Power10 optimization for _mm_blendv*

Power10 ISA added `xxblendv*` instructions which are realized in the
`vec_blendv` instrinsic.

Use `vec_blendv` for `_mm_blendv_epi8`, `_mm_blendv_ps`, and
`_mm_blendv_pd` compatibility intrinsics, when `_ARCH_PWR10`.

Update original implementation of _mm_blendv_epi8 to use signed types,
to better match the function parameters. Realization is unchanged.

Also, copy a test from i386 for testing `_mm_blendv_ps`.
This should have come with commit ed04cf6d73e233c74c4e55c27f1cbd89ae4710e8,
but was inadvertently omitted.

2022-01-10  Paul A. Clarke  <pc@us.ibm.com>

gcc
* config/rs6000/smmintrin.h (_mm_blendv_epi8): Use vec_blendv
when _ARCH_PWR10. Use signed types.
(_mm_blendv_ps): Use vec_blendv when _ARCH_PWR10.
(_mm_blendv_pd): Likewise.

gcc/testsuite
* gcc.target/powerpc/sse4_1-blendvps.c: Copy from gcc.target/i386,
adjust dg directives to suit.

2 years ago[vect] Re-analyze all modes for epilogues
Andre Vieira [Thu, 2 Dec 2021 14:34:15 +0000 (14:34 +0000)]
[vect] Re-analyze all modes for epilogues

gcc/ChangeLog:

* tree-vectorizer.c (better_epilogue_loop_than_p): Round factors up for
epilogue costing.
* tree-vect-loop.c (vect_analyze_loop): Re-analyze all modes for
epilogues, unless we are guaranteed that we can't have partial vectors.
* genopinit.c: (partial_vectors_supported): Generate new function.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/masked_epilogue.c: New test.

2 years agoFortran: Pass unlimited polymorphic argument to assumed type [PR103366].
Paul Thomas [Mon, 10 Jan 2022 16:54:53 +0000 (16:54 +0000)]
Fortran: Pass unlimited polymorphic argument to assumed type [PR103366].

2022-01-10  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/103366
* trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): Allow unlimited
polymorphic actual argument passed to assumed type formal.

gcc/testsuite/
PR fortran/103366
* gfortran.dg/pr103366.f90: New test.

2 years agox86_64: Ignore zero width bitfields in ABI and issue -Wpsabi warning about C zero...
Jakub Jelinek [Mon, 10 Jan 2022 16:43:23 +0000 (17:43 +0100)]
x86_64: Ignore zero width bitfields in ABI and issue -Wpsabi warning about C zero width bitfield ABI changes [PR102024]

For zero-width bitfields current GCC classify_argument does:
                  if (DECL_BIT_FIELD (field))
                    {
                      for (i = (int_bit_position (field)
                                + (bit_offset % 64)) / 8 / 8;
                           i < ((int_bit_position (field) + (bit_offset % 64))
                                + tree_to_shwi (DECL_SIZE (field))
                                + 63) / 8 / 8; i++)
                        classes[i]
                          = merge_classes (X86_64_INTEGER_CLASS, classes[i]);
                    }
which I think means that if the zero-width bitfields are at bit-positions
(in the toplevel aggregate) which are multiples of 64 bits doesn't do
anything, (int_bit_position (field) + (bit_offset % 64)) / 64 and
(int_bit_position (field) + (bit_offset % 64) + 63) / 64 should be equal.
But for zero-width bitfields at other bit positions it will call
merge_classes once.  Now, the typical case is that the zero width bitfield
is surrounded by some bitfields and in that case, it doesn't change
anything, but it can be sandwitched in between floats too as the testcases
show.
In C we had this behavior, in C++ previously the FE was removing the
zero-width bitfields and therefore they were ignored.
LLVM and ICC seems to ignore those bitfields both in C and C++ (== passing
struct S in SSE register rather than in GPR).

The x86-64 psABI has been recently clarified by
https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/1aa4398d26c250b252a0c4a0f777216c9a6789ec
that zero width bitfield should be always ignored.

This patch implements that and emits a warning for C for cases where the ABI
changed from GCC 11.

2022-01-10  Jakub Jelinek  <jakub@redhat.com>

PR target/102024
* config/i386/i386.c (classify_argument): Add zero_width_bitfields
argument, when seeing DECL_FIELD_CXX_ZERO_WIDTH_BIT_FIELD bitfields,
always ignore them, when seeing other zero sized bitfields, either
set zero_width_bitfields to 1 and ignore it or if equal to 2 process
it.  Pass it to recursive calls.  Add wrapper
with old arguments and diagnose ABI differences for C structures
with zero width bitfields.  Formatting fixes.

* gcc.target/i386/pr102024.c: New test.
* g++.target/i386/pr102024.C: New test.

2 years agoPartially sort MAINTAINERS.
Martin Liska [Mon, 10 Jan 2022 16:10:52 +0000 (17:10 +0100)]
Partially sort MAINTAINERS.

ChangeLog:

* MAINTAINERS: Fix obvious issues with sorting.

2 years agoira: Handle "soft" conflicts between cap and non-cap allocnos
Richard Sandiford [Mon, 10 Jan 2022 14:47:09 +0000 (14:47 +0000)]
ira: Handle "soft" conflicts between cap and non-cap allocnos

This patch looks for allocno conflicts of the following form:

- One allocno (X) is a cap allocno for some non-cap allocno X2.
- X2 belongs to some loop L2.
- The other allocno (Y) is a non-cap allocno.
- Y is an ancestor of some allocno Y2 in L2.
- Y2 is not referenced in L2 (that is, ALLOCNO_NREFS (Y2) == 0).
- Y can use a different allocation from Y2.

In this case, Y's register is live across L2 but is not used within it,
whereas X's register is used only within L2.  The conflict is therefore
only "soft", in that it can easily be avoided by spilling Y2 inside L2
without affecting any insn references.

In principle we could do this for ALLOCNO_NREFS (Y2) != 0 too, with the
callers then taking Y2's ALLOCNO_MEMORY_COST into account.  There would
then be no "cliff edge" between a Y2 that has no references and a Y2 that
has (say) a single cold reference.

However, doing that isn't necessary for the PR and seems to give
variable results in practice.  (fotonik3d_r improves slightly but
namd_r regresses slightly.)  It therefore seemed better to start
with the higher-value zero-reference case and see how things go.

On top of the previous patches in the series, this fixes the exchange2
regression seen in GCC 11.

gcc/
PR rtl-optimization/98782
* ira-int.h (ira_soft_conflict): Declare.
* ira-color.c (max_soft_conflict_loop_depth): New constant.
(ira_soft_conflict): New function.
(spill_soft_conflicts): Likewise.
(assign_hard_reg): Use them to handle the case described by
the comment above ira_soft_conflict.
(improve_allocation): Likewise.
* ira.c (check_allocation): Allow allocnos with "soft" conflicts
to share the same register.

gcc/testsuite/
* gcc.target/aarch64/reg-alloc-4.c: New test.

2 years agoira: Consider modelling caller-save allocations as loop spills
Richard Sandiford [Mon, 10 Jan 2022 14:47:08 +0000 (14:47 +0000)]
ira: Consider modelling caller-save allocations as loop spills

If an allocno A in an inner loop L spans a call, a parent allocno AP
can choose to handle a call-clobbered/caller-saved hard register R
in one of two ways:

(1) save R before each call in L and restore R after each call
(2) spill R to memory throughout L

(2) can be cheaper than (1) in some cases, particularly if L does
not reference A.

Before the patch we always did (1).  The patch adds support for
picking (2) instead, when it seems cheaper.  It builds on the
earlier support for not propagating conflicts to parent allocnos.

gcc/
PR rtl-optimization/98782
* ira-int.h (ira_caller_save_cost): New function.
(ira_caller_save_loop_spill_p): Likewise.
* ira-build.c (ira_propagate_hard_reg_costs): Test whether it is
cheaper to spill a call-clobbered register throughout a loop rather
than spill it around each individual call.  If so, treat all
call-clobbered registers as conflicts and...
(propagate_allocno_info): ...do not propagate call information
from the child to the parent.
* ira-color.c (move_spill_restore): Update accordingly.
* ira-costs.c (ira_tune_allocno_costs): Use ira_caller_save_cost.

gcc/testsuite/
* gcc.target/aarch64/reg-alloc-3.c: New test.

2 years agoira: Try to avoid propagating conflicts
Richard Sandiford [Mon, 10 Jan 2022 14:47:08 +0000 (14:47 +0000)]
ira: Try to avoid propagating conflicts

Suppose that:

- an inner loop L contains an allocno A
- L clobbers hard register R while A is live
- A's parent allocno is AP

Previously, propagate_allocno_info would propagate conflict sets up the
loop tree, so that the conflict between A and R would become a conflict
between AP and R (and so on for ancestors of AP).

However, when IRA treats loops as separate allocation regions, it can
decide on a loop-by-loop basis whether to allocate a register or spill
to memory.  Conflicts in inner loops therefore don't need to become
hard conflicts in parent loops.  Instead we can record that using the
“conflicting” registers for the parent allocnos has a higher cost.
In the example above, this higher cost is the sum of:

- the cost of saving R on entry to L
- the cost of keeping the pseudo register in memory throughout L
- the cost of reloading R on exit from L

This value is also a cap on the hard register cost that A can contribute
to AP in general (not just for conflicts).  Whatever allocation we pick
for AP, there is always the option of spilling that register to memory
throughout L, so the cost to A of allocating a register to AP can't be
more than the cost of spilling A.

To take an extreme example: if allocating a register R2 to A is more
expensive than spilling A to memory, ALLOCNO_HARD_REG_COSTS (A)[R2]
could be (say) 2 times greater than ALLOCNO_MEMORY_COST (A) or 100
times greater than ALLOCNO_MEMORY_COST (A).  But this scale factor
doesn't matter to AP.  All that matters is that R2 is more expensive
than memory for A, so that allocating R2 to AP should be costed as
spilling A to memory (again assuming that A and AP are in different
allocation regions).  Propagating a factor of 100 would distort the
register costs for AP.

move_spill_restore tries to undo the propagation done by
propagate_allocno_info, so we need some extra processing there.

gcc/
PR rtl-optimization/98782
* ira-int.h (ira_allocno::might_conflict_with_parent_p): New field.
(ALLOCNO_MIGHT_CONFLICT_WITH_PARENT_P): New macro.
(ira_single_region_allocno_p): New function.
(ira_total_conflict_hard_regs): Likewise.
* ira-build.c (ira_create_allocno): Initialize
ALLOCNO_MIGHT_CONFLICT_WITH_PARENT_P.
(ira_propagate_hard_reg_costs): New function.
(propagate_allocno_info): Use it.  Try to avoid propagating
hard register conflicts to parent allocnos if we can handle
the conflicts by spilling instead.  Limit the propagated
register costs to the cost of spilling throughout the child loop.
* ira-color.c (color_pass): Use ira_single_region_allocno_p to
test whether a child and parent allocno can share the same
register.
(move_spill_restore): Adjust for the new behavior of
propagate_allocno_info.

gcc/testsuite/
* gcc.target/aarch64/reg-alloc-2.c: New test.

2 years agoira: Add ira_subloop_allocnos_can_differ_p
Richard Sandiford [Mon, 10 Jan 2022 14:47:07 +0000 (14:47 +0000)]
ira: Add ira_subloop_allocnos_can_differ_p

color_pass has two instances of the same code for propagating non-cap
assignments from parent loops to subloops.  This patch adds a helper
function for testing when such propagations are required for correctness
and uses it to remove the duplicated code.

A later patch will use this in ira-build.c too, which is why the
function is exported to ira-int.h.

No functional change intended.

gcc/
PR rtl-optimization/98782
* ira-int.h (ira_subloop_allocnos_can_differ_p): New function,
extracted from...
* ira-color.c (color_pass): ...here.

2 years agoira: Add comments and fix move_spill_restore calculation
Richard Sandiford [Mon, 10 Jan 2022 14:47:07 +0000 (14:47 +0000)]
ira: Add comments and fix move_spill_restore calculation

This patch adds comments to describe each use of ira_loop_border_costs.
I think this highlights that move_spill_restore was using the wrong cost
in one case, which came from tranposing [0] and [1] in the original
(pre-ira_loop_border_costs) ira_memory_move_cost expressions.  The
difference would only be noticeable on targets that distinguish between
load and store costs.

gcc/
PR rtl-optimization/98782
* ira-color.c (color_pass): Add comments to describe the spill costs.
(move_spill_restore): Likewise.  Fix reversed calculation.

2 years agoira: Add a ira_loop_border_costs class
Richard Sandiford [Mon, 10 Jan 2022 14:47:07 +0000 (14:47 +0000)]
ira: Add a ira_loop_border_costs class

The final index into (ira_)memory_move_cost is 1 for loads and
0 for stores.  Thus the combination:

  entry_freq * memory_cost[1] + exit_freq * memory_cost[0]

is the cost of loading a register on entry to a loop and
storing it back on exit from the loop.  This is the cost to
use if the register is successfully allocated within the
loop but is spilled in the parent loop.  Similarly:

  entry_freq * memory_cost[0] + exit_freq * memory_cost[1]

is the cost of storing a register on entry to the loop and
restoring it on exit from the loop.  This is the cost to
use if the register is spilled within the loop but is
successfully allocated in the parent loop.

The patch adds a helper class for calculating these values and
mechanically replaces the existing instances.  There is no attempt to
editorialise the choice between using “spill inside” and “spill outside”
costs.  (I think one of them is the wrong way round, but a later patch
deals with that.)

No functional change intended.

gcc/
PR rtl-optimization/98782
* ira-int.h (ira_loop_border_costs): New class.
* ira-color.c (ira_loop_border_costs::ira_loop_border_costs):
New constructor.
(calculate_allocno_spill_cost): Use ira_loop_border_costs.
(color_pass): Likewise.
(move_spill_restore): Likewise.

2 years agolibstdc++: Add %j, %U, %w, %W time_get support, fix %y, %Y, %C, %p [PR77760]
Jakub Jelinek [Mon, 10 Jan 2022 14:38:47 +0000 (15:38 +0100)]
libstdc++: Add %j, %U, %w, %W time_get support, fix %y, %Y, %C, %p [PR77760]

glibc strptime passes around some state, what fields in struct tm have been
set and what needs to be finalized through possibly recursive calls, and
at the end performs various finalizations, like applying %p so that it
works for both %I %p and %p %I orders, or applying century so that both
%C %y and %y %C works, or computation of missing fields from others
(e.g. from %Y and %j one can compute tm_mon, tm_mday and tm_wday,
from %Y %U %w, %Y %W %w, %Y %U %a, or %Y %W %w one can compute
tm_mon, tm_mday, tm_yday or e.g. from %Y %m %d one can compute tm_wday
and tm_yday.

As the finalization is quite large and doesn't need to be a template
(doesn't depend on any iterators or char types), I've put it into libstdc++,
and left some padding in the state struct, so that perhaps in the future we
can track some more state without changing ABI.

Unfortunately, there is an ugly problem that the standard mandates that
get method calls the do_get virtual method and I don't see how we can
cary on any state in between those calls (even if we did an ABI change
for the facets, the methods are const, so that I think multiple threads
could use the same time_get objects and we couldn't store state in there).

There is a hack for that for GCC (seems to work with ICC too, doesn't work
with clang++) if the do_get method isn't overriden we can pass the state
around.

For both do_get_year and per IRC discussions also for %y, the behavior is
if 1-2 digits are parsed, the year is treated according to POSIX 2008 %y
rules (0-68 is 2000-2068, 69-99 is 1969-1999), if 3-4 digits are parsed,
it is treated as %Y.

2022-01-10  Jakub Jelinek  <jakub@redhat.com>

PR libstdc++/77760
* include/bits/locale_facets_nonio.h (__time_get_state): New struct.
(time_get::_M_extract_via_format): Declare new method with
__time_get_state& as an extra argument.
* include/bits/locale_facets_nonio.tcc (_M_extract_via_format): Add
__state argument, set various fields in it while parsing.  Handle %j,
%U, %w and %W, fix up handling of %y, %Y and %C, don't adjust tm_hour
for %p immediately.  Add a wrapper around the method without the
__state argument for backwards compatibility.
(_M_extract_num): Remove all __len == 4 special cases.
(time_get::do_get_time, time_get::do_get_date, time_get::do_get): Zero
initialize __state, pass it to _M_extract_via_format and finalize it
at the end.
(do_get_year): For 1-2 digit parsed years, map 0-68 to 2000-2068,
69-99 to 1969-1999.  For 3-4 digit parsed years use that as year.
(get): If do_get isn't overloaded from the locale_facets_nonio.tcc
version, don't call do_get but call _M_extract_via_format instead to
pass around state.
* config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Export _M_extract_via_format
with extra __time_get_state and __time_get_state::_M_finalize_state.
* src/c++98/locale_facets.cc (is_leap, day_of_the_week,
day_of_the_year): New functions in anon namespace.
(mon_yday): New var in anon namespace.
(__time_get_state::_M_finalize_state): Define.
* testsuite/22_locale/time_get/get/char/4.cc: New test.
* testsuite/22_locale/time_get/get/wchar_t/4.cc: New test.
* testsuite/22_locale/time_get/get_year/char/1.cc (test01): Parse 197
as year 197AD instead of error.
* testsuite/22_locale/time_get/get_year/char/5.cc (test01): Parse 1 as
year 2001 instead of error.
* testsuite/22_locale/time_get/get_year/char/6.cc: New test.
* testsuite/22_locale/time_get/get_year/wchar_t/1.cc (test01): Parse
197 as year 197AD instead of error.
* testsuite/22_locale/time_get/get_year/wchar_t/5.cc (test01): Parse
1 as year 2001 instead of error.
* testsuite/22_locale/time_get/get_year/wchar_t/6.cc: New test.

2 years agolibstdc++: Fix and simplify freestanding configuration [PR103866]
Jonathan Wakely [Thu, 6 Jan 2022 13:54:53 +0000 (13:54 +0000)]
libstdc++: Fix and simplify freestanding configuration [PR103866]

This fixes the --disable-hosted-libstdcxx build so that it works with
--without-headers. Currently you need to also use --with-newlib, which
is confusing for users who aren't actually using newlib.

The AM_PROG_LIBTOOL checks are currently skipped for --with-newlib and
--with-avrlibc builds, with this change they are also skipped when using
--without-headers.  It would be nice if using --disable-hosted-libstdcxx
automatically skipped those checks, but GLIBCXX_ENABLE_HOSTED comes too
late to make the AM_PROG_LIBTOOL checks depend on $is_hosted.

The checks for EOF, SEEK_CUR etc. cause the build to fail if there is no
<stdio.h> available.  Unlike most headers, which get a HAVE_FOO_H macro,
<stdio.h> is in autoconf's default includes, so every check tries to
include it unconditionally. This change skips those checks for
freestanding builds.

Similarly, the checks for <stdint.h> types done by GCC_HEADER_STDINT try
to include <stdio.h> and fail for --without-headers builds. This change
skips the use of GCC_HEADER_STDINT for freestanding. We can probably
stop using GCC_HEADER_STDINT entirely, since only one file uses the
gstdint.h header that is generated, and that could easily be changed to
use <stdint.h> instead. That can wait for stage 1.

We also need to skip the GLIBCXX_CROSSCONFIG stage if --without-headers
was used, since we don't have any of the functions it deals with.

The end result of the changes above is that it should not be necessary
for a --disable-hosted-libstdcxx --without-headers build to also use
--with-newlib.

Finally, compile libsupc++ with -ffreestanding when --without-headers is
used, so that <stdint.h> will use <gcc-stdint.h> instead of expecting it
to come from libc.

libstdc++-v3/ChangeLog:

PR libstdc++/103866
* acinclude.m4 (GLIBCXX_COMPUTE_STDIO_INTEGER_CONSTANTS): Do
nothing for freestanding builds.
(GLIBCXX_ENABLE_HOSTED): Define FREESTANDING_FLAGS.
* configure.ac: Do not use AC_LIBTOOL_DLOPEN when configured
with --without-headers.  Do not use GCC_HEADER_STDINT for
freestanding builds.
* libsupc++/Makefile.am (HOSTED_CXXFLAGS): Use -ffreestanding
for freestanding builds.
* configure: Regenerate.
* Makefile.in: Regenerate.
* doc/Makefile.in: Regenerate.
* include/Makefile.in: Regenerate.
* libsupc++/Makefile.in: Regenerate.
* po/Makefile.in: Regenerate.
* python/Makefile.in: Regenerate.
* src/Makefile.in: Regenerate.
* src/c++11/Makefile.in: Regenerate.
* src/c++17/Makefile.in: Regenerate.
* src/c++20/Makefile.in: Regenerate.
* src/c++98/Makefile.in: Regenerate.
* src/filesystem/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.

2 years agolibstdc++: Add dg-timeout-factor to some more regex tests
Jonathan Wakely [Fri, 7 Jan 2022 21:15:48 +0000 (21:15 +0000)]
libstdc++: Add dg-timeout-factor to some more regex tests

I'm seeing these fail with tool_timeout=30 on a busy machine.

libstdc++-v3/ChangeLog:

* testsuite/28_regex/algorithms/regex_replace/char/103664.cc:
Add dg-timeout-factor directive.
* testsuite/28_regex/basic_regex/84110.cc: Likewise.
* testsuite/28_regex/basic_regex/ctors/char/other.cc: Likewise.
* testsuite/28_regex/match_results/102667.cc: Likewise.

2 years agolibstdc++: Update default -std option in manual
Jonathan Wakely [Mon, 10 Jan 2022 11:23:12 +0000 (11:23 +0000)]
libstdc++: Update default -std option in manual

libstdc++-v3/ChangeLog:

* doc/xml/manual/using.xml: Update documentation around default
-std option.
* doc/html/*: Regenerate.

2 years agolibstdc++: Add -nostdinc++ for c++17 sources [PR100017]
Jonathan Wakely [Fri, 7 Jan 2022 15:21:03 +0000 (15:21 +0000)]
libstdc++: Add -nostdinc++ for c++17 sources [PR100017]

When building a build!=host compiler, the just-built gcc can't be used
to build the target libstdc++ (because it is built for the host triplet,
not the build triplet). The top-level configure.ac sets up the build
flags for libstdc++ (and other "raw_cxx" libs) like this:

GCC_TARGET_TOOL(c++ for libstdc++, RAW_CXX_FOR_TARGET, CXX,
[gcc/xgcc -shared-libgcc -B$$r/$(HOST_SUBDIR)/gcc -nostdinc++ -L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src -L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src/.libs -L$$r/$(TARGET_SUBDIR)/libstdc++-v3/libsupc++/.libs],
c++)

The -nostdinc++ flag is only used for the IN-TREE-TOOL, i.e. when using
the just-built gcc/xgcc compiler. This means that the cross-compiler
used to build libstdc++ will add its own libstdc++ headers to the
include path. That results in the #include <cfenv> in
src/c++17/floating_to_chars.cc and src/c++17/floating_from_chars.cc
doing #include_next <fenv.h> and finding the libstdc++ fenv.h wrapper
from the host compiler. Because that has the same include guard as the
<fenv.h> in the libstdc++ we're trying to build, we never reach the
underlying <fenv.h> from libc. That results in several errors of the
form:

error: 'fenv_t' has not been declared in '::'

The most correct fix would be to add -nostdinc++ to the
RAW_CXX_FOR_TARGET variable in configure.ac, or the
RAW_CXX_TARGET_EXPORTS variable in Makefile.tpl.

Another solution would be to make the libstdc++ <fenv.h> wrapper use
_GLIBCXX_INCLUDE_NEXT_C_HEADERS like our <stdlib.h> and other C header
wrappers.

For now though, the simplest and safest solution is to just add
-nostdinc++ to the CXXFLAGS used for src/c++17/*.cc, which is what this
does.

libstdc++-v3/ChangeLog:

PR libstdc++/100017
* src/c++17/Makefile.am (AM_CXXFLAGS): Add -nostdinc++.
* src/c++17/Makefile.in: Regenerate.

2 years agoProperly enable -freorder-blocks-and-partition on 64-bit Windows
Eric Botcazou [Mon, 10 Jan 2022 11:40:10 +0000 (12:40 +0100)]
Properly enable -freorder-blocks-and-partition on 64-bit Windows

The PR uncovered that -freorder-blocks-and-partition was working by accident
on 64-bit Windows, i.e. the middle-end was supposed to disable it with SEH.
After the change installed on mainline, the middle-end properly disables it,
which is too bad since a significant amount of work went into it for SEH.

gcc/
PR target/103465
* coretypes.h (unwind_info_type): Swap UI_SEH and UI_TARGET.

2 years agoFortran: Allow IEEE_CLASS to identify signaling NaNs
Francois-Xavier Coudert [Sun, 2 Jan 2022 10:36:23 +0000 (11:36 +0100)]
Fortran: Allow IEEE_CLASS to identify signaling NaNs

We use the issignaling macro, present in some libc's (notably glibc),
when it is available. Compile all IEEE-related files in the library
(both C and Fortran sources) with -fsignaling-nans to ensure maximum
compatibility.

libgfortran/ChangeLog:

PR fortran/82207
* Makefile.am: Pass -fsignaling-nans for IEEE files.
* Makefile.in: Regenerate.
* ieee/ieee_helper.c: Use issignaling macro to recognized
signaling NaNs.

gcc/testsuite/ChangeLog:

PR fortran/82207
* gfortran.dg/ieee/signaling_1.f90: New test.
* gfortran.dg/ieee/signaling_1_c.c: New file.

2 years agomiddle-end/101530 - fix shufflevector lowering
Richard Biener [Wed, 5 Jan 2022 14:13:33 +0000 (15:13 +0100)]
middle-end/101530 - fix shufflevector lowering

This makes __builtin_shufflevector lowering force the result
of the BIT_FIELD_REF lowpart operation to a temporary as to
fulfil the IL verifier constraint that BIT_FIELD_REFs should
be always in outermost handled component position.  Trying to
enforce this during gimplification isn't as straight-forward
as here where we know we're dealing with an rvalue.

FAIL: c-c++-common/torture/builtin-shufflevector-1.c   -O0  execution test

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

PR middle-end/101530
gcc/c-family/
* c-common.c (c_build_shufflevector): Wrap the BIT_FIELD_REF
in a TARGET_EXPR to force a temporary.

gcc/testsuite/
* c-c++-common/builtin-shufflevector-3.c: New testcase.

2 years agotree-optimization/100359 - restore unroll at -O3
Richard Biener [Wed, 5 Jan 2022 15:29:53 +0000 (16:29 +0100)]
tree-optimization/100359 - restore unroll at -O3

This fixes a mistake done with r8-5008 when introducing
allow_peel to the unroll code.  The intent was to allow
peeling that doesn't grow code but the result was that
with -O3 and UL_ALL this wasn't done.  The following
instantiates the desired effect by adjusting ul to UL_NO_GROWTH
if peeling is not allowed.

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

PR tree-optimization/100359
* tree-ssa-loop-ivcanon.c (try_unroll_loop_completely):
Allow non-growing peeling with !allow_peel and UL_ALL.

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

2 years ago[Ada] Fix bogus error on call to subprogram with incomplete profile
Eric Botcazou [Thu, 23 Dec 2021 15:48:11 +0000 (16:48 +0100)]
[Ada] Fix bogus error on call to subprogram with incomplete profile

gcc/ada/

* gcc-interface/trans.c (Identifier_to_gnu): Use correct subtype.
(elaborate_profile): New function.
(Call_to_gnu): Call it on the formals and the result type before
retrieving the translated result type from the subprogram type.

2 years ago[Ada] Fix internal error on unchecked union with component clauses
Eric Botcazou [Tue, 21 Dec 2021 23:02:15 +0000 (00:02 +0100)]
[Ada] Fix internal error on unchecked union with component clauses

gcc/ada/

* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Record_Type>: Fix
computation of boolean result in the unchecked union case.
(components_to_record): Rename MAYBE_UNUSED parameter to IN_VARIANT
and remove local variable of the same name.  Pass NULL recursively
as P_GNU_REP_LIST for nested variants in the unchecked union case.

2 years ago[Ada] Make pragma Inspection_Point work for constants
Eric Botcazou [Sat, 18 Dec 2021 21:36:40 +0000 (22:36 +0100)]
[Ada] Make pragma Inspection_Point work for constants

gcc/ada/

* gcc-interface/trans.c (lvalue_required_p) <N_Pragma>: New case.
<N_Pragma_Argument_Association>: Likewise.
(Pragma_to_gnu) <Pragma_Inspection_Point>: Fetch the corresponding
variable of a constant before marking it as addressable.

2 years ago[Ada] Reduce runtime dependencies on stage1
Arnaud Charlet [Mon, 29 Nov 2021 10:15:26 +0000 (10:15 +0000)]
[Ada] Reduce runtime dependencies on stage1

gcc/ada/

* gcc-interface/Make-lang.in (ADA_GENERATED_FILES): Remove
s-casuti.ad?, s-crtl.ad?, s-os_lib.ad?.  Update list of object
files accordingly.

2 years ago[Ada] Switch from __sync to __atomic builtins for Lock_Free_Try_Write
Piotr Trojanek [Fri, 31 Dec 2021 10:40:47 +0000 (11:40 +0100)]
[Ada] Switch from __sync to __atomic builtins for Lock_Free_Try_Write

gcc/ada/

* libgnat/s-atopri.ads (Atomic_Compare_Exchange): Replaces
deprecated Sync_Compare_And_Swap.
* libgnat/s-atopri.adb (Lock_Free_Try_Write): Switch from __sync
to __atomic builtins.

2 years ago[Ada] Remove CodePeer annotations for pragma Loop_Variant
Piotr Trojanek [Thu, 30 Dec 2021 12:15:56 +0000 (13:15 +0100)]
[Ada] Remove CodePeer annotations for pragma Loop_Variant

gcc/ada/

* libgnat/s-exponn.adb, libgnat/s-expont.adb,
libgnat/s-exponu.adb, libgnat/s-widthi.adb,
libgnat/s-widthu.adb: Remove CodePeer annotations for pragma
Loop_Variant.

2 years ago[Ada] Disable expansion of pragma Loop_Variant in CodePeer mode
Piotr Trojanek [Thu, 30 Dec 2021 12:08:58 +0000 (13:08 +0100)]
[Ada] Disable expansion of pragma Loop_Variant in CodePeer mode

gcc/ada/

* exp_prag.adb (Expand_Pragma_Loop_Variant): Disable expansion
in CodePeer mode.

2 years ago[Ada] Fix typo in comment about unit families
Piotr Trojanek [Mon, 27 Dec 2021 19:41:42 +0000 (20:41 +0100)]
[Ada] Fix typo in comment about unit families

gcc/ada/

* sem_util.adb (Is_Child_Or_Sibling): Fix typo in comment.

2 years ago[Ada] Adjust the alignment to the size for bit-packed arrays
Eric Botcazou [Thu, 30 Dec 2021 19:06:50 +0000 (20:06 +0100)]
[Ada] Adjust the alignment to the size for bit-packed arrays

gcc/ada/

* exp_pakd.adb (Install_PAT): If the PAT is a scalar type, apply
the canonical adjustment to its alignment.

2 years ago[Ada] Switch from __sync to __atomic builtins for atomic counters
Piotr Trojanek [Thu, 30 Dec 2021 17:07:19 +0000 (18:07 +0100)]
[Ada] Switch from __sync to __atomic builtins for atomic counters

gcc/ada/

* libgnat/s-atocou__builtin.adb (Decrement, Increment): Switch
from __sync to __atomic builtins; use 'Address to be consistent
with System.Atomic_Primitives.

2 years ago[Ada] Fix error on too large size clause for bit-packed array
Eric Botcazou [Wed, 29 Dec 2021 22:33:21 +0000 (23:33 +0100)]
[Ada] Fix error on too large size clause for bit-packed array

gcc/ada/

* exp_pakd.adb (Install_PAT): Do not reset the alignment here.
* layout.adb (Layout_Type): Call Adjust_Esize_Alignment after having
copied the RM_Size onto the Esize when the latter is too small.

2 years ago[Ada] Task arrays trigger spurious unreferenced warnings
Justin Squirek [Thu, 23 Dec 2021 04:09:05 +0000 (04:09 +0000)]
[Ada] Task arrays trigger spurious unreferenced warnings

gcc/ada/

* sem_warn.adb (Check_References): Handle arrays of tasks
similar to task objects.

2 years agoDaily bump.
GCC Administrator [Mon, 10 Jan 2022 00:16:20 +0000 (00:16 +0000)]
Daily bump.

2 years agoFortran: check arguments of MASKL/MASKR intrinsics before simplification
Harald Anlauf [Mon, 20 Dec 2021 21:59:53 +0000 (22:59 +0100)]
Fortran: check arguments of MASKL/MASKR intrinsics before simplification

gcc/fortran/ChangeLog:

PR fortran/103777
* simplify.c (gfc_simplify_maskr): Check validity of argument 'I'
before simplifying.
(gfc_simplify_maskl): Likewise.

gcc/testsuite/ChangeLog:

PR fortran/103777
* gfortran.dg/masklr_3.f90: New test.

2 years agoFortran: reject invalid non-constant pointer initialization targets
Harald Anlauf [Sun, 9 Jan 2022 21:08:14 +0000 (22:08 +0100)]
Fortran: reject invalid non-constant pointer initialization targets

gcc/fortran/ChangeLog:

PR fortran/101762
* expr.c (gfc_check_pointer_assign): For pointer initialization
targets, check that subscripts and substring indices in
specifications are constant expressions.

gcc/testsuite/ChangeLog:

PR fortran/101762
* gfortran.dg/pr101762.f90: New test.

2 years agoFortran: Ignore KIND argument of a few more intrinsics. [PR103789]
Mikael Morin [Fri, 7 Jan 2022 21:34:59 +0000 (22:34 +0100)]
Fortran: Ignore KIND argument of a few more intrinsics. [PR103789]

After PR97896 for which some code was added to ignore the KIND argument
of the INDEX intrinsics, and PR87711 for which that was extended to LEN_TRIM
as well, this propagates it further to MASKL, MASKR, SCAN and VERIFY.

PR fortran/103789

gcc/fortran/ChangeLog:

* trans-array.c (arg_evaluated_for_scalarization): Add MASKL, MASKR,
SCAN and VERIFY to the list of intrinsics whose KIND argument is to be
ignored.

gcc/testsuite/ChangeLog:

* gfortran.dg/maskl_1.f90: New test.
* gfortran.dg/maskr_1.f90: New test.
* gfortran.dg/scan_3.f90: New test.
* gfortran.dg/verify_3.f90: New test.

2 years agoTestsuite: Make dependence on -fdelete-null-pointer-checks explicit
Sandra Loosemore [Sun, 9 Jan 2022 06:02:13 +0000 (22:02 -0800)]
Testsuite: Make dependence on -fdelete-null-pointer-checks explicit

nios2-elf target defaults to -fno-delete-null-pointer-checks, breaking
tests that implicitly depend on that optimization.  Add the option
explicitly on these tests.

2022-01-08  Sandra Loosemore  <sandra@codesourcery.com>

gcc/testsuite/
* g++.dg/cpp0x/constexpr-compare1.C: Add explicit
-fdelete-null-pointer-checks option.
* g++.dg/cpp0x/constexpr-compare2.C: Likewise.
* g++.dg/cpp0x/constexpr-typeid2.C: Likewise.
* g++.dg/cpp1y/constexpr-94716.C: Likewise.
* g++.dg/cpp1z/constexpr-compare1.C: Likewise.
* g++.dg/cpp1z/constexpr-if36.C: Likewise.
* gcc.dg/init-compare-1.c: Likewise.

libstdc++-v3/
* testsuite/18_support/type_info/constexpr.cc: Add explicit
-fdelete-null-pointer-checks option.

2 years agoDaily bump.
GCC Administrator [Sun, 9 Jan 2022 00:16:20 +0000 (00:16 +0000)]
Daily bump.

2 years agox86_64: Improve (interunit) moves from TImode to V1TImode.
Roger Sayle [Sat, 8 Jan 2022 12:27:50 +0000 (12:27 +0000)]
x86_64: Improve (interunit) moves from TImode to V1TImode.

This patch improves the code generated when moving a 128-bit value
in TImode, represented by two 64-bit registers, to V1TImode, which
is a single SSE register.

Currently, the simple move:
typedef unsigned __int128 uv1ti __attribute__ ((__vector_size__ (16)));
uv1ti foo(__int128 x) { return (uv1ti)x; }

is always transferred via memory, as:
foo:    movq    %rdi, -24(%rsp)
        movq    %rsi, -16(%rsp)
        movdqa  -24(%rsp), %xmm0
        ret

with this patch, we now generate (with -msse2):
foo:    movq    %rdi, %xmm1
        movq    %rsi, %xmm2
        punpcklqdq      %xmm2, %xmm1
        movdqa  %xmm1, %xmm0
        ret

and with -mavx2:
foo:    vmovq   %rdi, %xmm1
        vpinsrq $1, %rsi, %xmm1, %xmm0
        ret

Even more dramatic is the improvement of zero extended transfers.

uv1ti bar(unsigned char c) { return (uv1ti)(__int128)c; }

Previously generated:
bar:    movq    $0, -16(%rsp)
        movzbl  %dil, %eax
        movq    %rax, -24(%rsp)
        vmovdqa -24(%rsp), %xmm0
        ret

Now generates:
bar:    movzbl  %dil, %edi
        movq    %rdi, %xmm0
        ret

My first attempt at this functionality attempted to use a simple
define_split, but unfortunately, this triggers very late during the
compilation preventing some of the simplifications we'd like (in
combine).  For example the foo case above becomes:

foo:    movq    %rsi, -16(%rsp)
        movq    %rdi, %xmm0
        movhps  -16(%rsp), %xmm0

transferring half directly, and the other half via memory.
And for the bar case above, GCC fails to appreciate that
movq/vmovq clears the high bits, resulting in:

bar:    movzbl  %dil, %eax
        xorl    %edx, %edx
        vmovq   %rax, %xmm1
        vpinsrq $1, %rdx, %xmm1, %xmm0
        ret

Hence the solution (i.e. this patch) is to add a special case
to ix86_expand_vector_move for TImode to V1TImode transfers.

2022-01-08  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/i386/i386-expand.c (ix86_expand_vector_move): Add
special case for TImode to V1TImode moves, going via V2DImode.

gcc/testsuite/ChangeLog
* gcc.target/i386/sse2-v1ti-mov-1.c: New test case.
* gcc.target/i386/sse2-v1ti-zext.c: New test case.

2 years agoc++, match.pd: Evaluate in constant evaluation comparisons like &var1 + 12 == &var2...
Jakub Jelinek [Sat, 8 Jan 2022 08:53:00 +0000 (09:53 +0100)]
c++, match.pd: Evaluate in constant evaluation comparisons like &var1 + 12 == &var2 + 24 [PR89074]

The match.pd address_comparison simplification can only handle
ADDR_EXPR comparisons possibly converted to some other type (I wonder
if we shouldn't restrict it in address_compare to casts to pointer
types or pointer-sized integer types, I think we shouldn't optimize
(short) (&var) == (short) (&var2) because we really don't know whether
it will be true or false).  On GIMPLE, most of pointer to pointer
casts are useless and optimized away and further we have in
gimple_fold_stmt_to_constant_1 an optimization that folds
&something p+ const_int
into
&MEM_REF[..., off]
On GENERIC, we don't do that and e.g. for constant evaluation it
could be pretty harmful if e.g. such pointers are dereferenced, because
it can lose what exact field it was starting with etc., all it knows
is the base and offset, type and alias set.
Instead of teaching the match.pd address_compare about 3 extra variants
where one or both compared operands are pointer_plus, this patch attempts
to fold operands of comparisons similarly to gimple_fold_stmt_to_constant_1
before calling fold_binary on it.
There is another thing though, while we do have (x p+ y) p+ z to
x p+ (y + z) simplification which works on GIMPLE well because of the
useless pointer conversions, on GENERIC we can have pointer casts in between
and at that point we can end up with large expressions like
((type3) (((type2) ((type1) (&var + 2) + 2) + 2) + 2))
etc.  Pointer-plus doesn't really care what exact pointer type it has as
long as it is a pointer, so the following match.pd simplification for
GENERIC only (it is useless for GIMPLE) also moves the cast so that nested
p+ can be simplified.

Note, I've noticed we don't really diagnose going out of bounds with
pointer_plus (unlike e.g. with ARRAY_REF) during constant evaluation, I
think another patch for cxx_eval_binary_expression with POINTER_PLUS will be
needed.  But it isn't clear to me what exactly it should do in case of
subobjects.  If we start with address of a whole var, (&var), I guess we
should diagnose if the pointer_plus gets before start of the var (i.e.
"negative") or 1 byte past the end of the var, but what if we start with
&var.field or &var.field[3] ?  For &var.field, shall we diagnose out of
bounds of field (except perhaps flexible members?) or the whole var?
For ARRAY_REFs, I assume we must at least strip all the outer ARRAY_REFs
and so start with &var.field too, right?

2022-01-08  Jakub Jelinek  <jakub@redhat.com>

PR c++/89074
gcc/
* match.pd ((ptr) (x p+ y) p+ z -> (ptr) (x p+ (y + z))): New GENERIC
simplification.
gcc/cp/
* constexpr.c (cxx_maybe_fold_addr_pointer_plus): New function.
(cxx_eval_binary_expression): Use it.
gcc/testsuite/
* g++.dg/cpp1y/constexpr-89074-2.C: New test.
* g++.dg/cpp1z/constexpr-89074-1.C: New test.

2 years agoc++: default mem-init of array [PR103946]
Jason Merrill [Sat, 8 Jan 2022 06:18:51 +0000 (01:18 -0500)]
c++: default mem-init of array [PR103946]

In the patch for PR92385 I added asserts to see if we tried to make a
vec_init of a vec_init, but didn't see any in regression testing.  This
testcase is one case, which seems reasonable: we create a VEC_INIT_EXPR for
the aggregate initializer, and then again to express the actual
initialization of the member.  We already do similar collapsing of
TARGET_EXPR.  So let's just remove the asserts.

PR c++/103946

gcc/cp/ChangeLog:

* init.c (build_vec_init): Remove assert.
* tree.c (build_vec_init_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/nsdmi-array1.C: New test.

2 years agoc++: destroying delete, throw in new-expr [PR100588]
Jason Merrill [Thu, 6 Jan 2022 18:26:21 +0000 (13:26 -0500)]
c++: destroying delete, throw in new-expr [PR100588]

The standard says that a destroying operator delete is preferred, but that
only applies to the delete-expression, not the cleanup if a new-expression
initialization throws.  As a result of this patch, several of the destroying
delete tests don't get EH cleanups, but I'm turning off the warning in cases
where the initialization can't throw anyway.

It's unclear what should happen if the class does not declare a non-deleting
operator delete; a proposal in CWG was to call the global delete, which
makes sense to me if the class doesn't declare its own operator new.  If it
does, we warn and don't call any deallocation function if initialization
throws.

PR c++/100588

gcc/cp/ChangeLog:

* call.c (build_op_delete_call): Ignore destroying delete
if alloc_fn.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/destroying-delete5.C: Expect warning.
* g++.dg/cpp2a/destroying-delete6.C: New test.

2 years agoDaily bump.
GCC Administrator [Sat, 8 Jan 2022 00:16:27 +0000 (00:16 +0000)]
Daily bump.

2 years agoanalyzer: add logging of aliasing
David Malcolm [Thu, 6 Jan 2022 16:43:36 +0000 (11:43 -0500)]
analyzer: add logging of aliasing

gcc/analyzer/ChangeLog:
* engine.cc (impl_run_checkers): Pass logger to engine ctor.
* region-model-manager.cc
(region_model_manager::region_model_manager): Add logger param and
use it to initialize m_logger.
* region-model.cc (engine::engine): New.
* region-model.h (region_model_manager::region_model_manager):
Add logger param.
(region_model_manager::get_logger): New.
(region_model_manager::m_logger): New field.
(engine::engine): New.
* store.cc (store_manager::get_logger): New.
(store::set_value): Log scope.  Log when marking a cluster as
unknown due to possible aliasing.
* store.h (store_manager::get_logger): New decl.

2 years agoanalyzer: implement __analyzer_dump_escaped
David Malcolm [Fri, 7 Jan 2022 18:36:00 +0000 (13:36 -0500)]
analyzer: implement __analyzer_dump_escaped

PR analyzer/103546 seems to involve an issue in how the analyzer
tracks which decls have escaped, so this patch adds a way to directly
test this from DejaGnu.

gcc/analyzer/ChangeLog:
* region-model-impl-calls.cc (cmp_decls): New.
(cmp_decls_ptr_ptr): New.
(region_model::impl_call_analyzer_dump_escaped): New.
* region-model.cc (region_model::on_stmt_pre): Handle
__analyzer_dump_escaped.
* region-model.h (region_model::impl_call_analyzer_dump_escaped):
New decl.
* store.h (binding_cluster::get_base_region): New accessor.

gcc/ChangeLog:
* doc/analyzer.texi
(Special Functions for Debugging the Analyzer): Document
__analyzer_dump_escaped.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/analyzer-decls.h (__analyzer_dump_escaped): New
decl.
* gcc.dg/analyzer/escaping-1.c: New test.

2 years agoanalyzer: add region::is_named_decl_p
David Malcolm [Fri, 7 Jan 2022 18:49:28 +0000 (13:49 -0500)]
analyzer: add region::is_named_decl_p

This patch adds a debug function that I've found handy when debugging
a problem with handling the decl "yy_buffer_stack" in PR analyzer/103546.

gcc/analyzer/ChangeLog:
* region.cc (region::is_named_decl_p): New.
* region.h (region::is_named_decl_p): New decl.

gcc/ChangeLog:
* doc/analyzer.texi (Other Debugging Techniques): Document
region::is_named_decl_p.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoc++: check delete access with trivial init [PR20040]
Jason Merrill [Thu, 6 Jan 2022 21:13:04 +0000 (16:13 -0500)]
c++: check delete access with trivial init [PR20040]

Apparently we need to check the accessibility of the deallocation function
even if there is no initialization.

PR c++/20040

gcc/cp/ChangeLog:

* init.c (build_new_1): Also build pointer cleanup if
TYPE_GETS_DELETE.
* cp-tree.h (TYPE_GETS_VEC_DELETE): New.

gcc/testsuite/ChangeLog:

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

2 years agotarget: [PR102941] Fix inline-asm flags with non-REG_P output
Andrew Pinski [Tue, 26 Oct 2021 07:28:09 +0000 (07:28 +0000)]
target: [PR102941] Fix inline-asm flags with non-REG_P output

So the problem here is that arm_md_asm_adjust would
just create a set directly to the output memory which is wrong.
It needs to output to a temp register first and then do a
move.

OK? Bootstrapped and tested on aarch64-linux-gnu with no regressions.
I have no way to test on arm even though this touches common code.

PR target/102941

gcc/ChangeLog:

* config/arm/aarch-common.c (arm_md_asm_adjust):
Use a temp if !REG_P.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/asm-flag-7.c: New test.
* gcc.target/arm/asm-flag-7.c: New test.

2 years agoi386: Robustify V2QI and V4QI move patterns
Uros Bizjak [Fri, 7 Jan 2022 19:40:35 +0000 (20:40 +0100)]
i386: Robustify V2QI and V4QI move patterns

Add sse2 isa attribute where needed and remove where not needed.

2022-01-07  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

* config/i386/mmx.md (*move<V_32:mode>_internal): Add isa attribute.
(*movv2qi_internal): Remve sse2 requirement for alternatives 4,5.

2 years ago[Ada] Read directory in Ada.Directories.Start_Search rather than Get_Next_Entry
Patrick Bernardi [Wed, 22 Dec 2021 21:32:41 +0000 (16:32 -0500)]
[Ada] Read directory in Ada.Directories.Start_Search rather than Get_Next_Entry

gcc/ada/

* libgnat/a-direct.adb (Search_Data): Remove type.
(Directory_Vectors): New package instantiation.
(Search_State): New type.
(Fetch_Next_Entry): Remove.
(Close): Remove.
(Finalize): Rewritten.
(Full_Name): Ditto.
(Get_Next_Entry): Return next entry from Search results vector
rather than querying the directory directly using readdir.
(Kind): Rewritten.
(Modification_Time): Rewritten.
(More_Entries): Use Search state cursor to determine if more
entries are available for users to read.
(Simple_Name): Rewritten.
(Size): Rewritten.
(Start_Search_Internal): Rewritten to load the contents of the
directory that matches the pattern and filter into the search
object.
* libgnat/a-direct.ads (Search_Type): New type.
(Search_Ptr): Ditto.
(Directory_Entry_Type): Rewritten to support new Start_Search
procedure.
* libgnat/s-filatt.ads (File_Length_Attr): New function.

2 years ago[Ada] Fix the check of the 'Old prefix
Etienne Servais [Thu, 16 Dec 2021 13:17:40 +0000 (14:17 +0100)]
[Ada] Fix the check of the 'Old prefix

gcc/ada/

* sem_attr.adb (Check_Reference): Fix condition.

2 years ago[Ada] Fix uses of pragma Unreferenced in MinGW runtime unit
Ghjuvan Lacambre [Wed, 22 Dec 2021 09:24:29 +0000 (10:24 +0100)]
[Ada] Fix uses of pragma Unreferenced in MinGW runtime unit

gcc/ada/

* libgnarl/s-taprop__mingw.adb (Timed_Sleep): Remove "pragma
Unreferenced" for Result.
(Timed_Delay): Likewise.

2 years ago[Ada] Fix layout of pragma Inline in generated AST unit
Piotr Trojanek [Tue, 21 Dec 2021 14:44:47 +0000 (15:44 +0100)]
[Ada] Fix layout of pragma Inline in generated AST unit

gcc/ada/

* gen_il-gen.adb (Put_Make_Decls): Put pragma Inline in a
dedicated line, so that the current indentation is taken into
account.

2 years ago[Ada] Fix style in expansion of multi-dimensional array aggregates
Piotr Trojanek [Tue, 21 Dec 2021 14:33:56 +0000 (15:33 +0100)]
[Ada] Fix style in expansion of multi-dimensional array aggregates

gcc/ada/

* exp_aggr.adb (Build_Array_Aggr_Code): Fix inconsistent style
in comments and code.

2 years ago[Ada] More default initialization for multi-dim array aggregates
Piotr Trojanek [Tue, 21 Dec 2021 14:20:30 +0000 (15:20 +0100)]
[Ada] More default initialization for multi-dim array aggregates

gcc/ada/

* exp_aggr.adb (Gen_Assign): Remove explicit initialization for
components of access types.
(Get_Assoc_Expr): Enable initialization for components of all
types that require simple initialization.

2 years ago[Ada] Crash in class-wide pre/postconditions
Javier Miranda [Fri, 17 Dec 2021 16:43:57 +0000 (16:43 +0000)]
[Ada] Crash in class-wide pre/postconditions

gcc/ada/

* atree.ads (Traverse_Func_With_Parent): New generic subprogram.
(Traverse_Proc_With_Parent): Likewise.
* atree.adb (Parents_Stack): New table used to traverse trees
passing the parent field of each node.
(Internal_Traverse_With_Parent): New generic subprogram.
(Traverse_Func_With_Parent): Likewise.
(Traverse_Proc_With_Parent): Likewise.
* contracts.adb (Fix_Parents): New subprogram.
(Restore_Original_Selected_Component): Enhanced to fix the
parent field of restored nodes.
(Inherit_Condition): Adding assertions to check the parent field
of inherited conditions and to ensure that the built inherited
condition has no reference to the formals of the parent
subprogram.
* sem_util.ads, sem_util.adb (Check_Parents): New subprogram.

2 years ago[Ada] Fix typo on "Placement" in comment
Etienne Servais [Tue, 21 Dec 2021 09:55:42 +0000 (10:55 +0100)]
[Ada] Fix typo on "Placement" in comment

gcc/ada/

* sem_attr.adb (Check_Placement_In_Test_Case): Fix typo.

2 years ago[Ada] Cleanup and modification of unreferenced warnings
Justin Squirek [Thu, 9 Dec 2021 17:06:20 +0000 (17:06 +0000)]
[Ada] Cleanup and modification of unreferenced warnings

gcc/ada/

* comperr.adb (Delete_SCIL_Files): Replace unnecessary
Unreferenced pragma with specific pragma Warnings.
* doc/gnat_rm/implementation_defined_pragmas.rst (Unreferenced):
Add documentation for new behavior.
* gnat_rm.texi: Regenerate.
* erroutc.adb (Set_At): Remove useless assignment.
* exp_ch2.adb (In_Assignment_Context): Deleted.
(Is_Object_Renaming_Name): Replace calls to Is_LHS with calls to
Known_To_Be_Assigned.
(Expand_Current_Value): Replace calls to May_Be_Lvalue with
calls to Known_To_Be_Assigned.
(Expand_Entry_Paramter): Replace calls to In_Assignment_Context
with calls to Known_To_Be_Assigned.
* exp_ch4.adb (Expand_N_Op_Rem): Remove unnecessary Unreferenced
pragma.
* exp_imgv.adb (Build_Enumeration_Image_Tables): Default
initialize S_N.
* ghost.adb (Check_Ghost_Policy): Replace call to May_Be_Lvalue
with call to Known_To_Be_Assigned.
* lib-xref.adb (Is_On_LHS): Deleted.
(OK_To_Set_Referenced): Rewrite subprogram to encompass the new
pragma Unreferenced behavior.
(Process_Deferred_References): Replace call to Is_LHS with call
to Known_To_Be_Assigned.
* libgnarl/s-taasde.adb, libgnarl/s-tasren.adb,
libgnarl/s-tpobop.adb, libgnat/a-calend.adb,
libgnat/a-calfor.adb, libgnat/a-cbdlli.adb,
libgnat/a-cbhama.adb, libgnat/a-cbhase.adb,
libgnat/a-cbmutr.adb, libgnat/a-cborma.adb,
libgnat/a-cborse.adb, libgnat/a-cdlili.adb,
libgnat/a-cfhama.adb, libgnat/a-cforse.adb,
libgnat/a-cidlli.adb, libgnat/a-cihama.adb,
libgnat/a-cihase.adb, libgnat/a-cimutr.adb,
libgnat/a-ciorma.adb, libgnat/a-ciormu.adb,
libgnat/a-ciorse.adb, libgnat/a-cohama.adb,
libgnat/a-cohase.adb, libgnat/a-comutr.adb,
libgnat/a-convec.adb, libgnat/a-coorma.adb,
libgnat/a-coormu.adb, libgnat/a-coorse.adb,
libgnat/a-crdlli.adb, libgnat/a-tigeau.adb,
libgnat/a-wtgeau.adb, libgnat/a-ztgeau.adb,
libgnat/g-calend.adb, libgnat/g-comlin.adb,
libgnat/g-expect.adb, libgnat/g-mbflra.adb,
libgnat/g-spipat.adb, libgnat/s-fatgen.adb,
libgnat/s-fileio.adb, libgnat/s-os_lib.adb,
libgnat/s-regpat.adb, libgnat/s-valued.adb,
libgnat/s-valuer.adb: Remove unnecessary Unreferenced pragmas
* sem_ch10.adb (Process_Spec_Clauses): Remove useless
assignments.
* sem_ch13.adb (Validate_Literal_Aspect): Default initialize I.
* sem_ch3.adb (Build_Derived_Concurrent_Type): Default
initialize Corr_Decl.
* sem_ch8.adb (Undefined): Replace calls to Is_LHS with calls to
Known_To_Be_Assigned.
(In_Abstract_View_Pragma): Likewise.
* sem_eval.adb (Eval_Selected_Component): Replace calls to
Is_LHS with calls to Known_To_Be_Assigned.
* sem_res.adb (Init_Component): Replace calls to May_Be_Lvalue
with calls to Known_To_Be_Assigned.
* sem_util.adb, sem_util.ads (End_Label_Loc): Default initialize
Owner.
(Explain_Limited_Type): Default initialize Expr_Func.
(Find_Actual): Modified to handle entry families.
(Is_LHS): Deleted.
(May_Be_Lvalue): Deleted.
(Known_To_Be_Assigned): Modified and improved to handle all
cases.
* sem_warn.adb (Traverse_Result): Replace calls to May_Be_Lvalue
with calls to Known_To_Be_Assigned.
(Check_Ref): Modify error on unreferenced out parameters to take
into account different warning flags.

2 years ago[Ada] Spurious error caused by order of interfaces in full view
Javier Miranda [Mon, 20 Dec 2021 11:51:44 +0000 (11:51 +0000)]
[Ada] Spurious error caused by order of interfaces in full view

gcc/ada/

* sem_ch3.adb (Reorder_Interfaces): When the conflicting
interface is identified we just replace the interface in the
list of interfaces of the tagged type (instead of adding a
duplicate to the list of interfaces).

2 years ago[Ada] Fix __gnat_kill on Windows
Dmitriy Anisimkov [Mon, 20 Dec 2021 11:44:58 +0000 (17:44 +0600)]
[Ada] Fix __gnat_kill on Windows

gcc/ada/

* adaint.c (__gnat_kill): Terminate process only in case of
SIGKILL, SIGINT, SIGBREAK, SIGTERM, SIGABRT.  Do not call
OpenProcess if not going to terminate process.

2 years ago[Ada] Fix a couple of issues with pragma Inspection_Point
Eric Botcazou [Sat, 18 Dec 2021 21:25:20 +0000 (22:25 +0100)]
[Ada] Fix a couple of issues with pragma Inspection_Point

gcc/ada/

* exp_prag.adb (Expand_Pragma_Inspection_Point): Do a single pass
over the arguments of the pragma.  Set the Address_Taken flag on
them and use the Has_Delayed_Freeze flag to spot those which have
their elaboration delayed.  Reuse the location variable Loc.

2 years ago[Ada] Remove repeated routines for printing AST in Mixed_Case
Piotr Trojanek [Fri, 3 Dec 2021 12:38:08 +0000 (13:38 +0100)]
[Ada] Remove repeated routines for printing AST in Mixed_Case

gcc/ada/

* osint.adb (To_Lower): Clarify that only To_Lower function
causes bootstrap issues; fix style.
* treepr.adb (Print_Str_Mixed_Case): Reuse existing case
conversion routine.
(To_Mixed): Rename from Capitalize; reuse System.Case_Util
procedure and explain the bootstrap issue.

2 years ago[Ada] Simplify traversal in hooking of transient scopes
Piotr Trojanek [Thu, 16 Dec 2021 15:15:00 +0000 (16:15 +0100)]
[Ada] Simplify traversal in hooking of transient scopes

gcc/ada/

* exp_ch7.adb (Process_Transients_In_Scope): Remove unnecessary
initialization of Must_Hook; change Detect_Subprogram_Call from
function to procedure; adapt caller.

2 years ago[Ada] Remove extra space before THEN keywords
Piotr Trojanek [Thu, 16 Dec 2021 20:54:04 +0000 (21:54 +0100)]
[Ada] Remove extra space before THEN keywords

gcc/ada/

* exp_ch5.adb, exp_disp.adb, exp_util.adb, par-ch4.adb,
sem_ch13.adb: Remove extra space before THEN that occurs at the
end of a line.

2 years ago[Ada] Fix exit status of GNAT.Expect.Close call on running process
Dmitriy Anisimkov [Wed, 15 Dec 2021 13:26:50 +0000 (19:26 +0600)]
[Ada] Fix exit status of GNAT.Expect.Close call on running process

gcc/ada/

* expect.c (__gnat_waitpid): Use macros WIFEXITED, WEXITSTATUS,
WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG to get exit status
or signal that caused the child process to terminate/stop.  Do
not process exit status in case of error in waitpid call.
* adaint.c (__gnat_kill): Use of GenerateConsoleCtrlEvent is
removed in Windows variant as it actually is not working and was
terminating the calling process.  Set signal number into exit
code parameter of TerminateProcess to work the same like in
Linux.

2 years ago[Ada] Remove explicit expansion of block with general case statement
Piotr Trojanek [Thu, 16 Dec 2021 20:04:40 +0000 (21:04 +0100)]
[Ada] Remove explicit expansion of block with general case statement

gcc/ada/

* exp_ch5.adb (Expand_N_Case_Statement): Remove explicit
expansion.

2 years ago[Ada] Update -gnatwr doc for import of parent package
Etienne Servais [Tue, 14 Dec 2021 08:46:19 +0000 (09:46 +0100)]
[Ada] Update -gnatwr doc for import of parent package

gcc/ada/

* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Update -gnatwr documentation.
* gnat_ugn.texi: Regenerate.

2 years ago[Ada] Fix comment about subprogram unnesting and unconstrained arrays
Piotr Trojanek [Tue, 14 Dec 2021 22:10:44 +0000 (23:10 +0100)]
[Ada] Fix comment about subprogram unnesting and unconstrained arrays

gcc/ada/

* exp_unst.adb (Unnest_Subprogram): Sync comment with the
current code.

2 years ago[Ada] Fix inconsistent quoting in messages about compile-time errors
Piotr Trojanek [Wed, 8 Dec 2021 22:24:13 +0000 (23:24 +0100)]
[Ada] Fix inconsistent quoting in messages about compile-time errors

gcc/ada/

* exp_ch4.adb (Raise_Accessibility_Error): Move exception name
to the message string; move << control characters to the end,
for consistency.
* sem_ch6.adb (Analyze_Function_Return): Likewise.
* sem_util.adb (Compile_Time_Constraint_Error): Likewise.
* gcc-interface/decl.c (gnat_to_gnu_entity): Remove quotes
around Storage_Error.
* gcc-interface/trans.c (gnat_to_gnu): Remove quotes around
Constraint_Error.

gcc/testsuite/

* gnat.dg/aggr26.adb: Update expected error message.

2 years ago[Ada] Consistent suppression for warnings inside null loops
Piotr Trojanek [Mon, 13 Dec 2021 13:07:42 +0000 (14:07 +0100)]
[Ada] Consistent suppression for warnings inside null loops

gcc/ada/

* errout.adb (Error_Msg): Move warning suppression code from
Error_Msg_NLE
(Error_Msg_NLE): Warning suppression is now done by the internal
call to Error_Msg.

2 years ago[Ada] Remove unnecessary guard for inserting non-empty list
Piotr Trojanek [Mon, 13 Dec 2021 19:25:15 +0000 (20:25 +0100)]
[Ada] Remove unnecessary guard for inserting non-empty list

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Remove unnecessary
guards.
* exp_ch4.adb (Expand_N_If_Expression): Likewise; clarify comment.
* exp_ch5.adb (Expand_N_If_Statement,
Expand_Iterator_Loop_Over_Container): Likewise.
* exp_ch9.adb (Expand_N_Task_Type_Declaration): Remove redundant
guard.
* freeze.adb (Freeze_All_Ent): Reduce scope of a local variable.

2 years ago[Ada] Remove unnecessary guards for appending non-empty lists
Piotr Trojanek [Mon, 13 Dec 2021 15:53:23 +0000 (16:53 +0100)]
[Ada] Remove unnecessary guards for appending non-empty lists

gcc/ada/

* exp_ch3.adb (Build_Init_Procedure): Remove unnecessary guard.
* exp_disp.adb (Make_DT): Likewise.
* sem_ch12.adb (Analyze_Associations): Likewise.

2 years ago[Ada] Check scalar range in arrays constructed by concatenation
Etienne Servais [Tue, 30 Nov 2021 16:47:52 +0000 (17:47 +0100)]
[Ada] Check scalar range in arrays constructed by concatenation

gcc/ada/

* sem_res.adb (Resolve_Op_Concat_Arg): Check range when
concatenating scalars.

2 years ago[Ada] treepr: print value only for discrete types
Bob Duff [Sat, 11 Dec 2021 12:45:54 +0000 (07:45 -0500)]
[Ada] treepr: print value only for discrete types

gcc/ada/

* treepr.adb (Print_Node_Ref): Change "not Is_Array_Type" to
"Is_Discrete_Type".

2 years ago[Ada] Use non-internal representation for access subprograms if UC to Address
Richard Kenner [Wed, 8 Dec 2021 22:11:26 +0000 (17:11 -0500)]
[Ada] Use non-internal representation for access subprograms if UC to Address

gcc/ada/

* libgnat/g-spipat.ads (Boolean_Func, Natural_Func,
VString_Func): Mark as Favor_Top_Level.
* sem_ch13.adb (Validate_Unchecked_Conversion): Avoid using
internal representation if Unchecked_Conversion between
an access to subprogram and System.Address within the same unit.

2 years ago[Ada] treepr: Print value of static expression
Bob Duff [Fri, 10 Dec 2021 20:53:04 +0000 (15:53 -0500)]
[Ada] treepr: Print value of static expression

gcc/ada/

* treepr.adb (Print_Node_Ref): Print the value if available.

2 years ago[Ada] Add an option to Get_Fullest_View to not recurse
Richard Kenner [Wed, 8 Dec 2021 22:11:00 +0000 (17:11 -0500)]
[Ada] Add an option to Get_Fullest_View to not recurse

gcc/ada/

* sem_util.ads, sem_util.adb (Get_Fullest_View): Add option to
not recurse and return the next-most-fullest view.

2 years ago[Ada] Warn on import of parent package
Bob Duff [Fri, 10 Dec 2021 19:04:59 +0000 (14:04 -0500)]
[Ada] Warn on import of parent package

gcc/ada/

* sem_ch10.adb (Check_Redundant_Withs): Add a warning if a
library unit with's its own ancestor. Note that this warning is
not triggered for something like "with P.R;" in P.Q, because
there the "with P;" is considered implicit.
* fname-sf.adb, libgnarl/s-stusta.adb, libgnarl/s-tasdeb.ads,
libgnat/a-calfor.adb, libgnat/a-tiboio.adb,
libgnat/a-wwboio.adb, libgnat/a-zzboio.adb, libgnat/i-cobol.adb,
libgnat/s-bitops.adb, libgnat/s-bitops.ads,
libgnat/s-direio.adb, libgnat/s-dwalin.adb,
libgnat/s-geveop.adb, libgnat/s-mmosin__unix.adb,
libgnat/s-os_lib.adb, libgnat/s-os_lib.ads,
libgnat/s-pooglo.ads, libgnat/s-secsta.adb,
libgnat/s-shasto.adb, libgnat/s-stausa.ads,
libgnat/s-stratt.ads, libgnat/s-ststop.adb: Remove with of
parent.
* sinfo.ads: Minor comment fix.

2 years ago[Ada] Small cleanup of osint-m.adb
Bob Duff [Fri, 10 Dec 2021 18:21:38 +0000 (13:21 -0500)]
[Ada] Small cleanup of osint-m.adb

gcc/ada/

* osint-m.adb: Remove with_clause and pragma.

2 years agoAllow propagations from inner loop to outer loop.
liuhongt [Mon, 20 Dec 2021 03:13:38 +0000 (11:13 +0800)]
Allow propagations from inner loop to outer loop.

NULL is considered as an outer loop of any other loop.

gcc/ChangeLog:

PR rtl-optimization/103750
* fwprop.c (forward_propagate_into): Allow propagations from
inner loop to outer loop.

gcc/testsuite/ChangeLog:

* g++.target/i386/pr103750-fwprop-1.C: New test.

2 years agonvptx: Add support for PTX's cnot instruction.
Roger Sayle [Fri, 7 Jan 2022 09:57:21 +0000 (09:57 +0000)]
nvptx: Add support for PTX's cnot instruction.

This is a simple patch, now that the nvptx backend has transitioned
to STORE_FLAG_VALUE=1, that adds support for NVidia's cnot instruction,
that implements C/C++ style logical negation.

Previously, the simple function:

int foo(int x) { return !x; }

on nvptx-none with -O2 would generate:

mov.u32 %r24, %ar0;
setp.eq.u32     %r28, %r24, 0;
selp.u32        %value, 1, 0, %r28;

with this patch, GCC now generates:

mov.u32 %r24, %ar0;
cnot.b32        %value, %r24;

2022-01-07  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/nvptx/nvptx.md (*cnot<mode>2): New define_insn.

gcc/testsuite/ChangeLog
* gcc.target/nvptx/cnot-1.c: New test case.

2 years agors6000: Define a pattern for mffscrni. If the RN is a constant, it can call gen_rs60...
Haochen Gui [Fri, 7 Jan 2022 06:20:44 +0000 (14:20 +0800)]
rs6000: Define a pattern for mffscrni.  If the RN is a constant, it can call gen_rs6000_mffscrni directly.

gcc/
* config/rs6000/rs6000.md (rs6000_mffscrni): Define.
(rs6000_set_fpscr_rn): Change the type of operand[0] from DI to SI.
Call gen_rs6000_mffscrni when operand[0] is a const_0_to_3_operand.

gcc/testsuite/
* gcc.target/powerpc/mffscrni_p9.c: New testcase for mffscrni.
* gcc.target/powerpc/test_fpscr_rn_builtin.c: Test mffscrn and mffscrni
separately.

2 years agoc++: temporarily restore VEC_INIT_EXPR gimplify [PR103936]
Jason Merrill [Fri, 7 Jan 2022 02:58:01 +0000 (21:58 -0500)]
c++: temporarily restore VEC_INIT_EXPR gimplify [PR103936]

PR103936 demonstrates that some VEC_INIT_EXPR can still survive into
GENERIC; until that's fixed let's put back the handling in cp_gimplify_expr.

PR c++/103936
PR c++/65591

gcc/cp/ChangeLog:

* cp-gimplify.c (cp_gimplify_expr): Restore VEC_INIT_EXPR handling.

gcc/testsuite/ChangeLog:

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

2 years agoSupport commutative alternative for AVX512 vpcmpeq{b,w,d,q}
liuhongt [Thu, 6 Jan 2022 07:33:20 +0000 (15:33 +0800)]
Support commutative alternative for AVX512 vpcmpeq{b,w,d,q}

gcc/ChangeLog:

* config/i386/sse.md
(*<avx512>_eq<mode>3<mask_scalar_merge_name>_1): Extend to
UNSPEC_PCMP_UNSIGNED.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr103774.c: New test.
* gcc.target/i386/avx512bw-vpcmpequb-1.c: Adjust scan assembler
from vpcmpub to (?:vpcmpub|vpcmpeqb).
* gcc.target/i386/avx512bw-vpcmpequw-1.c: Ditto.
* gcc.target/i386/avx512bw-vpcmpub-1.c: Ditto.
* gcc.target/i386/avx512bw-vpcmpuw-1.c: Ditto.
* gcc.target/i386/avx512f-vpcmpequd-1.c: Ditto.
* gcc.target/i386/avx512f-vpcmpequq-1.c: Ditto.
* gcc.target/i386/avx512f-vpcmpud-1.c: Ditto.
* gcc.target/i386/avx512vl-vpcmpequd-1.c: Ditto.
* gcc.target/i386/avx512vl-vpcmpequq-1.c: Ditto.
* gcc.target/i386/avx512vl-vpcmpuq-1.c: Ditto.

2 years agoOptimize V16HF vector insert to element 0 for AVX2.
liuhongt [Wed, 5 Jan 2022 07:26:18 +0000 (15:26 +0800)]
Optimize V16HF vector insert to element 0 for AVX2.

gcc/ChangeLog:

PR target/103753
* config/i386/i386-expand.c (ix86_expand_vector_set): Not use
gen_avx2_pblendph_1 when elt == 0.
* config/i386/sse.md (avx2_pblendph): Rename to ..
(avx2_pblend<ssemodesuffix>_1).. this, and extend to V16HI.
(*avx2_pblendw): Rename to ..
(*avx2_pblend<ssemodesuffix>): .. this, and extend to V16HF.
(avx2_pblendw): Rename to ..
(*avx2_pblend<ssemodesuffix>): .. this, and extend to V16HF.
(blendsuf): Removed.
(sse4_1_pblend<blendsuf>): Renamed to ..
(sse4_1_pblend<ssemodesuffix>): .. this.

gcc/testsuite/ChangeLog:

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

2 years agoFortran: Fix handling of optional argument to SIZE intrinsic [PR103898]
Sandra Loosemore [Thu, 6 Jan 2022 19:23:18 +0000 (11:23 -0800)]
Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898]

This patch fixes a think-o in the code that triggered an ICE
in the test case.

2021-01-06  Sandra Loosemore  <sandra@codesourcery.com>

PR fortran/103898

gcc/fortran/
* trans-intrinsic.c (gfc_conv_intrinsic_size): Make size_var
actually be a variable and fix surrounding code.

gcc/testsuite/
* gfortran.dg/pr103898.f90: New test.

2 years agoc++: when delegating constructor throws [PR103711]
Jason Merrill [Thu, 6 Jan 2022 00:39:48 +0000 (19:39 -0500)]
c++: when delegating constructor throws [PR103711]

We were always calling the complete destructor if the target constructor
throws, even if we were calling the base constructor.

PR c++/103711

gcc/cp/ChangeLog:

* init.c (perform_target_ctor): Select destructor by in_chrg.

gcc/testsuite/ChangeLog:

* g++.dg/eh/delegating1.C: New test.

2 years agoc++: nested catch in ctor fn-try-block [PR61611]
Jason Merrill [Thu, 6 Jan 2022 14:45:26 +0000 (09:45 -0500)]
c++: nested catch in ctor fn-try-block [PR61611]

Being in_function_try_handler isn't enough to satisfy the condition of
reaching the end of such a handler; in this case, we're reaching the end of
a handler within that handler, so we don't want the special semantics.

PR c++/61611

gcc/cp/ChangeLog:

* except.c (in_nested_catch): New.
(expand_end_catch_block): Check it.

gcc/testsuite/ChangeLog:

* g++.dg/eh/ctor-fntry1.C: New test.

2 years agoc++: destroy retval on throwing cleanup in try [PR33799]
Jason Merrill [Wed, 5 Jan 2022 22:01:12 +0000 (17:01 -0500)]
c++: destroy retval on throwing cleanup in try [PR33799]

My earlier attempt to fix this bug didn't handle the case where both the
return and the throwing cleanup are within a try-block that catches and
discards the exception.  Fixed by adding the retval cleanup to any
try-blocks as well as the function body.  PR102191 pointed out that we also
weren't handling templates properly, so I moved the call out of the parser.

PR c++/33799
PR c++/102191

gcc/cp/ChangeLog:

* except.c (maybe_splice_retval_cleanup): Check
current_binding_level.
* semantics.c (do_poplevel): Call it here.
* parser.c (cp_parser_compound_statement): Not here.

gcc/testsuite/ChangeLog:

* g++.dg/eh/return1.C: Add temporary in try block case.
* g++.dg/cpp2a/constexpr-dtor11.C: New test.

2 years agoc++: clean up ref-extended temp on throwing dtor [PR53868]
Jason Merrill [Wed, 5 Jan 2022 16:18:25 +0000 (11:18 -0500)]
c++: clean up ref-extended temp on throwing dtor [PR53868]

We have wrap_temporary_cleanups to handle the EH region nesting problems
between cleanups for complete variables and cleanups for temporaries used in
their construction, but we weren't calling it for temporaries extended from
binding to a reference.

We still don't want this for array cleanups (since my PR94041 fix), so I
move that exception from initialize_local_var to wrap_temporary_cleanups.

PR c++/53868

gcc/cp/ChangeLog:

* decl.c (cp_finish_decl): Use wrap_temporary_cleanups for
cleanups from set_up_extended_ref_temp.
(wrap_temporary_cleanups): Ignore array cleanups.
(initialize_local_var): Don't check for array here.
* cp-tree.h (BIND_EXPR_VEC_DTOR): New.
* init.c (build_vec_delete_1): Set it.

gcc/testsuite/ChangeLog:

* g++.dg/eh/ref-temp1.C: New test.
* g++.dg/eh/ref-temp2.C: New test.

2 years agoc++: keep destroying array after one dtor throws [PR66451]
Jason Merrill [Wed, 5 Jan 2022 14:49:37 +0000 (09:49 -0500)]
c++: keep destroying array after one dtor throws [PR66451]

When we're cleaning up an array, if one destructor throws, we should still
try to clean up the rest of the array.  We can use TRY_CATCH_EXPR for this,
instead of a TARGET_EXPR like my other recent patches, because a destructor
call can't involve any temporaries that need to live longer.

I thought about only doing this when we call build_vec_delete_1 from
build_vec_init, but it seems appropriate for delete-expressions as well;
we've said that the array's lifetime is over, it makes sense to keep trying
to destroy it.  The standard isn't clear, but clang seems to agree with me.

PR c++/66451

gcc/cp/ChangeLog:

* init.c (build_vec_delete_1): Handle throwing dtor.
(build_vec_init): Tell it we're in a cleanup already.

gcc/testsuite/ChangeLog:

* g++.dg/eh/array3.C: New test.
* g++.dg/eh/array1.C: Mark destructor as throw().
* g++.dg/ipa/devirt-40.C: Likewise.
* g++.dg/warn/pr83054.C: Likewise.
* g++.dg/eh/delete1.C: Shorten array to one element.

2 years agoc++: don't cleanup the last aggregate elt
Jason Merrill [Tue, 4 Jan 2022 20:25:07 +0000 (15:25 -0500)]
c++: don't cleanup the last aggregate elt

Now that we're building cleanups for aggregate elements more often, it seems
worth optimizing by avoiding building one for the last element; once it is
initialized, the complete object is fully initialized, the element cleanups
end in favor of the complete object cleanup, and so a cleanup for the last
element would guard nothing at all.

gcc/cp/ChangeLog:

* typeck2.c (split_nonconstant_init_1): Don't cleanup the last elt.
(split_nonconstant_init): Adjust.

gcc/testsuite/ChangeLog:

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

2 years agoc++: EH and partially constructed aggr temp [PR66139]
Jason Merrill [Thu, 5 Mar 2020 20:50:45 +0000 (15:50 -0500)]
c++: EH and partially constructed aggr temp [PR66139]

Now that PR94041 is fixed, I can return to addressing PR66139, missing
cleanups for partially constructed aggregate temporaries.  My previous
approach of calling split_nonconstant_init in cp_gimplify_init_expr broke
because gimplification is too late to be introducing destructor calls.  So
instead I now call it under cp_fold_function, just before cp_genericize;
doing it from cp_genericize itself ran into trouble with the rewriting of
invisible references.

So now the prediction in cp_gimplify_expr that cp_gimplify_init_expr
might need to replace references to TARGET_EXPR_SLOT within
TARGET_EXPR_INITIAL has come to pass.  constexpr.c already had the simple
search-and-replace tree walk I needed, but it needed to be fixed to actually
replace all occurrences instead of just the first one.

Handling of VEC_INIT_EXPR at gimplify time had similar issues that we worked
around with build_vec_init_elt, so I'm moving that to cp_fold_function as
well.  But it seems that build_vec_init_elt is still useful for setting the
VEC_INIT_EXPR_IS_CONSTEXPR flag, so I'm leaving it alone.

This also fixes 52320, because build_aggr_init of each X from build_vec_init
builds an INIT_EXPR rather than call split_nonconstant_init at that point,
and now that INIT_EXPR gets split later.

PR c++/66139
PR c++/52320

gcc/cp/ChangeLog:

* constexpr.c (replace_decl): Rename from replace_result_decl.
* cp-tree.h (replace_decl): Declare it.
* cp-gimplify.c (cp_gimplify_init_expr): Call it.
(cp_gimplify_expr): Don't handle VEC_INIT_EXPR.
(cp_genericize_init, cp_genericize_init_expr)
(cp_genericize_target_expr): New.
(cp_fold_r): Call them.
* tree.c (build_array_copy): Add a TARGET_EXPR.
* typeck2.c (digest_init_r): Look through a TARGET_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist116.C: New test.
* g++.dg/cpp0x/initlist117.C: New test.
* g++.dg/cpp0x/lambda/lambda-eh.C: New test.
* g++.dg/eh/aggregate1.C: New test.

2 years agoc++: temporary lifetime with array aggr init [PR94041]
Jason Merrill [Sat, 1 Jan 2022 21:00:22 +0000 (16:00 -0500)]
c++: temporary lifetime with array aggr init [PR94041]

The previous patch fixed temporary lifetime for aggregate initialization of
classes; this one extends that fix to arrays.  This specifically reverses my
r74790, the patch for PR12253, which was made wrong when these semantics
were specified in DR201.

Since the array cleanup region encloses the regions for any temporaries, we
don't need to add an additional region for the array object itself in either
initialize_local_var or split_nonconstant_init; we do, however, need to tell
split_nonconstant_init how to disable the cleanup once an enclosing object
is fully constructed, at which point we want to run that destructor instead.

PR c++/94041

gcc/cp/ChangeLog:

* decl.c (initialize_local_var): Fix comment.
* init.c (build_new_1): Do stabilize array init.
(build_vec_init): Use TARGET_EXPR for cleanup.  Initialization
of an element from an explicit initializer is not a
full-expression.
* tree.c (expand_vec_init_expr): Pass flags through.
* typeck2.c (split_nonconstant_init_1): Handle VEC_INIT_EXPR.
(split_nonconstant_init): Handle array cleanups.
* cp-tree.h: Adjust.

gcc/testsuite/ChangeLog:

* g++.dg/init/array12.C:
* g++.dg/init/aggr7-eh2.C: New test.
* g++.dg/init/aggr7-eh3.C: New test.

2 years agoc++: temporary lifetime with aggregate init [PR94041]
Jason Merrill [Thu, 5 Mar 2020 20:50:45 +0000 (15:50 -0500)]
c++: temporary lifetime with aggregate init [PR94041]

In C++98 the lifetime of temporaries in aggregate initialization was
unclear, but C++11 DR201 clarified that only temporaries created for
default-initialization of an array element with no corresponding
initializer-clause are destroyed immediately; all others persist until the
end of the full-expression.

But we never implemented that, and continued treating individual element
initializations as full-expressions, such as in my patch for PR50866 in
r180442.  This blocked my attempted fix for PR66139, which extended the use
of split_nonconstant_init, and thus the bug, to aggregate initialization of
temporaries within an expression.

The longer temporary lifetime creates further EH region overlap problems
like the ones that wrap_temporary_cleanups addresses: in aggr7.C, we start
out with a normal nesting of

A1
 c.b1
   A2
    c.b2
     ...
   ~A2
~A1

where on the way in, throwing from one of the inits will clean up from the
previous inits.  But once c.b2 is initialized, throwing from ~A2 must not
clean up c.b1; instead it needs to clean up c.  So as in build_new_1, we
deal with this by guarding the B cleanups with flags that are cleared once c
is fully constructed; throwing from one of the ~A still hits that region,
but does not call ~B.  And then wrap_temporary_cleanups deals with calling
~C, but we need to tell it not to wrap the subobject cleanups.

The change from expressing the subobject cleanups with CLEANUP_STMT to
TARGET_EXPR was also necessary because we need them to collate with the ~A
in gimplify_cleanup_point_expr; the CLEANUP_STMT representation only worked
with treating subobject initializations as full-expressions.

PR c++/94041

gcc/cp/ChangeLog:

* decl.c (check_initializer): Remove obsolete comment.
(wrap_cleanups_r): Don't wrap CLEANUP_EH_ONLY.
(initialize_local_var): Change assert to test.
* typeck2.c (maybe_push_temp_cleanup): New.
(split_nonconstant_init_1): Use it.
(split_nonconstant_init): Clear cleanup flags.

gcc/testsuite/ChangeLog:

* g++.dg/init/aggr7-eh.C: New test.
* g++.dg/cpp0x/initlist122.C: Also test aggregate variable.

2 years agoc++: loop over array elts w/o explicit init [PR92385]
Jason Merrill [Sat, 1 Jan 2022 21:00:09 +0000 (16:00 -0500)]
c++: loop over array elts w/o explicit init [PR92385]

The PR complains that initializing a large array with {} takes a long time
to compile; this was because digest_init would turn {} into a long
CONSTRUCTOR with an initializer for each element, instead of more sensibly
generating a loop.  The standard doesn't specify this implementation, but it
does allow for it by specifying that a temporary created "when a default
constructor is called to initialize an element of an array with no
corresponding initializer" is destroyed "before the construction of the next
array element, if any." rather than living until the end of the complete
object initialization as usual.

This change is also needed before the PR94041 fix extends the lifetime of
temporaries from elements with explicit initializers.

To implement this, I change digest_init so that in cases where
initialization of trailing array elements isn't constant, we return a
VEC_INIT_EXPR instead of a bare CONSTRUCTOR; when it is encountered later,
we call build_vec_init to generate the actual initialization code.

PR c++/92385

gcc/cp/ChangeLog:

* typeck2.c (PICFLAG_VEC_INIT): New.
(process_init_constructor_array): Set it.
(process_init_constructor): Handle it.
(split_nonconstant_init_1): Handle VEC_INIT_EXPR.
* init.c (build_vec_init): Likewise.
* cp-gimplify.c (cp_gimplify_expr): Factor out...
* tree.c (expand_vec_init_expr): ...this function.
(build_vec_init_elt): Handle BRACE_ENCLOSED_INITIALIZER_P.
(build_vec_init_expr): Likewise.
* constexpr.c (cxx_eval_vec_init): Likewise.
(reduced_constant_expression_p): Check arrays before C++20.
* cp-tree.h (expand_vec_init_expr): Declare.

gcc/testsuite/ChangeLog:

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

2 years agoc++: don't preevaluate new-initializer
Jason Merrill [Tue, 4 Jan 2022 19:39:52 +0000 (14:39 -0500)]
c++: don't preevaluate new-initializer

The preevaluation code was causing trouble with my fix for PR94041, and now
I see that it's actually wrong since P0145 was adopted for C++17, mandating
order of evaluation for many expressions that were previously unspecified.
I don't see a need to preserve the preevaluation code for older standard
modes.

gcc/cp/ChangeLog:

* init.c (build_new_1): Remove preevaluation code.

gcc/testsuite/ChangeLog:

* g++.old-deja/g++.martin/new1.C: Don't expect preeval.
* g++.dg/tree-ssa/stabilize1.C: Removed.

2 years agoDaily bump.
GCC Administrator [Fri, 7 Jan 2022 00:16:24 +0000 (00:16 +0000)]
Daily bump.

2 years agoanalyzer: make use of may_be_aliased in alias detection [PR103546]
David Malcolm [Thu, 6 Jan 2022 16:39:54 +0000 (11:39 -0500)]
analyzer: make use of may_be_aliased in alias detection [PR103546]

Whilst debugging PR analyzer/103546 (false +ve in flex-generated lexers)
I noticed that the analyzer was considering that writes through symbolic
pointers could be treated as clobbering static globals such as:

   static YY_BUFFER_STATE * yy_buffer_stack = NULL;

even for such variables that never have their address taken.

This patch fixes this issue at least, so that the analyzer can preserve
knowledge of such globals on code paths with writes through symbolic
pointers.

It does not fix the false +ve in the lexer code.

gcc/analyzer/ChangeLog:
PR analyzer/103546
* store.cc (store::eval_alias_1): Refactor handling of decl
regions, adding a test for may_be_aliased, rejecting those for
which it returns false.

gcc/testsuite/ChangeLog:
PR analyzer/103546
* gcc.dg/analyzer/aliasing-3.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 years agoFortran: Fix ICE in argument_rank_mismatch [PR103287]
Sandra Loosemore [Wed, 5 Jan 2022 21:18:10 +0000 (13:18 -0800)]
Fortran: Fix ICE in argument_rank_mismatch [PR103287]

This patch removes an incorrect assertion.  A user-friendly error for this
case is already given elsewhere.

2022-01-05  Steve Kargl  <kargl@gcc.gnu.org>
    Sandra Loosemore  <sandra@codesourcery.com>

PR fortran/103287

gcc/fortran/
* interface.c (argument_rank_mismatch): Replace incorrect assertion
with return.

gcc/testsuite/
* gfortran.dg/c-interop/pr103287-1.f90: new.
* gfortran.dg/c-interop/pr103287-2.f90: new.