Michal Jires [Sat, 15 Nov 2025 23:54:00 +0000 (00:54 +0100)]
ipa: Add flag ref_by_asm to symtab_node
ref_by_asm will be used by toplevel assembly to mark symbols that cannot
be removed.
It largely overlaps with force_output. Main difference is that ref_by_asm
is meaningful on declarations by not removing them. force_output with
declaration is ignored, which cannot be easily changed, since several
places depend on this behavior.
Global ref_by_asm should not be localized, because they cannot benefit
from it. It would only result in complications, for example by renaming
the symbol.
Notes on different solutions in unreachability analysis:
First unreachability analysis is done in analyze_functions. Marking
ref_by_asm declarations as needed from the start would require reprocessing,
because some declarations may gain definition during the analysis.
Since at this point declarations do not need adding any other symbol,
we can check for ref_by_asm at the end, next to referred_to_p check.
Second unreachability analysis is in remove_unreachable_nodes. Here
declarations (or symbols in_other_partition) may require an alias.
So there we need to add the declarations from the start.
POST_INC is a code that's only supposed to be valid in an address, so
it should only be calculated through the TARGET_ADDRESS_COST hook, not
by the TARGET_RTX_COSTS hook. But, because rtx_cost does not
special-case MEM costs by calling TARGET_ADDRESS_COST, we get here as
part of e.g. the auto-inc-dec and combine passes, so deal with it for
the time being. Without this, the cost is the value of size_factor *
COSTS_N_INSNS (1), i.e. 4 per word. There's no obvious observable
effect for generated code (coremark, libgcc and newlib-libc checked
for -march=v10), but it may make a difference in the future, so be
safe and correct the cost.
Tested at r16-6493-ge77ba7ef8c75 for cris-elf. That the cost actually
is changed is observable mostly simply by applying -dp when compiling
int incref(int n, char *p)
{
int sum = 0;
while (n--)
sum += *p++;
return sum;
}
and seeing that the cost for the single autoincrement is changed from e.g.
adds.b [$r11+],$r10 ;# 15 [c=12 l=2] *addsqisi_swap/1
to
adds.b [$r11+],$r10 ;# 15 [c=8 l=2] *addsqisi_swap/1
gcc:
* config/cris/cris.cc (cris_rtx_costs) <POST_INC>: Handle POST_INC
as ZERO_EXTEND and SIGN_EXTEND, i.e. as an operator without cost.
Jerome Guitton [Fri, 5 Dec 2025 23:04:40 +0000 (20:04 -0300)]
remove inclusion of tickLib.h from gthr-vxworks.h
This header is not used any more and its inclusion is problematic
when building against Helix Cert as it might end up dragging LLVM-specific
headers from spinLockLib.h.
libgcc/
* config/gthr-vxworks.h: Remove #include of tickLib.h.
Jeff Law [Sat, 10 Jan 2026 18:23:41 +0000 (11:23 -0700)]
Fix regression on mcore-elf port after recent switch conversion change
Filip's recent change to re-enable switch conversion at -Og triggered a
regression on the mcore-elf target.
If we look at tree-switch-conversion.cc we have this:
if (flag_pic)
return false;
The mcore-elf port defines a dummy ASM_OUTPUT_ADDR_DIFF_ELT which is designed
to trigger an assembler syntax error and thus fail loudly. That definition
comes from a time when it appears we had to define that macro in every port,
even if it wasn't being used.
These days we do not need to define that macro unless it's really needed. And
a definition like the one for mcore-elf will cause problems
(compile/pr69102.c). That definition has also been the cause of a long
standing failure in the port (gcc.dg/pr47446-2.c).
Naturally this has been through a round of testing where it fixes the two
issues noted above without any regressions.
This patch adds support for _Float16. As time of writing this, there is
no hardware _Float16 support on s390. Therefore, _Float16 operations
have to be extended and truncated which is supported via soft-fp.
The ABI demands that _Float16 values are left aligned in FP registers
similar as it is already the case for 32-bit FP values. If vector
extensions are available, copying between left-aligned FPRs and
right-aligned GPRs is natively supported. Without vector extensions,
the alignment has to be taken care of manually. For target z10,
instructions lgdr/ldgr can be used in conjunction with shifts. Copying
via lgdr from an FPR into a GPR is the easy case since for the shift the
target GPR can be utilized. However, copying via ldgr from a GPR into a
FPR requires a secondary reload register which is used for the shift
result and is then copied into the FPR. Prior z10, there is no hardware
support in order to copy directly between FPRs and GPRs. Therefore, in
order to copy from a GPR into an FPR we would require a secondary reload
register for the shift and secondary memory for copying the aligned
value. Since this is not supported, _Float16 support starts with z10.
As a consequence, for all targets older than z10 test
libstdc++-abi/abi_check fails.
gcc/ChangeLog:
* config/s390/s390-modes.def (FLOAT_MODE): Add HF mode.
(VECTOR_MODE): Add V{1,2,4,8,16}HF modes.
* config/s390/s390.cc (s390_scalar_mode_supported_p): For 64-bit
targets z10 and newer support HF mode.
(s390_vector_mode_supported_p): Add HF mode.
(s390_register_move_cost): Keep HF mode operands in registers.
(s390_legitimate_constant_p): Support zero constant.
(s390_secondary_reload): For GPR to FPR moves a secondary reload
register is required.
(s390_secondary_memory_needed): GPR<->FPR moves don't require
secondary memory.
(s390_libgcc_floating_mode_supported_p): For 64-bit targets z10
and newer support HF mode.
(s390_hard_regno_mode_ok): Allow HF mode for FPRs and VRs.
(s390_function_arg_float): Consider HF mode, too.
(s390_excess_precision): For EXCESS_PRECISION_TYPE_FLOAT16
return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.
(TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P): Define.
* config/s390/s390.md (movhf): Define.
(reload_half_gprtofpr_z10): Define.
(signbithf2): Define.
* config/s390/vector.md: Add new vector modes to various
iterators.
libgcc/ChangeLog:
* config.host: Include s390/t-float16.
* config/s390/libgcc-glibc.ver: Export symbols
__trunc{sf,df,tf}hf2, __extendhf{sf,df,tf}2, __fix{,uns}hfti,
__float{,un}tihf, __floatbitinthf.
* config/s390/t-softfp: Add to softfp_extras instead of setting
it.
* configure: Regenerate.
* configure.ac: Support float16 only for 64-bit targets z10 and
newer.
* config/s390/_dpd_dd_to_hf.c: New file.
* config/s390/_dpd_hf_to_dd.c: New file.
* config/s390/_dpd_hf_to_sd.c: New file.
* config/s390/_dpd_hf_to_td.c: New file.
* config/s390/_dpd_sd_to_hf.c: New file.
* config/s390/_dpd_td_to_hf.c: New file.
* config/s390/t-float16: New file.
* g++.target/s390/float16-1.C: New test.
* g++.target/s390/float16-2.C: New test.
* gcc.target/s390/float16-1-2.h: New test.
* gcc.target/s390/float16-1.c: New test.
* gcc.target/s390/float16-10.c: New test.
* gcc.target/s390/float16-2.c: New test.
* gcc.target/s390/float16-3.c: New test.
* gcc.target/s390/float16-4.c: New test.
* gcc.target/s390/float16-5.c: New test.
* gcc.target/s390/float16-6.c: New test.
* gcc.target/s390/float16-7.c: New test.
* gcc.target/s390/float16-8.c: New test.
* gcc.target/s390/float16-9.c: New test.
* gcc.target/s390/float16-signbit.h: New test.
* gcc.target/s390/vector/vec-extract-4.c: New test.
* gcc.target/s390/vector/vec-float16-1.c: New test.
Iain Sandoe [Sat, 10 Jan 2026 13:08:17 +0000 (13:08 +0000)]
Ada, Darwin: Fix bootstrap after recent warning improvements.
Similar to the changes in r16-6620, the improved gnatwu warning finds a 'use'
clause that is not needed in s-osinte__darwin.abd leading to a bootstrap
fail building the libraries.
Fixed by removing the extraneous 'use' clause.
gcc/ada/ChangeLog:
* libgnarl/s-osinte__darwin.adb: Delete unneeded use clause.
Wang Jinghao [Sat, 10 Jan 2026 10:43:14 +0000 (18:43 +0800)]
libstdc++: Fix std::system_category().message(int) on mingw32 target
On the mingw32 target, std::system_category().message(int) uses
FormatMessage api to format error messages. When the error message
contains insert sequences, it is unsafe not to use the
FORMAT_MESSAGE_OGNORE_INSERTS flag, as seen at:
https://devblogs.microsoft.com/oldnewthing/20071128-00/?p=24353
The output of FormatMessage ends with "\r\n" and includes a Full stop
character used by the current thread's UI language. Now, we will remove
"\r\n" and any trailing '.' from the output in any language environment.
In the testsuite for std::system_category().message(int), we first
switch the thread UI language to en-US to meet expectations in any
language environment.
libstdc++-v3/ChangeLog:
* src/c++11/system_error.cc (system_error_category) [_WIN32]:
Use FormatMessageA function instead of FormatMessage macro.
* testsuite/19_diagnostics/error_category/system_category.cc:
Fix typo in __MINGW32__ macro name. Adjust behavior on the
mingw32 target.
Andrew Pinski [Fri, 9 Jan 2026 10:02:01 +0000 (02:02 -0800)]
cfgcleanup: Protect latches always [PR123417]
So it turns out LOOPS_MAY_HAVE_MULTIPLE_LATCHES is set in places
along compiling. Setting it only means there might be multiple
latches currently. It does not mean let's go in an delete them
all; which is what remove_forwarder_block does currently. This
was happening before my set of patches too but since it was
only happening in merge_phi pass, latches were not cleared away
al of the time and then recreated.
This solves the problem by protecting latches all of the time
instead of depedent on LOOPS_MAY_HAVE_MULTIPLE_LATCHES not being set.
vect-uncounted_7.c needs to be xfailed here because we no longer
vectorize the code. Note the IR between GCC 15 and after this patch
is the same so I think this was just a case were the testcase
was added after the remove forwarder changes and should not have
vectorized (or vectorize differently).
Jakub Jelinek [Sat, 10 Jan 2026 10:36:25 +0000 (11:36 +0100)]
toplevel: Unbreak Ada build [PR123490]
As written earlier, the config-ml.in change from the
--with-multi-buildlist patch broke build of Ada, Ada uses
RTSDIR = rts$(subst /,_,$(MULTISUBDIR))
and expects that the primary multilib will result in rts
rather than rts_. it results in after the --with-multi-buildlist
changes.
The following patch fixes it by restoring previous behavior for
ml_subdir / MULTISUBDIR such that for primary multilib it is
still empty rather than /.
2026-01-10 Jakub Jelinek <jakub@redhat.com>
PR ada/123490
* config-ml.in: Restore ml_subdir being empty instead of /.
for the primary multilib.
Jakub Jelinek [Sat, 10 Jan 2026 10:35:30 +0000 (11:35 +0100)]
ranger: Verify gimple_call_num_args for several builtins [PR123431]
While gimple_call_combined_fn already do call
gimple_builtin_call_types_compatible_p and for most of builtins ensures
the right types of arguments, for type generic builtins it does not,
from POV of that function those functions are rettype (...).
Now, while the FE does some number of argument checking for the type
generic builtins, as the testcase below shows, it can be gamed.
So, this patch checks the number of arguments for type generic builtins
and does nothing if they have unexpected number of arguments.
Also for the returns arg verifies it can access the first argument.
2026-01-10 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/123431
* gimple-range-op.cc (gimple_range_op_handler::maybe_builtin_call):
Punt if type-generic builtins with a single argument don't have
exactly one argument. For returns_arg punt if call doesn't have
at least one argument.
Pietro Monteiro [Sat, 10 Jan 2026 01:52:13 +0000 (20:52 -0500)]
a68: Add exit function to POSIX prelude
Add the procedure `posixexit'.
gcc/algol68/ChangeLog:
* a68-low-posix.cc (a68_posix_setexitstatus): Delete function.
(a68_posix_exit): New function.
* a68-low-prelude.cc (a68_lower_setexitstatus): Delete function.
(a68_lower_posixexit): New function.
* a68-low-runtime.def (SET_EXIT_STATUS): Delete definition.
(POSIX_EXIT): Add definition for posixexit.
* a68-parser-prelude.cc (posix_prelude): Remove setexitstatus
identifier from and add posixexit identifier to standenv.
* a68.h (a68_posix_setexitstatus): Delete prototype.
(a68_lower_setexitstatus): Likewise.
(a68_posix_exit): New prototype.
(a68_lower_posixexit): Likewise.
* ga68.texi:
libga68/ChangeLog:
* ga68-posix.c (_libga68_posixexit): New function.
* ga68.h (_libga68_posixexit): New prototype.
(_libga68_set_exit_status): Delete prototype.
* ga68.map: Remove _libga68_set_exit_status from and add
_libga68_posixexit to the global map.
* libga68.c: include <stdlib.h>.
(_libga68_set_exit_status): Delete function.
(main): Return EXIT_SUCCESS.
gcc/testsuite/ChangeLog:
* algol68/execute/posix-exit-1.a68: New test.
Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
Robin Dapp [Thu, 8 Jan 2026 13:22:18 +0000 (14:22 +0100)]
forwprop: Use ssizetype for mask [PR123414].
RVV's vectors can get very large with LMUL8. In the PR we have
256-element char vectors which get permuted. For permuting them
we use a mask vectype that is deduced from the element type
without checking if the permute indices fit this type.
That leads to an invalid permute mask which gets optimized away.
This patch uses ssizetype as masktype instead.
PR tree-optimization/123414
gcc/ChangeLog:
* tree-ssa-forwprop.cc (simplify_vector_constructor):
Use ssizetype as mask type.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/pr123414.c: New test.
Thomas Koenig [Fri, 9 Jan 2026 21:00:07 +0000 (22:00 +0100)]
Fix broken bootstrap on FreeBSD.
As analyzed by Steve, on freebsd __gthread_t is a pointer type.
I thought it the cleanest solution to remove the #ifdef in gfc_unit,
make the "self" member a intptr_t and cast the return value of
__gthread_t to that type.
PR fortran/123512
libgfortran/ChangeLog:
* io/io.h: Change type of self to intptr_t.
* io/async.h (LOCK_UNIT): Cast __gthread_self () to intptr_t.
(TRYLOCK_UNIT): Likewise.
(OWN_THREAD_ID): Likewise.
Jakub Jelinek [Fri, 9 Jan 2026 20:54:38 +0000 (21:54 +0100)]
Update Copyright for gen-evolution.awk and gen-cxxapi-file.py
On Fri, Jan 09, 2026 at 05:54:47PM +0000, Joseph Myers wrote:
> I think updates to gcc/config/loongarch/genopts/gen-evolution.awk's calls
> to copyright_header are needed as well. At present, building for
> loongarch can result in files in the source tree being reverted to older
> copyright dates because the generation hasn't been updated (discovered via
> my glibc bot with GCC mainline stopping updating its GCC source tree
> because such modifications appeared in the sources). Of course this also
> shows up missing entries in contrib/gcc_update for the three files
> generated by gen-evolution.awk.
gen-evolution.awk was explicitly blacklisted
and so was gen-cxxapi-file.py, both because update-copyright.py
matched Copyright line also within the printing code but it wasn't
matching the expected form.
Fixed by making sure the printing code doesn't match it by using
print " Copy" "right (C) " ... in the awk case and
Copy{:s}right in the python case (with "" arg added).
2026-01-09 Jakub Jelinek <jakub@redhat.com>
contrib/
* update-copyright.py (GCCFilter): Don't filter out
gen-evolution.awk and gen-cxxapi-file.py.
gcc/
* config/loongarch/genopts/gen-evolution.awk: Update
copyright year.
(copyright_header): Separate parts of Copyright word
with " " so that it doesn't get matched by update-copyright.py.
(gen_full_header, gen_full_source, gen_full_def): Include
2026 year in the ranges.
gcc/cp/
* gen-cxxapi-file.py: Update copyright year. Separate
parts of Copyright word with {:s} so that it doesn't get matched
by update-copyright.py.
David Malcolm [Fri, 9 Jan 2026 20:54:16 +0000 (15:54 -0500)]
analyzer: port pop_frame_callbacks to pub/sub
More simplification/consolidation of some callback logic in analyzer in
favor of using the analyzer pub/sub channel.
No functional change intended.
gcc/analyzer/ChangeLog:
* common.h (struct on_frame_popped): New.
(subscriber::on_message): New vfunc for on_frame_popped.
* region-model.cc: Include "context.h" and "channels.h".
(region_model::pop_frame_callbacks): Delete.
(region_model::pop_frame): Port from notify_on_pop_frame to
using pub/sub channel.
* region-model.h (pop_frame_callback): Delete typedef.
(region_model::register_pop_frame_callback): Delete.
(region_model::pop_frame_callbacks): Delete.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.cc
(cpython_analyzer_events_subscriber::on_message): Implement for
on_frame_popped.
(plugin_init): Drop call to
region_model::register_pop_frame_callback in favor of the above
pub/sub handler.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Fri, 9 Jan 2026 20:54:16 +0000 (15:54 -0500)]
analyzer: port translation_unit_callbacks to pub/sub
Simplification/consolidation of some callback logic in analyzer in
favor of using the analyzer pub/sub channel.
No functional change intended.
gcc/analyzer/ChangeLog:
* analyzer-language.cc: Include "context.h" and "channels.h".
(finish_translation_unit_callbacks): Delete.
(register_finish_translation_unit_callback): Delete.
(run_callbacks): Delete.
(on_finish_translation_unit): Port from run_callbacks to pub/sub.
* analyzer-language.h (finish_translation_unit_callback): Delete
typedef.
(register_finish_translation_unit_callback): Delete decl.
* common.h (class translation_unit): New forward decl.
(struct analyzer_events::on_tu_finished): New.
(analyzer_events::subscriber::on_message): Add vfunc for
on_tu_finished messages.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.cc
(cpython_analyzer_events_subscriber::on_message): New.
(plugin_init): Port stashing of named types and global vars to
pub/sub framework.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Fri, 9 Jan 2026 20:54:16 +0000 (15:54 -0500)]
analyzer: replace PLUGIN_ANALYZER_INIT with a pub/sub channel
This patch eliminates the PLUGIN_ANALYZER_INIT event in favor of a new
analyzer_events_channel that can be subscribed to, and ports all the
in-tree analyzer plugins to using it.
The PLUGIN_* approach isn't typesafe, and the name suggests it's only
meant to be used for plugins, whereas the pub/sub approach is typesafe,
and treats the publish/subscribe network as orthogonal to whether the
code is built into the executable or is a plugin.
gcc/analyzer/ChangeLog:
* common.h: Define INCLUDE_LIST.
(class plugin_analyzer_init_iface): Replace with...
(gcc::topics::analyzer_events::on_ana_init): ...this.
(gcc::topics::analyzer_events::subscriber): New.
* engine.cc: Include "context.h" and "channels.h".
(class plugin_analyzer_init_impl): Replace with...
(class impl_on_ana_init): ...this. Fix some overlong lines.
(impl_run_checkers): Port from PLUGIN_ANALYZER_INIT to using
publish/subscribe framework.
gcc/ChangeLog:
* channels.h (gcc::topics::analyzer_events::subscriber): New
forward decl.
(compiler_channels::analyzer_events_channel): New field.
* doc/plugins.texi (PLUGIN_ANALYZER_INIT): Delete.
* plugin.cc (register_callback): Delete PLUGIN_ANALYZER_INIT.
(invoke_plugin_callbacks_full): Likewise.
* plugin.def (PLUGIN_ANALYZER_INIT): Delete this event.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.cc: Port from
PLUGIN_ANALYZER_INIT to subscribing to analyzer_events_channel.
* gcc.dg/plugin/analyzer_gil_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_kernel_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_known_fns_plugin.cc: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Fri, 9 Jan 2026 20:54:15 +0000 (15:54 -0500)]
diagnostics: add optional CFG dumps to SARIF/HTML output sinks
This patch adds a new key/value pair "cfgs={yes,no}" to diagnostics
sinks, "no" by default.
If set to "yes" for a SARIF sink, then GCC will add the internal state
of the CFG for all functions after each pertinent optimization pass in
graph form to theRun.graphs in the SARIF output.
If set to "yes" for an HTML sink, the generated HTML will contain SVG
displaying the graphs, adapted from code in graph.cc
Text sinks ignore it.
The SARIF output is thus a machine-readable serialization of (some of)
GCC's intermediate representation (as JSON), but it's much less than
GCC-XML used to provide. The precise form of the information is
documented as subject to change without notice.
Currently it shows both gimple statements and RTL instructions,
depending on the pass. My hope is that it should be possible to write a
"cfg-grep" tool that can read the SARIF and automatically identify
in which pass a particular piece of our IR appeared or disappeared,
for tracking down bugs in our optimization passes.
Implementation-wise:
* this uses the publish-subscribe mechanism from the earlier patch, by
having the diagnostics sink subscribe to pass_events::after_pass
messages from the pass_events_channel.
* the patch adds a new hook to cfghooks.h for dumping a basic block
into a SARIF property bag
gcc/ChangeLog:
* Makefile.in (OBJS): Add tree-diagnostic-cfg.o.
(OBJS-libcommon): Add custom-sarif-properties/cfg.o,
diagnostics/digraphs-to-dot.o, and
diagnostics/digraphs-to-dot-from-cfg.o.
* cfghooks.cc: Define INCLUDE_VECTOR. Add includes of
"diagnostics/sarif-sink.h" and "custom-sarif-properties/cfg.h".
(dump_bb_as_sarif_properties): New.
* cfghooks.h (diagnostics::sarif_builder): New forward decl.
(json::object): New forward decl.
(cfg_hooks::dump_bb_as_sarif_properties): New callback field.
(dump_bb_as_sarif_properties): New decl.
* cfgrtl.cc (rtl_cfg_hooks): Populate the new callback
field with rtl_dump_bb_as_sarif_properties.
(cfg_layout_rtl_cfg_hooks): Likewise.
* custom-sarif-properties/cfg.cc: New file.
* custom-sarif-properties/cfg.h: New file.
* diagnostics/digraphs-to-dot-from-cfg.cc: New file, partly
adapted from gcc/graph.cc.
* diagnostics/digraphs-to-dot.cc: New file.
* diagnostics/digraphs-to-dot.h: New file, based on material in...
* diagnostics/digraphs.cc: Include
"diagnostics/digraphs-to-dot.h".
(class conversion_to_dot): Rework and move to above.
(make_dot_graph_from_diagnostic_graph): Likewise.
(make_dot_node_from_digraph_node): Likewise.
(make_dot_edge_from_digraph_edge): Likewise.
(conversion_to_dot::get_dot_id_for_node): Likewise.
(conversion_to_dot::has_edges_p): Likewise.
(digraph::make_dot_graph): Use to_dot::converter::make and invoke
the result to make the dot graph.
* diagnostics/digraphs.h (digraph:get_all_nodes): New accessor.
* diagnostics/html-sink.cc
(html_builder::m_per_logical_loc_graphs): New field.
(html_builder::add_graph_for_logical_loc): New.
(html_sink::report_digraph_for_logical_location): New.
* diagnostics/sarif-sink.cc (sarif_array_of_unique::get_element):
New.
(sarif_builder::report_digraph_for_logical_location): New.
(sarif_sink::report_digraph_for_logical_location): New.
* diagnostics/sink.h: Include "diagnostics/logical-locations.h".
(sink::report_digraph_for_logical_location): New vfunc.
* diagnostics/text-sink.h
(text_sink::report_digraph_for_logical_location): New.
* doc/invoke.texi (fdiagnostics-add-output): Clarify wording.
Distinguish between scheme-specific vs GCC-specific keys, and add
"cfgs" as the first example of the latter.
* gimple-pretty-print.cc: Include "cfghooks.h", "json.h", and
"custom-sarif-properties/cfg.h".
(gimple_dump_bb_as_sarif_properties): New.
* gimple-pretty-print.h (diagnostics::sarif_builder): New forward
decl.
(json::object): Likewise.
(gimple_dump_bb_as_sarif_properties): New.
* graphviz.cc (get_compass_pt_from_string): New
* graphviz.h (get_compass_pt_from_string): New decl.
* libsarifreplay.cc (sarif_replayer::handle_graph_object): Fix
overlong line.
* opts-common.cc: Define INCLUDE_VECTOR.
* opts-diagnostic.cc: Define INCLUDE_LIST. Include
"diagnostics/sarif-sink.h", "tree-diagnostic-sink-extensions.h",
"opts-diagnostic.h", and "pub-sub.h".
(class gcc_extra_keys): New class.
(opt_spec_context::opt_spec_context): Add "client_keys" param and
pass to dc_spec_context.
(handle_gcc_specific_keys): New.
(try_to_make_sink): New.
(gcc_extension_factory::singleton): New.
(handle_OPT_fdiagnostics_add_output_): Rework to use
try_to_make_sink.
(handle_OPT_fdiagnostics_set_output_): Likewise.
* opts-diagnostic.h: Include "diagnostics/sink.h".
(class gcc_extension_factory): New.
* opts.cc: Define INCLUDE_LIST.
* print-rtl.cc: Include "dumpfile.h", "cfghooks.h", "json.h", and
"custom-sarif-properties/cfg.h".
(rtl_dump_bb_as_sarif_properties): New.
* print-rtl.h (diagnostics::sarif_builder): New forward decl.
(json::object): Likewise.
(rtl_dump_bb_as_sarif_properties): New decl.
* tree-cfg.cc (gimple_cfg_hooks): Use
gimple_dump_bb_as_sarif_properties for new callback field.
* tree-diagnostic-cfg.cc: New file, based on material in graph.cc.
* tree-diagnostic-sink-extensions.h: New file.
* tree-diagnostic.cc: Define INCLUDE_LIST. Include
"tree-diagnostic-sink-extensions.h".
(compiler_ext_factory): New.
(tree_diagnostics_defaults): Set gcc_extension_factory::singleton
to be compiler_ext_factory.
gcc/testsuite/ChangeLog:
* gcc.dg/diagnostic-cfgs-html.py: New test.
* gcc.dg/diagnostic-cfgs-sarif.py: New test.
* gcc.dg/diagnostic-cfgs.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Fri, 9 Jan 2026 20:54:15 +0000 (15:54 -0500)]
Add publish/subscribe topics and channel: pass_events
This patch adds a new "struct compiler_channels" to hold channels
relating to the compiler that plugins (or diagnostic sinks) might want
to subscribe to events for, accessed from the global gcc::context
object, along with a new gcc/topics/ source subdirectory to hold
strongly-typed publish/subscribe topics relating to the compiler.
For now, there is just one: pass_events_channel, which, if there are any
subscribers, issues notifications about passes starting/stopping on
particular functions, using topics::pass_events, declared in
topics/pass-events.h, but followup patches add more kinds of
notification channel.
A toy plugin in the testsuite shows how this could be used to build a
progress notification UI for the compiler, and a followup patch uses the
channel to (optionally) capture CFG information at each stage of
optimization in machine-readable form into a SARIF sink.
gcc/ChangeLog:
* channels.h: New file.
* context.cc: Define INCLUDE_LIST. Include "channels.h".
(gcc::context::context): Create m_channels.
(gcc::context::~context): Delete it.
* context.h (struct compiler_channels): New forward decl.
(gcc::context::get_channels): New accessor.
(gcc::context::m_channels): New field.
* passes.cc: Define INCLUDE_LIST. Include "topics/pass-events.h"
and "channels.h".
(execute_one_pass): If the global context's pass_events_channel
has subscribers, publish before_pass and after_pass events to it.
* topics/pass-events.h: New file.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/plugin.exp: Add progress_notifications_plugin.cc.
* gcc.dg/plugin/progress_notifications_plugin.cc: New test plugin.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Fri, 9 Jan 2026 20:54:15 +0000 (15:54 -0500)]
Add pub-sub.{h,cc}
This patch introduces a publish/subscribe mechanism, allowing for
loosely-coupled senders and receivers, with strongly-typed messages
passing between them. For example, a GCC subsystem could publish
messages about events, and a plugin could subscribe to them.
An example can be seen in the selftests.
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add pub-sub.o.
* pub-sub.cc: New file.
* pub-sub.h: New file.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::pub_sub_cc_tests.
* selftest.h (selftest::pub_sub_cc_tests): New decl.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Andrew Pinski [Thu, 8 Jan 2026 04:28:12 +0000 (20:28 -0800)]
aarch64: Fix PCH for sve builtins [PR123457]
The problem here is function_table was not in the GGC memory space and not
streamed out. So even though the builtins were reloaded, function_table was
a nullptr as it was not reloaded.
Also noticed initial_indexes should be marked with GTY so it is reloaded correctly
from PCH.
Built and tested for aarch64-linux-gnu.
PR target/123457
gcc/ChangeLog:
* config/aarch64/aarch64-sve-builtins.cc (struct registered_function_hasher):
Change base class to ggc_ptr_hash.
(initial_indexes): Mark with GTY.
(function_table): Likewise.
(handle_arm_sve_h): Allocate function_table from ggc instead of heap.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Jakub Jelinek [Fri, 9 Jan 2026 19:46:39 +0000 (20:46 +0100)]
c: Optimize TARGET_EXPRs for _Atomic loads [PR123475]
On the following testcase we emit a false positive warning that
a temporary (TARGET_EXPR slot) is used uninitialized, from the early_uninit
pass.
This regressed with my change to instrument for
-ftrivial-auto-var-init={zero,pattern} not just DECL_EXPRs, but also
TARGET_EXPR initializations if the TARGET_EXPR_INITIALIZER has void type.
Those cases are where the initializer doesn't necessarily have to initialize
the whole TARGET_EXPR slot, or might use parts or the whole slot before
those are initialized; this is how e.g. various C++ temporary objects are
constructed.
The problem is in pass interaction. The FE creates a TARGET_EXPR with
void type initializer because the initializer is originally
__atomic_load (&expr, &tmp, SEQ_CST); but it is folded instantly into
(void) (tmp = (type) __atomic_load_N (&expr, SEQ_CST)). The FE also
marks the TARGET_EXPR slot as TREE_ADDRESSABLE, because it would be
if it will use libatomic, but nothing in the IL then takes its address.
Now, since my r16-4212 change which was for mainly C++26 compliance
we see the TARGET_EXPR and because it has void type TARGET_EXPR_INITIALIZER,
we start with tmp = .DEFERRED_INIT (...); just in case the initialization
would attempt to use the slot before initialization or not initialize fully.
Because tmp is TREE_ADDRESSABLE and has gimple reg type, it is actually not
gimplified as tmp = .DEFERRED_INIT (...); but as _1 = .DEFERRED_INIT (...);
tmp = _1; but because it is not actually address taken in the IL, already
the ssa pass turns it into SSA_NAME (dead one), so we have
_1 = .DEFERRED_INIT (...); _2 = _1; and _2 is unused. Next comes
early_uninit and warns on the dead SSA_NAME copy that it uses uninitialized
var.
The following patch attempts to fix that by checking if
c_build_function_call_vec has optimized the call right away into pure
assignment to the TARGET_EXPR slot without the slot being used anywhere
else in the expression and 1) clearing again TREE_ADDRESSABLE on the slot,
because it isn't really addressable 2) optimizing the TARGET_EXPR, so that
it doesn't have void type TARGET_EXPR_INITIALIZER by changing it to the rhs
of the MODIFY_EXPR. That way gimplifier doesn't bother creating
.DEFERRED_INIT for it at all.
Or should something like this be done instead in the TARGET_EXPR
gimplification? I mean not the TREE_ADDRESSABLE clearing, that can't be
done without knowing what we know in the FE, but the rest, generally
TARGET_EXPR with initializer (void) (TARGET_EXPR_SLOT = something)
where something doesn't refer to TARGET_EXPR_SLOT can be optimized into
just something TARGET_EXPR_INITIALIZER.
2026-01-09 Jakub Jelinek <jakub@redhat.com>
PR c/123475
* c-typeck.cc (c_find_var_r): New function.
(convert_lvalue_to_rvalue): If c_build_function_call_vec
folded __atomic_load (&expr, &tmp, SEQ_CST); into
(void) (tmp = __atomic_load_<N> (&expr, SEQ_CST)), drop
TREE_ADDRESSABLE flag from tmp and set TARGET_EXPR
initializer just to the rhs of the MODIFY_EXPR.
Jakub Jelinek [Fri, 9 Jan 2026 19:45:09 +0000 (20:45 +0100)]
doc: List more valid -x option arguments
We miss quite a few -x option arguments that can be specified.
2026-01-09 Jakub Jelinek <jakub@redhat.com>
* doc/invoke.texi (-x): Add c++-system-module, objc-cpp-output,
objc++-cpp-output, adascil, adawhy, modula-2, modula-2-cpp-output,
rust, algol68 and lto as further possible option arguments.
Jonathan Wakely [Thu, 8 Jan 2026 14:03:01 +0000 (14:03 +0000)]
libstdc++: Simplify use_proxy_wait function
The __wait_args::_M_setup_proxy_wait function must only be called when
_M_obj == addr is true, so it's redundant for _M_setup_proxy_wait to
pass addr to use_proxy_wait. That address is already passed as
args._M_old anyway.
libstdc++-v3/ChangeLog:
* src/c++20/atomic.cc (use_proxy_wait): Remove unused second
parameter.
(__wait_args::_M_setup_proxy_wait): Remove second argument.
(__notify_impl): Likewise.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Jonathan Wakely [Thu, 8 Jan 2026 14:03:01 +0000 (14:03 +0000)]
libstdc++: Fix proxy wait detection in atomic wait
A failed assertion was observed with std::atomic<bool>::wait when the
loop in __atomic_wait_address is entered and calls _M_setup_wait a
second time, after waking from __wait_impl. When the first call to
_M_setup_wait makes a call to _M_setup_proxy_wait that function decides
that a proxy wait is needed for an object of type bool, and it updates
the _M_obj and _M_obj_size members to refer to the futex in the proxy
state, instead of referring to the bool object itself. The next time
_M_setup_wait is called it calls _M_setup_proxy_wait again but now it
sees _M_obj_size == sizeof(futex) and so this time decides a proxy wait
is *not* needed, and then fails the __glibcxx_assert(_M_obj == addr)
check.
The problem is that _M_setup_proxy_wait wasn't correctly handling the
case where it's called a second time, after the decision to use a proxy
wait has already been made. That can be fixed in _M_setup_proxy_wait by
checking if _M_obj != addr, which implies that a proxy wait has already
been set up by a previous call. In that case, _M_setup_proxy_wait should
only update _M_old to the latest value of the proxy _M_ver.
This change means that _M_setup_proxy_wait is safe to call repeatedly
for a proxy wait, and will only update _M_wait_state, _M_obj, and
_M_obj_size on the first call. On the second and subsequent calls, those
variables are already correctly set for the proxy wait so don't need to
be set again.
For non-proxy waits, calling _M_setup_proxy_wait more than once is safe,
but pessimizes performance. The caller shouldn't make a second call to
_M_setup_proxy_wait because we don't need to check again if a proxy wait
should be used (the answer won't change) and we don't need to load a
value from the proxy _M_ver.
However, it was difficult to detect the case of a non-proxy wait,
because _M_setup_wait doesn't know if it's being called the first time
(when _M_setup_proxy_wait is called to make the initial decision) or a
subsequent time (in which case _M_obj == addr implies a non-proxy wait
was already decided on). As a result, _M_setup_proxy_wait was being used
every time to see if it's a proxy wait. We can resolve this by splitting
the _M_setup_wait function into _M_setup_wait and _M_on_wake, where the
former is only called once to do the initial setup and the latter is
called after __wait_impl returns, to prepare to check the predicate and
possibly wait again. The new _M_on_wake function can avoid unnecessary
calls to _M_setup_proxy_wait by checking _M_obj == addr to identify a
non-proxy wait.
The three callers of _M_setup_wait are updated to use _M_on_wake instead
of _M_setup_wait after waking from a waiting function. This change
revealed a latent performance bug in __atomic_wait_address_for which was
not passing __res to _M_setup_wait, so a new value was always loaded
even when __res._M_has_val was true. By splitting _M_on_wake out of
_M_setup_wait this problem became more obvious, because we no longer
have _M_setup_wait doing two different jobs, depending on whether it was
passed the optional third argument or not.
libstdc++-v3/ChangeLog:
* include/bits/atomic_timed_wait.h (__atomic_wait_address_until):
Use _M_on_wake instead of _M_setup_wait after waking.
(__atomic_wait_address_for): Likewise.
* include/bits/atomic_wait.h (__atomic_wait_address): Likewise.
(__wait_args::_M_setup_wait): Remove third parameter and move
code to update _M_old to ...
(__wait_args::_M_on_wake): New member function to update _M_old
after waking, only calling _M_setup_proxy_wait if needed.
(__wait_args::_M_store): New member function to update _M_old
from a value, for non-proxy waits.
* src/c++20/atomic.cc (__wait_args::_M_setup_proxy_wait): If
_M_obj is not addr, only load a new value and return true.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Jonathan Wakely [Fri, 9 Jan 2026 15:29:13 +0000 (15:29 +0000)]
libstdc++: Ensure counting_semaphore::try_acquire_for times out [PR122878]
As noted in Bug 122878 comment 2, the _M_try_acquire_for implementation
doesn't reduce the remaining timeout each time it returns from an atomic
waiting function. This means that it can wait longer than requested, or
even loop forever. If there is a spurious wake from the timed waiting
function (__wait_until_impl) it will return indicating no timeout
occurred, which means the caller will check the value and potentially
sleep again. If spurious wakes happen every time, it will just keep
sleeping in a loop forever. This is observed to actually happen on
FreeBSD 14.0-STABLE where pthread_cond_timedwait gets a spurious wake
and so never times out.
The solution in this commit is to replace the implementation of
_M_try_acquire_for with a call to _M_try_acquire_until, converting the
relative timeout to an absolute timeout against the steady clock. This
is what ends up happening anyway, because we only have a
__wait_until_impl entry point into the library internals, so
__atomic_wait_address_for already converts the relative timeout to an
absolute timeout (except for the special case of a zero-value duration,
which only checks for an update while spinning for a finite number of
iterations, and doesn't sleep).
As noted in comment 4 of the PR, this requires some changes to
_M_try_acquire which was relying on the behaviour of _M_try_acquire_for
for zero-value durations. That behaviour is desirable for
_M_try_acquire so that it can handle short-lived contention without
failing immediately. To preserve that behaviour of _M_try_acquire it is
changed to do its own loop and to call __atomic_wait_address_for
directly with a zero duration, to do the spinloop.
libstdc++-v3/ChangeLog:
PR libstdc++/122878
* include/bits/semaphore_base.h (_M_try_acquire): Replace
_M_try_acquire_for call with explicit loop and call to
__atomic_wait_address_for.
(_M_try_acquire_for): Replace loop with call to
_M_try_acquire_until.
Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
Jerry DeLisle [Fri, 9 Jan 2026 17:38:52 +0000 (09:38 -0800)]
Fortran: [PR123483] Fix duplicate finalization
A duplicated call to a finalizer occured in cases where a derived type
has components, one or more of which are allocatable, and one or more
of which are finalizable. (The bug occured only if the derived type
is an extension of another type, which has defined assignment.)
New test case derived from the original report by Paul Thomas.
PR fortran/123483
gcc/fortran/ChangeLog:
* trans-array.cc (gfc_deallocate_alloc_comp): Ad the new
finalization argument and pass it to structure_alloc_comps.
* trans-array.h (gfc_deallocate_alloc_comp): Add a finalization
flag that can be passed by gfc_conv_procedure_call.
* trans-expr.cc (gfc_conv_procedure_call): Use the new
finalization flag.
gcc/testsuite/ChangeLog:
* gfortran.dg/finalize_61.f90: New test.
Signed off by: Andrew Benson <abensonca@gcc.gnu.org>
Keith Packard [Thu, 8 Jan 2026 18:14:07 +0000 (10:14 -0800)]
libstdc++: Fix C++ 11 ctype when using picolibc (blank vs space)
Existing toolchain builds rely on the similarity between picolibc and
newlib when building libstdc++ and use --with-newlib.
Switch to the picolibc 16-bit _ctype_wide array which provides
separate values for ctype_base::blank and ctype_base::space.
This fixes a bug where libstdc++ was including '\f', '\n', '\r' and
'\v' in the set of 'blank' chars. Afterwards, only ' ' and '\t' are in
this set, as specified by C++ 11.
libstdc++-v3/ChangeLog:
* acinclude.m4 (GLIBCXX_CONFIGURE): Add --with-picolibc.
* configure: Regenerate.
* configure.ac: Add handling for with_picolibc=yes.
* config/os/picolibc/ctype_base.h: New file.
* config/os/picolibc/ctype_configure_char.cc: New file.
* config/os/picolibc/ctype_inline.h: New file.
* config/os/picolibc/os_defines.h: New file.
[PR123121, LRA]: Fix wrong rematerialization of insns with several outputs
LRA in the test case, rematerialize insn with div/mod where div result
is not used. Still div result requires ax which is used by different
pseudos at point of rematerialization and this clobbers the pseudo
value. The patch solves the problem by constraining to single set
insns as we always rematerialize only one pseudo value. Also there is
no sense to rematerialize div/mod as usually their latency is more
than load value from CPU cache. The patch explicitly excludes such
insns from rematerialization.
gcc/ChangeLog:
PR rtl-optimization/123121
* lra-remat.cc (bad_for_rematerialization_p): Consider div/mod ops.
(operand_to_remat): Exclude rematerialization of insns with
multiple sets.
Peter Bergner [Fri, 9 Jan 2026 02:41:20 +0000 (20:41 -0600)]
RISC-V: Update tt-ascalon-d8's extension list [PR123492]
The Ascalon core implements the full RVA23 profile plus a few other optional
extensions. However, the -mcpu=tt-ascalon-d8 option doesn't enable them all.
Add the missing extensions.
2026-01-08 Peter Bergner <bergner@tenstorrent.com>
gcc/
PR target/123492
* config/riscv/riscv-cores.def (RISCV_CORE)<tt-ascalon-d8>: Add missing
extensions via use of rva23s64 profile and adding zkr, smaia, smmpm,
smnpm, smrnmi, smstateen, ssaia, ssstrict, svadu.
Signed-off-by: Peter Bergner <bergner@tenstorrent.com>
Martin Jambor [Wed, 7 Jan 2026 12:34:45 +0000 (13:34 +0100)]
ipa-cp: Use the VR and bits lattices for clones of non-local functions too
Since the IPA-CP lattices for value ranges cannot hold more values and
don't have any "variable" flag, we initialize them to bottom for
non-local nodes. However, that means we don't make use of known
information gathered in jump functions when the corresponding node is
cloned for some other reason. This patch allows collection of the
information and only does not use them for the original non-local
nodes, while making sure that we do not propagate information through
such-non local nodes as there may be unknown calls.
gcc/ChangeLog:
2026-01-06 Martin Jambor <mjambor@suse.cz>
* ipa-cp.h (class ipcp_bits_lattice): New members set_recipient_only,
recipient_only_p and m_recipient_only.
(class ipcp_vr_lattice): Likewise.
(ipcp_vr_lattice::init): Initialize also m_recipient_only.
* ipa-cp.cc (ipcp_bits_lattice::print): Adjust printting to also
print the new flag.
(ipcp_vr_lattice::print): Likewise.
(ipcp_vr_lattice::set_recipient_only): New function.
(ipcp_bits_lattice::set_recipient_only): Likewise.
(set_all_contains_variable): New parameter MAKE_SIMPLE_RECIPIENTS, set
bits and vr lattices to recibient only insted to bottom when it is
true.
(initialize_node_lattices): Pass true to the second parameter of
set_all_contains_variable.
(propagate_bits_across_jump_function): Treat recipient_only source
lattices like bottom.
(propagate_vr_across_jump_function): Likewise.
(ipcp_store_vr_results): Skip non-local nodes.
Martin Jambor [Mon, 5 Jan 2026 13:59:52 +0000 (14:59 +0100)]
ipa-cp: Better opportunity evaluation and ranking
This modifies the decision making stage of IPA-CP in two ways:
Previously, local effects of the cloning were estimated only for the
constant that was being considered, even though the calls which bring
it also carry other constants. With this patch, all knowsn constants
for the given subset of caller edges are considered and the heuritics
should therefore have more information and generally work better.
Also, when evaluating the opportunities for a given node, IPA-CP
previously just iterate over the parameters starting with the first
one and if any opportunity looked profitable, it was carried out and
associated calling edges were redirected, even if this precludes some
even better opportunity. The patch tries to mitigate this by first
using the initial estimates to sort all cloning candidates and then
iterate in that order.
The one difference from the version I posted before is that I have
extended the checking assert making sure the value we clone for is
indeed used to also work for non-aggregate constants and polymorphic
contexts.
gcc/ChangeLog:
2025-12-01 Martin Jambor <mjambor@suse.cz>
* ipa-cp.cc (good_cloning_opportunity_p): Dump a message when
bailing out early too.
(find_more_scalar_values_for_callers_subset): Rename to
find_scalar_values_for_callers_subset, collect constants regardless of
what is already in the vector. Remove dumping.
(find_more_contexts_for_caller_subset): Rename to
find_contexts_for_caller_subset, collect contexts regardless of what
is already in the vector. Remove dumping.
(find_aggregate_values_for_callers_subset): Rename to
find_aggregate_values_for_callers_subset_gc, implement using new
functions.
(find_aggregate_values_for_callers_subset_1): New function.
(find_aggregate_values_for_callers_subset): Likewise.
(copy_known_vectors_add_val): Removed.
(dump_reestimation_message): New function.
(decide_about_value): Remove formal parameter avals, compute it
independently, and use it to estimate local cloning effects.
(struct cloning_opportunity_ranking): New type.
(compare_cloning_opportunities): New function.
(cloning_opportunity_ranking_evaluation): Likewise.
(decide_whether_version_node): Pre-sort candidates for cloning before
really evaluating them. Calculate context independent values only
when considering versioning for all contexts.
(ipcp_val_agg_replacement_ok_p): Renamed to
ipcp_val_replacement_ok_p, check also non-aggregate values.
arm: prevent impossible tail- long-calls with static chain [PR119430]
When a function call uses up all argument registers, and needs IP for
the static chain, there aren't any call-clobbered registers left for
reload to assign as the sibcall target, when -mlong-calls is enabled.
Use the same logic that does the job for indirect calls to prevent
tail calls in this case.
With this change, it is possible to bootstrap armv7a-linux-gnu with
both -O3 and lto, but only with both -mlong-calls and
-ffunction-sections.
Without -mlong-calls, linker veneer thunks may clobber the static
chain register set up by callers in one lto unit, preventing them from
reaching the callee in a separate lto unit. -ffunction-sections is
required for -mlong-calls to be effective, because both caller and
callee are in the same section, and that disables long-calls when
!flag_reorder_blocks_and_partition.
gcc/ChangeLog
PR target/119430
* config/arm/arm.cc (arm_function_ok_for_sibcall): Disable
sibcalls for long-calls that use all call-clobbered
general-purpose registers, including the static chain.
Currently, operand modifier c truncates and extends any integer constant
to a signed 8-bit constant whereas the common code implementation just
prints the constant unmodified. The modifier was introduced in r0-87728-g963fc8d00baeca matching the new constraint C which ensures
that a constant is an 8-bit signed integer.
In the machine description, operand modifier c is only used for operands
with constraint C. Therefore, there is no immediate need for some
special constant printing.
Since print_operand() is also used by output_asm_insn(), inline asm is
also affected by this. Note, in output_asm_insn() we cannot utilize
output_addr_const() since not every CONST_INT is a valid address, i.e.,
we have up to 32-bit immediates and at most 20-bit (long) displacements.
In fact, %cN should behave the same as %N for any CONST_INT operand N,
although, this literally means that the output modifier accepts and
prints immediates which might be larger than any instruction accepts.
Though, regarding accepting or rejecting immediates, this is what
constraints et al. are for. Therefore, align %cN and %N.
Filip Kastl [Fri, 9 Jan 2026 14:16:50 +0000 (15:16 +0100)]
Enable -fbit-tests and -fjump-tables at -Og [PR123212]
Since GCC 15, bit test and jump table lowering was disabled for both -O0
and -Og to save compile time. On -Og, compile time isn't *that*
critical, so this patch enables bit tests and jump tables on -Og once
again.
PR c/123212
gcc/ChangeLog:
* opts.cc: Enable -fbit-tests and -fjump-tables at -Og.
Christophe Lyon [Fri, 9 May 2025 11:42:20 +0000 (11:42 +0000)]
arm: always enable both simd and mve builtins
We get lots of error messages when compiling arm_neon.h under
e.g. -mcpu=cortex-m55, because Neon builtins are enabled only when
!TARGET_HAVE_MVE. This has been the case since MVE support was
introduced.
This patch uses an approach similar to what we do on aarch64, but only
partially since Neon intrinsics do not use the "new" framework.
We register all types and Neon intrinsics, whether MVE is enabled or
not, which enables to compile arm_neon.h. However, we need to
introduce a "switcher" similar to aarch64's to avoid ICEs when LTO is
enabled: in that case, since we have to enable the MVE intrinsics, we
temporarily change arm_active_target.isa to enable MVE bits. This
enables hooks like arm_vector_mode_supported_p and arm_array_mode to
behave as expected by the MVE intrinsics framework. We switch back
to the previous arm_active_target.isa immediately after.
With a toolchain targetting e.g. cortex-m55,
gcc.target/arm/attr-neon3.c now compiles successfully, with only one
failure to be fixed separately:
FAIL: gcc.target/arm/attr-neon3.c check-function-bodies my1
Besides that, gcc.log is no longer full of errors messages when trying
to compile arm_neon.h if MVE is forced somehow.
gcc/ChangeLog:
* config/arm/arm-builtins.cc (arm_init_simd_builtin_types): Remove
TARGET_HAVE_MVE condition.
(class arm_target_switcher): New.
(arm_init_mve_builtins): Remove calls to
arm_init_simd_builtin_types and
arm_init_simd_builtin_scalar_types. Switch to MVE isa flags.
(arm_init_neon_builtins): Remove calls to
arm_init_simd_builtin_types and
arm_init_simd_builtin_scalar_types.
(arm_need_mve_mode_regs): New.
(arm_need_neon_mode_regs): New.
(arm_target_switcher::arm_target_switcher): New.
(arm_target_switcher::~arm_target_switcher): New.
(arm_init_builtins): Call arm_init_simd_builtin_scalar_types and
arm_init_simd_builtin_types. Always call arm_init_mve_builtins
and arm_init_neon_builtins.
Eric Botcazou [Fri, 9 Jan 2026 11:27:49 +0000 (12:27 +0100)]
Ada: Fix suboptimal copy of discriminated record to local variable (2nd try)
This happens for a discriminated record type with default discriminants, for
which GNAT allocates mutable objects with the maximum size, while trying not
to copy padding bits unnecessarily. When the padded size is small enough to
be copied efficiently, it should nevertheless be profitable to copy them in
order to avoid a call to memcpy with a dynamic size.
This version makes sure that it is safe to read the padded size on the RHS,
which is not the case for example when the LHS is an unconstrained variable
but the RHS is a constrained object.
gcc/ada
* gcc-interface/trans.cc (gnat_to_gnu): Add comment explaining why
it is necessary to remove the padding for an object of a type with
self-referential size when it is not converted to the result type.
* gcc-interface/utils2.cc (build_binary_op) <MODIFY_EXPR>: For an
assignment between small padded objects of the same type with self-
referential size, and which have the same (constant) size, use the
padded view of the objects.
Jakub Jelinek [Fri, 9 Jan 2026 11:19:26 +0000 (12:19 +0100)]
i386: Add OPTION_MASK_ISA_64BIT to 4 non-ia32 builtins [PR123489]
The following 4 builtins have corresponding insns guarded with TARGET_64BIT
and are only used in #ifdef __x86_64__ ... #endif section of an intrin
header, so when used by hand with -m32 they ICE.
Fixed thusly.
I've additionally verified all the #ifdef __x86_64__ ... #endif guarded
builtins used in intrinsic headers and checked whether they have
OPTION_MASK_ISA_64BIT, the only other exception was __builtin_ia32_prefetchi
but I think that one is fine, as expansion in that case has
if (TARGET_64BIT && TARGET_PREFETCHI
&& local_func_symbolic_operand (op0, GET_MODE (op0)))
emit_insn (gen_prefetchi (op0, op2));
else
{
warning (0, "instruction prefetch applies when in 64-bit mode"
" with RIP-relative addressing and"
" option %<-mprefetchi%>;"
" they stay NOPs otherwise");
emit_insn (gen_nop ());
}
Eric Botcazou [Tue, 16 Dec 2025 11:30:14 +0000 (12:30 +0100)]
ada: Fix suboptimal copy of discriminated record to local variable
This happens for a discriminated record type with default discriminants, for
which GNAT allocates mutable objects with the maximum size, while trying not
to copy padding bits unnecessarily. When the padded size is small enough to
be copied efficiently, it should nevertheless be profitable to copy them in
order to avoid a call to memcpy with a dynamic size.
gcc/ada/ChangeLog:
* gcc-interface/trans.cc (gnat_to_gnu): For the LHS of an assignment
or an actual parameter of a call, do not remove the padding even for
a type of self-referential size when the padded size is small enough
to be copied efficiently.
Javier Miranda [Tue, 23 Dec 2025 19:05:33 +0000 (19:05 +0000)]
ada: Improve fix for object with address clause and C++ constructor
Improves previous fix to handle an object that has an address clause
and it is initialized by C++ imported constructor call.
gcc/ada/ChangeLog:
* exp_ch3.adb (Expand_N_Object_Declaration): Remove previous patch
and place the call to the constructor into a compound statement
attached to the object; the compound statement will be moved to
the freezing actions of the object if the object has an address
clause.
Denis Mazzucato [Thu, 18 Dec 2025 12:34:18 +0000 (13:34 +0100)]
ada: Fix crash on legality check for initialization of implicit constructor
This patch fixes a crash occurring during the legality check of the Initialize
aspect when the constructor is implicitly created by the compiler, e.g., the
default copy constructor. In such case, Corresponding_Spec is not available, the
Specification field must be used instead.
gcc/ada/ChangeLog:
* sem_ch13.adb (Check_Constructor_Initialization_Expression): The first
parameter of an implicit constructor comes from Specification, not
Corresponding_Spec.
Eric Botcazou [Mon, 22 Dec 2025 09:52:01 +0000 (10:52 +0100)]
ada: Fix small oversight in accessibility change
The change incorrectly turned a Comes_From_Source test initially done on the
type conversion node, into a test on its parent node, that is used to decide
whether to apply an accessibility check to the type conversion.
gcc/ada/ChangeLog:
* exp_ch4.adb (Expand_N_Type_Conversion): Restore Comes_From_Source
test on N itself instead of its parent node.
Eric Botcazou [Thu, 18 Dec 2025 23:57:28 +0000 (00:57 +0100)]
ada: Fix accessibility level of function calls in Ada 95
This fixes the computation of the accessibility level in the default case.
gcc/ada/ChangeLog:
* accessibility.adb (Function_Call_Or_Allocator_Level): Return the
level of the subprogram in Ada 95 only in the case where the result
type is a return-by-reference type.
Suppress warnings generated for a Bounded_Indefinite_Holders instance
when compiled for a 32-bit target. The warnings are not useful because
the construct being flagged is in code that is dead (for that instance).
Eric Botcazou [Fri, 19 Dec 2025 17:24:45 +0000 (18:24 +0100)]
ada: Fix fallout of latest accessibility change with -gnata
Compiling with assertion enabled may create _Wrapped_Statements functions
with access result, whose anonymous access result type is the same entity
as that of their parent function, which fools the accessibility logic.
gcc/ada/ChangeLog:
* accessibility.adb (Function_Call_Or_Allocator_Level): Adjust the
latest change to cope with _Wrapped_Statements functions.
* einfo.ads (Wrapped_Statements): Fix description.
* sem_util.adb (In_Return_Value): Fix typo in comment.
Javier Miranda [Wed, 3 Dec 2025 19:37:53 +0000 (19:37 +0000)]
ada: Unsigned_Base_Range aspect (part 7)
Add support for ELIMINATED and MINIMIZED overflow checking modes
on types with the Unsigned_Base_Range aspect (modes available
under switch -gnato).
gcc/ada/ChangeLog:
* checks.ads (Convert_From_Bignum): Add a new formal and update
documentation.
(Convert_To_Bignum): Update documentation.
* checks.adb (Is_Signed_Integer_Arithmetic_Op): Renamed as
Is_Overflow_Arithmetic_Op, and replace calls to function
Is_Signed_Integer_Type by calls to Has_Overflow_Operations.
(Apply_Arithmetic_Overflow_Minimized_Eliminated): Add support
for types with the Unsigned_Base_Range aspect.
(Apply_Divide_Checks): Replace calls to Is_Signed_Integer_Type
by calls to Has_Overflow_Operations.
(Compute_Range_For_Arithmetic_Op): Adjust comment.
(Convert_To_Bignum): Add support for types with the Unsigned_
Base_Range aspect.
(Convert_From_Bignum): Add support for result type with the
Unsigned_Base_Range aspect.
(Minimize_Eliminate_Overflows): Add support for types with the
Unsigned_Base_Range aspect.
* exp_ch4.adb (Minimized_Eliminated_Overflow_Check): Replace
call to Is_Signed_Integer_Type by call to Has_Overflow_Operations.
(Expand_Compare_Minimize_Eliminate_Overflow): Add support for types
with the Unsigned_Base_Range aspect.
(Expand_Membership_Minimize_Eliminate_Overflow): Ditto.
(Expand_N_Op_Expon): Ditto.
(Expand_Exponentiation): New subprogram.
* rtsfind.ads (RE_Id): Add RE_LLU_To_Bignum, RE_LLU_From_Bignum.
* libgnat/s-bignum.ads (LLU_To_Bignum): New subprogram.
(LLU_From_Bignum): New subprogram.
* libgnat/s-bignum.adb (LLU_To_Bignum): New subprogram.
(LLU_From_Bignum): New subprogram.
* libgnat/s-genbig.ads (From_Bignum): New overloaded functions
for Long_Long_Long_Unsigned and Long_Long_Unsigned types.
(To_Bignum): Ditto.
* libgnat/s-genbig.adb (From_Bignum): New overloaded functions
for Long_Long_Long_Unsigned and Long_Long_Unsigned types.
(To_Bignum): Ditto.
* libgnat/s-expuns.ads (Exp_Unsigned): Fix documentation.
* libgnat/s-expllu.ads (Exp_Long_Long_Unsigned): Ditto.
* libgnat/s-explllu.ads (Exp_Long_Long_Long_Unsigned): Add missing
documentation.
Eric Botcazou [Thu, 11 Dec 2025 15:14:32 +0000 (16:14 +0100)]
ada: Reimplement AI12-0345, AI12-0372 and implement AI12-0402
The first two are binding interpretations, so apply to Ada 2012, and have
been only partially implemented. The third is Ada 2022 and has not been
implemented, but is very convenient to tame the effects of the first two.
They mostly pertain to explicitly aliased parameters and to adjusting the
rules determining the master of a function call, so that the RM 6.4.1(6.4)
legality rule is applied judiciously.
The change also does some housekeeping work in the implementation of static
accessibility checks, plugging a few loopholes: in Ada 2005 for objects of
anonymous access types, in Ada 2005 and 2012 for conversions between access
types done in extended return statements, and in Ada 2012 for explicitly
aliased parameters.
gcc/ada/ChangeLog:
* accessibility.ads (Is_Special_Aliased_Formal_Access): Delete.
* accessibility.adb (Is_Special_Aliased_Formal_Access): Likewise.
(Accessibility_Level.Innermost_Master_Scope_Depth): Look for non-
package bodies and statements directly.
(Accessibility_Level.Function_Call_Or_Allocator_Level): For a
function call in a return context, return the extra level of the
master of the call only for dynamic checks.
(Accessibility_Level) <N_Defining_Identifier>: Always return the
library level for an explicitly aliased parameter in the context
of a return from the subprogram where it is declared.
* exp_ch4.adb (Expand_N_Allocator): Test manually whether the
context is a return statement instead of calling In_Return_Value.
(Expand_N_Type_Conversion): Do not apply accessibility checks to
actuals of a tagged type in a synthesized subprogram call.
* sem_attr.adb (Resolve_Attribute) <Access>: Remove specific test
for explicitly aliased parameters.
* sem_ch4.adb: Remove clauses for Accessibility package.
(Analyze_Call): Do not apply static accessibility checks here...
* sem_res.adb (Resolve_Actuals): ...but here instead. Implement
a generalized form of AI12-0402.
(Valid_Conversion): Apply static accessibility checks in extended
return statements too.
* sem_util.ads (In_Return_Value): Adjust description.
(Is_Master): Delete.
* sem_util.adb (Is_Explicitly_Aliased): Reindent.
(In_Return_Value): Reimplement.
(Is_Master): Delete.
Viljar Indus [Fri, 12 Dec 2025 13:18:02 +0000 (15:18 +0200)]
ada: Add quickfixes for -gnawk warnings
gcc/ada/ChangeLog:
* errout.adb (Insert): New function to create an insertion fix.
(Deletion): New function to create a deletion fix.
* errout.ads: Likewise.
* sem_warn.adb (Create_Add_Constant_Fix): New function to create
a fix for adding a constant qualifier for a variable declaration.
(Change_In_Out_To_In_Fix): New function to create a fix for
convertinting an in out parameter direction to a an in direction.
Co-authored-by: Eric Botcazou <ebotcazou@adacore.com>
On Windows, the tasking runtime now calls SetThreadDescription on the
underlying system threads with the task images as argument.
gcc/ada/ChangeLog:
* adaint.c (__gnat_set_thread_description): New function.
* libgnarl/s-taprop__mingw.adb (Enter_Task): Set thread description.
* rtinit.c (__gnat_runtime_initialize): Set up function pointer.
* mingw32.h (HRESULT, pSetThreadDescription): New.
Denis Mazzucato [Mon, 8 Dec 2025 13:09:12 +0000 (14:09 +0100)]
ada: Fix parameterless constructors
This patch fix support for parameterless constructors. Specifically, it forbids calling the
parameterless constructor when no explicit one has been declared, and when the parameterless one has
been explicitly removed.
Furthermore, by freezing constructors as predefined operations, it is now possible to use them in
global object declarations right after the record type declaration.
gcc/ada/ChangeLog:
* exp_ch3.adb (Build_Init_Procedure): Remove call to constructors.
(Build_Default_Simple_Initialization): Implicit call to parameterless constructors in new
allocations.
(Expand_Freeze_Record_Type): Freeze constructors as we would freeze predefined operations.
(Constructor_Freeze): Freeze all constructors.
* sem_attr.adb (Analyze_Attribute): Handle missing parameterless constructors.
* sem_ch3.adb: The default constructor is now called parameterless.
* sem_util.adb (Find_Matching_Constructor): Return the constructor
matching the given condition. Before it was just checking its
existence.
(Has_Copy_Constructor): Move it upward to maintain alphabetic
order of utility subprograms.
(Has_Parameterless_Constructor): The default constructor is now called parameterless.
(Has_Explicit_Constructor): New utility to check for constructors
defined by the user. Used to understand if an implicit
parameterless constructor exists.
(Is_Copy_Constructor): Refactor easier control flow.
(Is_Parameterless_Constructor): New utility to check if a constructor has a profile
compatible with the parameterless constructor.
* sem_util.ads: Likewise.
Viljar Indus [Mon, 8 Dec 2025 11:26:54 +0000 (13:26 +0200)]
ada: Add diagnostic entry consistency checks
Verify that every diagnostic that has a switch also has the same
diagnostic marked as one of the diagnostics for that same switch.
Additionally verify that for every diagnostic marked for a switch
these diagnostics have the same switch marked as its switch.
gcc/ada/ChangeLog:
* errid.adb (Check_Diagnostic_To_Switch_Consistency): New subprogram
for checking the consistency of diagnostics.
(Check_Switch_To_Diagnostic_Consistency) New subprogram for checking
the consistency of switches.
(Add_All_Diagnostic_Rules): Check diagnostic consitency.
(Add_All_Switch_Rules): Check switch consitency.
Viljar Indus [Tue, 25 Nov 2025 12:46:08 +0000 (14:46 +0200)]
ada: Print gnat diagnostics with the gnat command
Remove the support for printing the diagnostic report
in the compiler when -gnatd_E is used. Instead print it
when the "gnat --diagnostics" command is used.
gcc/ada/ChangeLog:
* debug.adb: remove use case for -gnatd_E
* errout.adb (Output_Messages): remove printing of
the diagnostic repository when -gnatd_E is used.
* gnatcmd.adb: Add support for printing the diagnostic repository.
Viljar Indus [Tue, 25 Nov 2025 12:45:29 +0000 (14:45 +0200)]
ada: Add support for printing switches in the SARIF report
Previously the report for all of the available diagnostics
and switches was given in a custom JSON format. This patch
merges the two reports and includes them in a special SARIF
report where all of the diagnostics and switches are presented
as switches in the rules section of the report. Switches and
diagnostics are linked with each other through the relationship
node. Diagnostic rules will have a superset relation to a switch
rule and a Switch rule will have a subset relation to each of its
diagnostic rules.
In order to facilitate those changes the errid and errsw packages were
reorganized. Now errid will have the definitions for both all of the
Diagnostic_Id-s and Switch_Id-s. The two new subpackages for errid -
Diagnostic_Repository and Switch_Repository will hold the repository
information that will be presented in the SARIF report.
gcc/ada/ChangeLog:
* errid-diagnostic_repository.ads: New package for storing
information about diagnostics.
* errid-switch_repository.adb: New package for storing
information about switches.
* errid-switch_repository.ads: Likewise.
* errid.adb: Move common methods related to Diagnostic_Id-s and
Switch_Id-s to this pacakge.
* errid.ads: Likewise.
* errout.adb (Add_Unique_Diagnostics_And_Switches): New method
for gathering all of the unique Diagnostic_Id-s and Switch_Id-s
among all of the error messages.
(Output_Messages): Use the new SARIF printer interface for printing
the report.
* erroutc-sarif_emitter.adb (Print_Relationship): New method for
printing relationship nodes.
(Print_Rule): Support printing switches as rules. Add support
for printing relationship nodes under rules. Remove brackets around
the rule name.
(Print_Runs): Add a printer argument to pass all of the switches
and diagnostics as rules in the SARIF report.
(Print_Tool): Likewise.
(Free): New method.
(Get_Unique_Rules): Removed.
(Print_Result): Remove brackets around the rule name.
(Print_Rules): Print switches as rules.
* erroutc-sarif_emitter.ads (SARIF_Printer): New record type for
storing and passing all of the diagnostic and switch information
around in the SARIF printer.
(Report_Kind): New type for indicating the different reports the
SARIF emitter can produce.
(Free): New method for releasing all of the dynamically allocated
memory.
(Print_SARIF_Report): Add a SARIF_Printer argument.
* erroutc.adb (Get_Human_Id): Removed.
(Get_Switch): Removed.
(Get_Doc_Switch): Simplify code.
* erroutc.ads: (Get_Human_Id): Removed.
(Get_Switch): Removed.
* errsw.adb: Replaced by errid-switch_repository.adb.
* errsw.ads: Replaced by errid-switch_repository.ads.
* errutil.adb: Remove dependecy to errsw pacakge.
* par-endh.adb: Fix whitespace.
* gcc-interface/Make-lang.in: Update the dependencies.
* gcc-interface/Makefile.in: Likewise.
Steve Baird [Tue, 9 Dec 2025 22:14:53 +0000 (14:14 -0800)]
ada: Implement From_Address attribute
Add support for the GNAT-defined From_Address attribute.
gcc/ada/ChangeLog:
* doc/gnat_rm/implementation_defined_attributes.rst: Document the
From_Address attribute.
* exp_attr.adb (Expand_N_Attribute_Reference): Implement expansion
of a From_Address attribute reference.
* sem_attr.adb (Analyze_Attribute): Implement analysis of a
From_Address attribute reference.
(Eval_Attribute): A From_Address attribute reference cannot be
statically evaluated.
* snames.ads-tmpl: Declare Name_From_Address and Attribute_From_Address.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.
Steve Baird [Wed, 26 Nov 2025 00:14:52 +0000 (16:14 -0800)]
ada: new legality checks for Super and Initialize aspect specifications
An expression provided as part of a Super or Initialize aspect specification
is not allowed to reference the constructed object (that is, the first
parameter of the constructor procedure).
gcc/ada/ChangeLog:
* sem_ch13.adb (Analyze_Aspect_Specifications): Add new legality
checks for Super and Initialize aspect specifications, implemented
by calling a new local procedure,
Check_Constructor_Initialization_Expression.
Implement the predefined unit Ada.Containers.Bounded_Indefinite_Holders.
gcc/ada/ChangeLog:
* Makefile.rtl: add entry for new unit
* impunit.adb: add entry for new unit
* libgnat/a-cbinho.adb: new file with body for new unit
* libgnat/a-cbinho.ads: new file with spec for new unit
* libgnat/a-coboho.ads: add comment
* libgnat/a-undesu.ads: add Preelaborate aspect specification,
as per AI22-0050.
Eric Botcazou [Mon, 15 Dec 2025 09:48:05 +0000 (10:48 +0100)]
ada: Fix missing warning for unused use clause with use clause for child package
The -gnatwu switch does not give any warning for a unused use clause when a
use clause for a child package is present. It turns out that there are many
occurrences in the compiler itself!
Bob Duff [Thu, 11 Dec 2025 19:22:50 +0000 (14:22 -0500)]
ada: Tech debt: clean up miscellaneous VAST issues
Clean up various issues found while working on VAST.
Fix uses of Token_Node, which was used in cases where it was documented
as undefined, leading to strange behavior with respect to setting Parent
nodes.
Obey the comment about Validate_Subprogram_Calls in frontend.adb,
"this work will be done by VAST". Remove conditionals on
Debug_Flag_Underscore_XX.
gcc/ada/ChangeLog:
* debug.adb: Remove doc for gnatd_X; no longer used.
* einfo.ads: Minor comment improvement.
* exp_ch3.adb: Minor reformatting.
* exp_ch6.adb (Check_BIP_Actuals): Export.
(Validate_Subprogram_Calls): Move to Vast.
* exp_ch6.ads (Check_BIP_Actuals): Export.
* exp_ch7.adb (Make_Init_Call): Remove obsolete Set_Assignment_OK.
* frontend.adb: Move Validate_Subprogram_Calls call to VAST,
as the comment suggested.
* par.adb: Minor comment improvements.
* par-ch13.adb (Get_Aspect_Specifications):
Misc cleanup, including removal of redundant setting
of Aspects, and changing multiple 'if's to 'case'.
* par-ch4.adb (P_Simple_Name_Resync): Do not refer to Token_Node
when it is documented as not defined.
* par-ch6.adb: Minor comment improvement.
* par-util.adb (Bad_Spelling_Of): After setting Token from
identifier to keyword, destroy Token_Node, so it doesn't get
accidentally used.
* scans.adb (Save_Scan_State, Restore_Scan_State):
Put these in logical order. Make sure we're not saving
and restoring bogus information in Token_Node.
* scans.ads: Fix incorrect comment.
* scn.ads: Minor comment improvements. Do not duplicate (wrong)
information from Scans.
* scng.adb: Set Token_Node to Empty initially, so we don't
accidentally refer to bogus information from previous tokens.
* scng.ads: Minor comment improvement (remove information
about one actual from comment on the formal).
* sem_aux.ads (Initialization_Suppressed):
Minor comment improvement.
* sem_ch6.adb: Remove usage of Debug_Flag_Underscore_XX.
This code is pretty well tested by now, and anyway, it's
only called from within pragmas Assert.
* sem_util.adb (Enter_Name): Minor cleanup.
* sprint.adb (Dump_Generated_Only): Fix incorrect comment.
* vast.adb: Misc cleanup. Enable assertion about
Errout.Compilation_Errors (should be False if back end
is enabled).
(Validate_Subprogram_Calls): Move here from frontend.adb.
Move call to it here from frontend.adb.
Gary Dismukes [Fri, 5 Dec 2025 01:00:19 +0000 (01:00 +0000)]
ada: Compiler crash on ill-formed container indexing
The compiler blows up when analyzing an illegal indexing of a container
object (such as a vector) when the indexing expression has the form of
a named actual parameter and the name given for the parameter does not
match the name of the index formal of the corresponding indexing function
that the compiler identifies for doing the generalized indexing.
gcc/ada/ChangeLog:
* sem_ch4.adb (Try_Container_Indexing): Conditionalize last actual of
call to Error_Msg_NE to avoid blowup on N_Parameter_Association actuals.
Eric Botcazou [Wed, 10 Dec 2025 20:40:27 +0000 (21:40 +0100)]
ada: Change 'Size of formal unconstrained discriminated in out parameters
When the discriminated type is declared with default discriminants, it is
definite, so objects of the type can be declared without constraints, are
thus unconstrained, and are allocated with the maximum size by GNAT.
When these objects are passed as actuals of formal in out parameters, it
makes sense for the 'Size computed for them from within the subprogram to
also be the above "unconstrained" size instead of the "constrained" size
computed from the value of the discriminants present in them.
gcc/ada/ChangeLog:
* exp_attr.adb (Expand_Size_Attribute): If the attribute is applied
to a formal parameter allocated with an extra Constrained parameter,
use the value of the latter to choose between the "unconstrained" or
the "constrained" size of the formal parameter.
Javier Miranda [Wed, 10 Dec 2025 12:08:32 +0000 (12:08 +0000)]
ada: Warn on untagged record type equality under Ada 83/95 modes
Compiling under Ada 83 or Ada 95 mode, the warning reported under
-gnatw_q is triggered by the compiler when a user-defined "=" on
an untagged record type U is not used to compare a component C
(of type U) of an outer record R.
The warning is reported because it may be surprising that, under
Ada 83 and Ada 95 modes, the predefined "=" of the component type
C takes precedence over its user-defined "=" when objects of the
record type R are compared.
gcc/ada/ChangeLog:
* exp_ch4.adb (Expand_Composite_Equality): Under Ada83 and Ada95
modes, and compiling under -gnatw_q, search for an user-defined
equality and report a warning if found since it will not be called.
Piotr Trojanek [Wed, 3 Dec 2025 23:48:43 +0000 (00:48 +0100)]
ada: Restore previous mapping for Ada to Win32 task priorities
This patch restores previous mapping of Ada to Win32 task priorities used
when no pragma Task_Dispatching_Policy (FIFO_Within_Priorities) is present
(except for wrong mapping to values that can only be used for processes
with REALTIME_PRIORITY_CLASS).
The new mapping is consistent with the one used when that pragma is present
and provides distinct values for priorities in range of Default_Priority +/- 2.
gcc/ada/ChangeLog:
* libgnat/system-mingw.ads (Underlying_Priorities): Restore previous
mapping with distinct values around Default_Priority.
Denis Mazzucato [Wed, 19 Nov 2025 13:13:35 +0000 (14:13 +0100)]
ada: Implement copy constructors
This patch implements the copy constructor as a particular type of constructor
that copies its second parameter "From" into the first implicit "Self"
parameter. The copy constructor is called via the 'Make attribute and is always
available for tagged types.
Internally, when missing an implicit copy constructor with default behavior is
generated. Sometimes, when its behavior wouldn't differ from the default
byte-wise copy, no entity is actually generated. In this case, whenever the copy
constructor is called via the 'Make attribute, the call is rewritten simply as
its parameter "From".
gcc/ada/ChangeLog:
* exp_attr.adb (Expand_N_Attribute_Reference): Do not expand copy
constructor calls when unnecessary.
* exp_ch3.adb
(Build_Implicit_Copy_Constructor): If necessary, build the implicit copy
constructor as part of the initialization procedures of its type.
(Expand_N_Object_Declaration): Add implicit 'Make attribute calls for
objects that may need construction.
* exp_ch6.adb (Make_Parent_Constructor_Call): Constructor's procedure
calls should be only generated from expansion of the 'Make attribute as
there is hidden logic to handle copy constructors.
* sem_attr.adb (Analyze_Attribute): Emit a specific error message if a
non-copy constructor is called but no constructor is defined.
* sem_ch13.adb (Analyze_Aspect_Specifications): The Ekind of the
implicitly generated copy constructor is not a subprogram body.
* sem_ch4.adb (Extended_Primitive_Ops): Extend the operation list that
can be called via prefix notation to include constructors.
* sem_ch6.adb (Check_For_Primitive_Subprogram): Skip constructors for
primitive analysis.
* sem_util.adb (Has_Matching_Constructor): Generic function to
check for the existence of a constructor matching a given
condition.
(Has_Copy_Constructor): Check whether a type has an implicit or explicit
copy constructor.
(Has_Default_Constructor): Use Has_Matching_Constructor.
(Is_Copy_Constructor): Check whether a subprogram is a copy constructor.
(Is_Copy_Constructor_Call): Check whether an attribute call is call to a
copy constructor.
* sem_util.ads: Add specs for copy constructor utility functions.
* snames.ads-tmpl (Snames): Add names Self and From.
Martin Clochard [Mon, 3 Nov 2025 09:19:08 +0000 (10:19 +0100)]
ada: Move detection of anonymous access types in expansion of Old attributes
Expansion of the Old attribute with anonymous access type is treated
as a special case as the implicit constants need to be declared the
same way as for conditionally evaluated Old attributes. However, this
was implemented in a way that produced evaluation guards even when
the attribute was supposed to be unconditionally evaluated.
gcc/ada/ChangeLog:
* exp_attr.adb (Expand_N_Attribute_Reference): For Old attribute,
detect the anonymous access type case explicitly instead of
implicitly within in Eligible_For_Conditional_Evaluation.
* sem_util.ads: (Eligible_For_Conditional_Evaluation): Do not
return True on anonymous access types. This was also breaking usage
outside expansion (legality checks for Old).
* sem_util.adb: (Conditional_Evaluation_Condition): Special case
of no determiners for anonymous access types is no longer possible.
This patch replaces aspect-based version of the destructors extension
with a new version that uses the "direct attribute definition" syntax
that was recently introduced by the constructors extension.
gcc/ada/ChangeLog:
* snames.ads-tmpl: Make "Destructor" an attribute name.
* snames.adb-tmpl: Allow direct attribute definition for Destructor.
* gen_il-fields.ads (Destructor): New field.
(Is_Destructor): Remove.
* gen_il-gen-gen_entities.adb: (Destructor): New field.
(Is_Destructor): Remove.
* einfo.ads (Destructor): Document new field.
(Is_Destructor): Remove documentation.
* aspects.ads (Aspect_Destructor): Remove.
* exp_attr.adb (Expand_N_Attribute_Reference): Adapt after aspect
removal.
* exp_ch7.adb (Build_Finalize_Statements): Adapt to new destructor
representation.
* freeze.adb (Freeze_Entity): Remove obsolete check.
* sem_attr.adb (Analyze_Attribute, Eval_Attribute): Adapt to new
attribute.
* sem_ch13.adb (Analyze_Aspect_Specifications,
Check_Aspect_At_End_Of_Declarations): Adapt after aspect removal.
* sem_ch6.adb (Analyze_Direct_Attribute_Definition): Add handling
of Destructor attribute.
(Can_Be_Destructor_Of): New function.
* doc/gnat_rm/gnat_language_extensions.rst: Adapt documentation to
new syntax.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.
Eric Botcazou [Mon, 17 Nov 2025 20:18:28 +0000 (21:18 +0100)]
ada: Rename Find_Hook_Context function
The hook moniker is an obsolete reference to the previous implementation of
object finalization, which used hooks (and counters) to manage the objects.
gcc/ada/ChangeLog:
* exp_util.ads (Find_Hook_Context): Rename to...
(Find_Master_Context): ...this and alphabetize.
* exp_util.adb (Find_Master_Context): Rename to...
(Find_Master_Context): ...this and alphabetize.
* exp_ch4.adb (Insert_Conditional_Object_Declaration): Adjust to
above renaming.
(Process_Transients_In_Expression): Likewise.
Javier Miranda [Thu, 27 Nov 2025 17:56:08 +0000 (17:56 +0000)]
ada: Spurious warning on untagged record type equality
The frontend reports a spurious warning when the type of some
component of an untagged record type is a private record type
that has an user-defined equality operator and the sources
are compiled enabling warnings for ignored equality operators
(that is, switch -gnatdw_q).
The warning is spurious because it must not be reported when
the full type declaration of the private type is a record type.
gcc/ada/ChangeLog:
* exp_ch3.adb (Build_Untagged_Record_Equality): Add missing
support for incomplete and private types.
Viljar Indus [Thu, 27 Nov 2025 09:07:19 +0000 (11:07 +0200)]
ada: Fix crash when checking ghost levels of call arguments
We should avoid the check if the called entity cannot have formals
gcc/ada/ChangeLog:
* einfo-utils.adb (Can_Have_Formals): New function for checking
if the entity can support formals.
* einfo-utils.ads (Can_Have_Formals): Likewise.
* ghost.adb (Check_Procedure_Call_Argument_Levels): Avoid checking
the type of the formal if the called entity cannot hold formals.
Claire Dross [Tue, 25 Nov 2025 16:40:31 +0000 (17:40 +0100)]
ada: Fix Ultimate_Overlaid_Entity to match the SPARK RM semantics
The Ultimate_Overlaid_Entity function should return the root of the
last precisely supported address clause as per the definition in the
SPARK RM.
gcc/ada/ChangeLog:
* sem_util.ads (Overlaid_Entity): Return the root of the address
clause of an object if it is precisely supported in SPARK.
* sem_util.adb (Ultimate_Overlaid_Entity): Use Overlaid_Entity to
match the SPARK RM semantics.
* sem_prag.adb (Analyze_Global_Item): Only check for overlays on
variables.
(Analyze_Initialization_Item): Likewise.
(Analyze_Input_Item): Likewise.
Piotr Trojanek [Tue, 25 Nov 2025 10:29:28 +0000 (11:29 +0100)]
ada: Find overlying with slices
A recent change removed rewriting of address of a slice into address of first
component of a slice. Now we need to explicitly detect overlying with slices.
Together, both changes cause warnings to be emitted when slice of a constant
object is overlaid by a variable.
gcc/ada/ChangeLog:
* sem_util.adb (Find_Overlaid_Entity): Detect overlying with slice.
ada: Allow component clauses for certain record components with discriminants
Before this patch, the compiler rejected record representation clauses
when a component has a subtype with a non-static discriminant constraint.
This is a somewhat coarse-grained since the size of such a component can
be constant relatively to the discriminant. One such case in particular
is when the component subtype is an unchecked union.
This patch makes the compiler accept the unchecked union case.
Eric Botcazou [Mon, 24 Nov 2025 17:08:10 +0000 (18:08 +0100)]
ada: Fix premature finalization caused by predicate check on aggregate component
The predicate check may cause the creation of a temporary when it is applied
to a function call and the temporary will be finalized, so any assignment of
the temporary must be followed by an adjustment of the target.
gcc/ada/ChangeLog:
* exp_ch5.adb (Expand_N_Assignment_Statement): If a predicate check
made on the RHS forced the capture of a function call to remove its
side effects, demote No_Ctrl_Actions into No_Finalize_Actions on the
N_Assignment_Statement node.
Eric Botcazou [Sat, 22 Nov 2025 14:19:28 +0000 (15:19 +0100)]
ada: Make Exp_Ch9.Build_Task_Allocate_Block a function
This streamlines the code in the callers. No functional changes.
gcc/ada/ChangeLog:
* exp_ch9.ads (Build_Task_Allocate_Block): Change to function and
remove first formal parameter.
* exp_ch9.adb (Build_Task_Allocate_Block): Likewise. Return an
anonymous list of nodes.
* exp_aggr.adb (Convert_Aggr_In_Allocator): Adjust to above change.
* exp_ch4.adb (Expand_N_Allocator): Likewise.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Likewise.
Eric Botcazou [Thu, 20 Nov 2025 22:25:15 +0000 (23:25 +0100)]
ada: Give consistent error message for invalid prefix in select component
This gives a consistent error message for an invalid prefix in all the cases
where the prefix has been found to be the name of an entity.
gcc/ada/ChangeLog:
* sem_ch4.adb (Analyze_Selected_Component): Give a specific error
message for an invalid prefix that is the dereference of a name.
* sem_ch8.adb (Find_Selected_Component): Give a consistent error
message for the name of an invalid prefix.
Nathaniel Shead [Thu, 8 Jan 2026 09:38:43 +0000 (20:38 +1100)]
c++/modules: Mark implicit using-directive for imported unnamed namespace as imported [PR123393]
The assertion failure in the PR is due to the implicit using-directive
for the anonymous namespace not being considered imported, because
make_namespace_finish calls add_using_namespace without propagating
'from_import'.
PR c++/123393
gcc/cp/ChangeLog:
* name-lookup.cc (make_namespace_finish): Pass from_import to
add_using_namespace.
gcc/testsuite/ChangeLog:
* g++.dg/modules/namespace-18_a.C: New test.
* g++.dg/modules/namespace-18_b.C: New test.
We can reassociate the operations when the XOR only flips bits resulting from
the right or left shift, but not both. So after reassociation in gimple we
get:
> _1 = a_2(D) r>> 1;
> _3 = _1 ^ 1;
Which results in:
> rori a0,a0,1
> xori a0,a0,1
We don't bother with the transformation when the XOR is flipping a bit known to
be zero (ie, a high bit of the result of the right shift or a low bit on the
result of the left shift). For those cases we already figure out that the XOR
is just an IOR and the right things already "just happen".
This triggered some code generation changes on the SH (not surprising because
this BZ was derived from an older SH BZ). It doesn't seem to significantly
improve the SH code, though it does turn a cmp/pz + rotate through carry with a
rotate + xor with immediate. That may be a latency win on the SH, I really
don't know.
Shreya did the bulk of the work here. My contribution was the sister pattern
which has the XOR on the other operand and testcase development.
Bootstrapped and regression tested on x86 & riscv. Also tested across the
various embedded targets without any regressions.
PR target/121778
gcc/
* match.pd: Add pattern to recognize rotate with one or more
bits flipped via xor.
* config/sh/sh.md (*rotcl); New variant which handles the output
we get after the match.pd change above.
gcc/testsuite/
* gcc.target/riscv/pr121778.c: New test.
Co-Authored-By: Jeff Law <jeffrey.law@oss.qualcomm.com>
Jeff Law [Fri, 9 Jan 2026 04:14:18 +0000 (21:14 -0700)]
[RISC-V] Clamp long reservations to 7c
So I've been noticing the cycle time for a native build/test on the
Pioneer and BPI rising over the last many months. I've suspected a pain
point is likely genautomata due to long reservations in the DFAs.
Trying to describe a 30+ cycle bubble in the pipeline just isn't useful
and causes the DFA to blow up.
This is time to build insn-automata.cc using an optimized genautomata
using my skylake server cross compiling to riscv64. The baseline is what
we have today. Then I clamped the reservations (but not the latency) to
7c. 7c is arbitrary, but known not to blow up the DFA. I fixed the BPI
first, then the Andes 23 and so-on.
That's a significant improvement, though I probably wouldn't go forward
with just that improvement. It's less than a minute and skylake systems
aren't exactly new anymore...
Let's try that with an unoptimized genautomata. I often build that way
when debugging.
Baseline 343s
Final 79s
So that's saving ~4m on my skylake server for a common build. Given I
use ccache, that 4m is often a significant amount of the build time. So
this feels like a better motivating example.
But I'm really after bringing down bootstrap cycle times on the BPI and
Pioneer. So let's see what the BPI does. For an optimized genautomata
we get (not testing all the intermediate steps):
Baseline 310s
Final: 110s
Not bad. And if we look at unoptimized genautomata:
Baseline: 2196s
Final: 553s
Now we can see why bootstrap times have crept up meaningfully. That's
~27 minutes out of a 9hr bootstrap time on the BPI (pure bootstrap, no
testing). The effect is more pronounced on the Pioneer where the
improvement is 30+ minutes on a 4hr bootstrap time (each core is slower,
but there's 8x as many cores).
Tested on riscv{32,64}-elf and bootstrapped on the Pioneer (regression
testing in progress). I'll wait for pre-commit CI to do its thing.
The bug is a stale Virtual SSA VDEF on calls to functions that have
been marked const or pure.
pure_const pass analyzes function rocksdb::y::y() and determines it has no side
effects and marks it as const.
At this point, existing call sites to y::y() in other functions still have:
# .MEM_12 = VDEF <.MEM_11> rocksdb::y::y (&l, _9);
The VDEF indicates the call modifies memory but now that y::y() is const,
this VDEF is stale
Later passes after feedback_fnsplit SSA verification fails. Added fixup.