Jason Merrill [Mon, 3 Nov 2025 14:51:38 +0000 (17:51 +0300)]
c++: modules, clones, and overload resolution
21_strings/basic_string_view/cons/wchar_t/3.cc was failing with import std
because as in the reduced testcase, the module includes an instantiation of
the template constructor for <const char *, const char *>, and importing the
module was wrongly adding that instantiation to CLASSTYPE_MEMBER_VEC, so it
became part of the overload set independent of its template.
tsubst_function_decl doesn't add to CLASSTYPE_MEMBER_VEC, and importing
should work the same.
gcc/cp/ChangeLog:
* module.cc (trees_in::decl_value): Don't add an instantiation to
CLASSTYPE_MEMBER_VEC.
gcc/testsuite/ChangeLog:
* g++.dg/modules/clone-5_a.C: New test.
* g++.dg/modules/clone-5_b.C: New test.
Piotr Trojanek [Wed, 22 Oct 2025 15:38:04 +0000 (17:38 +0200)]
ada: Guard compile-time evaluator against rewritten if-expressions
A hopefully temporary fix for if-expression that has been rewritten into an
if-statement, where a object reference has the if-statement as its parent,
but is not part of the condition, then statements or else statements.
gcc/ada/ChangeLog:
* exp_util.adb (Get_Current_Value_Condition): Guard against orphaned
references in rewritten if-expressions.
Eric Botcazou [Tue, 21 Oct 2025 21:33:01 +0000 (23:33 +0200)]
ada: Restore alignment check for address clause given with alignment clause
The alignment check for address clauses had historically been performed
universally by GNAT, until a decade ago when it was disabled by default
on non-strict-alignment platforms.
This seems questionable when an alignment clause is also given for the
entity since the intent is clear, so the change restores it as well as
its associated warning.
Moreover, this alignment check had historically been subsumed into the
language-defined Range_Check, until two decades ago when it became the
implementation-defined Alignment_Check, while still being part of the
Range_Check to ease the transition. Now is probably a good time to cut
the apron strings and make Alignment_Check standalone.
gcc/ada/ChangeLog:
* doc/gnat_rm/representation_clauses_and_pragmas.rst (Address
Clauses): Adjust description of alignment checks.
* sem_ch13.adb (Address_Clause_Check_Record): Remove now unused
Alignment_Checks_Suppressed component.
(Alignment_Checks_Suppressed): Delete.
(Analyze_Attribute_Definition_Clause) <Attribute_Alignment>: Do not
consider the status of range checks to decide whether to generate an
alignment check. Always generate it if an alignment clause is also
given for the entity.
<Attribute_Alignment>: Generate an alignment check if an address
clause is also given for the entity.
(Register_Address_Clause_Check): Adjust for above removal.
(Validate_Address_Clauses): Test the Check_Address_Alignment flag
on the clause to decide whether to give the warning.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.
Piotr Trojanek [Mon, 20 Oct 2025 10:09:07 +0000 (12:09 +0200)]
ada: Decouple compile-time evaluation from while loop source locations
The compile-time evaluation relied on source locations to decide whether a
variable reference occurs within a WHILE loop where the evaluation can
assume the loop condition. Now this relies exclusively on the AST structure.
gcc/ada/ChangeLog:
* exp_util.adb (Find_In_Enclosing_Context): Refactor from handling of
IF statements.
(Get_Current_Value_Condition): Reuse IF code for WHILE statements.
Piotr Trojanek [Fri, 17 Oct 2025 09:25:00 +0000 (11:25 +0200)]
ada: Decouple compile-time evaluation from if_statement source locations
The compile-time evaluation relied on source locations to decide whether a
variable reference occurs within an IF statement where the evaluation can
assume the IF condition. This was unreliable, especially for rewritten and
internally generated IF statements, whose End_Span is typically left as zero.
This patch makes the evaluation exclusively dependent on the AST structure
itself, while the source location and the span of an if statement is only used
in assertion.
gcc/ada/ChangeLog:
* exp_util.adb (Get_Current_Value_Condition): Rewrite to not rely on
Sloc and End_Span of an if statement.
Piotr Trojanek [Fri, 17 Oct 2025 08:47:41 +0000 (10:47 +0200)]
ada: Preserve AST structure when copying tree with discrete types
When copying AST we created an orphaned copy of a scalar range. This was
confusing the compile-time evaluator, because we couldn't determine location of
a scalar range within an IF statement by looking at its parenthood chain.
gcc/ada/ChangeLog:
* sem_util.adb (Update_Semantic_Fields): Preserve tree structure when
copying scalar range of a discrete type.
Piotr Trojanek [Fri, 17 Oct 2025 08:33:44 +0000 (10:33 +0200)]
ada: Keep source locations for inlined subprograms from predefined units
Frontend inlining, which is now deprecated and only enabled with switch -gnatN
is used, used to reset source locations for subprograms from predefined units.
This was a workaround to prevent the debugger from visiting internal code in
Ada.Tags, but this problem no longer occurs (even when switch -gnatN is used)
and is no longer needed. This patch removes it, because it confused
compile-time evaluation, which makes use of source locations to recognize code
within IF statements.
Gary Dismukes [Thu, 16 Oct 2025 21:38:38 +0000 (21:38 +0000)]
ada: Crash on call to a dispatching op with if_expr and tag-indeterminate calls
The compiler can crash with a Storage_Error for a failed precondition
when compiling a call to a dispatching subprogram where an actual for a
controlling formal is given by an if_expression whose dependent expressions
are tag-indeterminate calls. This problem showed up on a build of Alire
(on the compilation of alire-roots.adb) done during a build_gnat_world
mailserver (as well as having been noticed and reported separately by
another engineering team).
The code in Sem_Disp.Check_Dispatching_Call for checking nondispatching
procedure calls for actuals that are calls to abstract tag-indeterminate
functions did not account for conditional expressions, and attempted to
retrieve the (nonexistent) Expression field from an N_If_Expression node,
failing the precondition for Expression. It was discovered that none of
the code checking for illegal calls to abstract tag-indeterminate functions
in procedure calls is needed, and the whole related "elsif" part is removed
by this change. (Note that there is separate checking done separately
within Check_Dispatching_Call that will catch nondispatching calls to
abstract functions.)
gcc/ada/ChangeLog:
* sem_disp.adb (Check_Dispatching_Call): Remove "elsif" that does error
checking for abstract tag-indeterminate calls (seems to be no longer
needed).
Marc Poulhiès [Fri, 10 Oct 2025 08:52:47 +0000 (10:52 +0200)]
ada: Fix another incorrectly nested procedure
When unnesting a loop, its body is moved inside a procedure, and inner
entities have their scope adjusted. The current GNAT Tree at this stage
is incoherent wrt scope information, and some nested entities are
incorrectly scoped, possibly leading to a crash of the unnester.
The existing Fixup_Inner_Scopes procedure has been added to adjust the
incoherences after the fact because fixing them earlier has proven to be
more complex than expected. This change adds one more adjustment by this
procedure for TSS (Type Support Subprogram) that may be embedded within
N_Freeze_Entity nodes.
gcc/ada/ChangeLog:
* exp_ch7.adb (Fixup_Inner_Scopes): Adjust to handle N_Freeze_Entity nodes.
* exp_unst.adb (Get_Level): Assert when the function didn't find the
nested level (indicates that inner sub has scope pointing higher in
the stack)
This patch extends the set of names recognized by
Is_Predefined_File_Name so that names that start with "a-" and are longer
than 12 characters are considered predefined.
This is motivated by the need to make gprname work with the in-tree
a-strunb__shared.ads file that uses GNAT syntax extensions but whose name
wasn't considered predefined before this patch.
Bob Duff [Wed, 15 Oct 2025 10:43:32 +0000 (06:43 -0400)]
ada: Get rid of Sy/Sm mixing (Expression)
We should not mix "syntactic" and "semantic" for the same field
in different node kinds.
The Expression field was both syntactic (in N_Exception_Declaration) and
semantic (in all other node kinds). This patch makes it always
syntactic.
Expression is the last such field, so we remove all code and comments
that allowed for such mixing.
The Expression field in N_Exception_Declaration was never properly
documented; fix that.
No change in overall compiler behavior.
An alternative would be to change the name of this Expression
field to be something else (Exception_Declaration_Expression?),
and keep it as "semantic". That would cause an earthquake in gigi,
because gigi wants to treat exception declarations more-or-less
like normal object declarations, with the Expression field being
the initialization expression. So we don't do that.
gcc/ada/ChangeLog:
* gen_il-gen-gen_nodes.adb (N_Exception_Declaration):
Change Expression from Sm to Sy, to match other Expression fields.
* gen_il-gen.adb (Setter_Needs_Parent):
Expression no longer needs to be a special case.
(Check_For_Syntactic_Field_Mismatch):
Do not exempt Expression from the Sy/Sm mixing rule.
This was the last such case, so remove all the exemption code.
* gen_il-gen.ads: Update comments to match new code.
* sinfo.ads (N_Exception_Declaration):
Document the meaning of the Expression field, because it
doesn't follow from the RM syntax of exception_declaration.
* exp_ch11.adb: Minor comment fixes.
Eric Botcazou [Wed, 15 Oct 2025 14:23:26 +0000 (16:23 +0200)]
ada: Reject nonconfirming size clauses on objects of floating-point types
The RM 13.1(7/5) subclause contains the following sentences: "If the size
of an object is greater than that of its subtype, the additional bits are
padding bits. For an elementary object, these padding bits are normally
read and updated along with the others."
GNAT implements it only for objects of integer and fixed-point types.
For objects of floating-point types, the padding bits are ignored (and
therefore not initialized) with a warning:
warning: 32 bits of "F" unused [enabled by default]
Implementing it for objects of floating-point types does not seem worth the
hassle, so rejecting nonconfirming size clauses is probably the cleanest
approach (clauses giving the object a size lower than that of its subtype
are already rejected for objects of floating-point types).
gcc/ada/ChangeLog:
* sem_ch13.adb (Analyze_Attribute_Definition_Clause)
<Attribute_Size>: Tweak wording of existing error message for the
size of all elementary objects. Move error handling for aliased
objects into the block for objects and give a similar error for
(nonaliased) floating-point objects.
Piotr Trojanek [Tue, 14 Oct 2025 14:15:46 +0000 (16:15 +0200)]
ada: Remove workaround for a freezing issue with address of a slice
Rewriting of an address of a slice, e.g. "X (Low .. High)'Address" into an
address of an indexed component, e.g. "X (Low)'Address", was only done as a
workaround for some freezing issue. Apparently this freezing issue is now
solved and the rewriting is causing problems for GNATprove. (This rewriting,
if needed, should be rather done in expansion and not resolution.)
gcc/ada/ChangeLog:
* sem_attr.adb (Resolve_Attribute): Remove rewriting of a slice
address expression.
Viljar Indus [Tue, 14 Oct 2025 09:02:13 +0000 (12:02 +0300)]
ada: Fix Put_Image for Multiway_Trees
Put_Image should start printing the tree from the Root instead
of the First_Child.
gcc/ada/ChangeLog:
* libgnat/a-cbmutr.adb (Put_Image): Fix the condition and starting point
for printing the tree.
* libgnat/a-cimutr.adb (Put_Image): Likewise.
* libgnat/a-comutr.adb (Put_Image): Likewise.
Viljar Indus [Fri, 10 Oct 2025 09:47:07 +0000 (12:47 +0300)]
ada: Avoid Ignored ghost code behavior in Codepeer_Mode
When the frontend is called by it should treat all ghost
code as checked. Avoid removing expansion in ignored ghost code regions
when Codepeer_Mode is active.
gcc/ada/ChangeLog:
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Avoid disabling
the expander for ignored ghost regions if Codepeer_Mode is active.
* sem_ch7.adb (Analyze_Package_Body_Helper): Likewise.
* freeze.adb (Freeze_Entity): Avoid triggering special freezing
action for entities within ignored ghost regions in Codepeer_Mode.
This patch introduces the 'Constructor attribute and implements its direct
attribute definition syntax within subprogram specification. This new shorthand
avoids having to come up with an arbitrary subprogram name and to type out the
constructor aspect. Before, constructors where defined through the aspect
Constructor, which has been removed.
Furthermore, this patch prepares for the expansion of direct attribute
definitions to other attributes.
gcc/ada/ChangeLog:
* errout.adb (Set_Msg_Node): Support N_Attribute_Reference and
nodes that denotes direct attribute definitions.
* exp_dbug.ads: Description for the encoding of direct attribute
definitions as tick are hard to deal in entity names.
* erroutc.adb
(Set_Msg_Insertion_Name): Replace underscore between prefix and
attribute name in direct attribute definitions; at this point we
lost the semantic information of node type and we resort to match
the string name as described in exp_dbug.adb.
* exp_aggr.adb (Convert_To_Positional): Use Needs_Construction and
Has_Default_Constructor.
* exp_ch3.adb (Build_Record_Init_Proc)
(Expand_N_Object_Declaration): Likewise.
* exp_attr.adb (Expand_N_Attribute_Reference): Likewise.
* exp_ch4.adb (Expand_N_Allocator): Likewise.
* exp_ch6.adb
(Prepend_Constructor_Procedure_Prologue): Use
Is_Constructor_Procedure.
(Make_Parent_Constructor_Call): Use
Direct_Attribute_Definition_Name.
* gen_il-fields.ads: Remove Constructor_List and Constructor_Name.
* gen_il-gen-gen_entities.adb: Likewise.
* einfo.ads (Needs_Construction): Add description.
(Has_Delayed_Aspects): Adjust indentation.
* par-ch13.adb (P_Attribute_Designators): Parse attribute
designators.
(P_Representation_Clause): Use P_Attribute_Designators.
* par-ch6.adb (P_Subprogram): Support attribute designators in
subprogram name.
(Rewrites_Entity_If_Direct_Attribute_Def): Fix the specification
node in case of direct attribute definitions.
* par-endh.adb (Check_End, Same_Label): Likewise.
* par.adb (P_Attribute_Designators): Specification.
* sem_attr.adb (Analyze_Attribute): Error when using 'Constructor
outside procedure specification.
(Analyze_Attribute): Add error handling code.
* sem_ch3.adb (Analyze_Aspect_Specifications): Likewise.
* sem_ch6.adb (Analyze_Direct_Attribute_Definition): Handle direct
attribute definitions. Add error handling code for the
'Construction attribute and set constructor flags when necessary.
(Analyze_Subprogram_Specification): Use
Analyze_Direct_Attribute_Definition.
* sem_util.adb (Direct_Attribute_Definition_Name): Name of
entities created for direct attribute definitions. We emit an
error if multiple attributes.
(Is_Direct_Attribute_Subp_Spec): Helper to check whether a
subprogram specification is a direct attribute definition.
(Is_Constructor_Procedure): Helper to check whether a subprogram
is a constructor procedure.
(Has_Default_Constructor): Check whether the default constructor
exists.
(Default_Constructor): Not used anymore.
(Parameter_Count): Likewise.
(Process_End_Label): Get_Attribute_Reference_Name_String encodes
also direct attribute definition end labels.
* sem_util.ads: Likewise.
* snames.ads-tmpl: Support for 'Constructor attribute.
* snames.adb-tmpl (Is_Direct_Attribute_Definition_Name): Helper to
check attributes allowed in direct attribute definitions.
* aspects.ads: Remove constructor aspect.
* sem_ch13.adb: Likewise.
Eric Botcazou [Thu, 9 Oct 2025 07:41:54 +0000 (09:41 +0200)]
ada: Tidy up code dealing with visibility in instances of formal packages
The actuals for parameters of formal packages are visible in the instance
if the formal packages either are declared with a box or contain defaulted
parameters. This is essentially implemented in Check_Generic_Actuals and
Restore_Private_Views, with the help of the Is_Visible_Formal flag.
This documents more prominently the processing and streamlines it, as well
as removes a couple of questionable calls to Set_Is_Hidden, thus plugging
a couple more loopholes in the implementation.
gcc/ada/ChangeLog:
PR ada/122161
* sem_ch12.adb: Improve the description of Check_Generic_Actuals,
Restore_Private_Views and Switch_View, and alphabetize them.
(Check_Generic_Actuals): Make actuals visible only if needed.
(Install_Formal_Packages): Pass exact Is_Formal_Box parameter and
remove call to Set_Is_Hidden.
(Instantiate_Formal_Package): Use Next_Non_Pragma consistently in
the loop computing the visibility of actuals.
(Analyze_Package_Instantiation): Use named second parameter in the
call to Restore_Private_Views.
(Analyze_Subprogram_Instantiation): Likewise.
(Instantiate_Package_Body): Likewise and for Check_Generic_Actuals.
(Instantiate_Subprogram_Body): Likewise.
(Restore_Env): Replace call to Restore_Private_Views.
(Restore_Private_Views): Remove default value for second parameter
and test of presence for first parameter. Consistently clear the
Is_Potentially_Use_Visible flag when setting the Is_Hidden flag.
Remove call to Set_Is_Hidden for a formal package of the enclosing
generic unit, if any.
Bob Duff [Fri, 10 Oct 2025 16:40:42 +0000 (12:40 -0400)]
ada: Get rid of Sy/Sm mixing (Actions)
We should not mix "syntactic" and "semantic" for the same field
in different node kinds.
The Actions field is both syntactic and semantic. This patch
makes it always syntactic.
No change in overall compiler behavior.
gcc/ada/ChangeLog:
* gen_il-gen.adb (N_Short_Circuit):
Make Actions syntactic.
(N_Case_Expression_Alternative): Likewise.
* gen_il-gen-gen_nodes.adb (Create_Type):
No longer exempt Actions from the syntactic/semantic ordering rule.
(Check_For_Syntactic_Field_Mismatch):
No longer exempt Actions from the syntactic/semantic mixing rule.
* sinfo.ads (N_Compound_Statement):
Add comment.
A recent patch added a procedure in the spec of System.Stream_Attributes
but failed to add the corresponding body in the CHERI-specific body of
this package. This patch fixes this.
gcc/ada/ChangeLog:
* libgnat/s-stratt__cheri.adb (W_80IEEE): New procedure.
Bob Duff [Wed, 8 Oct 2025 16:29:35 +0000 (12:29 -0400)]
ada: Get rid of unused node/entity fields (Set_ only)
The following fields are Set_ but not used in GNAT. We get rid of them
or document them as follows:
- Has_Pragma_Controlled
Remove.
- Corresponding_Entry_Body
Document that it is used by codepeer.
- Is_Activation_Record
Document that it is used by llvm.
- Is_Discriminant_Check_Function
Document that it is used by codepeer.
- Original_Access_Type
No change (already documented that it is used by codepeer).
Alexandre Oliva [Wed, 1 Oct 2025 14:59:18 +0000 (11:59 -0300)]
ada: Add ctor call after address clause
An object initialized by a C++-imported constructor call has the
constructor function call transformed into a procedure call, and the
call is inserted after the object declaration.
If the object has say an address clause, that transformation separates
the declaration from the address clause, causing the translation of
the call to fail.
Keep such clauses next to the declaration by inserting the constructor
procedure call after them.
gcc/ada/ChangeLog:
* exp_ch3.adb (Expand_N_Object_Declaration): Insert ctor call
after representation clauses.
Bob Duff [Tue, 7 Oct 2025 14:45:20 +0000 (10:45 -0400)]
ada: Remove exception handler in Check_Vanishing_Fields
Check_Vanishing_Fields calls Same_Node_To_Fetch_From, which was calling
Node_To_Fetch_From, which will raise an exception (as it should) on
..._Type_Only fields if called early (when the Base_Type,
Implementation_Base_Type, or Root_Type has not yet been set).
Other exceptions can also be raised when Check_Vanishing_Fields
is called early.
An exception handler was used to ignore any such exceptions. That was
correct, but it is annoying in gdb with "catch exception". (Note that
efficiency doesn't matter much, because Check_Vanishing_Fields is not
done in production mode.)
We now call Node_To_Fetch_From_If_Set, remove other potential raises,
and remove the now-unnecessary exception handler.
Note that other calls to Node_To_Fetch_From will still raise an
exception (as they should) for such "early" calls.
gcc/ada/ChangeLog:
* atree.adb (Same_Node_To_Fetch_From):
Use Node_To_Fetch_From_If_Set, and remove handler.
* einfo-utils.adb (Root_Type_If_Set):
Return Empty if Base_Type_If_Set returns Empty.
Return Empty if we find Etype (T) = Empty.
(Underlying_Type): Use "Has_Non_Limited_View..." instead
of "Present (Non_Limited_View...)", because the latter raises
an exception when given the wrong Ekind.
On some platforms, Long_Long_Float'Size (and Long_Long_Float'Stream_Size)
is 128 but only 80 bits are effectively used. This pack makes it so
'Write in this case write zeros for the padding bits instead of
unspecified values.
gcc/ada/ChangeLog:
* gen_il-fields.ads (Is_IEEE_Extended_Precision): New flag.
* gen_il-gen-gen_entities.adb: Likewise.
* gen_il-internals.adb (Image): Likewise.
* treepr.adb (Image): Likewise.
* einfo.ads: Document new flag.
* cstand.adb (Copy_Float_Type, Register_Float_Type): Use new flag.
* libgnat/s-stratt.ads (W_80IEEE): New procedure.
* libgnat/s-stratt.adb (W_80IEEE): Likewise.
* exp_strm.adb (Get_Primitives): Select new procedure when
appropriate.
* rtsfind.ads: Register new runtime procedure.
* sem_ch3.adb (Build_Derived_Numeric_Type,
Analyze_Subtype_Declaration): Propagate new flag.
Eric Botcazou [Tue, 7 Oct 2025 20:57:02 +0000 (22:57 +0200)]
ada: Fix incorrect static string concatenation with null left string
It comes from the implementation of an optimization for static concatenation
in Resolve_String_Literal, which causes the original subtype of the literal
to be lost. Now this subtype must be preserved in the case where the left
operand of the concatenation may be null, per the 4.5.3(5) subclause.
gcc/ada/ChangeLog:
PR ada/122160
* sem_res.adb (Resolve_Op_Concat_Rest): Do not build the subtype of
the second operand again if it has already been built.
(Resolve_String_Literal): Do not defer the creation of the subtype
for the right operand of a concatenation whose left operand may be
the null string.
Gary Dismukes [Mon, 6 Oct 2025 19:23:34 +0000 (19:23 +0000)]
ada: Remove dependence on secondary stack for type with controlled component
There are cases where GNAT introduces a dependence on the secondary stack
in a build-in-place function with a result subtype that is definite, when
this dependence could be avoided. In particular this is done for record
types that requires finalization due to having a controlled component.
At one time such functions required the secondary stack in order to
properly handle cases where the function might raise an exception
(to avoid improper finalization in the caller), but that is no longer
necessary. We remove the dependence of these functions on the SS,
along with the BIPalloc formal and the generation of the big if_statement
that uses that formal.
An additional small change is to revise the condition for determining when
to generate SS mark/release within functions.
gcc/ada/ChangeLog:
* exp_ch6.ads (Make_Build_In_Place_Call_In_Allocator): Simplify comment.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Remove obsolete
comment about not being able to allocate fixed-size controlled results
on the caller side, and replace another obsolete comment with a simpler
comment. Call Build_Allocate_Deallocate_Proc when the function doesn't
need a BIPalloc formal to ensure that function results with controlled
parts allocated on the caller side will be chained for finalization.
(Make_Build_In_Place_Call_In_Object_Declaration): Call Needs_BIP_Collection
on the function's Entity_Id rather than the function call.
(Needs_BIP_Collection): If a BIP function doesn't need a BIPalloc formal
then it doesn't need a BIP collection either; return False in that case.
(Needs_BIP_Alloc_Form): Remove test of Needs_BIP_Collection.
* exp_ch7.adb (Expand_Cleanup_Actions): Move test of Uses_Sec_Stack
to be the first conjunct in setting of Needs_Sec_Stack_Mark, and put
the other tests in a disjunction subsidiary to that. Improve preceding
comment.
Bob Duff [Tue, 7 Oct 2025 14:35:03 +0000 (10:35 -0400)]
ada: Get rid of Sy/Sm mixing (Default_Expression)
We should not mix "syntactic" and "semantic" for the same field
in different node kinds.
Change the name of Default_Expression (a syntactic field) on
N_Formal_Object_Declaration to be Expression. This avoids
the conflict with the name-named semantic field of
N_Parameter_Specification.
It is also more uniform with other syntactic categories that
use default_expression in the syntax rules. See, for example,
COMPONENT_DECLARATION in sinfo.ads, which is presumably intended
to be uniform with OBJECT_DECLARATION.
Fix the comment on N_Formal_Object_Declaration to refer
to the new field name Expression.
gcc/ada/ChangeLog:
* gen_il-gen-gen_nodes.adb: Rename Default_Expression to be
Expression.
* gen_il-gen.adb (Check_For_Syntactic_Field_Mismatch): Do not
exempt Default_Expression from the rule.
* par-ch12.adb (P_Formal_Object_Declarations): Use renamed setter.
* sem_ch12.adb (Default): Use renamed getter.
(Analyze_Formal_Object_Declaration): Likewise.
* sprint.adb (Sprint_Node_Actual): Use renamed getter.
* sinfo.ads: Fix comments.
Bob Duff [Mon, 6 Oct 2025 10:56:34 +0000 (06:56 -0400)]
ada: Incorrect warning redundant parens on in
This patch fixes a bug where GNAT gives a warning
about redundant parentheses on expressions like "(X in S) = B".
In fact, the parentheses are required in this case.
The bug is caused by constant-folding the expression into
an expression that does not require parentheses, but in
a way that retains the parentheses. The fix is to look
at Original_Node.
gcc/ada/ChangeLog:
* style.adb (Check_Xtra_Parens_Precedence):
Give warning based on Original_Node.
Eric Botcazou [Mon, 6 Oct 2025 19:36:56 +0000 (21:36 +0200)]
ada: Fix visibility issue in nested instance with use clause for formal package
The compiler gives a spurious visibility error for a formal object parameter
of a formal package with a use clause, present in a parent instance, when an
instance of a child generic unit is compiled, while this does not happen in
the same circumstances for a formal type parameter.
The discrepancy comes from the Check_Generic_Actuals procedure, which clears
the Is_Hidden flag on all the actuals of a generic instance, but only sets
the Is_Potentially_Use_Visible flag on the actuals for formal types.
The change also contains a fix for a pasto in Restore_Private_Views, which
is responsible for undoing the changes made by Check_Generic_Actuals.
gcc/ada/ChangeLog:
PR ada/122161
* sem_ch12.adb (Check_Generic_Actuals): Consistently set the
Is_Potentially_Use_Visible flag on actuals whenever the Is_Hidden
flag is cleared.
(Restore_Private_Views): Clear the Is_Potentially_Use_Visible flag
explicitly on the entities of an actual package.
Bob Duff [Mon, 6 Oct 2025 18:20:00 +0000 (14:20 -0400)]
ada: Get rid of Sy/Sm mixing (Chars)
We should not mix "syntactic" and "semantic" for the same field
in different node kinds.
The Chars field is both syntactic and semantic. This patch
makes it always syntactic, and does some other Chars-related
cleanups.
An attempt was made to instead rename the semantic field
to be Op_Chars, but that complicates things, because there
is a fair amount of code that fetches the Chars field
without knowing the node kind. Notably, Errout does this.
No change in overall compiler behavior.
gcc/ada/ChangeLog:
* gen_il-gen-gen_nodes.adb (N_Op):
Make Chars syntactic, and move it down into subclasses
N_Binary_Op and N_Unary_Op.
* gen_il-gen.adb (Create_Type):
Do not exempt Chars from the ordering rule.
(Exception_To_Inheritance_Rule): Exempt Chars from the
inheritance rule.
(Check_For_Syntactic_Field_Mismatch):
Do not exempt Chars from the syntactic mismatch rule.
This is the main point of this change.
(Put_Make_Bodies): The Nmake functions for types in N_Op
will now take a Chars parameter, which should always
default to No_Name. This will be overwritten by the
special-case Set_Chars call. Assert that it is in
fact defaulted.
* exp_ch4.adb (Expand_Array_Comparison):
Use the Nkind instead of the Chars, which seems cleaner.
Use a case instead of an elsif chain.
* sem_attr.adb (Proper_Op): Minor cleanup.
* sem_ch8.adb: Minor reformatting.
* sem_res.adb (Operator_Kind): Tighten up the result subtype.
ada: Catch Constraint_Errors on non-scalar streaming attributes
The specs for the streaming methods should use the first
subtype of the prefix attribute for the Item argument if the
prefix has a non-scalar type instead of the underlying type.
This will catch size errors for is smaller size are used for
the Item argument that has a constrained derived
type.
Additionally remove additional casts applied for the Input
attribute that convert the result to the prefix type.
This cast is only necessary for converting the result if
the Input attribute is used on a classwide type.
gcc/ada/ChangeLog:
* exp_attr.adb (Expand_N_Attribute_Reference): Use the
First_Subtype when creating the procedure for stream
attributes.
(Get_Array_Stream_Item_Type): New method for calculating
the type for the Item argument for streaming methods.
Loeka Rogge [Wed, 29 Oct 2025 13:57:55 +0000 (06:57 -0700)]
arc: Fix wrong vector ordering on big-endian architecture
V2HI vectors, explicitly or auto-generated, could be stored in memory wrongly
due to endianness. For example in the following c code stores to the struct
are SLP vectorized, causing them to be stored in the wrong order:
struct S {short a; short b;};
s.a = 520;
s.b = -1;
and is then loaded into the struct. For big-endian this is wrong because
the most significant bytes are written first in memory, storing -1 instead of
520 in s.a .
This patch swaps the 2 values in this step if the target is big-endian.
The added test creates a vector of 2 shorts and verifies the order when
it is passed in a register or in memory.
Regtested for arc and big-endian arc.
gcc/ChangeLog:
* config/arc/simdext.md(movv2hi_insn): Change order for movv2hi
for big-endian.
Alfie Richards [Tue, 14 Oct 2025 15:08:18 +0000 (15:08 +0000)]
docs: fmv: Update Function multi-versioning documentation [PR c/122202]
This updates the FMV documentation to the current state of things, including
the addition of "target_version" based FMV.
Left as much of the x86 target based FMV documentation unchanged as
the behaviour change there should be unchanged. Though highlights some of
the differences between it and target_version FMV to try avoid confusion there.
PR c/122202
gcc/ChangeLog:
* doc/extend.texi (target function attribute): Update to describe FMV
behaviour.
(target_version function attribute): New section.
(target_clones attribute): Update to descrbe new behaviour with
target_version.
(Function Multiversioning): Update to discuss both target_version and
target based FMV.
Kito Cheng [Wed, 22 Oct 2025 09:06:03 +0000 (17:06 +0800)]
RISC-V: Fix the ABI of empty unions and zero length array in struct
The RISC-V ABI currently defines that empty unions and zero length array
in struct should be ignored, but the implementation in GCC is not
correct.
e.g. for the following code:
```
struct S2eu_2f {
union{} e1;
float f;
float g;
};
```
The RISC-V ABI defines that the layout of S2eu_2f should be equivalent
to:
```
struct S2eu_2f {
float f;
float g;
};
```
However, the current GCC implementation passes S2eu_2f in a0 (lp64d)
rather than fa0 and fa1 (lp64d).
Also for the following code:
```
struct S0ae_2f {
struct{} e1[0];
float f;
float g;
};
```
The RISC-V ABI defines that the layout of S0ae_2f should be equivalent
to:
```
struct S0ae_2f {
float f;
float g;
};
```
And again, the current GCC implementation passes S0ae_2f in a0 (lp64d)
rather than fa0 and fa1 (lp64d).
This patch fixes the issue by updating the relevant functions to correctly
handle empty unions, also we have implemented the ABI change warning to
notify user that the ABI of empty unions and zero length array in struct
has been changed/fixed.
Generally ABI should not be changed, but the psABI is defined there for
long time and clang/LLVM has already implemented it correctly, so we
decide to fix it in GCC as well to maintain compatibility, and another
reason to fix that in GCC is zero length array and empty union in struct
should be rarely used in practice, so the impact should be limited.
* config/riscv/riscv.cc (riscv_flatten_aggregate_field): Skip
empty unions and zero-length arrays when flattening aggregate
fields for ABI classification.
(riscv_pass_aggregate_in_fpr_pair_p): Refactor to use separate
field parsing and emit ABI change warning for affected types.
(riscv_pass_aggregate_in_fpr_and_gpr_p): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/abi/param2.C: Add -Wno-psabi option for RISC-V.
* g++.target/riscv/abi/empty-struct+union-1.cc: New test.
* g++.target/riscv/abi/empty-struct+union-2.cc: New test.
* g++.target/riscv/abi/empty-struct+union-3.cc: New test.
* g++.target/riscv/abi/empty-struct+union-4.cc: New test.
* g++.target/riscv/abi/empty-struct-1.cc: New test.
* g++.target/riscv/abi/empty-struct-2.cc: New test.
* g++.target/riscv/abi/empty-struct-3.cc: New test.
* g++.target/riscv/abi/empty-struct-4.cc: New test.
* g++.target/riscv/abi/empty-struct-5.cc: New test.
* g++.target/riscv/abi/empty-struct-6.cc: New test.
* g++.target/riscv/abi/empty-struct-7.cc: New test.
* g++.target/riscv/abi/empty-struct-8.cc: New test.
* g++.target/riscv/abi/empty-struct-9.cc: New test.
* g++.target/riscv/abi/empty-struct-10.cc: New test.
* g++.target/riscv/abi/empty-struct-11.cc: New test.
* g++.target/riscv/abi/empty-struct-12.cc: New test.
* g++.target/riscv/abi/empty-union-1.cc: New test.
* g++.target/riscv/abi/empty-union-2.cc: New test.
* g++.target/riscv/abi/empty-union-3.cc: New test.
* g++.target/riscv/abi/empty-union-4.cc: New test.
* g++.target/riscv/riscv.exp: Add abi subdirectory.
* gcc.dg/compat/pr83487-1_x.c: Add -Wno-psabi option for RISC-V.
* gcc.dg/compat/pr83487-1_y.c: Likewise.
* gcc.dg/compat/pr83487-2_x.c: Likewise.
* gcc.dg/compat/pr83487-2_y.c: Likewise.
* gcc.dg/torture/pr28814.c: Likewise.
* gcc.target/riscv/abi/empty-struct+union-1.c: New test.
* gcc.target/riscv/abi/empty-struct+union-2.c: New test.
* gcc.target/riscv/abi/empty-struct+union-3.c: New test.
* gcc.target/riscv/abi/empty-struct+union-4.c: New test.
* gcc.target/riscv/abi/empty-struct-1.c: New test.
* gcc.target/riscv/abi/empty-struct-2.c: New test.
* gcc.target/riscv/abi/empty-struct-3.c: New test.
* gcc.target/riscv/abi/empty-struct-4.c: New test.
* gcc.target/riscv/abi/empty-struct-5.c: New test.
* gcc.target/riscv/abi/empty-struct-6.c: New test.
* gcc.target/riscv/abi/empty-struct-7.c: New test.
* gcc.target/riscv/abi/empty-struct-8.c: New test.
* gcc.target/riscv/abi/empty-struct-9.c: New test.
* gcc.target/riscv/abi/empty-struct-10.c: New test.
* gcc.target/riscv/abi/empty-struct-11.c: New test.
* gcc.target/riscv/abi/empty-struct-12.c: New test.
* gcc.target/riscv/abi/empty-union-1.c: New test.
* gcc.target/riscv/abi/empty-union-2.c: New test.
* gcc.target/riscv/abi/empty-union-3.c: New test.
* gcc.target/riscv/abi/empty-union-4.c: New test.
* gcc.target/riscv/riscv.exp: Add abi subdirectory.
Alfie Richards [Mon, 20 Oct 2025 12:01:13 +0000 (12:01 +0000)]
aarch64: Add missing fmv features.
Add all the missing FMV features from the ACLE.
gcc/ChangeLog:
* config/aarch64/aarch64-option-extensions.def (dit): New fmv feature.
(dpb): New fmv feature.
(dpb2): New fmv feature.
(memtag): Change to also define an FMV feature.
(ssbs): Change to also define an FMV feature.
(bti): New fmv feature.
* config/aarch64/aarch64.cc (FEAT_SSBS): Add macro.
(FEAT_MEMTAG): Ditto.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/fmv_priority.in: Update for new features.
* gcc.target/aarch64/fmv_priority1.c: Ditto.
* gcc.target/aarch64/fmv_priority2.c: Ditto.
xtensa: Revise implementation of hardware FP rounding instructions
Since each element in an MD iterator can have its own condition that is
true by default, it is simpler to specify the precondition for the ROUND.S
machine instruction such way.
There are no functional changes with this patch.
gcc/ChangeLog:
* config/xtensa/xtensa.md (int_iterator ANY_ROUND):
Specify "flag_unsafe_math_optimizations" in the condition of the
UNSPEC_ROUND element.
(int_attr c_round): Remove.
(l<m_round>sfsi2, *l<m_round>sfsi2_2x, *l<m_round>sfsi2_scaled):
Remove " && <c_round>" from the conditions.
Make scalar int mode and scalar fp mode tieable, so movgr2fr and
movfr2gr can be used instead of memory access.
For example, in pattern '*movsi_internal', when matching gr->fr,
due to the constraint '*' in alt4, it will match alt5, resulting
in memory access instead of movgr2fr.
gcc/ChangeLog:
* config/loongarch/loongarch.cc (loongarch_modes_tieable_p):
Make MODE_FLOAT and MODE_INT tieable.
* config/loongarch/loongarch.md: Adjust constraints.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/mode-tieable-opt.c: New test.
Guo Jie [Sun, 2 Nov 2025 03:31:32 +0000 (11:31 +0800)]
LoongArch: Eliminate unnecessary dependencies introduced by xvpermi.q
1. When the selector is 0x0, 0x1, 0x10, or 0x11, the result of
xvpermi.q does not depend on the output operand, thus eliminating
the dependency chain of the output operand as input, which can
reduce the number of instructions.
2. When the selector is 0x22, 0x23, 0x32, or 0x33, the result of
xvpermi.q does not depend on the second input operand, thus
eliminating the dependency chain of the second input operand,
which can also reduce the number of instructions.
gcc/ChangeLog:
* config/loongarch/lasx.md (lasx_xvpermi_q_<LASX:mode>):
Add new splitter for optimization.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/vec_pack_unpack_256.c: Adjust to changed
lasx_xvpermi_q_<LASX:mode> template.
* gcc.target/loongarch/vector/lasx/lasx-builtin.c: Ditto.
* gcc.target/loongarch/lasx-xvpermi_q-opt.c: New test.
Guo Jie [Sun, 2 Nov 2025 03:30:57 +0000 (11:30 +0800)]
LoongArch: Optimize AND large immediate operation
For large immediate values in variable AND operations:
if their bit representation has two consecutive 0 sequences,
one starting from the MSB can use the bstrpick.d instruction,
and the bstrins.d instruction for the other.
For example, in the case 'var & 0x3fffffffefffffff':
Before:
lu12i.w $r12,-65537
ori $r12,$r12,4095
lu52i.d $r12,$r12,0x3ff
and $r4,$r4,$r12
* config/loongarch/loongarch-protos.h
(loongarch_use_bstrins_bstrpick_for_and): New proto.
* config/loongarch/loongarch.cc
(loongarch_use_bstrins_bstrpick_for_and): Decide whether
to optimize.
(loongarch_rtx_costs): Adjust the cost of AND operation.
* config/loongarch/loongarch.md
(bstrins_bstrpick_for_and_imm<mode>): New insn_and_split.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/and-large-immediate-opt.c: New test.
Tamar Christina [Mon, 3 Nov 2025 08:07:13 +0000 (08:07 +0000)]
vect: Fix null dereference in boolean reductions [PR122475]
neutral_op can be null, so guard against that.
gcc/ChangeLog:
PR tree-optimization/122475
* tree-vect-loop.cc (vectorizable_reduction): Check for neutral_op.
gcc/testsuite/ChangeLog:
PR tree-optimization/122475
* gcc.dg/vect/pr122475.c: New test.
* gcc.target/aarch64/sve/vect-reduc-bool-19.c: New test.
* gcc.target/aarch64/sve/vect-reduc-bool-20.c: New test.
H.J. Lu [Mon, 20 Oct 2025 08:14:34 +0000 (16:14 +0800)]
x86-64: Inline memmove with overlapping unaligned loads and stores
Inline memmove in 64-bit since there are much less registers available
in 32-bit:
1. Load all sources into registers and store them together to avoid
possible address overlap between source and destination.
2. For known size, first try to fully unroll with 8 registers.
3. For size <= 2 * MOVE_MAX, load all sources into 2 registers first
and then store them together.
4. For size > 2 * MOVE_MAX and size <= 4 * MOVE_MAX, load all sources
into 4 registers first and then store them together.
5. For size > 4 * MOVE_MAX and size <= 8 * MOVE_MAX, load all sources
into 8 registers first and then store them together.
6. For size > 8 * MOVE_MAX,
a. If address of destination > address of source, copy backward
with a 4 * MOVE_MAX loop with unaligned loads and stores. Load
the first 4 * MOVE_MAX into 4 registers before the loop and
store them after the loop to support overlapping addresses.
b. Otherwise, copy forward with a 4 * MOVE_MAX loop with unaligned
loads and stores. Load the last 4 * MOVE_MAX into 4 registers
before the loop and store them after the loop to support
overlapping addresses.
Verified and benchmarked memmove implementations inlined with GPR, SSE2,
AVX2 and AVX512 using glibc memmove tests. It is available at
This is Shreya's work, my contribution was primarily covering the testing.
Bootstrapped and regression tested on x86 and riscv64. It's also been tested
on all the embedded targets in my tester without regression.
While this improves code generation to optimal on riscv-64, I'm electing to
keep the BZ open because we probably should have the same kind of
simplification in match.pd. Shreya is just starting to write some match.pd
patterns and I expect we'll return to write a match.pd pattern for this issue
relatively soon.
Obviously waiting for pre-commit CI to chime in before moving forward.
Jeff
--
In PR52345, we have this testcase:
int f(int a, int b)
{
int c = a != 0;
int d = (c!=0|b!=0);
return d;
}
Basically, "d" will either be 0 or 1. Depending on "a", "c" will also
either be 0 or 1. So if "a" is 0 and "b" is 0, then "d" will also be 0. Otherwise, it will be 1.
When the testcase is compiled, we get this generated assembly code:
snez a0,a0
or a0,a1,a0
snez a0,a0
RISC-V has a missed optimization here, as this can simply be done by first
computing a|b and checking if the result is equal to 0. If "a" is 0 and "b" is
0, we will get 0. Otherwise, we will get 1. Doing this removes the unnecessary
first snez instruction.
When we looked at the combine pass, it was trying:
Failed to match this instruction:
(set (reg/i:DI 10 a0)
(ne:DI (ior:DI (ne:DI (reg:DI 151 [ a ])
(const_int 0 [0]))
(reg:DI 152 [ b ]))
(const_int 0 [0])))
In simplify_relational_operation_1 of simplify-rtx.cc, we added a condition.
For cases where the outer code is a "not equal to" (NE) and the operands match
the pattern above, we simply emit an NE of an IOR of the two registers, giving
us:
or a0,a0,a1
snez a0,a0
We then generalized this to include the case where the outer code is an "equal
to" (EQ). With the logic working in the same way, we simply adjust the
recognition code to check that the outer code is either an NE or EQ and
generalize the NE we emit to match the outer code.
chenxiaolong [Wed, 29 Oct 2025 10:49:34 +0000 (18:49 +0800)]
LoongArch: Add builtin interfaces for 128 and 256 vector conversions.
gcc/ChangeLog:
* config/loongarch/lasx.md (vec_cast<mode>): New template
implemention.
(vec_insert_lo_<mode>): Dito.
(vec_insert_hi_<mode>): Dito.
* config/loongarch/lasxintrin.h (defined): Test for adding
the builtin function.
(__lasx_cast_128_s): Dito.
(__lasx_cast_128_d): Dito.
(__lasx_cast_128): Dito.
(__lasx_concat_128_s): Dito.
(__lasx_concat_128_d): Dito.
(__lasx_concat_128): Dito.
(__lasx_extract_128_lo_s): Dito.
(__lasx_extract_128_hi_s): Dito.
(__lasx_extract_128_lo_d): Dito.
(__lasx_extract_128_hi_d): Dito.
(__lasx_extract_128_lo): Dito.
(__lasx_extract_128_hi): Dito.
(__lasx_insert_128_lo_s): Dito.
(__lasx_insert_128_hi_s): Dito.
(__lasx_insert_128_lo_d): Dito.
(__lasx_insert_128_hi_d): Dito.
(__lasx_insert_128_lo): Dito.
(__lasx_insert_128_hi): Dito.
* config/loongarch/loongarch-builtins.cc
(CODE_FOR_lasx_extract_128_lo_s): Add builtins and register
icode.
(CODE_FOR_lasx_extract_128_hi_s): Dito.
(CODE_FOR_lasx_extract_128_lo_d): Dito.
(CODE_FOR_lasx_extract_128_hi_d): Dito.
(CODE_FOR_lasx_extract_128_lo): Dito.
(CODE_FOR_lasx_extract_128_hi): Dito.
(CODE_FOR_lasx_insert_128_lo_s): Dito.
(CODE_FOR_lasx_insert_128_hi_s): Dito.
(CODE_FOR_lasx_insert_128_lo_d): Dito.
(CODE_FOR_lasx_insert_128_hi_d): Dito.
(CODE_FOR_lasx_insert_128_lo): Dito.
(CODE_FOR_lasx_insert_128_hi): Dito.
(CODE_FOR_lasx_concat_128_s): Dito.
(CODE_FOR_lasx_concat_128_d): Dito.
(CODE_FOR_lasx_concat_128): Dito.
(CODE_FOR_lasx_cast_128_s): Dito.
(CODE_FOR_lasx_cast_128_d): Dito.
(CODE_FOR_lasx_cast_128): Dito.
(loongarch_expand_builtin_direct): For the newly added
insertion or extraction, construct the parallel parameter
corresponding to the operand.
* config/loongarch/loongarch-c.cc
(loongarch_update_cpp_builtins): Define
__loongarch_asx_sx_conv.
* config/loongarch/loongarch-ftypes.def: Declare the type
of the builtin function.
* doc/extend.texi: Add document description.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/vector/lasx/vect-concat-128-256-result.c: New test.
* gcc.target/loongarch/vector/lasx/vect-concat-128-256.c: New test.
* gcc.target/loongarch/vector/lasx/vect-extract-256-128-result.c: New test.
* gcc.target/loongarch/vector/lasx/vect-extract-256-128.c: New test.
* gcc.target/loongarch/vector/lasx/vect-insert-128-256-result.c: New test.
* gcc.target/loongarch/vector/lasx/vect-insert-128-256.c: New test.
Lulu Cheng [Sun, 25 May 2025 03:15:07 +0000 (11:15 +0800)]
LoongArch: Optimize normal immediate data loading.
Ensure that only one register is used when loading immediate values.
The original immediate value load is handled through virtual
registers, resulting in the following load operation
(0x1234567890abcdef):
lu12i.w $r4,-456004 # 0xfffffffffff90abc
or $r12,$r0,$r0
ori $r4,$r4,3567
lu32i.d $r12,0x45678
lu32i.d $r4,0
or $r4,$r4,$r12
lu52i.d $r4,$r4,0x123
The optimized sequence is as follows:
lu12i.w $r4,-456004 # 0xfffffffffff90abc
ori $r4,$r4,3567
lu32i.d $r4,0x45678
lu52i.d $r4,$r4,0x123
gcc/ChangeLog:
* config/loongarch/loongarch.cc (loongarch_move_integer):
No new virtual register is allocated during immediate load.
Gaius Mulley [Sun, 2 Nov 2025 21:44:03 +0000 (21:44 +0000)]
PR modula2/122499: misspelt procedure in import list causes clutter
A misspelt ident in an import list causes a sequence of clutted errors.
This bug fix filters unknowns built during import lists. It also
checks for spelling mistakes against the modules exported identifiers.
gcc/m2/ChangeLog:
PR modula2/122499
* gm2-compiler/M2StackSpell.mod (PushName): Add comment.
(GetSpellHint): Rewrite.
(GetExportedSpellHint): New procedure function.
(GetScopeSpellHint): New procedure function.
* gm2-compiler/P1Build.bnf (IdentScope): Rewrite.
(PossiblyExportIdent): Ditto.
* gm2-compiler/P1SymBuild.mod (BuildImportInnerModule): Add
parameter to AddNameToImportList.
* gm2-compiler/SymbolTable.def (GetUnknownOnImport): New
procedure function.
(GetUnknownDeclScope): Ditto.
(AddNameToScope): Add tok parameter.
(AddNameToImportList): Ditto.
* gm2-compiler/SymbolTable.mod (SymUndefined): New field
declScope.
New field onImport.
(MakeObject): Add tok parameter.
(FillInUnknownFields): Initialize declScope.
Initialize onImport.
(GetUnknownOnImport): New procedure function.
(GetUnknownDeclScope): Ditto.
(AddNameToScope): Pass tok to MakeObject.
(AddNameToImportList): Add tok parameter.
Pass tok to MakeObject.
(GetDeclaredSym): Add parameters to FillInUnknownFields.
(RequestSym): Ditto.
(FetchUnknownFromModule): Ditto.
(FetchUnknownFromDefImp): Ditto.
(FetchUnknownFrom): Ditto.
gcc/testsuite/ChangeLog:
PR modula2/122499
* gm2.dg/spell/iso/fail/badimport2.mod: New test.
* gm2.dg/spell/iso/fail/badimport3.mod: New test.
* gm2.dg/spell/iso/fail/badimport4.mod: New test.
Jeff Law [Sun, 2 Nov 2025 19:48:06 +0000 (12:48 -0700)]
[RISC-V] Expose sign extension for 32 bit rotates by constant values on rv64
Trivial improvement for 32 bit rotates on rv64 that I noticed while looking at
a PR121778. We were failing to use the _extended variant when the rotation
count was a constant on rv64 after cobbling together a prototype match.pd
pattern.
I suspect the guard was added by Jivan to avoid having to muck around in the
thead bitmanip extensions. But that's a bit of speculation on my part.
I reviewed the thead extensions and they do the expected thing for the W form
rotate. So this patch adds a pattern to thead.md that exposes the sign
extension and removes the restriction on generating that form from bitmanip.md.
I can envision this will help something, somewhere, but it's generally going to
be very much on the margins. I didn't take the time to find/construct a
testcase showing the missed optimization. There is one test that triggers the
thead W form rotate (xtheadbb-srri.c), so that's got some coverage and passes
(and I verified it's using the version with the sign extension exposed, so
that's good). PR121778 will trigger the missed optimization if we add a
suitable match.pd.
Regression tested on riscv32-elf and riscv64-elf. Bootstraps on the BPI and
Pioneer are in flight, but won't be finished for a long time.
Obviously waiting on pre-commit CI before moving forward.
* config/riscv/bitmanip.md (rotrsi3): Use the sign extended form
for 32 bit rotates on TARGET_64BIT, even for constant counts.
* config/riscv/thead.md (th_srrisi3_extended): New pattern.
(th_srri<mode>3): Adjust formatting.
Eric Botcazou [Sun, 2 Nov 2025 18:36:16 +0000 (19:36 +0100)]
Ada: Fix crash on tagged private type with unknown discriminants
This is an old issue with the extension of a tagged private type declared
with unknown discriminants in the public part of a generic child unit,
although the generic context is not a key factor (i.e. this also happens
for a nongeneric child unit). The public part of a child unit does not
have visibility on the private part of its parent, so the extension also
has unknown discriminants.
gcc/ada/
PR ada/58881
* sem_ch3.adb (Build_Derived_Private_Type): Build the underlying
full view when the derivation occurs in the public part of the
scope of the parent.
(Build_Derived_Record_Type): Propagate Has_Unknown_Discriminants
in the same circumstances.
(Constrain_Discriminated_Type): Give a specific error message for
any type with the Has_Unknown_Discriminants flag.
gcc/testsuite/
* gnat.dg/specs/unknown_discr1.ads: New test.
* gnat.dg/specs/unknown_discr1_pkg.ads: New helper.
* gnat.dg/specs/unknown_discr1_pkg-child.ads: Likewise.
* gnat.dg/specs/unknown_discr1_pkg-g.ads: Likewise.
* gnat.dg/specs/unknown_discr1_pkg-inst.ads: Likewise.
AVR: target/122527 -- Don't use __load_N to load from __flash1.
This patch fixes a case where a 3 byte or 4 byte load from __flash1
uses __load_3/4 to read the value, which is wrong.
This only occured when the device has ELPM but not ELPMx (avr31).
PR target/122527
gcc/
* config/avr/avr.cc (avr_load_libgcc_p): Return false if
the address-space is not ADDR_SPACE_FLASH.
(avr_out_lpm_no_lpmx [addr=REG]): Handle sizes of 3 and 4 bytes.
Nathaniel Shead [Sun, 26 Oct 2025 11:27:33 +0000 (22:27 +1100)]
c++/modules: Track all static class variables [PR122421]
The linker error in the PR is caused because when a static is defined
out of the class body, it doesn't yet have a definition and so
read_var_def (which would otherwise have noted it) never gets called.
This instead moves the responsibility for noting class-scope variables
to read_class_def.
PR c++/122421
gcc/cp/ChangeLog:
* module.cc (trees_in::read_var_def): Don't handle class-scope
variables anymore.
(trees_in::read_class_def): Handle them here instead.
gcc/testsuite/ChangeLog:
* g++.dg/modules/inst-6_a.C: New test.
* g++.dg/modules/inst-6_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
AVR: PR122505 - Fix bloated mulpsi3 in the wake of hacking around PR118012.
Since the PR118012 work-around patch, there is an SImode insn also for
the non-MUL case, but there is no mulpsi3. This makes the middle-end
use the mulsi3 insn for 24-bit multipications like in:
__uint24 mul24 (__uint24 a, __uint24 b)
{
return a * b;
}
The patch just allows the mulpsi3 insn for the non-MUL case, except for
AVR_TINY which passes the 2nd argument on the stack so no insn can be used.
The change might be beneficial even in the absence of PR118012 because
the __mulpsi3 footprint is leaner than a libcall.
PR tree-optimization/118012
PR tree-optimization/122505
gcc/
* config/avr/avr.md (mulpsi3): Also allow the insn condition
in the case where avropt_pr118012 && !AVR_TINY.
(*mulpsi3): Handle split for the !AVR_HAVE_MUL case.
(*mulpsi3-nomul.libgcc_split, *mulpsi3-nomul.libgcc): New insns.
Shreya Munnangi [Sat, 1 Nov 2025 22:48:54 +0000 (16:48 -0600)]
[RISC-V][SH][PR rtl-optimization/67731] Improve logical IOR of single bit bitfields
This is Shreya's work except for the SH testcase which I added after realizing
her work would also fix the testcases for that port. I bootstrapped and
regression tested this on sh4-linux-gnu, x86_64 & risc-v. It also was tested
across all the embedded targets in my tester without regressions.
--
We are extracting two single-bit bitfields from a structure and
determining whether they both have the value 0 or if at least one bit is set. This has been generating poor code:
> lw a5,0(a0)
> bexti a0,a5,1
> bexti a5,a5,2
> or a0,a0,a5
> ret
We address this as a simplification problem and optimize this using an
andi of the original value and a mask with just the desired bits set,
followed by a snez. This results in a 1 if any of those bits are set or 0 if none.
For cases where we want to extract three or more single-bit bitfields, we build
on the previous case. We take the result of the 2-bitfield case, extract the
mask, update it to include the new single-bit bitfield, and again perform an
andi + snez.
In our new testfile, we scan to ensure we do not see a bexti or an or
instruction, and that we have the correct assembly for both two and three single-bit bitfield cases: lw + andi + snez + ret.
PR target/67731
gcc/
* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
Handle IOR of single bit bitfields from the same object.
gcc/testsuite/
* gcc.target/riscv/pr67731.c: New test.
* gcc.target/sh/pr67731.c: New test.
Jeff Law [Sat, 1 Nov 2025 22:27:05 +0000 (16:27 -0600)]
[RISC-V] Reorder ready queue slightly to avoid unnecessary vsetvl instructions
As I've touched on before, particularly in the patchwork meeting, we can get a
modest reduction in the number of vsetvl instructions we emit by being somewhat
smarter in how we pull instructions out of the ready queue during scheduling.
Each insn in the scheduler's ready queue has a priority which reflects the how
that insn plays in a region's critical path. The higher the priority, the more
important it is for that instruction to issue.
When we have multiple insns with the same priority in the ready queue, we can
roughly expect that issuing any insn from that set is equally good. Yes there
are secondary sort keys that incorporate register lifetime and such, but those
are just that -- secondary concerns.
Given some set of insns with the same priority, we can select whichever one we
want, so select the insn with the same vector configuration as whatever vector
instruction was last issued from the ready queue.
This will naturally tend to group vector instructions with the same vector
configuration together, thus reducing the ping-ponging of vector configurations
that we sometimes see.
When I initially cobbled this together (about a year ago) Robin reported low
single digit improvements on the BPI for x264. A lot has changed since then
and it may not be as big a win now, but I think it still has value.
This did expose that one of the move patterns in vector.md didn't have the
proper vl_op/vtype_op attributes on it. Trivially fixed.
Tested for riscv32-elf, riscv64-elf and on the Pioneer with no regressions (of
course the Pioneer won't really exercise this code). BPI is in flight, but not
due to complete for ~24hrs. We've also been running this internally for
roughly a year 🙂
Jeff Law [Sat, 1 Nov 2025 14:30:41 +0000 (08:30 -0600)]
[PR rtl-optimization/122321][RISC-V] Bounds check another access to ira_reg_equiv array
So another case where we're indexing into the ira_reg_equiv array without
checking bounds. I sincerely hope we're not playing wack-a-mole here, but two
failures in a couple months for the same core problem is worrisome.
Bootstrapped and regression tested on x86_64 and riscv64 as well as run through
all the embedded targets in my tester without regressions.
PR rtl-optimization/122321
gcc/
* lra-constraints.cc (update_equiv): Make sure REGNO is in
ira_reg_equiv before trying to update ira_reg_equiv.
gcc/testsuite/
* gcc.target/riscv/rvv/autovec/pr122321.c: New test.
Martin Uecker [Sun, 5 Oct 2025 18:53:43 +0000 (20:53 +0200)]
c: GNU extension allowing compound literals of variable size
This patch implements a GNU extension by allowing compound literals
to be VLAs which then can be initialized with an empty initializer.
This addresses a use case where one would now need to use alloca, but
this also has limitations (e.g. allocated memory accumulates in a loop).
The error for a compound literal with variable size is changed to a
pedwarn, and a new error for static and constexpr is added.
gcc/c/ChangeLog:
* c-decl.cc (build_compound_literal): Add error.
* c-parser.cc (c_parser_braced_init): Take bool argument for
variable size instead of DECL.
(c_parser_initializer,c_parser_initval): Adapt.
(c_parser_postfix_expression_after_paren_type): Change
error to pedwarn.
* c-typeck.cc (process_init_element): Add error for
variable-size compound literal with static or constexpr.
gcc/ChangeLog:
* doc/extend.texi: Document new extension.
gcc/testsuite/ChangeLog:
* gcc.dg/gnu-compoundlit-1.c: New test.
* gcc.dg/gnu-compoundlit-2.c: New test.
* gcc.dg/pr68090.c: Adapt.
* gcc.dg/vla-init-4.c: Adapt.
* gcc.dg/vla-init-5.c: Adapt.
Martin Uecker [Fri, 31 Oct 2025 15:10:40 +0000 (16:10 +0100)]
c: Fix ICE when using va_arg with arrays [PR97986]
When array type is passed to va_arg, this is undefined behavior.
Emit a warning, and insert a run-time trap after evaluating side effects,
but return the correct type for sizeof / typeof. For C90 a VLA is an
error.
If both the source and destination are address (GP) registers, emitting
instructions that invert the MSB of the address register is two bytes
shorter if TARGET_DENSITY is enabled than emitting a NEG.S machine inst-
ruction that uses hardware FP registers with two reloads.
By the way, in configurations that do not use hardware FP register, the
RTL expansion pass will emit such insns by default.
gcc/ChangeLog:
* config/xtensa/xtensa.md (negsf2):
Add another insn pattern that is valid when TARGET_DENSITY is
enabled and both the source and destination are address registers.
Due to inconsistencies in the behavior of rounding half, making this
machine instruction available was retracted in a previous commit (5f3b5b0616fe883e86e95d9476371cf87059ca7f),
but it may be useful to have it available if strict implementation of
floating-point arithmetic is not required.
gcc/ChangeLog:
* config/xtensa/xtensa.md
(c_enum "unspec", int_iterator ANY_ROUND): Add UNSPEC_ROUND.
(int_attr m_round): Add a pair of UNSPEC_ROUND and "round".
(int_attr c_round): New integer iterator attribute, that expands
to "flag_unsafe_math_optimizations" in the case of UNSPEC_ROUND,
and to "1" otherwise.
(l<m_round>sfsi2, *l<m_round>sfsi2_2x, *l<m_round>sfsi2_scaled):
Append " && <c_round>" to the conditions.
Andrew Pinski [Sat, 1 Nov 2025 03:04:38 +0000 (20:04 -0700)]
testsuite: Fix fold-vecperm-1.c for targets that don't have vectors
This testcase is testing at optimization but with targets that don't
have vectors it will fail because there will be zero VEC_PERM_EXPR.
So instead let's check earlier in say forwprop3.
Pushed as obvious after a test on x86_64-linux-gnu with -mno-sse.
gcc/testsuite/ChangeLog:
* gcc.dg/fold-vecperm-1.c: Test at forwprop3.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Andrew Pinski [Fri, 31 Oct 2025 21:35:41 +0000 (14:35 -0700)]
ipa: Fix pritting of symtab_node type [PR122512]
The problem here r16-4747-g529c25ed6e0a06 changed
symtab_type to toplevel_type and then added 2 types
at the begining but didn't update symtab_type_names.
This obvious patch changes symtab_type_names to toplevel_type_names,
adds a _MAX type to toplevel_type and a comment about keeping them in sync.
Also adds an static assert to make sure if someone adds a toplevel_type
that toplevel_type_names get updated too.
Pushed as obvious after a build and test.
PR ipa/122512
gcc/ChangeLog:
* cgraph.h (enum toplevel_type): Add TOPLEVEL_MAX. Add comment
about keeping toplevel_type_names in sync.
* symtab.cc (symtab_type_names): Rename to ...
(toplevel_type_names): Add new types and add an assert about
the size.
(symtab_node::get_symtab_type_string): Use toplevel_type_names
instead of symtab_type_names.
(symtab_node::dump_base): Likewise.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
convert:
movi v31.4s, 0
ext v0.16b, v31.16b, v0.16b, #14
ret
We generate an ext with movi because this has same latency as a shift however
it has twice the throughput. The zero vector is zero latency as such in real
workloads this codegen is much better than using shifts.
As a reminder, BF16 -> FP32 is just shifting left 16 bits.
The expand pattern has to rely on generating multiple subregs due to a
restriction that subregs can't chang floating point size and type at the same
time.
I've tried alternative approaches like using the EXT as SF mode, but the
paradoxical subreg of BF -> SF isn't allowed and using an extend doesn't work
because extend is what we're defining.
Paul Thomas [Fri, 31 Oct 2025 12:59:23 +0000 (12:59 +0000)]
Fortran: Use specific PDT constructors from a generic list [PR122452]
2025-10-31 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/122452
* primary.cc (gfc_match_rvalue): Give priority to specific
procedures in a generic interface with the same name as a
PDT template. If found, use as the procedure instead of the
constructor generated from the PDT template.
gcc/testsuite/
PR fortran/122452
* gfortran.dg/pdt_65.f03: New test.
Richard Biener [Fri, 31 Oct 2025 07:57:39 +0000 (08:57 +0100)]
tree-optimization/122502 - avoid folding during imm use walk with active ranger
The following works around an unfortunate interaction with ranger
and immediate use walking. An actual solution needs more thoughts.
PR tree-optimization/122502
* tree-scalar-evolution.cc (final_value_replacement_loop):
Avoid folding from within FOR_EACH_IMM_USE_STMT due to active
ranger.
Andrew Pinski [Mon, 27 Oct 2025 23:20:40 +0000 (16:20 -0700)]
fold: Remove div_if_zero_remainder [PR122437]
While looking into something related to fold-const.cc, I noticed
that div_if_zero_remainder was unused. The last use of it was
removed in r5-3374-gf65586dcd19846 (via the removal of try_move_mult_to_index),
over 11 years ago. So it is time to remove this unused function too.
Plus this function is just a small wrapper around wi::multiple_of_p but
creating trees which can get expensive so folks should use wi::multiple_of_p
directly instead.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/122437
gcc/ChangeLog:
* fold-const.cc (div_if_zero_remainder): Remove.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>