platform/upstream/gcc.git
2 years ago[Ada] Handle case-expression inside if-expression in -gnato2
Etienne Servais [Tue, 8 Mar 2022 13:49:55 +0000 (14:49 +0100)]
[Ada] Handle case-expression inside if-expression in -gnato2

gcc/ada/

* checks.adb (Apply_Arithmetic_Overflow_Minimized_Eliminated):
Fix condition to return.

2 years ago[Ada] Update comment justifying non-inlining for proof inside generics
Yannick Moy [Fri, 11 Mar 2022 11:55:16 +0000 (12:55 +0100)]
[Ada] Update comment justifying non-inlining for proof inside generics

gcc/ada/

* inline.adb (Can_Be_Inlined_In_GNATprove_Mode): Update comment.

2 years ago[Ada] Fix iterated element association loop var escaping loop scope
Marc Poulhiès [Mon, 7 Mar 2022 13:02:13 +0000 (14:02 +0100)]
[Ada] Fix iterated element association loop var escaping loop scope

Fix the escaping of the loop variable from the loop scope in both forms
of iterated element associations (i.e. "for J in ..." and "for J of
..."). Create a dedicated scope around the analyses of both loops. Also
create a copy of the Loop_Parameter_Specification instead of analyzing
(and modifying) the original Tree as it will be reanalyzed later.

gcc/ada/

* sem_aggr.adb (Resolve_Iterated_Association): Create scope
around N_Iterated_Element_Association handling. Analyze a copy
of the Loop_Parameter_Specification. Call Analyze instead
Analyze_* to be more homogeneous.
(Sem_Ch5): Remove now unused package.

2 years ago[Ada] Fix internal error on iterated array aggregate
Eric Botcazou [Wed, 9 Mar 2022 23:31:11 +0000 (00:31 +0100)]
[Ada] Fix internal error on iterated array aggregate

The front-end drops the declaration of a temporary on the floor because
Insert_Actions fails to climb up out of an N_Iterated_Component_Association
when the temporary is created during the analysis of its Discrete_Choices.

gcc/ada/

* exp_util.adb (Insert_Actions) <N_Iterated_Component_Association>:
Climb up out of the node if the actions come from Discrete_Choices.

2 years ago[Ada] Accept calls to abstract subprograms in class-wide pre/post-conditions
Javier Miranda [Tue, 8 Mar 2022 22:55:16 +0000 (14:55 -0800)]
[Ada] Accept calls to abstract subprograms in class-wide pre/post-conditions

Fix a regression in the support for Ada 2022's treatment of calls to
abstract subprograms in pre/post-conditions (thanks to Javier Miranda
for producing this patch).

gcc/ada/

* sem_disp.adb (Check_Dispatching_Context): When checking to see
whether an expression occurs in a class-wide pre/post-condition,
also check for the possibility that it occurs in a class-wide
preconditions subprogram that was introduced as part of
expansion. Without this fix, some legal calls occuring in
class-wide preconditions may be incorrectly flagged as violating
the "a call to an abstract subprogram must be dispatching" rule.

2 years ago[Ada] Fix internal error on mix of controlled and protected types
Eric Botcazou [Thu, 10 Mar 2022 10:11:32 +0000 (11:11 +0100)]
[Ada] Fix internal error on mix of controlled and protected types

The key is that the protected type is a (limited) private type, which
fools a test in Cleanup_Scopes.

gcc/ada/

* inline.adb (Cleanup_Scopes): Test the underlying type.

2 years ago[Ada] Fix internal error on predicate aspect with iterator
Eric Botcazou [Wed, 9 Mar 2022 19:47:00 +0000 (20:47 +0100)]
[Ada] Fix internal error on predicate aspect with iterator

The semantic analysis of predicates involves a fair amount of tree
copying because of both semantic and implementation considerations, and
there is a difficulty with quantified expressions since they declare a
new entity that cannot be shared between the various copies of the tree.

This change implements a specific processing for it in New_Copy_Tree
that subsumes a couple of fixes made earlier for variants of the issue.

gcc/ada/

* sem_util.ads (Is_Entity_Of_Quantified_Expression): Declare.
* sem_util.adb (Is_Entity_Of_Quantified_Expression): New
predicate.
(New_Copy_Tree): Deal with all entities of quantified
expressions.
* sem_ch13.adb (Build_Predicate_Functions): Get rid of
superfluous tree copying and remove obsolete code.
* sem_ch6.adb (Fully_Conformant_Expressions): Deal with all
entities of quantified expressions.

2 years ago[Ada] Implement component finalization ordering rules for type extensions
Steve Baird [Thu, 3 Mar 2022 22:35:31 +0000 (14:35 -0800)]
[Ada] Implement component finalization ordering rules for type extensions

Finalization of a record object is required to finalize any components
that have an access discriminant constrained by a per-object expression
before other components. This includes the case of a type extension;
"early finalization" components of the parent type are required to be
finalized before non-early-finalization extension components. This is
implemented in the extension type's finalization procedure by placing
the call to the parent type's finalization procedure between the
finalization of the "early finalization" extension components and the
finalization of the other extension components. Previously that call was
executed after finalizing all of the extension conponents.

gcc/ada/

* exp_ch7.adb (Build_Finalize_Statements): Add Last_POC_Call
variable to keep track of the last "early finalization" call
generated for type extension's finalization procedure. If
non-empty, then this will indicate the point at which to insert
the call to the parent type's finalization procedure. Modify
nested function Process_Component_List_For_Finalize to set this
variable (and avoid setting it during a recursive call).  If
Last_POC_Call is empty, then insert the parent finalization call
before, rather than after, the finalization code for the
extension components.

2 years ago[Ada] Fix implementation issues with equality for untagged record types
Eric Botcazou [Mon, 28 Feb 2022 14:27:27 +0000 (15:27 +0100)]
[Ada] Fix implementation issues with equality for untagged record types

This moves the implementation of AI12-0101 + AI05-0123 from the expander
to the semantic analyzer and completes the implementation of AI12-0413,
which are both binding interpretations in Ada 2012, fixing a few bugs in
the process and removing a fair amount of duplicated code throughout.

gcc/ada/

* einfo-utils.adb (Remove_Entity): Fix couple of oversights.
* exp_ch3.adb (Is_User_Defined_Equality): Delete.
(User_Defined_Eq): Call Get_User_Defined_Equality.
(Make_Eq_Body): Likewise.
(Predefined_Primitive_Eq_Body): Call Is_User_Defined_Equality.
* exp_ch4.adb (Build_Eq_Call): Call Get_User_Defined_Equality.
(Is_Equality): Delete.
(User_Defined_Primitive_Equality_Op): Likewise.
(Find_Aliased_Equality): Call Is_User_Defined_Equality.
(Expand_N_Op_Eq): Call Underlying_Type unconditionally.
Do not implement AI12-0101 + AI05-0123 here.
(Expand_Set_Membership): Call Resolve_Membership_Equality.
* exp_ch6.adb (Expand_Call_Helper): Remove obsolete code.
* sem_aux.ads (Is_Record_Or_Limited_Type): Delete.
* sem_aux.adb (Is_Record_Or_Limited_Type): Likewise.
* sem_ch4.ads (Nondispatching_Call_To_Abstract_Operation): Declare.
* sem_ch4.adb (Analyze_Call): Call Call_Abstract_Operation.
(Analyze_Membership_Op): Call Resolve_Membership_Equality.
(Nondispatching_Call_To_Abstract_Operation): New procedure.
(Remove_Abstract_Operations): Call it.
* sem_ch6.adb (Check_Untagged_Equality): Remove obsolete error and
call Is_User_Defined_Equality.
* sem_ch7.adb (Inspect_Untagged_Record_Completion): New procedure
implementing AI12-0101 + AI05-0123.
(Analyze_Package_Specification): Call it.
(Declare_Inherited_Private_Subprograms): Minor tweak.
(Uninstall_Declarations): Likewise.
* sem_disp.adb (Check_Direct_Call): Adjust to new implementation
of Is_User_Defined_Equality.
* sem_res.ads (Resolve_Membership_Equality): Declare.
* sem_res.adb (Resolve): Replace direct error handling with call to
Nondispatching_Call_To_Abstract_Operation
(Resolve_Call): Likewise.
(Resolve_Equality_Op): Likewise.  mplement AI12-0413.
(Resolve_Membership_Equality): New procedure.
(Resolve_Membership_Op): Call Get_User_Defined_Equality.
* sem_util.ads (Get_User_Defined_Eq): Rename into...
(Get_User_Defined_Equality): ...this.
* sem_util.adb (Get_User_Defined_Eq): Rename into...
(Get_User_Defined_Equality): ...this. Call Is_User_Defined_Equality.
(Is_User_Defined_Equality): Also check the profile but remove tests
on Comes_From_Source and Parent.
* sinfo.ads (Generic_Parent_Type): Adjust field description.
* uintp.ads (Ubool): Invoke user-defined equality in predicate.

2 years ago[Ada] Remove duplicated detection of user-defined equality
Piotr Trojanek [Tue, 8 Mar 2022 16:46:26 +0000 (17:46 +0100)]
[Ada] Remove duplicated detection of user-defined equality

Cleanup related to handling of user-defined equality in GNATprove.

gcc/ada/

* exp_ch3.adb (User_Defined_Eq): Replace duplicated code with a
call to Get_User_Defined_Eq.

2 years ago[Ada] Improve building of untagged equality
Piotr Trojanek [Tue, 8 Mar 2022 16:37:29 +0000 (17:37 +0100)]
[Ada] Improve building of untagged equality

When checking components of a record type for their own user-defined
equality function it is enough to find just one such a component.

Cleanup related to handling of user-defined equality in GNATprove.

gcc/ada/

* exp_ch3.adb (Build_Untagged_Equality): Exit early when the
outcome of a loop is already known.

2 years ago[Ada] Map gnatlib-shared to gnatlib-shared-dual for aarch64-vx7r2
Olivier Hainque [Fri, 18 Feb 2022 22:57:42 +0000 (22:57 +0000)]
[Ada] Map gnatlib-shared to gnatlib-shared-dual for aarch64-vx7r2

This is an incremental change towards supporting shared libraries
for VxWorks on aarch64.

The aarch64-vx7r2 compiler supports compilation with -fpic/PIC.  This
change adds aarch64 to the list of CPUs for which GNATLIB_SHARED maps to
gnatlib-shared-dual for vxworks7r2, so "make gnatlib-shared" actually
builds a shared lib.

While other adjustments will be needed to get the runtime tests to pass,
this one is a necessary step and doesn't impair the rest.

gcc/ada/

* Makefile.rtl: Add aarch64 to the list of CPUs for which
GNATLIB_SHARED maps to gnatlib-shared-dual for vxworks7r2.

2 years ago[Ada] Couple of small consistency tweaks
Eric Botcazou [Tue, 8 Mar 2022 07:52:10 +0000 (08:52 +0100)]
[Ada] Couple of small consistency tweaks

This aligns Analyze_Negation and Analyze_Unary_Op with the other similar
procedures in Sem_Ch4.  No functional changes.

gcc/ada/

* sem_ch4.adb (Analyze_Negation): Minor tweak.
(Analyze_Unary_Op): Likewise.

2 years ago[Ada] Fix spurious error on limited view with incomplete type
Eric Botcazou [Thu, 3 Mar 2022 14:57:47 +0000 (15:57 +0100)]
[Ada] Fix spurious error on limited view with incomplete type

The problem is that Install_Limited_With_Clause does not fully implement
AI05-0129, in the case where a regular with clause is processed before a
limited_with clause of the same package: the visible "shadow" entity is
that of the incomplete type, instead of that of the full type per the AI.

This requires adjusting Remove_Limited_With_Unit to match the change in
Install_Limited_With_Clause and also Build_Incomplete_Type_Declaration,
which is responsible for synthesizing incomplete types out of full type
declarations for self-referential types.

A small tweak is also needed in Analyze_Subprogram_Body_Helper to align
it with an equivalent processing for CW types in Find_Type_Name. And the
patch also changes the Incomplete_View field in full type declarations
to point to the entity of the view instead of its declaration.

gcc/ada/

* exp_ch3.adb (Build_Assignment): Adjust to the new definition of
Incomplete_View field.
* sem_ch10.ads (Decorate_Type): Declare.
* sem_ch10.adb (Decorate_Type): Move to library level.
(Install_Limited_With_Clause): In the already analyzed case, also
deal with incomplete type declarations present in the sources and
simplify the replacement code.
(Build_Shadow_Entity): Deal with swapped views in package body.
(Restore_Chain_For_Shadow): Deal with incomplete type declarations
present in the sources.
* sem_ch3.adb (Analyze_Full_Type_Declaration): Adjust to the new
definition of Incomplete_View field.
(Build_Incomplete_Type_Declaration): Small consistency tweak.
Set the incomplete type as the Incomplete_View of the full type.
If the scope is a package with a limited view, build a shadow
entity for the incomplete type.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): When replacing
the limited view of a CW type as designated type of an anonymous
access return type, get to the CW type of the incomplete view of
the tagged type, if any.
(Collect_Primitive_Operations): Adjust to the new definition of
Incomplete_View field.
* sinfo.ads (Incomplete_View): Denote the entity itself instead
of its declaration.
* sem_util.adb: Remove call to Defining_Entity.

