]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 months agogimple-fold: Implement simple copy propagation for aggregates [PR14295]
Andrew Pinski [Fri, 21 Feb 2025 06:05:38 +0000 (22:05 -0800)] 
gimple-fold: Implement simple copy propagation for aggregates [PR14295]

This implements a simple copy propagation for aggregates in the similar
fashion as we already do for copy prop of zeroing.

Right now this only looks at the previous vdef statement but this allows us
to catch a lot of cases that show up in C++ code.

This used to deleted aggregate copies that are to the same location (PR57361)
But that was found to delete statements that are needed for aliasing markers reason.
So we need to keep them around until that is solved. Note DSE will delete the statements
anyways so there is no testcase added since we expose the latent bug in the same way.
See https://gcc.gnu.org/pipermail/gcc-patches/2025-May/685003.html for the testcase and
explaintation there.

Also adds a variant of pr22237.c which was found while working on this patch.

Changes since v1:
* v2: change check for vuse to use default definition.
      Remove dest/src arguments for optimize_agr_copyprop
      Changed dump messages slightly.
      Added stats
      Don't delete `a = a` until aliasing markers are added.

PR tree-optimization/14295
PR tree-optimization/108358
PR tree-optimization/114169

gcc/ChangeLog:

* tree-ssa-forwprop.cc (optimize_agr_copyprop): New function.
(pass_forwprop::execute): Call optimize_agr_copyprop for load/store statements.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/20031106-6.c: Un-xfail. Add scan for forwprop1.
* g++.dg/opt/pr66119.C: Disable forwprop since that does
the copy prop now.
* gcc.dg/tree-ssa/pr108358-a.c: New test.
* gcc.dg/tree-ssa/pr114169-1.c: New test.
* gcc.c-torture/execute/builtins/pr22237-1-lib.c: New test.
* gcc.c-torture/execute/builtins/pr22237-1.c: New test.
* gcc.dg/tree-ssa/pr57361.c: Disable forwprop1.
* gcc.dg/tree-ssa/pr57361-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agomatch.pd: Fold (x + y) >> 1 into IFN_AVG_FLOOR (x, y) for vectors
Pengfei Li [Wed, 4 Jun 2025 15:59:44 +0000 (16:59 +0100)] 
match.pd: Fold (x + y) >> 1 into IFN_AVG_FLOOR (x, y) for vectors

This patch folds vector expressions of the form (x + y) >> 1 into
IFN_AVG_FLOOR (x, y), reducing instruction count on platforms that
support averaging operations. For example, it can help improve the
codegen on AArch64 from:
        add     v0.4s, v0.4s, v31.4s
        ushr    v0.4s, v0.4s, 1
to:
        uhadd   v0.4s, v0.4s, v31.4s

As this folding is only valid when the most significant bit of each
element in both x and y is known to be zero, this patch checks leading
zero bits of elements in x and y, and extends get_nonzero_bits_1() to
handle uniform vectors. When the input is a uniform vector, the function
now returns the nonzero bits of its element.

Additionally, this patch adds more checks to reject vector types in bit
constant propagation (tree-bit-ccp), since tree-bit-ccp was designed for
scalar values only, and the new vector logic in get_non_zero_bits_1()
could lead to incorrect propagation results.

gcc/ChangeLog:

* match.pd: Add folding rule for vector average.
* tree-ssa-ccp.cc (get_default_value): Reject vector types.
(evaluate_stmt): Reject vector types.
* tree-ssanames.cc (get_nonzero_bits_1): Extend to handle
uniform vectors.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/acle/uhadd_1.c: New test.

2 months agocobol: Eliminate cppcheck warnings for libgcobol [PR119323]
Robert Dubner [Mon, 2 Jun 2025 22:40:28 +0000 (18:40 -0400)] 
cobol: Eliminate cppcheck warnings for libgcobol [PR119323]

I configured and ran cppcheck-2.17.0 with this config file:

<?xml version="1.0"?>
<def format="2">
  <define name="HOST_SIZE_T_PRINT_UNSIGNED" value="&quot;%ld&quot;"/>
  <define name="GCC_PRISZ" value="&quot;z&quot;"/>
  <define name="YYLTYPE" value="struct {int first_line; int first_column; int last_line; int last_column;}"/>
  <define name="__FLT128_MANT_DIG__" value="113"/>
  <define name="__FLT128_MIN_EXP__" value="-16381"/>
</def>

and this command line

cppcheck --inline-suppr --enable=all --force --language=c++ --library=$CFG \
--check-level=exhaustive \
--disable=unusedFunction \
--disable=missingInclude \
$(cat $FILES) > $RESULT 2>&1

$FILES was all of the .cc files in libgcobol.

The result was many hundreds of warnings.  The vast bulk of them were
recommendations for declaring variables as const, recommendations for
changing C-style casts to C++ casts, cheery notes about shadowed
variables, and complaints that malloc() results weren't being checked
for errors.

Two and a half days of applied OCD on my part has reduced the number of
warnings down to zero.

libgcobol/ChangeLog:

PR cobol/119323
* charmaps.cc (__gg__raw_to_ascii):  Eliminate cppcheck warnings.
(__gg__raw_to_ebcdic): Likewise.
(__gg__ebcdic_to_console): Likewise.
(__gg__console_to_ascii): Likewise.
(__gg__console_to_ebcdic): Likewise.
* common-defs.h (struct cbl_declarative_t): Likewise.
* gfileio.cc (get_filename): Likewise.
(max_value): Likewise.
(relative_file_delete_varying): Likewise.
(relative_file_delete): Likewise.
(read_an_indexed_record): Likewise.
(position_state_restore): Likewise.
(indexed_file_delete): Likewise.
(indexed_file_start): Likewise.
(sequential_file_rewrite): Likewise.
(relative_file_write_varying): Likewise.
(relative_file_write): Likewise.
(sequential_file_write): Likewise.
(indexed_file_write): Likewise.
(__io__file_write): Likewise.
(line_sequential_file_read): Likewise.
(indexed_file_read): Likewise.
(file_indexed_open): Likewise.
(__gg__file_reopen): Likewise.
* gmath.cc (conditional_stash): Likewise.
(__gg__pow): Likewise.
(multiply_int256_by_int64): Likewise.
(add_int256_to_int256): Likewise.
(divide_int256_by_int64): Likewise.
(squeeze_int256): Likewise.
(get_int256_from_qualified_field): Likewise.
(__gg__add_fixed_phase1): Likewise.
(__gg__addf1_fixed_phase2): Likewise.
(__gg__fixed_phase2_assign_to_c): Likewise.
(__gg__add_float_phase1): Likewise.
(__gg__addf1_float_phase2): Likewise.
(__gg__float_phase2_assign_to_c): Likewise.
(__gg__addf3): Likewise.
(__gg__subtractf1_fixed_phase2): Likewise.
(__gg__subtractf2_fixed_phase1): Likewise.
(__gg__subtractf1_float_phase2): Likewise.
(__gg__subtractf2_float_phase1): Likewise.
(__gg__subtractf3): Likewise.
(__gg__multiplyf1_phase1): Likewise.
(multiply_int128_by_int128): Likewise.
(__gg__multiplyf1_phase2): Likewise.
(__gg__multiplyf2): Likewise.
(shift_in_place128): Likewise.
(divide_int128_by_int128): Likewise.
(__gg__dividef1_phase2): Likewise.
(__gg__dividef23): Likewise.
(__gg__dividef45): Likewise.
* intrinsic.cc (struct input_state): Likewise.
(get_value_as_double_from_qualified_field): Likewise.
(kahan_summation): Likewise.
(variance): Likewise.
(get_all_time): Likewise.
(populate_ctm_from_date): Likewise.
(populate_ctm_from_time): Likewise.
(ftime_replace): Likewise.
(__gg__abs): Likewise.
(__gg__acos): Likewise.
(__gg__annuity): Likewise.
(__gg__asin): Likewise.
(__gg__atan): Likewise.
(__gg__byte_length): Likewise.
(__gg__char): Likewise.
(__gg__combined_datetime): Likewise.
(__gg__cos): Likewise.
(__gg__date_of_integer): Likewise.
(__gg__date_to_yyyymmdd): Likewise.
(__gg__day_of_integer): Likewise.
(__gg__day_to_yyyyddd): Likewise.
(__gg__exp): Likewise.
(__gg__exp10): Likewise.
(__gg__factorial): Likewise.
(__gg__formatted_current_date): Likewise.
(__gg__formatted_date): Likewise.
(__gg__formatted_datetime): Likewise.
(__gg__formatted_time): Likewise.
(__gg__integer): Likewise.
(__gg__integer_of_date): Likewise.
(__gg__integer_of_day): Likewise.
(__gg__integer_part): Likewise.
(__gg__fraction_part): Likewise.
(__gg__log): Likewise.
(__gg__log10): Likewise.
(__gg__max): Likewise.
(__gg__lower_case): Likewise.
(__gg__median): Likewise.
(__gg__min): Likewise.
(numval): Likewise.
(numval_c): Likewise.
(__gg__numval): Likewise.
(__gg__test_numval): Likewise.
(__gg__numval_c): Likewise.
(__gg__test_numval_c): Likewise.
(__gg__ord): Likewise.
(__gg__rem): Likewise.
(__gg__trim): Likewise.
(__gg__random): Likewise.
(__gg__reverse): Likewise.
(__gg__sign): Likewise.
(__gg__sin): Likewise.
(__gg__sqrt): Likewise.
(__gg__tan): Likewise.
(__gg__test_date_yyyymmdd): Likewise.
(__gg__test_day_yyyyddd): Likewise.
(__gg__upper_case): Likewise.
(__gg__year_to_yyyy): Likewise.
(gets_int): Likewise.
(gets_year): Likewise.
(gets_month): Likewise.
(gets_day): Likewise.
(gets_day_of_week): Likewise.
(gets_day_of_year): Likewise.
(gets_week): Likewise.
(gets_hours): Likewise.
(gets_minutes): Likewise.
(gets_seconds): Likewise.
(gets_nanoseconds): Likewise.
(fill_cobol_tm): Likewise.
(__gg__test_formatted_datetime): Likewise.
(__gg__integer_of_formatted_date): Likewise.
(__gg__seconds_from_formatted_time): Likewise.
(__gg__hex_of): Likewise.
(__gg__highest_algebraic): Likewise.
(__gg__lowest_algebraic): Likewise.
(floating_format_tester): Likewise.
(__gg__numval_f): Likewise.
(__gg__test_numval_f): Likewise.
(ismatch): Likewise.
(iscasematch): Likewise.
(strstr): Likewise.
(strcasestr): Likewise.
(strlaststr): Likewise.
(strcaselaststr): Likewise.
(__gg__substitute): Likewise.
(__gg__locale_compare): Likewise.
(__gg__locale_date): Likewise.
(__gg__locale_time): Likewise.
(__gg__locale_time_from_seconds): Likewise.
* libgcobol.cc (class ec_status_t): Likewise.
(__gg__set_truncation_mode): Likewise.
(malloc): Likewise.
(__gg__mabort): Likewise.
(__gg__resize_int_p): Likewise.
(__gg__resize_treeplet): Likewise.
(var_is_refmod): Likewise.
(value_is_too_big): Likewise.
(__gg__string_to_alpha_edited_ascii): Likewise.
(int128_to_field): Likewise.
(edited_to_binary): Likewise.
(get_binary_value_local): Likewise.
(__gg__get_date_yymmdd): Likewise.
(__gg__get_date_yyyymmdd): Likewise.
(__gg__get_date_yyddd): Likewise.
(__gg__get_yyyyddd): Likewise.
(__gg__get_date_dow): Likewise.
(get_scaled_rdigits): Likewise.
(format_for_display_internal): Likewise.
(compare_88): Likewise.
(get_float128): Likewise.
(compare_field_class): Likewise.
(compare_strings): Likewise.
(__gg__compare_2): Likewise.
(__gg__sort_table): Likewise.
(init_var_both): Likewise.
(alpha_to_alpha_move_from_location): Likewise.
(alpha_to_alpha_move): Likewise.
(__gg__move): Likewise.
(__gg__move_literala): Likewise.
(__gg__sort_workfile): Likewise.
(__gg__merge_files): Likewise.
(normalize_id): Likewise.
(inspect_backward_format_1): Likewise.
(__gg__inspect_format_1): Likewise.
(inspect_backward_format_2): Likewise.
(__gg__inspect_format_2): Likewise.
(__gg__inspect_format_4): Likewise.
(move_string): Likewise.
(__gg__string): Likewise.
(display_both): Likewise.
(__gg__display_string): Likewise.
(__gg__accept): Likewise.
(__gg__binary_value_from_qualified_field): Likewise.
(__gg__float128_from_qualified_field): Likewise.
(float128_to_int128): Likewise.
(float128_to_location): Likewise.
(__gg__set_initial_switch_value): Likewise.
(is_numeric_display_numeric): Likewise.
(is_packed_numeric): Likewise.
(is_alpha_a_number): Likewise.
(__gg__classify): Likewise.
(__gg__accept_envar): Likewise.
(__gg__set_envar): Likewise.
(command_line_plan_b): Likewise.
(__gg__get_command_line): Likewise.
(__gg__set_pointer): Likewise.
(__gg__ascii_to_internal_field): Likewise.
(__gg__internal_to_console_in_place): Likewise.
(__gg__routine_to_call): Likewise.
(__gg__fetch_call_by_value_value): Likewise.
(__gg__assign_value_from_stack): Likewise.
(__gg__literaln_alpha_compare): Likewise.
(string_in): Likewise.
(__gg__unstring): Likewise.
(local_ec_type_of): Likewise.
(struct exception_descr_t): Likewise.
(struct cbl_exception_t): Likewise.
(cbl_enabled_exception_t: Likewise.: Likewise.dump): Likewise.
(__gg__match_exception): Likewise.
(__gg__float128_from_location): Likewise.
(__gg__integer_from_float128): Likewise.
(__gg__set_exception_file): Likewise.
(__gg__func_exception_file): Likewise.
(__gg__set_exception_code): Likewise.
(__gg__is_float_infinite): Likewise.
(__gg__float32_from_128): Likewise.
(__gg__float32_from_64): Likewise.
(__gg__float64_from_128): Likewise.
(__gg__copy_as_big_endian): Likewise.
(__gg__get_figconst_data): Likewise.
(find_in_dirs): Likewise.
(__gg__function_handle_from_cobpath): Likewise.
(__gg__just_mangle_name): Likewise.
(__gg__function_handle_from_literal): Likewise.
(__gg__function_handle_from_name): Likewise.
(__gg__mirror_range): Likewise.
(__gg__deallocate): Likewise.
(__gg__allocate): Likewise.
(__gg__module_name): Likewise.
(__gg__set_env_name): Likewise.
(__gg__set_env_value): Likewise.
* libgcobol.h (__gg__mabort): Likewise.
(massert): Likewise.
(PTRCAST): Likewise.
(__gg__float128_from_location): Likewise.
(__gg__set_exception_file): Likewise.
(__gg__binary_value_from_qualified_field): Likewise.
(__gg__float128_from_qualified_field): Likewise.
* valconv.cc (__gg__realloc_if_necessary): Likewise.
(__gg__alphabet_create): Likewise.
(__gg__string_to_numeric_edited): Likewise.
(__gg__string_to_alpha_edited): Likewise.
* valconv.h: Likewise.

