]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
4 months agoC++: Adjust implicit '__cxa_bad_typeid' prototype to reality
Thomas Schwinge [Wed, 19 Mar 2025 11:18:26 +0000 (12:18 +0100)] 
C++: Adjust implicit '__cxa_bad_typeid' prototype to reality

In 2001 Subversion r40924 (Git commit 52a11cbfcf0cfb32628b6953588b6af4037ac0b6)
"IA-64 ABI Exception Handling", '__cxa_bad_typeid' changed from
'std::type_info const &' to 'void' return type:

    --- libstdc++-v3/libsupc++/exception_support.cc
    +++ /dev/null
    @@ -1,388 +0,0 @@
    -[...]
    -// Helpers for rtti. Although these don't return, we give them return types so
    -// that the type system is not broken.
    -[...]
    -extern "C" std::type_info const &
    -__cxa_bad_typeid ()
    -{
    -  [...]
    -}
    -[...]

    --- /dev/null
    +++ libstdc++-v3/libsupc++/unwind-cxx.h
    @@ -0,0 +1,163 @@
    +[...]
    +extern "C" void __cxa_bad_typeid ();
    +[...]

    --- /dev/null
    +++ libstdc++-v3/libsupc++/eh_aux_runtime.cc
    @@ -0,0 +1,56 @@
    +[...]
    +extern "C" void
    +__cxa_bad_typeid ()
    +{
    +  [...]
    +}

The implicit prototype in the C++ front end however wasn't likewise adjusted,
and so for nvptx we generate code for 'std::type_info const &' return type:

    // BEGIN GLOBAL FUNCTION DECL: __cxa_bad_typeid
    .extern .func (.param .u64 %value_out) __cxa_bad_typeid;

    {
    .param .u64 %value_in;
    call (%value_in),__cxa_bad_typeid;
    trap;
    // (noreturn)
    exit;
    // (noreturn)
    ld.param.u64 %r39,[%value_in];
    }

..., which is in conflict with the library code with 'void' return type:

    // BEGIN GLOBAL FUNCTION DECL: __cxa_bad_typeid
    .visible .func __cxa_bad_typeid;

    // BEGIN GLOBAL FUNCTION DEF: __cxa_bad_typeid
    .visible .func __cxa_bad_typeid
    {
    [...]
    }

..., and we thus get execution test FAILs for 'g++.dg/rtti/typeid11.C', for
example:

    error   : Prototype doesn't match for '__cxa_bad_typeid' in 'input file 4 at offset 22204', first defined in 'input file 4 at offset 22204'
    nvptx-run: cuLinkAddData failed: unknown error (CUDA_ERROR_UNKNOWN, 999)

With this patched, we get the expected:

     // BEGIN GLOBAL FUNCTION DECL: __cxa_bad_typeid
    -.extern .func (.param .u64 %value_out) __cxa_bad_typeid;
    +.extern .func __cxa_bad_typeid;

     {
    -.param .u64 %value_in;
    -call (%value_in),__cxa_bad_typeid;
    +call __cxa_bad_typeid;
     trap;
     // (noreturn)
     exit;
     // (noreturn)
    -ld.param.u64 %r39,[%value_in];
     }

..., and execution test PASSes for a few test cases.

gcc/cp/
* rtti.cc (throw_bad_typeid): Adjust implicit '__cxa_bad_typeid'
prototype to reality.  Adjust all users.

Co-authored-by: Jason Merrill <jason@redhat.com>
4 months agowidening_mul: Fix up further r14-8680 widening mul issues [PR119417]
Jakub Jelinek [Wed, 26 Mar 2025 13:03:50 +0000 (14:03 +0100)] 
widening_mul: Fix up further r14-8680 widening mul issues [PR119417]

The following testcase is miscompiled since r14-8680 PR113560 changes.
I've already tried to fix some of the issues caused by that change in
r14-8823 PR113759, but apparently didn't get it right.