2 years ago[Ada] Pick volatile refinement property of a subtype from its base type
Piotr Trojanek [Mon, 7 Mar 2022 14:27:06 +0000 (15:27 +0100)]
[Ada] Pick volatile refinement property of a subtype from its base type

Volatile refinement properties (e.g. Async_Writers), which refine the
Volatile aspect in SPARK, are inherited by subtypes from their base
types. In particular, this patch fixes handling of those properties for
subtypes of private types.

gcc/ada/

* sem_util.adb (Type_Or_Variable_Has_Enabled_Property): Given a
subtype recurse into its base type.

2 years ago[Ada] Clarify code for detecting volatile refinement properties
Piotr Trojanek [Mon, 7 Mar 2022 13:07:15 +0000 (14:07 +0100)]
[Ada] Clarify code for detecting volatile refinement properties

Routine Type_Or_Variable_Has_Enabled_Property handles either types or
objects; replace negation with an explicit positive condition.

Cleanup related to handling of volatile refinement aspects in SPARK;
behaviour is unaffected.

gcc/ada/

* sem_util.adb (Type_Or_Variable_Has_Enabled_Property): Clarify.

2 years ago[Ada] Remove duplicated code for detecting enabled pragmas
Piotr Trojanek [Fri, 4 Mar 2022 16:46:30 +0000 (17:46 +0100)]
[Ada] Remove duplicated code for detecting enabled pragmas

Routines Is_Enabled and Is_Enabled_Pragma are identical (except for
comments); remove this duplication.

Cleanup related to handling of volatile refinement aspects in SPARK;
behaviour is unaffected.

gcc/ada/

* sem_util.adb (Is_Enabled): Remove; use Is_Enabled_Pragma
instead.

2 years agoUse more ARRAY_SIZE.
Martin Liska [Thu, 13 Jan 2022 17:46:26 +0000 (18:46 +0100)]
Use more ARRAY_SIZE.

gcc/ada/ChangeLog:

* locales.c (iso_639_1_to_639_3): Use ARRAY_SIZE.
(language_name_to_639_3): Likewise.
(country_name_to_3166): Likewise.

gcc/analyzer/ChangeLog:

* engine.cc (exploded_node::get_dot_fillcolor): Use ARRAY_SIZE.
* function-set.cc (test_stdio_example): Likewise.
* sm-file.cc (get_file_using_fns): Likewise.
* sm-malloc.cc (malloc_state_machine::unaffected_by_call_p): Likewise.
* sm-signal.cc (get_async_signal_unsafe_fns): Likewise.

gcc/ChangeLog:

* attribs.cc (diag_attr_exclusions): Use ARRAY_SIZE.
(decls_mismatched_attributes): Likewise.
* builtins.cc (c_strlen): Likewise.
* cfg.cc (DEF_BASIC_BLOCK_FLAG): Likewise.
* common/config/aarch64/aarch64-common.cc (aarch64_option_init_struct): Likewise.
* config/aarch64/aarch64-builtins.cc (aarch64_lookup_simd_builtin_type): Likewise.
(aarch64_init_simd_builtin_types): Likewise.
(aarch64_init_builtin_rsqrt): Likewise.
* config/aarch64/aarch64.cc (is_madd_op): Likewise.
* config/arm/arm-builtins.cc (arm_lookup_simd_builtin_type): Likewise.
(arm_init_simd_builtin_types): Likewise.
* config/avr/gen-avr-mmcu-texi.cc (mcus[ARRAY_SIZE): Likewise.
(c_prefix): Likewise.
(main): Likewise.
* config/c6x/c6x.cc (N_SAVE_ORDER): Likewise.
* config/darwin-c.cc (darwin_register_frameworks): Likewise.
* config/gcn/mkoffload.cc (process_obj): Likewise.
* config/i386/i386-builtins.cc (get_builtin_code_for_version): Likewise.
(fold_builtin_cpu): Likewise.
* config/m32c/m32c.cc (PUSHM_N): Likewise.
* config/nvptx/mkoffload.cc (process): Likewise.
* config/rs6000/driver-rs6000.cc (host_detect_local_cpu): Likewise.
* config/s390/s390.cc (NR_C_MODES): Likewise.
* config/tilepro/gen-mul-tables.cc (find_sequences): Likewise.
(create_insn_code_compression_table): Likewise.
* config/vms/vms.cc (NBR_CRTL_NAMES): Likewise.
* diagnostic-format-json.cc (json_from_expanded_location): Likewise.
* dwarf2out.cc (ARRAY_SIZE): Likewise.
* genhooks.cc (emit_documentation): Likewise.
(emit_init_macros): Likewise.
* gimple-ssa-sprintf.cc (format_floating): Likewise.
* gimple-ssa-warn-access.cc (memmodel_name): Likewise.
* godump.cc (keyword_hash_init): Likewise.
* hash-table.cc (hash_table_higher_prime_index): Likewise.
* input.cc (for_each_line_table_case): Likewise.
* ipa-free-lang-data.cc (free_lang_data): Likewise.
* ipa-inline.cc (sanitize_attrs_match_for_inline_p): Likewise.
* optc-save-gen.awk: Likewise.
* spellcheck.cc (test_metric_conditions): Likewise.
* tree-vect-slp-patterns.cc (sizeof): Likewise.
(ARRAY_SIZE): Likewise.
* tree.cc (build_common_tree_nodes): Likewise.

gcc/c-family/ChangeLog:

* c-common.cc (ARRAY_SIZE): Use ARRAY_SIZE.
(c_common_nodes_and_builtins): Likewise.
* c-format.cc (check_tokens): Likewise.
(check_plain): Likewise.
* c-pragma.cc (c_pp_lookup_pragma): Likewise.
(init_pragma): Likewise.
* known-headers.cc (get_string_macro_hint): Likewise.
(get_stdlib_header_for_name): Likewise.
* c-attribs.cc: Likewise.

gcc/c/ChangeLog:

* c-decl.cc (match_builtin_function_types): Use ARRAY_SIZE.

gcc/cp/ChangeLog:

* module.cc (depset::entity_kind_name): Use ARRAY_SIZE.
* name-lookup.cc (get_std_name_hint): Likewise.
* parser.cc (cp_parser_new): Likewise.

gcc/fortran/ChangeLog:

* frontend-passes.cc (gfc_code_walker): Use ARRAY_SIZE.
* openmp.cc (gfc_match_omp_context_selector_specification): Likewise.
* trans-intrinsic.cc (conv_intrinsic_ieee_builtin): Likewise.
* trans-types.cc (gfc_get_array_descr_info): Likewise.

gcc/jit/ChangeLog:

* jit-builtins.cc (find_builtin_by_name): Use ARRAY_SIZE.
(get_string_for_type_id): Likewise.
* jit-recording.cc (recording::context::context): Likewise.

gcc/lto/ChangeLog:

* lto-common.cc (lto_resolution_read): Use ARRAY_SIZE.
* lto-lang.cc (lto_init): Likewise.

2 years agoOpenMP, C++: Add template support for the has_device_addr clause.
Marcel Vollweiler [Mon, 16 May 2022 08:02:50 +0000 (01:02 -0700)]
OpenMP, C++: Add template support for the has_device_addr clause.

This patch adds support for list items in the has_device_addr clause which type
is given by C++ template parameters.

gcc/cp/ChangeLog:

* pt.cc (tsubst_omp_clauses): Added OMP_CLAUSE_HAS_DEVICE_ADDR.
* semantics.cc (finish_omp_clauses): Added template decl processing.

libgomp/ChangeLog:

* testsuite/libgomp.c++/target-has-device-addr-7.C: New test.
* testsuite/libgomp.c++/target-has-device-addr-8.C: New test.
* testsuite/libgomp.c++/target-has-device-addr-9.C: New test.

2 years agoFix ubsan error in opts-global.cc
Martin Liska [Mon, 16 May 2022 07:48:27 +0000 (09:48 +0200)]
Fix ubsan error in opts-global.cc

Fixes:
opts-global.cc:75:15: runtime error: store to address 0x00000bc9be70 with insufficient space for an object of type 'char'
which happens when mask == 0, len == 0 and we allocate zero elements.
Eventually, result[0] is called which triggers the UBSAN.

gcc/ChangeLog:

* opts-global.cc (write_langs): Allocate at least one byte.

2 years agoAdd MIN/MAX folding from fold_cond_expr_with_comparison to match.pd
Richard Biener [Fri, 13 May 2022 07:35:30 +0000 (09:35 +0200)]
Add MIN/MAX folding from fold_cond_expr_with_comparison to match.pd

The following adds MIN/MAX folding from fold_cond_expr_with_comparison
to the part GIMPLE of match.pd, leaving the GENERIC part in
fold-const.cc since that's constrainted on frontend specific things
I did not want to carry to match.pd.

The effect becomes appearant when we no longer can rely on GENERIC
folding of COND_EXPRs in gcc.dg/tree-ssa/pr92834.c and
gcc.dg/tree-ssa/pr94786.c.

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

* match.pd (A cmp B ? A : B -> min/max): New patterns
carried over from fold_cond_expr_with_comparison.

2 years agoFix ICE caused by wrong condition.
liuhongt [Fri, 13 May 2022 07:48:01 +0000 (15:48 +0800)]
Fix ICE caused by wrong condition.

When d->perm[i] == d->perm[i-1] + 1 and d->perm[i] == nelt, it's not
continuous. It should fail if there's more than 2 continuous areas.

gcc/ChangeLog:

PR target/105587
* config/i386/i386-expand.cc
(expand_vec_perm_pslldq_psrldq_por): Fail when (d->perm[i] ==
d->perm[i-1] + 1) && d->perm[i] == nelt && start != -1.

gcc/testsuite/ChangeLog:

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

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

2 years agoi386: Remove constraints when used with constant integer predicates.
Uros Bizjak [Sun, 15 May 2022 20:07:46 +0000 (22:07 +0200)]
i386: Remove constraints when used with constant integer predicates.

const_int_operand and other const*_operand predicates do not need
constraints when the constraint is inherited from the range of
constant integer predicate.  Remove the constraint in case all
alternatives use the same inherited constraint.

2022-05-15  Uroš Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog:

* config/i386/i386.md: Remove constraints when used with
const_int_operand, const0_operand, const_1_operand, constm1_operand,
const8_operand, const128_operand, const248_operand, const123_operand,
const2367_operand, const1248_operand, const359_operand,
const_4_or_8_to_11_operand, const48_operand, const_0_to_1_operand,
const_0_to_3_operand, const_0_to_4_operand, const_0_to_5_operand,
const_0_to_7_operand, const_0_to_15_operand, const_0_to_31_operand,
const_0_to_63_operand, const_0_to_127_operand, const_0_to_255_operand,
const_0_to_255_mul_8_operand, const_1_to_31_operand,
const_1_to_63_operand, const_2_to_3_operand, const_4_to_5_operand,
const_4_to_7_operand, const_6_to_7_operand, const_8_to_9_operand,
const_8_to_11_operand, const_8_to_15_operand, const_10_to_11_operand,
const_12_to_13_operand, const_12_to_15_operand, const_14_to_15_operand,
const_16_to_19_operand, const_16_to_31_operand, const_20_to_23_operand,
const_24_to_27_operand and const_28_to_31_operand.
* config/i386/mmx.md: Ditto.
* config/i386/sse.md: Ditto.
* config/i386/subst.md: Ditto.
* config/i386/sync.md: Ditto.

2 years agoc++: hidden friend access [DR1699]
Jason Merrill [Sat, 19 Mar 2022 02:52:32 +0000 (22:52 -0400)]
c++: hidden friend access [DR1699]

It has come up several times that Clang considers hidden friends of a class
to be sufficiently memberly to be covered by a friend declaration naming the
class.  This is somewhat unclear in the standard: [class.friend] says
"Declaring a class to be a friend implies that private and protected members
of the class granting friendship can be named in the base-specifiers and
member declarations of the befriended class."

A hidden friend is a syntactic member-declaration, but is it a "member
declaration"?  CWG was ambivalent, and referred the question to EWG as a
design choice.  But recently Patrick mentioned that the current G++ choice
not to treat it as a "member declaration" was making his library work
significantly more cumbersome, so let's go ahead and vote the other way.

This means that the testcases for 100502 and 58993 are now accepted.

DR1699
PR c++/100502
PR c++/58993

gcc/cp/ChangeLog:

* friend.cc (is_friend): Hidden friends count as members.
* search.cc (friend_accessible_p): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/template/access37.C: Now OK.
* g++.dg/template/friend69.C: Now OK.
* g++.dg/lookup/friend23.C: New test.

2 years agoc++: parsing injected-class-name as template
Jason Merrill [Fri, 13 May 2022 01:28:47 +0000 (21:28 -0400)]
c++: parsing injected-class-name as template

While I was backporting the patch for PR102300, it occurred to me that it
would be cleaner to look through the injected-class-name earlier in the
function.  I don't think this changes any test results.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_template_name): Look through
injected-class-name.

2 years agoc++: array {}-init [PR105589]
Jason Merrill [Fri, 13 May 2022 20:07:10 +0000 (16:07 -0400)]
c++: array {}-init [PR105589]

My patch for 105191 made us use build_value_init more frequently from
build_vec_init_expr, but build_value_init doesn't like to be called to
initialize a class in a template.  That's caused trouble in the past, and
seems like a strange restriction, so let's fix it.

PR c++/105589
PR c++/105191
PR c++/92385

gcc/cp/ChangeLog:

* init.cc (build_value_init): Handle class in template.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-array16.C: New test.

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

2 years agoDaily bump.
GCC Administrator [Sat, 14 May 2022 00:17:19 +0000 (00:17 +0000)]
Daily bump.

2 years agoc++: Add fixed test [PR81952]
Marek Polacek [Fri, 13 May 2022 23:45:03 +0000 (19:45 -0400)]
c++: Add fixed test [PR81952]

This was fixed by r258755:
PR c++/81311 - wrong C++17 overload resolution.

PR c++/81952

gcc/testsuite/ChangeLog:

* g++.dg/overload/conv-op4.C: New test.

2 years agocompiler: always sort interface parse methods
Ian Lance Taylor [Thu, 12 May 2022 02:23:01 +0000 (19:23 -0700)]
compiler: always sort interface parse methods

The exporter relies on sorting interface parse methods.  It would sort
them as it encountered interface types.  However, when an interface
type is an element of a struct or array type, the exporter might
encounter that interface type before sorting the parse methods.  If it
then encountered an identical interface type again, it could get
confused about whether the two types are identical or not.

Fix the problem by always sorting the parse methods in the
finalize_methods pass.

Also firm up the export type sorting to make sure we never have this
kind of confusion again.  Doing this revealed that we need to be more
careful about sorting in order to handle aliases correctly.

Also fix the interface type hash computation to use the right hash
value when looking at parse methods rather than all methods.

The test case for this is https://go.dev/cl/405759.

Fixes golang/go#52841

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

2 years agoImproved V1TI (and V2DI) mode equality/inequality on x86_64.
Roger Sayle [Fri, 13 May 2022 21:26:29 +0000 (22:26 +0100)]
Improved V1TI (and V2DI) mode equality/inequality on x86_64.

This patch improves support for vector equality and inequality of
V1TImode vectors, and V2DImode vectors with sse2 but not sse4.
Consider the three functions below:

typedef unsigned int uv4si __attribute__ ((__vector_size__ (16)));
typedef unsigned long long uv2di __attribute__ ((__vector_size__ (16)));
typedef unsigned __int128 uv1ti __attribute__ ((__vector_size__ (16)));

uv4si eq_v4si(uv4si x, uv4si y) { return x == y; }
uv2di eq_v2di(uv2di x, uv2di y) { return x == y; }
uv1ti eq_v1ti(uv1ti x, uv1ti y) { return x == y; }

These all perform vector comparisons of 128bit SSE2 registers, generating
the result as a vector, where ~0 (all 1 bits) represents true and a zero
represents false.  eq_v4si is trivially implemented by x86_64's pcmpeqd
instruction. This patch improves the other two cases:

For v2di, gcc -O2 currently generates:

movq    %xmm0, %rdx
        movq    %xmm1, %rax
        movdqa  %xmm0, %xmm2
        cmpq    %rax, %rdx
        movhlps %xmm2, %xmm3
        movhlps %xmm1, %xmm4
        sete    %al
        movq    %xmm3, %rdx
        movzbl  %al, %eax
        negq    %rax
        movq    %rax, %xmm0
        movq    %xmm4, %rax
        cmpq    %rax, %rdx
        sete    %al
        movzbl  %al, %eax
        negq    %rax
        movq    %rax, %xmm5
        punpcklqdq      %xmm5, %xmm0
        ret

but with this patch we now generate:

        pcmpeqd %xmm0, %xmm1
        pshufd  $177, %xmm1, %xmm0
        pand    %xmm1, %xmm0
        ret

where the results of a V4SI comparison are shuffled and bit-wise ANDed
to produce the desired result.  There's no change in the code generated
for "-O2 -msse4" where the compiler generates a single "pcmpeqq" insn.

For V1TI mode, the results are equally dramatic, where the current -O2
output looks like:

        movaps  %xmm0, -40(%rsp)
        movq    -40(%rsp), %rax
        movq    -32(%rsp), %rdx
        movaps  %xmm1, -24(%rsp)
        movq    -24(%rsp), %rcx
        movq    -16(%rsp), %rsi
        xorq    %rcx, %rax
        xorq    %rsi, %rdx
        orq     %rdx, %rax
        sete    %al
        xorl    %edx, %edx
        movzbl  %al, %eax
        negq    %rax
        adcq    $0, %rdx
        movq    %rax, %xmm2
        negq    %rdx
        movq    %rdx, -40(%rsp)
        movhps  -40(%rsp), %xmm2
        movdqa  %xmm2, %xmm0
        ret

with this patch we now generate:

        pcmpeqd %xmm0, %xmm1
        pshufd  $177, %xmm1, %xmm0
        pand    %xmm1, %xmm0
        pshufd  $78, %xmm0, %xmm1
        pand    %xmm1, %xmm0
        ret

performing a V2DI comparison, followed by a shuffle and pand, and with
-O2 -msse4 take advantages of SSE4.1's pcmpeqq:

        pcmpeqq %xmm0, %xmm1
        pshufd  $78, %xmm1, %xmm0
        pand    %xmm1, %xmm0
        ret

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

gcc/ChangeLog
* config/i386/sse.md (vec_cmpeqv2div2di): Enable for TARGET_SSE2.
For !TARGET_SSE4_1, expand as a V4SI vector comparison, followed
by a pshufd and pand.
(vec_cmpeqv1tiv1ti): New define_expand implementing V1TImode
vector equality as a V2DImode vector comparison (see above),
followed by a pshufd and pand.

gcc/testsuite/ChangeLog
* gcc.target/i386/sse2-v1ti-veq.c: New test case.
* gcc.target/i386/sse2-v1ti-vne.c: New test case.

2 years agors6000: Remove a few needless 'lp64' contraints.
Paul A. Clarke [Tue, 8 Mar 2022 23:12:41 +0000 (17:12 -0600)]
rs6000: Remove a few needless 'lp64' contraints.

A few tests need not be restricted to 'lp64', so remove the restriction.

A few of those need a simple change to the DejaGnu directives to suppress
'-mcmodel' flags for '-m32'.

2022-05-13  Paul A. Clarke  <pc@us.ibm.com>

gcc/testsuite
* g++.target/powerpc/pr65240-1.C: Adjust DejaGnu directives.
* g++.target/powerpc/pr65240-2.C: Likewise.
* g++.target/powerpc/pr65240-3.C: Likewise.
* g++.target/powerpc/pr65240-4.C: Likewise.
* g++.target/powerpc/pr65242.C: Likewise.
* g++.target/powerpc/pr67211.C: Likewise.
* g++.target/powerpc/pr69667.C: Likewise.
* g++.target/powerpc/pr71294.C: Likewise.

2 years agors6000: Move g++.dg powerpc PR tests to g++.target
Paul A. Clarke [Mon, 21 Feb 2022 18:14:01 +0000 (12:14 -0600)]
rs6000: Move g++.dg powerpc PR tests to g++.target

Also adjust DejaGnu directives, as specifically requiring "powerpc*-*-*" is no
longer required.

2021-05-13  Paul A. Clarke  <pc@us.ibm.com>

gcc/testsuite
* g++.dg/pr65240.h: Move to g++.target/powerpc.
* g++.dg/pr93974.C: Likewise.
* g++.dg/pr65240-1.C: Move to g++.target/powerpc, adjust dg directives.
* g++.dg/pr65240-2.C: Likewise.
* g++.dg/pr65240-3.C: Likewise.
* g++.dg/pr65240-4.C: Likewise.
* g++.dg/pr65242.C: Likewise.
* g++.dg/pr67211.C: Likewise.
* g++.dg/pr69667.C: Likewise.
* g++.dg/pr71294.C: Likewise.
* g++.dg/pr84264.C: Likewise.
* g++.dg/pr84279.C: Likewise.
* g++.dg/pr85657.C: Likewise.

2 years agoPR tree-optimization/83907: Improved memset handling in strlen pass.
Roger Sayle [Fri, 13 May 2022 21:20:16 +0000 (22:20 +0100)]
PR tree-optimization/83907: Improved memset handling in strlen pass.

This patch implements the missed optimization enhancement PR 83907,
by handling memset with a constant byte value in tree-ssa's strlen
optimization pass.  Effectively, this treats memset(dst,'x',3) as
it would memcpy(dst,"xxx",3).

This patch also includes a tweak to handle_store to address another
missed optimization observed in the related test case pr83907-2.c.
The consecutive byte stores to memory get coalesced into a vector
write of a vector const, but unfortunately tree-ssa-strlen's
handle_store didn't previously handle the (unusual) case where the
stored "string" starts with a zero byte but also contains non-zero
bytes.

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

gcc/ChangeLog
PR tree-optimization/83907
* tree-ssa-strlen.cc (handle_builtin_memset): Record a strinfo
for memset with an constant char value.
(handle_store): Improved handling of stores with a first byte
of zero, but not storing_all_zeros_p.

gcc/testsuite/ChangeLog
PR tree-optimization/83907
* gcc.dg/tree-ssa/pr83907-1.c: New test case.
* gcc.dg/tree-ssa/pr83907-2.c: New test case.

2 years agoRISC-V: Implement C[LT]Z_DEFINED_VALUE_AT_ZERO
Philipp Tomsich [Fri, 1 Apr 2022 12:42:58 +0000 (14:42 +0200)]
RISC-V: Implement C[LT]Z_DEFINED_VALUE_AT_ZERO

The Zbb support has introduced ctz and clz to the backend, but some
transformations in GCC need to know what the value of c[lt]z at zero
is. This affects how the optab is generated and may suppress use of
CLZ/CTZ in tree passes.

Among other things, this is needed for the transformation of
table-based ctz-implementations, such as in deepsjeng, to work
(see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90838).

Prior to this change, the test case from PR90838 would compile to
on RISC-V targets with Zbb:
  myctz:
lui a4,%hi(.LC0)
ld a4,%lo(.LC0)(a4)
neg a5,a0
and a5,a5,a0
mul a5,a5,a4
lui a4,%hi(.LANCHOR0)
addi a4,a4,%lo(.LANCHOR0)
srli a5,a5,58
sh2add a5,a5,a4
lw a0,0(a5)
ret

After this change, we get:
  myctz:
ctz a0,a0
andi a0,a0,63
ret

Testing this with deepsjeng_r (from SPEC 2017) against QEMU, this
shows a clear reduction in dynamic instruction count:
 - before  1961888067076
 - after   1907928279874 (2.75% reduction)

This also merges the various target-specific test-cases (for x86-64,
aarch64 and riscv) within gcc.dg/pr90838.c.

This extends the macros (i.e., effective-target keywords) used in
testing (lib/target-supports.exp) to reliably distinguish between RV32
and RV64 via __riscv_xlen (i.e., the integer register bitwidth) :
testing for ILP32 could be misleading (as ILP32 is a valid memory
model for 64bit systems).

gcc/ChangeLog:

* config/riscv/riscv.h (CLZ_DEFINED_VALUE_AT_ZERO): Implement.
(CTZ_DEFINED_VALUE_AT_ZERO): Same.
* doc/sourcebuild.texi: add documentation for RISC-V specific
test target keywords

gcc/testsuite/ChangeLog:

* gcc.dg/pr90838.c: Add additional flags (dg-additional-options)
  when compiling for riscv64 and subsume gcc.target/aarch64/pr90838.c
  and gcc.target/i386/pr95863-2.c.
* gcc.target/aarch64/pr90838.c: Removed.
* gcc.target/i386/pr95863-2.c: Removed.
* lib/target-supports.exp: Recognize RV32 or RV64 via XLEN

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Signed-off-by: Manolis Tsamis <manolis.tsamis@vrull.eu>
Co-authored-by: Manolis Tsamis <manolis.tsamis@vrull.eu>
2 years agolibstdc++: Make std::thread::_State private
Jonathan Wakely [Thu, 12 May 2022 19:46:55 +0000 (20:46 +0100)]
libstdc++: Make std::thread::_State private

* include/bits/std_thread.h (thread::_State, thread::_State_ptr):
Declare as private unless _GLIBCXX_THREAD_IMPL is defined.
* src/c++11/thread.cc (_GLIBCXX_THREAD_IMPL): Define.

2 years agolibstdc++: Add noexcept to std::launch operators
Jonathan Wakely [Thu, 12 May 2022 18:33:58 +0000 (19:33 +0100)]
libstdc++: Add noexcept to std::launch operators

libstdc++-v3/ChangeLog:

* include/std/future (launch): Make operators noexcept.

2 years agolibstdc++: Allow std::swap to find overload for std::exception_ptr
Jonathan Wakely [Thu, 12 May 2022 13:18:53 +0000 (14:18 +0100)]
libstdc++: Allow std::swap to find overload for std::exception_ptr

The non-member swap for std::exception_ptr is in a nested namespace and
so can only be found by ADL currently. Add a using-declaration so that
qualified std::swap calls will use the std::exception_ptr::swap member,
instead of the generic std::swap.

There's no new test for this, because the generic std::swap works, it
just does more work than is necessary.

Also tell Doxygen to replace the __exception_ptr namespace with
"__unspecified__" in the generate docs, so the real name is not
documented.

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Replace __exception_ptr
with "__unspecified__".
* libsupc++/exception_ptr.h: Improve doxygen docs.
(__exception_ptr::swap): Also declare in namespace std.

2 years agolibstdc++: Make std::rethrow_if_nested work without RTTI
Jonathan Wakely [Thu, 12 May 2022 13:18:06 +0000 (14:18 +0100)]
libstdc++: Make std::rethrow_if_nested work without RTTI

This allows std::rethrow_if_nested to work with -fno-rtti by not
attempting the dynamic_cast if it requires RTTI, since that's ill-formed
with -fno-rtti. The cast will still work if a static upcast to
std::nested_exception is allowed.

Also use if-constexpr to avoid the compile-time overload resolution (and
SFINAE) and run-time dispatching for std::rethrow_if_nested and
std::throw_with_nested.

Also add better doxygen comments throughout the file.

libstdc++-v3/ChangeLog:

* libsupc++/nested_exception.h (throw_with_nested) [C++17]: Use
if-constexpr instead of tag dispatching.
(rethrow_if_nested) [C++17]: Likewise.
(rethrow_if_nested) [!__cpp_rtti]: Do not use dynamic_cast if it
would require RTTI.
* testsuite/18_support/nested_exception/rethrow_if_nested-term.cc:
New test.

2 years agoCheck operand for type, not LHS.
Andrew MacLeod [Fri, 13 May 2022 17:11:18 +0000 (13:11 -0400)]
Check operand for type, not LHS.

When folding, the LHS has not been set, so we should be checking the type of
op1.  We should also make sure op1 is not undefined.

PR tree-optimization/105597
gcc/
* range-op.cc (operator_minus::lhs_op1_relation): Use op1 instead
of the lhs and make sure it is not undefined.
gcc/testsuite/
* gcc.dg/pr105597.c: New.

2 years agolibgomp.fortran/target-nowait-array-section.f90: Fix typo
Tobias Burnus [Fri, 13 May 2022 18:04:38 +0000 (20:04 +0200)]
libgomp.fortran/target-nowait-array-section.f90: Fix typo

Fix typo as requested in the review approval.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/target-nowait-array-section.f90: New test.

2 years agoOpenMP/Fortran: Use firstprivat not alloc for ptr attach for arrays
Tobias Burnus [Fri, 13 May 2022 18:00:34 +0000 (20:00 +0200)]
OpenMP/Fortran: Use firstprivat not alloc for ptr attach for arrays

For a non-descriptor array,  map(A(n:m)) was mapped as
  map(tofrom:A[n-1] [len: ...]) map(alloc:A [pointer assign, bias: ...])
with this patch, it is changed to
  map(tofrom:A[n-1] [len: ...]) map(firstprivate:A [pointer assign, bias: ...])

The latter avoids an alloc - and also avoids the race condition with
nowait in the enclosed testcase. (Note: predantically, the testcase is
invalid since OpenMP 5.1, violating the map clause restriction at [354:10-13].

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_trans_omp_clauses): When mapping nondescriptor
array sections, use GOMP_MAP_FIRSTPRIVATE_POINTER instead of
GOMP_MAP_POINTER for the pointer attachment.

libgomp/ChangeLog:

* testsuite/libgomp.fortran/target-nowait-array-section.f90: New test.

2 years ago[AArch64] add barriers to ool __sync builtins
Sebastian Pop [Mon, 18 Apr 2022 15:13:20 +0000 (15:13 +0000)]
[AArch64] add barriers to ool __sync builtins

2022-05-13  Sebastian Pop  <spop@amazon.com>

gcc/
PR target/105162
* config/aarch64/aarch64-protos.h (atomic_ool_names): Increase dimension
of str array.
* config/aarch64/aarch64.cc (aarch64_atomic_ool_func): Call
memmodel_from_int and handle MEMMODEL_SYNC_*.
(DEF0): Add __aarch64_*_sync functions.

gcc/testsuite/
PR target/105162
* gcc.target/aarch64/sync-comp-swap-ool.c: New.
* gcc.target/aarch64/sync-op-acquire-ool.c: New.
* gcc.target/aarch64/sync-op-full-ool.c: New.
* gcc.target/aarch64/target_attr_20.c: Update check.
* gcc.target/aarch64/target_attr_21.c: Same.

libgcc/
PR target/105162
* config/aarch64/lse.S: Define BARRIER and handle memory MODEL 5.
* config/aarch64/t-lse: Add a 5th memory model for _sync functions.

2 years agotestsuite: btf: Fix btf-datasec-1.c for RISC-V
Palmer Dabbelt [Wed, 4 May 2022 00:27:15 +0000 (17:27 -0700)]
testsuite: btf: Fix btf-datasec-1.c for RISC-V

Similar to 37e65643d3e ("testsuite/101269: fix testcase when used with
-m32"), RISC-V needs to be told not to put symbols in the
sdata/srodata/sbss sections.

gcc/testsuite/ChangeLog

* gcc.dg/debug/btf/btf-datasec-1.c: Don't use small data on RISC-V.

2 years agotestsuite: opt: Fix const7.C for RISC-V.
Jia-Wei Chen [Fri, 13 May 2022 01:55:45 +0000 (09:55 +0800)]
testsuite: opt: Fix const7.C for RISC-V.

Similar to pr593993, RISC-V needs to limit symbols send in sdata.

gcc/testsuite/ChangeLog:

* g++.dg/opt/const7.C: Don't use small data on RISC-V.

2 years agoMove VREL values to their own enumerated type.
Andrew MacLeod [Thu, 12 May 2022 16:00:39 +0000 (12:00 -0400)]
Move VREL values to their own enumerated type.

Re-using some common things like EQ_EXPR and other relationals made
certain things easier, but complicated debugging and added extra overhead
when accessing lookup tables.   With forthcoming additional relation types,
it makes more sense to simple have a distinct relation kind.

* gimple-range-fold.cc (fold_using_range::range_of_phi): Use new VREL_*
enumerated values.
* gimple-range-path.cc (maybe_register_phi_relation): Ditto.
* range-op.cc (*::lhs_op1_relation): Return relation_kind, and use
new VREL enumerated values.
(*::lhs_op2_relation): Ditto.
(*::op1_op2_relation): Ditto.
(*::fold_range): Use new VREL enumerated values.
(minus_op1_op2_relation_effect): Ditto.
(range_relational_tests): Ditto.
* range-op.h (fold_range, op1_range, op2_range): Use VREL_VARYING.
(lhs_op1_relation, lhs_op2_relation, op1_op2_relation): Return
relation_kind.
(*_op1_op2_relation): Return relation_kind.
(relop_early_resolve): Use VREL_UNDEFINED.
* value-query.cc (range_query::query_relation): Use VREL_VARYING.
* value-relation.cc (VREL_LAST): Change enumerated value.
(vrel_range_assert): Delete.
(print_relation): Remove range assert.
(rr_negate_table): Adjust table to use new enumerated values..
(relation_negate): Remove range assert.
(rr_swap_table): Adjust.
(relation_swap): Remove range assert.
(rr_intersect_table): Adjust.
(relation_intersect): Remove range assert.
(rr_union_table): Adjust.
(relation_union): Remove range assert.
(rr_transitive_table): Adjust.
(relation_transitive): Remove range assert.
(equiv_oracle::query_relation): Use new VREL enumerated values.
(equiv_oracle::register_relation): Ditto.
(relation_oracle::register_stmt): Ditto.
(dom_oracle::set_one_relation): Ditto.
(dom_oracle::register_transitives): Ditto.
(dom_oracle::query_relation): Ditto.
(path_oracle::register_relation): Ditto.
(path_oracle::query_relation): Ditto.
* value-relation.h (enum relation_kind_t): New relation_kind.
(*_op1_op2_relation): Adjust prototypes.

2 years agoReturn a bool result for union, and add performance improvements.
Andrew MacLeod [Mon, 9 May 2022 17:32:31 +0000 (13:32 -0400)]
Return a bool result for union, and add performance improvements.

Union_ returns a boolean indicating if the operation changes the range.
Also optimize the common single-pair UNION single-pair case.

* gimple-range-edge.cc (calc_switch_ranges): Check union return value.
* value-range.cc (irange::legacy_verbose_union_): Add return value.
(irange::irange_single_pair_union): New.
(irange::irange_union): Add return value.
* value-range.h (class irange): Adjust prototypes.

2 years agoAdd a return value to intersect and speed it up.
Andrew MacLeod [Mon, 9 May 2022 17:20:06 +0000 (13:20 -0400)]
Add a return value to intersect and speed it up.

Return true if the intersection of ranges changed the original value.
Speed up the case when there is no change by calling an efficient
contains routine.

* value-range.cc (irange::legacy_verbose_intersect): Add return value.
(irange::irange_contains_p): New.
(irange::irange_intersect): Add return value.
* value-range.h (class irange): Adjust prototypes.

2 years agoFix return value in ranger_cache::get_global_range.
Andrew MacLeod [Fri, 18 Mar 2022 15:50:33 +0000 (11:50 -0400)]
Fix return value in ranger_cache::get_global_range.

The "is_current" status is returned by parameter, but was being returned by the
function as well instead of true if NAME had a global range, and FALSE
if it did not.

* gimple-range-cache.cc (ranger_cache::get_global_range): Return the
had_global value instead.

2 years agoMAINTAINERS: Add myself to write after approval
Surya Kumari Jangala [Fri, 13 May 2022 14:13:50 +0000 (09:13 -0500)]
MAINTAINERS: Add myself to write after approval

2022-05-13  Surya Kumari Jangala  <jskumari@linux.ibm.com>

* MAINTAINERS: Add myself to write after approval.

2 years agoAdd relation between op1 & op2 to lhs_opN_relation API.
Andrew MacLeod [Tue, 15 Feb 2022 15:17:26 +0000 (10:17 -0500)]
Add relation between op1 & op2 to lhs_opN_relation API.

We use the relation between op1 and op2 to help fold a statement, but
it was not provided to the lhs_op1_relation and lhs_op2_relation routines
to determine if is also creates a relation between the LHS and either operand.

gcc/
PR tree-optimization/104547
* gimple-range-fold.cc (fold_using_range::range_of_range_op): Add
the op1/op2 relation to the relation call.
* range-op.cc (*::lhs_op1_relation): Add param.
(*::lhs_op2_relation): Ditto.
(operator_minus::lhs_op1_relation): New.
(range_relational_tests): Add relation param.
* range-op.h (lhs_op1_relation, lhs_op2_relation): Adjust prototype.

gcc/testsuite/
* g++.dg/pr104547.C: New.

2 years agoc++: Local symbols do not get module manglings
Nathan Sidwell [Wed, 6 Apr 2022 13:37:12 +0000 (06:37 -0700)]
c++: Local symbols do not get module manglings

Internal-linkage entity mangling is entirely implementation defined --
there's no ABI issue.  Let's not mangle in any module attachment to
them, it makes the symbols unnecessarily longer.

gcc/cp/
* mangle.cc (maybe_write_module): Check external linkage.
gcc/testsuite/
* g++.dg/modules/mod-sym-4.C: New.

2 years agoExport global ranges during the VRP block walk.
Andrew MacLeod [Thu, 17 Feb 2022 00:59:34 +0000 (19:59 -0500)]
Export global ranges during the VRP block walk.

VRP currently searches the ssa_name list for globals to exported after it
finishes running.  Recent changes have VRP calling a side-effect routine for
each stmt during the walk.  This change simply exports globals as they are
calculated the final time during the walk.

* gimple-range.cc (gimple_ranger::register_side_effects): First check
if the DEF should be exported as a global.
* tree-vrp.cc (rvrp_folder::pre_fold_bb): Process PHI side effects,
which will export globals.
(execute_ranger_vrp): Remove call to export_global_ranges.

2 years agoClear killing defs when resetting the path in path_oracle.
Andrew MacLeod [Wed, 23 Feb 2022 17:25:20 +0000 (12:25 -0500)]
Clear killing defs when resetting the path in path_oracle.

When we reset the path oracle, we should clear the killing defs vector.

* value-relation.cc (path_oracle::reset_path): Clear killing_defs.

2 years agoMake range_from_dom more effective.
Andrew MacLeod [Thu, 24 Mar 2022 19:28:43 +0000 (15:28 -0400)]
Make range_from_dom more effective.

Add modes to range_from_dom such that we can simply query, or adjust the
cache and deal with multiple predecessor blocks.

* gimple-range-cache.cc (ranger_cache::ranger_cache): Start with
worlist truncated.
(ranger_cache::entry_range): Add rfd_mode parameter.
(ranger_cache::exit_range): Ditto.
(ranger_cache::edge_range): New.  Incorporate from range_on_edge.
(ranger_cache::range_of_expr): Adjust call to entry_range.
(ranger_cache::range_on_edge): Split to edge_range and call.
(ranger_cache::fill_block_cache): Always invoke range_from_dom.
(ranger_cache::range_from_dom): Make reentrant, add search mode, handle
mutiple predecessors.
(ranger_cache::update_to_nonnull): Adjust call to exit_range.
* gimple-range-cache.h (ranger_cache): Add enum rfd_mode.  Adjust
prototypes.

2 years agolibstdc++: Improve doxygen docs for <mutex>
Jonathan Wakely [Thu, 12 May 2022 22:06:04 +0000 (23:06 +0100)]
libstdc++: Improve doxygen docs for <mutex>

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Define
_GTHREAD_USE_MUTEX_TIMEDLOCK macro.
* include/bits/std_mutex.h (mutex, lock_guard): Use @since and
@headerfile.
* include/bits/unique_lock.h (unique_lock): Likewise.
* include/std/mutex (recursive_mutex, timed_mutex)
(recursive_timed_mutex, scoped_lock): Likewise.

2 years agolibstdc++: Improve doxygen docs for some of <memory>
Jonathan Wakely [Thu, 12 May 2022 22:04:29 +0000 (23:04 +0100)]
libstdc++: Improve doxygen docs for some of <memory>

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Define
_GLIBCXX23_CONSTEXPR macro.
* include/backward/auto_ptr.h (auto_ptr): Use @deprecated.
* include/bits/unique_ptr.h (default_delete): Use @since and
@headerfile.
* include/std/scoped_allocator: Remove @ingroup from @file
block.

2 years agolibstdc++: Improve doxygen docs for <thread> and <future>
Jonathan Wakely [Thu, 12 May 2022 21:26:34 +0000 (22:26 +0100)]
libstdc++: Improve doxygen docs for <thread> and <future>

libstdc++-v3/ChangeLog:

* include/bits/std_thread.h (thread, thread::id): Improve
doxygen docs.
* include/std/future: Likewise.
* include/std/thread (jthread): Likewise.

2 years agolibstdc++: Improve doxygen docs for algorithms and more
Jonathan Wakely [Thu, 12 May 2022 13:13:37 +0000 (14:13 +0100)]
libstdc++: Improve doxygen docs for algorithms and more

libstdc++-v3/ChangeLog:

* include/bits/ostream_insert.h: Mark helper functions as
undocumented by Doxygen.
* include/bits/stl_algo.h: Use markdown for formatting and mark
helper functions as undocumented.
* include/bits/stl_numeric.h:  Likewise.
* include/bits/stl_pair.h (pair): Add @headerfile.

2 years agolibstdc++: Improve doxygen docs for std::allocator
Jonathan Wakely [Thu, 12 May 2022 12:44:52 +0000 (13:44 +0100)]
libstdc++: Improve doxygen docs for std::allocator

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Define __allocator_base
so that Doxygen shows the right base-class for std::allocator.
* include/bits/alloc_traits.h: Improve doxygen docs.
* include/bits/allocator.h: Likewise.
* include/bits/new_allocator.h: Likewise.
* include/ext/new_allocator.h: Likewise.

2 years agolibstdc++: Improve doxygen docs for <regex>
Jonathan Wakely [Thu, 12 May 2022 11:16:17 +0000 (12:16 +0100)]
libstdc++: Improve doxygen docs for <regex>

Add @headerfile and @since tags. Improve grouping of non-member
functions via @relates tags.

Mark the std::pair base class of std::sub_match as undocumented, so that
the docs don't show all the related non-member functions are part of the
sub_match API. Use a new macro to re-add the data members for Doxygen
only.

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Define macro
_GLIBCXX_DOXYGEN_ONLY to expand its argument.
* include/bits/c++config (_GLIBCXX_DOXYGEN_ONLY): Define.
* include/bits/regex.h: Improve doxygen docs.
* include/bits/regex_constants.h: Likewise.
* include/bits/regex_error.h: Likewise.

2 years agolibstdc++: Improve doxygen docs for <atomic>
Jonathan Wakely [Wed, 11 May 2022 22:52:20 +0000 (23:52 +0100)]
libstdc++: Improve doxygen docs for <atomic>

libstdc++-v3/ChangeLog:

* include/std/atomic: Suppress doxygen docs for
implementation details.
* include/bits/atomic_base.h: Likewise.
* include/bits/shared_ptr_atomic.h: Use markdown. Fix grouping
so that std::atomic is not added to the pointer abstractions
group.

2 years agolibstdc++: Improve doxygen docs for <system_error>
Jonathan Wakely [Wed, 11 May 2022 21:48:17 +0000 (22:48 +0100)]
libstdc++: Improve doxygen docs for <system_error>

libstdc++-v3/ChangeLog:

* include/std/system_error: Improve doxygen comments.

2 years agolibstdc++: Improve doxygen docs for std::pointer_traits
Jonathan Wakely [Wed, 11 May 2022 15:13:16 +0000 (16:13 +0100)]
libstdc++: Improve doxygen docs for std::pointer_traits

libstdc++-v3/ChangeLog:

* include/bits/ptr_traits.h: Add some doxygen comments.

2 years agolibstdc++: Add macros for the inline namespace std::_V2
Jonathan Wakely [Wed, 11 May 2022 15:35:45 +0000 (16:35 +0100)]
libstdc++: Add macros for the inline namespace std::_V2

Use macros to open and close the inline namespace _V2 that is used for
ABI versioning of individual components such as chrono::system_clock.

This allows the namespace to be hidden in the docs generated by Doxygen,
so that we document std::foo instead of std::_V2::foo.

This also makes it easy to remove that namespace entirely for the
gnu-versioned-namespace build, where everything is already versioned as
std::__8 and there are no backwards compatibility guarantees.

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (PREDEFINED): Expand new macros to
nothing.
* include/bits/c++config (_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE)
(_GLIBCXX_END_INLINE_ABI_NAMESPACE): Define new macros.
* include/bits/algorithmfwd.h (_V2::__rotate): Use new macros
for the namespace.
* include/bits/chrono.h (chrono::_V2::system_clock): Likewise.
* include/bits/stl_algo.h (_V2::__rotate): Likewise.
* include/std/condition_variable (_V2::condition_variable_any):
Likewise.
* include/std/system_error (_V2::error_category): Likewise.

2 years agolibstdc++: Fix typo in doxygen @headerfile command
Jonathan Wakely [Wed, 11 May 2022 15:06:13 +0000 (16:06 +0100)]
libstdc++: Fix typo in doxygen @headerfile command

libstdc++-v3/ChangeLog:

* include/bits/mofunc_impl.h: Fix doxygen command.

2 years agolibstdc++: Disable Doxygen GROUP_NESTED_COMPOUNDS config option
Jonathan Wakely [Wed, 11 May 2022 15:46:03 +0000 (16:46 +0100)]
libstdc++: Disable Doxygen GROUP_NESTED_COMPOUNDS config option

Before Doxygen version 1.9.2 this option is broken (see
https://github.com/doxygen/doxygen/issues/8638 for more details) and
classes are not added to the correct groups by @ingroup and @addtogroup.

Also remove the obsolete CLASS_DIAGRAMS option that causes a warning.

libstdc++-v3/ChangeLog:

* doc/doxygen/user.cfg.in (GROUP_NESTED_COMPOUNDS): Set to NO.
(CLASS_DIAGRAMS): Remove obsolete option.

2 years agolibgomp nvptx plugin: Only consider '--with-cuda-driver=[...]' when applicable
Thomas Schwinge [Thu, 12 May 2022 15:51:43 +0000 (17:51 +0200)]
libgomp nvptx plugin: Only consider '--with-cuda-driver=[...]' when applicable

They're not applicable in 'PLUGIN_NVPTX_DYNAMIC' configurations.

libgomp/
* plugin/Makefrag.am (libgomp_plugin_nvptx_la_CPPFLAGS)
[PLUGIN_NVPTX_DYNAMIC]: Don't append '$(PLUGIN_NVPTX_CPPFLAGS)'.
(libgomp_plugin_nvptx_la_LDFLAGS) [PLUGIN_NVPTX_DYNAMIC]: Don't
append '$(PLUGIN_NVPTX_LDFLAGS)'.
* Makefile.in: Regenerate.

2 years agoAvoid visiting newly-created blocks in harden-conditionals
Alexandre Oliva [Fri, 13 May 2022 10:48:51 +0000 (07:48 -0300)]
Avoid visiting newly-created blocks in harden-conditionals

Reverse iteration over blocks, in gimple-harden-conditionals.cc, was
supposed to avoid visiting blocks introduced by hardening and
introducing further reversed conditionals and traps for them, but
newly-created blocks may be inserted before the current block, as
shown by the PR105455 testcase.

Use an auto_sbitmap to gather preexisting blocks that need visiting.

for  gcc/ChangeLog

* gimple-harden-conditionals.cc: Include sbitmap.h.
(pass_harden_conditional_branches::execute): Skip new blocks.
(pass_harden_compares::execute): Likewise.

2 years agoada: gcc-if: build proper String_Pointer for Get_External_Name
Alexandre Oliva [Fri, 13 May 2022 10:48:50 +0000 (07:48 -0300)]
ada: gcc-if: build proper String_Pointer for Get_External_Name

The compiler is allowed to assume it can access String bounds, such as
the prefix passed to Get_External_Name, even in circumstances in which
the prefix is not going to be used and has_prefix is false, so, from
the C side, we have to build a proper String_Template for the
String_Pointer.

for  gcc/ada/ChangeLog

* gcc-interface/decl.cc (is_cplusplus_method): Build proper
String for Get_External_Name.

2 years agoIntroduce tests for hardbool Machine_Attribute for Ada
Alexandre Oliva [Fri, 13 May 2022 10:48:49 +0000 (07:48 -0300)]
Introduce tests for hardbool Machine_Attribute for Ada

Test for the validity checking performed on nonstandard booleans
annotated with the "hardbool" Machine_Attribute pragma.

for  gcc/testsuite/ChangeLog

* gnat.dg/hardbool.ads: New.
* gnat.dg/hardbool.adb: New.

2 years agoarm: correctly handle misaligned MEMs on MVE [PR105463]
Richard Earnshaw [Wed, 11 May 2022 12:08:40 +0000 (13:08 +0100)]
arm: correctly handle misaligned MEMs on MVE [PR105463]

Vector operations in MVE must be aligned to the element size, so if we
are asked for a misaligned move in a wider mode we must recast it to a
form suitable for the known alignment (larger elements have better
address offset ranges, so there is some advantage to using wider
element sizes if possible).  Whilst fixing this, also rework the
predicates used for validating operands - the Neon predicates are
not right for MVE.

gcc/ChangeLog:

PR target/105463
* config/arm/mve.md (*movmisalign<mode>_mve_store): Use
mve_memory_operand.
(*movmisalign<mode>_mve_load): Likewise.
* config/arm/vec-common.md (movmisalign<mode>): Convert to generator
form...
(@movmisalign<mode>): ... thus.  Use generic predicates and then
rework operands if they are not valid.  For MVE rework to a
narrower element size if the alignment is not high enough.

2 years agoarm: fix some issues in mve_vector_mem_operand
Richard Earnshaw [Wed, 11 May 2022 10:40:42 +0000 (11:40 +0100)]
arm: fix some issues in mve_vector_mem_operand

There are a couple of issues with the mve_vector_mem_operand function.
Firstly, SP is permitted as a register provided there is no write-back
operation.  Secondly, there were some cases where 'strict' was not
being applied when checking which registers had been used.

gcc/ChangeLog:

* config/arm/arm.cc (mve_vector_mem_operand): Allow SP_REGNUM
when there is no write-back.  Fix use when strict is true.

2 years agoxtensa: Reflect the 32-bit Integer Divide Option
Takayuki 'January June' Suwa [Fri, 6 May 2022 10:34:19 +0000 (19:34 +0900)]
xtensa: Reflect the 32-bit Integer Divide Option

On Espressif's ESP8266 (based on Tensilica LX106, no hardware divider),
this patch reduces the size of each:

  __moddi3() @ libgcc.a :  969 -> 301 (saves 668)
  __divmoddi4()         : 1111 -> 426 (saves 685)
  __udivmoddi4()        : 1043 -> 319 (saves 724)

in bytes, respectively.

gcc/ChangeLog:

* config/xtensa/xtensa.h (TARGET_HAS_NO_HW_DIVIDE): New macro
definition.

2 years agoxtensa: Rename deprecated extv/extzv insn patterns to extvsi/extzvsi
Takayuki 'January June' Suwa [Fri, 6 May 2022 10:34:06 +0000 (19:34 +0900)]
xtensa: Rename deprecated extv/extzv insn patterns to extvsi/extzvsi

These patterns were deprecated since GCC 4.8.

gcc/ChangeLog:

* config/xtensa/xtensa.md (extvsi, extvsi_internal, extzvsi,
extzvsi_internal): Rename from extv, extv_internal, extzv and
extzv_internal, respectively.

2 years agoFix wrong SRA with VIEW_CONVERT_EXPR and reverse SSO
Eric Botcazou [Fri, 13 May 2022 09:15:08 +0000 (11:15 +0200)]
Fix wrong SRA with VIEW_CONVERT_EXPR and reverse SSO

Most cases of VIEW_CONVERT_EXPRs involving reverse scalar storage order are
disqualified for SRA because they are storage_order_barrier_p, but you can
still have a VIEW_CONVERT_EXPR to a regular composite type being applied to
a component of a record type with reverse scalar storage order.

In this case the bypass for !useless_type_conversion_p in sra_modify_assign,
albeit already heavily guarded, triggers and may generate wrong code, so the
patch makes sure that it does only when the SSO is the same on both side.

gcc/
* tree-sra.cc (sra_modify_assign): Check that scalar storage order
is the same on the LHS and RHS before rewriting one with the model
of the other.
gcc/testsuite/
* gnat.dg/sso17.adb: New test.

2 years ago[Ada] Fix incorrect call to inherited function with limited return type
Eric Botcazou [Sat, 5 Mar 2022 18:18:18 +0000 (19:18 +0100)]
[Ada] Fix incorrect call to inherited function with limited return type

This is a return convention mismatch coming from a discrepancy of the
Returns_By_Ref flag for the inherited function.

gcc/ada/

* sem_ch3.adb (Derive_Subprogram): For a function, also copy the
Returns_By_Ref flag from the parent.

2 years ago[Ada] Storage_Model_Object fails to return object entity
Gary Dismukes [Fri, 4 Mar 2022 22:19:18 +0000 (17:19 -0500)]
[Ada] Storage_Model_Object fails to return object entity

After a compilation unit containing a Designated_Storage_Model aspect
was processed by the compiler front end, the aspect's expression was
seen as not having been analyzed. In some cases this can lead to the
Storage_Model_Object function not returning the entity of the associated
model object (such as when the model object is specified using an
expanded name). This was due to a second copy of the aspect's expression
being made in Check_Aspect_At_Freeze_Point, and that copy wasn't
analyzed, even though the earlier version of the expression prior to
that copy had been. (The copy is needed for proper checking of Ada's
rules for ensuring that certain aspect expressions resolve the same way
at the freeze point and later at the end of the declarations.) This is
corrected by doing analysis of the new aspect expression within
Check_Aspect_At_Freeze_Point, as is already done in that procedure in
the case of several other aspects.

gcc/ada/

* sem_ch13.adb (Check_Aspect_At_Freeze_Point): Analyze the
expression of the aspect at this point, like other aspects that
denote simple entities. Ensures that function
Storage_Model_Object will have an entity to retrieve from the
aspect expression. Also, move comment about aspects that don't
require delay analysis in front of last alternative of the case
statement, where it's supposed to be.

2 years ago[Ada] Compiler crash on -gnata -O2
Javier Miranda [Tue, 15 Feb 2022 19:09:48 +0000 (19:09 +0000)]
[Ada] Compiler crash on -gnata -O2

gcc/ada/

* contracts.adb (Build_Unique_Name): New subprogram.
(Make_Class_Precondition_Subps): Use Build_Unique_Name to
generate the names of the call helpers and the name of indirect
call wrappers.
* freeze.adb (Needs_Wrapper): Remove dead code.
(Check_Inherited_Conditions): Defer building helpers and ICW
until all the dispatch table wrappers have been built and
analyzed. Required to ensure uniqueness in their names because
when building these wrappers for overlapped subprograms their
homonym number is not definite until they have been analyzed.

2 years ago[Ada] Only use alternate stack when needed
Arnaud Charlet [Fri, 25 Feb 2022 09:39:57 +0000 (04:39 -0500)]
[Ada] Only use alternate stack when needed

If we're not going to install a signal handler for SIGSEGV then we do
not need an alternate stack to handle this signal (and e.g. stack
overflows).

gcc/ada/

* libgnarl/s-taprop__linux.adb (Initialize): Do not use an
alternate stack if no handler for SEGV is installed.

2 years ago[Ada] Extend hardcfr testing (documentation)
Alexandre Oliva [Wed, 23 Feb 2022 15:57:15 +0000 (12:57 -0300)]
[Ada] Extend hardcfr testing (documentation)

Having realized that noreturn calls of __builtin_return are special,
and other noreturn calls don't get edges to the exit block, I've
realized the consequences of the logic to insert checking before
noreturn and tail calls were not quite what I'd expected before.

Specifically, noreturn calls other than __builtin_return don't get any
checking whatsoever.  Moreover, optional tail calls are only detected
long after hardcfr; the logic should work for must-tail calls, but
there doesn't seem to be a way to test it.

Documentation has been simplified so as to remove mention of these
possibilities, that can't really be relied on.

gcc/ada/

* doc/gnat_rm/security_hardening_features.rst (Control Flow
Redundancy): Drop mentions of noreturn and tail calls.
* gnat_rm.texi: Regenerate.

2 years ago[Ada] CUDA: use binder to generate kernel-registration code
Ghjuvan Lacambre [Tue, 14 Sep 2021 08:49:08 +0000 (10:49 +0200)]
[Ada] CUDA: use binder to generate kernel-registration code

Compiling CUDA code requires compiling code for the host (= CPU) and for
the device (= GPU). Device code is embedded into the host code and must
be registered with the CUDA runtime by the host.

The original approach we took for registering CUDA kernels was to
generate the registration-code on a unit basis, i.e. each unit took care
of registering its own kernels. Unfortunately, this makes linking
kernels and device functions that belong to different units much harder.

We thus rework this approach in order to have GNAT generate kernel names
in ALI files. The binder reads the ALI files and generates kernel
registration code for each of the kernels found in ALI files.

gcc/ada/

* ali.adb: Introduce new 'K' line in ALI files, used to
represent CUDA kernel entries.
* ali.ads: Create new CUDA_Kernels table, which contains entries
of type CUDA_Kernel_Record. Each CUDA_Kernel_Record corresponds
to a K line in an ali file.
* bindgen.adb: Introduce new Gen_CUDA_Init procedure in the
binder, which generates CUDA kernel registration code.
* gnat_cuda.adb: Move Get_CUDA_Kernels spec to package spec to
make it available to bindgen.adb.
* gnat_cuda.ads: Likewise.
* lib-writ.adb: Introduce new Output_CUDA_Symbols procedure,
which generates one 'K' line in the ALI file per visible CUDA
kernel.
* opt.ads: Introduce Enable_CUDA_Expansion option, triggered by
using the -gnatd_c flag.
* switch-b.adb: Likewise.
* switch-c.adb: Likewise.

2 years ago[Ada] Fix iterated component association for array aggregate
Marc Poulhiès [Fri, 18 Feb 2022 15:35:06 +0000 (16:35 +0100)]
[Ada] Fix iterated component association for array aggregate

Create a scope for the Ada 2022 iterated component association loops. In
the case of elements needing finalization, the late expansion would
crash on references to the loop variable within the loop body.

gcc/ada/

* exp_aggr.adb (Gen_Loop): Create scope for loop variable of
iterated components.

2 years ago[Ada] Simplify helper units for formal hashed sets/maps
Yannick Moy [Thu, 24 Feb 2022 16:30:36 +0000 (17:30 +0100)]
[Ada] Simplify helper units for formal hashed sets/maps

As tampering checks do not exist in formal hashed sets and maps, remove
the machinery for such checks in the version of generic key and node
operations for formal sets/maps. Update comments as well.

gcc/ada/

* libgnat/a-chtgfk.adb (Checked_Equivalent_Keys, Checked_Index):
Remove useless functions.
(Delete_Key_Sans_Free, Find, Generic_Conditional_Insert): Adapt
to removal of wrapper functions.
* libgnat/a-chtgfk.ads (Checked_Equivalent_Keys, Checked_Index):
Remove useless functions.
* libgnat/a-chtgfo.adb (Checked_Index): Remove useless function.
(Clear): Delete code commented out regarding Busy and Lock
management.
(Delete_Node_At_Index): Delete unused procedure.
(Delete_Node_Sans_Free, Free, Generic_Read, Next): Adapt to
removal of wrapper functions.
* libgnat/a-chtgfo.ads (Checked_Index): Remove useless function.
(Delete_Node_At_Index): Delete unused procedure.

2 years ago[Ada] Adapt body of formal sets and maps for SPARK
Yannick Moy [Thu, 17 Feb 2022 07:58:30 +0000 (08:58 +0100)]
[Ada] Adapt body of formal sets and maps for SPARK

Remove violations of SPARK rules, to prepare for the proof of hashed
sets and maps:

- Make the type of hash tables not tagged, so that it will be possible
  to mark the type of nodes as having relaxed initialization.

- Remove comparison of addresses as check or optimization: as a check,
  it is not necessary in SPARK as the caller cannot pass in aliased
  parameters in such cases; as an optimization, it is not possible in
  SPARK code.

- Avoid aliasing when inserting a node in the hash table. The code for
  insertion in sets and maps was explicitly aliasing a global for the
  container and a parameter for its hash table component, both being
  written. Rewrite the code to pass only the hash table as parameter.

- Insert constants for subtype constraints, which cannot depend on
  variables in SPARK code.

- Use procedures instead of functions when side-effects are expected.

- Rename variables whose value is only written through calls and not
  read, using Unused prefix, so that flow analysis does not warn about
  it.

gcc/ada/

* libgnat/a-cfhama.adb (Generic_Allocate): Retype to avoid
aliasing.
(Assign, Move): Remove address comparison.
(Include): Insert constants for subtype constraints.
(Insert): Rewrite to avoid aliasing and function with side-effects.
* libgnat/a-cfhase.adb (Generic_Allocate): Retype to avoid
aliasing.
(Assign, Move): Remove address comparison.
(Difference, Intersection, Is_Subset, Overlap,
Symmetric_Difference, Union): Remove address comparison.  Insert
constants for subtype constraints.
(Insert): Rewrite to avoid aliasing and function with
side-effects.
* libgnat/a-chtgfk.adb (Checked_Equivalent_Keys, Checked_Index,
Delete_Key_Sans_Free, Find, Generic_Replace_Element, Index):
Type for hash tables not tagged anymore.
(Generic_Conditional_Insert): New_Node generic formal is a
procedure taking the hash table as first parameter now, to avoid
aliasing in the caller.
* libgnat/a-chtgfk.ads: Same.
* libgnat/a-chtgfo.adb (Checked_Index, Clear,
Delete_Node_At_Index, Delete_Node_Sans_Free, First, Free,
Generic_Allocate, Generic_Iteration, Generic_Read,
Generic_Write, Index, Next): Type for hash tables not tagged
anymore.
(Generic_Equal): Removed tagged. Remove address comparison.
* libgnat/a-chtgfo.ads: Same.
* libgnat/a-cohata.ads (Hash_Table_Type): Remove tagged.

2 years ago[Ada] Remove dependency on tampering checks and controlled types for formal
Yannick Moy [Wed, 16 Feb 2022 12:56:50 +0000 (13:56 +0100)]
[Ada] Remove dependency on tampering checks and controlled types for formal

Formal hashed sets and maps are now using a different type of hash table
that does not require controlled types. This is possible because formal
containers do not rely on tampering checks, as cursors do not hold a
pointer to a single matching container, but are logical indexes that can
be used with multiple containers.

For simplicity of the package organisation, and symmetry with other
versions of containers, add a formal version of hashed types in the
shared Ada.Containers.Hash_Tables unit. This unit should be specialized
to only include the formal version of hash tables for runtimes that
do not support controlled types (so that the dependency on
Ada.Containers.Helpers can be removed).

The new versions of units for generic keys and operations are modified
versions of the units for bounded containers, with all tampering checks
removed (they were no-op in formal containers). A declaration of
constant Checks is added at the start of the body, as these units cannot
use the version in Ada.Containers.Helpers.

gcc/ada/

* Makefile.rtl: Add new files.
* libgnat/a-cfhama.adb: Use formal version of hash tables.
* libgnat/a-cfhama.ads: Same.
* libgnat/a-cfhase.adb: Same.
* libgnat/a-cfhase.ads: Same.
* libgnat/a-chtgfk.adb: New unit for formal containers, modified
version of Generic_Bounded_Keys.
* libgnat/a-chtgfk.ads: Same.
* libgnat/a-chtgfo.adb: New unit for formal containers, modified
version of Generic_Bounded_Operations.
* libgnat/a-chtgfo.ads: Same.
* libgnat/a-cohata.ads (Generic_Formal_Hash_Table_Types): Third
version of the type for hash tables, equivalent to the bounded
version without tampering checks.

2 years ago[Ada] Ada ABI change when building with assertions
Javier Miranda [Sun, 27 Feb 2022 11:42:46 +0000 (11:42 +0000)]
[Ada] Ada ABI change when building with assertions

Compiling with and without assertions enabled the name of some generated
symbols differ; this is an issue when using pre-built libraries.

gcc/ada/

* freeze.adb (Check_Inherited_Conditions): Dispatch table
wrappers must be placed in the list of entities of their scope
at the same place of their wrapped primitive. This is required
for private types since these wrappers are built when their full
tagged type declaration is frozen but they may override a
primitive defined in the public part of the package (and it is
important to maintain the wrapper in the list of public entities
of the package to ensure their correct visibility).

2 years ago[Ada] Take into account GNSA_ROOT env var for prefix
Johannes Kanig [Thu, 24 Feb 2022 10:47:47 +0000 (19:47 +0900)]
[Ada] Take into account GNSA_ROOT env var for prefix

The GNSA_ROOT environment variable can be used to indicate to the
compiler how to find the runtime directory.

gcc/ada/

* osint.ads, osint.adb (Relocate_Path): If the GNSA_ROOT
environment variable is set, we use that as the prefix, instead
of computing the prefix from the executable location.

2 years ago[Ada] Implement late initialization rules for type extensions
Steve Baird [Wed, 9 Feb 2022 01:43:14 +0000 (17:43 -0800)]
[Ada] Implement late initialization rules for type extensions

Default initialization of a record object is required to initialize any
components that "require late initialization" after other components.
This includes the case of a type extension; "late initialization"
components of the parent type are required to be initialized after
non-late-init extension components. This is implemented by generalizing
the use of an existing init proc parameter. Previously, the init proc
for a tagged type took a Boolean parameter indicating whether or not to
initialize the Tag component. With this change, this parameter can now
take on any of four values indicating whether to perform

   1) Full initialization (including the tag component).
   2) Full initialization except for the tag component.
   3) Early (non-tag) initialization only.
   4) Late (non-tag) initialization only.

