]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 months agoFix name mismatch for fortran.
hongtao.liu [Tue, 14 Jan 2025 00:13:22 +0000 (01:13 +0100)] 
Fix name mismatch for fortran.

Function name in afdo_string_table is step3d_t_tile.
but DECL_ASSEMBLER_NAME (edge->callee->decl))) gets
__step3d_t_mod_MOD_step3d_t_tile, Looks like the prefix is not in the
debug string table.
The patch uses
afdo_string_table->get_index_by_decl (edge->callee->decl) instead.

gcc/ChangeLog:

PR gcov-profile/118508
* auto-profile.cc
(autofdo_source_profile::get_callsite_total_count): Fix name
mismatch for fortran.

2 months agoFortran: Source allocation of pure module function rejected [PR119948]
Paul Thomas [Wed, 7 May 2025 07:52:52 +0000 (08:52 +0100)] 
Fortran: Source allocation of pure module function rejected [PR119948]

2025-05-07  Paul Thomas  <pault@gcc.gnu.org>
    and Steven G. Kargl  <kargl@gcc.gnu.org>

gcc/fortran
PR fortran/119948
* primary.cc (match_variable): Module procedures with sym the
same as result can be treated as variables, although marked
external.

gcc/testsuite/
PR fortran/119948
* gfortran.dg/pr119948.f90: Update to incorporate failing test,
where module procedure is the result. Test submodule cases.

2 months ago[RISC-V] Avoid unnecessary andi with -1 argument
Jeff Law [Wed, 7 May 2025 01:20:14 +0000 (19:20 -0600)] 
[RISC-V] Avoid unnecessary andi with -1 argument

I was preparing to do some testing of Shreya's next patch on spec and stumbled
across another "andi dst,src,-1" case.  I fixed some stuff like this in the
gcc-15 cycle, but this one slipped through.

It's probably about 100M instructions on deepsjeng.  So tiny, but there's no
good reason to leave the clearly extraneous instructions in the output.

As with the other cases, it's a post-reload splitter that's not being careful
enough about the code it generates.

This has gone through my tester successfully.  Waiting on the pre-commit tester
before going forward.

gcc/
* config/riscv/riscv.md (*branch<ANYI:mode>_shiftedarith_equals_zero):
Avoid generating unnecessary andi.  Fix formatting.

gcc/testsuite
* g++.target/riscv/redundant-andi.C: New test.

2 months agoDaily bump.
GCC Administrator [Wed, 7 May 2025 00:18:28 +0000 (00:18 +0000)] 
Daily bump.

2 months ago[PATCH] RISC-V: Minimal support for sdtrig and ssstrict extensions.
Dongyan Chen [Tue, 6 May 2025 23:09:54 +0000 (17:09 -0600)] 
[PATCH] RISC-V: Minimal support for sdtrig and ssstrict extensions.

This patch support sdtrig and ssstrict extensions[1].
To enable GCC to recognize and process sdtrig and ssstrict extensions correctly
at compile time.

[1] https://github.com/riscv/riscv-profiles/blob/main/src/rva23-profile.adoc

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc: New extension.

gcc/testsuite/ChangeLog:

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

2 months ago[PATCH] RISC-V: Recognized svadu and svade extension
Mingzhu Yan [Tue, 6 May 2025 22:59:09 +0000 (16:59 -0600)] 
[PATCH] RISC-V: Recognized svadu and svade extension

This patch support svadu and svade extension.
To enable GCC to recognize and process svadu and svade extension correctly at compile time.

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc (riscv_ext_version_table): New
extension.
(riscv_ext_flag_table) Ditto.
* config/riscv/riscv.opt: New mask.

* doc/invoke.texi (RISC-V Options): New extension

gcc/testsuite/ChangeLog:

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

2 months agoi386: Add costs for integer<->float conversions
Jan Hubicka [Tue, 6 May 2025 22:24:04 +0000 (00:24 +0200)] 
i386: Add costs for integer<->float conversions

Extend ix86_rtx_costs to cost FLOAT, UNSIGNED_FLOAT, FIX, and UNSIGNED_FIX.
There are many variants of integer<->float conversions and it seems
meaningful to start with the typical scalar and vector ones. On modern CPUs the
variants differs by at most 1 cycle.

gcc/ChangeLog:

* config/i386/i386.cc (ix86_rtx_costs): Cost FLOAT, UNSIGNED_FLOAT,
FIX, UNSIGNED_FIX.
* config/i386/i386.h (struct processor_costs): Add
cvtsi2ss, cvtss2si, cvtpi2ps, cvtps2pi.
* config/i386/x86-tune-costs.h (struct processor_costs): Update tables.

2 months agoFortran: Fix ICE with use of c_associated.
Jerry DeLisle [Tue, 6 May 2025 03:05:22 +0000 (20:05 -0700)] 
Fortran: Fix ICE with use of c_associated.

PR fortran/120049

gcc/fortran/ChangeLog:

* check.cc (gfc_check_c_associated): Modify checks to avoid
ICE and allow use, intrinsic :: iso_c_binding from a separate
module file.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr120049_a.f90: New test.
* gfortran.dg/pr120049_b.f90: New test.

2 months agolibstdc++: Rewrite atomic builtin checks [PR70560]
Jonathan Wakely [Fri, 25 Apr 2025 20:09:18 +0000 (21:09 +0100)] 
libstdc++: Rewrite atomic builtin checks [PR70560]

Currently the GLIBCXX_ENABLE_ATOMIC_BUILTINS macro checks for a variety
of __atomic built-ins for bool, short and int. If all those checks pass,
then it defines _GLIBCXX_ATOMIC_BUILTINS and uses the definitions from
config/cpu/generic/atomicity_builtins/atomicity.h for the non-inline
versions of __exchange_and_add and __atomic_add that get compiled into
libsupc++.

However, the config/cpu/generic/atomicity_builtins/atomicity.h
definitions only depend on __atomic_fetch_add not on
__atomic_test_and_set or __atomic_compare_exchange. And they only
operate on a variable of type _Atomic word, which is not necessarily one
of bool, short or int (e.g. for sparcv9 _Atomic_word is 64-bit long).

This means that for a target where _Atomic_word is int but there are no
1-byte or 2-byte atomic instructions, GLIBCXX_ENABLE_ATOMIC_BUILTINS
will fail the checks for bool and short and not define the macro
_GLIBCXX_ATOMIC_BUILTINS. That means that we will use a single global
mutex for reference counting in the COW std::string and std::locale,
even though we could use __atomic_fetch_add to do it lock-free.

This commit removes most of the GLIBCXX_ENABLE_ATOMIC_BUILTINS checks,
so that it only checks __atomic_fetch_add on _Atomic_word. The macro
defined by GLIBCXX_ENABLE_ATOMIC_BUILTINS is renamed from
_GLIBCXX_ATOMIC_BUILTINS to _GLIBCXX_ATOMIC_WORD_BUILTINS to better
reflect what it really means. This will enable the inline versions of
__exchange_and_add and __atomic_add for more targets. This is not an ABI
change, because targets which didn't previously use the inline
definitions of those functions made non-inlined calls to the functions
in the library. If the definitions of those functions now start using
atomics, that doesn't change the semantics for the code calling those
functions.

On affected targets, new code compiled after this change will see the
_GLIBCXX_ATOMIC_WORD_BUILTINS macro and so will use the always-inline
versions of __exchange_and_add and __atomic_add, which use
__atomic_fetch_add directly. That is also compatible with older code
which still calls the non-inline definitions, because those non-inline
definitions now also use __atomic_fetch_add.

The only configuration where this could be an ABI change is for a target
which previously defined _GLIBCXX_ATOMIC_BUILTINS (because all the
atomic built-ins for bool, short and int are supported), but which
defines _Atomic_word to some other type for which __atomic_fetch_add is
/not/ supported. Such a target would have called the inline functions
using __atomic_fetch_add, which would actually have depended on
libatomic (which is what the configure checks were supposed to
prevent!).  After this change, that target would not define the new
macro, _GLIBCXX_ATOMIC_WORD_BUILTINS, and so would make non-inline calls
into the library where __exchange_and_add and __atomic_add would use the
global mutex. That would be an ABI break. I don't consider that a
realistic scenario, because it wouldn't have made any sense to define
_Atomic_word to a wider type than int, when doing so would have required
libatomic to make libstdc++.so work. Surely such a target would have
just used int for its _Atomic_word type.

The GLIBCXX_ENABLE_BACKTRACE macro currently uses the
glibcxx_ac_atomic_int variable defined by the checks that this commit
removes from GLIBCXX_ENABLE_ATOMIC_BUILTINS. That wasn't a good check
anyway, because libbacktrace actually depends on atomic loads+stores for
pointers as well as int, and for atomic stores for size_t. This commit
replaces the glibcxx_ac_atomic_int check with a proper test for all the
required atomic operations on all three of int, void* and size_t. This
ensures that the libbacktrace code used for std::stacktrace will either
use native atomics, or implement those loads and stores only in terms of
__sync_bool_compare_and_swap (possibly requiring that to come from
libatomic or elsewhere).

libstdc++-v3/ChangeLog:

PR libstdc++/70560
PR libstdc++/119667
* acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): Only check for
__atomic_fetch_add on _Atomic_word. Define new macro
_GLIBCXX_ATOMIC_WORD_BUILTINS and stop defining macro
_GLIBCXX_ATOMIC_BUILTINS.
(GLIBCXX_ENABLE_BACKTRACE): Check for __atomic_load_n and
__atomic_store_n on int, void* and size_t.
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.host: Fix typo in comment.
* include/ext/atomicity.h (__exchange_and_add, __atomic_add):
Depend on _GLIBCXX_ATOMIC_WORD_BUILTINS macro instead of old
_GLIBCXX_ATOMIC_BUILTINS macro.

2 months agolibstdc++: Fix <numeric> parallel algos for move-only values [PR117905]
Jonathan Wakely [Wed, 4 Dec 2024 21:50:22 +0000 (21:50 +0000)] 
libstdc++: Fix <numeric> parallel algos for move-only values [PR117905]

All of reduce, transform_reduce, exclusive_scan, and inclusive_scan,
transform_exclusive_scan, and transform_inclusive_scan have a
precondition that the type of init meets the Cpp17MoveConstructible
requirements. It isn't required to be copy constructible, so when
passing it to the next internal function it needs to be moved, not
copied. We also need to move when creating local variables on the stack,
and when returning as part of a pair.

libstdc++-v3/ChangeLog:

PR libstdc++/117905
* include/pstl/glue_numeric_impl.h (reduce, transform_reduce)
(transform_reduce, inclusive_scan, transform_exclusive_scan)
(transform_inclusive_scan): Use std::move for __init parameter.
* include/pstl/numeric_impl.h (__brick_transform_reduce)
(__pattern_transform_reduce, __brick_transform_scan)
(__pattern_transform_scan): Likewise.
* include/std/numeric (inclusive_scan, transform_exclusive_scan):
Use std::move to create local copy of the first element.
* testsuite/26_numerics/pstl/numeric_ops/108236.cc: Move test
using move-only type to ...
* testsuite/26_numerics/pstl/numeric_ops/move_only.cc: New test.

2 months agolibstdc++: Fix dangling pointer in fs::path::operator+=(*this) [PR120029]
Jonathan Wakely [Wed, 30 Apr 2025 16:31:01 +0000 (17:31 +0100)] 
libstdc++: Fix dangling pointer in fs::path::operator+=(*this) [PR120029]

When concatenating a path we reallocate the left operand's storage to
make room for the new components being added. When the two operands are
the same object, or the right operand is one of the components of the
left operand, the reallocation invalidates the pointers that refer
into the right operand's storage.

The solution in this commit is to detect these aliasing cases and just
do the concatenation in terms of the contained string, as that code
already handles the case where the string aliases the path. The standard
specifies the concatenation in terms of the native() string, so all this
change does is disable the optimized implementation of concatenation for
path objects which attempts to avoid re-parsing the path from the
concatenated string.

The potential loss of performance for this case isn't likely to be an
issue, because concatenating a path with itself (or one of its existing
components) probably isn't a common use case.

The Filesystem TS implementation doesn't have the optimized form of
concatenation and always does it in terms of the native string and
reparsing the whole thing, so doesn't have this bug. A test is added to
confirm that anyway (that test has some slightly different results due
to different behaviour for trailing slashes and implicit "." filenames
in the TS spec).

libstdc++-v3/ChangeLog:

PR libstdc++/120029
* src/c++17/fs_path.cc (path::operator+=(const path&)): Handle
parameters that alias the path or one of its components.
* testsuite/27_io/filesystem/path/concat/120029.cc: New test.
* testsuite/experimental/filesystem/path/concat/120029.cc: New
test.

2 months agolibstdc++: Fix -Wmismatched-tags warnings for _Safe_iterator [PR120112]
Jonathan Wakely [Tue, 6 May 2025 11:47:32 +0000 (12:47 +0100)] 
libstdc++: Fix -Wmismatched-tags warnings for _Safe_iterator [PR120112]

This causes an ICE as shown in the PR, but it should be fixed in the
library code anyway.

libstdc++-v3/ChangeLog:

PR c++/120112
* include/bits/ptr_traits.h (_Safe_iterator_base): Use class
keyword in class-head of declaration.
* include/debug/debug.h (_Safe_iterator): Likewise.

2 months agoFix PR 119928, formal arguments used to wrongly inferred for CLASS.
Thomas Koenig [Tue, 6 May 2025 16:05:41 +0000 (18:05 +0200)] 
Fix PR 119928, formal arguments used to wrongly inferred for CLASS.

The problem was indeed that generating a formal from an actual
arglist is a bad idea when classes are involved.  Fixed in the
attached patch.  I think it still makes sense to remove the checks
when the other attributes are present (or PR96073 may come back
in different guise, even if I have to test case at present).
I have also converted the test to a run-time check.

gcc/fortran/ChangeLog:

PR fortran/119928
* interface.cc (gfc_check_dummy_characteristics): Do not issue
error if one dummy symbol has been generated from an actual
argument and the other one has OPTIONAL, INTENT, ALLOCATABLE,
POINTER, TARGET, VALUE, ASYNCHRONOUS or CONTIGUOUS.
(gfc_get_formal_from_actual_arglist): Do nothing if symbol
is a class.

gcc/testsuite/ChangeLog:

PR fortran/119928
* gfortran.dg/interface_60.f90: New test.

2 months agoipa: Drop the default value of suffix parameter of create_clone (PR119852)
Martin Jambor [Tue, 6 May 2025 15:28:44 +0000 (17:28 +0200)] 
ipa: Drop the default value of suffix parameter of create_clone (PR119852)

In PR 119852 we agreed that since the NULL-ness of the suffix
parameter should prevent creation of a record in the ipa-clones
dump (which is implemented by a previous patch), it should not default
to NULL.

gcc/ChangeLog:

2025-04-25  Martin Jambor  <mjambor@suse.cz>

PR ipa/119852
* cgraph.h (cgraph_node::create_clone): Remove the default value of
argument suffix.  Update function comment.
* cgraphclones.cc (cgraph_node::create_clone): Update function comment.
* ipa-inline-transform.cc (clone_inlined_nodes): Pass NULL to suffix
of create_clone explicitely.
* ipa-inline.cc (recursive_inlining): Likewise.
* lto-cgraph.cc (input_node): Likewise.

2 months agoipa: Fix create_version_clone_with_body declaration and comment
Martin Jambor [Tue, 6 May 2025 15:28:43 +0000 (17:28 +0200)] 
ipa: Fix create_version_clone_with_body declaration and comment

I noticed that the name of the fifth parameter of
cgraph_node::create_version_clone_with_body is different in the class
definition in cgraph.h and in the actual member function definition in
cgraphclones.cc.  The former (clone_name) is misleading and so this
patch changes it to the latter (suffix) which is also used in related
functions.

The patch also updates the function comment in both places because it
clearly became out of date.

gcc/ChangeLog:

2025-04-25  Martin Jambor  <mjambor@suse.cz>

* cgraph.h (cgraph_node::create_version_clone_with_body): Fix function
comment.  Change the name of clone_name to suffix, in line with the
function definition.
* cgraphclones.cc (cgraph_node::create_version_clone_with_body): Fix
function comment.

2 months agoipa: Do not emit info about temporary clones to ipa-clones dump (PR119852)
Martin Jambor [Tue, 6 May 2025 15:28:43 +0000 (17:28 +0200)] 
ipa: Do not emit info about temporary clones to ipa-clones dump (PR119852)

As described in PR 119852, the output of -fdump-ipa-clones can contain
"(null)" as the suffix/reason for cloning when we need to create a
clone to hold the original function during recursive inlining.  Such
clone is never output and so should not be part of the dump output
either.

gcc/ChangeLog:

2025-04-23  Martin Jambor  <mjambor@suse.cz>

