]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
7 weeks agodiagnostics: make experimental-html sink prettier [PR116792]
David Malcolm [Wed, 11 Jun 2025 00:06:38 +0000 (20:06 -0400)] 
diagnostics: make experimental-html sink prettier [PR116792]

This patch to the "experimental-html" diagnostic sink:
* adds use of the PatternFly 3 CSS library (via an optional link
  in the generated html to a copy in a CDN)
* uses PatternFly's "alert" pattern to show severities for diagnostics,
  properly nesting "note" diagnostics for diagnostic groups.
  Example:
    before: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/before/diagnostic-ranges.c.html
     after: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/after/diagnostic-ranges.c.html

* adds initial support for logical locations and physical locations
* adds initial support for multi-level nested diagnostics such as those
  for C++ concepts diagnostics.  Ideally this would show a clickable
  disclosure widget to expand/collapse a level, but for now it uses
  nested <ul> elements with <li> for the child diagnostics.
  Example:
    before: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/before/nested-diagnostics-1.C.html
     after: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/after/nested-diagnostics-1.C.html

gcc/ChangeLog:
PR other/116792
* diagnostic-format-html.cc: Include "diagnostic-path.h" and
"diagnostic-client-data-hooks.h".
(html_builder::m_logical_loc_mgr): New field.
(html_builder::m_cur_nesting_levels): New field.
(html_builder::m_last_logical_location): New field.
(html_builder::m_last_location): New field.
(html_builder::m_last_expanded_location): New field.
(HTML_STYLE): Add "white-space: pre;" to .source and .annotation.
Add "gcc-quoted-text" CSS class.
(html_builder::html_builder): Initialize the new fields.  If CSS
is enabled, add CDN links to PatternFly 3 stylesheets.
(html_builder::add_stylesheet): New.
(html_builder::on_report_diagnostic): Add "alert" param to
make_element_for_diagnostic, setting it by default, but unsetting
it for nested diagnostics below the top level.  Use
add_at_nesting_level for nested diagnostics.
(add_nesting_level_attr): New.
(html_builder::add_at_nesting_level): New.
(get_pf_class_for_alert_div): New.
(get_pf_class_for_alert_icon): New.
(get_label_for_logical_location_kind): New.
(add_labelled_value): New.
(html_builder::make_element_for_diagnostic): Add leading comment.
Add "alert" param.  Drop class="gcc-diagnostic" from <div> tag,
instead adding the class for a PatternFly 3 alert if "alert" is
true, and adding a <span> with an alert icon, both according to
the diagnostic severity.  Add a severity prefix to the message for
alerts.  Add any metadata/option text as suffixes to the message.
Show any logical location.  Show any physical location.  Don't
show the locus if the last location is unchanged within the
diagnostic_group.  Wrap any execution path element in a
<div id="execution-path"> and add a label to it.  Wrap any
generated patch in a <div id="suggested-fix"> and add a label
to it.
(selftest::test_simple_log): Update expected HTML.

gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/html-output/missing-semicolon.py: Update for changes
to diagnostic elements.
* gcc.dg/format/diagnostic-ranges-html.py: Likewise.
* gcc.dg/plugin/diagnostic-test-metadata-html.py: Likewise.  Drop
out-of-date comment.
* gcc.dg/plugin/diagnostic-test-paths-2.py: Likewise.
* gcc.dg/plugin/diagnostic-test-paths-4.py: Likewise.  Drop
out-of-date comment.
* gcc.dg/plugin/diagnostic-test-show-locus.py: Likewise.
* lib/htmltest.py (get_diag_by_index): Update to use search by id.
(get_message_within_diag): Update to use search by class.

libcpp/ChangeLog:
PR other/116792
* include/line-map.h (typedef expanded_location): Convert to...
(struct expanded_location): ...this.
(operator==): New decl, for expanded_location.
(operator!=): Likewise.
* line-map.cc (operator==): New decl, for expanded_location.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
7 weeks agodiagnostics: xml: add add_text_from_pp
David Malcolm [Wed, 11 Jun 2025 00:06:38 +0000 (20:06 -0400)] 
diagnostics: xml: add add_text_from_pp

Various places use
  xp.add_text (pp_formatted_text (&pp))
Add a helper function for this.
No functional change intended.

gcc/ChangeLog:
* diagnostic-path-output.cc: Use xml::printer::add_text_from_pp.
* diagnostic-show-locus.cc: Likewise.
* xml-printer.h (xml::printer::add_text_from_pp): New decl.
* xml.cc (xml::node_with_children::add_text_from_pp): New.
(xml::printer::add_text_from_pp): New.
* xml.h (xml::node_with_children::add_text_from_pp): New decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
7 weeks agodiagnostics: fix tag nesting issues in experimental-html sink [PR120610]
David Malcolm [Wed, 11 Jun 2025 00:06:37 +0000 (20:06 -0400)] 
diagnostics: fix tag nesting issues in experimental-html sink [PR120610]

I've been seeing issues in the experimental-html sink where the nesting
of tags goes wrong.

The two issues I've seen are:
* the pp_token_list from the diagnostic message that reaches the
  html_token_printer doesn't always have matching pairs of begin/end
  tokens (PR other/120610)
* a bug in diagnostic-show-locus where there was a stray xp.pop_tag,
  in print_trailing_fixits.

This patch:
* changes the xml::printer::pop_tag API so that it now takes the
  expected name of the element being popped (rather than expressing this
  in comments), and that, by default, the xml::printer asserts that this
  matches.
* gives the html_token_printer its own xml::printer instance to restrict
  the affected area of the DOM tree; this xml::printer doesn't enforce
  nesting (PR other/120610)
* adds RAII sentinel classes that automatically check for pushes/pops
  being balanced within a scope, using them in various places
* fixes the bug in print_trailing_fixits for html output

gcc/ChangeLog:
PR other/120610
* diagnostic-format-html.cc (html_builder::html_builder): Update
for new param of xml::printer::pop_tag.
(html_path_label_writer::end_label): Likewise.
(html_builder::make_element_for_diagnostic::html_token_printer):
Give the instance its own xml::printer.  Update for new param of
xml::printer::pop_tag.
(html_builder::make_element_for_diagnostic): Give the instance its
own xml::printer.
(html_builder::make_metadata_element): Update for new param of
xml::printer::pop_tag.
(html_builder::flush_to_file): Likewise.
* diagnostic-path-output.cc (begin_html_stack_frame): Likewise.
(begin_html_stack_frame): Likewise.
(end_html_stack_frame): Likewise.
(print_path_summary_as_html): Likewise.
* diagnostic-show-locus.cc
(struct to_text::auto_check_tag_nesting): New.
(struct to_html:: auto_check_tag_nesting): New.
(to_text::pop_html_tag): Change param to const char *.
(to_html::pop_html_tag): Likewise; rename param to
"expected_name".
(default_diagnostic_start_span_fn<to_html>): Update for new param
of xml::printer::pop_tag.
(layout_printer<to_html>::end_label): Likewise.
(layout_printer<Sink>::print_trailing_fixits): Add RAII sentinel
to check tag nesting for the HTML case.  Delete stray popping
of "td" in the presence of fix-it hints.
(layout_printer<Sink>::print_line): Add RAII sentinel
to check tag nesting for the HTML case.
(diagnostic_source_print_policy::print_as_html): Likewise.
(layout_printer<Sink>::print): Likewise.
* xml-printer.h (xml::printer::printer): Add optional
"check_popped_tags" param.
(xml::printer::pop_tag): Add "expected_name" param.
(xml::printer::get_num_open_tags): New accessor.
(xml::printer::dump): New decl.
(xml::printer::m_check_popped_tags): New field.
(class xml::auto_check_tag_nesting): New.
(class xml::auto_print_element): Update for new param of pop_tag.
* xml.cc: Move pragma pop so that the pragma also covers
xml::printer's member functions, "dump" in particular.
(xml::printer::printer): Add param "check_popped_tags".
(xml::printer::pop_tag): Add param "expected_name" and use it to assert
that the popped tag is as expected.  Assert that we have a tag to
pop.
(xml::printer::dump): New.
(selftest::test_printer): Update for new param of pop_tag.
(selftest::test_attribute_ordering): Likewise.

gcc/testsuite/ChangeLog:
PR other/120610
* gcc.dg/format/diagnostic-ranges-html.py: Remove out-of-date
comment.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
7 weeks agogimple-ssa-warn-access: add missing auto_diagnostic_group
David Malcolm [Wed, 11 Jun 2025 00:06:37 +0000 (20:06 -0400)] 
gimple-ssa-warn-access: add missing auto_diagnostic_group

Spotted whilst implementing nesting support in the
experimental-html diagnostic sink.

gcc/ChangeLog:
* gimple-ssa-warn-access.cc
(pass_waccess::maybe_check_dealloc_call): Add missing
auto_diagnostic_group to nest the "returned from %qD"
note within the warning.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
7 weeks agoRISC-V: testsuite: fix an obvious build error
Vineet Gupta [Tue, 20 May 2025 21:15:53 +0000 (14:15 -0700)] 
RISC-V: testsuite: fix an obvious build error

For a non-multilib build, I see following errors.

| FAIL: gcc.target/riscv/rvv/vtype-call-clobbered.c (test for excess errors)
| Excess errors:
| TC-INSTxyz/sysroot/usr/include/gnu/stubs.h:14:11: fatal error: gnu/stubs-lp64.h: No such file or directory compilation terminated.

The test selects non default ABI lp64 (vs. lp64d) for no real reason.
Fix that.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/vtype-call-clobbered.c: Fix -mabi.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
7 weeks agoMore API for IPA profile manipulation
Jan Hubicka [Tue, 10 Jun 2025 19:32:40 +0000 (21:32 +0200)] 
More API for IPA profile manipulation