With this change, the init proc for a type extension has the option of
performing the early and late portions of the parent's initialization
via two separate calls to the parent type's init proc.

gcc/ada/

* exp_ch3.ads (Build_Intialization_Call): Add new formal
parameter, Init_Control_Actual, with default value. Clients
outside of package Exp_Ch3 are unaffected.
* exp_ch3.adb (Initialization_Control): new package; support for
this 4-valued parameter.  The existing Requires_Late_Init
function is moved into this new package.
(Build_Initialization_Call): Add new formal parameter for
subprogram body, use this new formal parameter in generating an
init proc call.
(Build_Record_Init_Proc): Replace Set_Tag Boolean formal
parameter with 4-valued Init_Control_Formal. Wrap if-statements
with appropriate conditions around tag initialization, early
initialization, and late initialization statements.
* exp_util.adb (Build_Task_Image_Decl): Avoid problem with
duplicate declarations when an init proc for a type extension
calls the parent type's init proc twice.

2 years ago[Ada] Handle IN iterator for class-wide derived object of iterator type
Ed Schonberg [Tue, 15 Feb 2022 14:38:42 +0000 (15:38 +0100)]
[Ada] Handle IN iterator for class-wide derived object of iterator type

The compiler currently rejects iterating on an interface type derived
from an iterator type.