PR ipa/119852
* cgraphclones.cc (dump_callgraph_transformation): Document the
function.  Do not dump if suffix is NULL.

gcc/testsuite/ChangeLog:

2025-04-23  Martin Jambor  <mjambor@suse.cz>

PR ipa/119852
* gcc.dg/ipa/pr119852.c: New test.

2 months agoDocument option -fdump-ipa-clones
Martin Jambor [Tue, 6 May 2025 15:28:42 +0000 (17:28 +0200)] 
Document option -fdump-ipa-clones

I have noticed that the option -fdump-ipa-clones is not documented
although there are users who depend on it.  This patch adds the
missing documentation along with the description of the information it
dumps and the format it uses.

I am never quite sure which of the texinfo mark-ups is the most
appropriate in which situation, I'll of course incorporate any
feedback on this as well as the general wording of the text.

After we settle on a version, I'd like to backport the documentation
also at least to GCC 15, 14 and 13.

Is it perhaps OK for master and the branches or what would better be
changed?

Thanks,

Martin

gcc/ChangeLog:

2025-04-23  Martin Jambor  <mjambor@suse.cz>

* doc/invoke.texi (Developer Options): Document -fdump-ipa-clones.

2 months agolibgcobol: Fix bootstrap for targets without program_invocation_short_name
Iain Sandoe [Tue, 6 May 2025 08:42:40 +0000 (09:42 +0100)] 
libgcobol: Fix bootstrap for targets without program_invocation_short_name

program_invocation_short_name is not widely available, however getprogname()
appears to be a suitable replacement.

Amend the library configuration to look for both. Use program_invocation_short_name
in preference to getprogname() when it is available.  If neither is found fall
back to a constant string.

libgcobol/ChangeLog:

* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Check for program_invocation_short_name and
and getprogname().
* libgcobol.cc (default_exception_handler): When the platform
has program_invocation_short_name, use it otherwise fall
back to using getprogname() or a constant string (if neither
interface is available).

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2 months agodiagnostics: use diagnostic_option_id in one more place
David Malcolm [Tue, 6 May 2025 13:26:19 +0000 (09:26 -0400)] 
diagnostics: use diagnostic_option_id in one more place

No functional change intended.

gcc/ChangeLog:
* selftest-diagnostic.cc (test_diagnostic_context::report): Use
diagnostic_option_id rather than plain int.
* selftest-diagnostic.h (test_diagnostic_context::report):
Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agojson: implement JSON pointer; use it in sarif-replay [PR117988]
David Malcolm [Tue, 6 May 2025 13:26:19 +0000 (09:26 -0400)] 
json: implement JSON pointer; use it in sarif-replay [PR117988]

This patch extends our json class to track JSON pointers (RFC 6901),
and then uses this within sarif-replay to provide logical locations
within the JSON when reporting on issues in the SARIF.

gcc/ChangeLog:
PR sarif-replay/117988
* json.cc (json::pointer::token::token): New ctors.
(json::pointer::token::~token): New.
(json::pointer::token::operator=): New.
(json::object::set): Set the value's m_pointer_token.
(json::array::append): Likewise.
* json.h (json::pointer::token): New struct.
(json::value::get_pointer_token): New accessor.
(json::value::m_pointer_token): New field.
* libsarifreplay.cc (get_logical_location_kind_for_json_kind):
New.
(make_logical_location_from_jv): New.
(sarif_replayer::report_problem): Set the logical location of the
diagnostic.

gcc/testsuite/ChangeLog:
PR sarif-replay/117988
* sarif-replay.dg/2.1.0-invalid/3.1-not-an-object.sarif: Add
expected logical location.
* sarif-replay.dg/2.1.0-invalid/3.11.11-missing-arguments-for-placeholders.sarif:
Likewise.
* sarif-replay.dg/2.1.0-invalid/3.11.11-not-enough-arguments-for-placeholders.sarif:
Likewise.
* sarif-replay.dg/2.1.0-invalid/3.11.5-unescaped-braces.sarif: Likewise.
* sarif-replay.dg/2.1.0-invalid/3.13.2-no-version.sarif: Likewise.
* sarif-replay.dg/2.1.0-invalid/3.13.2-version-not-a-string.sarif: Likewise.
* sarif-replay.dg/2.1.0-invalid/3.13.4-bad-runs.sarif: Likewise.
* sarif-replay.dg/2.1.0-invalid/3.13.4-no-runs.sarif: Likewise.
* sarif-replay.dg/2.1.0-invalid/3.13.4-non-object-in-runs.sarif: Likewise.
* sarif-replay.dg/2.1.0-invalid/3.27.10-bad-level.sarif: Likewise.
* sarif-replay.dg/2.1.0-invalid/3.33.3-index-out-of-range.sarif: Likewise.
* sarif-replay.dg/2.1.0-unhandled/3.27.10-none-level.sarif: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agodiagnostics: support XML and JSON kinds of logical locations
David Malcolm [Tue, 6 May 2025 13:26:18 +0000 (09:26 -0400)] 
diagnostics: support XML and JSON kinds of logical locations

gcc/ChangeLog:
* diagnostic-format-sarif.cc (maybe_get_sarif_kind): Add cases for
new kinds of logical location.
* doc/libgdiagnostics/topics/logical-locations.rst: Add new kinds
of logical location for handling XML and JSON.
* libgdiagnostics.cc (impl_logical_location_manager::get_kind):
Add cases for new kinds of logical location.
(diagnostic_text_sink::text_starter): Likewise, introducing a
macro for this.
(diagnostic_manager_debug_dump_logical_location): Likewise.
* libgdiagnostics.h (enum diagnostic_logical_location_kind_t): Add
new kinds of logical location for handling XML and JSON.
* libsarifreplay.cc (handle_logical_location_object): Add entries
to "kind_values" for decoding sarif logical location kinds
relating to XML and JSON.
* logical-location.h (enum logical_location_kind): Add new kinds
of logical location for handling XML and JSON.

gcc/testsuite/ChangeLog:
* libgdiagnostics.dg/test-nested-logical-locations-json-c.py: New test.
* libgdiagnostics.dg/test-nested-logical-locations-json.c: New test.
* sarif-replay.dg/2.1.0-valid/3.33.7-json-example.sarif: New test.
* sarif-replay.dg/2.1.0-valid/3.33.7-xml-example.sarif: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agosarif output: capture nesting of logical locations [PR116176]
David Malcolm [Tue, 6 May 2025 13:26:18 +0000 (09:26 -0400)] 
sarif output: capture nesting of logical locations [PR116176]

Previously our SARIF output did not capture nesting of logical
locations: any time a result or event referred to a logical location it
would simply put a copy of the logical location into the pertinent
location object without a "parentIndex" property.

With this patch we instead populate such locations with minimal logical
locations with an "index" that refers to theRuns.logicalLocations,
populating theRuns.logicalLocations with the full logical locations,
including "parentIndex", recursively adding entries for the ancestor
locations as needed, so that the SARIF output captures the hierarchical
structure of the logical locations.

gcc/ChangeLog:
PR other/116176
* diagnostic-format-sarif.cc (class sarif_array_of_unique): New
template.
(class sarif_logical_location): Move here from
diagnostic-format-sarif.h.
(sarif_builder::m_cached_logical_locs): New.
(sarif_builder::sarif_builder): Initialize it.
(sarif_builder::set_any_logical_locs_arr): Call
make_minimal_sarif_logical_location rather than
make_sarif_logical_location_object.
(sarif_property_bag::set_logical_location): Likewise.
(make_sarif_logical_location_object): Replace with...
(sarif_builder::ensure_sarif_logical_location_for): ...this.
Capture "parentIndex" property.  Consolidate into
theRuns.logicalLocations.
(sarif_builder::make_minimal_sarif_logical_location): New.
(sarif_builder::make_run_object): Add "index" properties to
m_cached_logical_locs and move it to theRuns.logicalLocations.
(selftest::test_sarif_array_of_unique_1): New.
(selftest::test_sarif_array_of_unique_2): New.
(selftest::diagnostic_format_sarif_cc_tests): Call the new
selftests.
* diagnostic-format-sarif.h (class sarif_logical_location): Move
to diagnostic-format-sarif.cc.
(make_sarif_logical_location_object): Drop decl.
* json.cc (value::compare): New.
(object::compare): New.
(selftest::fail_comparison): New.
(selftest::assert_json_equal): New.
(ASSERT_JSON_EQ): New.
(selftest::assert_json_non_equal): New.
(ASSERT_JSON_NE): New.
(selftest::test_comparisons): New.
(selftest::json_cc_tests): Call the new selftest.
* json.h (json::value::dyn_cast_object): New vfunc.
(json::object::dyn_cast_object): New vfunc impl.
(json::object::compare): New decl.
* libgdiagnostics.cc
(impl_logical_location_manager::get_parent): New.
* logical-location.h (logical_location_manager::get_parent): New
vfunc impl.
* selftest-logical-location.h
(test_logical_location_manager::get_parent): New vfunc impl.
* tree-logical-location.cc (assert_valid_tree): New.
(tree_logical_location_manager::get_short_name): Support types as
well as decls.
(tree_logical_location_manager::get_name_with_scope): Gracefully
handle non-decl nodes.
(tree_logical_location_manager::get_internal_name): Likewise.
(tree_logical_location_manager::get_kind): Don't attempt to handle
null nodes.  Handle NAMESPACE_DECL and RECORD_TYPE.
(tree_logical_location_manager::get_name_for_path_output):
Gracefully handle non-decl nodes.
(tree_logical_location_manager::get_parent): New.
* tree-logical-location.h
(tree_logical_location_manager::get_parent): New vfunc impl.

gcc/testsuite/ChangeLog:
PR other/116176
* g++.dg/sarif-output/logical-locations-1.C: New test.
* g++.dg/sarif-output/logical-locations-1.py: New test script.
* g++.dg/sarif-output/logical-locations-2.C: New test.
* g++.dg/sarif-output/logical-locations-2.py: New test script.
* g++.dg/sarif-output/logical-locations-3.C: New test.
* g++.dg/sarif-output/logical-locations-3.py: New test script.
* g++.dg/sarif-output/sarif-output.exp: New script, adapted
from gcc.dg/sarif-output/sarif-output.exp.
* libgdiagnostics.dg/test-logical-location-c.py: Update for using
theRun.logicalLocations.
* libgdiagnostics.dg/test-warning-with-path-c.py: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agodiagnostics: add logical_location_manager; reimplement logical_location
David Malcolm [Tue, 6 May 2025 13:26:17 +0000 (09:26 -0400)] 
diagnostics: add logical_location_manager; reimplement logical_location

Previously we used an abstract base class logical_location with
concrete subclasses to separate the diagnostics subsystem from
implementation details of "tree" and of libgdiagnostics.

This approach required allocating implementation objects on the heap
whenever working with logical locations, and made comparing logical
locations awkward.

This patch reworks things so that the type "logical_location" becomes a
boxed pointer (const void *), and client code provides a single object
implementing a new logical_location_manager abstract base class.  The
manager class has responsibility for providing meaning to the boxed
pointers.  Within the compiler we use a manager in which they are "tree"
pointers, whereas within libgdiagnostics we use a manager in which they
are pointers to instances of libgdiagnostics'
"struct diagnostic_logical_location".  Other kinds of manager could be
implemented.

gcc/analyzer/ChangeLog:
* checker-event.cc (checker_event::checker_event): Update
initialization of m_logical_loc.
(checker_event::maybe_add_sarif_properties): Add "builder" param.
Replace call to make_sarif_logical_location_object with call to
sarif_property_bag::set_logical_location.
(superedge_event::maybe_add_sarif_properties): Add "builder"
param.
* checker-event.h (checker_event::get_logical_location):
Reimplement.
(checker_event::maybe_add_sarif_properties): Add "builder" param.
(checker_event::maybe_add_sarif_properties): Add "builder" param.
(checker_event::m_logical_loc): Convert from tree_logical_location
to logical_location.
(superedge_event::maybe_add_sarif_properties): Add sarif_builder
param.
* checker-path.h (checker_path::checker_path): Add logical_loc_mgr
param.
* diagnostic-manager.cc
(diagnostic_manager::emit_saved_diagnostic): Pass logical location
manager to emission_path ctor.
(diagnostic_manager::get_logical_location_manager): New.
* diagnostic-manager.h
(diagnostic_manager::get_logical_location_manager): New decl.