This patch attempts to make IPA profile manipulation easier.  It introduces

 node->scale_profile_to (count)
    which can be used to scale profile to a given IPA count.
    If IPA count is zero, then local profile is preserved and proper variant
    of global0 count is used.

 node->make_profile_local
    this can be used to drop IPA profile but keep local profile

 node->make_profile_global0
    this can be used to make IPA profile 0 but keep local
    profile.

Most of this can be accomplished by existing apply_scale.  I.e.
 - node->scale_profile_to (count)
     corresponds to
    node->apply_scale (count, node->count),
 - node->make_profile_local
     corresponds to
   node->apply_scale (node->count.guessed_local (), node->count)

I think new API is more clean about what intention is and less error prone.
Also it handles some side cases when entry block of profile happens to be 0,
but body is non-zero (by profile inconsistencies).  In this case the scaling
API did kind of random things.

I noticed three bugs in ipa-cp (two already in released GCCs while one mine
introduced by last patch):

@@ -4528,7 +4528,7 @@ lenient_count_portion_handling (profile_count remainder, cgraph_node *orig_node)
   if (remainder.ipa_p () && !remainder.ipa ().nonzero_p ()
       && orig_node->count.ipa_p () && orig_node->count.ipa ().nonzero_p ()
       && opt_for_fn (orig_node->decl, flag_profile_partial_training))
-    remainder = remainder.guessed_local ();
+    remainder = orig_node->count.guessed_local ();

The code was intended to drop IPA profile to local when remainder is 0.
In this case orig_node->count is some non-zero count but all of control flow
was redirected to a clone which means that remainer is 0 (adjusted).
Doing

     remainder = remainder.guessed_local ();

will turn it into 0 (guessed_local) and the scalling will then multiply
all counts by 0 and turn them tinto guessed local.
We want to keep original count but reduce the quality. i.e.

     remainder = orig_node->count.guessed_local ();

Second problem is:
       /* TODO: Profile has alreay gone astray, keep what we have but lower it
   to global0 category.  */
       remainder = orig_node->count.global0 ();
global0 means that converting to ipa count will be precise 0. Since we lost track
it should be adjusted 0 :)

Finally in:
  new_sum = orig_node_count.combine_with_ipa_count (new_sum);
  orig_node->count = remainder;

  new_node->apply_scale (new_sum, new_node->count);

   if (!orig_edges_processed)
    orig_node->apply_scale (remainder, orig_node->count);
    orig_node->scale_profile_to (remainder);

orig_node->count is first set to remainder and then scalling is done
(which in turn does nothing).

This is bug I introduced in last path which should have removed
orig_node->count = remainder.  As a result now counts of cgraph edges are not
adjusted correctly.  I am sorry for that.

gcc/ChangeLog:

* cgraph.cc (cgraph_node::make_profile_local): New member function.
(cgraph_node::make_profile_global0): New member function.
(cgraph_node::apply_scale): Do not call adjust_for_ipa_scalling.
(cgraph_node::scale_profile_to): New member function.
* cgraph.h (cgraph_node::make_profile_local,
cgraph_node::make_profile_global0, cgraph_node::scale_profile_to):
Declare.
* ipa-cp.cc (lenient_count_portion_handling): Fix logic dropping count
to local.
(update_counts_for_self_gen_clones): Use scale_profile_to.
(update_profiling_info): Use make_profile_local, make_profile_global0
and scale_profile_to.
(update_specialized_profile): Likewise.
* ipa-inline-transform.cc (clone_inlined_nodes): Call
adjust_for_ipa_scalling.

7 weeks agoexpand: Use less costly from sign and zero extensions for values where value range...
Jakub Jelinek [Tue, 10 Jun 2025 18:06:14 +0000 (20:06 +0200)] 
expand: Use less costly from sign and zero extensions for values where value range says they don't have MSB set [PR120434]