2 months agoext-dce: Don't refine live width with SUBREG mode if !TRULY_NOOP_TRUNCATION_MODES_P...
Xi Ruoyao [Sun, 11 May 2025 08:44:31 +0000 (16:44 +0800)] 
ext-dce: Don't refine live width with SUBREG mode if !TRULY_NOOP_TRUNCATION_MODES_P [PR 120050]

If we see a promoted subreg and TRULY_NOOP_TRUNCATION says the
truncation is not a noop, then all bits of the inner reg are live.  We
cannot reduce the live mask to that of the mode of the subreg.

gcc/ChangeLog:

PR rtl-optimization/120050
* ext-dce.cc (ext_dce_process_uses): Break early if a SUBREG in
rhs is promoted and the truncation from the inner mode to the
outer mode is not a noop when handling SETs.

2 months agoranger: Some parameter formatting fixes
Jakub Jelinek [Wed, 4 Jun 2025 15:22:58 +0000 (17:22 +0200)] 
ranger: Some parameter formatting fixes

When reading the code, I've noticed various function definitions
with misaligned parameters, they should IMHO always align below the first
character after opening ( and in most cases they do, but in some
cases they were indented more or less.  Perhaps the functions changed
name or something.

2025-06-04  Jakub Jelinek  <jakub@redhat.com>

* range-op-float.cc (range_operator::fold_range,
range_operator::op1_range, range_operator::op2_range,
range_operator::lhs_op1_relation, range_operator::lhs_op2_relation,
operator_equal::op1_range, foperator_unordered_gt::op1_range): Fix
up parameter indentation.
* range-op.cc (range_operator::fold_range, range_operator::op1_range,
range_operator::op1_op2_relation_effect,
range_operator::update_bitmask, plus_minus_ranges,
operator_bitwise_and::lhs_op1_relation): Likewise.

2 months agoranger: Add support for float <-> float casts [PR120231]
Jakub Jelinek [Wed, 4 Jun 2025 15:21:51 +0000 (17:21 +0200)] 
ranger: Add support for float <-> float casts [PR120231]

I've noticed we don't even support say float -> double and other
scalar floating point to scalar floating point conversions in the
ranger, we just end up with VARYING for those.

The following patch attempts to fix that.
The reverse cast case uses float_binary_op_range_finish e.g. because
if the result isn't infinite, then the source couldn't be infinite
either even if the reverse fold_range would suggest that.
And special cases the case of guaranteed widening cast (where
we have assurance that all the source type values are exactly
representable in the destination type; using ieee_bits for that).

2025-06-04  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/120231
* range-op-mixed.h (operator_cast::fold_range): Add overload
with 3 {,const} frange & operands.  Change parameter names and
add final override keywords for float <-> integer cast overloads.
(operator_cast::op1_range): Likewise.
* range-op-float.cc (operator_cast::fold_range): New overload
with 3 {,const} frange & operands.
(operator_cast::op1_range): Likewise.

* gcc.dg/tree-ssa/pr120231-1.c: New test.

2 months agolibstdc++: Test for formatting with empty spec for time points.
Tomasz Kamiński [Tue, 3 Jun 2025 09:40:17 +0000 (11:40 +0200)] 
libstdc++: Test for formatting with empty spec for time points.

Adding a tests for behavior of the ostream operator and the formatting
with empty chrono-spec for the chrono types. Current coverage is:
 * time point, zoned_time and local_time_format in this commit,
 * duration and hh_mm_ss in r16-1099-gac0a04b7a254fb,
 * calendar types in r16-1016-g28a17985dd34b7.

libstdc++-v3/ChangeLog:

* testsuite/std/time/format/empty_spec.cc: New tests.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agolibstdc++: Implement C++23 P1659R3 starts_with and ends_with
Patrick Palka [Wed, 4 Jun 2025 14:29:47 +0000 (10:29 -0400)] 
libstdc++: Implement C++23 P1659R3 starts_with and ends_with

This implements ranges::starts_with and ranges::ends_with from the C++23
paper P1659R3.  The corresponding_S_impl member functions take optional
optional size parameters __n1 and __n2 of the two ranges, where -1 means
the corresponding size is not known.

libstdc++-v3/ChangeLog:

* include/bits/ranges_algo.h (__starts_with_fn, starts_with):
Define.
(__ends_with_fn, ends_with): Define.
* include/bits/version.def (ranges_starts_ends_with): Define.
* include/bits/version.h: Regenerate.
* include/std/algorithm: Provide __cpp_lib_ranges_starts_ends_with.
* src/c++23/std.cc.in (ranges::starts_with): Export.
(ranges::ends_with): Export.
* testsuite/25_algorithms/ends_with/1.cc: New test.
* testsuite/25_algorithms/starts_with/1.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2 months ago[PATCH] RISC-V: Imply zicsr for svade and svadu extensions.
Dongyan Chen [Wed, 4 Jun 2025 14:03:31 +0000 (08:03 -0600)] 
[PATCH] RISC-V: Imply zicsr for svade and svadu extensions.

This patch implies zicsr for svade and svadu extensions.
According to the riscv-privileged spec, the svade and svadu extensions
are privileged instructions, so they should imply zicsr.

gcc/ChangeLog:

* config/riscv/riscv-ext.def: Imply zicsr.

2 months ago[PATCH v2] RISC-V: Add svbare extension.
Dongyan Chen [Wed, 4 Jun 2025 13:57:01 +0000 (07:57 -0600)] 
[PATCH v2] RISC-V: Add svbare extension.

This patch support svbare extension, which is an extension in RVA23 profile.
To enable GCC to recognize and process svbare extension correctly at compile time.

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension defs.
* config/riscv/riscv-ext.opt: Ditto.
* doc/riscv-ext.texi: Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-60.c: New test.

2 months agolibstdc++: Refactor __semaphore_base member functions
Jonathan Wakely [Mon, 2 Jun 2025 22:01:40 +0000 (23:01 +0100)] 
libstdc++: Refactor __semaphore_base member functions

Replace the _S_get_current and _S_do_try_acquire static member functions
with non-static member functions _M_get_current and _M_do_try_acquire.
This means they don't need the address of _M_counter passed in.

libstdc++-v3/ChangeLog:

* include/bits/semaphore_base.h (_S_get_current): Replace with
non-static _M_get_current.
(_S_do_try_acquire): Replace with non-static _M_do_try_acquire.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agolibstdc++: Fix std::counting_semaphore::acquire deadlock [PR104928]
Jonathan Wakely [Mon, 2 Jun 2025 12:06:27 +0000 (13:06 +0100)] 
libstdc++: Fix std::counting_semaphore::acquire deadlock [PR104928]

There's a deadlock in std::counting_semaphore that occurs when the
semaphore is under contention. The bug happens when one thread tries to
acquire the mutex, calling __semaphore_base::_S_do_try_acquire to
atomically decrement the counter using compare_exchange_strong. If the
counter is non-zero (and so should be possible to decrement) but another
thread changes it (either incrementing or decrementing it) then the
compare_exchange fails and _S_do_try_acquire returns false. Because that
function is used by the predicate passed to __atomic_wait_address, when
it returns false the thread does a futex wait until the value changes.
However, when the predicate is false because the compare_exchange failed
due to not matching the expected value, waiting for the value to change
is incorrect. The correct behaviour would be to retry the
compare_exchange using the new value (as long as it's still non-zero).
Waiting for the value to change again means we can block forever,
because it might never change again.

The predicate should only test the value, not also attempt to alter it,
and its return value should mean only one thing, not conflate a busy
semaphore that cannot be acquired with a contended one that can be
acquired by retrying.

The correct behaviour of __semaphore_base::_M_acquire would be to
attempt the decrement, and to retry immediately if it failed due to
contention on the variable (i.e. due to the variable not having the
expected value).  It should only wait for the value to change when the
value is zero, because that's the only time we can't decrement it.

This commit moves the _S_do_try_acquire call out of the predicate and
loops while it is false, only doing an atomic wait when the counter's
value is zero. The predicate used for the atomic wait now only checks
whether the value is decrementable (non-zero), without also trying to
perform that decrement.

In order for the caller to tell whether it should retry a failed
_S_do_try_acquire or should wait for the value to be non-zero, the value
obtained by a failed compare_exchange needs to be passed back to the
caller. _S_do_try_acquire is changed to take its parameter by reference,
so that the caller gets the new value and can check whether it's zero.

In order to avoid doing another atomic load after returning from an
atomic wait, the predicate is also changed to capture the local __val by
reference, and then assign to __val when it sees a non-zero value. That
makes the new value available to _M_acquire, so it can be passed to
_S_do_try_acquire as the expected value of the compare_exchange.
Although this means that the predicate is modifying data again, not just
checking a value, this modification is safe. It's not changing the
semaphore's counter, only changing a local variable in the caller to
avoid a redundant atomic load.

Equivalent changes are made to _M_try_acquire_until and
_M_try_acquire_for. They have the same bug, although they can escape the
deadlock if the wait is interrupted by timing out. For _M_acquire
there's no time out so it potentially waits forever.

_M_try_acquire also has the same bug, but can be simplified to just
calling _M_try_acquire_for(0ns). A timeout of zero results in calling
__wait_impl with the __spin_only flag set, so that the value is loaded
and checked in a spin loop but there is no futex wait. This means that
_M_try_acquire can still succeed under light contention if the counter
is being changed concurrently, at the cost of a little extra overhead.
It would be possible to implement _M_try_acquire as nothing more than an
atomic load and a compare_exchange, but it would fail when there is any
contention.

libstdc++-v3/ChangeLog:

PR libstdc++/104928
* include/bits/semaphore_base.h (_S_do_try_acquire): Take old
value by reference.
(_M_acquire): Move _S_do_try_acquire call out of the predicate
and loop on its result. Make the predicate capture and update
the local copy of the value.
(_M_try_acquire_until, _M_try_acquire_for): Likewise.
(_M_try_acquire): Just call _M_try_acquire_for.
* testsuite/30_threads/semaphore/104928-2.cc: New test.
* testsuite/30_threads/semaphore/104928.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoemit-rtl: Tweak validate_subreg ordered_p condition [PR120447]
Richard Sandiford [Wed, 4 Jun 2025 12:36:51 +0000 (13:36 +0100)] 
emit-rtl: Tweak validate_subreg ordered_p condition [PR120447]

In the comment trail for PR119966, I'd said that the validate_subreg
condition:

  /* The outer size must be ordered wrt the register size, otherwise
     we wouldn't know at compile time how many registers the outer
     mode occupies.  */
  if (!ordered_p (osize, regsize))
    return false;

"is also potentially relevant" for paradoxical subregs.  But I'd
forgotten an important caveat.  If the inner size is smaller than
a register, we know that the inner value will only occupy a single
register.  Although the paradoxical subreg might extend that single
register to multiple registers by padding with undefined bits,
the register size that matters for the extension is:

   REGMODE_NATURAL_SIZE (omode)

rather than regsize's:

   REGMODE_NATURAL_SIZE (imode)

The ordered check is still relevant if the inner value spans
multiple registers.

Enabling the check above for paradoxical subregs led to an ICE in the
testcase, where we tried to generate a VNx4QI paradoxical subreg of a
QI scalar.  This was previously allowed, and AFAIK worked correctly.

The patch doesn't have the effect of relaxing the condition for
non-paradoxical subregs, since:

  known_le (osize, isize) && known_le (isize, regsize)
    => known_le (osize, regsize)
    => ordered_p (osize, regsize)

So even before the patch for PR119966, the condition only existed for
the maybe_gt (isize, regsize) case.

The term "block" used in the comment is taken from the rtl.texi
documentation of subregs.

gcc/
PR rtl-optimization/120447
* emit-rtl.cc (validate_subreg): Restrict ordered_p test
between osize and regsize to cases where the inner value
occupies multiple blocks.

gcc/testsuite/
PR rtl-optimization/120447
* gcc.dg/pr120447.c: New test.

2 months agolibgomp.texi (omp_interop_*): Add note about 5.2-to-6.0 incompatibility
Tobias Burnus [Wed, 4 Jun 2025 11:25:05 +0000 (13:25 +0200)] 
libgomp.texi (omp_interop_*): Add note about 5.2-to-6.0 incompatibility

GCC uses the 6.0 types - which are unfortunately not quite compatible with
code expecting 5.1/5.2 data types.  Therefore, this commit adds a note to
hopefully reduce surprises. Namely:

For C/C++: while OpenMP 5.1 and 5.2 used 'int *ret_code', OpenMP 6.0 uses
'omp_interop_rc_t *ret_code' in omp_interop_{int,ptr,str} and 'int' instead
of 'omp_interop_rc_t ret_code' in omp_get_interop_rc_desc.

Neither C nor C++ like passing the wrong pointer type, albeit for C, GCC < 14
and clang only warn (gcc >= r14-6037-g9715c545d33b3a has an error) and
using -fpermissive turns it into a warning and -Wno-incompatible-pointer-types
silences it for C.

C++ also dislikes passing an int to an enum, albeit -fpermissive turns the
error into a warning with g++ (but not clang++). And, here, using an enum
on the caller side works with both int and enum on the callee side.

libgomp/ChangeLog:

* libgomp.texi (omp_interop_{int,ptr,str,rc_desc}): Add note about
the 'ret_code' type change in OpenMP 6.

Co-authored-by: Sandra Loosemore <sloosemore@baylibre.com>
2 months agolibstdc++: Fix format call and test formatting with empty specs for durations.
Tomasz Kamiński [Wed, 4 Jun 2025 09:05:11 +0000 (11:05 +0200)] 
libstdc++: Fix format call and test formatting with empty specs for durations.

This patches fixes an obvious error, where the output iterator argument was
missing for call to format_to, when duration with custom representation types
are used.

It's also adding the test for behavior of ostream operator and the formatting
with empty chron-spec for the chrono types. Current coverage is:
 * duration and hh_mm_ss in this commit,
 * calendar types in r16-1016-g28a17985dd34b7.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono:_M_s): Add missing
__out argument to format_to call.
* testsuite/std/time/format/empty_spec.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoRISC-V: Leverage get_vector_binary_rtx_cost to avoid code dup [NFC]
Pan Li [Wed, 4 Jun 2025 03:06:52 +0000 (11:06 +0800)] 
RISC-V: Leverage get_vector_binary_rtx_cost to avoid code dup [NFC]

Some similar code could be wrapped to func get_vector_binary_rtx_cost,
thus leverage this function to avoid code duplication.

The below test suites are passed for this patch series.
* The rv64gcv fully regression test.

gcc/ChangeLog:

* config/riscv/riscv.cc (get_vector_binary_rtx_cost): Rename
the args to scalar2vr.
(riscv_rtx_costs): Leverage above func to avoid code dup.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoUse MEM_EXPR only if MEM_P is true
H.J. Lu [Wed, 4 Jun 2025 00:48:40 +0000 (08:48 +0800)] 
Use MEM_EXPR only if MEM_P is true

On s390x, for input:

(call_insn/u 7 6 11 2 (parallel [
            (set (reg:SI 2 %r2)
                (call (subreg:QI (symbol_ref:SI ("__tls_get_offset") [flags 0x1]) 3)
                    (const_int 0 [0])))
            (clobber (reg:SI 14 %r14))
            (use (unspec:SI [
                        (const_int 0 [0])
                    ] UNSPEC_TLSLDM))
        ]) "/tmp/foo.c":12:26 2602 {*brasl_tls}
     (expr_list:REG_EH_REGION (const_int -2147483648 [0xffffffff80000000])
        (nil))
    (expr_list (use (reg:SI 2 %r2))
        (expr_list (use (reg:SI 12 %r12))
            (nil))))

after r16-1041-g2da641d0170090, get_call_rtx_from returns:

(call (subreg:QI (symbol_ref:SI ("__tls_get_offset") [flags 0x1]) 3)
    (const_int 0 [0]))

and we got

Program received signal SIGSEGV, Segmentation fault.
0x000000000131174f in prepare_call_arguments (
    bb=<basic_block 0x7fffe99dfba0 (2)>, insn=0x7fffe980cc60)
    at /export/gnu/import/git/sources/gcc/gcc/var-tracking.cc:6277
6277 fndecl = MEM_EXPR (XEXP (call, 0));
(gdb) bt
    bb=<basic_block 0x7fffe99dfba0 (2)>, insn=0x7fffe980cc60)
    at /export/gnu/import/git/sources/gcc/gcc/var-tracking.cc:6277
    at /export/gnu/import/git/sources/gcc/gcc/var-tracking.cc:10297
    at /export/gnu/import/git/sources/gcc/gcc/var-tracking.cc:10526
    at /export/gnu/import/git/sources/gcc/gcc/var-tracking.cc:10579
    at /export/gnu/import/git/sources/gcc/gcc/var-tracking.cc:10616

