]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 months agoFix time zone for 'cobol.dg/group2/FUNCTION_DATE___TIME_OMNIBUS.cob' (take 2) [PR119818]
Thomas Schwinge [Fri, 18 Apr 2025 11:01:57 +0000 (13:01 +0200)] 
Fix time zone for 'cobol.dg/group2/FUNCTION_DATE___TIME_OMNIBUS.cob' (take 2) [PR119818]

In recent commit 1cbfc71e53207bde3f0d28354b5c92d973d4b435
"cobol: Update and expand DejaGNU test suite", we lost the
commit ed8761241ac529ccddb2b76a1895c124c67c132c
"Fix time zone for 'cobol.dg/group2/FUNCTION_DATE___TIME_OMNIBUS.cob' [PR119818]"
patch, and with that in certain configurations regressed:

    PASS: cobol.dg/group2/FUNCTION_DATE___TIME_OMNIBUS.cob   -O0  (test for excess errors)
    [-PASS:-]{+FAIL:+} cobol.dg/group2/FUNCTION_DATE___TIME_OMNIBUS.cob   -O0  execution test
    [Etc.]

Re-apply that patch.

PR cobol/119818
gcc/testsuite/
* cobol.dg/group2/FUNCTION_DATE___TIME_OMNIBUS.cob:
'dg-set-target-env-var TZ UTC0' (take 2).

2 months agovect: fix vectorization of non-gather elementwise loads: Unrestrict test cases [PR124037]
Thomas Schwinge [Fri, 17 Apr 2026 08:20:51 +0000 (10:20 +0200)] 
vect: fix vectorization of non-gather elementwise loads: Unrestrict test cases [PR124037]

Contrary to an earlier revision of them, in my understanding, the test cases
'g++.dg/vect/vect-pr124037.cc', 'gcc.dg/vect/vect-pr124037.c' as added in
commit 4a30b45ffe3cb4ad2e35d73f1714f1a80e32edd7
"vect: fix vectorization of non-gather elementwise loads [PR124037]"
are no longer specific to early break vectorization, and the C++ one also
doesn't use 'mmap'.

PR tree-optimization/124037
gcc/testsuite/
* g++.dg/vect/vect-pr124037.cc: Unrestrict.
* gcc.dg/vect/vect-pr124037.c: Likewise.

2 months agolibgomp: fix omp_target_is_present and omp_get_mapped_ptr: Fix up 'libgomp.c/omp_targ...
Thomas Schwinge [Fri, 10 Apr 2026 14:51:48 +0000 (16:51 +0200)] 
libgomp: fix omp_target_is_present and omp_get_mapped_ptr: Fix up 'libgomp.c/omp_target_is_present.c'

It's probably a general issue that we don't 'omp_target_disassociate_ptr' after
'omp_target_associate_ptr', but in a multi-device setting, this results in an
execution test FAIL.

Fix up for commit 3923f9414e116a43c7f398f936ca4e5b21f66049
"libgomp: fix omp_target_is_present and omp_get_mapped_ptr".

libgomp/
* testsuite/libgomp.c/omp_target_is_present.c (check_routines):
'omp_target_disassociate_ptr' after 'omp_target_associate_ptr'.

2 months agolibstdc++: Further baseline_symbols.txt updates
Jakub Jelinek [Fri, 17 Apr 2026 13:05:14 +0000 (15:05 +0200)] 
libstdc++: Further baseline_symbols.txt updates

Unlike the previous patch which was (except for powerpc64-linux) actually
done from looking at actual libstdc++.so.6.0.35 symbols on each arch,
the following is all guesses.
Given the change analysis done in previous patch, I've updated
baseline_symbols.txt which have been updated in GCC 15 by applying the
aarch64-linux-gnu baseline_symbols.txt patch for targets which use
m size_t mangling and i486-linux-gnu baseline_symbols.txt patch for
targets which use j size_t mangling.
Skipped targets which haven't been updated in GCC 15 and hppa-linux-gnu
where the patch didn't apply cleanly.

2025-05-17  Jakub Jelinek  <jakub@redhat.com>

* config/abi/post/ia64-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/m68k-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/powerpc64-linux-gnu/32/baseline_symbols.txt: Update.
* config/abi/post/powerpc-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/sparc64-linux-gnu/32/baseline_symbols.txt: Update.
* config/abi/post/sparc64-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/x86_64-linux-gnu/x32/baseline_symbols.txt: Update.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2 months agolibstdc++: Add comments to non-obvious parts of std::print internals
Jonathan Wakely [Fri, 13 Mar 2026 21:07:29 +0000 (21:07 +0000)] 
libstdc++: Add comments to non-obvious parts of std::print internals

libstdc++-v3/ChangeLog:

* include/bits/print.h (_File_sink): Add comments.

2 months agolibstdc++: Optionally define std::print functions non-inline [PR124410]
Jonathan Wakely [Tue, 10 Mar 2026 21:19:09 +0000 (21:19 +0000)] 
libstdc++: Optionally define std::print functions non-inline [PR124410]

We don't want to export std::vprint_unicode etc. from libstdc++.so yet,
but we can give users the option of improving compile times by getting
the definitions of the std::print internals from libstdc++exp.a instead.

This commit adds a macro, _GLIBCXX_NO_INLINE_PRINT, which disables the
inline definitions of std::vprint_unicode etc. so that extern
definitions in libstdc++exp.a can be used instead.

With this change compiling a helloworld using std::print goes from 8s to
under 2s with trunk. For release branches with --enable-checking=release
we should see even faster times. The object file size is also
dramatically smaller, because there's just a single call to an extern
function instead of instantiating the entire std::print and std::format
implementation inline.

libstdc++-v3/ChangeLog:

PR libstdc++/124410
* doc/html/*: Regenerate.
* doc/xml/manual/using.xml (_GLIBCXX_NO_INLINE_PRINT): Document
macro.
* include/Makefile.am: Add bits/print.h and bits/ostream_print.h
headers.
* include/Makefile.in: Regenerate.
* include/std/ostream (vprint_nonunicode, vprint_unicode): Move
definitions to new bits/ostream_print.h header.
* include/std/print (__format::_File_sink, vprint_nonunicode)
(vprint_nonunicode_buffered, vprint_unicode)
(vprint_unicode_buffered): Move definitions to new bits/print.h
header.
* src/c++23/print.cc: Include new headers to define symbols for
inline print functions.
* include/bits/ostream_print.h: New file.
* include/bits/print.h: New file.

2 months agolibstdc++: Update Solaris baselines for GCC 16.1
Jonathan Wakely [Fri, 17 Apr 2026 10:49:47 +0000 (11:49 +0100)] 
libstdc++: Update Solaris baselines for GCC 16.1

This patch updates the Solaris libstdc++ baselines for GCC 16.1.

Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11 on trunk.

libstdc++-v3/ChangeLog:

* config/abi/post/i386-solaris/baseline_symbols.txt: Regenerate.
* config/abi/post/i386-solaris/amd64/baseline_symbols.txt:
Likewise.
* config/abi/post/sparc-solaris/baseline_symbols.txt: Likewise.
* config/abi/post/sparc-solaris/sparcv9/baseline_symbols.txt:
Likewise.

2 months agolibstdc++: Update baseline_symbols.txt on some Linux arches
Jakub Jelinek [Fri, 17 Apr 2026 12:25:48 +0000 (14:25 +0200)] 
libstdc++: Update baseline_symbols.txt on some Linux arches

The following patch updates baseline_symbols.txt files.

Most of these come from Fedora package builds, i386 used to be the same as
i486 in GCC <= 11 but hasn't been updated since, so the changes are larger
there.  riscv64 is from my build on cfarm95 where i'm debugging bitint
issues currently.  powerpc64 is hand edited mix of powerpc64le and old
powerpc64 (i.e. basically powerpc64le with IEEE stuff and DF128/DF64x stuff
removed).

Verification of the changes (ignoring the i386 changes which are across
multiple GCC versions) looks ok, in particular:
grep ^- patchwithouti386 | grep -v ^---
yields nothing
grep ^+ patchwithouti386 | grep -v ^+++ | grep -v GLIBCXX_3.4.35 | grep -v CXXABI_1.3.17
yields also nothing
grep ^+ patchwitouti386 | grep -v ^+++ | sort | uniq -c | sort -n
shows mostly 8 occurrences of stuff, the exceptions are just
      1 +OBJECT:16:_ZTIDF16_@@CXXABI_1.3.17
      1 +OBJECT:32:_ZTIPDF16_@@CXXABI_1.3.17
      1 +OBJECT:32:_ZTIPKDF16_@@CXXABI_1.3.17
      2 +FUNC:_ZNSt12__cow_stringC2EPKcj@@GLIBCXX_3.4.35
      2 +FUNC:_ZNSt8__detail17__wait_until_implEPKvRNS_16__wait_args_baseERKNSt6chrono8durationIxSt5ratioILx1ELx1000000000EEEE@@GLIBCXX_3.4.35
      6 +FUNC:_ZNSt12__cow_stringC2EPKcm@@GLIBCXX_3.4.35
      6 +FUNC:_ZNSt8__detail17__wait_until_implEPKvRNS_16__wait_args_baseERKNSt6chrono8durationIlSt5ratioILl1ELl1000000000EEEE@@GLIBCXX_3.4.35
The 6 vs. 2 is unsigned int vs. unsigned long difference, supposedly
size_t, and _ZTI*DF16_ are new just on s390x intentionally.

2025-05-17  Jakub Jelinek  <jakub@redhat.com>

* config/abi/post/x86_64-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/x86_64-linux-gnu/32/baseline_symbols.txt: Update.
* config/abi/post/i386-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/i486-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/aarch64-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/s390x-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/powerpc64-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/powerpc64le-linux-gnu/baseline_symbols.txt: Update.
* config/abi/post/riscv64-linux-gnu/baseline_symbols.txt: Update.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2 months agoarm, bitint: Add support for FP_HANDLE_EXCEPTIONS and FP_ROUNDMODE with hard float abi
Andre Vieira [Fri, 17 Apr 2026 10:13:07 +0000 (11:13 +0100)] 
arm, bitint: Add support for FP_HANDLE_EXCEPTIONS and FP_ROUNDMODE with hard float abi

This patch adds support for FP_HANDLE_EXCEPTIONS when using hard float abi.
This is used by _BitInt software emulation for floating point conversions to
throw an exception.

This patch also adds support for FP_ROUNDMODE with hard float abi, which is
also used by _BitInt floating point emulation.

libgcc/ChangeLog:

* config/arm/sfp-exceptions.c: New file.
* config/arm/sfp-machine.h: Define FP_HANDLE_EXCEPTIONS, FP_EX_*
MACROs, _FP_DECL_EX, FP_ROUNDMODE, FP_INIT_ROUNDMODE, FP_RND_* MACROs
and declare __sfp_handle_exceptions.
* config/arm/t-softfp: Add sfp-exceptions.c to LIB2ADD.

2 months agolibstdc++: Improve Doxygen comments in <chrono>
Jonathan Wakely [Wed, 1 Apr 2026 22:44:17 +0000 (23:44 +0100)] 
libstdc++: Improve Doxygen comments in <chrono>

libstdc++-v3/ChangeLog:

* include/std/chrono: Improve Doxygen comments.

2 months agolibstdc++: Add module initialization functions to the library [PR124268]
Jonathan Wakely [Wed, 11 Mar 2026 21:05:13 +0000 (21:05 +0000)] 
libstdc++: Add module initialization functions to the library [PR124268]

This tries to ensure that the module init functions are present in
libstdc++.so and libstdc++.a, so that users of the std and std.compat
modules don't need to manually link to std.o and/or std.compat.o in
addition to compiling the CMIs.

This also adds a clean-local target to remove the generated interface
units and manifest, and the gcm.cache directory for the CMIs.

This was previously committed and then reverted because it broke
bootstrap on a few targets. Most of the reasons the module interface
units failed to compile have (we believe) now been addressed with G++
changes, although there's still a problem on amdgcn (PR124554). Due to
that problem, and any not yet known problems, this version of the patch
tries to avoid breaking bootstrap again by allowing the modules to fail
to compile. If compiling std.o or std.compat.o fails then an empty
translation unit will be compiled and added to libstdc++.so instead.

This means that we will only export the module initialization functions
from the library if the module can be compiled for the target. This
seems fine because we don't need to initialize anything for a module
that cannot even be compiled! Fixing PR124554 and removing this kluge
should be done for GCC 17 in stage 1.

libstdc++-v3/ChangeLog:

PR libstdc++/124268
* config/abi/pre/gnu.ver: Export symbols.
* src/Makefile.am: Add libmodulesconvenience.la to libstdc++
link.
* src/Makefile.in: Regenerate.
* src/c++23/Makefile.am: Create libmodulesconvenience.la
and populate it with std.o and std.compat.o interface units,
with empty fallback objects if compiling the interface units
fails. Add clean-local target.
* src/c++23/Makefile.in: Regenerate.

2 months agolibstdc++: Skip std::generate_canonical tests for IBM long double [PR124540]
Jonathan Wakely [Thu, 16 Apr 2026 15:08:45 +0000 (16:08 +0100)] 
libstdc++: Skip std::generate_canonical tests for IBM long double [PR124540]

This tests assumes IEEE semantics, so fails on POWER with IBM long
double format. Just skip the long double part of the test.

libstdc++-v3/ChangeLog:

PR libstdc++/124540
* testsuite/26_numerics/random/uniform_real_distribution/operators/gencanon.cc:
Skip long double tests for IBM long double format.

2 months agomiddle-end: disable CRC pass when -Os and the target does not have CRC optabs [PR124900]
Tamar Christina [Fri, 17 Apr 2026 06:46:07 +0000 (07:46 +0100)] 
middle-end: disable CRC pass when -Os and the target does not have CRC optabs [PR124900]

The example

#include <stdint.h>
#include <stddef.h>

uint32_t crc32(const uint8_t *data, size_t length)
{
    uint8_t i;
    uint32_t crc = 0xffffffff; // Initial value
    while (length--) {
        crc ^= (uint32_t)(*data++) << 24;
#pragma GCC unroll 0
        for (i = 0; i < 8; ++i) {
            if (crc & 0x80000000)
                crc = (crc << 1) ^ 0x04C11DB7;
            else
                crc <<= 1;
        }
    }
    return crc;
}

when compiled with -Os -march=armv8-a increases the codesize significantly
because it generates a loop that's as big as the original but adds a lookup
table of 255 * 4 bytes.  This means it's actively making codesize bigger and
introduces a codesize regression from before the pass was added.

This patch disables the CRC table based expansion when compiling for size.

gcc/ChangeLog:

PR middle-end/124900
* gimple-crc-optimization.cc (crc_optimization::optimize_crc_loop): Do
not expand to table when compiling for size.
(class crc_optimization): Update prototype of optimize_crc_loop to
include loop.
(crc_optimization::execute): Pass loop to optimize_crc_loop.

gcc/testsuite/ChangeLog:

PR middle-end/124900
* gcc.target/aarch64/crc-1.c: New test.
* gcc.target/aarch64/crc-2.c: New test.
* gcc.target/aarch64/crc-3.c: New test.
* gcc.target/aarch64/crc-4.c: New test.

2 months agoc++: -Wkeyword-macro vs. contracts
Jakub Jelinek [Fri, 17 Apr 2026 05:52:07 +0000 (07:52 +0200)] 
c++: -Wkeyword-macro vs. contracts

contract_assert is a keyword listed in c_common_reswords for D_CXX26,
so no need to call cpp_warn separately on it, it is called already in
            tree id = get_identifier (c_common_reswords[i].word);
            if (IDENTIFIER_KEYWORD_P (id)
                /* Don't register keywords with spaces.  */
                && IDENTIFIER_POINTER (id)[IDENTIFIER_LENGTH (id) - 1] != ' ')
              cpp_warn (parse_in, IDENTIFIER_POINTER (id),
                        IDENTIFIER_LENGTH (id));
