]> gcc.gnu.org Git - gcc.git/log
gcc.git
2 years agotree-sra: Fix union handling in build_reconstructed_reference
Martin Jambor [Fri, 1 Jul 2022 18:57:18 +0000 (20:57 +0200)]
tree-sra: Fix union handling in build_reconstructed_reference

As the testcase in PR 105860 shows, the code that tries to re-use the
handled_component chains in SRA can be horribly confused by unions,
where it thinks it has found a compatible structure under which it can
chain the references, but in fact it found the type it was looking
for elsewhere in a union and generated a write to a completely wrong
part of an aggregate.

I don't remember whether the plan was to support unions at all in
build_reconstructed_reference but it can work, to an extent, if we
make sure that we start the search only outside the outermost union,
which is what the patch does (and the extra testcase verifies).

gcc/ChangeLog:

2022-07-01  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/105860
* tree-sra.cc (build_reconstructed_reference): Start expr
traversal only just below the outermost union.

gcc/testsuite/ChangeLog:

2022-07-01  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/105860
* gcc.dg/tree-ssa/alias-access-path-13.c: New test.
* gcc.dg/tree-ssa/pr105860.c: Likewise.

2 years agoRevert update-ssa assert in vectorizer
Richard Biener [Mon, 4 Jul 2022 11:53:24 +0000 (13:53 +0200)]
Revert update-ssa assert in vectorizer

The following reverts the just added assert that virtual SSA does not
need updating.  It instead goes for a select whitelist of transforms
known to be prone to difficulties with virtual SSA update.

* tree-vect-loop-manip.cc (vect_do_peeling): Revert assert
and update virtual SSA form again.  Assert we do so for
a known set of transforms only.
* tree-vectorizer.h (vec_info::any_known_not_updated_vssa): New.
* tree-vect-stmts.cc (vectorizable_load): When vectorizing
using load-lanes allow virtual SSA update.

2 years agoOpenMP: Move omp requires checks to libgomp
Tobias Burnus [Mon, 4 Jul 2022 11:51:02 +0000 (13:51 +0200)]
OpenMP: Move omp requires checks to libgomp

Handle reverse_offload, unified_address, and unified_shared_memory
requirements in libgomp by saving them alongside the offload table.
When the device lto1 runs, it extracts the data for mkoffload. The
latter than passes the value on to GOMP_offload_register_ver.

lto1 (either the host one, with -flto [+ ENABLE_OFFLOADING], or in the
offload-device lto1) also does the the consistency check is done,
erroring out when the 'omp requires' clause use is inconsistent.

For all in-principle supported devices, if a requirement cannot be fulfilled,
the device is excluded from the (supported) devices list. Currently, none of
those requirements are marked as supported for any of the non-host devices.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_target_data, c_parser_omp_target_update,
c_parser_omp_target_enter_data, c_parser_omp_target_exit_data): Set
OMP_REQUIRES_TARGET_USED.
(c_parser_omp_requires): Remove sorry.

gcc/ChangeLog:

* config/gcn/mkoffload.cc (process_asm): Write '#include <stdint.h>'.
(process_obj): Pass omp_requires_mask to GOMP_offload_register_ver.
(main): Ask lto1 to obtain omp_requires_mask and pass it on.
* config/nvptx/mkoffload.cc (process, main): Likewise.
* lto-cgraph.cc (omp_requires_to_name): New.
(input_offload_tables): Save omp_requires_mask.
(output_offload_tables): Read it, check for consistency,
save value for mkoffload.
* omp-low.cc (lower_omp_target): Force output_offloadtables
call for OMP_REQUIRES_TARGET_USED.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_target_data,
cp_parser_omp_target_enter_data, cp_parser_omp_target_exit_data,
cp_parser_omp_target_update): Set OMP_REQUIRES_TARGET_USED.
(cp_parser_omp_requires): Remove sorry.

gcc/fortran/ChangeLog:

* openmp.cc (gfc_match_omp_requires): Remove sorry.
* parse.cc (decode_omp_directive): Don't regard 'declare target'
as target usage for 'omp requires'; add more flags to
omp_requires_mask.

include/ChangeLog:

* gomp-constants.h (GOMP_VERSION): Bump to 2.
(GOMP_REQUIRES_UNIFIED_ADDRESS, GOMP_REQUIRES_UNIFIED_SHARED_MEMORY,
GOMP_REQUIRES_REVERSE_OFFLOAD, GOMP_REQUIRES_TARGET_USED):
New defines.

libgomp/ChangeLog:

* libgomp-plugin.h (GOMP_OFFLOAD_get_num_devices): Add
omp_requires_mask arg.
* plugin/plugin-gcn.c (GOMP_OFFLOAD_get_num_devices): Likewise;
return -1 when device available but omp_requires_mask != 0.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_get_num_devices): Likewise.
* oacc-host.c (host_get_num_devices, host_openacc_get_property):
Update call.
* oacc-init.c (resolve_device, acc_init_1, acc_shutdown_1,
goacc_attach_host_thread_to_device, acc_get_num_devices,
acc_set_device_num, get_property_any): Likewise.
* target.c (omp_requires_mask): New global var.
(gomp_requires_to_name): New.
(GOMP_offload_register_ver): Handle passed omp_requires_mask.
(gomp_target_init): Handle omp_requires_mask.
* libgomp.texi (OpenMP 5.0): Update requires impl. status.
(OpenMP 5.1): Add a missed item.
(OpenMP 5.2): Mark linear-clause change as supported in C/C++.
* testsuite/libgomp.c-c++-common/requires-1-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-1.c: New test.
* testsuite/libgomp.c-c++-common/requires-2-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-2.c: New test.
* testsuite/libgomp.c-c++-common/requires-3-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-3.c: New test.
* testsuite/libgomp.c-c++-common/requires-4-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-4.c: New test.
* testsuite/libgomp.c-c++-common/requires-5-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-5.c: New test.
* testsuite/libgomp.c-c++-common/requires-6.c: New test.
* testsuite/libgomp.c-c++-common/requires-7-aux.c: New test.
* testsuite/libgomp.c-c++-common/requires-7.c: New test.
* testsuite/libgomp.fortran/requires-1-aux.f90: New test.
* testsuite/libgomp.fortran/requires-1.f90: New test.

liboffloadmic/ChangeLog:

* plugin/libgomp-plugin-intelmic.cpp (GOMP_OFFLOAD_get_num_devices):
Return -1 when device available but omp_requires_mask != 0.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/requires-4.c: Update dg-*.
* c-c++-common/gomp/reverse-offload-1.c: Likewise.
* c-c++-common/gomp/target-device-ancestor-2.c: Likewise.
* c-c++-common/gomp/target-device-ancestor-3.c: Likewise.
* c-c++-common/gomp/target-device-ancestor-4.c: Likewise.
* c-c++-common/gomp/target-device-ancestor-5.c: Likewise.
* gfortran.dg/gomp/target-device-ancestor-3.f90: Likewise.
* gfortran.dg/gomp/target-device-ancestor-4.f90: Likewise.
* gfortran.dg/gomp/target-device-ancestor-5.f90: Likewise.
* gfortran.dg/gomp/target-device-ancestor-2.f90: Likewise. Move
post-FE checks to ...
* gfortran.dg/gomp/target-device-ancestor-2a.f90: ... this new file.
* gfortran.dg/gomp/requires-8.f90: Update as we don't regard
'declare target' for the 'requires' usage requirement.

Co-authored-by: Chung-Lin Tang <cltang@codesourcery.com>
Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
2 years agoKeep virtual SSA up-to-date in vectorizer
Richard Biener [Mon, 4 Jul 2022 10:36:05 +0000 (12:36 +0200)]
Keep virtual SSA up-to-date in vectorizer

The following removes a FIXME where we fail(ed) to keep virtual
SSA up-to-date, patching up the remaining two cases I managed to
trigger.  I've left an assert so that we pick up cases arising
for the cases I wasn't able to trigger.

2022-07-04  Richard Biener  <rguenther@suse.de>

* tree-vect-loop-manip.cc (vect_do_peeling): Assert that
no SSA update is needed instead of updating virtual SSA
form.
* tree-vect-stmts.cc (vectorizable_load): For hoisted
invariant load use the loop entry virtual use.
For emulated gather loads use the virtual use of the
original stmt like vect_finish_stmt_generation would do.

2 years agogcc-descr: by default show revision for HEAD
Martin Liska [Mon, 4 Jul 2022 10:13:44 +0000 (12:13 +0200)]
gcc-descr: by default show revision for HEAD

I've made the mistake multiple times while doing a bisection.
One would expect that gcc-descr w/o an argument would print
revision for the current HEAD and not master.
Thus change it.

contrib/ChangeLog:

* git-descr.sh: By default print revision for HEAD.

2 years agoFix crash on circular array types with -fdump switches
Eric Botcazou [Mon, 4 Jul 2022 10:16:38 +0000 (12:16 +0200)]
Fix crash on circular array types with -fdump switches

Such questionable arrays types can occur in Ada.

gcc/
* tree-pretty-print.cc (dump_generic_node) <ARRAY_TYPE>: Add guard
for direct circularity.

2 years agoUse default lower bound for vector types in debug info
Eric Botcazou [Mon, 4 Jul 2022 10:14:03 +0000 (12:14 +0200)]
Use default lower bound for vector types in debug info

Vector types are represented as array types with DW_AT_GNU_vector attribute
in the debug info and a range [0 .. TYPE_VECTOR_SUBPARTS - 1].  Now that's
obviously skewed toward the C family of languages, therefore the attached
patch changes the lower bound to the default for the language of the CU.

gcc/
* dwarf2out.cc (gen_array_type_die): Use the default lower bound of
the language for vector types.

2 years agoMAINTAINERS: fix alphabetic sorting
Martin Liska [Mon, 4 Jul 2022 10:16:32 +0000 (12:16 +0200)]
MAINTAINERS: fix alphabetic sorting

ChangeLog:

* MAINTAINERS: fix sorting of names

2 years agoPrevent another potential stack overflow issue when demangling a maliciouslt mangled...
Nick Clifton [Mon, 4 Jul 2022 10:05:03 +0000 (11:05 +0100)]
Prevent another potential stack overflow issue when demangling a maliciouslt mangled Rust name.

libiberty/
* rust-demangle.c (demangle_path_maybe_open_generics): Add
recursion limit.

2 years agoIntegrate nonzero bits with irange.
Aldy Hernandez [Fri, 1 Jul 2022 11:20:42 +0000 (13:20 +0200)]
Integrate nonzero bits with irange.

The nonzero bits and integer ranges compliment each other quite well,
and it only makes sense to make the mask a first class citizen in the
irange.  We do a half assed job of keeping ranges and nonzero bits
somewhat in sync in SSA_NAME_RANGE_INFO, and the goal has always
been to integrate them properly.  This patch does that, in preparation
for streaming out full-resolution iranges between passes (think
SSA_NAME_RANGE_INFO).

Having nonzero bits in the irange allows us to get better results from
things like irange::contains_p() and keeping them in the irange allows
us to propagate the bits throughout with the ranger.  This patch
provides the bare infrastructure, without any optimizations to
range-ops, etc.  Those will come as follow-ups.

