official-gcc.git
34 min agoUpdate the C FE routine "add_flexible_array_elts_to_size" C++ FE routine "layout_var_... mastertrunk
Qing Zhao [Mon, 6 May 2024 16:28:01 +0000 (6 16:28 +0000)]
Update the C FE routine "add_flexible_array_elts_to_size" C++ FE routine "layout_var_decl" to handle the cases when the DECL is union.

PR c/53548

Add testing cases to test the _bos for flexible array members in unions
or alone in structures.

gcc/c/ChangeLog:

PR c/53548
* c-decl.cc (add_flexible_array_elts_to_size): Handle the cases
when the DECL is union.

gcc/cp/ChangeLog:

PR c/53548
* decl.cc (layout_var_decl): Handle the cases when the DECL is
union with a flexible array member initializer.

gcc/testsuite/ChangeLog:

PR c/53548
* c-c++-common/fam-in-union-alone-in-struct-bos-1.c: New test.
* c-c++-common/fam-in-union-alone-in-struct-bos.c: New test.

35 min agoAdd testing cases for flexible array members in unions and alone in structures.
Qing Zhao [Mon, 6 May 2024 16:27:09 +0000 (6 16:27 +0000)]
Add testing cases for flexible array members in unions and alone in structures.

PR c/53548

gcc/testsuite/ChangeLog:

PR c/53548
* c-c++-common/fam-in-union-alone-in-struct-1.c: New testcase.
* c-c++-common/fam-in-union-alone-in-struct-2.c: New testcase.
* c-c++-common/fam-in-union-alone-in-struct-3.c: New testcase.

36 min agoC and C++ FE changes to support flexible array members in unions and alone in structu...
Qing Zhao [Mon, 6 May 2024 16:26:19 +0000 (6 16:26 +0000)]
C and C++ FE changes to support flexible array members in unions and alone in structures. Adjust testcases for flexible array member in union and alone in structure extension.

PR c/53548

gcc/c/ChangeLog:

PR c/53548
* c-decl.cc (finish_struct): Change errors to pedwarns for the cases
flexible array members in union or alone in structures.

gcc/cp/ChangeLog:

PR c/53548
* class.cc (diagnose_flexarrays): Change error to pdewarn for the case
flexible array members alone in structures.
* decl.cc (grokdeclarator): Change error to pdewarn for the case
flexible array members in unions.

gcc/ChangeLog:

PR c/53548
* stor-layout.cc (place_union_field): Use zero sizes for flexible array
member fields.

gcc/testsuite/ChangeLog:

PR c/53548
* c-c++-common/builtin-clear-padding-3.c: Adjust testcase.
* g++.dg/ext/flexary12.C: Likewise.
* g++.dg/ext/flexary19.C: Likewise.
* g++.dg/ext/flexary2.C: Likewise.
* g++.dg/ext/flexary3.C: Likewise.
* g++.dg/ext/flexary36.C: Likewise.
* g++.dg/ext/flexary4.C: Likewise.
* g++.dg/ext/flexary5.C: Likewise.
* g++.dg/ext/flexary8.C: Likewise.
* g++.dg/torture/pr64280.C: Likewise.
* gcc.dg/20050620-1.c: Likewise.
* gcc.dg/940510-1.c: Likewise.

38 min agoAllow flexible array members in unions and alone in structures [PR53548]
Qing Zhao [Mon, 6 May 2024 16:25:04 +0000 (6 16:25 +0000)]
Allow flexible array members in unions and alone in structures [PR53548]

The request for GCC to accept that the C99 flexible array member can be
in a union or alone in a structure has been made a long time ago around 2012
for supporting several practical cases including glibc.

A GCC PR has been opened for such request at that time:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53548

However, this PR was closed as WONTFIX around 2015 due to the following reason:

"there is an existing extension that makes the requested functionality possible"
i.e GCC fully supported that the zero-length array can be in a union or alone
in a structure for a long time. (though I didn't see any official documentation
on such extension)

It's reasonable to close PR53548 at that time since zero-length array extension
can be used for such purpose.

However, since GCC13, in order to improve the C/C++ security, we introduced
-fstrict-flex-arrays=n to gradually eliminate the "fake flexible array"
usages from C/C++ source code. As a result, zero-length arrays eventually
will be replaced by C99 flexiable array member completely.

Therefore, GCC needs to explicitly allow such extensions directly for C99
flexible arrays, since flexable array member in unions or alone in structs
are common code patterns in active use by the Linux kernel (and other projects).

For example, these do not error by default with GCC:

union one {
  int a;
  int b[0];
};

union two {
  int a;
  struct {
    struct { } __empty;
    int b[];
  };
};

But these do:

union three {
  int a;
  int b[];
};

struct four {
  int b[];
}

Clang has supported such extensions since March, 2024
https://github.com/llvm/llvm-project/pull/84428

GCC should also support such extensions. This will allow for
a seamless transition for code bases away from zero-length arrays without
losing existing code patterns.

gcc/ChangeLog:

PR c/53548
* doc/extend.texi: Add documentation for Flexible Array Members in
Unions and Flexible Array Members alone in Structures.

119 min agoAVR: ipa/92606 - Don't optimize PROGMEM data against non-PROGMEM.
Georg-Johann Lay [Fri, 3 May 2024 16:47:50 +0000 (3 18:47 +0200)]
AVR: ipa/92606 - Don't optimize PROGMEM data against non-PROGMEM.

ipa/92606: Inter-procedural analysis optimizes data across
address-spaces and PROGMEM.  As of v14, the PROGMEM part is
still not fixed (and there is still no target hook as proposed
in PR92932).  Just disable respective bogus optimization.

PR ipa/92606
gcc/
* config/avr/avr.cc (avr_option_override): Set
flag_ipa_icf_variables = 0.
gcc/testsuite/
* gcc.target/avr/torture/pr92606.c: New test.

2 hours agocontrib/gcc-changelog/git_check_commit.py: Implement --num-commits
Ken Matsui [Wed, 28 Feb 2024 21:00:23 +0000 (28 13:00 -0800)]
contrib/gcc-changelog/git_check_commit.py: Implement --num-commits

This patch implements a --num-commits (-n) flag for shorthand for
the range of hash~N..hash commits.

contrib/ChangeLog:

* gcc-changelog/git_check_commit.py: Implement --num-commits.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
4 hours agoOpenMP: Fix for ICE in tree-nested.cc.
Sandra Loosemore [Mon, 22 Apr 2024 18:24:25 +0000 (22 18:24 +0000)]
OpenMP: Fix for ICE in tree-nested.cc.

Use gimple_omp_target_clauses() instead of gimple_omp_taskreg_clauses()
when stmt is GIMPLE_OMP_TARGET, to avoid an as_a<> ICE.  The code
immediately following this is already conditionalized in the same way.

gcc/ChangeLog
* tree-nested.cc (convert_tramp_reference_stmt): Use the correct
accessor for GIMPLE_OMP_TARGET clauses.

5 hours agotree-optimization/100923 - re-do VN with contextual PTA info fix
Richard Biener [Wed, 28 Feb 2024 09:08:31 +0000 (28 10:08 +0100)]
tree-optimization/100923 - re-do VN with contextual PTA info fix

The following implements the gist of the PR100923 fix in a leaner
(and more complete) way by realizing that all ao_ref_init_from_vn_reference
uses need to have an SSA name in the base valueized with availability
in mind.  Instead of re-valueizing the whole chain of operands we can
simply only and always valueize the SSA name we put in the base.

This handles also two omitted places in vn_reference_lookup_3.

PR tree-optimization/100923
* tree-ssa-sccvn.cc (ao_ref_init_from_vn_reference): Valueize
base SSA_NAME.
(vn_reference_lookup_3): Adjust vn_context_bb around calls
to ao_ref_init_from_vn_reference.
(vn_reference_lookup_pieces): Revert original PR100923 fix.
(vn_reference_lookup): Likewise.

5 hours agoComplete ao_ref_init_from_vn_reference for all refs
Richard Biener [Tue, 27 Feb 2024 12:55:15 +0000 (27 13:55 +0100)]
Complete ao_ref_init_from_vn_reference for all refs

This makes sure we can create ao_refs from all VN operands we create.

* tree-ssa-sccvn.cc (ao_ref_init_from_vn_reference): Add
TARGET_MEM_REF support.  Handle more bases.

9 hours agoada: Allow use of writable parameters inside function with side-effects
Piotr Trojanek [Thu, 4 Jan 2024 16:37:06 +0000 (4 17:37 +0100)]
ada: Allow use of writable parameters inside function with side-effects

Writable parameters can be used as global outputs inside functions with
side-effects.

gcc/ada/

* sem_prag.adb (Collect_Global_Item): Handle functions with
side-effects.

9 hours agoada: Cleanup collecting of implicit outputs
Piotr Trojanek [Thu, 4 Jan 2024 16:10:47 +0000 (4 17:10 +0100)]
ada: Cleanup collecting of implicit outputs

Move handling of IN parameters to where both IN and IN OUT parameters
are handled. This makes the code marginally more efficient and
symmetrical to handling of implicit inputs.

gcc/ada/

* sem_prag.adb (Collect_Global_Item): Move code.

9 hours agoada: Support writable parameters in Depends with side-effects
Piotr Trojanek [Thu, 4 Jan 2024 14:01:55 +0000 (4 15:01 +0100)]
ada: Support writable parameters in Depends with side-effects

Functions with side-effects can modify writable parameters of mode IN,
so these parameters must be allowed to appear in their Depends aspects.

gcc/ada/

* sem_prag.adb (Find_Role): Handle functions with side-effects
like procedures.

9 hours agoada: Excess finalization on return of call to dispatching constructor
Gary Dismukes [Thu, 4 Jan 2024 00:34:33 +0000 (4 00:34 +0000)]
ada: Excess finalization on return of call to dispatching constructor