earlier.  contract_assert is also the only -fcontracts related keyword in
https://eel.is/c++draft/lex.key#tab:lex.key .  On the other side, pre/post
are identifiers with special meaning: https://eel.is/c++draft/tab:lex.name.special
and so need to be handled.  Note, contract_assert is also already correctly
tested in those tests.

2026-04-17  Jakub Jelinek  <jakub@redhat.com>

* lex.cc (cxx_init): Don't call cpp_warn on contract_assert,
instead call it on pre and post.

* g++.dg/warn/Wkeyword-macro-1.C: Expect error for pre/post for C++26.
* g++.dg/warn/Wkeyword-macro-2.C: Expect warning for pre/post for
C++26.
* g++.dg/warn/Wkeyword-macro-4.C: Expect error for pre/post for C++26.
* g++.dg/warn/Wkeyword-macro-5.C: Expect warning for pre/post for
C++26.
* g++.dg/warn/Wkeyword-macro-7.C: Likewise.
* g++.dg/warn/Wkeyword-macro-8.C: Likewise.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: Reject splicing of function parameters [PR123783]
Jakub Jelinek [Fri, 17 Apr 2026 05:50:35 +0000 (07:50 +0200)] 
c++: Reject splicing of function parameters [PR123783]

When discussing the PR recently, I've realized that we don't reject
splicing of function parameters, even when
http://eel.is/c++draft/expr.prim.splice#2
doesn't list function parameters anywhere and so
http://eel.is/c++draft/expr.prim.splice#2.7 should apply.
Note, this is something that can't be tested in check_splice_expr,
because REFLECT_EXPR_KIND isn't propagated to it and whether some
reflection is a reflection of a function parameter or variable_of thereof
only differentiates in that kind, otherwise it is PARM_DECL in both
cases.  So, the following patch diagnoses it in splice function.
And for the case where using [:variable_of(e):] could make it valid
a message suggesting that is emitted too.
In mangle3.C I had to drop one test, it is now rejected and the
test tests mangling, so better shouldn't have errors in it.
For the dep14.C case, I've applied variable_of on it so that we get
the previous behavior.  And in func2 there it was actually (I think
mistakenly) asking for paramete of func rather than func2, fixed that too.

2026-04-17  Jakub Jelinek  <jakub@redhat.com>

PR c++/123783
* reflect.cc (splice): Reject splicing of function parameters.

* g++.dg/reflect/mangle3.C: Remove f5<parameters_of (^^g)[0]>()
case.
* g++.dg/reflect/dep14.C: Include <ranges>.
(func): Apply variable_of to each vector member.
(func2): Likewise.  Use ^^func2 instead of ^^func.
* g++.dg/reflect/splice12.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: constexpr call hashing and gc [PR124632]
Jason Merrill [Fri, 17 Apr 2026 02:41:24 +0000 (22:41 -0400)] 
c++: constexpr call hashing and gc [PR124632]

In cxx_eval_call_expression, we unshare an argument that goes into
constexpr_call::bindings so it's independent, and then if it's a CONSTRUCTOR
we unshare it again before putting it in the constexpr value hashtable so
any modifications within the function don't affect the bindings.  And then
we free these latter CONSTRUCTOR if they aren't part of the return value.

In explicit-obj-lambda2.C, cl5 is a recursive constexpr lambda that takes a
class (the closure) by value.  If -Wtautological-compare is enabled, we try
to constant-fold cl5(5) to see if has a constant value.  In evaluating the
outer call we have an empty CONSTRUCTOR argument {} that we unshare twice.

When we try to evaluate the recursive call, the second unshare from the
first call initially goes into bindings.  But since this is a recursive call
get_fundef_copy needs need to make a copy of the FUNCTION_DECL, and since
this evaluation is for a warning uid_sensitive_constexpr_evaluation_p is
true, so we can't make a copy, so evaluating the recursive copy fails
without ever unsharing the argument.

Then when we get back to finishing up the outer call we ggc_free the
unshared CONSTRUCTOR that we don't need anymore.  But the recursive call
already added it to the constexpr_call_table, so now the entry there is
referring to freed memory.

The solution is doing the first unshare immediately when we create the entry
in the constexpr_call_table, not later after get_fundef_copy.  This should
also mean less unsharing, as we now only do the first unshare when creating
the constexpr_call_table entry, not on subsequent evaluations.  This only
affects uncacheable calls, but that's a significant subset.

PR c++/124632

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_call_expression): Unshare bindings
sooner.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/explicit-obj-lambda2.C: Do strict GC and -Wall.

2 months agoDaily bump.
GCC Administrator [Fri, 17 Apr 2026 00:16:26 +0000 (00:16 +0000)] 
Daily bump.

2 months agoc++: Temporarily ignore -Wformat* warnings in dump_data_member_spec
Jakub Jelinek [Thu, 16 Apr 2026 17:13:48 +0000 (19:13 +0200)] 
c++: Temporarily ignore -Wformat* warnings in dump_data_member_spec