On top of the just posted patch, the following patch attempts to
use value range to see if MSB is known to be false and for scalar integral
extension in that case tries to expand both sign and zero extension and
chooses based on RTX costs the cheaper one (if the costs are the same
uses what it used before, TYPE_UNSIGNED (TREE_TYPE (treeop0)) based.

The patch regresses the gcc.target/i386/pr78103-3.c test, will post
a separate patch for that momentarily (with the intent that if all 3
patches are approved, I'll commit the PR78103 related one before this one).

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

PR middle-end/120434
* expr.cc (expand_expr_real_2) <CASE_CONVERT>: If get_range_pos_neg
at -O2 for scalar integer extension suggests the most significant
bit of op0 is not set, try both unsigned and signed conversion and
choose the cheaper one.  If both are the same cost, choose one
based on TYPE_UNSIGNED (TREE_TYPE (treeop0)).

* gcc.target/i386/pr120434-2.c: New test.

7 weeks agoi386: Handle ZERO_EXTEND like SIGN_EXTEND in bsr patterns [PR120434]
Jakub Jelinek [Tue, 10 Jun 2025 18:07:06 +0000 (20:07 +0200)] 
i386: Handle ZERO_EXTEND like SIGN_EXTEND in bsr patterns [PR120434]

The just posted second PR120434 patch causes
+FAIL: gcc.target/i386/pr78103-3.c scan-assembler \\\\m(leaq|addq|incq)\\\\M
+FAIL: gcc.target/i386/pr78103-3.c scan-assembler-not \\\\mmovl\\\\M+
+FAIL: gcc.target/i386/pr78103-3.c scan-assembler-not \\\\msubq\\\\M
+FAIL: gcc.target/i386/pr78103-3.c scan-assembler-not \\\\mxor[lq]\\\\M
While the patch generally improves code generation by often using
ZERO_EXTEND instead of SIGN_EXTEND, where the former is often for free
on x86_64 while the latter requires an extra instruction or larger
instruction than one with just zero extend, the PR78103 combine patterns
and splitters were written only with SIGN_EXTEND in mind.  As CLZ is UB
on 0 and otherwise returns just [0,63] and is xored with 63, ZERO_EXTEND
does the same thing there as SIGN_EXTEND.

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

PR middle-end/120434
* config/i386/i386.md (*bsr_rex64_2): Rename to ...
(*bsr_rex64<u>_2): ... this.  Use any_extend instead of sign_extend.
(*bsr_2): Rename to ...
(*bsr<u>_2): ... this.  Use any_extend instead of sign_extend.
(bsr splitters after those): Use any_extend instead of sign_extend.

7 weeks agoexpand, ranger: Use ranger during expansion [PR120434]
Jakub Jelinek [Tue, 10 Jun 2025 18:04:52 +0000 (20:04 +0200)] 
expand, ranger: Use ranger during expansion [PR120434]

As the following testcase shows, during expansion we use value range info
in lots of places, but sadly currently use only the global ranges.
It is mostly through get_range_pos_neg function, which uses
get_global_range_query ()->range_of_expr (arg1, arg2)
but other spots use it directly.

On the testcase at the end of the patch, in foo we don't know range of x,
so emit the at least on x86_64 less efficient signed division in that case.
In bar, the default def SSA_NAME has global range and we try to expand
the division both as signed and unsigned because the range proves they will
have the same result and choose the cheaper one.
And finally in baz, we have VARYING in global range, but can do better if
we ask for range at the statement we're expanding.

The main problem of using the ranger during expansion is that things are in
flux, the already expanded basic blocks switch their IL from gimple to RTL
(bb->flags & BB_RTL) and the gimple stmts are gone, PHI nodes even earlier,
etc.

The patch attempts to make the ranger usable by keeping (bb->flags & BB_RTL)
== 0 on basic blocks for longer, in particular until the last
expand_gimple_basic_block call for the function.  Instead of changing the
IL right away, it uses a vector indexed by bb->index to hold the
future BB_HEAD/BB_END.  I had to do a few changes on the ranger side and
maybe testing in the wild will show a few extra cases, but I think those
are tolerable and can be guarded with currently_expanding_to_rtl so that
we don't punt on consistency checks on normal GIMPLE.
In particular, even with the patch there will still be some BB_RTL
bbs in the IL, e.g. the initial block after ENTRY, ENTRY and EXIT blocks
and from time to time others as well, but those should never contain
anything intreresting from the ranger POV.  And switch expansion can drop
the default edge if it is __builtin_unreachable.

Also, had to change the internal call TER expansion, the current way
of temporarily changing gimple_call_lhs ICEd badly in the ranger, so I'm
instead temporarily changing SSA_NAME_VAR of the SSA_NAME.

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

PR middle-end/120434
* cfgrtl.h (update_bb_for_insn_chain): Declare.
* cfgrtl.cc (update_bb_for_insn_chain): No longer static.
* cfgexpand.h (expand_remove_edge): Declare.
* cfgexpand.cc: Include "gimple-range.h".
(head_end_for_bb): New variable.
(label_rtx_for_bb): Drop ATTRIBUTE_UNUSED from bb argument.
Use head_end_for_bb if possible for non-BB_RTL bbs.
(expand_remove_edge): New function.
(maybe_cleanup_end_of_block): Use it instead of remove_edge.
(expand_gimple_cond): Don't clear EDGE_TRUE_VALUE and
EDGE_FALSE_VALUE just yet.  Use head_end_for_bb elts instead
of BB_END and update_bb_for_insn_chain instead of update_bb_for_insn.
(expand_gimple_tailcall): Use expand_remove_edge instead of
remove_edge.  Use head_end_for_bb elts instead of BB_END and
update_bb_for_insn_chain instead of update_bb_for_insn.
(expand_gimple_basic_block): Don't change bb to BB_RTL here, instead
use head_end_for_bb elts instead of BB_HEAD and BB_END.  Use
update_bb_for_insn_chain instead of update_bb_for_insn.
(pass_expand::execute): Enable ranger before expand_gimple_basic_block
calls and create head_end_for_bb vector.  Disable ranger after
those calls, turn still non-BB_RTL blocks into BB_RTL and set their
BB_HEAD and BB_END from head_end_for_bb elts, and clear EDGE_TRUE_VALUE
and EDGE_FALSE_VALUE flags on edges.  Release head_end_for_bb
vector.
* tree-outof-ssa.cc (expand_phi_nodes): Don't clear phi nodes here.
* tree.h (get_range_pos_neg): Add gimple * argument defaulted to NULL.
* tree.cc (get_range_pos_neg): Add stmt argument.  Use
get_range_query (cfun) instead of get_global_range_query () and pass
stmt as third argument to range_of_expr.
* expr.cc (expand_expr_divmod): Pass currently_expanding_gimple_stmt
to get_range_pos_neg.
(expand_expr_real_1) <case SSA_NAME>: Change internal fn handling
to avoid temporarily overwriting gimple_call_lhs of ifn, instead
temporarily overwrite SSA_NAME_VAR of its lhs.
(maybe_optimize_pow2p_mod_cmp): Pass currently_expanding_gimple_stmt
to get_range_pos_neg.
(maybe_optimize_mod_cmp): Likewise.
* internal-fn.cc (get_min_precision): Likewise.  Use
get_range_query (cfun) instead of get_global_range_query () and pass
currently_expanding_gimple_stmt as third argument to range_of_expr.
Pass g to get_range_pos_neg.
(expand_addsub_overflow): Pass currently_expanding_gimple_stmt
to get_range_pos_neg.
(expand_mul_overflow): Likewise.
(expand_arith_overflow): Pass stmt to get_range_pos_neg.
* gimple-range-edge.cc: Include rtl.h.
(gimple_outgoing_range_stmt_p): Return NULL for BB_RTL bbs.
(gimple_outgoing_range::calc_switch_range): If default_edge is NULL,
assert currently_expanding_to_rtl and return before trying to
set range on that edge.
* builtins.cc (expand_builtin_strnlen): Use get_range_query (cfun)
instead of get_global_range_query () and pass
currently_expanding_gimple_stmt as third argument to range_of_expr.
(determine_block_size): Likewise.
* gimple-range.cc (gimple_ranger::range_on_exit): Set s to NULL
instead of last_nondebug_stmt for BB_RTL bbs.
* stmt.cc: Include cfgexpand.h.
(expand_case): Use expand_remove_edge instead of remove_edge.

* gcc.target/i386/pr120434-1.c: New test.

7 weeks agoCheck if constant is a member before returning it.
Andrew MacLeod [Tue, 10 Jun 2025 16:11:18 +0000 (12:11 -0400)] 
Check if constant is a member before returning it.

set_range_from_bitmask checks the new bitmask, and if it is a constant,
simply returns the constant.  It never checks if that constant is
actually within the range.  If it is not, the result should be UNDEFINED.

* value-range.cc (irange::set_range_from_bitmask): When the bitmask
result is a singleton, check if it is contained in the range.

7 weeks agocobol: Variety of small changes in answer to cppcheck diagnostics.
James K. Lowden [Tue, 10 Jun 2025 14:34:28 +0000 (10:34 -0400)] 
cobol: Variety of small changes in answer to cppcheck diagnostics.

Remove non-ASCII input and blank lines from gcobol.1. Restrict
cobol.clean target to compiler object files.

gcc/cobol/ChangeLog:

* Make-lang.in: cobol.clean does not remove libgcobol files.
* cdf.y: Suppress 1 cppcheck false positive.
* cdfval.h (scanner_parsing):  Partial via cppcheck for PR119324.
* gcobol.1: Fix groff errors.
* gcobolspec.cc (append_arg): Const parameter.
* parse_ante.h (intrinsic_call_2): Avoid NULL dereference.

7 weeks agolibstdc++: Make __max_size_type and __max_diff_type structural
Patrick Palka [Tue, 10 Jun 2025 14:15:25 +0000 (10:15 -0400)] 
libstdc++: Make __max_size_type and __max_diff_type structural

This patch makes these integer-class types structural types by
public-izing their data members so that they could be used as NTTP
types.  I don't think this is required by the standard, but it seems
like a useful extension.

libstdc++-v3/ChangeLog:

* include/bits/max_size_type.h (__max_size_type::_M_val): Make
public instead of private.
(__max_size_type::_M_msb): Likewise.
(__max_diff_type::_M_rep): Likewise.
* testsuite/std/ranges/iota/max_size_type.cc: Verify
__max_diff_type and __max_size_type are structural.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
7 weeks agolibstdc++: Implement LWG3528 make_from_tuple can perform (the equivalent of) a C...
Yihan Wang [Mon, 9 Jun 2025 10:07:51 +0000 (11:07 +0100)] 
libstdc++: Implement LWG3528 make_from_tuple can perform (the equivalent of) a C-style cast

Implement LWG3528 to make std::make_from_tuple SFINAE friendly.

libstdc++-v3/ChangeLog:

* include/std/tuple (__can_make_from_tuple): New variable
template.
(__make_from_tuple_impl): Add static_assert.
(make_from_tuple): Constrain using __can_make_from_tuple.
* testsuite/20_util/tuple/dr3528.cc: New test.

Signed-off-by: Yihan Wang <yronglin777@gmail.com>
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
7 weeks agogcn: Add experimental MI300 (gfx942) support
Tobias Burnus [Tue, 10 Jun 2025 13:12:47 +0000 (15:12 +0200)] 
gcn: Add experimental MI300 (gfx942) support

As gfx942 and gfx950 belong to gfx9-4-generic, the latter two are also added.
Note that there are no specific optimizations for MI300, yet.

For none of the mentioned devices, any multilib is build by default; use
'--with-multilib-list=' when configuring GCC to build them alongside.
gfx942 was added in LLVM (and its mc assembler, used by GCC) in version 18,
generic support in LLVM 19 and gfx950 in LLVM 20.

gcc/ChangeLog:

* config/gcn/gcn-devices.def: Add gfx942, gfx950 and gfx9-4-generic.
* config/gcn/gcn-opts.h (TARGET_CDNA3, TARGET_CDNA3_PLUS,
TARGET_GLC_NAME, TARGET_TARGET_SC_CACHE): Define.
(TARGET_ARCHITECTED_FLAT_SCRATCH): Use also for CDNA3.
* config/gcn/gcn.h (gcn_isa): Add ISA_CDNA3 to the enum.
* config/gcn/gcn.cc (print_operand): Update 'g' to use
TARGET_GLC_NAME; add 'G' to print TARGET_GLC_NAME unconditionally.
* config/gcn/gcn-valu.md (scatter, gather): Use TARGET_GLC_NAME.
* config/gcn/gcn.md: Use %G<num> instead of glc; use 'buffer_inv sc1'
for TARGET_TARGET_SC_CACHE.
* doc/invoke.texi (march): Add gfx942, gfx950 and gfx9-4-generic.
* doc/install.texi (amdgcn*-*-*): Add gfx942, gfx950 and gfx9-4-generic.
* config/gcn/gcn-tables.opt: Regenerate.

libgomp/ChangeLog:

* testsuite/libgomp.c/declare-variant-4.h (gfx942): New variant function.
* testsuite/libgomp.c/declare-variant-4-gfx942.c: New test.

7 weeks ago[RISC-V] Fix ICE due to splitter emitting constant loads directly
Jeff Law [Tue, 10 Jun 2025 12:38:52 +0000 (06:38 -0600)] 
[RISC-V] Fix ICE due to splitter emitting constant loads directly

This is a fix for a bug found internally in Ventana using the cf3 testsuite.

cf3 looks to be dead as a project and likely subsumed by modern fuzzers.  In
fact internally we tripped another issue with cf3 that had already been
reported by Edwin with the fuzzer he runs.

Anyway, the splitter in question blindly emits the 2nd adjusted constant into a
register, that's not valid if the constant requires any kind of synthesis --
and it well could since we're mostly focused on the first constant turning into
something that can be loaded via LUI without increasing the cost of the second
constant.

Instead of using the split RTL template, this just emits the code we want
directly, using riscv_move_insn to synthesize the constant into the provided
temporary register.

Tested in my system.  Waiting on upstream CI's verdict before moving forward.

gcc/
* config/riscv/riscv.md (lui-constraint<X:mode>and_to_or): Do not use
the RTL template for split code.  Emit it directly taking care to avoid
emitting a constant load that needed synthesis.  Fix formatting.

gcc/testsuite/
* gcc.target/riscv/ventana-16122.c: New test.

7 weeks agolibfortran: Add script to regenerate source files
Francois-Xavier Coudert [Mon, 9 Jun 2025 15:19:04 +0000 (17:19 +0200)] 
libfortran: Add script to regenerate source files

Move the regeneration of libgfortran source files from the Makefile
to a standalone script. We were previously highjacking the
maintainer mode of autoconf/automake in a way that was not adequate,
leading to various issues. Bring our behavior in line with other
GCC libraries.

2025-06-09  François-Xavier Coudert  <fxcoudert@gcc.gnu.org>

libgfortran/ChangeLog:

PR libfortran/116400
* Makefile.am: Remove source file regeneration rules.
* Makefile.in: Regenerate.
* regenerate.sh: New file.

7 weeks agoada: Generic formal objects have no entry components
Piotr Trojanek [Tue, 25 Mar 2025 15:15:39 +0000 (16:15 +0100)] 
ada: Generic formal objects have no entry components

AST field Entry_Component doesn't make sense for generic formal objects and was
never used there. Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

* gen_il-gen-gen_entities.adb (Formal_Object_Kind): Remove
Entry_Component field.

7 weeks agoada: Remove redundant guard against attribute with no expressions
Piotr Trojanek [Wed, 26 Mar 2025 17:42:10 +0000 (18:42 +0100)] 
ada: Remove redundant guard against attribute with no expressions

We intentionally allow First to work on No_List, so there is no need to guard
against a No_List. Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_attr.adb (Resolve_Attribute): Remove redundant guard.

7 weeks agoada: Minor comment tweak
Eric Botcazou [Thu, 27 Mar 2025 21:56:59 +0000 (22:56 +0100)] 
ada: Minor comment tweak

This replaces a couple of occurrences of "function" by "subprogram".

gcc/ada/ChangeLog:

* inline.adb (Analyze_Inlined_Bodies): Minor comment tweak.

7 weeks agoada: Small cleanup in instantiation of generic bodies
Eric Botcazou [Thu, 27 Mar 2025 12:27:46 +0000 (13:27 +0100)] 
ada: Small cleanup in instantiation of generic bodies

This removes the code dealing with generic main units from the body of the
instantiation routine, namely Instantiate_Bodies, and replaces it by tests
done earlier in the processing.

The test added to Need_Subprogram_Instance_Body is already present in the
twin predicate Needs_Body_Instantiated.

gcc/ada/ChangeLog:

* inline.adb (Instantiate_Body): Do not call Add_Scope_To_Clean if
the main unit is generic.
(Instantiate_Bodies): Do not deal with generic main units here.
* sem_ch12.adb (Need_Subprogram_Instance_Body): Return false if the
main unit is generic.

7 weeks agoada: Do not install the support files of 128-bit types on 32-bit targets
Eric Botcazou [Thu, 27 Mar 2025 15:16:46 +0000 (16:16 +0100)] 
ada: Do not install the support files of 128-bit types on 32-bit targets

The files are not compiled into libgnat.a but are nevertheless installed
in the adainclude directory, which is unwanted.

gcc/ada/ChangeLog:

* Makefile.rtl (ADA_EXCLUDE_SRCS): Add the 128-bit support files.

7 weeks agoada: Factorize some duplicate code
Ronan Desplanques [Thu, 27 Mar 2025 11:13:20 +0000 (12:13 +0100)] 
ada: Factorize some duplicate code

Process_Subtype can be passed either a subtype indication or a subtype
mark. Before this patch, it branched directly depending on the kind of
the argument, but there actually was processing common to the two
branches like resolving the subtype mark. This patch factorizes this
common processing out of the if statement.

gcc/ada/ChangeLog:

* sem_ch3.adb (Process_Subtype): Factorize code.

7 weeks agoada: VAST found bug: Itypes with Parent
Bob Duff [Thu, 27 Mar 2025 10:14:33 +0000 (06:14 -0400)] 
ada: VAST found bug: Itypes with Parent

Fix the comment about Itypes, so the Parent field is no longer required.

Change VAST to no longer require it. Remove Check_Itype_Parents
from Check_Enum; it can no longer fail, so there's no point in
making it switchable.

gcc/ada/ChangeLog:

* einfo.ads (Associated_Node_For_Itype): Document that
Parent field may be empty.
* vast.adb:  Allow empty Parent in Itypes.

7 weeks agoada: Error on subtype with static predicate used in case_expression
Gary Dismukes [Sat, 22 Mar 2025 00:01:52 +0000 (00:01 +0000)] 
ada: Error on subtype with static predicate used in case_expression

The compiler improperly flags an error on the use of a subtype with a
static predicate as a choice in a case expression alternative, complaining
that the subtype has a nonstatic predicate. The fix for this is to add
a test for the subtype not having a static predicate.

gcc/ada/ChangeLog:

* einfo.ads: Revise comment about Dynamic_Predicate flag to make it
more accurate.
* sem_case.adb (Check_Choices): Test "not Has_Static_Predicate_Aspect"
as additional guard for error about use of subtype with nonstatic
predicate as a case choice. Improve related error message.

7 weeks agoada: Special case for inconsistent pointer in Scan_Raw_Unsigned
Tonu Naks [Tue, 25 Mar 2025 09:49:25 +0000 (09:49 +0000)] 
ada: Special case for inconsistent pointer in Scan_Raw_Unsigned

gcc/ada/ChangeLog:

* libgnat/s-valueu.adb: add explict raise
* libgnat/s-valueu.ads: update annotation

7 weeks agoada: Move Check_Discriminant_Conformance to Sem_Ch3
Ronan Desplanques [Tue, 25 Mar 2025 11:50:40 +0000 (12:50 +0100)] 
ada: Move Check_Discriminant_Conformance to Sem_Ch3

Check_Discriminant_Conformance is really only about concepts defined in
chapter 3 of the Ada reference manual, so it fits better in Sem_Ch3 than
in Sem_Ch6.

gcc/ada/ChangeLog:

* sem_ch6.adb, sem_ch6.ads (Check_Discriminant_Conformance): Move to …
* sem_ch3.adb (Check_Discriminant_Conformance): … here.

7 weeks agoada: Fix fallout of latest change
Eric Botcazou [Tue, 25 Mar 2025 23:37:22 +0000 (00:37 +0100)] 
ada: Fix fallout of latest change

Freeze_Static_Object needs to deal with the objects that have been created
by Insert_Conditional_Object_Declaration.

gcc/ada/ChangeLog:

* freeze.adb (Freeze_Static_Object): Do not issue any error message
for compiler-generated entities.

7 weeks agoada: VAST: treewalker improvements
Bob Duff [Tue, 25 Mar 2025 19:42:08 +0000 (15:42 -0400)] 
ada: VAST: treewalker improvements

Implement two basic checks: Check that N_Error nodes cannot appear in the
tree (because VAST is not called when the source is illegal).
Check that every node has a parent, except for certain nodes where
we check the opposite. (We do not yet check that the parent pointers
actually point to the right node.)

Minor improvements. Flags for controlling debugging outputs and the like.

Capability to enable/disable individual checks. The intent is to
implement that only when needed -- i.e. when VAST finds a bug, and we
have not yet fixed the bug.

gcc/ada/ChangeLog:

* vast.adb: Implement two checks. Improve debugging
outputs.

7 weeks agoada: Fix wrong initialization of library-level object by conditional expression
Eric Botcazou [Tue, 25 Mar 2025 17:23:50 +0000 (18:23 +0100)] 
ada: Fix wrong initialization of library-level object by conditional expression

The previous fix was not robust enough in the presence of transient scopes.

gcc/ada/ChangeLog:

* exp_ch4.adb (Insert_Conditional_Object_Declaration): Deal with a
transient scope being created around the declaration.
* freeze.adb (Freeze_Entity): Do not call Freeze_Static_Object for
a renaming declaration.

7 weeks agoada: Fix inconsistent comment for fixed-point Value attribute implementation
Eric Botcazou [Tue, 25 Mar 2025 17:35:10 +0000 (18:35 +0100)] 
ada: Fix inconsistent comment for fixed-point Value attribute implementation

The comment incorrectly mentions decimal fixed point.

gcc/ada/ChangeLog:

* libgnat/s-vafi32.ads: Fix head description.
* libgnat/s-vafi64.ads: Likewise.
* libgnat/s-vafi128.ads: Likewise.

7 weeks agoada: VAST: create treewalker
Bob Duff [Mon, 24 Mar 2025 20:21:53 +0000 (16:21 -0400)] 
ada: VAST: create treewalker

Walks all trees (not just the main unit), deals with switches and
flags. Doesn't check much of anything yet (asserts that "unused" nodes
are not present).

Move decisions (what tree(s) to check, what switches enable checking)
from the caller to the body of VAST.

gcc/ada/ChangeLog:

* vast.adb: Initial implementation.
* vast.ads: Rename procedure. Remove parameter; body should decide
what to do.
* lib.ads (ipu): Minor: Rewrite comment for brevity, and because
of an inconvenient misspelling.
(Num_Units): Not used; remove.
(Remove_Unit): Minor: Remove "Currently" (which was current a decade
ago from) comment.
* lib.adb (Num_Units): Not used; remove.
* debug_a.adb (Debug_A_Entry): Fix bug: Use Write_Name_For_Debug,
so this won't crash on the Error node.
* debug.adb: Document -gnatd_V and -gnatd_W compiler switches.
* exp_ch6.adb (Validate_Subprogram_Calls): Remove redundant check for
Serious_Errors_Detected. (We turn off code gen when errors are
detected.)
* frontend.adb: Move decisions into VAST body.
* namet.ads (Present): Remove unnecessary overriding; these are
inherited by the derived types.
* namet.adb (Present): Likewise.

7 weeks agoada: Storage_Error on Ordered_Maps container aggregate with enumeration Key_Type
Gary Dismukes [Fri, 21 Mar 2025 22:03:46 +0000 (22:03 +0000)] 
ada: Storage_Error on Ordered_Maps container aggregate with enumeration Key_Type

The compiler fails with a Storage_Error when compiling a container aggregate
for a Map type coming from an instantiation of Ada.Containers.Ordered_Maps
that specifies an enumeration type for the Key_Type formal.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Container_Aggr_Code.To_Int): Apply Enumeration_Pos
to Entity (Expr) rather than Expr.

