Marek Polacek [Mon, 2 Mar 2026 15:42:29 +0000 (10:42 -0500)]
c++/reflection: static member template operator [PR124324]
This testcase didn't compile properly because eval_is_function and
eval_extract got an unresolved TEMPLATE_ID_EXPR. We used to resolve
them in process_metafunction but I removed that call, thinking it was
no longer necessary. This patch puts it in eval_substitute which
should cover it.
Richard Biener [Mon, 2 Mar 2026 14:08:03 +0000 (15:08 +0100)]
Do not mark stmts PURE_SLP for loop vectorization
Remove this legacy marking from loop vectorization code and adjust
few leftovers from the removal of hybrid SLP support.
* tree-vect-slp.cc (vect_make_slp_decision): Do not call
vect_mark_slp_stmts.
* tree-vect-data-refs.cc (vect_enhance_data_refs_alignment):
We are always doing SLP.
(vect_supportable_dr_alignment): Likewise.
* tree-vect-loop.cc (vect_analyze_loop_2): No need to reset
STMT_SLP_TYPE.
Jonathan Yong [Thu, 26 Feb 2026 11:24:13 +0000 (11:24 +0000)]
gcc: libgdiagnostics DLL for mingw should be for mingw hosts
Fixed incorrect attempts to build a libgdiagnostics by naming it
as a DLL when gcc is configured as a cross compiler that targets
mingw but hosted on non-Windows systems.
gcc/ChangeLog:
* Makefile.in: the libgdiagnostics shared object for mingw
should be based on host name, not target name.
rtl-ssa: Ensure live-out uses before redefinitions [PR123786]
This patch fixes cases in which:
(1) a register is live in to an EBB;
(2) the register is live out of at least one BB in the EBB; and
(3) the register is redefined by a later BB in the same EBB.
We were supposed to create live-out uses for (2), so that the redefinition
in (3) cannot be moved up into the live range of (1).
The patch does this by collecting all definitions in second and
subsequence BBs of an EBB. It then creates degenerate phis for those
registers that do not naturally need phis. For speed and simplicity,
the patch does not check for (2). If a register is live in to the EBB,
then it must be used somewhere, either in the EBB itself or in a
successor outside of the EBB. A degenerate phi would eventually
be needed in either case.
This requires moving append_bb earlier, so that add_phi_nodes can
iterate over the BBs in an EBB.
live_out_value contained an on-the-fly optimisation to remove redundant
phis. That was a mistake. live_out_value can be called multiple times
for the same quantity. Replacing a phi on-the-fly messes up bookkeeping
for second and subsequent calls.
The live_out_value optimisation was mostly geared towards memory.
As an experiment, I added an assert for when the optimisation applied
to registers. It only fired once in an x86_64-linux-gnu bootstrap &
regression test, in gcc.dg/tree-prof/split-1.c. That's a very poor
(but unsurprising) return. And the optimisation will still be done
eventually anyway, during the phi simplification phase. Doing it on
the fly was just supposed to allow the phi's memory to be reused.
The patch therefore moves the optimisation into add_phi_nodes and
restricts it to memory (for which it does make a difference).
gcc/
PR rtl-optimization/123786
* rtl-ssa/functions.h (function_info::live_out_value): Delete.
(function_info::create_degenerate_phi): New overload.
* rtl-ssa/blocks.cc (all_uses_are_live_out_uses): Delete.
(function_info::live_out_value): Likewise.
(function_info::replace_phi): Keep live-out uses if they are followed
by a definition in the same EBB.
(function_info::create_degenerate_phi): New overload, extracted
from create_reg_use.
(function_info::add_phi_nodes): Ensure that there is a phi for
every live input that is redefined by a second or subsequent
block in the EBB. Record that such phis need live-out uses.
(function_info::record_block_live_out): Use look_through_degenerate_phi
rather than live_out_value when setting phi inputs. Remove use of
live_out_value for live-out uses. Inline the old handling of
bb_mem_live_out.
(function_info::start_block): Move append_bb call to...
(function_info::create_ebbs): ...here.
* rtl-ssa/insns.cc (function_info::create_reg_use): Use the new
create_degenerate_phi overload.
gcc/testsuite/
PR rtl-optimization/123786
* gcc.target/aarch64/pr123786.c: New test.
Jakub Jelinek [Tue, 3 Mar 2026 08:51:33 +0000 (09:51 +0100)]
i386: Fix up some FMA patterns for -masm=intel [PR124315]
The following 4 define_insns don't have matching operands between AT&T and
Intel syntax, %3 is "0" and %1 was missing.
Searched grep '%0%{%4%}|%0%{%4%}' *.md and didn't find other spots where
the operand numbers wouldn't match (reverse order of course).
2026-03-03 Jakub Jelinek <jakub@redhat.com>
PR target/124315
* config/i386/sse.md (avx512f_vmfmadd_<mode>_mask3<round_name>,
avx512f_vmfmsub_<mode>_mask3<round_name>,
avx512f_vmfnmadd_<mode>_mask3<round_name>,
avx512f_vmfnmsub_<mode>_mask3<round_name>): Use %<iptr>1 instead of
%<iptr>3 in -masm=intel syntax.
Jakub Jelinek [Tue, 3 Mar 2026 08:49:33 +0000 (09:49 +0100)]
i386: Rename avx512fp16_mov<mode> to *avx512fp16_mov<mode>
On Mon, Mar 02, 2026 at 08:04:53PM +0800, Hongtao Liu wrote:
> You are correct. There is no place that calls
> gen_avx512fp16_mov{v8hf,v8bf,v8hi}. The original pattern‘s name is
> avx512fp16_vmovsh which is added in r12-3407-g9e2a82e1f9d2c4, there's
> also another pattern named *avx512fp16_movsh . At that time, the * was
> added to distinguish between these two patterns.
> And yes, we can add* to the pattern name.
Richard Biener [Tue, 3 Mar 2026 08:18:36 +0000 (09:18 +0100)]
Remove XFAIL for detecting dot-product pattern in vect-reduc-dot-s8b.c
With the change to vect_reassociating_reduction_p this pattern will
always match (application is still conditional on uarch availability),
so remove the XFAIL.
PR testsuite/122961
* gcc.dg/vect/vect-reduc-dot-s8b.c: Remove XFAIL on
dot-prod pattern detection.
Patrick Palka [Tue, 3 Mar 2026 03:37:15 +0000 (22:37 -0500)]
c++: improve constraint recursion diagnostic
Our constraint recursion diagnostics are not ideal because they
usually show the atom with an uninstantiated parameter mapping, e.g
concepts-recursive-sat5.C:6:41: error: satisfaction of atomic constraint 'requires(A a, T t) {a | t;} [with T = T]' depends on itself
This is a consequence of our two-level caching of atomic constraints,
where we first cache the uninstantiated atom+args and then the
instantiated atom+no args, and most likely the first level of caching
detects the recursion, at which point we have no way to get a hold of
the instantiated atom.
This patch fixes this by linking the the first level of caching to the
second level, so that we can conveniently print the instantiated atom in
case of constraint recursion detected from the first level of caching.
Alternatively we could make only the second level of caching diagnose
constraint recursion but then we'd no longer catch constraint recursion
that occurs during parameter mapping instantiation. This current approach
seems simpler, and it also seems natural to have the two cache entries
somehow linked anyway.
gcc/cp/ChangeLog:
* constraint.cc (struct sat_entry): New data member inst_entry.
(satisfaction_cache::satisfaction_cache): Initialize inst_entry.
(satisfaction_cache::get): Use it to prefer printing the
instantiated atom in case of constraint recursion.
(satisfy_atom): Set inst_entry of the first cache entry to point
to the second entry.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-recursive-sat2.C: Verify that the
instantiated parameter mapping is printed.
* g++.dg/cpp2a/concepts-recursive-sat5.C: Likewise.
In the first testcase below, the targ generic lambda
template<class T, class V = decltype([](auto) { })>
...
has two levels of parameters, the outer level {T} and its own level.
We iteratively substitute into this targ lambda three times:
1. The first substitution is during coerce_template_parms with args={T*, }
and tf_partial set. Since tf_partial is set, we defer the substitution.
2. The next substitution is during regeneration of f<void>()::<lambda>
with args={void}. Here we merge with the deferred arguments to
obtain args={void*, } and substitute them into the lambda, returning
a regenerated generic lambda with template depth 1 (no more outer
template parameters).
3. The final (non-templated) substitution is during instantiation of
f<int>()::<lambda>'s call operator with args={int}. But at this
point, the targ generic lambda has only one set of template
parameters, its own, and so this substitution causes us to substitute
away all its template parameters (and its deduced return type).
We end up ICEing from tsubst_template_decl due to its operator()
having now having an empty template parameter set.
The problem ultimately is that the targ lambda leaks into a template
context that has more template parameters than its lexical context, and
we end up over-substituting into the lambda. By the third substitution
the lambda is effectively non-dependent and we really just want to lower
it to a non-templated lambda without actually doing any substitution.
Unfortunately, I wasn't able to get such lowering to work adequately
(e.g. precise dependence checks don't work, uses_template_parms (TREE_TYPE (t))
wrongly returns false, false, true respectively during each of the three
substitutions.)
This patch instead takes a different approach, and makes lambda
deferred-ness sticky: once we decide to defer substitution into a
lambda, we keep deferring any subsequent substitution until the
final substitution, which must be non-templated. So for this
particular testcase the substitutions are now:
1. Return a lambda with deferred args={T*, }.
2. Merge args={void} with deferred args={T*, }, obtaining args={void*, }
and returning a lambda with deferred args={void*, }.
3. Merge args={int} with deferred args={void*, }, obtaining args={void*, }.
Since this substitution is final (processing_template_decl is cleared),
we substitute args={void*, } into the lambda once and for all and
return a regenerated non-templated generic lambda with template depth 1.
In order for a subsequent add_extra_args to properly merge arguments
that have been iteratively deferred, it and build_extra_args needs
to propagate TREE_STATIC appropriately (which effectively signals
whether the arguments are a full set or not).
While PR123655 is a regression, this patch also fixes the similar
PR123408 which is not a regression. Thus, I suspect that the testcase
from the first PR only worked by accident.
PR c++/123665
PR c++/123408
gcc/cp/ChangeLog:
* pt.cc (build_extra_args): If TREE_STATIC was set on the
arguments, keep it set.
(add_extra_args): Set TREE_STATIC on the resulting arguments
when substituting templated arguments into a full set of
deferred arguments.
(tsubst_lambda_expr): Always defer templated substitution if
LAMBDA_EXPR_EXTRA_ARGS was set.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/lambda-targ22.C: New test.
* g++.dg/cpp2a/lambda-targ22a.C: New test.
* g++.dg/cpp2a/lambda-targ23.C: New test.
Robert Dubner [Mon, 2 Mar 2026 20:36:40 +0000 (15:36 -0500)]
cobol: Improved efficiency of code generated for MOVE "A" TO VAR(1:1). [119456]
This PR rightly noted that COBOL source code which obviously could
result in simple machine language did not. These changes take advantage
of the compiler knowing, at compile time, the values of literal offsets
and lengths, and uses that knowledge to generate much more efficient
GENERIC for those cases.
gcc/cobol/ChangeLog:
PR cobol/119456
* genapi.cc (mh_source_is_literalA): Don't set refmod_e attribute
unless it is necessary.
(have_common_parent): Helper routine that determines whether two
COBOL variables are members of the same data description.
(mh_alpha_to_alpha): Modified for greater efficiency when table
subscripts and reference modification parameters are numeric
literals.
* genutil.cc (get_data_offset): Recognizes when table subscripts
and refmod offsets are numeric literals.
(refer_size): Recognizes when refmod offsets are numeric literals.
(refer_size_source): Recognizes when table subscripts are numeric
literals.
doc: Switch some attribute examples to using standard syntax [PR102397]
To finish up PR102397, I've switched some of the attribute examples to
use the new standard syntax (in addition to the few examples that were
already there). Because the old syntax is so common in existing code,
I don't think we want to switch all of the examples -- although when
folks add new attributes going forward, I'd recommend using the
standard syntax in the documentation.
I tested that all the modified examples are accepted by GCC. There
are relatively few examples of target-specific attributes for the
targets I have existing builds for or can build easily to use for such
testing, so I decided to just to leave all the target-specific
examples alone and focus on the common attributes.
gcc/ChangeLog
PR c++/102397
* doc/extend.texi (Attributes): Explicitly say that all attributes
work in both syntaxes and examples may show either form.
(Common Attributes): Convert some examples to use the new syntax.
The unordered containers have 2 types of iterators, the usual ones and the
local_iterator to iterate through a given bucket. In _GLIBCXX_DEBUG mode there
are then 4 lists of iterators, 2 for iterator/const_iterator and 2 for
local_iterator/const_local_iterator.
This patch is making sure that the unordered container's mutex is only lock/unlock
1 time when those lists of iterators needed to be iterate for invalidation purpose.
Also remove calls to _M_check_rehashed after erase operations. Standard do not permit
to rehash on erase operation so we will never implement it.
libstdc++-v3/ChangeLog
* include/debug/safe_unordered_container.h
(_Safe_unordered_container::_M_invalidate_locals): Remove.
(_Safe_unordered_container::_M_invalidate_all): Lock mutex while calling
_M_invalidate_if and _M_invalidate_locals.
(_Safe_unordered_container::_M_invalidate_all_if): New.
(_Safe_unordered_container::_M_invalidate): New.
(_Safe_unordered_container::_M_invalidate_if): Make private, add __scoped_lock
argument.
(_Safe_unordered_container::_M_invalidate_local_if): Likewise.
* include/debug/safe_unordered_container.tcc
(_Safe_unordered_container::_M_invalidate_if): Adapt and remove lock.
(_Safe_unordered_container::_M_invalidate_local_if): Likewise.
* include/debug/unordered_map
(unordered_map::erase(const_iterator, const_iterator)): Lock before loop on
iterators. Remove _M_check_rehashed call.
(unordered_map::_M_self): New.
(unordered_map::_M_invalidate): Remove.
(unordered_map::_M_erase): Adapt and remove _M_check_rehashed call.
(unordered_multimap::_M_erase(_Base_iterator, _Base_iterator)): New.
(unordered_multimap::erase(_Kt&&)): Use latter.
(unordered_multimap::erase(const key_type&)): Likewise.
(unordered_multimap::erase(const_iterator, const_iterator)):
Lock before loop on iterators. Remove _M_check_rehashed.
(unordered_multimap::_M_self): New.
(unordered_multimap::_M_invalidate): Remove.
(unordered_multimap::_M_erase): Adapt. Remove _M_check_rehashed call.
* include/debug/unordered_set
(unordered_set::erase(const_iterator, const_iterator)): Add lock before loop
for iterator invalidation. Remove _M_check_rehashed call.
(unordered_set::_M_self): New.
(unordered_set::_M_invalidate): Remove.
(unordered_set::_M_erase): Adapt and remove _M_check_rehashed call.
(unordered_multiset::_M_erase(_Base_iterator, _Base_iterator)): New.
(unordered_multiset::erase(_Kt&&)): Use latter.
(unordered_multiset::erase(const key_type&)): Likewise.
(unordered_multiset::erase(const_iterator, const_iterator)):
Lock before loop on iterators. Remove _M_check_rehashed.
(unordered_multiset::_M_self): New.
(unordered_multiset::_M_invalidate): Remove.
(unordered_multiset::_M_erase): Adapt. Remove _M_check_rehashed call.
Filip Kastl [Mon, 2 Mar 2026 13:33:06 +0000 (14:33 +0100)]
sparc: Don't require a sparc assembler with TLS [PR123926]
Since r16-6798, it wasn't possible to build a sparc GCC without having
a sparc assembler installed. That shoudn't be the case since there are
usecases for just compiling into assembly.
The problem was sparc.h doing '#define TARGET_TLS HAVE_AS_TLS'.
Building GCC failed when HAVE_AS_TLS wasn't defined which is the case
when one doesn't have an assembler with TLS installed during
./configure.
This patch addresses the problem.
Pushing as obvious.
PR target/123926
gcc/ChangeLog:
* config/sparc/sparc.h (HAVE_AS_TLS): Default to 0.
Jakub Jelinek [Mon, 2 Mar 2026 14:44:40 +0000 (15:44 +0100)]
testsuite: Fix up vec-cvt-1.c for excess precision target [PR124288]
The intent of the code is to find the largest (or smallest) representable
float (or double) smaller (or greater than) or equal to the given integral
maximum (or minimum).
The code uses volatile vars to avoid excess precision, but was relying on
(volatile_var1 = something1 - something2) == volatile_var2
to actually store the subtraction into volatile var and read it from there,
making it an optimization barrier. That is not the case, we compare directly
the rhs of the assignment expression with volatile_var2, so on excess precision
targets it can result in unwanted optimizations.
Fixed by using a comma expression to make sure comparison doesn't know the
value to compare.
2026-03-02 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/124288
* gcc.dg/torture/vec-cvt-1.c (FLTTEST): Use comma expression
to store into {flt,dbl}m{in,ax} and read from it again for
comparison.
Alfie Richards [Mon, 23 Feb 2026 13:13:30 +0000 (13:13 +0000)]
aarch64: Fix FMV reachability and cgraph_node defintion value [PR 124167]
Fix the reachability checks for FMV nodes which were put in the wrong
place and fix the definition value for a dispatched symbol to match
that of the default node.
PR target/124167
gcc/ChangeLog
* attribs.cc (make_dispatcher_decl): Change node->definition
to inherit from the node its called on.
* ipa.cc (remote_unreachable_nodes): Move FMV logic out of
(!in_boundary_p) if block.
This patch adds line_info debug information support to .BTF.ext
sections.
Line info information is used by the BPF verifier to improve error
reporting and give more precise source code referenced errors.
gcc/ChangeLog:
PR target/113453
* config/bpf/bpf-protos.h (bpf_output_call): Change prototype.
* config/bpf/bpf.cc (bpf_output_call): Change to adapt operands
and return
the instruction template instead of immediately emit asm and
not allow proper final expected execution flow.
(bpf_output_line_info): Add function to introduce line info
entries in respective structures
(bpf_asm_out_unwind_emit): Add function as hook to
TARGET_ASM_UNWIND_EMIT. This hook is called before any
instruction is emitted.
* config/bpf/bpf.md: Change calls to bpf_output_call.
* config/bpf/btfext-out.cc (struct btf_ext_lineinfo): Add fields
to struct.
(bpf_create_lineinfo, btf_add_line_info_for): Add support
function to insert line_info data in respective structures.
(output_btfext_line_info): Function to emit line_info data in
.BTF.ext section.
(btf_ext_output): Call output_btfext_line_info.
* config/bpf/btfext-out.h: Add prototype for
btf_add_line_info_for.
Tomasz Kamiński [Fri, 27 Feb 2026 19:14:44 +0000 (20:14 +0100)]
libstdc++: Add #pragma to slience null-dereference warning in istreambuf_iterator::operator++ [PR105580]
The warning was produced by following sequence, given an istream_iterator<char>
it, such that *it will result in hitting EoF in it->_M_get(), and thus clearing
_M_sbuf, the subsequent call to ++it, will result in _M_sbuf->sbumpc() call on
null pointer. This is however an false-positive, as in such situation
it == istream_iteator() returns true, and the iterator should not be
incremented in first place.
This patch sliences the issue, by disabling the "-Wnull-dereference" using
GCC diagnostic pragmas. To work correctly the pragmas needs to be placed around
streambuf functions on which the issue originating from istreambuf_iterator are
reported.
PR libstdc++/105580
libstdc++-v3/ChangeLog:
* include/std/streambuf (streambuf::gptr, streambuf::egptr)
(streambuf::gbump): Surround with pragma disabling -Wnull-dereference.
* testsuite/24_iterators/istreambuf_iterator/105580.cc: Remove check for
warning being emitted.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Jakub Jelinek [Mon, 2 Mar 2026 09:46:00 +0000 (10:46 +0100)]
i386: Fix up avx512fp16_mov<mode> AVX10.2 operand order for -masm=intel [PR124294]
This insn uses incorrect operand order for -masm=intel in the AVX10.2
variant.
I've checked for similar mistakes and haven't found any in all the i386/*.md
files.
Note, I also wonder why the insn doesn't use * in front of the define_insn
name, I can't find anything that would need gen_avx512fp16_movv8{hi,hf,bf}.
2026-03-02 Jakub Jelinek <jakub@redhat.com>
PR target/124294
* config/i386/sse.md (avx512fp16_mov<mode>): Fix ordering of operands
for -masm=intel for the avx10_2 alternative. Fix up indentation in
the insn condition.
(vec_set<mode>_0): Fix comment typo, higer -> higher.
Jakub Jelinek [Mon, 2 Mar 2026 09:42:29 +0000 (10:42 +0100)]
Add r16-7757 -> r16-7745 to ignored_commits
2026-03-02 00:16:26,078:INFO:root:While processing 9a7da540b63e7d77e747b5cdd6fdbbd3954e28c8:
2026-03-02 00:16:26,078:INFO:root:Expected empty second line in commit message: "Revert "[PR115042, LRA]: Postpone processing of new reload insns" as it"
Tamar Christina [Mon, 2 Mar 2026 08:16:38 +0000 (08:16 +0000)]
testsuite: Fix testism in avx512fp16-xorsign-1.c
After r16-7762-g0383e6c398a this test now only vectorizes
the main loop and not the early break result checking loop
due to the FP * being able to raise an FE and we're compiling
with -ftrapping-math.
Test was marked unsupported so didn't notice it before.
testsuite: arm: drop additional option -march=armv7-a
Since r16-7155-g74907f407db641, the -march option is part of the
arm_neon effective target, thus, the extra -march is pointless.
Using -march=armv7-a also prevents testing using softfp or hard float
ABI.
gcc/testsuite/ChangeLog:
* gcc.target/arm/addr-modes-int.c: Drop additional option
-march=armv7-a.
testsuite: add -Wno-overflow to avoid warning in test [PR123191]
Without -Wno-overflow, for arm-none-eabi targets, I see warnings like:
coreutils-group_number.c:13:21: warning: conversion from 'long long unsigned int' to 'size_t' {aka 'unsigned int'} changes value from '18446744073709551615' to '4294967295' [-Woverflow]
Jakub Jelinek [Mon, 2 Mar 2026 07:02:45 +0000 (08:02 +0100)]
testsuite: Fix up anon4.C test for excess precision targets
The g++.dg/reflect/anon4.C test FAILs on i686-linux, because with
extended precision the store to .c rounds to double precision, but comparison
of it against 3.14 constant doesn't.
2026-03-02 Jakub Jelinek <jakub@redhat.com>
* g++.dg/reflect/anon4.C (test): Use (double) 3.14 instead of 3.14 in
comparisons.
Rainer Orth [Sun, 1 Mar 2026 17:32:26 +0000 (18:32 +0100)]
Switch to HAVE_SOLARIS_LD
When configuring GCC to use GNU ld on Solaris, gcc/configure can get
inconsistent ideas about gnu_ld_flag, which results in wrong settings
for various macros:
* Toplevel configure determines LD from PATH using
NCN_STRICT_CHECK_TOOLS(LD, ld). This may be either Solaris ld or GNU ld.
* The resulting LD is always passed to gcc/configure in stages 1 to 3.
* However, when LD and the value of --with-ld differ, there can result
two values of gnu_ld_flag in different sections of gcc/configure:
** config/lib-ld.m4 (AC_LIB_PROG_LD_GNU) determines gnu_ld_flag from $LD.
** However, gcc/configure also checks gcc_cv_ld which can come from
either --with-ld or PATH.
* When this happens, several linker tests arrive at wrong values,
e.g. Solaris ld versions of LD_AS_NEEDED_OPTION when actually GNU ld
is used.
To avoid this, this patch determines gnu_ld_flag from ld -V/--version
once gcc_cv_ld has finally been set.
Besides, just like the HAVE_GNU_AS case, the majority of HAVE_GNU_LD
uses are in Solaris-specific code to distinguish GNU ld from Solaris ld.
Again, it's easier to turn the check around, checking for Solaris ld
directly, which this patch does.
Bootstrapped without regressions on sparcv9-sun-solaris2.11,
amd64-pc-solaris2.11, sparc64-unknown-linux-gnu, and
x86_64-pc-linux-gnu.
Rainer Orth [Sun, 1 Mar 2026 17:04:03 +0000 (18:04 +0100)]
Switch to HAVE_SOLARIS_AS
The vast majority of the remaining uses of HAVE_GNU_AS are in
Solaris-specific code to distinguish uses of GNU as from Solaris as.
It's simpler to turn the check around, checking for Solaris as directly
instead.
The following patch does just that.
Bootstrapped without regressions on sparcv9-sun-solaris2.11,
amd64-pc-solaris2.11, sparc64-unknown-linux-gnu, and x86_64-pc-linux-gnu.
Nathaniel Shead [Wed, 25 Feb 2026 12:19:32 +0000 (23:19 +1100)]
c++/reflection: Improve static_assert diagnostics when comparing reflections
This adds another case to static_assert to print a helpful diagnostic
when comparing reflections. This makes it easier to see what's gone
wrong when doing 'static_assert(some_query(^^a) == some_query(^^b));'
by decomposing the resulting resulting reflection.
gcc/cp/ChangeLog:
* constexpr.cc (diagnose_failing_condition): Also decompose
comparisons of reflections.
gcc/testsuite/ChangeLog:
* g++.dg/reflect/diag5.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Marek Polacek <polacek@redhat.com> Reviewed-by: Jason Merrill <jason@redhat.com>
Jerry DeLisle [Sun, 1 Mar 2026 01:30:41 +0000 (17:30 -0800)]
Fortran: Fix libfortran cannot be cross compiled [PR124286]
Remove unneeded check for a sane CLZL and regenerate using
the correct version of autoconf.
PR fortran/124286
libgfortran/ChangeLog:
* acinclude.m4: Remove LIBGFOR_CHECK_SANE_BUILTIN_CLZL.
* caf/shmem/allocator.c (next_power_of_two): Use known sane
builtin.
* configure: Regenerate.
* configure.ac: Remove use of LIBGFOR_CHECK_SANE_BUILTIN_CLZL.
Marek Polacek [Wed, 25 Feb 2026 21:05:17 +0000 (16:05 -0500)]
c++: ICE with scoped member variable template-id [PR123143]
In this test we crash in lookup_member with
s.S::template a<42> == 42
but not without the "S::". The problem is that lookup_member gets
a TEMPLATE_DECL and not an identifier.
In tsubst_expr/COMPONENT_REF for variable templates we should not
go to the "Lookup the template functions" block; we should let
finish_class_member_access_expr do the job.
PR c++/123143
gcc/cp/ChangeLog:
* pt.cc (tsubst_expr) <case COMPONENT_REF>: Check identifier_p
before doing lookup for a template function.
Marek Polacek [Thu, 26 Feb 2026 20:53:16 +0000 (15:53 -0500)]
c++/reflection: reflection is unevaluated operand [PR123608]
We reject this test with
error: default argument '^^a' uses local variable 'a'
However: [dcl.fct.default]/9: "A parameter shall not appear as
a potentially-evaluated expression in a default argument.", and
[expr.reflect]/7: "The id-expression of a reflect-expression
is an unevaluated operand."
We still have to look at REFLECT_EXPRs in check_out_of_consteval_use_r
though, otherwise it wouldn't work too well.
PR c++/123608
gcc/cp/ChangeLog:
* cp-tree.h (unevaluated_p): Include REFLECT_EXPR.
* reflect.cc (check_out_of_consteval_use_r): Don't give up early
on REFLECT_EXPR_P.
Eric Botcazou [Sat, 28 Feb 2026 18:48:23 +0000 (19:48 +0100)]
Ada: Fix infinite recursion on unchecked union with representation clause
This is a regression present on all active branches: the compiler enters an
infinite recursion when it is generating the initialization procedure of an
unchecked union type with a representation clause, because the layout it has
done for it is problematic. This comes from an old kludge added to support
aggregates for such types, so the fix is to further tweak this kludge.
gcc/ada/
PR ada/124285
* gcc-interface/decl.cc (components_to_record): Force a packed
layout for the innermost variant of an unchecked union type with
fixed part and full representation clause.
gcc/testsuite/
* gnat.dg/specs/unchecked_union3.ads: New test.
So when DOM discovers the edge equivalence for vptr_14 on the 4->5 edge DOM now
back-propagates the value to the uses of vptr_14, particularly uses in bb#1.
That allows us to discover a simple equivalence for _1 which is a key nugget to
unlocking this BZ.
1 = (_3 != 0) by way of traversing the 2->4 edge.
1 = (vptr_14 != 0) by way of traversing the 4->5 edge
_1 = 0 by backproping the state of vptr_14 to use point in bb1
The last step is to back-propagate the _1 = 0 equivalence to the use points of
_1 in bb1. In particular to this statement
_3 = _1 | _2;
If we know that _1 == 0, then _3 and _2 must have the same values (nonzero in
this case).
_2 = ownvptr_15(D) != 0;
Since we know the state of _2, we can compute the state of ownvptr_15. Which
was the goal. We're still on the 4->5 edge, but we've managed to compute an
equivalence for ownvptr_15 which in turn allows us to know how the branch at
the end of bb5 will go.
Note this is not jump threading. It's a conditional equivalence with back
propagation.
The additional lookups in the hash table trigger messages in the dump file.
The unconstrained_commons.f test scans the DOM dump file to ensure certain
messages never appear. That scan test is now bogus. The test has other things
it checks to ensure DOM hasn't done anything wrong. So that one scan test in
unconstrained_commons.f has been removed.
Bootstrapped and regression tested on x86, armv7, loongarch64, riscv64.
Regression tested on the usual crosses as well.
PR tree-optimization/90036
gcc/
* tree-ssa-dom.cc (back_propagate_equivalences): Accept new
argument for available expression stack. Lookup equivalences
in the expression hash table too. If an expression hash a
known constant value, record it and recurse.
(record_temporary_equivalences): Back propagate for a subset of
edge equivalences.
gcc/testsuite
* gcc.dg/tree-ssa/pr90036.c: New test.
* gfortran.dg/unconstrained_commons.f: Drop useless DOM hash table
lookup check.
David Malcolm [Sat, 28 Feb 2026 04:35:46 +0000 (23:35 -0500)]
aarch64: improve diagnostics for bogus JSON tuning inputs [PR124094]
Use json-diagnostic.{h,cc} to improve the diagnostics issued
for malformed and invalid JSON tuning inputs: report the
file/line/column and, if possible, the JSON Pointer of the
problematic input.
$ ./xgcc -B. -S test.c -muser-provided-CPU=unsigned-3.json
cc1: warning: JSON tuning file does not contain version information; compatibility cannot be verified
cc1: error: key ‘tune_params.sve_width’ value 5000000000 is out of range for ‘uint’ type [0, 4294967295]
cc1: error: validation failed for the provided JSON data
$ ./xgcc -B. -S test.c -muser-provided-CPU=unsigned-3.json
cc1: warning: JSON tuning file does not contain version information; compatibility cannot be verified
unsigned-3.json: In JSON value ‘/tune_params/sve_width’
unsigned-3.json:3:18: error: key ‘tune_params.sve_width’ value 5000000000 is out of range for ‘uint’ type [0, 4294967295]
3 | "sve_width": 5000000000
| ^~~~~~~~~~
cc1: error: validation failed for the provided JSON data
gcc/ChangeLog:
PR target/124094
* config/aarch64/aarch64-generate-json-tuning-routines.py
(generate_field_code): Add "ctxt, " arg to function call when
operation is "parse".
(generate_function): Add "gcc_json_context &ctxt, " param to
function decl when operation is "parse".
* config/aarch64/aarch64-json-tunings-parser-generated.inc:
Regenerate, passing around a gcc_json_context &.
* config/aarch64/aarch64-json-tunings-parser.cc: Include
"json-diagnostic.h".
(WARNING_OPT) New macro.
(PARSE_INTEGER_FIELD): Add "ctxt" param and pass it around.
(PARSE_UNSIGNED_INTEGER_FIELD): Likewise.
(PARSE_BOOLEAN_FIELD): Likewise.
(PARSE_STRING_FIELD): Likewise.
(PARSE_OBJECT): Likewise.
(PARSE_ARRAY_FIELD): Likewise.
(PARSE_ENUM_FIELD): Likewise.
(parse_func_type): Likewise.
(parse_object_helper): Likewise. Use json_error rather than error.
(inform_about_wrong_kind_of_json_value): New.
(extract_string): Add "ctxt" param. Replace "warning" with a pair
of calls to json_warning and
inform_about_wrong_kind_of_json_value, tweaking wording
accordingly.
(extract_integer): Likewise.
(extract_unsigned_integer): Likewise.
(parse_enum_field): Likewise.
(validate_and_traverse): Replace "warning" and "error" with
"json_warning" and "json_error".
(check_version_compatibility): Use WARNING_OPT. Add
auto_diagnostic_group to group the error and note.
(aarch64_load_tuning_params_from_json_string): Add "js_filename"
param. Use gcc_json_context to capture location info. Use it
when reporting errors to get file/line/column info. Replace check
on root being non-null with assertion, as this is guaranteed if
error is non-null. Replace warning with json_warning.
(aarch64_load_tuning_params_from_json): Pass data_filename to
aarch64_load_tuning_params_from_json_string for use when reporting
diagnostics.
(selftest::test_json_integers): Add a placeholder filename.
(selftest::test_json_boolean): Likewise.
(selftest::test_json_strings): Likewise.
(selftest::test_json_enums): Likewise.
gcc/testsuite/ChangeLog:
PR target/124094
* gcc.target/aarch64/aarch64-json-tunings/boolean-2.c: Add options
-fdiagnostics-show-caret -fdiagnostics-show-line-numbers. Replace
dg-error with a pair of dg-regexps to verify that we report the
filename and JSON Pointer of where the error occurs, and then
the filename and location within the JSON file. Verify that we
quote and underline the pertinent part of the JSON file.
* gcc.target/aarch64/aarch64-json-tunings/empty-brackets.c: Likewise.
* gcc.target/aarch64/aarch64-json-tunings/enum-2.c: Likewise.
* gcc.target/aarch64/aarch64-json-tunings/integer-2.c: Likewise.
* gcc.target/aarch64/aarch64-json-tunings/integer-3.c: Likewise.
* gcc.target/aarch64/aarch64-json-tunings/string-2.c: Likewise.
* gcc.target/aarch64/aarch64-json-tunings/unidentified-key.c: Likewise.
* gcc.target/aarch64/aarch64-json-tunings/unsigned-2.c: Likewise.
* gcc.target/aarch64/aarch64-json-tunings/unsigned-3.c: Likewise.
* gcc.target/aarch64/aarch64-json-tunings/malformed.c: New test,
to verify behavior on a malformed JSON input file.
* gcc.target/aarch64/aarch64-json-tunings/malformed.json: New
test file. This is malformed JSON, due to a missing ':" between
key and value.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Sat, 28 Feb 2026 04:35:45 +0000 (23:35 -0500)]
Add json-diagnostic.{cc,h}
This patch adds support for emitting diagnostics about JSON input files
to global_dc, showing both the file/line/columns and the JSON Pointer
for the problematic json::value. Test coverage is added by the followup
on aarch64.
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add json-diagnostic.o.
* diagnostics/client-data-hooks.h
(class client_data_hooks_decorator): New.
* diagnostics/context.cc (context::set_client_data_hooks): Return
the old hooks.
* diagnostics/context.h (context::set_client_data_hooks): Update
decl likewise.
* json-diagnostic.cc: New file.
* json-diagnostic.h: New file.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Sat, 28 Feb 2026 04:35:44 +0000 (23:35 -0500)]
diagnostics: split out physical_location_maker from libgdiagnostics
Make this code usable elsewhere.
No functional change intended.
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon):
Add diagnostics/physical-location-maker.o.
* diagnostics/physical-location-maker.cc: New file, adapted from
material in libgdiagnostics.cc.
* diagnostics/physical-location-maker.h: New file, adapted from
material in libgdiagnostics.cc.
* libgdiagnostics.cc: Include
"diagnostics/physical-location-maker.h".
(diagnostic_manager::diagnostic_manager): Initialize
m_phys_loc_maker.
(diagnostic_manager::new_location_from_file_and_line): Split out
into physical_location_maker.
(diagnostic_manager::new_location_from_file_line_column):
Likewise.
(diagnostic_manager::ensure_linemap_for_file_and_line): Likewise.
(diagnostic_manager::m_phys_loc_maker): New field.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Sat, 28 Feb 2026 04:35:44 +0000 (23:35 -0500)]
diagnostics: use label_text for logical_location strings
Doing so makes it possible for logical_locations::manager subclasses to
return copies of temporary buffers, rather than requiring
the buffer to outlive the call. This is useful for generating
JSON pointer strings, for logical locations within JSON files.
gcc/ChangeLog:
* diagnostics/html-sink.cc
(html_builder::make_element_for_diagnostic): Update for logical
location strings being returned as label_text rather than
const char *.
* diagnostics/logical-locations.h
(logical_locations::manager::get_short_name): Return label_text
rather than const char *.
(logical_locations::manager::get_name_with_scope): Likewise.
(logical_locations::manager::get_internal_name): Likewise.
* diagnostics/sarif-sink.cc
(sarif_builder::ensure_sarif_logical_location_for): Update for
logical location strings being returned as label_text rather than
const char *.
(sarif_builder::make_minimal_sarif_logical_location): Likewise.
* diagnostics/selftest-logical-locations.cc
(test_manager::get_short_name): Likewise.
(test_manager::get_name_with_scope): Likewise.
(test_manager::get_internal_name): Likewise.
(selftest_logical_locations_cc_tests): Likewise.
* diagnostics/selftest-logical-locations.h
(test_manager::get_short_name): Likewise.
(test_manager::get_name_with_scope): Likewise.
(test_manager::get_internal_name): Likewise.
* diagnostics/state-graphs-to-dot.cc
(state_diagram::on_node_in_table): Likewise.
* libgdiagnostics.cc
(impl_logical_location_manager::get_short_name): Likewise.
(impl_logical_location_manager::get_name_with_scope): Likewise.
(impl_logical_location_manager::get_internal_name): Likewise.
* tree-logical-location.cc
(tree_logical_location_manager::get_short_name): Likewise.
(tree_logical_location_manager::get_name_with_scope): Likewise.
(tree_logical_location_manager::get_internal_name): Likewise.
* tree-logical-location.h
(tree_logical_location_manager::get_short_name): Likewise.
(tree_logical_location_manager::get_name_with_scope): Likewise.
(tree_logical_location_manager::get_internal_name): Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Sandra Loosemore [Fri, 27 Feb 2026 01:26:20 +0000 (01:26 +0000)]
doc: Restore anchors for deleted attribute section names.
This is a followup to commit gcc-16-7674-g6e3c137f5db: when I merged
attribute subsections, I should have left @anchors with the old names
in place to avoid breaking external links and bookmarks.
gcc/ChangeLog
* doc/extend.texi (Attributes): Rename the node "GNU Attribute
Syntax" node back to "Attribute Syntax"; fix references. Add
@anchor for sections recently merged away at the new location of
the material they used to contain.
openmp: Re-add support for private references to variable-length arrays with allocator clause [PR113436]
The previous patch for PR113436 fixed the testsuite regressions, but disabled
support for allocators when applied to references to variable-length objects
in private clauses. This patch re-adds it.
PR middle-end/113436
* omp-low.cc (lower_omp_target): Merge branches for allocating memory
for private clauses. Add handling for references when allocator
clause not specified.
gcc/testsuite/
PR middle-end/113436
* g++.dg/gomp/pr113436.C: Rename to...
* g++.dg/gomp/pr113436-1.C: ... this. Remove restriction on C++
dialect.
(f): Remove use of auto.
* g++.dg/gomp/pr113436-2.C: New. Original renamed to...
* g++.dg/gomp/pr113436-5.C: ... this. Add tests for alignment.
(f): Test references to VLAs of pointers.
* g++.dg/gomp/pr113436-3.C: New.
* g++.dg/gomp/pr113436-4.C: New.
libgomp/
PR middle-end/113436
* testsuite/libgomp.c++/pr113436-1.C (test_vla_by_ref): New.
(main): Add call to test_vla_by_ref.
* testsuite/libgomp.c++/pr113436-2.C (test_vla_by_ref): New.
(main): Add call to test_vla_by_ref.
Harald Anlauf [Tue, 24 Feb 2026 19:58:53 +0000 (20:58 +0100)]
Fortran: deferred-length character results and -fno-automatic [PR78187]
As the SAVE attribute cannot be specified for dummy variables and function
results (F2023:C862), the option -fno-automatic should not treat them as
automatically saved.
PR fortran/78187
gcc/fortran/ChangeLog:
* trans-decl.cc (gfc_trans_deferred_vars): An initialization block
shall be generated for deferred-length character results even
when -fno-automatic is given.
gcc/testsuite/ChangeLog:
* gfortran.dg/deferred_character_40.f90: New test.
Eric Botcazou [Fri, 27 Feb 2026 20:41:38 +0000 (21:41 +0100)]
Ada: Fix bogus visibility error for expression of iterated association
This completes the transition of the Resolve_Iterated_Association procedure
to the preanalysis of the original nodes for the sake of instantiations.
gcc/ada/
PR ada/124201
PR ada/124282
* exp_aggr.adb (Expand_Iterated_Component): Replace the iteration
variable in the expression as well.
* sem_aggr.adb (Resolve_Iterated_Component_Association): Preanalyze
the expression directly as well.
gcc/testsuite/
* gnat.dg/generic_inst18.adb: New test.
Eric Botcazou [Fri, 27 Feb 2026 18:54:33 +0000 (19:54 +0100)]
Ada: Fix assertion failure for unfrozen mutably tagged type as actual
This is a follow-up to the fix done last December at:
https://gcc.gnu.org/pipermail/gcc-patches/2025-December/704521.html
The fix is not sufficient when nested layers of generics are involved,
so this changes the implementation of mutably tagged types to have the
declaration of their CW-equivalent type immediately analyzed. But this
in turn requires making sure that the root type is frozen before the
CW-equivalent type in all cases.
gcc/ada/
PR ada/123306
* freeze.adb (Freeze_Entity): For a class-wide equivalent type of
a non-interface root type, freeze the root type before it.
* sem_ch3.adb (Derived_Type_Declaration): Minor tweak.
* sem_ch12.adb (Analyze_One_Association): Revert latest change.
* sem_ch13.adb (Analyze_Attribute_Definition_Clause) <Size>: When
the prefix is a class-wide type, insert the declaration of the CW-
equivalent type immediately after that of the root type, and the
size check for the root type into its own freezing actions.
gcc/testsuite/
* gnat.dg/specs/mutably_tagged2.ads: New test.
Owen Avery [Tue, 10 Feb 2026 03:45:48 +0000 (22:45 -0500)]
gccrs: Remove ProcMacroInvocLexer
ProcMacroInvocLexer and MacroInvocLexer were only separate because one
stored instances of const_TokenPtr directly, while the other stored
instances of AST::Token (a thin wrapper around const_TokenPtr). This
patch removes ProcMacroInvocLexer and makes MacroInvocLexer directly
store const_TokenPtr instances.
gcc/rust/ChangeLog:
* Make-lang.in (GRS_OBJS): Remove entries.
* ast/rust-ast.cc (DelimTokenTree::parse_to_meta_item): Handle
changes to AttributeParser.
(AttributeParser::AttributeParser): Change signature.
* ast/rust-macro.h (AttributeParser::AttributeParser): Likewise.
* expand/rust-macro-expand.cc
(MacroExpander::expand_eager_invocations): Handle changes to
MacroInvocLexer.
(MacroExpander::parse_proc_macro_output): Use MacroInvocLexer
instead of ProcMacroInvocLexer.
* expand/rust-macro-expand.h: Remove inclusion of
"rust-proc-macro-invoc-lexer.h".
* expand/rust-macro-invoc-lexer.cc
(MacroInvocLexer::peek_token): Handle changes to MacroInvocLexer
internal representation.
(MacroInvocLexer::get_token_slice): Likewise.
(MacroInvocLexer::split_current_token): Likewise and fix
iterator handling.
* expand/rust-macro-invoc-lexer.h (class MacroInvocLexerBase):
Remove and combine with...
(class MacroInvocLexer): ...its now only derived class.
* expand/rust-proc-macro-invoc-lexer.cc: Removed.
* expand/rust-proc-macro-invoc-lexer.h: Removed.
* parse/rust-parse-impl-proc-macro.cc: Removed.
Harishankar [Sat, 31 Jan 2026 12:15:51 +0000 (17:45 +0530)]
gccrs: parser: Fix rogue null pointer in null_denotation_path
The compiler previously crashed with a segmentation fault when parsing
a struct or tuple expression that failed to parse correctly (e.g.,
returning nullptr). This occurred because the parser implicitly wrapped
the null pointer result in a successful tl::expected, causing a crash
later when the compiler attempted to use the invalid pointer. This
patch adds checks in null_denotation_path to ensure that failed struct
and tuple parsing results are returned as errors (tl::unexpected)
instead of null pointers.
Fixes Rust-GCC/gccrs#4426
gcc/rust/ChangeLog:
* parse/rust-parse-impl-expr.hxx (null_denotation_path):
Check for null struct and tuple expressions to prevent segmentation fault.
Harishankar [Sat, 31 Jan 2026 12:15:51 +0000 (17:45 +0530)]
gccrs: parser: Fix ICE on invalid arithmetic expression
The compiler previously crashed with a segmentation fault when parsing
an arithmetic expression where the left-hand side was invalid (e.g.,
after a failed macro expansion). This occurred because the parser
attempted to access the location of the null 'left' pointer. This
patch adds a check to ensure the left operand is valid before proceeding.
Fixes Rust-GCC/gccrs#4414
gcc/rust/ChangeLog:
* parse/rust-parse-impl-expr.hxx (parse_arithmetic_or_logical_expr):
Check for null left operand to prevent segmentation fault.
Jayant Chauhan [Fri, 16 Jan 2026 17:23:28 +0000 (22:53 +0530)]
gccrs: ast: Add qualified_call helper to Builder
This patch implements the `qualified_call` helper method in the `Builder`
class. This logic was previously intended to be a local helper in
`DeriveClone`, but moving it to the `Builder` allows it to be reused
across the compiler for constructing qualified function calls.
It updates `DeriveClone::clone_call` to use this new `Builder` method,
simplifying the code and resolving the TODO.
Fixes Rust-GCC#4393
gcc/rust/ChangeLog:
* ast/rust-ast-builder.h (Builder::qualified_call): New method declaration.
* ast/rust-ast-builder.cc (Builder::qualified_call): Implement new method.
* expand/rust-derive-clone.cc (DeriveClone::clone_call): Use builder.qualified_call.
jayant chauhan [Sun, 1 Feb 2026 13:18:28 +0000 (18:48 +0530)]
gccrs: parser: Fix ICE in AnonConst by handling null macro result
The parse_anon_const function triggered an assertion failure (ICE) when
receiving a success Result containing a null expression pointer. This
occurred because null_denotation_path directly returned the result of
parse_macro_invocation_partial (which returns a raw pointer) without
checking for failure.
When parse_macro_invocation_partial failed (returning nullptr), it was
wrapped into a tl::expected success state containing nullptr, rather than
an error state.
This patch adds a check in null_denotation_path to verify if the parsed
macro invocation is null. If it is, it now returns a tl::unexpected error,
ensuring that invalid expressions are correctly reported as errors
upstream.
Fixes Rust-GCC#4412
gcc/rust/ChangeLog:
* parse/rust-parse-impl-expr.hxx (null_denotation_path): Check
if macro invocation returns null and return error.
Islam-Imad [Tue, 3 Feb 2026 12:11:48 +0000 (14:11 +0200)]
gccrs : parse: Fix ICE when using 'dyn' without trait bound
The parser was accepting 'dyn' as a standalone type in contexts like:
static STATIC_1: dyn = 1;
This invalid syntax should be rejected at parse time.
Fixes Rust-GCC/gccrs#3905
gcc/rust/ChangeLog:
* lex/rust-lex.cc (is_whitespace): refactor if-else to switch
* lex/rust-token.h: refactor if-else to switch
* parse/rust-parse-impl.hxx: return nullptr when type is in invalid state
gcc/testsuite/ChangeLog:
* rust/compile/issue-3904.rs: refactor the testcase to match the new thrown error
jayant chauhan [Sun, 1 Feb 2026 11:09:30 +0000 (16:39 +0530)]
gccrs: util/attributes: Fix ICE on bare #[deprecated] attribute
The check_deprecated_attribute function previously assumed that the
attribute always contained an input (arguments). However, #[deprecated]
is valid without arguments. Accessing the input on a bare #[deprecated]
attribute resulted in a null pointer dereference and a segmentation fault.
This patch adds a guard clause to check if the attribute has input
before attempting to access it, preventing the crash.
Fixes Rust-GCC#4410
gcc/rust/ChangeLog:
* util/rust-attributes.cc (check_deprecated_attribute): Guard against
attributes without input.
Harishankar [Thu, 22 Jan 2026 13:43:30 +0000 (19:13 +0530)]
gccrs: ast: Fix module path resolution for sibling modules in root
Currently, the compiler fails to resolve module paths when a file in the
root directory (e.g. 'bar.rs') attempts to load a sibling module
(e.g. 'foo.rs') if a 'bar/' directory does not exist. The compiler
incorrectly assumes that if 'bar.rs' is not 'mod.rs', it must look
exclusively in a subdirectory.
This patch adds a fallback mechanism in 'Module::process_file_path'.
If the subdirectory search fails, it strips the implicit subdirectory
and attempts to resolve the module in the parent directory, consistent
with Rust 2018 path rules.
Fixes Rust-GCC/gccrs#4402
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Module::process_file_path): Add fallback search
for sibling modules when subdirectory search fails.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4402.rs: New test.
* rust/compile/issue_4402_foo.rs: New test.
* rust/compile/compile.exp:Ignore issue_4402_foo.rs
Jayant Chauhan [Fri, 16 Jan 2026 16:58:00 +0000 (22:28 +0530)]
gccrs: util/attributes: Error on malformed lint attributes
Emit a diagnostic when lint attributes (allow, deny, warn, forbid) are
used without arguments. Previously, these attributes were accepted silently
if malformed, which could lead to confusion or ignored lints. This ensures
users are informed of the expected form: #[allow(lint_name)].
Fixes Rust-GCC#4358
gcc/rust/ChangeLog:
* util/rust-attributes.cc (check_lint_attribute): New helper.
(AttributeChecker::visit): Call helper for lint attributes on functions.
The compiler implicitely inject the core crate in every crate but those
explicitely tagged with `no_core`. Since most of the tests were
developped with no core in mind, most of those shall have the no_core
attribute inserted.
The core library is made accessible through the `core` identifier in
every crate unless the crate opt out with the `#![no_core]` attribute.
This commit implicitely inject this extern crate when required.
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Crate::inject_extern_crate): Add a function to
inject an extern crate item to a crate.
* ast/rust-ast.h: Add function prototype for inject_extern_crate.
* rust-session-manager.cc (has_attribute): Add helper to determine if
a crate has a given inner attribute.
(Session::compile_crate): Add a step to inject the core extern crate
when the no_core attribute is missing.
* util/rust-attribute-values.h: Add the no_core attribute value.
gccrs: Prevent resolution of items within parent modules
An item from a parent module should be brought into scope with a Use
declaration and not implicitly. This means we should not continue
iterating over the upper ribs when meeting a module rib.
This fix breaks the compilation of core since the items from the
uppermost ribs are brought within scope with the prelude mechanism which
is not complete yet.
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.hxx: Prevent iteration on parent ribs.
gcc/testsuite/ChangeLog:
* rust/compile/name_resolution26.rs: New test.
* rust/compile/derive-default1.rs: Add no_core attribute and fix the
testcase with a proper name usage which does not break name resolution
rules.
* rust/compile/derive-eq-invalid.rs: Likewise.
* rust/compile/derive-hash1.rs: Likewise.
* rust/compile/issue-2905-2.rs: Likewise.
* rust/compile/issue-3402-1.rs: Likewise.
* rust/compile/issue-3403.rs: Likewise.
* rust/compile/name_resolution18.rs: Likewise.
* rust/compile/privacy2.rs: Likewise.
* rust/execute/torture/derive-default1.rs: Likewise.
* rust/core/core.exp: Revert last compilation step to attribute check.
* typecheck/rust-hir-type-check-pattern.cc (visit(StructPattern)): Implement
type check case for HIR::StructPatternFieldTuplePat.
* checks/errors/rust-hir-pattern-analysis.cc (lower_struct_pattern): Implement
case for HIR::StructPatternField::ItemType::TUPLE_PAT.
* backend/rust-compile-pattern.cc:
* CompilePatternCheckExpr::visit (HIR::StructPattern): Implement code
gen for HIR::StructPatternField::ItemType::TUPLE_PAT case.
* CompilePatternBindings::handle_struct_pattern_tuple_pat: Implement
bindings for HIR::StructPatternFieldTuplePat.
* backend/rust-compile-pattern.h: Update function definition for
handle_struct_pattern_tuple_pat.
Mason Pike [Fri, 26 Dec 2025 15:06:51 +0000 (16:06 +0100)]
gccrs: add outer attributes
gcc/rust/ChangeLog:
* util/rust-attributes.cc: add attributes to the __outer_attributes set.
This prevents some inconsistent behavior, like: https://godbolt.org/z/Eq1GE7xxY
Mason Pike [Fri, 26 Dec 2025 14:45:47 +0000 (15:45 +0100)]
gccrs: remove some loops
gcc/rust/ChangeLog:
* util/rust-attributes.cc: factor out loops from
several functions to prevent us from having to loop
several times over the same attributes
Jayant Chauhan [Fri, 16 Jan 2026 19:49:56 +0000 (01:19 +0530)]
gccrs: expand: Refactor field expansion and add documentation
This patch refactors and in
to use a common template helper , reducing
code duplication as requested by the FIXME. It also adds missing documentation
for .
gcc/rust/ChangeLog:
* expand/rust-expand-visitor.h (expand_closure_params): Add documentation.
(expand_fields): New private template helper.
* expand/rust-expand-visitor.cc (expand_struct_fields): Use helper.
(expand_tuple_fields): Use helper.
Jayant Chauhan [Fri, 16 Jan 2026 19:20:36 +0000 (00:50 +0530)]
gccrs: backend: Factor out asm operand chaining
This patch introduces a static helper in .
This removes code duplication when building tree lists for assembly inputs
and outputs. It also removes commented-out debug code to clean up the file.
gcc/rust/ChangeLog:
* backend/rust-compile-asm.cc (chain_asm_operand): New helper.
(CompileAsm::asm_construct_outputs): Use helper and remove dead code.
(CompileAsm::asm_construct_inputs): Use helper and remove dead code.
* rust/compile/issue-4375-ice-regression.rs: New test.
* rust/compile/issue-4375-multiple-errors.rs: New test.
* rust/compile/issue-4375-tuple-pattern.rs: New test.
Jayant Chauhan [Thu, 15 Jan 2026 17:59:10 +0000 (23:29 +0530)]
gccrs: util/attributes: handle #[export_name] on static items
This patch enables validation for the #[export_name] attribute when used
on static items. It reuses the validation logic introduced for functions
to ensure that statics also receive compile-time checks for malformed
inputs (e.g. non-string literals).
Fixes Rust-GCC#4388
gcc/rust/ChangeLog:
* util/rust-attributes.cc (AttributeChecker::visit): Add check for
export_name on static items.
Jayant Chauhan [Thu, 15 Jan 2026 17:15:40 +0000 (22:45 +0530)]
gccrs: util/attributes: error on malformed #[export_name] input
Emit a diagnostic when #[export_name] is used without arguments or
with invalid arguments (non-string literals). This prevents silent
failures or backend crashes when lowering the attribute to GIMPLE,
ensuring the attribute follows the expected form: #[export_name = name].
Fixes Rust-GCC#4387
gcc/rust/ChangeLog:
* util/rust-attributes.cc (check_export_name_attribute): New helper.
(AttributeChecker::visit): Check export_name on functions.
Arthur Cohen [Wed, 14 Jan 2026 17:42:37 +0000 (18:42 +0100)]
gccrs: nr: Add proper prelude resolution and fill it upon encountering a prelude.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add Type::Kind.
* ast/rust-macro.h: Use it.
* ast/rust-path.h: Likewise.
* ast/rust-type.h: Likewise.
* resolve/rust-default-resolver.cc (is_lang_impl): New method.
(DefaultResolver::visit): Collect lang item implementations in the
prelude.
* resolve/rust-forever-stack.h: Add new method for lang prelude injection.
* resolve/rust-forever-stack.hxx: Define it.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Identifier patterns
can resolve to empty structs or variants.
* resolve/rust-name-resolution-context.h: Improve resolution.
The rust language requires the export_name attribute to change the name
of a symbol within the assembly whilst keeping a different name at the
language level. This is used multiple times within rust-for-linux.
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: Change the assembly name on functions
with the export_name attribute. Do not mangle the name.
* util/rust-attribute-values.h: Add export_name attribute value.
* util/rust-attributes.cc: Add export_name attribute to builtin
attribute list.
Jayant Chauhan [Tue, 13 Jan 2026 21:17:00 +0000 (02:47 +0530)]
gccrs: util/attributes: Check that #[target_feature] is only used on unsafe functions
The #[target_feature] attribute allows code generation that may not be
supported by the runtime hardware, making it inherently unsafe. This
patch adds a check to ensure it is only applied to functions declared
as 'unsafe', matching rustc behavior (E0658).
Fixes Rust-GCC#4234
gcc/rust/ChangeLog:
* util/rust-attributes.cc (AttributeChecker::visit):
Reject #[target_feature] on non-unsafe functions.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4234.rs: New test.
* rust/compile/unsafe11.rs: Mark function as unsafe to
to satisfy new #[target_feature] restriction.
Removes duplicate error in block expression parsing.
Removes cascading error in match arm parsing.
Adds proper error detection for unterminated expression.
Fixes Rust-GCC/gccrs#1210
gcc/rust/ChangeLog:
* parse/rust-parse-impl-expr.hxx: Removes duplicate errors.
* parse/rust-parse-impl.hxx: Detects when an expression without
block is not properly terminated
Jayant Chauhan [Tue, 13 Jan 2026 08:10:47 +0000 (13:40 +0530)]
gccrs: util/attributes: Error on #[repr] applied to functions
The #[repr] attribute is only valid for structs, enums, and unions.
Applying it to a function is invalid and should result in an error.
This patch adds a check in the attribute visitor to reject #[repr]
on functions, matching rustc behavior.
Fixes Rust-GCC#4232
gcc/rust/ChangeLog:
* util/rust-attributes.cc (AttributeChecker::check_attributes): Emit error for #[repr].