A few notes:

Legacy SSA_NAME_RANGE_INFO updates the nonzero bits every time a range
is set.  Here instead, we don't update the nonzero bits on a new
range, but calculate it on the fly when irange::get_nonzero_bits() is
called.  The goal is to only store nonzero bits that provide
meaningful information that can't be gleaned from the range itself.
But you can always call get_nonzero_bits() and get the full
information.

Nonzero bits are not supported in legacy mode.  The mask may be set
as a consequence of propagation or reading global ranges, but no
one from legacy land should be querying irange::get_nonzero_bits.  There
is an assert enforcing this.  However, legacy/global set_nonzero_bits()
continue to work as before.  There is no change to legacy behavior.

There is virtually no performance change with this patch, as there are
no consumers.  The next patch I post will be the SSA_NAME_RANGE_INFO
conversion to the new world, in which I will discuss performance
proper.  Hint: I'll be chewing up the time budget we gained with the
vrange conversion.

Tested and benchmarked on x86-64 Linux.

gcc/ChangeLog:

* value-range-storage.cc (irange_storage_slot::set_irange): Set
nonzero bits in irange.
(irange_storage_slot::get_irange): Get nonzero bits from irange.
* value-range.cc (irange::operator=): Set nonzero bits.
(irange::irange_set): Same.
(irange::irange_set_anti_range): Same.
(irange::set): Same.
(irange::verify_range): Same.
(irange::legacy_equal_p): Check nonzero bits.
(irange::equal_p): Same.
(irange::contains_p): Handle nonzero bits.
(irange::irange_union): Same.
(irange::irange_intersect): Same.
(irange::dump): Same.
(irange::set_nonzero_bits): New.
(irange::get_nonzero_bits): New.
(irange::intersect_nonzero_bits): New.
(irange::union_nonzero_bits): New.
(irange::dump_bitmasks): New.
* value-range.h (class irange): Add m_nonzero_mask.
(gt_ggc_mx): Handle nonzero bits.
(gt_pch_nx): Same.
(irange::set_undefined): Set nonzero bits.
(irange::set_varying): Same.
(irange::normalize_kind): Call set_undefined.

2 years agoPut virtual operands into loop-closed SSA
Richard Biener [Tue, 21 Jun 2022 14:17:58 +0000 (16:17 +0200)]
Put virtual operands into loop-closed SSA

When attempting to manually update SSA form after high-level loop
transforms such as loop versioning it is helpful when the loop-closed
SSA form includes virtual operands.  While we have the special
rewrite_virtuals_into_loop_closed_ssa function that doesn't
presently scale, invoking update_ssa by itself.  So the following
makes the regular loop-closed SSA form also cover virtual operands.
For users of loop_version this allows to use cheaper
TODO_update_ssa_no_phi, skipping dominance frontier compute
(for the whole function) and iterated dominance frontiers for each
copied def.

* tree-ssa-loop-manip.h
(rewrite_virtuals_into_loop_closed_ssa): Remove.
(rewrite_into_loop_closed_ssa_1): Likewise.
* tree-ssa-loop-manip.cc (rewrite_into_loop_closed_ssa_1):
Make static.
(rewrite_into_loop_closed_ssa): Remove loop overload,
always rewrite virtuals into LC SSA.
(check_loop_closed_ssa_bb): Also check virtuals.
* tree-ssa-dce.cc (remove_dead_phis): Preserve virtual
LC PHIs when in LC SSA.
* gimple-loop-jam.cc (fuse_loops): Do not rewrite into
loop-closed SSA here, but ...
(tree_loop_unroll_and_jam): ... here once.
* tree-if-conv.cc (version_loop_for_if_conversion): Use
the cheaper TODO_update_ssa_no_phi.
* tree-loop-distribution.cc (version_loop_by_alias_check):
Likewise.
* tree-ssa-loop-unswitch.cc (tree_unswitch_single_loop):
Likewise.
* tree-vect-loop-manip.cc (vect_loop_versioning): Likewise.
(tree_unswitch_outer_loop): Do not rewrite virtuals into
LC ssa.
* tree-parloops.cc (transform_to_exit_first_loop_alt):
Likewise.
(pass_parallelize_loops::execute): After finishing rewrite
into LC SSA again because we do not maintain it properly.

2 years ago[Ada] Do not make procedure call with only tag-indeternminate actuals dispatching
Eric Botcazou [Wed, 1 Jun 2022 23:00:48 +0000 (01:00 +0200)]
[Ada] Do not make procedure call with only tag-indeternminate actuals dispatching

The RM 3.9.2(19) clause says that the controlling tag value is statically
determined to be the tag of the tagged type involved.  As a matter of fact,
the call would be made dispatching only as a by-product of the propagation
of the controlling tag value to the tag-indeternminate actuals, but that's
unnecessary and not done in the equivalent case of a procedure call with
both statically tagged and tag-indeternminate actuals.

gcc/ada/

* sem_disp.adb (Check_Dispatching_Call): Merge the two special cases
where there are no controlling actuals but tag-indeternminate ones.

2 years ago[Ada] Fix dispatching call to primitive function with controlling tagged result
Eric Botcazou [Wed, 1 Jun 2022 22:45:14 +0000 (00:45 +0200)]
[Ada] Fix dispatching call to primitive function with controlling tagged result

When a dispatching call is made to a primitive function with a controlling
tagged result, the call is dispatching on result and thus must return the
class-wide type of the tagged type to accommodate all possible results.

This was ensured by Expand_Dispatching_Call only in the common case where
the result type is the type of the controlling argument, which does not
cover the case of a primitive function inherited from an ancestor type.

gcc/ada/

* exp_disp.adb (Expand_Dispatching_Call): Fix detection of calls
that are dispatching on tagged result.

2 years ago[Ada] vx7r2: do not include s-qnx.ads in the kernel and rtp runtimes
Doug Rupp [Tue, 31 May 2022 17:28:54 +0000 (10:28 -0700)]
[Ada] vx7r2: do not include s-qnx.ads in the kernel and rtp runtimes

Target specific runtime files must be added to a the exclude list so the
files don't automatically get copied to other runtimes.

gcc/ada/

* Makefile.rtl (ADA_EXCLUDE_SRCS): Add s-qnx.ads.

2 years ago[Ada] Small housekeeping work in Expand_N_Object_Declaration
Eric Botcazou [Tue, 31 May 2022 11:20:46 +0000 (13:20 +0200)]
[Ada] Small housekeeping work in Expand_N_Object_Declaration

The local function Rewrite_As_Renaming can be called twice in certain
circumstances, which is both not quite safe and unnecessary, so this
replaces it with a local variable whose value is computed only once.

No functional changes.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration) <OK_To_Rename_Ref>: New
local function.
<Rewrite_As_Renaming>: Change to a local variable whose value is
computed once and generate a call to Finalize after this is done.
Simplify the code creating the renaming at the end.

2 years ago[Ada] Makefile.rtl: remove references t oVxworks RTP Cert .spec files
Doug Rupp [Thu, 19 May 2022 20:41:27 +0000 (13:41 -0700)]
[Ada] Makefile.rtl: remove references t oVxworks RTP Cert .spec files

gcc/ada/

* Makefile.rtl (GCC_SPEC_FILES): Remove vxworks cert files.

2 years ago[Ada] Refactor duplicated resolution of Count and Index attributes
Piotr Trojanek [Tue, 31 May 2022 10:22:21 +0000 (12:22 +0200)]
[Ada] Refactor duplicated resolution of Count and Index attributes

Attribute Index, which was added to Ada 2022 by AI12-0143, is resolved
just like attribute Count. However, code duplication rightly triggered a
CodePeer warning.

gcc/ada/

* sem_attr.adb (Resolve_Attribute): Refactor duplicated code for
Count and Index attributes.

2 years ago[Ada] Use static stack allocation for small string if-expressions
Eric Botcazou [Sun, 29 May 2022 16:18:20 +0000 (18:18 +0200)]
[Ada] Use static stack allocation for small string if-expressions

This changes the expanded code generated for if-expressions of 1-dimensional
arrays to create a static temporary on the stack if a small upper bound can
be computed for the length of a subtype covering the result.  Static stack
allocation is preferred over dynamic allocation for code generation purpose.

This also contains a couple of enhancements to the support code for checks,
so as to avoid generating useless checks during the modified expansion.

gcc/ada/

* checks.adb (Apply_Length_Check_On_Assignment): Return early if
the Suppress_Assignment_Checks flag is set.
(Selected_Range_Checks): Deal with conditional expressions.
* exp_ch4.adb (Too_Large_Length_For_Array): New constant.
(Expand_Concatenate): Use it in lieu of Too_Large_Max_Length.
(Expand_N_If_Expression): If the result has a unidimensional array
type but the dependent expressions have constrained subtypes with
known bounds, create a static temporary on the stack with a subtype
covering the result.
(Get_First_Index_Bounds): Deal with string literals.
* uintp.ads (Uint_256): New deferred constant.
* sinfo.ads (Suppress_Assignment_Checks): Document new usage.

2 years ago[Ada] Adjust previous change to Rewrite_As_Renaming
Eric Botcazou [Sun, 29 May 2022 11:35:57 +0000 (13:35 +0200)]
[Ada] Adjust previous change to Rewrite_As_Renaming

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration.Rewrite_As_Renaming):
Do not rewrite if the declaration has got constraints.
* sinfo.ads (Case Expression Alternative): Fix typo.

2 years ago[Ada] Use static stack allocation for small dynamic string concatenations
Eric Botcazou [Fri, 27 May 2022 13:28:29 +0000 (15:28 +0200)]
[Ada] Use static stack allocation for small dynamic string concatenations

This changes the expanded code generated for dynamic concatenations to
use a static array subtype for the temporary created on the stack if a
small upper bound can be computed for the length of the result.  Static
stack allocation is preferred over dynamic allocation for code
generation purposes.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration.Rewrite_As_Renaming):
Be prepared for slices.
* exp_ch4.adb (Get_First_Index_Bounds): New procedure.
(Expand_Array_Comparison.Length_Less_Than_4): Call it.
(Expand_Concatenate): Try to compute a maximum length for
operands with variable length and a maximum total length at the
end.  If the concatenation is dynamic, but a sensible maximum
total length has been computed, use this length to create a
static array subtype for the temporary and return a slice of it.

2 years ago[Ada] Enforce deferred constant completion rules
Steve Baird [Thu, 26 May 2022 00:21:39 +0000 (17:21 -0700)]
[Ada] Enforce deferred constant completion rules

If a constrained subtype is given when a deferred constant is declared,
then the subtype given in the completion is required (at compile time)
to be subject to a statically matching constraint. This rule was not
properly enforced in some cases and constructs that should have been
rejected were incorrectly accepted.

gcc/ada/

* sem_ch3.adb (Check_Possible_Deferred_Completion): Delete
Prev_Obj_Def formal parameter.  Reorganize code so that
statically matching check is also performed in the case where
the subtype given in the initial declaration is constrained and
the subtype given in the completion is not.

