]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 months agoada: Adjust the Android RTS config to match linux
Olivier Hainque [Wed, 12 Feb 2025 17:15:00 +0000 (17:15 +0000)] 
ada: Adjust the Android RTS config to match linux

Android has many traits of Linux, reflected
by the gcc port triplets composition (<cpu>-android-linux).

The Android Ada RTS was so far configured as a mostly "posix"
port, which happens to be very little tested, if at all.

This change reworks the Android Ada RTS to map a lot more closely
to that of a regular Linux target, a natural fit and much more toroughly
exercized.

This expects support of pthread rwlocks in the bionic libc,
which is there in the not-so-old-but-not-so-recent versions we
tested (Android 11 at least).

gcc/ada/ChangeLog:

* Makefile.rtl: Rework the Android pairs to match those of a
regular Linux port rather than a generic posix one.
* libgnarl/s-osinte__android.ads: Import pcrtl and add bindings
for the pthread_rwlock entry points, used by the Linux units now
in the libgnat target pairs.
* sysdep.c (__gnat_has_cap_sys_nice): Define for Android,
conservative return 0.
* adaint.c (__gnat_cpu_alloc): Define for Android as for Linux.

2 months agoada: Document representation clauses previously required by ASIS
Piotr Trojanek [Tue, 25 Feb 2025 11:48:32 +0000 (12:48 +0100)] 
ada: Document representation clauses previously required by ASIS

A record type used for name identifiers had representation clause to make sure
that table with identifiers is written to an ASIS file without holes. Now ASIS
mode has been deconstructed, but we still want this representation clause to
ensure efficient implementation.

Comment update; behavior is unaffected.

gcc/ada/ChangeLog:

* namet.ads (Name_Entry): Update comments to explain the current needs.

2 months agoada: Deconstruct representation clauses required by ASIS
Piotr Trojanek [Mon, 24 Feb 2025 13:19:46 +0000 (14:19 +0100)] 
ada: Deconstruct representation clauses required by ASIS

When GNAT was operating in ASIS mode, it was writing internal tables to files,
so we annotated record types for elements stored in these tables with
representation clauses to avoid holes with potentially uninitialized data.

Since ASIS mode has been now deconstructed and we no longer write internal
tables to files, we can remove explicit representation clauses and rely on the
data layout chosen by the compiler.

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

* lib.ads (Unit_Record): Remove representation clauses and filler
components
* lib-load.adb, lib-writ.adb: Remove initialization of data fillers.
* nlists.adb (Allocate_List_Tables): Remove explicit initialization.
* repinfo.adb (Exp_Node): Remove representation clauses.
* sinput.ads (Source_File_Record): Likewise.
* urealp.adb (Ureal_Entry): Likewise.

2 months agoada: Fix typo in documentation about convention and representation
Piotr Trojanek [Tue, 25 Feb 2025 12:02:38 +0000 (13:02 +0100)] 
ada: Fix typo in documentation about convention and representation

Currently there are only three exceptions to the general rule; the fourth
exception applied to OpenVMS, whose support has been deconstructed.

gcc/ada/ChangeLog:

* doc/gnat_rm/representation_clauses_and_pragmas.rst
(Effect of Convention on Representation): Fix number of list items.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

2 months agoada: Fix libgpr2 build failure with compiler built with assertions
Eric Botcazou [Mon, 24 Feb 2025 21:27:21 +0000 (22:27 +0100)] 
ada: Fix libgpr2 build failure with compiler built with assertions

The problem is that the Entity field is accessed for a node without one.

gcc/ada/ChangeLog:

* sem_ch10.adb (Install_Siblings.In_Context): Add missing guard.

2 months agoada: Tweak condition for name resolution failure
Ronan Desplanques [Fri, 21 Feb 2025 16:32:35 +0000 (17:32 +0100)] 
ada: Tweak condition for name resolution failure

It is sometimes used as a convention across GNAT's code to set the Etype
field of a node to Any_Type to signal a name resolution error. This has
the potential to be confusing, which is why this patch replaces one such
use of the convention by a less convoluted check.

This only affects error recovery paths, and possibly doesn't change the
behavior of the compiler at all.

gcc/ada/ChangeLog:

* sem_ch4.adb (Analyze_Selected_Component): Tweak condition.

2 months agoada: Fix wrong initialization of library-level object by conditional expression
Eric Botcazou [Fri, 21 Feb 2025 09:03:22 +0000 (10:03 +0100)] 
ada: Fix wrong initialization of library-level object by conditional expression

At library level the object must be allocated statically and with its bounds
when its nominal subtype is an unconstrained array type.

gcc/ada/ChangeLog:

* exp_ch4.adb (Insert_Conditional_Object_Declaration): Make sure the
object is allocated properly by the code generator at library level.

2 months agoada: Convert floating-point zero to machine representation
Piotr Trojanek [Thu, 20 Feb 2025 18:25:02 +0000 (19:25 +0100)] 
ada: Convert floating-point zero to machine representation

When statically evaluating floating-point expressions we convert the final
result to machine number. However, we skipped this conversion if the result was
zero.

This inconsistency was introduced when adding a warning for compile-time
evaluation that gives different result from a run-time evaluation, but left
when this warning was deconstructed. It causes a crash in GNATprove, which
expects all floating-point numbers in the GNAT AST to be in a machine
representation form.

gcc/ada/ChangeLog:

* sem_eval.adb (Check_Non_Static_Context): Remove special handling of
floating-point zero.

2 months agoada: Move Incomplete_View from node to entity field
Piotr Trojanek [Wed, 19 Feb 2025 15:32:43 +0000 (16:32 +0100)] 
ada: Move Incomplete_View from node to entity field

The Incomplete_View property of a type was attached to its full type
declaration as a semantic field, but retrieving it from there required
low-level tree navigation and caused code duplication. In one case we
relied on internal class-wide type being attached to the corresponding
full type declaration, which is an undocumented assumption.

It seems better to attach this field to entities, just like we do with
Full_View and many other type properties. Ideally, this field should be
present just in type entities, but currently we set it before setting
the proper entity kind.

Behavior is unaffected. This is rather a code cleanup, originating from the
need to use Incomplete_View in GNATprove.

gcc/ada/ChangeLog:

* einfo.ads (Incomplete_View): Move from Sinfo; adapt wording.
* exp_ch3.adb (Build_Record_Init_Proc): Adapt retrieval of
Incomplete_View.
* gen_il-fields.ads (Opt_Field_Enum): Move Incomplete_View from node
to entity field.
* gen_il-gen-gen_entities.adb (Gen_Entities): Add field.
* gen_il-gen-gen_nodes.adb (Gen_Nodes): Remove field.
* sem_ch3.adb (Analyze_Full_Type_Declaration,
Check_Anonymous_Access_Component): Adapt setting of Incomplete_View.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Adapt retrieval of
Incomplete_View for class-wide types; no longer rely on class-wide
type being attached to non-classwide type declaration.
* sem_util.adb (Collect_Primitive_Operations): Adapt retrieval of
Incomplete_View.
* sinfo.ads (Incomplete_View): Move to Einfo.

2 months agoada: Initial prototype of constructors
squirek [Thu, 20 Feb 2025 13:12:58 +0000 (13:12 +0000)] 
ada: Initial prototype of constructors

The patch implements the experimental constructors RFC. Currently a WIP.

gcc/ada/ChangeLog:

* aspects.ads: Add support for constructors.
* exp_aggr.adb: Likewise.
* exp_attr.adb: Likewise.
* exp_ch3.adb: Likewise.
* exp_ch4.adb: Likewise.
* exp_util.adb: Likewise.
* gen_il-fields.ads: Likewise.
* gen_il-gen-gen_entities.adb: Likewise.
* gen_il-gen-gen_nodes.adb: Likewise.
* par-ch4.adb: Likewise.
* sem_aggr.adb: Likewise.
* sem_attr.adb, sem_attr.ads: Likewise.
* sem_ch13.adb: Likewise.
* sem_ch3.adb: Likewise.
* sem_ch5.adb: Likewise.
* sem_ch6.adb: Likewise.
* sem_res.adb: Likewise.
* sem_util.adb, sem_util.ads: Likewise.
* snames.ads-tmpl: Likewise.

2 months agoada: Implement use implies with experimental extension
squirek [Tue, 18 Feb 2025 10:54:01 +0000 (10:54 +0000)] 
ada: Implement use implies with experimental extension

The patch implements the experimental feature to allow use package
clauses within the context area to imply with.

gcc/ada/ChangeLog:

* doc/gnat_rm/gnat_language_extensions.rst: Add documentation.
* gnat_rm.texi: Regenerate.

2 months agoada: Tweak definition of Modulus field of entities
Eric Botcazou [Tue, 18 Feb 2025 10:24:15 +0000 (11:24 +0100)] 
ada: Tweak definition of Modulus field of entities

The compiler may build modular integer subtypes whose base type is private
in the context of instantiations, but we want to be able to get the Modulus.

gcc/ada/ChangeLog:

* einfo.ads (Modulus): Change to implementation base type only.
* gen_il-gen-gen_entities.adb (Modular_Integer_Kind): Change type
of Modulus field to Impl_Base_Type_Only.

2 months agoada: Restore Original_Access_Type field in E_Access_Subprogram_Type entities
Eric Botcazou [Mon, 17 Feb 2025 09:29:48 +0000 (10:29 +0100)] 
ada: Restore Original_Access_Type field in E_Access_Subprogram_Type entities

It is used by CodePeer to recognize the special access pattern.

gcc/ada/ChangeLog:

* einfo.ads (Original_Access_Type): Restore.
* gen_il-fields.ads (Opt_Field_Enum): Restore Original_Access_Type.
* gen_il-gen-gen_entities.adb: Adjust accordingly.
* exp_ch9.adb (Expand_Access_Protected_Subprogram_Type): Restore the
call to Set_Original_Access_Type.

2 months agoada: Remove more unused fields from entities
Eric Botcazou [Fri, 14 Feb 2025 11:31:33 +0000 (12:31 +0100)] 
ada: Remove more unused fields from entities

This removes 5 more unused fields from entities, as well as 1 flag.

gcc/ada/ChangeLog:

* einfo.ads (Default_Expr_Function): Delete.
(Dependent_Instances): Likewise.
(Handler_Records): Likewise.
(Needs_Activation_Record): Likewise.
(Original_Access_Type): Likewise.
(Register_Exception_Call): Likewise.
* sinfo.ads (Accept_Handler_Records): Likewise.
* gen_il-fields.ads (Opt_Field_Enum): Remove Accept_Handler_Records,
Default_Expr_Function, Dependent_Instances, Handler_Records,
Needs_Activation_Record, Original_Access_Type and
Register_Exception_Call.
* gen_il-gen-gen_entities.adb: Adjust accordingly.
* gen_il-gen-gen_nodes.adb: Likewise.
* exp_ch9.adb (Expand_Access_Protected_Subprogram_Type): Remove call
to Set_Original_Access_Type.
(Expand_N_Selective_Accept): Remove call to Set_Handler_Records.
* exp_ch11.adb (Expand_N_Exception_Declaration): Remove call to
Set_Register_Exception_Call.
* sem_ch3.adb (Access_Subprogram_Declaration): Remove call to
Set_Needs_Activation_Record.
* sem_ch12.adb (Instantiate_Package_Body): Remove call to
Set_Handler_Records.