See Ada RM 5.5.1(6/3) and 5.5.2(3/3).

gcc/ada/

* sem_ch5.adb (Analyze_Iterator_Specification): Fix Typ in the
case of a class-wide derived iterator.

2 years ago[Ada] Facilitate proof of Overwrite in bounded strings library
Yannick Moy [Wed, 23 Feb 2022 11:58:42 +0000 (12:58 +0100)]
[Ada] Facilitate proof of Overwrite in bounded strings library

Consistently use >= operator in both the code and contracts of
function/procedure Overwrite, to facilitate proof, instead of the strict
inequality > sometimes, as only New_Item remains in the result in the
case of equal size too.

gcc/ada/

* libgnat/a-strbou.ads (Overwrite): Switch to >= operator in
contracts.
* libgnat/a-strsup.adb (Super_Overwrite): Switch to >= operator
in code of procedure (function already uses it).
* libgnat/a-strsup.ads (Super_Overwrite): Switch to >= operator
in contracts.

2 years ago[Ada] Fix code example on representation clause
Etienne Servais [Wed, 23 Feb 2022 10:44:42 +0000 (11:44 +0100)]
[Ada] Fix code example on representation clause

The column is superfluous, component names are missing.

gcc/ada/

* doc/gnat_rm/representation_clauses_and_pragmas.rst: Fix code
snippet.
* gnat_rm.texi: Regenerate.