2 years ago[Ada] Assertions in Einfo.Utils
Bob Duff [Thu, 26 May 2022 14:27:42 +0000 (10:27 -0400)]
[Ada] Assertions in Einfo.Utils

Add predicates on subtypes E and N.

gcc/ada/

* einfo-utils.ads, einfo-utils.adb: Add predicates on subtypes E
and N.  Change some parameters to use the unpredicated subtypes,
because they sometimes return e.g. Empty.  Note that N_Entity_Id
has a predicate; Entity_Id does not.
* exp_tss.adb (Base_Init_Proc): Use Entity_Id instead of E,
because otherwise we fail the predicate. We shouldn't be
referring to single-letter names from far away anyway.
* sem_aux.adb (Is_Derived_Type): Likewise.
* sem_res.adb (Is_Definite_Access_Type): Use N_Entity_Id for
predicate.
* types.ads (Entity_Id): Add comment explaining the difference
between Entity_Id and N_Entity_Id.

2 years ago[Ada] Tech debt: Remove code duplication
Justin Squirek [Thu, 26 May 2022 15:02:01 +0000 (15:02 +0000)]
[Ada] Tech debt: Remove code duplication

This patch corrects removes some code duplication within the GNAT
compiler.

gcc/ada/

* exp_util.adb (Remove_Side_Effects): Combine identical
branches.
* sem_attr.adb (Analyze_Attribute): Combine identical cases
Attribute_Has_Same_Storage and Attribute_Overlaps_Storage.
* sem_prag.adb (Check_Role): Combine E_Out_Parameter case with
general case for parameters.
* sem_util.adb (Accessibility_Level): Combine identical
branches.
* sprint.adb (Sprint_Node_Actual): Combine cases for
N_Real_Range_Specification and N_Signed_Integer_Type_Definition.

2 years ago[Ada] Single character argument in call to Quote_Argument raises error
Justin Squirek [Thu, 26 May 2022 15:15:46 +0000 (15:15 +0000)]
[Ada] Single character argument in call to Quote_Argument raises error

This patch corrects an issue in the compiler whereby calling
Quote_Argument with an argument that is of size 1 may lead to a
CONSTRAINT_ERROR raised at runtime due to an undersized buffer.

gcc/ada/

* libgnat/s-os_lib.adb (Quote_Argument): Modify the result
buffer size calculation to handle the case where Arg'Length is
1.

2 years ago[Ada] Fix missing error on 'Access of constrained array
Bob Duff [Wed, 25 May 2022 15:51:52 +0000 (11:51 -0400)]
[Ada] Fix missing error on 'Access of constrained array

For X'Access, the designated subtype of the access type must statically
match the nominal subtype of X.  This patch fixes a bug where the error
was not detected when there is an unrelated declaration of the form "Y :
T := X;", where T is an unconstrained array subtype.

gcc/ada/

* exp_util.adb (Expand_Subtype_From_Expr): Generate a new
subtype when Is_Constr_Subt_For_UN_Aliased is True, so the
Is_Constr_Subt_For_U_Nominal flag will not be set on the
preexisting subtype.
* sem_attr.adb, sem_ch3.adb: Minor.

2 years ago[Ada] Do not use front-end build-in-place mechanism for nonlimited types
Eric Botcazou [Thu, 26 May 2022 11:34:55 +0000 (13:34 +0200)]
[Ada] Do not use front-end build-in-place mechanism for nonlimited types

It was only used in specific cases for controlled types but no longer
provides any significant benefit in practice.

gcc/ada/

* debug.adb (d.9): Remove usage.
* exp_ch6.adb (Expand_Simple_Function_Return): Remove redundant
test on Debug_Flag_Dot_L.
(Is_Build_In_Place_Result_Type): Return false for nonlimited types.
(Is_Build_In_Place_Function): Tidy up and remove redundant test on
Debug_Flag_Dot_L.

2 years ago[Ada] Call-initialize all controlled objects in place
Eric Botcazou [Thu, 26 May 2022 09:06:01 +0000 (11:06 +0200)]
[Ada] Call-initialize all controlled objects in place

This changes the compiler to build in place almost all objects that need
finalization and are initialized with the result of a function call, thus
saving a pair of Adjust/Finalize calls for the anonymous return object.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Don't adjust the object
if the expression is a function call.
<Rewrite_As_Renaming>: Return true if the object needs finalization
and is initialized  with the result of a function call returned on
the secondary stack.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Add Use_Sec_Stack boolean
parameter.  Early return if the parent is an object declaration and
Use_Sec_Stack is false.
(Expand_Call_Helper): Adjust call to Expand_Ctrl_Function_Call.
* exp_ch7.adb (Find_Last_Init): Be prepared for initialization still
present in the object declaration.
* sem_ch3.adb (Analyze_Object_Declaration): Call the predicates
Needs_Secondary_Stack and Needs_Finalization to guard the renaming
optimization.

2 years ago[Ada] Add Ada 2022 Key function to sets containers
Bob Duff [Tue, 24 May 2022 17:03:21 +0000 (13:03 -0400)]
[Ada] Add Ada 2022 Key function to sets containers

This patch adds the new Generic_Keys.Key function to the set children
of Ada.Containers.

gcc/ada/