2 months agoada: Incorrect unresolved operator name in an instantiation
Steve Baird [Fri, 7 Feb 2025 20:29:46 +0000 (12:29 -0800)] 
ada: Incorrect unresolved operator name in an instantiation

In some cases, a generic containing a use of a unary operator successfully
compiles but the compiler incorrectly rejects the corresponding use in
an instantiation.

gcc/ada/ChangeLog:

* sem_ch4.adb
(Find_Unary_Types): Because we reanalyze names in an instance,
we sometimes have to take steps to filter out extraneous name
resolution candidates that happen to be visible at the point of the
instance declaration. Remove some code that appears to have been
written with this in mind. This is done for two reasons. First, the
code sometimes doesn't work (possibly because the In_Instance test
is not specific enough - it probably should be testing to see whether
we are in an instance of the particular generic in which the result
of calling Corresponding_Generic_Type was declared) and causes correct
code to be rejected. Second, the code seems to no longer be necessary
(possibly because of subsequent fixes in this area which are not
specific to unary operators).

2 months agoada: Remove dead code
Ronan Desplanques [Thu, 13 Feb 2025 13:19:58 +0000 (14:19 +0100)] 
ada: Remove dead code

The code this patch removes is never executed on any of the available
test suites. The patch that introduced it mentions that it fixes a test
in particular, but that test passes anyway today.

gcc/ada/ChangeLog:

* sem_ch8.adb (Premature_Usage): Remove dead code.

2 months agoada: Remove Size_Check_Code field from entities
Eric Botcazou [Thu, 13 Feb 2025 11:07:37 +0000 (12:07 +0100)] 
ada: Remove Size_Check_Code field from entities

It has been unused for a very long time.

gcc/ada/ChangeLog:

* einfo.ads (Size_Check_Code): Delete.
* gen_il-fields.ads (Opt_Field_Enum): Remove Size_Check_Code.
* gen_il-gen-gen_entities.adb (Constant_Or_Variable_Kind): Likewise.
* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Remove call
to Kill_Size_Check_Code.
* sem_prag.adb (Analyze_Pragma): Likewise.
* sem_util.ads (Kill_Size_Check_Code): Delete.
* sem_util.adb (Kill_Size_Check_Code): Likewise.

2 months agoada: Allow IN OUT parameters for first parameter of traversal functions
Claire Dross [Wed, 12 Feb 2025 11:10:20 +0000 (12:10 +0100)] 
ada: Allow IN OUT parameters for first parameter of traversal functions

In general, functions in SPARK cannot have parameters of mode IN OUT
unless they are annotated with the Side_Effects aspect. Borrowing
traversal functions are special functions which can return a part
of their first parameter as an access-to-variable type. This might not
be allowed in Ada if the parameter is a constant. Allow the first
parameter of borrowing traversal functions to have mode IN OUT.

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_SPARK_Subprogram_Specification):
Allow the first parameter of functions whose return type is
an anonymous access-to-variable type to have mode IN OUT.

2 months agoada: Improve large unconstrained-but-definite warning
Ronan Desplanques [Wed, 12 Feb 2025 18:09:18 +0000 (19:09 +0100)] 
ada: Improve large unconstrained-but-definite warning

Before this patch, Check_Discriminant_Use called Is_Limited type on
entities before they were fully analyzed. That caused Is_Limited_Type
to incorrectly return False for records that are limited because they
have a limited component.

This patch pushes back the emissions of the Check_Discriminant_Use
warning after analysis of record declarations. A new field to
E_Record_Type entity is added to take relevant discriminant uses into
account.

gcc/ada/ChangeLog:

* gen_il-fields.ads: New field.
* gen_il-gen-gen_entities.adb: New field.
* einfo.ads: Document new field.
* sem_res.adb (Check_Discriminant_Use): Record relevant uses in new
field. Move warning emission to...
* sem_ch3.adb (Analyze_Full_Type_Declaration): ... Here.

2 months agoada: Do not generate warning about missing overriding indicator
Steve Baird [Thu, 6 Feb 2025 01:35:16 +0000 (17:35 -0800)] 
ada: Do not generate warning about missing overriding indicator

We were previously generating a warning about a missing overriding
indicator in some cases when a dispatching subprogram is declared.
In at least some (and perhaps all) cases where this warning was generated,
it was incorrect. It was also generated very infrequently. The simple
solution is to stop generating the warning.

gcc/ada/ChangeLog:

* sem_disp.adb
(Check_Dispatching_Operation): Delete code to generate
"missing overriding indicator" warning. Update comments.

2 months agoada: Move standard subtype declarations generation
Ronan Desplanques [Wed, 12 Feb 2025 09:37:30 +0000 (10:37 +0100)] 
ada: Move standard subtype declarations generation

Before this patch, the subtype declarations for Standard.Natural and
Standard.Positive were created before the entity for Standard.Integer
was complete. In preparation of a future change that will make it
impossible to call Etype on an incomplete node, this patch delays the
creation of these subtype declarations. It doesn't affect the behavior
of the compiler.

gcc/ada/ChangeLog:

* cstand.adb (Create_Standard): Delay declaration generation for
Natural and Positive.

2 months agoada: Remove useless calls
Ronan Desplanques [Wed, 12 Feb 2025 09:34:06 +0000 (10:34 +0100)] 
ada: Remove useless calls

The subprogram calls this patch removes were useless because they were
already made in New_Standard_Entity.

gcc/ada/ChangeLog:

* cstand.adb (Create_Standard): Remove useless calls.

2 months agoada: Fix internal error on allocator involving interface type
Eric Botcazou [Tue, 11 Feb 2025 11:47:36 +0000 (12:47 +0100)] 
ada: Fix internal error on allocator involving interface type

The problem is that an itype duplicated through Duplicate_Subexpr_No_Checks
ends up in a different scope than its source.  It is fixed by adding a new
formal parameter New_Scope to the function and forwarding it in the call to
the New_Copy_Tree function.

gcc/ada/ChangeLog:

* exp_aggr.adb (Expand_Record_Aggregate): Use the named form for the
second actual parameter in the call to Duplicate_Subexpr.
* exp_attr.adb (Expand_Size_Attribute): Likewise.
* exp_ch5.adb (Expand_Assign_Array): Likewise.
(Expand_Assign_Array_Bitfield): Likewise.
(Expand_Assign_Array_Bitfield_Fast): Likewise.
* exp_util.ads (Duplicate_Subexpr): Add New_Scope formal parameter.
(Duplicate_Subexpr_No_Checks): Likewise.
(Duplicate_Subexpr_Move_Checks): Likewise.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Pass Proc_Id as the
actual for New_Scope in the calls to Duplicate_Subexpr_No_Checks.
(Duplicate_Subexpr): Add New_Scope formal parameter and forward it
in the call to New_Copy_Tree.
(Duplicate_Subexpr_No_Checks): Likewise.
(Duplicate_Subexpr_Move_Checks): Likewise.

2 months agoada: Fix for validity checking of limited scalar types
Piotr Trojanek [Tue, 28 Jan 2025 11:12:23 +0000 (12:12 +0100)] 
ada: Fix for validity checking of limited scalar types

With a recent change we are now validity checking objects of private scalar
types, but need to handle private scalar types whose public view is limited.

gcc/ada/ChangeLog:

* checks.adb (Insert_Valid_Check): Set flag Assignment_OK in the object
declaration inserted for the validity checks.

2 months agolibstdc++: Support wide characters output for sys_info and local_info [PR120565]
Tomasz Kamiński [Fri, 6 Jun 2025 07:07:49 +0000 (09:07 +0200)] 
libstdc++: Support wide characters output for sys_info and local_info [PR120565]

Formatting sys_info as wchar_t require widening of the abbrev (zone) member.
To support that we reuse the existing code in support for '%Z' specifier, for
local_time_format, and produce output using singe format call with
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]" format string. As noted in the
comment, produced output is locale independed, as it does not contain decimal
separtors.

For sys_info, the outputed literals are widended using _GLIBCXX_WIDEN, except
opening and closing brackets, that are fetched from __format::_Separators.

PR libstdc++/120565

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h
(operator<<(basic_ostream<_CharT, _Traits>&, const sys_info&))
(operator<<(basic_ostream<_CharT, _Traits>&, const local_info&)):
Support wchar_t as _CharT.
* testsuite/std/time/format/empty_spec.cc: Instantiated test_infos for
wchar_t and increase timeout.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agolibstdc++: Test for formatting with empty spec for local_info and sys_info.
Tomasz Kamiński [Thu, 5 Jun 2025 14:27:41 +0000 (16:27 +0200)] 
libstdc++: Test for formatting with empty spec for local_info and sys_info.

We do not test with wchar_t currently, as operator<< (and format) are
ill-formed in such case, because we do not widen abbrev member of local_info.

Adding a tests for behavior of the ostream operator and the formatting
with empty chrono-spec for the chrono types. The coverage is now
complete:
 * sys_info, local_info in this commit,
 * time point, zoned_time and local_time_format in r16-1107-g3cfa53aa95a19c,
 * duration and hh_mm_ss in r16-1099-gac0a04b7a254fb,
 * calendar types in r16-1016-g28a17985dd34b7.

Finally, the timeout for the test was increased again and preprocessor checks
for zoned_time where changed to _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
to match ones from bits/chrono_io.h file.

libstdc++-v3/ChangeLog:

* testsuite/std/time/format/empty_spec.cc: New tests and increased
timeout.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoRISC-V: Support -mcpu for XiangShan Kunminghu cpu.
Jiawei [Wed, 4 Jun 2025 09:56:49 +0000 (17:56 +0800)] 
RISC-V: Support -mcpu for XiangShan Kunminghu cpu.

This patch adds support for the XiangShan Kunminghu CPU in GCC, allowing
the use of the `-mcpu=xiangshan-kunminghu` option.

XiangShan-KunMingHu is the third-generation open-source high-performance
RISC-V processor.[1] You can find the corresponding ISA extension from the
XiangShan Github repository.[2] The latest news of KunMingHu can be found
in the XiangShan Biweekly.[3]

[1] https://github.com/OpenXiangShan/XiangShan-User-Guide/releases.
[2] https://github.com/OpenXiangShan/XiangShan/blob/master/src/main/scala/xiangshan/Parameters.scala
[3] https://docs.xiangshan.cc/zh-cn/latest/blog

A dedicated scheduling model for KunMingHu's hybrid pipeline will be
proposed in a subsequent PR.

gcc/ChangeLog:

* config/riscv/riscv-cores.def (RISCV_TUNE): New cpu tune.
(RISCV_CORE): New cpu.
* doc/invoke.texi: Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/mcpu-xiangshan-kunminghu.c: New test.

Co-Authored-By: Jiawei Chen <jiawei@iscas.ac.cn>
Co-Authored-By: Yangyu Chen <cyy@cyyself.name>
Co-Authored-By: Tang Haojin <tanghaojin@outlook.com>
2 months agotree-optimization/120032 - CLZ matching, fallback for missing range-info
Richard Biener [Thu, 5 Jun 2025 12:23:06 +0000 (14:23 +0200)] 
tree-optimization/120032 - CLZ matching, fallback for missing range-info