2 years ago[Ada] Do not overwrite limited view of result type
Eric Botcazou [Sat, 19 Feb 2022 11:30:47 +0000 (12:30 +0100)]
[Ada] Do not overwrite limited view of result type

This removes obsolete code that overwrites a limited view present as the
result type of a function during the tentative analysis of prefixed
views for function calls involving tagged types. The original view is
necessary for the code generator to break the circularity present in
this setup.

The change also adds a couple of guards for the illegal case where the
limited view is the only view available when the function is invoked.

gcc/ada/

* aspects.adb (Find_Value_Of_Aspect): Add guard.
* sem_ch4.adb (Complete_Object_Operation): Remove obsolete code.
* sem_ch5.adb (Has_Sec_Stack_Default_Iterator): Add guard.

2 years ago[Ada] Wrong address for class-wide interface access conversion
Javier Miranda [Tue, 15 Feb 2022 18:39:42 +0000 (18:39 +0000)]
[Ada] Wrong address for class-wide interface access conversion

The compiler generates wrong code on instantiations of package
Address_To_Access_Conversions when the generic formal is a class-wide
interface type; this causes wrong dispatching calls when the
access-to-class-wide-interface object returned by To_Pointer is used to
dispatch a call.

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference): The expansion of
'Address in a call to an instantiation of the implicit
subprogram To_Pointer with a class-wide interface type target
requires adding an implicit type conversion to force
displacement of the "this" pointer.