7 weeks agoada: Fix omission in comment
Ronan Desplanques [Mon, 24 Mar 2025 11:39:29 +0000 (12:39 +0100)] 
ada: Fix omission in comment

gcc/ada/ChangeLog:

* sem_ch3.adb (Find_Type_Of_Object): Fix comment.

7 weeks agoada: Rename constant in Analyze_Component_Declaration
Ronan Desplanques [Mon, 24 Mar 2025 11:19:07 +0000 (12:19 +0100)] 
ada: Rename constant in Analyze_Component_Declaration

"Typ" is typically used to name constants that are entity IDs for types.
Before this patch, a constant local to Analyze_Component_Declaration
designating a syntactic subtype indication had that name. This patch
renames it to "Ind".

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

* sem_ch3.adb (Analyze_Component_Declaration): Rename constant.

7 weeks agoada: Simplify Constrain_Array
Ronan Desplanques [Fri, 21 Mar 2025 15:49:20 +0000 (16:49 +0100)] 
ada: Simplify Constrain_Array

Before this patch, Constrain_Array had a feature where it could be
passed Empty for the first actual and would then create an Itype itself.
There was only one use of this feature and it was unnecessary, so this
patch removes it.

gcc/ada/ChangeLog:

* sem_ch3.adb (Constrain_Array): Simplify.
(Process_Subtype): Adjust.