The following allows us to emit a conditional move when the value
of the table based CLZ/CLZ implementation at zero differs from what
the target implementation guarantees or we cannot easily fixup
otherwise.  In that case emit a val == 0 ? table-based-zero-result : ...

PR tree-optimization/120032
* tree-ssa-forwprop.cc (simplify_count_zeroes): When we cannot use
the IFN to determine the result at zero use a conditional move
to reproduce the correct result from the table-based
algorithm.

* gcc.target/i386/pr120032-3.c: New testcase.

2 months agotree-optimization/120032 - matching of table based CLZ
Richard Biener [Wed, 28 May 2025 13:09:19 +0000 (15:09 +0200)] 
tree-optimization/120032 - matching of table based CLZ

The following adds the ability to match a table based CLZ implementation
similar as to how we can do for CTZ.  I'm re-using the workers for
matching up array and string tables by using a lambda and templates
and kept the transform step for CLZ/CTZ inter-mangled.

PR tree-optimization/120032
* match.pd (clz_table_index): New match.
* tree-ssa-forwprop.cc (check_table_array): Rename from
check_ctz_array.  Split out actual verification to a functor.
(check_table_string): Rename from check_ctz_string and likewise.
(check_table): Rename from check_ctz_table and adjust.
(gimple_clz_table_index): Declare.
(simplify_count_zeroes): Rename from simplify_count_trailing_zeroes.
Extend to cover CLZ.
(pass_forwprop::execute): Adjust.

* gcc.target/i386/pr120032-1.c: New testcase.
* gcc.target/i386/pr120032-2.c: Likewise.

2 months agoUse ranger for table based CTZ detection
Richard Biener [Wed, 28 May 2025 13:26:48 +0000 (15:26 +0200)] 
Use ranger for table based CTZ detection

The following uses context sensitive ranger for determining whether
the input to the table based CTZ is ever zero.

* tree-ssa-forwprop.cc (simplify_count_trailing_zeroes):
Use ranger instead of tree_expr_nonzero_p.

2 months agoRefactor CTZ detection in forwprop
Richard Biener [Wed, 28 May 2025 12:13:00 +0000 (14:13 +0200)] 
Refactor CTZ detection in forwprop

The following refactors the CTZ detection code to be more easily
extensible to also handle CLZ.

* tree-ssa-forwprop.cc (optimize_count_trailing_zeroes):
Inline into ...
(simplify_count_trailing_zeroes): ... this function.
Split out ...
(check_ctz_table): ... a wrapper for CONSTRUCTOR vs. STRING_CST
handling.

2 months agoDaily bump.
GCC Administrator [Fri, 6 Jun 2025 00:18:30 +0000 (00:18 +0000)] 
Daily bump.

2 months ago[RISC-V] Improve signed division by 2^n
Jeff Law [Thu, 5 Jun 2025 22:58:45 +0000 (16:58 -0600)] 
[RISC-V] Improve signed division by 2^n

So another class of cases where we can do better than a zicond sequence.  Like
the prior patch this came up evaluating some code from Shreya to detect more
conditional move cases.

This patch allows us to use the "splat the sign bit" idiom to efficiently
select between 0 and 2^n-1.  That's particularly important for signed division
by a power of two.

For signed division by a power of 2, you conditionally add 2^n-1 to the
numerator, then right shift that result.  Using zicond somewhat naively you get
something like this (for n / 4096):

>         li      a5,4096
>         addi    a5,a5,-1
>         slti    a4,a0,0
>         add     a5,a0,a5
>         czero.eqz       a5,a5,a4
>         czero.nez       a0,a0,a4
>         add     a0,a0,a5
>         srai    a0,a0,12

After this patch you get this instead:

>         srai    a5,a0,63
>         srli    a5,a5,52
>         add     a0,a5,a0
>         srai    a0,a0,12

It's not *that* much faster, but it's certainly shorter.

So the trick here is that after splatting the sign bit we have 0, -1. So a
subsequent logical shift right would generate 0 or 2^n-1.

Yes, there a nice variety of other constant pairs we can select between. Some
notes have been added to the PR I opened yesterday.

The first thing we need to do is throttle back zicond generation. Unfortunately
we don't see the constants from the division-by-2^n algorithm, so we have to
disable for all lt/ge 0 cases.  This can have small negative impacts.  I looked
at this across spec and didn't see anything I was particularly worried about
and numerous small improvements from that alone.

With that in place we need to recognize the form seen by combine. Essentially
it sees the splat of the sign bit feeding a logical AND. We split that into two
right shifts.

This has survived in my tester.  Waiting on upstream pre-commit before moving
forward.

gcc/
* config/riscv/riscv.cc (riscv_expand_conditional_move): Avoid
zicond in some cases involving sign bit tests.
* config/riscv/riscv.md: Split a splat of the sign bit feeding a
masking off high bits into a pair of right shifts.

gcc/testsuite
* gcc.target/riscv/nozicond-3.c: New test.

2 months ago[i386] Improve "mov<mode>cc" expander for DImode immediates [PR120553]
Uros Bizjak [Thu, 5 Jun 2025 20:53:35 +0000 (22:53 +0200)] 
[i386] Improve "mov<mode>cc" expander for DImode immediates [PR120553]

"mov<mode>cc" expander uses x86_64_general_operand predicate that limits the
range of immediate operands to 32-bit size.  The usage of this predicate
causes ifcvt to force out-of-range immediates to registers when converting
through noce_try_cmove.  The testcase:

long long foo (long long c) { return c >= 0 ? 0x400000000ll : -1ll; }

compiles (-O2) to:

foo:
testq %rdi, %rdi
movq $-1, %rax
movabsq $0x400000000, %rdx
cmovns %rdx, %rax
ret

The above testcase can be compiled to a more optimized code without
problematic CMOV instruction if 64-bit immediates are allowed in
"mov<mode>cc" expander:

foo:
movq %rdi, %rax
sarq $63, %rax
btsq $34, %rax
ret

The expander calls the ix86_expand_int_movcc function which internally
sanitizes arguments of emitted logical insns using expand_simple_binop.
The out-of-range immediates are forced to a temporary register just
before the instruction, so the instruction combiner is then able to
synthesize 64-bit BTS instruction.

The code improves even for non-exact-log2 64-bit immediates, e.g.

long long foo (long long c) { return c >= 0 ? 0x400001234ll : -1ll; }

that now compiles to:

foo:
        movabsq $0x400001234, %rdx
        movq    %rdi, %rax
        sarq    $63, %rax
        orq     %rdx, %rax
        ret

again avoiding problematic CMOV instruction.

PR target/120553

gcc/ChangeLog:

* config/i386/i386.md (mov<mode>cc): Use "general_operand"
predicate for operands 2 and 3 for all modes.

gcc/testsuite/ChangeLog:

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

2 months agodoc: update links to c99status.html
Marek Polacek [Thu, 5 Jun 2025 19:50:45 +0000 (15:50 -0400)] 
doc: update links to c99status.html

gcc/ChangeLog:

* doc/invoke.texi: Update a link to c99status.html.
* doc/standards.texi: Likewise.

2 months agoCCP: Manually rename the virtual mem op when inserting clobbers
Andrew Pinski [Sat, 31 May 2025 05:30:01 +0000 (22:30 -0700)] 
CCP: Manually rename the virtual mem op when inserting clobbers

Right now the only place where CCP needs to have the virtual op renamed is
after inserting clobbers which come right before __builtin_stack_restore.
So let's manually do the correct thing so we can remove the TODO_update_ssa todo.

gcc/ChangeLog:

* tree-ssa-ccp.cc (insert_clobber_before_stack_restore): Update the virtual
op on the inserted clobber and the stack restore function.
(do_ssa_ccp): Don't add TODO_update_ssa to the todo.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agocobol: Guard clock_gettime(). [PR119975]
Robert Dubner [Thu, 5 Jun 2025 14:53:02 +0000 (10:53 -0400)] 
cobol: Guard clock_gettime(). [PR119975]

This attempts to eliminate "'clock_gettime' not declared..." when
building on x86_64-apple-darwin15.6.0.  Calls to clock_gettime have been
reduced to two locations.  Both have been guarded with

gcc/cobol/ChangeLog:

PR cobol/119975
* genapi.cc (parser_intrinsic_call_0): Use get_time_nanoseconds().
* genutil.cc (get_time_64): Rename to get_time_nanoseconds().
(get_time_nanoseconds): Likewise.
* genutil.h (get_time_64): Likewise.
(get_time_nanoseconds): Likewise.
* util.cc (class cbl_timespec): Timing routine uses
get_time_nanoseconds().
(operator-): Likewise.
(parse_file): Likewise.

libgcobol/ChangeLog:

PR cobol/119975
* configure.ac: AC_CHECK_LIB(rt, clock_gettime).
* config.h.in: Likewise.
* configure: Likewise.
* gfileio.cc: Remove in-line cppcheck-suppress.
* intrinsic.cc (timespec_to_string): Use guarded clock_gettime().
(__gg__current_date): Likewise.
(__gg__seconds_past_midnight): Likewise.
(__gg__formatted_current_date): Likewise.
(__gg__random): Likewise.
(__gg__random_next): Likewise.
(__gg__when_compiled): Likewise.
* libgcobol.cc (cobol_time): Likewise.
(get_time_nanoseconds): Likewise.
(__gg__clock_gettime): Likewise.
(__gg__get_date_hhmmssff): Likewise.
* libgcobol.h (__gg__clock_gettime): Likewise.
(struct cbl_timespec): Likewise.

2 months agoaarch64:sve: Use make_ssa_name instead of create_tmp_var in the folder
Andrew Pinski [Sat, 31 May 2025 17:22:34 +0000 (10:22 -0700)] 
aarch64:sve: Use make_ssa_name instead of create_tmp_var in the folder

Currently gimple_folder::convert_and_fold calls create_tmp_var; that
means while in ssa form, the pass which calls fold_stmt will always
have to update the ssa (via TODO_update_ssa or otherwise).  This seems
not very useful since we know that this will always be a ssa name, using
make_ssa_name instead is better and don't need to depend on the ssa updater.
Plus this should have a small compile time performance and memory usage
improvement too since this uses an anonymous ssa name rather than creating a
full decl for this.

Changes since v1:
* Use make_ssa_name instead of create_tmp_reg_or_ssa_name, anonymous ssa
  names are allowed early on in gimple too.

Built and tested on aarch64-linux-gnu.

gcc/ChangeLog:

* config/aarch64/aarch64-sve-builtins.cc: Include value-range.h and tree-ssanames.h
(gimple_folder::convert_and_fold): Use make_ssa_name
instead of create_tmp_var for the temporary. Add comment about callback argument.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agoranger: Add support for float <-> int casts [PR120231]
Jakub Jelinek [Thu, 5 Jun 2025 16:10:22 +0000 (18:10 +0200)] 
ranger: Add support for float <-> int casts [PR120231]

The following patch adds support for float <-> integer conversions in
ranger.
The patch reverts part of the r16-571 changes, those changes were right
for fold_range, but not for op1_range, where RO_IFI and RO_FIF are actually
called rather than RO_IFF and RO_FII that the patch expected.
Also, the float -> int operation actually uses FIX_TRUNC_EXPR tree code
rather than NOP_EXPR or CONVERT_EXPR and int -> float uses FLOAT_EXPR,
but I think we can just handle all of them using operator_cast, at least
as long as we don't try to use VIEW_CONVERT_EXPR using that too; not really
sure handling VCE at least for floating to integral or vice versa would
be actually useful though.