The body of this function has been moved from eval_display_string_of,
which ignored some warnings already.
The new function doesn't ignore those, we we get
../../gcc/cp/reflect.cc: In function ‘void dump_data_member_spec(pretty_printer*, tree)’:
../../gcc/cp/reflect.cc:3692:18: warning: ‘T’ conversion used unquoted [-Wformat=]
 3692 |   pp_printf (pp, "(%T, %E, %E, %E, %s, {", TREE_VEC_ELT (r, 0),
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~
../../gcc/cp/reflect.cc:3692:18: warning: spurious trailing punctuation sequence ‘{’ in format [-Wformat-diag]
../../gcc/cp/reflect.cc:3692:18: warning: unbalanced punctuation character ‘{’ in format [-Wformat-diag]
../../gcc/cp/reflect.cc:3699:18: warning: unbalanced punctuation character ‘}’ in format [-Wformat-diag]
 3699 |   pp_printf (pp, "})");
      |                  ^~~~
../../gcc/cp/reflect.cc:3699:18: warning: unbalanced punctuation character ‘)’ in format [-Wformat-diag]
extra warnings which can break bootstrap when promoted into errors.

2026-04-16  Jakub Jelinek  <jakub@redhat.com>

* reflect.cc (dump_data_member_spec): Temporarily ignore
-Wformat and -Wformat-diag warnings.

2 months agoarm: support +CDECP<n> options on cortex-m85
Richard Earnshaw [Thu, 16 Apr 2026 13:50:07 +0000 (14:50 +0100)] 
arm: support +CDECP<n> options on cortex-m85

The Cortex-m85 CPU supports the CDE extension, which requires use of the
+cdecp<n> CPU name modifiers.  This patch enables these options.  This is
all pretty-much boiler-plate since Srinath added support on Cortex-m55.

gcc/ChangeLog:

* config/arm/arm-cpus.in (cortex-m85): Allow +cdecp<n>.
* doc/invoke.texi: Document this

gcc/testsuite/ChangeLog:

* gcc.target/arm/multilib.exp: Test CDE options on cortex-m85.

2 months agoc++/reflection: detect bad splices in class member access [PR124614]
Marek Polacek [Wed, 15 Apr 2026 22:29:37 +0000 (18:29 -0400)] 
c++/reflection: detect bad splices in class member access [PR124614]

This testcase shows that we still don't detect some invalid splices
used in a class member access.  E.g. in,

  b.[:reflect_constant (^^B::id):];

the splice designates a reflection which cannot be used in obj.[:R:].
We can enhance check_splice_expr to check for exactly those codes
that can be handled.  This is also an opportunity to finally factor
our the long splice_p checks into a helper.

It can also be something like

  b.[:reflect_constant (data_member_spec (^^int, { .name = "i" })):];

where we don't correctly print the RHS, thus the dump_data_member_spec
addition.

PR c++/124614

gcc/cp/ChangeLog:

* cp-tree.h (valid_splice_for_member_access_p): Declare.
(dump_data_member_spec): Declare.
* error.cc (dump_expr) <case REFLECT_EXPR>: Print a data member
description.
* parser.cc (cp_parser_splice_expression): Use
valid_splice_for_member_access_p.
* pt.cc (tsubst_splice_expr): Likewise.
* reflect.cc (dump_data_member_spec): New.
(eval_display_string_of): Use it.
(valid_splice_for_member_access_p): New.
(check_splice_expr): Check that we got
valid_splice_for_member_access_p for a member access.
* typeck.cc (finish_class_member_access_expr): Use
valid_splice_for_member_access_p.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/member23.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: Fix up expansion-stmt mangling ICE [PR124120]
Jakub Jelinek [Thu, 16 Apr 2026 13:51:04 +0000 (15:51 +0200)] 
c++: Fix up expansion-stmt mangling ICE [PR124120]

One of the reflect/* tests ICEs on Solaris but not on Linux (at least not
when using recent glibc).
I've tracked it down to a problem with expansion statements, due to the
workaround we have for missing part of P2686R4 where we make some artificial
vars static.  Some of them (the __for_range and __for_begin) have DECL_NAMEs
(with a space in it) and so even when they are static, don't cause problems.
But the iter variable (in https://eel.is/c++draft/stmt.expand#5.2 ) is when
constexpr still static and was nameless.
Now, because it is constexpr and not odr used, it is optimized out, but if
the TU also contains weakref attribute or something else that requires
cgraph to construct assembler_name_hash, we ICE when trying to mangle
the iter nameless variable.

The following patch fixes that by giving it yet another artificial name.

2026-04-16  Jakub Jelinek  <jakub@redhat.com>

PR c++/124120
* pt.cc (finish_expansion_stmt): Give iter variable an artificial
name.

* g++.dg/cpp26/expansion-stmt40.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agostormy16, xtensa: Set TREE_PUBLIC on TYPE_NAME of __va_list_tag [PR124565]
Jakub Jelinek [Thu, 16 Apr 2026 13:19:23 +0000 (15:19 +0200)] 
stormy16, xtensa: Set TREE_PUBLIC on TYPE_NAME of __va_list_tag [PR124565]

Apparently stormy16 and xtensa suffer from the same problem as alpha and
sh, in particular that
 module;
 #include <cstdarg>
 export module pr124565;
 export namespace std {
   using std::va_list;
 }
fails to compile with -fmodules.

Fix is the same as for alpha/sh.

2026-04-16  Jakub Jelinek  <jakub@redhat.com>

PR target/124565
* config/stormy16/stormy16.cc (xstormy16_build_builtin_va_list): Set
TREE_PUBLIC on type_decl.
* config/xtensa/xtensa.cc (xtensa_build_builtin_va_list): Likewise.

2 months agoFortran: Fix dependencies in elemental subroutine calls [PR120140]
Paul Thomas [Thu, 16 Apr 2026 13:09:49 +0000 (14:09 +0100)] 
Fortran:  Fix dependencies in elemental subroutine calls [PR120140]

2026-04-16  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/120140
* resolve.cc (resolve_elemental_dependencies): New function,
preceded by prototype for add_temp_assign_before_call.
(resolve_call): If an elemental subroutine call has at least
two actual erguments, call resolve_elemental_dependencies to
generate temporary expressions for the arguments if required.
(get_temp_from_expr): Add optional boolean argument, which if
set, makes the resulting temporary unconditionally allocatable.
(add_temp_assign_before_call): New function.

gcc/testsuite/
PR fortran/123352
* gfortran.dg/defined_assignment_13.f90: Add previously failing
tests.

2 months agogcn: doc/install.texi - fix by-default required LLVM version [PR124897]
Tobias Burnus [Thu, 16 Apr 2026 10:47:57 +0000 (12:47 +0200)] 
gcn: doc/install.texi - fix by-default required LLVM version [PR124897]

The default multilib requires the linker + assembler of LLVM 20 not 19.
While LLVM 19 supports gfx942 and generic archs, it does not yet support
gfx9-4-generic.

gcc/ChangeLog:

PR target/124897
* doc/install.texi (amdgcn-amdhsa): Fix required LLVM version for
default multilib.

2 months agolibstdc++: Export explicit instantiations of __format::__do_vformat_to.
Tomasz Kamiński [Fri, 3 Apr 2026 11:39:20 +0000 (13:39 +0200)] 
libstdc++: Export explicit instantiations of __format::__do_vformat_to.

This patch extracts a __format::__do_vformat_to for the _Sink_iter
(and matching format context) and exports explicit instantiations
of it for char and wchar_t. As every format function is implementing
as delegating to one of these overloads, this significantly reduces
the compilation time.

Instantiating __format::__do_vformat_to triggers specializations of
formatters for types stored in basic_format_arg directly (arithmetic
types, strings). In case when their behavior depends on the TU specific
configuration, only one configuration can be exported from shared
lib. In case of beforementioned formatters:
* ? (debug mode) is accepted in for strings and characters
* multibyte utf-8 encoded character is accepted as fill when the
  literal encoding is Unicode.

The first issue is addressed by this patch, by declaring extern
definition only for the C++20. We will need to reconsider how to
handle the specifiers when C++23 becomes stable.

The literal encoding is handled by adding a second template parameter
to __do_vformat_to overload, that is initialized with 1 if literal
encoding is Unicode (the parameter has unsigned type to allow more
information to be encoded). This allows library to export implementation
for Unicode literal encoding (format-inst.cc is compiled with appropriate
flag), by declaring extern specialization only for value 1.

libstdc++-v3/ChangeLog:

* config/abi/pre/gnu.ver (GLIBCXX_3.4): Exclude exports
of std::basic_fo* (matching basic_format_context).
(GLIBCXX_3.4.35): Export __format::__do_vformat_to
specializations for _Sink_iter and char/wchar_t.
* include/std/format: (__format::__do_vformat_to):
Extract overload accepting _Sink_iter and provide extern
explicit specialization for char/wchar_t in C++20 mode.
* src/c++20/Makefile.am: Add format-inst.cc.
* src/c++20/Makefile.in: Regenerate.
* src/c++20/format-inst.cc: New file defining explicit
instantiation.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoanalyzer: do not segfault when printing unknown impl location
Torbjörn SVENSSON [Wed, 15 Apr 2026 14:20:03 +0000 (16:20 +0200)] 
analyzer: do not segfault when printing unknown impl location

When dump_impl_location_t::m_function or dump_impl_location_t::m_file is NULL,
then GCC segfaults when attempting to print the location.

$ ./bin/arm-none-eabi-gcc ../ice-pr124055-1.c -fanalyzer -Wanalyzer-too-complex -Wanalyzer-symbol-too-complex -O -fdump-analyzer -frounding-math -S -o /dev/null -wrapper lldb,--
(lldb) target create "/build/r16-8473-g5cc0ead3625fe6/bin/../lib/gcc/arm-none-eabi/16.0.1/cc1"
...
(lldb) r
Process 31748 launched: '/build/r16-8473-g5cc0ead3625fe6/lib/gcc/arm-none-eabi/16.0.1/cc1' (arm64)
Process 31748 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x000000018ae7ea44 libsystem_platform.dylib`_platform_strlen + 4
libsystem_platform.dylib`_platform_strlen:
->  0x18ae7ea44 <+4>:  ldr    q0, [x1]
    0x18ae7ea48 <+8>:  adr    x3, 0x18ae7e980 ; ___lldb_unnamed_symbol320
    0x18ae7ea4c <+12>: ldr    q2, [x3], #0x10
    0x18ae7ea50 <+16>: and    x2, x0, #0xf
Target 0: (cc1) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x000000018ae7ea44 libsystem_platform.dylib`_platform_strlen + 4
    frame #1: 0x0000000101223d68 cc1`pp_quoted_string(pretty_printer*, char const*, unsigned long) + 244
    frame #2: 0x0000000101220628 cc1`pretty_printer::format(text_info&) + 2772
    frame #3: 0x0000000101108b8c cc1`ana::logger::log_va(char const*, char**) + 100
    frame #4: 0x0000000101108970 cc1`ana::logger::log(char const*, ...) + 28
    frame #5: 0x0000000101129da4 cc1`ana::impl_region_model_context::on_unexpected_tree_code(tree_node*, dump_location_t const&) + 80
    frame #6: 0x0000000101174d3c cc1`ana::region_model_manager::get_region_for_unexpected_tree_code(ana::region_model_context*, tree_node*, dump_location_t const&) + 184
...

This happens when GCC is built with GCC <4.8 or with another toolchain,
like LLVM. Seen on macOS with clang-1600.0.26.6.

gcc/analyzer/ChangeLog:

* engine.cc (impl_region_model_context::on_unexpected_tree_code): Print
"<unknown>" when m_file or m_function is NULL.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2 months agoi386/testsuite: Fix pr90178.c test failure for 32-bit targets
Uros Bizjak [Thu, 16 Apr 2026 07:52:48 +0000 (09:52 +0200)] 
i386/testsuite: Fix pr90178.c test failure for 32-bit targets

The testcase counts occurrences of `xorl %eax, %eax` to detect whether
there is only one terminal basic block.  This approach is brittle because
it depends on register allocation decisions, which differ between targets.

On x86_64, IRA creates the following sequence:

   11: NOTE_INSN_BASIC_BLOCK 3
    6: ax:DI=0
      REG_EQUAL 0
   48: pc=L38
   ...
   38: L38:
   41: NOTE_INSN_BASIC_BLOCK 8
   40: use ax:DI

This sequence is reordered in bbro pass to:

   30: L30:
   11: NOTE_INSN_BASIC_BLOCK 7
   63: {ax:DI=0;clobber flags:CC;}
      REG_UNUSED flags:CC
   60: use ax:DI
   48: simple_return

On x86_32, IRA zeroes %ecx, which is later copied to %eax in
the terminal basic block:

   12: NOTE_INSN_BASIC_BLOCK 3
    7: cx:SI=0
      REG_EQUAL 0
   45: pc=L36
   ...
   36: L36:
   39: NOTE_INSN_BASIC_BLOCK 7
   37: ax:SI=cx:SI
   38: use ax:SI

This sequence is reordered in bbro pass to:

   28: L28:
   12: NOTE_INSN_BASIC_BLOCK 7
   69: {cx:SI=0;clobber flags:CC;}
      REG_UNUSED flags:CC
   71: ax:SI=cx:SI
      REG_DEAD cx:SI
   72: use ax:SI
   73: NOTE_INSN_EPILOGUE_BEG
   74: bx:SI=[sp:SI++]
      REG_CFA_ADJUST_CFA sp:SI=sp:SI+0x4
      REG_CFA_RESTORE bx:SI
   75: si:SI=[sp:SI++]
      REG_CFA_ADJUST_CFA sp:SI=sp:SI+0x4
      REG_CFA_RESTORE si:SI
   76: simple_return

After the bbro pass, zero is not propagated from %ecx to %eax, so the final
assembly does not contain `xorl %eax, %eax`:

.L5:
        xorl    %ecx, %ecx
        ...
        movl    %ecx, %eax
        ret

The test uses `xorl %eax, %eax` as a proxy for detecting multiple terminal
basic blocks, which is brittle because it depends on register allocation.
Instead, simply count `ret` instructions, which directly reflects the
number of terminal basic blocks and does not depend on register allocation.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr90178.c: Scan for 2 `ret` instructions.

2 months agomiddle-end/124877 - fix mis-apply of PROMOTE_PROTOTYPES
Richard Biener [Tue, 14 Apr 2026 11:16:01 +0000 (13:16 +0200)] 
middle-end/124877 - fix mis-apply of PROMOTE_PROTOTYPES

The following corrects how we apply PROMOTE_PROTOTYPES during RTL
expansion.  The unsignedp field in args info is supposed to
denote the signedness of the unpromoted value, but we've set it
to the signedness of integer_type_node.  So delay adjusting the
type until after we compute signedness of the formal argument.
This was originally changed for GCC16 with r16-169-g78db4753c9646a
and r16-170-ga670ebde399548.

The patch makes PROMOTE_PROTOTYPES newly affect transparent union
passing, promoting a smaller than int first element, which we
did not in GCC 15.  gcc.target/i386/pr124877-2.c has a testcase
showing the effect nicely.

Overall this restores behavior to that of GCC 15 before we
moved PROMOTE_PROTOTYPES application from frontends to RTL
expansion, but GCC 15 did not apply promotion to the transparent
union case.

PR middle-end/124877
* calls.cc (initialize_argument_information): Compute
signedness of the formal argument type before applying
PROMOTE_PROTOTYPES promotion.  Also apply promotion to
a smaller than int integer first member type of a
transparent union.
* target.def (promote_prototypes): Update documentation.
* doc/tm.texi: Re-generate.

* gcc.target/i386/pr124877-1.c: New testcase.
* gcc.target/i386/pr124877-2.c: Likewise.
* gcc.target/i386/pr124877-3.c: Likewise.

2 months agoi386: Fix up TARGET_AVOID_FALSE_DEP_FOR_BMI APX NF splitters [PR124892]
Jakub Jelinek [Thu, 16 Apr 2026 08:03:21 +0000 (10:03 +0200)] 
i386: Fix up TARGET_AVOID_FALSE_DEP_FOR_BMI APX NF splitters [PR124892]

The following testcase is miscompiled because the 3
TARGET_AVOID_FALSE_DEP_FOR_BMI APX NF splitters use ix86_expand_clear.
All other uses of ix86_expand_clear are on either splitters where we know
something clobbers flags register or sets it at the end of pattern (so
clearly flags register is not live across the pattern) or in
define_peephole2 where we explicitly check peep2_regno_dead_p (?, FLAGS_REG).
Now, ix86_expand_clear handles right the QI/HImode cases by setting SImode
instead and based on TARGET_USE_MOV0 and/or optimize_insn_for_size_p
decides whether to use xor reg, reg form or mov $0, reg.
Now, for these 3 APX NF splitters there is actually no flags clobber nor set
in the pattern and because it is a splitter, we don't know if flags register
is live across it (likely yes, otherwise why the APX NF pattern would be
used) or not.  So, we can't use ix86_expand_clear which could clobber flags.
As the splitters are only SWI48, we don't have to worry about QI/HImode
clearing and so IMHO just want to always use the mov $0, reg form by hand.
If flags actually isn't live across it, we have
;; Attempt to always use XOR for zeroing registers (including FP modes).
(define_peephole2
  [(set (match_operand 0 "general_reg_operand")
        (match_operand 1 "const0_operand"))]
  "GET_MODE_SIZE (GET_MODE (operands[0])) <= UNITS_PER_WORD
   && (! TARGET_USE_MOV0 || optimize_insn_for_size_p ())
   && peep2_regno_dead_p (0, FLAGS_REG)"
  [(parallel [(set (match_dup 0) (const_int 0))
              (clobber (reg:CC FLAGS_REG))])]
  "operands[0] = gen_lowpart (word_mode, operands[0]);")
peephole2 which would turn the mov $0, reg back to xor reg, reg.

2026-04-16  Jakub Jelinek  <jakub@redhat.com>

PR target/124892
* config/i386/i386.md (clz<mode>2_lzcnt_nf,
<lt_zcnt>_<mode>_nf, popcount<mode>2_nf): Emit explicit
set of (match_dup 0) to (const_int 0) without flags clobber instead of
using ix86_expand_clear.

* gcc.target/i386/apx-pr124892.c: New test.

Reviewed-by: Hongtao Liu <crazylht@gmail.com>
2 months agotree-ssa-propagate: Call update_stmt before folding [PR124891]
Jakub Jelinek [Thu, 16 Apr 2026 08:02:16 +0000 (10:02 +0200)] 
tree-ssa-propagate: Call update_stmt before folding [PR124891]

The following testcase ICEs, because we
      did_replace |= substitute_and_fold_engine->replace_uses_in (stmt);
and replace some SSA_NAME with INTEGER_CST and without update_stmt
call fold_stmt.  Now fold_stmt ends up asking ranger about something end
ICEs because it attempts to walk SSA_USE_OPs on that stmt and because
we haven't updated the stmt, walks even the INTEGER_CST among ssa uses
and checking ICEs because it attempts to test SSA_NAME flags on the
INTEGER_CST.

The following patch fixes it by calling update_stmt before folding in that
case, it is called again after folding just in case it is folded.

2026-04-16  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/124891
* tree-ssa-propagate.cc
(substitute_and_fold_dom_walker::before_dom_children): Call update_stmt
in the did_replace case before calling fold_stmt.

* gcc.dg/torture/pr124891.c: New test.

Reviewed-by: Richard Biener <rguenth@suse.de>
2 months agotestsuite: aarch64: ensure INT*_MIN macro definitions for C++ acle asm
Alexandre Oliva [Thu, 16 Apr 2026 04:06:19 +0000 (01:06 -0300)] 
testsuite: aarch64: ensure INT*_MIN macro definitions for C++ acle asm

VxWorks' libc doesn't define __STDC_LIMIT_MACROS when compiling C++98,
and then GCC's stdint.h doesn't define INT<N>_MIN, that a number of
acle asm testcases expect.  If the macro is not defined, define the
macro in the header first included by all the affected tests, namely,
{div_s{32,64},mul_s{16,32,64,8}}.c.

for  gcc/testsuite/ChangeLog

* gcc.target/aarch64/sve/acle/asm/test_sve_acle.h
(__STDC_LIMIT_MACROS): Define.

2 months agoc++: fix constexpr union with empty member [PR123346]
Egas Ribeiro [Thu, 1 Jan 2026 03:41:14 +0000 (03:41 +0000)] 
c++: fix constexpr union with empty member [PR123346]

r14-2820 changed cxx_eval_bare_aggregate to set no_slot based on whether
new_ctx.ctor is NULL_TREE, to handle empty subobject elision. However
this incorrectly omits entries for empty union members, which later need
the entry to exist.
This caused valid code to be rejected as non-constant after gcc 13.3,
and in trunk caused an ICE when the diagnostic code tries to print a
CONSTRUCTOR with a null value.

PR c++/123346

gcc/cp/ChangeLog:

* constexpr.cc (init_subob_ctx): Do initialize new_ctx.ctor
for an empty union member.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constexpr-union10.C: New test.

Signed-off-by: Egas Ribeiro <egas.g.ribeiro@gmail.com>
Co-authored-by: Jason Merrill <jason@redhat.com>
2 months agoc++, contracts: implicit capture in lambda contract [PR124648]
Iain Sandoe [Wed, 8 Apr 2026 09:47:16 +0000 (15:17 +0530)] 
c++, contracts: implicit capture in lambda contract [PR124648]

We were currently accepting invalid code by allowing contract assertions
to trigger implicit lambda captures contrary to:
[expr.prim.lambda.closure] / p10.

The solution here is to mark captures that occur within contract
assertion scopes and then clear that mark if we then see a normal
capture for the same entity - we must defer the error handling since
the following is valid:

  auto f5 = [=] {
    contract_assert (i > 0); // OK, i is referenced elsewhere.
    return i;
  };

PR c++/124648

gcc/cp/ChangeLog:

* cp-tree.h (DECL_CONTRACT_CAPTURE_P): New.
* parser.cc (cp_parser_lambda_body): Scan the captures for
ones were only added in contract assertion scopes.  Issue
errors for those found.
* semantics.cc (process_outer_var_ref): Mark implicit
captures that occur in contract assertion scopes.  Clear
the mark if the entity is subsequently captured 'normally'.
(set_contract_capture_flag): New.

gcc/testsuite/ChangeLog:

* g++.dg/contracts/cpp26/expr.prim.lambda.closure.p10.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
Co-authored-by: Jason Merrill <jason@redhat.com>
2 months agoc++, contracts: omit unnecessary const-wrappers
Iain Sandoe [Wed, 8 Apr 2026 09:37:28 +0000 (15:07 +0530)] 
c++, contracts: omit unnecessary const-wrappers

We need to view class pointers as const, which we do by wrapping
them in a view convert expression.  However, we do not need to do
this if the original is already const-qualified.

gcc/cp/ChangeLog:

* contracts.cc (view_as_const): Check for const-qualified
class pointer before wrapping it.
* parser.cc (cp_parser_late_contract_condition): Use revised
handling of const-ification of class pointers.
(cp_parser_contract_assert): Likewise.
(cp_parser_function_contract_specifier): Likewise.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
Co-authored-by: Jason Merrill <jason@redhat.com>
2 months agoDaily bump.
GCC Administrator [Thu, 16 Apr 2026 00:16:26 +0000 (00:16 +0000)] 
Daily bump.

2 months agoc++: ICE with deleted main [PR120338]
Marek Polacek [Wed, 15 Apr 2026 18:15:06 +0000 (14:15 -0400)] 
c++: ICE with deleted main [PR120338]

Here we ICE with deleted main which is later redefined at

  gcc_assert (DECL_SAVED_TREE (fn));

because for some reason when deleting main I chose NULL_TREE instead of
error_mark_node as its DECL_INITIAL.  For other deleted functions we
also use error_mark_node so that

  void foo() = delete;
  void foo() {}

results in the "redefinition of" error.  Let's do the same for main, then.

PR c++/120338

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Set DECL_INITIAL to error_mark_node
instead of NULL_TREE for deleted main.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/deleted19.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agotestsuite: Change -encoding binary to -translation binary
Jakub Jelinek [Wed, 15 Apr 2026 19:29:35 +0000 (21:29 +0200)] 
testsuite: Change -encoding binary to -translation binary

tcl 9 errors on -encoding binary and suggests using -translation binary
instead, which has been supported even in older tcl versions.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

* go.test/go-test.exp (errchk): Use -translation binary instead of
-encoding binary for TCL 9 compatibility.

Reviewed-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 months agoAda: Fix bogus warning for array variable on the LHS of aggregate assignment
Eric Botcazou [Wed, 15 Apr 2026 17:37:54 +0000 (19:37 +0200)] 
Ada: Fix bogus warning for array variable on the LHS of aggregate assignment

That's another ancient issue with -gnatwu, but the fix is again trivial.

gcc/ada/
PR ada/105212
* exp_aggr.adb (Build_Array_Aggr_Code): If the aggregate comes from
source, call Set_Referenced_Modified on the target.

gcc/testsuite/
* gnat.dg/warn36.adb: New test.

2 months agoAda: Fix bogus warning for character literal referenced in string literal
Eric Botcazou [Wed, 15 Apr 2026 17:31:14 +0000 (19:31 +0200)] 
Ada: Fix bogus warning for character literal referenced in string literal

That's an ancient issue with -gnatwu, but the fix is again trivial.

gcc/ada/
PR ada/87170
* sem_res.adb (Resolve_String_Literal): Copy Comes_From_Source from
the string literal to the character literals.

gcc/testsuite/
* gnat.dg/warn35.adb: New test.

2 months agoPR modula2/124081 Bugfix ICE in expand_expr_real_2 with a record
Gaius Mulley [Wed, 15 Apr 2026 17:34:23 +0000 (18:34 +0100)] 
PR modula2/124081 Bugfix ICE in expand_expr_real_2 with a record

This patch fixes an ICE which occurs when attempting to create a
set using a subrange from a record field.  The fix ensures that the
record field is copied to a temporary prior to the set construction.

gcc/m2/ChangeLog:

PR modula2/124081
* gm2-compiler/M2Quads.mod (SafeCheckWithField): New procedure.
(BuildInclRange): Reimplement.
(AddFieldTo): Ditto.
(BuildComponentValue): Ditto.

gcc/testsuite/ChangeLog:

PR modula2/124081
* gm2/iso/run/pass/setcons.mod: New test.
* gm2/iso/run/pass/setcons2.mod: New test.
* gm2/iso/run/pass/setcons3.mod: New test.
* gm2/iso/run/pass/setcons4.mod: New test.
* gm2/iso/run/pass/setcons5.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 months agoc++/reflection: generic lambda with dependent splice [PR123783]
Marek Polacek [Wed, 15 Apr 2026 14:52:29 +0000 (10:52 -0400)] 
c++/reflection: generic lambda with dependent splice [PR123783]

For a generic lambda, we normally collect the captures while parsing
the lambda: finish_id_expression calls process_outer_var_ref which does
add_capture.  Then when instantiating, we'll find the capture via
retrieve_local_specialization.  Once the closure type has been
finalized, it's frozen and we can't add new fields.  This is what
happens in the following test though, which is the reason we crash:

  [&]<auto> {
    [:e:];
  }

where while parsing we can't know what the splice will designate.
We'll only find out after we've substituted the splice but then it's
too late to capture anything.

A possible solution would be to speculatively capture all locals when
we see a dependent splice in a generic lambda.  But since this test is
invalid anyway, that would be a lot of work for no good reason.  So this
patch changes the internal_error to an ordinary error.

PR c++/123783

gcc/cp/ChangeLog:

* lambda.cc (add_capture): When trying to capture something in
an instantiation of generic lambda, give an error instead of an ICE.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/dep14.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
2 months agolibstdc++: Fix philox_engine counter increment carry
Elena Tyuleneva [Wed, 15 Apr 2026 14:54:51 +0000 (15:54 +0100)] 
libstdc++: Fix philox_engine counter increment carry

The philox counter increment that happens in
philox_engine::_M_transition(), applies +1 to _M_x[0] before the bitwise
OR with (_M_x[1] << __w), so the carry from _M_x[0] is merged into the
_M_x[1] portion rather than being added to it. This causes the counter
to cycle prematurely and never advance past {0, 0, 1, 2^w - 1}.

Fix by changing operations order, which results in forming the
full-width value from _M_x[1]:_M_x[0] and then adding 1 on both the n ==
4 and n == 2 paths.

libstdc++-v3/ChangeLog:

* include/bits/random.tcc (philox_engine::_M_transtiion): Fix
counter increment to propagate carry correctly.
* testsuite/26_numerics/random/philox_engine/operators/counter_carry.cc:
New test.

Signed-off-by: Elena Tyuleneva <elena.tyuleneva@intel.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
2 months agolibstdc++: Fix philox2x64 case for 32-bit targets
Jonathan Wakely [Wed, 15 Apr 2026 16:37:29 +0000 (17:37 +0100)] 
libstdc++: Fix philox2x64 case for 32-bit targets

While testing a patch for std::philox_engine I noticed that
instantiating std::philox_engine with n=2 and w=64 fails on targets
without __int128, because it relies on an implicit conversion from the
intermediate counter type to the result type. When w=64 and the target
doesn't support __int128, we use the __rand_uint128 class type for the
intermediate counter values, but that does not support implicit
conversion to integral types.

This adds the necessary casts to make the conversions explicit.

libstdc++-v3/ChangeLog:

* include/bits/random.tcc (philox_engine::_M_transition): Cast
intermediate values to result_type for n=2 case.

2 months agosra: Dont use build_reconstructed_reference on MEM_REFs changin types (PR122976)
Martin Jambor [Wed, 15 Apr 2026 16:28:32 +0000 (18:28 +0200)] 
sra: Dont use build_reconstructed_reference on MEM_REFs changin types (PR122976)

PR122976 is basically a variant of PR105860 but instead of a union
there is a MEM_REF with a different type from the underlying DECL it
accesses.  Like in the other bug, this confuses
build_reconstructed_reference which then finds wrong compatible base
and proceeds to identify a bogus FIELD_DECL to assign to a new access,
leading to memory accesses to a wrong place.  This is caught by the
internal verifier when checking but unfortunately leads to
miscompilation without it.  The patch fixes this by clearing
grp_same_access_path of such accesses so that
build_reconstructed_reference is not used at all for them.

The original testcase no longer exhibits the bug on master since
r16-3201-gee67004474d521 (Andrew Pinski: forwprop: Copy prop
aggregates into args) but it turns out that my artificial one still
triggers.

If you want more details on what is going on, here they are, the issue
involves two VAR_DECLs:

struct tySequence__6H5Oh5UUvVCLiakt9aTwtUQ ISRA.487D.19501;
struct tyObject_Rlp__dNpAlq42D2iOFkwuW8WMyQ nextRef_1D.19109;

where the types are (NI is int64_t):

  struct tySequence__6H5Oh5UUvVCLiakt9aTwtUQ {
    NI len; tySequence__6H5Oh5UUvVCLiakt9aTwtUQ_Content* p;
  };

  struct tyObject_Rlp__dNpAlq42D2iOFkwuW8WMyQ {
   tySequence__6H5Oh5UUvVCLiakt9aTwtUQ bytes;
   NI position;
  };

And an assignment between them:

  ISRA.487D.19501 = MEM[(struct tySequence__6H5Oh5UUvVCLiakt9aTwtUQ *)&nextRef_1D.19109];

which triggers code that tries to create accesses for LHS
corresponding to those collected for nextRef_1.  Unfortunately the one
for offset 64 was created from access:

  MEM[(struct tyTuple__hnCuDR9cLe2lA3YIkwKIyuA *)&nextRef_1D.19109].Field1D.6487.lenD.5644 = 0;

which brings a third type into the mix:

  struct tyTuple__hnCuDR9cLe2lA3YIkwKIyuA {
   NI Field0;
   tySequence__6H5Oh5UUvVCLiakt9aTwtUQ Field1;
  };

which is setting the len field after the type-cast but in terms of the
underlying type of the DECL, it is actually setting the pointer field.

Because SRA looks at the accesses rather than the types, it also means
that the access for the pointer was represented by a signed 64bit
integer and the stored expression was the above, two COMPONENT_REFs
bolted on top of the type changing MEM_REF.  The access also got the
grp_same_access_path flag set, meaning we'd try to preserve the
"access path," the chain of handled_references in many contexts such
as propagating the accesses across assignments.

And there things went wrong, build_reconstructed_reference found the
MEM_REF, realized it was compatible with the base DECL and happily
assumed that means that whatever was used on top of the MEM_REF can be
used on top of the DECL to access the corresponding bit of memory.

The wrong bit was not clearing grp_same_access_path, which we for
example cleared when the MEM_REF had a non-zero offset and so this
patch detects the situation and clears it.

gcc/ChangeLog:

2026-03-15  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/122976
* tree-sra.cc (path_comparable_for_same_access): Return false if the
base is a MEM_REF with a different underlying type.

gcc/testsuite/ChangeLog:

2026-03-18  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/122976
* gcc.dg/tree-ssa/pr122976.c: New test.

2 months agoc++: reference to static local meta::info as targ [PR124824]
Patrick Palka [Tue, 14 Apr 2026 19:36:54 +0000 (15:36 -0400)] 
c++: reference to static local meta::info as targ [PR124824]

Here we're crashing in discriminator_for_local_entity during mangling
of f<&M>() because determine_local_discriminator is never called for
the static local meta::info M.  The relevant code path in cp_finish_decl
was disabled for consteval-only types in the main Reflection commit
r16-6808 to avoid creating a varpool_node for such types.

This patch naively fixes this by moving the consteval_only_p check so
that we still call determine_local_discriminator for such types.

PR c++/124824

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Sink !consteval_only_p check to
only guard the varpool_node::get_create call.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/mangle6.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: Fix up constexpr EH handling of TARGET_EXPR temporaries [PR124755]
Jakub Jelinek [Wed, 15 Apr 2026 15:28:53 +0000 (17:28 +0200)] 
c++: Fix up constexpr EH handling of TARGET_EXPR temporaries [PR124755]

The following testcase is incorrectly rejected with spurious error about
<anonymous> used outside of its lifetime.
We constant evaluate
    <<cleanup_point <<< Unknown tree: expr_stmt
      (void) (n = TARGET_EXPR <D.2693, foo (m)>, n + D.2693) >>>>>;
in a loop, D.2693 is integral TARGET_EXPR_SLOT and foo throws in the second
or later iteration.  Because D.2693 is not is_complex nor has
aggregate/vector type, we don't ctx->global->put_value (slot, something)
until the TARGET_EXPR_INITIAL evaluation successfully finishes, at which
point we ctx->save_exprs->safe_push (slot); and
ctx->global->put_value (slot, r); Because of the save_exprs push, the
CLEANUP_POINT_EXPR handling then
        /* Forget SAVE_EXPRs and TARGET_EXPRs created by this
           full-expression.  */
        for (tree save_expr : save_exprs)
          destroy_value_checked (ctx, save_expr, non_constant_p);
and that ctx->global->put_value (slot, void_node); (i.e. marks it out of
lifetime).  In the second iteration, we again don't call put_value on the
slot early, notice TARGET_EXPR_INITIAL evaluation throws, still
ctx->save_exprs->safe_push (slot); but then return.  That means
the remembered value is still void_node and so destroy_value_checked
complains.

The following patch fixes that by calling put_value in the case where
we know we haven't changed it yet (i.e. it is not is_complex and it doesn't
have aggregate/vector type), so that destroy_value_checked doesn't complain.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