7 weeks agoada: Fix infinite loop with aggregate in generic unit
Eric Botcazou [Thu, 20 Mar 2025 22:29:33 +0000 (23:29 +0100)] 
ada: Fix infinite loop with aggregate in generic unit

Root_Type does not return the same type for the private and the full view of
a derived private tagged type when both derive from an interface type.

gcc/ada/ChangeLog:

* sem_ch12.adb (Copy_Generic_Node): Do not call Root_Type to find
the root type of an aggregate of a derived tagged type.

7 weeks agoada: Fix use-after-free in Compute_All_Tasks
Ronan Desplanques [Tue, 18 Mar 2025 12:56:58 +0000 (13:56 +0100)] 
ada: Fix use-after-free in Compute_All_Tasks

This patch fixes a bug in System.Stack_Usage.Tasking.Compute_All_Tasks
where it would attempt to read the stack of threads that had already
completed.

gcc/ada/ChangeLog:

* libgnarl/s-stusta.adb (Compute_All_Tasks): Skip terminated tasks.

7 weeks agoada: Fix the detection of configuration pragmas
Viljar Indus [Wed, 19 Mar 2025 09:28:13 +0000 (11:28 +0200)] 
ada: Fix the detection of configuration pragmas

Some pragma nodes like the ones for Assertion_Policy are
replaced by a Null_Statement. This is not taken into account
when analyzing if the pragma is a configuration pragma.

gcc/ada/ChangeLog:

* sem_prag.adb (Is_Configuration_Pragma): Check that nodes
preceding the pragma are pragma nodes or originally were
pragma nodes.

7 weeks agoada: Fix Value_Decimal to raise Constraint_Error on boundary values
Eric Botcazou [Tue, 18 Mar 2025 21:44:15 +0000 (22:44 +0100)] 
ada: Fix Value_Decimal to raise Constraint_Error on boundary values

Even though the issue is not user-visible, it's a (minor) departure from the
specification of the procedure.

gcc/ada/ChangeLog:

* libgnat/s-valued.adb (Integer_to_Decimal): Add Extra parameter and
use its value to call Bad_Value on boundary values.
(Scan_Decimal): Adjust call to Integer_to_Decimal.
(Value_Decimal): Likewise.

7 weeks agoada: Add Incomplete_Type_OK formal to Process_Subtype
Ronan Desplanques [Tue, 18 Mar 2025 17:02:29 +0000 (18:02 +0100)] 
ada: Add Incomplete_Type_OK formal to Process_Subtype

Before this patch, Process_Subtype looked at the parent of its argument
to determine whether it was called in a context where it was OK for the
subtype mark to refer to the incomplete view of a type. This patch adds
a new formal so that it becomes the responsibility of the caller in
order to make the code simpler overall.

The only change in the behavior of the compiler is that the messages
emitted in some error situations with the -gnatf switch are slightly
different.

gcc/ada/ChangeLog:

* sem_ch3.ads (Process_Subtype): New formal.
* sem_ch3.adb (Process_Subtype): Likewise.
(Analyze_Subtype_Declaration, Access_Type_Declaration): Use new
formal.

7 weeks agoada: Fix recursive call in Process_Subtype
Ronan Desplanques [Tue, 18 Mar 2025 07:53:35 +0000 (08:53 +0100)] 
ada: Fix recursive call in Process_Subtype

Process_Subtype calls itself in some error situations. This recursive
call was not updated together with the recent addition of the
Excludes_Null formal. This does not matter in practice because there can
never be both a null exclusion and another constraint at the same time,
but this patch updates the call anyway to make the situation clearer.

gcc/ada/ChangeLog:

* sem_ch3.adb (Process_Subtype): Fix recursive call.

7 weeks agoada: Rename a couple of local variables
Eric Botcazou [Tue, 18 Mar 2025 10:36:35 +0000 (11:36 +0100)] 
ada: Rename a couple of local variables

Block_Node is the name of an entity field, so the change renames local
variables with this name for the sake of clarity.

gcc/ada/ChangeLog:

* par-ch5.adb (P_Declare_Statement): Rename local variable.
(P_Begin_Statement): Likewise.

7 weeks agoada: Remove outdated comment about reused entity fields
Piotr Trojanek [Tue, 18 Mar 2025 09:41:43 +0000 (10:41 +0100)] 
ada: Remove outdated comment about reused entity fields

With the current representation of GNAT AST the entity fields are not reused.

gcc/ada/ChangeLog:

* einfo.ads (Overridden_Operation, Static_Initialization): Remove
comments about a reused entity field.

7 weeks agoada: Tweak formatting in Process_Subtype
Ronan Desplanques [Mon, 17 Mar 2025 16:21:45 +0000 (17:21 +0100)] 
ada: Tweak formatting in Process_Subtype

This patch removes parentheses and vertical alignment that misleadingly
suggested the presence of function calls where there weren't any.

gcc/ada/ChangeLog:

* sem_ch3.adb (Process_Subtype): Tweak formatting.

7 weeks agoada: Add assertion on expanded code in particular case
Ronan Desplanques [Mon, 17 Mar 2025 16:18:26 +0000 (17:18 +0100)] 
ada: Add assertion on expanded code in particular case

This patch adds an assertion that checks that expanded code does not
contain erroneous access subtype definitions.

gcc/ada/ChangeLog:

* sem_ch3.adb (Process_Subtype): Add assertion.

7 weeks agoada: Factorize initialization of local variable
Ronan Desplanques [Mon, 17 Mar 2025 16:15:29 +0000 (17:15 +0100)] 
ada: Factorize initialization of local variable

gcc/ada/ChangeLog:

* sem_ch3.adb (Process_Subtype): Factorize initialization of variable.

7 weeks agoRISC-V: Regen riscv-ext.texi [NFC]
Kito Cheng [Tue, 10 Jun 2025 02:32:37 +0000 (10:32 +0800)] 
RISC-V: Regen riscv-ext.texi [NFC]

Regenerates the `riscv-ext.texi` file in the GCC documentation.

gcc/ChangeLog:

* doc/riscv-ext.texi: Regen.

7 weeks agoRISC-V: Add test for vec_duplicate + vremu.vv combine case 1 with GR2VR cost 0, 1...
Pan Li [Mon, 9 Jun 2025 08:35:47 +0000 (16:35 +0800)] 
RISC-V: Add test for vec_duplicate + vremu.vv combine case 1 with GR2VR cost 0, 1 and 2

Add asm dump check test for vec_duplicate + vremu.vv combine to vremu.vx,
with the GR2VR cost is 0, 1 and 2.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c: Add asm check
for vremu.vx combine.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u8.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
7 weeks agoRISC-V: Add test for vec_duplicate + vremu.vv combine case 0 with GR2VR cost 0, 2...
Pan Li [Mon, 9 Jun 2025 08:33:52 +0000 (16:33 +0800)] 
RISC-V: Add test for vec_duplicate + vremu.vv combine case 0 with GR2VR cost 0, 2 and 15

Add asm dump check test for vec_duplicate + vrem.vv combine to vrem.vx,
with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
for vremu.vx combine.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_data.h: Add test
data for run test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vrem-run-1-u16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vrem-run-1-u32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vrem-run-1-u64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vrem-run-1-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
7 weeks agoRISC-V: Reconcile the existing test for vremu.vx combine
Pan Li [Mon, 9 Jun 2025 08:28:50 +0000 (16:28 +0800)] 
RISC-V: Reconcile the existing test for vremu.vx combine

Some existing vrem related test need some adjust for the
asm check due to cost model.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/binop/vrem-rv32gcv.c: Adjust the
asm check for vremu.
* gcc.target/riscv/rvv/autovec/binop/vrem-rv64gcv.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
7 weeks agoRISC-V: Combine vec_duplicate + vremu.vv to vremu.vx on GR2VR cost
Pan Li [Mon, 9 Jun 2025 08:24:34 +0000 (16:24 +0800)] 
RISC-V: Combine vec_duplicate + vremu.vv to vremu.vx on GR2VR cost

This patch would like to combine the vec_duplicate + vremu.vv to the
vremu.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;                                            \
  }

  DEF_VX_BINARY(int32_t, /)

Before this patch:
  10   │ test_vx_binary_or_int32_t_case_0:
  11   │     beq a3,zero,.L8
  12   │     vsetvli a5,zero,e32,m1,ta,ma
  13   │     vmv.v.x v2,a2
  14   │     slli    a3,a3,32
  15   │     srli    a3,a3,32
  16   │ .L3:
  17   │     vsetvli a5,a3,e32,m1,ta,ma
  18   │     vle32.v v1,0(a1)
  19   │     slli    a4,a5,2
  20   │     sub a3,a3,a5
  21   │     add a1,a1,a4
  22   │     vremu.vv v1,v1,v2
  23   │     vse32.v v1,0(a0)
  24   │     add a0,a0,a4
  25   │     bne a3,zero,.L3