The patch "regressed" two tests, gfortran.dg/inline_matmul_16.f90 and
g++.dg/tree-ssa/loop-split-1.C.  In the first case, there is a loop doing
matmul on various sizes of matrices, up to 10x10 matrices, and Fortran
FE given the options emits two implementations of the matmul, one inline
for the case where the matmul has less than 1000 elements and one for
larger matmuls.  The check for whatever reason uses floating point
calculations and before this patch we weren't able to prove that all the
matrices will be smaller than the cutoff and the test was checking for
presence of the fallback call; with the patch we are able to figure it
out and only keep the inline copy.  I've duplicated the test, once
unmodified source which doesn't expect _gfortran_matmul string in optimized
dump anymore, and another copy which uses volatile ten instead of 10 in
loop upper bounds so that it has to keep the fallback and scans for it.
The other test is g++.dg/tree-ssa/loop-split-1.C, which does
constexpr unsigned s = 100000000;
...
    for(unsigned i = 0; i < s; ++i)
    {
        if(i == 0)
            a[i] = b[i] * c[i];
        else
            a[i] = (b[i] + c[i]) * c[i-1] * std::log(i);
    }
and for some reason the successful loop splitting for which the test
searches in a dump file is dependent on the errno fallback of std::log,
where we do t = std::log((double)i); if ((double)i) u> 0); else log ((double)i);
But i goes only from 1 to 100000000, so (double)i has the range
[1.0, 100000000.0] with the patch and so we see it will never need errno
nor raise exception.  I've tested adding + d for it where d is 0.0 but
modifiable in some other TU, and tested it also with r14-2851 and r14-2852,
where the former FAILed the test both unmodified and modified, while
the latter PASSed both versions.

2025-06-05  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/120231
* range-op.cc (range_op_table::range_op_table): Register op_cast
also for FLOAT_EXPR and FIX_TRUNC_EXPR.
(RO_III): Adjust comment.
(range_op_handler::op1_range): Handle RO_IFI rather than RO_IFF.
Don't handle RO_FII.
(range_operator::op1_range): Remove overload with
irange &, tree, const frange &, const frange &, relation_trio
and frange &, tree, const irange &, const irange &, relation_trio
arguments.  Add overload with
irange &, tree, const frange &, const irange &, relation_trio
arguments.
* range-op-mixed.h (operator_cast::op1_range): Remove overload with
irange &, tree, const frange &, const frange &, relation_trio
and frange &, tree, const irange &, const irange &, relation_trio
arguments.  Add overload with
irange &, tree, const frange &, const irange &, relation_trio and
frange &, tree, const irange &, const frange &, relation_trio
arguments.
* range-op.h (range_operator::op1_cast): Remove overload with
irange &, tree, const frange &, const frange &, relation_trio
and frange &, tree, const irange &, const irange &, relation_trio
arguments.  Add overload with
irange &, tree, const frange &, const irange &, relation_trio
arguments.
* range-op-float.cc (operator_cast::fold_range): Implement
float to int and int to float casts.
(operator_cast::op1_range): Remove overload with
irange &, tree, const frange &, const frange &, relation_trio
and frange &, tree, const irange &, const irange &, relation_trio
arguments.  Add overload with
irange &, tree, const frange &, const irange &, relation_trio and
frange &, tree, const irange &, const frange &, relation_trio
arguments and implement reverse op of float to int and int to float
cast there.

* gcc.dg/tree-ssa/pr120231-2.c: New test.
* gcc.dg/tree-ssa/pr120231-3.c: New test.
* gfortran.dg/inline_matmul_16.f90: Don't expect any _gfortran_matmul
strings in optimized dump.
* gfortran.dg/inline_matmul_26.f90: New test.
* g++.dg/tree-ssa/loop-split-1.C (d): New variable.
(main): Use std::log (i + d) instead of std::log (i).

2 months agoFix typo in afdo_calculate_branch_prob
Jan Hubicka [Thu, 5 Jun 2025 16:10:16 +0000 (18:10 +0200)] 
Fix typo in afdo_calculate_branch_prob

gcc/ChangeLog:

* auto-profile.cc (afdo_calculate_branch_prob): Fix typo
in previous patch.

2 months agoaarch64: Add testcase for vld2 which was fixed by r16-1113 [PR89606]
Andrew Pinski [Wed, 4 Jun 2025 21:32:33 +0000 (14:32 -0700)] 
aarch64: Add testcase for vld2 which was fixed by r16-1113 [PR89606]

This aarch64 specific vld2 intrinsics testcase was fixed by r16-1113-g069caa5cea91f
(simple copy propagation for aggregates). I didn't include it in the original
patch as I was testing on x86_64 but I got around to testing this
and now we don't have any more extra movs so let's add a testcase.

Tested for aarch64-linux-gnu.

PR tree-optimization/89606

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/vld2-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agoc++: substituting fn parm redeclared with dep alias tmpl [PR120224]
Patrick Palka [Thu, 5 Jun 2025 15:07:25 +0000 (11:07 -0400)] 
c++: substituting fn parm redeclared with dep alias tmpl [PR120224]

Here we declare f twice, the second time around using a dependent
alias template.  Due to alias template transparency these are logically
the same overload.  But now the function type of f (produced from the
first declaration) diverges from the type of its formal parameter
(produced from the subsequent redefinition) in that substituting T=int
succeeds for the function type but not for the formal parameter type.
This eventually causes us to produce an undiagnosed error_mark_node in
the AST of the function call, leading to failure of the sanity check
check added in r14-6343-g0c018a74eb1aff.

Before r14-6343 we would still go on to reject the testcase later at
instantiation time, from regenerate_decl_from_template, making this a
regression.

To fix this, it seems we just need to propagate error_mark_node upon
substitution failure into the type of a PARM_DECL.

PR c++/120224

gcc/cp/ChangeLog:

* pt.cc (tsubst_function_decl): Return error_mark_node if
substituting into the formal parameter list failed.
(tsubst_decl) <case PARM_DECL>: Return error_mark_node
upon TREE_TYPE substitution failure, when in a SFINAE
context.  Return error_mark_node upon DECL_CHAIN substitution
failure.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/alias-decl-80.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: quadratic constexpr folding of arith expr [PR118340]
Patrick Palka [Thu, 5 Jun 2025 15:06:04 +0000 (11:06 -0400)] 
c++: quadratic constexpr folding of arith expr [PR118340]

Here the PR's testcase demonstrates that the cp_fully_fold calls in
cp_build_binary_op (for diagnosing arithmetic overflow) lead to
quadratic behavior when building up a large arithmetic constant
expression.  The problem is ultimately that maybe_constant_value's
caching doesn't reuse intermediate values, unlike cp_fold.  (And
unfortunately we can't leverage the cp_fold cache in this call site
because here we want to evaluate constexpr calls even in -O0, which
cp_fold avoids.)

This patch fixes this by making maybe_constant_value look up each
operand of the given expression to see if we've previously reduced it,
and if so, rebuild the expression using the (presumably) reduced
operands and evaluate that.  After this patch each version of the
testcase from the PR compiles in ~0.1s on my machine.

PR c++/118340

gcc/cp/ChangeLog:

* constexpr.cc (maybe_constant_value): First try looking up each
operand in the cv_cache and reusing the result.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoRISC-V: Don't use structured binding in riscv-common.cc
Kito Cheng [Thu, 5 Jun 2025 07:23:59 +0000 (15:23 +0800)] 
RISC-V: Don't use structured binding in riscv-common.cc

It's new C++ language feature introduced in C++17, which is higher than
the build environment required by the GCC (C++14).

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc: Remove structured binding
from the code.

2 months agoreal: Fix up real_from_integer [PR120547]
Jakub Jelinek [Thu, 5 Jun 2025 13:47:19 +0000 (15:47 +0200)] 
real: Fix up real_from_integer [PR120547]

The function has 2 problems, one is _BitInt specific and the other is
most likely also reproduceable only with it.

The first issue is that I've missed updating the function for _BitInt,
maxbitlen as MAX_BITSIZE_MODE_ANY_INT + HOST_BITS_PER_WIDE_INT
obviously isn't guaranteed to be larger than any integral type we might
want to convert at compile time from wide_int to REAL_VALUE_FORMAT.
Just using len instead of it works fine, at least when used after
HOST_BITS_PER_WIDE_INT is added to it and it is truncated to multiples
of HOST_BITS_PER_WIDE_INT.

The other bug is that if the value has too many significant bits (formerly
maxbitlen - cnt_l_z, now len - cnt_l_z), the code just shifts it right and
adds the shift count to the future exponent.  That isn't correct for
rounding as the testcase attempts to show, the internal real format has more
bits than any precision in supported format, but we still need to
distinguish bewtween values exactly half way between representable floating
point values (those should be rounded to even) and the case when we've
shifted away some non-zero bits, so the value was tiny bit larger than half
way and then we should round up.

The patch uses something like e.g. soft-fp uses in these cases, right shift
with sticky bit in the least significant bit.

2025-06-05  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/120547
* real.cc (real_from_integer): Remove maxbitlen variable, use
len instead of that.  When shifting right, or in 1 if any of the
shifted away bits are non-zero.  Formatting fix.

* gcc.dg/bitint-123.c: New test.

2 months agolibstdc++: Fix std::format thousands separators when sign present [PR120548]
Jonathan Wakely [Wed, 4 Jun 2025 17:22:28 +0000 (18:22 +0100)] 
libstdc++: Fix std::format thousands separators when sign present [PR120548]

The leading sign character should be skipped when deciding whether to
insert thousands separators into a floating-point format.

libstdc++-v3/ChangeLog:

PR libstdc++/120548
* include/std/format (__formatter_fp::_M_localize): Do not
include a leading sign character in the string to be grouped.
* testsuite/std/format/functions/format.cc: Check grouping when
sign is present in the output.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoFix handling of GUESSED_LOCAL in auto-fdo and preserve more static profile
Jan Hubicka [Thu, 5 Jun 2025 13:24:36 +0000 (15:24 +0200)] 
Fix handling of GUESSED_LOCAL in auto-fdo and preserve more static profile

This patch fixes ICE where GUESSED_LOCAL was kept in autofdo profile.
It may make more sense to turn GESSED_LOCAL 0 to GUESSED 0 since it seems
bit more informative then autofdo 0 (which really means that count is below
the 2% threshold or that info was lost due to some code transformation).

The patch also modifies code setting probabilities of edge to keep reliable
predictions of 0 or 1.

gcc/ChangeLog:

* auto-profile.cc (update_count_by_afdo_count): Fix handling
of GUESSED_LOCAL.
(afdo_calculate_branch_prob): Preserve static profile for
probabilities 0 and 1.

2 months agoRISC-V: Fix ICE for gcc.dg/graphite/pr33576.c with rv32gcv
Pan Li [Thu, 5 Jun 2025 03:04:33 +0000 (11:04 +0800)] 
RISC-V: Fix ICE for gcc.dg/graphite/pr33576.c with rv32gcv