2 years ago[Ada] Crash in task body reference to discriminant
Javier Miranda [Sun, 6 Feb 2022 11:23:53 +0000 (11:23 +0000)]
[Ada] Crash in task body reference to discriminant

The compiler may crash processing the successor or predecessor of a task
type discrete discriminant.

gcc/ada/

* sem_attr.adb (Resolve_Attribute): Ensure that attribute
expressions are resolved at this stage; required for preanalyzed
references to discriminants since their resolution (and
expansion) will take care of updating their Entity attribute to
reference their discriminal.

2 years ago[Ada] Improve expected type error messages
Justin Squirek [Mon, 31 Jan 2022 21:51:38 +0000 (21:51 +0000)]
[Ada] Improve expected type error messages

This patch improves error messages concerning type mismatches by
printing the actual expected type in more cases instead of the expected
type's first subtype.

gcc/ada/

* sem_util.adb (Wrong_Type): Avoid using the first subtype of
the expected type in error messages when the expected type is
not internally generated.

2 years ago[Ada] Document control flow redundancy
Alexandre Oliva [Wed, 9 Feb 2022 09:25:13 +0000 (06:25 -0300)]
[Ada] Document control flow redundancy

Add documentation about -fharden-control-flow-redundancy.

gcc/ada/

* doc/gnat_rm/security_hardening_features.rst: Add subsection on
Control Flow Redundancy.
* gnat_rm.texi: Regenerate.

