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>
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.
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>
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):
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 :)
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.
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)).
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.
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.
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.
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>
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>
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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".
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.
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.
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.
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.
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.
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; \
}
* 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.