The div of rvv has not such insn v2 = div (vec_dup (x), v1), thus
the generated rtl like that hit the unreachable assert when
expand insn.  This patch would like to remove op div from
the binary op form (vec_dup (x), v) to avoid pattern matching
by mistake.

No new test introduced as pr33576.c covered already.

The below test suites are passed for this patch series.
* The rv64gcv fully regression test.

gcc/ChangeLog:

* config/riscv/autovec-opt.md: Leverage vdup_v and v_vdup
binary op for different patterns.
* config/riscv/vector-iterators.md: Add vdup_v and v_vdup
binary op iterators.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months ago[RISC-V] Improve sequences to generate -1, 1 in some cases.
Jeff Law [Thu, 5 Jun 2025 12:17:25 +0000 (06:17 -0600)] 
[RISC-V] Improve sequences to generate -1, 1 in some cases.

This patch has a minor improvement to if-converted sequences based on
observations I found while evaluating another patch from Shreya to handle more
cases with zicond insns.

Specifically there is a smaller/faster way than zicond to generate a -1,1
result when the condition is testing the sign bit.

So let's consider these two tests (rv64):

long foo1 (long c, long a) { return c >= 0 ? 1 : -1; }
long foo2 (long c, long a) { return c < 0 ? -1 : 1; }

So if we right arithmetic shift c by 63 bits, that splats the sign bit across a
register giving us 0, -1 for the first test and -1, 0 for the second test.  We
then unconditionally turn on the LSB resulting in 1, -1 for the first case and
-1, 1 for the second.

This is implemented as a 4->2 splitter.  There's another pair of cases we don't
handle because we don't have 4->3 splitters.  Specifically if the true/false
values are reversed in the above examples without reversing the condition.

Raphael is playing a bit in the gimple space to see what opportunities might
exist to recognize more idioms in phiopt and generate better code earlier.  No
idea how that's likely to pan out.

This is a pretty consistent small win.  It's been through the rounds in my
tester.  Just waiting on a green light from pre-commit testing.

gcc/
* config/riscv/zicond.md: Add new splitters to select
1, -1 or -1, 1 based on a sign bit test.

gcc/testsuite/

* gcc.target/riscv/nozicond-1.c: New test.
* gcc.target/riscv/nozicond-2.c: New test.

2 months agoRISC-V: Support Ssu64xl extension.
Jiawei [Thu, 5 Jun 2025 05:59:14 +0000 (13:59 +0800)] 
RISC-V: Support Ssu64xl extension.

Support the Ssu64xl extension, which requires UXLEN to be 64.

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension definition.
* config/riscv/riscv-ext.opt: New extension mask.
* doc/riscv-ext.texi: Document the new extension.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-ssu64xl.c: New test.

Signed-off-by: Jiawei <jiawei@iscas.ac.cn>
2 months agoRISC-V: Support Sstvecd extension.
Jiawei [Thu, 5 Jun 2025 05:52:08 +0000 (13:52 +0800)] 
RISC-V: Support Sstvecd extension.

Support the Sstvecd extension, which allows Supervisor Trap Vector
Base Address register (stvec) to support Direct mode.

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension definition.
* config/riscv/riscv-ext.opt: New extension mask.
* doc/riscv-ext.texi: Document the new extension.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-sstvecd.c: New test.

Signed-off-by: Jiawei <jiawei@iscas.ac.cn>
2 months agoRISC-V: Support Sstvala extension.
Jiawei [Thu, 5 Jun 2025 05:46:39 +0000 (13:46 +0800)] 
RISC-V: Support Sstvala extension.

Support the Sstvala extension, which provides all needed values in
Supervisor Trap Value register (stval).

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension definition.
* config/riscv/riscv-ext.opt: New extension mask.
* doc/riscv-ext.texi: Document the new extension.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-sstvala.c: New test.

Signed-off-by: Jiawei <jiawei@iscas.ac.cn>
2 months agoRISC-V: Support Sscounterenw extension.
Jiawei [Thu, 5 Jun 2025 05:33:21 +0000 (13:33 +0800)] 
RISC-V: Support Sscounterenw extension.

Support the Sscounterenw extension, which allows writeable enables for any
supported counter.

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension definition.
* config/riscv/riscv-ext.opt: New extension mask.
* doc/riscv-ext.texi: Document the new extension.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-sscounterenw.c: New test.

Signed-off-by: Jiawei <jiawei@iscas.ac.cn>
2 months agoRISC-V: Support Ssccptr extension.
Jiawei [Thu, 5 Jun 2025 05:15:02 +0000 (13:15 +0800)] 
RISC-V: Support Ssccptr extension.

Support the Ssccptr extension, which allows the main memory to support
page table reads.

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension definition.
* config/riscv/riscv-ext.opt: New extension mask.
* doc/riscv-ext.texi: Document the new extension.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-ssccptr.c: New test.

Signed-off-by: Jiawei <jiawei@iscas.ac.cn>
2 months agoRISC-V: Support Smrnmi extension.
Jiawei [Thu, 5 Jun 2025 03:24:43 +0000 (11:24 +0800)] 
RISC-V: Support Smrnmi extension.

Support the Smrnmi extension, which provides new CSRs
for Machine mode Non-Maskable Interrupts.

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension definition.
* config/riscv/riscv-ext.opt: New extension mask.
* doc/riscv-ext.texi: Document the new extension.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-smrnmi.c: New test.

Signed-off-by: Jiawei <jiawei@iscas.ac.cn>
2 months agoRISC-V: Support Sm/scsrind extensions.
Jiawei [Thu, 5 Jun 2025 02:16:19 +0000 (10:16 +0800)] 
RISC-V: Support Sm/scsrind extensions.

Support the Sm/scsrind extensions, which provide indirect access to
machine-level CSRs.

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension definition.
* config/riscv/riscv-ext.opt: New extension mask.
* doc/riscv-ext.texi: Document the new extension.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-smcsrind.c: New test.

Signed-off-by: Jiawei <jiawei@iscas.ac.cn>
2 months agoFix crash with constant initializer caused by IPA
Eric Botcazou [Thu, 5 Jun 2025 11:20:26 +0000 (13:20 +0200)] 
Fix crash with constant initializer caused by IPA

The testcase compiled with -O2 -gnatn makes the compiler crash in
vect_can_force_dr_alignment_p during SLP vectorization:

  if (decl_in_symtab_p (decl)
      && !symtab_node::get (decl)->can_increase_alignment_p ())
    return false;

because symtab_node::get (decl) returns a null node.  The phenomenon occurs
for a pair of twin symbols listed like so in .cgraph:

Opt7_Pkg.T12b/17 (Opt7_Pkg.T12b)
  Type: variable definition analyzed
  Visibility: semantic_interposition external public artificial
  Aux: @0x44d45e0
  References:
  Referring: opt7_pkg__enum_name_table/13 (addr) opt7_pkg__enum_name_table/13
(addr)
  Availability: not-ready
  Varpool flags: initialized read-only const-value-known

Opt7_Pkg.T8b/16 (Opt7_Pkg.T8b)
  Type: variable definition analyzed
  Visibility: semantic_interposition external public artificial
  Aux: @0x7f9fda3fff00
  References:
  Referring: opt7_pkg__enum_name_table/13 (addr) opt7_pkg__enum_name_table/13
(addr)
  Availability: not-ready
  Varpool flags: initialized read-only const-value-known

with:

opt7_pkg__enum_name_table/13 (Opt7_Pkg.Enum_Name_Table)
  Type: variable definition analyzed
  Visibility: semantic_interposition external public
  Aux: @0x44d45e0
  References: Opt7_Pkg.T8b/16 (addr) Opt7_Pkg.T8b/16 (addr) Opt7_Pkg.T12b/17
(addr) Opt7_Pkg.T12b/17 (addr)
  Referring: opt7_pkg__image/2 (read) opt7_pkg__image/2 (read)
opt7_pkg__image/2 (read) opt7_pkg__image/2 (read) opt7_pkg__image/2 (read)
opt7_pkg__image/2 (read) opt7_pkg__image/2 (read) opt7_pkg__image/2 (read)
  Availability: not-ready
  Varpool flags: initialized read-only const-value-known

being the crux of the matter.

What happens is that symtab_remove_unreachable_nodes leaves the last symbol
in kind of a limbo state: in .remove_symbols, we have:

opt7_pkg__enum_name_table/13 (Opt7_Pkg.Enum_Name_Table)
  Type: variable
  Body removed by symtab_remove_unreachable_nodes
  Visibility: externally_visible semantic_interposition external public
  References:
  Referring: opt7_pkg__image/2 (read) opt7_pkg__image/2 (read)
  Availability: not_available
  Varpool flags: initialized read-only const-value-known

This means that the "body" (DECL_INITIAL) of the symbol has been disregarded
during reachability analysis, causing the first two symbols to be discarded:

Reclaiming variables: Opt7_Pkg.T12b/17 Opt7_Pkg.T8b/16

but the DECL_INITIAL is explicitly preserved for later constant folding,
which makes it possible to retrofit the DECLs corresponding to the first
two symbols in the GIMPLE IR and ultimately leads to the crash.

gcc/
* tree-vect-data-refs.cc (vect_can_force_dr_alignment_p): Return
false if the variable has no symtab node.

gcc/testsuite/
* gnat.dg/specs/opt7.ads: New test.
* gnat.dg/specs/opt7_pkg.ads: New helper.
* gnat.dg/specs/opt7_pkg.adb: Likewise.

2 months agolibstdc++: Export std::indirect and std::polymorphic from std module [PR119152]
Tomasz Kamiński [Wed, 4 Jun 2025 14:39:43 +0000 (16:39 +0200)] 
libstdc++: Export std::indirect and std::polymorphic from std module [PR119152]

PR libstdc++/119152

libstdc++-v3/ChangeLog:

* src/c++23/std.cc.in (std::indirect, pmr::indirect)
[__cpp_lib_indirect]
(std::polymorphic, pmr::polymorphic) [__cpp_lib_polymorphic]: Export.

2 months agomiddle-end: Fix operation_could_trap_p for FIX_TRUNC expressions
Spencer Abson [Tue, 3 Jun 2025 12:15:12 +0000 (12:15 +0000)] 
middle-end: Fix operation_could_trap_p for FIX_TRUNC expressions

Floating-point to integer conversions can be inexact or invalid (e.g., due to
overflow or NaN).  However, since users of operation_could_trap_p infer the
bool FP_OPERATION argument from the expression's type, the FIX_TRUNC family
are considered non-trapping here.

This patch handles them explicitly.

gcc/ChangeLog:

* tree-eh.cc (operation_could_trap_helper_p): Cover FIX_TRUNC
expressions explicitly.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve/pr96357.c: Change to avoid producing
a conditional FIX_TRUNC_EXPR, whilst still reproducing the bug
in PR96357.
* gcc.dg/tree-ssa/ifcvt-fix-trunc-1.c: New test.
* gcc.dg/tree-ssa/ifcvt-fix-trunc-2.c: Likewise.

2 months agolibstdc++: Fix formatting of 3-digits months,day,weekday and hour [PR120481]
Tomasz Kamiński [Mon, 2 Jun 2025 07:06:56 +0000 (09:06 +0200)] 
libstdc++: Fix formatting of 3-digits months,day,weekday and hour [PR120481]