Update prepare_call_arguments to check MEM_P before using MEM_EXPR.

gcc/

PR debug/120525
* var-tracking.cc (prepare_call_arguments): Use MEM_EXPR only
if MEM_P is true.

gcc/testsuite/

PR debug/120525
* gcc.dg/pr120525.c: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2 months agoFortran: Fix missing substring ref for allocatable saved vars [PR120483]
Andre Vehreschild [Mon, 2 Jun 2025 08:41:48 +0000 (10:41 +0200)] 
Fortran: Fix missing substring ref for allocatable saved vars [PR120483]

Compute a substring ref on an allocatable static character array
using pointer arithmetic.  Using an array type corrupts type
layouting and crashes omp generation.

PR fortran/120483

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_substring): Use pointer arithmetic on
static allocatable char arrays.

gcc/testsuite/ChangeLog:

* gfortran.dg/save_8.f90: New test.

2 months agoRISC-V: Add Shlcofideleg extension.
Jiawei [Tue, 27 May 2025 06:37:03 +0000 (14:37 +0800)] 
RISC-V: Add Shlcofideleg extension.

This patch add the RISC-V Shlcofideleg extension. It supports delegating
LCOFI interrupts(the count-overflow interrupts) to VS-mode.[1]

[1] https://riscv.github.io/riscv-isa-manual/snapshot/privileged

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension defs.
* config/riscv/riscv-ext.opt: Ditto.
* doc/riscv-ext.texi: Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-shlocofideleg.c: New test.

Signed-off-by: Jiawei <jiawei@iscas.ac.cn>
2 months agoi386: Add more peephole2 for APX NDD
Hu, Lin1 [Mon, 10 Mar 2025 08:52:22 +0000 (16:52 +0800)] 
i386: Add more peephole2 for APX NDD

The patch aims to optimize
         movb    (%rdi), %al
         movq    %rdi, %rbx
         xorl    %esi, %eax, %edx
         movb    %dl, (%rdi)
         cmpb    %sil, %al
 jne
to
         xorb    %sil, (%rdi)
         movq    %rdi, %rbx
 jne

Reduce 2 mov and 1 cmp instructions.

Due to APX NDD allowing the dest register and source register to be different,
some original peephole2 are invalid. Add new peephole2 patterns for APX NDD.

gcc/ChangeLog:

* config/i386/i386.md (define_peephole2): Define some new peephole2 for
APX NDD.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr49095-2.c: New test.

2 months agoi386: Add more forms peephole2 for adc/sbb
Hu, Lin1 [Wed, 19 Feb 2025 07:51:40 +0000 (15:51 +0800)] 
i386: Add more forms peephole2 for adc/sbb

Enable -mapxf will change some patterns about adc/sbb.

Hence gcc will raise an extra mov like
         movq    8(%rdi), %rax
         adcq    %rax, 8(%rsi), %rax
         movq    %rax, 8(%rdi)
rather than
         movq    8(%rsi), %rax
         adcq    %rax, 8(%rdi)

The patch add more kinds of peephole2 to eliminate the extra mov.

gcc/ChangeLog:

* config/i386/i386.md: Add 4 new peephole2 by swap the original
peephole2's operands' order to support new pattern.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr79173-13.c: New test.
* gcc.target/i386/pr79173-14.c: Ditto.
* gcc.target/i386/pr79173-15.c: Ditto.
* gcc.target/i386/pr79173-16.c: Ditto.
* gcc.target/i386/pr79173-17.c: Ditto.
* gcc.target/i386/pr79173-18.c: Ditto.

2 months agoAlways add REG_CALL_DECL note for CALL
H.J. Lu [Mon, 2 Jun 2025 21:56:37 +0000 (05:56 +0800)] 
Always add REG_CALL_DECL note for CALL

Always add REG_CALL_DECL note for CALL so that get_call_fndecl works
without -fipa-ra.

PR other/120494
* calls.cc (expand_call): Always add REG_CALL_DECL note.
(emit_library_call_value_1): Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2 months agoDaily bump.
GCC Administrator [Wed, 4 Jun 2025 00:18:13 +0000 (00:18 +0000)] 
Daily bump.

2 months agoFortran: ICE due to missing locus with data statement for coarray [PR99838]
Harald Anlauf [Tue, 3 Jun 2025 18:48:31 +0000 (20:48 +0200)] 
Fortran: ICE due to missing locus with data statement for coarray [PR99838]

PR fortran/99838

gcc/fortran/ChangeLog:

* data.cc (gfc_assign_data_value): For a new initializer use the
location from the constructor as fallback.

gcc/testsuite/ChangeLog:

* gfortran.dg/coarray_data_2.f90: New test.

2 months agoc: Enable -Wjump-misses-init for -Wc++-compat [PR120078]
Martin Uecker [Mon, 2 Jun 2025 11:57:03 +0000 (13:57 +0200)] 
c: Enable -Wjump-misses-init for -Wc++-compat [PR120078]

Fix a typo that prevented the warning from being activated with -Wc++compat.

PR c/120078

gcc/c-family/ChangeLog:
* c.opt (Wjump-misses-init): Fix typo.

gcc/testsuite/ChangeLog:
* gcc.dg/Wjump-misses-init-3.c: New test.

2 months agoc: Move checking assertions from recursion when forming composite types to avoid...
Martin Uecker [Sun, 1 Jun 2025 18:34:52 +0000 (20:34 +0200)] 
c: Move checking assertions from recursion when forming composite types to avoid ICE.

The checking assertion in composite_type_internal for structures and unions may
fail if there are self-referential types.  To avoid this, we move them out of
the recursion.  This should also be more efficient and covers other types.
We have to ignore some cases where we form composite types with qualifiers
not matching (PR120510).

gcc/c/ChangeLog:
* c-typeck.cc (composite_type_internal,composite_type): Move
checking assertions.

gcc/testsuite/ChangeLog:
* gcc.dg/gnu23-tag-composite-6.c: Update.

2 months agoc: fix ICE with enum completed with packed attribute after forward decl [PR116892]
Martin Uecker [Sun, 1 Jun 2025 20:30:42 +0000 (22:30 +0200)] 
c: fix ICE with enum completed with packed attribute after forward decl [PR116892]

After forward declaration of an enum and when completing it with the
attribute packed, we need to propagate TYPE_PACKED to all main variants.

PR c/116892

gcc/c/ChangeLog:
* c-decl.cc (finish_enum): Propagate TYPE_PACKED.

gcc/testsuite/ChangeLog:
* gcc.dg/pr116892.c: New test.

2 months agoc++: add -fno-modules to some tests
Jason Merrill [Thu, 21 Nov 2024 19:43:17 +0000 (20:43 +0100)] 
c++: add -fno-modules to some tests

These tests in the modules/ directory specifically want to test
behavior without modules enabled, so let's make that explicit.

gcc/testsuite/ChangeLog:

* g++.dg/modules/cpp-1.C
* g++.dg/modules/cpp-3.C
* g++.dg/modules/cpp-4.C: Specify -fno-modules.

2 months agoImprove create_tmp_reg_or_ssa_name, always create SSA name
Richard Biener [Tue, 3 Jun 2025 13:02:16 +0000 (15:02 +0200)] 
Improve create_tmp_reg_or_ssa_name, always create SSA name

In GIMPLE we can always use SSA names, so do that as it is cheaper.

* gimple-fold.cc (create_tmp_reg_or_ssa_name): Always
create a SSA name.

2 months agoc++: add operator| for WMB_Flags
Jason Merrill [Sat, 24 May 2025 18:41:43 +0000 (14:41 -0400)] 
c++: add operator| for WMB_Flags

There are a lot of uses of | on WMB_Flags, that currently need to then be
cast back to WMB_Flags.  Let's avoid the need for that.

gcc/cp/ChangeLog:

* name-lookup.h (operator|, operator|=): Define for WMB_Flags.

2 months agoRISC-V: Reconcile the existing test for vdiv.vx combine
Pan Li [Mon, 2 Jun 2025 13:21:18 +0000 (21:21 +0800)] 
RISC-V: Reconcile the existing test for vdiv.vx combine

Some existing vdiv related test need some adjust for the
asm check.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv-nofm.c: Adjust
the asm check for vdiv.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv.c: Ditto.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv-nofm.c: Ditto.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Add test for vec_duplicate + vdiv.vv combine case 1 with GR2VR cost 0, 1...
Pan Li [Mon, 2 Jun 2025 09:03:02 +0000 (17:03 +0800)] 
RISC-V: Add test for vec_duplicate + vdiv.vv combine case 1 with GR2VR cost 0, 1 and 2

Add asm dump check test for vec_duplicate + vdiv.vv combine to vdiv.vx,
with the GR2VR cost is 0, 1 and 2.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i16.c: Add asm check
check for vdiv.vx combine.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i8.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Add test for vec_duplicate + vdiv.vv combine case 0 with GR2VR cost 0, 2...
Pan Li [Mon, 2 Jun 2025 09:01:27 +0000 (17:01 +0800)] 
RISC-V: Add test for vec_duplicate + vdiv.vv combine case 0 with GR2VR cost 0, 2 and 15

Add asm dump check test for vec_duplicate + vdiv.vv combine to vdiv.vx,
with the GR2VR cost is 0, 2 and 15.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c: Add asm check
for vdiv.vx combine.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_data.h: Add test
data for vdiv run test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-i8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Combine vec_duplicate + vidv.vv to vdiv.vx on GR2VR cost
Pan Li [Mon, 2 Jun 2025 08:56:59 +0000 (16:56 +0800)] 
RISC-V: Combine vec_duplicate + vidv.vv to vdiv.vx on GR2VR cost

This patch would like to combine the vec_duplicate + vdiv.vv to the
vdiv.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

Assume we have example code like below, GR2VR cost is 0.

  #define DEF_VX_BINARY(T, OP)                                        \
  void                                                                \
  test_vx_binary (T * restrict out, T * restrict in, T x, unsigned n) \
  {                                                                   \
    for (unsigned i = 0; i < n; i++)                                  \
      out[i] = in[i] OP x;                                            \
  }

  DEF_VX_BINARY(int32_t, /)

Before this patch:
  10   │ test_vx_binary_or_int32_t_case_0:
  11   │     beq a3,zero,.L8
  12   │     vsetvli a5,zero,e32,m1,ta,ma
  13   │     vmv.v.x v2,a2
  14   │     slli    a3,a3,32
  15   │     srli    a3,a3,32
  16   │ .L3:
  17   │     vsetvli a5,a3,e32,m1,ta,ma
  18   │     vle32.v v1,0(a1)
  19   │     slli    a4,a5,2
  20   │     sub a3,a3,a5
  21   │     add a1,a1,a4
  22   │     vdiv.vv v1,v1,v2
  23   │     vse32.v v1,0(a0)
  24   │     add a0,a0,a4
  25   │     bne a3,zero,.L3

After this patch:
  10   │ test_vx_binary_or_int32_t_case_0:
  11   │     beq a3,zero,.L8
  12   │     slli    a3,a3,32
  13   │     srli    a3,a3,32
  14   │ .L3:
  15   │     vsetvli a5,a3,e32,m1,ta,ma
  16   │     vle32.v v1,0(a1)
  17   │     slli    a4,a5,2
  18   │     sub a3,a3,a5
  19   │     add a1,a1,a4
  20   │     vdiv.vx v1,v1,a2
  21   │     vse32.v v1,0(a0)
  22   │     add a0,a0,a4
  23   │     bne a3,zero,.L3

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_vx_binary_vec_vec_dup): Add new
case for DIV op.
* config/riscv/riscv.cc (get_vector_binary_rtx_cost): Add new func
to get the cost of vector binary.
(riscv_rtx_costs): Add div rtx match and leverage above wrap to
get cost.
* config/riscv/vector-iterators.md: Add new op div to no_shift_vx_op.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agotree-optimization/120517 - fix dataref group split math
Richard Biener [Tue, 3 Jun 2025 12:09:22 +0000 (14:09 +0200)] 
tree-optimization/120517 - fix dataref group split math

DR_INIT is already measured in bytes, so there's no need to multiply
the DR_INIT difference of two DRs by the size of one of the DRs when
comparing that difference against MAX_BITSIZE_MODE_ANY_MODE.

PR tree-optimization/120517
* tree-vect-data-refs.cc (vect_analyze_data_ref_accesses):
Fix math in dataref group split.

2 months agolibstdc++: Check feature test macro for jthread in <stop_token>
Jonathan Wakely [Mon, 2 Jun 2025 22:25:43 +0000 (23:25 +0100)] 
libstdc++: Check feature test macro for jthread in <stop_token>

Check the appropriate feature test macro instead of checking that
__cplusplus >= 201703L.

libstdc++-v3/ChangeLog:

* include/std/stop_token: Check __glibcxx_jthread instead of
__cplusplus.

2 months agolibstdc++: Use new __is_destructible built-in in <type_traits>
Jonathan Wakely [Thu, 29 May 2025 12:50:08 +0000 (13:50 +0100)] 
libstdc++: Use new __is_destructible built-in in <type_traits>

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_destructible, is_destructible_v):
Define using new built-in.
(is_nothrow_destructible, is_nothrow_destructible_v): Likewise.
(is_trivially_destructible, is_trivially_destructible_v):
Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agolibstdc++: Fix errors and incorrect returns in atomic timed waits
Jonathan Wakely [Mon, 2 Jun 2025 10:24:32 +0000 (11:24 +0100)] 
libstdc++: Fix errors and incorrect returns in atomic timed waits

The __detail::__wait_until function has a comment that should have been
removed when r16-1000-g225622398a9631 changed the return type from a
std::pair to a struct with three members.

The __atomic_wait_address_until_v and __atomic_wait_address_for_v
function templates are apparently never used or instantiated, because
they don't compile. This fixes them, but they're still unused.  I plan
to make use of them in a later commit.

In __atomic_wait_address_until_v, __res.first in the return statement
should have also been changed when r16-1000-g225622398a9631 changed
__wait_result_type, and &__args should have been changed to just __args
by r16-988-g219bb905a60d95.

In __atomic_wait_address_for_v, the parameter is a copy & paste error
and should use chrono::duration not chrono::time_point

Fix _M_spin_until_impl so that the _M_has_val member of the result is
accurate.  If the deadline has passed then it never enters the loop and
so never loads a fresh value, so _M_has_val should be false.  There's
also a redundant clock::now() call in __spin_until_impl which can be
removed, we can reuse the call immediately before it.

libstdc++-v3/ChangeLog:

* include/bits/atomic_timed_wait.h (__detail::__wait_until):
Remove incorrect comment.
(__atomic_wait_address_until_v): Do not take address of __args in
call to __detail::__wait_until. Fix return statement to refer to
member of __wait_result_type.
(__atomic_wait_address_for_v): Change parameter type from
time_point to duration.
* src/c++20/atomic.cc (__spin_until_impl): Fix incorrect
return value. Reuse result of first call to clock.

2 months agolibstdc++: Replace some implicit conversions in std::vector
Jonathan Wakely [Thu, 29 May 2025 10:40:59 +0000 (11:40 +0100)] 
libstdc++: Replace some implicit conversions in std::vector

This replaces two implicit conversions from ptrdiff_t to size_t with
explicit conversions that include unreachable hints for the ptrdiff_t
value not being negative.

libstdc++-v3/ChangeLog:

* include/bits/stl_vector.h (~_Vector_base): Add unreachable
hint for negative capacity and cast to size_t explicitly.
* include/bits/vector.tcc (vector::_M_realloc_append): Use
size() instead of end() - begin().

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agolibstdc++: Use explicit cast to unsigned in std::rotr and std::rotl
Jonathan Wakely [Thu, 29 May 2025 10:29:38 +0000 (11:29 +0100)] 
libstdc++: Use explicit cast to unsigned in std::rotr and std::rotl

This suppresses some -Wsign-conversion warnings from Clang when
compiling with -Wsystem-headers.

libstdc++-v3/ChangeLog:

* include/std/bit (__rotl, __rotr): Use static_cast for
conversion from int to unsigned.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agolibstdc++: Remove redundant macro checks in std.cc.in
Jonathan Wakely [Tue, 27 May 2025 15:54:52 +0000 (16:54 +0100)] 
libstdc++: Remove redundant macro checks in std.cc.in

__cpp_lib_any and __cpp_lib_chrono are defined unconditionally in C++20
and __cpp_lib_three_way_comparison and __cpp_lib_concepts depend on
front-end features which are definitely supported by GCC trunk and all
non-GCC compilers we care about.

libstdc++-v3/ChangeLog:

* src/c++23/std.cc.in: Remove redundant checks for feature test
macros that are always true.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoRISC-V: Use helper function to get FPR to VR move cost
Paul-Antoine Arras [Wed, 28 May 2025 10:09:22 +0000 (12:09 +0200)] 
RISC-V: Use helper function to get FPR to VR move cost

Since last patch introduced get_fr2vr_cost () to get the correct cost to move
data from a floating-point to a vector register, this patch replaces existing
uses of the constant FR2VR.

gcc/ChangeLog:

* config/riscv/riscv-vector-costs.cc (costs::adjust_stmt_cost): Replace
FR2VR with get_fr2vr_cost ().
* config/riscv/riscv.cc (riscv_register_move_cost): Likewise.
(riscv_builtin_vectorization_cost): Likewise.

2 months agoRISC-V: Add pattern for vector-scalar multiply-add/sub [PR119100]
Paul-Antoine Arras [Mon, 12 May 2025 12:42:24 +0000 (14:42 +0200)] 
RISC-V: Add pattern for vector-scalar multiply-add/sub [PR119100]

This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into a plus-mult or minus-mult RTL instruction.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f        v6,fa0
  vfmadd.vv       v9,v6,v7

After, we get only one:
  vfmadd.vf       v9,fa0,v7

On SPEC2017's 503.bwaves_r, depending on the workload, the reduction in dynamic
instruction count varies from -4.66% to -4.75%.

PR target/119100

gcc/ChangeLog:

* config/riscv/autovec-opt.md (*<optab>_vf_<mode>): Add new pattern to
combine vec_duplicate + vfm{add,sub}.vv into vfm{add,sub}.vf.
* config/riscv/riscv-opts.h (FPR2VR_COST_UNPROVIDED): Define.
* config/riscv/riscv-protos.h (get_fr2vr_cost): Declare function.
* config/riscv/riscv.cc (riscv_rtx_costs): Add cost model for MULT with
VEC_DUPLICATE.
(get_fr2vr_cost): New function.
* config/riscv/riscv.opt: Add new option --param=fpr2vr-cost.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_mulop.h: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_mulop_data.h: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_mulop_run.h: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmadd-run-1-f16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmadd-run-1-f32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmadd-run-1-f64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmsub-run-1-f16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmsub-run-1-f32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmsub-run-1-f64.c: New test.

2 months agox86: Add g++.target/i386/pr103750.C
H.J. Lu [Tue, 3 Jun 2025 09:17:57 +0000 (17:17 +0800)] 
x86: Add g++.target/i386/pr103750.C

Add a test for PR target/103750 fixed by r16-170-ga670ebde399548.

PR target/103750
* g++.target/i386/pr103750.C: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2 months agolibgomp: Fix up omp_target_memset-3.c test for C++ [PR120444]
Jakub Jelinek [Tue, 3 Jun 2025 05:54:37 +0000 (07:54 +0200)] 
libgomp: Fix up omp_target_memset-3.c test for C++ [PR120444]