After this patch:
  10   │ test_vx_binary_or_int32_t_case_0:
  11   │     beq a3,zero,.L8
  12   │     slli    a3,a3,32
  13   │     srli    a3,a3,32
  14   │ .L3:
  15   │     vsetvli a5,a3,e32,m1,ta,ma
  16   │     vle32.v v1,0(a1)
  17   │     slli    a4,a5,2
  18   │     sub a3,a3,a5
  19   │     add a1,a1,a4
  20   │     vremu.vx v1,v1,a2
  21   │     vse32.v v1,0(a0)
  22   │     add a0,a0,a4
  23   │     bne a3,zero,.L3

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_vx_binary_vec_vec_dup): Add new
case UMOD.
* config/riscv/riscv.cc (riscv_rtx_costs): Ditto.
* config/riscv/vector-iterators.md: Add new op umod.

Signed-off-by: Pan Li <pan2.li@intel.com>
7 weeks agoDaily bump.
GCC Administrator [Tue, 10 Jun 2025 00:18:54 +0000 (00:18 +0000)] 
Daily bump.

7 weeks ago[AutoFDO] Fix profile bootstrap for x86_64
Kugan Vivekanandarajah [Mon, 9 Jun 2025 23:19:37 +0000 (09:19 +1000)] 
[AutoFDO] Fix profile bootstrap for x86_64

This patch fixes profile bootstrap for x86_64 by special
caseing cpu_type for x86_64 as it shares AUTO_PROFILE
from i386.

ChangeLog:

* configure.ac: Special case cpu_type for x86_64.
* configure: Regenerate.

Signed-off-by: Kugan Vivekanandarajah <kvivekananda@nvidia.com>
7 weeks agoc: Add remove_qualifier helper function [PR120510]
Martin Uecker [Sat, 7 Jun 2025 13:55:34 +0000 (15:55 +0200)] 
c: Add remove_qualifier helper function [PR120510]

Add a helper function to replace repeated code for removing
qualifiers but not atomic.  Make sure to also remove qualifiers
but not atomic from the element type of arrays.

PR c/120510

gcc/c/ChangeLog:
* c-typeck.cc (remove_qualifiers): New function.
(composite_type_internal): Use it.
(comp_target_types): Use it.
(type_lists_compatible_p): Use it.
(find_anonymous_field_with_type): Use it.
(convert_to_anonymous_field): Use it.
(convert_for_assignment): Use it.

7 weeks agoc: partial fix for qualifier inconsistency II [PR120510]
Martin Uecker [Sat, 7 Jun 2025 12:24:28 +0000 (14:24 +0200)] 
c: partial fix for qualifier inconsistency II [PR120510]

This fixes a case where we invoke composite_type with types
that do not have matching qualifiers.  With this change, we can
activate the checking assertion that makes sure the composite
type is compatible with the two original types also for arrays.

PR c/120510

gcc/c/ChangeLog:
* c-typeck.cc (composite_type_internal): Activate checking
assertion for arrays.
(common_pointer_type): Remove qualifiers also from arrays.

7 weeks agoc: partial fix for qualifier inconsistency [PR120510]
Martin Uecker [Thu, 5 Jun 2025 21:55:39 +0000 (23:55 +0200)] 
c: partial fix for qualifier inconsistency [PR120510]

Checking assertions revealed that we sometimes produce
composite types with incorrect qualifiers, e.g. the example

int f(int [_Atomic]);
int f(int [_Atomic]);
int f(int [_Atomic]);

was rejected because atomic was lost in the second declaration.

PR c/120510

gcc/c/ChangeLog:
* c-typeck.cc (composite_types_internal): Handle arrays
declared with atomic for function arguments.

gcc/testsuite/ChangeLog:
* gcc.dg/pr120510.c

7 weeks agoc++: Fix template class lookup [PR120495, PR115605].
Iain Sandoe [Mon, 2 Jun 2025 08:42:23 +0000 (09:42 +0100)] 
c++: Fix template class lookup [PR120495, PR115605].

In the reported issues, using lookup_template_class () directly on (for example)
the coroutine_handle identifier fails because a class-local  TYPE_DECL is found.
This is because, in the existing code, lookup is called with default parameters
which means that class contexts are examined first.

Fix this, when a context is provided by the caller, by doing lookup in namespace
provided.

PR c++/120495
PR c++/115605

gcc/cp/ChangeLog:

* pt.cc (lookup_template_class): Honour provided namespace contexts
when looking up class templates.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr120495.C: New test.
* g++.dg/pr115605.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
7 weeks agoMAINTAINERS: Update my email address
Peter Bergner [Mon, 9 Jun 2025 21:01:52 +0000 (16:01 -0500)] 
MAINTAINERS: Update my email address

2025-06-09  Peter Bergner  <bergner@tenstorrent.com>

* MAINTAINERS: Update my email address and add myself to DCO.

Signed-off-by: Peter Bergner <bergner@tenstorrent.com>
7 weeks agodiagnostics: convert enum logical_location_kind to enum class
David Malcolm [Mon, 9 Jun 2025 18:15:25 +0000 (14:15 -0400)] 
diagnostics: convert enum logical_location_kind to enum class

No functional change intended.

gcc/ChangeLog:
* diagnostic-format-sarif.cc (maybe_get_sarif_kind): Update for
conversion of enum logical_location_kind to enum class.
* diagnostic.cc (logical_location_manager::function_p): Likewise.
* libgdiagnostics.cc (html-output/missing-semicolon.py::get_kind):
Likewise.
* logical-location.h (enum logical_location_kind): Convert to...
(enum class logical_location_kind): ...this.
* selftest-logical-location.cc
(test_logical_location_manager::item_from_funcname): Update for
conversion of enum logical_location_kind to enum class.
* tree-logical-location.cc
(tree_logical_location_manager::get_kind): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
7 weeks agoPR modula2/120606: FOR loop ICE if the last expression uses an array
Gaius Mulley [Mon, 9 Jun 2025 17:26:36 +0000 (18:26 +0100)] 
PR modula2/120606: FOR loop ICE if the last expression uses an array

This patch fixes the ICE which occurs if the last expression is an array.
It ensures that the start and end values of the for loop expressions are
dereferenced.

gcc/m2/ChangeLog:

PR modula2/120606
* gm2-compiler/M2Quads.mod (ForLoopLastIterator): Dereference
start and end expressions e1 and e2 respectively.

gcc/testsuite/ChangeLog:

PR modula2/120606
* gm2/pim/pass/forarray.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
7 weeks agoFix profile updating in ipa-cp
Jan Hubicka [Fri, 6 Jun 2025 15:57:00 +0000 (17:57 +0200)] 
Fix profile updating in ipa-cp

Bootstrapping with autoprofiledbootstrap, LTO and checking enables ICEs in WPA
because we end up mixing local and IPA count in
ipa-cp.cc:update_specialized_profile.  This is because of missing call to
profile_count::adjust_for_ipa_scaling.  While looking into that I however
noticed that the function forgets to update indirect call edges. This made me
to commonize same logic which currently exists in clone_inlined_nodes,
update_specialized_profile, update_profiling_info and
update_counts_for_self_gen_clones.

While testing it I noticed that we also ICE when linking with
-fdump-ipa-all-details-blocks since IPA and local counts are temporarily mixed
during IPA transformation stage, so I also added check to profile_count::dump
to not crash and added verifier to gimple_verify_flow_info.

Other problem I also noticed is that while profile updates done by inliner (via
cgraph_node::clone) are correctly using global0 profiles instead of erasing
profile completely when IPA counts drops to 0, the scaling in ipa-cp is not
doing that, so we lose info and possibly some code quality.  I will fix that
incrementally. Similarly ipa-split, when offlining region with 0 entry count
may re-do frequency propagation to get something useful.

gcc/ChangeLog:

* cgraph.cc (cgraph_node::apply_scale): New member function.
* cgraph.h (struct cgraph_node): declare.
* ipa-cp.cc (update_counts_for_self_gen_clones):
Use cgraph_node::apply_scale.
(update_profiling_info): Do not overwrite local
profile when dropping to 0 global profile.
(update_specialized_profile): Likewise.
* ipa-inline-transform.cc (update_noncloned_counts): Remove.
(can_remove_node_now_p_1): Fix formating.
(clone_inlined_nodes): Use cgraph_node::apply_scale.
* profile-count.cc (profile_count::dump): Do not ICE
when count is not compatible with entry block count.
* tree-cfg.cc (gimple_verify_flow_info): Check
compatibility of count and entry block count.

7 weeks agoPR modula2/119779: ASM examples no longer work
Gaius Mulley [Mon, 9 Jun 2025 14:26:35 +0000 (15:26 +0100)] 
PR modula2/119779: ASM examples no longer work

This patch introduces a regression test using the example in the
documentation and tests it using -masm=intel on x86_64-*-gnu systems.

gcc/testsuite/ChangeLog:

PR modula2/119779
* gm2.dg/doc/examples/run/pass/doc-examples-run-pass.exp: New test.
* gm2.dg/doc/examples/run/pass/exampleadd2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
7 weeks agodiagnostics: fix <title> of experimental-html output [PR116792]
David Malcolm [Mon, 9 Jun 2025 13:40:06 +0000 (09:40 -0400)] 
diagnostics: fix <title> of experimental-html output [PR116792]

Add a new vfunc diagnostic_output_format::set_main_input_filename
so that we can separate setting the <title> of HTML output and
the diagnostic_artifact_role::analysis_target of SARIF output from
creation of the sinks.  Calling it is done by the various creators
of the sinks.