This patch fixes the handle multiple digits values for the month, day, weekday
and hour, when used with the %m, %d, %e, %m, %u, %w, %H, and %D, %F specifiers.
The values are now  printed unmodified. This patch also fixes printing negative
year with %F, where the values was not padded to four digits.

Furthemore, the %I,%p are adjusted to handle input with hours values set to
over 24 hours. In the case the values is interpretd modulo 24. This was already
the case for %r (locale's 12-hour clock), as we convert the input into seconds.

In case of %u, %w we print values unchanged, this makes the behavior of this
specifiers equivalent to printing the iso_encoding and c_encoding respectively.
As constructing weekday from value 7, initializes it with 0, the !ok() weekdays
values are always greater of equal eight, so they are clearly distinguishable.

The months, weekday, day values that can have 3 decimal digit as maximum
(range [0, 255]), we are using new _S_str_d1, _S_str_d2 that return string_view
containing textual representation, without padding or padded to two digits.
This function accepts are 3 character buffer, that are used for 3 digits number.
In other cases, we return _S_digit and _S_two_digits result directly. The former
is changed to return string_view to facilitate this.

For %F and %D when at least one component have more digits that expected (2 for
month and day, 4 for year), we produce output using format_to with appropriate
format string. Otherwise the representation is produced in local char buffer.
Two simply fill this buffer, _S_fill_two_digits function was added. We also
make sure that minus is not included in year width for %F.

The handling of %C, %Y, %y was adjusted to use similar pattern, for years with
more than two digits. To support that the order of characters in _S_chars was
adjusted so it contain "-{}" string.

For handling of %H, we print 3 or more digits values using format_to. The handling
for large hours values in %T and %R was changed, so they printed using format_to,
and otherwise we use same stack buffer as for minutes to print them.

PR libstdc++/120481

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__format::_S_chars): Reorder so it
contains "-{}".
(__format::_S_colon, __format::_S_slash, __format::_S_space)
(__format::_S_plus_minus): Updated starting indicies.
(__format::_S_minus_empty_spec): Define.
(__formatter_chrono::_M_C_y_Y, __formatter_chrono::_M_R_T):
Rework implementation.
(__formatter_chrono::_M_d_e, __formatter_chrono::_M_F)
(__formatter_chrono::_M_m, __formatter_chrono::_M_u_w)
(__formatter_chrono::_M_H_I, __formatter_chrono::_M_p):
Handle multi digits values.
(__formatter_chrono::_S_digit): Return string view.
(__formatter_chrono::_S_str_d1, __formatter_chrono::_S_str_d2)
(__formatter_chrono::_S_fill_two_digits): Define.
* testsuite/std/time/format/empty_spec.cc: Update test for
year_month_day, that uses '%F'.
* testsuite/std/time/format/pr120481.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agogcn: Update --with-arch= for newer archs
Tobias Burnus [Thu, 5 Jun 2025 08:36:21 +0000 (10:36 +0200)] 
gcn: Update --with-arch= for newer archs

Replace hard-coded list of supported devices by directly checking
config/gcn/gcn-devices.def.

gcc/ChangeLog:

* config.gcc (--with-{arch,tune}): Use .def file to validate gcn
processor names.
* doc/install.texi (amdgcn*-*-*): Update list of devices supported
by --with-arch/--with-tune.

2 months agoada: Confusing "modified by call, but value overwritten" warning
squirek [Mon, 13 Jan 2025 21:04:51 +0000 (21:04 +0000)] 
ada: Confusing "modified by call, but value overwritten" warning

The patch fixes an issue in the compiler whereby not referencing a local
variable used in multiple procedure calls as an "out" actual in between
calls would lead to a warning despite "-gnatw.o" not being present.
Additionally, this meant that using pragma Unreferenced on such variables
would not be able to silence such warnings.

gcc/ada/ChangeLog:

* sem_warn.adb
(Warn_On_Useless_Assignment): Disable out value "overwritten" warning
when we are not warning on unread out parameters (e.g. "-gnatw.o").

2 months agoada: Add explicit null pointer check in C.Strings.Update
Tonu Naks [Fri, 7 Feb 2025 12:55:30 +0000 (12:55 +0000)] 
ada: Add explicit null pointer check in C.Strings.Update

gcc/ada/ChangeLog:

* libgnat/i-cstrin.adb: null pointer check in Update

2 months agoada: Remove ghost code and SPARK annotations from runtime units
Arnaud Charlet [Tue, 4 Feb 2025 13:10:10 +0000 (13:10 +0000)] 
ada: Remove ghost code and SPARK annotations from runtime units

This is a clean up to facilitate maintenance now that these units have
been proven.

gcc/ada/ChangeLog:

* exp_util.adb, rtsfind.adb, rtsfind.ads, sem_prag.adb: Remove
references to RO_GH_Big_Integer and
Ada_Numerics_Big_Numbers_Big_Integers_Ghost.
* libgnat/a-strfix.adb, libgnat/a-strmap.adb,
libgnat/a-strsea.adb, libgnat/a-strsup.adb,
libgnat/i-c.ads, libgnat/i-c.adb, libgnat/s-aridou.adb,
libgnat/s-aridou.ads, libgnat/s-arit128.adb,
libgnat/s-arit128.ads, libgnat/s-arit32.adb,
libgnat/s-arit32.ads, libgnat/s-arit64.adb,
libgnat/s-arit64.ads, libgnat/s-casuti.adb,
libgnat/s-exnint.ads, libgnat/s-exnlli.ads,
libgnat/s-exnllli.ads, libgnat/s-expint.ads,
libgnat/s-explli.ads, libgnat/s-expllli.ads,
libgnat/s-explllu.ads, libgnat/s-expllu.ads,
libgnat/s-expmod.adb, libgnat/s-expmod.ads,
libgnat/s-exponn.adb, libgnat/s-exponn.ads,
libgnat/s-expont.adb, libgnat/s-expont.ads,
libgnat/s-exponu.adb, libgnat/s-exponu.ads,
libgnat/s-imaged.ads, libgnat/s-imaged.adb,
libgnat/s-expuns.ads, libgnat/s-imagef.ads,
libgnat/s-imagef.adb, libgnat/s-imagei.adb,
libgnat/s-imagei.ads, libgnat/s-imageu.adb,
libgnat/s-imageu.ads, libgnat/s-imgboo.adb,
libgnat/s-imde128.ads, libgnat/s-imde32.ads,
libgnat/s-imde64.ads, libgnat/s-imfi128.ads,
libgnat/s-imfi32.ads, libgnat/s-imfi64.ads,
libgnat/s-imgboo.ads, libgnat/s-imgint.ads,
libgnat/s-imglli.ads, libgnat/s-imgllli.ads,
libgnat/s-imglllu.ads, libgnat/s-imgllu.ads,
libgnat/s-imguns.ads, libgnat/s-valboo.adb,
libgnat/s-valboo.ads, libgnat/s-valint.ads,
libgnat/s-vallli.ads, libgnat/s-valllli.ads,
libgnat/s-vallllu.ads, libgnat/s-valllu.ads,
libgnat/s-valuns.ads, libgnat/s-valuti.adb,
libgnat/s-valuti.ads, libgnat/s-valuei.adb,
libgnat/s-valuei.ads, libgnat/s-valueu.ads,
libgnat/s-valueu.adb, libgnat/s-veboop.adb,
libgnat/s-veboop.ads, libgnat/s-widint.ads,
libgnat/s-widlli.ads, libgnat/s-widllli.ads,
libgnat/s-widlllu.ads, libgnat/s-widllu.ads,
libgnat/s-widthi.adb, libgnat/s-widthu.adb,
libgnat/s-widthu.ads, libgnat/s-widuns.ads: Remove ghost code
and SPARK annotations.
* libgnat/a-nbnbig.ads, libgnat/a-nbnbig.adb,
libgnat/s-spark.ads, libgnat/s-spcuop.adb,
libgnat/s-spcuop.ads, libgnat/s-vaispe.adb,
libgnat/s-vaispe.ads, libgnat/s-vauspe.adb,
libgnat/s-vauspe.ads, libgnat/s-vs_int.ads,
libgnat/s-vs_lli.ads, libgnat/s-vs_llu.ads,
libgnat/s-vs_uns.ads, libgnat/s-valspe.adb,
libgnat/s-valspe.ads, libgnat/s-vsllli.ads,
libgnat/s-vslllu.ads: Removed.
* Makefile.rtl: Update list of runtime units.
* gcc-interface/Make-lang.in: Remove object files.

2 months agoada: Fix SFN_Patterns documentation comment
Ronan Desplanques [Mon, 3 Feb 2025 13:22:22 +0000 (14:22 +0100)] 
ada: Fix SFN_Patterns documentation comment

The documentation comment under SFN_Patterns was misleading. This patch
fixes it and also fixes Get_Default_File_Name which assumed the comment
was correct.

gcc/ada/ChangeLog:

* fname-uf.adb: Fix documentation comment.
(Get_Default_File_Name): Fix indices of default patterns.

2 months agoada: Tweak wording of documentation comments in Atree
Ronan Desplanques [Fri, 7 Feb 2025 13:43:37 +0000 (14:43 +0100)] 
ada: Tweak wording of documentation comments in Atree

This patch removes an outdated reference to the concept of node
extensions in comments. It also slightly clarifies the documentation of
Atree.Relocate_Node.

gcc/ada/ChangeLog:

* atree.ads (New_Copy, Relocate_Node): Tweak documentation comments.

2 months agoada: Activate SPARK_Mode in Ada.Numerics.*_Random specs
Andres Toom [Tue, 28 Jan 2025 13:41:27 +0000 (15:41 +0200)] 
ada: Activate SPARK_Mode in Ada.Numerics.*_Random specs

gcc/ada/ChangeLog:

* libgnat/a-nudira.ads: Activate SPARK mode and add missing
basic contracts. Mark the unit as always terminating.
* libgnat/a-nuflra.ads: Idem.

2 months agoada: Spurious compilation error with repeated loop index
Javier Miranda [Thu, 6 Feb 2025 09:40:57 +0000 (09:40 +0000)] 
ada: Spurious compilation error with repeated loop index

When multiple for-loop statements in the same scope use the
same index name to iterate through container elements, the
compiler reports a spurious error indicating a conflict
between index names.

gcc/ada/ChangeLog:

* exp_ch7.adb (Process_Object_Declaration): Avoid generating
duplicate names for master nodes.

2 months agoada: Remove useless global variable
Ronan Desplanques [Wed, 5 Feb 2025 13:45:28 +0000 (14:45 +0100)] 
ada: Remove useless global variable

This patch removes a global variable that was made useless by a previous
change and mistakenly hadn't been removed then.

gcc/ada/ChangeLog:

* opt.ads: Remove useless variable.
* sem_ch9.adb (Analyze_Abort_Statement, Analyze_Accept_Alternative,
Analyze_Accept_Statement, Analyze_Asynchronous_Select,
Analyze_Conditional_Entry_Call, Analyze_Delay_Alternative,
Analyze_Delay_Relative, Analyze_Delay_Until, Analyze_Entry_Body,
Analyze_Entry_Body_Formal_Part, Analyze_Entry_Call_Alternative,
Analyze_Entry_Declaration, Analyze_Entry_Index_Specification,
Analyze_Protected_Body, Analyze_Protected_Definition,
Analyze_Protected_Type_Declaration, Analyze_Requeue,
Analyze_Selective_Accept, Analyze_Single_Protected_Declaration,
Analyze_Single_Task_Declaration, Analyze_Task_Body,
Analyze_Task_Definition, Analyze_Task_Type_Declaration,
Analyze_Terminate_Alternative, Analyze_Timed_Entry_Call,
Analyze_Triggering_Alternative): Remove useless assignments.

2 months agoada: Exception-raising loop incorrectly eliminated
Steve Baird [Thu, 30 Jan 2025 21:28:50 +0000 (13:28 -0800)] 
ada: Exception-raising loop incorrectly eliminated

If the body of a loop includes a raise statement then the loop should not be
considered to be free of side-effects and therefore eligible for elimination
by the compiler.

gcc/ada/ChangeLog:

* sem_util.adb
(Side_Effect_Free_Statements): Return False if the statement list
includes an explicit (i.e. Comes_From_Source) raise statement.

2 months agoada: Missing error on expression function returning incomplete type
Javier Miranda [Tue, 4 Feb 2025 19:41:53 +0000 (19:41 +0000)] 
ada: Missing error on expression function returning incomplete type

When the type of the expression of an expression function is
an incomplete type, the frontend does not report the expected
error.

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_Expression_Function): Add missing check
on premature use of incomplete type.

2 months agoada: Add Ghost aspect to Lo in s-arit32.adb
Aleksandra Pasek [Mon, 3 Feb 2025 18:09:36 +0000 (18:09 +0000)] 
ada: Add Ghost aspect to Lo in s-arit32.adb

gcc/ada/ChangeLog:

* libgnat/s-arit32.adb: Add Ghost aspect to Lo.

2 months agoada: Fix crash on access to protected return
Ronan Desplanques [Mon, 27 Jan 2025 11:04:41 +0000 (12:04 +0100)] 
ada: Fix crash on access to protected return

The generation of the check mandated by Ada issue AI05-0073 was not done
handled properly for protected types when used through subtypes. This
patch fixes the issue.

gcc/ada/ChangeLog:

* exp_ch4.adb (Tagged_Membership): Fix for protected types.

2 months agoada: Improve efficiency of very large shift counts
Bob Duff [Tue, 4 Feb 2025 19:36:03 +0000 (14:36 -0500)] 
ada: Improve efficiency of very large shift counts

For a call to an intrinsic shift function with a large Amount, for
example Shift_Right(..., Amount => Natural'Last), and a
compile-time-known value, the compiler would take an absurdly long time
to compute the value. This patch fixes that by special-casing shift
counts that are larger than the size of the thing being shifted.

gcc/ada/ChangeLog:

* sem_eval.adb (Fold_Shift): If the Amount parameter is greater
than the size in bits, use the size. For example, if we are
shifting an Unsigned_8 value, then Amount => 1_000_001 gives the
same result as Amount => 8. This change avoids computing the value
of 2**1_000_000, which takes too long and uses too much memory.
Note that the computation we're talking about is a compile-time
computation. Minor cleanup. DRY.
* sem_eval.ads (Fold_Str, Fold_Uint, Fold_Ureal): Fold the
comments into one comment, because DRY. Remove useless
verbiage.

2 months agoada: Tweak caching of streaming subprograms
Ronan Desplanques [Fri, 31 Jan 2025 09:40:42 +0000 (10:40 +0100)] 
ada: Tweak caching of streaming subprograms

gcc/ada/ChangeLog:

* exp_attr.adb (Interunit_Ref_OK): Tweak categorization of compilation
units.

2 months agoada: Add missing Ghost aspect to Lemma_Not_In_Range_Big2xx64 in s-aridou.adb
Aleksandra Pasek [Mon, 3 Feb 2025 16:29:21 +0000 (16:29 +0000)] 
ada: Add missing Ghost aspect to Lemma_Not_In_Range_Big2xx64 in s-aridou.adb

gcc/ada/ChangeLog:

* libgnat/s-aridou.adb: Add missing Ghost aspect to
Lemma_Not_In_Range_Big2xx64.

2 months agoada: Mitigate issue with tracebacks
Ronan Desplanques [Thu, 30 Jan 2025 15:02:31 +0000 (16:02 +0100)] 
ada: Mitigate issue with tracebacks

The way we fetch the path to shared objects for traceback generation is
not perfectly precise. This patch adds a sanity check to mitigate the
consequences of incorrect shared object paths. It's motivated by a real
world failure in a GNATSAS test.

gcc/ada/ChangeLog:

* libgnat/s-trasym__dwarf.adb (Init_Module): Add mitigation.

2 months agoada: Implement built-in-place expansion of two-pass array aggregates
Eric Botcazou [Fri, 24 Jan 2025 09:26:13 +0000 (10:26 +0100)] 
ada: Implement built-in-place expansion of two-pass array aggregates

These are array aggregates containing only component associations that are
iterated with iterator specifications, as per RM 4.3.3(20.2/5-20.4/5).

It is implemented for the array aggregates that are used to initialize an
object, as specified by RM 7.6(17.2/3-17.3/3) for immutably limited types
and types that need finalization, but for all types like other aggregates.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Two_Pass_Aggr_Code): New function containing
most of the code initially present in Two_Pass_Aggregate_Expansion.
(Two_Pass_Aggregate_Expansion): Remove redundant N parameter.
Implement built-in-place expansion for (static) object declarations
and allocators, using Build_Two_Pass_Aggr_Code for the main work.
(Expand_Array_Aggregate): Adjust Two_Pass_Aggregate_Expansion call.
Replace Etype (N) by Typ in a couple of places.
* exp_ch3.adb (Expand_Freeze_Array_Type): Remove special case for
two-pass array aggregates.
(Expand_N_Object_Declaration): Do not adjust the object when it is
initialized by a two-pass array aggregate.
* exp_ch4.adb (Expand_Allocator_Expression): Apply the processing
used for container aggregates to two-pass array aggregates.
* exp_ch6.adb (Validate_Subprogram_Calls): Skip calls present in
initialization expressions of N_Object_Declaration nodes that have
No_Initialization set.
* sem_ch3.adb (Analyze_Object_Declaration): Detect the cases of an
array originally initialized by an aggregate consistently.

2 months agoada: Add missing Ghost aspect to Lemma_Not_In_Range_Big2xx32 in s-arit32.adb
Johannes Kliemann [Tue, 28 Jan 2025 12:13:31 +0000 (12:13 +0000)] 
ada: Add missing Ghost aspect to Lemma_Not_In_Range_Big2xx32 in s-arit32.adb

gcc/ada/ChangeLog:

* libgnat/s-arit32.adb (Lemma_Not_In_Range_Big2xx32): Add missing
Ghost aspect.

2 months agoada: Fix reproducer generation
Ronan Desplanques [Mon, 20 Jan 2025 15:14:21 +0000 (16:14 +0100)] 
ada: Fix reproducer generation

This patch fixes reproducer generation in the case of crashes in the
back end in the presence of preprocessing dependencies.

gcc/ada/ChangeLog:

* generate_minimal_reproducer.adb (Generate_Minimal_Reproducer): Fix
handling of preprocessing dependencies.

2 months agoada: Reject Valid_Value arguments originating from Standard
Viljar Indus [Mon, 20 Jan 2025 13:10:22 +0000 (15:10 +0200)] 
ada: Reject Valid_Value arguments originating from Standard

The constraint for Valid_Value not applying to types from Standard
should also apply to all types derived from those types.

gcc/ada/ChangeLog:

* doc/gnat_rm/implementation_defined_attributes.rst: Update the
documentation for Valid_Value.
* sem_attr.adb (Analyze_Attribute): Reject types where
the root type originates from Standard.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

2 months agoada: Error about assignment to limited target on aggregate with "for of" iterator
Gary Dismukes [Sat, 18 Jan 2025 01:11:12 +0000 (01:11 +0000)] 
ada: Error about assignment to limited target on aggregate with "for of" iterator

The compiler reports a spurious error about an assignment to a limited
object on an aggregate of a array type with limited components that has
an association with a "for of" iterator. This is fixed by arranging to
have the Assignment_OK flag set on the indexed_names generated by the
expander for initializing the aggregate object.

gcc/ada/ChangeLog:

* exp_aggr.adb (Two_Pass_Aggregate_Expansion): Change call to Make_Assignment
for the indexed aggregate object to call Change_Make_OK_Assignment instead.

2 months agoada: Add error message for a declared-too-late abstract state constituent
Steve Baird [Tue, 14 Jan 2025 23:53:57 +0000 (15:53 -0800)] 
ada: Add error message for a declared-too-late abstract state constituent

In the error case of an undefined abstract state constituent, we want to
help users distinguish between the case where the constituent is
"really" undefined versus being defined "too late" (i.e., after a body).
So in the latter case we generate an additional message.

gcc/ada/ChangeLog:

* sem_prag.adb
(Analyze_Constituent): In the specific case case of a defined-too-late
abstract state constituent, generate an additional error message.

2 months agoada: Fix various issues in the SARIF report
Viljar Indus [Mon, 20 Jan 2025 18:04:59 +0000 (20:04 +0200)] 
ada: Fix various issues in the SARIF report

gcc/ada/ChangeLog:

* diagnostics-sarif_emitter.adb (Print_Invocations): fix
commandLine and executionSuccessful nodes.
Fix typo in the name for startLine.
* osint.adb (Modified Get_Current_Dir) Fix generation of
the current directory.
(Relative_Path): Avoid relative paths starting with a
path separator.
* osint.ads: Update the documentation for Relative_Path.

2 months agoada: Fix unnecessarily large allocation in New_String
Ronan Desplanques [Mon, 20 Jan 2025 12:37:08 +0000 (13:37 +0100)] 
ada: Fix unnecessarily large allocation in New_String

This patches fixes an issue where Interfaces.C.Strings.New_String
allocates more memory than necessary when passed a string that contains
a NUL character.

gcc/ada/ChangeLog:

* libgnat/i-cstrin.adb (New_String): Fix size of allocation.

2 months agoada: Implement use implies with experimental extension
squirek [Fri, 17 Jan 2025 15:38:43 +0000 (15:38 +0000)] 
ada: Implement use implies with experimental extension

The patch implements the experimental feature to allow use package
clauses within the context area to imply with.

gcc/ada/ChangeLog:

* sem_ch8.adb (Analyze_Package_Name): Add code to expand use
clauses such that they have an implicit with associated with them
when extensions are enabled.
* sem_ch10.ads (Analyze_With_Clause): New.
* sem_ch10.adb (Analyze_With_Clause): Add comes from source check
for warning.
(Expand_With_Clause): Moved to the spec.
* sem_util.adb, sem_util.ads
(Is_In_Context_Clause): Moved from sem_prag.
* sem_prag.adb (Analyze_Pragma): Update calls to
Is_In_Context_Clause.
(Is_In_Context_Clause): Moved to sem_util.

2 months agoada: Extend and clarify documentation of stack size settings for Windows
Piotr Trojanek [Thu, 16 Jan 2025 16:41:56 +0000 (17:41 +0100)] 
ada: Extend and clarify documentation of stack size settings for Windows