The test PASSes for C, but FAILs for C++:
.../libgomp.c-c++-common/omp_target_memset-3.c: In function 'void test_it(void*, int, size_t)':
.../libgomp.c-c++-common/omp_target_memset-3.c:31:7: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
.../libgomp.c-c++-common/omp_target_memset-3.c:33:13: error: invalid conversion from 'void*' to 'int8_t*' {aka 'signed char*'} [-fpermissive]
.../libgomp.c-c++-common/omp_target_memset-3.c:10:19: note: initializing argument 1 of 'void init_val(int8_t*, int, size_t)'
.../libgomp.c-c++-common/omp_target_memset-3.c:37:14: error: invalid conversion from 'void*' to 'int8_t*' {aka 'signed char*'} [-fpermissive]
.../libgomp.c-c++-common/omp_target_memset-3.c:17:20: note: initializing argument 1 of 'void check_val(int8_t*, int, size_t)'
.../libgomp.c-c++-common/omp_target_memset-3.c:38:18: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
.../libgomp.c-c++-common/omp_target_memset-3.c:38:18: error: invalid conversion from 'void*' to 'int8_t*' {aka 'signed char*'} [-fpermissive]
.../libgomp.c-c++-common/omp_target_memset-3.c:17:20: note: initializing argument 1 of 'void check_val(int8_t*, int, size_t)'
.../libgomp.c-c++-common/omp_target_memset-3.c: In function 'int main()':
.../libgomp.c-c++-common/omp_target_memset-3.c:46:7: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]

The following two-liner fixes that, tested on x86_64-linux and i686-linux.

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

PR libgomp/120444
* testsuite/libgomp.c-c++-common/omp_target_memset-3.c (test_it):
Change ptr argument type from void * to int8_t *.
(main): Change ptr variable type from void * to int8_t * and cast
omp_target_alloc result to the latter type.

2 months agophiprop: Add testcase for already fixed case [PR116824]
Andrew Pinski [Tue, 3 Jun 2025 03:50:44 +0000 (20:50 -0700)] 
phiprop: Add testcase for already fixed case [PR116824]

This testcase was fixed by r16-906-g8da568c885dc90. Since
this is a C testcase, it would be useful to have a C testcase besides
a C++ one too.

Tested for x86_64-linux-gnu.

PR tree-optimization/116824

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/phiprop-2.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agoswitch-conversion: Mark CSWTCH as mergeable [PR120451]
Andrew Pinski [Mon, 2 Jun 2025 22:56:20 +0000 (15:56 -0700)] 
switch-conversion: Mark CSWTCH as mergeable [PR120451]

When we have a smallish CSWTCH, it could be placed in the rodata.cst16
section so it can be merged with other constants across TUs.

The fix is simple; just mark the decl as mergable (DECL_MERGEABLE).
DECL_MERGEABLE was added with r14-1500-g4d935f52b0d5c0 specifically
to improve these kind of decls.

PR tree-optimization/120451

gcc/ChangeLog:

* tree-switch-conversion.cc (switch_conversion::build_one_array): Mark
the newly created decl as mergable.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/cswtch-6.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agoDaily bump.
GCC Administrator [Tue, 3 Jun 2025 00:18:06 +0000 (00:18 +0000)] 
Daily bump.

2 months ago[lra] force reg update after spilling to memory [PR120424]
Alexandre Oliva [Mon, 2 Jun 2025 23:21:45 +0000 (20:21 -0300)] 
[lra] force reg update after spilling to memory [PR120424]

In the added C++ testcase, a stack slot at a negative sp offset is
used to hold a value across a call.

There are a couple of causes that directly lead to this outcome:

- the -fstack-clash-protection and -fnon-call-exception options, that
cause arm_frame_pointer_required to flip from false to true when the
first pseudo gets spilled to memory;

- when the affected pseudo is spilled to memory, we fail to update lra
regno info, because the insns that reference it are already on the
lra_constraint_insn_stack;

There is another potentially-related issue:

- when we notice that the frame pointer can no longer be eliminated to
the stack pointer, we immediately clear can_eliminate, and also
prev_can_eliminate, but update_reg_eliminate relied on the latter to
tell that it needs to propagate a previous_offset to the
newly-selected elimination, or restore the original offsets.

This patch ensures that we update insn register info after spilling a
pseudo to memory, and enables update_reg_eliminate to recognize the
case in which a previously-preferred elimination is disabled
regardless of prev_can_eliminate.

for  gcc/ChangeLog

PR rtl-optimization/120424
PR middle-end/118939
* lra-spills.cc (spill_pseudos): Update insn regno info.
* lra-eliminations.cc (update_reg_eliminate): Recognize
disabling of active elimination regardless of
prev_can_eliminate.

for  gcc/testsuite/ChangeLog

PR rtl-optimization/120424
PR middle-end/118939
* g++.target/arm/pr120424.C: New.
* gnat.dg/controlled9.adb: New.
* gnat.dg/controlled9_pkg.ads: New.

2 months agocobol: Honor HAVE_CLOCK_GETTIME and HAVE_GETTIMEOFDAY. [PR119975]
Robert Dubner [Mon, 2 Jun 2025 19:55:20 +0000 (15:55 -0400)] 
cobol: Honor HAVE_CLOCK_GETTIME and HAVE_GETTIMEOFDAY. [PR119975]

These changes cause genapi.cc to use whichever of clock_gettime() or
gettimeofday() are available.  This prevents compilation errors on
systems where clock_gettime() is not available.

gcc/cobol/ChangeLog:

PR cobol/119975
* genapi.cc (parser_intrinsic_call_0): Use get_time_64() function.
* genutil.cc (get_time_64): Definition created.
* genutil.h (get_time_64): Declaration created.

2 months agoc++: more __is_destructible fixes [PR107600]
Jason Merrill [Mon, 2 Jun 2025 18:58:42 +0000 (14:58 -0400)] 
c++: more __is_destructible fixes [PR107600]

PR c++/107600

gcc/cp/ChangeLog:

* method.cc (destructible_expr): Fix refs and arrays of unknown
bound.

gcc/testsuite/ChangeLog:

* g++.dg/ext/is_destructible2.C: Add more cases.

2 months ago[PATCH] RISC-V: Add smcntrpmf extension.
Dongyan Chen [Mon, 2 Jun 2025 19:30:29 +0000 (13:30 -0600)] 
[PATCH] RISC-V: Add smcntrpmf extension.

This patch support smcntrpmf extension[1].
To enable GCC to recognize and process smcntrpmf extension correctly at compile time.

[1]https://github.com/riscvarchive/riscv-smcntrpmf

gcc/ChangeLog:

* config/riscv/riscv-ext.def: New extension defs.
* config/riscv/riscv-ext.opt: Ditto.
* doc/riscv-ext.texi: Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/arch-59.c: New test.

2 months agoc++: constinit diagnostic regression [PR120506]
Jason Merrill [Mon, 2 Jun 2025 14:59:02 +0000 (10:59 -0400)] 
c++: constinit diagnostic regression [PR120506]

In r16-57 I thought it was unnecessary to mention incomplete initialization
after another diagnostic, but actually it's useful elaboration.

PR c++/120506

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_outermost_constant_expr): Always check
CONSTRUCTOR_NO_CLEARING.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constinit21.C: New test.

2 months agoc++, coroutines: Some cleanups in build_actor.
Iain Sandoe [Sat, 31 May 2025 15:13:40 +0000 (16:13 +0100)] 
c++, coroutines: Some cleanups in build_actor.

We were incorrectly guarding all the frame cleanups on the
basis of frame_needs_free (which is always set for the present
code-gen since we have no allocation elision).  The net result
being that the (incorrect) code was behaving as expected.

We built, but never used, a label for the frame destruction;
in practice it is never triggered independently of the promise
and argument copy destruction.

Finally there are a few instances where we had been building
expressions manually rather than using higher-level APIs.

gcc/cp/ChangeLog:

* coroutines.cc (build_actor_fn): Remove an unused
label, guard the frame deallocation correctly, use
simpler APIs to build if and return statements.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2 months agoc++: Emit an error for attempted constexpr co_await [PR118903].
Iain Sandoe [Fri, 30 May 2025 19:09:40 +0000 (20:09 +0100)] 
c++: Emit an error for attempted constexpr co_await [PR118903].

We checked that the coroutine expressions were not suitable for
constexpr, but did not emit and error when needed.

PR c++/118903

gcc/cp/ChangeLog:

* constexpr.cc (potential_constant_expression_1): Emit
an error when co_await et. al. are used in constexpr
contexts.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr118903.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2 months agoc++: Add co_await, co_yield and co_return to dump_expr.
Iain Sandoe [Fri, 30 May 2025 19:06:26 +0000 (20:06 +0100)] 
c++: Add co_await, co_yield and co_return to dump_expr.

These were omitted there as an oversight, most of the error handling
for the coroutines code is specific rather than using generic %qE etc.

gcc/cp/ChangeLog:

* error.cc (dump_expr): Add co_await, co_yield and co_return.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2 months agolibstdc++: Remove spaces before function parameter list
Jonathan Wakely [Thu, 29 May 2025 10:33:54 +0000 (11:33 +0100)] 
libstdc++: Remove spaces before function parameter list

We don't use this GCC coding convention in libstdc++.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (basic_string::size): Remove space
before parameter list.
(basic_string::capacity): Likewise.
* include/bits/stl_deque.h (deque::size): Likewise.
* include/bits/stl_vector.h (vector::size, vector::capacity):
Likewise.
* include/bits/vector.tcc (vector::_M_realloc_insert): Likewise.
(vector::_M_realloc_append): Likewise.

2 months agolibstdc++: Implement LWG 2439 for std::unique_copy [PR120386]
Jonathan Wakely [Wed, 21 May 2025 19:12:50 +0000 (20:12 +0100)] 
libstdc++: Implement LWG 2439 for std::unique_copy [PR120386]

The current overload set for __unique_copy handles three cases:

- The input range uses forward iterators, the output range does not.
  This is the simplest case, and can just compare adjacent elements of
  the input range.

- Neither the input range nor output range use forward iterators.
  This requires a local variable copied from the input range and updated
  by assigning each element to the local variable.

- The output range uses forward iterators.
  For this case we compare the current element from the input range with
  the element just written to the output range.

There are two problems with this implementation. Firstly, the third case
assumes that the value type of the output range can be compared to the
value type of the input range, which might not be possible at all, or
might be possible but give different results to comparing elements of
the input range. This is the problem identified in LWG 2439.

Secondly, the third case is used when both ranges use forward iterators,
even though the first case could (and should) be used. This means that
we compare elements from the output range instead of the input range,
with the problems described above (either not well-formed, or might give
the wrong results).

The cause of the second problem is that the overload for the first case
looks like:

OutputIterator
__unique_copy(ForwardIter, ForwardIter, OutputIterator, BinaryPred,
              forward_iterator_tag, output_iterator_tag);

When the output range uses forward iterators this overload cannot be
used, because forward_iterator_tag does not inherit from
output_iterator_tag, so is not convertible to it.

To fix these problems we need to implement the resolution of LWG 2439 so
that the third case is only used when the value types of the two ranges
are the same. This ensures that the comparisons are well behaved. We
also need to ensure that the first case is used when both ranges use
forward iterators.

This change replaces a single step of tag dispatching to choose between
three overloads with two step of tag dispatching, choosing between two
overloads at each step. The first step dispatches based on the iterator
category of the input range, ignoring the category of the output range.
The second step only happens when the input range uses non-forward
iterators, and dispatches based on the category of the output range and
whether the value type of the two ranges is the same. So now the cases
that are handled are:

- The input range uses forward iterators.
- The output range uses non-forward iterators or a different value type.
- The output range uses forward iterators and has the same value type.

For the second case, the old code used __gnu_cxx::__ops::__iter_comp_val
to wrap the predicate in another level of indirection. That seems
unnecessary, as we can just use a pointer to the local variable instead
of an iterator referring to it.

During review of this patch, it was discovered that all known
implementations of std::unique_copy and ranges::unique_copy (except
cmcstl2) disagree with the specification. The standard (and the SGI STL
documentation) say that it uses pred(*i, *(i-1)) but everybody uses
pred(*(i-1), *i) instead, and apparently always has done. This patch
adjusts ranges::unique_copy to be consistent.

In the first __unique_copy overload, the local copy of the iterator is
changed to be the previous position not the next one, so that we use
++first as the "next" iterator, consistent with the logic used in the
other overloads. This makes it easier to compare them, because we aren't
using pred(*first, *next) in one and pred(something, *first) in the
others. Instead it's always pred(something, *first).

libstdc++-v3/ChangeLog:

PR libstdc++/120386
* include/bits/ranges_algo.h (__unique_copy_fn): Reorder
arguments for third case to match the first two cases.
* include/bits/stl_algo.h (__unique_copy): Replace three
overloads with two, depending only on the iterator category of
the input range.  Dispatch to __unique_copy_1 for the
non-forward case.
(__unique_copy_1): New overloads for the case where the input
range uses non-forward iterators.
(unique_copy): Only pass the input range category to
__unique_copy.
* testsuite/25_algorithms/unique_copy/lwg2439.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agolibgomp: Add OpenMP's omp_target_memset/omp_target_memset_async
Tobias Burnus [Mon, 2 Jun 2025 15:43:57 +0000 (17:43 +0200)] 
libgomp: Add OpenMP's omp_target_memset/omp_target_memset_async