gcc/ChangeLog:
PR other/116792
* diagnostic-format-html.cc (html_builder::m_title_element): New
field.
(html_builder::html_builder): Initialize it.  Don't add
placeholder text.
(html_builder::set_main_input_filename): New.
(html_output_format::set_main_input_filename): New.
(test_html_diagnostic_context::test_html_diagnostic_context): Call
set_main_input_filename on the new sink.
(seldtest::test_simple_log): Update expected <title> text.
* diagnostic-format-json.cc (diagnostic_output_format_init_json):
Return a reference to the new sink.
(diagnostic_output_format_init_json_stderr): Likewise.
(diagnostic_output_format_init_json_file): Likewise.
* diagnostic-format-sarif.cc (sarif_builder::sarif_builder): Drop
"main_input_filename_" param, and move adding an artifact for it
with diagnostic_artifact_role::analysis_target to...
(sarif_builder::set_main_input_filename): ...this new function.
(sarif_output_format::set_main_input_filename): New.
(sarif_output_format::sarif_output_format): Drop
"main_input_filename_" param.
(sarif_stream_output_format::sarif_stream_output_format):
Likewise.
(sarif_file_output_format::sarif_file_output_format): Likewise.
(diagnostic_output_format_init_sarif): Return a reference to *FMT.
(diagnostic_output_format_init_sarif_stderr): Return a refererence
to the new sink.  Drop "main_input_filename_" param.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
(make_sarif_sink): Drop "main_input_filename_" param.
(selftest::test_sarif_diagnostic_context::test_sarif_diagnostic_context):
Likewise.  Call set_main_input_filename on the new format.
(selftest::test_sarif_diagnostic_context::buffered_output_format::buffered_output_format):
Drop "main_input_filename_" param.
(selftest::test_make_location_object): Likewise.
* diagnostic-format-sarif.h
(diagnostic_output_format_init_sarif_stderr): Return a refererence
to the new sink.  Drop "main_input_filename_" param.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
(make_sarif_sink): Drop "main_input_filename_" param.
* diagnostic-format.h
(diagnostic_output_format::set_main_input_filename): New vfunc.
(diagnostic_output_format_init_json_stderr): Return a refererence
to the new sink.
(diagnostic_output_format_init_json_file): Likewise.
* diagnostic.cc (diagnostic_output_format_init): Likewise.  Call
set_main_input_filename on the new sink.
* libgdiagnostics.cc (sarif_sink::sarif_sink): Update for above
changes.
* opts-diagnostic.cc (sarif_scheme_handler::make_sink): Likewise.
(handle_OPT_fdiagnostics_add_output_): Likewise.
(handle_OPT_fdiagnostics_set_output_): Likewise.

gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/html-output/missing-semicolon.py: Update expected <title>
text.  Drop out-of-date comment.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
7 weeks ago[RISC-V] Enable more if-conversion on RISC-V
Jeff Law [Mon, 9 Jun 2025 12:55:21 +0000 (06:55 -0600)] 
[RISC-V] Enable more if-conversion on RISC-V

Another czero related adjustment.  This time in costing of conditional move
sequences.  Essentially a copy from a promoted subreg can and should be ignored
from a costing standpoint.  We had some code to do this, but its conditions
were too strict.

No real surprises evaluating spec.  This should be a minor, but probably not
measurable improvement in x264 and xz.   It is if-converting more in some
particular harm to hot routines, but not necessarily in the hot parts of those
routines.

It's been tested on riscv32-elf and riscv64-elf.  Versions of this have
bootstrapped and regression tested as well, though perhaps not this exact
version.

Waiting on pre-commit testing.

gcc/
* config/riscv/riscv.cc (riscv_noce_conversion_profitable_p): Relax
condition for adjustments due to copies from promoted SUBREGs.

7 weeks agopowerpc: testsuite: Fix powerpc FMV symbol tests [PR 120519]
Alfie Richards [Wed, 4 Jun 2025 15:24:36 +0000 (15:24 +0000)] 
powerpc: testsuite: Fix powerpc FMV symbol tests [PR 120519]

As discussed on the BZ page, this removes the overly specific resolver tests
which proved overly specific, and modifies the jump instructions.

gcc/testsuite/ChangeLog:

PR testsuite/120519
* g++.target/powerpc/mvc-symbols1.C: Modify tests.
* g++.target/powerpc/mvc-symbols2.C: Ditto.
* g++.target/powerpc/mvc-symbols3.C: Ditto.
* g++.target/powerpc/mvc-symbols4.C: Ditto.

7 weeks agoada: Support fixed-lower-bound array types as generic actual parameters
Gary Dismukes [Mon, 17 Mar 2025 18:30:00 +0000 (18:30 +0000)] 
ada: Support fixed-lower-bound array types as generic actual parameters

Attempting to use a fixed-lower-bound array type (or subtype) as
an actual parameter for a formal unconstrained array type was being
rejected by the compiler (complaining about the index type of the
actual not matching the index type of the formal type).  The compiler
was improperly testing the actual's FLB range and finding that it didn't
statically match the index type of the formal array type; it should
instead test the underlying index type of the FLB type or subtype.

gcc/ada/ChangeLog:

* sem_ch3.adb (Constrain_Index): In the case of a fixed-lower-bound index,
set Etype of the newly created itype's Scalar_Range from the index's Etype.
* sem_ch12.adb (Validate_Array_Type_Instance): If the actual subtype is
a fixed-lower-bound type, then check again the Etype of its Scalar_Range.

7 weeks agoada: Reject component-related aspects on formal non-array types
Piotr Trojanek [Mon, 17 Mar 2025 12:20:53 +0000 (13:20 +0100)] 
ada: Reject component-related aspects on formal non-array types

In Ada 2022 aspects Atomic_Components and Volatile_Components can be specified
for a formal array type, but they were wrongly accepted on any formal type.

Also, we don't need to check if the corresponding pragmas appear in Ada 2022
mode, because generic formal parameters can't have explicit representation
pragmas in any Ada version and can only have aspects since Ada 2022.

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pragma): Fix conditions for legality checks on
formal type declarations.

7 weeks agoada: Fix glitch in handling of Atomic_Components on generic formal type
Piotr Trojanek [Mon, 17 Mar 2025 11:57:26 +0000 (12:57 +0100)] 
ada: Fix glitch in handling of Atomic_Components on generic formal type

In Ada 2022 aspects Atomic_Components and Volatile_Components can be specified
for a formal array type, but then they need to be set on the base type entity.
Otherwise we get an assertion failure in debug build and wrong legality errors
in production builds.

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pragma): If pragmas apply to a formal array
type, then set the flags on the base type.

7 weeks agoada: Clarify code in Process_Subtype
Ronan Desplanques [Fri, 14 Mar 2025 13:41:56 +0000 (14:41 +0100)] 
ada: Clarify code in Process_Subtype

This patch factorizes two if statements together in the body of
Process_Subtype, to improve readability.

gcc/ada/ChangeLog:

* sem_ch3.adb (Process_Subtype): Clarify code.

7 weeks agoada: Add null exclusion formal to Process_Subtype
Ronan Desplanques [Thu, 13 Mar 2025 15:28:59 +0000 (16:28 +0100)] 
ada: Add null exclusion formal to Process_Subtype

Before this patch, Process_Subtype looked at the parent of its argument
to determine whether it was called in a context that excluded null. This
patch replaces this lookup with a new formal parameter to
Process_Subtype, and updates the calls to it accordingly.

gcc/ada/ChangeLog:

* sem_ch3.ads (Process_Subtype): Add formal.
* sem_ch3.adb (Process_Subtype): Use new formal.
(Analyze_Subtype_Declaration, Array_Type_Declaration,
Build_Derived_Access_Type): Pass new actual.
* sem_ch4.adb (Find_Type_Of_Object): Likewise.

7 weeks agoada: Call Mutate_Ekind earlier for formal entities
Ronan Desplanques [Thu, 13 Mar 2025 13:12:52 +0000 (14:12 +0100)] 
ada: Call Mutate_Ekind earlier for formal entities

This patch migrates the handling of "premature usage" type of error to
the Is_Self_Hidden mechanism.

gcc/ada/ChangeLog:

* sem_ch6.adb (Set_Formal_Mode): Extend profile. Move parts of the
body…
(Process_Formals): … here. Move call to Set_Formal_Mode earlier. Call
Set_Is_Not_Self_Hidden in second traversal.

7 weeks agoada: Missing discriminant check on assignment of Bounded_Vector aggregate
Gary Dismukes [Sat, 8 Mar 2025 01:05:35 +0000 (01:05 +0000)] 
ada: Missing discriminant check on assignment of Bounded_Vector aggregate

When a container aggregate for a Bounded_Vector type involves an iterated
association that is assigned to a vector object whose capacity (as defined
by the Capacity discriminant) is less than the number of elements of the
aggregate, Constraint_Error should be raised due to failing a discriminant
check on the assignment. But the compiler fails to do proper expansion,
plus omits the check, and instead creates a temporary whose capacity is
bounded by that of the target vector of the assignment. It attempts to
assign all elements of the aggregate to the temporary, resulting in
a failure on a call to the Replace_Element operation that assigns past
the length of the temporary vector (which can result in a Storage_Error
due to a segment violation).

This is fixed by ensuring that the temporary object is declared with
an unconstrained base subtype rather than the assignment target's
constrained subtype.

gcc/ada/ChangeLog:

* exp_aggr.adb (Expand_Container_Aggregate): Use the Base_Type of the
subtype provided by the context as the subtype of the temporary object
initialized by the aggregate.

7 weeks agoada: Remove duplicated code in parser for Chapter 4 (continued)
Eric Botcazou [Mon, 10 Mar 2025 11:02:45 +0000 (12:02 +0100)] 
ada: Remove duplicated code in parser for Chapter 4 (continued)

P_Qualified_Simple_Name and P_Function_Name contain essentially the same
code, except that P_Function_Name does not error out on an operator symbol
that is followed by something else than a dot.

This deletes P_Function_Name and changes P_Qualified_Simple_Name[_Resync]
to not error out either in this case, with the only consequence that the
error message given for:

  generic
    type T is private;
  function "&" (A, B : String) return String;

  procedure Proc is new "&" (Integer);