gcc/ChangeLog:
* diagnostic-client-data-hooks.h: Include "logical-location.h".
(diagnostic_client_data_hooks::get_logical_location_manager): New.
(diagnostic_client_data_hooks::get_current_logical_location):
Convert return type from const logical_location * to
logical_location.
* diagnostic-format-json.cc: Include
"diagnostic-client-data-hooks.h".
(make_json_for_path): Update to use logical_location_manager from
the context.
* diagnostic-format-sarif.cc
(sarif_builder::get_logical_location_manager): New.
(sarif_builder::make_location_object): Update type of logical_loc
from "const logical_location *" to "logical_location".
(sarif_builder::set_any_logical_locs_arr): Likewise.
(sarif_builder::m_logical_loc_mgr): New field.
(sarif_result::on_nested_diagnostic): Use logical_location default
ctor rather than nullptr.
(sarif_builder::sarif_builder): Initialize m_logical_loc_mgr from
context's client data hooks.
(sarif_builder::make_locations_arr): Convert type of logical_loc
from from "const logical_location *" to "logical_location".
(sarif_builder::set_any_logical_locs_arr): Likewise.  Pass manager
to make_sarif_logical_location_object.
(sarif_builder::make_location_object): Likewise.
(sarif_property_bag::set_logical_location): New.
(make_sarif_logical_location_object): Update for introduction of
logical_location_manager.
(populate_thread_flow_location_object): Pass builder to
ev.maybe_add_sarif_properties.
(selftest::test_make_location_object): Use logical_location
default ctor rather than nullptr.
* diagnostic-format-sarif.h (class logical_location): Replace
forward decl with include of "logical-location.h".
(class sarif_builder): New forward decl.
(sarif_property_bag::set_logical_location): New.
(make_sarif_logical_location_object): Add "mgr" param.
* diagnostic-path.cc
(diagnostic_path::get_first_event_in_a_function): Update for
change of logical_location type.
(per_thread_summary::per_thread_summary): Pass in
"logical_loc_mgr".
(per_thread_summary::m_logical_loc_mgr): New field.
(event_range::m_logical_loc): Update for change of
logical_location type.
(path_summary::get_logical_location_manager): New accessor.
(path_summary::m_logical_loc_mgr): New field.
(path_summary::get_or_create_events_for_thread_id): Pass
m_logical_loc_mgr to per_thread_summary ctor.
(path_summary::path_summary): Initialize m_logical_loc_mgr.
(thread_event_printer::print_swimlane_for_event_range): Add param
"logical_loc_mgr".  Update for change in logical_loc type.
(print_path_summary_as_text): Pass manager to
thread_event_printer::print_swimlane_for_event_range.
(diagnostic_text_output_format::print_path): Update for
introduction of logical_location_manager.
* diagnostic-path.h: Include "logical-location.h".
(class sarif_builder): New forward decl.
(diagnostic_event::get_logical_location): Convert return type from
"const logical_location *" to "logical_location".
(diagnostic_event::maybe_add_sarif_properties): Add sarif_builder
param.
(diagnostic_path::get_logical_location_manager): New accessor.
(diagnostic_path::diagnostic_path): New ctor, taking manager.
(diagnostic_path::m_logical_loc_mgr): New field.
* diagnostic.cc
(diagnostic_context::get_logical_location_manager): New.
(logical_location::function_p): Convert to...
(logical_location_manager::function_p): ...this.
* diagnostic.h (class logical_location): Replace forward decl
with...
(class logical_location_manager): ...this.
(diagnostic_context::get_logical_location_manager): New decl.
* lazy-diagnostic-path.cc
(selftest::test_lazy_path::test_lazy_path): Pass m_logical_loc_mgr
to path ctor.
(selftest::test_lazy_path::make_inner_path): Likewise.
(selftest::test_lazy_path::m_logical_loc_mgr): New field.
* lazy-diagnostic-path.h
(lazy_diagnostic_path::lazy_diagnostic_path): New ctor.
* libgdiagnostics.cc (struct diagnostic_logical_location): Convert
from subclass of logical_location to a plain struct, dropping
accessors.
(class impl_logical_location_manager): New.
(impl_diagnostic_client_data_hooks::get_logical_location_manager):
New
(impl_diagnostic_client_data_hooks::m_logical_location_manager):
New field.
(diagnostic_manager::get_logical_location_manager): New.
(libgdiagnostics_path_event::get_logical_location): Reimplement.
(diagnostic_execution_path::diagnostic_execution_path): Add
logical_loc_mgr and pass to base class.
(diagnostic_execution_path::same_function_p): Update for change to
logical_location type.
(diagnostic::add_execution_path): Pass logical_loc_mgr to path
ctor.
(impl_diagnostic_client_data_hooks::get_current_logical_location):
Reimplement.
(diagnostic_text_sink::text_starter): Reimplement printing of
logical location.
(diagnostic_manager::new_execution_path): Pass mgr to path ctor.
(diagnostic_manager_debug_dump_logical_location): Update for
changes to diagnostic_logical_location.
(diagnostic_logical_location_get_kind): Likewise.
(diagnostic_logical_location_get_parent): Likewise.
(diagnostic_logical_location_get_short_name): Likewise.
(diagnostic_logical_location_get_fully_qualified_name): Likewise.
(diagnostic_logical_location_get_decorated_name): Likewise.
* logical-location.h (class logical_location_manager): New.
(class logical_location): Convert to typedef of
logical_location_manager::key.
* selftest-diagnostic-path.cc
(selftest::test_diagnostic_path::test_diagnostic_path): Pass
m_test_logical_loc_mgr to base ctor.
(selftest::test_diagnostic_path::same_function_p): Use pointer
comparison.
(selftest::test_diagnostic_path::add_event): Use
logical_location_from_funcname.
(selftest::test_diagnostic_path::add_thread_event): Likewise.
(selftest::test_diagnostic_path::logical_location_from_funcname):
New.
(selftest::test_diagnostic_event::test_diagnostic_event): Fix
indentation.  Pass logical_location rather than const char *.
* selftest-diagnostic-path.h
(selftest::test_diagnostic_event::test_diagnostic_event):
Likewise.
(selftest::test_diagnostic_event::get_logical_location): Update
for change to logical_location type.
(selftest::test_diagnostic_event::get_function_name): Drop.
(selftest::test_diagnostic_event::m_logical_loc): Convert from
test_logical_location to logical_location.
(selftest::test_diagnostic_path::logical_location_from_funcname):
New.
(selftest::test_diagnostic_path::m_test_logical_loc_mgr): New
field.
* selftest-logical-location.cc: Include "selftest.h".
(selftest::test_logical_location::test_logical_location): Drop.
(selftest::test_logical_location_manager::~test_logical_location_manager):
New.
(selftest::test_logical_location::get_short_name): Replace with...
(selftest::test_logical_location_manager::get_short_name):
...this.
(selftest::test_logical_location::get_name_with_scope): Replace
with...
(selftest::test_logical_location_manager::get_name_with_scope):
...this.
(selftest::test_logical_location::get_internal_name): Replace
with...
(selftest::test_logical_location_manager::get_internal_name):
...this.
(selftest::test_logical_location::get_kind): Replace with...
(selftest::test_logical_location_manager::get_kind): ...this.
(selftest::test_logical_location::get_name_for_path_output):
Replace with...
(selftest::test_logical_location_manager::get_name_for_path_output):
...this.
(selftest::test_logical_location_manager::logical_location_from_funcname):
New.
(selftest::test_logical_location_manager::item_from_funcname):
New.
(selftest::selftest_logical_location_cc_tests): New.
* selftest-logical-location.h (class test_logical_location):
Replace with...
(class test_logical_location_manager): ...this.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest_logical_location_cc_tests.
* selftest.h (selftest::selftest_logical_location_cc_tests): New
decl.
* simple-diagnostic-path.cc
(simple_diagnostic_path::simple_diagnostic_path): Add
"logical_loc_mgr" param and pass it to base ctor.
(simple_diagnostic_event::simple_diagnostic_event): Update init of
m_logical_loc.
(selftest::test_intraprocedural_path): Update for changes to
logical locations.
* simple-diagnostic-path.h: Likewise.
* tree-diagnostic-client-data-hooks.cc
(compiler_data_hooks::get_logical_location_manger): New.
(compiler_data_hooks::get_current_logical_location): Update.
(compiler_data_hooks::m_current_fndecl_logical_loc): Replace
with...
(compiler_data_hooks::m_logical_location_manager): ...this.
* tree-logical-location.cc
(compiler_logical_location::get_short_name_for_tree): Replace
with...
(tree_logical_location_manager::get_short_name): ...this.
(compiler_logical_location::get_name_with_scope_for_tree): Replace
with...
(tree_logical_location_manager::get_name_with_scope): ...this.
(compiler_logical_location::get_internal_name_for_tree): Replace
with...
(tree_logical_location_manager::get_internal_name): ...this.
(compiler_logical_location::get_kind_for_tree): Replace with...
(tree_logical_location_manager::get_kind): ...this.
(compiler_logical_location::get_name_for_tree_for_path_output):
Replace with...
(tree_logical_location_manager::get_name_for_path_output):
...this.
(tree_logical_location::get_short_name): Drop.
(tree_logical_location::get_name_with_scope): Drop.
(tree_logical_location::get_internal_name): Drop.
(tree_logical_location::get_kind): Drop.
(tree_logical_location::get_name_for_path_output): Drop.
(current_fndecl_logical_location::get_short_name): Drop.
(current_fndecl_logical_location::get_name_with_scope): Drop.
(current_fndecl_logical_location::get_internal_name): Drop.
(current_fndecl_logical_location::get_kind): Drop.
(current_fndecl_logical_location::get_name_for_path_output): Drop.
* tree-logical-location.h (class compiler_logical_location): Drop.
(class tree_logical_location): Drop.
(class current_fndecl_logical_location): Drop.
(class tree_logical_location_manager): New.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic_plugin_test_paths.cc: Update for
changes to simple_diagnostic_path.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months agolibgdiagnostics: add accessors for diagnostic_logical_location [LIBGDIAGNOSTICS_ABI_1]
David Malcolm [Tue, 6 May 2025 13:26:17 +0000 (09:26 -0400)] 
libgdiagnostics: add accessors for diagnostic_logical_location [LIBGDIAGNOSTICS_ABI_1]

For followup work I need to be able to get at data from a
diagnostic_logical_location after creating it, hence the
need to extend libgdiagnostics with accessor entrypoints.

This is the first extension to libgdiagnostics since the initial
release.  The patch uses symbol versioning to add the new
entrypoints in the same way that libgccjit does.

gcc/ChangeLog:
* doc/libgdiagnostics/topics/compatibility.rst: New file, based
on gcc/jit/docs/topics/compatibility.rst.
* doc/libgdiagnostics/topics/index.rst: Add compatibility.rst.
* doc/libgdiagnostics/topics/logical-locations.rst (Accessors):
New section.
* libgdiagnostics++.h (logical_location::operator bool): New.
(logical_location::operator==): New.
(logical_location::operator!=): New.
(logical_location::get_kind): New.
(logical_location::get_parent): New.
(logical_location::get_short_name): New.
(logical_location::get_fully_qualified_name): New.
(logical_location::get_decorated_name): New.
* libgdiagnostics.cc
(diagnostic_logical_location::get_fully_qualified_name): New.
(diagnostic_logical_location_get_kind): New entrypoint.
(diagnostic_logical_location_get_parent): New entrypoint.
(diagnostic_logical_location_get_short_name): New entrypoint.
(diagnostic_logical_location_get_fully_qualified_name): New
entrypoint.
(diagnostic_logical_location_get_decorated_name): New entrypoint.
* libgdiagnostics.h
(LIBDIAGNOSTICS_HAVE_LOGICAL_LOCATION_ACCESSORS): New define.
(diagnostic_logical_location_get_kind): New entrypoint.
(diagnostic_logical_location_get_parent): New entrypoint.
(diagnostic_logical_location_get_short_name): New entrypoint.
(diagnostic_logical_location_get_fully_qualified_name): New
entrypoint.
(diagnostic_logical_location_get_decorated_name): New entrypoint.
* libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_1): New.

gcc/testsuite/ChangeLog:
* libgdiagnostics.dg/test-logical-location.c: Include
<string.h>.
(main): Verify that the accessors work.
* libgdiagnostics.dg/test-logical-location.cc: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 months ago[RISC-V][PR middle-end/114512] Recognize more bext idioms for RISC-V
Shreya Munnangi [Tue, 6 May 2025 12:38:00 +0000 (06:38 -0600)] 
[RISC-V][PR middle-end/114512] Recognize more bext idioms for RISC-V

This is Shreya's next chunk of work.  When I was looking for good bugs for her
to chase down I cam across PR114512.  While the bug isn't necessarily a RISC-V
specific bug, its testcases did show how we were failing to recognize certain
bit extraction idioms and how the lispy nature of RTL allows us to tackle these
issues in the combiner.

First, the bit position may be masked.  The RISC-V port does not define
SHIFT_COUNT_TRUNCATED for valid reasons.  So if we want to optimize away a mask
that matches what the hardware will do, we need suitable insns that include
that explicit masking.

In addition to needing to incorporate masking, the masking may happen in a
subword mode.  So we need to recognize the mask wrapped in a zero extension.

Those two captured the most common cases.

We can also have a single bit extraction implemented as a left shift of the bit
into the sign bit, then a right shift by the size of a word - 1.  These are
less common, but we did cover the case derived from the upstream bug report as
well as one class seen reviewing the instruction stream for spec2017.

Finally, extracting a single bit at a variable position from a constant as seen
with some regularity in spec2017.  In that scenario, combine's chosen split
point wasn't ideal (I forget what it selected, but it definitely wasn't
helpful).  So we've got a new splitter for this case as well.

Earlier versions of this have gone through my tester as well as a bootstrap and
regression cycle.  This version has just gone through a cycle in my tester (but
missed today's bootstrap cycle).

Waiting on the upstream pre-commit tester to render its verdict, but the plan
is to commit on Shreya's behalf once that's clean.

Co-authored-by: Jeff Law <jlaw@ventanamicro.com>
PR middle-end/114512
gcc/
* config/riscv/bitmanip.md (bext* patterns): New patterns for
bext recognition plus splitter for extracting variable bit from
a constant.
* config/riscv/predicates.md (bitpos_mask_operand): New predicate.

gcc/testsuite/
* gcc.target/riscv/pr114512.c: New test.

2 months agoRISC-V: Add testcases for vec_duplicate + vadd.vv combine when GR2VR cost 15
Pan Li [Sat, 3 May 2025 03:37:09 +0000 (11:37 +0800)] 
RISC-V: Add testcases for vec_duplicate + vadd.vv combine when GR2VR cost 15

Add asm dump check and for vec_duplicate + vadd.vv combine to vadd.vx.
The late-combine will not take action when GR2VR cost is 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_vadd-3-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-3-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-3-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-3-i8.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-3-u16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-3-u32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-3-u64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-3-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Add testcases for vec_duplicate + vadd.vv combine when GR2VR cost 1
Pan Li [Sat, 3 May 2025 03:27:50 +0000 (11:27 +0800)] 
RISC-V: Add testcases for vec_duplicate + vadd.vv combine when GR2VR cost 1

Add asm dump check and for vec_duplicate + vadd.vv combine to vadd.vx.
The late-combine will not take action when GR2VR cost is 1.

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_vadd-2-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-2-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-2-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-2-i8.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-2-u16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-2-u32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-2-u64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-2-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Add testcases for vec_duplicate + vadd.vv combine when GR2VR cost 0
Pan Li [Sat, 3 May 2025 02:40:20 +0000 (10:40 +0800)] 
RISC-V: Add testcases for vec_duplicate + vadd.vv combine when GR2VR cost 0

Add asm dump check and run test for vec_duplicate + vadd.vv combine
to vadd.vx.  Introduce new folder to hold all related testcases.

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

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/rvv.exp: Add new folder vx_vf for all
vec_dup + vv to vx testcases.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary.h: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_data.h: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_run.h: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-1-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-1-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-1-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-1-i8.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-1-u16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-1-u32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-1-u64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-1-u8.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-i8.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-u16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-u32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-u64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vadd-run-1-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Combine vec_duplicate + vadd.vv to vadd.vx on GR2VR cost
Pan Li [Thu, 1 May 2025 13:23:54 +0000 (21:23 +0800)] 
RISC-V: Combine vec_duplicate + vadd.vv to vadd.vx on GR2VR cost

This patch would like to combine the vec_duplicate + vadd.vv to the
vadd.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR, it will:

* The pattern matching will be active by default.
* The cost of GR2VR will be added to the total cost of pattern, aka:
  vec_dup cost = gr2vr_cost
  vadd.vv v, (vec_dup (x)) = gr2vr_cost + 1

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_binary_vx_add:
  11   â”‚     beq a3,zero,.L8
  12   â”‚     vsetvli a5,zero,e32,m1,ta,ma // Deleted if GR2VR cost zero
  13   â”‚     vmv.v.x v2,a2                // Ditto.
  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   â”‚     vadd.vv v1,v2,v1
  23   â”‚     vse32.v v1,0(a0)
  24   â”‚     add a0,a0,a4
  25   â”‚     bne a3,zero,.L3

After this patch:
  10   â”‚ test_binary_vx_add:
  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   â”‚     vadd.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/autovec-opt.md (*<optab>_vx_<mode>): Add new
combine to convert vec_duplicate + vadd.vv to vaddvx on GR2VR
cost.
* config/riscv/riscv.cc (riscv_rtx_costs): Take care of the cost
when vec_dup and vadd v, vec_dup(x).
* config/riscv/vector-iterators.md: Add new iterator for vx.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Add gr2vr cost helper function
Pan Li [Tue, 6 May 2025 08:42:16 +0000 (16:42 +0800)] 
RISC-V: Add gr2vr cost helper function

After we introduced the --param=gpr2vr-cost option to set the cost
value of when operation act from gpr to vr, we would like to introduce
a new helper function to get the cost of gp2vr.  And then make sure
all reference to gr2vr should go this helper function.

The helper function will pick up the GR2VR value if the above option is
not provided, or the default GR2VR will be returned.

gcc/ChangeLog:

* config/riscv/riscv-protos.h (get_gr2vr_cost): Add new decl to
get the cost of gr2vr.
* config/riscv/riscv-vector-costs.cc (costs::adjust_stmt_cost):
Leverage the helper function to get the cost of gr2vr.
* config/riscv/riscv.cc (riscv_register_move_cost): Ditto.
(riscv_builtin_vectorization_cost): Ditto.
(get_gr2vr_cost): Add new impl of the helper function.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Add new option --param=gpr2vr-cost= for rvv insn
Pan Li [Tue, 6 May 2025 08:26:06 +0000 (16:26 +0800)] 
RISC-V: Add new option --param=gpr2vr-cost= for rvv insn

During investigate the combine from vec_dup and vop.vv into
vop.vx, we need to depend on the cost of the insn operate
from the gpr to vr, for example, vadd.vx.  Thus, for better
control and test, we introduce a new option, aka below:

--param=gpr2vr-cost=<unsigned int>

To specific the cost value of the insn that operate from
the gpr to vr.

gcc/ChangeLog:

* config/riscv/riscv-opts.h (RVV_GR2VR_COST_UNPROVIDED): Add
new macro to indicate the param is not provided.
* config/riscv/riscv.opt: Add new option --pararm=gpr2vr-cost.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agolibstdc++: Add noexcept to some std::counted_iterator operations
Jonathan Wakely [Thu, 1 May 2025 21:56:56 +0000 (22:56 +0100)] 
libstdc++: Add noexcept to some std::counted_iterator operations

This was inspired by LWG 4245 but goes further. Anything which only
reads or writes the _M_length member can be noexcept. That
member is an iterator difference_type which means it's a signed integer
type or the __max_diff_type integer-like class type, so all arithmetic
and comparisons are non-throwing.

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator.h (counted_iterator): Add noexcept
to friend operators which only access the _M_length member.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agotree-optimization/1157777 - STLF fails with BB vectorization of loop
Richard Biener [Mon, 17 Mar 2025 14:04:28 +0000 (15:04 +0100)] 
tree-optimization/1157777 - STLF fails with BB vectorization of loop

The following tries to address us BB vectorizing a loop body that
swaps consecutive elements of an array like for bubble-sort.  This
causes the vector store in the previous iteration to fail to forward
to the vector load in the current iteration since there's a partial
overlap.

We try to detect this situation by looking for a load to store
data dependence and analyze this with respect to the containing loop
for a proven problematic access.  Currently the search for a
problematic pair is limited to loads and stores in the same SLP
instance which means the problematic load happens in the next
loop iteration and larger dependence distances are not considered.

On x86 with generic costing this avoids vectorizing the loop body,
but once you do core-specific tuning the saved cost for the vector
store vs. the scalar stores makes vectorization still profitable,
but at least the STLF issue is avoided.

For example on my Zen4 machine with -O2 -march=znver4 the testcase in
the PR is improving from
  insertion_sort  =>     2327
to
  insertion_sort  =>      997
but plain -O2 (or -fno-tree-slp-vectorize) gives
  insertion_sort  =>      183
In the end a better target-side cost model for small vector
vectorization is needed to reject this vectorization from this side.

I'll note this is a machine independent heuristic (similar to the
avoid-store-forwarding RTL optimization pass), I expect that uarchs
implementing vectors will suffer from this kind of issue.  I know
some aarch64 uarchs can forward from upper/lower part stores, this
isn't considered at the moment.  The actual vector size/overlap
distance check could be moved to a target hook if it turns out
necessary.