The compiler expands a too-early finalization call for the result
object of an extended return statement that returns a call to a
dispatching constructor function for a limited interface type,
resulting in premature (and extra) finalization of the result.
The temporary object that the compiler creates to hold the result
of the build-in-place call loses the fact that it comes from a
return, and the wrong BIP allocation form may be passed in the
call to the dispatching constructor, and the later code for dealing
with finalization in Exp_Ch7.Build_Finalizer incorrectly finalizes
the result object.

gcc/ada/

* exp_ch6.adb
(Make_Build_In_Place_Iface_Call_In_Object_Declaration): Set the
Is_Return_Object flag on the entity of the temp object created to
hold the BIP call result, from the flag on the passed-in object
declaration's entity. Update copyright notice to 2024.

9 hours agoada: Give error for reference to nonvisible library unit
Bob Duff [Wed, 3 Jan 2024 21:32:51 +0000 (3 16:32 -0500)]
ada: Give error for reference to nonvisible library unit

This patch fixes a bug where the compiler would allow
a name X to refer to a library unit that is not visible.
In particular, this happens when the name X occurs in the
private part of a library package, and the parent of that
package contains an instantiation of a generic package, and the
spec of that generic package has "private with X;",
but there is no "private with X;" or "with X;" that applies
to the place where the name X occurs.

Also misc cleanup.

gcc/ada/

* sem_ch10.adb (Expand_With_Clause): Misc cleanup.
(Install_Private_With_Clauses): Avoid installing a private
with_clause that comes from an instantiated generic
(it is marked as Implicit_With, but doesn't come from a parent
with). Fix typo in comment, and other minor cleanups.

9 hours agoada: Tweak discriminant source locations
Ronan Desplanques [Wed, 3 Jan 2024 11:09:03 +0000 (3 12:09 +0100)]
ada: Tweak discriminant source locations

This patch changes the source location information for the default
expressions of discrimants to better represent the fact that they're
evaluated at the point of object declaration, in the cases where
a Build_Default_Subtype optimization is performed. This fixes a
regression with CodePeer diagnostics introduced by a recent change
around Build_Default_Subtype optimizations.

gcc/ada/

* sem_util.adb (Build_Default_Subtype): Tweak source location
information.

9 hours agoada: Do not attempt to generate finalization actions with restricted profile
Eric Botcazou [Fri, 22 Dec 2023 11:46:29 +0000 (22 12:46 +0100)]
ada: Do not attempt to generate finalization actions with restricted profile

These actions are not supported with this profile, but we were nevertheless
attempting to generate them for protected objects.

gcc/ada/

* exp_ch7.adb (Build_Finalizer.Process_Declarations): Do not call
Processing_Actions for simple protected objects if the profile is
restricted.
* exp_util.adb (Requires_Cleanup_Actions): Do not return True for
simple protected objects if the profile is restricted.

9 hours agoada: Small cleanup in C/C++ front-end interface
Eric Botcazou [Thu, 21 Dec 2023 21:56:16 +0000 (21 22:56 +0100)]
ada: Small cleanup in C/C++ front-end interface

The fe.h header file is supposed to contain only the declarations needed
by the code in the gcc-interface repository.

gcc/ada/

* fe.h: Remove unused declarations and add 'extern' to others.

no-issue-check

9 hours agoada: Deconstruct support for abstract states with Relaxed_Initialization
Piotr Trojanek [Thu, 21 Dec 2023 16:31:51 +0000 (21 17:31 +0100)]
ada: Deconstruct support for abstract states with Relaxed_Initialization

GNATprove newer implemented support for abstract states with aspect
Relaxed_Initialization, so the frontend support is now deconstructed.

gcc/ada/

* einfo-utils.adb (Is_Relaxed_Initialization_State): Remove.
* einfo-utils.ads (Is_Relaxed_Initialization_State): Remove.
* einfo.ads: Remove description of removed aspect.
* fe.h (Is_Relaxed_Initialization_State): Remove.
* sem_prag.adb (Analyze_Abstract_State): Remove support for
Relaxed_Initialization.
* sem_util.adb (Has_Relaxed_Initialization): Likewise.
* sem_util.ads (Has_Relaxed_Initialization): Likewise.

9 hours agoada: Spurious reference warning on qualified expression
Justin Squirek [Thu, 21 Dec 2023 18:41:15 +0000 (21 18:41 +0000)]
ada: Spurious reference warning on qualified expression

Incremental improvement/clean up.

gcc/ada/

* sem_warn.adb (Within_Postcondition): Add coverage for
Preconditions

9 hours agoada: Spurious reference warning on qualified expression
Justin Squirek [Thu, 21 Dec 2023 18:38:38 +0000 (21 18:38 +0000)]
ada: Spurious reference warning on qualified expression

Incremental improvement/clean up.

gcc/ada/

* sem_warn.adb (Within_Postcondition): Add/modify comments to
document various cases.

9 hours agoada: Spurious reference warning on qualified expression
Justin Squirek [Thu, 21 Dec 2023 18:35:22 +0000 (21 18:35 +0000)]
ada: Spurious reference warning on qualified expression

Incremental improvement/clean up.

gcc/ada/

* sem_warn.adb (Within_Postcondition): Renamed to
Within_Contract_Or_Predicate.

9 hours agoada: Spurious reference warning on qualified expression
Justin Squirek [Thu, 21 Dec 2023 18:31:27 +0000 (21 18:31 +0000)]
ada: Spurious reference warning on qualified expression

This patch fixes an error in the compiler whereby an assignment to an out
formal (whose type requires a predicate check) can lead to spurious
"value may be referenced before it has a value" warnings when the RHS is a
qualified expression.

gcc/ada/

* sem_warn.adb (Within_Postcondition): Add case to ignore
references within generated predicate function calls.

9 hours agoada: Fix RM reference in comment
Ronan Desplanques [Thu, 21 Dec 2023 11:39:23 +0000 (21 12:39 +0100)]
ada: Fix RM reference in comment

The RM 2.2(15) that the comment mentioned before this patch doesn't
exist. It's pretty clear that the comment meant to refer to
RM 2.2(14) instead.

gcc/ada/

* hostparm.ads: Fix reference to RM clause.

9 hours agoada: Make a couple of comment tweaks
Eric Botcazou [Thu, 21 Dec 2023 11:01:06 +0000 (21 12:01 +0100)]
ada: Make a couple of comment tweaks

This removes a reference to a mechanism that didn't make it into the final
implementation and completes the description of another.

gcc/ada/

* libgnat/s-finpri.ads (Finalize_Master): Remove obsolete reference
in the description.
(Finalize_Object): Document the effects of repeated calls.

9 hours agoada: Rework processing of special objects needing finalization
Eric Botcazou [Wed, 20 Dec 2023 16:39:10 +0000 (20 17:39 +0100)]
ada: Rework processing of special objects needing finalization

This reworks the processing of special objects needing finalization in the
new implementation.  These special objects, i.e. return object in extended
return statements and transient objects, cannot be automatically handled by
the post-processing phase because they have additional requirements, either
conditional finalization for the former or immediate finalization for the
latter and, therefore, a specific processing during expansion is needed for
them before the post-processing phase can complete the work.

The previous scheme used to do minimal processing during expansion, leaving
the bulk of the work to the post-processing phase. Unfortunately this scheme
turned out not to be stable for Expression_With_Actions nodes under copying
by means of New_Copy_Tree or equivalent devices. The new scheme moves a bit
more processing to the expansion, namely the generation of the attachment to
the master node, whose result can then be naturally copied by New_Copy_Tree.

A side effect is to further simplify the implementation of Build_Finalizer
in Exp_Ch7, which has one fewer special case to deal with.

gcc/ada/

* einfo.ads (Finalization_Master_Node_Or_Object): Rename into...
(Finalization_Master_Node): ...this and adjust description.
* exp_ch4.adb (Process_Transient_In_Expression): Attach the object
to its master node here.
* exp_ch7.ads (Attach_Object_To_Master_Node): New declaration.
* exp_ch7.adb (Attach_Object_To_Master_Node): New procedure.
(Build_Finalizer.Process_Declarations): Examine the type of a
variable to spot master nodes.
(Build_Finalizer.Process_Object_Declaration): Look only at the
object and deal specifically with the case of a master node.
(Build_Finalizer.Build_BIP_Cleanup_Stmts): Move to child function
of Attach_Object_To_Master_Node.
(Build_Finalizer.Make_Address_For_Finalize): Move to...
(Insert_Actions_In_Scope_Around.Process_Transient_In_Scope): Attach
the object to its master node here.
(Make_Address_For_Finalize): ...here.
(Make_Master_Node_Declaration): Adjust to above renaming and set
Finalization_Master_Node only on the object.
(Make_Suppress_Object_Finalize_Call): Adjust to above renaming and
attach the object to its master node here.
* exp_util.adb (Requires_Cleanup_Actions): Examine the type of a
variable to spot master nodes.
* gen_il-fields.ads (Opt_Field_Enum): Adjust to above renaming.
* gen_il-gen-gen_entities.adb (Allocatable_Kind): Likewise.
* rtsfind.ads (RE_Id): Add RE_Chain_Node_To_Master.
(RE_Unit_Table): Add entry for  RE_Chain_Node_To_Master.
* libgnat/s-finpri.ads (Chain_Node_To_Master): New declaration.
* libgnat/s-finpri.adb (Chain_Node_To_Master): New procedure.
(Attach_Object_To_Master): Call it.
(Finalize_Master): Do not raise Program_Error on null addresses.
(Finalize_Object): Add assertion that the address is not null.

9 hours agoada: Replace references to PO_Simple by Protected_Objects in comments
Eric Botcazou [Wed, 20 Dec 2023 15:27:09 +0000 (20 16:27 +0100)]
ada: Replace references to PO_Simple by Protected_Objects in comments

The child unit was renamed a while ago.

gcc/ada/