PR c++/124755
* constexpr.cc (cxx_eval_constant_expression): If TARGET_EXPR_INITIAL
throws and !is_complex and type is neither aggregate nor vector,
call ctx->global->put_value (slot, NULL) before returning.

* g++.dg/cpp26/constexpr-eh19.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agobitintlower: Padding bit fixes, part 1 [PR123635]
Jakub Jelinek [Wed, 15 Apr 2026 15:21:06 +0000 (17:21 +0200)] 
bitintlower: Padding bit fixes, part 1 [PR123635]

x86_64/ia32/aarch64 say padding bits of _BitInt values have unspecified
values, and until GCC 16 those were the only supported _BitInt targets.
In GCC 16, we've added _BitInt support for some further arches,
loongarch, riscv, s390x and arm and all of them chose to specify the
padding bits (require zero or sign extension depending on whether the
type is signed or unsigned).
s390x is big-endian, on the other side has abi_limb_mode the same as
limb_mode, so the extension is always just within the same limb.
loongarch chose to require weird extension, only within the same limb
but not abi limb, so the current extensions are also mostly ok.
riscv and arm both use abi_limb_mode larger than limb_)mode and require
extension, which means that say for _BitInt(513) one needs to sign extend
not just within the limb corresponding to bit 512 (32-bit on arm, 64-bit
on loongarch), but within the whole abi limb (64-bit on arm, 128-bit on
loongarch), which means when working with the usual limbs we need to
extend another whole 32-bit or 64-bit limb above the one we'd normally
extend.

