Eric Botcazou [Thu, 1 May 2025 23:10:36 +0000 (01:10 +0200)]
ada: Small cleanup in the finalization machinery
The generic finalization machinery and the finalization machinery for
transient objects disagree on which controlled objects should be finalized
indirectly, i.e. through an access value: the former only considers return
objects of (selected) function calls, whereas the latter considers all
objects designated by a reference, which means that it must be careful
about not finalizing them twice.
The discrepancy does not seem to cause problems in practice, but is awkward
and creates additional work for the finalization machinery for transient
objects, as well as code duplication.
gcc/ada/ChangeLog:
* exp_util.ads (Is_Finalizable_Access): New predicate.
(Is_Non_BIP_Func_Call): Delete.
(Is_Secondary_Stack_BIP_Func_Call): Likewise.
* exp_util.adb (Is_Finalizable_Access): New predicate.
(Initialized_By_Aliased_BIP_Func_Call): Delete.
(Initialized_By_Reference): Likewise.
(Is_Aliased): Only consider the nontransient object serviced by
the transient scope.
(Is_Part_Of_BIP_Return_Statement): Minor tweak.
(Is_Finalizable_Transient): Remove calls to Initialized_By_Reference
and Initialized_By_Aliased_BIP_Func_Call.
Call Is_Finalizable_Access for access objects.
(Is_Non_BIP_Func_Call): Delete.
(Is_Secondary_Stack_BIP_Func_Call): Likewise.
(Requires_Cleanup_Actions): Call Is_Finalizable_Access for access
objects.
(Side_Effect_Free): Return True for N_Reference.
* exp_ch7.adb (Build_Finalizer.Process_Declarations): Call
Is_Finalizable_Access for access objects.
Eric Botcazou [Fri, 2 May 2025 13:32:54 +0000 (15:32 +0200)]
ada: Fix wrong finalization of temporary constrained array of controlled type
This regression has been introduced by the rewrite of the finalization
machinery, which now requires a specific handling of constrained array
types with controlled component and an unconstrained first subtype.
gcc/ada/ChangeLog:
* exp_util.adb (Is_Expression_Of_Func_Return): New predicate.
(Is_Related_To_Func_Return): Call Is_Expression_Of_Func_Return.
(Remove_Side_Effects): Generate a temporary for a function call
that returns a constrained array type with controlled component
and an unconstrained first subtype.
Piotr Trojanek [Tue, 29 Apr 2025 08:34:04 +0000 (10:34 +0200)]
ada: Remove wrong optimization in frontend inlining of procedure calls
When using obsolete frontend inlining (switch -gnatN), we must always rewrite
the procedure call into a single block node. Otherwise, the copy-back of
parameters passed by-copy is inserted before the inlined procedure body, which
causes wrong code to be generated.
gcc/ada/ChangeLog:
* inline.adb (Rewrite_Procedure_Call): Replace with a simple rewriting
of procedure call into a single block node, i.e. remove broken
optimization.
* sem_util.adb (Next_Actual): Adapt GNATprove-specific code that peeks
into inlined calls.
Martin Clochard [Tue, 29 Apr 2025 09:36:19 +0000 (11:36 +0200)]
ada: Minor fix in handling of inherited Pre/Post'Class aspect
Mapping of calls to primitive functions in Pre/Post'Class aspects
inherited by derived types was only testing against controlling formals
of the parent subprogram. This lead to missing some calls, because formals
could be rewritten to that of the derived subprogram before the test
happens.
gcc/ada/ChangeLog:
* exp_util.adb (Is_Controlling_Formal_Ref): test scope against
derived subprogram as well.
Subprogram Compilation_Errors is used to check whether any
errors have been detected during the compilation process. It
relies on Total_Errors_Detected and Warnings_Treated_As_Errors
counts. Total_Erros_Detected are updated immidiatelly after
the error objects have been created. Warnings_Treated_As_Errors
were updated only when the messages are being printed.
This leads to a situation where we do not have the correct count
of Warnings_Treated_As_Errors unless the errors have been printed.
gcc/ada/ChangeLog:
* errout.adb (Error_Msg_Internal): Relocate Warn_As_Err propagation
to Increase_Error_Msg_Counti.
(Delete_Warning_And_Continuations): Update
Warnings_Treated_As_Errors count.
(Delete_Warning): Likewise.
(To_Be_Removed): Likewise.
* erroutc.adb (Increase_Error_Msg_Count): Count warnings treated
as errors here and perform the propagation of this property to
the parent message.
(Output_Msg_Text): Remove counting of warnings as errors from
here.
(Decrease_Error_Msg_Count): Update Warnings_Treated_As_Errors
count.
I recently noticed that libphobos isn't enable by default on 32-bit
Darwin with the target triples determined by config.guess. E.g. on a
Darwin 15 system the target triple is something like
i386-apple-darwin15.6.0 while configure.tgt only matches
i?86-*-darwin1[2-7].
This patch also allows such minor and micro versions.
Yuao Ma [Tue, 1 Jul 2025 07:50:28 +0000 (09:50 +0200)]
gcc: middle-end opt for trigonometric pi-based functions builtins
This patch partially handled PR118592.
This patch builds upon r16-710-g591d3d02664c7b and r16-711-g89935d56f768b4. It
introduces middle-end optimizations, such as constant folding, for our
trigonometric pi-based function built-ins.
[testsuite] restore default action from dfp.exp [PR120631]
dfp.exp tests for dfprt before deciding whether to default to run or
compile, and the PR120631 tests override that without checking for
dfprt. Rework them to avoid attempting to link and run programs
when dfp runtime support isn't available.
for gcc/testsuite/ChangeLog
PR middle-end/120631
* gcc.dg/dfp/pr120631.c: Drop overrider of dg-do default action.
* gcc.dg/dfp/bitint-9.c: Likewise.
* gcc.dg/dfp/bitint-10.c: Likewise.
James K. Lowden [Mon, 30 Jun 2025 20:51:49 +0000 (16:51 -0400)]
cobol: Revise diagnostic linemap management.
Update linemap filename before location in both parsers. Rely on
parser to update linemap. Lexer maintains location. Various small
syntax corrections and extensions.
Jeff Law [Mon, 30 Jun 2025 20:38:33 +0000 (14:38 -0600)]
[committed] [PR rtl-optimization/120242] Fix SUBREG_PROMOTED_VAR_P after ext-dce's actions
I've gone back and forth of these problems multiple times. We have two passes,
ext-dce and combine which eliminate extensions using totally different
mechanisms.
ext-dce looks for cases where the state of upper bits in an object aren't
observable and if they aren't observable, then eliminates extensions which set
those bits.
combine looks for cases where we know the state of the upper bits and can prove
an extension is just setting those bits to their prior value. Combine also
looks for cases where the precise extension isn't really important, just the
knowledge that the upper bits are zero or sign extended from a narrower mode
is needed.
Combine relies heavily on the SUBREG_PROMOTED_VAR state to do its job. If the
actions of ext-dce (or any other pass for that matter) make
SUBREG_PROMOTED_VAR's state inconsistent with combine's expectations, then
combine can end up generating incorrect code.
--
When ext-dce eliminates an extension and turns it into a subreg copy (without
any known SUBREG_PROMOTED_VAR state). Since we can no longer guarantee the
destination object has any known extension state, we scurry around and wipe
SUBREG_PROMOTED_VAR state for the destination object.
That's fine and dandy, but ultimately insufficient. Consider if the
destination of the optimized extension was used as a source in a simple copy
insn. Furthermore assume that the destination of that copy is used within a
SUBREG expression with SUBREG_PROMOTED_VAR set. ext-dce's actions have
clobbered the SUBREG_PROMOTED_VAR state on the destination of that copy, albeit
indirectly.
This patch addresses this problem by taking the set of pseudos directly
impacted by ext-dce's actions and expands that set by building a transitive
closure for pseudos connected via copies. We then scurry around finding
SUBREG_PROMOTED_VAR state to wipe for everything in that expanded set of
pseudos. Voila, everything just works.
--
The other approach here would be to further expand the liveness sets inside
ext-dce. That's a simpler path forward, but ultimately regresses the quality
of codes we do care about.
One good piece of news is that with the transitive closure bits in place, we
can eliminate a bit of the live set expansion we had in place for
SUBREG_PROMOTED_VAR objects.
--
So let's take one case of the 5 that have been reported.
Combine will do its thing on insns 30/31. Essentially the sign extension is
not necessary in this context, assuming the promoted subreg status in insn 30
-- the equality test doesn't really care about the kind of extension, just
knowing the value is extended is enough to safely elide the extension.
And now we've come to the crux the problem. That promotion state needs to be
adjusted. The new ext-dce code will see that copy at insn 26 and add (reg 144)
to the set of registers that need promotion state wiped. And everything is
happy after that.
The other cases are similar in nature.
--
This has been bootstrapped and regression tested on x86_64 and aarch64.
Variants have bootstrapped & regression tested on several other platforms and
it's survived testing on the crosses as well.
* ext-dce.cc (ext_dce_process_uses): Remove some cases where we
unnecessarily expanded live sets for promoted subregs.
(expand_changed_pseudos): New function.
(reset_subreg_promoted_p): Use it.
[RISC-V] Correct CFA notes for stack-clash protection [PR120714]
Fixes incorrect SP-addresses used in CFA notes for the stack probes
unrelative to the frame's top. It applied to the RISC-V targets code
generation when the stack-clash protection is enabled.
PR target/120714
gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_allocate_and_probe_stack_space):
Fix SP-addresses in REG_CFA_DEF_CFA notes for stack-clash case.
David Malcolm [Mon, 30 Jun 2025 19:04:55 +0000 (15:04 -0400)]
diagnostics: remove "json" output format
The "json" output format for diagnostics was deprecated in GCC 15, with
advice to users seeking machine-readable diagnostics from GCC to use
SARIF instead.
This patch eliminates it from GCC 16, simplifying the diagnostics
subsystem somewhat.
Note that the Ada frontend seems to have its own implementation of this
in errout.adb (Output_JSON_Message), and documented in
gnat_ugn.texi. This patch does not touch Ada.
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Drop diagnostic-format-json.o.
* common.opt (fdiagnostics-format=): Drop
"json|json-stderr|json-file".
(diagnostics_output_format): Drop values "json", "json-stderr",
and "json-file".
* diagnostic-format-json.cc: Delete file.
* diagnostic-format.h
(diagnostic_output_format_init_json_stderr): Delete.
(diagnostic_output_format_init_json_file): Delete.
* diagnostic.cc (diagnostic_output_format_init): Delete cases for
DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR and
DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE.
* diagnostic.h (DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR): Delete.
(DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE): Delete.
* doc/invoke.texi: Remove references to json output format.
* doc/ux.texi: Likewise.
* selftest-run-tests.cc (selftest::run_tests): Drop call to
deleted selftest::diagnostic_format_json_cc_tests.
* selftest.h (selftest::diagnostic_format_json_cc_tests): Delete.
ivopts: Fix scan-assembler-not regexes for aarch64/sve test
The test added by r16-1671-ge7ff8e8d77df74 passed despite using
regular expressions that would never match real assembly language
output from the compiler. Because the regular expressions were not
expected to match, and didn't, this was not noticeable; however,
it also made that part of the test useless.
The regular expressions have been fixed. Verified that the fixed
regular expressions do match assembly language output produced by
the compiler before the changes to ivopts in commit e7ff8e8d77d,
but do not match assembly language output produced by the compiler
after the changes to ivopts.
Pan Li [Fri, 27 Jun 2025 03:35:18 +0000 (11:35 +0800)]
RISC-V: Reconcile the existing test due to cost model change
The cost model change will make the default cost of vx to 2, thus
reconcile the asm check for this change.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_trunc-1-u16.c:
Update the asm check due to cost model change.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_trunc-1-u32.c:
Diito.
* gcc.target/riscv/rvv/autovec/sat/vec_sat_u_sub_trunc-1-u8.c:
Ditto.
Pan Li [Fri, 27 Jun 2025 01:02:03 +0000 (09:02 +0800)]
RISC-V: Combine vec_duplicate + vssubu.vv to vssubu.vx on GR2VR cost
This patch would like to combine the vec_duplicate + vssubu.vv to the
vssubu.vx. From example as below code. The related pattern will depend
on the cost of vec_duplicate from GR2VR. Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.
Assume we have example code like below, GR2VR cost is 0.
#define DEF_VX_BINARY(T, FUNC) \
void \
test_vx_binary (T * restrict out, T * restrict in, T x, unsigned n) \
{ \
for (unsigned i = 0; i < n; i++) \
out[i] = FUNC (in[i], x); \
}
T sat_sub(T a, T b)
{
return (a - b) & (-(T)(a >= b));
}
* config/riscv/riscv-v.cc (expand_vx_binary_vec_vec_dup): Add
new case US_MINUS.
* config/riscv/riscv.cc (riscv_rtx_costs): Ditto.
* config/riscv/vector-iterators.md: Add new op us_minus.
ada: Fix Execution_Successful value with exceptions
Store the Exit_Code value and use that to generate
the Exceution_Successful value in the SARIF report.
gcc/ada/ChangeLog:
* comperr.adb (Compiler_Abort): Pass the exit code in calls to
Output_Messages.
* errout.adb (Output_Messages): Add new parameter for the
Exit_Code and store its value.
* errout.ads (Output_Messages): Likewise.
* erroutc-sarif_emitter.adb (Print_Invocations): Set
Execution_Successful based on the exit code.
* erroutc.ads (Exit_Code): Store the exit code value.
* gnat1drv.adb (Gnat1drv): Pass the exit code in calls to
Output_Messages.
* prepcomp.adb (Parse_Preprocessing_Data_File, Prpare_To_Preprocess):
Likewise.
The description of the Has_Exit field in Einfo makes it pretty clear
that it can only be meaningful for loop entities. It was however defined
in all entities until this patch, which restricts this field to E_Loop.
Bob Duff [Tue, 29 Apr 2025 17:12:44 +0000 (13:12 -0400)]
ada: Make class-wide Max_Size_In_Storage_Elements return a large value
Max_Size_In_Storage_Elements is supposed to return a value greater or
equal to what is passed for any heap allocation for an object of the
type. For a tagged type T, we don't know the allocation size for
descendants; therefore T'Class'Max_Size_In_Storage_Elements should
return a huge number. In particular, it now returns Storage_Count'Last,
which is greater than any possible heap allocation.
Previously, T'Class'Max_Size_In_Storage_Elements was returning
the same value as T'Max_Size_In_Storage_Elements, which was
wrong.
gcc/ada/ChangeLog:
* exp_attr.adb (Attribute_Max_Size_In_Storage_Elements):
Return Storage_Count'Last converted to universal_integer.
Tonu Naks [Fri, 28 Mar 2025 12:41:29 +0000 (12:41 +0000)]
ada: Add documentation of implemented Ada 2022 features
gcc/ada/ChangeLog:
* doc/gnat_rm.rst: add entry point for the new chapter
* doc/gnat_rm/about_this_guide.rst: add reference to the new
chapter
* doc/gnat_rm/implementation_of_ada_2022_features.rst: new file
* doc/gnat_rm/implementation_of_ada_2012_features.rst: update
explanation about RM references
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.
ada: Reuse Snames classification of reserved words
Before this patch, Check_Future_Keyword had hardcoded lists of what
reserved words were introduced in what versions of the Ada language
specification. This patch makes it use the classification in Snames
instead.
gcc/ada/ChangeLog:
* par-util.adb (Check_Future_Keyword): Use Snames subtypes. Extend
comment.
Bob Duff [Sun, 27 Apr 2025 19:15:51 +0000 (15:15 -0400)]
ada: Fix bug in -gnatw.o switch (unreferenced out parameters)
Fixes this bug: If -gnatw.o is specified, it is ignored unless
-gnatwm is also specified (either directly, or as part of a
catch-all switch like -gnatwa).
gcc/ada/ChangeLog:
* sem_warn.adb (Warn_On_Useless_Assignments):
Enable Warn_On_Useless_Assignment in the case of
Warn_On_All_Unread_Out_Parameters.
ada: Remove uses of E_Void for subtype declarations
This patch slightly reorganizes Analyze_Subtype_Declaration so that the
proper Ekind of the new subtype's entity is set before anything else is
done with it. A new local subprogram is introduced in the process.
gcc/ada/ChangeLog:
* sem_ch3.adb (Analyze_Subtype_Declaration): Remove uses of E_Void.
(Copy_Parent_Attributes): New procedure.
Eric Botcazou [Sat, 26 Apr 2025 13:18:57 +0000 (15:18 +0200)]
ada: Fix missing rounding in System.Value_R.Scan_Raw_Real
The extra digit returned by the function is supposed to be rounded, either
by Scan_Integral_Digits or by Scan_Decimal_Digits, but that is not the case
when it is the last digit read by Scan_Integral_Digits.
The problem is fixed by rounding it in Scan_Decimal_Digits in this case.
gcc/ada/ChangeLog:
* libgnat/s-valuer.adb (Scan_Decimal_Digits): Also pretend that the
precision limit was just reached if it was already reached.
(Scan_Integral_Digits): Add Extra_Rounded out parameter, set it to
False on entry and to True when Extra is rounded.
(Scan_Raw_Real): New Extra_Rounded local variable. Pass it in the
calls to Scan_Integral_Digits. If it is True, pass a dummy extra
digit to Scan_Decimal_Digits.
Javier Miranda [Mon, 10 Mar 2025 19:40:26 +0000 (19:40 +0000)]
ada: Array aggregates of mutably tagged objects
When an array of mutably tagged class-wide types is initialized
with an array aggregate, the compiler erroneously rejects it
reporting that the type of the aggregate cannot be a
class-wide type. In addition, Program_Error is not raised at
runtime on array type or record type objects when they have
mutably tagged abstract class-wide type components that are
initialized by default.
gcc/ada/ChangeLog:
* sem_aggr.adb (Resolve_Record_Aggregate): Adjust the code to
handle mutably tagged class-wide types since they don't have
discriminants, but all class-wide types are considered to have
unknown discriminants. Initialize mutably tagged class-wide
type components calling their IP subprogram.
* exp_aggr.adb (Gen_Assign): Handle mutably tagged class-wide type
components that have an initializing qualified expression, and
mutably tagged class-wide components default initialization.
(Gen_Loop): Handle mutably tagged class-wide types.
(Gen_Assign): ditto.
(Build_Record_Aggr_Code): Default initialization of mutably tagged
class-wide types is performed by their IP subprogram.
* exp_ch3.adb (Init_Component): Generate code to raise Program_Error
in the IP subprogram of arrays when the type of their components is
a mutably tagged abstract class-wide type.
(Build_Init_Procedure): ditto for the init procedure of record types.
(Build_Init_Statements): Ensure that the type of the expression
initializing a mutably class-wide tagged type component is frozen.
(Requires_Init_Proc): Mutably tagged class-wide types require the
init-proc since it takes care of their default initialization.
* sem_util.adb (Needs_Simple_Initialization): Mutably tagged class-wide
types don't require simple initialization.
* types.ads (PE_Abstract_Type_Component): New reason for Program_Error.
* types.h (PE_Abstract_Type_Component): ditto.
* exp_ch11.adb (Get_RT_Exception_Name): Handle new reason for
Program_Error.
* libgnat/a-except.adb (Rcheck_PE_Abstract_Type_Component): New
subprogram.
Piotr Trojanek [Thu, 24 Apr 2025 14:56:20 +0000 (16:56 +0200)]
ada: Ignore unchecked type conversions while getting enclosing object
This patch both makes GNAT emit warnings on unused assignments where previously
they were suppressed for obscure reasons and synchronizes routine
Get_Enclosing_Object with a similar routine in GNATprove (which differs in
handling of explicit dereferences).
gcc/ada/ChangeLog:
* sem_util.adb (Get_Enclosing_Object): Traverse unchecked type
conversions since they from the compiler and should be transparent for
semantic reasoning.
Gary Dismukes [Tue, 22 Apr 2025 21:50:53 +0000 (21:50 +0000)]
ada: Filling in gaps in handling of inherited Pre/Post'Class aspects
The initial set of changes for doing proper mapping of calls to primitive
functions in Pre/Post'Class aspects inherited by derived types was not
handling some cases (such as when formals are referenced as part of
dereferences, certain aspects such as 'Old and 'Access, and conditional
and declare expressions), and mishandling other cases (such as nested
function calls).
This set of changes attempts to properly address those cases. It also
includes a change to suppress unneeded (and sometimes wrong) accessibility
checks on conversions of actual parameters of a derived type to the parent
type when passing them on calls to parent primitives (encountered while
developing these changes).
gcc/ada/ChangeLog:
* exp_util.adb (Must_Map_Call_To_Parent_Primitive): Change function
name (was Call_To_Parent_Dispatching_Op_Must_Be_Mapped). Move logic
for attributes and dereferences, plus testing for controlled formals,
into new function Expr_Has_Ctrl_Formal_Ref. Add handling for
access attributes, multiple levels of attributes/dereferences,
conditional_expressions, and declare_expressions. Properly account
for function calls with multiple operands and enclosing calls.
(Expr_Has_Ctrl_Formal_Ref): New function to determine whether
an expression is a reference to a controlling formal or has
a prefix that is such a reference.
(Is_Controlling_Formal_Ref): New function in Expr_Has_Ctrl_Formal_Ref
to determine if a node is a direct reference to a controlling formal.
* freeze.adb (Build_DTW_Body): Create an unchecked conversion instead
of a regular type conversion for converting actuals in calls to parent
inherited primitives that are wrapped for inherited pre/postconditions.
Avoids generating unnecessary checks (such as accessibility checks on
conversions for anonymous access formals).
Piotr Trojanek [Thu, 24 Apr 2025 08:53:14 +0000 (10:53 +0200)]
ada: Tune name and commend document of a ghost utility routine
Detection of ghost entities work similarly for names of objects (in assignment
statements) and for names of subprograms (in subprogram calls). Tune routine
name and its comment to match this similarity.
Piotr Trojanek [Thu, 24 Apr 2025 08:43:18 +0000 (10:43 +0200)]
ada: Fix detection of ghost objects in unusual procedure calls
When name of a called procedure involves unusual constructs, e.g. type
conversions (like in "Typ (Obj).all"), we must look at the outermost construct
to decide whether the name denotes a ghost entity.
gcc/ada/ChangeLog:
* ghost.adb (Ghost_Entity): Remove; use Get_Enclosing_Ghost_Object
instead; adapt callers.
Piotr Trojanek [Fri, 18 Apr 2025 14:43:38 +0000 (16:43 +0200)]
ada: Fix detection of ghost objects in assignment statements
Remove duplicated and inconsistent code for detecting ghost objects on the
left-hand side of assignment statements. Fix detection in the presence of
attribute references (e.g. "X'Access.all"), function calls (e.g. "F.all"),
qualified expressions (e.g. "T'(new Integer'(0)).all") and unchecked type
conversions (which come from expansion).
gcc/ada/ChangeLog:
* ghost.adb
(Whole_Object_Ref): Remove; use Get_Enclosing_Ghost_Object instead.
(Is_Ghost_Assignment): Handle more than object identifiers.
(Mark_And_Set_Ghost_Assignment): Likewise.
* sem_util.adb (Get_Enclosing_Ghost_Object): Detect more expressions
as ghost references; rename to better match the intended meaning.
* sem_util.ads (Get_Enclosing_Ghost_Object): Rename; adjust comment.
Eric Botcazou [Fri, 18 Apr 2025 20:39:57 +0000 (22:39 +0200)]
ada: Elide copy for calls as values of nonlimited by-reference components
...in aggregates. This prevents a temporary from being created on the
primary stack to hold the result of the function calls before it is copied
to the component of the aggregate in the nonlimited by-reference case.
This requires a small tweak to Check_Function_Writable_Actuals to avoid
giving a spurious error in a specific case.
gcc/ada/ChangeLog:
* exp_aggr.ads (Parent_Is_Regular_Aggregate): New predicate.
* exp_aggr.adb (In_Place_Assign_OK.Safe_Component): Implement more
accurate criterion for function calls.
(Convert_To_Assignments): Use Parent_Is_Regular_Aggregate predicate.
(Expand_Array_Aggregate): Likewise. Remove obsolete comment.
(Initialize_Component): Do not adjust when the expression is a naked
function call and Back_End_Return_Slot is True.
(Parent_Is_Regular_Aggregate): New predicate.
* exp_ch3.adb (Build_Record_Init_Proc.Build_Assignment): Add test of
Back_End_Return_Slot in conjunction with a function call.
* exp_ch4.adb (Expand_Allocator_Expression): Likewise. Use the
Is_Container_Aggregate predicate to detect container aggregates.
(Expand_N_Case_Expression): Delay the expansion if the parent is a
regular aggregate and the type should not be copied.
(Expand_N_If_Expression): Likewise.
(New_Assign_Copy): New function.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Bail out when the parent
is a regular aggregate.
* sem_util.adb (Check_Function_Writable_Actuals): Do not take into
account attribute references created by the compiler.
ada: use pointer decay for socket address type compatibility
GCC 14 is stricter about type conversions. Taking the address of an
array and decaying the array to a pointer to its first element yield
the same address, but the types are no longer considered compatible.
The socket data structures want decayed pointers rather than addresses
of arrays, so drop the '&'s.
gcc/ada/ChangeLog:
* socket.c [__vxworks]
(__gnat_gethostbyname): Drop excess '&'.
(__gnat_gethostbyaddr): Likewise.
A vxworks-specific part of adaint.c calls isalpha without including
ctype.h. gcc-14 rejects calls of undeclared functions. Include the
required header file when compiling for vxworks.
Steve Baird [Sat, 12 Apr 2025 00:38:29 +0000 (17:38 -0700)]
ada: Record type Put_Image procedures omitting discriminant values
If a type T has a partial view with a known_discriminant_part and no
user-specified Put_Image aspect specification, then the output generated
by T'Put_Image would incorrectly omit the discriminant values.
gcc/ada/ChangeLog:
* exp_put_image.adb (Build_Record_Put_Image_Procedure): If
Discriminant_Specifications takes us from the full view of a type
to an (intentionally) unanalyzed subtree, then instead find
discriminant entities by calling Discriminant_Specifications on
the partial view of the type.
ada: Fix crash on nested access-to-subprogram types
This patch fixes a crash on some subprograms with anonymous
access-to-subprogram parameters by removing delayed freezing of
subprograms in some cases where it wasn't necessary. The -gnatD output
for itypes is also improved.
Eric Botcazou [Fri, 18 Apr 2025 12:48:04 +0000 (14:48 +0200)]
ada: Remove redundant condition in test of System.Val_Real.Integer_To_Real
The second condition of the conjunction is redundant with the first.
gcc/ada/ChangeLog:
* libgnat/s-valrea.adb (Integer_to_Real): Rename to...
(Integer_To_Real): ...this. Remove the second condition of the
conjunction in the test for the zero value.
(Scan_Real): Adjust to above renaming.
(Value_Real): Likewise.
* libgnat/s-valuer.ads (Scan_Raw_Real): Add note about Val.
Before this patch, Print_Node failed to honor its Prefix_Char formal
parameter when printing the Parent field. This had no consequences
because Prefix_Char was only used to print members of Nlists, and those
don't have a parent in the tree. But this patch fixes it anyway in
preparation for new debug printing features.
gcc/ada/ChangeLog:
* treepr.adb (Print_Node): Tweak Parent field printing.
Piotr Trojanek [Tue, 16 Jan 2024 21:43:09 +0000 (22:43 +0100)]
ada: Remove dead branch from Get_Enclosing_Object
The dead branch in routine Get_Enclosing_Object was most likely some
experiment from the early days of GNATprove. This routine is meant
to be called with the LHS of an assignment statement where an implicit
dereference is always rewritten into explicit one, regardless if code
is generated.
gcc/ada/ChangeLog:
* sem_util.adb (Get_Enclosing_Object): Remove dead code.
Steve Baird [Mon, 7 Apr 2025 21:15:37 +0000 (14:15 -0700)]
ada: Fix Itype-related predicate check omissions.
Clean up problematic interactions between Itype subtypes and predicates,
which were causing required predicate checks to be (incorrectly) omitted.
gcc/ada/ChangeLog:
* einfo-utils.adb (Predicate_Function): Improve handling of a case
where a predicate specified for a subtype of a partial view of a
type was incorrectly ignored.
(Set_Predicate_Function): If the attribute has already been set to
the same value, then do nothing (instead of raising P_E).
* sem_ch13.adb (Build_Predicate_Function): Add new function
Has_Source_Predicate. If a subtype inherits a predicate but also
has its own explicitly specified predicate, then avoid
misinterpreting the presence of the function built for the
inherited predicate to mean that no additional predicate function
is needed.
* sem_util.adb (Build_Subtype): In the case where we are given a
constrained record or array subtype and we need to construct a
different subtype, subject to a different constraint, the
subtype_mark of the constructed subtype needs to reference an
unconstrained subtype (because a new constraint is going to be
imposed). If the Predicated_Parent attribute of the given subtype
is present and refers to a suitable unconstrained subtype, then
use that subtype instead of setting the Predicated_Parent
attribute on a new node (and performing the associated attribute
copying).
Eric Botcazou [Mon, 14 Apr 2025 08:23:52 +0000 (10:23 +0200)]
ada: Fix internal error on Ghost aspect applied to Big_Integers
That's a regression introduced by the rewrite of the finalization machinery,
in the form of dangling references to Master_Node entities remaining in the
tree after the removal of the ignored Ghost code.
gcc/ada/ChangeLog:
* exp_ch7.adb (Process_Transient_In_Scope): Bail out if the object
is an ignored ghost entity.
Eric Botcazou [Mon, 14 Apr 2025 08:04:27 +0000 (10:04 +0200)]
ada: Fix internal error on expression function called for default expression
This happens for the default expression of a controlled component when an
aggregate is used for the record type, because of a freeze node generated
for the expression within an artificial block that is needed to implement
the cleanup actions attached to the assignment of the component.
This is fixed by extending the special treatment applied to freeze nodes
by Insert_Actions, in the case of loops generated for aggregates, to the
case of blocks generated for aggregates.
gcc/ada/ChangeLog:
* exp_util.adb (Insert_Actions): Extend special treatment applied
to freeze nodes to the case of blocks generated for aggregates.
Peter Bergner [Mon, 30 Jun 2025 13:31:25 +0000 (19:01 +0530)]
rs6000: Disassemble opaque modes using subregs to allow optimizations
PR109116 reveals missed optimizations when using unspecs to extract
vector components from opaque-mode variables. Since RTL optimizers do
not understand unspecs, this leads to redundant register copies. Replace
unspecs with subregs, which are well understood by RTL passes, allowing
optimizations to take place.
Kito Cheng [Thu, 19 Jun 2025 06:31:42 +0000 (14:31 +0800)]
RISC-V: Primary vector pipeline model for sifive 7 series
This commit introduces a primary vector pipeline model for the SiFive 7
series, that pipeline model is kind of simplified version, it only
defined vector command queue, arithmetic unit, and vector load store
unit.
The latency of real hardware is LMUL-aware, but I realize that will
complicate the model a lots, so I just use a simplified version, which
all LMUL use same latency, we may improve it later once we have found
meaningful performance difference.
gcc/ChangeLog:
* config/riscv/sifive-7.md: Add primary vector pipeline model
for SiFive 7 series.
Richard Biener [Mon, 30 Jun 2025 09:23:49 +0000 (11:23 +0200)]
Handle SLP build operand swapping for ternaries and calls
The following adds SLP build operand swapping for .FMA which is
a ternary operator and a call. The current code only handles
binary operators in assignments, thus the patch extends this to
handle both calls and assignments as well as binary and ternary
operators.
* tree-vect-slp.cc (vect_build_slp_2): Handle ternary
and call operators when swapping operands.
* gcc.target/i386/vect-pr82426.c: Pass explicit -ffp-contract=fast.
* gcc.target/i386/vect-pr82426-2.c: New testcase variant with
-ffp-contract=on.
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into a (possibly negated) minus-mult RTL instruction.
Before this patch, we have two instructions, e.g.:
vfmv.v.f v6,fa0
vfnmacc.vv v2,v6,v4
After, we get only one:
vfnmacc.vf v2,fa0,v4
PR target/119100
gcc/ChangeLog:
* config/riscv/autovec-opt.md (*vfnmsub_<mode>,*vfnmadd_<mode>): Handle
both add and acc variants.
* config/riscv/vector.md (*pred_mul_neg_<optab><mode>_scalar_undef): New
pattern.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfnmacc and
vfnmsac.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f64.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f64.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f64.c: Likewise.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_mulop.h (DEF_VF_MULOP_CASE_1):
Fix return type.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmacc-run-1-f16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmacc-run-1-f32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmacc-run-1-f64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmsac-run-1-f16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmsac-run-1-f32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmsac-run-1-f64.c: New test.
Kyrylo Tkachov [Mon, 2 Jun 2025 14:08:12 +0000 (07:08 -0700)]
aarch64: Add support for NVIDIA GB10
This adds support for -mcpu=gb10. This is a big.LITTLE configuration
involving Cortex-X925 and Cortex-A725 cores. The appropriate MIDR numbers
are added to detect them in -mcpu=native. We did not add an
-mcpu=cortex-x925.cortex-a725 option because GB10 does include the crypto
instructions which we want on by default, and the current convention is to not
enable such extensions for Arm Cortex cores in -mcpu where they are optional
in the IP.
Bootstrapped and tested on aarch64-none-linux-gnu.
Jakub Jelinek [Mon, 30 Jun 2025 09:08:16 +0000 (11:08 +0200)]
Extend nonnull_if_nonzero attribute [PR120520]
C2Y voted in the
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3466.pdf
paper, which clarifies some of the conditional nonnull cases.
For strncat/__strncat_chk no changes are necessary, we already
use __attribute__((nonnull (1), nonnull_if_nonzero (2, 3))) attributes
on the builtin and glibc can do the same too, meaning that first
argument must be nonnull always and second must be nonnull if
the third one is nonzero.
The problem is with the fread/fwrite changes, where the paper adds:
If size or nmemb is zero,
+ptr may be a null pointer,
fread returns zero and the contents of the array and the state of
the stream remain unchanged.
and ditto for fwrite, so the two argument nonnull_if_nonzero attribute
isn't usable to express that, because whether the pointer can be null
depends on 2 integral arguments rather than one.
The following patch extends the nonnull_if_nonzero attribute, so that
instead of requiring 2 arguments it allows 2 or 3, the first one
is still the pointer argument index which sometimes must not be null
and the other one or two are integral arguments, if there are 2, the
invalid case is only if pointer is null and both the integral arguments
are nonzero.
2025-06-30 Jakub Jelinek <jakub@redhat.com>
PR c/120520
PR c/117023
gcc/
* builtin-attrs.def (DEF_LIST_INT_INT_INT): Define it and
use for 1,2,3.
(ATTR_NONNULL_IF123_LIST): New DEF_ATTR_TREE_LIST.
(ATTR_NONNULL_4_IF123_LIST): Likewise.
* builtins.def (BUILT_IN_FWRITE): Use ATTR_NONNULL_4_IF123_LIST
instead of ATTR_NONNULL_LIST.
(BUILT_IN_FWRITE_UNLOCKED): Likewise.
* gimple.h (infer_nonnull_range_by_attribute): Add another optional
tree * argument defaulted to NULL.
* gimple.cc (infer_nonnull_range_by_attribute): Add OP3 argument,
handle 3 argument nonnull_if_nonzero attribute.
* builtins.cc (validate_arglist): Handle 3 argument nonnull_if_nonzero
attribute.
* tree-ssa-ccp.cc (pass_post_ipa_warn::execute): Likewise.
* ubsan.cc (instrument_nonnull_arg): Adjust
infer_nonnull_range_by_attribute caller, handle 3 argument
nonnull_if_nonzero attribute.
* gimple-range-infer.cc (gimple_infer_range::gimple_infer_range):
Handle 3 argument nonnull_if_nonzero attribute.
* doc/extend.texi (nonnull_if_nonzero): Document 3 argument version
of the attribute.
gcc/c-family/
* c-attribs.cc (c_common_gnu_attributes): Allow 2 or 3 arguments for
nonnull_if_nonzero attribute instead of only 2.
(handle_nonnull_if_nonzero_attribute): Handle 3 argument
nonnull_if_nonzero.
* c-common.cc (struct nonnull_arg_ctx): Rename other member to other1,
add other2 member.
(check_function_nonnull): Clear a if nonnull attribute has an
argument. Adjust for nonnull_arg_ctx changes. Handle 3 argument
nonnull_if_nonzero attribute.
(check_nonnull_arg): Adjust for nonnull_arg_ctx changes, emit different
diagnostics for 3 argument nonnull_if_nonzero attributes.
(check_function_arguments): Adjust ctx var initialization.
gcc/analyzer/
* sm-malloc.cc (malloc_state_machine::on_stmt): Handle 3 argument
nonnull_if_nonzero attribute.
gcc/testsuite/
* gcc.dg/nonnull-9.c: Tweak for 3 argument nonnull_if_nonzero
attribute support, add further tests.
* gcc.dg/nonnull-12.c: New test.
* gcc.dg/nonnull-13.c: New test.
* gcc.dg/nonnull-14.c: New test.
* c-c++-common/ubsan/nonnull-8.c: New test.
* c-c++-common/ubsan/nonnull-9.c: New test.
with sfp being eliminated to (plus:DI (reg:DI sp) (const_int 16)).
Initially, during the !subst_p phase, lra_eliminate_regs_1 sees
the PLUS and recurses into each operand. The recursive call sees
the SUBREG and recurses into the SUBREG_REG. Since !subst_p,
this final recursive call replaces (reg:DI sfp) with:
(plus:DI (reg:DI sfp) (const_int 16))
(i.e. keeping the base register the same). So the SUBREG is
eliminated to:
The simplify_gen_subreg then returns null, because simplify_subreg_regno
fails both with allow_stack_regs==false (when trying to simplify the
SUBREG to a REG) and with allow_stack_regs=true (when validating
whether the SUBREG can be generated). And that in turn happens
because aarch64 refuses to allow SImode to be stored in sfp:
if (regno == SP_REGNUM)
/* The purpose of comparing with ptr_mode is to support the
global register variable associated with the stack pointer
register via the syntax of asm ("wsp") in ILP32. */
return mode == Pmode || mode == ptr_mode;
if (regno == FRAME_POINTER_REGNUM || regno == ARG_POINTER_REGNUM)
return mode == Pmode;
This seems dubious. If the frame pointer can hold a DImode value then it
can also hold an SImode value. There might be limited cases when the low
32 bits of the frame pointer are useful, but aarch64_hard_regno_mode_ok
doesn't have the context to second-guess things like that. It seemed
from a quick scan of other targets that they behave more as I'd expect.
So there might be a target bug here too. But it seemed worth fixing the
unchecked use of lowpart_subreg independently of that.
The patch fixes an existing ICE in gcc.c-torture/compile/pass.c.
Jan Hubicka [Mon, 30 Jun 2025 07:14:46 +0000 (09:14 +0200)]
Re-add logic to mitigate some afdo profile inconsistencies
This patch re-adds logic to increase counts of annotated basic blocks if otherwise
the Kirhoff law can not be solved. This is done only in easy cases where total
count of in or out edges is smaller than the count of BB or when BB has single
exit which is annotated by small count.
This helps to solve problems seen i.e. in parest where header of loops gets too
low count because vectorizer replaced the IV condiitonal and did not preserved
debug info. We should solve the debug info issues as well, and simiar problems
can now be tracked by in afdo debug dumps.
gcc/ChangeLog:
* auto-profile.cc (autofdo_source_profile::offline_external_functions):
Add missing newline in dump.
(afdo_propagate_edge): If annotated BB or edge has too small count
bump it up to mitigate profile imprecisions caused by vectorizer.
(afdo_propagate): Increase number of iteraitons and fix dump
Jan Hubicka [Sun, 29 Jun 2025 05:05:16 +0000 (07:05 +0200)]
Impove diagnostics of mismatched discriminators in auto-profile
We are missing discriminator info in auto-profiles, for example in exchange2.
I am not sure why, since I see the info still present in dwarf2out, so it may
be bug at create_gcov side.
This patch makes the workaround to ouptput better diagnostics (to actually show
the soruce location). This needs promotion of location info through the inline
stack API, so I turned it from pair to actual structure. Overall I think pairs
are overused in this source and makes it harder to read.
Jin Ma [Sat, 28 Jun 2025 11:55:00 +0000 (19:55 +0800)]
RISC-V: Refactor the function bitmap_union_of_preds_with_entry
The current implementation of this function is somewhat difficult to
understand, as it uses a direct break statement within the for loop,
rendering the loop meaningless. Additionally, during the Coverity check
on the for loop, a warning appeared: "unreachable: Since the loop
increment ix++; is unreachable, the loop body will never execute more
than once." Therefore, I have made some simple refactoring to address
these issues.
Kito Cheng [Thu, 26 Jun 2025 09:21:27 +0000 (17:21 +0800)]
RISC-V: Add pipeline-checker script
Pipeline checker utility for RISC-V architecture that validates processor
pipeline models. This tool analyzes machine description files to ensure all
instruction types are properly handled by pipeline scheduling models.
I write this tool since I am implment vector pipeline stuff for SiFive
core, but it's hard to find which instruction type is not handled by
pipeline scheduling models. This tool will help me to find out which
instruction type is not handled by pipeline scheduling models, so I can
fix them.
And I think it may be useful for other RISC-V core developers, so I
decided to upstream that :)
Usage:
```
./pipeline-checker <your-pipeline-model>
```
Example:
```
$ ./pipeline-checker sifive-7.md
Error: Some types are not consumed by the pipemodel
Missing types:
{'vfclass', 'vimovxv', 'vmov', 'rdfrm', 'wrfrm', 'ghost', 'wrvxrm', 'crypto', 'vwsll', 'vfmovfv', 'vimovvx', 'sf_vc', 'vfmovvf', 'sf_vc_se', 'rdvlenb', 'vbrev', 'vrev8', 'sf_vqmacc', 'sf_vfnrclip', 'vsetvl_pre', 'rdvl', 'vsetvl'}
```
Gaius Mulley [Sun, 29 Jun 2025 23:26:03 +0000 (00:26 +0100)]
[PR modula2/117203] Followup add Delete procedure function
This patch provides GetFileName procedure function for
FIO.File, FileSystem.File and IOChan.ChanId. The
return result from these procedures can be passed into
StringFileSysOp.Unlink to complete the required delete.
gcc/m2/ChangeLog:
PR modula2/117203
* gm2-libs-log/FileSystem.def (GetFileName): New
procedure function.
(WriteString): New procedure.
* gm2-libs-log/FileSystem.mod (GetFileName): New
procedure function.
(WriteString): New procedure.
* gm2-libs/SFIO.def (GetFileName): New procedure function.
* gm2-libs/SFIO.mod (GetFileName): New procedure function.
* gm2-libs-iso/IOChanUtils.def: New file.
* gm2-libs-iso/IOChanUtils.mod: New file.
PR modula2/117203
* gm2/isolib/run/pass/testdelete2.mod: New test.
* gm2/pimlib/logitech/run/pass/testdelete2.mod: New test.
* gm2/pimlib/run/pass/testdelete.mod: New test.
Robert Dubner [Sun, 29 Jun 2025 14:54:36 +0000 (10:54 -0400)]
cobol: Normalize generating and using function_decls.
Because COBOL doesn't require function prototypes, it is possible to, for
example,
CALL "getcwd" USING <parameters>
and then later
CALL "getcwd" USING <parameters> RETURNING <alphanumeric>
The second call "knows" that the return value is a char*, but the first one
does not. So, the first one gets a default return value type of SSIZE_t, which
later needs to be replaced with CHAR_P.
These [all too] extensive changes ensure that all references to a particular
function use the same function_decl, and take measures to make sure that one
function_decl is back-modified, if necessary, with the best return value type.
Filip Kastl [Sun, 29 Jun 2025 08:16:35 +0000 (10:16 +0200)]
contrib/mklog.py: Fix writing to a global variable
The last patch of mklog.py put top-level code into function 'main()'.
Because of this, writing to global variable 'root' has to be preceded by
explicitly declaring 'root' as global. Otherwise the write only has a
local effect.
Without this change, the '-d' cmdline flag would be broken.
Commited as obvious.
contrib/ChangeLog:
* mklog.py: In 'main()', specify variable 'root' as global.
Eric Botcazou [Sat, 28 Jun 2025 15:42:26 +0000 (17:42 +0200)]
Fix compilation of concatenation with illegal character constant
This fixes an error recovery issue, whereby the compilation of a string
concatenation with an illegal character constant hangs.
gcc/ada/
PR ada/120854
* sem_eval.adb (Get_String_Val): Be prepared for an integer literal
after a serious error is detected, and raise PE on other nodes.
gcc/testsuite/
* gnat.dg/concat6.adb: New test.
Nathaniel Shead [Fri, 27 Jun 2025 08:56:25 +0000 (18:56 +1000)]
c++/modules: Make bitfield storage unit detection more robust
Modules streaming needs to handle these differently from other unnamed
FIELD_DECLs that are streamed for internal RECORD_DECLs, and there
doesn't seem to be a good way to detect this case otherwise.
This matters only to allow for compiler-generated type definitions that
build FIELD_DECLs with no name, as otherwise they get confused.
Currently the only such types left I hadn't earlier fixed by giving
names to are contextless, for which we have an early check to mark their
fields as MK_unique anyway, but there may be other cases in the future.
gcc/cp/ChangeLog:
* module.cc (trees_out::walking_bit_field_unit): New flag.
(trees_out::trees_out): Initialize it.
(trees_out::core_vals): Set it.
(trees_out::get_merge_kind): Use it, move previous ad-hoc check
into assertion.
Nathaniel Shead [Mon, 23 Jun 2025 12:24:22 +0000 (22:24 +1000)]
c++/modules: Ensure type of partial spec VAR_DECL is consistent with its template [PR120644]
We were erroring because the TEMPLATE_DECL of the existing partial
specialisation has an undeduced return type, but the imported
declaration did not.
The root cause is similar to what was fixed in r13-2744-g4fac53d6522189,
where modules streaming code assumes that a TEMPLATE_DECL and its
DECL_TEMPLATE_RESULT will always have the same TREE_TYPE. That commit
fixed the issue by ensuring that when the type of a variable is deduced
the TEMPLATE_DECL is updated as well, but missed handling partial
specialisations. This patch ensures that the same adjustment is made
there as well.
PR c++/120644
gcc/cp/ChangeLog:
* decl.cc (cp_finish_decl): Also propagate type to partial
templates.
* module.cc (trees_out::decl_value): Add assertion that the
TREE_TYPE of a streamed template decl matches its inner.
(trees_in::is_matching_decl): Clarify function return type
deduction should only occur for non-TEMPLATE_DECL.
* pt.cc (template_for_substitution): Handle partial specs.
gcc/testsuite/ChangeLog:
* g++.dg/modules/auto-7.h: New test.
* g++.dg/modules/auto-7_a.H: New test.
* g++.dg/modules/auto-7_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com> Reviewed-by: Patrick Palka <ppalka@redhat.com>
Jan Hubicka [Sat, 28 Jun 2025 03:02:27 +0000 (05:02 +0200)]
Fix handling of dwarf name and duplicated names
I have tested Kugan's patch on exchange2 and noticed multiple problems:
1) with LTO the translation from dwarf names to symbol names is disabled
since we free lang data sooner. I moved the offline pass upstream which
however also may make us miss clones intorduced betwen free lang data
and annotation. This is not very important right now and may be furhter
fixed by splitting off auto-profile-read and offline passes.
2) I noticed that we miss a lot of AFDO inlines because some code compares
name indexes for equality in belief that it compares symbol names. This
is not ture if we drop prefixes. For this reason I integrated get_original_name
into the renaming machinery which actually updates indexes so string table
conitnues to work as symbol table.
This lets me to drop
afdo_string_table->get_index (afdo_string_table->get_name (other->name ()))
hops that were introduced at some places
Now after renaming all afdo instances should go by DECL_ASSEMBLER_NAME
names.
3) Detection of realized offline instances had an ordering issue where we
omitted marking of those that were offlined later. Since we can now
lookup assembler names, I simplified the logic into single-pass.
* auto-profile.cc (get_original_name): Only strip suffixes introduced
after auto-fdo annotation.
(string_table::get_index_by_decl): Simplify.
(string_table::add_name): New member function.
(string_table::read): Micro-optimize allocation.
(function_instance::get_function_instance_by_decl): Dump reasons
for failure; try to compensate lost discriminators.
(function_instance::merge): Simplify sanity check; do not check
for realized flag; fix merging of targets.
(function_instance::offline_if_in_set): Simplify.
(function_instance::dump): Sanity check that names are consistent.
(autofdo_source_profile::offline_external_functions): Also handle
stripping suffixes.
(walk_block): Move up in source.
(autofdo_source_profile::offline_unrealized_inlines): Also compute
realized functions.
(autofdo_source_profile::get_function_instance_by_name_index): Simplify.
(autofdo_source_profile::add_function_instance): Simplify.
(autofdo_source_profile::read): Do not strip suffxies; error on duplicates.
(mark_realized_functions): Remove.
(auto_profile): Do not call mark_realized_functions.
* passes.def: Move auto_profile_offline before free_lang_data.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-prof/clone-test.c: New test.
* gcc.dg/tree-prof/clone-merge-1.c: Updae template.
Eric Botcazou [Fri, 27 Jun 2025 21:47:49 +0000 (23:47 +0200)]
Fix misoptimization of CONSTRUCTOR with reverse SSO
fold_ctor_reference already punts on a CONSTRUCTOR whose type has reverse
storage order, but it can be invoked in a couple of places on a CONSTRUCTOR
with native storage order that has been wrapped in a VIEW_CONVERT_EXPR to a
type with reverse storage order; this would require a post adjustment that
does not currently exist, thus yield wrong code for this admittedly quite
pathological (but supported) case.
gcc/
* gimple-fold.cc (fold_const_aggregate_ref_1) <COMPONENT_REF>:
Bail out immediately if the reference has reverse storage order.
* tree-ssa-sccvn.cc (fully_constant_vn_reference_p): Likewise.
gcc/testsuite/
* gnat.dg/sso20.adb: New test.
The following patch implements the C++26
P3533R2 - constexpr virtual inheritance
paper.
The changes include not rejecting it for C++26, tweaking the
error wording to show that it is valid in C++26, adjusting
synthesized_method_walk not to make synthetized cdtors non-constexpr
just because of virtual base classes in C++26 and various tweaks in
constexpr.cc so that it can deal with the expressions used for
virtual base member accesses or cdtor calls which need __in_chrg
and/or __vtt_parm arguments to be passed in some cases implicitly when
they aren't passed explicitly. And dynamic_cast constant evaluation
tweaks so that it handles also expressions with types with virtual bases.
2025-06-27 Jakub Jelinek <jakub@redhat.com>
PR c++/120777
gcc/
* gimple-fold.cc (gimple_get_virt_method_for_vtable): Revert
2018-09-18 changes.
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Predefine
__cpp_constexpr_virtual_inheritance=202506L for C++26.
gcc/cp/
* constexpr.cc: Implement C++26 P3533R2 - constexpr virtual
inheritance.
(is_valid_constexpr_fn): Don't reject constexpr cdtors in classes
with virtual bases for C++26, adjust error wording.
(cxx_bind_parameters_in_call): Add ORIG_FUN argument, add
values for __in_chrg and __vtt_parm arguments when needed.
(cxx_eval_dynamic_cast_fn): Adjust function comment, HINT -1
should be possible. For C++26 if obj is cast from POINTER_PLUS_EXPR,
attempt to use cxx_fold_indirect_ref to simplify it and if successful,
build ADDR_EXPR of that.
(cxx_eval_call_expression): Add orig_fun variable, set it to
fun before looking through clones, pass it to
cxx_bind_parameters_in_call.
(reduced_constant_expression_p): Add SZ argument, pass DECL_SIZE
of FIELD_DECL e.index to recursive calls and don't return false
if SZ is non-NULL and there are unfilled fields with bit position
at or above SZ.
(cxx_fold_indirect_ref_1): Handle reading of vtables using
ptrdiff_t dynamic type instead of some pointer type. Set el_sz
to DECL_SIZE_UNIT value rather than TYPE_SIZE_UNIT of
DECL_FIELD_IS_BASE fields in classes with virtual bases.
(cxx_fold_indirect_ref): In canonicalize_obj_off lambda look
through COMPONENT_REFs with DECL_FIELD_IS_BASE in classes with
virtual bases and adjust off correspondingly. Remove assertion that
off is integer_zerop, pass tree_to_uhwi (off) instead of 0 to the
cxx_fold_indirect_ref_1 call.
* cp-tree.h (publicly_virtually_derived_p): Declare.
(reduced_constant_expression_p): Add another tree argument defaulted
to NULL_TREE.
* method.cc (synthesized_method_walk): Don't clear *constexpr_p
if there are virtual bases for C++26.
* class.cc (build_base_path): Compute fixed_type_p and
virtual_access before checks for build_simple_base_path instead of
after that and conditional cp_build_addr_expr. Use build_simple_path
if !virtual_access even when v_binfo is non-NULL.
(layout_virtual_bases): For build_base_field calls use
access_public_node rather than access_private_node if
publicly_virtually_derived_p.
(build_vtbl_initializer): Revert 2018-09-18 and 2018-12-11 changes.
(publicly_virtually_derived_p): New function.
gcc/testsuite/
* g++.dg/cpp26/constexpr-virt-inherit1.C: New test.
* g++.dg/cpp26/constexpr-virt-inherit2.C: New test.
* g++.dg/cpp26/constexpr-virt-inherit3.C: New test.
* g++.dg/cpp26/feat-cxx26.C: Add __cpp_constexpr_virtual_inheritance
tersts.
* g++.dg/cpp2a/constexpr-dtor3.C: Don't expect one error for C++26.
* g++.dg/cpp2a/constexpr-dtor16.C: Don't expect errors for C++26.
* g++.dg/cpp2a/constexpr-dynamic10.C: Likewise.
* g++.dg/cpp0x/constexpr-ice21.C: Likewise.
* g++.dg/cpp0x/constexpr-ice4.C: Likewise.
* g++.dg/abi/mangle1.C: Guard the test on c++23_down.
* g++.dg/abi/mangle81.C: New test.
* g++.dg/ipa/ipa-icf-4.C (A::A): For
__cpp_constexpr_virtual_inheritance >= 202506L add user provided
non-constexpr constructor.
In powerpc64-unknown-linux-musl, signal.h does not include asm/ptrace.h,
which causes "member access into incomplete type 'struct pt_regs'"
errors. Include the header explicitly to fix this.
Also in sanitizer_linux_libcdep.cpp, there is a usage of TlsPreTcbSize
which is not defined in such a platform. Guard the branch with macro.
Harald Anlauf [Fri, 27 Jun 2025 21:00:48 +0000 (23:00 +0200)]
Fortran: follow-up fix to checking of renamed-on-use interface name [PR120784]
Commit r16-1633 introduced a regression for imported interfaces that were
not renamed-on-use, since the related logic did not take into account that
the absence of renaming could be represented by an empty string.