* libgnat/a-cbhase.ads, libgnat/a-cborse.ads,
libgnat/a-cihase.ads, libgnat/a-ciorse.ads,
libgnat/a-cohase.ads, libgnat/a-coorse.ads (Key): New function
that takes a Container parameter, implemented as an expression
function, so it is self explanatory (doesn't need a comment).

2 years ago[Ada] Fix length of title underlines.
Vasiliy Fofanov [Wed, 25 May 2022 15:49:38 +0000 (17:49 +0200)]
[Ada] Fix length of title underlines.

gcc/ada/

* doc/gnat_rm/the_gnat_library.rst: Fix length of title
underlines.

2 years ago[Ada] Compiler rejects legal allocator in record component constraint expression
Steve Baird [Tue, 24 May 2022 23:03:58 +0000 (16:03 -0700)]
[Ada] Compiler rejects legal allocator in record component constraint expression

In some cases when a legal allocator which defines a new subtype for the
allocated object occurs as part of a record component constraint
expression, the compiler would incorrectly reject the allocator.

gcc/ada/

* sem_ch4.adb (Analyze_Allocator): After calling Insert_Action
to insert a subtype declaration associated with an allocator,
the subtype declaration will usually be analyzed. But not
always. Add an explicit call to Preanalyze to cope with the
unusual case. The subtype declaration must be at least
preanalyzed before the call to Sem_Ch3.Process_Subtype a little
while later, during which we analyze an identifier that refers
to the subtype.

2 years ago[Ada] Avoid unwanted warnings for statically-known-successful assertions
Steve Baird [Tue, 24 May 2022 21:09:14 +0000 (14:09 -0700)]
[Ada] Avoid unwanted warnings for statically-known-successful assertions

The -gnatwc switch enables warnings for test condition outcomes that are
known at compile time. Such warnings are unlikely to be useful in the
case of an assertion expression (or a subexpression thereof), so do not
generate them in that case.

gcc/ada/

* sem_warn.adb (Warn_On_Constant_Valid_Condition): Do not
generate a warning if the expression in question is an assertion
expression, or a subexpression thereof. But do call
Test_Comparison so that it can generate warnings for the cases
that it generates warnings for.
* sem_prag.ads: Modify Assertion_Expression_Pragma constant so
that the predicate Sem_Util.In_Assertion_Expression_Pragma
returns True for the expression of a Compile_Time_Error pragma.

2 years ago[Ada] Add a RM entry for the functional infinite sequences
Julien Bortolussi [Tue, 24 May 2022 14:15:47 +0000 (16:15 +0200)]
[Ada] Add a RM entry for the functional infinite sequences

Modify the RM to take into account the new functional container.

gcc/ada/

* doc/gnat_rm/the_gnat_library.rst: Add the new entry.
* gnat_rm.texi: Regenerate.

2 years ago[Ada] Give missing error on ambiguous operand of equality operator
Eric Botcazou [Tue, 24 May 2022 18:38:01 +0000 (20:38 +0200)]
[Ada] Give missing error on ambiguous operand of equality operator

When the code responsible for giving errors on ambiguous operands of
comparison and equality operators was moved from the 1st phase (analysis)
to the 2nd phase (resolution) of semantic processing, it was incorrectly
restricted to the operator case, which was valid during the 1st phase but
is not during the 2nd phase.

gcc/ada/

* sem_res.adb (Resolve_Comparison_Op): Deal with ambiguous operands
in all cases.
(Resolve_Equality_Op): Likewise, except for the case of the implicit
inequality operator created for a user-defined operator that is not
an intrinsic subprogram.

2 years ago[Ada] Add Ada 2022 features to sets containers
Bob Duff [Mon, 23 May 2022 13:47:18 +0000 (09:47 -0400)]
[Ada] Add Ada 2022 features to sets containers

This patch adds some Ada 2022 features to the set children of
Ada.Containers.

gcc/ada/

* libgnat/a-cbhase.adb, libgnat/a-cbhase.ads,
libgnat/a-cborse.adb, libgnat/a-cborse.ads,
libgnat/a-cihase.adb, libgnat/a-cihase.ads,
libgnat/a-ciorse.adb, libgnat/a-ciorse.ads,
libgnat/a-cohase.adb, libgnat/a-cohase.ads,
libgnat/a-conhel.adb, libgnat/a-conhel.ads,
libgnat/a-coorse.adb, libgnat/a-coorse.ads: Add Has_Element,
Element, Query_Element, and Next subprograms that take a Set
parameter. Add Tampering_With_Cursors_Prohibited function. These
are all new in Ada 2022.

2 years ago[Ada] Update the documentation of functional containers
Claire Dross [Tue, 24 May 2022 14:37:18 +0000 (16:37 +0200)]
[Ada] Update the documentation of functional containers

Functional containers are now controlled. Update the documentation
accordingly.

gcc/ada/

* doc/gnat_rm/the_gnat_library.rst: Functional vectors, sets,
and maps are now controlled.
* gnat_rm.texi: Regenerate.

2 years ago[Ada] Add GNAT specific pragmas to the equivalent Assertion_Policy for -gnata
Claire Dross [Tue, 24 May 2022 08:42:46 +0000 (10:42 +0200)]
[Ada] Add GNAT specific pragmas to the equivalent Assertion_Policy for -gnata

All assertion pragmas are enabled by default when using -gnata. We need
to add the GNAT specific ones to the list.

gcc/ada/

* doc/gnat_ugn/building_executable_programs_with_gnat.rst
(Debugging and Assertion Control): Add GNAT specific assertion
pragmas to the equivalent Assertion_Policy for the -gnata
option.
* gnat_ugn.texi: Regenerate.

2 years ago[Ada] Incorrect accessibility check on return of discriminated type
Justin Squirek [Thu, 24 Mar 2022 18:42:09 +0000 (18:42 +0000)]
[Ada] Incorrect accessibility check on return of discriminated type

This patch corrects an error in the compiler whereby the presence of a
call to a function returning a type with an access discriminant within
an expanded loop condition caused the wrong value to be supplied for the
extra- accessibility-of-result actual, thus causing incorrect checks
within the callee at the point of return.

This change also corrects a problem where spurious "null value not
allowed" warnings were generated for tagged type declarations with an
access discriminant specified as "null."

gcc/ada/

* sem_disp.adb (Most_Descendant_Use_Clause): Remove call to
deprecated Is_Internal.
* sem_util.adb (Innermost_Master_Scope_Depth): Use
Find_Enclosing_Scope instead of Nearest_Dynamic_Scope to avoid
cases where relevant scopes get skipped leading to an incorrect
scope depth calculation.

2 years ago[Ada] Plug loophole for built-in-place return with limited_with clause
Eric Botcazou [Mon, 23 May 2022 23:14:18 +0000 (01:14 +0200)]
[Ada] Plug loophole for built-in-place return with limited_with clause

When the result type of a function requiring built-in-place return is
only visible through a limited_with clause, the compiled needs to wait
for the nonlimited view to be available in order to compute whether
the built-in-place return is needed, and this comprises tagging the
function with the Returns_By_Ref flag.

gcc/ada/

* exp_ch6.adb (Build_In_Place_Formal): Also compute Returns_By_Ref
for the function if the extra formals were not built initially.

2 years ago[Ada] Fix for resolution of overloaded subprogram for Iterable aspect
Piotr Trojanek [Fri, 20 May 2022 20:29:51 +0000 (22:29 +0200)]
[Ada] Fix for resolution of overloaded subprogram for Iterable aspect

When resolving the Iterable aspect we look for a functions that are
declared in the same scope as the annotated type and that have the
required number and types formal parameters. However, we didn't guard
against functions that have no formal parameter at all.

gcc/ada/

* sem_ch13.adb (Resolve_Iterable_Operation): Add guard to
prevent crash when the examined function has no formal
parameters and Etype is called on Empty entity.

2 years ago[Ada] Create new unbounded functional sequence
Julien Bortolussi [Wed, 4 May 2022 15:45:34 +0000 (17:45 +0200)]
[Ada] Create new unbounded functional sequence

Add a new unbounded functional sequence. This sequence is indexed by
Big_Positive and so is unbounded from the user and spark points view.
Hower the actually implemented sequence are bounded by Count_Type'Last.

gcc/ada/

* libgnat/a-cfinse.adb, libgnat/a-cfinse.ads: Implementation
files of the sequence.
* Makefile.rtl, impunit.adb: Take into account the add of the
new files

2 years ago[Ada] Adjust description of Pure_Function pragma
Eric Botcazou [Mon, 23 May 2022 07:48:49 +0000 (09:48 +0200)]
[Ada] Adjust description of Pure_Function pragma

The current wording can be read as implying that the result of a call
to a pure function does not depend on the context, which is incorrect.
The pragma only guarantees the absence of side effects of such a call.

gcc/ada/

* doc/gnat_rm/implementation_defined_pragmas.rst (Pure_Function):
Fix ambiguous wording about context dependence.
* gnat_rm.texi: Regenerate.

2 years agotree-optimization/106055 - issue with autopar
Richard Biener [Fri, 1 Jul 2022 13:32:30 +0000 (15:32 +0200)]
tree-optimization/106055 - issue with autopar

When autopar uses graphites canonicalize_loop_closed_ssa it fails to
check whether propagation is allowed and thus it ends up messing up
abnormal constraints.

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

PR tree-optimization/106055
* graphite.cc (canonicalize_loop_closed_ssa): Check whether
we can propagate.

* gcc.dg/graphite/pr106055.c: New testcase.

2 years agoi386: Extend cvtps2pd to memory
Haochen Jiang [Mon, 30 May 2022 09:12:31 +0000 (17:12 +0800)]
i386: Extend cvtps2pd to memory

gcc/ChangeLog:

PR target/43618
* config/i386/sse.md (extendv2sfv2df2): New define_expand.
(sse2_cvtps2pd_<mask_name>): Change constraint of operands[1].
(*sse2_cvtps2pd_<mask_name>_1): Rename from extendvsdfv2df2.

gcc/testsuite/ChangeLog:

PR target/43618
* gcc.target/i386/pr43618-1.c: New test.

2 years agoRemove some deprecated irange methods.
Aldy Hernandez [Sun, 3 Jul 2022 16:22:11 +0000 (18:22 +0200)]
Remove some deprecated irange methods.

Tested on x86-64 Linux.

gcc/ChangeLog:

* ipa-cp.cc (ipcp_vr_lattice::meet_with_1): Use operator!=.
* ipa-prop.cc (struct ipa_vr_ggc_hash_traits): Same.
* tree-ssa-loop-unswitch.cc (struct unswitch_predicate): Use set
with two arguments.
(find_unswitching_predicates_for_bb): Same.
* tree-vrp.cc (range_fold_unary_symbolics_p): Same.
* value-range-equiv.cc (value_range_equiv::equal_p): Use operator==.
* value-range.cc (irange::equal_p): Rename to...
(irange::operator==): ...this.
* value-range.h (irange::set): Remove.
(irange::operator==): Remove.
(irange::set_zero): Use set with two arguments.
* vr-values.cc (vr_values::extract_range_from_binary_expr): Same.
(vr_values::extract_range_from_unary_expr): Same.
(check_for_binary_op_overflow): Same.
(bounds_of_var_in_loop): Same.

2 years agoDaily bump.
GCC Administrator [Mon, 4 Jul 2022 00:16:19 +0000 (00:16 +0000)]
Daily bump.

2 years agox86: Support 2/4/8 byte constant vector stores
H.J. Lu [Sat, 18 Jun 2022 00:02:05 +0000 (17:02 -0700)]
x86: Support 2/4/8 byte constant vector stores

1. Add a predicate for constant vectors which can be converted to integer
constants suitable for constant integer stores.  For a 8-byte constant
vector, the converted 64-bit integer must be valid for store with 64-bit
immediate, which is a 64-bit integer sign-extended from a 32-bit integer.
2. Add a new pattern to allow 2-byte, 4-byte and 8-byte constant vector
stores, like

(set (mem:V2HI (reg:DI 84))
     (const_vector:V2HI [(const_int 0 [0]) (const_int 1 [0x1])]))

3. After reload, convert constant vector stores to constant integer
stores, like

(set (mem:SI (reg:DI 5 di [84]))
     (const_int 65536 [0x10000]))

For

void
foo (short * c)
{
  c[0] = 0;
  c[1] = 1;
}

it generates

movl $65536, (%rdi)

instead of

movl .LC0(%rip), %eax
movl %eax, (%rdi)

gcc/

PR target/106022
* config/i386/i386-protos.h (ix86_convert_const_vector_to_integer):
New.
* config/i386/i386.cc (ix86_convert_const_vector_to_integer):
New.
* config/i386/mmx.md (V_16_32_64): New.
(*mov<mode>_imm): New patterns for stores with 16-bit, 32-bit
and 64-bit constant vector.
* config/i386/predicates.md (x86_64_const_vector_operand): New.

gcc/testsuite/

PR target/106022
* gcc.target/i386/pr106022-1.c: New test.
* gcc.target/i386/pr106022-2.c: Likewise.
* gcc.target/i386/pr106022-3.c: Likewise.
* gcc.target/i386/pr106022-4.c: Likewise.

2 years agoMove range allocator code to value-range-storage.*
Aldy Hernandez [Sun, 3 Jul 2022 13:25:38 +0000 (15:25 +0200)]
Move range allocator code to value-range-storage.*

Now that vrange_storage is in its own file, I think it's prudent to
move all the vrange allocator code there since it's all related.
The users of value-range.h do not need to know the implementation
details of the storage facilities.

Tested and benchmarked on x86-64 Linux.

gcc/ChangeLog:

* gimple-range-cache.cc: Include value-range-storage.h.
* gimple-range-cache.h (class block_range_cache): Add "class" to
m_range_allocator.
* gimple-range-edge.cc
(gimple_outgoing_range::gimple_outgoing_range): Allocate allocator.
(gimple_outgoing_range::~gimple_outgoing_range): Free allocator.
(gimple_outgoing_range::calc_switch_ranges): Dereference allocator.
* gimple-range-edge.h: Add "class" to m_range_allocator.
* gimple-range-infer.cc
(infer_range_manager::infer_range_manager): Allocate allocator.
(infer_range_manager::~infer_range_manager): Free allocator.
(infer_range_manager::get_nonzero): Dereference allocator.
(infer_range_manager::add_range): Same.
* gimple-range-infer.h (class vrange_allocator): Add "class" to
m_range_allocator.
* value-range-storage.h (class vrange_allocator): Move from
value-range.h.
(class obstack_vrange_allocator): Same.
(class ggc_vrange_allocator): Same.
(vrange_allocator::alloc_vrange): Same.
(vrange_allocator::alloc_irange): Same.
* value-range.h (class vrange_allocator): Move to value-range-storage.h.
(class obstack_vrange_allocator): Same.
(class ggc_vrange_allocator): Same.

2 years agoAdd myself to write after approval and DCO.
Immad Mir [Sun, 3 Jul 2022 09:08:51 +0000 (14:38 +0530)]
Add myself to write after approval and DCO.

This is text alignment correction for my previous patch.

ChangeLog:
* MAINTAINERS: add myself.

2 years agoAdd myself to write-after-approval and DCO
Immad Mir [Sun, 3 Jul 2022 08:56:14 +0000 (14:26 +0530)]
Add myself to write-after-approval and DCO

ChangeLog:
* MAINTAINERS: Add myself to write after approval and DCO.

2 years agoImplement class vrange_storage to stream ranges to long term memory.
Aldy Hernandez [Fri, 10 Jun 2022 12:59:40 +0000 (14:59 +0200)]
Implement class vrange_storage to stream ranges to long term memory.

This patch implements a storage class that will be used to stream out
ranges to long term storage, initially in SSA_NAME_RANGE_INFO, but it
is flexible enough to use with our obstack allocator.  For instance,
in the future we could use it in the ranger cache to save memory.

The current size of range_info_def which is used in
SSA_NAME_RANGE_INFO is 16 bytes.  With this patch, the size of the
slot (irange_storage_slot) will be 24 bytes.  But we'll have the
ability to be able to store up to 5 pairs of sub-ranges if necessary.
If we ever need to save more (say for switches), we could explore a
trailing_wide_ints structure with a pointer to the m_len[N] bits as
Jakub has suggested.

In follow-up patches I will contribute the SSA_NAME_RANGE_INFO changes
as well as changes storing the nonzero bits within an irange.

For reference, the main interface is rather simple:

class vrange_storage
{
public:
  vrange_storage (vrange_allocator *alloc) : m_alloc (alloc) { }
  void *alloc_slot (const vrange &r);
  void free (void *slot);
  void get_vrange (const void *slot, vrange &r, tree type);
  void set_vrange (void *slot, const vrange &r);
  static bool fits_p (const void *slot, const vrange &r);
};

The above class will have the knowledge to stream out the different
ranges we support (currently only irange_storage_slot).  As has been
discussed, the irange storage will use trailing wide ints:

class GTY ((variable_size)) irange_storage_slot
{
<snip>
<snip>
  // This is the maximum number of wide_int's allowed in the trailing
  // ints structure, without going over 16 bytes (128 bits) in the
  // control word that preceeds the HOST_WIDE_INTs in
  // trailing_wide_ints::m_val[].
  static const unsigned MAX_INTS = 12;

  // Maximum number of range pairs we can handle, considering the
  // nonzero bits take one wide_int.
  static const unsigned MAX_PAIRS = (MAX_INTS - 1) / 2;

  trailing_wide_ints<MAX_INTS> m_ints;
};

Tested on x86-64 Linux.

gcc/ChangeLog:

* Makefile.in (OBJS): Add value-range-storage.o.
(GTFILES): Add value-range-storage.h.
* gengtype.cc (open_base_files): Add value-range-storage.h.
* value-range-storage.cc: New file.
* value-range-storage.h: New file.

2 years agoloongarch: use -mno-check-zero-division as the default for optimized code
Xi Ruoyao [Sat, 2 Jul 2022 08:16:44 +0000 (16:16 +0800)]
loongarch: use -mno-check-zero-division as the default for optimized code

Integer division by zero is undefined behavior anyway, and there are
already many platforms where neither the GCC port and the hardware do
anything to trap on division by zero.  So any portable program shall not
rely on SIGFPE on division by zero, in both theory and practice.  As the
result, there is no real reason to cost two additional instructions just
for the trap on division by zero with a new ISA.

One remaining reason to trap on division by zero may be debugging,
especially while -fsanitize=integer-divide-by-zero is not implemented
for LoongArch yet.  To make debugging easier, keep -mcheck-zero-division
as the default for -O0 and -Og, but use -mno-check-zero-division as the
default for all other optimization levels.

Co-authored-by: Lulu Cheng <chenglulu@loongson.cn>
gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_check_zero_div_p):
New static function.
(loongarch_idiv_insns): Use loongarch_check_zero_div_p instead
of TARGET_CHECK_ZERO_DIV.
(loongarch_output_division): Likewise.
* common/config/loongarch/loongarch-common.cc
(TARGET_DEFAULT_TARGET_FLAGS): Remove unneeded hook.
* doc/invoke.texi: Update to match the new behavior.