The problem is that the r14-8680 changes sometimes set *type_out to
a narrower type than the *new_rhs_out actually has (because it will
handle stuff like _1 = rhs1 & 0xffff; and imply from that HImode type_out.

Now, if in convert_mult_to_widen or convert_plusminus_to_widen we actually
get optab for the modes we've asked for (i.e. with from_mode and to_mode),
everything works fine, if the operands don't have the expected types,
they are converted to those (for INTEGER_CSTs with fold_convert,
otherwise with build_and_insert_cast).
On the following testcase on aarch64 that is not the case, we ask
for from_mode HImode and to_mode DImode, but get actual_mode SImode.
The mult_rhs1 operand already has SImode and we change type1 to unsigned int
and so no cast is actually done, except that the & 0xffff is lost that way.

The following patch ensures that if we change typeN because of wider
actual_mode (or because of a sign change), we first cast to the old
typeN (if the r14-8680 code was encountered, otherwise it would have the
same precision) and only then change it, and then perhaps cast again.

On the testcase on aarch64-linux the patch results in the expected
-       add     x19, x19, w0, uxtw 1
+       add     x19, x19, w0, uxth 1
difference.

2025-03-26  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/119417
* tree-ssa-math-opts.cc (convert_mult_to_widen): Before changing
typeN because actual_precision/from_unsignedN differs cast rhsN
to typeN if it has a different type.
(convert_plusminus_to_widen): Before changing
typeN because actual_precision/from_unsignedN differs cast mult_rhsN
to typeN if it has a different type.

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

4 months agoprofile: Don't instrument fake exit edges after musttail [PR118442]
Jakub Jelinek [Wed, 26 Mar 2025 12:59:16 +0000 (13:59 +0100)] 
profile: Don't instrument fake exit edges after musttail [PR118442]

When -fprofile-generate is used musttail often fails because the
compiler adds instrumentation after the tail calls.

This patch ignores EDGE_FAKE edges added from musttail calls to EXIT.

2025-03-26  Jakub Jelinek  <jakub@redhat.com>
    Andi Kleen  <ak@gcc.gnu.org>

PR gcov-profile/118442
* profile.cc (branch_prob): Ignore EDGE_FAKE edges from musttail calls
to EXIT.

* c-c++-common/pr118442.c: New test.

4 months agoi386: Fix up pr55583.c testcase [PR119465]
Jakub Jelinek [Wed, 26 Mar 2025 11:19:14 +0000 (12:19 +0100)] 
i386: Fix up pr55583.c testcase [PR119465]

In r15-4289 H.J. fixed up the pr55583.c testcase to use unsigned long long
or long long instead of unsigned long or long.  That change looks correct to
me because the
void test64r () { b = ((u64)b >> n) | (a << (64 - n)); }
etc. functions otherwise aren't really 64-bit rotates, but something that
triggers UB all the time (at least one of the shifts is out of bounds).
I assume that change fixed the FAILs on -mx32, but it caused
FAIL: gcc.target/i386/pr55583.c scan-assembler-times (?n)shldl?[\\\\t ]*\\\\\$2 1
FAIL: gcc.target/i386/pr55583.c scan-assembler-times (?n)shrdl?[\\\\t ]*\\\\\$2 2
regression on i686-linux (but just for -m32 without defaulting to SSE2 or
what).  The difference is that for say -m32 -march=x86-64 the stv pass
handles some of the rotates in SSE and so we get different sh[rl]dl
instruction counts from the case when SSE isn't enabled and stv pass isn't
done.

The following patch fixes that by disabling SSE for ia32 and always testing
for the same number of instructions.

Tested with all of
make check-gcc RUNTESTFLAGS='--target_board=unix\{-m32/-march=x86-64,-m32/-march=i686,-mx32,-m64\} i386.exp=pr55583.c'

2025-03-26  Jakub Jelinek  <jakub@redhat.com>

PR target/55583
PR target/119465
* gcc.target/i386/pr55583.c: Add -mno-sse -mno-mmx to
dg-additional-options.  Expect 4 shrdl and 2 shldl instructions on
ia32.

4 months agolibstdc++: Check presence of iterator_category for flat_sets insert_range [PR119415]
Tomasz Kamiński [Wed, 26 Mar 2025 06:34:37 +0000 (07:34 +0100)] 
libstdc++: Check presence of iterator_category for flat_sets insert_range [PR119415]

As pointed out by Hewill Kang (reporter) in the issue, checking if iterator
of the incoming range satisfies __cpp17_input_iterator, may still lead
to hard errors inside of insert_range for iterators that satisfies
that concept, but specialize iterator_traits without iterator_category
typedef (std::common_iterator specialize iterator_traits without
iterator_category in some cases).

To address that we instead check if the iterator_traits<It>::iterator_category
is present and denote at least input_iterator_tag, using existing __has_input_iter_cat.

PR libstdc++/119415

libstdc++-v3/ChangeLog:

* include/std/flat_set (_Flat_set_impl:insert_range):
Replace __detail::__cpp17_input_iterator with __has_input_iter_cat.
* testsuite/23_containers/flat_multiset/1.cc: New tests
* testsuite/23_containers/flat_set/1.cc: New tests

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agotestsuite: i386: Require dfp support in gcc.target/i386/pr117946.c etc.
Rainer Orth [Wed, 26 Mar 2025 10:46:57 +0000 (11:46 +0100)] 
testsuite: i386: Require dfp support in gcc.target/i386/pr117946.c etc.

Two tests FAIL on 64-bit Solaris/x86:

FAIL: gcc.target/i386/pr117946.c (test for excess errors)
FAIL: gcc.target/i386/pr118017.c (test for excess errors)

The failure mode is the same in both cases:

Excess errors:
/vol/gcc/src/hg/master/local/gcc/testsuite/gcc.target/i386/pr117946.c:4:47: error: decimal floating-point not supported for this target

Excess errors:
/vol/gcc/src/hg/master/local/gcc/testsuite/gcc.target/i386/pr118017.c:6:47: error: decimal floating-point not supported for this target

Fixed by requiring dfp support.

Tested on i386-pc-solaris2.11 and x86_64-pc-linux-gnu.

2025-03-25  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
* gcc.target/i386/pr117946.c: Require dfp support.
* gcc.target/i386/pr118017.c: Likewise.  Use
dg-require-effective-target for both this and int128.

4 months agolibgomp.texi: Document supported OpenMP 'interop' types for nvptx and gcn
Tobias Burnus [Wed, 26 Mar 2025 10:27:56 +0000 (11:27 +0100)] 
libgomp.texi: Document supported OpenMP 'interop' types for nvptx and gcn

Note that this commit also updates the API interface to OpenMP 6.0;
while 5.1 and 5.2 use 'int *' for the the ret_code argument,
OpenMP 6.0 changed this to omp_interop_rc_t *; this enum also exists in
OpenMP 5.1. However, C++ does not like this change such that unless NULL
is passed (i.e. the argument is ignored), OpenMP 5.x and 6.x are not
compatible.

Note that GCC's omp.h already follows OpenMP 6.0 and is now in sync with
the documentation.

libgomp/ChangeLog:

* libgomp.texi (OpenMP 5.1): Add @ref to offload-target specifics
for 'interop'.
(OpenMP 6.0): Mark dispatch's interop clause as implemented.
(omp_get_interop_int, omp_get_interop_str,
omp_get_interop_ptr, omp_get_interop_type_desc): Add @ref to
Offload-Target Specifics; change ret_code argument type to
'omp_interop_rc_t *'.
(Offload-Target Specifics): Document the supported OpenMP
interop foreign runtimes on AMD and Nvidia GPUs.

4 months agolibstdc++: Add P1206R7 range operations to std::deque [PR111055]
Tomasz Kamiński [Fri, 21 Mar 2025 08:03:54 +0000 (09:03 +0100)] 
libstdc++: Add P1206R7 range operations to std::deque [PR111055]

This is another piece of P1206R7, adding from_range constructor, append_range,
prepend_range, insert_range, and assign_range members to std::deque.

For append_front of input non-sized range, we are emplacing element at the front and
then reverse inserted elements. This does not existing elements, and properly handle
aliasing ranges.

For insert_range, the handling of insertion in the middle of input-only ranges
that are sized could be optimized, we still insert nodes one-by-one in such case.
For forward and stronger ranges, we reduce them to common_range case, by computing
the iterator when computing the distance. This is slightly suboptimal, as it require
range to be iterated for non-common forward ranges that are sized, but reduces
number of instantiations.

This patch extract _M_range_prepend, _M_range_append helper functions that accepts
(iterator, sentinel) pair. This all used in all standard modes.

PR libstdc++/111055

libstdc++-v3/ChangeLog:

* include/bits/deque.tcc (deque::prepend_range, deque::append_range)
(deque::insert_range, __advance_dist): Define.
(deque::_M_range_prepend, deque::_M_range_append):
Extract from _M_range_insert_aux for _ForwardIterator(s).
* include/bits/stl_deque.h (deque::assign_range): Define.
(deque::prepend_range, deque::append_range, deque::insert_range):
Declare.
(deque(from_range_t, _Rg&&, const allocator_type&)): Define constructor
and deduction guide.
* include/debug/deque (deque::prepend_range, deque::append_range)
(deque::assign_range): Define.
(deque(from_range_t, _Rg&&, const allocator_type&)): Define constructor
and deduction guide.
* testsuite/23_containers/deque/cons/from_range.cc: New test.
* testsuite/23_containers/deque/modifiers/append_range.cc: New test.
* testsuite/23_containers/deque/modifiers/assign/assign_range.cc:
New test.
* testsuite/23_containers/deque/modifiers/prepend_range.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agoi386: Require in peephole2 that memory is offsettable [PR119450]
Jakub Jelinek [Wed, 26 Mar 2025 07:47:20 +0000 (08:47 +0100)] 
i386: Require in peephole2 that memory is offsettable [PR119450]

The following testcase ICEs because a peephole2 attempts to offset
memory which is not offsettable (in particular address is a ZERO_EXTEND
in this case).

Because peephole2s don't support constraints, I've added a check for this
in the peephole2's condition.

2025-03-26  Jakub Jelinek  <jakub@redhat.com>

PR target/119450
* config/i386/i386.md (narrow test peephole2): Test for
offsettable_memref_p in condition.

* gcc.target/i386/pr119450.c: New test.

4 months agotarget/119010 - add missing DF load/store reservations for znver4 and znver5
Richard Biener [Tue, 25 Mar 2025 14:18:14 +0000 (15:18 +0100)] 
target/119010 - add missing DF load/store reservations for znver4 and znver5

The following resolves missing reservations for DFmode *movdf_internal
loads and stores, visible as 'nothing' in -fsched-verbose=2 dumps.

PR target/119010
* config/i386/zn4zn5.md (znver4_sse_mov_fp, znver4_sse_mov_fp_load,
znver5_sse_mov_fp_load, znver4_sse_mov_fp_store,
znver5_sse_mov_fp_store): Also match V1SF and DF.

4 months agotarget/119010 - add missing integer store reservations for znver4 and znver5
Richard Biener [Tue, 25 Mar 2025 14:40:22 +0000 (15:40 +0100)] 
target/119010 - add missing integer store reservations for znver4 and znver5

The imov and imovx classified stores miss reservations in the znver4/5
pipeline description.  The following adds them.

PR target/119010
* config/i386/zn4zn5.md (znver4_imov_double_store,
znver5_imov_double_store, znver4_imov_store, znver5_imov_store):
New reservations for integer stores.

4 months agomiddle-end/118795 - fix can_vec_perm_const_p query in match.pd
Richard Biener [Tue, 25 Mar 2025 12:45:36 +0000 (13:45 +0100)] 
middle-end/118795 - fix can_vec_perm_const_p query in match.pd

When expanding to RTL we always use vec_perm_indices with two operands
which can make a difference with respect to supported vs. unsupported.
So the following adjusts a query in match.pd for target support which
got this "wrong" and using 1 for a equal operand permute.

PR middle-end/118795
* match.pd (vec_perm <vec_perm <a, b>> -> vec_perm <a, b>):
Use the appropriate check to see whether the original
outer permute was supported.

* g++.dg/torture/pr118795.C: New testcase.

4 months agorust: Use 'lbasename()' consistently.
Iain Sandoe [Mon, 24 Mar 2025 08:33:53 +0000 (08:33 +0000)] 
rust: Use 'lbasename()' consistently.

The amends the remaining case in the rust code to use the libiberty
lbasename() instead of the (potentially variably-behaved) system
'basename()'.

gcc/rust/ChangeLog:

* metadata/rust-export-metadata.cc
(PublicInterface::write_to_path): Use 'lbasename()' instead of
'basename()'.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 months agotestsuite: add testcase for recent alias fix
Sam James [Tue, 25 Mar 2025 07:47:27 +0000 (07:47 +0000)] 
testsuite: add testcase for recent alias fix

r15-7961-gdc47161c1f32c3 fixes a typo in ao_compare::compare_ao_refs
but there wasn't a testcase available at the time. Now there is.

Thanks to Andrew for the testcase.

gcc/testsuite/ChangeLog:
PR testsuite/119382

* gcc.dg/ipa/ipa-icf-40.c: New test.

Co-authored-by: Andrew Pinski <quic_apinski@quicinc.com>
4 months agoi386: Add "s_" as Saturation for AVX10.2 Converting Intrinsics.
Hu, Lin1 [Fri, 21 Mar 2025 02:43:10 +0000 (10:43 +0800)] 
i386: Add "s_" as Saturation for AVX10.2 Converting Intrinsics.

This patch aims to add "s_" after 'cvt' represent saturation.

gcc/ChangeLog:

* config/i386/avx10_2-512convertintrin.h (_mm512_mask_cvtx2ps_ph): Formatting fixes
(_mm512_mask_cvtx_round2ps_ph): Ditto
(_mm512_maskz_cvtx_round2ps_ph): Ditto
(_mm512_cvtbiassph_bf8): Rename to _mm512_cvts_biasph_bf8.
(_mm512_mask_cvtbiassph_bf8): Rename to _mm512_mask_cvts_biasph_bf8.
(_mm512_maskz_cvtbiassph_bf8): Rename to _mm512_maskz_cvts_biasph_bf8.
(_mm512_cvtbiassph_hf8): Rename to _mm512_cvts_biasph_hf8.
(_mm512_mask_cvtbiassph_hf8): Rename to _mm512_mask_cvts_biasph_hf8.
(_mm512_maskz_cvtbiassph_hf8): Rename to _mm512_maskz_cvts_biasph_hf8.
(_mm512_cvts2ph_bf8): Rename to _mm512_cvts_2ph_bf8.
(_mm512_mask_cvts2ph_bf8): Rename to _mm512_mask_cvts_2ph_bf8.
(_mm512_maskz_cvts2ph_bf8): Rename to _mm512_maskz_cvts_2ph_bf8.
(_mm512_cvts2ph_hf8): Rename to _mm512_cvts_2ph_hf8.
(_mm512_mask_cvts2ph_hf8): Rename to _mm512_mask_cvts_2ph_hf8.
(_mm512_maskz_cvts2ph_hf8): Rename to _mm512_maskz_cvts_2ph_hf8.
(_mm512_cvtsph_bf8): Rename to _mm512_cvts_ph_bf8.
(_mm512_mask_cvtsph_bf8): Rename to _mm512_mask_cvts_ph_bf8.
(_mm512_maskz_cvtsph_bf8): Rename to _mm512_maskz_cvts_ph_bf8.
(_mm512_cvtsph_hf8): Rename to _mm512_cvts_ph_hf8.
(_mm512_mask_cvtsph_hf8): Rename to _mm512_mask_cvts_ph_hf8.
(_mm512_maskz_cvtsph_hf8): Rename to _mm512_maskz_cvts_ph_hf8.
* config/i386/avx10_2convertintrin.h
(_mm_cvtbiassph_bf8): Rename to _mm_cvts_biasph_bf8.
(_mm_mask_cvtbiassph_bf8): Rename to _mm_mask_cvts_biasph_bf8.
(_mm_maskz_cvtbiassph_bf8): Rename to _mm_maskz_cvts_biasph_bf8.
(_mm256_cvtbiassph_bf8): Rename to _mm256_cvts_biasph_bf8.
(_mm256_mask_cvtbiassph_bf8): Rename to _mm256_mask_cvts_biasph_bf8.
(_mm256_maskz_cvtbiassph_bf8): Rename to _mm256_maskz_cvts_biasph_bf8.
(_mm_cvtbiassph_hf8): Rename to _mm_cvts_biasph_hf8.
(_mm_mask_cvtbiassph_hf8): Rename to _mm_mask_cvts_biasph_hf8.
(_mm_maskz_cvtbiassph_hf8): Rename to _mm_maskz_cvts_biasph_hf8.
(_mm256_cvtbiassph_hf8): Rename to _mm256_cvts_biasph_hf8.
(_mm256_mask_cvtbiassph_hf8): Rename to _mm256_mask_cvts_biasph_hf8.
(_mm256_maskz_cvtbiassph_hf8): Rename to _mm256_maskz_cvts_biasph_hf8.
(_mm_cvts2ph_bf8): Rename to _mm_cvts_2ph_bf8.
(_mm_mask_cvts2ph_bf8): Rename to _mm_mask_cvts_2ph_bf8.
(_mm_maskz_cvts2ph_bf8): Rename to _mm_maskz_cvts_2ph_bf8.
(_mm256_cvts2ph_bf8): Rename to _mm256_cvts_2ph_bf8.
(_mm256_mask_cvts2ph_bf8): Rename to _mm256_mask_cvts_2ph_bf8.
(_mm256_maskz_cvts2ph_bf8): Rename to _mm256_maskz_cvts_2ph_bf8.
(_mm_cvts2ph_hf8): Rename to _mm_cvts_2ph_hf8.
(_mm_mask_cvts2ph_hf8): Rename to _mm_mask_cvts_2ph_hf8.
(_mm_maskz_cvts2ph_hf8): Rename to _mm_maskz_cvts_2ph_hf8.
(_mm256_cvts2ph_hf8): Rename to _mm256_cvts_2ph_hf8.
(_mm256_mask_cvts2ph_hf8): Rename to _mm256_mask_cvts_2ph_hf8.
(_mm256_maskz_cvts2ph_hf8): Rename to _mm256_maskz_cvts_2ph_hf8.
(_mm_cvtsph_bf8): Rename to _mm_cvts_ph_bf8.
(_mm_mask_cvtsph_bf8): Rename to _mm_mask_cvts_ph_bf8.
(_mm_maskz_cvtsph_bf8): Rename to _mm_maskz_cvts_ph_bf8.
(_mm256_cvtsph_bf8): Rename to _mm256_cvts_ph_bf8.
(_mm256_mask_cvtsph_bf8): Rename to _mm256_mask_cvts_ph_bf8.
(_mm256_maskz_cvtsph_bf8): Rename to _mm256_maskz_cvts_ph_bf8.
(_mm_cvtsph_hf8): Rename to _mm_cvts_ph_hf8.
(_mm_mask_cvtsph_hf8): Rename to _mm_mask_cvts_ph_hf8.
(_mm_maskz_cvtsph_hf8): Rename to _mm_maskz_cvts_ph_hf8.
(_mm256_cvtsph_hf8): Rename to _mm256_cvts_ph_hf8.
(_mm256_mask_cvtsph_hf8): Rename to _mm256_mask_cvts_ph_hf8.
(_mm256_maskz_cvtsph_hf8): Rename to _mm256_maskz_cvts_ph_hf8.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx10_2-512-convert-1.c: Modify function name
to follow the latest version.
* gcc.target/i386/avx10_2-512-vcvt2ph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvt2ph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtbiasph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtph2hf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-convert-1.c: Ditto.

4 months agoDaily bump.
GCC Administrator [Wed, 26 Mar 2025 00:17:07 +0000 (00:17 +0000)] 
Daily bump.

4 months agocobol: Changes to eliminate _Float128 from the front end [PR119241]
Bob Dubner [Tue, 25 Mar 2025 19:38:38 +0000 (15:38 -0400)] 
cobol: Changes to eliminate _Float128 from the front end [PR119241]

These changes switch _Float128 types to REAL_VALUE_TYPE in the front end.
Some __int128 variables and function return values are changed to
FIXED_WIDE_INT(128)

gcc/cobol

PR cobol/119241
* cdf.y: (cdfval_base_t::operator()): Return const.
* cdfval.h: (struct cdfval_base_t): Add const cdfval_base_t&
operator().
(struct cdfval_t): Add cdfval_t constructor.  Change cdf_value
definitions.
* gcobolspec.cc (lang_specific_driver): Formatting fix.
* genapi.cc: Include fold-const.h and realmpfr.h.
(initialize_variable_internal): Use real_to_decimal instead of
strfromf128.
(get_binary_value_from_float): Use wide_int_to_tree instead of
build_int_cst_type.
(psa_FldLiteralN): Use fold_convert instead of strfromf128,
real_from_string and build_real.
(parser_display_internal): Rewritten to work on REAL_VALUE_TYPE
rather than _Float128.
(mh_source_is_literalN): Use FIXED_WIDE_INT(128) rather than
__int128, wide_int_to_tree rather than build_int_cst_type,
fold_convert rather than build_string_literal.
(real_powi10): New function.
(binary_initial_from_float128): Change type of last argument from
_Float128 to REAL_VALUE_TYPE, process it using real.cc and mpfr
APIs.
(digits_from_float128): Likewise.
(initial_from_float128): Make static.  Remove value argument, add
local REAL_VALUE_TYPE value variable instead, process it using
real.cc and native_encode_expr APIs.
(parser_symbol_add): Adjust initial_from_float128 caller.
* genapi.h (initial_from_float128): Remove declaration.
* genutil.cc (get_power_of_ten): Change return type from __int128
to FIXED_WIDE_INT(128), ditto for retval type, change type of pos
from __int128 to unsigned long long.
(scale_by_power_of_ten_N): Use wide_int_to_tree instead of
build_int_cst_type.  Use FIXED_WIDE_INT(128) instead of __int128
as power_of_ten variable type.
(copy_little_endian_into_place): Likewise.
* genutil.h (get_power_of_ten): Change return type from __int128
to FIXED_WIDE_INT(128).
* parse.y (%union): Change type of float128 from _Float128 to
REAL_VALUE_TYPE.
(string_of): Change argument type from _Float128 to
const REAL_VALUE_TYPE &, use real_to_decimal rather than
strfromf128.  Add another overload with tree argument type.
(field: cdf): Use real_zerop rather than comparison against 0.0.
(occurs_clause, const_value): Use real_to_integer.
(value78): Use build_real and real_to_integer.
(data_descr1): Use real_to_integer.
(count): Use real_to_integer, real_from_integer and real_identical
instead of direct comparison.
(value_clause): Use real_from_string3 instead of num_str2i.  Use
real_identical instead of direct comparison.  Use build_real.
(allocate): Use real_isneg and real_iszero instead of <= 0 comparison.
(move_tgt): Use real_to_integer, real_value_truncate,
real_from_integer and real_identical instead of comparison of casts.
(cce_expr): Use real_arithmetic and real_convert or real_value_negate
instead of direct arithmetics on _Float128.
(cce_factor): Use real_from_string3 instead of numstr2i.
(literal_refmod_valid): Use real_to_integer.
* symbols.cc (symbol_table_t::registers_t::registers_t): Formatting
fix.
(ERROR_FIELD): Likewise.
(extend_66_capacity): Likewise.
(cbl_occurs_t::subscript_ok): Use real_to_integer, real_from_integer
and real_identical.
* symbols.h (cbl_field_data_t::etc_t::value): Change type from
_Float128 to tree.
(cbl_field_data_t::etc_t::etc_t): Adjust defaulted argument value.
(cbl_field_data_t::cbl_field_data_t): Formatting fix.  Use etc()
rather than etc(0).
(cbl_field_data_t::value_of): Change return type from _Float128 to
tree.
(cbl_field_data_t::operator=): Change return and argument type from
_Float128 to tree.
(cbl_field_data_t::valify): Use real_from_string, real_value_truncate
and build_real.
(cbl_field_t::same_as): Use build_zero_cst instead of _Float128(0.0).

gcc/testsuite

* cobol.dg/literal1.cob: New testcase.
* cobol.dg/output1.cob: Likewise

Co-authored-by: Richard Biener <rguenth@suse.de>
Co-authored-by: Jakub Jelinek <jakub@redhat.com>
Co-authored-by: James K. Lowden <jklowden@cobolworx.com>
Co-authored-by: Robert Dubner <rdubher@symas.com>
4 months agoc++: add fixed test [PR101881]
Marek Polacek [Tue, 25 Mar 2025 19:40:25 +0000 (15:40 -0400)] 
c++: add fixed test [PR101881]

Fixed recently by r15-7822.

PR c++/101881

gcc/testsuite/ChangeLog:

* g++.dg/ext/vector44.C: New test.

4 months agoc++: Properly fold <COND_EXPR>.*<COMPONENT> [PR114525]
Simon Martin [Tue, 25 Mar 2025 19:11:19 +0000 (20:11 +0100)] 
c++: Properly fold <COND_EXPR>.*<COMPONENT> [PR114525]

We've been miscompiling the following since r0-51314-gd6b4ea8592e338 (I
did not go compile something that old, and identified this change via
git blame, so might be wrong)