PR libgomp/120444

include/ChangeLog:

* cuda/cuda.h (cuMemsetD8, cuMemsetD8Async): Declare.

libgomp/ChangeLog:

* libgomp-plugin.h (GOMP_OFFLOAD_memset): Declare.
* libgomp.h (struct gomp_device_descr): Add memset_func.
* libgomp.map (GOMP_6.0.1): Add omp_target_memset{,_async}.
* libgomp.texi (Device Memory Routines): Document them.
* omp.h.in (omp_target_memset, omp_target_memset_async): Declare.
* omp_lib.f90.in (omp_target_memset, omp_target_memset_async):
Add interfaces.
* omp_lib.h.in (omp_target_memset, omp_target_memset_async): Likewise.
* plugin/cuda-lib.def: Add cuMemsetD8.
* plugin/plugin-gcn.c (struct hsa_runtime_fn_info): Add
hsa_amd_memory_fill_fn.
(init_hsa_runtime_functions): DLSYM_OPT_FN load it.
(GOMP_OFFLOAD_memset): New.
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_memset): New.
* target.c (omp_target_memset_int, omp_target_memset,
omp_target_memset_async_helper, omp_target_memset_async): New.
(gomp_load_plugin_for_device): Add DLSYM (memset).
* testsuite/libgomp.c-c++-common/omp_target_memset.c: New test.
* testsuite/libgomp.c-c++-common/omp_target_memset-2.c: New test.
* testsuite/libgomp.c-c++-common/omp_target_memset-3.c: New test.
* testsuite/libgomp.fortran/omp_target_memset.f90: New test.
* testsuite/libgomp.fortran/omp_target_memset-2.f90: New test.

2 months agoc++: __is_destructible fixes [PR107600]
Jason Merrill [Mon, 2 Jun 2025 14:09:07 +0000 (10:09 -0400)] 
c++: __is_destructible fixes [PR107600]

destructible_expr was wrongly assuming that TO is a class type.

When is_xible_helper was added in r8-742 it returned early for abstract
class types, which is correct for __is_constructible, but not
__is_assignable or (now) __is_destructible.

PR c++/107600

gcc/cp/ChangeLog:

* method.cc (destructible_expr): Handle non-classes.
(constructible_expr): Check for abstract class here...
(is_xible_helper): ...not here.

gcc/testsuite/ChangeLog:

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

2 months agoc++: __has_trivial_destructor regression
Jason Merrill [Mon, 2 Jun 2025 12:36:22 +0000 (08:36 -0400)] 
c++: __has_trivial_destructor regression

We don't want the new call to get_dtor to cause function instantiation.

PR c++/107600

gcc/cp/ChangeLog:

* semantics.cc (trait_expr_value) [CPTK_HAS_TRIVIAL_DESTRUCTOR]:
Add cp_unevaluated.

gcc/testsuite/ChangeLog:

* g++.dg/ext/has_trivial_destructor-3.C: New test.

2 months agolibstdc++: Pass small trivial types by value in polymorphic wrappers
Tomasz Kamiński [Wed, 28 May 2025 09:16:22 +0000 (11:16 +0200)] 
libstdc++: Pass small trivial types by value in polymorphic wrappers

This patch adjust the passing of parameters for the move_only_function,
copyable_function and function_ref. For types that are declared as being passed
by value in signature template argument, they are passed by value to the invoker,
when they are small (at most two pointers), trivially move constructible and
trivially destructible. The latter guarantees that passing them by value has not
user visible side effects.

In particular, this extends the set of types forwarded by value, that was
previously limited to scalars, to also include specializations of std::span and
std::string_view, and similar standard and program defined-types.

Checking the suitability of the parameter types requires the types to be complete.
As a consequence, the implementation imposes requirements on instantiation of
move_only_function and copyable_function. To avoid producing the errors from
the implementation details, a static assertion was added to partial
specializations of copyable_function, move_only_function and function_ref.
The static assertion uses existing __is_complete_or_unbounded, as arrays type
parameters are automatically decayed in function type.

Standard already specifies in [res.on.functions] p2.5 that instantiating these
partial specialization with incomplete types leads to undefined behavior.

libstdc++-v3/ChangeLog:

* include/bits/funcwrap.h (__polyfunc::__pass_by_rref): Define.
(__polyfunc::__param_t): Update to use __pass_by_rref.
* include/bits/cpyfunc_impl.h:: Assert that are parameters type
are complete.
* include/bits/funcref_impl.h: Likewise.
* include/bits/mofunc_impl.h: Likewise.
* testsuite/20_util/copyable_function/call.cc: New test.
* testsuite/20_util/function_ref/call.cc: New test.
* testsuite/20_util/move_only_function/call.cc: New test.
* testsuite/20_util/copyable_function/conv.cc: New test.
* testsuite/20_util/function_ref/conv.cc: New test.
* testsuite/20_util/move_only_function/conv.cc: New test.
* testsuite/20_util/copyable_function/incomplete_neg.cc: New test.
* testsuite/20_util/function_ref/incomplete_neg.cc: New test.
* testsuite/20_util/move_only_function/incomplete_neg.cc: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agolibstdc++: Implement C++26 std::polymorphic [PR119152]
Jonathan Wakely [Tue, 27 May 2025 09:38:41 +0000 (11:38 +0200)] 
libstdc++: Implement C++26 std::polymorphic [PR119152]

This patch implements C++26 std::polymorphic as specified in P3019 with
amendment to move assignment from LWG 4251.

The implementation always allocate stored object on the heap. The manager
function (_M_manager) is similary keep with the object (polymorphic::_Obj),
which reduces the size of the polymorphic to size of the single pointer plus
allocator (that is declared with [[no_unique_address]]).

The implementation does not not use small-object optimization (SSO). We may
consider adding this in the future, as SSO is allowed by the standard. However,
storing any polimorphic object will require providing space for two pointers
(manager function and vtable pointer) and user-declared data members.

PR libstdc++/119152

libstdc++-v3/ChangeLog:

* include/bits/indirect.h (std::polymorphic, pmr::polymorphic)
[__glibcxx_polymorphic]: Define.
* include/bits/version.def (polymorphic): Define.
* include/bits/version.h: Regenerate.
* include/std/memory: Define __cpp_lib_polymorphic.
* testsuite/std/memory/polymorphic/copy.cc: New test.
* testsuite/std/memory/polymorphic/copy_alloc.cc: New test.
* testsuite/std/memory/polymorphic/ctor.cc: New test.
* testsuite/std/memory/polymorphic/ctor_poly.cc: New test.
* testsuite/std/memory/polymorphic/incomplete.cc: New test.
* testsuite/std/memory/polymorphic/invalid_neg.cc: New test.
* testsuite/std/memory/polymorphic/move.cc: New test.
* testsuite/std/memory/polymorphic/move_alloc.cc: New test.

Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoor1k: Fix struct return test
Stafford Horne [Sat, 31 May 2025 05:54:58 +0000 (06:54 +0100)] 
or1k: Fix struct return test

In or1k structs are returned from functions using the memory address
passed in r3.  In the current version of GCC the struct stores changed
from r11 (the return value) to r3 the incoming memory address.  Both of
are valid.

Adjust the test to match what GCC is producing now.

gcc/testsuite/ChangeLog:

* gcc.target/or1k/return-2.c: Fix test.

2 months agoor1k: Support long jump offsets with -mcmodel=large
Stafford Horne [Mon, 12 May 2025 20:47:21 +0000 (21:47 +0100)] 
or1k: Support long jump offsets with -mcmodel=large

The -mcmodel=large option was originally added to handle generation of
large binaries with large PLTs.  However, when compiling the Linux
kernel with allyesconfig the output binary is so large that the jump
instruction 26-bit immediate is not large enough to store the jump
offset to some symbols when linking.  Example error:

  relocation truncated to fit: R_OR1K_INSN_REL_26 against symbol `do_fpe_trap' defined in .text section in arch/openrisc/kernel/traps.o

We fix this by forcing jump offsets to registers when -mcmodel=large.

Note, to get the Linux kernel allyesconfig config to work with OpenRISC,
this patch is needed along with some other patches to the Linux hand
coded assembly bits.

gcc/ChangeLog:

* config/or1k/predicates.md (call_insn_operand): Add condition
to not allow symbol_ref operands with TARGET_CMODEL_LARGE.
* config/or1k/or1k.opt: Document new -mcmodel=large
implications.
* doc/invoke.texi: Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/or1k/call-1.c: New test.
* gcc.target/or1k/got-1.c: New test.

2 months agotestsuite: Add tls_link effective target
Christophe Lyon [Thu, 17 Apr 2025 15:55:14 +0000 (15:55 +0000)] 
testsuite: Add tls_link effective target

Some tests have 'dg-do link' but currently require 'tls' which is a
compile-only check.

In some configurations of arm-none-eabi, the 'tls' effective-target
can be successful although these tests fail to link with
undefined reference to `__aeabi_read_tp'

This patch as a new tls_link effective target which makes sure we can
build an executable.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp (check_effective_target_tls_link): New.
* g++.dg/tls/pr102496-1.C: Require tls_link.
* g++.dg/tls/pr77285-1.C: Likewise.

gcc/ChangeLog:

* doc/sourcebuild.texi (tls_link): Add documentation.

2 months agoRISC-V: Adjust build rule for gen-riscv-ext-opt and gen-riscv-ext-texi
Kito Cheng [Wed, 28 May 2025 09:59:11 +0000 (17:59 +0800)] 
RISC-V: Adjust build rule for gen-riscv-ext-opt and gen-riscv-ext-texi

Separate the build rules to compile and link stage to make sure
BUILD_LINKERFLAGS and BUILD_LDFLAGS are applied correctly.

We hit this issue when we try to build GCC with non-system-default g++,
and it use newer libstdc++, and then got error from using older libstdc++ from
system, that should not happened if we link with -static-libgcc and
-static-libstdc++.

gcc/ChangeLog:

* config/riscv/t-riscv: Adjust build rule for gen-riscv-ext-opt
and gen-riscv-ext-texi.

2 months agoc++tools: Don't check --enable-default-pie.
Kito Cheng [Tue, 27 May 2025 02:10:15 +0000 (10:10 +0800)] 
c++tools: Don't check --enable-default-pie.

`--enable-default-pie` is an option to specify whether to enable
position-independent executables by default for `target`.

However c++tools is build for `host`, so it should just follow
`--enable-host-pie` option to determine whether to build with
position-independent executables or not.

NOTE:

I checked PR 98324 and build with same configure option
(`--enable-default-pie` and lto bootstrap) on x86-64 linux to make sure
it won't cause same problem.

c++tools/ChangeLog:

* configure.ac: Don't check `--enable-default-pie`.
* configure: Regen.

2 months agoRISC-V: Implement full-featured iterator for riscv_subset_list [NFC]
Kito Cheng [Mon, 26 May 2025 06:43:47 +0000 (14:43 +0800)] 
RISC-V: Implement full-featured iterator for riscv_subset_list [NFC]

This commit implements a full-featured iterator for the
riscv_subset_list, that it able to use range-based-for-loop.

That could simplfy the code in the future, and make it more readable,
also more compatible with standard C++ containers.

gcc/ChangeLog:

* config/riscv/riscv-c.cc (riscv_cpu_cpp_builtins): Use
range-based-for-loop.
* config/riscv/riscv-subset.h (riscv_subset_list::iterator):
New.
(riscv_subset_list::const_iterator): New.

2 months agoOpenMP: Handle more cases in user/condition selector
Sandra Loosemore [Mon, 2 Jun 2025 03:26:42 +0000 (03:26 +0000)] 
OpenMP: Handle more cases in user/condition selector

Tobias had noted that the C front end was not treating C23 constexprs
as constant in the user/condition selector property, which led to
missed opportunities to resolve metadirectives at parse time.
Additionally neither C nor C++ was permitting the expression to have
pointer or floating-point type -- the former being a common idiom in
other C/C++ conditional expressions.  By using the existing front-end
hooks for the implicit conversion to bool in conditional expressions,
we also get free support for using a C++ class object that has a bool
conversion operator in the user/condition selector.

gcc/c/ChangeLog
* c-parser.cc (c_parser_omp_context_selector): Call
convert_lvalue_to_rvalue and c_objc_common_truthvalue_conversion
on the expression for OMP_TRAIT_PROPERTY_BOOL_EXPR.

gcc/cp/ChangeLog
* cp-tree.h (maybe_convert_cond): Declare.
* parser.cc (cp_parser_omp_context_selector): Call
maybe_convert_cond and fold_build_cleanup_point_expr on the
expression for OMP_TRAIT_PROPERTY_BOOL_EXPR.
* pt.cc (tsubst_omp_context_selector): Likewise.
* semantics.cc (maybe_convert_cond): Remove static declaration.

gcc/testsuite/ChangeLog
* c-c++-common/gomp/declare-variant-2.c: Update expected output.
* c-c++-common/gomp/metadirective-condition-constexpr.c: New.
* c-c++-common/gomp/metadirective-condition.c: New.
* c-c++-common/gomp/metadirective-error-recovery.c: Update expected
output.
* g++.dg/gomp/metadirective-condition-class.C: New.
* g++.dg/gomp/metadirective-condition-template.C: New.