* libgnarl/s-taprob.ads (Protection): Add cross-reference to the
counterpart in System.Tasking.Protected_Objects.Entries.
* libgnarl/s-taskin.ads (Locking Rules): Replace PO_Simple by
Protected_Objects.
* libgnarl/s-tpoben.ads (Protection_Entries): Likewise.

9 hours agoada: Fix wrong Finalization_Size for No_Heap_Finalization objects
Eric Botcazou [Sat, 16 Dec 2023 10:34:48 +0000 (16 11:34 +0100)]
ada: Fix wrong Finalization_Size for No_Heap_Finalization objects

When an access type is subject to the No_Heap_Finalization pragma, no header
is added in front of objects allocated through it, and the value returned by
Finalization_Size is defined to be the size of this header.

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference) <Finalization_Size>:
Return 0 if the prefix is a dereference of an access value subject
to the No_Heap_Finalization pragma.

9 hours agoada: Fix spurious warning emission
Ronan Desplanques [Tue, 19 Dec 2023 16:13:20 +0000 (19 17:13 +0100)]
ada: Fix spurious warning emission

This patch fixes a bug where GNAT would emit incorrect warnings
about obsolescent syntax for array aggregates with generics and
particular arrangements of Ada version pragmas.

This patch also removes a syntactic field that was introduced to
support the emission of this warning, but is no longer required.

gcc/ada/

* exp_imgv.adb (Append_Table_To): Remove reference to removed
field.
* gen_il-fields.ads: Remove Is_Enum_Array_Aggregate field.
* gen_il-gen-gen_nodes.adb: Likewise.
* sem_aggr.adb: Tweak warning emission condition.
* sinfo.ads: Remove documentation for Is_Enum_Array_Aggregate.

9 hours agoada: Replace redundant conditions with assertions
Piotr Trojanek [Tue, 19 Dec 2023 09:23:55 +0000 (19 10:23 +0100)]
ada: Replace redundant conditions with assertions

Fix warnings from the CodePeer. The code structure is essentially:

  if A and B then ...
  elsif not A and not B then ...
  elsif A then ...
  elsif B then ...  --  this condition is redundant
  end if;

and it causes CodePeer to say "exception is raised in a conditional
branch", which most likely means that the condition is redundant.

gcc/ada/

* make.adb (Scan_Make_Arg): Remove redundant condition.
* switch-b.adb (Scan_Debug_Switches): Likewise.
* switch-c.adb (Scan_Front_End_Switches): Likewise.

9 hours agoada: Fix detection of (Un)Hide_Info pragma in GNATprove mode
Yannick Moy [Tue, 19 Dec 2023 09:52:38 +0000 (19 10:52 +0100)]
ada: Fix detection of (Un)Hide_Info pragma in GNATprove mode

Spec or body may not be in a list for subunit.

gcc/ada/

* inline.adb (Can_Be_Inlined_In_GNATprove_Mode): Add guard.

9 hours agoada: Fix missing associated node for packed array itypes
Piotr Trojanek [Mon, 18 Dec 2023 13:31:52 +0000 (18 14:31 +0100)]
ada: Fix missing associated node for packed array itypes

After decoration, itypes should have its associated node set.

gcc/ada/

* exp_pakd.adb (Create_Packed_Array_Impl_Type): Set associated
node for the packed array itype.
* exp_util.adb (Possible_Side_Effect_In_SPARK): Remove
workaround for a missing associated node.

9 hours agoada: Don't propagate convention to internal subprograms
Richard Kenner [Sun, 17 Dec 2023 12:47:44 +0000 (17 07:47 -0500)]
ada: Don't propagate convention to internal subprograms

AI95-117 requires that all new primitives of a tagged type must
inherit the convention of the full view of the type. However, we need
not do this for primitives that are internally-generated, such as for
finalization. There are issues with GNAT LLVM when primitives have
convention C since the UC from that subprogram type to the type used
in the dispatch table will generate a warning. We're not doing
anything here about the case where the convention C is explicit or
there are user-specified primitives on a type with convention C, but
let's not make the problem worse by putting convention C on internal
subprograms.

gcc/ada/

* freeze.adb (Freeze_Entity): When changing the convention of
primitive to match that of the type, only do this for user-specified
primitives.

9 hours agoada: Fix memory leak in 'Image
Bob Duff [Fri, 15 Dec 2023 21:59:43 +0000 (15 16:59 -0500)]
ada: Fix memory leak in 'Image

Fix memory leak in 'Image by managing the secondary stack
in scopes that call the new Ada 2020 'Image, which calls 'Put_Image
and then Get, which returns on the secondary stack.

gcc/ada/

* exp_put_image.adb (Build_Image_Call): Call Set_Uses_Sec_Stack on
the current scope. We don't do this at all call sites, because
there are three; better to do it here.

9 hours agoada: Extend Round attribute to ordinary fixed point types
Eric Botcazou [Sat, 16 Dec 2023 12:20:06 +0000 (16 13:20 +0100)]
ada: Extend Round attribute to ordinary fixed point types

The attribute is only defined by the language for decimal fixed point
types (RM 3.5.10(12)) but it could be useful to have it for ordinary
fixed point types too because conversions from floating point truncate
in both cases.

gcc/ada/

* sem_attr.adb (Analyze_Attribute) <Attribute_Round>: Also accept it
for ordinary fixed point types.
* doc/gnat_rm/implementation_defined_attributes.rst (Round): New.
* gnat_rm.texi: Regenerate.

9 hours agoada: Fix non-idiomatic construct
Eric Botcazou [Fri, 15 Dec 2023 18:07:44 +0000 (15 19:07 +0100)]
ada: Fix non-idiomatic construct

gcc/ada/

* exp_ch3.adb (Expand_Freeze_Class_Wide_Type): Use No instead of
not Present.

9 hours agoada: Adjust source location for degenerate scope master
Eric Botcazou [Fri, 15 Dec 2023 12:08:38 +0000 (15 13:08 +0100)]
ada: Adjust source location for degenerate scope master

When the finalization scope master degenerates into a simple master node,
the latter must inherit the source location that the former would have had.

gcc/ada/

* exp_ch7.adb (Build_Finalizer.Process_Object_Declaration): Adjust
the Sloc of the master node declaration in the degenerate case.

9 hours agoada: Prevent inlining in GNATprove for memory leaks
Yannick Moy [Wed, 13 Dec 2023 16:40:03 +0000 (13 17:40 +0100)]
ada: Prevent inlining in GNATprove for memory leaks

In some cases, inlining a call in GNATprove could lead to
missing a memory leak. Recognize such cases and do not inline
such calls.

gcc/ada/

* inline.adb (Call_Can_Be_Inlined_In_GNATprove_Mode):
Add case to prevent inlining of call.
* inline.ads: Likewise.
* sem_res.adb (Resolve_Call): Update comment and message.

9 hours agoada: Partial implementation of redesign of support for object finalization
Eric Botcazou [Thu, 21 Sep 2023 21:27:44 +0000 (21 23:27 +0200)]
ada: Partial implementation of redesign of support for object finalization

This set of changes is a partial reimplemention of the support for Ada
finalization in the GNAT compiler and run-time library, based on the
redesign done by Hristian Kirtchev in February 2022.  It only affects
the scope-based finalization of objects and does not touch the support
for finalization of dynamically allocated objects.

It also does not modify the internal architecture of this support in the
front-end but only changes its output, i.e. the expanded code.  In other
words, the code-based dispatching scheme in finalizers and the hook-based
approach for transient objects are replaced by finalization scope masters
and master nodes, which maintain a list of objects needing finalization,
but the expansion of the code that builds these masters is still performed
mainly during a dedicated post-processing phase.

gcc/ada/

* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add s-finpri$(objext).
* contracts.adb (Add_Call_Helper): Append freeze actions to the
class-wide type rather than the specific tagged type.
* einfo.ads (Finalization_Master_Node_Or_Node): Document.
(Status_Flag_Or_Transient_Decl): Remove.
* exp_attr.adb (Expand_N_Attribute_Reference) <Address>: Do not
adjust a return object of a class-wide interface type.
* exp_ch3.adb  (Expand_Freeze_Class_Wide_Type): Add test that
Finalize_Address is not already present as a condition for calling
Make_Finalize_Address_Body.
(Expand_Freeze_Record_Type): Call Make_Finalize_Address_Body for
class-wide types of both regular tagged types and interface types.
* exp_ch4.adb (Process_Transients_In_Expression): Replace the use
of hooks with the use of master nodes.
* exp_ch6.adb (Build_Flag_For_Function): Delete.
(Expand_N_Extended_Return_Statement): Create a master node for the
return object if it does not exist.  At the end of the statement,
generate a call to Suppress_Object_Finalize.
(Expand_Non_Function_Return): Likewise just before the return.
* exp_ch7.ads (Make_Master_Node_Declaration): Declare.
(Make_Suppress_Object_Finalize_Call): Likewise.
* exp_ch7.adb (Build_Finalization_Master): Defer generating the
call to Set_Finalize_Address until freezing if the Finalize_Address
procedure has not been analyzed yet.
(Build_Finalizer): Reimplement the expansion using a finalization
scope master per finalizer.
(Insert_Actions_In_Scope_Around): Replace finalization hooks by
master nodes and calls to the Finalize_Object.
(Make_Master_Node_Declaration): New procedure.
(Make_Suppress_Object_Finalize_Call): Likewise.
* exp_util.ads (Build_Transient_Object_Statements): Delete.
* exp_util.adb (Build_Transient_Object_Statements): Likewise.
(Requires_Cleanup_Actions): Remove obsolete code and return true
for master nodes.
* gen_il-fields.ads (Opt_Field_Enum): Add
Finalization_Master_Node_Or_Object and
remove Status_Flag_Or_Transient_Decl.
* gen_il-gen-gen_entities.adb (Allocatable_Kind): Likewise.
* rtsfind.ads (RTU_Id): Add System_Finalization_Primitives.
(RE_Id): Add entities of System_Finalization_Primitives.
(RE_Unit_Table): Add entries for them.
* sem_ch3.adb (Analyze_Object_Declaration): For an array whose type
has an unconstrained first subtype and a controlled component, set
the Is_Constr_Array_Subt_With_Bounds flag.
* libgnat/s-finpri.ads: New file.
* libgnat/s-finpri.adb: Likewise.