=== cut here ===
struct Foo { int x; };
Foo& get (Foo &v) { return v; }
void bar () {
  Foo v; v.x = 1;
  (true ? get (v) : get (v)).*(&Foo::x) = 2;
  // v.x still equals 1 here...
}
=== cut here ===

The problem lies in build_m_component_ref, that computes the address of
the COND_EXPR using build_address to build the representation of
  (true ? get (v) : get (v)).*(&Foo::x);
and gets something like
  &(true ? get (v) : get (v))  // #1
instead of
  (true ? &get (v) : &get (v)) // #2
and the write does not go where want it to, hence the miscompile.

This patch replaces the call to build_address by a call to
cp_build_addr_expr, which gives #2, that is properly handled.

PR c++/114525

gcc/cp/ChangeLog:

* typeck2.cc (build_m_component_ref): Call cp_build_addr_expr
instead of build_address.

gcc/testsuite/ChangeLog:

* g++.dg/expr/cond18.C: New test.

4 months agotoplevel, libcobol: Add dependency on libquadmath build [PR119244].
Iain Sandoe [Tue, 25 Mar 2025 16:20:58 +0000 (16:20 +0000)] 
toplevel, libcobol: Add dependency on libquadmath build [PR119244].

For the configuration of libgcobol to be correct for targets that need
to use libquadmath for 128b FP support, we must be able to find the
quadmath library (or not, for targets that have the support in libc).

PR cobol/119244

ChangeLog:

* Makefile.def: libgcobol configure depends on libquadmath build.
* Makefile.in: Regenerate.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 months agogcc, gcov: Use 'lbasename' consistently.
Iain Sandoe [Thu, 13 Mar 2025 17:28:55 +0000 (17:28 +0000)] 
gcc, gcov: Use 'lbasename' consistently.

The 'basename' implementation can vary with the host platform (e.g. POSIX
c.f. Linux). This is the only current uses of basename() in the source
so convert them to use lbasename() as most other cases do.

gcc/ChangeLog:

* gcov.cc (get_gcov_intermediate_filename): Use lbasename().

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 months agogcc, configure: When checking for basename, use the same process as libiberty [PR119250].
Iain Sandoe [Thu, 13 Mar 2025 17:23:33 +0000 (17:23 +0000)] 
gcc, configure: When checking for basename, use the same process as libiberty [PR119250].

We need the configure result from the decl check for basename() in the GCC
configuration to match that obtained when configuring libiberty or we get
conflicts when <libgen.h> is included in any TU that also includes "system.h"
or "libiberty.h" directly.

PR other/119250

gcc/ChangeLog:

* config.in: Regenerate.
* configure: Regenerate.
* configure.ac: Match the configure test in libiberty when checking
the basename decl.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 months agolibiberty: Append <libgen.h> to AC_CHECK_DECLS [PR119218].
Iain Sandoe [Wed, 12 Mar 2025 15:04:31 +0000 (15:04 +0000)] 
libiberty: Append <libgen.h> to AC_CHECK_DECLS [PR119218].

Darwin and Solaris, at least, provide basename() in libc, but only
declare it in <libgen.h>.  That library is not one of the set in
AC_INCLUDES_DEFAULT and so we fail the config test and fall back
to the libiberty-provided version.  In itself, this is not an
issue; however, if we include <libgen.h> and libiberty.h in the same
TU we do then get a decl conflict.

PR other/119218

libiberty/ChangeLog:

* config.in: Regenerate.
* configure: Regenerate.
* configure.ac: Append <libgen.h> to AC_INCLUDES_DEFAULT
when checking for the 'basename' decl.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 months agoC prototypes for functions returning C function pointers.
Thomas Koenig [Tue, 25 Mar 2025 17:42:30 +0000 (18:42 +0100)] 
C prototypes for functions returning C function pointers.

This patch handles dumping prototypes for C functions returning
function pointers.  For the test case

MODULE test
   USE, INTRINSIC :: ISO_C_BINDING
CONTAINS
   FUNCTION lookup(idx) BIND(C)
     type(C_FUNPTR) :: lookup
     integer(C_INT), VALUE :: idx
     lookup = C_FUNLOC(x1)
   END FUNCTION lookup

   subroutine x1()
   end subroutine x1
 END MODULE test

the prototype is

void (*lookup (int idx)) ();

Regression-tested.  Again no test case because I don't know how.
During testing, I also found that vtabs were dumped, this is
also corrected.

gcc/fortran/ChangeLog:

PR fortran/119419
* dump-parse-tree.cc (write_funptr_fcn): New function.
(write_type): Invoke it for C_FUNPTR.
(write_interop_decl): Do not dump vtabs.

4 months agolibstdc++: Allow std::ranges::to to create unions
Jonathan Wakely [Tue, 25 Mar 2025 00:27:52 +0000 (00:27 +0000)] 
libstdc++: Allow std::ranges::to to create unions

LWG 4229 points out that the std::ranges::to wording refers to class
types, but I added an assertion using std::is_class_v which only allows
non-union class types. LWG consensus is that unions should be allowed,
so this additionally uses std::is_union_v.

libstdc++-v3/ChangeLog:

* include/std/ranges (ranges::to): Allow unions as well as
non-union class types.
* testsuite/std/ranges/conv/lwg4229.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agolibstdc++: Optimize std::vector construction from input iterators [PR108487]
Jonathan Wakely [Tue, 25 Mar 2025 13:24:08 +0000 (13:24 +0000)] 
libstdc++: Optimize std::vector construction from input iterators [PR108487]

LWG 3291 make std::ranges::iota_view's iterator have input_iterator_tag
as its iterator_category, even though it satisfies the C++20
std::forward_iterator concept. This means that the traditional
std::vector::vector(InputIterator, InputIterator) constructor treats
iota_view iterators as input iterators, because it only understands the
C++17 iterator requirements, not the C++20 iterator concepts. This
results in a loop that calls emplace_back for each individual element of
the iota_view, requiring the vector to reallocate repeatedly as the
values are inserted. This makes it unnecessarily slow to construct a
vector from an iota_view.