gcc/testsuite/ChangeLog:

* gcc.c-torture/execute/20101011-1.c (dg-additional-options):
add -mcheck-zero-division for LoongArch targets.

2 years agoUse fixed-width types in allocation size tests
Tim Lange [Sun, 3 Jul 2022 01:22:30 +0000 (03:22 +0200)]
Use fixed-width types in allocation size tests

The patch changes the types inside the tests for the allocation size
checker to fixed-width types of stdint.h to account for different
architectures with different type widths.

2022-07-03  Tim Lange  <mail@tim-lange.me>

gcc/testsuite/ChangeLog:

* gcc.dg/analyzer/allocation-size-1.c: Use fixed-length types.
* gcc.dg/analyzer/allocation-size-2.c: Likewise.
* gcc.dg/analyzer/allocation-size-3.c: Likewise.
* gcc.dg/analyzer/allocation-size-4.c: Likewise.
* gcc.dg/analyzer/allocation-size-5.c: Likewise.

2 years agotree-optimization: only DSE trapping insn if -fdelete-dead-exceptions
Ian Lance Taylor [Fri, 1 Jul 2022 21:51:45 +0000 (14:51 -0700)]
tree-optimization: only DSE trapping insn if -fdelete-dead-exceptions

gcc/ChangeLog:

* tree-ssa-dse.cc (dse_optimize_stmt): Only delete a trapping
statement if -fdelete-dead-exceptions.

gcc/testsuite/ChangeLog:

* g++.dg/torture/except-1.C: New test.

2 years agoDaily bump.
GCC Administrator [Sun, 3 Jul 2022 00:16:23 +0000 (00:16 +0000)]
Daily bump.

2 years agoMAINTAINERS: Add myself to write after approval and DCO
Tim Lange [Sat, 2 Jul 2022 17:27:08 +0000 (19:27 +0200)]
MAINTAINERS: Add myself to write after approval and DCO

2022-07-02  Tim Lange  <mail@tim-lange.me>

ChangeLog:

* MAINTAINERS: Add myself.

2 years agoanalyzer: add allocation size checker [PR105900]
Tim Lange [Thu, 30 Jun 2022 22:02:17 +0000 (00:02 +0200)]
analyzer: add allocation size checker [PR105900]

This patch adds an checker that warns about code paths in which a buffer
is assigned to a incompatible type, i.e. when the allocated buffer size
is not a multiple of the pointee's size.

Regression-tested on x86_64 Linux. Also compiled coreutils, curl, openssh and
httpd with the patch enabled.

2022-07-01  Tim Lange  <mail@tim-lange.me>

gcc/analyzer/ChangeLog:

PR analyzer/105900
* analyzer.opt: Added Wanalyzer-allocation-size.
* checker-path.cc (region_creation_event::get_desc): Added call to new
virtual function pending_diagnostic::describe_region_creation_event.
* checker-path.h: Added region_creation_event::get_desc.
* diagnostic-manager.cc (diagnostic_manager::add_event_on_final_node):
New function.
* diagnostic-manager.h:
Added diagnostic_manager::add_event_on_final_node.
* pending-diagnostic.h (struct region_creation): New event_desc struct.
(pending_diagnostic::describe_region_creation_event): Added virtual
function to overwrite description of a region creation.
* region-model.cc (class dubious_allocation_size): New class.
(capacity_compatible_with_type): New helper function.
(class size_visitor): New class.
(struct_or_union_with_inheritance_p): New helper function.
(is_any_cast_p): New helper function.
(region_model::check_region_size): New function.
(region_model::set_value): Added call to
region_model::check_region_size.
* region-model.h (class region_model): New function check_region_size.
* svalue.cc (region_svalue::accept): Changed to post-order traversal.
(initial_svalue::accept): Likewise.
(unaryop_svalue::accept): Likewise.
(binop_svalue::accept): Likewise.
(sub_svalue::accept): Likewise.
(repeated_svalue::accept): Likewise.
(bits_within_svalue::accept): Likewise.
(widening_svalue::accept): Likewise.
(unmergeable_svalue::accept): Likewise.
(compound_svalue::accept): Likewise.
(conjured_svalue::accept): Likewise.
(asm_output_svalue::accept): Likewise.
(const_fn_result_svalue::accept): Likewise.

gcc/ChangeLog:

PR analyzer/105900
* doc/invoke.texi: Added Wanalyzer-allocation-size.

gcc/testsuite/ChangeLog:

PR analyzer/105900
* gcc.dg/analyzer/pr96639.c: Changed buffer size to omit warning.
* gcc.dg/analyzer/allocation-size-1.c: New test.
* gcc.dg/analyzer/allocation-size-2.c: New test.
* gcc.dg/analyzer/allocation-size-3.c: New test.
* gcc.dg/analyzer/allocation-size-4.c: New test.
* gcc.dg/analyzer/allocation-size-5.c: New test.

Signed-off-by: Tim Lange <mail@tim-lange.me>
2 years agoanalyzer: implement five new warnings for misuse of POSIX file descriptor APIs [PR106...
Immad Mir [Sat, 2 Jul 2022 16:39:37 +0000 (22:09 +0530)]
analyzer: implement five new warnings for misuse of POSIX file descriptor APIs [PR106003].

This patch adds a new state machine to the analyzer for checking usage of POSIX file descriptor
APIs with five new warnings.

It adds:
- check for FD leaks (CWE 775).
- check for double "close" of a FD (CWE-1341).
- check for read/write of a closed file descriptor.
- check whether a file descriptor was used without being checked for validity.
- check for read/write of a descriptor opened for just writing/reading.

gcc/ChangeLog:
PR analyzer/106003
* Makefile.in (ANALYZER_OBJS): Add sm-fd.o.
* doc/invoke.texi:  Add -Wanalyzer-fd-double-close, -Wanalyzer-fd-leak,
-Wanalyzer-fd-access-mode-mismatch, -Wanalyzer-fd-use-without-check,
-Wanalyzer-fd-use-after-close.

gcc/analyzer/ChangeLog:
PR analyzer/106003
* analyzer.opt (Wanalyzer-fd-leak): New option.
(Wanalyzer-fd-access-mode-mismatch): New option.
(Wanalyzer-fd-use-without-check): New option.
(Wanalyzer-fd-double-close): New option.
(Wanalyzer-fd-use-after-close): New option.
* sm.h (make_fd_state_machine): New decl.
* sm.cc (make_checkers): Call make_fd_state_machine.
* sm-fd.cc: New file.

gcc/testsuite/ChangeLog:
PR analyzer/106003
* gcc.dg/analyzer/fd-1.c: New test.
* gcc.dg/analyzer/fd-2.c: New test.
* gcc.dg/analyzer/fd-3.c: New test.
* gcc.dg/analyzer/fd-4.c: New test.

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

2 years agocompiler: use correct init order for multi-value initialization
Ian Lance Taylor [Fri, 1 Jul 2022 00:40:00 +0000 (17:40 -0700)]
compiler: use correct init order for multi-value initialization

Use the correct initialization order for

var a = c
var b, c = x.(bool)

The global c is initialized by the preinit of b, but were missing a
dependency of c on b, so a would be initialized to the zero value of c
rather than the correct value.

Simply adding the dependency of c on b didn't work because the preinit
of b refers to c, so that appeared circular.  So this patch changes
the init order to skip dependencies that only appear on the left hand
side of assignments in preinit blocks.

Doing that didn't work because the write barrier pass can transform "a
= b" into code like "gcWriteBarrier(&a, b)" that is not obviously a
simple assigment.  So this patch moves the collection of dependencies
to just after lowering, before the write barriers are inserted.

Making those changes permit relaxing the requirement that we don't
warn about self-dependency in preinit blocks, so now we correctly warn
for

var a, b any = b.(bool)

The test case is https://go.dev/cl/415238.

Fixes golang/go#53619

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/415594

2 years agotrailing_wide_ints with runtime variable lengths
Aldy Hernandez [Fri, 10 Jun 2022 13:00:44 +0000 (15:00 +0200)]
trailing_wide_ints with runtime variable lengths

Currently global ranges are stored in SSA_NAME_RANGE_INFO as a pair of
wide_int-like objects along with the nonzero bits.  We frequently lose
precision when streaming out our higher resolution iranges.  The plan
was always to store the full irange between passes.  However, as was
originally discussed eons ago:

https://gcc.gnu.org/pipermail/gcc-patches/2017-May/475139.html

...we need a memory efficient way of saving iranges, preferably using
the trailing_wide_ints idiom.

The problem with doing so is that trailing_wide_ints assume a
compile-time specified number of elements.  For irange, we need to
determine the size at run-time.

One solution is to adapt trailing_wide_ints such that N is the maximum
number of elements allowed, and allow setting the actual number at
run-time (defaulting to N).  The attached patch does this, while
requiring no changes to existing users.

It uses a byte to store the number of elements in the
trailing_wide_ints control word.  The control word is currently a
16-bit precision, an 8-bit max-length, and the rest is used for
m_len[N].  On a 64-bit architecture, this allows for 5 elements in
m_len without having to use an extra word.  With this patch, m_len[]
would be smaller by one byte (4) before consuming the padding.  This
shouldn't be a problem as the only users of trailing_wide_ints use N=2
for NUM_POLY_INT_COEFFS in aarch64, and N=3 for range_info_def.

For irange, my plan is to use one more word to fit a maximum of 12
elements (the above 4 plus 8 more).  This would allow for 6 pairs of
sub-ranges which would be more than adequate for our needs.  In
previous tests we found that 99% of ranges fit within 3-4 pairs.  More
precisely, this would allow for 5 pairs, plus the nonzero bits, plus a
spare wide-int for future development.

Ultimately this means that streaming an irange would consume one more
word than what we currently do for range_info_def.  IMO this is a nice
trade-off considering we started storing a slew of wide-ints directly
;-).

