Denis Mazzucato [Tue, 20 Jan 2026 11:54:02 +0000 (12:54 +0100)]
ada: Update references to Parameter Associations RM 6.4.1
AI12-0095-1 added a paragraph after RM 6.4.1(6.3/3), all the subsequent RM
references within 6.x may be off by one; this patch updates those references.
Martin Clochard [Tue, 20 Jan 2026 16:44:13 +0000 (17:44 +0100)]
ada: Set Etype before analysis for conditions generated for 'Old
The absence of Etype decoration is problematic for GNATprove, which
cannot use analyze to fill the blanks in the output.
gcc/ada/ChangeLog:
* sem_util.adb (As_Boolean): utility to fill decoration in expressions
(Determining_Condition): set Etype for generated Boolean connectors
(Conditional_Evaluation_Condition): set Etype for generated connectors
Gary Dismukes [Tue, 20 Jan 2026 22:35:50 +0000 (22:35 +0000)]
ada: Formal function default given by expression rejected with -gnatX
The compiler should be allowing formal functions to be defaulted by
an expression when the core extensions are enabled, but it was
requiring all extensions to be enabled.
gcc/ada/ChangeLog:
* par-ch12.adb (P_Formal_Subprogram_Declaration): Pass True for
the Is_Core_Extension parameter on call to Error_Msg_GNAT_Extension.
Piotr Trojanek [Mon, 19 Jan 2026 22:04:10 +0000 (23:04 +0100)]
ada: Reject pragma CPU and Priority that duplicate corresponding aspects
When a main subprogram had its CPU or priority specified first by an aspect
specification and then by a corresponding pragma, then the pragma was silently
ignored. Now such a pragma is rejected.
gcc/ada/ChangeLog:
* sem_ch13.adb (Analyze_Aspect_Specifications): Record aspect CPU and
Priority applied to subprogram as a representation item.
Claire Dross [Fri, 16 Jan 2026 16:02:50 +0000 (17:02 +0100)]
ada: Reject exceptional contracts on No_Raise subprograms
Rejectd the SPARK-specific exceptional contract pragmas Exceptional_Cases and
Exit_Cases when they are not compatible with the No_Raise GNAT-specific aspect.
gcc/ada/ChangeLog:
* sem_prag.adb (Analyze_Exit_Contract): The Exception_Raised exit kind
is not compatible with No_Raise.
(Analyze_Pragma): The Exceptional_Cases pragma is not compatible with
No_Raise.
Eric Botcazou [Sun, 18 Jan 2026 21:12:25 +0000 (22:12 +0100)]
ada: Fix fallout of recent freezing change for expression functions
The change unnecessarily prevents the profile of all dispatching operations
from being frozen by their subprogram body, which exposes a weakness in the
implementation of freezing for generic units. This just reverts that part.
gcc/ada/ChangeLog:
PR ada/93702
* exp_ch3.adb (Make_Controlling_Function_Wrappers): Revert latest
change.
* sem_ch12.adb (Analyze_One_Association): Remove redundant line.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Freeze the profile
again for bodies that are not generated from expression functions.
Javier Miranda [Fri, 16 Jan 2026 17:11:55 +0000 (17:11 +0000)]
ada: Spurious error on formals with First_Controlling_Parameter type
This patch fixes a spurious error reported by the frontend when
a dispatching primitive of a tagged type has additional formals
with types that have the First_Controlling_Parameter aspect.
gcc/ada/ChangeLog:
* sem_disp.adb (Check_Controlling_Formals): Formals of a type
specifying aspect First_Controlling_Parameter are not candidate
controlling parameters when they are not the first formal of
the dispatching primitive.
Eric Botcazou [Tue, 13 Jan 2026 19:00:28 +0000 (20:00 +0100)]
ada: Fix early freezing of tagged type by expression function in nested package
This addresses a long-standing issue in the implementation of expression
functions of Ada 2012, pertaining to their interaction with the freezing
of types that are referenced in their expression: when they are used as
the completion of a function declaration, their expression causes these
types to become frozen, but when they are stand-alone, it does not.
The last rule is problematic for GNAT, because it goes against its freezing
model devised for Ada 95, where types must always be frozen for code to be
generated. Therefore the current implementation needs to resort to several
kludges in order to implement it, but these are not bullet proof and do not
always work when tagged types are involved.
The new approach is to insert the generated body of stand-alone expression
functions at the next freezing point, instead of at the end of the current
package. This makes a difference for nested packages, which are precisely
the problematic case. This requires the analysis and resolution performed
on the body, potentially out of context now, to give identical results as
the preanalysis and resolution performed on the expression in its context,
which is achieved by treating the generated body as an inlined body.
This approach requires a more complete implementation of the special rules
for freezing expression functions, so the change overhauls it and plugs the
most blatant loopholes of the current implementation.
gcc/ada/ChangeLog:
PR ada/93702
* contracts.adb (Analyze_Entry_Or_Subprogram_Contract): Call
Freeze_Expr_Types_Before instead of Freeze_Expr_Types.
(Process_Preconditions_For): Likewise.
* exp_ch3.adb (Make_Controlling_Function_Wrappers): Do not set
Was_Expression_Function flag on the generated bodies.
* exp_ch6.adb (Expand_Call_Helper): Call Original_Node on the
result of the call to Expression_Of_Expression_Function.
* freeze.ads (Freeze_Expr_Types): Delete.
(Freeze_Expr_Types_Before): New procedure declaration.
* freeze.adb (Check_Expression_Function): Delete.
(Freeze_And_Append): Add Do_Freeze_Profile formal parameter and
pass it to Freeze_Entity. Remove call to Check_Expression_Function.
(Freeze_Entity): Set Test_E consistently and freeze the expression
of expression functions that are primitives of a tagged type.
(Freeze_Profile): Adjust calls to Should_Freeze_Type.
(In_Expanded_Body): Also return true for DIC procedures.
(Freeze_Expression): Remove call to Check_Expression_Function.
Freeze the expression of expression functions.
(Freeze_Expr_Types): Add Result and Before formal parameters.
Make a copy and preanalyze/resolve it only if Typ is present.
(Freeze_Expr_Types.Explain_Error): New procedure.
(Freeze_Expr_Types.Find_Incomplete_Constant): Likewise.
(Freeze_Expr_Types.Check_And_Freeze_Type): Return immediately if
the type is already frozen. Report errors on N instead of Node.
If Before is False, append the freeze nodes to Result.
(Freeze_Expr_Types.Freeze_Type_Refs): Call Find_Incomplete_Constant.
(Freeze_Expr_Types_Before): New procedure.
(Should_Freeze_Type): Remove formal parameter E and
specific kludge for stand-alone expression functions.
* ghost.ads (Mark_And_Set_Ghost_Body_Of_Expression_Function): New
procedure declaration.
* ghost.adb (Mark_And_Set_Ghost_Body_Of_Expression_Function): New
procedure body.
* rtsfind.adb (RTE): Preserve and reset the In_Inlined_Body flag.
(RTE_Record_Component): Likewise.
* sem_attr.adb (Resolve_Attribute) <Attribute_Access>: Just call
Freeze_Expression to freeze the expression of prefixes that are
expression functions and remove obsolete implementation.
* sem_ch3.adb (Analyze_Declarations): Adjust commentary.
(Check_Completion): Also skip stand-alone expressions functions.
* sem_ch4.adb (Analyze_Case_Expression): Always analyze the choices.
* sem_ch6.adb: Add with and use clauses for Sem_Ch7.
(Analyze_Expression_Function): Call Freeze_Expr_Types_Before instead
of Freeze_Expr_Types for expression functions that are completions.
For stand-alone expression functions, set In_Private_Part on the
entity if it is in the private part, propagate the results of the
resolution of the specification of the the declaration to that of
the body and insert the body at the next freezing point.
(Analyze_Subprogram_Body_Helper): Remove the machinery for masking
and unmasking unfrozen types. For a stand-alone expression function,
call Mark_And_Set_Ghost_Body_Of_Expression_Function, remove obsolete
code dealing with the freezing of the spec, set In_Inlined_Body to
True, make the full view of the private types of its scope visible
if this is not the current scope and it is in the private part, and
avoid making the spec immediately visible.
(Analyze_Subprogram_Specification): Fix typo.
(New_Overloaded_Entity): Set Has_Completion on a [generic] package
that conflicts with the entity to prevent a cascaded error.
* sem_ch7.ads (Is_Private_Base_Type): New function declaration moved
here from...
* sem_ch7.adb (Is_Private_Base_Type): ...here. Remove.
* sem_ch8.adb (Analyze_Subprogram_Renaming): Call Freeze_Expression
to freeze the expression of expression functions, but only if the
renaming comes from source.
* sem_ch12.adb (Analyze_One_Association): Likewise, and remove the
manual freezing for calls to them.
* sem_res.adb (Resolve): Remove obsolete commentary.
(Resolve_Call): Always freeze the expression of names that are
expression functions.
* sem_util.adb (Check_Fully_Declared): Add commentary and do not
check types with private component declared outside of the current
scope when it is a generic unit.
(Expression_Of_Expression_Function): Return Expression directly.
(Is_Inlinable_Expression_Function): Call Original_Node on the
result of the call to Expression_Of_Expression_Function.
Eric Botcazou [Fri, 16 Jan 2026 18:55:07 +0000 (19:55 +0100)]
ada: Fix fallout of latest change to Analyze_Subprogram_Renaming
Replacing the original expression by Expression_Of_Expression_Function is
not fully equivalent because Expression_Of_Expression_Function returns the
Original_Node of the expression.
gcc/ada/ChangeLog:
* sem_ch8.adb (Analyze_Subprogram_Renaming): Retrieve again the
expression of the expression function manually.
Eric Botcazou [Thu, 15 Jan 2026 23:31:16 +0000 (00:31 +0100)]
ada: Small tweak to error message for premature freezing of deferred constant
The tweak is to add the name of the constant to the error message. That's
a minor improvement in this simple case, but it will help for the same error
in a more complex case.
gcc/ada/ChangeLog:
* sem_res.adb (Resolve_Entity_Name): Add the name of the constant
to the error message for premature freezing of deferred constants.
Gary Dismukes [Thu, 15 Jan 2026 20:40:28 +0000 (20:40 +0000)]
ada: Missing contract checks for calls to formal subprograms within instances
While working on a visibility bug, it was noticed that preconditions
on formal subprograms are not being checked on calls to the subprograms
within package instantiations. The wrapper subprogram that is created to
perform the check (and invoke the actual subprogram) was not being used
as the target of calls, and the actual subprogram is being called instead
(bypassing the check). This was due to the subprogram renaming created
(for the actual-to-formal association) and the wrapper being homographs,
and the loop over interpretations in Collect_Interps happening to resolve
calls to the actual instead of the wrapper. This wrong resolution is
avoided by removing the homographic subprogram renaming, so that the
resolution can only resolve to the wrapper (which will only include
the precondition check in the case where assertions are enabled).
gcc/ada/ChangeLog:
* sem_ch12.adb (Build_Subprogram_Wrapper): Remove the subprogram
renaming created for the formal-to-actual association from the
list of renamings (only when such a subprogram renaming is present).
Also, change the name from plural to singular, since the procedure
only creates one wrapper, update the spec comment to reflect that,
and clarify the state and use of the Renamings parameter.
Denis Mazzucato [Fri, 9 Jan 2026 15:04:57 +0000 (16:04 +0100)]
ada: Fix Initialize aspect for constructors
This patch improve the analysis for the Initialize aspect in constructor bodies.
Specifically:
- Assignments based on the Initialize aspect are always placed at the end of the
constructor prologue, otherwise they could be overwritten depending on the
original order of components.
- Introduce the "others" default choice for the Initialize aggregate.
- Improve diagnostics when the Initialize aspect is clearly misspelled.
- Flag components that are required to be initialized but are missing from the
Initialize aspect.
- Check whether aggregate choices refer to ancestors, which is not allowed.
gcc/ada/ChangeLog:
* exp_ch3.adb (Build_Implicit_Parameterless_Constructor): Add Initialize
aspect with default others to trigger Initialize aspect analysis.
* exp_ch6.adb (Prepend_Constructor_Procedure_Prologue): Fix
initialization order.
(Init_From_Initialize_Expression): Retrieve initialization expression or
the default one base on the Initialize aspect.
(Init_From_Default_Or_Constructor):. Retrieve initialization expression
based on the default one in the record initialization list or the init
procedure.
* sem_ch13.adb (Analyze_Aspect_Specifications): Add check for
missing components that require initialization, and add an
expression_with_action node to place ABE during resolution of
aggregates with function calls.
(Check_Constructor_Choices): Helper to check that the aggregate choices
do not refer to ancestors.
(Diagnose_Misplaced_Aspects): Improve diagnostics when it is a clear
misspelling of Initialize aspect.
* sem_ch6.adb (Analyze_Direct_Attribute_Definition): If missing, add a
compiler generated Initialize aspect with default others to trigger
Initialize analysis.
Eric Botcazou [Mon, 12 Jan 2026 20:45:44 +0000 (21:45 +0100)]
ada: Fix incorrect finalization of renamed function call at library level
This is a regression present in recent releases for the peculiar case of the
renaming of a controlled function call done at library level, which causes
the compiler to create a dangling reference to a temporary created on the
stack of the elaboration routine to hold the result of the function call.
gcc/ada/ChangeLog:
* exp_ch6.adb (Expand_Ctrl_Function_Call): Bail out for the name
of an object renaming declaration at library level, if the call
does not return on the secondary stack.
* exp_ch8.adb (Expand_N_Object_Renaming_Declaration): Rewrite the
renaming as a regular object declaration if it is declared at
library level and the name is a controlled function call whose
result is not returned on the secondary stack.
* exp_util.adb (Rewrite_Object_Declaration_As_Renaming): Minor fix.
Gary Dismukes [Wed, 7 Jan 2026 20:23:55 +0000 (20:23 +0000)]
ada: Visibility bug in instance of generic with precondition on formal subprogram
The compiler may issue an error saying that a global entity referenced in
the precondition of a formal subprogram is not visible when the containing
generic is instantiated at a place where the entity is not directly visible.
This was due to the formal subprogram's contract not having been analyzed
in the generic template. As a result, the nodes with global references were
not properly captured (by Save_Global_References).
An additional problem was exposed, which was that references within
contract aspect specifications of generic formals to other formals of the
same generic were not being properly analyzed/resolved, due to copying
the aspect specifications of the already-analyzed copy of the generic
formal when building subprogram wrappers for the contracts. This could
lead to blowups in the back end due to references to the original formals
occurring in the expansion of the instantiation. This is addressed by
copying the aspect specifications of the unanalyzed formals rather than
those that were analyzed in the copy of the generic template.
gcc/ada/ChangeLog:
* contracts.adb (Analyze_Contracts): Add cases for formal subprogram
Nkinds so that Analyze_Entry_Or_Subprogram_Contract will be called
for them.
* sem_attr.adb (Analyze_Attribute_Old_Result): Account for the cases
of formal subprogram Nkinds, allowing Old attributes for those.
* sem_ch12.adb (Build_Subprogram_Wrappers): Add a formal for passing
the unanalyzed generic formal, and use it for copying any aspect
specifications of the generic formal rather than copying the analyzed
generic formal's aspects.
(Analyze_One_Association): Pass Assoc.Un_Formal as an additional
actual in the call to Build_Subprogram_Wrappers.
Steve Baird [Thu, 8 Jan 2026 22:31:16 +0000 (14:31 -0800)]
ada: Missing dynamic accessibility check assigning conditional expr to saooaaat.
When a conditional expression is assigned to a saooaaat (that is, to a
stand-alone object of an anonymous access type), in some cases the
required dynamic accessibility check was not being performed.
gcc/ada/ChangeLog:
* accessibility.adb (Needs_Accessibility_Level_Temp_Or_Check): Conform
to spec changes. Return True for the RHS of an assignment statement.
* accessibility.ads: Change name of Is_Anonymous_Access_Actual
to Needs_Accessibility_Level_Temp_Or_Check; the function now returns
True in cases other than those described by the old name.
Also change name of the formal parameter from N to Conditional_Expr.
* exp_ch4.adb (Expand_N_If_Expression): Update call to a function
whose name changed.
Javier Miranda [Wed, 24 Dec 2025 10:46:40 +0000 (10:46 +0000)]
ada: Improve machinery for generating predicate check
gcc/ada/ChangeLog:
* sem_util.adb (Is_Fully_Initialized_Variant): Moved inside
subprogram Is_Fully_Initialized_Type.
(Is_Fully_Initialized_Constrained_Array): New subprogram that
factorizes code of Is_[Fully|Partially]_Initialized_Type.
(Is_Fully_Initialized_Record_Type): New subprogram; add missing
support for incomplete types.
(Is_Partially_Initialized_Record_Type): New subprogram; add missing
support for incomplete types.
(Is_Partially_Initialized_Type): Add new formal for predicate checks.
* sem_util.ads (Is_Partially_Initialized_Type): Add new formal for
predicate checks.
* sem_warn.adb (Type_OK_For_No_Value_Assigned): Use named parameters
in call to Is_Partially_Initialized_Type.
* sem_ch3.adb (Analyze_Object_Declaration): Add new actual for
predicate checks.
Eric Botcazou [Sun, 11 Jan 2026 12:00:32 +0000 (13:00 +0100)]
ada: Small tweaks to semantic analysis of expression functions
They are mostly about streamlining the implementation, but also eliminate
unexpected or duplicate error messages in some specific cases.
gcc/ada/ChangeLog:
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Introduce new local
boolean constant From_Expression_Function, use it throughout, and
replace an equivalent test by it. Do not deal with name conflicts
here when it is true. Do not verify the consistency of overriding
indicators for stand-alone expression functions.
* sem_util.ads (Is_Expression_Function_Or_Completion): Fix improper
wording in description.
* sem_util.adb (Is_Expression_Function_Or_Completion): Streamline
the implementation.
Eric Botcazou [Thu, 8 Jan 2026 20:58:05 +0000 (21:58 +0100)]
ada: Fix endless loop on Address aspect for object with dynamic address
The freezing machinery ends up inserting a freeze node into its own Actions
list, which causes Expand_N_Freeze_Entity to enter an endless loop, because
Remove_Init_Call incorrectly returns the initialization call of a different
variable than the one for which it was invoked.
gcc/ada/ChangeLog:
* exp_util.adb (Remove_Init_Call.Find_Init_Call_In_List): Check that
the first actual denotes the expected variable modulo qualification
and conversion.
Javier Miranda [Sun, 4 Jan 2026 10:32:56 +0000 (10:32 +0000)]
ada: Handle call to C++ constructor placed in return statement
Add missing support for C++ constructor call placed in the return
statement.
gcc/ada/ChangeLog:
* sem_ch3.adb (Analyze_Object_Declaration): Report an error if the
return statement of a function with foreign convention has a call
to a C++ constructor.
* exp_ch3.adb (Expand_N_Object_Declaration): Handle initialization
expression calling a C++ constructor in an extended return statement
of a subprogram with Ada convention.
Denis Mazzucato [Tue, 23 Dec 2025 14:25:46 +0000 (15:25 +0100)]
ada: Enable checks during analysis of expanded dispatching calls
This patch enables the generation of run-time checks during the analysis and
resolution of expanded dispatching calls. They were previously disabled to avoid
reporting spurious warnings under the ZFP run-time, but this is no longer
required.
gcc/ada/ChangeLog:
* exp_disp.adb (Expand_Dispatching_Call): Remove suppression of checks
during analysis of expanded dispatching calls.
This makes it possible to use the word "finally" as an identifier when
GNAT extensions are enabled. This does not make the syntax ambiguous
and the "finally" syntax extension is not affected.
gcc/ada/ChangeLog:
* doc/gnat_rm/gnat_language_extensions.rst: Add that finally is a
non-reserved keyword.
* par-ch5.adb (P_Sequence_Of_Statements): handle "finally" syntax
extension.
* snames.ads-tmpl: Remove the concept of GNAT extension reserved
word.
* snames.adb-tmpl (Is_Keyword_Name): Likewise.
* scans.adb (Initialize_Ada_Keywords): Likewise.
* par-util.adb (Check_Future_Keyword): Likewise.
* gnat_rm.texi: Regenerate.
Bob Duff [Wed, 7 Jan 2026 18:57:52 +0000 (13:57 -0500)]
ada: Crash with pragma Ignore_Pragma in SPARK mode
This patch fixes a bug in the expansion of protected bodies.
Consolidate the various cases that simply copy the Op_Body,
which is usually a protected subprogram declaration or body.
Remove the "raise Program_Error", because it's not really the
job of this code to enforce the rules about what can appear
in a protected body. Better to remove all the cases that
have accreted over the years, and just assume that anything
not allowed syntactically must be an artifact of expansion.
The specific goal here is to avoid raising Program_Error
when Op_Body is a null statement, which happens when there
is a "SPARK_Mode => Off" aspect (turned into a pragma)
and also a "pragma Ignore_Pragma (SPARK_Mode)" (which turns
the pragma into a null statement). The fix here is more
general and more "DRY".
gcc/ada/ChangeLog:
* exp_ch9.adb (Expand_N_Protected_Body):
Remove "raise Program_Error" and consolidate other
cases.
The GPR files can be used to build the Ada runtime, usually via
libada.gpr as the entry point. This commits extends the GPR project
definitions to make them suitable for shared and static PIC runtime
builds.
When LIBRARY_KIND is "static-pic", the libraries gain a "_pic" suffix,
as expected by the build tools. When it's "dynamic", we configure the
Library_Version attribute in order to set the right SONAME on Unix, as
well as the expected symlinks.
Finally, libgnarl.gpr now depends on libgnat.gpr; the missing dependency
hasn't caused problems so far because static libraries don't resolve
missing symbols at build time, but it's necessary to build shared
libraries.
gcc/ada/ChangeLog:
* libgnarl/libgnarl.gpr: Add dependency on libgnat.gpr.
Set Library_Name and Library_Version depending on Library_Kind.
* libgnat/libgnat.gpr: Likewise.
Denis Mazzucato [Tue, 6 Jan 2026 12:38:49 +0000 (13:38 +0100)]
ada: Support for implicit parameterless constructor
An implicit parameterless constructor is available when no other constructor is
declared for a tagged type that has an ancestor with constructors. The implicit
parameterless constructor calls the parent parameterless constructor through the
Super aspect without arguments.
gcc/ada/ChangeLog:
* aspects.ads (Aspects): Make Super aspect optional to allow for
explicit call to parent parameterless constructor.
* exp_ch3.adb (Build_Implicit_Parameterless_Constructor): Build implicit
parameterless constructor when no other constructors are defined but the
type has an ancestor with constructors.
* exp_ch6.adb
(Init_Expression_If_Any): Pe4rmit implicit calls to parameterless
constructors in initialization expressions if available.
(Make_Parent_Constructor_Call): Super without parameters calls the
parent parameterless constructor.
* sem_ch13.adb (Analyze_Aspect_Specification): Allow Super aspect
without expression.
* sem_ch3.adb (Analyze_Object_Declaration): Delay check for missing
parameterless constructor until the the implicit constructor is built.
Steve Baird [Mon, 15 Dec 2025 21:47:35 +0000 (13:47 -0800)]
ada: New aspects for use in CodePeer's taint analysis.
Add minimal compiler support for three new aspects: Taint_Sanitizer,
Taint_Sink, and Taint_Source. This support consists of accepting (with no
accompanying semantic analysis) aspect specifications for these aspects, using
either aspect_specification syntax or pragmas. Such aspect specifications are
subsequently ignored by the compiler front end. These aspects are intended for
use with CodePeer and are (or will be) documented in CodePeer documentation;
they are not documented in the GNAT RM.
gcc/ada/ChangeLog:
* aspects.ads: Add three new Taint_Xxx aspects to the Aspect_Id
enumeration type and define a corresponding subtype,
Ignored_Aspects.
* exp_prag.adb (Expand_N_Pragma): Don't rewrite a taint-related
pragma as a null statement. We want to leave the (unanalyzed)
pragma in the tree.
* sem_ch13.adb (Analyze_One_Aspect): Leave taint-related aspect
specifications
(and their arguments, if any) unanalyzed.
(Check_Aspect_At_Freeze_Point): Update a case statement to treat
the new aspects as an error case.
* sem_util.adb (Should_Ignore_Pragma_Sem): Return True for an
ignored pragma.
* snames.ads-tmpl: Define names for the three new aspects.
Denis Mazzucato [Mon, 22 Dec 2025 12:44:41 +0000 (13:44 +0100)]
ada: Fix spurious range check for out mode scalars in class-wide preconditions
This patch fixes a spurious range check that was generated for out mode scalars
after a class-wide precondition call. This issue was not present in static
preconditions, but only in dynamic ones. This patch refactors the two helper
call builders into the same to ensure the same processing of actuals.
gcc/ada/ChangeLog:
* exp_ch6.adb (Build_Helper_Call): Refactor code to handle both static and
dynamic precondition calls in the same way.
Denis Mazzucato [Tue, 16 Dec 2025 10:16:32 +0000 (11:16 +0100)]
ada: Refactor assignments in constructor prologue
Constructor prologues now call the same routine as initialization procedures to
build component assignments.
gcc/ada/ChangeLog:
* exp_ch3.adb (Build_Record_Init_Proc): Move Build_Assignment to
Build_Component_Assignment in Exp_Util for a more general use.
* exp_ch6.adb (Prepend_Constructor_Procedure_Prologue): refactor using
Build_Component_Assignment.
* exp_util.adb (Build_Component_Assignment): Logic to build component
assignments for initialization procedures and constructor prologues.
* exp_util.ads (Build_Component_Assignment): Likewise.
* sem_ch5.adb (Analyze_Assignment): Revert back changes from previous
attempt to fix assignments of limited types in constructor prologues,
the use of Build_Component_Assignment makes those changes unnecessary.
Eric Botcazou [Sat, 3 Jan 2026 08:58:32 +0000 (09:58 +0100)]
ada: Fix typo in head comment of Sinput specification
As explained later in the commentary of the file, wide characters specified
to be line terminators are considered to be logical instead of physical line
terminators. The change also aligns the description of the physical line
terminators with the one present later in the commentary.
Tomasz Kamiński [Mon, 18 May 2026 11:14:25 +0000 (13:14 +0200)]
libstdc++: Add data/member for initializer_list, and remove std overloads
This implements changes section 4.6 of P3016R6, and initializer_list related
parts of 4.7 and 4.8. The change makes immediately dangling invocations of
std::begin, std::end, and std::data on braced-init list ill-formed (see
range_access_neg.cc and range_access17_neg.cc):
auto it = std::begin({1, 2, 3}); // ILL-FORMED, it was dangling
(it == std::end({1, 2, 3})); // ILL-FORMED, was unspecified
auto* ptr = std::data({1, 2, 3}); // ILL-FORMED, ptr was dangling
However, similary problemetic calls for std::rbegin, std::rend remain
well-formed (see range_access14_neg.cc), as initializer_list overloads
are preserved for these functions:
auto rit = ranges::rbegin({1, 2, 3}); // COMPILES, dangling
auto rend = ranges::rend({1, 2, 3}); // COMPILES, danging
Note, that non-problematic std::size({1, 2, 3}) and std::empty({1, 2, 3})
use c-array overloads, and remain well-formed.
Per paper, to keep std::data(il) and std::empty(il) well-formed, the data
and empty member are added to initializer_list.
libstdc++-v3/ChangeLog:
* include/bits/version.def (initializer_list): Define with value
202511 for C++26.
* include/bits/version.h: Regenerate.
* libsupc++/initializer_list (initializer_list::data)
(initializer_list::empty) [__glibcxx_initializer_list >= 202511L]:
Define.
(std::begin(initializer_list<_Tp>), std::end(initializer_list<_Tp>)):
Define only if __glibcxx_initializer_list < 202511L (i.e. not defined).
* include/bits/range_access.h (std::empty(initializer_list<_Tp>))
(std::data(initializer_list<_Tp>)): Define only if
__glibcxx_initializer_list < 202511L (i.e. not defined).
* testsuite/18_support/initializer_list/range_access.cc: Move test for
brace-init list to range_access_neg.c. Included <iterator> in C++26 or
later mode.
* testsuite/18_support/initializer_list/data_empty_mem.cc: New test.
* testsuite/18_support/initializer_list/range_access14.cc: New test.
* testsuite/18_support/initializer_list/range_access14_neg.cc: New test.
* testsuite/18_support/initializer_list/range_access17.cc: New test.
* testsuite/18_support/initializer_list/range_access17_neg.cc: New test.
* testsuite/18_support/initializer_list/range_access_neg.cc: New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Eric Botcazou [Mon, 25 May 2026 07:42:04 +0000 (09:42 +0200)]
Restore original format of -fstack-usage and add new second field
This should minimize the backward compatibility breakage.
gcc/
* doc/invoke.texi (fstack-usage): Document new second field.
* toplev.cc (output_stack_usage_1): Revert latest changes and add
the mangled name as the second field.
If the last bit in a bitmap was in elt->bits[0], bitmap_last_set_bit
would not read it and would instead fall through with "word" still set
to elt->bits[1], which is known to be 0.
This patch fixes it to use the same structure as
bitmap_first_set_bit_worker.
As you might expect from this, only the sbitmap version of this
function appears to be used.
gcc/
* bitmap.cc (bitmap_last_set_bit): Fix handling of index 0.
Jerry DeLisle [Sun, 24 May 2026 18:51:49 +0000 (11:51 -0700)]
Fortran: [PR93727] Fix EX format kind=8 output on ILP32 targets
On 32-bit targets such as ARM where unsigned long is 32 bits, the
kind=8 case in get_float_hex_string used unsigned long for frac_part.
The kind=8 mantissa requires 52 bits (13 hex digits), so the cast
silently truncated the upper bits, producing wrong hex output. In
addition, converting a ~4.5e15 double value to a 32-bit unsigned long
is out of range, which raised IEEE_INVALID_FLAG on ARM hardware.
Fix kind=8 by using GFC_UINTEGER_8, which is guaranteed 64 bits on all
targets. Update kind=10 and kind=16 to use GFC_UINTEGER_8 throughout
for consistency with libgfortran conventions.
PR fortran/93727
libgfortran/ChangeLog:
* io/write_float.def (get_float_hex_string): Fix kind=8 frac_part
from unsigned long to GFC_UINTEGER_8 to correct truncated hex
output and IEEE_INVALID_FLAG on ILP32 targets. Update kind=10
and kind=16 to use GFC_UINTEGER_8 for consistency.
Peter Damianov [Sun, 24 May 2026 18:59:46 +0000 (14:59 -0400)]
algol68: Open source files in binary mode
When building a source file with CRLF newlines on Windows, the CRLFs were
getting converted to LFs, so a86_file_read was returning "short" byte counts
and tripping an assert. Make sure files get opened in binary mode to avoid this.
gcc/algol68/ChangeLog:
* a68-lang.cc (a68_handle_option): Open file in binary mode.
* a68-parser-scanner.cc (read_source_file): Open file in binary mode.
(include_files): Likewise.
Despite a similar rule existing earlier in match.pd, this simplify
rule is needed because the front-end (before pass 006.original)
performs trivial constant optimizations, such as ~1 -> -2 on
integers (at least those defined as `int`).
Andrew Pinski [Tue, 19 May 2026 01:20:14 +0000 (18:20 -0700)]
stack_usage: Print out the user visibility name too
Since the output here should be usable via humans, we
should print out the user realable name and not just the
mangled name. For C, that means we print out the same name
twice which is fine. The mangled name is useful to correspond
the assembly with the stack usage too.
For C++ it will something like:
t.c:2:5:_Z5unopti `int unopt(int)` 16 static
Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
* toplev.cc (output_stack_usage_1): Print out the human readable
name in quotes.
gcc/testsuite/ChangeLog:
* gcc.dg/stack-usage-1.c: Update testcase.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Andrew Pinski [Fri, 22 May 2026 19:07:28 +0000 (12:07 -0700)]
ifcvt: factor: turn asserts about abnormals to conditional [PR125419]
I missed that factor_out_operators might look further up when it is doing its
factoring so we end up with a statement that ssa names that are used in abnormal
edges.
This changes the asserts to just reject the factoring instead.
Bootstrapped and tested on x86_64-linx-gnu.
PR tree-optimization/125419
gcc/ChangeLog:
* tree-if-conv.cc (factor_out_operators): Change
asserts about abnormals into a conditional to reject
it.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/pr125419-1.c: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Jerry DeLisle [Mon, 11 May 2026 01:13:48 +0000 (18:13 -0700)]
Fortran: [PR93727] Implement EX format specifier for WRITE
These changes implement a portion of the Fortran 2018
EX format specifier for WRITE output. Hexadecimal
floating point formats for KIND=4,8,10, and 16 real
numbers if supported by the configured machine.
Format tokens are added as place holders for future leading
zero specifiers.
Remaining to be completed is proper rounding of truncated
hex float strings and implementing the READ functions. These
will be a followup patches.
PR fortran/93727
gcc/fortran/ChangeLog:
* io.cc (enum format_token): Add FMT_EX, FMT_LPS, FMT_LPZ, FMT_LZ
enums to identify specific tokens.
(format_lex): Add parsing and checking of the EXw.d and EXw.dEe edit
specifiers.
libgfortran/ChangeLog:
* io/format.c (format_lex): Add new FMT_EX token handing.
(parse_format_list): Likewise.
(next_format): Likewise
* io/io.h (write_ex): Add prototype for new function.
(internal_proto): Likewise.
* io/transfer.c (formatted_transfer_scalar_write): Use FMT_EX token.
* io/write.c (write_default_char4): White space fix.
(write_a): White space fix.
(write_boz): White space fix.
(write_decimal): White space fix.
(otoa_big): White space fix.
(write_character): White space fix.
(write_float_0): White space fix.
(write_ex): New function which uses the new helper function
get_float_hex_string() to build the hexadecimal float format for
output.
(write_real): White space fix.
(write_complex): White space fix.
(nml_write_obj): White space fix.
(namelist_write): White space fix.
* io/write_float.def: Add defines to handle the various forms of
KIND=16 floats. These handle the selection of the appropriate versions
of the frexp, fabs, and scalbn used to extract the components of the
floating point values.
(GFC_REAL_16_FREXP): New define.
(GFC_REAL_16_FABS): New define.
(GFC_REAL_16_SCALBN): New define.
(get_float_hex_string): New function which exatracts the bits and builds
the basic hexadecimal format strings into a buffer. The buffer is provided
by the caller write_ex.
(build_float_string): White space fix.
(quadmath_snprintf): White space fix.
(determine_en_precision): White space fix.
gcc/testsuite/ChangeLog:
* gfortran.dg/EXformat_1.F90: New test.
* gfortran.dg/EXformat_2.f90: New test.
Co-Authored-By: Harald Anlauf <anlauf@gcc.gnu.org>
Daniel Barboza [Sat, 17 Jan 2026 19:01:54 +0000 (16:01 -0300)]
fold-const.cc: remove fold_overflow_warning()
Remove all remaining callers of fold_overflow_warning() in
fold-const.cc, along with all associated logic.
pointer_may_wrap_p is also removed - it was being called twice, both
times to determine whether to call fold_overflow_warning() or not, and
had no other uses after fold_overflow_warning() was removed.
* gcc.dg/Wstrict-overflow-22.c: Removed, given that we do not
generated a warning for the pattern being tested.
* gcc.dg/Wstrict-overflow-5.c: Likewise.
We want to eliminate another source of Wstrict-overflow warnings from
tree_expr_nonnegative_warnv_p, via fold_overflow_warn(). At this point
strict_overflow_p is marked as ATTRIBUTE_UNUSED and we can remove it.
By removing it, the function would lost the "warnv" and be renamed to
tree_expr_nonnegative_p. This matches an existing function, that has a
different API. In a closer inspection we verify that
tree_expr_nonnegative_p is a wrapper for tree_expr_nonnegative_warn_p,
that throws a warning and leaves depth = 0 by default. This same
behavior can be achieved by removing strict_overflow_p from
tree_expr_nonnegative_warnv_p, so we'll go ahead with its rename and the
removal of the pre-existing tree_expr_nonnegative_p.
The additional strict_overflow_p local variables we've been adding to
satisfy the RECURSE() macro are all eliminated.
gcc/c-family/ChangeLog:
* c-warn.cc (warn_for_sign_compare): Remove strict_overflow_p
argument from tree_expr_nonnegative_p call.
gcc/c/ChangeLog:
* c-typeck.cc (build_conditional_expr): Likewise.
gcc/ChangeLog:
* fold-const.cc (fold_binary_loc): Likewise.
(tree_expr_nonnegative_warnv_p): Renamed to
tree_expr_nonnegative_p. Argument strict_overflow_p removed.
(tree_expr_nonnegative_p): Removed.
(RECURSE): Removed strict_overflow_p argument.
(tree_unary_nonnegative_p): Local strict_overflow_p variable
added to support the RECURSE() macro was removed.
(tree_binary_nonnegative_p): Likewise.
(tree_single_nonnegative_p): Likewise.
(tree_call_nonnegative_p): Likewise.
(tree_invalid_nonnegative_p): Likewise.
(tree_binary_nonzero_p): Removed sub_strict_overflow_p variable
from tree_expr_nonnegative_p call.
* fold-const.h (tree_expr_nonnegative_p): Removed.
(tree_expr_nonnegative_warnv_p): Renamed to
tree_expr_nonnegative_p, removed strict_overflow_p argument.
* tree-ssa-loop-manip.cc (create_iv): Removed ovf variable from
tree_expr_nonnegative_p call.
Daniel Barboza [Sat, 17 Jan 2026 19:01:52 +0000 (16:01 -0300)]
fold-const.cc: remove strict_overflow_p from tree_expr_nonnegative helpers
Before handling the fold_overflow_warn() call from
tree_expr_nonnegative_warnv_p we'll remove all remaining
strict_overflow_p flags from the helpers that are still using it.
An ATTRIBUTE_UNUSED tag was added in the strict_overflow_p argument in
tree_expr_nonnegative_warnv_p because the variable is now unused, but
removing it right now will incur a lot of non-trivial changes that would
be too much for this patch. This tag, and all the extra lines we're
adding to make RECURSE() happy, will be dealt with in the next patch.
gimple-fold.cc functions got impacted by the changes and were changed
accordingly.
gcc/ChangeLog:
* fold-const.cc (tree_call_nonnegative_warnv_p): Renamed to
tree_call_nonnegative_warnv_p.
(tree_call_nonnegative_p): Removed strict_overflow_p flag.
(tree_invalid_nonnegative_warnv_p): Renamed to
tree_invalid_nonnegative_p.
(tree_invalid_nonnegative_p): Removed strict_overflow_p flag.
(tree_expr_nonnegative_warnv_p): Added ATTRIBUTE_UNUSED tag in
the now unused strict_overflow_p argument. Removed
strict_overflow_p call from tree_invalid_nonnegative_p.
* fold-const.h (tree_call_nonnegative_warnv_p): Renamed to
tree_call_nonnegative_p.
(tree_call_nonnegative_p): Removed strict_overflow_p flag.
* gimple-fold.cc (gimple_call_nonnegative_warnv_p): Renamed to
gimple_call_nonnegative_p.
(gimple_call_nonnegative_p): Removed strict_overflow_p flag.
(gimple_stmt_nonnegative_warnv_p): Renamed to
gimple_stmt_nonnegative_p.
(gimple_stmt_nonnegative_p): Removed strict_overflow_p flag.
* gimple-fold.h (gimple_stmt_nonnegative_warnv_p): Renamed to
gimple_stmt_nonnegative_p.
(gimple_stmt_nonnegative_p): Removed strict_overflow_p flag.
* gimple-range-fold.cc (fold_using_range::fold_stmt): Removed
strict_overflow_p flag from gimple_stmt_nonnegative_p.
(fold_using_range::range_of_call): Likewise.
Daniel Barboza [Sat, 17 Jan 2026 19:01:51 +0000 (16:01 -0300)]
fold-const.cc: remove strict_overflow_p flag from tree_single_nonnegative_p
Similar to the previous patches: remove the strict_overflow_p flag to
allow us to remove the fold_overflow_warn() from the parent function
tree_single_nonnegative_warnv_p.
The changes done in fold-const.cc caused a ripple effect on
gimple-fold.cc, where we ended up doing similar changes to
gimple_assign_nonnegative_warnv_p and gimple_phi_nonnegative_warnv_p.
gcc/ChangeLog:
* fold-const.cc (tree_single_nonnegative_warnv_p): Renamed to
tree_single_nonnegative_p.
(tree_single_nonnegative_p): Removed strict_overflow_p flag.
(tree_expr_nonnegative_warnv_p): Removed strict_overflow_p flag
from tree_single_nonnegative_p call.
* fold-const.h (tree_single_nonnegative_warnv_p): Renamed to
tree_single_nonnegative_p.
(tree_single_nonnegative_p): Removed strict_overflow_p flag.
* gimple-fold.cc (gimple_assign_nonnegative_warnv_p): Renamed to
gimple_assign_nonnegative_p.
(gimple_assign_nonnegative_p): Removed strict_overflow_p flag.
(gimple_phi_nonnegative_warnv_p): Renamed to
gimple_phi_nonnegative_p.
(gimple_phi_nonnegative_p): Removed strict_overflow_p flag.
(gimple_stmt_nonnegative_warnv_p): Removed strict_overflow_p
flag from gimple_phi_nonnegative_p and gimple_assign_nonnegative_p
calls.
Daniel Barboza [Sat, 17 Jan 2026 19:01:50 +0000 (16:01 -0300)]
fold-const.cc: remove strict_overflow_p from tree_unary_nonnegative
Similar to what was done with tree_binary_nonnegative_p in the previous
patch, we want to remove overflow flags from all
tree_unary_nonnegative_warnv_p helpers, and then remove all overflow
flags from the parent helper itself.
gcc/ChangeLog:
* fold-const.cc (tree_unary_nonnegative_warnv_p): Renamed to
tree_unary_nonnegative_p.
(tree_unary_nonnegative_p): Removed strict_overflow_p flag.
(tree_expr_nonnegative_warnv_p): Removed strict_overflow_flag
from tree_unary_nonnegative_p calls.
* fold-const.h (tree_unary_nonnegative_warnv_p): Renamed to
tree_unary_nonnegative_p.
(tree_unary_nonnegative_p): Removed strict_overflow_p flag.
* gimple-fold.cc (gimple_assign_nonnegative_warnv_p): Removed
strict_overflow_flag from tree_unary_nonnegative_p calls.
gcc/testsuite/ChangeLog:
* gcc.dg/Wstrict-overflow-24.c: Removed since the pattern
doesn't throw warnings anymore.
* gcc.dg/Wstrict-overflow-9.c: Likewise.
Daniel Barboza [Sat, 17 Jan 2026 19:01:49 +0000 (16:01 -0300)]
fold-const.cc: remove strict_overflow_p from tree_binary_nonnegative
We want to remove a fold_overflow_warn() nested inside
tree_exp_nonnegative_warnv_p. This function uses a lot of helpers, and
some of them do recursive calls for the helper itself.
Let's deal with strict_overflow_p flags for each helper first, starting
with tree_binary_nonnegative_warnv_p, that is now renamed to
tree_binary_nonnegative_p since it doesn't handle warnings anymore.
The RECURSE() macro expects a strict_overflow_p variable to be valid in
its scope, so we can't just remove the flag from the function
parameters. We're adding a temporary block that declares a local
strict_overflow_p variable to make RECURSE() happy. These declarations
will all be removed when we deal with tree_expr_nonnegative_warnv_p.
gcc/ChangeLog:
* fold-const.cc (tree_binary_nonnegative_warnv_p): Renamed to
tree_binary_nonnegative_p.
(tree_binary_nonnegative_p): Removed strict_overflow_p flag. Add
a local variable with the same name for RECURSE() that we'll
remove later.
(tree_expr_nonnegative_warnv_p): Removed strict_overflow_p flag
from tree_binary_nonnegative_p call.
* fold-const.h (tree_binary_nonnegative_warnv_p): Renamed to
tree_binary_nonnegative_p.
(tree_binary_nonnegative_p): Removed strict_overflow_p flag.
* gimple-fold.cc (gimple_assign_nonnegative_warnv_p): Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/pr56355-1.c: Removed since it's a warning check test
and we do not emit warnings for the code being tested.
Daniel Barboza [Sat, 17 Jan 2026 19:01:48 +0000 (16:01 -0300)]
fold-const.cc: remove strict_overflow_p from maybe_canonicalize_comparison
Remove the strict overflow flag from maybe_canonicalize_comparison
functions. All related fold_overflow_warning calls are also removed.
gcc/ChangeLog:
* fold-const.cc (maybe_canonicalize_comparison_1): Removed
strict_overflow_p flag.
(maybe_canonicalize_comparison): Removed strict_overflow_p
flag and all fold_overflow_warning calls.
Daniel Barboza [Sat, 17 Jan 2026 19:01:47 +0000 (16:01 -0300)]
fold-const.cc: remove strict_overflow_p from tree_expr_nonzero_warnv_p
After changing all its internal helpers we're ready to change
tree_expr_nonzero_warnv_p. By removing the strict_overflow_p flag from
it we'll make the existing tree_expr_nonzero_p unneeded. We'll delete it
and rename tree_expr_nonzero_warnv_p to tree_expr_nonzero_p without
changing the API and the behavior for existing callers.
And we'll end up removing a fold_overflow_warn() call, which was our
whole idea in the end.
gcc/ChangeLog:
* fold-const.cc (tree_expr_nonzero_warnv_p): Renamed to
tree_expr_nonzero_p and removed the strict_overflow_p flag.
(tree_expr_nonzero_p): Removed it since it's now redundant with
tree_expr_nonzero_warnv_p.
(tree_unary_nonzero_p): Removed the local sub_strict_overflow_p
flag from the tree_expr_nonzero_p call.
(tree_binary_nonzero_p): Likewise.
(tree_single_nonzero_p): Likewise.
Daniel Barboza [Sat, 17 Jan 2026 19:01:44 +0000 (16:01 -0300)]
fold-const.cc: remove strict_overflow_p from tree_unary_nonzero_warnv_p
This helper is called by tree_expr_nonzero_warnv_p(), a helper that is
gating a call to fold_overflow_warning() that we want to eliminate.
For now let's change the comment from tree_expr_nonzero_warnv_p() to
mention that we're throwing overflow warnings just for certain cases,
not all. We'll change that comment again when we get to work on
tree_expr_nonzero_warnv_p().
The helper is renamed to remove the "warn" from its name since it
doesn't throw or set any overflow warnings anymore.
gcc/ChangeLog:
* fold-const.cc (mask_with_tz): Changed comment that describes
tree_expr_nonzero_warnv_p warn on overflow behavior.
(tree_expr_nonzero_warnv_p): Removed strict_overflow_p flag.
(tree_unary_nonzero_warnv_p): Renamed to tree_unary_nonzero_p.
(tree_unary_nonzero_p): Removed strict_overflow_p flag.
* fold-const.h (tree_unary_nonzero_warnv_p): Renamed to
tree_unary_nonzero_p.
(tree_unary_nonzero_p): Removed strict_overflow_p flag.
Daniel Barboza [Sat, 17 Jan 2026 19:01:42 +0000 (16:01 -0300)]
fold-const.cc: remove strict_overflow flag from make_range helpers
This is a first step towards deprecating -Wstrict_overflow. The warning
is rooted in several places throughout the code, fold-const.cc functions
being one of them (via fold_overload_warn()).
These helpers are used in other files as well so the approach taken is to
gradually remove it from fold-const.cc while fixing the existing callers
along the way.
Philipp Tomsich [Sat, 23 May 2026 16:31:11 +0000 (10:31 -0600)]
[RISC-V] Improve slli+zext+andi sequence for RISC-V
So this is another patch mostly from the VRULL team. Given something like
this:
> #define T int
> typedef long unsigned int size_t;
> extern void *xcalloc (size_t, size_t) ;
> typedef struct sparseset_def
> {
> unsigned T *dense;
> unsigned T *sparse;
> unsigned T members;
> unsigned T size;
> unsigned T iter;
> unsigned char iter_inc;
> unsigned char iterating;
> unsigned T elms[2];
> } *sparseset;
> sparseset
> sparseset_alloc (unsigned T n_elms)
> {
> unsigned T n_bytes = sizeof (struct sparseset_def)
> + ((n_elms - 1) * 2 * sizeof (unsigned T));
> sparseset set = (sparseset) xcalloc (1, n_bytes);
> return set;
> }
It currently compiles into this with rv64gcb:
> addi a1,a0,4
> slli a1,a1,3
> zext.w a1,a1
> andi a1,a1,-8
> li a0,1
> tail xcalloc
But we can do better. In particular the slli+zext+andi sequence can be
improved into:
The new pattern needs to be a define_insn_and_split due to a chain of
define_insn_and_split patterns that start with mvconst_internal 🙁
To avoid regressing zba-shadd.c I had to turn an existing define_split into a
define_insn_and_split 🙁 🙁
This has been regression tested on riscv32-elf and riscv64-elf. It's been
bootstrapped and regression tested on the K1 design (where is likely triggered
a few times during bootstrap) and on the Pioneer (which doesn't have Zba, so
this pattern should never trigger). Waiting on pre-commit testing's verdict.
gcc/
* config/riscv/bitmanip.md (slli_slli_uw): New pattern.
(plus+and+ashift splitter): Turn into define_insn_and_split.
(riscv_slli_uw): Renamed from *slliuw.
gcc/testsuite
* gcc.target/riscv/and-shift-1.c: New test.
Paul Thomas [Sat, 23 May 2026 13:58:36 +0000 (14:58 +0100)]
Fortran: Fix scalar class to derived select type entities. [PR125263]
2026-05-23 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/125263
* trans-expr.cc (gfc_trans_assignment_1): Pass scalar class to
derived type assignment expressions to gfc_trans_scalar_assign.
gcc/testsuite/
PR fortran/125263
* gfortran.dg/pr125263.f90: New test.
Paul Thomas [Sat, 23 May 2026 13:40:19 +0000 (14:40 +0100)]
Fortran: Fix ICE in allocatable finalization expression [PR125391]
2026-05-23 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/125391
* trans.cc (gfc_assignment_finalizer_call): For finalization of
allocatable and pointer lhs before assignment, gfc_conv_expr
should be used with se.descriptor_only. This avoids implicit of
set_factored_descriptor_value by gfc_conv_expr_descriptor.
gcc/testsuite/
PR fortran/125391
* gfortran.dg/pr125391.f90: New test.
Dimitar Dimitrov [Wed, 25 Mar 2026 20:34:05 +0000 (22:34 +0200)]
pru: Inline muldi3 when optimizing for speed
When optimizing for speed, it is faster to inline the 32-bit
multiplication sub-operations, instead of calling a library function.
This saves instruction cycles spent for preparing a call to the multi64
library function, at the expense of duplication in text section.
The inlined muldi3 operation uses only a few temporary registers,
so there should be no negative effects due to increased register
pressure. Even more, the register pressure may even decrease with
inlining because the number of temporary registers is much lower than
the number of caller-saved registers for PRU.
gcc/ChangeLog:
* config/pru/constraints.md: Prevent allocating r27 as
SImode destination for mulsi3 pattern.
* config/pru/pru.h (enum reg_class): Expand MULDST_REGS
to allow fitting DImode.
* config/pru/pru.md (umulsidi3): New pattern.
(muldi3): Ditto.
Jason Merrill [Fri, 22 May 2026 16:57:09 +0000 (12:57 -0400)]
c++: defaulted ctor vs template ctor [PR125135]
Here we were getting into a CWG1092 cycle again through
check_non_deducible_conversions, trying to lazily declare the RE move
constructor, looking for a constructor to move A, considering the
constructor template which takes RE&, and so trying to lazily declare the RE
constructors again.
Julian Brown [Fri, 22 May 2026 21:55:50 +0000 (23:55 +0200)]
OpenMP: Enable 'declare mapper' mappers for 'target update' directives
This patch enables use of 'declare mapper' for 'target update' directives,
for C and C++ but not yet for Fortran.
There are some implementation choices here and some
"read-between-the-lines" consequences regarding this functionality,
as follows:
* It is possible to invoke a mapper which contains clauses that
don't make sense for a given 'target update' operation. E.g. if a
mapper definition specifies a "from:" mapping and the user does "target
update to(...)" which triggers that mapper, the resulting map kind
(OpenMP 5.2, "Table 5.3: Map-Type Decay of Map Type Combinations")
is "alloc" (and for the inverse case "release"). For such cases,
an '-Wopenmp' warning is issued and the map clause in question is
dropped from the mapper expansion. (Other choices might be to make
this an error, or to do the same thing but silently, or warn only
given some special option.)
gcc/c-family/ChangeLog:
* c-common.h (enum c_omp_region_type): Add C_ORT_UPDATE and
C_ORT_OMP_UPDATE codes.
* c-omp.cc (omp_basic_map_kind_name): New function.
(omp_instantiate_mapper): Add LOC parameter and 'target update'
support.
(c_omp_instantiate_mappers): Add 'target update' support.
Wang Yaduo [Fri, 22 May 2026 17:26:10 +0000 (11:26 -0600)]
[PATCH v4] RISC-V: Add per-type reduction costs to the vector cost model
Add type-specific reduction costs for integer (i8/i16/i32/i64) and
floating-point (f16/f32/f64) reductions. Ordered (fold-left) FP
reductions receive separate higher costs. Use helpers is_reduction()
and get_reduction_cost() for readability. Adjust affected tests to use
-mmax-vectorization.
Changes in v4:
- Fix failure in gcc.target/riscv/rvv/autovec/cond/pr111401.c by
adding -mmax-vectorization.
Tested locally with qemu, all affected tests pass.
gcc/
* config/riscv/riscv-protos.h (common_vector_cost): Add
reduc_i8_cost through reduc_f64_cost and
reduc_f{16,32,64}_ordered_cost.
* config/riscv/riscv.cc: Set costs in rvv_vls_vector_cost and
rvv_vla_vector_cost.
* config/riscv/riscv-vector-costs.cc (is_reduction): New helper.
(get_reduction_cost): New helper.
(costs::adjust_stmt_cost): Use them for vec_to_scalar kind.
cfgrtl: Forbid forwarder blocks from having clobbers [PR125375]
In this testcase, jump2 was presented with:
L1:
set the return register
do epilogue stuff
goto L4
L2:
do the same epilogue stuff
L3:
clobber the return register
goto L4
The question then is: is the L3 block a forwarder block? It is a
forwarder block in the sense that a jump to L3 can be replaced with a
jump to L4. But it isn't a forwarder block in the sense of a jump to L3
being equivalent to a jump to L4. In particular, a jump to L4 cannot be
merged with a jump or fallthrough to L3 unless we can prove that the
clobber is valid for both paths.
In the testcase, L3 was marked as a forwarder block and so cross-jumping
created:
L1:
set the return register
L2:
do epilogue stuff
L3:
clobber the return register
goto L4
The set of the return register was then inevitably deleted as dead.
The clobber in this case is of the return register. But the same
principle/problem would apply to any clobber. We can't introduce new
clobbers on a path without proving that the clobbered thing is dead.
This question arises due to an old quirk of active_insn_p that predates
CVS history:
Thus a clobber is "active" before RA but not after it. This means
that, according to flow_active_insn_p, a block with a clobber is not
a forwarder block before RA, but can be afterwards.
The "most optimal" solution would probably be to split the concept
of forwarder block into two, one that allows clobbers and one that
doesn't. However, that would be difficult to retrofit at this stage
and isn't likely to be suitable for backporting. This patch therefore
takes the more conservative approach of making flow_active_insn_p treat
clobbers in the same way after RA as it does before RA.
Some of this infrastructure is probably ripe for updating. For example,
flow might have required explicit uses of the return register, but DF
should cope well enough without. We should probably also check
whether the active_insn_p behaviour still makes sense.
gcc/
PR rtl-optimization/125375
* cfgrtl.cc (flow_active_insn_p): Return true for clobbers.
>>> Produces 2 regressions:
>>> |
>>> | regressions.sum:
>>> | Running gcc:gcc.target/aarch64/aarch64.exp ...
>>> | FAIL: gcc.target/aarch64/tbz_1.c check-function-bodies g1
>>> | FAIL: gcc.target/aarch64/tbz_1.c check-function-bodies g2
>> I've reproduced this locally. I haven't gotten into the debug cycle
>> yet, but wanted folks to know it's mine AFAICT to avoid duplicating
>> debugging efforts.
>
> I think the fix is just a testcase fix.
> Currently the testcase has:
> ** tbnz w[0-9]+, #?0, .L([0-9]+)
>
> But that should just can be:
> ** tbnz [wx][0-9]+, #?0, .L([0-9]+)
>
> to match both x0 and w0 there. But are valid in this case with bit 0.
> For both g1 and g2.
Yea, so I wanted to verify this was behaving per expectation. It is. We have
this in g1:
We can trivially see that the zero extension is pointless because the value is
masked with 0x1 immediately thereafter. So ext-dce replaces the zero_extend
with a subreg which then simplifies the sequence into:
Jonathan Wakely [Fri, 22 May 2026 12:25:57 +0000 (13:25 +0100)]
libstdc++: Fix some test failures due to vector using allocate_at_least
Some std::vector tests are FAILing for 32-bit targets because
std::vector now rounds up allocations to an alignment boundary,
perturbing the expected capacity of the vectors in the tests.
Tweak the tests so that they don't depend on the precise capacity, which
is unspecified anyway.
The 23_containers/vector/modifiers/insert_vs_emplace.cc test still
FAILs, that needs a different fix.
libstdc++-v3/ChangeLog:
* testsuite/23_containers/vector/modifiers/emplace/self_emplace.cc:
Ensure there is no unused capacity before inserting new element.
* testsuite/23_containers/vector/modifiers/insert/self_insert.cc:
Likewise.
Jakub Jelinek [Fri, 22 May 2026 09:19:18 +0000 (11:19 +0200)]
match.pd: Handle BUILT_IN_BITREVERSE8 like other BUILT_IN_BITREVERSE* [PR125399]
I've mistakenly omitted BUILT_IN_BITREVERSE8 in the BITREVERSE
operator list.
The following patch fixes that, plus extends the __builtin_bitreverse32
test with one further check and duplicates the test for the other
builtins, i.e. __builtin_bitreverse{8,16,64,128}.
* gcc.dg/builtin-bitreverse-4.c (foo9): New function.
* gcc.dg/builtin-bitreverse-5.c: New test.
* gcc.dg/builtin-bitreverse-6.c: New test.
* gcc.dg/builtin-bitreverse-7.c: New test.
* gcc.dg/builtin-bitreverse-8.c: New test.
The following patch attempts to implement the C++26
P3074R7 - trivial unions (was std::uninitialized<T>)
paperand proposed resolution of
CWG3189 - Implicitly deleted destructors for union-like classes
with the exception of the
#define __cpp_lib_constexpr_inplace_vector 2025XXL // also in <inplace_vector>
addition and possibly needed <inplace_vector> changes (will defer that to
Jonathan / Tomasz) and except for the changes in [class.default.ctor]/4 which
were reverted by P3726R2 later on .
There is one change which doesn't affect just C++26 but also older versions
of the standard, https://eel.is/c++draft/class.default.ctor#2.2 or its older
counterparts, e.g. C++11 had in [class.ctor]/5
"any non-variant non-static data member of const-qualified type (or array thereof)
with no brace-or-equal-initializer does not have a user-provided default
constructor"
but we've been ignoring the "non-variant" part thereof and diagnosing it
for variant members too. Note, this is related to the other unimplemented
rule I've posted a patch earlier for that was dismissed (reject
all variant members const before C++26), so some cases which we've rejected
for a wrong reason will now be accepted when they are still invalid before
C++26.
2026-05-22 Jakub Jelinek <jakub@redhat.com>
PR c++/119059
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): For C++26 predefine
__cpp_trivial_union to 202502L.
gcc/cp/
* method.cc: Implement C++26 P3074R7 - trivial unions (was
std::uninitialized<T>) (except the sentence removed again in P3726R2)
and proposed resolution of CWG3189 - Implicitly deleted destructors
for union-like classes.
(walk_field_subobs): Don't do default_init_uninitialized_part checks
for variant members. Don't check subobject ctor/dtor for variant
members for ctor/inheriting ctor or when subobject doesn't have member
initializer for dtor and it is either the dtor_from_ctor case or
the current class doesn't have user provided ctors.
* class.cc (check_field_decl): Don't or in
TYPE_HAS_NONTRIVIAL_DESTRUCTOR or TYPE_HAS_DEFAULT_CONSTRUCTOR of
variant subobjects for C++26.
gcc/testsuite/
* g++.dg/DRs/dr2581-1.C: Expect warning for __cpp_trivial_union.
* g++.dg/DRs/dr2581-2.C: Expect error for __cpp_trivial_union.
* g++.dg/cpp26/feat-cxx26.C: Add __cpp_trivial_union checking.
* g++.dg/cpp26/trivial-union1.C: New test.
* g++.dg/cpp26/trivial-union2.C: New test.
* g++.dg/reflect/trivial-union1.C: New test.
* g++.dg/reflect/type_trait6.C: Adjust expected result of
one is_destructible_type and two is_nothrow_destructible_type calls.
* g++.dg/reflect/is_constructible_type1.C: Adjust expected result
of one is_constructible_type call.
* g++.dg/init/pr43719.C: Don't expect one error.
* g++.dg/init/pr25811.C: Don't expect 3 diagnostic messages,
instead expect a different one for C++98 only.
* g++.dg/other/anon-union2.C: Only expect one diagnostic for
C++23 and older.
* g++.dg/cpp0x/union1.C: Only expect 6 diagnostic messages for
C++23 and older.
* g++.dg/cpp0x/union4.C: Only expect 3 diagnostic messages for
C++23 and older.
* g++.dg/cpp0x/defaulted2.C: Only expect 2 diagnostic messages for
C++23 and older.
Kishan Parmar [Fri, 22 May 2026 06:55:25 +0000 (12:25 +0530)]
rs6000: Add MPCCORE to TARGET_NO_LWSYNC
The MPC8xx PowerQUICC family only implements full 'sync', 'lwsync'
is not yet supported. The CPU actually checks that the
should-be-zero bits of the sync instruction are zero, and faults
otherwise - same situation as for E500 cores.
Fix emitting 'lwsync' instructions by adding PROCESSOR_MPCCORE
to the TARGET_NO_LWSYNC define.
Encountered an illegal instruction crash (in libstdc++ atomics) and
verified the fix on actual MPC860 hardware.
Avinal Kumar [Thu, 21 May 2026 10:24:12 +0000 (15:54 +0530)]
match: Handle X != INT_MIN ? -X : INT_MIN [PR125050]
The pattern X != C1 ? -X : C2 currently bails out when C1 is
INT_MIN and the type doesn't wrap, because a signed negation
of INT_MIN is undefined behavior. But the whole expression is
well-defined: it is equivalent to (signed)(-(unsigned)X).
Handle the wi::only_sign_bit_p case by emitting an unsigned
negate instead of giving up, mirroring what the abs pattern
already does for the same edge case.
PR tree-optimization/125050
gcc/ChangeLog:
* match.pd: (X != C1 ? -X : C2): Handle C1 being INT_MIN
by emitting (signed)(-(unsigned)X) instead of bailing out.
gcc/testsuite/ChangeLog:
* gcc.dg/fold-condneg-2.c: Update expected optimization.
* gcc.dg/pr125050.c: New test.
* gcc.dg/tree-ssa/phi-opt-50.c: New test.
* gcc.dg/tree-ssa/phi-opt-51.c: New test.
Jonathan Wakely [Thu, 21 May 2026 22:13:53 +0000 (23:13 +0100)]
libstdc++: Combine duplicated tests for <atomic>
The types_std_c++0x.cc and types_std_c++20.cc tests are almost
identical, and the latter is redundant now that we can (and do) run all
tests for any -std option, and run with -std=gnu++20 by default.
Likewise for the _neg.cc tests.
Merge the C++20-specific parts into the c++0x tests and remove the c++20
ones.
libstdc++-v3/ChangeLog:
* testsuite/29_atomics/headers/atomic/types_std_c++0x.cc: Check
for C++20 std::memory_order enum. Use feature test macro for
char8_t.
* testsuite/29_atomics/headers/atomic/types_std_c++0x_neg.cc:
Add check for atomic_char8_t.
* testsuite/29_atomics/headers/atomic/types_std_c++20.cc:
Removed.
* testsuite/29_atomics/headers/atomic/types_std_c++20_neg.cc:
Removed.
* testsuite/29_atomics/headers/atomic/types_std_c++2a.cc:
Removed.
avoid-store-forwarding: Continue BB analysis after complex memory ops
The pass aborted analysis of the entire remaining basic block when it
encountered a complex memory operation (non-simple store/load).
Store-forwarding opportunities after the complex operation were silently
missed.
Replace the early return with a flush-and-continue: clear the pending
store candidates and keep scanning. The two other flush sites
(throwing insns, unknown-size memory) already use this pattern.
gcc/ChangeLog:
* avoid-store-forwarding.cc
(store_forwarding_analyzer::avoid_store_forwarding): Replace
return with flush-and-continue for complex memory operations.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/avoid-store-forwarding-6.c: New test.
avoid-store-forwarding: Reject bit-inserts that clobber live hard regs
The bit-insert sequences generated by store_bit_field can clobber hard
registers (such as the flags register on x86) as a side effect. If
such a register is live at the insertion point, the transformation
would corrupt it, breaking flag-dependent sequences like carry chains
(see PR119795).
Add a liveness check in process_store_forwarding: after generating the
bit-insert sequences, collect the hard registers they clobber (excluding
the intended destination) and reject the transformation if any of them
is live at the insertion point. Per-insn live-out hard-register sets
are computed once per BB by simulating it backward with
df_simulate_one_insn_backwards, and cached in store_forwarding_analyzer
so subsequent forwarding candidates in the same BB reuse the result.
The cache is populated lazily on the first candidate that produces
non-empty clobbers, so on targets where bit-inserts have no side-effect
clobbers (such as aarch64 bfi) the BB walk never runs.
gcc/ChangeLog:
* avoid-store-forwarding.cc: Include regs.h.
(record_hard_reg_clobbers): New callback.
(store_forwarding_analyzer::m_bb_live_after): New cache.
(store_forwarding_analyzer::compute_bb_live_after): New helper.
(store_forwarding_analyzer::process_store_forwarding): Add
liveness check for hard registers clobbered by bit-insert
sequences, using the cached per-BB live-out information, and
evict the load_insn entry from the cache before delete_insn
in the load-elim path.
(store_forwarding_analyzer::avoid_store_forwarding): Clear the
per-BB liveness cache on entry.
The store_exprs_del vector was introduced in the PR119795 fix as a
conservative safety measure alongside the actual bug fixes (adding
forwardings.truncate(0) on vector mismatch and true_dependence
detection). It tracks deleted store candidates and blocks forwarding
when a deleted store's range overlaps with the load.
However, this check is not needed for correctness. In the non-load-
elimination path the load is kept and reads all bytes from memory;
the bit-insert only overwrites forwarded bytes. Deleted stores remain
in the instruction stream, so their memory effects are visible to the
load. In the load-elimination path, all bytes must be covered by
forwarded stores (enforced by the bitmap check), so missing stores
cannot cause partial updates.
The vector grows monotonically through the basic block and is scanned
for each forwarding candidate, producing O(n^2) behavior for large
basic blocks.
Remove the mechanism entirely. This eliminates the O(n^2) scan and
simplifies the code.
gcc/ChangeLog:
* avoid-store-forwarding.cc
(store_forwarding_analyzer::avoid_store_forwarding): Remove
store_exprs_del vector and all associated tracking. Remove the
same_range_as_removed check from the forwarding loop. Update
block comment.
libffi/ChangeLog:
PR libffi/117635
* testsuite/lib/libffi.exp (load_gcc_lib): Load library from GCC
testsuite.
Load target-supports.exp and target-supports-dg.exp.
(libffi-init): Use libraries in GCC build tree.
Pass correct flags on darwin.
(libffi_target_compile): If '--with-build-sysroot=[...]' was
specified, use it for build-tree testing. Link with
-shared-libgcc -lstdc++ for C++ sources.
Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
Marek Polacek [Tue, 19 May 2026 00:51:06 +0000 (20:51 -0400)]
c++: fix bogus error with xobj member function [PR125330]
In this test since r17-472 we issue a bogus "not declared in this scope"
error when parsing the requires because we failed to pushdecl. Xobj
parameters reuse the default argument field (in _parameter_declaration)
so we also have to check this_identifier.
PR c++/125330
gcc/cp/ChangeLog:
* parser.cc (cp_parser_parameter_declaration_list): Also
pushdecl when parameter->default_argument is this_identifier.
Jason Merrill [Tue, 19 May 2026 09:15:00 +0000 (05:15 -0400)]
c++: another constexpr empty class tweak
While talking about PR125336, I noticed that we were unnecessarily omitting
a subobject CONSTRUCTOR for non-potentially-overlapping fields of empty
class type. Let's check is_empty_field instead.
Jason Merrill [Thu, 21 May 2026 19:02:21 +0000 (15:02 -0400)]
c++: this capture in template [PR125384]
The r16-1019 change to special-case 'this' capture handling dropped the
'const' qualifier from the capture proxy, so the call to rvalue in
finish_this_expr no longer built a NOP_EXPR to express dropping that
'const'.
PR c++/125384
PR c++/113563
gcc/cp/ChangeLog:
* lambda.cc (build_capture_proxy): 'this' capture proxy is const.
Wilco Dijkstra [Mon, 9 Feb 2026 19:01:19 +0000 (19:01 +0000)]
AArch64: Add PIC/PIE support to large model [PR 123791]
Use an indirection via GOT for data accesses that might be out of range of
ADRP. Using the GOT avoids placing relro symbol references in literal pools
(PR 123791). It also allows the large model to trivially support PIC/PIE.
Constants and readonly data use ADRP since the maximum text size is 2GB in
the large model [1]. The code quality of -mcmodel=large improves dramatically
as a result: codesize of SPEC2017 reduces by 2.2%.
gcc:
PR target/123791
* config/aarch64/aarch64.cc (aarch64_cannot_force_const_mem): Remove
forcing symbol references to const mem.
(aarch64_can_use_per_function_literal_pools_p): Return false for
large model.
(aarch64_use_blocks_for_constant_p): Update comment.
(initialize_aarch64_code_model): Allow PIC/PIE.
(aarch64_classify_symbol): Use SYMBOL_SMALL_ABSOLUTE for constant
references and SYMBOL_SMALL_GOT_4G for writeable data.