Bob Duff [Thu, 6 Mar 2025 19:21:51 +0000 (14:21 -0500)]
ada: Back out removal of renaming tranformation
A previous change (commit 33eebd96d27fa2b29cec79f55167a11aaf7f4802)
removed code in Analyze_Object_Renaming that tranformed renamings
into object declarations. This reinstates that code.
Removing the code causes failures in
gnatbugs-large/2023/gnat-435_deep_blue_capital.
Ideally, we SHOULD remove that transformation at some point,
but that will require further changes.
gcc/ada/ChangeLog:
* exp_ch6.adb: (Make_Build_In_Place_Call_In_Object_Declaration):
Deal with renamings transformed into object declarations.
* sem_ch8.adb (Analyze_Object_Renaming):
Reinstate transformation of a renaming into
an object declaration.
Setting the proper Ekind on object entities was once needed to catch
cases of premature usages. The introduction of Is_Self_Hidden changed
that, so this patch replaces the Mutate_Ekind calls in the natural
place.
Before this patch, the constant mark of object declarations was stripped
in some error situations. This behavior is currently not useful so this
patch removes it.
gcc/ada/ChangeLog:
* sem_ch3.adb (Analyze_Object_Declaration): Tweak error handling.
Piotr Trojanek [Thu, 6 Mar 2025 09:01:35 +0000 (10:01 +0100)]
ada: Specialize syntax error on malformed Abstract_State contract
Syntax for the Abstract_State contract is the same as for extended aggregates,
but conceptually they are completely different. This patch specializes error
messages emitted on syntax errors for these constructs.
gcc/ada/ChangeLog:
* par-ch13.adb (Get_Aspect_Specifications): Save and restore flag while
parsing aspect Abstract_State.
* par-ch2.adb (P_Pragma): Same while parsing pragma Abstract_State.
* par-ch4.adb (P_Aggregate_Or_Paren_Expr): Specialize error message
for contract Abstract_State and extended aggregate.
* par.adb (Inside_Abstract_State): Add new context flag.
Before this patch, Build_Static_Dispatch_Tables was called on generic
package bodies. While this has not been proved to cause any actual bug,
it was clearly inappropriate and also useless, so this patch removes
those calls.
Piotr Trojanek [Wed, 5 Mar 2025 10:19:22 +0000 (11:19 +0100)]
ada: Tune recent change for warning about unsupported overlays
Fix crash occurring when overlay applies to protected component and expansion
is disabled, e.g. because of semantic checking mode (switch -gnatc) or because
the compiler is running in GNATprove mode.
Also, simply pick the type of overlaid object from the attribute prefix itself.
gcc/ada/ChangeLog:
* sem_util.adb (Find_Overlaid_Entity): Don't call Etype on empty Ent;
tune style; move computation of Overl_Typ out of the loop.
Javier Miranda [Mon, 3 Mar 2025 11:34:35 +0000 (11:34 +0000)]
ada: Pragma Ada_XX not propagated from library level spec to body
Add documentation to pragmas Ada_83, Ada_95, Ada_05, Ada_12,
and Ada_2022: when placed before a library level package
specification they are not propagated to the corresponding
package body; they must be added explicitly to the package
body.
This patch removes a special exemption in Enter_Name. That exemption was
preceded by a comment which described what situations it was supposed to
be required for, but it was unnecessary even in those situations.
gcc/ada/ChangeLog:
* sem_util.adb (Enter_Name): Remove special handling.
This patch removes a comment that misleadingly presented a condition as
being met only in rare situations, while it's in fact satisfied in very
basic cases such as simple object declarations.
Bob Duff [Tue, 4 Mar 2025 19:47:41 +0000 (14:47 -0500)]
ada: Constraint check on tagged build-in-place object decls
In the case of "X : T := F (...);", where T is a constrained
discriminated tagged subtype, perform a constraint check
after F returns. The result of F is allocated by the callee
on the secondary stack in this case.
Note that there are still missing checks for some build-in-place
calls.
gcc/ada/ChangeLog:
* exp_ch6.adb: Remove a couple of "???" suggesting something that
we will likely never do.
(Make_Build_In_Place_Call_In_Object_Declaration):
When a constraint check is needed, do the check.
Do it at the call site for now.
The check is still missing in the untagged case,
because the caller allocates in that case.
* sem_ch8.adb (Analyze_Object_Renaming):
Remove obsolete transformation of a renaming into
an object declaration. Given that we also (sometimes) tranform
object declarations into renamings, this transformation was
adding complexity; the new code in
Make_Build_In_Place_Call_In_Object_Declaration above
would need to explicitly avoid the run-time check in the case of
renamings, because renamings are supposed to ignore the nominal
subtype. Anyway, it is no longer needed.
* exp_ch3.adb (Expand_N_Object_Declaration): Rewrite comment;
it IS clear how to do it, but we haven't done it right yet.
ada: Remove incorrect bits in Copy_Node documentation
This patch removes a leftover reference to the concept of node extension
and a note about aspect specification that's been incorrect since at
least the latest rework of aspect specification representation.
Marc Poulhiès [Tue, 25 Feb 2025 15:50:04 +0000 (16:50 +0100)]
ada: Emit more warnings on unsupported overlay
In the case where the overlaid object is nested in a record or is an
array element as in:
for Foo'Address use Item.Nested_Item'Address;
or for Foo'Address use Item (Bar)'Address;
the compiler was not emitting a warning in case of differing
Scalar_Storage_Order values.
gcc/ada/ChangeLog:
* sem_util.adb (Find_Overlaid_Entity): Add extra parameter to
extract the type being overlaid.
(Note_Possible_Modification): Adjust call to Find_Overlaid_Entity.
(Ultimate_Overlaid_Entity): Likewise.
* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Likewise.
* sem_util.ads (Find_Overlaid_Entity): Add extra parameter to
extract the type being overlaid.
* freeze.adb (Check_Address_Clause): Likewise.
Gary Dismukes [Fri, 28 Feb 2025 00:08:19 +0000 (00:08 +0000)]
ada: Incorrect creation of corresponding expression of class-wide contracts
GNAT was incorrectly implementing the Ada rules for resolving calls to
primitive functions within inherited class-wide pre- and postconditions,
as specified in RM22 6.1.1 (relating to AI12-0113). Only function calls
that involve formals of the associated primitive subprogram should be
treated using the "(notional) formal derived type" rules. In particular,
calls that are tag-indeterminate (for example, "F(G)") should not be mapped
to call the corresponding primitives of the derived type (they should still
call the primitives of the ancestor type). The fix for this involves a new
predicate function that recursively traverses calls to determine the calls
that satisfy the criteria for mapping. These changes also completely remove
the mapping of formals that was done in Contracts.Merge_Class_Conditions
(in Inherit_Condition), since the mapping will be done later anyway by
Build_Class_Wide_Expression, and the earlier mapping interferes with that.
Note: The utility function Sem_Util.Check_Parents is no longer called
after removal of the single call to it from contracts.adb, but it's being
retained (along with the generic subprograms in Atree that it depends on)
for possible use in VAST.
gcc/ada/ChangeLog:
* contracts.adb (Inherit_Condition): Remove Assoc_List and its uses
along with function Check_Condition, since mapping of formals will
effectively be done in Build_Class_Wide_Expression (by Replace_Entity).
* exp_util.adb (Replace_Entity): Only rewrite entity references in
function calls that qualify according to the result of calling the
new function Call_To_Parent_Dispatching_Op_Must_Be_Mapped.
(Call_To_Parent_Dispatching_Op_Must_Be_Mapped): New function that
determines whether a function call to a primitive of Par_Subp
associated tagged type needs to be mapped (according to whether
it has any actuals that reference controlling formals of the
primitive).
ada: Clarify warning in Atree.Rewrite documentation
The documentation of Atree.Rewrite warns about a potential misuse of
that subprogram. This patch makes the text of that warning more specific.
The documentation of Atree.Replace had the same note but this patch
replaces it with a mention of the one in Rewrite's documentation.
This patch visually packs together the statements that implement the
exceptions in Rewrite that a few fields are not actually overwritten, in
order to improve the readability of the code.
Is_Object returns True for "record field" entities, which might make
sense in some contexts but not when Kill_Current_Values is called in a
default expression of a record component. This patch refines the choice
of considered entities in Kill_Current_Values accordingly.
Eric Botcazou [Thu, 27 Feb 2025 19:43:04 +0000 (20:43 +0100)]
ada: Fix spurious error on anonymous array initialized by conditional expression
Even though the actual subtype of the anonymous array is not yet set on the
object itself by the time Insert_Conditional_Object_Declaration is called,
it is set on its initialization expression, so it can simply be forwarded
to Insert_Conditional_Object_Declaration from there, which avoids creating
a new one for each new object and triggering a subtype mismatch later.
gcc/ada/ChangeLog:
* exp_ch4.adb (Insert_Conditional_Object_Declaration): Remove Decl
formal parameter, add Typ and Const formal parameters.
(Expand_N_Case_Expression): Fix pasto in comment. Adjust call to
Insert_Conditional_Object_Declaration and tidy up surrounding code.
(Expand_N_If_Expression): Adjust couple of calls to
Insert_Conditional_Object_Declaration.
Tamar Christina [Mon, 9 Jun 2025 06:03:27 +0000 (07:03 +0100)]
middle-end: Add new parameter to scale scalar loop costing in vectorizer
This patch adds a new param vect-scalar-cost-multiplier to scale the scalar
costing during vectorization. If the cost is set high enough and when using
the dynamic cost model it has the effect of effectively disabling the
costing vs scalar and assumes all vectorization to be profitable.
This is similar to using the unlimited cost model, but unlike unlimited it
does not fully disable the vector cost model. That means that we still
perform comparisons between vector modes. And it means it also still does
costing for alias analysis.
As an example, the following:
void
foo (char *restrict a, int *restrict b, int *restrict c,
int *restrict d, int stride)
{
if (stride <= 1)
return;
for (int i = 0; i < 3; i++)
{
int res = c[i];
int t = b[i * stride];
if (a[i] != 0)
res = t * d[i];
c[i] = res;
}
}
compiled with -O3 -march=armv8-a+sve -fvect-cost-model=dynamic fails to
vectorize as it assumes scalar would be faster, and with
-fvect-cost-model=unlimited it picks a vector type that's so big that the large
sequence generated is working on mostly inactive lanes:
...
and p3.b, p3/z, p4.b, p4.b
whilelo p0.s, wzr, w7
ld1w z23.s, p3/z, [x3, #3, mul vl]
ld1w z28.s, p0/z, [x5, z31.s, sxtw 2]
add x0, x5, x0
punpklo p6.h, p6.b
ld1w z27.s, p4/z, [x0, z31.s, sxtw 2]
and p6.b, p6/z, p0.b, p0.b
punpklo p4.h, p7.b
ld1w z24.s, p6/z, [x3, #2, mul vl]
and p4.b, p4/z, p2.b, p2.b
uqdecw w6
ld1w z26.s, p4/z, [x3]
whilelo p1.s, wzr, w6
mul z27.s, p5/m, z27.s, z23.s
ld1w z29.s, p1/z, [x4, z31.s, sxtw 2]
punpkhi p7.h, p7.b
mul z24.s, p5/m, z24.s, z28.s
and p7.b, p7/z, p1.b, p1.b
mul z26.s, p5/m, z26.s, z30.s
ld1w z25.s, p7/z, [x3, #1, mul vl]
st1w z27.s, p3, [x2, #3, mul vl]
mul z25.s, p5/m, z25.s, z29.s
st1w z24.s, p6, [x2, #2, mul vl]
st1w z25.s, p7, [x2, #1, mul vl]
st1w z26.s, p4, [x2]
...
With -fvect-cost-model=dynamic --param vect-scalar-cost-multiplier=200
you get more reasonable code:
foo:
cmp w4, 1
ble .L1
ptrue p7.s, vl3
index z0.s, #0, w4
ld1b z29.s, p7/z, [x0]
ld1w z30.s, p7/z, [x1, z0.s, sxtw 2]
ptrue p6.b, all
cmpne p7.b, p7/z, z29.b, #0
ld1w z31.s, p7/z, [x3]
mul z31.s, p6/m, z31.s, z30.s
st1w z31.s, p7, [x2]
.L1:
ret
This model has been useful internally for performance exploration and cost-model
validation. It allows us to force realistic vectorization overriding the cost
model to be able to tell whether it's correct wrt to profitability.
gcc/ChangeLog:
* params.opt (vect-scalar-cost-multiplier): New.
* tree-vect-loop.cc (vect_estimate_min_profitable_iters): Use it.
* doc/invoke.texi (vect-scalar-cost-multiplier): Document it.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/sve/cost_model_16.c: New test.
Nathan Myers [Wed, 4 Jun 2025 18:52:29 +0000 (14:52 -0400)]
libstdc++: sstream from string_view (P2495R3) [PR119741]
Add constructors to stringbuf, stringstream, istringstream, and ostringstream,
and a matching overload of str(sv) in each, that take anything convertible to
a string_view in places where the existing ctors and function take a string.
Note this change omits the constraint applied to the istringstream constructor
from string cited as a "drive-by" in P2495R3, as we have determined it is
redundant.
libstdc++-v3/ChangeLog:
PR libstdc++/119741
* include/std/sstream: full implementation, really just
decls, requires clause and plumbing.
* include/bits/version.def, include/bits/version.h:
new preprocessor symbol
__cpp_lib_sstream_from_string_view.
* testsuite/27_io/basic_stringbuf/cons/char/string_view.cc:
New tests.
* testsuite/27_io/basic_istringstream/cons/char/string_view.cc:
New tests.
* testsuite/27_io/basic_ostringstream/cons/char/string_view.cc:
New tests.
* testsuite/27_io/basic_stringstream/cons/char/string_view.cc:
New tests.
* testsuite/27_io/basic_stringbuf/cons/wchar_t/string_view.cc:
New tests.
* testsuite/27_io/basic_istringstream/cons/wchar_t/string_view.cc:
New tests.
* testsuite/27_io/basic_ostringstream/cons/wchar_t/string_view.cc:
New tests.
* testsuite/27_io/basic_stringstream/cons/wchar_t/string_view.cc:
New tests.
Pan Li [Sun, 8 Jun 2025 08:48:33 +0000 (16:48 +0800)]
RISC-V: Combine vec_duplicate + vrem.vv to vrem.vx on GR2VR cost
This patch would like to combine the vec_duplicate + vrem.vv to the
vrem.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, OP) \
void \
test_vx_binary (T * restrict out, T * restrict in, T x, unsigned n) \
{ \
for (unsigned i = 0; i < n; i++) \
out[i] = in[i] OP x; \
}
* config/riscv/riscv-v.cc (expand_vx_binary_vec_vec_dup): Add new
case MOD.
* config/riscv/riscv.cc (riscv_rtx_costs): Ditto.
* config/riscv/vector-iterators.md: Add new op mod.
As described in prior patches of this series, FRM mode switching state
machine has special handling around calls. After a call_insn, if in DYN_CALL
state, it needs to transition back to DYN, which requires back checking
if prev insn was indeed a call.
Defering/delaying this could lead to unncessary final transitions leading
to extraenous FRM save/restores.
However the current back checking of call_insn was too coarse-grained.
It used prev_nonnote_nondebug_insn_bb () which implies current insn to
be in the same BB as the call_insn, which need not always be true.
The problem is not with the API, but the use thereof.
Fix this by tracking call_insn more explicitly in TARGET_MODE_NEEDED.
- On seeing a call_insn, record a "call note".
- On subsequent insns if a "call note" is seen, do the needed state switch
and clear the note.
- Remove the old BB based search.
The number of FRM read/writes across SPEC2017 -Ofast -mrv64gcv improves.
While this was a missed-optimization exercise, testing exposed a latent
bug as additional testsuite failure, captured as PR120203. The existing
test float-point-dynamic-frm-74.c was missing FRM save after a call
which this fixes (as a side-effect of robust call state tracking).
Vineet Gupta [Sun, 8 Jun 2025 21:55:01 +0000 (14:55 -0700)]
RISC-V: frm/mode-switch: Reduce FRM restores on DYN transition [PR119164]
FRM mode switching state machine has DYN as default state which it also
fallsback to after transitioning to other states such as DYN_CALL.
Currently TARGET_MODE_EMIT generates a FRM restore on any transition to
DYN leading to spurious/extraneous FRM restores.
Only do this if an interim static Rounding Mode was observed in the state
machine.
Fixes the extraneous FRM read/write in PR119164 (and also PR119832 w/o need
for TARGET_MODE_CONFLUENCE). Also reduces the number of FRM writes in
SPEC2017 -Ofast -mrv64gcv build significantly.
Vineet Gupta [Sun, 8 Jun 2025 21:54:37 +0000 (14:54 -0700)]
RISC-V: frm/mode-switch: remove dubious frm edge insertion before call_insn
This showed up when debugging the testcase for PR119164.
RISC-V FRM mode-switching state machine has special handling for transitions
to and from a call_insn as FRM needs to saved/restored around calls
despite it not being a callee-saved reg; rather it's a "global" reg
which can be temporarily modified "locally" with a static RM.
Thus a call needs to see the prior global state, hence the restore (from a
prior backup) before the call. Corollarily any call can potentially clobber
the FRM, thus post-call it needs to be it needs to be re-read/saved.
The following example demostrate this:
- insns 2, 4, 6 correspond to actual user code,
- rest 1, 3, 5, 6 are frm save/restore insns generated by mode switch for the
above described ABI semantics.
Current implementation of RISC-V TARGET_MODE_NEEDED has special handling
if the call_insn is last insn of BB, to ensure FRM save/reads are emitted
on all the edges. However it doesn't work as intended and is borderline
bogus for following reasons:
- It fails to detect call_insn as last of BB (PR119164 test) if the
next BB starts with a code label (say due to call being conditional).
Granted this is a deficiency of API next_nonnote_nondebug_insn_bb ()
which incorrectly returns next BB code_label as opposed to returning
NULL (and this behavior is kind of relied upon by much of gcc).
This causes missed/delayed state transition to DYN.
- If code is tightened to actually detect above such as:
- rtx_insn *insn = next_nonnote_nondebug_insn_bb (cur_insn);
- if (!insn)
+ if (BB_END (BLOCK_FOR_INSN (cur_insn)) == cur_insn)
edge insertion happens but ends up splitting the BB which generic
mode-sw doesn't expect and ends up hittng an ICE.
- TARGET_MODE_NEEDED hook typically don't modify the CFG.
- For abnormal edges, insert_insn_end_basic_block () is called, which
by design on encountering call_insn as last in BB, inserts new insn
BEFORE the call, not after.
So this is just all wrong and ripe for removal. Moreover there seems to
be no testsuite coverage for this code path at all. Results don't change
at all if this is removed.
The total number of FRM read/writes emitted (static count) across all
benchmarks of a SPEC2017 -Ofast -march=rv64gcv build decrease slightly
so its a net win even if minimal but the real gain is reduced complexity
and maintenance.
Andrew Pinski [Fri, 6 Jun 2025 18:34:48 +0000 (11:34 -0700)]
phi-opt: Do limited form of cselim from phiopt [PR120533]
So currently cselim is limited to targets which have conditional move
and also happens later in the pipeline. This adds the limited form of cselim;
where there is only one store in the two sides and no loads after the store.
This fixes phiprop-2.c for gcn target and now can match the MIN in phiopt1
so it moves the matching of MIN to phiopt1.
The other testcases already disable cselim so they need to disable phiopt too.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/120533
gcc/ChangeLog:
* tree-ssa-phiopt.cc (cond_if_else_store_replacement_limited): New function.
(pass_phiopt::execute): Call cond_if_else_store_replacement_limited
for diamand case.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr35286.c: Add -fno-ssa-phiopt.
* gcc.dg/tree-ssa/split-path-6.c: Likewise.
* gcc.dg/tree-ssa/split-path-7.c: Likewise.
* gcc.dg/tree-ssa/phiprop-2.c: Move the check for MIN_EXPR to phiopt1.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Andrew Pinski [Fri, 6 Jun 2025 18:07:57 +0000 (11:07 -0700)]
cselim: change how to detect no load/stores after store in single_trailing_store_in_bb
So the current code iterates through the uses of the vdef of the store to see if there
is an use of the vdef inside the bb. Except in this case we know the only usage will
be a phi node, so change the loop into calling single_imm_use and then checking if the
usage statement was the PHI node.
Bootstrapped and tested on x86_64-linux-gnu.
Also did a quick test by adding a return false after the checks of single_trailing_store_in_bb
in cond_if_else_store_replacement to make sure this code still does the correct thing.
gcc/ChangeLog:
* tree-ssa-phiopt.cc (single_trailing_store_in_bb): Add vphi argument.
Check for single use of the vdef of the store instead of a loop
and check vdef's single use statement is the same as vphi.
(cond_if_else_store_replacement): Update call to single_trailing_store_in_bb.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Andrew Pinski [Sun, 8 Jun 2025 18:12:46 +0000 (11:12 -0700)]
cselim: Use get_virtual_phi instead of a loop in cond_if_else_store_replacement
Don't inline finding of the virtual op phi node, instead use get_virtual_phi.
This is based on the review of a different patch (https://gcc.gnu.org/pipermail/gcc-patches/2025-June/686076.html).
Pushed as obvious after a bootstrap/test on x86_64-linux-gnu.
gcc/ChangeLog:
* tree-ssa-phiopt.cc (cond_if_else_store_replacement): Use get_virtual_phi
instead of inlining it.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Shreya Munnangi [Sun, 8 Jun 2025 14:42:53 +0000 (08:42 -0600)]
[RISC-V] Handle 32bit operands in condition for conditional moves
So here's the next chunk of conditional move work from Shreya.
It's been a long standing wart that the conditional move expander does not
support sub-word operands in the comparison. Particularly since we have
support routines to handle the necessary extensions for that case.
This patch adjusts the expander to use riscv_extend_comparands rather than fail
for that case. I've built spec2017 before/after this and we definitely get
more conditional moves and they look sensible from a performance standpoint.
None are likely hitting terribly hot code, so I wouldn't expect any performance
jumps.
Waiting on pre-commit testing to do its thing.
gcc/
* config/riscv/riscv.cc (riscv_expand_conditional_move): Use
riscv_extend_comparands to extend sub-word comparison arguments.
xtensa: Implement l(ceil|floor)sfsi2 insn patterns and their scaled variants
By using the previously unused CEIL|FLOOR.S floating-point coprocessor
instructions. In addition, two instruction operand format codes are added
to output the scale value as assembler source.
/* example */
int test0(float a) {
return __builtin_lceilf(a);
}
int test1(float a) {
return __builtin_lceilf(a * 2);
}
int test2(float a) {
return __builtin_lfloorf(a);
}
int test3(float a) {
return __builtin_lfloorf(a * 32768);
}
However, because the rounding-half behavior (e.g., the rule that determines
whether 1.5 should be rounded to 1 or 2) of the two is inconsistent;
the lroundsfsi2 pattern is explicitly specified that rounding to nearest
integer and away from zero, but the other hand, the ROUND.S instruction is
not specified that by the ISA and is implementation-dependent.
Therefore lroundsfsi2 cannot be implemented by ROUND.S.
gcc/ChangeLog:
* config/xtensa/xtensa.cc (printx, print_operand):
Add two instruction operand format codes 'U' and 'V',
whose represent scale factors of 0 to 15th positive/negative
power of two.
* config/xtensa/xtensa.md (c_enum "unspec"):
Add UNSPEC_CEIL and UNSPEC_FLOOR.
(int_iterator ANY_ROUND, int_attr m_round):
New integer iterator and its attribute.
(fix<s_fix>_truncsfsi2, *fix<s_fix>_truncsfsi2_2x,
*fix<s_fix>_truncsfsi2_scaled, float<s_float>sisf2,
*float<s_float>sisf2_scaled):
Use output templates with the operand formats added above,
instead of individual output statements.
(l<m_round>sfsi2, *l<m_round>sfsi2_2x, *l<m_round>sfsi2_scaled):
New insn patterns.
In commit 5e918a4db9e4a5bdbeafec6881fa8b22a55d3789, regenerated files
were not included in the commit as they should have been. Therefore, a
whitespace fix was not propagated. Sync generated files now, as obtained
from a run with --enable-maintainer-mode.
Gaius Mulley [Sat, 7 Jun 2025 15:25:19 +0000 (16:25 +0100)]
[PR modula2/119650, PR modula2/117203]: WriteString and Delete are missing from base libraries
This patch introduces a Write procedure for an array of char,
the string and char datatype. It uses the m2r10 style of
naming the module on the datatype. This uncovered a bug
in the import handling inside Quadident. It also includes
an Unlink procedure from a new module FileSysOp and a String
interface to this module.
gcc/m2/ChangeLog:
PR modula2/119650
PR modula2/117203
* gm2-compiler/P2Build.bnf (CheckModuleQualident): New
procedure.
(Qualident): Rewrite.
* gm2-compiler/P3Build.bnf (PushTFQualident): New procedure.
(CheckModuleQualident): Ditto.
(Qualident): Rewrite.
* gm2-compiler/PCBuild.bnf (PushTFQualident): New procedure.
(CheckModuleQualident): Ditto.
(Qualident): Rewrite.
* gm2-compiler/PHBuild.bnf (PushTFQualident): New procedure.
(CheckModuleQualident): Ditto.
(Qualident): Rewrite.
* gm2-libs/ARRAYOFCHAR.def: New file.
* gm2-libs/ARRAYOFCHAR.mod: New file.
* gm2-libs/CFileSysOp.def: New file.
* gm2-libs/CHAR.def: New file.
* gm2-libs/CHAR.mod: New file.
* gm2-libs/FileSysOp.def: New file.
* gm2-libs/FileSysOp.mod: New file.
* gm2-libs/String.def: New file.
* gm2-libs/String.mod: New file.
* gm2-libs/StringFileSysOp.def: New file.
* gm2-libs/StringFileSysOp.mod: New file.
libgm2/ChangeLog:
PR modula2/119650
PR modula2/117203
* libm2pim/Makefile.am (M2MODS): Add ARRAYOFCHAR,
CHAR.mod, StringFileSysOp.mod and String.mod.
(M2DEFS): Add ARRAYOFCHAR, CHAR.mod,
StringFileSysOp.mod and String.mod.
(libm2pim_la_SOURCES): Add CFileSysOp.c.
* libm2pim/Makefile.in: Regenerate.
* libm2pim/CFileSysOp.cc: New file.
gcc/testsuite/ChangeLog:
PR modula2/119650
* gm2/iso/fail/CHAR.mod: New test.
* gm2/iso/run/pass/CHAR.mod: New test.
* gm2/iso/run/pass/importself.mod: New test.
* gm2/pimlib/run/pass/testwrite.mod: New test.
* gm2/pimlib/run/pass/testwritechar.mod: New test.
Jeff Law [Sat, 7 Jun 2025 13:48:46 +0000 (07:48 -0600)]
[to-be-committed][RISC-V] Handle 32bit operands in condition for conditional moves
So here's the next chunk of conditional move work from Shreya.
It's been a long standing wart that the conditional move expander does not
support sub-word operands in the comparison. Particularly since we have
support routines to handle the necessary extensions for that case.
This patch adjusts the expander to use riscv_extend_comparands rather than fail
for that case. I've built spec2017 before/after this and we definitely get
more conditional moves and they look sensible from a performance standpoint.
None are likely hitting terribly hot code, so I wouldn't expect any performance
jumps.
Waiting on pre-commit testing to do its thing.
* config/riscv/riscv.cc (riscv_expand_conditional_move): Use
riscv_extend_comparands to extend sub-word comparison arguments.
Andrew Pinski [Sat, 7 Jun 2025 04:50:27 +0000 (21:50 -0700)]
Fix index of some warnings [PR120572]
The problem here is opindex should not include the `-` part of the option.
But Wmusttail-local-addr and Wno-maybe-musttail-local-addr currently do.
This deletes them.
Robert Dubner [Fri, 6 Jun 2025 20:32:22 +0000 (16:32 -0400)]
cobol: Diagnostic messages, Flex build, and some cppcheck reports. [PR120328, PR119695]
Remove %0x and similar from diagnostic framework messages. Remove %zu
from printf messages because it is not supported on some
platforms. Corrections in response to cppcheck. Sundry small fixes.
Jason Merrill [Fri, 6 Jun 2025 14:26:28 +0000 (10:26 -0400)]
c++: recursive template with deduced return [PR120555]
Here since r15-4120 we were prematurely complaining about the use of func
within its own definiton, which is fine at instantiation time. So don't
require this for function templates that are currently being defined.
But keep the error for instantiations of templates that are not currently
being defined, which we similarly did not diagnose before r15-4120 but other
implementations do.
Both of these follow the general principle from [temp.res.general]/6 that we
only error in a template body if no instatiation could be well-formed.
Also remove a redundant call to require_deduced_type.
Jonathan Wakely [Fri, 6 Jun 2025 16:18:40 +0000 (17:18 +0100)]
libstdc++: Add more tests for semaphores
libstdc++-v3/ChangeLog:
* testsuite/30_threads/semaphore/1.cc: Check type properties and
max() values.
* testsuite/30_threads/semaphore/3.cc: New test.
* testsuite/30_threads/semaphore/cons_neg.cc: New test.
Jonathan Wakely [Fri, 6 Jun 2025 13:16:15 +0000 (14:16 +0100)]
libstdc++: Use std::conditional_t instead of lambda to select semaphore implementation
The lambda expression causes testsuite failures such as:
FAIL g++.dg/modules/xtreme-header-2_b.C -std=c++26 (test for excess errors)
libstdc++-v3/ChangeLog:
* include/bits/semaphore_base.h (_Select_semaphore_impl): Rename
to _Semaphore_impl and use std::conditional_t instead of an
immediately invoked lambda expression.
* include/std/semaphore (counting_semaphore): Adjust to use new
name.
David Malcolm [Fri, 6 Jun 2025 17:41:28 +0000 (13:41 -0400)]
diagnostics: introduce xml::doctypedecl to avoid hardcoding html
As further generalization of XML support during prototyping of new
features, don't hardcode the HTML DTD.
gcc/ChangeLog:
* diagnostic-format-html.cc (struct html_doctypedecl): New.
(html_builder::html_builder): Use it to populate the document's
m_doctypedecl.
* xml.cc (xml::document::write_as_xml): Replace hardcoded HTML DTD
with use of m_doctypedecl field.
(selftest::test_no_dtd): New.
(selftest::xml_cc_tests): New.
* xml.h (struct doctypedecl): New decl.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Fri, 6 Jun 2025 17:41:27 +0000 (13:41 -0400)]
diagnostics: move xml defs to a new xml.cc
While prototyping new features I'm finding it helpful to use XML
beyond the "experimental-html" diagnostics sink. Move the
implementation of the xml classes to their own file.
No functional change intended.
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add xml.o.
* diagnostic-format-html.cc (namespace xml): Move implementation
to xml.cc
(selftest::test_printer): Likewise.
(selftest::test_attribute_ordering): Likewise.
(selftest::diagnostic_format_html_cc_tests): Don't call the moved
tests here; they will be called from xml_cc_tests in xml.cc.
* selftest-run-tests.cc (selftest::run_tests): Call xml_cc_tests.
* selftest.h (selftest::xml_cc_tests): New decl.
* xml.cc: New file, based on material from
diagnostic-format-html.cc.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Andrew Pinski [Thu, 5 Jun 2025 22:03:27 +0000 (15:03 -0700)]
cselim: Update the vop manually for cond_if_else_store replacement
To speed up things slightly, we can do the update of the vop for the
newly inserted store manually.
This will also allow a simplified part of cselim to be used inside
phi-opt to move the store out earlier and independent of the full cselim.
gcc/ChangeLog:
* tree-ssa-phiopt.cc (cond_if_else_store_replacement_1): Add vphi argument.
Manually update the vphi and new_stmt vdef/lhs.
(cond_if_else_store_replacement): Update call to cond_if_else_store_replacement_1.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Jonathan Wakely [Wed, 4 Jun 2025 19:09:21 +0000 (20:09 +0100)]
libstdc++: Adjust effective-target requirements for <barrier> and <semaphore>
These features depend on __cpp_lib_atomic_wait which is not available
for freestanding, and is available when either gthreads is supported, or
the target is linux (for futex support).
Jeff Law [Fri, 6 Jun 2025 14:45:53 +0000 (08:45 -0600)]
[committed] Fix compromised ARC test
Jakub's recent changes for pr120231 compromised this arc port specific test.
Essentially we collapse the entire FMA sequence down to a constant and thus
never emit the FMA instruction the test wants to see.
If we make "a" an extern so that we don't know its value the optimizers can't
collapse the calculation away completely and we can verify that we get an FMA
operation.
Pushing to the trunk.
gcc/testsuite
* gcc.target/arc/fma-1.c: Make "a" extern so the optimizers can
see any value and optimize away the key computation.
By adding omp_get_initial_device and omp_get_num_devices builtins for
C, C++, and Fortran, the following can be achieved:
* By making them pure, multiple calls can be avoiding in some cases.
* Some comparisons can be optimized at compile time.
omp_get_initial_device will be converted to omp_get_num_devices for
consistency; note that OpenMP 6 also permits omp_initial_device (== -1)
as value.
If GCC has not been configure for offloading, either intrinsic will
leads to 0 - and on the offload side, -1 (= omp_initial_device) is
returned for omp_initial_device.
gcc/fortran/ChangeLog:
* f95-lang.cc (ATTR_PURE_NOTHROW_LIST): Define.
* trans-expr.cc (get_builtin_fn): Handle omp_get_num_devices
and omp_get_intrinsic_device.
* gfortran.h (gfc_option_t): Add disable_omp_... for them.
* options.cc (gfc_handle_option): Handle them with
-fno-builtin-.
* libgomp.texi (omp_get_num_devices, omp_get_intrinsic_device):
Document builtin handling.
gcc/testsuite/ChangeLog:
* c-c++-common/gomp/omp_get_num_devices_initial_device-2.c: New test.
* c-c++-common/gomp/omp_get_num_devices_initial_device.c: New test.
* gfortran.dg/gomp/omp_get_num_devices_initial_device-2.f90: New test.
* gfortran.dg/gomp/omp_get_num_devices_initial_device.f90: New test.
Tobias Burnus [Fri, 6 Jun 2025 13:57:50 +0000 (15:57 +0200)]
builtins.def: Enable OpenMP/OpenACC builtins also with -fno-nonansi-builtins
The flags -std=c.. and -std=c++.. imply -fno-nonansi-builtins, which disabled
the OpenMP/OpenACC intrinsics - but -fopenmp/-fopenacc builtin use should be
rather othogonal to the user's choice between -std=c... and -std=gnuc...
gcc/ChangeLog:
* builtins.def (DEF_GOACC_BUILTIN_COMPILER, DEF_GOMP_BUILTIN_COMPILER):
Set NONANSI_P = false to enable those also with -fno-nonansi-builtins.
Patrick Palka [Fri, 6 Jun 2025 13:34:17 +0000 (09:34 -0400)]
libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]
The const lvalue operator[] overload wasn't properly forwarding the key
type to the generic overload, causing a hard error for const keys.
Rather than correcting the forwarded type this patch just makes the
non-template overloads call try_emplace directly instead. That way we
can remove the non-standard same_as constraint on the generic overload
and match the spec more closely.
PR libstdc++/120432
libstdc++-v3/ChangeLog:
* include/std/flat_map (flat_map::operator[]): Make the
non-template overloads call try_emplace directly. Remove
non-standard same_as constraint on the template overload.
* testsuite/23_containers/flat_map/1.cc (test08): New test.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Pan Li [Fri, 6 Jun 2025 01:33:21 +0000 (09:33 +0800)]
RISC-V: Combine vec_duplicate + vidvu.vv to vdivu.vx on GR2VR cost
This patch would like to combine the vec_duplicate + vdivu.vv to the
vdivu.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, OP) \
void \
test_vx_binary (T * restrict out, T * restrict in, T x, unsigned n) \
{ \
for (unsigned i = 0; i < n; i++) \
out[i] = in[i] OP x; \
}
The below test suites are passed for this patch.
* The rv64gcv fully regression test.
gcc/ChangeLog:
* config/riscv/riscv-v.cc (expand_vx_binary_vec_vec_dup): Add new
case UDIV.
* config/riscv/riscv.cc (riscv_rtx_costs): Ditto.
* config/riscv/vector-iterators.md: Add new op divu.
Richard Biener [Fri, 6 Jun 2025 10:22:36 +0000 (12:22 +0200)]
Remove non-SLP path from vectorizable_store
This prunes now unreachable paths from vectorizable_store,
eliminates the toplevel ncopies and loops that become non-loops.
And eliminates the use of STMT_VINFO_VECTYPE.
Gaius Mulley [Fri, 6 Jun 2025 09:46:48 +0000 (10:46 +0100)]
PR modula2/120542: Return statement in the main procedure crashes the compiler
The patch checks whether a return statement is allowed. It also checks
to see that a return expression is allowed.
gcc/m2/ChangeLog:
PR modula2/120542
* gm2-compiler/M2Quads.mod (BuildReturnLower): New procedure.
(BuildReturn): Allow return without an expression from
module initialization blocks. Generate an error if an
expression is provided. Call BuildReturnLower if no error
was seen.
gcc/testsuite/ChangeLog:
PR modula2/120542
* gm2/iso/fail/badreturn.mod: New test.
* gm2/iso/fail/badreturn2.mod: New test.
* gm2/iso/pass/modulereturn.mod: New test.
* gm2/iso/pass/modulereturn2.mod: New test.
because the very old code for ARRAY_TYPE in store_constructor is confused in
the case where it cannot perform static host-based arithmetics on offsets.
But the root cause is that it performs all the calculations in signed
sizetype while TYPE_DOMAIN is supposed to be a subtype of (unsigned)
sizetype, even for signed index types in Ada like in the testcase,
so the code takes the dynamic path instead of the static one for
negative indices.
gcc/
* expr.cc (store_constructor) <ARRAY_TYPE>: Perform the arithmetics
on offsets in (unsigned) sizetype.
gcc/testsuite/
* gnat.dg/specs/aggr7.ads: New test.
Jan Hubicka [Fri, 6 Jun 2025 08:56:51 +0000 (10:56 +0200)]
Avoid useless reading of profile data in LTO
New auto-profile merging dumps made me notice that we read the afdo
data when we are in LTO. This is not necessary since profile is read
at compile time and streamed to LTO bytecode.
gcc/ChangeLog:
* coverage.cc (coverage_init): Return early when in LTO
Jonathan Wakely [Wed, 4 Jun 2025 15:58:45 +0000 (16:58 +0100)]
libstdc++: Add assertions to atomic waiting functions that need platform wait
These overloads should never be used for proxy waits, so add assertions
to ensure that they aren't used accidentally.
The reason they can't be used is that they don't call
__args._M_setup_wait to obtain a __wait_state pointer. Even if that was
changed, they would wait on a proxy wait which is potentially used by
many other threads waiting on other addresses, meaning spurious wake ups
are likely. In order to make the functions correct they would need to
perform additional loads and comparisons of the atomic variable before
calling __wait_impl or __wait_until_impl, which would make these
functions no faster than the general purpose overloads that take an
accessor function and predicate. That would be possible, and I think
they would then work for proxy waits, but doesn't seem necessary at this
time.
In order to preseve the property that these functions are more
lightweight and efficient than the general ones, they should not be used
for proxy waits.
libstdc++-v3/ChangeLog:
* include/bits/atomic_timed_wait.h (__atomic_wait_address_until_v):
Add assertion to prevent use with proxy waits.
(__atomic_wait_address_for_v): Likewise.
* include/bits/atomic_wait.h (__atomic_wait_address_v):
Likewise.
Jonathan Wakely [Wed, 4 Jun 2025 14:53:20 +0000 (15:53 +0100)]
libstdc++: Optimize std::counting_semaphore for futex path
Rename __semaphore_base to __semaphore_impl, because it's not used as a
base class. Replace the three identical lambda expressions with a named
class, __semaphore_impl::_Available, which stores the most recent
value of the counter as a data member, and provides call operators that
test whether the value is decrementable (i.e. whether the semaphore can
be acquired).
Add a new __platform_semaphore_impl class template to be used when
__platform_wait is available, which uses __platform_wait_t for the
counter and uses more efficient atomic waits for the acquire functions.
For a binary semaphore some members are further optimized because we
know the counter can only be zero or one.
Also add a bare wait flag to __atomic_wait_address_v, for consistency
with __atomic_wait_address_until_v and __atomic_wait_address_for_v and
to allow semaphores to use it without the redundant overhead of tracking
waiters.
libstdc++-v3/ChangeLog:
* include/bits/atomic_wait.h (__atomic_wait_address_v): Add bare
wait flag.
* include/bits/semaphore_base.h (__semaphore_base): Rename to
__semaphore_impl. Replace local variable and predicate lambdas
with _Available struct.
(__platform_semaphore_impl): New class template.
(__semaphore_impl): Remove alias template.
(_Select_semaphore_impl): New alias template.
* include/std/semaphore (counting_semaphore): Use
_Select_semaphore_impl.
Jan Hubicka [Fri, 6 Jun 2025 08:43:38 +0000 (10:43 +0200)]
More of autofdo 0 issues
This patch fixes ICE seen when building spec2k17 with autofdo and enable
checking compiler. Bause we special case 0 of autofdo to be kind of 1 in IPA
scalling, we can now end up with function heving global0 profile but producing
inline clone with nonzero profile.
I think correct way is to extend auto-profile generation to merge static profile
with afdo in places afdo profile is missing and drop the autofdo 0 hacks, but
I think we need to run benchmarks first before making broader changes here.
* profile-count.cc (profile_count::to_sreal_scale): Special case 0 of autofdo.
(profile_count::combine_with_ipa_count): If outer function has GLOBAL0 profile
but innter counter has non-zero profile, force it to be 0.
Piotr Trojanek [Thu, 27 Feb 2025 10:44:54 +0000 (11:44 +0100)]
ada: Avoid repeated range checks when negating a rational number
Use local constant to avoid repeated range checks (at least in the debug
builds), but also to make the code easier to read and consistent in style
with similar routines in the same package.
gcc/ada/ChangeLog:
* urealp.adb (UR_Negate): Capture array element in a local constant.
Piotr Trojanek [Tue, 18 Feb 2025 13:38:24 +0000 (14:38 +0100)]
ada: Add null exclusion to registration of floating-point types
Null exclusion both clarifies the intention of the code and allows GNAT to
eliminate runtime checks where possible (or make them fail where violated), at
least in developer builds. Code cleanup.
Piotr Trojanek [Wed, 26 Feb 2025 13:02:15 +0000 (14:02 +0100)]
ada: Check references to subprogram outputs with Program_Exit expression
Add check for references to subprogram outputs occurring within the
Program_Exit expression. This check is necessarily partial, as it misses
objects referenced by subprograms called from the Program_Exit expression,
but this is consistent with other checks.
gcc/ada/ChangeLog:
* sem_prag.adb (Analyze_Pragma): Add dependency of Program_Exit on
Global and Depends contracts.
(Analyze_Program_Exit_In_Decl_Part): Check references to subprogram
outputs.
Piotr Trojanek [Thu, 13 Feb 2025 15:39:43 +0000 (16:39 +0100)]
ada: Support aspect Program_Exit with no expression
New aspect Program_Exit for SPARK was originally designed to require an
expression, but now we want this expression to be optional.
gcc/ada/ChangeLog:
* aspects.ads (Aspect_Argument): Argument for Program_Exit is now
optional.
* doc/gnat_rm/implementation_defined_pragmas.rst
(Pragma Program_Exit): Change documentation for pragma syntax.
* sem_prag.adb (Analyze_Pragma): Argument for Program_Exit is now
optional.
(Analyze_Program_Exit_In_Decl_Part): Likewise.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.
Piotr Trojanek [Thu, 13 Feb 2025 15:26:33 +0000 (16:26 +0100)]
ada: Add new aspect Program_Exit for SPARK
A new aspect Program_Exit is added for SPARK to specify that a subprogram
can exit the entire program, e.g. GNAT.System.OS_Exit. The implementation
is based on the existing machinery for similar aspects, in particular, for
aspects Subprogram_Variant and Always_Terminates.
gcc/ada/ChangeLog:
* aspects.ads (Aspect_Id): Add new aspect identifier.
(Aspect_Argument): Specify argument for the new aspect.
(Is_Representation_Aspect): New aspect is not a representation aspect.
(Aspect_Names): Map new aspect to name.
(Aspect_Delay): New aspect is always delayed.
* contracts.adb (Expand_Subprogram_Contract)
(Add_Pre_Post_Condition, Add_Contract_Item)
(Analyze_Entry_Or_Subprogram_Contract)
(Analyze_Entry_Or_Subprogram_Body_Contract)
(Analyze_Subprogram_Body_Stub_Contract): Support new aspect.
* contracts.ads (Add_Contract_Item,
Analyze_Entry_Or_Subprogram_Contract,
Analyze_Entry_Or_Subprogram_Body_Contract,
Analyze_Subprogram_Body_Stub_Contract): Mention new contract in
comment.
* doc/gnat_rm/implementation_defined_aspects.rst
(Aspect Program_Exit): Document new aspect.
* doc/gnat_rm/implementation_defined_pragmas.rst
(Pragma Program_Exit): Document new pragma.
* einfo-utils.adb (Get_Pragma): Support new pragma.
* einfo-utils.ads (Get_Pragma): Mention new pragma in comment.
* exp_prag.adb (Expand_Pragma_Program_Exit): Expand new pragma;
body.
* exp_prag.ads (Expand_Pragma_Program_Exit): Expand new pragma;
spec.
* inline.adb (Remove_Aspects_And_Pragmas): Support new pragma.
* par-prag.adb (Prag): Support new pragma.
* sem_attr.adb (Analyze_Attribute_Old_Result): Accept attribute
Old in new pragma.
* sem_ch12.adb (Implementation of Generic Contracts): Mention new
aspect in comment.
* sem_ch13.adb (Insert_Pragma, Analyze_Aspect_Specifications):
Convert new new aspect to pragma.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Renumber
subsequent rule in comment.
* sem_prag.adb (Check_Postcondition_Use_In_Inlined_Subprogram)
(Contract_Freeze_Error): Mention new pragma in comment.
(Analyze_Pragma): Support new pragma; renumber subsequent rule in
comment.
(Analyze_Program_Exit_In_Decl_Part): Analyze new pragma; body.
(Sig_Flags): References in new pragma are significant when
detecting unreferenced objects.
* sem_prag.ads (Aspect_Specifying_Pragma)
(Assertion_Expression_Pragma, Pragma_Significant_To_Subprograms):
Support new aspect and pragma.
(Analyze_Program_Exit_In_Decl_Part): Analyze new pragma; spec.
(Find_Related_Package_Or_Body): Mention new pragma in comment.
* sem_util.adb (Is_Subprogram_Contract_Annotation): Support new
pragma.
* sem_util.ads (Is_Subprogram_Contract_Annotation): Mention new
pragma in comment.
* sinfo.ads (Is_Generic_Contract_Pragma): Mention new pragma in
comment.
* snames.ads-tmpl (Preset Names, Pragma_Id): Add name and pragma
identifiers.
* gnat_rm.texi: Regenerate.
Piotr Trojanek [Wed, 26 Feb 2025 17:00:57 +0000 (18:00 +0100)]
ada: Deconstruct C header for the SCOs unit
The C version of SCOs unit provided a gigi interface to source code obligations
that at some point were generated by the frontend. This functionality has been
deconstructed long ago.
gcc/ada/ChangeLog:
* libgnat/g-dyntab.ads (Instance): Update and extend comment.
* scos.ads: Remove comment about the corresponding C header.
* scos.h: Remove.
Steve Baird [Tue, 25 Feb 2025 21:51:40 +0000 (13:51 -0800)]
ada: Child unit subprograms are not primitive subprograms
If a package declares a type and a child unit of that package is a subprogram
with a parameter (or function result) of that type, then that subprogram is
not a primitive subprogram of that type. Previously this was handled
incorrectly in some cases, leading to incorrect analysis of overriding
indicators.
gcc/ada/ChangeLog:
* sem_util.adb (Collect_Primitive_Operations): When collecting
primitive operations, do not include child unit subprograms.
Javier Miranda [Fri, 31 Jan 2025 20:21:09 +0000 (20:21 +0000)]
ada: Constant_Indexing used when context requires a variable
In the case of an assignment where the type of its left hand side
is an indexable container that has indexable container components
(for example a container vector of container vectors), and both
indexable containers have Constant_Indexing and Variable_Indexing
aspects, the left hand side of the assignment is erroneously
interpreted as constant indexing. The error results in spurious
compile-time error messages saying that the left hand side of
the assignment must be a variable.
gcc/ada/ChangeLog:
* sem_ch4.adb (Constant_Indexing_OK): Add missing support for
RM 4.1.6(13/3), and improve performance to avoid climbing more
than needed. Add documentation.
(Try_Indexing_Function): New subprogram.
(Expr_Matches_In_Formal): Added new formals.
(Handle_Selected_Component): New subprogram.
(Has_IN_Mode): New subprogram.
(Try_Container_Indexing): Add documentation, code reorganization
and extend its functionality to improve its support for prefixed
notation calls.
ada: Refactor the implementation of gnat diagnostics
The goal of this patch is to remove the implementation from the
Diagnostic objects and port the new features over to the
Error_Msg_Objects.
gcc/ada/ChangeLog:
* debug.adb: Mark -gnatd_D as unused.
* diagnostics-repository.adb: Move to...
* errid.adb: ...here.
* diagnostics-repository.ads: Move to...
* errid.ads: ...here.
* errout.adb (Error_Msg_Internal): Add new arguments for the new
attributes of Error_Msg_Objects.
(Error_Msg): Likewise.
(Error_Msg_N): Likewise.
(Labeled_Span): New method for creating Labeled_Span-s
(Primary_Label_Span): New method for creating primary Labeled_Spans.
(Secondary_Labeled_Span): New method for creating secondary
Labeled_Spans.
(Edit): New method for creating Edit elements.
(Fix): New method for creating Fix elements.
(Error_Msg_F): Simplify code for evaluating the span.
(Error_Msg_FE): Likewise.
(Error_Msg_NE): Likewise.
(Error_Msg_NEL): Likewise.
(Error_Msg_N_Gigi): New method that is used as a wrapper for the
Error_Msg_xxx methods that have the new arguments. This function
is later mapped to the Error_Msg method used inside gigi.
(Error_Msg_NE_Gigi): Likewise.
(Write_JSON_Span): Ensure that the Style prefix is included that is
removed when parsing the message is reinserted to the JSON report.
(Output_Messages): Use the new Pretty_Printer and Sarif_Printer
packages to print the messages and remove the old implementation
for the pretty printer.
(Set_Msg_Text): Remove message kind insertion characters from the
final message text to avoid some message kinds being duplicated.
(To_Full_Span_First): New method for creating a span for a node.
(To_Full_Span): Likewise.
* errout.ads: Add the specs for all of the newly added functions.
* diagnostics-pretty_emitter.adb: Move to...
* erroutc-pretty_emitter.adb: ...here.
* diagnostics-pretty_emitter.ads: Move to...
* erroutc-pretty_emitter.ads: ...here.
* diagnostics-sarif_emitter.adb: Move to...
* erroutc-sarif_emitter.adb: ...here.
* diagnostics-sarif_emitter.ads: Move to...
* erroutc-sarif_emitter.ads: ...here.
* erroutc.adb (Next_Error_Msg): New method for iterating to the
next error message.
(Next_Continuation_Msg): New method for iterating to the next
continuation message.
(Primary_Location): New method for returning the first primary
location for the error message.
(Get_Human_Id): New method for returning the human readable
name for the switch associated with this error message.
(Get_Doc_Switch): New method for creating the tag for the switch
used in the error message.
(Output_Text_Within): Change the method to operating on Strings
instead of String pointers.
(Output_Msg_Text): Simplify implementation for generating the
error message.
(Prescan_Message): Make the String handling more error proof.
* erroutc.ads (Error_Msg_Object): Add new attributes that were
added to Diagnostic objects to Error_Msg_Objects.
Add new methods for handling the new error objects.
* diagnostics-switch_repository.adb: Move to...
* errsw.adb: ...here.
* errutil.adb (Error_Msg): Initialize all of the new attributes
added to Error_Msg_Object-s.
* fe.h (Error_Msg_N): Update the binding.
(Error_Msg_NE): Update the binding.
For now the error_msg methods in gigi will use the old
simplified interface for those methods.
* diagnostics-json_utils.adb: Move to...
* json_utils.adb: ...here.
* diagnostics-json_utils.ads: Move to...
* json_utils.ads: ...here.
* par-endh.adb: Replace the old error_msg
calls with the updated interface.
* sem_aggr.adb: Likewise.
* sem_ch13.adb: Likewise.
* sem_ch4.adb: Likewise.
* sem_ch9.adb: Likewise.
* diagnostics-brief_emitter.adb: Removed.
* diagnostics-brief_emitter.ads: Removed.
* diagnostics-constructors.adb: Removed.
* diagnostics-constructors.ads: Removed.
* diagnostics-converter.adb: Removed.
* diagnostics-converter.ads: Removed.
* diagnostics-switch_repository.ads: Removed.
* diagnostics-utils.adb: Removed.
* diagnostics-utils.ads: Removed.
* diagnostics.adb: Removed.
* diagnostics.ads: Removed.
* errsw.ads: New file. Based on diagnostics-switch_repository.ads.
It additionally contains all the switch enumerations.
* gcc-interface/Make-lang.in: Update compilation dependencies.
* gcc-interface/Makefile.in: Likewise.
ada: Set Ekind early for entities created in expansion
This patch adds early Ekind assignments to entities created for the
expansion of a few constructs. The only effect is to enable more dynamic
checks for the uses of those entities that used to happen before the
Ekind had been set.
Olivier Hainque [Fri, 21 Feb 2025 08:18:38 +0000 (08:18 +0000)]
ada: Rework Android struct sigaction bindings
A previous change arranged for the common definition of
struct_sigaction in s-osinte__android.ads to work both for
ARM and aarch64 by way of representation clauses with
field offsets taken from specialized versions of s-linux
(one for ARM, one for aarch64).
The aarch64 variant had the offsets wrong, placing the
sa_handler pointer at offset 4, following the sa_flags int
at offset 0. The pointer is 8 bytes wide so should be
placed at an offset multiple of 8. This caused a discrepancy
between the Ada runtime actions and the expectations of the
underlying libc functions called.
This change refactors the struct_sigaction definition
to instanciate an entire type provided by s-linux instead,
parametrized by sigset_t which needs to remain provided
by the common System.OS_Interface spec.
gcc/ada/ChangeLog:
* libgnarl/s-linux__android-aarch64.ads: Provide an
Android_Sigaction generic package to expose an aarch64
version of struct_sigation, using a provided sigset_t
for sa_flags.
* libgnarl/s-linux__android-arm.ads: Likewise, for ARM
rather than aarch64.
* libgnarl/s-osinte__android.ads: Move sigset_t definition
to the visible part and use it to instantiate the Android_Sigation
generic provided by System.Linux, which is specialized for ARM vs
aarch64. Define struct_sigaction out of the Android_Sigaction
instance, remove the local representation clauses.
Olivier Hainque [Wed, 12 Feb 2025 17:15:00 +0000 (17:15 +0000)]
ada: Adjust the Android RTS config to match linux
Android has many traits of Linux, reflected
by the gcc port triplets composition (<cpu>-android-linux).
The Android Ada RTS was so far configured as a mostly "posix"
port, which happens to be very little tested, if at all.
This change reworks the Android Ada RTS to map a lot more closely
to that of a regular Linux target, a natural fit and much more toroughly
exercized.
This expects support of pthread rwlocks in the bionic libc,
which is there in the not-so-old-but-not-so-recent versions we
tested (Android 11 at least).
gcc/ada/ChangeLog:
* Makefile.rtl: Rework the Android pairs to match those of a
regular Linux port rather than a generic posix one.
* libgnarl/s-osinte__android.ads: Import pcrtl and add bindings
for the pthread_rwlock entry points, used by the Linux units now
in the libgnat target pairs.
* sysdep.c (__gnat_has_cap_sys_nice): Define for Android,
conservative return 0.
* adaint.c (__gnat_cpu_alloc): Define for Android as for Linux.