This change adds a new _M_range_initialize_n function for initializing a
vector from a range (which doesn't have to be common) and a size. This
new function can be used by vector(InputIterator, InputIterator) and
vector(from_range_t, R&&) when std::ranges::distance can be used to get
the size. It can also be used by the _M_range_initialize overload that
gets the size for a Cpp17ForwardIterator pair using std::distance, and
by the vector(initializer_list) constructor.

With this new function constructing a std::vector from iota_view does
a single allocation of the correct size and so doesn't need to
reallocate in a loop.

Previously the _M_range_initialize overload for Cpp17ForwardIterator was
using a local RAII _Guard_alloc object to own the storage, but that was
redundant. The _Vector_base can own the storage right away, and its
destructor will deallocate it if _M_range_initialize exits via an
exception.

libstdc++-v3/ChangeLog:

PR libstdc++/108487
* include/bits/stl_vector.h (vector(initializer_list)): Call
_M_range_initialize_n instead of _M_range_initialize.
(vector(InputIterator, InputIterator)): Use _M_range_initialize_n
for C++20 sized sentinels and forward iterators.
(vector(from_range_t, R&&)): Use _M_range_initialize_n for sized
ranges and forward ranges.
(vector::_M_range_initialize(FwIt, FwIt, forward_iterator_tag)):
Likewise.
(vector::_M_range_initialize_n): New function.
* testsuite/23_containers/vector/cons/108487.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agolibstdc++: Adjust how __gnu_debug::vector detects invalidation
Jonathan Wakely [Mon, 24 Mar 2025 21:21:02 +0000 (21:21 +0000)] 
libstdc++: Adjust how __gnu_debug::vector detects invalidation

The new C++23 member functions assign_range, insert_range and
append_range were checking whether the begin() iterator changed after
calling the base class member. That works, but is technically undefined
when the original iterator has been invalidated by a change in capacity.

We can just check the capacity directly, because reallocation only
occurs if a change in capacity is required.

N.B. we can't use data() either because std::vector<bool> doesn't have
it.

libstdc++-v3/ChangeLog:

* include/debug/vector (vector::assign_range): Use change in
capacity to detect reallocation.
(vector::insert_range, vector::append_range): Likewise. Remove
unused variables.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agolibstdc++: Fix std::vector::append_range for overlapping ranges
Jonathan Wakely [Fri, 21 Mar 2025 23:21:42 +0000 (23:21 +0000)] 
libstdc++: Fix std::vector::append_range for overlapping ranges

Unlike insert_range and assign_range, the append_range function does not
have a precondition that the range doesn't overlap *this. That means we
need to avoid relocating the existing elements until after copying from
the range. This means I need to revert r15-8488-g3e1d760bf49d0e which
made the from_range_t constructor use append_range, because the
constructor can avoid the additional complexity needed by append_range.
When relocating the existing elements in append_range we can use
std::__relocate_a to do it more efficiently, if that's valid.

std::vector<bool>::append_range needs similar treatment, although it's a
bit simpler as we know that the elements are trivially copyable and so
we don't need to worry about them throwing. assign_range doesn't allow
overlapping ranges, so can be rewritten to be more efficient than
calling append_range for the forward or sized range case.

libstdc++-v3/ChangeLog:

* include/bits/stl_bvector.h (vector::assign_range): More
efficient implementation for forward/sized ranges.
(vector::append_range): Handle potentially overlapping range.
* include/bits/stl_vector.h (vector(from_range_t, R&&, Alloc)):
Do not use append_range for non-sized input range case.
(vector::append_range): Handle potentially overlapping range.
* include/bits/vector.tcc (vector::insert_range): Forward range
instead of moving it.
* testsuite/23_containers/vector/bool/modifiers/insert/append_range.cc:
Test overlapping ranges.
* testsuite/23_containers/vector/modifiers/append_range.cc:
Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agoAdd support of --enable-host-pie to the native Ada compiler
Eric Botcazou [Tue, 25 Mar 2025 17:11:08 +0000 (18:11 +0100)] 
Add support of --enable-host-pie to the native Ada compiler

gcc/ada/
PR ada/119440
* gcc-interface/Make-lang.in (GCC_LINK): Filter out -pie in stage 1
(GCC_LLINK): Likewise.
* gcc-interface/Makefile.in (COMPILER): Delete and replace by CC.
(COMPILER_FLAGS): Delete.
(ALL_COMPILERFLAGS): Delete and replace by ALL_CFLAGS.
(ALL_ADAFLAGS): Move around.
(enable_host_pie): New substituted variable.
(LD_PICFLAG): Likewise.  Do not add it to TOOLS_LIBS.
(LIBIBERTY): Test enable_host_pie.
(LIBGNAT): Likewise and use libgnat_pic.a if yes.
(TOOLS_FLAGS_TO_PASS): Pass $(PICFLAG) under CFLAGS & $(LD_PICFLAG)
under LDFLAGS.  Also pass through ADA_CFLAGS.
(common-tools): Add $(ALL_CFLAGS) $(ADA_CFLAGS) to the --GCC string
of $(GNATLINK) commands.
(../../gnatdll$(exeext)): Likewise.
(gnatmake-re): Likewise.
(gnatlink-re): Likewise.
(gnatlib-shared-dual): Remove all the object files at the end.

gnattools/
PR ada/119440
* configure.ac (host-pie): New switch.
(host-bind-now): Likewise.
Substitute PICFLAG and LD_PICFLAG.
* configure: Regenerate.
* Makefile.in (PICFLAG): New substituted variable.
(LD_PICFLAG): Likewise.
(TOOLS_FLAGS_TO_PASS): Pass $(PICFLAG) under CFLAGS & $(LD_PICFLAG)
under LDFLAGS.  Do not pass -I- under ADA_INCLUDES.
(TOOLS_FLAGS_TO_PASS_RE): Likewise.

4 months agoc++: lambda, default argument, unevaluated context
yxj-github-437 [Tue, 25 Mar 2025 15:43:10 +0000 (23:43 +0800)] 
c++: lambda, default argument, unevaluated context

This patch would like to avoid the ICE when template lambdas call with
default parameters in unevaluated context. The bug is the same as
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119385. For example:

    1   | template <class T>
    2   | void foo(T x) {
    3   |   sizeof []<int=0>(T=x) { return 0; }();
    4   | }
    5   |
    6   | void test {
    7   |   foo(0);
    8   | }

when compile with -fsyntax-only -std=c++20, it will have ICE similar to

test.cc: In instantiation of 'void foo(T) [with T = int]':
test.cc:7:6:   required from here
    6 |   foo(0);
      |   ~~~^~~
test.cc:3:38: internal compiler error: in tsubst_expr, at cp/pt.cc:21919
    2 |   sizeof []<int=0>(T=x) { return 0; }();
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

And if without the template code `<int=0>`, the code will pass compile, it's
wrong.

When parsing lambda, the sizeof will affect the lambda internal unevaluated
operand being handled. So consider save/restore cp_unevaluated_operand.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_lambda_expression): Use cp_evaluated.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-uneval25.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
4 months agoarm: testsuite: skip mtp tests on thumb1
Richard Earnshaw [Tue, 25 Mar 2025 16:30:36 +0000 (16:30 +0000)] 
arm: testsuite: skip mtp tests on thumb1

These tests need access to the MRC instruction, but that isn't part of
of the Thumb1 ISA.  So skip the tests when this isn't the case.

gcc/testsuite/ChangeLog:

* gcc.target/arm/mtp_1.c: Require arm32.
* gcc.target/arm/mtp_2.c: Likewise.
* gcc.target/arm/mtp_3.c: Likewise.
* gcc.target/arm/mtp_4.c: Likewise.

4 months agoOpenMP: Create additional interop objects with append_args.
Sandra Loosemore [Tue, 25 Mar 2025 15:55:45 +0000 (15:55 +0000)] 
OpenMP: Create additional interop objects with append_args.

This patch adds support for the case where #pragma omp declare variant
with append_args is used inside a #pragma omp dispatch interop that
specifies fewer interop args than required by the variant; new interop
objects are implicitly created and then destroyed around the call to the
variant, using the GOMP_interop builtin.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant): Remove accidental
redeclaration of pref.

gcc/ChangeLog
* gimplify.cc (modify_call_for_omp_dispatch): Adjust arguments.
Remove the "sorry" for the case where new interop objects must be
constructed, and add code to make it work instead.
(expand_variant_call_expr): Adjust arguments and call to
modify_call_for_omp_dispatch.
(gimplify_variant_call_expr): Simplify logic for calling
expand_variant_call_expr.

gcc/testsuite/ChangeLog
* c-c++-common/gomp/append-args-1.c: Adjust expected behavior.
* c-c++-common/gomp/append-args-interop.c: New.
* c-c++-common/gomp/dispatch-11.c: Adjust expected behavior.
* g++.dg/gomp/append-args-1.C: Likewise.
* gfortran.dg/gomp/append-args-interop.f90: New.
* gfortran.dg/gomp/declare-variant-mod-2.f90: Adjust expected behavior.

libgomp/ChangeLog
* libgomp.texi (OpenMP 5.1): Mark append_args as fully supported.

Co-Authored-By: Tobias Burnus <tburnus@baylibre.com>
4 months agoarm: testsuite: adjust ftest tests
Richard Earnshaw [Tue, 25 Mar 2025 15:36:02 +0000 (15:36 +0000)] 
arm: testsuite: adjust ftest tests

The ftest-*.c tests for Arm check certain ACLE mandated macros to ensure
they are correctly defined based on the selected architecture.  ACLE
states that the macro should be defined if the operation exists in
the hardware, but it doesn't have to exist in the current ISA because
and interworking call to the library function will still result in using
the hardware operation (both GCC and Clang agree on this).  So adjust
the tests accordingly.

Whilst cleaning this up, also remove the now redundant dg-skip-if operations
that were testing for incompatible command-line options.  That should now
be a thing of the past as the framework will clean this up more thoroughly
before running the test, or detect incompatible option combinations.

gcc/testsuite/ChangeLog:

* gcc.target/arm/ftest-armv4t-thumb.c:  Expect __ARM_FEATURE_CLZ to be
defined.  Remove redundant dg-skip-if rules.
* gcc.target/arm/ftest-armv5t-thumb.c: Likewise.
* gcc.target/arm/ftest-armv5te-thumb.c: Likewise.
* gcc.target/arm/ftest-armv6-thumb.c: Likewise.
* gcc.target/arm/ftest-armv6k-thumb.c: Likewise.
* gcc.target/arm/ftest-armv6z-thumb.c: Likewise.
* gcc.target/arm/ftest-armv7em-thumb.c: Remove redundant dg-skip-if
rules.  Add a require-effective-target for armv7em.
* gcc.target/arm/ftest-armv7a-arm.c: Likewise.
* gcc.target/arm/ftest-armv7a-thumb.c: Likewise.
* gcc.target/arm/ftest-armv7r-arm.c: Likewise.
* gcc.target/arm/ftest-armv7r-thumb.c: Likewise.
* gcc.target/arm/ftest-armv7ve-arm.c: Likewise.
* gcc.target/arm/ftest-armv7ve-thumb.c: Likewise.
* gcc.target/arm/ftest-armv8a-arm.c: Likewise.
* gcc.target/arm/ftest-armv8a-thumb.c: Likewise.
* gcc.target/arm/ftest-armv4-arm.c: Remove redundant dg-skip-if rules.
* gcc.target/arm/ftest-armv4t-arm.c: Likewise.
* gcc.target/arm/ftest-armv5t-arm.c: Likewise.
* gcc.target/arm/ftest-armv5te-arm.c: Likewise.
* gcc.target/arm/ftest-armv6-arm.c: Likewise.
* gcc.target/arm/ftest-armv6k-arm.c: Likewise.
* gcc.target/arm/ftest-armv6m-thumb.c: Likewise.
* gcc.target/arm/ftest-armv6t2-arm.c: Likewise.
* gcc.target/arm/ftest-armv6t2-thumb.c: Likewise.
* gcc.target/arm/ftest-armv6z-arm.c: Likewise.