There might be the chance to use a smaller vector size for the loads
avoiding the penalty rather than falling back to elementwise accesses,
that's not implemented either.

PR tree-optimization/1157777
* tree-vectorizer.h (_slp_tree::avoid_stlf_fail): New member.
* tree-vect-slp.cc (_slp_tree::_slp_tree): Initialize it.
(vect_print_slp_tree): Dump it.
* tree-vect-data-refs.cc (vect_slp_analyze_instance_dependence):
For dataflow dependent loads of a store check whether there's
a cross-iteration data dependence that for sure prohibits
store-to-load forwarding and mark involved loads.
* tree-vect-stmts.cc (get_group_load_store_type): For avoid_stlf_fail
marked loads use VMAT_ELEMENTWISE.

* gcc.dg/vect/bb-slp-pr115777.c: New testcase.

2 months agogimple-fold: Fix fold_truth_andor_for_ifcombine [PR120074]
Jakub Jelinek [Tue, 6 May 2025 11:00:10 +0000 (13:00 +0200)] 
gimple-fold: Fix fold_truth_andor_for_ifcombine [PR120074]

The following testcase ICEs because of a mismatch between wide_int
precision, in particular lr_and_mask has 32-bit precision while sign has
16-bit.

decode_field_reference ensures that {ll,lr,rl,rr}_and_mask has
{ll,lr,rl,rr}_bitsize precision, so the
        ll_and_mask |= sign;
and
        rl_and_mask |= sign;
and
        ll_and_mask &= sign;
and
        rl_and_mask &= sign;
cases should work right, sign has in those cases {ll,rl}_bitsize
precision.  The problem is that nothing until much later guarantees
that ll_bitsize == lr_bitsize or rl_bitsize == rr_bitsize.
In the testcase there is
((b ^ a) & 3) < 0
where a is 16-bit and b is 32-bit, so it is the lsignbit handling,
and because of the xor the xor operand is moved to the *r_and_mask, so
with ll_and_mask being 16-bit 3 and lr_and_mask being 32-bit 3.