2 months ago[PATCH] testsuite: RISC-V: Fix the typo in param-autovec-mode.c
Liao Shihua [Mon, 2 Jun 2025 03:11:25 +0000 (21:11 -0600)] 
[PATCH] testsuite: RISC-V: Fix the typo in param-autovec-mode.c

This patch fixes the typo in the test case `param-autovec-mode.c` in the RISC-V
autovec testsuite.

The option `autovec-mode` is changed to `riscv-autovec-mode` to match the
expected parameter name.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/param-autovec-mode.c: Change
`autovec-mode` to `riscv-autovec-mode` in dg-options.

2 months agoDaily bump.
GCC Administrator [Mon, 2 Jun 2025 00:16:29 +0000 (00:16 +0000)] 
Daily bump.

2 months agoMove get_call_rtx_from to final.c
H.J. Lu [Sun, 1 Jun 2025 01:29:48 +0000 (09:29 +0800)] 
Move get_call_rtx_from to final.c

Move get_call_rtx_from to final.c and call call_from_call_insn.

PR other/120493
* final.cc (call_from_call_insn): Change the argument type to
const rtx_call_insn *.
(get_call_rtx_from): New.
* rtl.h (is_a_helper <const rtx_call_insn *>::test): New.
(get_call_rtx_from): Moved to the final.cc section.
* rtlanal.cc (get_call_rtx_from): Removed.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2 months agoFortran: Fix handling of parsed format strings.
Jerry DeLisle [Sat, 31 May 2025 15:57:22 +0000 (08:57 -0700)] 
Fortran: Fix handling of parsed format strings.

Previously parsed strings with errors were being cached such
that subsequent use of the format string were not being
checked for errors.

PR libfortran/119856

libgfortran/ChangeLog:

* io/format.c (parse_format_list): Set the fmt->error
message for missing comma.
(parse_format): Do not cache the parsed format string
if a previous error ocurred.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr119856.f90: New test.

2 months agoforwprop: Manually rename the virtual mem op for complex and vector loads prop
Andrew Pinski [Sat, 31 May 2025 22:10:14 +0000 (15:10 -0700)] 
forwprop: Manually rename the virtual mem op for complex and vector loads prop

There are two places which forwprop replaces an original load to a few different loads.
Both can set the vuse manually instead of relying on update_ssa.
One is doing a complex load followed by REAL/IMAG_PART only
And the other is very similar but for vector loads followed by BIT_FIELD_REF.

Since this was the last place that needed to handle updating the ssa form,
Remove the TODO_update_ssa also from the pass.

gcc/ChangeLog:

* tree-ssa-forwprop.cc (optimize_vector_load): Set the vuse manually
on the new load statements. Also remove forward declaration since
the definition is before the first use.
(pass_forwprop::execute): Likewise for complex loads.
(pass_data_forwprop): Remove TODO_update_ssa.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agocobol: Wrap the call to fprintf in a libgcobol routine. [PR119524]
Robert Dubner [Sun, 1 Jun 2025 16:32:37 +0000 (12:32 -0400)] 
cobol: Wrap the call to fprintf in a libgcobol routine. [PR119524]

gcc/cobol/ChangeLog:

PR cobol/119524
* gengen.cc (gg_printf): Use the new __gg__fprintf_stderr() function
instead of generating a call to fprintf().

libgcobol/ChangeLog:

PR cobol/119524
* libgcobol.cc (__gg__fprintf_stderr): New function.

2 months agoPR modula2/120474: InOut buffering should flush the WriteLn before the Read
Gaius Mulley [Sun, 1 Jun 2025 10:25:25 +0000 (11:25 +0100)] 
PR modula2/120474: InOut buffering should flush the WriteLn before the Read

This patch adds a BufferFlush to InOut.mod:LocalWrite.

gcc/m2/ChangeLog:

PR modula2/120474
* gm2-libs-log/InOut.mod (LocalWrite): Call FIO.FlushBuffer.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 months agoc: fix ICE related to tagged types with attributes in diagnostics [PR120380]
Martin Uecker [Thu, 29 May 2025 15:17:12 +0000 (17:17 +0200)] 
c: fix ICE related to tagged types with attributes in diagnostics [PR120380]

get_aka_type will create a new type for diagnostics, but for tagged types
attributes will then be ignored with a warning.  This can lead to reentering
warning code which leads to an ICE.  Fix this by ignoring the attributes
for tagged types.

PR c/120380

gcc/c/ChangeLog:
* c-objc-common.cc (get_aka_type): Ignore attributes for tagged types.

gcc/testsuite/ChangeLog:
* gcc.dg/pr120380.c: New test.

2 months agoc++: rename PR120123 test
Jason Merrill [Sun, 1 Jun 2025 03:10:44 +0000 (23:10 -0400)] 
c++: rename PR120123 test

As Patrick points out (and I had realized after pushing it), this testcase
has nothing to do with explicit object parameters.

PR c++/120123

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/explicit-obj-lambda18.C: Move to...
* g++.dg/cpp2a/concepts-lambda24.C: ...here.

2 months agoRISC-V: Fix line too long format issue for autovect.md [NFC]
Pan Li [Sat, 31 May 2025 03:01:06 +0000 (11:01 +0800)] 
RISC-V: Fix line too long format issue for autovect.md [NFC]

Inspired by the avg_ceil patches, notice there were even more
lines too long from autovec.md.  So fix that format issues.

gcc/ChangeLog:

* config/riscv/autovec.md: Fix line too long for sorts
of pattern.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoxtensa: Remove include of reload.h
Takayuki 'January June' Suwa [Tue, 27 May 2025 06:59:21 +0000 (15:59 +0900)] 
xtensa: Remove include of reload.h

As one of the last steps in removing old reload.

gcc/ChangeLog:

* config/xtensa/xtensa.cc: Remove include of reload.h.

2 months agoxtensa: Remove an unnecessary constraint modifier from movsf_internal insn pattern
Takayuki 'January June' Suwa [Tue, 27 May 2025 06:58:35 +0000 (15:58 +0900)] 
xtensa: Remove an unnecessary constraint modifier from movsf_internal insn pattern

In this case, there is no need to consider reloading when memory is the
destination.  On the other hand, when memory is the source, reloading
read from constant pool becomes double indirection and should obviously
be avoided.

gcc/ChangeLog:

* config/xtensa/xtensa.md (movsf_internal):
Remove destination side constraint modifier '^' in the third
alternative.

2 months agoxtensa: Implement TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS
Takayuki 'January June' Suwa [Tue, 27 May 2025 06:57:26 +0000 (15:57 +0900)] 
xtensa: Implement TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS

Implement TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS in order to avoid using
ALL_REGS rclass as is done on other targets, instead of overestimating
between integer and FP register move costs.

gcc/ChangeLog:

* config/xtensa/xtensa.cc
(xtensa_ira_change_pseudo_allocno_class):
New prototype and function.
(TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS): Define macro.
(xtensa_register_move_cost):
Change between integer and FP register move cost to a value
based on actual behavior, i.e. 2, the default and the same as
the move cost between integer registers.

2 months agoDaily bump.
GCC Administrator [Sun, 1 Jun 2025 00:17:06 +0000 (00:17 +0000)] 
Daily bump.

2 months agoPR modula2/120497: error is generated for good code when returning a pointer var...
Gaius Mulley [Sun, 1 Jun 2025 00:05:55 +0000 (01:05 +0100)] 
PR modula2/120497: error is generated for good code when returning a pointer var variable

The return type checking needs to skip over the Lvalue part of the VAR
parameter or variable.

gcc/m2/ChangeLog:

PR modula2/120497
* gm2-compiler/M2Range.mod (IsAssignmentCompatible): Remove from
import list.
(FoldTypeReturnFunc): Rewrite to skip the Lvalue of a var
variable.
(CodeTypeReturnFunc): Ditto.
(CodeTypeIndrX): Call AssignmentTypeCompatible rather than
IsAssignmentCompatible.
(FoldTypeIndrX): Ditto.

gcc/testsuite/ChangeLog:

PR modula2/120497
* gm2/pim/pass/ReturnType.mod: New test.
* gm2/pim/pass/ReturnType2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 months agoHave TODO_verify_* not set by any pass
Andrew Pinski [Fri, 30 May 2025 06:50:08 +0000 (23:50 -0700)] 
Have TODO_verify_* not set by any pass

This is a follow up to the patch set starting at https://gcc.gnu.org/pipermail/gcc-patches/2014-April/386650.html.

Currently TODO_verify_{il,all} is set by a few passes as TODOs afterwards but
we don't need to do that any more. Those were mostly removed back in
https://gcc.gnu.org/pipermail/gcc-patches/2014-May/387647.html

And now since TODO_verify_all is no longer used, remove it too.
Removes last_verified from the function structure since it is always 0 before the
call to execute_todo that has TODO_verify_all set on it.

Also this removes the ability for good to use TODO_verify_il from the passes and reserves
bit 31 of the TODO for the verfification and internally only the passes.cc code.

gcc/ChangeLog:

* function.h (struct function): Remove last_verified.
* gimple-harden-conditionals.cc (pass_data_harden_compares): Remove
TODO_verify_il.
(pass_data_harden_conditional_branches): Likewise.
* gimple-harden-control-flow.cc (pass_harden_control_flow_redundancy::execute):
Don't return TODO_verify_il.
* ipa-strub.cc (pass_data_ipa_strub): Remove TODO_verify_il.
* passes.cc (TODO_verify_il): Define.
(execute_function_todo): Don't use or set last_verified.
(clear_last_verified): Remove.
(execute_one_ipa_transform_pass): Update comment before execute_todo.
Assert that none of the todos have TODO_verify_il set on it.
(execute_one_pass): Don't call clear_last_verified on all functions.
Assert that none of the todos have TODO_verify_il set on it.
* tree-inline.cc (initialize_cfun): Don't copy last_verified.
* tree-pass.h (TODO_verify_all): Remove.
* tree-vrp.cc (pass_data_early_vrp): Remove TODO_verify_all.
(pass_data_fast_vrp): Likewise.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agotree-optimization/120357 - ICE with early break vectorization
Richard Biener [Fri, 30 May 2025 12:11:47 +0000 (14:11 +0200)] 
tree-optimization/120357 - ICE with early break vectorization

When doing early break vectorization of a loop with a conditional
reduction the epilog creation code is confused as to before which exit
to insert the conditional reduction induction IV update.  The
following make sure this is done before the main IV exit.

PR tree-optimization/120357
* tree-vect-loop.cc (vect_create_epilog_for_reduction): Create
the conditional reduction induction IV increment before the
main IV exit.

* gcc.dg/vect/vect-early-break_136-pr120357.c: New testcase.

2 months agoPR modula2/120389 Assigning wrong type to an array causes an ICE
Gaius Mulley [Sat, 31 May 2025 00:53:48 +0000 (01:53 +0100)] 
PR modula2/120389 Assigning wrong type to an array causes an ICE

This patch provides follow on fixes for undetected type violations
which can occur then Lvalues are generated during assignment.
For example array accesses and with statements.  The type checker
M2Check.mod has been overhauled and cleaned up.

gcc/ChangeLog:

PR modula2/120389
* doc/gm2.texi (-fm2-strict-type-reason): Document new flag.

gcc/m2/ChangeLog:

PR modula2/120389
* gm2-compiler/M2Check.def (AssignmentTypeCompatible): Add new
parameter enableReason.
* gm2-compiler/M2Check.mod (EquivalenceProcedure): New type.
(falseReason2): New procedure function.
(falseReason1): Ditto.
(falseReason0): Ditto.
(checkTypeEquivalence): Rewrite.
(checkUnboundedArray): Ditto.
(checkUnbounded): Ditto.
(checkArrayTypeEquivalence): Ditto.
(checkCharStringTypeEquivalence): Ditto.
(buildError4): Add false reason.
(buildError2): Ditto.
(IsTyped): Use GetDType.
(IsTypeEquivalence): New procedure function.
(checkVarTypeEquivalence): Ditto.
(checkVarEquivalence ): Rewrite.
(checkConstMeta): Ditto.
(checkEnumField): New procedure function.
(checkEnumFieldEquivalence): Ditto.
(checkSubrangeTypeEquivalence): Rewrite.
(checkSystemEquivalence): Ditto.
(checkTypeKindViolation): Ditto.
(doCheckPair): Ditto.
(InitEquivalenceArray): New procedure.
(addEquivalence): Ditto.
(checkProcType): Rewrite.
(deconstruct): Deallocate reason string.
(AssignmentTypeCompatible): Initialize reason and reasonEnable
fields.
(ParameterTypeCompatible): Ditto.
(doExpressionTypeCompatible): Ditto.
* gm2-compiler/M2GenGCC.mod (CodeIndrX) Rewrite.
(CheckBinaryExpressionTypes): Rewrite and simplify now that the
type checker is more robust.
(CheckElementSetTypes): Ditto.
(CodeXIndr): Add new range assignment type check.
* gm2-compiler/M2MetaError.def: Correct comments.
* gm2-compiler/M2Options.def (SetStrictTypeAssignment): New procedure.
(SetStrictTypeReason): Ditto.
* gm2-compiler/M2Options.mod: (SetStrictTypeAssignment): New procedure.
(SetStrictTypeReason): Ditto.
(StrictTypeReason): Initialize.
(StrictTypeAssignment): Ditto.
* gm2-compiler/M2Quads.mod (CheckBreak): Delete.
(BreakQuad): New global variable.
(BreakAtQuad): Delete.
(gdbhook): New procedure.
(BreakWhenQuadCreated): Ditto.
(CheckBreak): Ditto.
(Init): Call BreakWhenQuadCreated and gdbhook.
(doBuildAssignment): Add type assignment range check.
(CheckProcTypeAndProcedure): Only check if the procedure
types differ.
(doIndrX): Add type IndrX range check.
(CheckReturnType): Add range return type check.
* gm2-compiler/M2Range.def (InitTypesIndrXCheck): New procedure
function.
(InitTypesReturnTypeCheck): Ditto.
* gm2-compiler/M2Range.mod (InitTypesIndrXCheck): New procedure
function.
(InitTypesReturnTypeCheck): Ditto.
(HandlerExists): Add new clauses.
(FoldAssignment): Pass extra FALSE parameter to
AssignmentTypeCompatible.
(FoldTypeReturnFunc): New procedure.
(FoldTypeAssign): Ditto.
(FoldTypeIndrX): Ditto.
(CodeTypeAssign): Rewrite.
(CodeTypeIndrX): New procedure.
(CodeTypeReturnFunc): Ditto.
(FoldTypeCheck): Add new case clauses.
(CodeTypeCheck): Ditto.
(FoldRangeCheckLower): Ditto.
(IssueWarning): Ditto.
* gm2-gcc/m2options.h (M2Options_SetStrictTypeAssignment): New
function prototype.
(M2Options_SetStrictTypeReason): Ditto.
* gm2-lang.cc (gm2_langhook_handle_option): New case clause
OPT_fm2_strict_type_reason.
* lang.opt (-fm2-strict-type-reason): New option.

gcc/testsuite/ChangeLog:

PR modula2/120389
* gm2/pim/fail/testcharint.mod: New test.
* gm2/pim/fail/testindrx.mod: New test.
* gm2/pim/pass/testxindr.mod: New test.
* gm2/pim/pass/testxindr2.mod: New test.
* gm2/pim/pass/testxindr3.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 months agoDaily bump.
GCC Administrator [Sat, 31 May 2025 00:19:06 +0000 (00:19 +0000)] 
Daily bump.

2 months agodiagnostics: implement highlight-a vs -b in HTML output [PR116792]
David Malcolm [Fri, 30 May 2025 23:57:46 +0000 (19:57 -0400)] 
diagnostics: implement highlight-a vs -b in HTML output [PR116792]

Update HTML output so that it renders highlight-a vs highlight-b
via <span> tags in the message itself, in the quoted source line,
in the underlines, and in the labels and their vertical bars.

Example output can be seen at:
  https://dmalcolm.fedorapeople.org/gcc/2025-05-28/diagnostic-ranges.c.html

gcc/ChangeLog:
PR other/116792
* diagnostic-format-html.cc (HTML_STYLE): Add ".highlight-a" and
".highlight-b".
(html_builder::make_element_for_diagnostic): Handle begin_color
and end_color.
* diagnostic-show-locus.cc (to_html::to_html): Add "richloc"
param and use it to initialize m_richloc.
(to_html::colorize_text_for_range_idx): Drop.
(to_html::get_location_range_by_idx): New.
(to_html::get_highlight_color_for_range_idx): New.
(to_html::m_richloc): New field.
(print_html_span_start): Update for new param of to_html ctor.
(line_printer::m_was_in_range_p): New field.
(line_printer::m_last_range_idx): New field.
(layout_printer<Sink>::print_source_line): Use set_in_range
and set_outside_range rather than colorization calls.
(layout_printer<Sink>::set_in_range): New.
(layout_printer<Sink>::set_outside_range): New.
(layout_printer<Sink>::print_annotation_line): Use set_in_range
and set_outside_range rather than colorization calls.
(layout_printer<to_text>::begin_label): Convert param from label
to state_idx.  Add "is_label_text" param and use it to guard logic
for turning off colorization within paths.
(layout_printer<to_html>::begin_label): Likewise.  Push <span>
for any highlight color.
(layout_printer<to_text>::end_label): Likewise.
(layout_printer<to_text>::end_label): Likewise, popping the
<span>.
(layout_printer<Sink>::print_any_labels): Convert begin/end_label
calls to pass in state_idx rather than label.  Use begin/end_label
rather than colorization calls.
(layout_printer<Sink>::layout_printer): Likewise.
(layout_printer<Sink>::layout_printer): Initialize new fields.
(diagnostic_source_print_policy::print_as_html): Update for new
param of to_html ctor.

gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/format/diagnostic-ranges-html.py: New test script.
* gcc.dg/format/diagnostic-ranges.c: Add HTML generation to
options, and invoke the new script to check the HTML output.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agoc++: another xobj lambda testcase [PR120123]
Jason Merrill [Fri, 30 May 2025 22:27:45 +0000 (18:27 -0400)] 
c++: another xobj lambda testcase [PR120123]

Patrick noticed this was fixed by r16-970.

PR c++/120123

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/explicit-obj-lambda18.C: New test.

2 months agoFix typo in comment in execute_all_ipa_transforms.
Andrew Pinski [Fri, 30 May 2025 07:00:31 +0000 (00:00 -0700)] 
Fix typo in comment in execute_all_ipa_transforms.

small typo, missing n at the end of function.

Pushed as obvious after a bootstrap/test.

gcc/ChangeLog:

* passes.cc (execute_all_ipa_transforms): Fix typo in
commenet.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agoc: Update description of C library facilities provided by GCC for C23
Joseph Myers [Fri, 30 May 2025 20:15:53 +0000 (20:15 +0000)] 
c: Update description of C library facilities provided by GCC for C23

The documentation of which standard C library facilities (headers) are
provided by GCC, as being those required of freestanding
implementations, is reasonably accurate for C99 and before (if you
ignore the provision of <tgmath.h> for non-GNU targets).  It's less
accurate for C11, since we provide <stdatomic.h> although that's not
required for freestanding implementations.  And it's very inaccurate
for C23, which specifies that freestanding implementations also
provide most of <string.h>, memalignment from <stdlib.h>, and, when
supporting Annex F, also <fenv.h>, <math.h> and the strto*
floating-point numeric conversion functions from <stdlib.h>.

I don't think expanding the scope of the C library facilities GCC
provides to include all those extra facilities specified by C23 for
freestanding implementations is a good idea.  (Indeed, GCC once used
to install assert.h on some platforms, but stopped doing so a long
time ago.)  Rather, it seems better to document that in both the
freestanding and the hosted cases, GCC is intended to provide the
compiler part of a conforming implementation, to be combined with a
corresponding library implementation, rather than providing all the
required library facilities in either case.

The rule about which headers GCC provides is then described in terms
of headers not declaring functions with external linkage, which is
much closer to existing practice, although still not perfect in all
cases (<stdatomic.h>, although mainly providing type-generic
operations, does declare a few non-type-generic functions that we
provide in libatomic).

A paragraph in trouble.texi that talks about freestanding
implementations with -ansi -pedantic is not changed (given that the
description in terms of freestanding implementations is sufficiently
accurate for C90); if the -ansi there were changed to an option for a
more recent standard, a corresponding change to that paragraph might
be needed as well.

Tested with "make info html pdf".

* doc/standards.texi (C Language): Document library facilities
provided in terms of headers not declaring functions with external
linkage, not in terms of headers required of freestanding
implementations.
* doc/sourcebuild.texi (Subdirectories, Headers): Likewise.
* doc/trouble.texi (Standard Libraries): Likewise.

2 months agoFortran: parameter inquiries of constant complex arrays [PR102599,PR114022]
Harald Anlauf [Fri, 30 May 2025 17:25:15 +0000 (19:25 +0200)] 
Fortran: parameter inquiries of constant complex arrays [PR102599,PR114022]

PR fortran/102599
PR fortran/114022

gcc/fortran/ChangeLog:

* expr.cc (simplify_complex_array_inquiry_ref): Helper function for
simplification of inquiry references (%re/%im) of constant complex
arrays.
(find_inquiry_ref): Use it for handling %re/%im inquiry references
of complex arrays.
(scalarize_intrinsic_call): Fix frontend memleak.
* primary.cc (gfc_match_varspec): When the reference is NULL, the
previous simplification has succeeded in evaluating inquiry
references also of arrays.

gcc/testsuite/ChangeLog:

* gfortran.dg/inquiry_type_ref_8.f90: New test.

2 months agoc++: more xobj lambda 'this' capture [PR113563]
Jason Merrill [Fri, 30 May 2025 12:59:31 +0000 (08:59 -0400)] 
c++: more xobj lambda 'this' capture [PR113563]

Nathaniel shared a more extensive test, which revealed more needed fixes.

PR c++/113563

gcc/cp/ChangeLog:

* lambda.cc (lambda_capture_field_type): Handle 'this' normally.
(build_capture_proxy): Special-case 'this' by-ref capture more.
(nonlambda_method_basetype): Look through xobj lambdas.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/explicit-obj-lambda17.C: New test.

2 months agoC: Flex array in union followed by a structure field is not reported [PR120354]
Qing Zhao [Thu, 29 May 2025 15:59:41 +0000 (15:59 +0000)] 
C: Flex array in union followed by a structure field is not reported [PR120354]

There is only one last_field for a structure type, but there might
be multiple last_fields for a union type, therefore we should ORed
the result of TYPE_INCLUDES_FLEXARRAY for multiple last_fields of
a union type.

PR c/120354

gcc/c/ChangeLog:

* c-decl.cc (finish_struct): Or the results for TYPE_INCLUDES_FLEXARRAY.

gcc/testsuite/ChangeLog:

* gcc.dg/pr120354.c: New test.

2 months agoC: Flex array in the middle via type alias is not reported [PR120353]
Qing Zhao [Wed, 28 May 2025 21:13:38 +0000 (21:13 +0000)] 
C: Flex array in the middle via type alias is not reported [PR120353]

The root cause of the bug is: the TYPE_INCLUDES_FLEXARRAY marking of the
structure type is not copied to its aliased type.
The fix is to copy this marking to all the variant types of the current
structure type.

PR c/120353

gcc/c/ChangeLog:

* c-decl.cc (finish_struct): Copy TYPE_INCLUDES_FLEXARRAY marking
to all the variant types of the current structure type.

gcc/testsuite/ChangeLog:

* gcc.dg/pr120353.c: New test.

2 months agolibstdc++: Test for formatting with empty spec for calendar types.
Tomasz Kamiński [Fri, 30 May 2025 09:31:35 +0000 (11:31 +0200)] 
libstdc++: Test for formatting with empty spec for calendar types.

Adding a test for behavior of the ostream operator and the formatting
with empty chron-spec for the chrono types. This commit covers calendar
types.

libstdc++-v3/ChangeLog:

* testsuite/std/time/format/empty_spec.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoRISC-V: Add test cases for avg_ceil vaadd implementation
Pan Li [Thu, 29 May 2025 13:33:44 +0000 (21:33 +0800)] 
RISC-V: Add test cases for avg_ceil vaadd implementation

Add asm and run testcase for avg_ceil vaadd implementation.

The below test suites are passed for this patch series.
* The rv64gcv fully regression test.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/avg.h: Add test helper macros.
* gcc.target/riscv/rvv/autovec/avg_data.h: Add test data for
avg_ceil.
* gcc.target/riscv/rvv/autovec/avg_ceil-1-i16-from-i32.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-1-i16-from-i64.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-1-i32-from-i64.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-1-i8-from-i16.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-1-i8-from-i32.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-1-i8-from-i64.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-run-1-i16-from-i32.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-run-1-i16-from-i64.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-run-1-i32-from-i64.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-run-1-i8-from-i16.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-run-1-i8-from-i32.c: New test.
* gcc.target/riscv/rvv/autovec/avg_ceil-run-1-i8-from-i64.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Reconcile the existing test for avg_ceil
Pan Li [Thu, 29 May 2025 13:31:54 +0000 (21:31 +0800)] 
RISC-V: Reconcile the existing test for avg_ceil

Some existing avg_floor test need updated due to change to
leverage vaadd.vv directly.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls/avg-4.c: Update asm check
to vaadd.
* gcc.target/riscv/rvv/autovec/vls/avg-5.c: Ditto.
* gcc.target/riscv/rvv/autovec/vls/avg-6.c: Ditto.
* gcc.target/riscv/rvv/autovec/widen/vec-avg-rv32gcv.c: Ditto.
* gcc.target/riscv/rvv/autovec/widen/vec-avg-rv64gcv.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>