4 months agoi386: Fix up combination of -2 r<<= (x & 7) into btr [PR119428]
Jakub Jelinek [Tue, 25 Mar 2025 15:55:24 +0000 (16:55 +0100)] 
i386: Fix up combination of -2 r<<= (x & 7) into btr [PR119428]

The following patch is miscompiled from r15-8478 but latently already
since my r11-5756 and r11-6631 changes.
The r11-5756 change was
https://gcc.gnu.org/pipermail/gcc-patches/2020-December/561164.html
which changed the splitters to immediately throw away the masking.
And the r11-6631 change was an optimization to recognize
(set (zero_extract:HI (...) (const_int 1) (...)) (const_int 1)
as btr.

The problem is their interaction.  x86 is not a SHIFT_COUNT_TRUNCATED
target, so the masking needs to be explicit in the IL.
And combine.cc (make_field_assignment) has since 1992 optimizations
which try to optimize x &= (-2 r<< y) into zero_extract (x) = 0.
Now, such an optimization is fine if y has not been masked or if the
chosen zero_extract has the same mode as the rotate (or it recognizes
something with a left shift too).  IMHO such optimization is invalid
for SHIFT_COUNT_TRUNCATED targets because we explicitly say that
the masking of the shift/rotate counts are redundant there and don't
need to be part of the IL (I have a patch for that, but because it
is just latent, I'm not sure it needs to be posted for gcc 15 (and
also am not sure if it should punt or add operand masking just in case)).
x86 is not SHIFT_COUNT_TRUNCATED though and so even fixing combine
not to do that for SHIFT_COUNT_TRUNCATED targets doesn't help, and we don't
have QImode insv, so it is optimized into HImode insertions.  Now,
if the y in x &= (-2 r<< y) wasn't masked in any way, turning it into
HImode btr is just fine, but if it was x &= (-2 r<< (y & 7)) and we just
decided to throw away the masking, using btr changes the behavior on it
and causes e2fsprogs and sqlite miscompilations.

So IMHO on !SHIFT_COUNT_TRUNCATED targets, we need to keep the maskings
explicit in the IL, either at least for the duration of the combine pass
as does the following patch (where combine is the only known pass to have
such transformation), or even keep it until final pass in case there are
some later optimizations that would also need to know whether there was
explicit masking or not and with what mask.  The latter change would be
much larger.

The following patch just reverts the r11-5756 change and adds a testcase.

2025-03-25  Jakub Jelinek  <jakub@redhat.com>

PR target/96226
PR target/119428
* config/i386/i386.md (splitter after *<rotate_insn><mode>3_mask,
splitter after *<rotate_insn><mode>3_mask_1): Revert 2020-12-05
changes.

* gcc.c-torture/execute/pr119428.c: New test.

4 months agoRISC-V: disable the abd expander for gcc-15 release [PR119224]
Vineet Gupta [Mon, 24 Mar 2025 17:36:52 +0000 (10:36 -0700)] 
RISC-V: disable the abd expander for gcc-15 release [PR119224]

It seems the new expander triggers a latent issue in sched1 causing
extraneous spills in a different sad variant.
Given how close we are to gcc-15 release, disable it for now.

Since we do want to retain and re-enable this capabilty, manully disable
vs. reverting the orig patch which takes away the test case too.
Fix the orig test case to expect old codegen idiom (although vneg is no
longer emitted, in favor of vrsub).
Also add a new testcase which flags any future spills in the affected
routine.

PR target/119224

gcc/ChangeLog:
* config/riscv/autovec.md: Disable abd splitter.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/pr117722.c: Adjust output insn.
* gcc.target/riscv/rvv/autovec/pr119224.c: Add new test.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
4 months agoOpenMP: interop - fix Fortran test
Paul-Antoine Arras [Mon, 24 Mar 2025 14:53:36 +0000 (15:53 +0100)] 
OpenMP: interop - fix Fortran test

This fixes up commit r15-8654-g99e2906ae255fc:
* Do not use omp_lib in Fortran compile test; instead, provide needed
declarations explicitly.
* Update scan-dump patterns to be compatible with 32-bit architectures.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/interop-5.f90: Declare omp_interop_kind explicitly
instead of use'ing omp_lib. Update scan-dumps to allow for 4-byte
pointers.

4 months agoinstall.texi: gcn - suggest to use Newlib with simd math fix [PR119325]
Tobias Burnus [Tue, 25 Mar 2025 14:07:56 +0000 (15:07 +0100)] 
install.texi: gcn - suggest to use Newlib with simd math fix [PR119325]

Suggest a Newlib with a fix for the SIMD math issue.  Newlib commit:
https://sourceware.org/git/?p=newlib-cygwin.git;a=commitdiff;h=2ef1a37e7

Additionally, for generic support in ROCm, it is expected that 6.4 will
added the support; the current version is 6.3.3 and it does not support it;
bump >6.3.2 to >6.3.3 in install.texi to avoid doubts.

gcc/ChangeLog:

PR middle-end/119325

* doc/install.texi (gcn): Change ROCm > 6.3.2 to >6.3.3 for generic
support; mention Newlib commit that fixes a SIMD math issue.

4 months agoomp-general.cc: Remove 'if' around call to always 'true' returning function [PR118627]
Tobias Burnus [Tue, 25 Mar 2025 14:02:54 +0000 (15:02 +0100)] 
omp-general.cc: Remove 'if' around call to always 'true' returning function [PR118627]

Before omp_parse_access_method and omp_parse_access_methods unconditionally
returned true, now they are void functions.
Accordingly, calls had to be updated by removing the 'if' around the call;
this also fixes Clang's -Wsometimes-uninitialized warning when compiling
omp-general.cc as one variable remained uninitialized for a never occurring
false.

gcc/ChangeLog:

PR middle-end/118627

* omp-general.cc (omp_parse_access_method): Change to return void.
(omp_parse_access_methods): Return void; remove 'if' around a
function call.
(omp_parse_expr): Remove 'if' around a function call.

4 months agoarm: testsuite: avoid dg-options in primary LTO file
Richard Earnshaw [Tue, 25 Mar 2025 13:48:06 +0000 (13:48 +0000)] 
arm: testsuite: avoid dg-options in primary LTO file

As the primary LTO file in this test, it cannot use dg-options.  Move
the flags from there to dg-lto-options.

gcc/testsuite/ChangeLog:

* gcc.target/arm/lto/pr96939_0.c (dg-options):  Delete.  Move the
options from here ...
(dg-lto-options): ... to here.

4 months agoarm: testsuite: update expected output in vect-early-break-cbranch.c
Richard Earnshaw [Tue, 25 Mar 2025 13:31:54 +0000 (13:31 +0000)] 
arm: testsuite: update expected output in vect-early-break-cbranch.c

Similar to r15-4930-gd56d2f3102ada3, update the branch operations when not
using CBN?Z for inverting the direction of the branch operations.

gcc/testsuite/ChangeLog:

* gcc.target/arm/vect-early-break-cbranch.c: Allow BEQ as well as BNE.

4 months agoarm: testsuite use -std=gnu17 for pr65647.c
Richard Earnshaw [Tue, 25 Mar 2025 13:18:06 +0000 (13:18 +0000)] 
arm: testsuite use -std=gnu17 for pr65647.c

This test has missing prototypes.  To avoid disturbing the test, use gnu17.

gcc/testsuite/ChangeLog:

* gcc.target/arm/pr65647.c (dg-options): Add -std=gnu17.

4 months agotestsuite: aarch64: arm: Remove redundant dg-do run in advsimd-intrinsics tests
Christophe Lyon [Fri, 14 Mar 2025 13:12:08 +0000 (13:12 +0000)] 
testsuite: aarch64: arm: Remove redundant dg-do run in advsimd-intrinsics tests

Tests under advsimd-intrinsics are controlled by
advsimd-intrinsics.exp which computes the adequate dg-do-what
depending on the actual target, it should not be redefined in the
tests, except when the action can never be 'run'.

This currently makes no difference, but it would when we remove
dg-skip-if for arm targets from tests that could at least be compiled
(e.g. vst1x2.c)

gcc/testsuite/

* gcc.target/aarch64/advsimd-intrinsics/vabdh_f16_1.c: Remove
dg-do directive.
* gcc.target/aarch64/advsimd-intrinsics/vabsh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vaddh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcageh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcagth_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcaleh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcalth_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vceqh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vceqzh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcgeh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcgezh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcgth_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcgtzh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcleh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vclezh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vclth_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcltzh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtah_s16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtah_s32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtah_s64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtah_u16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtah_u32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtah_u64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_f16_s16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_f16_s32_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_f16_s64_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_f16_u16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_f16_u32_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_f16_u64_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_f16_s16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_f16_s32_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_f16_s64_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_f16_u16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_f16_u32_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_f16_u64_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_s16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_s32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_s64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_u16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_u32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_n_u64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_s16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_s32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_s64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_u16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_u32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvth_u64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtmh_s16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtmh_s32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtmh_s64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtmh_u16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtmh_u32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtmh_u64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtnh_s16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtnh_s32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtnh_s64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtnh_u16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtnh_u32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtnh_u64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtph_s16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtph_s32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtph_s64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtph_u16_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtph_u32_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vcvtph_u64_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vdiv_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vdivh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vduph_lane.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vfmah_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vfmas_lane_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vfmas_n_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vfmash_lane_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vfmsh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vld1x2.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vld1x3.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vld1x4.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmaxh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmaxnmh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmaxnmv_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmaxv_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vminh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vminnmh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vminnmv_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vminv_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmul_lane_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmulh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmulh_lane_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmulx_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmulx_lane_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmulx_n_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmulxh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vmulxh_lane_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vnegh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vpminmaxnm_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vqrshrn_high_n.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vqrshrun_high_n.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vqshrn_high_n.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vqshrun_high_n.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrecpeh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrecpsh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrecpxh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrndah_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrndh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrndi_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrndih_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrndmh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrndnh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrndph_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrndxh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrsqrteh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vrsqrtsh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vsqrt_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vsqrth_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vst1x2.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vst1x3.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vst1x4.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vsubh_f16_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vtrn_half.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vuzp_half.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vzip_half.c: Likewise.

4 months agotestsuite: aarch64: restore torture options in vml[as]_float_not_used.c
Christophe Lyon [Mon, 17 Mar 2025 23:38:50 +0000 (23:38 +0000)] 
testsuite: aarch64: restore torture options in vml[as]_float_not_used.c

Remove dg-options, so that the test is executed as expected using the
options defined by advsimd-intrinsics.exp.

gcc/testsuite/
* gcc.target/aarch64/advsimd-intrinsics/vmla_float_not_fused.c:
Remove dg-options.
* gcc.target/aarch64/advsimd-intrinsics/vmls_float_not_fused.c:
Likewise.

4 months agotestsuite: aarch64: restore torture options in bf16_dup.c
Christophe Lyon [Mon, 17 Mar 2025 23:37:25 +0000 (23:37 +0000)] 
testsuite: aarch64: restore torture options in bf16_dup.c

Remove dg-options, so that the test is executed as expected using the
options defined by advsimd-intrinsics.exp.
(Previously we pretend we do, but in fact all torture options are
silently overriden with -O2)

We skip it at -O0, because the tested optimizations does not take
place at this level.

gcc/testsuite/
* gcc.target/aarch64/advsimd-intrinsics/bf16_dup.c: Remove
dg-options.

4 months agotestsuite: aarch64: arm: move saturating_arithmetic_autovect tests to simd/
Christophe Lyon [Tue, 18 Mar 2025 14:56:41 +0000 (14:56 +0000)] 
testsuite: aarch64: arm: move saturating_arithmetic_autovect tests to simd/

These tests force dg-options because they rely on -ftree-vectorize and
do not make use of torture options, so move them to simd/ where they
belong.

gcc/testsuite/
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect.inc:
Move to gcc.target/aarch64/simd/.
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_1.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_2.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_3.c: Likewise.
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_4.c: Likewise.