Now, either b in the above case would be INTEGER_CST, in that case
if rr_arg was also INTEGER_CST we'd use the l_const && r_const case
and try to handle it, or we'd run into (though much later)
      if (ll_bitsize != lr_bitsize || rl_bitsize != rr_bitsize
...
        return 0;

One possibility is dealing with a different precision using wide_int::from.

Another option used in this patch as it is safest is
+         if (ll_bitsize != lr_bitsize)
+           return 0;
          if (!lr_and_mask.get_precision ())
            lr_and_mask = sign;
          else
            lr_and_mask &= sign;
and similarly in the other hunk, i.e. punt if there is a mismatch
early.

And yet another option would be to compute
the sign
      wide_int sign = wi::mask (ll_bitsize - 1, true, ll_bitsize);
      /* If ll_arg is zero-extended and we're testing the sign bit, we know
         what the result should be.  Shifting the sign bit out of sign will get
         us to mask the entire field out, yielding zero, i.e., the sign bit of
         the zero-extended value.  We know the masked value is being compared
         with zero, so the compare will get us the result we're looking
         for: TRUE if EQ_EXPR, FALSE if NE_EXPR.  */
      if (lsignbit > ll_bitsize && ll_unsignedp)
        sign <<= 1;
once again for the lr_and_mask and rr_and_mask cases using rl_bitsize.

As we just return 0; anyway unless l_const && r_const, if l_const & r_const
are false it doesn't really matter what is chosen, but for the const
cases it matters and I'm not sure what is right.  So the second option
might be safest.

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

PR tree-optimization/120074
* gimple-fold.cc (fold_truth_andor_for_ifcombine): For
lsignbit && l_xor case, punt if ll_bitsize != lr_bitsize.  Similarly
for rsignbit && r_xor case, punt if rl_bitsize != rr_bitsize.
Formatting fix.

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

2 months agoFix i386 bootstrap on non-Windows platforms
Jan Hubicka [Tue, 6 May 2025 10:07:15 +0000 (12:07 +0200)] 
Fix i386 bootstrap on non-Windows platforms

* config/i386/i386.cc (ix86_tls_index): Add ifdef.

3 months agotree-optimization/120031 - CTZ pattern matching fails a case
Richard Biener [Tue, 6 May 2025 06:36:01 +0000 (08:36 +0200)] 
tree-optimization/120031 - CTZ pattern matching fails a case

This PR is about the pattern matching in tree-ssa-forwprop.cc not
working for the fallback implementation in ZSTD which uses a cast
aroud the negation of the value to be tested.  There's a pattern
eliding casts in (T')-(T)x already but that only covered an
inner widening conversion.  The following extends this to other
conversions given the negation will then be carried out in an
unsigned type.

PR tree-optimization/120031
* match.pd ((nop_outer_cast)-(inner_cast)var -> -(outer_cast)(var)):
Allow inner conversions that are not widenings when the outer
type is unsigned.

* gcc.target/i386/pr120031.c: New testcase.

3 months agoAllow a PCH to be mapped to a different address
LIU Hao [Wed, 11 May 2022 14:42:53 +0000 (22:42 +0800)] 
Allow a PCH to be mapped to a different address

First, try mapping the PCH to its original address. If that fails, try
letting the system choose one; the PCH can be relocated thereafter.

Reference: https://gcc.gnu.org/pipermail/gcc-patches/2022-May/594556.html

2022-05-11  LIU Hao <lh_mouse@126.com>
Signed-off-by: Jonathan Yong <10walls@gmail.com>
PR pch/14940

gcc/ChangeLog:
* config/i386/host-mingw32.cc (mingw32_gt_pch_use_address):
Replace the loop that attempted to map the PCH only to its
original address with more adaptive operations

3 months agoImplement Windows TLS
Julian Waters [Fri, 2 May 2025 09:59:13 +0000 (09:59 +0000)] 
Implement Windows TLS

This patch implements native Thread Local Storage access on Windows, as motivated by
PR80881. Currently, Thread Local Storage accesses on Windows relies on emulation, which
is detrimental to performance in certain applications, notably the Python Interpreter
and the gcc port of the Java Virtual Machine. This patch was heavily inspired by Daniel
Green's original work on native Windows Thread Local Storage from over a decade ago, which
can be found at https://github.com/venix1/MinGW-GDC/blob/master/patches/mingw-tls-gcc-4.8.patch
as a reference.

Co-authored-by: Eric Botcazou <botcazou@adacore.com>
Co-authored-by: Uroš Bizjak <ubizjak@gmail.com>
Co-authored-by: Liu Hao <lh_mouse@126.com>
Signed-off-by: Julian Waters <tanksherman27@gmail.com>
Signed-off-by: Jonathan Yong <10walls@gmail.com>
gcc/ChangeLog:

* config/i386/i386.cc (ix86_legitimate_constant_p): Handle new UNSPEC.
(legitimate_pic_operand_p): Handle new UNSPEC.
(legitimate_pic_address_disp_p): Handle new UNSPEC.
(ix86_legitimate_address_p): Handle new UNSPEC.
(ix86_tls_index_symbol): New symbol for _tls_index.
(ix86_tls_index): Handle creation of _tls_index symbol.
(legitimize_tls_address): Create thread local access sequence.
(output_pic_addr_const): Handle new UNSPEC.
(i386_output_dwarf_dtprel): Handle new UNSPEC.
(i386_asm_output_addr_const_extra): Handle new UNSPEC.
* config/i386/i386.h (TARGET_WIN32_TLS): Define.
* config/i386/i386.md: New UNSPEC.
* config/i386/predicates.md: Handle new UNSPEC.
* config/mingw/mingw32.h (TARGET_WIN32_TLS): Define.
(TARGET_ASM_SELECT_SECTION): Define.
(DEFAULT_TLS_SEG_REG): Define.
* config/mingw/winnt.cc (mingw_pe_select_section): Select proper TLS section.
(mingw_pe_unique_section): Handle TLS section.
* config/mingw/winnt.h (mingw_pe_select_section): Declare.
* configure: Regenerate.
* configure.ac: New check for broken linker thread local support

3 months agolibgomp: Update SVE test
Tejas Belagod [Fri, 11 Apr 2025 04:32:28 +0000 (10:02 +0530)] 
libgomp: Update SVE test

Fix udr-sve.c target test that to check for the correct results based on the
OpenMP clauses used.  The test was first written with a misunderstood
functionality of the reduction clause.

Tested with aarch64-linux-gnu. OK for trunk?

libgomp/ChangeLog:

* testsuite/libgomp.c-target/aarch64/udr-sve.c: Fix test.

3 months agolibphobos: enable for sparc64-unknown-linux-gnu
Sam James [Sun, 20 Apr 2025 00:43:39 +0000 (01:43 +0100)] 
libphobos: enable for sparc64-unknown-linux-gnu

This bootstraps with some test failures but works well enough to build
11..15.

libphobos/ChangeLog:

* configure.tgt: Add sparc64-unknown-linux-gnu as a supported target.

3 months agoDaily bump.
GCC Administrator [Tue, 6 May 2025 00:17:14 +0000 (00:17 +0000)] 
Daily bump.

3 months ago[RISC-V][PR target/119971] Avoid losing shift count masking
Jeff Law [Mon, 5 May 2025 23:14:29 +0000 (17:14 -0600)] 
[RISC-V][PR target/119971] Avoid losing shift count masking

As is outlined in the PR, we have a few define_insn_and_split patterns which
optimize away explicit masking of shift/bit positions when the masking matches
what the hardware's behavior.

A small number of those define_insn_and_split patterns generate a single
instruction.  It's fairly elegant in that we were essentially just rewriting
the RTL to match an existing pattern.

In one case we'd do the rewriting and later turn a 32bit shift into a bset.
That's not safe because the masking of a 32bit shift uses 0x1f while masking on
bset uses 0x3f on rv64.   The net was incorrect code as seen in the BZ entry.

The fix is pretty simple.  There's no real reason we need to use a
define_insn_and_split.  It was just convenient.  Instead we can use a simple
define_insn.  That avoids a change in the masking behavior for the shift
count/bit position and the masking stays in the RTL.

I quickly scanned the entire port and didn't see any additional
define_insn_and_splits that obviously generated a single instruction outside
the shift/rotate space, though in the vector space that's nontrivial to
ascertain.

This was been run through my tester for the cross configurations, but not the
native bootstrap/regression test (yet).

PR target/119971
gcc/
* config/riscv/bitmanip.md (rotation with masked count): Rewrite
as define_insn patterns.  Fix formatting.
* config/riscv/riscv.md (shift with masked count): Similarly.

gcc/testsuite
* gcc.target/riscv/pr119971.c: New test.
* gcc.target/riscv/zbb-rol-ror-03.c: Adjust test slightly.

3 months agoi386: Do not use explicit operands for MOVS instructions [PR120019]
Uros Bizjak [Mon, 5 May 2025 11:59:43 +0000 (13:59 +0200)] 
i386: Do not use explicit operands for MOVS instructions [PR120019]

Some assemblers do not support MOVS instructions with explicit operands.
Emit instruction with implicit operands, but prefix the instruction with a
segment override prefix if the memory operand refers to ADDR_SPACE_SEG_FS
or ADDR_SPACE_SEG_GS named address space.

PR target/120019

gcc/ChangeLog:

* config/i386/i386.cc (ix86_print_operand): Handle 'v' operand
modifier to emit segment override prefix.
* config/i386/i386.md (*strmovdi_rex_1): Use %v operand modifier
to emit segment override prefix.
(*strmovsi_1): Ditto.
(*strmovhi_1): Ditto.
(*strmovqi_1): Ditto.
(*rep_movdi_rex64): Ditto.
(*rep_movsi): Ditto.
(*rep_movqi): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr111657-1.c (dg-do): Change to "assemble".
(dg-options): Remove -masm=att and add -save-temps.
(dg-final): Update scan-assembler and scan-assembler-not strings.

Co-authored-by: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
3 months agoPR modula2/120117: ICE when attempting to obtain the MAX of an aliased set type
Gaius Mulley [Mon, 5 May 2025 17:16:20 +0000 (18:16 +0100)] 
PR modula2/120117: ICE when attempting to obtain the MAX of an aliased set type

The ICE occurred because of a bug in M2GenGCC.mod:FoldBecomes which
attempted to remove the same quadruple twice.  Thereafter cc1gm2
generated an erroneous error type error as PCSymBuild did not skip
an aliased set type.  The type of the const was set incorrectly
(as a set type) rather than the type of the set element.

gcc/m2/ChangeLog:

PR modula2/120117
* gm2-compiler/M2GenGCC.mod (FoldBecomes): Remove the call to
RemoveQuad since this is performed by TypeCheckBecomes.
* gm2-compiler/PCSymBuild.mod (buildConstFunction): Rewrite
header comment.
Check for a set or a type aliased set and appropriately
skip type equivalences and obtain the element type.
* gm2-compiler/SymbolTable.mod (PutConst): Add call to
CheckBreak.

gcc/testsuite/ChangeLog:

PR modula2/120117
* gm2/pim/pass/highbit.mod: New test.
* gm2/pim/pass/highbit2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
3 months agoAllow IPA_CP to handle UNDEFINED as VARYING.
Andrew MacLeod [Fri, 2 May 2025 19:48:08 +0000 (15:48 -0400)] 
Allow IPA_CP to handle UNDEFINED as VARYING.

When applying a bitmask to reflect ranges, it is sometimes deferred and
this can result in an UNDEFINED result.  IPA is not expecting this, and
add a check for it, and convert to VARYING if encountered.

PR tree-optimization/120048
gcc/
* ipa-cp.cc (ipcp_store_vr_results): Check for UNDEFINED.

gcc/testsuite/
* gcc.dg/pr120048.c: New.

3 months agoRISC-V: Fix gcc.target/riscv/predef-19.c [PR120054]
Kito Cheng [Mon, 5 May 2025 02:08:22 +0000 (10:08 +0800)] 
RISC-V: Fix gcc.target/riscv/predef-19.c [PR120054]

gcc/testsuite/ChangeLog:

PR target/120054
* gcc.target/riscv/predef-19.c: Adjust testcase.

3 months agodwarf2out: Propagate dtprel into the .debug_addr table in resolve_addr_in_expr
Kyle Huey [Fri, 2 May 2025 00:13:47 +0000 (17:13 -0700)] 
dwarf2out: Propagate dtprel into the .debug_addr table in resolve_addr_in_expr

For a debugger to display statically-allocated[0] TLS variables the compiler
must communicate information[1] that can be used in conjunction with knowledge
of the runtime enviroment[2] to calculate a location for the variable for
each thread. That need gives rise to dw_loc_dtprel in dwarf2out, a flag tracking
whether the location description is dtprel, or relative to the
"dynamic thread pointer". Location descriptions in the .debug_info section for
TLS variables need to be relocated by the static linker accordingly, and
dw_loc_dtprel controls emission of the needed relocations.

This is further complicated by -gsplit-dwarf. -gsplit-dwarf is designed to allow
as much debugging information as possible to bypass the static linker to improve
linking performance. One of the ways that is done is by introducing a layer of
indirection for relocatable values[3]. That gives rise to addr_index_table which
ultimately results in the .debug_addr section.

While the code handling addr_index_table clearly contemplates the existence of
dtprel entries[4] resolve_addr_in_expr does not, and the result is that when
using -gsplit-dwarf the DWARF for TLS variables contains an address[5] rather
than an offset, and debuggers can't work with that.

This is visible on a trivial example. Compile

```
static __thread int tls_var;

int main(void) {
  tls_var = 42;
  return 0;
}
```

with -g and -g -gsplit-dwarf. Run the program under gdb. When examining the
value of tls_var before and after the assignment, -g behaves as one would
expect but -g -gsplit-dwarf does not. If the user is lucky and the miscalculated
address is not mapped, gdb will print "Cannot access memory at address ...".
If the user is unlucky and the miscalculated address is mapped, gdb will simply
give the wrong value. You can further confirm that the issue is the address
calculation by asking gdb for the address of tls_var and comparing that to what
one would expect.[6]

Thankfully this is trivial to fix by modifying resolve_addr_in_expr to propagate
the dtprel character of the location where necessary. gdb begins working as
expected and the diff in the generated assembly is clear.

```
        .section        .debug_addr,"",@progbits
        .long   0x14
        .value  0x5
        .byte   0x8
        .byte   0
 .Ldebug_addr0:
-       .quad   tls_var
+       .long   tls_var@dtpoff, 0
        .quad   .LFB0
```

[0] Referring to e.g. __thread as statically-allocated vs. e.g. a
    dynamically-allocated pthread_key_create() call.
[1] Generally an offset in a TLS block.
[2] With glibc, provided by libthread_db.so.
[3] Relocatable values are moved to a table in the .debug_addr section, those
    values in .debug_info are replaced with special values that look up indexes
    in that table, and then the static linker elsewhere assigns a single per-CU
    starting index in the .debug_addr section, allowing those special values to
    remain permanently fixed and the resulting data to be ignored by the linker.
[4] ate_kind_rtx_dtprel exists, after all, and new_addr_loc_descr does produce
    it where appropriate.
[5] e.g. an address in the .tbss/.tdata section.
[6] e.g. on x86-64 by examining %fsbase and the offset in the assembly

2025-05-01  Kyle Huey  <khuey@kylehuey.com>

* dwarf2out.cc (resolve_addr_in_expr): Propagate dtprel into the address
table when appropriate.

3 months agotestsuite: Link gcc.dg/lto/modref-2_0 with libm
John David Anglin [Mon, 5 May 2025 13:30:45 +0000 (09:30 -0400)] 
testsuite: Link gcc.dg/lto/modref-2_0 with libm

2025-05-05  John David Anglin  <danglin@gcc.gnu.org>

gcc/testsuite/ChangeLog:

PR testsuite/120085
* gcc.dg/lto/modref-2_0.c: Link test with libm.

3 months agoAda: Fix assertion failure on Finalizable aspect for tagged record type
Eric Botcazou [Mon, 5 May 2025 10:58:58 +0000 (12:58 +0200)] 
Ada: Fix assertion failure on Finalizable aspect for tagged record type

This is a (benign) assertion failure on the mainline for the new Finalizable
aspect put on a tagged record type when not all the primitives are declared.
This compiles and runs on the 15 branch because assertions are disabled.

gcc/ada/
PR ada/120104
* exp_ch3.adb (Expand_Freeze_Record_Type): For a controlled tagged
type, freeze only the controlled primitives that are present.

gcc/testsuite/
* gnat.dg/specs/finalizable1.ads: New test.

3 months agoc++: Remove obsolete prototype
Simon Martin [Mon, 5 May 2025 08:37:52 +0000 (10:37 +0200)] 
c++: Remove obsolete prototype

I noticed while investigating PR c++/119437 that r8-2724-g88b811bd290630
removed parsing_default_capturing_generic_lambda_in_template but not its
prototype in cp-tree.h.

This patch fixes this.

gcc/cp/ChangeLog:

* cp-tree.h (parsing_default_capturing_generic_lambda_in_template):
Remove obsolete prototype.

3 months agovect-simd-clone-1[6-8][cd].c: Expect in-branch clones for x86: Fix target selector...
Thomas Schwinge [Mon, 5 May 2025 08:21:35 +0000 (10:21 +0200)] 
vect-simd-clone-1[6-8][cd].c: Expect in-branch clones for x86: Fix target selector syntax

Fix-up for commit f9f81d5017adc5d860b24f67aeb89b4e79c7ebdb
"vect-simd-clone-1[6-8][cd].c: Expect in-branch clones for x86", where we lost
the relevant testing, for example, for x86_64, or GCN:

     PASS: gcc.dg/vect/vect-simd-clone-16c.c (test for excess errors)
     UNSUPPORTED: gcc.dg/vect/vect-simd-clone-16c.c -flto -ffat-lto-objects
     PASS: gcc.dg/vect/vect-simd-clone-16c.c execution test
    -PASS: gcc.dg/vect/vect-simd-clone-16c.c scan-tree-dump-times vect "[\\n\\r] [^\\n]* = foo\\.simdclone" 0

     PASS: gcc.dg/vect/vect-simd-clone-16d.c (test for excess errors)
     UNSUPPORTED: gcc.dg/vect/vect-simd-clone-16d.c -flto -ffat-lto-objects
     PASS: gcc.dg/vect/vect-simd-clone-16d.c execution test
    -PASS: gcc.dg/vect/vect-simd-clone-16d.c scan-tree-dump-times vect "[\\n\\r] [^\\n]* = foo\\.simdclone" 0

     PASS: gcc.dg/vect/vect-simd-clone-17c.c (test for excess errors)
     UNSUPPORTED: gcc.dg/vect/vect-simd-clone-17c.c -flto -ffat-lto-objects
     PASS: gcc.dg/vect/vect-simd-clone-17c.c execution test
    -PASS: gcc.dg/vect/vect-simd-clone-17c.c scan-tree-dump-times vect "[\\n\\r] [^\\n]* = foo\\.simdclone" 0

     PASS: gcc.dg/vect/vect-simd-clone-17d.c (test for excess errors)
     UNSUPPORTED: gcc.dg/vect/vect-simd-clone-17d.c -flto -ffat-lto-objects
     PASS: gcc.dg/vect/vect-simd-clone-17d.c execution test
    -PASS: gcc.dg/vect/vect-simd-clone-17d.c scan-tree-dump-times vect "[\\n\\r] [^\\n]* = foo\\.simdclone" 0

     PASS: gcc.dg/vect/vect-simd-clone-18c.c (test for excess errors)
     UNSUPPORTED: gcc.dg/vect/vect-simd-clone-18c.c -flto -ffat-lto-objects
     PASS: gcc.dg/vect/vect-simd-clone-18c.c execution test
    -PASS: gcc.dg/vect/vect-simd-clone-18c.c scan-tree-dump-times vect "[\\n\\r] [^\\n]* = foo\\.simdclone" 0

     PASS: gcc.dg/vect/vect-simd-clone-18d.c (test for excess errors)
     UNSUPPORTED: gcc.dg/vect/vect-simd-clone-18d.c -flto -ffat-lto-objects
     PASS: gcc.dg/vect/vect-simd-clone-18d.c execution test
    -PASS: gcc.dg/vect/vect-simd-clone-18d.c scan-tree-dump-times vect "[\\n\\r] [^\\n]* = foo\\.simdclone" 0

..., which this commit restores.

PR middle-end/112877
gcc/testsuite/
* gcc.dg/vect/vect-simd-clone-16c.c: Fix target selector syntax.
* gcc.dg/vect/vect-simd-clone-16d.c: Likewise.
* gcc.dg/vect/vect-simd-clone-17c.c: Likewise.
* gcc.dg/vect/vect-simd-clone-17d.c: Likewise.
* gcc.dg/vect/vect-simd-clone-18c.c: Likewise.
* gcc.dg/vect/vect-simd-clone-18d.c: Likewise.

3 months ago'libgomp.c/interop-hsa.c': GCN offloading only
Thomas Schwinge [Mon, 5 May 2025 08:19:30 +0000 (10:19 +0200)] 
'libgomp.c/interop-hsa.c': GCN offloading only

Fix-up for commit 8d84ea28510054fbbb8a2b7441916bd75e29163f
"OpenMP, GCN: Add interop-hsa testcase", which added 'libgomp.c/interop-hsa.c'.
If nvptx offloading compilation is enabled in addition to GCN, the former ICEs:

    during RTL pass: final
    [...]/libgomp.c/interop-hsa.c: In function 'get_kernel_ptr':
    [...]/libgomp.c/interop-hsa.c:34:1: internal compiler error: RTL check: expected code 'subreg', have 'reg' in nvptx_print_operand, at config/nvptx/nvptx.cc:3082
    0x1ccdb96 internal_error(char const*, ...)
            [...]/gcc/diagnostic-global-context.cc:517
    0x7446c3 rtl_check_failed_code1(rtx_def const*, rtx_code, char const*, int, char const*)
            [...]/gcc/rtl.cc:770
    0x7fa533 nvptx_print_operand
            [...]/gcc/config/nvptx/nvptx.cc:3082
    0xb25f34 output_operand(rtx_def*, int)
            [...]/gcc/final.cc:3641
    0xb26f07 output_asm_insn(char const*, rtx_def**)
            [...]/gcc/final.cc:3534
    0xb29d91 output_asm_insn(char const*, rtx_def**)
            [...]/gcc/final.cc:2639
    0xb29d91 final_scan_insn_1
            [...]/gcc/final.cc:2642
    0xb2a59f final_scan_insn(rtx_insn*, _IO_FILE*, int, int, int*)
            [...]/gcc/final.cc:2892
    0xb2a68c final_1
            [...]/gcc/final.cc:1983
    0xb2b378 rest_of_handle_final
            [...]/gcc/final.cc:4250
    0xb2b378 execute
            [...]/gcc/final.cc:4328

Regardless of the issue that nvptx offloading compilation probably shouldn't
ICE, the 'asm' insert clearly is valid for GCN only.

libgomp/
* testsuite/libgomp.c/interop-hsa.c: GCN offloading only.

3 months agoc++: Inhibit subsequent warnings/notes in diagnostic_groups with an inhibited warning...
Simon Martin [Mon, 5 May 2025 08:12:08 +0000 (10:12 +0200)] 
c++: Inhibit subsequent warnings/notes in diagnostic_groups with an inhibited warning [PR118163,PR118392]

Those 2 PRs show that even when using a *single* diagnostic_group, it's
possible to end up with a warning being inhibited and its associated
note still emitted, which leads to puzzling user experience. Example
from PR118392:

===
$ gcc/cc1plus inhibit-warn-3.C -w
inhibit-warn-3.C:10:17: note: only here as a â€˜friend’
   10 |     friend void bar();
      |                 ^~~
===

Following a suggestion from ppalka@, this patch keeps track of the
"diagnostic depth" at which a warning in inhibited, and makes sure that
all subsequent notes at that depth or deeper are inhibited as well,
until a subsequent warning or error is accepted at that depth, or the
diagnostic_group or nesting level is popped.

PR c++/118163
PR c++/118392

gcc/ChangeLog:

* diagnostic.cc (diagnostic_context::initialize): Initialize
m_diagnostic_groups.m_inhibiting_notes_from.
(diagnostic_context::inhibit_notes_in_group): New.
(diagnostic_context::notes_inhibited_in_group): New
(diagnostic_context::report_diagnostic): Call
inhibit_notes_in_group and notes_inhibited_in_group.
(diagnostic_context::end_group): Call inhibit_notes_in_group.
(diagnostic_context::pop_nesting_level): Ditto.
* diagnostic.h (diagnostic_context::m_diagnostic_groups): Add
member to track the depth at which a warning has been inhibited.
(diagnostic_context::notes_inhibited_in_group): Declare.
(diagnostic_context::inhibit_notes_in_group): Declare.
* doc/ux.texi: Document diagnostic_group behavior with regards
to inhibited warnings.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/incomplete-type-2.C: New test.
* g++.dg/diagnostic/incomplete-type-2a.C: New test.
* g++.dg/diagnostic/inhibit-warn-3.C: New test.

3 months agotestsuite/120084 - adjust gcc.dg/lto/pr60779_0.c
Richard Biener [Mon, 5 May 2025 07:14:13 +0000 (09:14 +0200)] 
testsuite/120084 - adjust gcc.dg/lto/pr60779_0.c

Require the linker plugin so functions are properly detected as
unused when inlined.

PR testsuite/120084
* gcc.dg/lto/pr60779_0.c: Require linker-plugin.

3 months agoi386: Fix comment typo on truncsfbf2 pattern
Jakub Jelinek [Mon, 5 May 2025 07:17:21 +0000 (09:17 +0200)] 
i386: Fix comment typo on truncsfbf2 pattern

I've noticed a typo on the flag name, fixed thusly.

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

* config/i386/i386.md (truncsfbf2): Fix comment typo,
unsafte -> unsafe.

3 months agoRISC-V: Apply clang-format to genrvv-type-indexer.cc [NFC]
Kito Cheng [Mon, 5 May 2025 02:16:14 +0000 (10:16 +0800)] 
RISC-V: Apply clang-format to genrvv-type-indexer.cc [NFC]

Tweak the formatting of the genrvv-type-indexer.cc file to conform to
the style used by clang-format. This is a no-functional-change commit
that only modifies the formatting of the code.

gcc/Changelog:

* config/riscv/genrvv-type-indexer.cc: Apply clang-format to the
file.

3 months agocobol: Rewrite exception handling. Partially refactor subscript/refmod calculations.
Robert Dubner [Fri, 2 May 2025 20:56:52 +0000 (16:56 -0400)] 
cobol: Rewrite exception handling.  Partially refactor subscript/refmod calculations.

This commit includes changes to exception handling, and changes to the
calculations for offsets and lengths when processing subscripted table entries
and variables with (from:length) reference modifications.

Exception handling in COBOL requires significant amounts of information to be
built at compile time and sent to libgcobol.so at run time.  The changes here
reduce some problems caused by creating structures by the host that are
processed by the target, mainly by creating arrays of simple integers rather
than by turning a structure into a stream of bytes.

Significant changes to the logic of exception handling brings the run-time
performance more in line with the ISO specification.

The handling of COBOL variables that include tables defined with DEPENDING ON
clauses is subtly different when used as sending variables versus when they are
receiving variables.  This commit folds the very similar refer_offset_source
and refer_offset_dest routines into a single refer_offset routine.  It also
streamlines the refer_length_source and refer_length_dest routines by moving
common code into a static refer_length() routine, and having
refer_length_source() and refer_length_dest() each call refer_length() with a
a type flag.

Co-Authored by: James K. Lowden <jklowden@cobolworx.com>
Co-Authored by: Robert Dubner <rdubner@symas.com>

gcc/cobol/ChangeLog:

* cdf.y: Exceptions.
* except.cc (cbl_enabled_exception_t::dump): Likewise.
(cbl_enabled_exceptions_t::dump): Likewise.
(cbl_enabled_exceptions_t::status): Likewise.
(cbl_enabled_exceptions_t::encode): Likewise.
(cbl_enabled_exceptions_t::turn_on_off): Likewise.
(cbl_enabled_exceptions_t::match): Likewise.
(declarative_runtime_match): Likewise. Likewise.
* exceptg.h (struct cbl_exception_files_t): Likewise.
(class exception_turn_t): Likewise.
(apply_cdf_turn): Likewise.
* genapi.cc (treeplet_fill_source): Use refer_offset().
(function_handle_from_name): Likewise.
(parser_initialize_programs): Likewise.
(parser_statement_begin): Likewise.
(array_of_long_long): Exceptions.
(parser_compile_ecs): Exceptions.
(parser_compile_dcls): Exceptions.
(store_location_stuff): Exceptions.
(initialize_variable_internal): Use refer_offset().
(compare_binary_binary): Use refer_offset().
(cobol_compare): Use refer_offset().
(paragraph_label): Formatting.
(parser_goto): Use refer_offset().
(parser_perform_times): Likewise.
(internal_perform_through_times): Likewise.
(parser_enter_file): Exceptions.
(psa_FldLiteralN): Add comment.
(parser_accept): Use refer_offset().
(parser_accept_command_line): Likewise.
(parser_accept_command_line_count): Likewise.
(parser_accept_envar): Likewise.
(parser_set_envar): Likewise.
(parser_display_internal): Likewise.
(parser_initialize_table): Likewise.
(parser_sleep): Likewise.
(parser_allocate): Likewise.
(parser_free): Likewise.
(parser_division): Likewise.
(parser_relop_long): Likewise.
(parser_see_stop_run): Likewise.
(parser_classify): Likewise.
(parser_file_add): Include symbol_table_index in __gg__file_init().
(parser_file_open): Use refer_offset().
(parser_file_write): Move forward declaration of store_location_stuff().
(parser_file_start): Use refer_offset().
(parser_inspect_conv): Likewise:
(parser_intrinsic_numval_c): Likewise:
(parser_intrinsic_subst): Likewise:
(parser_intrinsic_call_1): Likewise:
(parser_intrinsic_call_2): Likewise:
(parser_intrinsic_call_3): Likewise:
(parser_intrinsic_call_4): Likewise:
(parser_sort): Likewise:
(parser_return_start): Exceptions.
(parser_unstring): Use refer_offset().
(create_and_call): Likewise.
(parser_set_pointers): Use refer_offset().
(parser_program_hierarchy): Comment.
(parser_set_handled): Exceptions; removed.
(parser_set_file_number): Exceptions; removed.
(stash_exceptions): Exceptions; removed.
(parser_exception_prepare): Exceptions; removed.
(parser_match_exception): Exceptions; eliminate blob.
(parser_check_fatal_exception): Exceptions.
(parser_push_exception): Create.
(parser_pop_exception): Create.
(mh_identical): Use refer_offset().
(mh_source_is_literalN): Likewise.
(mh_dest_is_float): Likewise.
(mh_numeric_display): Likewise.
(mh_little_endian): Likewise.
(mh_source_is_group): Likewise.
(move_helper): Likewise.
(binary_initial_from_float128): Formatting; change error message.
(initial_from_float128): Change name to "initial_from_initial"
(initial_from_initial): Add one byte to allocation for figconsts.
(parser_symbol_add): Use initial_from_initial().
(parser_symbol_add): Eliminate unneeded logic around actually_create...
* genapi.h: Exceptions.
* genmath.cc (fast_add): Use refer_offset().
(fast_subtract): Likewise.
(fast_multiply): Likewise.
(fast_divide): Likewise.
* genutil.cc: Exceptions; various global definitions.
(get_integer_value): Comment.
(get_data_offset_dest): Eliminate.
(get_data_offset_source): Rename to get_data_offset().
(get_data_offset): Use refer_offset().
(get_binary_value): Likewise; eliminate use of literal_decl_node.
(build_array_of_treeplets): Likewise.
(build_array_of_fourplets): Likewise.
(REFER_CHECK): Comment:
(refer_refmod_length): Use get_any_capacity(); use refer_offset;
set reflen to integer_one_node.
(refer_offset_dest): Change name to refer_offset.
(refer_offset): Use get_data_offset().
(refer_size_dest): Change name to refer_size().
(refer_size): Use get_any_capacity().
(refer_offset_source): Use refer_offset().
(refer_size_source): Likewise.
(qualified_data_source): Likewise.
(qualified_data_dest): Likewise.
(qualified_data_location): Likewise.
* genutil.h: Exceptions; changes to global declarations.
* lexio.cc (likely_nist_file): Added to detect NIST file format.
(cdftext::free_form_reference_format): Handle NIST file format.
* parse.y: (strip_trailing_zeroes): Added.
Changes for exceptions.
* parse_ante.h (parse_error_inc): Likewise.
(YYLLOC_DEFAULT): Likewise.
(static_cast): Likewise.
(is_cobol_word): Change to is_cobol_charset.
(is_cobol_charset): Refine allowed characters.
(require_numeric): Change to require integer.
(require_integer): Likewise.
(current_enabled_ecs): Exceptions.
(is_integer_literal): Change interpretation.
(procedure_division_ready): Exceptions.
(statement_epilog): Likewise.
(statement_begin): Likewise.
* show_parse.h: Changes to GCOBOL_SHOW handling.
* structs.cc: Add symbol_index to cblc_file_t structure.
* symbols.cc (field_str): Repair .initial handling in FldLiteralN.
* symbols.h (struct cbl_field_t): Eliminate literal_decl_node.
(current_enabled_ecs): Exceptions.
* util.cc (cbl_message): Add final newline to error message.
(ftoupper): Added.
(iso_cobol_word): Add list of ISO reserved words.
* util.h (ftoupper): Added.

libgcobol/ChangeLog:

* charmaps.cc: Add #include <vector>.
* common-defs.h (COMMON_DEFS_H_): Add #include <stdio.h>.
(enum cbl_file_mode_t): Add file_mode_any_e.
(enum file_stmt_t): Created.
(cbl_file_mode_str): Add case for file_mode_any_e.
(ec_cmp): Exceptions.
(struct cbl_enabled_exception_t): Likewise.
(struct cbl_declarative_t): Likewise.
(class cbl_enabled_exceptions_array_t): Likewise.
(class cbl_enabled_exceptions_t): Likewise.
(struct cbl_enabled_exceptions_array_t): Likewise.
(enabled_exception_match): Likewise.
* constants.cc: Add #include <vector>.
* exceptl.h (struct cbl_exception_t): Removed.
(struct cbl_declarative_t): Removed.
(class ec_status_t): Removed.
* gcobolio.h: Add symbol_table_index to cblc_file_t.
* gfileio.cc: Add #include <vector>
(establish_status): Comment.
(__io__file_init): Handle symbol_table_index.
(__io__file_delete): Set file->prior_op.
(__io__file_rewrite): Likewise.
(__io__file_read): Likewise.
(__io__file_open): Likewise.
(__io__file_close): Likewise.
* gmath.cc: Include #include <vector>.
* intrinsic.cc: Include #include <vector>.
* libgcobol.cc: Multiple modifications for exceptions.
* valconv.cc: #include <vector>.

3 months agoDaily bump.
GCC Administrator [Mon, 5 May 2025 00:17:44 +0000 (00:17 +0000)] 
Daily bump.

3 months ago[V2][RISC-V] Trivial permutation constant derivation
Jeff Law [Sun, 4 May 2025 22:59:51 +0000 (16:59 -0600)] 
[V2][RISC-V] Trivial permutation constant derivation

This is a patch from late 2024 (just before stage1 freeze), but I never pushed
hard to the change, and thus never integrated it.

It's mostly unchanged except for updating insn in the hash table after finding
an optimizable case.  We were holding the deleted insn in the hash table rather
than the new insn.  Just something I noticed recently.

Bootstrapped and regression tested on my BPI and regression tested riscv32-elf
and riscv64-elf configurations.  We've used this since November internally, so
it's well exercised on spec as well.

gcc/
* config.gcc (riscv): Add riscv-vect-permcost.o to extra_objs.
* config/riscv/riscv-passes.def (pass_vector_permcost): Add new pass.
* config/riscv/riscv-protos.h (make_pass_vector_permconst): Declare.
* config/riscv/riscv-vect-permconst.cc: New file.
* config/riscv/t-riscv: Add build rule for riscv-vect-permcost.o

3 months agoFortran: array subreferences and components of derived types [PR119986]
Harald Anlauf [Sat, 3 May 2025 18:35:57 +0000 (20:35 +0200)] 
Fortran: array subreferences and components of derived types [PR119986]

PR fortran/119986

gcc/fortran/ChangeLog:

* expr.cc (is_subref_array): When searching for array references,
do not terminate early so that inquiry references to complex
components work.
* primary.cc (gfc_variable_attr): A substring reference can refer
to either a scalar or array character variable.  Adjust search
accordingly.

gcc/testsuite/ChangeLog:

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

3 months ago[RISC-V] Adjust rvv tests after recent jump threading change
Jeff Law [Sun, 4 May 2025 17:05:44 +0000 (11:05 -0600)] 
[RISC-V] Adjust rvv tests after recent jump threading change

Richi's jump threading patch is resulting in new jump threading opportunities
triggering in various vsetvl related tests.  When those new threading
opportunities are realized on vector code we usually end up with a different
number of vsetvls due to the inherent block copying.

At first I was adjusting cases to work with the new jump threads, then realized
we could easily end up back here if we change the threading heuristics and
such.  So I just made these tests disable jump threading.  I didn't do it
pervasively, just for those that have been affected.

gcc/testsuite

* gcc.target/riscv/rvv/vsetvl/avl_prop-2.c: Disable jump threading
and adjust number of expected vsetvls as needed.
* gcc.target/riscv/rvv/vsetvl/avl_single-56.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-67.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-68.c: Likewise.
* gcc.target/riscv/rvv/vsetvl/avl_single-71.c: Likewise.

3 months ago[PATCH] RISC-V: Implment H modifier for printing the next register name
Jin Ma [Sun, 4 May 2025 14:44:27 +0000 (08:44 -0600)] 
[PATCH] RISC-V: Implment H modifier for printing the next register name

For RV32 inline assembly, when handling 64-bit integer data, it is
often necessary to process the lower and upper 32 bits separately.
Unfortunately, we can only output the current register name
(lower 32 bits) but not the next register name (upper 32 bits).

To address this, the modifier 'H' has been added to allow users
to handle the upper 32 bits of the data. While I believe the
modifier 'N' (representing the next register name) might be more
suitable for this functionality, 'N' is already in use.
Therefore, 'H' (representing the high register) was chosen instead.

Co-Authored-By: Dimitar Dimitrov <dimitar@dinux.eu>
gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_print_operand): Add H.
* doc/extend.texi: Document for H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/modifier-H-error-1.c: New test.
* gcc.target/riscv/modifier-H-error-2.c: New test.
* gcc.target/riscv/modifier-H.c: New test.

3 months ago[to-be-committed][RISC-V] Adjust testcases and finish register move costing fix
Jeff Law [Sun, 4 May 2025 14:28:56 +0000 (08:28 -0600)] 
[to-be-committed][RISC-V] Adjust testcases and finish register move costing fix

The recent adjustment to more correctly cost register moves tripped a few
testsuite regressions.

I'm pretty torn on the thead test adjustments.  But in reality they only worked
because the register move costing was broken.  So I've reverted the scan-asm
part of those to a prior state for two of those tests.  The other was only
failing at -Og/-Oz which was added to the exclude list.

The other Zfa test is similar, but we can make the test behave with a suitable
-mtune option and thus preserve the test.

While investigating I also noted that vector moves aren't being handled
correctly for subclasses of the integer/fp register files.  So I fixed those
while I was in there.

Note this may have an impact on some of your work Pan.  I haven't followed the
changes from the last week or so due to illness.

Waiting on pre-commit's verdict, though it did spin through my tester
successfully, though not all of the regressions related to that change are
addressed (there's still one for rv32 I'll look at shortly).

gcc/
* config/riscv/riscv.cc (riscv_register_move_cost): Handle
subclasses with vector registers as well.

gcc/testsuite/

* gcc.target/riscv/xtheadfmemidx-xtheadfmv-medany.c: Adjust expected
output.
* gcc.target/riscv/xtheadfmemidx-zfa-medany.c: Likewise.
* gcc.target/riscv/xtheadfmv-fmv.c: Skip for -Os and -Oz.
* gcc.target/riscv/zfa-fmovh-fmovp.c: Use sifive-p400 tuning.

3 months agoImprove maybe_hot handling in inliner heuristics
Jan Hubicka [Sun, 4 May 2025 08:52:35 +0000 (10:52 +0200)] 
Improve maybe_hot handling in inliner heuristics

Inliner currently applies different heuristics to hot and cold calls (the
second are inlined only if the code size will shrink).  It may happen that the
call itself is hot, but the significant time is spent in callee and inlining
makes it faster.  For this reason we want to check if the anticipated speedup
is considered hot which is done by this patch (that is similar ot my earlier
ipa-cp change).

In general I think this is less important compared to ipa-cp change, since large
benefit from inlining happens only when something useful is propagated into the
callee and should be handled earlier by ipa-cp. However the patch improves
SPEC2k17 imagick runtime by about 9% as discussed in PR 11900 though it is
mostly problem of bad train data set which does not train well parts of program
that are hot for ref data set.  As discussed in the PR log, the particular call
that needs to be inlined has count that falls very slightly bellow the cutoff
and scaling it up by expected savings enables inlining.

gcc/ChangeLog:

PR target/119900
* cgraph.cc (cgraph_edge::maybe_hot_p): Add
a variant accepting a sreal scale; use reliability of
profile.
* cgraph.h (cgraph_edge::maybe_hot_p): Declare
a varaint accepting a sreal scale.
* ipa-inline.cc (callee_speedup): New function.
(want_inline_small_function_p): add early return
and avoid duplicated lookup of summaries; use scaled
maybe_hot predicate.

3 months agoRISC-V: Remove unnecessary frm restore volatile define_insn
Pan Li [Sun, 4 May 2025 01:26:02 +0000 (09:26 +0800)] 
RISC-V: Remove unnecessary frm restore volatile define_insn

After we add the frm register to the global_regs, we may not need to
define_insn that volatile to emit the frm restore insns.  The
cooperatively-managed global register will help to handle this, instead
of emit the volatile define_insn explicitly.

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_emit_frm_mode_set): Refactor
the frm mode set by removing fsrmsi_restore_volatile.
* config/riscv/vector-iterators.md (unspecv): Remove as
unnecessary.
* config/riscv/vector.md (fsrmsi_restore_volatile): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/float-point-dynamic-frm-49.c: Adjust
the asm dump check times.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-50.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-52.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-74.c: Ditto.
* gcc.target/riscv/rvv/base/float-point-dynamic-frm-75.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
3 months agoDaily bump.
GCC Administrator [Sun, 4 May 2025 00:16:35 +0000 (00:16 +0000)] 
Daily bump.