Tested and benchmarked on x86-64 Linux.  There was no discernible
performance change in our benchmark suite.

gcc/ChangeLog:

* wide-int.h (struct trailing_wide_ints): Add m_num_elements.
(trailing_wide_ints::set_precision): Add num_elements argument.
(trailing_wide_ints::extra_size): Same.

2 years agolibstdc++: Add missing prerequisite to generated header [PR106162]
Jonathan Wakely [Fri, 1 Jul 2022 21:23:43 +0000 (22:23 +0100)]
libstdc++: Add missing prerequisite to generated header [PR106162]

The ${host_builddir}/largefile-config.h header can't be written until
its parent directory has been created, so it needs to have the creation
of that directory as a prerequisite.

libstdc++-v3/ChangeLog:

PR libstdc++/106162
* include/Makefile.am (largefile-config.h): Add
stamp-${host_alias} prerequisite.
* include/Makefile.in: Regenerate.

2 years agoc++: Minor cleanup in parser.cc
Lewis Hyatt [Fri, 1 Jul 2022 17:53:34 +0000 (13:53 -0400)]
c++: Minor cleanup in parser.cc

The code to determine whether a given token starts a module directive is
currently repeated in 4 places in parser.cc. I am about to submit a patch
that needs to add it in a 5th place, so since the code is not completely
trivial (needing to check for 3 different token types), it seems worthwhile
to factor this logic into its own function.

gcc/cp/ChangeLog:

* parser.cc (cp_token_is_module_directive): New function
refactoring common code.
(cp_parser_skip_to_closing_parenthesis_1): Use the new function.
(cp_parser_skip_to_end_of_statement): Likewise.
(cp_parser_skip_to_end_of_block_or_statement): Likewise.
(cp_parser_declaration): Likewise.

2 years agocompiler: rename "requires" to "needs"
Ian Lance Taylor [Fri, 1 Jul 2022 17:56:37 +0000 (10:56 -0700)]
compiler: rename "requires" to "needs"

As of C++20 "requires" is a C++ keyword.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/415754

2 years agoc++: fix broken copy elision with nested TARGET_EXPRs [PR105550]
Marek Polacek [Wed, 25 May 2022 22:11:31 +0000 (18:11 -0400)]
c++: fix broken copy elision with nested TARGET_EXPRs [PR105550]

In this problem, we are failing to properly perform copy elision with
a conditional operator, so this:

  constexpr A a = true ? A{} : A{};

fails with:

  error: 'A{((const A*)(&<anonymous>))}' is not a constant expression

The whole initializer is

  TARGET_EXPR <D.2395, 1 ? TARGET_EXPR <D.2393, {.p=(const struct A *) &<PLACEHOLDER_EXPR struct A>}> : TARGET_EXPR <D.2394, {.p=(const struct A *) &<PLACEHOLDER_EXPR struct A>}>>

where the outermost TARGET_EXPR is elided, but not the nested ones.
Then we end up replacing the PLACEHOLDER_EXPRs with the temporaries the
TARGET_EXPRs represent, which is precisely what should *not* happen with
copy elision.

I've tried the approach of tweaking ctx->object, but I ran into gazillion
problems with that.  I thought that I would let cxx_eval_constant_expression
/TARGET_EXPR create a new object only when ctx->object was null, then
adjust setting of ctx->object in places like cxx_bind_parameters_in_call
and cxx_eval_component_reference but that failed completely.  Sometimes
ctx->object has to be reset, sometimes it cannot be reset, 'this' needed
special handling, etc.  I gave up.

Instead, this patch strips TARGET_EXPRs from the operands of ?: like
we do in various other places in constexpr.c.

PR c++/105550

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_conditional_expression): Strip TARGET_EXPRs.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/nsdmi-aggr16.C: Remove FIXME.
* g++.dg/cpp1y/nsdmi-aggr17.C: Remove FIXME.
* g++.dg/cpp0x/constexpr-elision1.C: New test.
* g++.dg/cpp1y/constexpr-elision1.C: New test.

2 years agoOpenMP: Handle tofrom with target enter/exit data
Tobias Burnus [Fri, 1 Jul 2022 15:52:03 +0000 (17:52 +0200)]
OpenMP: Handle tofrom with target enter/exit data

In 5.2, a map clause can be map-entering or map-exiting,
either containing 'tofrom'. The main reason for this is
permit 'map(x)' with 'omp target enter/exit data',
avoiding to specify 'to:/from:' explicitly. (OpenMP
defaults to 'tofrom'.)

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_target_enter_data,
c_parser_omp_target_exit_data): Accept tofrom
map-type modifier but use 'to' / 'from' internally.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_omp_target_enter_data,
cp_parser_omp_target_exit_data): Accept tofrom
map-type modifier but use 'to' / 'from' internally.

gcc/fortran/ChangeLog:

* dump-parse-tree.cc (show_omp_namelist): For the map-type,
also handle the always modifer and release/delete.
* openmp.cc (resolve_omp_clauses): Accept tofrom
map-type modifier for target enter/exit data,
but use 'to' / 'from' internally.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.2): Mark target enter/exit data
with fromto as implemented.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/target-data-2.c: New test.
* c-c++-common/gomp/target-data-3.c: New test.
* gfortran.dg/gomp/target-data-1.f90: New test.
* gfortran.dg/gomp/target-data-2.f90: New test.

2 years agoi386: Use "r" constraint in *andn<mode>3_doubleword_bmi
Uros Bizjak [Fri, 1 Jul 2022 15:25:03 +0000 (17:25 +0200)]
i386: Use "r" constraint in *andn<mode>3_doubleword_bmi

ANDN is non-destructive, so use "r" instead of "0" for its operand 1 constraint.

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

gcc/ChangeLog:

* config/i386/i386.md (*andn<mode>3_doubleword_bmi):
Use "r" constraint for operand 1.

2 years agoc++: warn about using keywords as identifiers [PR106111]
Marek Polacek [Tue, 28 Jun 2022 22:59:19 +0000 (18:59 -0400)]
c++: warn about using keywords as identifiers [PR106111]

In C++03, -Wc++11-compat should warn about

  int constexpr;

since 'constexpr' is a keyword in C++11.  Jonathan reports that
we don't emit a similar warning for 'alignas' or 'alignof', and,
as I found out, 'thread_local'.

Similarly, we don't warn for most C++20 keywords.  That happens
because RID_LAST_CXX20 hasn't been updated in a while.

PR c++/106111

gcc/c-family/ChangeLog:

* c-common.h (enum rid): Update RID_LAST_CXX20.

gcc/cp/ChangeLog:

* parser.cc (cp_lexer_get_preprocessor_token): Also warn about
RID_ALIGNOF, RID_ALIGNAS, RID_THREAD.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/keywords1.C: New test.
* g++.dg/cpp2a/keywords1.C: New test.

2 years agoAdd a recursion limit to the demangle_const function in the Rust demangler.
Nick Clifton [Fri, 1 Jul 2022 14:58:52 +0000 (15:58 +0100)]
Add a recursion limit to the demangle_const function in the Rust demangler.

libiberty/
PR demangler/105039
* rust-demangle.c (demangle_const): Add recursion limit.

2 years agoc++: tweak resolve_args change
Jason Merrill [Fri, 1 Jul 2022 04:37:10 +0000 (00:37 -0400)]
c++: tweak resolve_args change

I don't know why I used tf_error instead of complain here.

PR c++/105779

gcc/cp/ChangeLog:

* call.cc (resolve_args): Use complain.

2 years agoc++: add fixup to missing .template warning
Jason Merrill [Wed, 29 Jun 2022 21:12:09 +0000 (17:12 -0400)]
c++: add fixup to missing .template warning

I experimented with giving this diagnostic in another place, which didn't
work out, but we can still benefit from adding the fixup.

gcc/cp/ChangeLog:

* parser.cc (missing_template_diag): Split out...
(cp_parser_id_expression): ...from here.

2 years agoc++: dependent generic lambda template-id [PR106024]
Jason Merrill [Fri, 24 Jun 2022 03:14:35 +0000 (23:14 -0400)]
c++: dependent generic lambda template-id [PR106024]

We were wrongly looking up the generic lambda op() in a dependent scope, and
then trying to look up its instantiation at substitution time, but lambdas
aren't instantiated, so we crashed.  The fix is to not look into dependent
class scopes.

But this created trouble with wrongly trying to use a template from the
enclosing scope when we aren't actually looking at a template-argument-list,
in template/lookup18.C, so let's avoid that.

PR c++/106024

gcc/cp/ChangeLog:

* parser.cc (missing_template_diag): Factor out...
(cp_parser_id_expression): ...from here.
(cp_parser_lookup_name): Don't look in dependent object_type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-generic10.C: New test.

2 years agoAvoid unused sbitmap in update_ssa
Richard Biener [Fri, 1 Jul 2022 11:59:32 +0000 (13:59 +0200)]
Avoid unused sbitmap in update_ssa

The following avoids copying and using blocks_to_update to
the interesting_blocks sbitmap when doing update_ssa as it is
unused besides the redundant query in the domwalk.

* tree-into-ssa.cc (rewrite_update_dom_walker::before_dom_children):
Do not look at interesting_blocks which is a copy of
blocks_to_update.
(update_ssa): Do not initialize it.
(pass_build_ssa::execute): Set interesting_blocks to NULL
after releasing it.

2 years agoRevert maybe_ne -> known_ne change in vn_reference_lookup_3
Richard Biener [Fri, 1 Jul 2022 11:16:33 +0000 (13:16 +0200)]
Revert maybe_ne -> known_ne change in vn_reference_lookup_3

This reverts the change as discussed.

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

* tree-ssa-sccvn.cc (vn_reference_lookup_3): Revert
back to using maybe_ne (off, -1).

2 years agoMake sure checking code is conditional in VN
Richard Biener [Fri, 1 Jul 2022 10:35:58 +0000 (12:35 +0200)]
Make sure checking code is conditional in VN

VN has checking code with gcc_unreachable (), the following makes
it cheaper by instead guarding the side-effect with flag_checking.

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

* tree-ssa-sccvn.cc (vn_nary_op_insert_into): Make
checking dominance check conditional on flag_checking.

2 years agolibstdc++: Add nodiscard attribute to filesystem operations
Jonathan Wakely [Fri, 1 Jul 2022 10:40:29 +0000 (11:40 +0100)]
libstdc++: Add nodiscard attribute to filesystem operations