The following patch tweaks the bitint_info, so that it differentiates
between the different extension possibilities (x86_64/ia32/aarch64
bitint_ext_undef, loongarch bitint_ext_partial, arm/riscv bitint_ext_full,
s390x doesn't really matter if bitint_ext_partial or bitint_ext_full, but
chose to document bitint_ext_full and in gimple-lower-bitint.cc treat it
as bitint_ext_partial).
And then for a subset of lowerings handle it even for the
bitint_extended == bitint_ext_full cases.
In particular, this patch handles the mergeable stmts (like +/- and many
others which walk from least significant limb to most significant limb
and can handle 2 limbs in a loop), including the separate_ext extension
(where a mergeable operation is then extended to much wider _BitInt,
handled by handling normally the mergeable operation, remembering if
we should zero or sign extend (and whether to 0 or -1) and then in a
separate loop or straight line code store the 0s or -1s), division/modulo
(these are done by forcing larger prec on the output, modulo result
should never be larger than the first operand and same sign, division
of negative minimum by -1 is UB and otherwise also should be never larger
than first operand), signed multiplication (again, done by extending
prec because signed multiplication overflow is UB), unsigned multiplication
(this one can't be handled that way because unsigned mult overflow wraps,
so we need to pass exact lhs prec, so the code stores zero limb when
needed), and conversions from floating point (binary or decimal) to _BitInt
(signed or unsigned), those again are supposed to store minimum or maximum
value on overflow and so lhs prec needs to be maintained, so the code
for unsigned result clears one limb when needed or for signed result
right shifts the second most significant limb by limb prec - 1 and stores
that into most significant limb.

Note, <<, >>, add/sub overflow and mul overflow at least aren't done in
this patch, to be resolved incrementally.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/123635
* target.h (enum bitint_ext): New.
(struct bitint_info): Change extend type from bool to enum bitint_ext
and document it.
* gimple-lower-bitint.cc (bitint_extended): Change type from bool
to enum bitint_ext.
(bitint_precision_kind): Change bitint_extended to bitint_ext_partial
from bitint_ext_full if limb_mode is the same as abi_limb_mode.
(bitint_large_huge::limb_access_type): For
bitint_extended == bitint_ext_full allow access to the most
significant limb solely with padding bits if present.
(bitint_large_huge::lower_mergeable_stmt): Handle
bitint_extended == bitint_ext_full extension if needed.
(bitint_large_huge::lower_muldiv_stmt): Likewise.
(bitint_large_huge::lower_float_conv_stmt): Likewise.
* config/aarch64/aarch64.cc (aarch64_bitint_type_info): Set
info->extended to bitint_ext_undef rather than false.
* config/arm/arm.cc (arm_bitint_type_info): Set
info->extended to bitint_ext_full rather than true.
* config/i386/i386.cc (ix86_bitint_type_info): Set
info->extended to bitint_ext_undef rather than false.
* config/loongarch/loongarch.cc (loongarch_bitint_type_info): Set
info->extended to bitint_ext_partial rather than true.
* config/riscv/riscv.cc (riscv_bitint_type_info): Set
info->extended to bitint_ext_full rather than true.
* config/s390/s390.cc (s390_bitint_type_info): Likewise.

* gcc.dg/bitintext.h: Handle __riscv__ like __arm__.
* gcc.dg/torture/bitint-86.c: New test.
* gcc.dg/torture/bitint-87.c: New test.

Reviewed-by: Richard Biener <rguenth@suse.de>
2 months agoc++: mangling of extern "C" in anon ns [PR117133]
Jason Merrill [Tue, 14 Apr 2026 17:49:52 +0000 (13:49 -0400)] 
c++: mangling of extern "C" in anon ns [PR117133]

r15-3910 updated decl_linkage to return 'internal' for extern "C"
declarations in an anonymous namespace, as specified by C++11. This
unintentionally changed the result of unmangled_name_p for such variables,
though functions were unaffected.

The standard says that only variables with external linkage have language
linkage, but it doesn't say anything about name mangling for declarations
with internal linkage, so I think we might as well retain the old mangling
behavior.  And then we don't need to document the mangling change.

I also notice that such variables still get global symbols, as
constrain_visibility still thinks that extern "C" takes priority, but let's
save fixing (and documenting) that for GCC 17.

PR c++/117133
PR c++/124768
PR c++/124773

gcc/cp/ChangeLog:

* mangle.cc (unmangled_name_p): Don't mangle internal extern "C"
variables.

gcc/ChangeLog:

* doc/trouble.texi (Linkage in Anonymous Namespaces): Remove.

gcc/testsuite/ChangeLog:

* g++.dg/abi/mangle84.C: New test.

2 months agoc++: unusual await_suspend parameters [PR123975]
Jason Merrill [Tue, 14 Apr 2026 23:19:37 +0000 (19:19 -0400)] 
c++: unusual await_suspend parameters [PR123975]

expand_one_await_expression was assuming we could replace the last argument
of await_suspend with a call to handle::from_address.  This is wrong if
either the handle parameter has a different type (123975) or await_suspend
has additional parameters (121643).

The change to pr105287.C is needed because that test now correctly calls
operator coroutine_handle<>(), and that addition confuses the analyzer into
thinking there's a use-after-free problem.  Since the analyzer is known to
have a lot of trouble with coroutines (PR105382), let's ignore the new false
positive and just check that the test doesn't ICE.

PR c++/121643
PR c++/123975

gcc/cp/ChangeLog:

* coroutines.cc (build_co_await): Pass rvalue to await_suspend.
(expand_one_await_expression): Fix await_suspend surgery.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr105287.C: Add dg-excess-errors.
* g++.dg/coroutines/pr121643.C: New test.
* g++.dg/coroutines/pr123975.C: New test.

2 months agoc++: coro return proxy that destroys [PR121961]
Jason Merrill [Wed, 15 Apr 2026 04:51:22 +0000 (00:51 -0400)] 
c++: coro return proxy that destroys [PR121961]

After the actor of simple() hits final_suspend and returns to the ramp, the
ramp returns the Wrapper variable holding the result of get_return_object,
which calls operator Result.  Then we destroy the Wrapper, which calls
destroy() on the handle.  Then we return to the ramp, and run the rest of
the cleanups.

Before this patch there were two bugs causing us to clean up the frame too
soon, in destroy(): First, the actor destroy() handling was unconditionally
cleaning up the frame rather than checking the refcount.  Second, the ramp
was decrementing the refcount too soon.

PR c++/121961

gcc/cp/ChangeLog:

* coroutines.cc (build_actor_fn): Move the delete label before
the refcount handling.
(cp_coroutine_transform::build_ramp_function): Decrement refcount
after destroying gro.

gcc/testsuite/ChangeLog:

* g++.dg/asan/coroutines1.C: New test.

2 months agoTweak ChangeLogs
Jakub Jelinek [Wed, 15 Apr 2026 08:27:29 +0000 (10:27 +0200)] 
Tweak ChangeLogs

Add 2 ChangeLog entries ignored from automatic ChangeLog generations because
of invalid reversion commit message.

2 months agoDaily bump.
GCC Administrator [Wed, 15 Apr 2026 08:16:45 +0000 (08:16 +0000)] 
Daily bump.

2 months agocontrib: Add 9df40f1f4bec855d and d5fb79718b222072 to ignored_commits
Jakub Jelinek [Wed, 15 Apr 2026 08:14:32 +0000 (10:14 +0200)] 
contrib: Add 9df40f1f4bec855d and d5fb79718b222072 to ignored_commits

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

* gcc-changelog/git_update_version.py: Add
9df40f1f4bec855da864f535e242308ceb1cd5ad and
d5fb79718b22207253d62c92dcf8b1c16e1ea370 to ignored_commits.

2 months agocontrib: Add eec8da328cf1f91db302ab4cee803e269e68ad33 to ignored_commits
Jakub Jelinek [Wed, 15 Apr 2026 08:11:03 +0000 (10:11 +0200)] 
contrib: Add eec8da328cf1f91db302ab4cee803e269e68ad33 to ignored_commits

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

* gcc-changelog/git_update_version.py: Add
eec8da328cf1f91db302ab4cee803e269e68ad33 to ignored_commits.

2 months agocontrib: Add 69a2c243dd2cf9f77150c0eb86dfbc0931876bc1 to ignored_commits
Jakub Jelinek [Wed, 15 Apr 2026 08:06:43 +0000 (10:06 +0200)] 
contrib: Add 69a2c243dd2cf9f77150c0eb86dfbc0931876bc1 to ignored_commits

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