3 months agoc++: let plain -Wabi warn about future changes
Jason Merrill [Thu, 1 May 2025 13:42:40 +0000 (09:42 -0400)] 
c++: let plain -Wabi warn about future changes

c_common_post_options limits flag_abi_version and flag_abi_compat_version to
actual ABI version numbers, but let's not do that for warn_abi_version; we
might want to add a warning relative to a future ABI version that isn't
available in the current release, such backporting the PR120012 warning.

Also allow plain -Wabi to include such a warning without complaining that
it's useless.

Also warn about an unsupported -fabi-version argument.

gcc/c-family/ChangeLog:

* c-opts.cc (c_common_post_options): Let plain -Wabi warn
about changes in a future version.

3 months agoc++: add fixed testcase [PR85944]
Jason Merrill [Fri, 2 May 2025 14:47:01 +0000 (10:47 -0400)] 
c++: add fixed testcase [PR85944]

This testcase was incidentally fixed by r16-325 for PR119162.

PR c++/85944

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-temp3.C: New test.

3 months agoImprove ix86 VEC_MERGE costs
Jan Hubicka [Fri, 2 May 2025 22:26:29 +0000 (00:26 +0200)] 
Improve ix86 VEC_MERGE costs

ix86_rtx_costs VEC_MERGE by special casing AVX512 mask operations and otherwise
returning cost->sse_op completely ignoring costs of the operands.  Since
VEC_MERGE is also used to represent scalar variant of SSE/AVX operation, this
means that many instructions (such as SSE converisions) are often costed as
sse_op instead of their real cost.

This patch adds pattern matching for the VEC_MERGE pattern which also forced me
to add special cases for masked versions and vcmp otherwise combine is confused
by the default cost compred to the cost of recognized version of the
instruction.

Since now the important cases should be handled, I also added recursion to the
remaining cases so substituting constants and memory is adequately costed.

gcc/ChangeLog:

* config/i386/i386.cc (unspec_pcmp_p): New function.
(ix86_rtx_costs): Cost VEC_MERGE more realistically.

3 months agoDaily bump.
GCC Administrator [Sat, 3 May 2025 00:18:18 +0000 (00:18 +0000)] 
Daily bump.

3 months agosimplify-rtl: Fix crash due to simplify_with_subreg_not [PR120059]
Andrew Pinski [Fri, 2 May 2025 16:46:24 +0000 (09:46 -0700)] 
simplify-rtl: Fix crash due to simplify_with_subreg_not [PR120059]

r16-286-gd84fbc516ea57d added a call to simplify_gen_subreg but didn't
check if the result of simplify_gen_subreg was non-null. simplify_gen_subreg
can return NULL if the subreg would be not valid. In the case below we had
a hard register for the SSE register xmm0 of mode SI and doing a subreg to
QI mode but QImode is not a valid mode for the SSE register so simplify_gen_subreg
would return NULL.

This adds the obvious check.

Pushed as obvious after bootstrap/test on x86_64-linux-gnu.

PR rtl-optimization/120059

gcc/ChangeLog:

* simplify-rtx.cc (simplify_with_subreg_not): Check the result
of simplify_gen_subreg.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr120059-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agoc: Fix up RAW_DATA_CST handling in check_constexpr_init [PR120057]
Jakub Jelinek [Fri, 2 May 2025 19:19:05 +0000 (21:19 +0200)] 
c: Fix up RAW_DATA_CST handling in check_constexpr_init [PR120057]

The pr120057-1.c testcase is incorrectly rejected since
 r15-4377 (and for a while it also ICEd after the error), i.e.
the optimization of large C initializers using RAW_DATA_CST.
Similarly, the embed-18.c testcase is incorrectly rejected since
the embed support has been introduced and RAW_DATA_CST used for that.

The callers of check_constexpr_init (store_init_value and
output_init_element) compute int_const_expr as
      int_const_expr = (TREE_CODE (init) == INTEGER_CST
                        && !TREE_OVERFLOW (init)
                        && INTEGRAL_TYPE_P (TREE_TYPE (init)));
but that is only passed through down to check_constexpr_init.
I think tweaking those 2 callers to also allow RAW_DATA_CST for
int_const_expr when check_constexpr_init needs top special case it
no matter what would be larger, so the patch just changes
check_constexpr_init to deal with RAW_DATA_CST in the initializers.
For TYPE_UNSIGNED char precision integral types RAW_DATA_CST is
always valid, for !TYPE_UNSIGNED we need to check for 128-255 values
being turned into negative ones.

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

PR c/120057
* c-typeck.cc (check_constexpr_init): Handle RAW_DATA_CST.

* gcc.dg/cpp/embed-18.c: New test.
* gcc.dg/pr120057-1.c: New test.
* gcc.dg/pr120057-2.c: New test.

3 months agoranger: Improve nonnull_if_nonzero attribute [PR117023]
Jakub Jelinek [Fri, 2 May 2025 17:40:55 +0000 (19:40 +0200)] 
ranger: Improve nonnull_if_nonzero attribute [PR117023]