Some of these are not truly "pure" because they access the file system,
e.g. exists and file_size, but they do not modify anything and are only
useful for the return value.

If you really want to use one of those functions just to check whether
an error is reported (either via an exception or an error_code&
argument) you can still do so, but you need to cast the discarded result
to void.  Several tests need such a change, because they were indeed
only calling the functions to check for expected errors.

libstdc++-v3/ChangeLog:

* include/bits/fs_ops.h: Add nodiscard to all pure functions.
* include/experimental/bits/fs_ops.h: Likewise.
* testsuite/27_io/filesystem/operations/all.cc: Do not discard
results of absolute and canonical.
* testsuite/27_io/filesystem/operations/absolute.cc: Cast
discarded result to void.
* testsuite/27_io/filesystem/operations/canonical.cc: Likewise.
* testsuite/27_io/filesystem/operations/exists.cc: Likewise.
* testsuite/27_io/filesystem/operations/is_empty.cc: Likewise.
* testsuite/27_io/filesystem/operations/read_symlink.cc:
Likewise.
* testsuite/27_io/filesystem/operations/status.cc: Likewise.
* testsuite/27_io/filesystem/operations/symlink_status.cc:
Likewise.
* testsuite/27_io/filesystem/operations/temp_directory_path.cc:
Likewise.
* testsuite/experimental/filesystem/operations/canonical.cc:
Likewise.
* testsuite/experimental/filesystem/operations/exists.cc:
Likewise.
* testsuite/experimental/filesystem/operations/is_empty.cc:
Likewise.
* testsuite/experimental/filesystem/operations/read_symlink.cc:
Likewise.
* testsuite/experimental/filesystem/operations/temp_directory_path.cc:
Likewise.

2 years agogcn: Remove useless register keyword
Tobias Burnus [Fri, 1 Jul 2022 10:21:24 +0000 (12:21 +0200)]
gcn: Remove useless register keyword

gcc/ChangeLog:

* config/gcn/gcn-protos.h (print_operand_address): Remove register
keyword on 'rtx addr' argument.

2 years ago[Committed] Add constraints to new andn<dwi>_doubleword_bmi pattern in i386.md.
Roger Sayle [Fri, 1 Jul 2022 10:14:12 +0000 (11:14 +0100)]
[Committed] Add constraints to new andn<dwi>_doubleword_bmi pattern in i386.md.

Many thanks to Uros for spotting that I'd forgotten to add constraints
to the new define_insn_and_split *andn<dwi>_doubleword_bmi when moving it
from pre-reload to post-reload.  I've pushed this obvious fix after a
make bootstrap on x86_64-pc-linux-gnu.  Sorry for the inconvenience to
anyone building the tree with a non-default architecture that enables
BMI.

2022-07-01  Roger Sayle  <roger@nextmovesoftware.com>
    Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog
* config/i386/i386.md (*andn<mode>3_doubleword_bmi): Add constraints
to post-reload define_insn_and_split.

2 years agoEnable some features for RTEMS in libstdc++
Sebastian Huber [Wed, 8 Jun 2022 06:44:36 +0000 (08:44 +0200)]
Enable some features for RTEMS in libstdc++

Remove RTEMS support from crossconfig.m4 since this code is not used due to
"with_newlib" being "yes".

libstdc++-v3/ChangeLog:

* configure: Regnerate.
* configure.ac (newlib, *-rtems*): Enable TLS support for all RTEMS
targets except bfin, lm32, mips, moxie, or1k, and v850.
For all RTEMS targets, define HAVE_ALIGNED_ALLOC, HAVE_AT_QUICK_EXIT,
HAVE_LINK, HAVE_POLL, HAVE_QUICK_EXIT, HAVE_READLINK, HAVE_SETENV,
HAVE_SLEEP, HAVE_SOCKATMARK, HAVE_STRERROR_L, HAVE_SYMLINK,
HAVE_TRUNCATE, and HAVE_USLEEP.
* crossconfig.m4 (*-rtems*): Remove.

2 years agoRevert "testsuite/102690: Only check warning for lp64 in Warray-bounds-16.C"
Kito Cheng [Fri, 1 Jul 2022 09:55:55 +0000 (17:55 +0800)]
Revert "testsuite/102690: Only check warning for lp64 in Warray-bounds-16.C"

This reverts commit 0f6eef398045deb2a62d18b526831719c7c20c8a.

2 years agowide-int: Fix up wi::shifted_mask [PR106144]
Jakub Jelinek [Fri, 1 Jul 2022 09:17:41 +0000 (11:17 +0200)]
wide-int: Fix up wi::shifted_mask [PR106144]

As the following self-test testcase shows, wi::shifted_mask sometimes
doesn't create canonicalized wide_ints, which then fail to compare equal
to canonicalized wide_ints with the same value.
In particular, wi::mask (128, false, 128) gives { -1 } with len 1 and prec 128,
while wi::shifted_mask (0, 128, false, 128) gives { -1, -1 } with len 2
and prec 128.
The problem is that the code is written with the assumption that there are
3 bit blocks (or 2 if start is 0), but doesn't consider the possibility
where there are 2 bit blocks (or 1 if start is 0) where the highest block
isn't present.  In that case, there is the optional block of negate ? 0 : -1
elts, followed by just one elt (either one from the if (shift) or just
negate ? -1 : 0) and the rest is implicit sign-extension.
Only if end < prec there is 1 or more bits above it that have different bit
value and so we need to emit all the elts till end and then one more elt.

if (end == prec) would work too, because we have:
  if (width > prec - start)
    width = prec - start;
  unsigned int end = start + width;
so end is guaranteed to be end <= prec, dunno what is preferred.

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

PR middle-end/106144
* wide-int.cc (wi::shifted_mask): If end >= prec, return right after
emitting element for shift or if shift is 0 first element after start.
(wide_int_cc_tests): Add tests for equivalency of wi::mask and
wi::shifted_mask with 0 start.

2 years agoPR target/106122: Don't update %esp via the stack with -Oz on x86.
Roger Sayle [Fri, 1 Jul 2022 08:18:07 +0000 (09:18 +0100)]
PR target/106122: Don't update %esp via the stack with -Oz on x86.

When optimizing for size with -Oz, setting a register can be minimized by
pushing an immediate value to the stack and popping it to the destination.
Alas the one general register that shouldn't be updated via the stack is
the stack pointer itself, where "pop %esp" can't be represented in GCC's
RTL ("use of a register mentioned in pre_inc, pre_dec, post_inc or
post_dec is not permitted within the same instruction").  This patch
fixes PR target/106122 by explicitly checking for SP_REG in the
problematic peephole2.

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

gcc/ChangeLog
PR target/106122
* config/i386/i386.md (peephole2): Avoid generating pop %esp
when optimizing for size.

gcc/testsuite/ChangeLog
PR target/106122
* gcc.target/i386/pr106122.c: New test case.

2 years agoDouble word logical operation clean-ups in i386.md.
Roger Sayle [Fri, 1 Jul 2022 08:13:17 +0000 (09:13 +0100)]
Double word logical operation clean-ups in i386.md.

This patch tidies up and unifies doubleword handling in i386.md;
converting all doubleword splitters for logic operations to post-reload
form, generalizing their define_insn_and_split templates to <dwi> form
(supporting TARGET_64BIT ? TImode : DImode), and where required tweaking
the corresponding expanders to use SDWIM to support TImode doubleword
operations.

2022-07-01  Roger Sayle  <roger@nextmovesoftware.com>
    Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog
* config/i386/i386.md (general_szext_operand): Add TImode
support using x86_64_hilo_general_operand predicate.
(*cmp<dwi>_doubleword): Use x86_64_hilo_general_operand predicate.
(*add<dwi>3_doubleword): Improved optimization of zero addition.
(and<mode>3): Use SDWIM mode iterator to add support for double
word bit-wise AND in TImode.  Use force_reg when double word
immediate operand isn't x86_64_hilo_general_operand.
(and<dwi>3_doubleword): Generalized from anddi3_doubleword and
converted into a post-reload splitter.
(*andndi3_doubleword): Previous define_insn deleted.
(*andn<mode>3_doubleword_bmi): New define_insn_and_split for
TARGET_BMI that splits post-reload.
(*andn<mode>3_doubleword): New define_insn_and_split for
!TARGET_BMI, that lowers/splits before reload.
(<any_or><mode>3): Use SDWIM mode iterator to add suppport for
double word bit-wise XOR and bit-wise IOR in TImode.  Use
force_reg when double word immediate operand isn't
x86_64_hilo_general_operand.
(*<any_or>di3_doubleword): Generalized from <any_or>di3_doubleword.
(one_cmpl<mode>2): Use SDWIM mode iterator to add support for
double word bit-wise NOT in TImode.
(one_cmpl<dwi>2_doubleword): Generalize from one_cmpldi2_doubleword
and converted into a post-reload splitter.

2 years agoAmend fix for PR middle-end/105874
Eric Botcazou [Fri, 1 Jul 2022 07:59:05 +0000 (09:59 +0200)]
Amend fix for PR middle-end/105874

The original fix is very likely too big a hammer.

gcc/
PR middle-end/105874
* expr.cc (expand_expr_real_1) <normal_inner_ref>: Force
EXPAND_MEMORY for the expansion of the inner reference only
in the usual cases where a memory reference is required.

2 years agolto: pass -pthread to AM_LDFLAGS [PR 106118]
Pekka Seppänen [Tue, 28 Jun 2022 14:14:09 +0000 (17:14 +0300)]
lto: pass -pthread to AM_LDFLAGS [PR 106118]

Move -pthread from configure.ac to Makefile.in so that it is passed to AM_LDFLAGS.

PR lto/106118

lto-plugin/ChangeLog:

* configure.ac: Move -pthread from here...
* Makefile.am: ...to here.
* configure: Regenerate.
* Makefile.in: Likewise.

2 years agotree-optimization/106131 - wrong code with FRE rewriting
Richard Biener [Thu, 30 Jun 2022 08:33:40 +0000 (10:33 +0200)]
tree-optimization/106131 - wrong code with FRE rewriting

The following makes sure to not use the original TBAA type for
looking up a value across an aggregate copy when we had to offset
the read.

2022-06-30  Richard Biener  <rguenther@suse.de>

PR tree-optimization/106131
* tree-ssa-sccvn.cc (vn_reference_lookup_3): Force alias-set
zero when offsetting the read looking through an aggregate
copy.

* g++.dg/torture/pr106131.C: New testcase.

2 years agoif-to-switch: properly allow side effects only for first condition
Martin Liska [Thu, 30 Jun 2022 13:00:17 +0000 (15:00 +0200)]
if-to-switch: properly allow side effects only for first condition

Properly allow side effects only for a first BB in a condition chain.

PR tree-optimization/106126

gcc/ChangeLog:

* gimple-if-to-switch.cc (struct condition_info): Save
has_side_effect.
(find_conditions): Parse all BBs.
(pass_if_to_switch::execute): Allow only side effects for first
BB.

gcc/testsuite/ChangeLog:

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

2 years agoi386: Add AVX512BW to AVX512F in MASK_ISA2
Haochen Jiang [Wed, 29 Jun 2022 02:38:34 +0000 (10:38 +0800)]
i386: Add AVX512BW to AVX512F in MASK_ISA2

gcc/ChangeLog:

* common/config/i386/i386-common.cc (OPTION_MASK_ISA2_AVX512F_UNSET):
Add OPTION_MASK_ISA2_AVX512BW_UNSET, remove
OPTION_MASK_ISA2_AVX512BF16_UNSET and
OPTION_MASK_ISA2_AVX512FP16_UNSET.

2 years agoAdd myself for write after approval
Haochen Jiang [Fri, 1 Jul 2022 01:58:13 +0000 (09:58 +0800)]
Add myself for write after approval

ChangeLog:

* MAINTAINERS (Write After Approval): Add myself.

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

2 years agolibgo: handle stat st_atim32 field and SYS_SECCOMP
Ian Lance Taylor [Wed, 29 Jun 2022 22:32:04 +0000 (15:32 -0700)]
libgo: handle stat st_atim32 field and SYS_SECCOMP

Patches for musl support, from Sören Tempel.

Fixes PR go/105225

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/415294

2 years agoFortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243]
Harald Anlauf [Wed, 29 Jun 2022 19:36:17 +0000 (21:36 +0200)]
Fortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243]