2 years ago[Ada] Fix compiler crash on FOR iteration scheme over container
Eric Botcazou [Thu, 17 Feb 2022 17:20:01 +0000 (18:20 +0100)]
[Ada] Fix compiler crash on FOR iteration scheme over container

The front-end drops a freeze node on the floor because it puts the node
into the Condition_Actions of an N_Iteration_Scheme of a FOR loop.

gcc/ada/

* exp_util.adb (Insert_Actions) <N_Iteration_Scheme>: Check that
it is a WHILE iteration scheme before using Condition_Actions.

2 years ago[Ada] Remove obsolete uses of Unchecked_Conversion from Ada 83
Piotr Trojanek [Wed, 9 Feb 2022 21:32:19 +0000 (22:32 +0100)]
[Ada] Remove obsolete uses of Unchecked_Conversion from Ada 83

Similar to a recent removal of obsolete uses of Unchecked_Deallocation.

In Ada 83 the Unchecked_Conversion was a top-level unit; since Ada 95 it
is an obsolete renaming of Ada.Unchecked_Conversion. GNAT doesn't warn
yet about uses of these obsolete renamings, but it still seems better to
avoid them.

gcc/ada/

* atree.adb, gen_il-gen.adb, osint.adb, set_targ.adb,
sinput.adb, table.adb, treepr.adb, types.ads: Replace uses of
Unchecked_Conversion in the compiler itself.
* libgnarl/a-reatim.adb, libgnarl/s-osinte__gnu.ads,
libgnarl/s-osinte__kfreebsd-gnu.ads, libgnat/a-coboho.adb,
libgnat/a-stuten.ads, libgnat/s-putima.adb: Likewise in the
runtime.
* doc/gnat_ugn/gnat_and_program_execution.rst: Likewise in
documentation.
* gnat_ugn.texi: Regenerate.