On Mon, Mar 31, 2025 at 11:30:20AM -0400, Andrew MacLeod wrote:
> Infer range processing was adjusted to allow a query to be specified,
> but during VRP folding, ranger w3as not providing a query.  This results
> in contextual ranges being missed.   Pass the cache in as the query
> which provide a read-only query of the current state.

Now that this patch is in, I've retested my patch and it works fine.
If we can determine a range for the arg2 argument and prove that it
doesn't include zero, we can imply nonzero for the arg1 argument.

2025-05-02  Jakub Jelinek  <jakub@redhat.com>
    Andrew MacLeod  <amacleod@redhat.com>

PR c/117023
* gimple-range-infer.cc (gimple_infer_range::gimple_infer_range):
For nonnull_if_nonzero attribute check also arg2 range if it doesn't
include zero and in that case call add_nonzero too.

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

3 months agocobol: Fix up exception handling [PR119364]
Jakub Jelinek [Fri, 2 May 2025 17:10:59 +0000 (19:10 +0200)] 
cobol: Fix up exception handling [PR119364]

The following patch on top of the
https://gcc.gnu.org/pipermail/gcc-patches/2025-May/682500.html
fixes most of the remaining make check-cobol FAILs in the
i686-linux -> x86_64-linux cross-compiler.

Using the testing environment detailed in
https://gcc.gnu.org/pipermail/gcc-patches/2025-April/680403.html
with this patch I get just cobol.dg/group1/declarative_1.cob FAILs
in i686-linux -> x86_64-linux cross and no FAILs in x86_64-linux
native one.

The patch isn't needed just for cross-compilation with different
hosts, but also on x86_64-linux/aarch64-linux native, because without
it the FE is hashing padding bits which contain random garbage and making
code generation decisions based on that.  That is very much against the
reproduceability requirements.

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

PR cobol/119364
* structs.h (cbl_enabled_exception_type_node): New variable
declaration.
* structs.cc (cbl_enabled_exception_type_node): New variable.
(create_cbl_enabled_exception_t): New function.
(create_our_type_nodes): Initialize cbl_enabled_exception_type_node
using it.
* genapi.cc (stash_exceptions): Don't compare padding bits to
determine if the exceptions are the same as last time.  Use
cbl_enabled_exception_type_node for target size and field offsets
and native_encode_expr to write each field into byte sequence.

3 months agocobol, v2: Fix up cobol cross-compilation from 32-bit arches [PR119364]
Jakub Jelinek [Fri, 2 May 2025 17:09:34 +0000 (19:09 +0200)] 
cobol, v2: Fix up cobol cross-compilation from 32-bit arches [PR119364]

Right now it is not possible to even build cross-compilers from 32-bit
architectures to e.g. x86_64-linux or aarch64-linux, even from little-endian
ones.

The following patch attempts to fix that.

There were various issues seen e.g. trying to build i686-linux ->
x86_64-linux cross-compiler (so still 64-bit libgcobol, but the compiler
is 32-bit).
1) warning about >> 32 shift of size_t, on 32-bit arches size_t is 32-bit
   and so the shift is UB; fixed by doing (new_size>>16)>>16 so that
   it ors in >> 32 when new_size is 64-bit and 0 when it is 32-bit
2) enum cbl_field_attr_t was using size_t as underlying type, but has
   various bitmasks which require full 64-bit type; changed this to uint64_t
   underlying type and using unsigned long long in the structure; various
   routines which operate with those attributes had to be changed also to
   work with uint64_t instead of size_t
3) on i686-linux, config.h can #define _FILE_OFFSET_BITS 64 or similar
   macros; as documented, those macros have to be defined before including
   first C library header, but some sources included cobol-system.h which
   includes config.h only after various other headers; this resulted in
   link failures, as ino_t was sometimes unsigned long and sometines
   unsigned long long, depending on whether config.h was included first or
   not, and e.g. cobol_filename uses ino_t argument
4) lots of places used %ld or %lx *printf format specifers with size_t
   arguments; that works only if size_t is unsigned long, but not when it
   is unsigned int or unsigned long long or some other type; now while
   ISO C99 has %zd or %zx to print size_t and C++14 includes C99 (or C11?),
   while for the C++ headers the C++ compilers typically have full control
   over it and so support everything in C++14 (e.g. libstdc++ in GCC 5.1+
   or libc++ if not too old), for C library we are dependent on the system
   C library (note, on the host for the compiler side).  And not all hosts
   support C99 in their C libraries; so instead of just changing it to
   %zd or %zx, I'm changing it to what we use elsewhere in GCC,
   HOST_SIZE_T_PRINT_{DEC,UNSIGNED,HEX_PURE} or GCC_PRISZ macros in the
   *printf family format string and casts of the size_t arguments to
   fmt_size_t.  Note, if not using the C library *printf family (e.g. in
   dbgmsg, sprintf, snprintf, fprintf, etc.) but the GCC diagnostic code
   (e.g. err_msg, error, warning, yywarn, ...), then %zd/%zu is supported
   and on the other side HOST_SIZE_T_PRINT_{DEC,UNSIGNED,HEX_PURE} etc.
   macros shouldn't be used (for two reasons, because it is unnecessary
   when %zd/%zu is guaranteed to be supported there because GCC has
   control over that and more importantly because it breaks translations,
   both extraction of the to be translated strings and we don't want to
   have different messages, once with %lld, once with %ld, once with just %d
   or %I64d depending on host, translators couldn't translate it all).
5) see above, there were already tons of %zd/%zu or %3zu etc. format
   specifers in *printf format strings, this patch changes those too
6) I've noticed dbgmsg wasn't declared with printf attribute, which resulted
   in bugs where format specifiers didn't match actually passed types of
   arguments

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

PR cobol/119364
libgcobol/
* valconv.cc (__gg__realloc_if_necessary): Use (new_size>>16)>>16;
instead of new_size>>32; to avoid warnings on 32-bit hosts.
* common-defs.h (enum cbl_field_attr_t): Use uint64_t
as underlying type rather than size_t.
* gcobolio.h (cblc_field_t): Change attr member type from size_t
to unsigned long long.
gcc/cobol/
* util.cc (is_numeric_edited): Use HOST_SIZE_T_PRINT_UNSIGNED
instead of "%zu" and cast corresponding argument to fmt_size_t.
(normalize_picture): Use GCC_PRISZ instead of "z" and pass address
of fmt_size_t var to sscanf and copy afterwards.
(cbl_refer_t::str): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" and cast corresponding argument
to fmt_size_t.
(struct move_corresponding_field): Likewise.
(valid_move): Likewise.
(ambiguous_reference): Likewise.
(parent_names): Likewise.
(find_corresponding::find_corresponding): Likewise.
(corresponding_fields): Likewise.
(unique_stack::push): Likewise.
(cobol_filename): Likewise.
* lexio.cc: Include config.h first.
(recognize_replacements): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" and cast corresponding argument
to fmt_size_t.
(check_source_format_directive): Likewise.
(parse_replacing_pair): Use size_t(0) instead of 0UL in span_t
construction.
(parse_replace_pairs): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(parse_copy_directive): Likewise.
(parse_replace_last_off): Likewise.
(parse_replace_text): Likewise.
(bytespan_t::append): Likewise.
(cdftext::map_file): Likewise.
(cdftext::process_file): Likewise.
* symfind.cc (dump_symbol_map2): Likewise.
(dump_symbol_map_value): Likewise.
(build_symbol_map): Likewise.
(is_name::dump_key): Likewise.
(symbol_match2): Likewise.
(symbol_find): Likewise.
(symbol_find_of): Likewise.
* cdf.y: Likewise.
* symbols.cc: Include config.h first.
(cbl_field_t::set_attr): Return uint64_t rather than size_t
and replace size_t(attr) with uint64_t(attr).
(cbl_field_t::clear_attr): Likewise.
(symbol_field_capacity): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(symbol_find_odo_debug): Likewise.
(symbols_dump): Likewise.
(calculate_capacity): Likewise.
(field_str): Likewise.
(symbols_update): Likewise.
(symbol_field_forward): Likewise.
(numeric_group_attrs): Return uint64_t rather than size_t and
change inherit variable to from size_t to uint64_t.
(new_literal_add): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(temporaries_t::dump): Likewise.
(cbl_label_t::str): Likewise.
(symbol_label_add): Likewise.
(symbol_program_add): Likewise.
(symbol_forward_names): Likewise.
(symbol_forward_to): Likewise.
(cbl_file_key_t::deforward): Likewise.
(cbl_file_key_t::str): Likewise.
* gengen.cc (show_type): Use PRId64 instead of "ld".
(gg_unique_in_function): Use HOST_SIZE_T_PRINT_DEC instead of
%ld and cast corresponding argument to fmt_size_t.
* scan.l: Add %top section with #include "config.h".
* genmath.cc (parser_add): Use HOST_SIZE_T_PRINT_DEC instead of
%ld and cast corresponding argument to fmt_size_t.
(parser_subtract): Likewise.
* parse.y: Include "config.h" before <fstream>.  Use
HOST_SIZE_T_PRINT_UNSIGNED instead of "%zu" and cast corresponding
argument to fmt_size_t.  Change type of sign_attrs, group_sign and
type_implies from size_t to uint64_t.
(perform_t::ec_labels_t::new_label): Use HOST_SIZE_T_PRINT_UNSIGNED
instead of "%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC
instead of "%zd" and cast corresponding argument to fmt_size_t.
(stringify_src_t::dump): Likewise.
(lang_check_failed): Likewise.
(numstr2i): Use GCC_PRISZ instead of "z" and pass address of temporary
with fmt_size_t type to sscanf and then copy it over.
(initialize_statement): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(dump_inspect_oper): Likewise.
(new_literal): Likewise.
(literal_subscripts_valid): Likewise.
(eval_subject_t::label): Likewise.
* genapi.cc (level_88_helper): Likewise.
(parser_call_targets_dump): Likewise.
(combined_name): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(section_label): Likewise.
(paragraph_label): Likewise.
(leave_procedure): Likewise.
(parser_perform): Likewise.
(parser_perform_times): Likewise.
(internal_perform_through): Likewise.
(internal_perform_through_times): Likewise.
(parser_enter_program): Likewise.
(parser_init_list_size): Likewise.
(parser_init_list): Likewise.
(psa_FldLiteralN): Likewise.
(psa_FldBlob): Likewise.
(parser_assign): Likewise.
(parser_free): Pass p->field->name to dbgmsg.
(parser_division): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(perform_outofline_before_until): Likewise.
(perform_outofline_after_until): Likewise.
(perform_outofline_testafter_varying): Likewise.
(perform_outofline_before_varying): Likewise.
(perform_inline_testbefore_varying): Likewise.
(parser_inspect): Change n_operations parameter type from
unsigned long to size_t.
(parser_intrinsic_callv): Use HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(parser_bitop): Use HOST_SIZE_T_PRINT_HEX_PURE instead of
"%lx" and cast corresponding argument to fmt_size_t.
(parser_bitwise_op): Likewise.
(parser_program_hierarchy): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(parser_set_handled): Use HOST_SIZE_T_PRINT_HEX_PURE instead of
"%lx" and cast corresponding argument to fmt_size_t.
(parser_set_numeric): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(psa_new_var_decl): Use HOST_SIZE_T_PRINT_DEC instead of "%ld"
and cast corresponding argument to fmt_size_t.
(parser_symbol_add): Use HOST_SIZE_T_PRINT_DEC instead of "%zd"
or HOST_SIZE_T_PRINT_HEX_PURE instead of "%lx" and cast corresponding
argument to fmt_size_t.
* cdf-copy.cc: Include "config.h" first.
* scan_ante.h (trim_location): Use HOST_SIZE_T_PRINT_UNSIGNED instead
of "%zu" or "%d" and cast corresponding argument to fmt_size_t.
* structs.cc (create_cblc_field_t): Use ULONGLONG instead of SIZE
for "attr".
* cbldiag.h (dbgmsg): Add ATTRIBUTE_PRINTF_1.
* gcobolspec.cc (lang_specific_driver): Use HOST_SIZE_T_PRINT_DEC
instead of "%ld" and cast corresponding argument to fmt_size_t.
* parse_ante.h (literal_of): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(evaluate_elem_t::dump): Likewise.
(arith_t::another_pair): Likewise.
(current_t::end_program): Likewise.
(file_add): Likewise.
(implicit_paragraph): Likewise.
(implicit_section): Likewise.
(data_division_ready): Use HOST_SIZE_T_PRINT_DEC instead of "%d"
and cast corresponding argument to fmt_size_t.
* symbols.h (struct cbl_field_t): Change attr member type from size_t
to uint64_t.
(cbl_field_t::set_attr): Change return type from size_t to uint64_t.
(cbl_field_t::clear_attr): Likewise.
(function_descr_t::init): Use HOST_SIZE_T_PRINT_UNSIGNED instead of
"%zu" or GCC_PRISZ instead of "z" or HOST_SIZE_T_PRINT_DEC instead
of "%zd" and cast corresponding argument to fmt_size_t.
(cbl_perform_tgt_t::dump): Likewise.
(numeric_group_attrs): Change return type from size_t to uint64_t.

3 months agolibsanitizer: Fix build with glibc 2.42
Florian Weimer [Fri, 2 May 2025 15:41:43 +0000 (17:41 +0200)] 
libsanitizer: Fix build with glibc 2.42

The termio structure will be removed from glibc 2.42.  It has
been deprecated since the late 80s/early 90s.