gcc/fortran/ChangeLog:

PR fortran/103137
PR fortran/103138
PR fortran/103693
PR fortran/105243
* decl.cc (gfc_match_data_decl): Reject CLASS entity declaration
when it is given the PARAMETER attribute.

gcc/testsuite/ChangeLog:

PR fortran/103137
PR fortran/103138
PR fortran/103693
PR fortran/105243
* gfortran.dg/class_58.f90: Fix test.
* gfortran.dg/class_73.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
2 years agoc-family: Add <time.h> names to diagnostics for known headers
Jonathan Wakely [Wed, 29 Jun 2022 22:41:46 +0000 (23:41 +0100)]
c-family: Add <time.h> names to diagnostics for known headers

gcc/c-family/ChangeLog:

* known-headers.cc (get_stdlib_header_for_name): Add <time.h>
names.

gcc/testsuite/ChangeLog:

* g++.dg/spellcheck-stdlib.C: Check <ctime> types and functions.

2 years agolto: Fix option merging [PR106129]
Joseph Myers [Thu, 30 Jun 2022 16:41:40 +0000 (16:41 +0000)]
lto: Fix option merging [PR106129]

The LTO merging of options from different input files was broken by:

commit 227a2ecf663d69972b851f51f1934d18927b62cd
Author: Martin Liska <mliska@suse.cz>
Date:   Fri Mar 12 11:53:47 2021 +0100

    lto-wrapper: Use vec<cl_decoded_option> data type.

Previously, find_and_merge_options would merge options it read into
those in *opts. After this commit, options in *opts on entry to
find_and_merge_options are ignored; the only merging that takes place
is between multiple sets of options in the same input file that are
read in the same call to this function (not sure how that case can
occur at all). The effects include, for example, that if some objects
are built with PIC enabled and others with it disabled, and the last
LTO object processed has PIC enabled, the choice of PIC for the last
object will result in the whole program being built as PIC, when the
merging logic is intended to ensure that a mixture of PIC and non-PIC
objects results in the whole program being built as non-PIC.

Fix this with an extra argument to find_and_merge_options to determine
whether merging should take place.  This shows up a second issue with
that commit (which I think wasn't actually intended to change code
semantics at all): once merging is enabled again, the check for
-Xassembler options became an infinite loop in the case where both
inputs had -Xassembler options, with the same first option, so fix
that loop to restore the previous semantics.

Note that I'm not sure how LTO option merging might be tested in the
testsuite (clearly there wasn't sufficient, if any, coverage to detect
these bugs).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

PR lto/106129
* lto-wrapper.cc (find_option): Add argument start.
(merge_and_complain): Loop over existing_opt_index and
existing_opt2_index for Xassembler check.  Update calls to
find_option.
(find_and_merge_options): Add argument first to determine whether
to merge options with those passed in *opts.
(run_gcc): Update calls to find_and_merge_options.

2 years agolibstdc++: Fix comment typos
Jonathan Wakely [Thu, 30 Jun 2022 10:28:23 +0000 (11:28 +0100)]
libstdc++: Fix comment typos

libstdc++-v3/ChangeLog:

* include/bits/utility.h: Fix comment typos.

2 years agolibstdc++: Improve exceptions thrown from fs::temp_directory_path
Jonathan Wakely [Tue, 28 Jun 2022 15:09:21 +0000 (16:09 +0100)]
libstdc++: Improve exceptions thrown from fs::temp_directory_path

Currently the throwing overload of fs::temp_directory_path() will
discard the path that was obtained from the environment. When it fails
because the path doesn't resolve to a directory you get an unhelpful
error like:

  filesystem error: temp_directory_path: Not a directory

It would be better to also print the path in that case, e.g.

  filesystem error: temp_directory_path: Not a directory [/home/bob/tmp]

libstdc++-v3/ChangeLog:

* src/c++17/fs_ops.cc (fs::temp_directory_path()): Include path
in exception.
(fs::temp_directory_path(error_code&)): Rearrange to more
closely match the structure of the first overload.
* src/filesystem/ops.cc (fs::temp_directory_path): Likewise.
* testsuite/27_io/filesystem/operations/temp_directory_path.cc:
Check that exception contains the path.
* testsuite/experimental/filesystem/operations/temp_directory_path.cc:
Likewise.

2 years agolibstdc++: Fix experimental::filesystem::status on Windows [PR88881]
Jonathan Wakely [Tue, 28 Jun 2022 14:56:30 +0000 (15:56 +0100)]
libstdc++: Fix experimental::filesystem::status on Windows [PR88881]

Although the Filesystem TS isn't properly supported on Windows (unlike
the C++17 Filesystem lib), most tests do pass. Two of the failures are
due to PR 88881 which was only fixed for std::filesystem not the TS.
This applies the fix to the TS implementation too.

libstdc++-v3/ChangeLog:

PR libstdc++/88881
* src/filesystem/ops.cc (has_trailing_slash): New helper
function.
(fs::status): Strip trailing slashes.
(fs::symlink_status): Likewise.
* testsuite/experimental/filesystem/operations/temp_directory_path.cc:
Clean the environment before each test and use TMP instead of
TMPDIR so the test passes on Windows.

2 years agoImplement ggc_vrange_allocator.
Aldy Hernandez [Fri, 10 Jun 2022 13:02:51 +0000 (15:02 +0200)]
Implement ggc_vrange_allocator.

This patch makes the vrange_allocator an abstract class, and uses it
to implement the obstack allocator as well as a new GC allocator.

The GC bits will be used to implement the vrange storage class for
global ranges, which will be contributed in the next week or so.

Tested and benchmarked on x86-64 Linux.

gcc/ChangeLog:

* gimple-range-cache.cc (block_range_cache::block_range_cache):
Rename vrange_allocator to obstack_vrange_allocator.
(ssa_global_cache::ssa_global_cache): Same.
* gimple-range-edge.h (class gimple_outgoing_range): Same.
* gimple-range-infer.h (class infer_range_manager): Same.
* value-range.h (class vrange_allocator): Make abstract.
(class obstack_vrange_allocator): Inherit from vrange_allocator.
(class ggc_vrange_allocator): New.

2 years agoc++: Note macro locations
Nathan Sidwell [Mon, 27 Jun 2022 14:51:12 +0000 (07:51 -0700)]
c++: Note macro locations

In order to prune ordinary locations, we need to note the locations of
macros we'll be writing out.  This rearanges the macro processing to achieve
that.  Also drop an unneeded parameter from macro reading & writing.

Fix some it's/its errors.

gcc/cp/
* module.cc (module_state::write_define): Drop located param.
(module_state::read_define): Likewise.
(module_state::prepare_macros): New, broken out of ...
(module_state::write_macros): ... here.  Adjust.
(module_state::write_begin): Adjust.
gcc/testsuite/
* g++.dg/modules/inext-1.H: Check include-next happened.

2 years agoUse xchg for DImode double word rotate by 32 bits with -m32 on x86.
Roger Sayle [Thu, 30 Jun 2022 10:00:03 +0000 (11:00 +0100)]
Use xchg for DImode double word rotate by 32 bits with -m32 on x86.

This patch was motivated by the investigation of Linus Torvalds' spill
heavy cryptography kernels in PR 105930.  The <any_rotate>di3 expander
handles all rotations by an immediate constant for 1..63 bits with the
exception of 32 bits, which FAILs and is then split by the middle-end.
This patch makes these 32-bit doubleword rotations consistent with the
other DImode rotations during reload, which results in reduced register
pressure, fewer instructions and the use of x86's xchg instruction
when appropriate.  In theory, xchg can be handled by register renaming,
but even on micro-architectures where it's implemented by 3 uops (no
worse than a three instruction shuffle), avoiding nominating a
"temporary" register, reduces user-visible register pressure (and
has obvious code size benefits).

The effects are best shown with the new testcase:

unsigned long long bar();
unsigned long long foo()
{
  unsigned long long x = bar();
  return (x>>32) | (x<<32);
}

for which GCC with -m32 -O2 currently generates:

        subl    $12, %esp
        call    bar
        addl    $12, %esp
        movl    %eax, %ecx
        movl    %edx, %eax
        movl    %ecx, %edx
        ret

but with this patch now generates:

        subl    $12, %esp
        call    bar
        addl    $12, %esp
        xchgl   %edx, %eax
        ret

With this patch, the number of lines of assembly language generated
for the blake2b kernel (from the attachment to PR105930) decreases
from 5626 to 5404. Although there's an impressive reduction in
instruction count, there's no change/reduction in stack frame size.

2022-06-30  Roger Sayle  <roger@nextmovesoftware.com>
    Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog
* config/i386/i386.md (swap_mode): Rename from *swap<mode> to
provide gen_swapsi.
(<any_rotate>di3): Handle !TARGET_64BIT rotations by 32 bits
via new gen_<insn>32di2_doubleword below.
(<anyrotate>32di2_doubleword): New define_insn_and_split
that splits after reload as either a pair of move instructions
or an xchgl (using gen_swapsi).

gcc/testsuite/ChangeLog
* gcc.target/i386/xchg-3.c: New test case.

2 years agoAvoid computing RPO for update_ssa
Richard Biener [Wed, 29 Jun 2022 12:55:43 +0000 (14:55 +0200)]
Avoid computing RPO for update_ssa

At some point when domwalk got the ability to use RPO for ordering
dominator children we carefully avoided update_ssa eating the cost
of RPO compute.  Unfortunately some later consolidation of CTORs
lost this again so the following makes this explicit via a special
value to the bb_index_to_rpo argument of domwalk, speeding up
update_ssa again.

* domwalk.h (dom_walker::dom_walker): Update comment to
reflect reality and new special argument value for
bb_index_to_rpo.
* domwalk.cc (dom_walker::dom_walker): Recognize -1
bb_index_to_rpo.
* tree-into-ssa.cc
(rewrite_update_dom_walker::rewrite_update_dom_walker): Tell
dom_walker to not use RPO.

This page took 0.116236 seconds and 5 git commands to generate.