* gcc-changelog/git_update_version.py: Add
69a2c243dd2cf9f77150c0eb86dfbc0931876bc1 to ignored_commits.

2 months agotestsuite: Portability fixes for reflect/mangle[23].C
Jakub Jelinek [Wed, 15 Apr 2026 07:58:02 +0000 (09:58 +0200)] 
testsuite: Portability fixes for reflect/mangle[23].C

In one case we mangle size_t, which varries among targets, m on x86_64,
j on ia32, could be y as well.
And the other problematic spot is that we canonicalize ARRAY_REF indices
to ptrdiff_t:
              if (TREE_CODE (decl) == ARRAY_REF
                  && TREE_CODE (op) == INTEGER_CST)
                /* Canonicalize array offsets to ptrdiff_t; how they were
                   written doesn't matter for subobject identity.  */
                op = fold_convert (ptrdiff_type_node, op);
and again those varry among targets, l on x86_64, i on ia32, could be
x on other targets.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

* g++.dg/reflect/mangle2.C: Expect \[jmy] instead of just m for size_t
mangling.
* g++.dg/reflect/mangle3.C: Expect \[ilx] instead of just l for
ptrdiff_t mangling.

2 months agotestsuite: Require hard_float eff. target and use -frounding-math in bitint-31.c
Jakub Jelinek [Wed, 15 Apr 2026 07:54:55 +0000 (09:54 +0200)] 
testsuite: Require hard_float eff. target and use -frounding-math in bitint-31.c

Other tests which use fesetround and test rounding behavior use both
fenv and hard_float effective targets and -frounding-math in dg-options.

This patch adjusts bitint-31.c to do the same.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

* gcc.dg/bitint-31.c: Require hard_float effective target, add
-frounding-math to dg-options.

2 months agolibstdc++: Implement LWG4403: CTAD misses difference type casting
Matthias Kretz [Tue, 14 Apr 2026 12:54:03 +0000 (14:54 +0200)] 
libstdc++: Implement LWG4403: CTAD misses difference type casting

libstdc++-v3/ChangeLog:

* include/bits/simd_vec.h (basic_vec deduction guide): Explicit
cast to simd-size-type from range size type.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
2 months agoc++: Implement CWG3149 - Rvalues in destructuring expansion statements
Jakub Jelinek [Wed, 15 Apr 2026 07:02:06 +0000 (09:02 +0200)] 
c++: Implement CWG3149 - Rvalues in destructuring expansion statements

The following patch implements CWG3149.  If expansion_init
is not an lvalue in destructiring expansion stmt, init is wrapped
in a static_cast to decltype(u_i)&&.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

* pt.cc (finish_expansion_stmt): Implement CWG3149 - Rvalues in
destructuring expansion statements.  For esk_destructuring, if
expansion_init is not lvalue_p, wrap init into a static_cast
to decltype of destruct_decls[i].

* g++.dg/cpp26/expansion-stmt39.C: New test.
* g++.dg/reflect/cwg3149.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: Fix up type alias reflection mangling
Jakub Jelinek [Wed, 15 Apr 2026 06:59:43 +0000 (08:59 +0200)] 
c++: Fix up type alias reflection mangling

As discussed earlier, including in the
https://github.com/itanium-cxx-abi/cxx-abi/issues/208
issue, we should include the underlying type in the mangling of
type aliases in addition to mangling the name of the type alias,
because in different TUs the type alias could have different underlying
types.
Just adding write_char ('_'); write_type (DECL_ORIGINAL_TYPE (arg));
is not enough though, because write_prefix (arg); is subject of
substitutions and we treat the underlying type and type alias as
similar types for substitution purposes.
So, I think we have to avoid that, we can remember for substitutions
decl_mangling_prefix of the type alias TYPE_DECL, but I think we need
to then emit the unqualified name and optionally template arguments
if it is an alias template.

The following patch implements that.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

* mangle.cc (write_reflection): Adjust grammar for type alias
reflections.  Don't use write_prefix on arg, instead
write_prefix its mangling context, write_unqualified_name of
the alias, optionally write_template_args, append underscore
and write_type the original type.

* g++.dg/reflect/mangle1.C: Adjust expected mangling of type
aliases.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: Check base accessibility in cp_decomp_size [PR124862]
Jakub Jelinek [Wed, 15 Apr 2026 06:57:23 +0000 (08:57 +0200)] 
c++: Check base accessibility in cp_decomp_size [PR124862]

clang in __builtin_structured_binding_size checks whether base which
contains the destructible members is accessible.
In cp_finish_decomp we call:
      if (type != btype)
        {
          t = convert_to_base (t, btype, /*check_access*/true,
                               /*nonnull*/false, tf_warning_or_error);
          type = btype;
        }
which calls lookup_base which diagnoses that.  The following patch
just calls lookup_base in that case.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

PR c++/124862
* decl.cc (cp_decomp_size): If btype is different from type,
check if it is accessible.

* g++.dg/ext/builtin-structured-binding-size5.C: New test.
* g++.dg/ext/builtin-structured-binding-size6.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: Mark in cxx_mark_addressable DECL_VALUE_EXPR of DECL_ANON_UNION_VAR_P too [PR124850]
Jakub Jelinek [Wed, 15 Apr 2026 06:55:48 +0000 (08:55 +0200)] 
c++: Mark in cxx_mark_addressable DECL_VALUE_EXPR of DECL_ANON_UNION_VAR_P too [PR124850]

The following testcase ICEs since my PR53932 change in checking,
because it sees address of the unnamed anon union VAR_DECL taken
but without having TREE_ADDRESSABLE set.

The following patch sets it during cxx_mark_addressable.  I'm wondering
how we can get away with not marking other DECL_VALUE_EXPR cases,
but couldn't come up with a testcase where it would be needed (e.g. for
structured bindings, etc.).  So just doing it for anon union vars seems
safer to me at least for now.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

PR c++/124850
* typeck.cc (cxx_mark_addressable): For DECL_ANON_UNION_VAR_P vars
also mark their DECL_VALUE_EXPR.

* g++.dg/other/anon-union8.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++, libstdc++: Implement LWG4483 - Multidimensional arrays are not supported by...
Jakub Jelinek [Wed, 15 Apr 2026 06:52:17 +0000 (08:52 +0200)] 
c++, libstdc++: Implement LWG4483 - Multidimensional arrays are not supported by meta::reflect_constant_array and related functions

The following patch attempts to implement LWG4483.  As written in the
approved resolution, some checks are done on strip_array_types (valuet)
rather than on valuet and one is skipped.  Tomasz on IRC reasoned why
input_range should otherwise already ensure we see similar type, so just
for the possibility of fuzzed <meta> the patch adds some verification.
And as the array cases are contiguous, instead of actually recursing (for
which we'd need to have lvalue of the *it rather than prvalue) it just
walks the CONSTRUCTORs for the arrays and handles the elts in there
recursively.
The <meta> changes do exactly what the LWG4483 change says to do.

2026-04-15  Jakub Jelinek  <jakub@redhat.com>

* reflect.cc (adjust_array_elt): New function.
(get_range_elts): Implement LWG4483 - Multidimensional arrays are not
supported by meta::reflect_constant_array and related functions.
Handle ARRAY_TYPE valuet.  Don't unshare_expr in the class valuet case,
get_template_param_object will unshare.

* g++.dg/reflect/reflect_constant_array9.C: New test.
* g++.dg/reflect/reflect_constant_array10.C: New test.
* g++.dg/reflect/reflect_constant_array11.C: New test.
* g++.dg/reflect/define_static_array6.C: New test.
* g++.dg/reflect/define_static_object2.C: Uncomment older tests and
fix them, add tests for unions.

* include/std/meta (define_static_object): Adjust for LWG4483 changes
- handle unions and arrays differently.

Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2 months agox86: Fix a typo in comments
H.J. Lu [Wed, 15 Apr 2026 05:40:18 +0000 (13:40 +0800)] 
x86: Fix a typo in comments

Since x86_64_preserve_none_int_parameter_registers is used in
ix86_function_arg_regno_p, not ix86_function_value_regno_p, replace
ix86_function_value_regno_p with ix86_function_arg_regno_p in comments.

* config/i386/i386.cc
(x86_64_preserve_none_int_parameter_registers): Replace
ix86_function_value_regno_p with ix86_function_arg_regno_p in
comments.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2 months agogcov: return failure if malloc fails
Torbjörn SVENSSON [Thu, 26 Mar 2026 18:02:16 +0000 (19:02 +0100)] 
gcov: return failure if malloc fails

Don't assume that malloc always returns a non-null pointer.

xmalloc is sometimes an alias for malloc due to this in libgcc/libgcov.h:

  /* work around the poisoned malloc/calloc in system.h.  */
  #ifndef xmalloc
  #define xmalloc malloc
  #endif

libgcc/ChangeLog:

* libgcov-driver-system.c (gcov_exit_open_gcda_file): Handle
potential NULL value from malloc.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2 months agotestsuite: add missing override to member function
Torbjörn SVENSSON [Tue, 14 Apr 2026 13:11:02 +0000 (15:11 +0200)] 
testsuite: add missing override to member function

Without this patch, this ends up in the logs with llvm as the default
compiler for the host:

/build/gcc_src/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.cc:122:8: warning: 'matches_call_types_p' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  122 |   bool matches_call_types_p (const call_details &cd) const
      |        ^
/build/r16-8473-g5cc0ead3625fe6/bin/../lib/gcc/arm-none-eabi/16.0.1/plugin/include/analyzer/common.h:301:16: note: overridden virtual function is here
  301 |   virtual bool matches_call_types_p (const call_details &cd) const = 0;
      |                ^
1 warning generated.

gcc/testsuite/ChangeLog:

* gcc.dg/plugin/analyzer_known_fns_plugin.cc: Add missing
override to member function.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2 months agotestsuite: add explicit comparison to if statement
Torbjörn SVENSSON [Tue, 14 Apr 2026 13:18:57 +0000 (15:18 +0200)] 
testsuite: add explicit comparison to if statement

Without this patch, this ends up in the logs with llvm as the default
compiler for the host:

/build/gcc_src/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc:484:17: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
  484 |               if (call = check_for_named_call (stmt, "acquire_lock_a", 0))
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/gcc_src/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc:484:17: note: place parentheses around the assignment to silence this warning
  484 |               if (call = check_for_named_call (stmt, "acquire_lock_a", 0))
      |                        ^
      |                   (                                                      )
/build/gcc_src/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc:484:17: note: use '==' to turn this assignment into an equality comparison
  484 |               if (call = check_for_named_call (stmt, "acquire_lock_a", 0))
      |                        ^
      |                        ==
...
2 warnings generated.

gcc/testsuite/ChangeLog:

* gcc.dg/plugin/diagnostic_plugin_test_paths.cc: Compare with
NULL in if statement.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2 months agogccrs: backend: Prevent error_mark_node from leaking into const context
jayant chauhan [Sat, 14 Feb 2026 18:59:26 +0000 (00:29 +0530)] 
gccrs: backend: Prevent error_mark_node from leaking into const context

Fixes Rust-GCC#3910

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): Do not insert
const_expr into the context if it is an error_mark_node.
* backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3910.rs: New test.

Signed-off-by: jayant chauhan <0001jayant@gmail.com>
2 months agogccrs: Added test case for global import all
AhmedSaid3617 [Sat, 11 Apr 2026 09:41:47 +0000 (11:41 +0200)] 
gccrs: Added test case for global import all

gcc/testsuite/ChangeLog:

* rust/compile/glob-import-all.rs: New test.

Signed-off-by: AhmedSaid3617 <said.ahmed3617@gmail.com>
2 months agogccrs: Fixed glob-import all ICE
AhmedSaid3617 [Sat, 11 Apr 2026 09:35:56 +0000 (11:35 +0200)] 
gccrs: Fixed glob-import all ICE

Modified toplevel name resolver to recognize use ::*; and use *; as valid import statements, to prevent ICE.

gcc/rust/ChangeLog:

* ast/rust-item.h:(PathType::get_glob_type): Added const qualifier to allow
function call from const objects.
* resolve/rust-forever-stack.hxx:
(ForeverStack<N>::resolve_path): Check for empty segments vector and
return starting point.
* resolve/rust-toplevel-name-resolver-2.0.cc (flatten_glob): Preserve the
opening scope resolution property of the use statement.

Signed-off-by: AhmedSaid3617 <said.ahmed3617@gmail.com>
2 months agogccrs: Fix ICE in unused var when we hit unit const type
Islam-Imad [Thu, 9 Apr 2026 13:09:10 +0000 (15:09 +0200)] 
gccrs: Fix ICE in unused var when we hit unit const type

the problem is compiling if-expr doesn't set translated to unit type.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): set unit type.

gcc/testsuite/ChangeLog:

* rust/compile/issue-4517.rs: New test.

Signed-off-by: Islam-Imad <islamimad404@gmail.com>
2 months agogccrs: intrinsic: Add tests for cttz and cttz_nonzero
Mohamed Ali [Wed, 1 Apr 2026 17:38:13 +0000 (19:38 +0200)] 
gccrs: intrinsic: Add tests for cttz and cttz_nonzero

gcc/testsuite/ChangeLog:

* rust/compile/cttz.rs: New test.
* rust/compile/cttz_nonzero.rs: New test.
* rust/execute/torture/cttz.rs: New test.
* rust/execute/torture/cttz_nonzero.rs: New test.

Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>
2 months agogccrs: intrinsic: Add cttz and cttz_nonzero intrinsics
Mohamed Ali [Wed, 1 Apr 2026 17:26:25 +0000 (19:26 +0200)] 
gccrs: intrinsic: Add cttz and cttz_nonzero intrinsics

This commit introduces the cttz and cttz_nonzero intrinsics for counting leading zeros
in integer types.

The implementation includes handlers for both intrinsics, which validate input types and utilize

Addresses: Rust-GCC#658

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc: Register cttz and cttz_nonzero intrinsics.
* backend/rust-intrinsic-handlers.cc (cttz_handler): Implemnt cttz_handler.
(cttz_nonzero_handler): Implemnt cttz_nonzero_handler.
* backend/rust-intrinsic-handlers.h (cttz_handler): Add decl for cttz_handler.
(cttz_nonzero_handler): Add decl for cttz_handler.
* util/rust-intrinsic-values.h: map cttz_nonzero to its name.

Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>
2 months agogccrs: Replace usages of chainon
Owen Avery [Mon, 30 Mar 2026 02:21:20 +0000 (22:21 -0400)] 
gccrs: Replace usages of chainon

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc: Include "rust-ggc.h".
(chain_asm_operand): Use GGC::ChainList.
(CompileAsm::asm_construct_outputs): Likewise.
(CompileAsm::asm_construct_inputs): Likewise.
(CompileLlvmAsm::construct_operands): Likewise.
(CompileLlvmAsm::construct_clobbers): Likewise.
* util/rust-ggc.h (class ChainList): New class.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: refactor function qualifier parsing
Philipp Gesang [Thu, 12 Mar 2026 19:59:15 +0000 (20:59 +0100)] 
gccrs: refactor function qualifier parsing

gcc/rust/ChangeLog
* parse/rust-parse-impl.hxx: Refactor qualifier parsing
* parse/rust-parse.h: (parse_function_qualifiers) Likewise

Signed-off-by: Philipp Gesang <phg@phi-gamma.net>
2 months agogccrs: parse all function qualifiers before generating error
Philipp Gesang [Fri, 30 Jan 2026 19:14:24 +0000 (20:14 +0100)] 
gccrs: parse all function qualifiers before generating error

Instead of erroring out on the first misplaced qualifier, parse
as many qualifiers as possible to allow for more helpful error
message giving the correct order the qualifiers should be in.
Duplicate qualifiers are a kind of a special case and generate a
separate error message.

gcc/rust/ChangeLog
* parse/rust-parse-impl.hxx (parse_function_qualifiers)
Collect qualifiers into vector before generating the
error message
* parse/rust-parse.h: (parse_function_qualifiers) Make
function fallible

gcc/testsuite/ChangeLog:
* rust/compile/func-qualifier-default.rs:
Adapt to change in compiler messages
* rust/compile/func-qualifier-order.rs: Renamed existing
test file for clarity (from)
* rust/compile/func-qualifier-order-1.rs: Renamed existing
test file (to)
* rust/compile/func-qualifier-order-2.rs: New test file
* rust/compile/func-qualifier-order-3.rs: New test file

Signed-off-by: Philipp Gesang <phg@phi-gamma.net>
2 months agogccrs: add test cases for fn qualifiers, default keyword
Philipp Gesang [Thu, 29 Jan 2026 19:00:34 +0000 (20:00 +0100)] 
gccrs: add test cases for fn qualifiers, default keyword

gcc/testsuite/ChangeLog:

* rust/compile/func-qualifier-order.rs: New test file
* rust/compile/func-qualifier-default.rs: New test file

Signed-off-by: Philipp Gesang <phg@phi-gamma.net>
2 months agogccrs: Reject `default` functions after parsing.
Kushal Pal [Sat, 24 Feb 2024 11:55:48 +0000 (17:25 +0530)] 
gccrs: Reject `default` functions after parsing.

Functions with `default` qualifier outside of `impl` blocks should be
allowed to parse successfully and are later rejected during the
ASTValidation pass.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Add error for functions with `default` qualifier outside of impl
blocks.
* parse/rust-parse-impl.hxx (Parser::parse_item):
Allow parsing of functions with `default` qualifier.
(Parser::parse_vis_item): Likewise.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2 months agogccrs: Add `default` as function qualifier.
Kushal Pal [Sat, 24 Feb 2024 10:28:48 +0000 (15:58 +0530)] 
gccrs: Add `default` as function qualifier.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (AstBuilder::fn_qualifiers):
Add new parameter.
* ast/rust-ast-builder.h: Likewise.
* ast/rust-ast.cc (Function::Function):
Remove current default parameter.
(Function::operator=):
Remove current default parameter.
* ast/rust-item.h (class FunctionQualifiers):
Add data member to represent defaultness of a function.
(class Function):
Remove current default parameter.
* parse/rust-parse-impl.hxx (Parser::parse_function_qualifiers):
Parse function qualifiers in order.
* util/rust-common.h (enum class): Create enum to represent
defaultness of a function.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2 months agogccrs: Fix ICE caused by TypeCheckBase::parse_repr_options
Yap Zhi Heng [Tue, 24 Mar 2026 13:23:24 +0000 (21:23 +0800)] 
gccrs: Fix ICE caused by TypeCheckBase::parse_repr_options

Fixes Rust-GCC/gccrs#3550. Previously parse_repr_options assumes that all attrs in its
params are token trees, but it is possible that already-parsed meta items can be passed
as params as well due to expansion of cfg_attr.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options):
Allow parsing of AttrInputMetaItemContainer.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 months agogccrs: Move attribute checker to it's own file
Pierre-Emmanuel Patry [Mon, 30 Mar 2026 09:00:36 +0000 (11:00 +0200)] 
gccrs: Move attribute checker to it's own file

Both attribute utility and attribute checker (pre-expansion) were mixed
within the same file/translation unit. Splitting them apart will allow
a shorter header to include and make both file easier to navigate.

gcc/rust/ChangeLog:

* Make-lang.in: Add a new rust-attribute-checker file.
* checks/errors/rust-builtin-attribute-checker.h (check_valid_attribute_for_item):
Change BuiltinAttributeChecker doc comment.
* rust-session-manager.cc: Include the new rust-attribute-checker
header.
* util/rust-attributes.cc (AttributeChecker::AttributeChecker): Move to
rust-attribute-checker.cc.
(AttributeChecker::go): Likewise.
(is_proc_macro_type): Likewise.
(check_proc_macro_non_function): Likewise.
(check_proc_macro_non_root): Likewise.
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h (class AttributeChecker): Move to
rust-attribute-checker.h.
* checks/errors/rust-attribute-checker.cc: New file.
* checks/errors/rust-attribute-checker.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Add additional builtin attribute values
Pierre-Emmanuel Patry [Mon, 30 Mar 2026 08:20:49 +0000 (10:20 +0200)] 
gccrs: Add additional builtin attribute values

Add deny, warn and forbid attribute values.

gcc/rust/ChangeLog:

* checks/errors/rust-builtin-attribute-checker.cc (std::function<void):
Use the new attribute value variables instead of raw values.
* util/rust-attribute-values.h: Add deny, warn and forbid values.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Clean up internal attribute checking
Pierre-Emmanuel Patry [Sun, 29 Mar 2026 03:24:30 +0000 (05:24 +0200)] 
gccrs: Clean up internal attribute checking

Move all internal attribute structure checking within specific handler
functions called from the attribute visit function instead of multiple
duplicated sources in the various items. Store those handlers in a map
to avoid the expensive string switch comparisons.

gcc/rust/ChangeLog:

* checks/errors/rust-builtin-attribute-checker.cc (check_doc_attribute):
Move from here...
(doc): ...to here.
(check_deprecated_attribute): Move from here...
(deprecated): ...to here.
(check_link_section_attribute): Move from here...
(link_section): ... to here.
(check_export_name_attribute): Move from here...
(export_name): ... to here.
(check_no_mangle_function): Remove internal structure checking and move
it to no_mangle handler.
(check_lint_attribute): Move from here...
(lint): ... to here.
(link_name): Likewise with link_name.
(check_crate_type): Move to anonymous namespace within the handler
namespace.
(proc_macro_derive): Add proc macro specific handler.
(proc_macro): Likewise.
(target_feature): Likewise.
(no_mangle): Add specific handler for no_mangler attribute internal
structure checking.
(std::function<void): Add map with attribute name to handler matching.
(tl::optional<std::function<void): Likewise.
(lookup_handler): Add an helper function to retrieve the handler of any
builtin attribute.
(BuiltinAttributeChecker::visit): Change attribute visitor call with
new handler call.
* checks/errors/rust-builtin-attribute-checker.h (check_valid_attribute_for_item):
Add prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Add a function for default outer attribute checks
Pierre-Emmanuel Patry [Sun, 29 Mar 2026 01:57:10 +0000 (03:57 +0200)] 
gccrs: Add a function for default outer attribute checks

Add an helper function to keep most of the attribute checking short.

gcc/rust/ChangeLog:

* checks/errors/rust-builtin-attribute-checker.cc (BuiltinAttributeChecker::visit):
Deduplicate lines using the new templated function within the visitor
functions.
* checks/errors/rust-builtin-attribute-checker.h (class BuiltinAttributeChecker):
Create a new templated function that achieves the default attribute
checking operations.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Add macro_export to concat macro
Pierre-Emmanuel Patry [Mon, 30 Mar 2026 10:39:32 +0000 (12:39 +0200)] 
gccrs: Add macro_export to concat macro

This macro export is required with recent rust versions but not version
1.49. Since the test was not trying to highlight this rust 1.49 behavior
this commit put the least constrained version of the code.

gcc/testsuite/ChangeLog:

* rust/compile/doc_macro.rs: Add macro_export on macro.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Update test with builtin macro definition
Pierre-Emmanuel Patry [Sat, 28 Mar 2026 18:27:04 +0000 (19:27 +0100)] 
gccrs: Update test with builtin macro definition

Those test contain builtin macros that were not correctly defined. This
was mostly fine because the compiler emitted attribute errors before the
expansion step but now that the new builtin attribute checking is
executed after the expansion we cannot ignore those missing definitions.

gcc/testsuite/ChangeLog:

* rust/compile/doc_macro.rs: Add concat builtin macro definition.
* rust/compile/early_feature_gate_in_macro.rs: Add stringify builtin
macro definition.
* rust/compile/issue-3661.rs: Likewise.
* rust/compile/parse_time_feature_gate.rs: Add concat and stringify
builtin macro definition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Flatten AttrInputExpr literals to AttrInputLiteral
Pierre-Emmanuel Patry [Fri, 27 Mar 2026 14:30:31 +0000 (15:30 +0100)] 
gccrs: Flatten AttrInputExpr literals to AttrInputLiteral

Some macros may be expanded to literals within attribute input. This
this means they could be converted to AttrInputLiteral and properly
differentiate both expr and literal in the builtin attribute checker to
emit an error message when a real expr remains within an attribute.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Flatten
AttrInputExpr containing a literal to an AttrInputLiteral.
* expand/rust-expand-visitor.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Visit builtin attributes within the expand visitor
Pierre-Emmanuel Patry [Fri, 27 Mar 2026 11:15:13 +0000 (12:15 +0100)] 
gccrs: Visit builtin attributes within the expand visitor

Those attribute may contain macros within their input that must be
expanded, hence why we must visit them.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add helper to set a new attribute input.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_stmts):
Visit builtin attributes.
(ExpandVisitor::visit): Likewise.
* resolve/rust-early-name-resolver-2.0.cc (Early::visit): Expand
attribute input expr.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Move builtin attribute checking to its own pass
Pierre-Emmanuel Patry [Thu, 26 Mar 2026 15:53:26 +0000 (16:53 +0100)] 
gccrs: Move builtin attribute checking to its own pass

Builtin attribute checking should be done after macro expansion because
we want to support macros within attributes.

gcc/rust/ChangeLog:

* Make-lang.in: Add file for builtin attribute checking.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_doc_item_attribute):
Remove error emission and replace it with an assert. The error message
will now be emitted from the builtin attribute checking pass.
* rust-session-manager.cc (Session::compile_crate): Add builtin
attribute checking step after expansion.
* util/rust-attributes.cc (Attributes::is_known): Move down.
(Attributes::extract_string_literal): Likewise.
(Attributes::valid_outer_attribute): Add a function to retrieve outer/
inner status for a given builtin attribute value.
(AttributeChecker::visit): Move some checking to builtin attribute
checker.
(identify_builtin): Rename function from here ...
(lookup_builtin): ... to here.
(check_doc_alias): Move to builtin attribute checker.
(check_doc_attribute): Likewise.
(check_deprecated_attribute): Likewise.
(check_valid_attribute_for_item): Likewise.
(AttributeChecker::check_inner_attribute): Likewise.
(check_link_section_attribute): Likewise.
(check_export_name_attribute): Likewise.
(check_lint_attribute): Likewise.
(check_no_mangle_function): Likewise.
(is_proc_macro_type): Update function call name.
* util/rust-attributes.h (identify_builtin): Update prototype.
(lookup_builtin): Likewise.
* checks/errors/rust-builtin-attribute-checker.cc: New file.
* checks/errors/rust-builtin-attribute-checker.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/issue-4226.rs: Update text to match error message from
attribute checking pass that was not triggered before.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Remove AttrInputMacro attribute input kind
Pierre-Emmanuel Patry [Wed, 25 Mar 2026 15:51:42 +0000 (16:51 +0100)] 
gccrs: Remove AttrInputMacro attribute input kind