is now identical to the one given for:

  generic
    type T is private;
  function "&" (A, B : String) return String;

  function Func is new "&" (Integer);

namely:

q.ads:7:12: error: operator symbol not allowed for generic subprogram

gcc/ada/ChangeLog:

* par-ch4.adb (P_Function_Name): Delete body.
(P_Qualified_Simple_Name_Resync): Do not raise Error_Resync on an
operator symbol followed by something else than a dot.
* par-ch6.adb (P_Subprogram): Do not call P_Function_Name.
* par.adb (P_Function_Name): Delete declaration.

7 weeks agoada: Set Ekind of components earlier
Ronan Desplanques [Mon, 10 Mar 2025 09:37:11 +0000 (10:37 +0100)] 
ada: Set Ekind of components earlier

Before this patch, the calls to set the proper Ekind of component
entities were delayed in order to catch "premature usage" type of
errors. This patch moves those calls to the natural place, at the
beginning of Analyze_Component_Declaration, and makes premature usage
error dectection use the newer Is_Self_Hidden mechanism.

The motivation for this patch is to accomodate future removals of
operations on E_Void entities.

gcc/ada/ChangeLog:

* sem.adb (Analyze): Adapt to new Ekinds.
* sem_ch3.adb (Analyze_Component_Declaration): Set Ekind early.
(Is_Visible_Component, Record_Type_Definition): Adjust.

7 weeks agoada: Fix comment
Ronan Desplanques [Mon, 10 Mar 2025 09:31:21 +0000 (10:31 +0100)] 
ada: Fix comment

gcc/ada/ChangeLog:

* sem.adb (Analyze): Fix comment.

7 weeks agoada: Remove duplicated code in parser for Chapter 4
Eric Botcazou [Fri, 7 Mar 2025 16:37:58 +0000 (17:37 +0100)] 
ada: Remove duplicated code in parser for Chapter 4

P_Qualified_Simple_Name and P_Qualified_Simple_Name_Resync contain exactly
the same code, so this change makes the former call the latter.

gcc/ada/ChangeLog:

* par-ch4.adb (P_Name): Remove obsolete references in comments.
(P_Qualified_Simple_Name): Call P_Qualified_Simple_Name_Resync.
(P_Qualified_Simple_Name_Resync): Adjust a couple of comments.

7 weeks agoada: Fix SPARK test failures caused by new handling of inherited class-wide pre/post
Gary Dismukes [Fri, 7 Mar 2025 19:35:25 +0000 (19:35 +0000)] 
ada: Fix SPARK test failures caused by new handling of inherited class-wide pre/post

The revised handling of inherited class-wide pre/postconditions (for
properly implementing the rules of RM 6.1.1(7/5)) broke two SPARK tests
(N709-001__contracts and V516-041__private_ownership). This change fixes
that, by refining the test for detecting formal parameters used as actuals
in calls to primitive functions, as well as adding handling for 'Result
attributes given as actuals in such calls.

gcc/ada/ChangeLog:

* exp_util.adb (Call_To_Parent_Dispatching_Op_Must_Be_Mapped): Replace
test of Covers with test of Is_Controlling_Formal. Add handling for
'Result actuals. Remove Actual_Type and its uses.

7 weeks agoada: Simplify handling of selected components as name references
Piotr Trojanek [Fri, 7 Mar 2025 11:08:44 +0000 (12:08 +0100)] 
ada: Simplify handling of selected components as name references

The selector_name of a selected_component always points to an identifier than
is an object name, i.e. specifically, name of a component or discriminant.
There is no need to examine this.

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

* sem_util.adb (Is_Name_Reference): Remove check for selector_name of a
selected_component; reuse existing code for indexed components and
slices.
(Statically_Names_Object): Remove dead code.

7 weeks agoada: Restrict Overlays_Constant flag to selected entities
Eric Botcazou [Fri, 7 Mar 2025 08:36:45 +0000 (09:36 +0100)] 
ada: Restrict Overlays_Constant flag to selected entities

Namely E_Constant and E_Variable entities.

gcc/ada/ChangeLog:

* einfo.ads (Overlays_Constant): Define in constants and variables.
* gen_il-gen-gen_entities.adb (Entity_Kind): Move Overlays_Constant
semantic flag to...
(Constant_Or_Variable_Kind): ...here.
* sem_util.adb (Note_Possible_Modification): Add guard.

7 weeks agoada: Back out removal of renaming tranformation
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.

7 weeks agoada: Set Ekind early in object declarations
Ronan Desplanques [Thu, 6 Mar 2025 11:54:44 +0000 (12:54 +0100)] 
ada: Set Ekind early in object declarations

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.

gcc/ada/ChangeLog:

* sem_ch3.adb (Analyze_Object_Declaration): Call Mutate_Ekind earlier.

7 weeks agoada: Tweak error recovery path
Ronan Desplanques [Thu, 6 Mar 2025 11:54:44 +0000 (12:54 +0100)] 
ada: Tweak error recovery path

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.

7 weeks agoada: Specialize syntax error on malformed Abstract_State contract
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.

7 weeks agoada: Do not build dispatch tables for generics
Ronan Desplanques [Wed, 5 Mar 2025 15:18:49 +0000 (16:18 +0100)] 
ada: Do not build dispatch tables for generics

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.

gcc/ada/ChangeLog:

* sem_ch10.adb (Analyze_Compilation_Unit): Check for generic bodies.
* exp_disp.adb (Build_Dispatch_Tables): Likewise.

7 weeks agoada: Tune recent change for warning about unsupported overlays
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.

7 weeks agoada: Pragma Ada_XX not propagated from library level spec to body
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.

gcc/ada/ChangeLog:

* doc/gnat_rm/implementation_defined_pragmas.rst: Adding
documentation.
* doc/gnat_ugn/the_gnat_compilation_model.rst: ditto.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

7 weeks agoada: Remove redundant error checking
Ronan Desplanques [Tue, 4 Mar 2025 12:16:39 +0000 (13:16 +0100)] 
ada: Remove redundant error checking

This patch removes a test for a condition that can never be false.

gcc/ada/ChangeLog:

* sem_attr.adb (Analyze_Attribute): Remove test.

7 weeks agoada: Remove unnecessary special handling
Ronan Desplanques [Tue, 4 Mar 2025 13:29:07 +0000 (14:29 +0100)] 
ada: Remove unnecessary special handling

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.

7 weeks agoada: Remove misleading comment
Ronan Desplanques [Tue, 4 Mar 2025 13:24:32 +0000 (14:24 +0100)] 
ada: Remove misleading comment

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.

gcc/ada/ChangeLog:

* sem_util.adb (Enter_Name): Remove comment.

7 weeks agoada: Constraint check on tagged build-in-place object decls
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.

7 weeks agoada: Remove incorrect bits in Copy_Node documentation
Ronan Desplanques [Fri, 28 Feb 2025 10:50:30 +0000 (11:50 +0100)] 
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.

gcc/ada/ChangeLog:

* atree.ads (Copy_Node): Fix comment.

7 weeks agoada: Check validity using signedness from the type and not its base type
Piotr Trojanek [Tue, 4 Mar 2025 11:33:34 +0000 (12:33 +0100)] 
ada: Check validity using signedness from the type and not its base type

When attribute Valid is applied to a private type, we used the signedness of
its implementation base type which wrongly included negative values.

gcc/ada/ChangeLog:

* exp_attr.adb (Expand_N_Attribute_Reference): When expanding attribute
Valid, use signedness from the validated view, not from its base type.

7 weeks agoada: Emit more warnings on unsupported overlay
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.

7 weeks agoada: Incorrect creation of corresponding expression of class-wide contracts
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).

7 weeks agoada: Remove outdated comment
Ronan Desplanques [Mon, 3 Mar 2025 14:42:32 +0000 (15:42 +0100)] 
ada: Remove outdated comment

This patch removes a comment that was made incorrect by the introduction
of Is_Self_Hidden.

gcc/ada/ChangeLog:

* sem_ch3.adb (Analyze_Object_Declaration): Remove comment.

7 weeks agoada: Add example in Current_Entity_In_Scope comment
Ronan Desplanques [Mon, 3 Mar 2025 11:03:02 +0000 (12:03 +0100)] 
ada: Add example in Current_Entity_In_Scope comment

gcc/ada/ChangeLog:

* sem_util.ads (Current_Entity_In_Scope): Add example in comment.

7 weeks agoada: Clarify warning in Atree.Rewrite documentation
Ronan Desplanques [Fri, 28 Feb 2025 11:25:20 +0000 (12:25 +0100)] 
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.

gcc/ada/ChangeLog:

* atree.ads (Rewrite, Replace): Clarify comments.

7 weeks agoada: Remove incorrect comment
Ronan Desplanques [Fri, 28 Feb 2025 11:24:04 +0000 (12:24 +0100)] 
ada: Remove incorrect comment

This patchs removes a comment that was incorrect, as noted by a ???
comment that was right after and that this patch also removes.

gcc/ada/ChangeLog:

* atree.ads (Rewrite): Remove comment.

7 weeks agoada: Improve readability in Atree.Rewrite body
Ronan Desplanques [Fri, 28 Feb 2025 11:19:12 +0000 (12:19 +0100)] 
ada: Improve readability in Atree.Rewrite body

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.

gcc/ada/ChangeLog:

* atree.adb (Rewrite): Improve readability.

7 weeks agoada: Tweak Kill_Current_Values
Ronan Desplanques [Thu, 27 Feb 2025 10:25:45 +0000 (11:25 +0100)] 
ada: Tweak Kill_Current_Values

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.

gcc/ada/ChangeLog:

* sem_util.adb (Kill_Current_Values): Tweak condition.