The original documentation for more recent versions of Windows didn't specify
whether the specified stack size acts as a "reserved" or "committed" stack
size.

Also, clarify the wording for older versions of Windows.

gcc/ada/ChangeLog:

* doc/gnat_ugn/platform_specific_information.rst
(Setting Stack Size from gnatlink): Improve documentation.
* gnat-style.texi: Regenerate.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

2 months agoada: Spurious accessibility error with -gnatc
squirek [Thu, 16 Jan 2025 17:09:49 +0000 (17:09 +0000)] 
ada: Spurious accessibility error with -gnatc

The patch fixes an issue in the compiler whereby a spurious accessibility
error gets generated in semantic checking mode (-gnatc) when an explicitly
aliased formal gets used as an actual for an access disriminant in a return
object.

gcc/ada/ChangeLog:

* accessibility.adb (Check_Return_Construct_Accessibility):
Disable check generation when we are only checking semantics.
* opt.ads: Add new flag for -gnatc mode
* switch-c.adb (Scan_Front_End_Switches): Set flag for -gnatc mode

2 months agoada: Mark the types of operator arguments as used
Viljar Indus [Thu, 9 Jan 2025 10:37:56 +0000 (12:37 +0200)] 
ada: Mark the types of operator arguments as used

When a use type clause is used then it makes the type and
all of its operators use visible in the context. When analyzing
whether a use type clause is effective we should additionally
mark the types of an overloaded operator as cases where the
use type clause is effective.

gcc/ada/ChangeLog:

* sem_ch8.adb (Mark_Use_Type): Additionally mark the types
of the parameters and return values as used when analyzing an
operator.

2 months agoada: Fix couple of remaining incompatibilities with CHERI architecture
Eric Botcazou [Thu, 16 Jan 2025 14:51:00 +0000 (15:51 +0100)] 
ada: Fix couple of remaining incompatibilities with CHERI architecture

These are the usual problematic patterns in the expanded code.

gcc/ada/ChangeLog:

* exp_ch9.adb (Build_Dispatching_Requeue): Take 'Tag of the
concurrent object instead of doing an unchecked conversion.
* exp_pakd.adb (Expand_Packed_Address_Reference): Perform address
arithmetic using an operator of System.Storage_Elements.

2 months agoada: Fix buffer overflow for function call returning discriminated limited record
Eric Botcazou [Wed, 15 Jan 2025 19:37:48 +0000 (20:37 +0100)] 
ada: Fix buffer overflow for function call returning discriminated limited record

This occurs when the discriminated limited record type is declared with
default values for its discriminants, is not controlled, and the context
of the call is anonymous, i.e. the result of the call is not assigned
to an object.  In this case, a temporary is created to hold the result
of the call, with the default values of the discriminants, but the result
may have different values for the discriminants and, in particular, may
be larger than the temporary, which leads to a buffer overflow.

This problem does not occur when the context is an object declaration, so
the fix just makes sure that the expansion in an anonymous context always
uses the model of an object declaration.  It requires a minor tweak to the
helper function Entity_Of of the Sem_Util package.

gcc/ada/ChangeLog:

* exp_ch6.adb (Expand_Actuals): Remove obsolete comment.
(Make_Build_In_Place_Call_In_Anonymous_Context): Always use a proper
object declaration initialized with the function call in the cases
where a temporary is needed, with Assignment_OK set on it.
* sem_util.adb (Entity_Of): Deal with rewritten function call first.

2 months agoada: Fix New_Char_Array with empty arrays
Ronan Desplanques [Thu, 16 Jan 2025 11:55:37 +0000 (12:55 +0100)] 
ada: Fix New_Char_Array with empty arrays

This patch fixes an integer underflow issue on calls of the form
New_Char_Array (X) with X'Last < X'First - 2. That integer underflow
caused attempts at allocating impossibly large amount of memory in some
cases.

gcc/ada/ChangeLog:

* libgnat/i-cstrin.adb (Position_Of_Nul): Change specification and
adjust body accordingly.
(New_Char_Array): Fix size of allocation.
(To_Chars_Ptr): Adapt to Position_Of_Nul change.

2 months agoada: Fix adareducer oracle generation
Ronan Desplanques [Wed, 15 Jan 2025 08:57:10 +0000 (09:57 +0100)] 
ada: Fix adareducer oracle generation

This patch adds a missing "-quiet" switch to the compiler invocations
performed by generated oracles. Without that switch, log lines could be
present before bug boxes for crashes in gigi and that caused the crash
detection logic to fail.

gcc/ada/ChangeLog:

* generate_minimal_reproducer.adb (Generate_Minimal_Reproducer): Fix
oracle generation.

2 months agoada: Fix Generate_Minimal_Reproducer on instantiations
Ronan Desplanques [Wed, 15 Jan 2025 08:54:45 +0000 (09:54 +0100)] 
ada: Fix Generate_Minimal_Reproducer on instantiations

Before this patch, the code that creates a copy of the semantic closure
with the default naming convention was incorrect when the compiler was
processing a library unit that was an instantiation of a generic with a
body. This patch adds code to detect that situation and adjusts the
copying process accordingly.

gcc/ada/ChangeLog:

* generate_minimal_reproducer.adb (Generate_Minimal_Reproducer):
Fix when main library item is an instantiation.

2 months agoada: Fix compile-time failure due to duplicated attribute subprograms.
Steve Baird [Mon, 13 Jan 2025 22:18:26 +0000 (14:18 -0800)] 
ada: Fix compile-time failure due to duplicated attribute subprograms.

For a given type, and for certain attributes (the 4 streaming attributes
and, for Ada2022, the Put_Image attribute), the compiler needs to keep track
of whether a subprogram has already been generated for the given
type/attribute pair. In some cases this was being done incorrectly;
the compiler ended up generating duplicate subprograms (with the same
name), resulting in compilation failures. This could occur if the prefix
of an attribute reference denoted a subtype (more precisely, a non-first
subtype). This includes the case of a subtype declaration that is implicitly
introduced by the compiler to capture the binding between a formal type
in a generic and the corresponding actual type in an instantiation.

gcc/ada/ChangeLog:

* exp_attr.adb (Expand_N_Attribute_Reference): When accessing the
maps declared in package Cached_Attribute_Ops, the key value
passed to Get or to Set should never be the entity node for a
subtype. Use the entity of the corresponding type declaration
instead.

2 months agoada: Mark constants inside a declare expression as referenced
Viljar Indus [Tue, 14 Jan 2025 11:31:04 +0000 (13:31 +0200)] 
ada: Mark constants inside a declare expression as referenced

Expressions within a declare expression were simply bound to
locally defined constants. However they were never marked as
referenced. This would trigger an unreferenced constant warning
if -gnatwu was used.

gcc/ada/ChangeLog:

* sem_res.adb (Resolve_Declare_Expression): Mark used
local variables inside a declare expression as referenced.

2 months agoada: Cleanup preanalysis of static expressions (part 6)
Javier Miranda [Tue, 14 Jan 2025 11:08:57 +0000 (11:08 +0000)] 
ada: Cleanup preanalysis of static expressions (part 6)

Rename Preanalyze_Spec_Expression as Preanalyze_And_Resolve_Spec_Expression,
Preanalyze_Assert_Expression as Preanalyze_And_Resolve_Assert_Expression,
and Preanalyze_Default_Expression as Preanalyze_And_Resolve_Default_Expression;
cleanup the version of Preanalyze_Assert_Expression without context type.

gcc/ada/ChangeLog:

* sem.ads: Update reference to renamed subprogram in documentation.
* sem_ch3.ads (Preanalyze_Assert_Expression): Renamed.
(Preanalyze_Spec_Expression): Renamed.
* sem_ch3.adb (Preanalyze_Assert_Expression): Renamed and code cleanup.
(Preanalyze_Spec_Expression): Renamed.
(Preanalyze_Default_Expression): Renamed.
* contracts.adb: Update calls to renamed subprograms.
* exp_pakd.adb: Ditto.
* exp_util.adb: Ditto.
* freeze.adb: Ditto.
* sem_ch12.adb: Ditto.
* sem_ch13.adb: Ditto.
* sem_ch6.adb: Ditto.
* sem_prag.adb: Ditto.
* sem_res.adb (Preanalyze_And_Resolve): Add to the version without
context type the special handling for GNATprove mode provided by
the version with context type; required to cleanup the body of
Preanalyze_Assert_Expression.

2 months agoada: Spurious accessibility error with -gnatc
squirek [Tue, 14 Jan 2025 06:40:08 +0000 (06:40 +0000)] 
ada: Spurious accessibility error with -gnatc

The patch fixes an issue in the compiler whereby a spurious accessibility
error gets generated in semantic checking mode (-gnatc) when an explicitly
aliased formal gets used as an actual for an access disriminant in a return
object.

gcc/ada/ChangeLog:

* accessibility.adb
(Check_Return_Construct_Accessibility): Disable check generation
when we are only checking semantics.

2 months agoada: Use absolute paths in SARIF reports
Viljar Indus [Mon, 2 Dec 2024 10:18:06 +0000 (12:18 +0200)] 
ada: Use absolute paths in SARIF reports

gcc/ada/ChangeLog:

* diagnostics-json_utils.adb: Add new method To_File_Uri to
convert any path to the URI standard.
* diagnostics-json_utils.ads: Likewise.
* diagnostics-sarif_emitter.adb: Converted Artifact_Change
types to use the Source_File_Index instead of the file name
to store the source file.
Removed the body from Destroy (Elem : in out Artifact_Change)
since it no longer contained elements with dynamic memory.
Updated the implementation of Equals (L, R : Artifact_Change)
to take into account the changes for Artifact_Change.
Print_Artifact_Location: Use the Source_File_Index as an
input argument. Now prints the uriBaseId attribute and a
relative path from the uriBaseId to the file in question as
the value of the uri attribute.
New method Print_Original_Uri_Base_Ids to print the
originalUriBaseIds node.
Print_Run no prints the originalUriBaseIds node.
Use constants instead of strings for all the SARIF attributes.
* osint.adb: Add new method Relative_Path to calculate the
relative path from a base directory.
Add new method Root to calculate the root of each directory.
Add new method Get_Current_Dir to get the current working
directory for the execution environment.
* osint.ads: Likewise.
* clean.adb: Use full names for calls to Get_Current_Dir.
* gnatls.adb: Likewise.

2 months agoada: Avoid calling Resolve with Stand.Any_Fixed as the expected type
Steve Baird [Fri, 10 Jan 2025 21:15:18 +0000 (13:15 -0800)] 
ada: Avoid calling Resolve with Stand.Any_Fixed as the expected type

When we call Resolve for an expression, we pass in the expected type
for that expression. In the absence of semantic errors, that expected type
should never be any of the "Any_xxx" types declared in stand.ads (e.g.,
Any_Array, Any_Numeric, Any_Real). In particular, it should never be Any_Fixed.
Fix a case in which this rule was being violated.

gcc/ada/ChangeLog:

* sem_res.adb
(Set_Mixed_Mode_Operand): If we are about to call Resolve
passing in Any_Fixed as the expected type, then instead pass in
the fixed point type of the other operand (i.e., B_Typ).