Cherry-picked from LLVM commit 59978b21ad9c65276ee8e14f26759691b8a65763
("[sanitizer_common] Remove interceptors for deprecated struct termio
(#137403)").

Co-Authored-By: Tom Stellard <tstellar@redhat.com>
libsanitizer/

* sanitizer_common/sanitizer_common_interceptors_ioctl.inc: Cherry
picked from LLVM commit 59978b21ad9c65276ee8e14f26759691b8a65763.
* sanitizer_common/sanitizer_platform_limits_posix.cpp: Likewise.
* sanitizer_common/sanitizer_platform_limits_posix.h: Likewise.

3 months agoRevert "[PATCH 30/61] MSA: Make MSA and microMIPS R5 unsupported"
Jeff Law [Fri, 2 May 2025 14:12:23 +0000 (08:12 -0600)] 
Revert "[PATCH 30/61] MSA: Make MSA and microMIPS R5 unsupported"

This reverts commit 727a43e0a66052235706379239359807230054e0.

3 months agoMake ix86 cost of VEC_SELECT equivalent to SUBREG cost 1
Jan Hubicka [Fri, 2 May 2025 13:53:35 +0000 (15:53 +0200)] 
Make ix86 cost of VEC_SELECT equivalent to SUBREG cost 1

This patch fixes regression of imagick with PGO and AVX512 where correcting size
cost of SSE operations (to be 4 instead of 2 originally cut&pasted from x87)
made late combine to eliminate zero registers introduced by rapd.  The problem
is that cost-model mistakely accounts VEC_SELECT as real instruction while it is
optimized to nothing if src==dest (which is the case of these testcases).
This register is used to eliminate false dependency between source and destination
of int->fp conversions.

While ix86_insn_cost hook already contains logic to incrase cost of the zero-extend
the costs was not enough.

gcc/ChangeLog:

PR target/119900
* config/i386/i386.cc (ix86_can_change_mode_class): Add TODO
comment.
(ix86_rtx_costs): Make VEC_SELECT equivalent to SUBREG cost 1.

3 months agoc++: CTAD and constexpr ctor [PR115207]
Jason Merrill [Fri, 2 May 2025 12:35:38 +0000 (08:35 -0400)] 
c++: CTAD and constexpr ctor [PR115207]

Here we failed to constant-evaluate the A<int> constructor because DECL_SIZE
wasn't set on 'a' yet, so compare_address thinks we can't be sure it isn't
at the same address as 'i'.

Normally DECL_SIZE is set by build_decl calling layout_decl, but that
doesn't happen here because we don't have a type yet.  So we need to
layout_decl again after deduction.

PR c++/115207

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Call layout_decl after CTAD.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/class-deduction118.C: New test.

3 months agoc++: fix some testcases
Jason Merrill [Fri, 2 May 2025 13:33:39 +0000 (09:33 -0400)] 
c++: fix some testcases

After r16-332 these tests started failing.  constexpr-89285.C should have
always given this error, and the new nonlit19.C needs to remove the
destructor body to prevent -fimplicit-constexpr from making the testcase
well-formed.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/constexpr-89285.C: Always diagnose reinterpret_cast.
* g++.dg/cpp23/constexpr-nonlit19.C: Remove ~A body.

3 months agoc++: C++17/20 class layout divergence [PR120012]
Jason Merrill [Wed, 30 Apr 2025 14:18:46 +0000 (10:18 -0400)] 
c++: C++17/20 class layout divergence [PR120012]

C++20 made a class with only explicitly defaulted constructors no longer
aggregate, and this wrongly affected whether the class is considered "POD
for layout purposes" under the ABI.

Conveniently, we already have check_non_pod_aggregate to diagnose cases
where this makes a difference, due to PR103681 around a C++14 aggregate
change.

PR c++/120012

gcc/cp/ChangeLog:

* cp-tree.h (struct lang_type): Add non_aggregate_pod.
(CLASSTYPE_NON_AGGREGATE_POD): New.
* class.cc (check_bases_and_members): Set it.
(check_non_pod_aggregate): Diagnose it.

gcc/ChangeLog:

* doc/invoke.texi: Document C++20 aggregate fix.
* common.opt: Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/abi/base-defaulted1.C: New test.
* g++.dg/abi/base-defaulted1a.C: New test.

3 months agoi386: -Wabi false positive with indirect call [PR60336]
Jason Merrill [Thu, 1 May 2025 15:40:17 +0000 (11:40 -0400)] 
i386: -Wabi false positive with indirect call [PR60336]

This warning relies on the TRANSLATION_UNIT_WARN_EMPTY_P flag (set in
cxx_init_decl_processing) to decide whether we want to warn about the GCC 8
empty class parameter passing fix, but in a call through a function pointer
we don't have a translation unit and so complain for any -Wabi flag, even
now long after this was likely to be relevant.

In that situation, let's check the TU for current_function_decl instead.
And if we still can't come up with a TU, default to not warning.

PR c++/60336

gcc/ChangeLog:

* config/i386/i386.cc (ix86_warn_parameter_passing_abi):
If no target, check the current TU.

gcc/testsuite/ChangeLog:

* g++.dg/abi/pr60336-8a.C: New test.

3 months agolibstdc++: Add missing feature-test macro in <memory>
Dhruv Chawla [Tue, 8 Apr 2025 08:01:24 +0000 (01:01 -0700)] 
libstdc++: Add missing feature-test macro in <memory>

Per version.syn#2, <memory> is required to define
__cpp_lib_addressof_constexpr as 201603L.

Bootstrapped and tested on aarch64-linux-gnu.

Signed-off-by: Dhruv Chawla <dhruvc@nvidia.com>
libstdc++-v3/ChangeLog:
* include/std/memory: Define __glibcxx_want_addressof_constexpr.
* testsuite/20_util/headers/memory/version.cc: Test for macro
value.

3 months agolibstdc++: Make __gnu_test::default_init_allocator usable in constexpr
Jonathan Wakely [Thu, 1 May 2025 21:41:40 +0000 (22:41 +0100)] 
libstdc++: Make __gnu_test::default_init_allocator usable in constexpr

If we make this test allocator usable in constant expressions then we'll
get an error if the 'state' data member isn't initialized. This makes it
a more reliable check that allocators are correctly value-initialized
when they're required to be.

libstdc++-v3/ChangeLog:

* testsuite/23_containers/vector/allocator/default_init.cc:
Add a check using constant evaluation.
* testsuite/23_containers/vector/bool/allocator/default_init.cc:
Likewise.
* testsuite/util/testsuite_allocator.h (default_init_allocator):
Make all member functions and equality ops constexpr.

3 months agolibstdc++: Add some more makefile dependencies
Jonathan Wakely [Thu, 10 Apr 2025 11:56:43 +0000 (12:56 +0100)] 
libstdc++: Add some more makefile dependencies

Add more prerequisites for wchar and dual-abi targets in the src/c++11
directory, and simplify the existing ones (we don't need to add the main
xxx.cc source file as a prerequisite of xxx.o because that's implicit,
we only need to add the ones that Make can't determine on its own).

Also add similar prerequisites for the dual-abi targets in the src/c++17
directory.

libstdc++-v3/ChangeLog:

* src/c++11/Makefile.am: Simplify existing prerequisites for wchar and
dual-abi targets that are built from other sources. Add similar
prerequisites for more wchar and dual-abi files.
* src/c++11/Makefile.in: Regenerate.
* src/c++17/Makefile.am [ENABLE_DUAL_ABI]: Add prerequisites for
dual-abi targets that are built from other sources.
* src/c++17/Makefile.in: Regenerate.

3 months agoRemove TARGET_LRA_P override when defining to hook_bool_void_true
Richard Biener [Fri, 2 May 2025 06:40:46 +0000 (08:40 +0200)] 
Remove TARGET_LRA_P override when defining to hook_bool_void_true

Two targets were converted but retain the default.

* config/arc/arc.cc (TARGET_LRA_P): Remove define.
* config/gcn/gcn.cc (TARGET_LRA_P): Likewise.

3 months agogimple: Switch bit-test lowering testcases for the more powerful alg
Filip Kastl [Thu, 1 May 2025 13:32:36 +0000 (15:32 +0200)] 
gimple: Switch bit-test lowering testcases for the more powerful alg

This patch adds 2 testcases.  One tests that GCC is able to create
bit-test clusters of size 64.  The other one contains two switches which
GCC wouldn't completely cover with bit-test clusters before the changes
from this patch set.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Filip Kastl <fkastl@suse.cz>
3 months agogimple: Don't warn about using different algs for big switch lowering [PR117091]
Filip Kastl [Thu, 1 May 2025 13:32:07 +0000 (15:32 +0200)] 
gimple: Don't warn about using different algs for big switch lowering [PR117091]

We currently don't switch to a faster switch lowering algorithm when a
switch is too big.  This patch removes a warning about this.

PR middle-end/117091

gcc/ChangeLog:

* tree-switch-conversion.cc (switch_decision_tree::analyze_switch_statement):
Remove warning about using different algorithms.

Signed-off-by: Filip Kastl <fkastl@suse.cz>
3 months agogimple: Make bit-test switch lowering more powerful
Filip Kastl [Thu, 1 May 2025 13:31:30 +0000 (15:31 +0200)] 
gimple: Make bit-test switch lowering more powerful

A reasonable goal for bit-test lowering is to produce the least amount
of clusters for a given switch (a cluster is basically a group of cases
that can be handled by constantly many operations).

The current algorithm doesn't always give optimal solutions in that
sense.  This patch should fix this.  The important thing is basically
just to ask if a cluster is_beneficial() more proactively.

The patch also has a fix for a mistake which made bit-test lowering only
create BITS_IN_WORD - 1 big clusters.  There are also some new comments
that go into more detail on the dynamic programming algorithm.

gcc/ChangeLog:

* tree-switch-conversion.cc (bit_test_cluster::find_bit_tests):
Modify the dynamic programming algorithm to take is_beneficial()
into account earlier.  To do this efficiently, copy some logic
from is_beneficial() here.  Add detailed comments about how the
DP algorithm works.
(bit_test_cluster::can_be_handled): Check that the cluster range
is >, not >= BITS_IN_WORD.  Remove the
"vec<cluster *> &, unsigned, unsigned" overloaded variant since
we no longer need it.
(bit_test_cluster::is_beneficial): Add a comment that this
function is closely tied to m_max_case_bit_tests.  Remove the
"vec<cluster *> &, unsigned, unsigned" overloaded variant since
we no longer need it.
* tree-switch-conversion.h: Remove the vec overloaded variants
of bit_test_cluster::is_beneficial and
bit_test_cluster::can_be_handled.

Signed-off-by: Filip Kastl <fkastl@suse.cz>
3 months agogimple: Merge slow and fast bit-test switch lowering [PR117091]
Filip Kastl [Thu, 1 May 2025 13:30:52 +0000 (15:30 +0200)] 
gimple: Merge slow and fast bit-test switch lowering [PR117091]

PR117091 showed that bit-test switch lowering can take a lot of time.
The algorithm was O(n^2).  We therefore came up with a faster algorithm
(O(n * BITS_IN_WORD)) and made GCC choose between the slow and the fast
algorithm based on how big the switch is.

Here I combine the algorithms so that we get the results of the slower
algorithm in the faster asymptotic time.

PR middle-end/117091

gcc/ChangeLog:

* tree-switch-conversion.cc (bit_test_cluster::find_bit_tests_fast):
Remove function.
(bit_test_cluster::find_bit_tests_slow): Remove function.
(bit_test_cluster::find_bit_tests): We don't need to decide
between slow and fast so just put the modified (no longer) slow
algorithm here.

Signed-off-by: Filip Kastl <fkastl@suse.cz>
3 months agoc: Fix crash in c-typeck.cc convert_arguments with indirect calls
Florian Weimer [Fri, 2 May 2025 09:39:29 +0000 (11:39 +0200)] 
c: Fix crash in c-typeck.cc convert_arguments with indirect calls

gcc/c/

PR c/120055
* c-typeck.cc (convert_arguments): Check if fundecl is null
before checking for builtin function declaration.

gcc/testsuite/

* gcc.dg/Wdeprecated-non-prototype-6.c: New test.

3 months agoaarch64: Optimize SVE extract last for VLS.
Jennifer Schmitz [Wed, 12 Mar 2025 07:37:42 +0000 (00:37 -0700)] 
aarch64: Optimize SVE extract last for VLS.

For the test case
int32_t foo (svint32_t x)
{
  svbool_t pg = svpfalse ();
  return svlastb_s32 (pg, x);
}
compiled with -O3 -mcpu=grace -msve-vector-bits=128, GCC produced:
foo:
pfalse p3.b
lastb w0, p3, z0.s
ret
when it could use a Neon lane extract instead:
foo:
umov w0, v0.s[3]
ret

Similar optimizations can be made for VLS with other vector widths.

We implemented this optimization by guarding the emission of
pfalse+lastb in the pattern vec_extract<mode><Vel> by
!val.is_constant ().
Thus, for last-extract operations with VLS, the patterns
*vec_extract<mode><Vel>_v128, *vec_extract<mode><Vel>_dup, or
*vec_extract<mode><Vel>_ext are used instead.
We added tests for 128-bit VLS and adjusted the tests for the other vector
widths.

The patch was bootstrapped and tested on aarch64-linux-gnu, no regression.
OK for mainline?

Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>
gcc/
* config/aarch64/aarch64-sve.md (vec_extract<mode><Vel>):
Prevent the emission of pfalse+lastb for VLS.

gcc/testsuite/
* gcc.target/aarch64/sve/extract_last_128.c: New test.
* gcc.target/aarch64/sve/extract_1.c: Adjust expected outcome.
* gcc.target/aarch64/sve/extract_2.c: Likewise.
* gcc.target/aarch64/sve/extract_3.c: Likewise.
* gcc.target/aarch64/sve/extract_4.c: Likewise.

3 months ago++: Small build_vec_init improvement [PR117827]
Jakub Jelinek [Fri, 2 May 2025 07:16:27 +0000 (09:16 +0200)] 
++: Small build_vec_init improvement [PR117827]

As discussed in the
https://gcc.gnu.org/pipermail/gcc-patches/2025-January/674492.html
thread, the following patch attempts to improve build_vec_init generated
code.  E.g. on g++.dg/eh/aggregate1.C test the patch has differences like:
                         D.2988 = &D.2950->e1;
                         D.2989 = D.2988;
                         D.2990 = 1;
                         try
                           {
                             goto <D.2996>;
                             <D.2997>:
                             A::A (D.2989);
                             D.2990 = D.2990 + -1;
                             D.2989 = D.2989 + 1;
                             <D.2996>:
                             if (D.2990 >= 0) goto <D.2997>; else goto <D.2995>;
                             <D.2995>:
                             retval.4 = D.2988;
                             _13 = &D.2950->e2;
                             A::A (_13);
-                            D.2990 = 1;
+                            D.2988 = 0B;
                             D.2951 = D.2951 + -1;
                           }
                         catch
                           {
                             {
                               struct A * D.2991;

                               if (D.2988 != 0B) goto <D.3028>; else goto <D.3029>;
                               <D.3028>:
                               _11 = 1 - D.2990;
                               _12 = (sizetype) _11;
                               D.2991 = D.2988 + _12;
                               <D.3030>:
                               if (D.2991 == D.2988) goto <D.3031>; else goto <D.3032>;
                               <D.3032>:
                               D.2991 = D.2991 + 18446744073709551615;
                               A::~A (D.2991);
                               goto <D.3030>;
                               <D.3031>:
                               goto <D.3033>;
                               <D.3029>:
                               <D.3033>:
                             }
                           }
in 3 spots.  As you can see, both setting D.2990 (i.e. iterator) to
maxindex and setting D.2988 (i.e. rval) to nullptr have the same effect of
not actually destructing anything anymore in the cleanup, the
advantage of clearing rval is that setting something to zero is often less
expensive than potentially huge maxindex and that the cleanup tests that
value first.

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

PR c++/117827
* init.cc (build_vec_init): Push to *cleanup_flags clearing of rval
instead of setting of iterator to maxindex.

3 months agovect: Use internal storage for converts for call into supportable_indirect_convert_op...
Andrew Pinski [Thu, 1 May 2025 16:05:47 +0000 (09:05 -0700)] 
vect: Use internal storage for converts for call into supportable_indirect_convert_operation [PR118617]

While looking into PR 118616, I noticed that
supportable_indirect_convert_operation only pushes up to 2 into its vec.
And the 2 places which call supportable_indirect_convert_operation,
use an auto_vec but without an internal storage. In this case an internal
storage of 2 elements would save both memory and slight compile time performance.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/118617
gcc/ChangeLog:

* tree-vect-generic.cc (expand_vector_conversion): Have 2 elements
as internal storage for converts.
* tree-vect-stmts.cc (vectorizable_conversion): Likewise.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agoget_known_nonzero_bits_1 should use wi::bit_and_not [PR118659]
Andrew Pinski [Thu, 1 May 2025 07:14:27 +0000 (00:14 -0700)] 
get_known_nonzero_bits_1 should use wi::bit_and_not [PR118659]

While looking into bitwise optimizations, I noticed that
get_known_nonzero_bits_1 does `bm.value () & ~bm.mask ()` which
is ok except it creates a temporary wide_int. Instead if we
use wi::bit_and_not, we can avoid the temporary and on some
targets use the andn/bic instruction.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

PR tree-optimization/118659
* tree-ssanames.cc (get_known_nonzero_bits_1): Use
wi::bit_and_not instead of `a & ~b`.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agoexpand: Remove unsignedp argument from get_compare_parts [PR118090]
Andrew Pinski [Thu, 1 May 2025 15:31:18 +0000 (08:31 -0700)] 
expand: Remove unsignedp argument from get_compare_parts [PR118090]

While helping Eikansh with a patch to ccmp, it was noticed that the
result stored in the up pointer that gets passed to get_compare_parts
was unused on all call sites.
It was always unused since get_compare_parts was added in
r8-1717-gf580a969d7fbab. It looks it was not noticed it became unused
when rcode was set via get_compare_parts and in RTL, the signedness is
part of the comparison.

PR middle-end/118090
gcc/ChangeLog:

* ccmp.cc (get_compare_parts): Remove the up argument.
(expand_ccmp_next): Update call to get_compare_parts.
(expand_ccmp_expr_1): Likewise.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agoRegenerate opt-urls
Richard Biener [Fri, 2 May 2025 06:02:41 +0000 (08:02 +0200)] 
Regenerate opt-urls

* common.opt.urls: Regenerate.

3 months agoDaily bump.
GCC Administrator [Fri, 2 May 2025 00:17:18 +0000 (00:17 +0000)] 
Daily bump.

3 months agoconfig-list.mk: Update FreeBSD targets to version 13
Gerald Pfeifer [Thu, 1 May 2025 22:06:59 +0000 (00:06 +0200)] 
config-list.mk: Update FreeBSD targets to version 13

contrib:
* config-list.mk: Update FreeBSD targets to version 13.

3 months agoFix BZ 119317: named loops (C2y) with debug info
Christopher Bazley [Thu, 1 May 2025 21:00:42 +0000 (22:00 +0100)] 
Fix BZ 119317: named loops (C2y) with debug info

Named loops (C2y) could not previously be compiled with
-O1 and -ggdb2 or higher because the label preceding
a loop (or switch) could not be found when using such
command lines.

This could be observed by compiling
gcc/gcc/testsuite/gcc.dg/c2y-named-loops-1.c with
the provoking command line (or any minimal example such
as that cited in the bug report).

The fix was simply to ignore the tree nodes inserted
for debugging information.

Base commit is 79aa2a283a8d3327ff4d6dca77e81d5b1ac3a01e

PR c/119317

gcc/c/ChangeLog:

* c-decl.cc (c_get_loop_names): Do not prematurely
end the search for a label that names a loop or
switch statement upon encountering a DEBUG_BEGIN_STMT.
Instead, ignore any instances of DEBUG_BEGIN_STMT.

gcc/testsuite/ChangeLog:

* gcc.dg/c2y-named-loops-8.c: New test.