This attribute kind is being replaced with AttrInputExpr attributes.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Remove
AttrInputMacro handling.
* ast/rust-ast-collector.h: Remove function prototype.
* ast/rust-ast-full-decls.h (class AttrInputMacro): Remove forward
declaration.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove function.
* ast/rust-ast-visitor.h: Remove function prototypes.
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Remove handling of
macros.
(AttrInputMacro::as_string): Remove function.
(AttrInputMacro::AttrInputMacro): Likewise.
(AttrInputMacro::operator=): Likewise.
(AttrInputMacro::accept_vis): Likewise.
* ast/rust-ast.h: Remove MACRO kind.
* ast/rust-expr.h (class AttrInputMacro): Add getter for expr pointer.
Remove AttrInputMacro class.
* expand/rust-derive.h: Remove function prototype.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Change function
to AttrInputExpr.
* expand/rust-expand-visitor.h: Update prototype.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Remove function.
* hir/rust-ast-lower-base.h: Remove function prototype.
* parse/rust-parse-impl-attribute.hxx: Parse the attribute content as
AttrInputExpr instead.
* util/rust-attributes.cc (check_doc_attribute): Remove MACRO kind
handling.
(check_export_name_attribute): Remove switch and only handle literals.
(AttributeChecker::visit): Remove function.
* util/rust-attributes.h: Remove function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: rust: Fix ICE in function_set_parameters
Egas Ribeiro [Wed, 25 Mar 2026 10:18:01 +0000 (10:18 +0000)] 
gccrs: rust: Fix ICE in function_set_parameters

When lowering a function to HIR with a refutable pattern in its
parameter pattern, we were ICE'ing due to a lack of checks for invalid
refutable patterns. Fix this by erroring on invalid patterns while
lowering a function.

Fixes Rust-GCC/gccrs#3919

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): added
refutable pattern checks for function params.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3919-ice-func-parms.rs: New test.

Signed-off-by: Egas Ribeiro <egas.g.ribeiro@tecnico.ulisboa.pt>
2 months agogccrs: Disambiguate identifier and path patterns
Owen Avery [Sun, 22 Mar 2026 22:48:57 +0000 (18:48 -0400)] 
gccrs: Disambiguate identifier and path patterns

gcc/rust/ChangeLog:

* Make-lang.in (GRS_OBJS): Add rust-identifier-path.o.
* resolve/rust-early-name-resolver-2.0.cc: Include
"rust-identifier-path.h".
(Early::go): Use IdentifierPathPass.
(Early::visit): Handle identifier patterns which should be path
patterns.
* resolve/rust-early-name-resolver-2.0.h: Include
"rust-pattern.h".
(Early::visit): Add visiting function declaration for
IdentifierPattern.
(Early::ident_path_to_convert): New member variable.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Call Mappings::add_function_node.
* util/rust-hir-map.cc (Mappings::add_function_node): New
member function definition.
(Mappings::is_function_node): Likewise.
* util/rust-hir-map.h (Mappings::add_function_node): New
member function declaration.
(Mappings::is_function_node): Likewise.
(Mappings::function_nodes): New member variable.
* resolve/rust-identifier-path.cc: New file.
* resolve/rust-identifier-path.h: New file.

gcc/testsuite/ChangeLog:

* rust/execute/ident_pat_vs_path_1.rs: New test.
* rust/execute/ident_pat_vs_path_2.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: expand: Added a more complete test
Jayant Chauhan [Tue, 6 Jan 2026 10:09:23 +0000 (15:39 +0530)] 
gccrs: expand: Added a more complete test

This patch adds a regression test ensuring that deriving on invalid items
(such as functions or traits) triggers a diagnostic error instead of an
Internal Compiler Error (ICE). It also verifies that Tuple Structs are
accepted as valid targets for derivation.

Fixes Rust-GCC#3875

gcc/testsuite/ChangeLog:

* rust/compile/issue-3875.rs: New test.

Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
2 months agogccrs: Deduplicate some functions within PointerVisitor
Pierre-Emmanuel Patry [Fri, 13 Mar 2026 14:50:27 +0000 (15:50 +0100)] 
gccrs: Deduplicate some functions within PointerVisitor

Some functions within the PointerVisitor were obvious duplicate from the
inherited DefaultASTVisitor.

gcc/rust/ChangeLog:

* ast/rust-ast-pointer-visitor.cc (PointerVisitor::visit): Remove
duplicated functions.
* ast/rust-ast-pointer-visitor.h: Remove duplicated function
prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Strip down 1.0 resolver
Owen Avery [Fri, 27 Mar 2026 03:20:27 +0000 (23:20 -0400)] 
gccrs: Strip down 1.0 resolver

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (MacroExpander::expand_crate):
Remove usage of Resolver::get_macro_scope.
* resolve/rust-name-resolver.cc (Resolver::Resolver): Handle
removal of member variables.
(Resolver::push_new_name_rib): Remove function definition.
(Resolver::push_new_type_rib): Likewise.
(Resolver::push_new_label_rib): Likewise.
(Resolver::push_new_macro_rib): Likewise.
(Resolver::find_name_rib): Likewise.
(Resolver::find_type_rib): Likewise.
(Resolver::find_macro_rib): Likewise.
(Resolver::insert_builtin_types): Likewise.
(Resolver::get_builtin_types): Likewise.
(Resolver::generate_builtins): Likewise.
(Resolver::setup_builtin): Likewise.
(Resolver::insert_resolved_label): Likewise.
(Resolver::lookup_resolved_label): Likewise.
(Resolver::insert_resolved_macro): Likewise.
(Resolver::lookup_resolved_macro): Likewise.
(Resolver::push_closure_context): Likewise.
(Resolver::pop_closure_context): Likewise.
(Resolver::insert_captured_item): Likewise.
(Resolver::decl_needs_capture): Likewise.
(Resolver::get_captures): Likewise.
(Resolver::insert_resolved_name): Replace function
implementation with rust_unreachable call.
(Resolver::lookup_resolved_name): Likewise.
(Resolver::insert_resolved_type): Likewise.
(Resolver::lookup_resolved_type): Likewise.
(Resolver::insert_resolved_misc): Likewise.
(Resolver::lookup_resolved_misc): Likewise.
* resolve/rust-name-resolver.h (Resolver::insert_builtin_types):
Remove member function declaration.
(Resolver::get_builtin_types): Likewise.
(Resolver::push_new_name_rib): Likewise.
(Resolver::push_new_type_rib): Likewise.
(Resolver::push_new_label_rib): Likewise.
(Resolver::push_new_macro_rib): Likewise.
(Resolver::find_name_rib): Likewise.
(Resolver::find_type_rib): Likewise.
(Resolver::find_label_rib): Likewise.
(Resolver::find_macro_rib): Likewise.
(Resolver::insert_resolved_label): Likewise.
(Resolver::lookup_resolved_label): Likewise.
(Resolver::insert_resolved_macro): Likewise.
(Resolver::lookup_resolved_macro): Likewise.
(Resolver::get_name_scope): Likewise.
(Resolver::get_type_scope): Likewise.
(Resolver::get_label_scope): Likewise.
(Resolver::get_macro_scope): Likewise.
(Resolver::get_global_type_node_id): Likewise.
(Resolver::set_unit_type_node_id): Likewise.
(Resolver::get_unit_type_node_id): Likewise.
(Resolver::set_never_type_node_id): Likewise.
(Resolver::get_never_type_node_id): Likewise.
(Resolver::push_new_module_scope): Likewise.
(Resolver::pop_module_scope): Likewise.
(Resolver::peek_current_module_scope): Likewise.
(Resolver::peek_crate_module_scope): Likewise.
(Resolver::peek_parent_module_scope): Likewise.
(Resolver::push_closure_context): Likewise.
(Resolver::pop_closure_context): Likewise.
(Resolver::insert_captured_item): Likewise.
(Resolver::get_captures): Likewise.
(Resolver::as_debug_string): Likewise.
(Resolver::decl_needs_capture): Likewise.
(Resolver::generate_builtins): Likewise.
(Resolver::setup_builtin): Likewise.
(Resolver::mappings): Remove member variable.
(Resolver::tyctx): Likewise.
(Resolver::builtins): Likewise.
(Resolver::name_scope): Likewise.
(Resolver::type_scope): Likewise.
(Resolver::label_scope): Likewise.
(Resolver::macro_scope): Likewise.
(Resolver::global_type_node_id): Likewise.
(Resolver::unit_ty_node_id): Likewise.
(Resolver::never_ty_node_id): Likewise.
(Resolver::name_ribs): Likewise.
(Resolver::type_ribs): Likewise.
(Resolver::label_ribs): Likewise.
(Resolver::macro_ribs): Likewise.
(Resolver::resolved_names): Likewise.
(Resolver::resolved_types): Likewise.
(Resolver::resolved_labels): Likewise.
(Resolver::resolved_macros): Likewise.
(Resolver::misc_resolved_items): Likewise.
(Resolver::current_module_stack): Likewise.
(Resolver::closure_context): Likewise.
(Resolver::closures_capture_mappings): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: nr1.0: Remove support in checking phases
Owen Avery [Thu, 28 Aug 2025 01:20:16 +0000 (21:20 -0400)] 
gccrs: nr1.0: Remove support in checking phases

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc: Remove inclusion of
"options.h".
(ConstChecker::ConstChecker): Initialize 2.0 resolver.
(ConstChecker::visit): Assume nr2.0 is enabled.
* checks/errors/rust-const-checker.h: Adjust includes.
(ConstChecker::resolver): Change type to 2.0 resolver.
* checks/errors/rust-unsafe-checker.cc: Remove inclusion of
"options.h".
(UnsafeChecker::UnsafeChecker): Initialize 2.0 resolver.
(UnsafeChecker::visit): Assume nr2.0 is enabled.
* checks/errors/rust-unsafe-checker.h: Adjust includes.
(UnsafeChecker::resolver): Change type to 2.0 resolver.
* checks/lints/rust-lint-marklive.cc
(MarkLive::visit_path_segment): Assume nr2.0 is enabled.
(MarkLive::visit): Likewise.
(MarkLive::find_ref_node_id): Likewise.
* checks/lints/rust-lint-marklive.h: Include
"rust-immutable-name-resolution-context.h".
(MarkLive::resolver): Change type to 2.0 resolver, as a
reference instead of a pointer.
(MarkLive::MarkLive): Initialize 2.0 resolver.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Remove redundant expand visitor overloads
Owen Avery [Sun, 22 Mar 2026 18:57:02 +0000 (14:57 -0400)] 
gccrs: Remove redundant expand visitor overloads

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Remove
some redundant function overloads.
* expand/rust-expand-visitor.h (ExpandVisitor::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Add no_builtins attribute to list of builtins
Pierre-Emmanuel Patry [Thu, 12 Mar 2026 16:34:41 +0000 (17:34 +0100)] 
gccrs: Add no_builtins attribute to list of builtins

gcc/rust/ChangeLog:

* util/rust-attribute-values.h: Add "no_builtins"
attribute value.
* util/rust-attributes.cc: Add "no_builtins" to
the list of builtin attributes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Accepts "compiler_builtins" attribute
Pierre-Emmanuel Patry [Thu, 12 Mar 2026 15:52:15 +0000 (16:52 +0100)] 
gccrs: Accepts "compiler_builtins" attribute

This attribute shall be accepted/rejected depending on the feature
activation status.

gcc/rust/ChangeLog:

* checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit):
Rework visit to avoid multiple iterations. Add check for
"compiler_builtins" attribute.
(FeatureGate::check_no_core_attribute): Remove loop.
* checks/errors/feature/rust-feature-gate.h: Update function prototype.
* util/rust-attribute-values.h: Add "compiler_builtins" attribute
value.
* util/rust-attributes.cc: Add "compiler_builtins" to the list of
builtin attributes.

gcc/testsuite/ChangeLog:

* rust/compile/compiler_builtins_gate.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: intrinsic: Add separated tests for each type
Mohamed Ali [Thu, 19 Mar 2026 12:58:45 +0000 (14:58 +0200)] 
gccrs: intrinsic: Add separated tests for each type

gcc/testsuite/ChangeLog:

* rust/execute/torture/ctlz_i16.rs: New test.
* rust/execute/torture/ctlz_i32.rs: New test.
* rust/execute/torture/ctlz_i64.rs: New test.
* rust/execute/torture/ctlz_i8.rs: New test.
* rust/execute/torture/ctlz_nonzero_i16.rs: New test.
* rust/execute/torture/ctlz_nonzero_i32.rs: New test.
* rust/execute/torture/ctlz_nonzero_i64.rs: New test.
* rust/execute/torture/ctlz_nonzero_i8.rs: New test.
* rust/execute/torture/ctlz_nonzero_u16.rs: New test.
* rust/execute/torture/ctlz_nonzero_u32.rs: New test.
* rust/execute/torture/ctlz_nonzero_u64.rs: New test.
* rust/execute/torture/ctlz_nonzero_u8.rs: New test.
* rust/execute/torture/ctlz_u16.rs: New test.
* rust/execute/torture/ctlz_u32.rs: New test.
* rust/execute/torture/ctlz_u64.rs: New test.
* rust/execute/torture/ctlz_u8.rs: New test.

Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>