9 hours agoada: Do not inline in GNATprove the subprograms with (Un)Hide_Info
Yannick Moy [Wed, 13 Dec 2023 14:38:59 +0000 (13 15:38 +0100)]
ada: Do not inline in GNATprove the subprograms with (Un)Hide_Info

The annotations Hide_Info and Unhide_Info in GNATprove are meant to
give special visibility in the corresponding scope to the precise definition
of some entities. Hence, such scopes should not be inlined in GNATprove.

gcc/ada/

* inline.adb (Can_Be_Inlined_In_GNATprove_Mode): Adapt checking.

11 hours agolibgfortran: Fix libgfortran.so versioning on Solaris with subdirs
Rainer Orth [Mon, 6 May 2024 07:31:11 +0000 (6 09:31 +0200)]
libgfortran: Fix libgfortran.so versioning on Solaris with subdirs

The move of libgfortran objects to subdirectories completely broke the
creation of libgfortran.so on Solaris.  Since the gfortran.ver-sun rule
doesn't support that structure, no libtool objects are found, thus no
symbols exported from libgfortran.so, causing every link to fail.

This patch fixes this by allowing for the new structure.

Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11.

2024-05-05  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

libgfortran:
* Makefile.am [LIBGFOR_USE_SYMVER_SUN] (gfortran.ver-sun): Handle
objects in subdirs.
* Makefile.in: Regenerate.

14 hours agoexpmed: TRUNCATE value1 if needed in store_bit_field_using_insv
YunQiang Su [Sun, 28 Apr 2024 16:33:44 +0000 (29 00:33 +0800)]
expmed: TRUNCATE value1 if needed in store_bit_field_using_insv

PR target/113179.

In `store_bit_field_using_insv`, we just use SUBREG if value_mode
>= op_mode, while in some ports, a sign_extend will be needed,
such as MIPS64:
  If either GPR rs or GPR rt does not contain sign-extended 32-bit
  values (bits 63..31 equal), then the result of the operation is
  UNPREDICTABLE.

The problem happens for the code like:
  struct xx {
        int a:4;
        int b:24;
        int c:3;
        int d:1;
  };

  void xx (struct xx *a, long long b) {
        a->d = b;
  }

In the above code, the hard register contains `b`, may be note well
sign-extended.

gcc/
PR target/113179
* expmed.cc(store_bit_field_using_insv): TRUNCATE value1 if
needed.

gcc/testsuite
PR target/113179
* gcc.target/mips/pr113179.c: New tests.

15 hours agoconfig-ml.in: Fix multi-os-dir search
YunQiang Su [Sun, 5 May 2024 15:12:37 +0000 (5 23:12 +0800)]
config-ml.in: Fix multi-os-dir search

When building multilib libraries, CC/CXX etc are set with an option
-B*/lib/, instead of -B<something>/lib/<multi-os-directory>.
This will make some trouble in some case, for example building
cross toolchain based on Debian's cross packages:

  If we have libc6-dev-i386-amd64-cross packages installed on
  a non-x86 machine. This package will have the files in
  /usr/x86_4-linux-gnu/lib32.  The fellow configure will fail
  when build libgcc for i386, with complains the libc is not
  i386 ones:
     ../configure --enable-multilib --enable-multilib \
            --target=x86_64-linux-gnu

Let's insert a "-B*/lib/`CC ${flags} --print-multi-os-directory`"
before "-B*/lib/".

This patch is based on the patch used by Debian now.

ChangeLog

* config-ml.in: Insert an -B option with multi-os-dir into
compiler commands used to build libraries.

18 hours agoDaily bump.
GCC Administrator [Mon, 6 May 2024 00:16:49 +0000 (6 00:16 +0000)]
Daily bump.

24 hours agoFortran: fix issues with class(*) assignment [PR114827]
Harald Anlauf [Mon, 29 Apr 2024 17:52:52 +0000 (29 19:52 +0200)]
Fortran: fix issues with class(*) assignment [PR114827]

gcc/fortran/ChangeLog:

PR fortran/114827
* trans-array.cc (gfc_alloc_allocatable_for_assignment): Take into
account _len of unlimited polymorphic entities when calculating
the effective element size for allocation size and array span.
Set _len of lhs to _len of rhs.
* trans-expr.cc (trans_class_assignment): Take into account _len
of unlimited polymorphic entities for allocation size.

gcc/testsuite/ChangeLog:

PR fortran/114827
* gfortran.dg/asan/unlimited_polymorphic_34.f90: New test.

35 hours agoUpdate libbid according to the latest Intel Decimal Floating-Point Math Library.
liuhongt [Wed, 27 Mar 2024 00:20:13 +0000 (27 08:20 +0800)]
Update libbid according to the latest Intel Decimal Floating-Point Math Library.

The Intel Decimal Floating-Point Math Library is available as open-source on Netlib[1].

[1] https://www.netlib.org/misc/intel/.

libgcc/config/libbid/ChangeLog:

* bid128_fma.c (add_and_round): Fix bug: the result
of (+5E+368)*(+10E-34)+(-10E+369) was returning
-9999999999999999999999999999999999E+336 instead of expected
result -1000000000000000000000000000000000E+337.
(bid128_ext_fma): Ditto.
(bid64qqq_fma): Ditto.
* bid128_noncomp.c: Change return type of bid128_class from
int to class_t.
* bid128_round_integral.c: Add default case to avoid compiler
warning.
* bid128_string.c (bid128_to_string): Replace 0x30 with '0'
for zero digit.
(bid128_from_string): Ditto.
* bid32_to_bid128.c (bid128_to_bid32): Fix Bug. In addition
to the INEXACT flag, the UNDERFLOW flag needs to be set (and
was not) when converting an input such as
+6931674235302037148946035460357709E+1857 to +1000000E-101
* bid32_to_bid64.c (bid64_to_bid32): fix Bug, In addition to
the INEXACT flag, the UNDERFLOW flag needs to be set (and was
not) when converting an input such as +9999999000000001E-111
to +1000000E-101. Furthermore, significant bits of NaNs are
set correctly now. For example,  0x7c00003b9aca0000 was
returning 0x7c000002 instead of 0x 7c000100.
* bid64_noncomp.c: Change return type of bid64_class from int
to class_t.
* bid64_round_integral.c (bid64_round_integral_exact): Add
default case to avoid compiler warning.
* bid64_string.c (bid64_from_string): Fix bug for rounding
up. The input string "10000000000000000" was returning
+1000000000000001E+1 instead of +1000000000000000E+1.
* bid64_to_bid128.c (bid128_to_bid64): Fix bug, in addition to
the INEXACT flag, the UNDERFLOW flag needs to be set (and was
not) when converting an input such as
+9999999999999999999999999999999999E-417 to
+1000000000000000E-398.
* bid_binarydecimal.c (bid32_to_binary64): Fix bug for
conversion between binary and bid types. For example,
0x7c0F4240 was returning 0x7FFFA12000000000 instead of
expected double precision 0x7FF8000000000000.
(binary64_to_bid32): Ditto.
(binary80_to_bid32): Ditto.
(binary128_to_bid32): Ditto.
(binary80_to_bid64): Ditto.
(binary128_to_bid64): Ditto.
* bid_conf.h (BID_HIGH_128W): New macro.
(BID_LOW_128W): Ditto.
* bid_functions.h (__ENABLE_BINARY80__): Ditto.
(ALIGN): Ditto.
* bid_inline_add.h (get_add128): Add default case to avoid compiler
warning.
* bid_internal.h (get_BID64): Ditto.
(fast_get_BID64_check_OF): Ditto.
(ALIGN): New macro.

Co-authored-by: Anderson, Cristina S <cristina.s.anderson@intel.com>
Co-authored-by: Akkas, Ahmet <ahmet.akkas@intel.com>
Co-authored-by: Cornea, Marius <marius.cornea@intel.com>
42 hours agoRemove m_nloops field from loop_versioning
Andrew Pinski [Sun, 28 Apr 2024 01:54:43 +0000 (27 18:54 -0700)]
Remove m_nloops field from loop_versioning

This is a small cleanup of loop_versioning where m_nloops
is only used in the constructor so we can remove the whole
field.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* gimple-loop-versioning.cc (loop_versioning): Remove m_nloops field.
(loop_versioning::loop_versioning): Remove initialization of
m_nloops field and move it to be a local variable.
(loop_versioning::analyze_blocks): Fix formating.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
42 hours agoDaily bump.
GCC Administrator [Sun, 5 May 2024 00:16:48 +0000 (5 00:16 +0000)]
Daily bump.

2 days agoAdd prange entries in gimple-range-op.cc.
Aldy Hernandez [Wed, 20 Mar 2024 10:27:21 +0000 (20 11:27 +0100)]
Add prange entries in gimple-range-op.cc.

gcc/ChangeLog:

* gimple-range-op.cc (class cfn_pass_through_arg1): Add overloads
for prange operations.
(cfn_strlen): Same.

2 days agoImplement operator_ge for prange....
Aldy Hernandez [Wed, 20 Mar 2024 10:15:03 +0000 (20 11:15 +0100)]
Implement operator_ge for prange....

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_ge::fold_range): New.
(operator_ge::op1_range): New.
(operator_ge::op2_range): New.
(operator_ge::op1_op2_relation): New.
(operator_ge::pointers_handled_p): New.

2 days agoImplement operator_gt for prange.
Aldy Hernandez [Wed, 20 Mar 2024 10:10:03 +0000 (20 11:10 +0100)]
Implement operator_gt for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_gt::fold_range): New.
(operator_gt::op1_range): New.
(operator_gt::op2_range): New.
(operator_gt::op1_op2_relation): New.
(operator_gt::pointers_handled_p): New.