4 months agotestsuite: arm: remove duplicate -mcpu=unset in arm_v8_1_lob_ok
Christophe Lyon [Wed, 19 Mar 2025 10:59:04 +0000 (10:59 +0000)] 
testsuite: arm: remove duplicate -mcpu=unset in arm_v8_1_lob_ok

This was probably a typo / oversight.

gcc/testsuite/
* lib/target-supports.exp
(check_effective_target_arm_v8_1_lob_ok): Remove duplicate
-mcpu=unset.

4 months agolibstdc++: Add testcase for std::filesystem::copy [PR118699]
Jonathan Wakely [Thu, 30 Jan 2025 17:02:47 +0000 (17:02 +0000)] 
libstdc++: Add testcase for std::filesystem::copy [PR118699]

This was fixed last year by r15-2409-g017e3f89b081e4 (and backports), so
just add the testcase.

libstdc++-v3/ChangeLog:

PR libstdc++/118699
* testsuite/27_io/filesystem/operations/copy.cc: Check copying a
file to a directory.

4 months agoarm: add commutative alternatives to <US>mull pattern.
Richard Earnshaw [Tue, 25 Mar 2025 11:50:30 +0000 (11:50 +0000)] 
arm: add commutative alternatives to <US>mull pattern.

Prior to Armv6, the SMULL and UMULL instructions, which have the form

     UMULL Rdlo, Rdhi, Rm, Rs

had an operand restriction such that Rdlo, Rdhi and Rm must all be
different registers.  Rs, however can overlap either of the
destination registers.  Add some register-tie alternatives to allow
the register allocator to find these forms without having to use
additional register moves.

In addition to this, the test is pretty meaningless on Thumb-1 targets
as the S/UMULL instructions do not exist in a 16-bit encoding.  So skip
the test in this case.

gcc/ChangeLog:

* config/arm/arm.md (<US>mull): Add alternatives that allow Rs
to be tied to either Rdlo or Rdhi.

gcc/testsuite/ChangeLog:

* gcc.target/arm/pr42575.c: Skip test if thumb1.

4 months agoopcodes: fix wrong code in expand_binop_directly [PR117811]
Richard Earnshaw [Thu, 20 Mar 2025 14:42:59 +0000 (14:42 +0000)] 
opcodes: fix wrong code in expand_binop_directly [PR117811]

If expand_binop_directly fails to add a REG_EQUAL note it tries to
unwind and restart.  But it can unwind too far if expand_binop changed
some of the operands before calling it.  We don't need to unwind that
far anyway since we should end up taking exactly the same route next
time, just without a target rtx.

To fix this we remove LAST from the argument list and let the callers
(all in expand_binop) do their own unwinding if the call fails.
Instead we unwind just as far as the entry to expand_binop_directly
and recurse within this function instead of all the way back up.

gcc/ChangeLog:

PR middle-end/117811
* optabs.cc (expand_binop_directly): Remove LAST as an argument,
instead record the last insn on entry.  Only delete insns if
we need to restart and restart by calling ourself, not expand_binop.
(expand_binop): Update callers to expand_binop_directly.  If it
fails to expand the operation, delete back to LAST.

gcc/testsuite:

PR middle-end/117811
* gcc.dg/torture/pr117811.c: New test.

4 months agolibstdc++: Cast -1 to size_t in <format> [PR119429]
Jonathan Wakely [Mon, 24 Mar 2025 21:25:20 +0000 (21:25 +0000)] 
libstdc++: Cast -1 to size_t in <format> [PR119429]