2 days agoImplement operator_le for prange.
Aldy Hernandez [Wed, 20 Mar 2024 10:07:30 +0000 (20 11:07 +0100)]
Implement operator_le for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_le::fold_range): New.
(operator_le::op1_range): New.
(operator_le::op2_range): New.
(operator_le::op1_op2_relation): New.
(operator_le::pointers_handled_p): New.

2 days agoImplement operator_lt for prange.
Aldy Hernandez [Wed, 20 Mar 2024 10:03:24 +0000 (20 11:03 +0100)]
Implement operator_lt for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (max_limit): New.
(min_limit): New.
(build_lt): New.
(build_le): New.
(build_gt): New.
(build_ge): New.
(operator_lt::fold_range): New.
(operator_lt::op1_range): New.
(operator_lt::op2_range): New.
(operator_lt::op1_op2_relation): New.
(operator_lt::pointers_handled_p): New.

2 days agoImplement operator_equal for prange.
Aldy Hernandez [Wed, 20 Mar 2024 09:54:39 +0000 (20 10:54 +0100)]
Implement operator_equal for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_equal::fold_range): New.
(operator_equal::op1_range): New.
(operator_equal::op2_range): New.
(operator_equal::op1_op2_relation): New.
(operator_equal::pointers_handled_p): New.

2 days agoImplement operator_not_equal for prange.
Aldy Hernandez [Wed, 20 Mar 2024 09:49:11 +0000 (20 10:49 +0100)]
Implement operator_not_equal for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_not_equal::fold_range): New.
(operator_not_equal::op1_range): New.
(operator_not_equal::op2_range): New.
(operator_not_equal::op1_op2_relation): New.
(operator_not_equal::pointers_handled_p): New.

2 days agoImplement operator_bitwise_or for prange.
Aldy Hernandez [Wed, 20 Mar 2024 09:29:50 +0000 (20 10:29 +0100)]
Implement operator_bitwise_or for prange.

We seem to have a range-op entry for pointer bitwise OR that we've
inherited from the original VRP implementation, but it never gets
used.  If this is not valid gimple, we can safely remove this entry.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_bitwise_or::pointers_handled_p): New.

2 days agoImplement operator_bitwise_and for prange.
Aldy Hernandez [Wed, 20 Mar 2024 09:23:31 +0000 (20 10:23 +0100)]
Implement operator_bitwise_and for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_bitwise_and::fold_range): New.
(operator_bitwise_and::pointers_handled_p): New.

2 days agoImplement operator_pointer_diff for prange.
Aldy Hernandez [Wed, 20 Mar 2024 09:12:47 +0000 (20 10:12 +0100)]
Implement operator_pointer_diff for prange.

gcc/ChangeLog:

* range-op-ptr.cc
(operator_pointer_diff::op1_op2_relation_effect): New.
(operator_pointer_diff::pointers_handled_p): New.

2 days agoImplement pointer_plus_operator for prange.
Aldy Hernandez [Wed, 20 Mar 2024 09:04:41 +0000 (20 10:04 +0100)]
Implement pointer_plus_operator for prange.

gcc/ChangeLog:

* range-op-ptr.cc (class pointer_plus_operator): Add overloaded declarations
for pointer variants.
(pointer_plus_operator::fold_range): New.
(pointer_plus_operator::op2_range): New.
(pointer_plus_operator::pointers_handled_p): New.

2 days agoImplement operator_addr_expr for prange.
Aldy Hernandez [Wed, 20 Mar 2024 08:51:33 +0000 (20 09:51 +0100)]
Implement operator_addr_expr for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_addr_expr::op1_range): New.
(operator_addr_expr::pointers_handled_p): New.

2 days agoImplement operator_min and operator_max for prange.
Aldy Hernandez [Wed, 20 Mar 2024 07:44:49 +0000 (20 08:44 +0100)]
Implement operator_min and operator_max for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_min::fold_range): New.
(operator_min::pointers_handled_p): New.
(operator_max::fold_range): New.
(operator_max::pointers_handled_p): New.

2 days agoImplement operator_cast for prange.
Aldy Hernandez [Wed, 20 Mar 2024 07:04:32 +0000 (20 08:04 +0100)]
Implement operator_cast for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_cast::fold_range): New.
(operator_cast::op1_range): New.
(operator_cast::lhs_op1_relation): New.
(operator_cast::pointers_handled_p): New.

2 days agoImplement operator_cst for prange.
Aldy Hernandez [Wed, 20 Mar 2024 06:55:57 +0000 (20 07:55 +0100)]
Implement operator_cst for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for pointer variants.
* range-op-ptr.cc (operator_cst::fold_range): New.
(operator_cst::pointers_handled_p): New.

2 days agoImplement operator_identity for prange.
Aldy Hernandez [Wed, 20 Mar 2024 06:50:11 +0000 (20 07:50 +0100)]
Implement operator_identity for prange.

gcc/ChangeLog:

* range-op-mixed.h: Add overloaded declarations for fold_range, op1_range,
lhs_op1_relation, pointers_handled_p.
* range-op-ptr.cc (operator_identity::fold_range): New.
(operator_identity::lhs_op1_relation): New.
(operator_identity::op1_range): New.
(operator_identity::pointers_handled_p): New.

2 days agoImplement range-op dispatch for prange.
Aldy Hernandez [Wed, 20 Mar 2024 06:19:45 +0000 (20 07:19 +0100)]
Implement range-op dispatch for prange.

This patch adds the range-op dispatch code for prange, and adds some
temporary sanity checks (for flag_checking only) to make sure we handle
all the pointer/integer variants.

In order to make sure I got all the combinations right, I started with
a clean slate, trapping on all pointer operands.  Then I added support
for each one piecemeal.  To verify the work, I added a
pointers_handled_p() helper that is implemented for each range-op
entry and returns TRUE iff the operator can handle a given combination
of pointers.  If this helper returns false, we will trap, because it
indicates an operator that was not implemented.  This is temporary
checking code, and I will rip it out once the the dust has
settled in a few days.

gcc/ChangeLog:

* range-op-mixed.h: Add using declarator for all classes.
* range-op-ptr.cc (range_operator::pointers_handled_p): New.
(range_operator::fold_range): New.
(range_operator::op1_op2_relation_effect): New.
(range_operator::op1_range): New.
(range_operator::op2_range): New.
(range_operator::op1_op2_relation): New.
(range_operator::lhs_op1_relation): New.
(range_operator::update_bitmask): New.
(class pointer_plus_operator): New.
(class operator_pointer_diff): New.
(class hybrid_min_operator): New.
(class hybrid_max_operator): New.
* range-op.cc: Add RO_PPP, RO_PPI, RO_IPP, RO_IPI, RO_PIP, RO_PII.
(range_op_handler::discriminator_fail): New.
(has_pointer_operand_p): New.
(range_op_handler::fold_range): Add pointer support.
(range_op_handler::op1_range): Same.
(range_op_handler::op2_range): Same.
(range_op_handler::lhs_op1_relation): Same.
(range_op_handler::lhs_op2_relation): Same.
(range_op_handler::op1_op2_relation): Same.
(class operator_div): Add using.
(class operator_lshift): Add using.
(class operator_rshift):Add using.
(class operator_trunc_mod):Add using.
(class operator_absu):Add using.
* range-op.h (enum range_op_dispatch_type): New.
Add extern definitions for RO_*.

2 days agoAdd prange implementation for get_legacy_range.
Aldy Hernandez [Wed, 20 Mar 2024 05:39:48 +0000 (20 06:39 +0100)]
Add prange implementation for get_legacy_range.

gcc/ChangeLog:

* value-range.cc (get_legacy_range): New version for prange.

2 days agoAdd hashing support for prange.
Aldy Hernandez [Wed, 20 Mar 2024 05:39:07 +0000 (20 06:39 +0100)]
Add hashing support for prange.

gcc/ChangeLog:

* value-range.cc (add_vrange): Add prange support.

2 days agoAdd storage support for prange.
Aldy Hernandez [Wed, 20 Mar 2024 05:38:06 +0000 (20 06:38 +0100)]
Add storage support for prange.

gcc/ChangeLog:

* value-range-storage.cc (vrange_allocator::clone_varying): Add
prange support.
(vrange_allocator::clone_undefined): Same.
(vrange_storage::alloc): Same.
(vrange_storage::set_vrange): Same.
(vrange_storage::get_vrange): Same.
(vrange_storage::fits_p): Same.
(vrange_storage::equal_p): Same.
(prange_storage::alloc): New.
(prange_storage::prange_storage): New.
(prange_storage::set_prange): New.
(prange_storage::get_prange): New.
(prange_storage::equal_p): New.
(prange_storage::fits_p): New.
* value-range-storage.h (class prange_storage): Add prange support.

2 days agoAdd streaming support for prange.
Aldy Hernandez [Wed, 20 Mar 2024 05:34:26 +0000 (20 06:34 +0100)]
Add streaming support for prange.

gcc/ChangeLog:

* data-streamer-in.cc (streamer_read_value_range): Add prange support.
* data-streamer-out.cc (streamer_write_vrange): Same.

2 days agoImplement basic prange class.
Aldy Hernandez [Wed, 20 Mar 2024 05:25:52 +0000 (20 06:25 +0100)]
Implement basic prange class.

This provides a bare prange class with bounds and bitmasks.  It will
be a drop-in replacement for pointer ranges, so we can pull their
support from irange.  The range-op code will be contributed as a
follow-up.

The code is disabled by default, as irange::supports_p still accepts
pointers:

inline bool
irange::supports_p (const_tree type)
{
  return INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type);
}

Once the prange operators are implemented in range-ops, pointer
support will be removed from irange to activate pranges.

gcc/ChangeLog:

* value-range-pretty-print.cc (vrange_printer::visit): New.
* value-range-pretty-print.h: Declare prange visit() method.
* value-range.cc (vrange::operator=): Add prange support.
(vrange::operator==): Same.
(prange::accept): New.
(prange::set_nonnegative): New.
(prange::set): New.
(prange::contains_p): New.
(prange::singleton_p): New.
(prange::lbound): New.
(prange::ubound): New.
(prange::union_): New.
(prange::intersect): New.
(prange::operator=): New.
(prange::operator==): New.
(prange::invert): New.
(prange::verify_range): New.
(prange::update_bitmask): New.
(range_tests_misc): Use prange.
* value-range.h (enum value_range_discriminator): Add VR_PRANGE.
(class prange): New.
(Value_Range::init): Add prange support.
(Value_Range::operator=): Same.
(Value_Range::supports_type_p): Same.
(prange::prange):  New.
(prange::supports_p): New.
(prange::supports_type_p): New.
(prange::set_undefined): New.
(prange::set_varying): New.
(prange::set_nonzero): New.
(prange::set_zero): New.
(prange::contains_p): New.
(prange::zero_p): New.
(prange::nonzero_p): New.
(prange::type): New.
(prange::lower_bound): New.
(prange::upper_bound): New.
(prange::varying_compatible_p): New.
(prange::get_bitmask): New.
(prange::fits_p): New.

2 days agoMinimal prange class showing inlining degradation to VRP.
Aldy Hernandez [Sat, 4 May 2024 04:45:18 +0000 (4 06:45 +0200)]
Minimal prange class showing inlining degradation to VRP.

There is a 2% slowdown to VRP unrelated to the work at hand.  This patch
is a skeleton implementation of prange that exhibits this degradation.  It
is meant as a place in the commit history we can return to in order to revisit
the issue.

The relevant discussion is here:

https://gcc.gnu.org/pipermail/gcc/2024-May/243898.html

gcc/ChangeLog:

* value-range.h (class prange): New.

2 days agoDaily bump.
GCC Administrator [Sat, 4 May 2024 00:16:30 +0000 (4 00:16 +0000)]
Daily bump.

2 days agolibbacktrace: add DLLS as they are loaded
Ian Lance Taylor [Fri, 3 May 2024 22:23:23 +0000 (3 15:23 -0700)]
libbacktrace: add DLLS as they are loaded

Patch from Björn Schäpers.

* pecoff.c (struct dll_notification_data): Define.
(LDR_DLL_NOTIFICATION): New typedef.
(LDR_REGISTER_FUNCTION): New typedef.
(struct dll_notification_context): Define.
(dll_notification): New static function.
(backtrace_initialize): Register DLL notification.

2 days agoFix printing COMPOUND_EXPR in .original [PR23872]
Andrew Pinski [Wed, 17 Apr 2024 00:43:36 +0000 (16 17:43 -0700)]
Fix printing COMPOUND_EXPR in .original [PR23872]

Starting with the merge of the openmp branch into the trunk
(r0-73077-g953ff28998b59b), COMPOUND_EXPR started to be printed
as `expr; , expr` which is wrong. This was due to the wrong
conversion of dumping_stmts into `!(flags & TDF_SLIM)`. That is wrong
as we are not dumping stmts at this point (`!(flags & TDF_SLIM)` was always
true for this case as TDF_SLIM case was handled before hand). So switch it
to be always false.

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

PR middle-end/23872
* tree-pretty-print.cc (dump_generic_node <case COMPOUND_EXPR>): Fix
calls to dump_generic_node and also remove unreachable code that is testing
`flags & TDF_SLIM`.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/atomic-21.f90: Update testcase for the removal of `;`.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 days agoc++: initializer_list<string> and EH [PR114935]
Jason Merrill [Fri, 3 May 2024 13:52:46 +0000 (3 09:52 -0400)]
c++: initializer_list<string> and EH [PR114935]

When we initialize an array of a type with a non-trivial destructor, such as
the backing array for the initializer_list, we have a cleanup to destroy any
constructed elements if a later constructor throws.  When the array being
created is a variable, the end of that EH region naturally coincides with
the beginning of the EH region for the cleanup for the variable as a whole.

But if the array is a temporary, or a subobject of one, the array cleanup
region lasts for the rest of the full-expression, along with the normal
cleanup for the TARGET_EXPR.  As a result, when tata throws we clean it up
twice.  Before r14-1705 we avoided this by disabling the array cleanup in
split_nonconstant_init, but after that we don't go through
split_nonconstant_init, so let's handle it in cp_genericize_target_expr.

PR c++/114935

gcc/cp/ChangeLog:

* cp-gimplify.cc (cp_genericize_init): Add flags parm.
(cp_genericize_init_expr): Pass nullptr.
(cp_genericize_target_expr): Handle cleanup flags.
* typeck2.cc (build_disable_temp_cleanup): Factor out of...
(split_nonconstant_init): ...here.
* cp-tree.h (build_disable_temp_cleanup): Declare.

gcc/testsuite/ChangeLog:

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

2 days agoPR modula2/114929 extra for loop iteration count regression tests
Gaius Mulley [Fri, 3 May 2024 19:48:01 +0000 (3 20:48 +0100)]
PR modula2/114929 extra for loop iteration count regression tests

This patch introduces three more for loop tests checking the iteration
count using the CHAR and enumeration data types.

gcc/testsuite/ChangeLog:

PR modula2/114929
* gm2/pim/run/pass/testforloopchar.mod: New test.
* gm2/pim/run/pass/testforloopchar2.mod: New test.
* gm2/pim/run/pass/testforloopenum.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 days agoc++: Implement __is_pointer built-in trait
Ken Matsui [Mon, 10 Jul 2023 00:49:08 +0000 (9 17:49 -0700)]
c++: Implement __is_pointer built-in trait

This patch implements built-in trait for std::is_pointer.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_pointer.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer.
Arrange the order lexically around __is_pointer.
* g++.dg/ext/is_pointer.C: New test.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jason Merrill <jason@redhat.com>
2 days agoc++: Implement __is_volatile built-in trait
Ken Matsui [Wed, 22 Mar 2023 23:26:25 +0000 (22 16:26 -0700)]
c++: Implement __is_volatile built-in trait

This patch implements built-in trait for std::is_volatile.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_volatile.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_VOLATILE.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Test existence of __is_volatile.
* g++.dg/ext/is_volatile.C: New test.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jason Merrill <jason@redhat.com>
2 days agoc++: Implement __is_const built-in trait
Ken Matsui [Tue, 21 Mar 2023 16:10:52 +0000 (21 09:10 -0700)]
c++: Implement __is_const built-in trait

This patch implements built-in trait for std::is_const.

gcc/cp/ChangeLog:

* cp-trait.def: Define __is_const.
* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONST.
* semantics.cc (trait_expr_value): Likewise.
(finish_trait_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has-builtin-1.C: Test existence of __is_const.
* g++.dg/ext/is_const.C: New test.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
Reviewed-by: Jason Merrill <jason@redhat.com>
3 days agoRISC-V: miscll comment fixes [NFC]
Vineet Gupta [Tue, 1 Mar 2022 11:45:19 +0000 (1 03:45 -0800)]
RISC-V: miscll comment fixes [NFC]

gcc/ChangeLog:
* config/riscv/riscv.cc: Comment updates.
* config/riscv/riscv.h: Ditto.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
3 days agodocs: rtl: document GET_MODE_INNER
Vineet Gupta [Thu, 17 Feb 2022 21:49:45 +0000 (17 13:49 -0800)]
docs: rtl: document GET_MODE_INNER

gcc/ChangeLog
* doc/rtl.texi: Add entry for GET_MODE_INNER.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
3 days agotestsuite: fix analyzer C++ failures on Solaris [PR111475]
David Malcolm [Fri, 3 May 2024 13:05:29 +0000 (3 09:05 -0400)]
testsuite: fix analyzer C++ failures on Solaris [PR111475]

As part of PR analyzer/96395, these patches moved testcases from
gcc.dg/analyzer to c-c++-common/analyzer:
r14-3503-g55f6a7d949abc7
r14-3823-g50b5199cff6908
r14-6564-gae034b9106fbdd

Unfortunately this led to numerous g++ testsuite failures on Solaris,
tracked as PR analyzer/111475.

Almost all of the failures are due to standard library differences where
including a C standard library on C++ e.g. <stdlib.h> leads to the plain
symbols referencing the symbols "std::" via a "using" declaration,
whereas I had written the code expecting them to use symbols in the root
namespace.

The analyzer has special-case handling of many functions by name.
This patch generalizes such handling to also match against functions
in "std::" for all of the cases I found in the testsuite (via manual
inspection of the preprocessed test cases against Solaris headers).
This fixes cases where the analyzer was failing to "know about" the
behavior of such functions.

Other such failures are due to "std::" prefixes appearing in names of
functions in the output, leading to mismatches against expected output.
The patch adds regexes to some cases, and moves some other cases back
from c-c++-common to gcc.dg where the dg-multiline syntax isn't
expressive enough.

Various "fd-*.c" failures relate to Solaris's socket-handling functions
not being marked with "noexcept", where due to PR analyzer/97111 we
mishandle the exception-handling edges in the CFG, leading to leak
false positives.  The patch works around this by adding -fno-exceptions
to these cases, pending a proper fix for PR analyzer/97111.

gcc/analyzer/ChangeLog:
PR analyzer/111475
* analyzer.cc (is_special_named_call_p): Add "look_in_std" param.
(is_std_function_p): Make non-static.
* analyzer.h (is_special_named_call_p): Add optional "look_in_std"
param.
(is_std_function_p): New decl.
* engine.cc (stmt_requires_new_enode_p): Look for both "signal"
and "std::signal".
* kf.cc (register_known_functions): Add various "std::" copies
of the known functions.
* known-function-manager.cc
(known_function_manager::~known_function_manager): Clean up
m_std_ns_map_id_to_kf.
(known_function_manager::add_std_ns): New.
(known_function_manager::get_match): Also look for known "std::"
functions.
(known_function_manager::get_by_identifier_in_std_ns): New.
* known-function-manager.h
(known_function_manager::add_std_ns): New decl.
(known_function_manager::get_by_identifier_in_std_ns): New decl.
(known_function_manager::m_std_ns_map_id_to_kf): New field.
* sm-file.cc (register_known_file_functions): Add various "std::"
copies of the known functions.
* sm-malloc.cc (malloc_state_machine::on_stmt): Handle
"std::realloc".
* sm-signal.cc (signal_unsafe_p): Consider "std::" copies of the
functions as also being async-signal-unsafe.
(signal_state_machine::on_stmt): Consider "std::signal".

gcc/testsuite/ChangeLog:
PR analyzer/111475
* c-c++-common/analyzer/fd-glibc-byte-stream-socket.c: Add
-fno-exceptions for now.
* c-c++-common/analyzer/fd-manpage-getaddrinfo-client.c: Likewise.
* c-c++-common/analyzer/fd-mappage-getaddrinfo-server.c: Rename to...
* c-c++-common/analyzer/fd-manpage-getaddrinfo-server.c: ...this, and
add -fno-exceptions for now.
* c-c++-common/analyzer/fd-socket-meaning.c: Add -fno-exceptions
for now.
* c-c++-common/analyzer/fd-symbolic-socket.c: Likewise.
* c-c++-common/analyzer/flexible-array-member-1.c: Use regexp to
handle C vs C++ differences in spelling of function name, which
could have a "std::" prefix on some targets.
* c-c++-common/analyzer/pr106539.c: Likewise.
* c-c++-common/analyzer/malloc-ipa-8-unchecked.c: Move back to...
* gcc.dg/analyzer/malloc-ipa-8-unchecked.c: ...here, dropping
attempt to generalize output for C vs C++.
* c-c++-common/analyzer/signal-4a.c: Move back to...
* gcc.dg/analyzer/signal-4a.c: ...here, dropping attempt to
generalize output for C vs C++.
* c-c++-common/analyzer/signal-4b.c: Move back to...
* gcc.dg/analyzer/signal-4b.c: ...here, dropping attempt to
generalize output for C vs C++.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
3 days agoAdd default bitmap obstack allocation check
Richard Biener [Fri, 5 Apr 2024 09:02:46 +0000 (5 11:02 +0200)]
Add default bitmap obstack allocation check

The following adds a check that the global bitmap obstack is initialized
when allocating a bitmap from it.

* bitmap.cc (bitmap_alloc): When using the global bitmap obstack
assert that is initialized.

3 days agoSilence two instances of -Wcalloc-transposed-args
Peter Damianov [Fri, 3 May 2024 08:02:35 +0000 (3 01:02 -0700)]
Silence two instances of -Wcalloc-transposed-args

libgcc/
* libgcov-util.c (tag_counters): Swap order of arguments to xcalloc.
(topen_to_memory_representation): Likewise.

Signed-off-by: Peter Damianov <peter0x44@disroot.org>
3 days agolibstdc++: Update powerpc-linux-gnu baseline_symbols
Andreas Schwab [Sat, 3 Feb 2024 13:00:41 +0000 (3 14:00 +0100)]
libstdc++: Update powerpc-linux-gnu baseline_symbols

* config/abi/post/powerpc-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/powerpc64-linux-gnu/32/baseline_symbols.txt: Update.

3 days agoAvoid changing type in the type_hash_canon hash
Richard Biener [Fri, 3 May 2024 09:48:07 +0000 (3 11:48 +0200)]
Avoid changing type in the type_hash_canon hash

When building a type and type_hash_canon returns an existing type
avoid changing it, in particular its TYPE_CANONICAL.

PR middle-end/114931
* tree.cc (build_array_type_1): Return early when type_hash_canon
returned an older existing type.
(build_function_type): Likewise.
(build_method_type_directly): Likewise.
(build_offset_type): Likewise.

3 days agocfgrtl: Fix MEM_EXPR update in duplicate_insn_chain [PR114924]
Alex Coplan [Fri, 3 May 2024 08:23:59 +0000 (3 09:23 +0100)]
cfgrtl: Fix MEM_EXPR update in duplicate_insn_chain [PR114924]

The PR shows that when cfgrtl.cc:duplicate_insn_chain attempts to
update the MR_DEPENDENCE_CLIQUE information for a MEM_EXPR we can end up
accidentally dropping (e.g.) an ARRAY_REF from the MEM_EXPR and end up
replacing it with the underlying MEM_REF.  This leads to an
inconsistency in the MEM_EXPR information, and could lead to wrong code.

While the walk down to the MEM_REF is necessary to update
MR_DEPENDENCE_CLIQUE, we should use the outer tree expression for the
MEM_EXPR.  This patch does that.

gcc/ChangeLog:

PR rtl-optimization/114924
* cfgrtl.cc (duplicate_insn_chain): When updating MEM_EXPRs,
don't strip (e.g.) ARRAY_REFs from the final MEM_EXPR.

3 days agotree-inline: Add __builtin_stack_{save,restore} pair about inline calls with calls...
Jakub Jelinek [Fri, 3 May 2024 07:44:30 +0000 (3 09:44 +0200)]
tree-inline: Add __builtin_stack_{save,restore} pair about inline calls with calls to alloca [PR113596]

The following patch adds save_NNN = __builtin_stack_save (); ...
__builtin_stack_restore (save_NNN);
pair around inline calls which call alloca (alloca calls because of
VLA vars are ignored in that decision).
The patch doesn't change anything on whether we try to inline such calls or
not, it just fixes the behavior when we inline them despite those checks.
The stack save/restore restores the behavior that alloca acquired regions
are freed at the end of the containing call.

2024-05-03  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/113596
* tree-inline.cc (expand_call_inline): Emit __builtin_stack_save
and __builtin_stack_restore calls around inlined functions which
call alloca.

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

3 days agotree-optimization/114921 - _Float16 -> __bf16 isn't noop
Richard Biener [Thu, 2 May 2024 11:55:15 +0000 (2 13:55 +0200)]
tree-optimization/114921 - _Float16 -> __bf16 isn't noop

The vectorizer handles a _Float16 to __bf16 conversion through
vectorizable_assignment, thinking it's a noop.  The following
fixes this by requiring the same vector component mode when
checking for CONVERT_EXPR_CODE_P, being stricter than for
VIEW_CONVERT_EXPR.

PR tree-optimization/114921
* tree-vect-stmts.cc (vectorizable_assignment): Require
same vector component modes for input and output for
CONVERT_EXPR_CODE_P.

3 days agoc++: remove lookup_template_class's entering_scope flag
Patrick Palka [Fri, 3 May 2024 01:14:30 +0000 (2 21:14 -0400)]
c++: remove lookup_template_class's entering_scope flag

lookup_template_class's entering_scope flag controls whether to prefer
returning the primary template type A<T> instead of the corresponding
implicit instantiation A<T>.  When we want to set this flag as part of
substitution, we need to use tsubst_aggr_type which also takes this flag
as a parameter.  But having this separate entry point to type substitution
turned out to be subtly problematic because it doesn't reuse typedefs
like tsubst does, which r13-4729-gbe124477b38a71 fixed in a way that
respects the flag after the fact, by adjusting the entering_scope=false
result of lookup_template_class as if entering_scope=true was passed.

But if that's possible then it means lookup_template_class's
entering_scope flag is not necessary after all -- we can just do the
after-the-fact adjustment everywhere that we currently pass
entering_scope=true to it and tsubst_aggr_type.

To that end, this patch replaces this flag with an adjustment function
adjust_type_for_entering_scope, to be used whereever we currently need
the entering_scope=true behavior.  In turn we can get rid of
tsubst_aggr_type since the only reason we needed this entry point
was to be able to pass entering_scope=true to lookup_template_class.

gcc/cp/ChangeLog:

* coroutines.cc (instantiate_coro_traits): Adjust call to
lookup_template_class.
(instantiate_coro_handle_for_promise_type): Likewise.
* cp-tree.h (adjust_type_for_entering_scope): Declare.
(lookup_template_class): Adjust declaration.
* decl.cc (make_typename_type): Adjust call to
lookup_template_class. Likewise.
(get_tuple_size): Likewise.
(get_tuple_element_type): Likewise.
* pt.cc (adjust_type_for_entering_scope): Define.
(tsubst_entering_scope): Define.
(lookup_template_class): Remove entering_scope parameter.
Replace tsubst_aggr_type call with tsubst_entering_scope.
(tsubst_aggr_type): Remove.
(tsubst_aggr_type_1): Inline into tsubst.
(tsubst_function_decl): Replace tsubst_aggr_type call
with tsubst_entering_scope.
(tsubst_template_decl): Likewise.
(tsubst_decl): Likewise.
(tsubst) <case RECORD_TYPE, UNION_TYPE, ENUMERAL_TYPE>:
Inlined from tsubst_aggr_type_1.
<case BOUND_TEMPLATE_TEMPLATE_PARM>: Adjust calls to
lookup_template_class.
<case TYPENAME_TYPE>: Replace tsubst_aggr_type call with
tsubst_entering_scope.
<case UNBOUND_CLASS_TEMPLATE>: Likewise.
Increment processing_template_decl when substituting the
context.
(tsubst_expr) <case FIELD_DECL>: Replace tsubst_aggr_type
call with tsubst_entering_scope.
<case TEMPLATE_DECL>: Likewise.
(instantiate_template): Likewise.
(resolve_typename_type): Adjust lookup_template_class call
and call adjust_type_for_entering_scope afterward.
(listify): Adjust lookup_template_class call.
(alias_ctad_tweaks): Likewise.
* semantics.cc (finish_template_type): Adjust lookup_template_class
call and maybe call adjust_type_for_entering_scope afterward.

Reviewed-by: Jason Merrill <jason@redhat.com>
3 days agoPR modula2/114929 for loop fails to iterate down to zero when using a cardinal type
Gaius Mulley [Fri, 3 May 2024 00:22:10 +0000 (3 01:22 +0100)]
PR modula2/114929 for loop fails to iterate down to zero when using a cardinal type

There is a bug in the for loop control code which is exposed when an
unsigned type is used in the iterator variable.  See
gm2/pim/run/pass/testforloopzero[234].mod.  The bug is in the
calculation of the last iterator value.  The bug fix is to avoid using
negative expressions when calculating the last iterator value with a
negative step value.  This patch detects if e1, e2, step value are all
constant, in which case the ztype is used internally and there is no
overflow.  If the last iterator value is held in a variable then it
uses a different method to calculate the last iterator depending upon
the sign of the step value.

gcc/m2/ChangeLog:

PR modula2/114929
* gm2-compiler/M2LangDump.mod (GenQualidentSymString): Add
missing return result into identstr.
* gm2-compiler/M2Quads.mod (ForLoopLastIteratorVariable): New
procedure.
(ForLoopLastIteratorConstant): Ditto.
(ForLoopLastIterator): Ditto.
(BuildForToByDo): Remove LastIterator calculation and call
ForLoopLastIterator instead.
(FinalValue): Replace with ...
(LastIterator): ... this.

gcc/testsuite/ChangeLog:

PR modula2/114929
* gm2/pim/run/pass/testforloopzero.mod: New test.
* gm2/pim/run/pass/testforloopzero2.mod: New test.
* gm2/pim/run/pass/testforloopzero3.mod: New test.
* gm2/pim/run/pass/testforloopzero4.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
3 days agoDaily bump.
GCC Administrator [Fri, 3 May 2024 00:17:26 +0000 (3 00:17 +0000)]
Daily bump.

3 days ago[committed][RISC-V] Fix nearbyint failure on rv32 and formatting nits
Jeff Law [Thu, 2 May 2024 23:13:12 +0000 (2 17:13 -0600)]
[committed][RISC-V] Fix nearbyint failure on rv32 and formatting nits

The CI system tripped an execution failure for rv32 with the ceil/round patch.

The fundamental problem is the FP->INT step in these sequences requires the
input size to match the output size.  The output size was based on rv32/rv64.
Meaning that we'd try to do DF->SI->DF.

That doesn't preserve the semantics we want in at least two ways.

The net is we can't use this trick for DF values on rv32.  While inside the
code I realized we had a similar problem for HF modes.  HF modes we can support
only for Zfa.  So I fixed that proactively.

The CI system also pointed out various formatting nits.  I think this fixes all
but one overly long line.

Note I could have factored the TARGET_ZFA test.  But I think as-written it's
clearer what the desired cases to transform are.

gcc/
* config/riscv/riscv.md (<round_pattern><ANYF:mode>2): Adjust
condition to match what can be properly implemented.  Fix various
formatting issues.
(l<round_pattern><ANYF:mode>si2_sext): Fix formatting

3 days agolibgfortran: Fix up the autoreconf warnings
Francois-Xavier Coudert [Thu, 2 May 2024 21:03:37 +0000 (2 23:03 +0200)]
libgfortran: Fix up the autoreconf warnings

This means using sub-dirs and amending some of the recipes accordingly.

libgfortran/ChangeLog:

* Makefile.am: Use sub-dirs, amend recipies accordingly.
* Makefile.in: Regenerate.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
3 days ago[RFA][RISC-V] Improve constant synthesis for constants with 2 bits set
Jeff Law [Thu, 2 May 2024 20:06:22 +0000 (2 14:06 -0600)]
[RFA][RISC-V] Improve constant synthesis for constants with 2 bits set

In doing some preparation work for using zbkb's pack instructions for constant
synthesis I figured it would be wise to get a sense of how well our constant
synthesis is actually working and address any clear issues.

So the first glaring inefficiency is in our handling of constants with a small
number of bits set.  Let's start with just two bits set.   There are 2016
distinct constants in that space (rv64).  With Zbs enabled the absolute worst
we should ever do is two instructions (bseti+bseti).  Yet we have 503 cases
where we're generating 3+ instructions when there's just two bits set in the
constant.  A constant like 0x8000000000001000 generates 4 instructions!

This patch adds bseti (and indirectly binvi if we needed it) as a first class
citizen for constant synthesis.  There's two components to this change.

First, we can't generate an IOR with a constant like (1 << 45) as an operand.
The IOR/XOR define_insn is in riscv.md.  The constant argument for those
patterns must match an arith_operand which means its not really usable for
generating bseti directly in the cases we care about (at least one of the bits
will be in the 32..63 range and thus won't match arith_operand).

We have a few things we could do.  One would be to extend the existing pattern
to incorporate bseti cases.  But I suspect folks like the separation of the
base architecture (riscv.md) from the Zb* extensions (bitmanip.md).  We could
also try to generate the RTL for bseti
directly, bypassing gen_fmt_ee (which forces undesirable constants into registers based on the predicate of the appropriate define_insn). Neither of these seemed particularly appealing to me.

So what I've done instead is to make ior/xor a define_expand and have the
expander allow a wider set of constant operands when Zbs is enabled.  That
allows us to keep the bulk of Zb* support inside bitmanip.md and continue to
use gen_fmt_ee in the constant synthesis paths.

Note the code generation in this case is designed to first set as many bits as
we can with lui, then with addi since those can both set multiple bits at a
time.  If there are any residual bits left to set we can emit bseti
instructions up to the current cost ceiling.

This results in fixing all of the 503 2-bit set cases where we emitted too many
instructions.  It also significantly helps other scenarios with more bits set.

The testcase I'm including verifies the number of instructions we generate for
the full set of 2016 possible cases.  Obviously this won't be possible as we
increase the number of bits (there are something like 48k cases with just 3
bits set).

gcc/

* config/riscv/predicates.md (arith_or_zbs_operand): New predicate.
* config/riscv/riscv.cc (riscv_build_integer_one): Use bseti to set
single bits when profitable.
* config/riscv/riscv.md (*<optab><mode>3): Renamed with '*' prefix.
(<optab><mode>3): New expander for IOR/XOR.

gcc/testsuite
* gcc.target/riscv/synthesis-1.c: New test.

3 days agoRegenerate gcc.pot
Joseph Myers [Thu, 2 May 2024 19:43:15 +0000 (2 19:43 +0000)]
Regenerate gcc.pot

* gcc.pot: Regenerate.

4 days agoRISC-V: Add testcase for pr114734
Patrick O'Neill [Tue, 30 Apr 2024 20:26:45 +0000 (30 13:26 -0700)]
RISC-V: Add testcase for pr114734

gcc/testsuite/ChangeLog:

PR middle-end/114734

* gcc.target/riscv/rvv/autovec/pr114734.c: New test.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
4 days ago[committed] [RISC-V] Don't run new rounding tests on newlib risc-v targets
Jeff Law [Thu, 2 May 2024 14:42:32 +0000 (2 08:42 -0600)]
[committed] [RISC-V] Don't run new rounding tests on newlib risc-v targets

The new round_32.c and round_64.c tests depend on the optimizers to recognize
the conversions feeding the floor/ceil calls and convert them into ceilf,
floorf and the like.

Those transformations only occur when the target indicates the C library has
the appropriate routines (fnclass == function_c99_misc).  While newlib has
these routines, they are not exposed as available to the compiler and thus the
transformation the tests depend on do not happen. Naturally the scan-tests then
fail.

gcc/testsuite
* gcc.target/riscv/round_32.c: Add require-effective-target glibc.
* gcc.target/riscv/round_64.c: Likewise.

4 days agoc++: Clear is_unbraced_* when parsing declaration_seq_opt [PR114917]
Nathaniel Shead [Thu, 2 May 2024 02:55:24 +0000 (2 12:55 +1000)]
c++: Clear is_unbraced_* when parsing declaration_seq_opt [PR114917]

Currently we incorrectly retain "in_unbraced_linkage_specification_p"
and "in_unbraced_export_declaration_p" when parsing a (braced)
declaration-seq.  This patch ensures that we clear these flags before
parsing the toplevel declarations.

Strictly speaking we don't need to save and restore the flags around the
parsing because there's currently no way to provide new declarations
within the unbraced context after the closing brace, but this patch does
it anyway in case this ever changes and for consistency with other
places that these flags are adjusted.

PR c++/114917

gcc/cp/ChangeLog:

* parser.cc (cp_parser_declaration_seq_opt): Clear
parser->in_unbraced_* flags when parsing toplevel declarations.

gcc/testsuite/ChangeLog:

* g++.dg/modules/export-5_a.C: New test.
* g++.dg/modules/export-5_b.C: New test.
* g++.dg/parse/linkage4.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
4 days agomodula2: Regenerate libgm2 Makefile.ins using correct include order
Gaius Mulley [Thu, 2 May 2024 13:38:51 +0000 (2 14:38 +0100)]
modula2: Regenerate libgm2 Makefile.ins using correct include order

Regenerated libgm2/Makefile.in (and subdir Makefile.in) using
aclocal -I .. -I ../config (or autoreconf).

libgm2/ChangeLog:

* Makefile.in: Regenerate.
* libm2cor/Makefile.in: Ditto.
* libm2iso/Makefile.in: Ditto.
* libm2log/Makefile.in: Ditto.
* libm2min/Makefile.in: Ditto.
* libm2pim/Makefile.in: Ditto.
* aclocal.m4: Ditto.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
4 days agoImprove SLP dump and graph
Richard Biener [Wed, 27 Mar 2024 09:53:11 +0000 (27 10:53 +0100)]
Improve SLP dump and graph

The following notes which lanes are considered live and adds an overload
to produce a graphviz graph for multiple entries into an SLP graph.

* tree-vect-slp.cc (vect_print_slp_tree): Mark live lanes.
(dot_slp_tree): New overload for multiple entries.