This avoids a runtime error from Clang's annoying -fsanitize=integer
(even though it's not undefined and behaves correctly).

libstdc++-v3/ChangeLog:

PR libstdc++/119429
* include/std/format (__format::_Scanner::_Scanner): Cast
default argument to size_t.

4 months agolibstdc++: Fix handling of common cpp20-only ranges for flat sets [PR119415]
Tomasz Kamiński [Mon, 24 Mar 2025 17:04:28 +0000 (18:04 +0100)] 
libstdc++: Fix handling of common cpp20-only ranges for flat sets [PR119415]

These patch add check to verify if common range iterators satisfies
Cpp17LegacyIterator requirements (__detail::__cpp17_input_iterator),
before invoking overloads of insert that accepts two iterators.
As such overloads existed before c++20 iterators were introduced,
they commonly assume existence of iterator_traits<..>::iterator_category,
and passing a cpp20-only iterators, leads to hard errors.

In case if user-defined container wants to support more efficient
insertion in such cases, it should provided insert_range method,
as in the case of standard containers.

PR libstdc++/119415

libstdc++-v3/ChangeLog:

* include/std/flat_set (_Flat_set_impl:insert_range):
Add __detail::__cpp17_input_iterator check.
* testsuite/23_containers/flat_multiset/1.cc: New tests
* testsuite/23_containers/flat_set/1.cc: New tests

Reviewed-by: Patrick Palka <ppalka@redhat.com>, Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 months agotailc: Only diagnose musttail failures during tailc or musttail passes [PR119376]
Jakub Jelinek [Tue, 25 Mar 2025 08:36:41 +0000 (09:36 +0100)] 
tailc: Only diagnose musttail failures during tailc or musttail passes [PR119376]

The following testcases FAIL because musttail failures are diagnosed
not just in the tailc or musttail passes, but also during the tailr1
and tailr2.
tailr1 pass is before IPA and in the testcases eh cleanup has not
cleaned up the IL sufficiently yet to make the musttail calls pass,
even tailr2 could be too early.

The following patch does that only during the tailc pass, and if that
pass is not actually executed, during musttail pass.
To do it only in the tailc pass, I chose to pass a new bool flag, because
while we have the opt_tailcalls argument, it is actually passed by reference
to find_tail_calls and sometimes cleared during that.
musttail calls when the new DIAG_MUSTTAIL flag is not set are handled like
any other calls, we simply silently punt on those if they can't be turned
into tail calls.

Furthermore, I had to tweak the musttail pass gate.  Previously it was
!flag_optimize_sibling_calls && f->has_musttail.  The problem is that
gate of tailr and tailc passes is
flag_optimize_sibling_calls != 0 && dbg_cnt (tail_call)
and furthermore, tailc pass is only in the normal optimization queue,
so only if not -O0 or -Og.  So when one would use tail_call dbg_cnt
with some limit, or when e.g. using -foptimize-sibling-calls with -O0 or
-Og, nothing would actually diagnose invalid musttail calls or set tail call
flags on those if they are ok.  I could insert a new PROP_ flag on whether
musttail has been handled by tailc pass, but given that we have the
cfun->has_musttail flag already and nothing after tailc/musttail passes uses
it, I think it is easier to just clear the flag when musttail failures are
diagnosed and correct ones have [[tail call]] flag added.  Expansion will
then only look at the [[tail call]] flag, it could even at the [[must tail
call]] flag, but I don't see a point to check cfun->has_musttail.

2025-03-25  Jakub Jelinek  <jakub@redhat.com>

PR ipa/119376
* tree-tailcall.cc (suitable_for_tail_opt_p): Add DIAG_MUSTTAIL
argument, propagate it down to maybe_error_musttail.
(suitable_for_tail_call_opt_p): Likewise.
(maybe_error_musttail): Add DIAG_MUSTTAIL argument.  Don't emit error
for gimple_call_must_tail_p calls if it is false.
(find_tail_calls): Add DIAG_MUSTTAIL argument, propagate it down to
maybe_error_musttail, suitable_for_tail_opt_p,
suitable_for_tail_call_opt_p and find_tail_calls calls.
(tree_optimize_tail_calls_1): Add DIAG_MUSTTAIL argument, propagate
it down to find_tail_calls and if set, clear cfun->has_musttail flag
at the end.  Rename OPT_MUSTCALL argument to OPT_MUSTTAIL.
(execute_tail_calls): Pass true to DIAG_MUSTTAIL
tree_optimize_tail_calls_1 argument.
(pass_tail_recursion::execute): Pass false to DIAG_MUSTTAIL
tree_optimize_tail_calls_1 argument.
(pass_musttail::gate): Don't test flag_optimize_sibling_calls.
(pass_musttail::execute): Pass true to DIAG_MUSTTAIL
tree_optimize_tail_calls_1 argument.

* g++.dg/torture/musttail1.C: New test.
* g++.dg/opt/musttail2.C: New test.

4 months agoPR modula2/119449 MAX of SYSTEM.REAL64 cause an ICE
Gaius Mulley [Tue, 25 Mar 2025 02:08:05 +0000 (02:08 +0000)] 
PR modula2/119449 MAX of SYSTEM.REAL64 cause an ICE

This bugfix implements MAX(REAL64) and MIN(REAL64) etc for
REAL64, REAL96 and REAL128.

gcc/m2/ChangeLog:

PR modula2/119449
* gm2-compiler/M2GCCDeclare.def (TryDeclareType): Remove tokenno
parameter.
* gm2-compiler/M2GCCDeclare.mod (TryDeclareType): Ditto.
* gm2-compiler/M2GenGCC.mod (FoldTBitsize): Remove op2 and
rename op1 as res and op3 as type.
(FoldStandardFunction): Call FoldTBitsize omitting op2.
* gm2-compiler/M2Quads.mod (GetTypeMin): Rewrite.
(GetTypeMinLower): New procedure function.
(GetTypeMax): Rewrite.
(GetTypeMaxLower): New procedure function.
* gm2-compiler/M2Range.mod (CheckCancelled): Comment out.
* gm2-compiler/M2System.mod (CreateMinMaxFor): Add realtype
parameter.
(MapType): Rewrite to use realtype.
(CreateType): Ditto.
(AttemptToCreateType): Ditto.
(MakeFixedSizedTypes): Add realtype boolean.
(InitPIMTypes): Ditto.
(InitISOTypes): Ditto.
(MakeExtraSystemTypes): Ditto.
* gm2-gcc/m2pp.cc (m2pp_nop_expr): Remove code.
* gm2-gcc/m2type.cc (IsGccRealType): New function.
(m2type_GetMinFrom): Rewrite.
(m2type_GetMaxFrom): Ditto.
(do_min_real): Declare static.
(do_max_real): Declare static.

gcc/testsuite/ChangeLog:

PR modula2/119449
* gm2/pim/pass/minmaxreal.mod: New test.
* gm2/pim/pass/minmaxreal2.mod: New test.
* gm2/pim/pass/minmaxreal3.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
4 months agoi386: Fix AVX10.2 sat cvt intrinsic.
Hu, Lin1 [Tue, 25 Mar 2025 01:24:59 +0000 (09:24 +0800)] 
i386: Fix AVX10.2 sat cvt intrinsic.

The patch aims to modify the missed fixed for vcvttph2iubs's testcase.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx10_2-512-vcvttph2iubs-2.c: Modify testcase.

4 months agoDaily bump.
GCC Administrator [Tue, 25 Mar 2025 00:19:18 +0000 (00:19 +0000)] 
Daily bump.

4 months agovect: Add assert to expand_vector_conversion [PR118616]
Andrew Pinski [Sun, 23 Mar 2025 17:38:39 +0000 (10:38 -0700)] 
vect: Add assert to expand_vector_conversion [PR118616]

In some cases (after inliing due to LTO and -O3), GCC cannot
figure out that the length of the converts vect is not empty
when supportable_indirect_convert_operation returns true. So
we get an extra warning because we loop through all but the last
entry and GCC decided that `converts.length () - 1` is -1. This
adds an assert to avoid the warning and maybe even produce slightly
better code for this function. A gcc_checking_assert would be better
here but we don't convert that into an assume attribute or
`if(!a) __builtin_unreachable();`, I filed PR 119439  for that.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/118616
gcc/ChangeLog:

* tree-vect-generic.cc (expand_vector_conversion): Add
an assert that converts vect is non empty if
supportable_indirect_convert_operation returns true.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
4 months agolibstdc++: Fix some broken links in the manual
Jonathan Wakely [Mon, 24 Mar 2025 21:28:47 +0000 (21:28 +0000)] 
libstdc++: Fix some broken links in the manual

libstdc++-v3/ChangeLog:

* doc/xml/manual/policy_data_structures_biblio.xml: Fix two
broken links.
* doc/html/manual/policy_data_structures.html: Regenerate.

4 months agolibstdc++: Add testcases for resolved bug [PR101527]
Jonathan Wakely [Mon, 24 Mar 2025 21:36:16 +0000 (21:36 +0000)] 
libstdc++: Add testcases for resolved bug [PR101527]

These tests were fixed by a front-end change r13-465-g4df735e01e3199 so
this just adds them to the testsuite to be sure we don't regress.

libstdc++-v3/ChangeLog:

PR libstdc++/101527
* testsuite/24_iterators/common_iterator/101527.cc: New test.
* testsuite/24_iterators/counted_iterator/101527.cc: New test.

4 months agoUpdate gcc hr.po, sv.po
Joseph Myers [Mon, 24 Mar 2025 20:05:34 +0000 (20:05 +0000)] 
Update gcc hr.po, sv.po

* hr.po, sv.po: Update.

4 months agolibgomp: Save OpenMP device number when initializing the interop object
Tobias Burnus [Mon, 24 Mar 2025 18:52:10 +0000 (19:52 +0100)] 
libgomp: Save OpenMP device number when initializing the interop object

The interop object (opaque object to the user, used internally in libgomp)
already had a 'device_num' member, but it was missed to actually set it.

libgomp/ChangeLog:

* target.c (gomp_interop_internal): Set the 'device_num' member
when initializing an interop object.

4 months agoc++: pack indexing and if consteval
Jason Merrill [Sat, 22 Mar 2025 14:52:14 +0000 (10:52 -0400)] 
c++: pack indexing and if consteval

The pack index is manifestly constant-evaluated, and the call to
maybe_constant_value needs to reflect that or we wrongly complain about
non-constant index if the evaluation uses if consteval.

gcc/cp/ChangeLog:

* semantics.cc (finish_type_pack_element): Pass mce_true to
maybe_constant_value.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/pack-indexing16.C: New test.

4 months agocobol: Move includes before system.h
Iain Sandoe [Sat, 15 Mar 2025 22:37:58 +0000 (22:37 +0000)] 
cobol: Move includes before system.h

This just moves an include ahead of cobol-system.h which
in turn includes system.h.

gcc/cobol/ChangeLog:

* cdf-copy.cc: Move host include before system.h

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 months agolibgomp/plugin/plugin-nvptx.c: Fix device used for stream creation
Tobias Burnus [Mon, 24 Mar 2025 15:08:20 +0000 (16:08 +0100)] 
libgomp/plugin/plugin-nvptx.c: Fix device used for stream creation

libgomp/ChangeLog:

* plugin/plugin-nvptx.c (GOMP_OFFLOAD_interop): Set context for
stream creation to use the specified device.

4 months agoRemove buffer overflow in cobol driver
Andreas Schwab [Mon, 24 Mar 2025 10:39:29 +0000 (11:39 +0100)] 
Remove buffer overflow in cobol driver

PR cobol/119390
* gcobolspec.cc (lang_specific_driver): Use pointer instead of
copying into fixed array.

4 months agotestsuite: d: Break up Wbuiltin_declaration_mismatch2.d into smaller tests
Iain Buclaw [Mon, 24 Mar 2025 13:07:49 +0000 (14:07 +0100)] 
testsuite: d: Break up Wbuiltin_declaration_mismatch2.d into smaller tests

gcc/testsuite/ChangeLog:

* gdc.dg/Wbuiltin_declaration_mismatch2.d: Split test into ...
* gdc.dg/Wbuiltin_declaration_mismatch3.d: New test.
* gdc.dg/Wbuiltin_declaration_mismatch4.d: New test.
* gdc.dg/Wbuiltin_declaration_mismatch5.d: New test.
* gdc.dg/Wbuiltin_declaration_mismatch6.d: New test.

4 months agogccrs: support generic super traits recursively
Philip Herron [Sat, 22 Mar 2025 17:40:48 +0000 (17:40 +0000)] 
gccrs: support generic super traits recursively

In order to handle generic super traits on any trait bound we need to ensure
we track the TypeBoundPredicate as part of the TraitReference instead of just
the raw TraitReferences because these will have any applied generics enplace.

Then for any TypeBoundPredicate it takes a copy of the super traits because
this is the usage of a TraitBound and we can apply generics which then need
to be recursively applied up the chain of super predicates.

The main tweak is around TypeBoundPredicate::lookup_associated_item because
we need to associate the predicate with the item we are looking up so the caller
can respect the generics correctly as well.

Fixes Rust-GCC#3502

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc: update call
* typecheck/rust-hir-trait-reference.cc (TraitReference::lookup_trait_item): track predicate
(TraitReference::is_equal): likewise
(TraitReference::is_object_safe): likewise
(TraitReference::satisfies_bound): likewise
* typecheck/rust-hir-trait-reference.h: likewise
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): track super traits
(TypeBoundPredicate::operator=): likewise
(TypeBoundPredicate::apply_generic_arguments): ensure we apply to super predicates
(TypeBoundPredicateItem::operator=): take copy of parent predicate
(TypeBoundPredicateItem::error): pass error instead of nullptr
(TypeBoundPredicateItem::is_error): update to no longer check for nullptr
(TypeBoundPredicateItem::get_parent): updated
(TypeBoundPredicateItem::get_tyty_for_receiver): likewise
(TypeBoundPredicate::get_associated_type_items): likewise
* typecheck/rust-tyty-bounds.h (class TypeBoundPredicateItem): move
* typecheck/rust-tyty-subst.cc: flag to handle placeholder Self on traits
* typecheck/rust-tyty-subst.h (class TypeBoundPredicateItem): likewise
* typecheck/rust-tyty.h (class TypeBoundPredicateItem): refactored

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-3502.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: nr2.0: Fix StructExprFieldIdentifier handling
Owen Avery [Mon, 3 Mar 2025 01:03:12 +0000 (20:03 -0500)] 
gccrs: nr2.0: Fix StructExprFieldIdentifier handling

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Add visitor for StructExprFieldIdentifier.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Adjust indentifier expression handling
Owen Avery [Wed, 19 Mar 2025 00:28:25 +0000 (20:28 -0400)] 
gccrs: nr2.0: Adjust indentifier expression handling

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Make sure to return early after a resolution
error, improve the resolution error message, fix a typo, handle
ambiguous resolutions, and remove an old comment.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Modify multiple definition error
Owen Avery [Sun, 23 Feb 2025 21:45:41 +0000 (16:45 -0500)] 
gccrs: Modify multiple definition error

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc
(ResolveExpr::visit): Modify error message.
* resolve/rust-ast-resolve-implitem.h
(ResolveToplevelImplItem::visit): Likewise.
(ResolveTopLevelTraitItems::visit): Likewise.
(ResolveToplevelExternItem::visit): Likewise.
* resolve/rust-ast-resolve-stmt.cc
(ResolveStmt::visit): Likewise.
* resolve/rust-ast-resolve-stmt.h
(ResolveStmt::visit): Likewise.
* resolve/rust-ast-resolve-toplevel.h
(ResolveTopLevel::visit): Likewise.
* resolve/rust-ast-resolve-type.h
(ResolveGenericParams::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.
* rust/compile/redef_error2.rs: Modify expected error.
* rust/compile/redef_error5.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Adjust visitors for struct expressions
Owen Avery [Sun, 9 Feb 2025 08:28:43 +0000 (03:28 -0500)] 
gccrs: nr2.0: Adjust visitors for struct expressions

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Make sure to always visit the struct
name.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Avoid visiting the struct name twice.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Prevent multiple resolution insertion
Owen Avery [Wed, 26 Feb 2025 14:56:42 +0000 (09:56 -0500)] 
gccrs: Prevent multiple resolution insertion

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc
(DeriveClone::clone_impl): Avoid using the same node id multiple
times.
(DeriveClone::clone_enum_identifier): Likewise.
(DeriveClone::clone_enum_tuple): Likewise.
* expand/rust-derive-copy.cc
(DeriveCopy::copy_impl): Likewise.
* resolve/rust-ast-resolve-item.cc
(flatten_list): Likewise.
* resolve/rust-ast-resolve-path.cc
(ResolvePath::resolve_path): Prevent reinsertion of resolutions.
* resolve/rust-ast-resolve-type.cc
(ResolveRelativeTypePath::go): Likewise.
* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* resolve/rust-name-resolver.cc
(Resolver::insert_resolved_name): Catch multiple resolution
insertions.
(Resolver::insert_resolved_type): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Fix test self-path2.rs
Owen Avery [Sun, 9 Feb 2025 20:16:59 +0000 (15:16 -0500)] 
gccrs: nr2.0: Fix test self-path2.rs

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-path.cc
(ResolvePath::resolve_path): Adjust the error message for a lower
self segment in the middle of a path.
* resolve/rust-ast-resolve-type.cc
(ResolveRelativeTypePath::go): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove self-path2.rs
* rust/compile/self-path2.rs: Adjust expected errors.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: emit an error for type or const parameters on foreign items
Ryutaro Okada [Fri, 14 Mar 2025 12:25:03 +0000 (21:25 +0900)] 
gccrs: emit an error for type or const parameters on foreign items

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
emit an error for type or const parameters on foreign items

gcc/testsuite/ChangeLog:

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

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
4 months agogccrs: Fix modules with same name as builtins causing ICE (#3315)
Liam Naddell [Tue, 11 Feb 2025 21:42:41 +0000 (16:42 -0500)] 
gccrs: Fix modules with same name as builtins causing ICE (#3315)

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h (ForeverStack): Add a dedicated prelude node for
the Language prelude
* resolve/rust-forever-stack.hxx (ForeverStack): Add support code for the
prelude node
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Move
language prelude builtins to the prelude context
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::scoped): Add code for handling
the prelude corner case
* resolve/rust-rib.h (Rib::Kind): Add a special Prelude rib type

gcc/testsuite/ChangeLog:

* rust/compile/issue-3315-1.rs: Add test for module with same name
as builtin
* rust/compile/issue-3315-2.rs: Test with utilization of i32
type
* rust/compile/nr2/exclude: issue-3315-2.rs Does not work with
NR2.0

Signed-off-by: Liam Naddell <liamnprg@gmail.com>
4 months agogccrs: nr2.0: Check compile/torture/*.rs tests
Owen Avery [Sun, 2 Mar 2025 23:54:37 +0000 (18:54 -0500)] 
gccrs: nr2.0: Check compile/torture/*.rs tests

gcc/testsuite/ChangeLog:

* rust/compile/nr2/compile.exp: Adjust to cover tests in the
torture subdirectory.
* rust/compile/nr2/exclude: Add entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Remove mangling tests from exclusion list
Pierre-Emmanuel Patry [Tue, 11 Mar 2025 13:35:04 +0000 (14:35 +0100)] 
gccrs: Remove mangling tests from exclusion list

Those tests are now passing.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove two mangling tests from exclusion
file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fix canonical path parent resolution
Pierre-Emmanuel Patry [Tue, 11 Mar 2025 13:33:05 +0000 (14:33 +0100)] 
gccrs: Fix canonical path parent resolution

The algorithm was comparing using the wrong id, this lead to some
mangling errors as an erroneous parent was selected.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Fix the id comparison.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Insert crate name in canonical path
Pierre-Emmanuel Patry [Mon, 10 Mar 2025 15:05:18 +0000 (16:05 +0100)] 
gccrs: Insert crate name in canonical path

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Insert a new segment with the crate's
name as canonical's path prefix.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add a function to get the crate number from node id
Pierre-Emmanuel Patry [Mon, 10 Mar 2025 14:13:27 +0000 (15:13 +0100)] 
gccrs: Add a function to get the crate number from node id

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::lookup_crate_num): Add function to
retrieve crate number from it's node id.
(Mappings::node_is_crate): change function with call to
lookup_crate_num to avoid looping through all crates.
(Mappings::insert_ast_crate): Populate node id to crate number map.
* util/rust-hir-map.h: Change function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove finalize import visitor
Pierre-Emmanuel Patry [Thu, 13 Mar 2025 14:18:58 +0000 (15:18 +0100)] 
gccrs: Remove finalize import visitor

This visitor is not used anymore.

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.cc (FinalizeImports::FinalizeImports):
Remove constructor.
(FinalizeImports::go): Remove function.
(FinalizeImports::visit): Likewise.
* resolve/rust-finalize-imports-2.0.h (class FinalizeImports): Remove
FinalizeImports class.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove tests from exclusion list
Pierre-Emmanuel Patry [Thu, 13 Mar 2025 13:51:53 +0000 (14:51 +0100)] 
gccrs: Remove tests from exclusion list

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove issue-1786 and issue-3033 from
exclusion list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Move import mapping resolution to in tree visit
Pierre-Emmanuel Patry [Thu, 13 Mar 2025 12:41:38 +0000 (13:41 +0100)] 
gccrs: Move import mapping resolution to in tree visit

Import mapping was relying on resolve_path which in turn relies on
the cursor function. This means the mapping resolver should be called
from the correct scope instead of being called from the crate scope.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::Early): Move the
top level visitor from the function scope to attributes.
(Early::go): Remove top level visitor creation and adapt calling code.
Remove call to mapping resolution and import finalization.
(Early::finalize_simple_import): Move the finalization from it's
visitor.
(Early::finalize_glob_import): Likewise.
(Early::finalize_rebind_import): Likewise.
(Early::visit): Add mapping resolution and finalization in
UseDeclaration visitor function.
* resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Move
function.
(finalize_glob_import): Likewise.
(finalize_rebind_import): Likewise.
(FinalizeImports::visit): Remove call to finalizers.
* resolve/rust-early-name-resolver-2.0.h (class Early): Add top level
attribute.
* resolve/rust-finalize-imports-2.0.h: Add function prototypes.
* resolve/rust-toplevel-name-resolver-2.0.h: Change getter return type
to reference.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: check for recursion trait cycle with bounds checks
Philip Herron [Wed, 12 Mar 2025 17:03:25 +0000 (17:03 +0000)] 
gccrs: check for recursion trait cycle with bounds checks

We need to be careful when doing bounds check as to not create a recusive
trait resolution. This patch checks for that case and fixes a bad type
is equal check on ADT Types which was caught with a regression here.

Fixes Rust-GCC#3126

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::ResolveHirItem): new helper
* typecheck/rust-hir-trait-resolve.h: add helper prototype
* typecheck/rust-type-util.cc (query_type): add debug
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): check for recursion
* typecheck/rust-tyty.cc (VariantDef::is_equal): fix is equal check

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-3126.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: track DefId on ADT Types this could be useful information
Philip Herron [Tue, 18 Feb 2025 17:45:58 +0000 (17:45 +0000)] 
gccrs: track DefId on ADT Types this could be useful information

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): track DefId of origin
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): likewise
(ADTType::ADTType): likewise
(ADTType::get_id): likewise
(ADTType::clone): likewise
* typecheck/rust-tyty.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: remove visitor which is not needed here
Philip Herron [Tue, 18 Feb 2025 17:44:05 +0000 (17:44 +0000)] 
gccrs: remove visitor which is not needed here

Just a small refactor to remove a visitor which is not needed.

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::Compile): remove visitor
(ResolvePathRef::ResolvePathRef): likewise
(ResolvePathRef::visit): likewise
* backend/rust-compile-resolve-path.h (class ResolvePathRef): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix some small issues
Owen Avery [Tue, 11 Mar 2025 16:03:34 +0000 (12:03 -0400)] 
gccrs: Fix some small issues

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc
(assume_handler): Fix copy/paste error.
* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): Fix spelling mistake.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add a test for enum variant name resolution
Pierre-Emmanuel Patry [Wed, 5 Mar 2025 10:56:49 +0000 (11:56 +0100)] 
gccrs: Add a test for enum variant name resolution

Highlight the fact that a value inside an enum definition refers to
a struct outside of the enum and not to the enum variant's name
directly.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove nr2 exhaustiveness test from exclusion list
Pierre-Emmanuel Patry [Tue, 4 Mar 2025 17:12:14 +0000 (18:12 +0100)] 
gccrs: Remove nr2 exhaustiveness test from exclusion list

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add enum variant string information to definition
Pierre-Emmanuel Patry [Tue, 4 Mar 2025 15:59:11 +0000 (16:59 +0100)] 
gccrs: Add enum variant string information to definition

New enum variant status now appears in the string representation of
the resolver's definition.

gcc/rust/ChangeLog:

* resolve/rust-rib.cc (Rib::Definition::to_string): Add enum variant
status.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Keep definition provenance to skip enum variants
Pierre-Emmanuel Patry [Tue, 4 Mar 2025 15:41:48 +0000 (16:41 +0100)] 
gccrs: Keep definition provenance to skip enum variants

Enum variants shouldn't be accessed directly even from within an enum.
This commit keeps the provenance for enum variants definition so we
can skip them when resolving a value within an enum definition.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Add new function to insert enum
variants and add argument to resolver's get function to explicitely
skip enum variants.
* resolve/rust-forever-stack.hxx: Update function
definitions.
* resolve/rust-name-resolution-context.cc (NameResolutionContext::insert_variant):
Add function to insert enum variants.
* resolve/rust-name-resolution-context.h: Add function's prototype.
* resolve/rust-rib.cc (Rib::Definition::Definition): Add new boolean to
hint at enum variant provenance.
(Rib::Definition::is_variant): New getter for variant status.
(Rib::Definition::Shadowable): Update constructor to opt out of enum
variants.
(Rib::Definition::Globbed): Likewise.
(Rib::Definition::NonShadowable): Change constructor to forward enum
variant provenance status.
* resolve/rust-rib.h: Update function prototypes.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::insert_enum_variant_or_error_out):
Add function to insert enum variants in the name resolver.
(TopLevel::visit): Update several enum variant's visitor function
with the new enum variant name resolving code.
* resolve/rust-toplevel-name-resolver-2.0.h: Update function
prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add rib kind debug representation
Pierre-Emmanuel Patry [Thu, 27 Feb 2025 11:28:32 +0000 (12:28 +0100)] 
gccrs: Add rib kind debug representation

Rib kind had no string representation, and thus were not used in the
debug string representation.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Output rib kind.
* resolve/rust-rib.h: Add function to get string representation from
a rib kind.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: nr2.0: Set the node id of the root node
Owen Avery [Tue, 18 Feb 2025 08:56:33 +0000 (03:56 -0500)] 
gccrs: nr2.0: Set the node id of the root node

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(ForeverStack::ForeverStack): Set the node id of the root node
to that of the current crate.
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Use the node id of the root
node during resolution of crate segments.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: expansion: Correctly expand $crate metavar
Arthur Cohen [Mon, 24 Feb 2025 12:09:17 +0000 (13:09 +0100)] 
gccrs: expansion: Correctly expand $crate metavar

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc: Use new SubstituteCtx API.
* expand/rust-macro-expand.h: Likewise.
* expand/rust-macro-substitute-ctx.cc: Implement proper expansion of $crate.
* expand/rust-macro-substitute-ctx.h: Adapt APIs to take macro definition when
substituting.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Store crate information when
inserting macro definition in mappings.
(Mappings::lookup_macro_def_crate): New.
* util/rust-hir-map.h: Adapt mappings to store crate in which macros were defined.

gcc/testsuite/ChangeLog:

* rust/execute/crate-metavar1.rs: New test.
* rust/compile/crate-metavar1.rs: New test.

4 months agogccrs: nr2.0: Make sure PathInExpression is default resolved
Owen Avery [Tue, 18 Feb 2025 08:06:09 +0000 (03:06 -0500)] 
gccrs: nr2.0: Make sure PathInExpression is default resolved

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Call DefaultResolver::visit earlier, in order to
ensure it is called even if Late::visit returns early.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Reduce usage of rust-session-manager.h
Owen Avery [Sat, 1 Mar 2025 23:05:07 +0000 (18:05 -0500)] 
gccrs: Reduce usage of rust-session-manager.h

gcc/rust/ChangeLog:

* util/rust-edition.cc: New file.
* util/rust-edition.h: New file.
* Make-lang.in: Add rust-edition.o to the object list.

* ast/rust-pattern.cc: Remove inclusion of
rust-session-manager.h.
* expand/rust-macro-expand.cc: Likewise.
* expand/rust-macro-builtins-helpers.h: Likewise.

* expand/rust-macro-builtins-include.cc: Include
rust-session-manager.h.
* expand/rust-macro-builtins-utility.cc: Likewise.

* lex/rust-lex.cc: Include rust-edition.h instead of
rust-session-manager.h.
(Lexer::classify_keyword): Use get_rust_edition instead of
Session and CompileOptions.

* parse/rust-parse-impl.h: Include rust-edition.h instead of
rust-session-manager.h.
(Parser::parse_async_item): Use get_rust_edition instead of
Session and CompileOptions.

* checks/errors/rust-feature.h: Include rust-edition.h instead
of rust-session-manager.h.
(class Feature): Use Rust::Edition instead of
Rust::CompileOptions::Edition.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: session-manager: Call into DesugarQuestionMark
Arthur Cohen [Thu, 23 Jan 2025 11:46:09 +0000 (11:46 +0000)] 
gccrs: session-manager: Call into DesugarQuestionMark

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Call DesugarQuestionMark::go().

4 months agogccrs: lower: Error out when lowering ErrorPropagationExpr
Arthur Cohen [Thu, 23 Jan 2025 11:44:33 +0000 (11:44 +0000)] 
gccrs: lower: Error out when lowering ErrorPropagationExpr

Adapt functions for lowering nodes that should never reach the lowering phase to cause an
unreachable, and mark them as final so as it not possible to override them in other visitors.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc: Adapt functions for ErrorPropagationExpr and MacroInvocation.
* hir/rust-ast-lower-base.h: Mark them as final.
* hir/rust-ast-lower-expr.cc: Remove previous definition for those overrides.
* hir/rust-ast-lower-expr.h: Likewise.

4 months agogccrs: ast: Add base for desugaring try expressions
Arthur Cohen [Wed, 22 Jan 2025 17:20:37 +0000 (17:20 +0000)] 
gccrs: ast: Add base for desugaring try expressions

gcc/rust/ChangeLog:

* Make-lang.in: Compile it.
* ast/rust-desugar-question-mark.cc: New file.
* ast/rust-desugar-question-mark.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/try-expr1.rs: New test.

4 months agogccrs: Adjust unknown macro error message
Owen Avery [Tue, 25 Feb 2025 15:16:18 +0000 (10:16 -0500)] 
gccrs: Adjust unknown macro error message

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::visit): Adjust error produced when macro resolution
fails.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro43.rs: Adjust expected errors.
* rust/compile/macros/mbe/macro44.rs: Likewise.
* rust/compile/nested_macro_use2.rs: Likewise.
* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Handle lang item type path segments
Owen Avery [Sun, 9 Feb 2025 08:02:58 +0000 (03:02 -0500)] 
gccrs: nr2.0: Handle lang item type path segments

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Stop when hitting a lang
item segment.
(ForeverStack::resolve_segments): Resolve lang item segments.
(ForeverStacl::resolve_path): Handle single segment lang item
paths and add comment.
* util/rust-unwrap-segment.cc
(unwrap_segment_get_lang_item): Add.
* util/rust-unwrap-segment.h
(unwrap_segment_get_lang_item): Add.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>