Compare commits

...
1533 Commits
Author SHA1 Message Date
liuhongt dd645f6b9e Deprecate -mstore-max= and related tuning.
For memset, the size of used vector is decided by MIN(MOVE_MAX_PIECES,
STORE_MAX_PIECES).
Unless there's u-arch prefer big size vector for memcpy and small size
vector for memset, there's no need to have a separate option or tune
for it.
In general, x86 backend always prefer big size vector for memset due
to STLF issue.

gcc/ChangeLog:

	PR target/121970
	* config/i386/i386-options.cc (ix86_target_string): Remove
	store_max.
	(ix86_debug_options): Ditto.
	(ix86_function_specific_print): Ditto.
	(ix86_valid_target_attribute_tree): Ditto.
	(ix86_option_override_internal): Ditto.
	* config/i386/i386-expand.cc (ix86_expand_builtin): Ditto.
	* config/i386/i386-options.h (ix86_target_string): Ditto.
	* config/i386/i386.h (MOVE_MAX): Ditto.
	(STORE_MAX_PIECES): Set by move_max.
	* config/i386/i386.opt: Deprecate mmove-max=.
	* config/i386/x86-tune.def (X86_TUNE_AVX256_STORE_BY_PIECES):
	Removed.
	(X86_TUNE_AVX512_STORE_BY_PIECES): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pieces-memcmp-2.c: Remove mstore-max.
	* gcc.target/i386/pieces-memcpy-19.c: Ditto.
	* gcc.target/i386/pieces-memcpy-20.c: Ditto.
	* gcc.target/i386/pr104610.c: Ditto.
	* gcc.target/i386/pieces-memset-47.c: Scan warning for
	mstore-max deprecation.
	* gcc.target/i386/pieces-memset-48.c: Change mstore-max to mmove-max.
	* gcc.target/i386/pr121410.c: Ditto.
	* gcc.target/i386/pieces-memset-11.c: Change
	avx256_store_by_pieces to avx256_move_by_pieces.
	* gcc.target/i386/pieces-memset-14.c: Ditto.
	* gcc.target/i386/pieces-memset-2.c: Ditto.
	* gcc.target/i386/pieces-memset-20.c: Ditto.
	* gcc.target/i386/pieces-memset-23.c: Ditto.
	* gcc.target/i386/pieces-memset-29.c: Ditto.
	* gcc.target/i386/pieces-memset-30.c: Ditto.
	* gcc.target/i386/pieces-memset-33.c: Ditto.
	* gcc.target/i386/pieces-memset-34.c: Ditto.
	* gcc.target/i386/pieces-memset-37.c: Ditto.
	* gcc.target/i386/pieces-memset-44.c: Ditto.
	* gcc.target/i386/pieces-memset-5.c: Ditto.
	* gcc.target/i386/pr100865-10a.c: Ditto.
	* gcc.target/i386/pr100865-4a.c: Ditto.
	* gcc.target/i386/pr90773-20.c: Ditto.
	* gcc.target/i386/pr90773-21.c: Ditto.
	* gcc.target/i386/pr90773-22.c: Ditto.
	* gcc.target/i386/pr90773-23.c: Ditto.
	* g++.target/i386/pr80566-1.C: Ditto.
	* gcc.target/i386/pieces-memset-45.c: Change
	avx512_store_by_pieces to avx512_move_by_pieces.
2025-09-27 22:14:05 -07:00
Peter Damianov bd352bd592 diagnostics: Fix mojibake from displaying UTF-8 on Windows consoles
UTF-8 characters in diagnostic output (such as the warning emoji ⚠️
used by fanalyzer) display as mojibake on Windows unless the utf8
code page is being used

This patch adds UTF-8 to UTF-16 conversion when outputting to a console
on Windows.

gcc/ChangeLog:
	* pretty-print.cc (decode_utf8_char): Move forward declaration.
	(mingw_utf8_str_to_utf16_str): New function to convert UTF-8 to UTF-16.
	(is_console_handle): New function to detect Windows console handles.
	(write_all): Add UTF-8 to UTF-16 conversion for console output,
	falling back to WriteFile for ASCII strings and regular files.

Signed-off-by: Peter Damianov <peter0x44@disroot.org>
Signed-off-by: Jonathan Yong <10walls@gmail.com>
2025-09-28 01:32:43 +00:00
GCC Administrator 214372031a Daily bump. 2025-09-28 00:19:51 +00:00
Jonathan Wakely e1b9ccaa10 libstdc++: Fix -Wmaybe-uninitialized warnings in testsuite
These are false positives, but we might as well just value-init the
variables to avoid the warnings.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/allocator_traits/members/allocate_hint.cc:
	Value-initialize variables to avoid -Wmaybe-uninitialized
	warning.
	* testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
	Likewise.
	* testsuite/20_util/duration/114244.cc: Likewise.
	* testsuite/20_util/duration/io.cc: Likewise.
2025-09-27 21:18:43 +01:00
Jonathan Wakely c2ccc43dda libstdc++: Fix some -Wsign-compare warnings in headers
In all these cases we know the value with signed type is not negative so
the cast is safe.

libstdc++-v3/ChangeLog:

	* include/bits/deque.tcc (deque::_M_shrink_to_fit): Cast
	difference_type to size_type to avoid -Wsign-compare warning.
	* include/std/spanstream (basic_spanbuf::seekoff): Cast
	streamoff to size_t to avoid -Wsign-compare warning.
2025-09-27 21:18:42 +01:00
Jonathan Wakely f6c71c2079 libstdc++: Fix VERIFY(idx = 1) bugs in tests
These should be checking for equality, not performing assignments.

The tests for from_range on associative containers were actually
checking the wrong thing, but the bug in the is_equal function was
making the incorrect checks pass anyway, because all the values being
used were non-zero, so the result of lhs.id = rhs.id was true, but would
have been false if lhs.id == rhs.id had been used as intended.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc:
	Fix assignment used instead of equality comparison.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoull.cc:
	Likewise.
	* testsuite/23_containers/map/cons/from_range.cc: Fix is_equal
	function and expected value of comparison functions after
	construction.
	* testsuite/23_containers/multimap/cons/from_range.cc: Likewise.
	* testsuite/23_containers/multiset/cons/from_range.cc: Likewise.
	* testsuite/23_containers/set/cons/from_range.cc: Likewise.
	* testsuite/23_containers/unordered_map/cons/from_range.cc: Fix
	is_equal functions.
	* testsuite/23_containers/unordered_multimap/cons/from_range.cc:
	Likewise.
	* testsuite/23_containers/unordered_multiset/cons/from_range.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/cons/from_range.cc:
	Likewise.
	* testsuite/25_algorithms/minmax/constrained.cc: Fix assignment
	used instead of equality comparison.
	* testsuite/27_io/manipulators/extended/get_time/wchar_t/1.cc:
	Likewise.
2025-09-27 21:17:40 +01:00
YunQiang Su 10bb371eee MIPS/testsuite: Use isa_rev=2 instead of >=2
So that they won't fail for r6 targets.

gcc/testsuite/ChangeLog:
	* gcc.target/mips/mips16e2.c: Use isa_rev=2 instead of >=2.
	* gcc.target/mips/mips16e2-cache.c: Ditto.
	* gcc.target/mips/mips16e2-cmov.c: Ditto.
	* gcc.target/mips/mips16e2-gp.c: Ditto.
2025-09-27 22:28:19 +08:00
ChengLulu b07bab1953 MIPS: Fix the issue with the '-fpatchable-function-entry=' feature.
PR target/99217

gcc/ChangeLog:

	* config/mips/mips.cc (mips_start_function_definition):
	Implements the functionality of '-fpatchable-function-entry='.
	(mips_print_patchable_function_entry): Define empty function.
	(TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY): Define macro.

gcc/testsuite/ChangeLog:

	* gcc.target/mips/pr99217.c: New test.
2025-09-27 20:55:07 +08:00
Jason Merrill a0536f80ff c++: concepts and conversions [PR112632]
One case missed in my fix for this PR: Here we were omitting the
IMPLICIT_CONV_EXPR that expresses the conversion from int to char because
the target type was non-dependent and the argument was not type-dependent.
But we still need it if the argument is value-dependent.

	PR c++/112632

gcc/cp/ChangeLog:

	* pt.cc (convert_template_argument): Also force IMPLICIT_CONV_EXPR
	if the argument is value-dependent.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-conv4.C: New test.
2025-09-27 09:06:34 +01:00
Jason Merrill 6fda31f7b3 c++: add testcase [PR121854]
Add the testcase for this GCC 15 PR, already fixed on trunk by r16-970.

	PR c++/121854

gcc/testsuite/ChangeLog:

	* g++.dg/cpp23/explicit-obj-lambda19.C: New test.
2025-09-27 09:06:21 +01:00
Jason Merrill 90ad957406 c++: implicit 'this' in generic lambda [PR122048]
Here template substitution was replacing a reference to the 'this' of X::f
with the implicit closure parameter of the operator(), which is wrong.  The
closure parameter is never a suitable replacement for a 'this' parameter.

	PR c++/122048

gcc/cp/ChangeLog:

	* pt.cc (tsubst_expr): Don't use a lambda current_class_ptr.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1y/lambda-generic-this6.C: New test.
2025-09-27 09:04:58 +01:00
Jie Mei f731fa5801 MIPS: Add conditions for use of the -mmips16e2 and -mips16 option.
Changes from V1:
* Raise the minimal revision to r2.

MIPS16e2 ASE is a superset of MIPS16e ASE, which is again a superset
of MIPS16 ASE. Later, all of them are forbidden in Release 6.

Make -mmips16e2 imply -mips16 as the ASE requires, so users won't
be surprised even if they expect it to. Meanwhile, check if
mips_isa_rev <= 5 when -mips16 is effective and >= 2 when -mmips16e2
is effective.

Co-developed-by: Rong Zhang <rongrong@oss.cipunited.com>
Signed-off-by: Rong Zhang <rongrong@oss.cipunited.com>

gcc/ChangeLog:
	* config/mips/mips.cc(mips_option_override):Add conditions
	for use of the -mmips16e2 and -mips16 option.

gcc/testsuite/ChangeLog:
	* gcc.target/mips/mips16e2-cache.c: Use isa_rev>=2 instead of
	-mips32r2 and remove -mips16 option.
	* gcc.target/mips/mips16e2-cmov.c: Add isa_rev>=2 and remove
	-mips16 option.
	* gcc.target/mips/mips16e2-gp.c: Same as above.
	* gcc.target/mips/mips16e2.c: Same as above.
2025-09-27 15:27:49 +08:00
Paul Thomas 25f7f04e44 Fortran: Revert r16-4069 causing memory leaks in f951 [PR87908]
2025-09-27  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/87908
	* interface.cc (check_interface0): Revert changes.

gcc/testsuite/
	PR fortran/87908
	* gfortran.dg/pr87908.f90: Delete.
2025-09-27 08:01:30 +01:00
Jie Mei 51a3669ab6 MIPS: Add MSUBF.fmt instruction for MIPSr6
GCC currently uses two instructions (NEG.fmt and MADDF.fmt) for
operations like `x - (y * z)' for MIPSr6. We can further tune this by
using only MSUBF.fmt instead of those two.

This patch adds MSUBF.fmt instrutions with corresponding tests.

gcc/ChangeLog:

	* config/mips/mips.md (fms<mode>4): Generates MSUBF.fmt
	instructions.
	(*fms<mode>4_msubf): Same as above.
	(fnma<mode>4): Same as above.
	(*fnma<mode>4_msubf): Same as above.

gcc/testsuite/ChangeLog:

	* gcc.target/mips/mips-msubf.c: New tests for MIPSr6.
2025-09-27 13:48:40 +08:00
GCC Administrator 4ab8a985b8 Daily bump. 2025-09-27 00:18:25 +00:00
Alejandro Colomar 33c35b7f4c c, objc: Add -Wmultiple-parameter-fwd-decl-lists
Warn about this:

	void f(int x; int x; int x);

Add a new diagnostic, -Wmultiple-parameter-fwd-decl-lists, which
diagnoses uses of this obsolescent syntax.

Add this diagnostic in -Wextra.

Forward declarations of parameters are very rarely used.  And functions
that need two forward declaractions of parameters are also quite rare.
This combination results in this code almost not existing in any code
base, which makes adding this to -Wextra okay.  FWIW, I've tried finding
such code using a code search engine, and didn't find any cases (but the
regex for that isn't easy to writei, so I wouldn't trust it).

gcc/c-family/ChangeLog:

	* c.opt: Add -Wmultiple-parameter-fwd-decl-lists

gcc/c/ChangeLog:

	* c-decl.cc (c_scope): Rename {warned > had}_forward_parm_decls.
	(mark_forward_parm_decls): Add
	-Wmultiple-parameter-fwd-decl-lists.

gcc/ChangeLog:

	* doc/extend.texi: Clarify documentation about lists of
	parameter forward declarations, and mention that more than one
	of them are unnecessary.
	* doc/invoke.texi: Document the new
	-Wmultiple-parameter-fwd-decl-lists.

gcc/testsuite/ChangeLog:

	* gcc.dg/Wmultiple-parameter-fwd-decl-lists.c: New test.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-09-26 19:28:24 +00:00
Harald Anlauf e6b4908c04 Fortran: fix uninitialized read in testcase gfortran.dg/pdt_48.f03
Running the testcase using valgrind --leak-check=full --track-origins=yes:

==28585== Conditional jump or move depends on uninitialised value(s)
==28585==    at 0x400E19: MAIN__ (pdt_48.f03:48)
==28585==    by 0x400EDB: main (pdt_48.f03:34)
==28585==  Uninitialised value was created by a heap allocation
==28585==    at 0x4841984: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28585==    by 0x400975: __pdt_m_MOD_add (pdt_48.f03:30)
==28585==    by 0x400D84: MAIN__ (pdt_48.f03:44)
==28585==    by 0x400EDB: main (pdt_48.f03:34)

The cause was a partial initialization of a vector used in a subsequent
addition.  Initialize the remaining elements of the first vector by zero.

gcc/testsuite/ChangeLog:

	* gfortran.dg/pdt_48.f03:
2025-09-26 19:20:39 +02:00
Jan Hubicka 40d9e9601a Fix precise 0 handling in afdo_propagate_edge
Currently afdo_propagate_edge will turn precise 0 to autofdo 0 because it thinks
auto-profile claims some samples has been executed in the given basic block, while
this is only a consequence of < being defined by
 0 (predise) < 0 (autofdo)

gcc/ChangeLog:

	* auto-profile.cc (afdo_propagate_edge): Fix handling of precize 0
	counts.
2025-09-26 15:57:31 +02:00
Andrew Stubbs fdc8037a59 amdgcn: Remove vector alignment restrictions
The supported misalignment logic seems to be a bit arbitrary.  Some of it looks
like it was copied from the Arm implementation, although testing shows that the
packed accesses do not work (weird subregs happen).

AMD GCN does have some alignment restrictions on Buffer instructions, but as we
don't use those that's irrelvant.  The Flat and Global instructions (that we do
use) have no such restrictions.

LDS memory -- which can be accessed via Flat instructions -- does have
alignment restrictions, but the compiler is not using LDS for arbitrary
vectors.  If the user deliberately choses to place unaligned data in
low-latency memory then a runtime exception should occur (no silent bad
behaviour), so there's no reason to pessimise the normal case.

gcc/ChangeLog:

	* config/gcn/gcn.cc
	(gcn_vectorize_support_vector_misalignment): Allow any alignment, as
	long as it's not packed.
2025-09-26 11:23:06 +00:00
Joseph Myers 1b876bdffd c: Give permerror for excess braces in scalar initializers [PR88642]
As noted in bug 88642, the C front end fails to give errors or
pedwarns for scalar initializers with too many levels of surrounding
braces.  There is a warning for redundant braces around a scalar
initializer within a larger braced initializer (valid for a single
such level within a structure, union or array initializer; not valid
for more than one such level, or where the outer layer of braces is
itself for a scalar, either redundant braces themselves or part of a
compound literal), but this never becomes an error even for invalid
cases.  Check for this case and turn the warning into a permerror when
there are more levels of braces than permitted.  The existing warning
is unchanged for a single (permitted) level of redundant braces around
a scalar initializer inside a structure, union or array initializer,
and it's also unchanged that no such warning is given for a single
(permitted) level of redundant braces around a top-level scalar
initializer.

Technically this is a C2y issue (these rules on valid initializers
moved into Constraints as a result of N3346, accepted in Minneapolis;
previously, as a "shall" outside constraints, violating these rules
resulted in compile-time undefined behavior without requiring a
diagnostic).

Hopefully little code is actually relying on not getting an error
here.  In view of gcc.dg/tree-ssa/ssa-dse-10.c showing that at least
some code may be using such over-braced initializers (initializer of
pubKeys at line 1167 in that test; I'm not at all sure how that
initializer ends up getting interpreted to translate it to something
equivalent but properly structured), this is made a permerror rather
than a hard error, so -fpermissive (as already used by that test) can
be used to disable the error (the default -fpermissive for old
standards modes is not a problem given that before C2y this is
undefined behavior not a constraint violation).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

	PR c/88642

gcc/c/
	* c-typeck.cc (constructor_braced_scalar): New variable.
	(struct constructor_stack): Add braced_scalar field.
	(really_start_incremental_init): Handle constructor_braced_scalar
	and braced_scalar field.
	(push_init_level): Handle constructor_braced_scalar and
	braced_scalar field.  Give permerror rather than warning for
	nested braces around scalar initializer.
	(pop_init_level): Handle constructor_braced_scalar and
	braced_scalar field.

gcc/testsuite/
	* gcc.dg/c2y-init-1.c: New test.
2025-09-26 11:12:12 +00:00
Jan Hubicka 9f9c8d63a5 Fix integer overflow in profile_count::probability_in
This patch fixes integer overflow in profile_count::probability_in which happens
for very large counts.  This was probably not that common in practice until
scaled AutoFDO profiles were intorduces.

This was introduced as cut&paste from profile_probability implementation.
I reviewed multiplicaitons in the file for safety and noticed that in some
cases the code is over-protective. In profile_probability::operator/ we alrady
scale that m_val <= other.m_val and thus we know result will be in the range
0...max_probability.  In profile_probability::apply_scale we deal with 30bit
value from profile_probability so no overflow can happen.

gcc/ChangeLog:

	* profile-count.h (profile_probability::operator/): Do not cap
	twice.
	(profile_probability::operator/=): Likewise.
	(profile_probability::apply_scale): Do not watch for overflow.
	(profile_count::probability_in): Watch overflow.
2025-09-26 12:39:44 +02:00
Jonathan Wakely 1cf6cda055 libstdc++: Reuse predicates in std::search and std::is_permutation
Hoist construction of the call wrappers out of the loop when we're
repeatedly creating a call wrapper with the same bound arguments.

We need to be careful about iterators that return proxy references,
because bind1st(pred, *first) could bind a reference to a prvalue proxy
reference returned by *first. That would then be an invalid reference by
the time we invoked the call wrapper.

If we dereference the iterator first and store the result of that on the
stack, then we don't have a prvalue proxy reference, and can bind it (or
the value it refers to) into the call wrapper:

  auto&& val = *first; // lifetime extension
  auto wrapper = bind1st(pred, val);
  for (;;)
    /* use wrapper */;

This ensures that the reference returned from *first outlives the call
wrapper, whether it's a proxy reference or not.

For C++98 compatibility in __search we can use __decltype(expr) instead
of auto&&.

libstdc++-v3/ChangeLog:

	* include/bits/stl_algobase.h (__search, __is_permutation):
	Reuse predicate instead of creating a new one each time.
	* include/bits/stl_algo.h (__is_permutation): Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-26 11:05:59 +01:00
Jonathan Wakely b83c2e52a2 libstdc++: Simplify std::erase functions for sequence containers
This removes the use of std::ref that meant that __remove_if used an
indirection through the reference, which might be a pessimization. Users
can always use std::ref to pass expensive predicates into erase_if, but
we shouldn't do it unconditionally. We can std::move the predicate so
that if it's not cheap to copy and the user didn't use std::ref, then we
try to use a cheaper move instead of a copy.

There's no reason that std::erase shouldn't just be implemented by
forwarding to std::erase_if. I probably should have done that in
r12-4083-gacf3a21cbc26b3 when std::erase started to call __remove_if
directly.

libstdc++-v3/ChangeLog:

	* include/std/deque (erase_if): Move predicate instead of
	wrapping with std::ref.
	(erase): Forward to erase_if.
	* include/std/inplace_vector (erase_if, erase): Likewise.
	* include/std/string (erase_if, erase): Likewise.
	* include/std/vector (erase_if, erase): Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-26 11:05:54 +01:00
Jonathan Wakely aaeca77a79 libstdc++: Eliminate __gnu_cxx::__ops function objects
This removes the indirect functors from <bits/predefined_ops.h> that are
used by our STL algorithms. Currently we wrap all predicates and values
into callables which accept iterator arguments, and automatically
dereference the iterators. With this change we no longer do that
dereferencing and so all predicates are passed values not iterators, and
the algorithms that invoke those predicates must dereference the
iterators.

This avoids wrapping user-provided predicates into another predicate
that does the dereferencing. User-provided predicates are now passed
unchanged to our internal algos like __search_n. For the overloads that
take a value instead of a predicate, we still need to create a predicate
that does comparison to the value, but we can now use std::less<void>
and std::equal_to<void> as the base predicate and bind the value to
those base predicates.

Because the "transparent operators" std::less<void> and
std::equal_to<void> were not added until C++14, this change defines
those explicit specializations unconditionally for C++98 and C++11 too
(but the default template arguments that make std::less<> and
std::equal_to<> refer to those specializations are still only present
for C++14 and later, because we don't need to rely on those default
template arguments for our internal uses).

When binding a predicate and a value into a new call wrapper, we now
decide whether to store the predicate by value when it's an empty type
or a scalar (such as a function pointer). This avoids a
double-indirection through function pointers, and avoids storing and
invoking stateless empty functors through a reference. For C++11 and
later we also use [[no_unique_address]] to avoid wasted storage for
empty predicates (which includes all standard relational ops, such as
std::less).

The call wrappers in bits/predefined_ops.h all have non-const operator()
because we can't be sure that the predicates they wrap are
const-invocable. The requirements in [algorithms.requirements] for
Predicate and BinaryPredicate template arguments require pred(*i) to be
valid, but do not require that std::to_const(pred)(*i) has to be valid,
and similarly for binary_pred.

libstdc++-v3/ChangeLog:

	* include/bits/predefined_ops.h (equal_to, less): Define aliases
	for std::equal_to<void> and std::less<void>.
	(bind1st, bind2nd, not1, __equal_to): New object generator
	functions for adapting predicates.
	(__iter_less_iter, __iter_less_val, __iter_comp_val)
	(__val_less_iter, __val_comp_iter, __iter_equal_to_iter)
	(__iter_equal_to_val, __iter_comp_iter, __negate): Remove all
	object generator functions and the class templates they return.
	* include/bits/stl_algo.h (__move_median_to_first, __find_if_not)
	(__find_if_not_n, __search_n_aux, find_end, find_if_not)
	(__remove_copy_if, remove_copy, remove_copy_if, remove)
	(remove_if, __adjacent_find, __unique, unique, __unique_copy)
	(__unique_copy_1, __stable_partition_adaptive, stable_partition)
	(__heap_select, __partial_sort_copy, partial_sort_copy)
	(__unguarded_linear_insert, __insertion_sort)
	(__unguarded_insertion_sort, __unguarded_partition)
	(lower_bound, __upper_bound, upper_bound, __equal_range)
	(equal_range, binary_search, __move_merge_adaptive)
	(__move_merge_adaptive_backward, __merge_adaptive_resize)
	(__merge_without_buffer, inplace_merge, __move_merge)
	(__includes, includes, __next_permutation, next_permutation)
	(__prev_permutation, prev_permutation, __replace_copy_if)
	(replace_copy, replace_copy_if, __is_sorted_until)
	(is_sorted_until, __minmax_element, minmax_element, minmax)
	(is_permutation, __is_permutation, find, find_if, adjacent_find)
	(count, count_if, search, search_n, unique_copy, partial_sort)
	(nth_element, sort, __merge, merge, stable_sort, __set_union)
	(set_union, __set_intersection, set_intersection)
	(__set_difference, set_difference, __set_symmetric_difference)
	(set_symmetric_difference, __min_element, min_element)
	(__max_element, max_element, min, max): Use direct predicates
	instead of __iter_equal_to_iter, __iter_comp_iter, and
	__iter_less_iter, __negate etc. Dereference iterators when
	invoking predicates.
	* include/bits/stl_algobase.h (__lexicographical_compare_impl)
	(__lexicographical_compare::__lc, __lower_bound, lower_bound)
	(lexicographical_compare, __mismatch, mismatch, __find_if)
	(__count_if, __remove_if, __search, __is_permutation)
	(is_permutation, search): Likewise.
	* include/bits/stl_function.h (equal_to<void>, less<void>):
	Define transparent comparison functions for C++98 and C++11.
	* include/bits/stl_heap.h (__is_heap_until, __is_heap)
	(__push_heap, push_heap, __adjust_heap, pop_heap, make_heap)
	(sort_heap, is_heap_until, is_heap): Likewise.
	* include/std/deque (erase_if): Remove call to __pred_iter.
	(erase): Replace __iter_equals_val with __equal_to.
	* include/std/inplace_vector (erase_if, erase): Likewise.
	* include/std/string (erase_if, erase): Likewise.
	* include/std/vector (erase_if, erase): Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: François Dumont <frs.dumont@gmail.com>
2025-09-26 11:05:49 +01:00
Jonathan Wakely 11ce485bcf libstdc++: Fix unsafe comma operators in <random> [PR122062]
This fixes a 'for' loop in std::piecewise_linear_distribution that
increments two iterators with a comma operator between them, making it
vulnerable to evil overloads of the comma operator.

It also changes a 'for' loop used by some other distributions, even
though those are only used with std::vector<double>::iterator and so
won't find any overloaded commas.

libstdc++-v3/ChangeLog:

	PR libstdc++/122062
	* include/bits/random.tcc (__detail::__normalize): Use void cast
	for operands of comma operator.
	(piecewise_linear_distribution): Likewise.
	* testsuite/26_numerics/random/piecewise_linear_distribution/cons/122062.cc:
	New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Hewill Kang <hewillk@gmail.com>
2025-09-26 11:01:08 +01:00
Paul Thomas 947b22d9d0 Fortran: Fix uninitialized reads for pdt_13.f03 etc. [PR122002]
2025-09-26  Harald Anlauf  <anlauf@gcc.gnu.org>

gcc/fortran
	PR fortran/122002
	* decl.cc (gfc_get_pdt_instance): Initialize 'instance' to NULL
	and set 'kind_value' to zero before calling gfc_extract_int.
	* primary.cc (gfc_match_rvalue): Intitialize 'ctr_arglist' to
	NULL and test for default values if gfc_get_pdt_instance
	returns NULL.
2025-09-26 07:30:07 +01:00
Lulu Cheng d6ee89a65b LoongArch: Implement TARGET_CAN_INLINE_P[PR121875].
Because LoongArch does not implement TARGET_CAN_INLINE_P,
functions with the target attribute set and those without
it cannot be inlined.  At the same time, setting the
always_inline attribute will cause compilation failure.

To solve this problem, I implemented this hook. During the
implementation process, it checks the status of the target
special options of the caller and callee, such as the ISA
extension.

	PR target/121875

gcc/ChangeLog:

	* config/loongarch/loongarch.cc
	(loongarch_can_inline_p): New function.
	(TARGET_CAN_INLINE_P): Define.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/can_inline_1.c: New test.
	* gcc.target/loongarch/can_inline_2.c: New test.
	* gcc.target/loongarch/can_inline_3.c: New test.
	* gcc.target/loongarch/can_inline_4.c: New test.
	* gcc.target/loongarch/can_inline_5.c: New test.
	* gcc.target/loongarch/can_inline_6.c: New test.
	* gcc.target/loongarch/pr121875.c: New test.
2025-09-26 09:13:18 +08:00
GCC Administrator 11a662dd8b Daily bump. 2025-09-26 00:20:03 +00:00
Gerald Pfeifer 505c139c58 doc: Standardize on "bitwise" and "elementwise"
...over "bit-wise" and "element-wise".

gcc:
	* doc/invoke.texi (Warning Options): Use "bitwise" over
	"bit-wise".
	* doc/extend.texi (Vector Extensions): Use "elementwise"
	over "element-wise".
	* doc/md.texi (Standard Names): Ditto.
2025-09-26 00:09:32 +02:00
Gerald Pfeifer 29c28bb912 doc: Fix grammar around Vector Extensions
gcc:
	* doc/extend.texi (Vector Extensions): Fix grammar.
2025-09-25 23:59:06 +02:00
Harald Anlauf 43508d358b Fortran: ICE in character(kind=4) deferred-length array reference [PR121939]
PR fortran/121939

gcc/fortran/ChangeLog:

	* trans-types.cc (gfc_init_types): Set string flag for all
	character types.

gcc/testsuite/ChangeLog:

	* gfortran.dg/deferred_character_39.f90: Disable temporary
	workaround for character(kind=4) deferred-length bug.
2025-09-25 18:51:48 +02:00
John David Anglin 80d729c4b1 hppa: Fix asm in atomic_store_8 in sync-libfuncs.c
Fix typo in the asm in atomic_store_8.  Also correct floating
point store.

Reported by Nick Hudson for netbsd.

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

libgcc/ChangeLog:

	* config/pa/sync-libfuncs.c (atomic_store_8): Fix asm.
2025-09-25 10:49:39 -04:00
Luc Grosheintz 5756d0b613 libstdc++: Refactor __mdspan::__static_quotient.
For padded layouts we want to check that the product of the
padded stride with the remaining extents is representable.

Creating a second overload, allows passing in subspans of the
static extents and retains the ergonomics for the common case
of passing in all static extents.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__static_quotient): New overload.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-09-25 15:55:43 +02:00
Jonathan Wakely 08530be259 libstdc++: Check feature test macro for robust_nonmodifying_seq_ops
We should check the relevant feature test macro instead of just the
value of __cplusplus.

Also add a comment explaining why the __cplusplus check guarding
__sample *can't* be changed to check __glibcxx_sample (because __sample
is also used in C++14 by std::experimental::sample, not only by C++17
std::sample).

libstdc++-v3/ChangeLog:

	* include/bits/stl_algo.h: Check robust_nonmodifying_seq_ops
	feature test macro instead of checking __cplusplus value. Add
	comment to another __cplusplus check.
	* include/bits/stl_algobase.h: Add comment to #endif.
2025-09-25 14:52:25 +01:00
Jonathan Wakely 0959f0e0ce libstdc++: Remove unwanted STDC_HEADERS macro from c++config.h [PR79147]
Similar to r16-4034-g1953939243e1ab, this comments out another macro
that Autoconf adds to the generated config.h but which is not wanted in
the c++config.h file that we install.

There's no benefit to defining _GLIBCXX_STDC_HEADERS in user code, so we
should just prevent it from being defined.

libstdc++-v3/ChangeLog:

	PR libstdc++/79147
	PR libstdc++/103650
	* include/Makefile.am (c++config.h): Adjust sed command to
	comment out STDC_HEADERS macro.
	* include/Makefile.in: Regenerate.
2025-09-25 14:51:50 +01:00
Luc Grosheintz 181e7bea46 libstdc++: Prepare mapping layout tests for padded layouts.
Using the existing tests for padded layouts requires the following
changes:

 * The padded layouts are template classes. In order to be able to use
   partially specialized templates, functions need to be converted to
   structs.

 * The layout mapping tests include a check that only applies if
   is_exhaustive is static. This commit introduces a concept to check if
   is_exhaustive is a static member function.

 * Fix a test to not use a hard-coded layout_left.

The test empty.cc contains indentation mistakes that are fixed.

libstdc++-v3/ChangeLog:

	* testsuite/23_containers/mdspan/layouts/empty.cc: Fix indent.
	* testsuite/23_containers/mdspan/layouts/mapping.cc
	(test_stride_1d): Fix test.
	(test_stride_2d): Rewrite using a struct.
	(test_stride_3d): Ditto.
	(has_static_is_exhaustive): New concept.
	(test_mapping_properties): Update test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-09-25 15:40:19 +02:00
Nathaniel Shead 4f9f1269f4 c++/modules: Remove incorrect assertion [PR122015,PR122019]
This assertion, despite what I said in r16-4070, is not valid: we can
reach here when deduping a VAR_DECL that didn't get a LANG_SPECIFIC in
the current TU.  It's still correct to always use lang_cplusplus however
as for anything else the decl would have been created with an
appropriate LANG_SPECIFIC to start with.

	PR c++/122015
	PR c++/122019

gcc/cp/ChangeLog:

	* module.cc (trees_in::install_entity): Remove incorrect
	assertion.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-09-25 21:16:10 +10:00
Xi Ruoyao 19167808a6 doc: Reword the description of -f[no-]fp-int-builtin-inexact default
Now -std=gnu23 is the default, so -fno-fp-int-builtin-inexact is
effectively the default value.

gcc/

	* doc/invoke.texi (-ffp-int-builtin-inexact): Reword to match
	the default value with the default C standard.
2025-09-25 10:06:59 +08:00
GCC Administrator e4b9750478 Daily bump. 2025-09-25 00:21:38 +00:00
Dusan Stojkovic d53f7ad85e [PATCH][PR target/121778] RISC-V: Improve rotation detection for RISC-V
This patch splits the canonical sign-bit checking idiom
into a 2-insn sequence when Zbb is available. Combine often normalizes
(xor (lshr A, (W - 1)) 1) to (ge A, 0). For width W = bitsize (mode), the
identity:

(a << 1) | (a >= 0)  ==  (a << 1) | ((a >> (W - 1)) ^ 1)  ==  ROL1 (a) ^ 1

lets us split:

(ior:X (ashift:X A 1) (ge:X A 0))

into:
  →  rotatert:X A, (W-1)
  →  xor:X        A, 1

	PR target/121778

gcc/ChangeLog:

	* config/riscv/riscv.md: Add define_split pattern.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/pr121778-1.c: New test.
	* gcc.target/riscv/pr121778-2.c: New test.
2025-09-24 15:13:01 -06:00
Joseph Myers dfbce1feae c: Fix handling of register atomic compound literals
The logic for loads and stores of _Atomic objects in the C front end
involves taking the address of such objects, with really_atomic_lvalue
detecting cases where this cannot be done (and also no special
handling is needed for atomicity), in particular register _Atomic
objects.  This logic failed to deal with the case of register _Atomic
compound literals, so resulting in spurious errors "error: address of
register compound literal requested" followed by "error: argument 1 of
'__atomic_load' must be a non-void pointer type".  (This is a C23 bug
that I found while changing really_atomic_lvalue as part of previous
C2y changes.)  Add a use of COMPOUND_LITERAL_EXPR_DECL in that case.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c/
	* c-typeck.cc (really_atomic_lvalue): For a COMPOUND_LITERAL_EXPR,
	check C_DECL_REGISTER on the COMPOUND_LITERAL_EXPR_DECL.

gcc/testsuite/
	* gcc.dg/c23-complit-9.c: New test.
2025-09-24 19:53:01 +00:00
Mikael Morin 3386216618 fortran: Favor parser-generated module procedure namespaces [PR122046]
In the testcase from the PR, an assertion triggers because the compiler
tries to access the parent namespace of a contained procedure.  But the
namespace is the formal namespace of a module procedure symbol in a
submodule, which hasn't its parent set.

To add a bit of context, in submodules, module procedures inherited from
their parent module have two different namespaces holding their dummy
arguments.  The first one is generated by the the host association of
the module from the .mod file, and is made accessible in the procedure
symbol's formal_ns field.  Its parent field is not set.  The second one
is generated by the parser and contains the procedure implementation.
It's accessible from the list of contained procedures in the submodule
namespace.  Its parent field is set.

This change modifies gfc_get_procedure_ns to favor the parser-generated
namespace in the submodule case where there are two namespaces to choose
from.

	PR fortran/122046

gcc/fortran/ChangeLog:

	* symbol.cc (gfc_get_procedure_ns): Try to find the namespace
	among the list of contained namespaces before returning the
	value from the formal_ns field.

gcc/testsuite/ChangeLog:

	* gfortran.dg/submodule_34.f90: New test.
2025-09-24 21:02:48 +02:00
Andrew Pinski 966cdec2b2 gimple-fold/fab: Move ASSUME_ALIGNED handling to gimple-fold [PR121762]
This is the next patch in the series of removing fab.
This one is simplier than builtin_constant_p because the only
time we want to simplify this builtin is at the final folding step.

Note align-5.c needs to change slightly as __builtin_assume_aligned
is no longer taken into account for the same reason as why PR 111875
is closed as invalid and why the testcase is failing at -Og
I added a new testcase align-5a.c where the pointer is explictly aligned
so that the check is gone there.
Note __builtin_assume_aligned should really be instrumented for UBSAN,
I filed PR 122038 for that.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/121762
gcc/ChangeLog:

	* gimple-fold.cc (gimple_fold_builtin_assume_aligned): New function.
	(gimple_fold_builtin): Call gimple_fold_builtin_assume_aligned
	for BUILT_IN_ASSUME_ALIGNED.
	* tree-ssa-ccp.cc (pass_fold_builtins::execute): Remove handling
	of BUILT_IN_ASSUME_ALIGNED.

gcc/testsuite/ChangeLog:

	* c-c++-common/ubsan/align-5.c: Update as __builtin_assume_aligned
	is no longer taked into account.
	* c-c++-common/ubsan/align-5a.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-24 10:45:31 -07:00
Jennifer Schmitz 0088e4a419 AArch64: Enable dispatch scheduling for Neoverse V2.
This patch adds dispatch constraints for Neoverse V2 and illustrates the steps
necessary to enable dispatch scheduling for an AArch64 core.

The dispatch constraints are based on section 4.1 of the Neoverse V2 SWOG.
Please note that the values used here deviate slightly from the current SWOG
version but are based on correct numbers. Arm will do an official Neoverse V2
SWOG release with the updated values in due time.

Here are the steps how we implemented the dispatch constraints for
Neoverse V2:
1. We used instruction attributes to group instructions into dispatch groups,
   corresponding to operations that utilize a certain pipeline type. For that,
   we added a new attribute (neoversev2_dispatch) with values for the
   different dispatch groups. The values of neoversev2_dispatch are determined
   using expressions of other instruction attributes.
   For example, the SWOG describes a constraint of "Up to 4 uOPs utilizing the
   M pipelines". Thus, one of the values of neoversev2_dispatch is "m" and it
   groups instructions that use the M pipelines such as integer multiplication.
   Note that we made some minor simplifications compared to the information
   in the SWOG, because the instruction annotation does not allow for a fully
   accurate mapping of instructions to utilized pipelines. To give one example,
   the instructions IRG and LDG are both tagged with "memtag", but IRG uses
   the M pipelines, while LDG uses the L pipelines.
2. In the Neoverse V2 tuning model, we added an array of available slots per
   dispatch constraint and a callback function that takes an insn as
   input and returns a vector of pairs (a, b) where a is an index in the
   array of slots and b is the number of occupied slots. The callback
   function calls get_attr_neoversev2_dispatch(insn) and switches over the
   result values to create a vector of occupied slots.
   Thus, the new attribute neoversev2_dispatch provides a compact way to define
   the dispatch constraints.
   The array of available slots, its length, and a pointer to the
   callback function are collected in a struct dispatch_constraint_into
   which is referenced in the tune_params.
3. We enabled dispatch scheduling for Neoverse V2 by adding the
   AARCH64_EXTRA_TUNE_DISPATCH_SCHED tune flag.

Performance evaluation showed no regression in several different
workloads including SPEC2017 and GROMACS2024.
Thank you, Tamar, for helping with performance evaluation.

The patch was bootstrapped and tested on aarch64-linux-gnu, no regression.

Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>

gcc/ChangeLog:

	* config/aarch64/aarch64.md: Include neoversev2.md.
	* config/aarch64/tuning_models/neoversev2.h: Enable dispatch
	scheduling and add dispatch constraints.
	* config/aarch64/neoversev2.md: New file and new instruction attribute
	neoversev2_dispatch.
2025-09-24 16:18:35 +02:00
Jennifer Schmitz c8bd7b2d55 AArch64: Implement target hooks for dispatch scheduling.
This patch adds dispatch scheduling for AArch64 by implementing the two target
hooks TARGET_SCHED_DISPATCH and TARGET_SCHED_DISPATCH_DO.

The motivation for this is that cores with out-of-order processing do
most of the reordering to avoid pipeline hazards on the hardware side
using large reorder buffers. For such cores, rather than scheduling
around instruction latencies and throughputs, the compiler should aim to
maximize the utilized dispatch bandwidth by inserting a certain
instruction mix into the frontend dispatch window.

In the following, we will describe the overall implementation:
Recall that the Haifa scheduler makes the following 6 types of queries to
a dispatch scheduling model:
1) targetm.sched.dispatch (NULL, IS_DISPATCH_ON)
2) targetm.sched.dispatch_do (NULL, DISPATCH_INIT)
3) targetm.sched.dispatch (insn, FITS_DISPATCH_WINDOW)
4) targetm.sched.dispatch_do (insn, ADD_TO_DISPATCH_WINDOW)
5) targetm.sched.dispatch (NULL, DISPATCH_VIOLATION)
6) targetm.sched.dispatch (insn, IS_CMP)

For 1), we created the new tune flag AARCH64_EXTRA_TUNE_DISPATCH_SCHED.

For 2-5), we modeled dispatch scheduling using the class dispatch_window.
A dispatch_window object represents the window of operations that is dispatched
per cycle. It contains the two arrays max_slots and free_slots (the length
of the arrays is the number of dispatch constraints specified for a core)
to keep track of the available slots.
The dispatch_window class exposes functions to ask whether a given
instruction would fit into the dispatch_window or to add an instruction to
the window.
The model operates using only one dispatch_window object that is constructed
when 2) is called. Upon construction, it copies the number of available slots
given in the tuning model (more details on the changes to tune_params below).
During scheduling, instructions are added according to the dispatch
constraints. For that, the dispatch_window queries the tuning model using a
callback function that takes an insn as input and returns a vector of
pairs (a, b), where a is the index of the constraint and b is the number of
slots occupied.
The dispatch_window checks if the instruction fits into the current
window. If not, i.e. the current window is full, the free_slots array is
reset to max_slots. Then the dispatch_window deducts b slots from
free_slots[a] for each pair (a, b) in the vector returned by the callback.
A dispatch violation occurs when the number of free slots becomes negative
for any dispatch_constraint.

For 6), return false (see comment in aarch64-sched-dispatch.cc).

Dispatch information for a core can be added in its tuning model. We added
the new field *dispatch_constraint to the struct tune_params that holds a
pointer to a struct dispatch_constraints_info.
All current tuning models were initialized with nullptr.
(In the next patch, dispatch information will be added for Neoverse V2.)

The patch was bootstrapped and tested on aarch64-linux-gnu, no regression.

Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>

gcc/ChangeLog:

	* config.gcc: Add aarch64-sched-dispatch.o to extra_objs.
	* config/aarch64/aarch64-protos.h (struct tune_params): New
	field for dispatch scheduling.
	(struct dispatch_constraint_info): New struct for dispatch scheduling.
	* config/aarch64/aarch64-tuning-flags.def
	(AARCH64_EXTRA_TUNING_OPTION): New flag to enable dispatch scheduling.
	* config/aarch64/aarch64.cc (TARGET_SCHED_DISPATCH): Implement
	target hook.
	(TARGET_SCHED_DISPATCH_DO): Likewise.
	(aarch64_override_options_internal): Add check for definition of
	dispatch constraints if dispatch-scheduling tune flag is set.
	* config/aarch64/t-aarch64: Add aarch64-sched-dispatch.o.
	* config/aarch64/tuning_models/a64fx.h: Initialize fields for
	dispatch scheduling in tune_params.
	* config/aarch64/tuning_models/ampere1.h: Likewise.
	* config/aarch64/tuning_models/ampere1a.h: Likewise.
	* config/aarch64/tuning_models/ampere1b.h: Likewise.
	* config/aarch64/tuning_models/cortexa35.h: Likewise.
	* config/aarch64/tuning_models/cortexa53.h: Likewise.
	* config/aarch64/tuning_models/cortexa57.h: Likewise.
	* config/aarch64/tuning_models/cortexa72.h: Likewise.
	* config/aarch64/tuning_models/cortexa73.h: Likewise.
	* config/aarch64/tuning_models/cortexx925.h: Likewise.
	* config/aarch64/tuning_models/emag.h: Likewise.
	* config/aarch64/tuning_models/exynosm1.h: Likewise.
	* config/aarch64/tuning_models/fujitsu_monaka.h: Likewise.
	* config/aarch64/tuning_models/generic.h: Likewise.
	* config/aarch64/tuning_models/generic_armv8_a.h: Likewise.
	* config/aarch64/tuning_models/generic_armv9_a.h: Likewise.
	* config/aarch64/tuning_models/neoverse512tvb.h: Likewise.
	* config/aarch64/tuning_models/neoversen1.h: Likewise.
	* config/aarch64/tuning_models/neoversen2.h: Likewise.
	* config/aarch64/tuning_models/neoversen3.h: Likewise.
	* config/aarch64/tuning_models/neoversev1.h: Likewise.
	* config/aarch64/tuning_models/neoversev2.h: Likewise.
	* config/aarch64/tuning_models/neoversev3.h: Likewise.
	* config/aarch64/tuning_models/neoversev3ae.h: Likewise.
	* config/aarch64/tuning_models/olympus.h: Likewise.
	* config/aarch64/tuning_models/qdf24xx.h: Likewise.
	* config/aarch64/tuning_models/saphira.h: Likewise.
	* config/aarch64/tuning_models/thunderx.h: Likewise.
	* config/aarch64/tuning_models/thunderx2t99.h: Likewise.
	* config/aarch64/tuning_models/thunderx3t110.h: Likewise.
	* config/aarch64/tuning_models/thunderxt88.h: Likewise.
	* config/aarch64/tuning_models/tsv110.h: Likewise.
	* config/aarch64/tuning_models/xgene1.h: Likewise.
	* config/aarch64/aarch64-sched-dispatch.cc: New file for
	dispatch scheduling for aarch64.
	* config/aarch64/aarch64-sched-dispatch.h: New header file.
2025-09-24 16:18:28 +02:00
Jennifer Schmitz cb80cdbef4 AArch64: Annotate SVE instructions with new instruction attribute.
In this patch, we add the new instruction attribute "sve_type" and use it to
annotate the SVE instructions in aarch64-sve.md and aarch64-sve2.md. This
allows us to use instruction attributes to group instructions into dispatch
groups for dispatch scheduling. While there had already been fine-grained
annotation of scalar and neon instructions (mostly using the "type"-attribute),
annotation was missing for SVE instructions.

The values of the attribute "sve_type" are comparatively coarse-grained, but
fulfill the two criteria we aimed for with regard to dispatch scheduling:
- the annotation allows the definition of CPU-specific high-level attributes
  mapping instructions to dispatch constraints
- the annotation is by itself CPU-independent and consistent, i.e. all
  instructions fulfilling certain criteria are tagged with the corresponding
  value

The patch was bootstrapped and tested on aarch64-linux-gnu, no regression.

Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>

gcc/ChangeLog:

	* config/aarch64/aarch64-sve.md: Annotate instructions with
	attribute sve_type.
	* config/aarch64/aarch64-sve2.md: Likewise.
	* config/aarch64/aarch64.md (sve_type): New attribute sve_type.
	* config/aarch64/iterators.md (sve_type_unspec): New int attribute.
	(sve_type_int): New code attribute.
	(sve_type_fp): New int attribute.
2025-09-24 16:18:17 +02:00
Luc GrosheintzandTomasz Kamiński 41c95d5e53 libstdc++: Move test for __cpp_lib_not_fn to version.cc
When running the tests without pre-compiled headers
(--disable-libstdcxx-pch), the test fails, because the feature
testing macro (FTM) isn't defined yet.

This commit moves checking the FTM to a dedicated file (version.cc)
that's run without PCH.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/function_objects/not_fn/nttp.cc: Move
	test of feature testing macro to version.cc
	* testsuite/20_util/function_objects/not_fn/version.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-24 14:35:19 +02:00
Richard Biener 1f6b1ed047 tree-optimization/116816 - improve VMAT_ELEMENTWISE with SLP
The following implements VMAT_ELEMENTWISE for grouped loads, in
particular for being able to serve as fallback for unhandled
load permutations since it's trivial to load elements in the
correct order.

	PR tree-optimization/116816
	* tree-vect-stmts.cc (get_load_store_type): Allow multi-lane
	single-element interleaving to fall back to VMAT_ELEMENTWISE.
	Fall back to VMAT_ELEMENTWISE when we cannot handle a load
	permutation.
	(vectorizable_load): Do not check a load permutation
	for VMAT_ELEMENTWISE.  Handle grouped loads with
	VMAT_ELEMENTWISE and directly apply a load permutation.
2025-09-24 13:33:02 +02:00
Richard Biener 191d8b846c Fix get_load_store_type wrt VMAT_ELEMENTWISE classification
We may not classify a BB vectorization load as VMAT_ELEMENTWISE as
that will ICE.  Instead we build vectors from existing scalar loads.
Make that explicit.

	* tree-vect-stmts.cc (get_load_store_type): Explicitly fail
	when we end up with VMAT_ELEMENTWISE for BB vectorization.
2025-09-24 13:33:02 +02:00
Tomasz Kamiński dbf94a19f2 libstdc++: Reflect operator<< constraints in formatter for local_time.
The r16-3996-gdc78d691c5e5f7 commit (resolution of LWG4257) constrained the
operator<< for local_time, but didn't update the corresponding formatter. This
meant it didn't conditionally support formatting with an empty format spec ("{}"),
which is defined in terms of operator<<.

This patch addresses that by initializing __defSpec for the local_time
formatter in the same manner as it's done for sys_time. This functionality is
extracted to the _S_spec_for_tp function of __formatter_duration. As formatting
of local_time is defined and constrained in terms of operator<< for sys_time,
we can check the viability of the ostream operator for sys_time in both cases.

As default _M_chrono_spec may now be empty for local_time, the parse method
now checks if it was supplied in the format string, similarly to sys_time. The
condition for performing runtime check is expressed directly by checking if a
empty default is provided. This avoids the need to access the value of
__stream_insertable outside of the __defSpec computation.

As a note, despite their similar behavior, formatters sys_time and local_time
cannot be easily defined in terms of each other, as sys_time provides time zone
information while local_time does not.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (__formatter_duration::_S_spec_for_tp):
	Extracted from defition of formatter<sys_time>::__defSpec.
	(formatter<chrono::sys_time<_Duration>, _CharT>::parse): Simplify
	condition in if contexpr.
	(formatter<chrono::sys_time<_Duration>, _CharT>::__stream_insertable):
	Remove.
	(formatter<chrono::sys_time<_Duration>, _CharT>::__defSpec)
	(formatter<chrono::local_time<_Duration>, _CharT>::__defSpec):
	Compute using __formatter_duration::_S_spec_for_tp.
	(forrmatter<chrono::sys_time<_Duration>, _CharT>::parse): Check if
	parse _M_chrono_spec
	* testsuite/std/time/format/empty_spec.cc: Extend tests for floating
	point and other non-streamable durations (years).

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-24 11:57:09 +02:00
Tomasz Kamiński 36058be77f libstdc++: Use basic_format_parse_context<_CharT> in internal chrono formatters.
libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (__formatter_chrono::_M_parse):
	Replace _ParseContext with basic_format_parse_context<_CharT> and
	make it non-template.
	(__formatter_duration::_M_parse): Replace _ParseContext with
	basic_format_parse_context<_CharT> and remove unused default
	argument.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-24 11:56:32 +02:00
Xi Ruoyao 82edaadc6b docs: Note that -fisolate-erroneous-paths-dereference turns division by zero into a trap [PR 122040]
And this behavior is not limited to -fdelete-null-pointer-checks.

gcc/

	PR tree-optimization/122040
	* doc/invoke.texi (-fisolate-erroneous-paths-dereference):
	Mention it also turns division by zero into a trap in addition
	to null dereference.
2025-09-24 16:24:44 +08:00
Xi Ruoyao 2c98d7cf3a LoongArch: Add isnan expander [PR 66462]
Add an expander for isnan using fclass.  Since isnan is
just a compare, enable it only with -fsignaling-nans to avoid
generating spurious exceptions.  This fixes part of PR66462.

int isnan1 (float x) { return __builtin_isnan (x); }

With -fno-signaling-nans:

	fcmp.cun.s	$fcc0,$f0,$f0
	movcf2fr	$f0,$fcc0
	movfr2gr.s	$r4,$f0
	jr	$r1

With -fsignaling-nans:

	fclass.s	$f0,$f0
	movfr2gr.s	$r4,$f0
	andi	$r4,$r4,3
	sltu	$r4,$r0,$r4
	jr	$r1

	PR middle-end/66462

gcc/

	* config/loongarch/loongarch.md (FCLASS_MASK): Add 3.
	(fclass_optab): Assign isnan for 3.
	(<FCLASS_MASK:fclass_optab><ANYF:mode>2): If FCLASS_MASK is 3,
	only enable when -fsignaling-nans.

gcc/testsuite:

	* gcc.target/loongarch/fclass-compile.c: Update test.
	* gcc.target/loongarch/fclass-run.c: Likewise.
2025-09-24 16:24:41 +08:00
Nathaniel Shead fe2f86a960 c++/modules: Fix language linkage handling [PR122019]
The ICE in the linked PR is caused because when current_lang_name is
lang_name_c, set_decl_linkage calls decl_linkage on the retrofitted
declaration.  This is problematic because at this point we haven't
finished streaming the declaration, and so we crash when attempting to
access these missing bits (such as the type).

The only declarations we can reach here will be things like types that
don't get a language linkage anyway, so it seems reasonable to just
hardcode a C++ language linkage here to work around the issue.

An alternative fix would be to override current_lang_name in
lazy_load_binding instead, but this is potentially confusing if we ever
deliberately implement `extern "C" import "header_unit.hpp";` to
override the language linkage of imported declarations, so I went with
this approach instead.  (Though it seems we never will do this.)

While testing this I found that we don't currently complain about
mismatching language linkages for variables, and module_may_redeclare
doesn't cope well with implementation units, so this patch also fixes
those issues.

	PR c++/122019

gcc/cp/ChangeLog:

	* module.cc (trees_in::install_entity): Don't be affected by
	global language linkage state.
	(trees_in::is_matching_decl): Check mismatching language linkage
	for variables too.
	(module_may_redeclare): Report the correct module name for
	partitions and implementation units.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/lang-4_a.C: New test.
	* g++.dg/modules/lang-4_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-09-24 17:33:24 +10:00
Paul Thomas e77daa5730 Fortran: Fix ICE in check_interface [PR87908]
2025-09-24  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/87908
	* interface.cc (check_interface0): If a vtable is found in the
	interface list, check that it is either a subroutine or a
	function. Let resolve.cc do any further checking.

gcc/testsuite/
	PR fortran/87908
	* gfortran.dg/pr87908.f90: New test.
2025-09-24 08:01:23 +01:00
Patrick Palka e9f3138f38 libstdc++/testsuite: Unpoison 'u' on s390x in names.cc test
This is the s390 counterpart to r11-7364-gd0453cf5c68b6a, and fixes the
following names.cc failure caused by a use of a poisoned identifier.
If we look at the corresponding upstream header[1] it's clear that the
problematic identifier is 'u'.

In file included from /usr/include/linux/types.h:5,
                 from /usr/include/linux/sched/types.h:5,
                 from /usr/include/bits/sched.h:61,
                 from /usr/include/sched.h:43,
                 from /usr/include/pthread.h:22,
                 from /usr/include/c++/14/s390x-redhat-linux/bits/gthr-default.h:35,
                 from /usr/include/c++/14/s390x-redhat-linux/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/c++/14/s390x-redhat-linux/bits/stdc++.h:54,
                 from /root/rpmbuild/BUILD/gcc-14.3.1-20250617/libstdc++-v3/testsuite/17_intro/names.cc:384:
/usr/include/asm/types.h:24: error: expected unqualified-id before '[' token
/usr/include/asm/types.h:24: error: expected ')' before '[' token
/root/rpmbuild/BUILD/gcc-14.3.1-20250617/libstdc++-v3/testsuite/17_intro/names.cc:101: note: to match this '('
compiler exited with status 1
FAIL: 17_intro/names.cc  -std=gnu++98 (test for excess errors)
Excess errors:
/usr/include/asm/types.h:24: error: expected unqualified-id before '[' token
/usr/include/asm/types.h:24: error: expected ')' before '[' token

[1]: https://github.com/torvalds/linux/blob/master/arch/s390/include/uapi/asm/types.h

libstdc++-v3/ChangeLog:

	* testsuite/17_intro/names.cc: Undefine 'u' on s390*-linux.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-09-23 22:41:26 -04:00
Pan Li 1617b9e1bb RISC-V: Add test case of unsigned scalar SAT_MUL form 5 for mul
Add test case for both the run and asm check of mul based SAT_MUL.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/sat/sat_u_mul-6-u16-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u16-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u16-from-u64.rv64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u32-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u32-from-u64.rv64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u8-from-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u8-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u8-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u8-from-u64.rv64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u16-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u16-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u32-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u8-from-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u8-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u8-from-u64.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-24 10:35:07 +08:00
Pan Li 02142e21d9 Match: Add form 5 of unsigned SAT_MUL for mul
This patch would like to try to match the the unsigned
SAT_MUL form 5, aka below:

  #define DEF_SAT_U_MUL_FMT_5(NT, WT)             \
  NT __attribute__((noinline))                    \
  sat_u_mul_##NT##_from_##WT##_fmt_5 (NT a, NT b) \
  {                                               \
    WT x = (WT)a * (WT)b;                         \
    NT hi = x >> (sizeof(NT) * 8);                \
    NT lo = (NT)x;                                \
    return lo | -!!hi;                            \
  }

  while WT is uint16_t, uint32_t and uint64_t.
  and T is uint8_t, uint16_t, uint32_t.

gcc/ChangeLog:

	* match.pd: Add pattern of mult and reuse the widen-mul
	by for keyword.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-24 10:35:07 +08:00
GCC Administrator 3b52634c71 Daily bump. 2025-09-24 00:21:37 +00:00
David Malcolm 0d5af6a757 sarif output: add descriptions to fix-it hints (§3.55.2) [PR121986]
SARIF "fix" objects SHOULD have a "description" property (§3.55.2) that
describes the proposed fix, but currently GCC's SARIF output doesn't
support this, and we don't capture this anywhere internally as we build
fix-it hints in the compiler.

Currently we can have zero or more instances of fixit_hint associated
with a diagnostic, each representing an edit of a range of the source
code. Ideally we would have an internal API that allowed for associating
multiple fixes with a diagnostic, each with a description worded in terms
of the source language (e.g. "Fix 'colour' mispelling of field 'color'"),
and each consisting of multiple edited ranges.

For now, this patch extends the sarif output sink so that it
autogenerates descriptions of fix-it hints for simple cases of
insertion, deletion, and replacement of a single range
(e.g. "Replace 'colour' with 'color'").

gcc/ChangeLog:
	PR diagnostics/121986
	* diagnostics/sarif-sink.cc: Include "intl.h".
	(sarif_builder::make_message_describing_fix_it_hint): New.
	(sarif_builder::make_fix_object): Attempt to auto-generate a
	description for fix-it hints.

gcc/testsuite/ChangeLog:
	PR diagnostics/121986
	* gcc.dg/sarif-output/extra-semicolon.c: New test.
	* gcc.dg/sarif-output/extra-semicolon.py: New test.
	* gcc.dg/sarif-output/missing-semicolon.py: Verify the description
	of the insertion fix-it hint.
	* libgdiagnostics.dg/test-fix-it-hint-c.py: Verify the description
	of the replacement fix-it hint.

libcpp/ChangeLog:
	PR diagnostics/121986
	* include/rich-location.h (fixit_hint::deletion_p): New accessor.
	(fixit_hint::replacement_p): New accessor.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-23 16:45:12 -04:00
Jonathan Wakely 2dc3e74b9d libstdc++: Refactor std::philox_engine member functions
libstdc++-v3/ChangeLog:

	* include/bits/random.h: Include <bits/ios_base.h> instead of
	<iomanip>. Change preprocessor checks to use internal feature
	test macro.
	(philox_engine): Reword doxygen comments. Use typename instead
	of class in template parameter lists. Reformat and adjust
	whitespace.
	(philox_engine::_If_seed_seq): Replace alias template with
	__is_seed_seq variable template.
	(philox_engine::philox_engine(result_type)): Define inline.
	(philox_engine::seed(result_type), philox_engine::set_counter)
	(philox_engine::operator(), philox_engine::discard): Likewise.
	(operator==): Define as defaulted.
	(operator<<): Reuse widened char.
	* include/bits/random.tcc: Reformat and adjust whitespace.
	(philox_engine::_M_philox): Use std::array copy constructor and
	std::array::fill instead of looping.
	* testsuite/26_numerics/random/philox4x32.cc: Gate test on
	feature test macro. Add static_assert to check typedef.
	* testsuite/26_numerics/random/philox4x64.cc: Likewise.
	* testsuite/26_numerics/random/philox_engine/cons/copy.cc: Add
	VERIFY assertions to check copies are equal. Test different
	seeds.
	* testsuite/26_numerics/random/philox_engine/cons/default.cc:
	Add VERIFY assertions to check construction results.
	* testsuite/26_numerics/random/philox_engine/cons/seed.cc:
	Likewise.
	* testsuite/26_numerics/random/philox_engine/operators/equal.cc:
	Also test inequality.
	* testsuite/26_numerics/random/philox_engine/operators/serialize.cc:
	Remove redundant include and return.
	* testsuite/26_numerics/random/philox_engine/requirements/constants.cc:
	Check values of all constants.
	* testsuite/26_numerics/random/philox_engine/requirements/typedefs.cc:
	Check typedefs are correct.
	* testsuite/26_numerics/random/philox_engine/cons/119794.cc:
	Removed.
	* testsuite/26_numerics/random/philox_engine/cons/seed_seq.cc:
	Removed.
	* testsuite/26_numerics/random/philox_engine/operators/inequal.cc:
	Removed.
	* testsuite/26_numerics/random/philox_engine/requirements/constexpr_data.cc:
	Removed.
	* testsuite/26_numerics/random/philox_engine/requirements/constexpr_functions.cc:
	Removed.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	line number.
2025-09-23 16:38:29 +01:00
1nfocalypse 1c06243e65 libstdc++: Implement Philox Engine (PR119794)
Conforms with errata LWG4143, LWG4153 for Philox Engine.

	PR libstdc++/119794

libstdc++-v3/ChangeLog:

	* include/bits/random.h (philox_engine): Define.
	* include/bits/random.tcc (philox_engine): Define member
	functions.
	* include/bits/version.def (philox_engine): New macro.
	* include/bits/version.h: Regenerated.
	* include/std/random: Define __glibcxx_want_philox_engine and
	include <bits/version.h>.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	line number.
	* testsuite/26_numerics/random/philox4x32.cc: New test.
	* testsuite/26_numerics/random/philox4x64.cc: New test.
	* testsuite/26_numerics/random/philox_engine/cons/119794.cc: New test.
	* testsuite/26_numerics/random/philox_engine/cons/copy.cc: New test.
	* testsuite/26_numerics/random/philox_engine/cons/default.cc: New test.
	* testsuite/26_numerics/random/philox_engine/cons/seed.cc: New test.
	* testsuite/26_numerics/random/philox_engine/cons/seed_seq.cc: New test.
	* testsuite/26_numerics/random/philox_engine/operators/equal.cc: New test.
	* testsuite/26_numerics/random/philox_engine/operators/inequal.cc: New test.
	* testsuite/26_numerics/random/philox_engine/operators/serialize.cc: New test.
	* testsuite/26_numerics/random/philox_engine/requirements/constants.cc: New test.
	* testsuite/26_numerics/random/philox_engine/requirements/constexpr_data.cc: New test.
	* testsuite/26_numerics/random/philox_engine/requirements/constexpr_functions.cc: New test.
	* testsuite/26_numerics/random/philox_engine/requirements/typedefs.cc: New test.
2025-09-23 16:38:29 +01:00
Ben Wu 52d702d72a libstdc++: fix element construction in std::deque::emplace [PR118087]
In order to emplace a value in the middle of a deque, a temporary was
previously constructed directly with __args... in _M_emplace_aux.
This would not work since std::deque is allocator-aware and should
construct elements with _Alloc_traits::construct instead before the
element is moved.

Using the suggestion in PR118087, we can define _Temporary_value
similar to the one used in std::vector, so the temporary can be
constructed with uses-allocator construction.

	PR libstdc++/118087

libstdc++-v3/ChangeLog:

	* include/bits/deque.tcc: Use _Temporary_value in
	_M_emplace_aux.
	* include/bits/stl_deque.h: Introduce _Temporary_value.
	* testsuite/23_containers/deque/modifiers/emplace/118087.cc:
	New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Ben Wu <soggysocks206@gmail.com>
2025-09-23 16:38:28 +01:00
Richard Earnshaw 2e1c124096 arm: mve: fix out-of range literal pool for a const_vector [PR121810]
For the pattern mve_mov<mode>, the alternative that describes literal
pool support is incorrect.  This leads to compiler getting the
calculations wrong for the available distance to the next pool
fragment because the selected alternative is a shorter sequence than
the correct one.  In particular the sequence generated for a 128-bit
constant is

	vldr.64	 d0, Pool    // Insn length 4, alternative 7 (part 1)
	vldr.64	 d1, Pool+8  // Insn length 4, alternative 7 (part 2)

Note that the second instruction needs 4 bytes more range than the
first because the PC has advanced by 4 bytes, but the next slot in the
pool has advanced by 8.

The fix is to move the 'Ui' constraint to the correct alternative
and to move the pool-range attributes to that alternative as well.

I've fixed a couple of other nits in this code at the same time:
- the thumb2_neg_pool_range attribute was misnamed (as neg_pool_range),
meaning it was ignored in Thumb state, which is the only time this
pattern is available.
- the load range was not a multiple of 4, which makes no sense for
an insn sequence that is a multiple of 4 bytes long.  I've rounded the
value down out of caution, but it may well have been OK with 1020 as
the forward range.

I'm not adding a testcase for this patch; the code to reproduce is
simply too complex to reliably test for a regression.

gcc/ChangeLog:
	PR target/121810
	* config/arm/mve.md (mve_mov<mode>): Move the Ui constraint
	and pool_range attributes to the final alternative.  Fix
	the forward range value and correctly name the negative
	range.
2025-09-23 15:36:59 +01:00
Tomasz Kamiński 7dd28f0a81 libstdc++: Make function_ref(nontype<f>, r) CTAD SFINAE friendly [PR121940]
Instantiating the __deduce_funcref function body for function pointers
without arguments or member pointers with non-matching object types
previously led to hard errors due to the formation of invalid types.

The __deduce_funcref function is now adjusted to return void in such
cases. The corresponding function_ref deduction guide is constrained to
only match if the return type is not void, making it SFINAE friendly.

	PR libstdc++/121940

libstdc++-v3/ChangeLog:

	* include/bits/funcwrap.h (__polyfunc::__deduce_funcref): Return void
	for ill-formed constructs.
	(function_ref(nontype_t<__f>, _Tp&&)): Constrain on __deduce_funcref
	producing non-void results.
	* testsuite/20_util/function_ref/deduction.cc: Negative tests.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-23 15:17:07 +02:00
Bob Duff 54c1b58486 ada: Fix unnesting problem related to constructors
This patch fixes a bug in unnesting, which is used by the llvm back end.

Exp_Unst relies on the Scope field of nodes to detect up-level
references. Temps created by Prepend_Constructor_Procedure_Prologue
could have an incorrect Scope, causing Exp_Unst to use an up-level
reference to an activation record to implement up-level references. That
won't work; Exp_Unst is supposed to REMOVE up-level references.
This patch corrects the Scope of such temps.

gcc/ada/ChangeLog:

	* exp_ch6.adb (Prepend_Constructor_Procedure_Prologue):
	Push/Pop the procedure scope, so that temps created herein
	get the right Scope.
2025-09-23 15:01:13 +02:00
Jose Ruiz 0a10fc5d72 ada: Improve robustness of stack usage tracking in concurrent contexts
Enabled computation of stack usage for tasks that have already
initialized their stacks with the expected fill pattern.

Ensured that stack usage snapshots for tasks are taken while
the runtime is locked, to maintain consistency.

For the environment task, approximated the stack origin using
the topmost stack known address during initialization, and take
into account that the Stack_Analyzer object is not part of its
ATCB.

gcc/ada/ChangeLog:

	* libgnarl/s-stusta.adb (Report_Impl): Export a copy of
	the current stack usage while holding the runtime lock.
	(Report_For_Task): Do not compute stack usage for a task
	that has not yet initialized its stack with the expected
	pattern.
	(Report_For_Task): The Stack_Analyzer object for the
	environment task is not part of its ATCB. For the rest of
	the tasks wait until we have initialized the stack pattern
	before computing stack usage.
	(Report_All_Tasks, Get_All_Tasks_Usage,
	Get_Current_Task_Usage): Adapt to the new interface from
	Report_Impl. Take into account that Result_Array can be
	null. When we don't store stack results for a task we
	need to compute it when requested.
	(Print): Handle the case when we don't know the stack
	usage to be reported.
	* libgnat/s-stausa.adb (Initialize): For the environment
	task, approximate the stack origin with the topmost
	stack address that is known.
	* libgnat/s-stausa.ads: Clarify comments.
2025-09-23 15:01:13 +02:00
Denis Mazzucato 346b4921f9 ada: Refactor of Ultimate_Prefix
gcc/ada/ChangeLog:

	* sem_util.adb (Ultimate_Prefix): Clean-up the loop condition by using
	Has_prefix instead of an explicit list of node kinds.
2025-09-23 15:01:13 +02:00
Denis Mazzucato be42204d1f ada: Fix missing warning when child packages hide homonym units
Improve consistency of the warning message when child units are hiding other
with'ed homonym package, regardless of the order of the context clauses.

gcc/ada/ChangeLog:

	* sem_ch10.adb (Install_Siblings): Fix condition to emit warning.
2025-09-23 15:01:13 +02:00
Viljar Indus e8303f86c6 ada: Fix Is_Case_Choice_Pattern for allocators
gcc/ada/ChangeLog:

	* sem_case.adb (Is_Case_Choice_Pattern): Return False for allocators.
2025-09-23 15:01:13 +02:00
Douglas B Rupp 5d3f5fde93 ada: Remove rtp base spec linker option pragma
Remove the linker option pragmas from vxworks7 rtp system specs,
since this is needed only with gnatmake.  The same info is contained
in gprbuild, which is the only tool that can be used for building
vxworks apps.

gcc/ada/ChangeLog:

	* libgnat/system-vxworks7-aarch64-rtp-smp.ads (Linker_Options):
	Remove pragma for RTP specs.
	* libgnat/system-vxworks7-ppc-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-ppc64-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-x86-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-x86_64-rtp-smp.ads: Likewise.
2025-09-23 15:01:12 +02:00
Gary Dismukes 56902d1717 ada: New preprocessing option for emitting empty comments for deleted lines
When integrated preprocessing is done on a source file with lines that are
filtered out, by default this can result in multiple blank lines being emitted,
but this can clash with the style switch -gnatyu, which will flag cases of
multiple blank lines.  A new preprocessing option "-e" is added to allow
outputting "empty" comment lines rather than blank lines (the comments consist
of "--!" and no other text).  This option is also available for the gnatprep
tool.  This behavior is the default when integrated preprocessing is done
without generating a ".prep" output file with -gnateG, but when -gnateG is
used, blank lines are still substituted by default for directives and removed
source lines (for compatibility with long-existing behavior).  The -gnateG
switch is also extended to allow appending 'b', 'c', or 'e' at the end of
the switch to force any of the replacement options ('b' => blank lines,
'c' => comments including the original source lintes, and 'e' => empty
comment lines).

gcc/ada/ChangeLog:

	* doc/gnat_ugn/building_executable_programs_with_gnat.rst: Add doc
	for addition of -gnateG options b, c, and e.
	* doc/gnat_ugn/the_gnat_compilation_model.rst: Add doc for "-e" optionn
	on gnatprep and integrated preprocessing. Add doc for addition of
	-gnateG options b, c, and e.
	* gprep.adb (Scan_Command_Line): Add 'e' to the list of allowed switch
	letters in the string passed to GNAT.Command_Line.Getopt. Set the flag
	Opt.Empty_Comment_Deleted_Lines to True when the "-e" switch is found.
	(Usage): Output a switch description for the "-e" switch.
	* opt.ads: Add new flag variable Empty_Comment_Deleted_Lines. Add
	"GNAT" to the "GNATPREP" comment line for Comment_Deleted_Lines.
	* prep.adb (Output_Line): Add handling for Empty_Comment_Deleted_Lines,
	outputting comment lines consisting of "--!" for lines that are removed
	in the preprocessed source file when Empty_Comment_Deleted_Lines is True.
	* prepcomp.adb (Preproc_Data): Add Empty_Comments component (defaulting
	to False).
	(No_Preproc_Data): Add association for Empty_Comments component.
	(Parse_Preprocessing_Data_File): Add handling for new switch -e.
	(Prepare_To_Preprocess): Add logic for setting the new option
	Empty_Comment_Deleted_Lines (and making it the default for
	integrated preprocessing in the absence of other switches).
	* switch-c.adb (Scan_Front_End_Switches): Add support adding a single
	character 'b', 'c', 'e' to the "-gnateG" switch, to select any of the
	three options for replacing deleted lines in preprocessing output file.
	* usage.adb: Update usage info for -gnateG, to reflect the option of
	appending b, c, or e to the switch.
	* gnat_ugn.texi: Regenerate.
2025-09-23 15:01:12 +02:00
Piotr Trojanek bbd00cd05d ada: Include finally statements in debug pretty-printing
Handled sequence of statements now includes optional finally statements.

gcc/ada/ChangeLog:

	* sprint.adb (Sprint_Node_Actual): Print finally statements, if
	present.
2025-09-23 15:01:12 +02:00
Javier Miranda fde2299c3a ada: Spurious predicate check at default initialization
For an object created by an object_declaration with no explicit
initialization expression, if the type of the object is a record
type (or a private record type) with no components and a dynamic
predicate, then no predicate check must be performed at runtime
(RM 3.2.4(31/5)).

gcc/ada/ChangeLog:

	* sem_util.adb (Is_Partially_Initialized_Type): Return False
	for record types with no components.
2025-09-23 15:01:12 +02:00
Steve Baird dcb84365a6 ada: Document the GNAT-defined Extended_Access aspect
GNAT RM update to document the new Extended_Access aspect.

gcc/ada/ChangeLog:

	* doc/gnat_rm/implementation_defined_aspects.rst: Document the
	Extended_Access aspect.
	* gnat_rm.texi: Regenerate.
	* gnat_ugn.texi: Regenerate.
2025-09-23 15:01:12 +02:00
Richard Earnshaw b8701893e9 toplevel: Fix syntax issue in .editorconfig
.editorconfig entries need to be a single filesystem glob pattern.

ChangeLog:

	* .editorconfig: Fix glob patterns.
2025-09-23 13:17:01 +01:00
Paul Thomas 300c9047bd Fortran: Check ICE in gfc_conv_array_initializer has gone [PR105380]
2025-09-23  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	* ChangeLog: Correct PR number for entry on 18th Sept: 114815 to
	121948.

gcc/testsuite/
	* ChangeLog: Ditto.

	PR fortran/105380
	* gfortran.dg/pdt_49.f03: New test.
2025-09-23 12:46:28 +01:00
Pan Li 5756c9816e Widen-Mul: Fix typo assignment in build_and_insert_cast [PR122031]
The previous fix for PR122021 introduces a typo that the assignment
to the var itself.  This PR would like to fix the typo, and sorry for
my silly mistake.

The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. The x86 bootstrap tests.
3. The x86 fully regression tests.

	PR middle-end/122031

gcc/ChangeLog:

	* tree-ssa-math-opts.cc (build_and_insert_cast): Fix the typo
	of self assignment.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-23 18:51:32 +08:00
Richard Earnshaw ab6879f3e9 arm: fix target-specific test duplicates for gcc
This patch fixes all the duplicates that I see when testing GCC (C
code).  Some of these were real problems with the testsuite where we
were testing the wrong thing because of typos; others are due to
laxity in the tests so that we had a degree of ambiguity in the
results.  I've mostly fixed the latter category by converting the
relevant test into a check-function-bodies test.

gcc/testsuite/ChangeLog:

	* gcc.target/arm/acle/simd32.c (test_sadd16): Scan for sadd16.
	* gcc.target/arm/armv8_2-fp16-neon-1.c (vcgtz, 128-bit): Scan for vcgt.
	* gcc.target/arm/armv8_2-fp16-neon-2.c (vcgtz, 128-bit): Scan for vcgt.
	(vmul, vmul N): Use check function bodies to avoid ambiguity.
	* gcc.target/arm/armv8_2-fp16-scalar-1.c (vrndm): Scan for vrintm.
	(vrndn): Scan for vrintn.
	(vrndp): Scan for vrintp.
	(vrndx): Scan for vrintx.
	* gcc.target/arm/asm-flag-1.c: Scan for movlt.
	* gcc.target/arm/csneg.c: Convert to check-function-bodies.
	* gcc.target/arm/mve/dlstp-compile-asm-2.c (test10): Fix comment that caused test9 scan
	to be run twice.
	* gcc.target/arm/mve/intrinsics/vgetq_lane_f16.c: Convert to check-function-bodies.
	* gcc.target/arm/mve/intrinsics/vgetq_lane_f32.c: Likewise.
	* gcc.target/arm/mve/intrinsics/vgetq_lane_s16.c: Likewise.
	* gcc.target/arm/mve/intrinsics/vgetq_lane_s32.c: Likewise.
	* gcc.target/arm/mve/intrinsics/vgetq_lane_s8.c: Likewise.
	* gcc.target/arm/mve/intrinsics/vgetq_lane_u16.c: Likewise.
	* gcc.target/arm/mve/intrinsics/vgetq_lane_u32.c: Likewise.
	* gcc.target/arm/mve/intrinsics/vgetq_lane_u8.c: Likewise.
2025-09-23 11:15:58 +01:00
Alfie Richards de60b080e3 aarch64: Remove FMV beta warning.
This patch removes the warning for target_version and target_clones in aarch64
as it is now spec compliant.

gcc/ChangeLog:

	* config/aarch64/aarch64.cc (aarch64_process_target_version_attr):
	Remove warning.
	* config/aarch64/aarch64.opt: Mark -Wno-experimental-fmv-target
	deprecated.
	* doc/invoke.texi: Ditto.

gcc/testsuite/ChangeLog:

	* g++.target/aarch64/mv-1.C: Remove option.
	* g++.target/aarch64/mv-and-mvc-error1.C: Ditto.
	* g++.target/aarch64/mv-and-mvc-error2.C: Ditto.
	* g++.target/aarch64/mv-and-mvc-error3.C: Ditto.
	* g++.target/aarch64/mv-and-mvc1.C: Ditto.
	* g++.target/aarch64/mv-and-mvc2.C: Ditto.
	* g++.target/aarch64/mv-and-mvc3.C: Ditto.
	* g++.target/aarch64/mv-and-mvc4.C: Ditto.
	* g++.target/aarch64/mv-error1.C: Ditto.
	* g++.target/aarch64/mv-error2.C: Ditto.
	* g++.target/aarch64/mv-error3.C: Ditto.
	* g++.target/aarch64/mv-error4.C: Ditto.
	* g++.target/aarch64/mv-error5.C: Ditto.
	* g++.target/aarch64/mv-error6.C: Ditto.
	* g++.target/aarch64/mv-error7.C: Ditto.
	* g++.target/aarch64/mv-error8.C: Ditto.
	* g++.target/aarch64/mv-pragma.C: Ditto.
	* g++.target/aarch64/mv-symbols1.C: Ditto.
	* g++.target/aarch64/mv-symbols10.C: Ditto.
	* g++.target/aarch64/mv-symbols11.C: Ditto.
	* g++.target/aarch64/mv-symbols12.C: Ditto.
	* g++.target/aarch64/mv-symbols13.C: Ditto.
	* g++.target/aarch64/mv-symbols2.C: Ditto.
	* g++.target/aarch64/mv-symbols3.C: Ditto.
	* g++.target/aarch64/mv-symbols4.C: Ditto.
	* g++.target/aarch64/mv-symbols5.C: Ditto.
	* g++.target/aarch64/mv-symbols6.C: Ditto.
	* g++.target/aarch64/mv-symbols7.C: Ditto.
	* g++.target/aarch64/mv-symbols8.C: Ditto.
	* g++.target/aarch64/mv-symbols9.C: Ditto.
	* g++.target/aarch64/mvc-error1.C: Ditto.
	* g++.target/aarch64/mvc-error2.C: Ditto.
	* g++.target/aarch64/mvc-symbols1.C: Ditto.
	* g++.target/aarch64/mvc-symbols2.C: Ditto.
	* g++.target/aarch64/mvc-symbols3.C: Ditto.
	* g++.target/aarch64/mvc-symbols4.C: Ditto.
	* g++.target/aarch64/mv-warning1.C: Removed.
	* g++.target/aarch64/mvc-warning1.C: Removed.
2025-09-23 09:47:44 +00:00
Alfie Richards 1d36100bcf aarch64: testsuite: Add diagnostic tests for Aarch64 FMV.
Add tests covering many FMV errors for Aarch64, including
redeclaration, and mixing target_clones and target_versions.

gcc/testsuite/ChangeLog:

	* g++.target/aarch64/mv-and-mvc-error1.C: New test.
	* g++.target/aarch64/mv-and-mvc-error2.C: New test.
	* g++.target/aarch64/mv-and-mvc-error3.C: New test.
	* g++.target/aarch64/mv-error1.C: New test.
	* g++.target/aarch64/mv-error2.C: New test.
	* g++.target/aarch64/mv-error3.C: New test.
	* g++.target/aarch64/mv-error4.C: New test.
	* g++.target/aarch64/mv-error5.C: New test.
	* g++.target/aarch64/mv-error6.C: New test.
	* g++.target/aarch64/mv-error7.C: New test.
	* g++.target/aarch64/mv-error8.C: New test.
	* g++.target/aarch64/mvc-error1.C: New test.
	* g++.target/aarch64/mvc-error2.C: New test.
	* g++.target/aarch64/mvc-warning1.C: Modified test.
2025-09-23 09:47:44 +00:00
Alfie Richards a96bd4a013 fmv: Support mixing of target_clones and target_version.
Add support for a FMV set defined by a combination of target_clones and
target_version definitions.

Additionally, change is_function_default_version to consider a function
declaration annotated with target_clones containing default to be a
default version.

Lastly, add support for the case that a target_clone has all versions filtered
out and therefore the declaration should be removed. This is relevant as now
the default could be defined in a target_version, so a target_clones no longer
necessarily contains the default.

This takes advantage of refactoring done in previous patches changing how
target_clones are expanded and how conflicting decls are handled.

gcc/ChangeLog:

	* attribs.cc (is_function_default_version): Update to handle
	target_clones.
	* cgraph.h (FOR_EACH_FUNCTION_REMOVABLE): New macro.
	* multiple_target.cc (expand_target_clones): Update logic to delete
	empty target_clones and modify diagnostic.
	(ipa_target_clone): Update to use FOR_EACH_FUNCTION_REMOVABLE.

gcc/c-family/ChangeLog:

	* c-attribs.cc: Add support for target_version and target_clone mixing.

gcc/testsuite/ChangeLog:

	* g++.target/aarch64/mv-and-mvc1.C: New test.
	* g++.target/aarch64/mv-and-mvc2.C: New test.
	* g++.target/aarch64/mv-and-mvc3.C: New test.
	* g++.target/aarch64/mv-and-mvc4.C: New test.
2025-09-23 09:47:44 +00:00
Alfie Richards 62287200df c++: Refactor FMV frontend conflict and merging logic and hooks.
This change refactors FMV handling in the frontend to allows greater
reasoning about versions in shared code.

This is needed for allowing target_clones and target_versions to be used
together in a function set, as there is then two distinct concerns when
encountering two declarations that previously were conflated:

1. Are these two declarations completely disjoint FMV declarations
(ie. the sets of versions they define have no overlap). If so, they don't
conflict so there is no need to merge and both can be pushed.
2. For two declarations that aren't completely disjoint, are they matching
and therefore mergeable. (ie. two target_clone decls that define the same set
of versions, or an un-annotated declaration, and a target_clones definition
containing the default version). If so, continue to the existing merging logic
to try to merge these and diagnose if it's not possible.
If not, then diagnose the conflicting declarations.

To do this the common_function_versions function has been renamed
disjoint_function_versions (meaning, are the version sets defined by these
two decl's completely distinct from each other).

A new hook called same_function_version is introduces taking two
string_slice's (each representing a single version) and determining if they
define the same version.

A new function, called diagnose_versioned_decls is added, which checks
if two decls (with overlapping version sets) can be merged and diagnose when
they cannot be (only in terms of the attributes, the existing logic is used to
detect other mergeability conflicts like redefinition).

This only effects targets with TARGET_HAS_FMV_TARGET_ATTRIBUTE set to false.
(ie. aarch64 and riscv), the existing logic for i86 and ppc is unchanged.
This also means the same function version hook is only used for aarch64 and
riscv.

gcc/ChangeLog:

	* attribs.h (common_function_versions): Removed.
	* attribs.cc (common_function_versions): Removed.
	* config/aarch64/aarch64.cc (aarch64_common_function_versions): Removed.
	(aarch64_same_function_versions): New function to check if two version
	strings imply the same version.
	(TARGET_OPTION_FUNCTION_VERSIONS): Removed.
	(TARGET_OPTION_SAME_FUNCTION_VERSIONS): New macro.
	* config/i386/i386.cc (TARGET_OPTION_FUNCTION_VERSIONS): Removed.
	* config/rs6000/rs6000.cc (TARGET_OPTION_FUNCTION_VERSIONS): Removed.
	* config/riscv/riscv.cc (riscv_same_function_versions):  New function
	to check if two version strings imply the same version.
	(riscv_common_function_versions): Removed.
	(TARGET_OPTION_FUNCTION_VERSIONS): Removed.
	(TARGET_OPTION_SAME_FUNCTION_VERSIONS): New macro.
	* doc/tm.texi: Regenerated.
	* target.def: Remove common_version hook and add same_function_version
	hook.
	* doc/tm.texi.in: Ditto.
	* tree.cc (distinct_version_decls): New function.
	(mergeable_version_decls): Ditto.
	* tree.h (distinct_version_decls): New function.
	(mergeable_version_decls): Ditto.
	* hooks.h (hook_stringslice_stringslice_unreachable): New function.
	* hooks.cc (hook_stringslice_stringslice_unreachable): New function.

gcc/cp/ChangeLog:

	* class.cc (resolve_address_of_overloaded_function): Updated to use
	dijoint_versions_decls instead of common_function_version hook.
	* decl.cc (decls_match): Refacture to use disjoint_version_decls and
	to pass through conflicting_version argument.
	(maybe_version_functions): Updated to use
	disjoint_version_decls instead of common_function_version hook.
	(duplicate_decls): Add logic to handle conflicting unmergable decls
	and improve diagnostics for conflicting versions.
	* decl2.cc (check_classfn): Updated to use
	disjoint_version_decls instead of common_function_version hook.
2025-09-23 09:47:44 +00:00
Alfie Richards c2c7fd312c c: c++: Add target_[version/clones] to decl diagnostics formatting.
Adds the target_version and target_clones attributes to diagnostic messages
for target_version semantics.

This is because the target_version/target_clones attributes affect the identity
of the decls, so need to be represented in diagnostics for them.

This also requires making maybe_print_whitespace available to c++ code so
we can control if whitespace is needed cosistantly between c and c++
diagnostics.

After this change diagnostics look like:

c:
```
test.c:6:8: error: redefinition of ‘foo [[target_version("sve")]]’
    6 | float  foo  () {return 1;}
      |        ^~~
test.c:3:8: note: previous definition of ‘foo [[target_version("sve")]]’ with type ‘float(void)’
    3 | float  foo  () {return 2;}
      |        ^~~
test.c:12:8: error: redefinition of ‘bar [[target_clones("sve")]]’
   12 | float  bar () {return 1;}
      |        ^~~
test.c:9:8: note: previous definition of ‘bar [[target_clones("sve")]]’ with type ‘float(void)’
    9 | float  bar () {return 2;}
      |        ^~~
```

c++:
```
test.cpp:6:8: error: redefinition of ‘float foo [[target_version("sve")]] ()’
    6 | float  foo  () {return 1;}
      |        ^~~
test.cpp:3:8: note: ‘float foo [[target_version("sve")]] ()’ previously defined here
    3 | float  foo  () {return 2;}
      |        ^~~
test.cpp:12:8: error: redefinition of ‘float bar [[target_clones("sve")]] ()’
   12 | float  bar () {return 1;}
      |        ^~~
test.cpp:9:8: note: ‘float bar [[target_clones("sve")]] ()’ previously defined here
    9 | float  bar () {return 2;}
      |        ^~~
```

This only affects targets which use target_version (aarch64 and riscv).

gcc/c-family/ChangeLog:

	* c-pretty-print.cc (pp_c_function_target_version): New function.
	(pp_c_function_target_clones): New function.
	(pp_c_maybe_whitespace): Move to c-pretty-print.h.
	* c-pretty-print.h (pp_c_function_target_version): New function.
	(pp_c_function_target_clones): New function.
	(pp_c_maybe_whitespace): Moved here from c-pretty-print.cc.

gcc/c/ChangeLog:

	* c-objc-common.cc (c_tree_printer): Add printing of target_clone and
	target_version in decl diagnostics.

gcc/cp/ChangeLog:

	* cxx-pretty-print.h (pp_cxx_function_target_version): New macro.
	(pp_cxx_function_target_clones): Ditto.
	(pp_cxx_maybe_whitespace): Ditto.
	* error.cc (dump_function_decl): Add printing of target_clone and
	target_version in decl diagnostics.
2025-09-23 09:47:43 +00:00
Alfie Richards aeb9a43bbb fmv: c++: Change target_version semantics to follow ACLE specification.
This patch changes the semantics of target_version and target_clones attributes
to match the behavior described in the Arm C Language extension.

The changes to behavior are:

- The scope and signature of an FMV function set is now that of the default
  version.
- The FMV resolver is now created at the locations of the default version
  implementation. Previously this was at the first call to an FMV function.
- When a TU has a single annotated function version, it gets mangled.
  - This includes a lone annotated default version.

This only affects targets with TARRGET_HAS_FMV_TARGET_ATTRIBUTE set to false.
Currently that is aarch64 and riscv.

This is achieved by:

- Skipping the existing FMV dispatching code at C++ gimplification and instead
  making use of the target_clones dispatching code in multiple_targets.cc.
  (This fixes PR target/118313 for aarch64 and riscv).
- Splitting target_clones pass in two, an early and late pass, where the early
  pass handles cases where multiple declarations are used to define a version,
  and the late pass handling target semantics targets, and cases where a FMV
  set is defined by a single target_clones decl.
- Changing the logic in add_candidates and resolve_address of overloaded
  function to prevent resolution of any version except a default version.
  (thus making the default version determine scope and signature of the
  versioned function set).
- Adding logic for dispatching a lone annotated default version in
  multiple_targets.cc
  - As as annotated default version gets mangled an alias is created from the
    dispatched symbol to the default version as no ifunc resolution is required
    in this case. (ie. an alias from `_Z3foov` to `_Z3foov.default`)
- Adding logic to `symbol_table::remove_unreachable_nodes` and analyze_functions
  that a reference to the default function version also implies a possible
  reference to the other versions (so they shouldnt be deleted and do need to
  be analyzed).

gcc/ChangeLog:

	PR target/118313
	* cgraph.cc (delete_function_version): Made public static member of
	cgraph_node.
	* cgraph.h (delete_function_version): Ditto.
	* cgraphunit.cc (analyze_functions): Add logic for target version
	dependencies.
	* ipa.cc (symbol_table::remove_unreachable_nodes): Ditto.
	* multiple_target.cc (create_dispatcher_calls): Change to support
	target version semantics.
	(ipa_target_clone): Change to dispatch all function sets in
	target_version semantics, and to have early and late pass.
	(expand_target_clones): Add logic for cases of target_clones with no
	defaults.
	(is_simple_target_clones_case): New function.
	(class pass_target_clone): New parameter for early or late pass.
	* config/aarch64/aarch64.cc: (aarch64_get_function_versions_dispatcher):
	Refactor with the assumption that the DECL node will be default.
	* config/riscv/riscv.cc: (riscv_get_function_versions_dispatcher):
	Refactor with the assumption that the DECL node will be default.
	* passes.def: Split target_clones pass into early and late version.

gcc/cp/ChangeLog:

	PR target/118313
	* call.cc (add_candidates): Change to not resolve non-default versions
	in target_version semantics.
	* class.cc (resolve_address_of_overloaded_function): Ditto.
	* cp-gimplify.cc (cp_genericize_r): Change logic to not apply for
	target_version semantics.
	* decl.cc (maybe_mark_function_versioned): Remove static.
	* cp-tree.h (maybe_mark_function_versioned): New function.
	* decl2.cc (cplus_decl_attributes ): Change to mark and therefore
	mangle all target_version decls in target_version semantics.
	* typeck.cc (cp_build_function_call_vec): Add error for calling
	unresolvable non-default node in target_version semantics.

gcc/testsuite/ChangeLog:

	* g++.target/aarch64/mv-1.C: Change for target_version semantics.
	* g++.target/aarch64/mv-symbols2.C: Ditto.
	* g++.target/aarch64/mv-symbols3.C: Ditto.
	* g++.target/aarch64/mv-symbols4.C: Ditto.
	* g++.target/aarch64/mv-symbols5.C: Ditto.
	* g++.target/aarch64/mvc-symbols3.C: Ditto.
	* g++.target/riscv/mv-symbols2.C: Ditto.
	* g++.target/riscv/mv-symbols3.C: Ditto.
	* g++.target/riscv/mv-symbols4.C: Ditto.
	* g++.target/riscv/mv-symbols5.C: Ditto.
	* g++.target/riscv/mvc-symbols3.C: Ditto.
	* g++.target/aarch64/mv-symbols10.C: New test.
	* g++.target/aarch64/mv-symbols11.C: New test.
	* g++.target/aarch64/mv-symbols12.C: New test.
	* g++.target/aarch64/mv-symbols13.C: New test.
	* g++.target/aarch64/mv-symbols6.C: New test.
	* g++.target/aarch64/mv-symbols7.C: New test.
	* g++.target/aarch64/mv-symbols8.C: New test.
	* g++.target/aarch64/mv-symbols9.C: New test.
2025-09-23 09:47:43 +00:00
Alfie Richards 3cc894e7c3 fmv: c++: Add check_target_clone hook for filtering target_clone versions.
This patch introduces the TARGET_CHECK_TARGET_CLONE_VERSION hook
which is used to determine if a target_clones version string parses.

The hook has a flag to enable emitting diagnostics.

This is as specified in the Arm C Language Extension. The purpose of this
is to be able to ignore invalid versions to allow some portability of code
using target_clones attributes.

Currently this is only properly implemented for the Aarch64 backend.

For riscv which is the only other backend which uses target_version
semantics a partial implementation is present, where this hook is used
to check parsing, in which errors will be emitted on a failed parse
rather than warnings. A refactor of the riscv parsing logic would be
required to enable this functionality fully.

This fixes PR 118339 where parse failures could cause ICE in Aarch64.

gcc/ChangeLog:

	PR target/118339
	* target.def: Add check_target_clone_version hook.
	* tree.cc (get_clone_attr_versions): Add filter argument.
	(get_clone_versions): Add filter argument.
	* tree.h (get_clone_attr_versions): Add filter.
	(get_clone_versions): Add filter argument.
	* config/aarch64/aarch64.cc (aarch64_check_target_clone_version):
	New function
	(TARGET_CHECK_TARGET_CLONE_VERSION): New define.
	* config/riscv/riscv.cc (riscv_check_target_clone_version):
	New function.
	(TARGET_CHECK_TARGET_CLONE_VERSION): New define.
	* doc/tm.texi: Regenerated.
	* doc/tm.texi.in: Add documentation for new hook.
	* hooks.h (hook_stringslice_locationtptr_true): New function.
	* hooks.cc (hook_stringslice_locationtptr_true): New function.

gcc/c-family/ChangeLog:

	* c-attribs.cc (handle_target_clones_attribute): Update to use new hook.
2025-09-23 09:47:43 +00:00
Alfie Richards 2564e45b3b riscv: Refactor riscv target parsing to take string_slice.
This is a quick refactor of the riscv target processing code
to take a string_slice rather than a decl.

The reason for this is to enable it to work with target_clones
where merging logic requires reasoning about each version string
individually in the front end.

This refactor primarily serves just to get this working. Ideally the
logic here would be further refactored as currently there is no way to
check if a parse fails or not without emitting an error.
This makes things difficult for later patches which intends to emit a
warning and ignoring unrecognised/not parsed target_clone values rather
than erroring which can't currently be achieved with the current riscv
code.

gcc/ChangeLog:

	* config/riscv/riscv-protos.h (riscv_process_target_version_str): New function..
	* config/riscv/riscv-target-attr.cc (riscv_process_target_attr): Refactor to take
	string_slice.
	(riscv_process_target_version_str): New function.
	* config/riscv/riscv.cc (parse_features_for_version): Refactor to take
	string_slice.
	(riscv_compare_version_priority): Ditto.
	(dispatch_function_versions): Change to pass location.
2025-09-23 09:47:43 +00:00
Alfie Richards b500cd2634 x86: fmv: Refactor FMV name mangling.
This patch is an overhaul of how FMV name mangling works. Previously
mangling logic was duplicated in several places across both target
specific and independent code. This patch changes this such that all
mangling is done in targetm.mangle_decl_assembler_name (including for the
dispatched symbol and dispatcher resolver).

Adds the assembler_name member to cgraph_function_version_info to store
the base assembler name of the function set, before FMV mangling.

This allows for the removing of previous hacks, such as where the default
mangled decl's assembler name was unmangled to then remangle all versions
and the resolver and dispatched symbol.

This introduces a change (shown in test changes) for the assembler name of the
dispatched symbol for a x86 versioned function set. Previously it used the
function name mangled twice. This was hard to reproduce without hacks I
wasn't comfortable with. Therefore, the mangling is changed to instead append
".ifunc" which matches clang's behavior.

This change also refactors expand_target_clone using
targetm.mangle_decl_assembler_name for mangling and get_clone_versions.
It is modified such that if the target_clone is in a FMV structure
the ordering is preserved once expanded. This is used later for ACLE semantics
and target_clone/target_version mixing.

gcc/ChangeLog:

	* attribs.cc (make_dispatcher_decl): Move duplicated cgraph logic into
	this function and change to use targetm.mangle_decl_assembler_name for
	mangling.
	* cgraph.cc (cgraph_node::insert_new_function_version): Record
	assembler_name.
	* cgraph.h (struct cgraph_function_version_info): Add assembler_name.
	(struct cgraph_node): Add dispatcher_resolver_function and
	is_target_clone.
	* config/aarch64/aarch64.cc (aarch64_parse_fmv_features): Change to
	support string_slice.
	(aarch64_process_target_version_attr): Ditto.
	(get_feature_mask_for_version): Ditto.
	(aarch64_mangle_decl_assembler_name): Add logic for mangling dispatched
	symbol and resolver.
	(get_suffixed_assembler_name): Removed.
	(make_resolver_func): Refactor to use
	aarch64_mangle_decl_assembler_name for mangling.
	(aarch64_generate_version_dispatcher_body): Remove remangling.
	(aarch64_get_function_versions_dispatcher): Refactor to remove
	duplicated cgraph logic.
	* config/i386/i386-features.cc
	(ix86_mangle_function_version_assembler_name): Refactor to use
	clone_identifier and to mangle default.
	(ix86_mangle_decl_assembler_name): Add logic for mangling dispatched
	symbol and resolver.
	(ix86_get_function_versions_dispatcher): Remove duplicated cgraph
	logic.
	(make_resolver_func): Refactor to use ix86_mangle_decl_assembler_name
	for mangling.
	* config/riscv/riscv.cc (riscv_mangle_decl_assembler_name): Add logic
	for FMV mangling.
	(get_suffixed_assembler_name): Removed.
	(make_resolver_func): Refactor to use riscv_mangle_decl_assembler_name
	for mangling.
	(riscv_generate_version_dispatcher_body): Remove unnecessary remangling.
	(riscv_get_function_versions_dispatcher): Remove duplicated cgraph
	logic.
	* config/rs6000/rs6000.cc (rs6000_mangle_decl_assembler_name): New
	function.
	(rs6000_get_function_versions_dispatcher): Remove duplicated cgraph
	logic.
	(make_resolver_func): Refactor to use rs6000_mangle_decl_assembler_name
	for mangling.
	(rs6000_mangle_function_version_assembler_name): New function.
	* multiple_target.cc (create_dispatcher_calls): Remove mangling code.
	(get_attr_str): Removed.
	(separate_attrs): Ditto.
	(is_valid_asm_symbol): Removed.
	(create_new_asm_name): Ditto.
	(expand_target_clones): Refactor to use
	targetm.mangle_decl_assembler_name for mangling and be more general.
	* tree.cc (get_target_clone_attr_len): Removed.
	* tree.h (get_target_clone_attr_len): Removed.

gcc/cp/ChangeLog:

	* decl.cc (maybe_mark_function_versioned): Change to insert function version
	and therefore record assembler name.

gcc/testsuite/ChangeLog:

	* g++.target/i386/mv-symbols1.C: Update x86 FMV mangling.
	* g++.target/i386/mv-symbols3.C: Ditto.
	* g++.target/i386/mv-symbols4.C: Ditto.
	* g++.target/i386/mv-symbols5.C: Ditto.
2025-09-23 09:47:43 +00:00
Alfie Richards c965a760e0 cgraph: Add clone_identifier function.
This is similar to clone_function_name and its siblings but takes an
identifier tree node rather than a function declaration.

This is to be used in conjunction with the identifier node stored in
cgraph_function_version_info::assembler_name to mangle FMV functions in
later patches.

gcc/ChangeLog:

	* cgraph.h (clone_identifier): New function.
	* cgraphclones.cc (clone_identifier): New function.
	(clone_function_name): Refactored to use clone_identifier.
	(is_valid_asm_symbol): New helper function.
2025-09-23 09:47:42 +00:00
Jonathan Wakely 1953939243 libstdc++: Remove unwanted PACKAGE macros from c++config.h [PR79147]
Autoconf insists on adding macros like PACKAGE_NAME and
PACKAGE_BUG_TARNAME to config.h but those are useless for libstdc++
because it's not a complete package, just a sub-directory of gcc, and we
never use any of those strings in our sources.

Since we include the generated config.h in our installed c++config.h
header, those useless macros are exposed to users. We do transform them
to use the reserved _GLIBCXX_ prefix, but they're still just useless
noise in the installed header.

I don't know any way to get autoconf to not add them to config.h but
this change comments them out so they're not defined when users include
our headers.

Although not really important now that the macro isn't being defined,
this change also avoids the double substitution for PACKAGE_VERSION
which was resulting in _GLIBCXX_PACKAGE__GLIBCXX_VERSION.

libstdc++-v3/ChangeLog:

	PR libstdc++/79147
	* include/Makefile.am (c++config.h): Adjust sed command to
	comment out all PACKAGE_XXX macros and to avoid adjusting
	PACKAGE_VERSION twice.
	* include/Makefile.in: Regenerate.
2025-09-23 10:17:09 +01:00
Jonathan Wakely 9959c4db9e contrib: Fix typo in comment in libstdc++ script
contrib/ChangeLog:

	* unicode/gen_libstdcxx_unicode_data.py: Fix comment type.
2025-09-23 10:17:08 +01:00
Tomasz Kamiński c61535ff3d libstdc++: Remove leftover __formatter_chrono base classes.
This patch removes the __formatter_chrono<_CharT> base class from the
formatters for utc_time, gps_time, and tai_time. These formatters
are using the __formatter_duration<_CharT> member only.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (formatter<chrono::utc_time, _CharT>):
	(formatter<chrono::gps_time<_Duration>, _CharT>)
	(formatter<chrono::tai_time<_Duration>, _CharT): Remove
	__formatter_chrono base class.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-23 10:44:13 +02:00
liuhongt 753e5c8a3b Disable vect unroll for znver2/Znver1.
Since it regressed SPEC performance(Refer to PR121994), I guess
it's related to register pressure and can be tuned by adjusting
reduc_lat_mult_thr. I don't have Zen2 machine, so for simplity, I'll
just disable unroll in vectorizer for Zen2.

Also adjust count number for {AVX256,AVX512}_SPLIT_REGS.

gcc/ChangeLog:

	PR target/121994
	* config/i386/x86-tune-costs.h (znver2_cost): Set
	vect_unroll_limit to 1.
	(znver1_cost): Ditto.
	* config/i386/i386.cc (ix86_vector_costs::add_stmt_cost):
	Adjust count number for	{AVX256,AVX512}_SPLIT_REGS.
2025-09-23 00:31:52 -07:00
GCC Administrator 5a43bcc730 Daily bump. 2025-09-23 00:20:06 +00:00
Peter Bergner 4275518a06 RISC-V: Add missing define_insn_reservation to tt-ascalon-d8.md [PR121982]
The tt-ascalon-d8's pipeline description has reservations for 16-bit, 32-bit
and 64-bit vector integer divides, but was missing a reservation for 8-bit
vector integer divides, leading to an ICE.  Add the missing reservation.

2025-09-22  Peter Bergner  <bergner@tenstorrent.com>

gcc/
	PR target/121982
	* config/riscv/tt-ascalon-d8.md (tt_ascalon_d8_vec_idiv_byte): New
	define_insn_reservation.

gcc/testsuite/
	PR target/121982
	* gcc.target/riscv/pr121982.c: New test.

Signed-off-by: Peter Bergner <bergner@tenstorrent.com>
2025-09-22 18:30:20 -05:00
Nathaniel Shead cc79849cc8 c++: Fix canonical type for lambda pack captures [PR122015]
comp_template_parms_position uses whether a TEMPLATE_TYPE_PARM is a pack
to determine equivalency.  This in turn affects whether
canonical_type_parameter finds a pre-existing auto type as equivalent.

When generating the 'auto...' type for a lambda pack capture, we only
mark it as a pack after generating the node (and calculating its
canonical); this means that later when comparing a version streamed in
from a module we think that two equivalent types have different
TYPE_CANONICAL, because the latter already had
TEMPLATE_PARM_PARAMETER_PACK set before calculating its canonical.

This patch fixes this by using a new 'make_auto_pack' function to ensure
that packness is set before the canonical is looked up.

	PR c++/122015

gcc/cp/ChangeLog:

	* cp-tree.h (make_auto_pack): Declare.
	* lambda.cc (lambda_capture_field_type): Use make_auto_pack to
	ensure TYPE_CANONICAL is set correctly.
	* pt.cc (make_auto_pack): New function.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/lambda-11.h: New test.
	* g++.dg/modules/lambda-11_a.H: New test.
	* g++.dg/modules/lambda-11_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-09-23 09:25:00 +10:00
Jonathan Wakely 09f9e63593 contrib: Add DerivedGeneralCategory.txt to comment in libstdc++ script
contrib/ChangeLog:

	* unicode/gen_libstdcxx_unicode_data.py: Update comment at the
	top of the file to mention DerivedGeneralCategory.txt
	prerequisite.
2025-09-22 18:19:32 +01:00
Jonathan Wakely 67d7046067 top-level: Add .editorconfig file
This config file sets default formatting behaviour for a large number
of common editors, see https://editorconfig.org

It also ensures that https://forge.sourceware.org formats GCC code
correctly, because it defaults to tab_width=4 but will respect a
.editorconfig file if present in the repo.

ChangeLog:

	* .editorconfig: New file.
2025-09-22 18:19:26 +01:00
Andrew Pinski 8a6598f4a2 fab/gimple-fold: Move __builtin_constant_p folding to gimple-fold [PR121762]
This is the first patch in removing fold_all_builtins pass.
We want to fold __builtin_constant_p into 0 if we know the argument can't be
a constant. So currently that is done in fab pass (though ranger handles it now too).
Instead of having fab do it we can check PROP_last_full_fold if set and set it
to 0 instead.

Note for -Og, fab was the only place which did this conversion, so we need to
set PROP_last_full_fold for it; later on fab will be removed and isel will do
it instead but that is for another day.

Also instead of going through fold_call_stmt to call fold_builtin_constant_p,
fold_builtin_constant_p is called directly from gimple_fold_builtin_constant_p.
This should speed up the compiling slight :).

Note fab was originally added to do this transformation during the development
of the ssa branch.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/121762
gcc/ChangeLog:

	* builtins.cc (fold_builtin_constant_p): Make non-static.
	* builtins.h (fold_builtin_constant_p): New declaration.
	* gimple-fold.cc (gimple_fold_builtin_constant_p): New function.
	(gimple_fold_builtin): Call gimple_fold_builtin_constant_p
	for BUILT_IN_CONSTANT_P.
	* tree-ssa-ccp.cc (pass_fold_builtins::execute): Set PROP_last_full_fold
	on curr_properties. Remove handling of BUILT_IN_CONSTANT_P.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-22 08:44:40 -07:00
Tomasz Kamiński dc38eaf935 libstdc++: Rework handling of ISO week calendar and week index formatting.
The handling of ISO week-calendar year specifiers (%G, %g) and ISO week
number (%V) was merged into a single _M_g_G_V function, as the latter
requires ISO year value, computed by the former.

The values for %U and %W, which are based on the number of days since the
first Sunday and Monday of the year respectively, are now expressed as an
offset from the existing _M_day_of_year field. This reduces redundant
computation. The required flags were also updated to only need _DayOfYear
and _Weekday.

The _M_g_G_V function uses _M_day_of_year to compute __idoy, the day of the
year for the nearest Thursday. This value is used to determine if the ISO
year is the previous year (__idoy <= 0), the current year (__idoy <= 365/366),
next year (__idoy <= 730), or later year. This avoids an expensive conversion
from local_days to year_month_day in most cases. If the ISO calendar year
is current year, the __idoy value is reused for weekday index computation.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h(__formatter_chrono::_M_parse): Update
	needed flags for %g, %G, %V, %U, %W.
	(__formatter_chrono::_M_format_to): Change how %V is handled.
	(__formatter_chrono::_M_g_G): Merged into _M_g_G_V.
	(__formatter_chrono::_M_g_G_V): Reworked from _M_g_G.
	(__formatter_chrono::_M_U_V_W): Changed into _M_U_V.
	(__formatter_chrono::_M_U_W): Reworked implementation.
	* testsuite/std/time/year_month_day/io.cc: New tests.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-22 16:20:02 +02:00
Tomasz Kamiński f8681ec8d0 libstdc++: Move start_lifetime_as functions to bits/stl_construct.h [PR106658]
This allows inplace_vector to use these functions without including the entire
<memory> header.

Preprocessor checks are changed to use __glibcxx macros, so new functions are
available outside memory header, that exports __cpp_lib macros.

	PR libstdc++/106658

libstdc++-v3/ChangeLog:

	* include/bits/stl_construct.h (std::start_lifetime_as_array)
	(std::start_lifetime_as): Moved from std/memory, with update
	to guard macros.
	* include/std/memory (std::start_lifetime_as_array)
	(std::start_lifetime_as): Moved to bits/stl_construct.h.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-22 15:59:21 +02:00
Gerald Pfeifer 915803d88b doc: Drop broken reference to modindex in libgdiagnostics
gcc:
	* doc/libgdiagnostics/index.rst: Drop broken reference to
	`modindex`.
2025-09-22 15:20:45 +02:00
Pan Li 7a5da9ab53 Widen-Mul: Fix mis-compile for build_and_insert_cast refinement [PR122021]
The previous refinement in build_and_insert_cast will convert 2
cast into one, aka:

uint16_t _3;

From:
int16_t _4 = (uint16_t)_3; // no-extend
int32_t _5 = (int32_t)_4   // sign-extend 16 => 32

To:
int32_t _5 = (int32_t)_3;  // zero-extend 16 => 32

That will have a problem for sign-extend, the highest bits may be all 1s
but will be loss after convert to zero-extend.  Thus, there will be more
cases if the convert has different types.  Case 1 as above and Case 2,
3, and 4 as following.

Case 2:
  int16_t _3;

  From:
  uint32_t _4 = (uint32_t)_3; // zero-extend 16 => 32
  uint64_t _5 = (uint64_t)_4; // zero-extend 32 => 64

  To:
  uint64_t _5 = (uint32_t)_3; // zero-extend 16 => 64

Case 3:
  uint8_t _3;

  From:
  uint16_t _4 = (uint16_t)_3; // zero-extend 8 => 16
  int32_t _5 = (int32_t)_4;   // zero-extend 16 => 32

  To:
  int32_t _5 = (int32_t)_3;   // zero-extend 8 => 32

Case 4:
  int8_t _3;

  From:
  int16_t _4 = (int16_t)_3;   // sign-extend 8 => 16
  uint32_t _5 = (uint32_t)_4; // zero-extend 16 => 32
  To:
  uint32_t _5 = (uint32_t)_3; // zero-extend 8 => 32

Then, we can see, there will be mis-compile if and only if there is
a cast from small to big size with sign extend.  Thus, restrict the
check and stop prop if there is sign extend cast.

The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. The x86 bootstrap tests.
3. The x86 fully regression tests.

	PR middle-end/122021

gcc/ChangeLog:

	* tree-ssa-math-opts.cc (build_and_insert_cast): Add sign-extend
	check before prop.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr122021-0.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-22 20:59:27 +08:00
Richard Biener 52b53cfb53 tree-optimization/122016 - PRE insertion breaks abnormal coalescing
When PRE asks VN to simplify a NARY but not insert, that bypasses
the abnormal guard in maybe_push_res_to_seq and we blindly accept
new uses of abnormals.  The following fixes this.

	PR tree-optimization/122016
	* tree-ssa-sccvn.cc (vn_nary_simplify): Do not use the
	simplified expression when it references abnormals.

	* gcc.dg/torture/pr122016.c: New testcase.
2025-09-22 11:42:28 +02:00
Richard Biener 32a8a1c26b tree-optimization/122023 - rotate pattern with reductions
The following disables the use of rotate patterns with reductions
since it breaks then single rotate SSA use-def chain constraints.

	PR tree-optimization/122023
	* tree-vect-patterns.cc (vect_recog_rotate_pattern): Disable
	for rotates.

	* gcc.dg/vect/pr122023.c: New testcase.
2025-09-22 11:42:28 +02:00
Eric Botcazou 7e29e1a0a1 Ada: Fix internal error on use clause present in generic formal part
This is a regression present on the mainline and 15 branch: the compiler
aborts on a use clause present in the formal part of a generic unit because
of an oversight in the new inference code for generic actual parameters.

The fix also adds a missing test to Analyze_Dimension_Array_Aggregate.

gcc/ada/
	PR ada/121968
	* sem_ch12.adb (Associations.Find_Assoc): Add guard for clauses.
	* sem_dim.adb (Analyze_Dimension_Array_Aggregate): Add test for
	N_Iterated_Component_Association nodes.
2025-09-22 11:13:58 +02:00
Dimitar Dimitrov 2948d12f92 pru: Reject bit-fields for TI ABI
TI ABI has non-conventional requirements for bit-fields, which cannot
be implemented with the current target hooks in GCC.

Target hooks are focused on packing and alignment.  But PRU uses packed
structs by default, and has 1 byte alignment for all types.  As an
example, this makes it difficult to implement the TI ABI requirement
for the following struct to be sized to 4 bytes, per the bit-field type:

  struct S { int i : 1; }

Instead of introducing new target hooks and making risky changes to
common GCC code, simply declare bit-fields as not supported in TI ABI
mode.

PRU is a baremetal target.  It has neither support for interrupts nor an
RTOS.  Hence ABI compatibility is not that critical.  I have not seen
any projects which rely on ABI compatibility in order to mix object
files from GCC and the TI proprietary compiler.

The target-specific pass to scan for TI ABI compatibility was rewritten
as an IPA pass.  This allowed scanning not only of function bodies, but
also global variable declarations.  Diagnostic locations should now be
more accurate.  Thus some test cases had to be adjusted.

	PR target/116205

gcc/ChangeLog:

	* config/pru/pru-passes.cc (class pass_pru_tiabi_check): Make
	this an IPA pass.
	(chkp_type_has_function_pointer): Remove.
	(check_type_tiabi_compatibility): New function.
	(chk_function_decl): Rename.
	(check_function_decl): Simplify.
	(check_op_callback): Rework to use
	check_type_tiabi_compatibility.
	(pass_pru_tiabi_check::execute): Rework to scan all symbols and
	gimple contents of all defined functions.
	* config/pru/pru-passes.def (INSERT_PASS_AFTER): Move after
	pass_ipa_auto_profile_offline.
	* config/pru/pru-protos.h (make_pru_tiabi_check): New
	declaration to mark as IPA pass.
	(make_pru_minrt_check): Specify it is making a gimple pass.
	* doc/invoke.texi: Document that bit-fields are now rejected for
	TI ABI.

gcc/testsuite/ChangeLog:

	* gcc.target/pru/mabi-ti-1.c: Adjust diagnostic location.
	* gcc.target/pru/mabi-ti-2.c: Ditto.
	* gcc.target/pru/mabi-ti-3.c: Ditto.
	* gcc.target/pru/mabi-ti-5.c: Ditto.
	* gcc.target/pru/mabi-ti-6.c: Ditto.
	* gcc.target/pru/mabi-ti-7.c: Adjust diagnostic locations and
	add global variables for checking.
	* gcc.target/pru/mabi-ti-11.c: New test.
	* gcc.target/pru/mabi-ti-12.c: New test.
	* gcc.target/pru/mabi-ti-8.c: New test.
	* gcc.target/pru/mabi-ti-9.c: New test.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2025-09-22 10:02:32 +03:00
Paul Thomas 5e6937b9ab Fortran: Fix error recovery after missing END BLOCK [PR103508]
2025-09-22  Steve Kargl  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/103508
	* decl.cc (gfc_match_end): Remove only the current partial
	rather than removing the entire sibling chain.

gcc/testsuite/
	PR fortran/103508
	* gfortran.dg/pr103508.f90: New test.
2025-09-22 07:33:07 +01:00
GCC Administrator 0874adaf69 Daily bump. 2025-09-22 00:18:39 +00:00
Andrew Pinski c6781f5558 fab: Remove forced label check from optimize_unreachable
Since optimize_unreachable does not directly remove the bb, we can still remove
the condition that goes to a block containing a forced label. This is a small cleanup
from the original patch which added optimize_unreachable.

The review of the original patch missed that the bb was not being removed by the pass
but later on by cleanupcfg; https://gcc.gnu.org/pipermail/gcc-patches/2012-July/343239.html.
Which is why this is allowed to be done.

I added another testcase to check that the `if` is removed too.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-ccp.cc (optimize_unreachable): Don't check for forced labels.

gcc/testsuite/ChangeLog:

	* gcc.dg/builtin-unreachable-7.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-21 14:38:25 -07:00
Harald Anlauf 518ec01b36 Fortran: fix frontend memory leaks for ALLOCATE with SOURCE [PR109010]
When running under valgrind the Fortran frontend showed several leaks
involving __gmp_default_allocate for simple code such as

  program p
    real, pointer :: x(:)
    allocate (x, source = reshape ([1.], [1]))
  end

as not all used components of the structure gfc_code were freed when a
statement was freed.  Just do so.

	PR fortran/109010

gcc/fortran/ChangeLog:

	* st.cc (gfc_free_statement): Also free components expr3 and expr4.
2025-09-21 21:54:44 +02:00
Jan Hubicka 058b2ef951 Update calls_comdat_local in cgraph_node::create_version_clone
This patches fixes ICE when ipa-split is run from ipa-profile.  In normal
computation we recompute the flag elsewhere, but it is supposed to be kept
up-to-date by passes possibly modifying it.

gcc/ChangeLog:

	* cgraphclones.cc (cgraph_node::create_version_clone): Recompute
	calls_comdat_local
2025-09-21 19:55:16 +02:00
Jan Hubicka d74aec06b1 One extra special case for AFDO0
This patch makes inliner and ipa-cp to consider optimization interesting even
in scenarios where aufdo countis 0, but scaleis high enough to make optimization
worthwhile.

gcc/ChangeLog:

	* cgraph.cc (cgraph_edge::maybe_hot_p): For AFDO profiles force
	count to be non-zero.
2025-09-21 19:55:16 +02:00
Mark Wielaard 5cef5f2bf8 Regenerate gcc/m2/lang.opt.urls
Autogenerate for -fmem-report and -ftime-report.

Fixes: 273b53effb ("PR modula2/121856: New wideset implementation")

gcc/m2/ChangeLog:

	* lang.opt.urls: Regenerate.
2025-09-21 18:57:27 +02:00
Jan Hubicka 9766f99e6e Increase auto-fdo profile scaling
Increase scaling factor for auto-fdo profiles.  I origianlly used
n_bits/2 which is also used by local guessing algorithm.  For local guessing
algorithm the main factor is to prevent inliner scaling up the profile till
overflow.

With sane IPA profile large scaling up should essentially never happen. Inliner and
ipa-cp only duplicates code and should only scale down. ipa-icf and tail merging merges
code but not very large number of code paths.
In practice scaling up still happens when profile is inconsisent, so this use
n_bits-10, which is 50 currently.  The main advantage of this is to reduce chances
things drop to 0 and we hit the various special cases for 0 auto-FDO profile.

gcc/ChangeLog:

	* auto-profile.cc (autofdo_source_profile::read): Scale profile up to
	profile_count::n_bits - 10.
2025-09-21 16:53:22 +02:00
Thomas Koenig 0f28eb8ab9 Fix test case and add errors for when -fexternal-blas64 makse no sense.
-fexternal-blas64 requires front-end optimization to be turned on.
This patch issues a hard error if this is not the case, and also issues
an error on not-64 bit systems, where specifying it would make no sense,
and lead to errors.  Finally, this makes sure that the test is only performed
on 64-bit systems.

I tried creating test cases for the hard errors for the wrong option
combinations, but didn't succeed; see the thread on the gcc mailing
list on that topic.  These can always be added afterwards.

gcc/fortran/ChangeLog:

	PR fortran/121161
	* invoke.texi: Mention that -ffrontend-optimize is required
	for -fexternal-blas64.
	* options.cc (gfc_post_options): Fatal error if -fexternal-blas64
	is specified without -ffrontend-optimize.
	* trans-types.cc (gfc_init_kinds): Fatal error if -fexternal-blas64
	is specified on a system which does not have 64-bit ptrdiff_t.

gcc/testsuite/ChangeLog:

	PR fortran/121161
	* gfortran.dg/matmul_blas_3.f90: Add effective target lp64.
2025-09-21 14:48:29 +02:00
Jan Hubicka c4bf7dcade Make inliner more careful about profile inconsistencies
This patch makes inliner to not subtract inlined function profile from the
offline copy in cases where profile is clearly not consistent.  As a result we
do not drop the offline version to likely never executed profile.  This helps
in cases the profile got lost, i.e. by comdat function merging and also for
auto-fdo.

gcc/ChangeLog:

	* ipa-inline-transform.cc (clone_inlined_nodes): Add KEEP_OFFLINE_COPY
	parameter.
	(inline_call): Sanity check profile and if it is clearly broken do
	not subtract profile from original function.
	* ipa-inline.cc (recursive_inlining): Update.
	* ipa-inline.h (clone_inlined_nodes): Update.
2025-09-21 12:28:45 +02:00
Harald Anlauf 749af11149 Fortran: fix issues with rank-2 deferred-length character arrays [PR108581]
PR fortran/108581

gcc/fortran/ChangeLog:

	* trans-array.cc (gfc_conv_expr_descriptor): Take the dynamic
	string length into account when deriving the dataptr offset for
	a deferred-length character array.

gcc/testsuite/ChangeLog:

	* gfortran.dg/deferred_character_39.f90: New test.
2025-09-21 10:33:27 +02:00
GCC Administrator ee4bbfe627 Daily bump. 2025-09-21 00:18:03 +00:00
Gaius Mulley ec9a23f1c2 PR modula2/122009: ODR fixes and prototype correction.
This small patch fixes -Wodr warnings and also corrects a prototype.

gcc/m2/ChangeLog:

	PR modula2/122009
	* gm2-compiler/M2GenGCC.mod (FromM2WIDESETImport): Assign
	sym to NulSym.
	(CodeMakeAdr): Remove fourth parameter to BuildLogicalOrAddress.
	(FoldMakeAdr): Ditto.
	* gm2-compiler/M2Quads.mod (BuildAssignmentBoolean): Remove
	unused parameter checkTypes.
	(doBuildAssignment): Remove checkTypes parameter when calling
	BuildAssignmentBoolean.
	* gm2-gcc/m2expr.def (BuildLogicalOrAddress): Remove
	needconvert parameter.
	* gm2-gcc/m2statement.def (IfExprJump): Change label type
	to CharStar.
	* gm2-gcc/m2type.cc (m2type_BuildEnumerator): Remove const.
	* gm2-gcc/m2type.h (m2type_BuildEnumerator): Ditto.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-09-20 19:40:32 +01:00
Patrick Palka 396e911884 c++: find_template_parameters and NTTPs [PR121981]
Here the normal form of the two immediately-declared D<<placeholder>, V>
constraints is the same, so we rightfully share the normal form between
them.  We first compute the normal form from the context of auto deduction
for W in which case the placeholder has level 2 where the set of
in-scope template parameters has depth 2 (a dummy level is added from
normalize_placeholder_type_constraints).

Naturally the atomic constraint only depends on the template parameter
V of depth 1 index 0.  The depth 2 of current_template_parms however
means that find_template_parameters when it sees V within the atomic
constraint will recurse into its TREE_TYPE, an auto of level 2, and mark
the atomic constraint as also depending on the template parameter of
depth 2 index 0, which is clearly wrong.  Later during constraint
checking for B we ICE within the satisfaction cache since we lack two
levels of template arguments supposedly needed by the cached atomic
constraint.

I think when find_template_parameters sees an NTTP, it doesn't need to
walk its TREE_TYPE because NTTP substitution is done obliviously with
respect to its type -- only the corresponding NTTP argument matters,
not other template arguments possibly used within its type.  This is
most clearly true for (unconstrained) auto NTTPs as in the testcase, but
also true for other NTTPs.  Doing so fixes the testcase because we no
longer record any depth 2 when walking V within the atomic constraint.

	PR c++/121981

gcc/cp/ChangeLog:

	* pt.cc (any_template_parm_r) <case TEMPLATE_TYPE_PARM>:
	Don't walk TREE_TYPE.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-placeholder15.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-09-20 10:45:22 -04:00
Eczbek fa71e855ab c++: Fix lambdas with variadic parameters and static specifier [PR119048]
PR c++/119048

gcc/cp/ChangeLog:

	* lambda.cc (compare_lambda_sig): Only skip first parameter for
	object members.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp23/static-operator-call8.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-09-20 15:09:56 +01:00
Paul Thomas 8ded56a52a Fortran: Fix regtest failure in pdt_48.f03. [PR83746]
2025-09-20  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/83746
	* trans-decl.cc (gfc_trans_deferred_vars): If a procedure with
	an non-allocatable, non-pointer explicit PDT result has no
	default initializer, the parameterized components should be
	allocated.
2025-09-20 14:25:47 +01:00
Jan Hubicka 9ee937b2f9 Add --param max-devirt-targets
Currently we speculatively devirtualize using static analysis (with no profile
feedback) only when there is one possible target found.  With profile feedback
we support multiple targets which seems useful in some scenarios.

This patch adds --param max-devirt-targets which enables devirtualization up to
given number of targets and defaults it to 3.  This happens i.e. in spec2017
omnetpp, though the devirtualizaton is later undone by inliner since it is not
considered useful.  The patch still seems to improve omnetpp by 2% in some
setups.

Other advantage of the patch is that the multi-target devirtualizatoin gets
tested without profile feedback so we more likely notice problems with it.

gcc/ChangeLog:

	* doc/invoke.texi (--param max-devirt-targets) Document.
	* ipa-devirt.cc (ipa_devirt): Implement muti-target
	devirtualization.
	* params.opt (max-devirt-targets): New parameter.

gcc/testsuite/ChangeLog:

	* g++.dg/ipa/devirt-2.C: Update template.
	* g++.dg/ipa/devirt-42.C: Update template.
	* g++.dg/lto/devirt-2_0.C: Update template.
2025-09-20 15:12:26 +02:00
Joseph Myers 3eca9b5119 c: Implement C2y N3481 constraint against lvalue conversion with incomplete type
C2y replaces undefined behavior for lvalue conversion of an lvalue
with incomplete, non-array type with a constraint violation.
Implement this in GCC, which means disallowing lvalue conversion of
qualified or atomic void for C2y.  (Unqualified, non-atomic void is
excluded from the definition of "lvalue".)

I'm not convinced that the resolution of C90 DR#106 (which said that
certain cases with qualified void were valid) was really justified
even based on the wording of C90; nevertheless, this patch takes the
conservative approach of only disallowing qualified void here for C2y.

The test for this change showed that attempting to access an _Atomic
void object produced an ICE-after-error attempting the atomic load
logic for such a type.  require_complete_type returning
error_mark_node prevents this ICE from occurring any more in C2y mode;
to avoid it in older modes, a check of COMPLETE_TYPE_P is added to
really_atomic_lvalue.  I didn't find any existing bug report in
Bugzilla for this issue.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c/
	* c-typeck.cc (really_atomic_lvalue): Return false for incomplete
	types.
	(convert_lvalue_to_rvalue): Call require_complete_type for
	qualified void for C2y.

gcc/testsuite/
	* gcc.dg/c11-atomic-6.c, gcc.dg/c23-incomplete-1.c,
	gcc.dg/c2y-incomplete-3.c: New tests.
2025-09-20 00:24:26 +00:00
GCC Administrator dcc231417f Daily bump. 2025-09-20 00:20:23 +00:00
Nathan Myers a77146f015 libstdc++: Add NTTP bind_front, -back, not_fn (P2714) [PR119744]
Add non-type template parameter function-object/-pointer argument
versions of bind_front, bind_back, and not_fn.

This introduces a new internal type _Bind_fn_t to carry the
template-argument function object when no arguments are bound,
used in both bind_front and bind_back. Otherwise they return
a lambda object that has captured the arguments.

There is no need to change libstdc++-v3/src/c++23/std.cc.in
because existing exports: "using std::bind_front;" etc. export
the new overloads.

libstdc++-v3/ChangeLog:
	PR libstdc++/119744
	* include/bits/version.def: Redefine __cpp_lib_bind_front etc.
	* include/bits/version.h: Ditto.
	* include/std/functional: Add new bind_front etc. overloads
	* testsuite/20_util/function_objects/bind_back/1.cc:
	Check plumbing better
	* testsuite/20_util/function_objects/bind_back/nttp.cc: New test.
	* testsuite/20_util/function_objects/bind_back/nttp_neg.cc: New test.
	* testsuite/20_util/function_objects/bind_front/1.cc:
	Check plumbing better
	* testsuite/20_util/function_objects/bind_front/nttp.cc: New test.
	* testsuite/20_util/function_objects/bind_front/nttp_neg.cc: New test.
	* testsuite/20_util/function_objects/not_fn/nttp.cc: New test.
	* testsuite/20_util/function_objects/not_fn/nttp_neg.cc: New test.
	* testsuite/20_util/headers/functional/synopsis.cc: New decls.
2025-09-19 17:31:31 -04:00
Jonathan Wakely dc78d691c5 libstdc++: Constrain operator<< for chrono::local_type
This was reported as LWG 4257 and moved to Tentatively Ready status.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h: Remove unused <iomanip> header.
	(operator<<): Constrain overload for chrono::local_time.
	* testsuite/std/time/clock/local/io.cc: Check constraints.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-09-19 21:12:15 +01:00
Alexandre Oliva 12992edaa9 [ira] avoid resetting ira_reg_equiv for function invariants
An aarch64 toolchain built with --enable-default-pie fails
gcc.target/aarch64/sme/nonlocal_goto_[123].c because the register
allocator ends up resetting equivalences, so it concludes it needs to
preserve a rematerializable function invariant across a call instead
of rematerializing it.

Restore the find_reg_equiv_invariant_const logic that was in place
before commit 55a2c3226a rewrote it and
added a (spurious?) requirement for non-function-invariants to retain
an equivalence when other PIC-related conditions didn't apply.  That
requirement seems either reversed or unnecessary.


for  gcc/ChangeLog

	* ira.cc (setup_reg_equiv): Retain function invariant
	equivalences.
2025-09-19 16:45:19 -03:00
Andrew Pinski 401d457c37 forwprop: change optimize_aggr_zeroprop and optimize_agr_copyprop to take stmt instead of gsi
As mentioned, optimize_aggr_zeroprop and optimize_agr_copyprop don't change the stmt
so they should take stmt instead of the iterator.

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

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_aggr_zeroprop): Take gimple*
	instead of iterator.
	(optimize_agr_copyprop): Likewise.
	(simplify_builtin_call): Update call to optimize_aggr_zeroprop.
	(pass_forwprop::execute): Update calls to optimize_aggr_zeroprop
	and optimize_agr_copyprop.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-19 11:50:13 -07:00
Andrew Pinski f2818238a5 forwprop: Don't loop on the stmt when optimize_aggr_zeroprop or optimize_agr_copyprop return true
Since now optimize_aggr_zeroprop and optimize_agr_copyprop work by forward walk to prop
the zero/aggregate and does not change the statement at hand, there is no reason to
repeat the loop if they do anything.  This will prevent problems like PR 121962 from
happening again as we will never loop.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_aggr_zeroprop_1): Change return type
	to void.
	(optimize_aggr_zeroprop): Likewise.
	(optimize_agr_copyprop_1): Likewise.
	(optimize_agr_copyprop_arg): Likewise.
	(optimize_agr_copyprop): Likewise.
	(simplify_builtin_call): Handle update of the return type
	of optimize_aggr_zeroprop.
	(pass_forwprop::execute): Likewise and optimize_agr_copyprop.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-19 11:47:33 -07:00
Michael Eager 7894c00982 [MicroBlaze][PR target/118280] Fix __atomic_test_and_set
Atomic support enhanced to fix existing atomic_compare_and_swapsi pattern
to handle side effects; new patterns atomic_fetch_op and atomic_test_and_set
added. As MicroBlaze has no QImode test/set instruction, use shift magic
to implement atomic_test_and_set.

	PR target/118280
gcc/
	* config/microblaze/iterators.md: New.
	* config/microblaze/microblaze-protos.h: Add
	microblaze_subword_address.
	* config/microblaze/microblaze.cc: Ditto.
	* config/microblaze/microblaze.md: constants: Add UNSPECV_CAS_BOOL,
	UNSPECV_CAS_MEM, UNSPECV_CAS_VAL, UNSPECV_ATOMIC_FETCH_OP
	type: add atomic
	* config/microblaze/sync.md: Add atomic_fetch_<atomic_optab>si
	atomic_test_and_set

Signed-off-by: Kirk Meyer <kirk.meyer@sencore.com>
Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>
Signed-off-by: Gopi Kumar Bulusu <gopi@sankhya.com>
Signed-off-by: Michael Eager <eager@eagercon.com>
2025-09-19 10:18:13 -07:00
Jan Hubicka 310c9a3842 Improve costing of speculative calls in ipa-fnsummary
This patch implements logic to estimate_edge_devirt_benefit to not account call
statement sizes of speculative calls in case we know the call we be turned to
direct call by inlining.  I also noticed that estimate_edge_size_and_time fails
to accont code size savings by devirtualization when not asked to compute hints
(this is quite rare; only early inliner and inlining functions called once is
affected) and compensated for that in estimate_calls_size_and_time

gcc/ChangeLog:

	* ipa-fnsummary.cc (estimate_edge_devirt_benefit): Handle speculative
	edges correctly.
	(estimate_edge_size_and_time): Even when not collecting hints,
	devirtualization affects function size.
	(estimate_calls_size_and_time): Do not use tables when devirtualization
	is possible.
2025-09-19 19:09:00 +02:00
Jan Hubicka ad3fb999a1 Improve ipa-cp devirtualization costing
This patch fixed devirtualization time benefit of ipa-cp which should be scaled
by edge frequency but it is not.  The cost model is still not correct for speculative
calls, since it does not take into account the fact that code size will shrink if
speculation is removed.
I also made cgraph_edge::make_direct to not ICE when there are multiple speculations
to same target. This can happen in combination of devirtualization and ICF in some
rare cases.

gcc/ChangeLog:

	* cgraph.cc (cgraph_edge::make_direct): Do not ICE when there are
	multiple speculations to comptaible targets
	(cgraph_edge::combined_sreal_frequency): New member function.
	* cgraph.h (cgraph_edge::combined_sreal_frequency): Declare.
	* ipa-cp.cc (devirtualization_time_bonus): Return sreal; consider
	profile.
	(estimate_local_effects): Likewise.
2025-09-19 19:05:34 +02:00
Paul Thomas 1f8600897b Fortran: Intrinsic functions in PDT specification exprs. [PR83746]
2025-09-19  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/83746
	* trans-array.cc (structure_alloc_comps): Add the pre and post
	blocks to 'fnblock' for all the evaluations of parameterized
	expressions in PDT component allocatation.

gcc/testsuite/
	PR fortran/83746
	* gfortran.dg/pdt_48.f03: New test.
2025-09-19 17:48:45 +01:00
Gaius Mulley 273b53effb PR modula2/121856: New wideset implementation
The new wideset implementation uses an ARRAY OF BYTE (internally) to
represent large sets.  This replaces the huge struct of anonymous
fields created by the old implementation and results in quicker
declaration times for large set types.

gcc/ChangeLog:

	PR modula2/121856
	* doc/gm2.texi (Compiler options): New item -fwideset.

gcc/m2/ChangeLog:

	PR modula2/121856
	* Make-lang.in (GM2-LIBS-BOOT-DEFS): Add M2Diagnostic.def.
	Add Selective.def.
	(GM2-LIBS-BOOT-MODS): Add M2Diagnostic.mod.
	(GM2-LIBS-BOOT-C): Add Selective.c.
	(GM2-LIBS-DEFS): Add Selective.def.
	(GM2-LIBS-MODS): Add M2Diagnostic.mod.
	(MC-LIB-MODS): Add M2Diagnostic.mod.
	(m2/gm2-libs-boot/Selective.o): New rule.
	(BUILD-PGE-O): Add m2/pge-boot/GM2Diagnostic.o.
	Add m2/pge-boot/GM2Diagnostic.o.
	Add m2/pge-boot/GStringConvert.o.
	Add m2/pge-boot/Gdtoa.o.
	Add m2/pge-boot/Gldtoa.o.
	* Make-maintainer.in (PPG-LIB-DEFS): Add M2Diagnostic.def.
	Add StringConvert.def.
	(PPG-LIB-MODS): Add M2Diagnostic.mod.
	Add StringConvert.mod.
	(PGE-DEF): Add M2Diagnostic.def.
	(PGE-DEPS): Add GM2Diagnostic.cc.
	Add GM2Diagnostic.h.
	* gm2-compiler/FifoQueue.def (PutSetIntoFifoQueue): New
	procedure.
	(GetSetFromFifoQueue): New procedure function.
	* gm2-compiler/FifoQueue.mod (PutSetIntoFifoQueue): New
	procedure.
	(GetSetFromFifoQueue): New procedure function.
	* gm2-compiler/M2ALU.def (KillValue): New procedure.
	(PushSetTree): Rename parameter t to value.
	(ConstructSetConstant): Rewrite comment.
	* gm2-compiler/M2ALU.mod: Rewrite to use the new set type
	and introduce memory diagnostics.
	* gm2-compiler/M2Base.mod (InitBaseProcedures): Lookup M2WIDESET.
	* gm2-compiler/M2CaseList.mod (CheckCaseBoundsResolved): Change
	format specifier to allow the preceeding indefinite article to
	have a n concatenated providing the following string substitute
	begins with a vowel.
	(checkTypes): Ditto.
	* gm2-compiler/M2Check.mod (checkGenericUnboundedTyped): New
	procedure function.
	* gm2-compiler/M2Code.mod (OptimizationAnalysis): Replace with ...
	(ResourceAnalysis): ... this.
	* gm2-compiler/M2Comp.mod (PopulateResource): New procedure.
	(compile): Call PopulateResource.
	Call M2Diagnostic.Generate.
	* gm2-compiler/M2GCCDeclare.mod: Rewrite for new set type.
	* gm2-compiler/M2GenGCC.mod: Rewrite implementation for
	becomes, incl, excl, and, or, not, xor for the new set type.
	* gm2-compiler/M2MetaError.def: Extend comment documenting
	the v format specifier.
	* gm2-compiler/M2MetaError.mod (errorBlock): New field vowel.
	(initErrorBlock): Initialize field vowel.
	Reformat comments.
	(pop): Call checkVowel.
	(checkVowel): New procedure.
	(isVowel): New procedure function.
	(symDesc): Remove indefinite article.
	(op): Set vowel field in case clause.
	* gm2-compiler/M2Options.def (OptimizeSets): New global.
	(TimeReport): Ditto.
	(MemReport): Ditto.
	(SetMemReport): New procedure.
	(SetTimeReport): Ditto.
	(SetWideset): Ditto.
	(GetWideset): New procedure function.
	* gm2-compiler/M2Options.mod (SetOptimizing): Assign
	OptimizeSets depending upon the optimization level.
	(SetMemReport): New procedure.
	(SetTimeReport): Ditto.
	(SetWideset): Ditto.
	(GetWideset): New procedure function.
	(OptimizeSets): Initialize to FALSE.
	(TimeReport): Ditto.
	(MemReport): Ditto.
	* gm2-compiler/M2Quads.mod (M2Diagnostic): Import.
	(QuadsMemDiag): New global variable.
	(NewQuad): Bump QuadsMemDiag whenever a quad is allocated.
	(BuildAssignmentBoolean): New procedure.
	(doBuildAssignment): Ditto.
	Add v to the format specifier.
	(CheckCompatibleWithBecomes): Add v to the format specifier.
	(CheckProcTypeAndProcedure): Ditto.
	(BuildAddAdrFunction): Ditto.
	(BuildSubAdrFunction): Ditto.
	(BuildDifAdrFunction): Ditto.
	(BuildDesignatorArrayStaticDynamic): Ditto.
	(BuildDesignatorPointer): Ditto.
	(CheckVariableOrConstantOrProcedure): Ditto.
	(Init): Initialize QuadsMemDiag.
	* gm2-compiler/M2Range.mod (CodeTypeAssign): Add v to the
	format specifier.
	* gm2-compiler/M2Scaffold.mod (DeclareScaffoldFunctions):
	Generate more precise warning note.
	* gm2-compiler/M2SymInit.mod (PrintSymInit): Add record
	field warning.
	* gm2-compiler/M2System.mod
	(IsPseudoSystemFunctionConstExpression): Add TBitSize.
	* gm2-compiler/NameKey.mod: Add MemDiagnostic code
	commented out.
	* gm2-compiler/P1SymBuild.mod (StartBuildProcedure):
	Add v format specifier.
	* gm2-compiler/P2SymBuild.mod (BuildFieldRecord): Ditto.
	* gm2-compiler/P3Build.bnf (SetType): Reformat.
	* gm2-compiler/PathName.def (Copyright): Added.
	* gm2-compiler/PathName.mod: Remove blank line.
	* gm2-compiler/SymbolConversion.mod (gdbhook): New procedure.
	(BreakWhenSymBooked): Ditto.
	(CheckBook): Ditto.
	(Init): Rewrite.
	* gm2-compiler/SymbolTable.def (GetSetArray): New procedure.
	(PutSetArray): Ditto.
	(MakeSetArray): New procedure function.
	(PutSetInWord): New procedure.
	(GetSetInWord): New procedure function.
	(IsConstVar): Ditto.
	* gm2-compiler/SymbolTable.mod (SymSet): SetInWord new field.
	SetArray new field.
	Align new field.
	(SymMemDiag): New global variable.
	(Init): Initialize SymMemDiag.
	(IsConstVar): New procedure function.
	(IsVariableSSA): Replace InternalError with Return FALSE.
	(GetNthParamOrdered): Reimplement.
	(GetNthParamAnyClosest): Ditto.
	(GetOuterModuleScope): Ditto.
	(MakeSet): Ditto.
	(PutSetArray): New procedure.
	(GetSetArray): New procedure function.
	(MakeSetArray): Ditto.
	(PutSetInWord): New procedure.
	(GetSetInWord): New procedure function.
	* gm2-gcc/init.cc (_M2_M2Diagnostic_init): Define
	prototype.
	(init_FrontEndInit):Call _M2_M2Diagnostic_init.
	* gm2-gcc/m2block.cc (m2block_GetTotalConstants): New function.
	(m2block_GetGlobalTypes): Ditto.
	* gm2-gcc/m2block.def (GetTotalConstants): New procedure function.
	(GetGlobalTypes): New procedure function.
	* gm2-gcc/m2block.h (m2block_GetTotalConstants): New function
	prototype.
	(m2block_GetGlobalTypes): Ditto.
	* gm2-gcc/m2convert.cc (converting_ISO_generic): Reimplement.
	(m2convert_ToPIMByte): New function.
	* gm2-gcc/m2convert.def (ToLoc): New procedure function.
	(ToPIMByte): Ditto.
	* gm2-gcc/m2convert.h (m2convert_ToPIMByte): Ditto.
	* gm2-gcc/m2decl.h (m2decl_RememberVariables): Ditto.
	* gm2-gcc/m2expr.cc (m2expr_BuildLogicalShift): Reimplement.
	(m2expr_BuildLRotate): Ditto.
	(m2expr_BuildLRLn): Ditto.
	(m2expr_BuildLRRn): Ditto.
	(m2expr_BuildLogicalRotate): Ditto.
	(buildUnboundedArrayOf): Ditto.
	(BuildIfBitInSetLower): New function.
	(m2expr_BuildBinarySetDo): Reimplement.
	(m2expr_BuildIfInSet): Ditto.
	(m2expr_BuildIfNotInSet): New function.
	(m2expr_Build4LogicalOr): Reimplement.
	(m2expr_BuildSetNegate): Ditto.
	(m2expr_BuildLogicalOrAddress): Ditto.
	(m2expr_BuildLogicalOr): Ditto.
	(m2expr_BuildLogicalAnd): Ditto.
	(m2expr_BuildSymmetricDifference): Ditto.
	(m2expr_BuildLogicalDifference): Ditto.
	(boolean_enum_to_unsigned): Ditto.
	(m2expr_BuildIsSuperset): Ditto.
	(m2expr_BuildIsNotSuperset): Ditto.
	(m2expr_BuildIsSubset): Ditto.
	(m2expr_BuildIfBitInSetJump): Ditto.
	(m2expr_BuildIfNotConstInVar): Ditto.
	(m2expr_BuildIfVarInVar): Ditto.
	(m2expr_BuildIfNotVarInVar): Remove.
	(m2expr_BuildIfConstInVar): Remove.
	(m2expr_BuildForeachWordInSetDoIfExpr): Ditto.
	(m2expr_BuildBinaryForeachWordDo): Ditto.
	(m2expr_BuildIfInRangeGoto): Reimplement.
	(m2expr_BuildIfNotInRangeGoto): Ditto.
	(m2expr_SetAndNarrow): Ditto.
	(m2expr_GetBitsetZero): New function.
	(m2expr_GetRValue): Ditto.
	* gm2-gcc/m2expr.def (GetBitsetZero): New function.
	(BuildSetNegate): Ditto.
	(BuildLogicalOr): Reimplement.
	(BuildLogicalAnd): Ditto.
	(BuildSymmetricDifference): Ditto.
	(BuildLogicalDifference): Ditto.
	(BuildIfInSet): New procedure function.
	(BuildIfNotInSet): Ditto.
	(BuildEqualTo): Reimplement.
	(BuildNotEqualTo): Ditto.
	(BuildBinaryForeachWordDo): Remove.
	(BuildBinarySetDo): Ditto.
	(GetRValue): New procedure function.
	* gm2-gcc/m2expr.h (m2expr_BuildBinaryForeachWordDo): Remove.
	(m2expr_BuildForeachWordInSetDoIfExpr): Ditto.
	(m2expr_BuildIfNotVarInVar): Ditto.
	(m2expr_BuildIfVarInVar): Ditto.
	(m2expr_BuildIfNotConstInVar): Ditto.
	(m2expr_BuildIfConstInVar): Ditto.
	(m2expr_BuildLogicalDifference): Reimplement.
	(m2expr_BuildSymmetricDifference): Ditto.
	(m2expr_BuildLogicalAnd): Ditto.
	(m2expr_BuildLogicalOr): Ditto.
	(m2expr_BuildLogicalOrAddress): Ditto.
	(m2expr_BuildSetNegate): Ditto.
	(m2expr_GetBitsetZero): New function.
	(m2expr_GetRValue): Ditto.
	(m2expr_BuildIfInSet): Ditto.
	(m2expr_BuildIfNotInSet): Ditto.
	* gm2-gcc/m2options.h (M2Options_SetTimeReport): New function.
	(M2Options_SetMemReport): Ditto.
	(M2Options_SetWideset): Ditto.
	(M2Options_GetWideset): Ditto.
	* gm2-gcc/m2pp.cc (m2pp_shiftrotate_expr): New function.
	(m2pp_simple_expression): Ditto.
	* gm2-gcc/m2statement.cc (m2statement_BuildStartFunctionCode):
	Tidyup comments.
	(m2statement_BuildEndFunctionCode): Ditto.
	(m2statement_BuildPushFunctionContext): Ditto.
	(copy_array): Ditto.
	(CopyByField_Lower): Ditto.
	(m2statement_BuildGoto): Ditto.
	(m2statement_DeclareLabel): Ditto.
	(m2statement_BuildParam): Ditto.
	(nCount): Ditto.
	(m2statement_BuildProcedureCallTree): Ditto.
	(m2statement_BuildBuiltinCallTree): Ditto.
	(m2statement_BuildFunctValue): Ditto.
	(m2statement_BuildCall2): Ditto.
	(m2statement_BuildCall3): Ditto.
	(m2statement_BuildFunctionCallTree): Ditto.
	(m2statement_SetLastFunction): Ditto.
	(m2statement_SetParamList): Ditto.
	(m2statement_GetLastFunction): Ditto.
	(m2statement_GetParamList): Ditto.
	(m2statement_GetCurrentFunction): Ditto.
	(m2statement_GetParamTree): Ditto.
	(m2statement_BuildTryFinally): Ditto.
	(m2statement_BuildCleanUp): Ditto.
	(m2statement_BuildUnaryForeachWordDo): Remove.
	(m2statement_BuildExcludeVarConst): Ditto.
	(m2statement_BuildExcludeVarVar): Ditto.
	(m2statement_BuildIncludeVarConst): Ditto.
	(m2statement_BuildIncludeVarVar): Ditto.
	(m2statement_DoJump): Remove.
	(m2statement_IfExprJump): New function.
	(m2statement_IfBitInSetJump): Ditto.
	* gm2-gcc/m2statement.def (DoJump): Remove.
	(IfExprJump): New procedure function.
	(BuildUnaryForeachWordDo): Remove.
	(IfBitInSetJump): New procedure function.
	* gm2-gcc/m2statement.h (m2statement_BuildForeachWordDo): Remove.
	(m2statement_DoJump): Ditto.
	(m2statement_IfExprJump): New function.
	(m2statement_IfBitInSetJump): Ditto.
	* gm2-gcc/m2treelib.cc (m2treelib_do_jump_if_bit): Reimplement.
	(nCount): Replace with ...
	(m2treelib_nCount): ... this.
	(m2treelib_DoCall): Reimplement.
	(m2treelib_get_rvalue): Remove.
	* gm2-gcc/m2treelib.def (get_rvalue): Remove.
	(nCount): New procedure function.
	* gm2-gcc/m2treelib.h (m2treelib_get_rvalue): Remove.
	(m2treelib_nCount): New function.
	* gm2-gcc/m2type.cc (constructor_elements): Change type to vec.
	(m2type_BuildEndArrayType): Reformat.
	(build_m2_type_node_by_array): Ditto.
	(m2type_GetBooleanEnumList): New procedure function.
	(m2type_BuildEnumerator): Add const to char *.
	(m2type_BuildSetConstructorElement): Reimplement.
	(m2type_BuildEndSetConstructor): Ditto.
	(build_record_constructor): New function.
	(m2type_BuildEndRecordConstructor): Reimplement.
	(m2type_BuildRecordConstructorElement): Ditto.
	(m2type_BuildStartArrayConstructor): Reimplement.
	(m2type_BuildEndArrayConstructor): Remove blank lines.
	* gm2-gcc/m2type.def (BuildSetConstructorElement): Reimplement.
	(BuildEndArrayType): Reformat.
	(GetBooleanEnumList): New function.
	* gm2-gcc/m2type.h (m2type_BuildEnumerator): Add const to char *.
	(m2type_BuildSetConstructorElement): Reimplement.
	(m2type_GetBooleanEnumList): New procedure function.
	* gm2-lang.cc (OPT_fmem_report): New option.
	(OPT_ftime_report): Ditto.
	(OPT_fwideset): Ditto.
	* gm2-libs-coroutines/SYSTEM.def (ShiftVal): Remove.
	(ShiftLeft): Ditto.
	(ShiftRight): Ditto.
	(RotateVal): Ditto.
	(RotateLeft): Ditto.
	(RotateRight): Ditto.
	* gm2-libs-coroutines/SYSTEM.mod: Reimplement.
	* gm2-libs-iso/SYSTEM.def (ShiftVal): Remove.
	(ShiftLeft): Ditto.
	(ShiftRight): Ditto.
	(RotateVal): Ditto.
	(RotateLeft): Ditto.
	(RotateRight): Ditto.
	* gm2-libs-iso/SYSTEM.mod: Reimplement.
	* gm2-libs/SYSTEM.def (ShiftVal): Remove.
	(ShiftLeft): Ditto.
	(ShiftRight): Ditto.
	(RotateVal): Ditto.
	(RotateLeft): Ditto.
	(RotateRight): Ditto.
	* gm2-libs/SYSTEM.mod: Reimplement.
	* gm2-libs/SysStorage.def (DEALLOCATE): Improve comment.
	* gm2-libs/SysStorage.mod: Improve comment.
	* init/ppginit (M2Diagnostic): Add.
	(StringConvert): Add.
	* lang.opt (fmem-report): Add access to c.opt.
	(ftime-report): Ditto.
	(fwideset): New option.
	* pge-boot/main.cc (_M2_M2Diagnostic_init): New function.
	(_M2_M2Diagnostic_fini): Ditto.
	(_M2_StringConvert_init): Ditto.
	(_M2_StringConvert_fini): Ditto.
	(main): Call _M2_M2Diagnostic_init.
	Call _M2_StringConvert_init.
	Call _M2_M2Diagnostic_fini.
	Call _M2_StringConvert_fini.
	* tools-src/makeSystem: Add -gdb option.
	* gm2-libs/M2Diagnostic.def: New file.
	* gm2-libs/M2Diagnostic.mod: New file.
	* gm2-libs/M2WIDESET.def: New file.
	* gm2-libs/M2WIDESET.mod: New file.
	* mc-boot/GM2Diagnostic.cc: New file.
	* mc-boot/GM2Diagnostic.h: New file.
	* pge-boot/GM2Diagnostic.cc: New file.
	* pge-boot/GM2Diagnostic.h: New file.
	* pge-boot/GSelective.h: New file.
	* pge-boot/GStringConvert.cc: New file.

libgm2/ChangeLog:

	* libm2pim/Makefile.am (M2MODS): Add M2Diagnostic.mod.
	Add M2WIDESET.mod.
	(M2DEFS): Add M2Diagnostic.def.
	Add M2WIDESET.def.
	* libm2pim/Makefile.in: Regenerate.

gcc/testsuite/ChangeLog:

	* gm2/errors/fail/testbit2.mod: Rewrite.
	* gm2/iso/run/pass/shift4.mod: Rewrite adding more internal
	tests.
	* gm2/iso/run/pass/testsystem.mod (FindFirstElement): Add
	bounds check.
	* gm2/sets/run/pass/multisetrotate4.mod: Add more runtime
	error messages.
	* gm2/sets/run/pass/simplepacked.mod (testpset): Correct
	setname.
	* lib/gm2.exp (gm2_init_minx): Add -fno-wideset.
	* gm2/iso/run/pass/assigncons.mod: New test.
	* gm2/iso/run/pass/constructor3.mod: New test.
	* gm2/iso/run/pass/proc_test.mod: New test.
	* gm2/iso/run/pass/simplelarge2.mod: New test.
	* gm2/iso/run/pass/simplelarge3.mod: New test.
	* gm2/iso/run/pass/simplelarge4.mod: New test.
	* gm2/pimlib/wideset/run/pass/bitset.mod: New test.
	* gm2/pimlib/wideset/run/pass/bitset2.mod: New test.
	* gm2/pimlib/wideset/run/pass/colorset.mod: New test.
	* gm2/pimlib/wideset/run/pass/colorset2.mod: New test.
	* gm2/pimlib/wideset/run/pass/colorset3.mod: New test.
	* gm2/pimlib/wideset/run/pass/highbit.mod: New test.
	* gm2/pimlib/wideset/run/pass/highbit2.mod: New test.
	* gm2/sets/run/pass/multisetrotate5.mod: New test.
	* gm2/sets/run/pass/setcard.mod: New test.
	* gm2/sets/run/pass/setincl.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-09-19 17:26:18 +01:00
Jeff Law cc0959221e [RISC-V][PR target/121983] Fix unprotected REGNO invocation
So this was a naked REGNO usage, which of course blows up if RTL checking is
enabled and something else sneaks in (SUBREG).   Thankfully it never results in
incorrect code, though I could theorize it could cause a bootstrap comparison
failure in the "right" circumstances.

Bootstrapped & regression tested on the Pioneer.  Also regression tested on
riscv64-elf and riscv32-elf.   I'll push to the trunk once pre-commit CI is
done.

jeff

	PR target/121983
gcc/
	* config/riscv/riscv.cc (riscv_macro_fusion_pair_p): Make sure
	object is a REG before asking for its REGNO.  Fix a trivial
	whitespace nit.

gcc/testsuite/
	* gcc.target/riscv/pr121983.c: New test.
2025-09-19 09:18:02 -06:00
Raphael Moreira Zinsly b71ff5184a RISC-V: Improve slide patterns recognition
Improve shuffle_slide_patterns to better recognize permutations that
can be constructed by a slideup or slidedown, covering more cases:
Slideup one vector into the middle the other like
  {0, 4, 5, 3}.
Slidedown one vector not ending in the last element like
  {5, 6, 2, 3}.
Slidedown one vector from the beginning like
  {4, 5, 2, 3}.

gcc/ChangeLog:

	* config/riscv/riscv-v.cc
	(shuffle_slide_patterns): Cover more permutations.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/shuffle-slide-run.h:
	New test.
	* gcc.target/riscv/rvv/autovec/shuffle-slidedown-run.c:
	Likewise.
	* gcc.target/riscv/rvv/autovec/shuffle-slideup-run.c:
	Likewise.
	* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-slide.h:
	Likewise.
	* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-slidedown-1.c:
	Likewise.
	* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-slidedown-2.c:
	Likewise.
	* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-slidedown-perm.h:
	Likewise.
	* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-slideup-1.c:
	Likewise.
	* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-slideup-2.c:
	Likewise.
	* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-slideup-perm.h:
	Likewise.
2025-09-19 11:08:41 -03:00
Jim Lin afdf44154f RISC-V: Only Save/Restore required registers for ILP32E/LP64E
Previously the spec
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/70
has changed the save/restore routines to save/restore the registers which
are really used for ILP32E/LP64 rather than always save/restore all
of ra/s0/s1.

I also found here that lacks the implementation for lp64e. If it's
necessary I will file anothor patch for that.

gcc/ChangeLog:

	* config/riscv/riscv.cc (riscv_compute_frame_info): Remove the
	dedicated calculation for RVE.

libgcc/ChangeLog:

	* config/riscv/save-restore.S: Only save/restore the registers
	which are really used for ILP32E/LP64.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/save-restore-cfi-3.c: New test.
2025-09-19 07:09:21 -06:00
Jeff Law 4f01f39d02 [RISC-V] Optimize clear-lowest-set-bit sequence when ctz is nearby
Daniel Barboza and I were looking at deepsjeng recently and spotted an oddity.
In particular we had a sequence like this:

    addi a1,a0,-1
    and a1,a0,a1

That idiom clears the lowest set bit in a0.  In the initial code we looked at
there was a subsequent ctz dest,a0.  In other cases I could see an earlier ctz.
And when I went digging further I even found the ctz between the addi/and.

The key is the ctz uses the same input as the addi, but a different output.  So
the ctz doesn't participate in combine with the addi/and.

Tackling this in gimple isn't really feasible as the resultant code is going to
have a higher expression count.  The bclr idiom looks like (and (rotate (-2)
(count) (input)) where the count comes from a ctz.  SO to make it work from a
costing standpoint, we'd have to go find the ctz and use it.

Tackling in gimple->rtl expansion looked potentially feasible, but sign and
general type changes make that painful.  So while I could see the add+and and
could speculatively hope there was a nearby ctz it looked less than ideal from
an implementation standpoint.  It also tickled some undesirable behavior in the
combiner.

Tackling in combine isn't possible because the ctz doesn't feed the addi/and or
vice-versa.

Tackling with a peephole works sometimes, but is easily thwarted by the
scheduler putting random code in the middle of the sequences we want to adjust.

So in the end I just made a new RISC-V pass that runs after combine.

It walks each block looking for the addi+and construct.  When found it then
looks a few instructions in either direction for a related ctz. When found
it'll move things around as necessary and use ctz+bclr.  It depends on DCE to
eliminate the almost certainly dead addi+and insns.

I haven't benchmarked this one on design, but it's definitely picking up the
opportunities in deepsjeng and saves a few billion instructions.  It has
survived a riscv64-elf and riscv32-elf build.  Bootstrap on the BPI is in
flight, bootstrap on the Pioneer passes, but this code won't trigger this
because the Pioneer doesn't have ctz or bclr instructions.

Note while I would expect some of this pass to be usable on other targets, it
does make some assumptions about RTL structure that hold on RISC-V.  For
example subword arithmetic has an explicit sign extension to word mode, bit
position is QImode, etc.

Comments?  Other thoughts on how to resolve?

gcc/
	* config.gcc (riscv*); Add riscv-bclr-lowest-set-bit.o to extra_objs.
	* config/riscv/riscv-bclr-lowest-set-bit.cc: New file.
	* config/riscv/riscv-passes.def: Add new pass after combine.
	* config/riscv/riscv-protos.h (make_pass_bclr_lowest_set_bit): Add
	prototype.
	* config/riscv/t-riscv: Add rules to build riscv-bclr-lowest-set-bit.o.

gcc/testsuite
	* gcc.target/riscv/bclr-lowest-set-bit-1.c: New test.
2025-09-19 06:55:35 -06:00
Richard Biener 95fc85aff1 Remove accidentially left if (0) block
The following removes a block I added (and disabled again) when
developing the PR121720 fix.

	* tree-ssa-pre.cc (compute_antic_aux): Remove dead code.
2025-09-19 12:19:18 +02:00
Eric Botcazou 5ca8c27364 ada: Implement support for Is_Link_Once flag on entities
gcc/ada/ChangeLog:

	* gcc-interface/gigi.h (create_var_decl): Add LINKONCE_FLAG boolean
	parameter.
	(create_subprog_decl): Likewise.
	* gcc-interface/decl.cc (gnat_to_gnu_entity): Adjust calls to
	create_var_decl and create_subprog_decl.
	(elaborate_expression_1): Likewise.
	* gcc-interface/trans.cc (gigi): Likewise.
	(build_raise_check): Likewise.
	(Subprogram_Body_to_gnu): Likewise.
	(create_temporary): Likewise.
	(Exception_Handler_to_gnu): Likewise.
	(Compilation_Unit_to_gnu): Likewise.
	(gnat_to_gnu): Likewise.
	(use_alias_for_thunk_p): Return false for a one-only target.
	* gcc-interface/utils.cc (maybe_pad_type): Adjust call to
	create_var_decl.
	(create_var_decl): Add LINKONCE_FLAG boolean parameter.
	(create_subprog_decl): Likewise.
2025-09-19 11:26:11 +02:00
Marc Poulhiès 6eb4909a31 ada: Initial support for Extended Access types
This change introduces the support for the new GNAT specific
Extended_Access aspect for access to unconstrained array type :

  type Ext_Access is access all Some_Array_Type with Extended_Access;

 This new kind of access type does not use the existing "fat" layout with
 a record of two pointers: one to the actual data, one to a record with the
 bounds of the array. Instead, it removes the second indirection and extends
 the record to contain the pointer to the actual data followed by the bounds.

This mainly allows the following features:
- have access to slice of array
- easier interface when allocation is done in a foreign language

gcc/ada/ChangeLog:

	* gcc-interface/ada-tree.h (TYPE_EXTENDED_POINTER_P): New.
	(TYPE_IS_EXTENDED_POINTER_P): New.
	(TYPE_EXTENDED_UNCONSTRAINED_ARRAY): New.
	(SET_TYPE_EXTENDED_UNCONSTRAINED_ARRAY): New.
	(TYPE_DUMMY_EXT_POINTER_TO): New.
	(SET_TYPE_DUMMY_EXT_POINTER_TO): New.
	* gcc-interface/decl.cc (get_extended_unconstrained_array): New.
	(gnat_to_gnu_entity): Handle extended access type.
	(get_unpadded_extended_type): New.
	(gnat_to_gnu_component_type): Handle extended access type.
	(build_template_type): New.
	(gnat_to_gnu_field): Handle extended access type.
	(validate_size): Likewise.
	(set_rm_size): Likewise.
	(copy_and_substitute_in_layout): Likewise.
	(rm_size): Likewise.
	* gcc-interface/gigi.h (get_unpadded_extended_type): New.
	(build_template_type): New.
	(build_dummy_unc_pointer_types_ext): New.
	(finish_extended_pointer_type): New.
	(build_unc_object_type_from_ptr): Rename first parameter.
	* gcc-interface/misc.cc (gnat_print_type): Handle extended access type.
	* gcc-interface/trans.cc (Identifier_to_gnu): Likewise.
	(Attribute_to_gnu): Likewise.
	(gnat_to_gnu): Likewise.
	* gcc-interface/utils.cc (convert_to_fat_pointer): Assert if converting an
	extended pointer.
	(build_dummy_unc_pointer_types_ext): New.
	(finish_extended_pointer_type): New.
	(finish_record_type): Handle extended access type.
	(build_unc_object_type_from_ptr): Likewise.
	(convert_to_extended_pointer): New.
	(convert): Handle extended access type.
	(gnat_pushdecl): Likewise.
	(maybe_pad_type): Likewise.
	* gcc-interface/utils2.cc (build_unary_op): Likewise.
	(build_binary_op): Likewise.
	(build_allocator): Likewise.
	(gnat_save_expr): Likewise.
	(gnat_protect_expr): Likewise.
	(gnat_stabilize_reference_1): Likewise.
2025-09-19 11:26:11 +02:00
Eric Botcazou 7d04808036 ada: Make error recovery for structural generic instantiation more robust
This adds a guard for the case of a selected component whose prefix is an
illegal structural generic instance.

gcc/ada/ChangeLog:

	* sem_ch4.adb (Analyze_Selected_Component): Bail out if the prefix
	has Void_Type.
2025-09-19 11:26:11 +02:00
Piotr Trojanek 616d104215 ada: Remove unnecessary declare block
Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

	* sem_ch4.adb (Analyze_User_Defined_Binary_Op): Remove declare block.
2025-09-19 11:26:11 +02:00
Eric Botcazou e564d6b1a7 ada: Preliminary implementation of structural generic instantiation
It contains the changes to the parser required for the new syntax, as well
as the mechanism to instantiate generics implicitly.  The implementation is
strictly structural, in the sense that if the implicit instantiation cannot
be made structural for semantic dependence reasons, then it is rejected.

gcc/ada/ChangeLog:

	* doc/gnat_rm/gnat_language_extensions.rst (Structural Generic
	Instantiation): New entry
	* einfo.ads (Is_Link_Once): New flag defined in entities.
	* sinfo.ads (Is_Structural): New flag defined in instantiations.
	* gen_il-fields.ads (Opt_Field_Enum): Add Is_Link_Once and
	Is_Structural.
	* gen_il-gen-gen_entities.adb (Entity_Kind): Add Is_Link_Once
	semantic flag.
	* gen_il-gen-gen_nodes.adb (N_Generic_Instantiation): Move up
	Parent_Spec field and add Is_Structural semantic flag.
	* frontend.adb: Add with clause for Sem_Ch12.
	(Frontend): After analysis is complete and bodies are instantiated,
	call Sem_Ch12.Mark_Link_Once on the declarations of the main unit.
	* par.adb (P_Qualified_Simple_Name): Delete.
	(P_Qualified_Simple_Name_Resync): Likewise
	(P_Exception_Name): New function declaration.
	(P_Label_Name): Likewise.
	(P_Loop_Name): Likewise.
	(P_Generic_Unit_Name): Likewise.
	(P_Library_Unit_Name): Likewise.
	(P_Package_Name): Likewise.
	(P_Parent_Unit_Name): Likewise.
	(P_Subtype_Name): Likewise.
	(P_Subtype_Name_Resync): Likewise.
	* par-ch3.adb (P_Subtype_Mark_Resync): Replace call to
	P_Qualified_Simple_Name_Resync by P_Subtype_Name_Resync.
	(P_Identifier_Declarations): Replace call to
	P_Qualified_Simple_Name_Resync by P_Exception_Name.
	(P_Derived_Type_Def_Or_Private_Ext_Decl): Replace call to
	P_Qualified_Simple_Name by P_Subtype_Name.
	(P_Interface_Type_Definition): Replace calls to
	P_Qualified_Simple_Name by P_Subtype_Name.
	* par-ch4.adb (P_Reduction_Attribute_Reference): Move around and
	change name of parameter.
	(P_Name): Document new grammar rule and make a couple of tweaks.
	(P_Exception_Name): New function.
	(P_Label_Name): Likewise.
	(P_Loop_Name): Likewise.
	(P_Generic_Unit_Name): Likewise.
	(P_Library_Unit_Name): Likewise.
	(P_Package_Name): Likewise.
	(P_Parent_Unit_Name): Likewise.
	(P_Subtype_Name): Likewise.
	(P_Subtype_Name_Resync): Likewise.
	(P_Qualified_Simple_Name): Rename into...
	(P_Simple_Name): ...this.
	(P_Qualified_Simple_Name_Resync): Rename into...
	(P_Simple_Name_Resync): ...this.  Accept left parenthesis and
	dot as name extensions.
	(P_Allocator): Replace call to P_Qualified_Simple_Name_Resync
	by P_Subtype_Name_Resync.
	* par-ch5.adb (P_Goto_Statement): Replace call to
	P_Qualified_Simple_Name by P_Label_Name.
	(Parse_Loop_Flow_Statement): Replace call to
	P_Qualified_Simple_Name by P_Loop_Name.
	* par-ch6.adb (P_Subprogram): Replace call to
	P_Qualified_Simple_Name by P_Generic_Unit_Name.
	* par-ch7.adb (P_Package): Replace calls to
	P_Qualified_Simple_Name by P_Package_Name and P_Generic_Unit_Name.
	* par-ch8.adb (P_Use_Package_Clause): Replace calls to
	P_Qualified_Simple_Name by P_Package_Name.
	* par-ch9.adb (P_Task): Replace call to
	P_Qualified_Simple_Name by P_Subtype_Name.
	(P_Protected): Likewise.
	* par-ch10.adb (P_Context_Clause): Replace call to
	P_Qualified_Simple_Name by P_Library_Unit_Name.
	(P_Subunit): Replace call to P_Qualified_Simple_Name by
	P_Parent_Unit_Name.
	* par-ch12.adb (P_Generic): Replace call to
	P_Qualified_Simple_Name by P_Generic_Unit_Name.
	(P_Formal_Derived_Type_Definition): Replace call to
	P_Qualified_Simple_Name by P_Subtype_Name.
	(P_Formal_Package_Declaration): Replace call to
	P_Qualified_Simple_Name by P_Generic_Unit_Name.
	* sem_ch4.adb: Add with and use clauses for Sem_Ch12.
	(Analyze_Call): Accept implicit instantiations with -gnatX0.
	(Analyze_Indexed_Component_Form): Likewise.
	* sem_ch8.adb (Analyze_Use_Package): Add guard before inserting
	a with clause automatically when there is a use clause.
	(Check_In_Previous_With_Clause): Retrieve original names.
	(Check_Library_Unit_Renaming): Deal with structural instances.
	(End_Use_Type): Minor tweak.
	* sem_ch10.adb (Analyze_With_Clause): Remove useless test and
	call Defining_Entity_Of_Instance.
	* sem_ch12.ads (Build_Structural_Instantiation): New function.
	(Mark_Link_Once): New procedure.
	* sem_ch12.adb: Add with and use clauses for Exp_Dbug.
	(Analyze_Associations): Add support for structural instantiations.
	(Analyze_Package_Instantiation): Likewise.
	(Analyze_Subprogram_Instantiation): Likewise.
	(Analyze_Structural_Associations): New procedure.
	(Need_Subprogram_Instance_Body): Return True for instantiation is
	in the auxiliary declarations of the main unit.
	(Build_Structural_Instantiation): New function.
	(Mark_Link_Once): New procedure.
	* sem_util.ads (Add_Local_Declaration): New procedure.
	(Defining_Entity_Of_Instance): New function.
	* sem_util.adb (Add_Local_Declaration): New procedure.
	(Defining_Entity_Of_Instance): New function.
	* gnat_rm.texi: Regenerate.
	* gnat_ugn.texi: Regenerate.
2025-09-19 11:26:11 +02:00
Ronan Desplanques dadb33b99a ada: Fix comment about operational aspects
The comment this patch changes claimed that operational aspects are
"view-specific". The following excerpt from ARM 13.1 (11/5) indicates
that the set of view-specific aspects is in fact much more restricted:

    If a type-related aspect is defined for the partial view of a type,
    then it has the same definition for the full view of the type, except
    for certain Boolean-valued operational aspects where the language
    specifies that the partial view can have the value False even when
    the full view has the value True.

On the other hand, a feature of operational aspects is that they can be
specified on partial views, unlike representation aspects. That's stated
by AARM 13.1 (9.c/1):

    Unlike representation items, operational items can be specified on
    partial views.

So this patch changes the comment to be about that instead.

gcc/ada/ChangeLog:

	* aspects.ads: Fix comment.
2025-09-19 11:26:10 +02:00
Ronan Desplanques 600e85df55 ada: Remove comment
The comment this patch removes was about representation aspects but it
was placed above Operational_Aspect. The comment in itself was not very
helpful either since operational aspects, for example, are also needed
during expansion and code generation.

gcc/ada/ChangeLog:

	* aspects.ads: Remove comment.
2025-09-19 11:26:10 +02:00
Marc Poulhiès 32c70b25f0 ada: Add procedure to write an extended access as a String
Add the Put_Image_Extended_Access_Pointer procedure for supporting
Ext_Access'Image.

gcc/ada/ChangeLog:

	* libgnat/s-putima.ads (Ext_Access_Pointer): New.
	(Put_Image_Extended_Access_Pointer): New.
	* libgnat/s-putima.adb (Ext_Acc_Instance): New.
	(Put_Image_Extended_Access_Pointer): New.
	* rtsfind.ads (RE_Id, RE_Unit_Table): Set value for
	RE_Put_Image_Extended_Access_Pointer.
	* exp_put_image.adb (Build_Elementary_Put_Image_Call): Handle extended
	access.
2025-09-19 11:26:10 +02:00
Marc Poulhiès 7c6e533f05 ada: Add C binding for Is_Extended_Access_Type
gcc/ada/ChangeLog:

	* fe.h (Is_Extended_Access_Type): Add C bindings.
	* sem_util.ads (Is_Extended_Access_Type): Add comment that any
	change to the function must take care of the C binding.
2025-09-19 11:26:10 +02:00
Marc Poulhiès dc61789283 ada: Do not set Esize for Extended Accesses
The size of an extended access is unknown at this stage, so leave Esize
empty.

gcc/ada/ChangeLog:

	* layout.adb (Layout_Type): Adjust comment and code extended
	accesses.
2025-09-19 11:26:10 +02:00
Ronan Desplanques f8e59edf55 ada: Remove superfluous statements
This patch removes two occurrences of the following pattern:

    Analyze_Component_Declaration (N);
    Mutate_Ekind (Defining_Identifier (N), E_Component);

The second statement here has absolutely no effect, so its presence can
be confusing to the reader.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Add_Tag): Remove superfluous statements.
2025-09-19 11:26:10 +02:00
Steve Baird d832626b1a ada: Compiler crashes on subunits with Streaming/Put_Image attribute references
When necessary, the compiler builds subprograms to implement the streaming
attributes (or the Put_Image attribute) for a type. In some cases involving
separate subunits, these compiler-generated subprograms were inserted at the
wrong point in the tree, resulting in internal compiler errors.

gcc/ada/ChangeLog:

	* exp_attr.adb (Interunit_Ref_OK): Treat a subunit like a body.
	(Build_And_Insert_Type_Attr_Subp): When climbing up the
	tree, go from an N_Subunit node to its stub (instead of to the
	subunit's N_Compilation_Unit node).
2025-09-19 11:26:10 +02:00
Gary Dismukes b0f15d09da ada: Incorrect expansion of VADS Size attribute applied to an array type
The compiler fails, either with an Assert_Failure (for a compiler with
assertions enabled) or by producing a bad value, when processing a VADS_Size
attribute (or a Size attribute when pragma Use_VADS_Size is in force),
in the case where the prefix denotes a composite type or subtype whose
object size (Esise) is not known by the front end. The bug is due to
Eval_Attribute attempting to fold a VADS-related size attribute even
when Esize is not yet known for the type.

gcc/ada/ChangeLog:

	* sem_attr.adb (Eval_Attribute): In the case of a VADS-specific
	size attribute, only fold to the object size when the Esize field
	is known.
2025-09-19 11:26:09 +02:00
Jonathan Wakely acfd5ab079 libstdc++: Reorder start_lifetime_as macro in version.def
libstdc++-v3/ChangeLog:

	* include/bits/version.def (start_lifetime_as): Move adjacent to
	other C++23 macros.
	* include/bits/version.h: Regenerate.
2025-09-19 10:22:24 +01:00
Richard Biener 4943123298 Remove DR_GROUP_STORE_COUNT
This was only used for non-SLP.

	* tree-vectorizer.h (_stmt_vec_info::store_count): Remove.
	(DR_GROUP_STORE_COUNT): Likewise.
	* tree-vect-stmts.cc (vect_transform_stmt): Remove non-SLP
	path.
2025-09-19 11:14:03 +02:00
Richard Biener 11e09c9ad8 Cleanup vect_get_num_copies API
The following removes the dual non-SLP/SLP API in favor of only
handling SLP.  This also removes the possibility to override
vectype of a SLP node with an inconsistent one while still using
the SLP nodes number of lanes.  This requires adjustment of
a few places where such inconsistencies happened.

	* tree-vectorizer.h (vect_get_num_copies): Remove unused
	overload.  Remove defaulted vectype argument and always
	use the vector type of the SLP node.
	* tree-vect-loop.cc (vect_reduction_update_partial_vector_usage):
	Adjust.
	(vectorizable_lane_reducing): Likewise.
	(vect_transform_reduction): Likewise.
	(vectorizable_nonlinear_induction): Likewise.
	* tree-vect-stmts.cc (check_load_store_for_partial_vectors):
	Likewise.
2025-09-19 09:35:02 +02:00
Richard Biener 140a29ae84 Remove SLP_TREE_NUMBER_OF_VEC_STMTS
The following removes the redundant SLP_TREE_NUMBER_OF_VEC_STMTS,
replacing it with vect_get_num_copies.  Previously it was already
made sure that all setters adhere to that.

	* tree-vectorizer.h (_slp_tree::vec_stmts_size): Remove.
	(SLP_TREE_NUMBER_OF_VEC_STMTS): Likewise.
	* tree-vect-loop.cc (vectorizable_reduction): Adjust.
	(vect_transform_cycle_phi): Likewise.
	(vect_transform_lc_phi): Likewise.
	(vectorizable_recurr): Likewise.
	(vectorizable_induction): Likewise.
	(vectorizable_live_operation): Likewise.
	* tree-vect-slp.cc (_slp_tree::_slp_tree): Do not set
	SLP_TREE_NUMBER_OF_VEC_STMTS.
	(vect_slp_analyze_node_operations_1): Likewise.
	(vect_slp_analyze_node_operations): Likewise.
	(vect_prologue_cost_for_slp): Adjust.
	(vect_create_constant_vectors): Likewise.
	(vect_get_slp_vect_def): Likewise.
	(vect_transform_slp_perm_load_1): Likewise.
	(vectorizable_slp_permutation_1): Likewise.
	(vect_schedule_slp_node): Likewise.
	(vectorize_slp_instance_root_stmt): Likewise.
	* tree-vect-stmts.cc (vect_model_simple_cost): Likewise.
	(vectorizable_bswap): Likewise.
	(vectorizable_call): Likewise.
	(vectorizable_conversion): Likewise.
	(vectorizable_shift): Likewise.
	(vectorizable_operation): Likewise.
	(vectorizable_store): Likewise.
	(vectorizable_load): Likewise.
	(vectorizable_condition): Likewise.
	(vectorizable_early_exit): Likewise.
2025-09-19 09:35:01 +02:00
GCC Administrator f07d1f3135 Daily bump. 2025-09-19 00:20:17 +00:00
Joseph Myers 6e4698c136 c: Add more C2Y tests
Add further tests for things defined in C2Y that correspond to how GCC
already behaves.  Some of these are for previous undefined behavior
where what is violated has become a constraint but previously was a
"shall" outside Constraints.  Others (c2y-anon-init-1.c and
c2y-incomplete-2.c) reflect semantics that were intended all along but
not correctly or sufficiently clearly stated in the standard.

Tested for x86_64-pc-linux-gnu.

	* gcc.dg/c2y-anon-init-1.c, gcc.dg/c2y-incomplete-2.c:
	gcc.dg/c2y-linkage-1.c, gcc.dg/c2y-linkage-2.c,
	gcc.dg/c2y-linkage-3.c, gcc.dg/c2y-linkage-4.c,
	gcc.dg/c2y-static-assert-1.c: New tests.
2025-09-18 22:08:04 +00:00
Jason Merrill 44e3e66a14 c++: tweak constexpr union diagnostic
It's now possible to see an active member of a union that has not actually
been initialized, so let's clarify the diagnostic.

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_eval_component_reference): Clarify diagnostic.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/constexpr-98122.C: Adjust diagnostic.
	* g++.dg/cpp26/constexpr-new6a.C: New test.
2025-09-18 23:47:39 +02:00
Jason Merrill 12975b8aa2 c++: clobber class new-expressions
Since Jakub's P2795R5 work removes the initial clobber from constructors,
let's add a clobber for new of all non-empty classes.

gcc/cp/ChangeLog:

	* init.cc (build_new_1): Clobber classes.

gcc/testsuite/ChangeLog:

	* g++.dg/analyzer/pr97116.C: Adjust diagnostic.
	* g++.dg/warn/Warray-bounds-20.C: Likewise.
2025-09-18 23:46:37 +02:00
Jason Merrill b8af1b3a00 c++: improve constexpr clobber handling
r16-3022 changed placement new to clobber the object, and improved constexpr
handling to do more with clobbers.  But it occurred to me that in a lot of
cases we don't need to introduce a constructor_elt to represent an
uninitialized member of an uninitialized struct/array.

gcc/cp/ChangeLog:

	* constexpr.cc (get_or_insert_ctor_field): -2 means don't insert.
	(cxx_eval_component_reference): Handle finding void_node.
	(cxx_eval_store_expression): Don't represent initial clobber
	unless we need to activate a union member.
	(cxx_eval_statement_list): Don't ask for a void prvalue.
	(cxx_eval_loop_expr): The expr is discarded-value.
	(cxx_eval_constant_expression): A loose clobber is non-constant.
	Handle getting void_node instead of a real result.
	(potential_constant_expression_1): A local temp is
	potentially-constant.
	* init.cc (build_new_1): Don't clobber empty types or
	in a template.
	(build_vec_init): Fix clobber handling.

gcc/testsuite/ChangeLog:

	* g++.dg/init/pr25811.C: Tweak diagnostic.
	* g++.dg/warn/Warray-bounds-12.C: Likewise.
	* g++.dg/warn/Warray-bounds-13.C: Likewise.
	* g++.dg/cpp26/constexpr-new6.C: New test.
2025-09-18 23:45:53 +02:00
Jason Merrill c91e508a52 c++: -Wmismatched-new-delete, -O0, new (nothrow)
With new (nothrow) we need to check whether the allocation returned null,
and the resulting COND_EXPR was confusing -Wmismatched-new-delete-2 at -O0.
Let's help it out by appending the address if it's the same on both arms.

gcc/cp/ChangeLog:

	* init.cc (build_new_1): Append alloc_node to checking COND_EXPR.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Wmismatched-new-delete-2.C: Remove xfail.
2025-09-18 23:45:09 +02:00
David Malcolm 423d7b24e7 diagnostics: add dump methods to client_data_hooks and logical_location_manager
gcc/ChangeLog:
	* diagnostics/client-data-hooks.h (client_data_hooks::dump): New.
	* diagnostics/context.cc (context::dump): Dump
	m_client_data_hooks.
	(client_data_hooks::dump): New.
	* diagnostics/logical-locations.h
	(logical_locations::manager::dump): New.
	* diagnostics/selftest-logical-locations.cc: Include
	"diagnostics/dumping.h".
	(test_manager::dump): New.
	* diagnostics/selftest-logical-locations.h (test_manager::dump):
	New decl.
	* libgdiagnostics.cc: Include "diagnostics/dumping.h".
	(impl_logical_location_manager::dump): New.
	* tree-logical-location.cc: Include "diagnostics/dumping.h".
	(tree_logical_location_manager::dump): New.
	* tree-logical-location.h (tree_logical_location_manager::dump):
	New decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-18 16:07:09 -04:00
David Malcolm 21fe45f111 diagnostics/libcpp: convert enum location_aspect to enum class
Modernization; no functional change intended.

gcc/ChangeLog:
	* diagnostics/paths-output.cc: Update for conversion of
	location_aspect to enum class.
	* diagnostics/source-printing.cc: Likewise.
	* input.cc: Likewise.
	* input.h: Likewise.

libcpp/ChangeLog:
	* include/line-map.h (enum location_aspect): Convert to...
	(enum class location_aspect): ...this.
	* line-map.cc: Update for conversion of location_aspect to enum
	class.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-18 16:07:04 -04:00
David Malcolm 60d7488008 diagnostics: use diagnostic.h in fewer places
No functional change intended.

gcc/ChangeLog:
	* diagnostics/buffering.cc: Drop include of "diagnostic.h".
	* diagnostics/buffering.h: Likewise.
	* diagnostics/context.h (diagnostics::metadata): Add forward decl.
	* diagnostics/html-sink.cc: Drop include of "diagnostic.h".
	* diagnostics/lazy-paths.cc: Likewise.
	* diagnostics/macro-unwinding.cc: Likewise.
	* diagnostics/macro-unwinding.h (diagnostics:diagnostic_info): Add
	forward decl.
	* diagnostics/option-classifier.h: Include
	"diagnostics/option-id.h" and "diagnostics/kinds.h".
	(diagnostics:diagnostic_info): Add forward decl.
	* diagnostics/output-spec.cc: Drop include of "diagnostic.h".
	* diagnostics/paths-output.cc: Likewise.
	* diagnostics/paths.cc: Likewise.
	* diagnostics/sarif-sink.cc: Likewise.
	* diagnostics/selftest-context.cc: Likewise.
	* diagnostics/selftest-paths.cc: Likewise.
	* diagnostics/source-printing-options.h: Include
	"rich-location.h".
	* diagnostics/text-sink.cc: Drop include of "diagnostic.h".

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-18 16:06:39 -04:00
Qing Zhao f613fdc692 Fix SRA issue with -ftrivial-auto-var-init= [PR121894]
In tree-sra.cc, for the following stmt (initialization in source code):
s = {};

for the above lhs "s", the field "grp_assignment_write" of the created
struct access is 1;

however, for the following stmt (compiler added initialization):
s = .DEFERRED_INIT (size, init_type, &"s"[0]);

for the above lhs "s", the field "grp_assignment_write" of the created
struct access is 0;

Since the field "grp_assignment_write" of the struct access for the
corresponding LHS "s" is not set correctly when the RHS is .DEFERRED_INIT,
SRA phase didn't do a correct transformation for call to .DEFERRED_INIT.

To fix this issue, we should set the field "grp_assignment_write" correctly
for .DEFERRED_INIT.

	PR tree-optimization/121894

gcc/ChangeLog:

	* tree-sra.cc (scan_function): Set grp_assignment_write to 1 when
	specially handle call to .DEFERRED_INIT.

gcc/testsuite/ChangeLog:

	* g++.dg/opt/auto-init-sra-pr121894.C: New test.
2025-09-18 18:31:33 +00:00
Paul Thomas c52c745c98 Fortran: Implement PDT constructors with syntax variants [PR114815]
2025-09-18  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/114815
	* decl.cc (gfc_get_pdt_instance): Copy the contents of 'tb' and
	not the pointer.
	* primary.cc (gfc_match_rvalue): If there is only one actual
	argument list, use if for the type spec parameter values. If
	this fails try the default type specification values and use
	the actual arguments for the component values.
	* resolve.cc (build_init_assign): Don't initialize implicit PDT
	function results.

gcc/testsuite/
	PR fortran/114815
	* gfortran.dg/pdt_3.f03: Add missing deallocation of 'matrix'.
	* gfortran.dg/pdt_17.f03: Change dg-error text.
	* gfortran.dg/pdt_47.f03: New test.
2025-09-18 19:00:08 +01:00
Zhongyao Chen 642504b41c RISC-V: Correct lmul estimation
The vectorizer's compute_estimated_lmul function could previously
return a bad value when the estimated lmul was larger than RVV_M8.
This is corrected to return RVV_M8, preventing a register spill.

The patch includes a new regression test for PR target/121910, based
on the x264 mc_chroma function. The test uses scan-tree-dump to
confirm that the compiler chooses the expected vector mode (RVVM1QI)
at -O3, verifying the fix.

	PR target/121910
gcc/ChangeLog:

	* config/riscv/riscv-vector-costs.cc (compute_estimated_lmul):
	Return RVV_M8 when estimated lmul is too large.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/pr121910.c: New file.
2025-09-18 09:32:20 -06:00
Jakub Jelinek b49f1dad54 openmp: Fix up ICE in lower_omp_regimplify_operands_p [PR121977]
The following testcase ICEs in functions called from
lower_omp_regimplify_operands_p, because maybe_lookup_decl returns
NULL for this (on the outer taskloop context) when regimplifying the
taskloop pre body.  If it isn't found in current context, we should
look in outer ones.

2025-09-18  Jakub Jelinek  <jakub@redhat.com>

	PR c++/121977
	* omp-low.cc (lower_omp_regimplify_operands_p): If maybe_lookup_decl
	returns NULL, use maybe_lookup_decl_in_outer_ctx as fallback.

	* g++.dg/gomp/pr121977.C: New test.
2025-09-18 16:41:32 +02:00
Karl Meakin 1d0a5e9fcb AArch64: Add SME LUTv2 intrinsics
Add intrinsic functions for the SME LUTv2 architecture extension
(`svluti4_zt`, `svwrite_lane_zt` and `svwrite_zt`).

gcc/ChangeLog:

	* config/aarch64/aarch64-sme.md (@aarch64_sme_write_zt<SVE_FULL:mode>): New insn.
	(aarch64_sme_lut_zt): Likewise.
	* config/aarch64/aarch64-sve-builtins-shapes.cc (parse_type): New type format "%T".
	(struct luti_lane_zt_base): New function shape.
	(SHAPE): Likewise.
	(struct write_zt_def): Likewise.
	(struct write_lane_zt_def): Likewise.
	* config/aarch64/aarch64-sve-builtins-shapes.h: New function shape.
	* config/aarch64/aarch64-sve-builtins-sme.cc (class svluti_zt_impl): New function expander.
	(class svwrite_zt_impl): Likewise.
	(class svwrite_lane_zt_impl): Likewise.
	(FUNCTION): Likewise
	* config/aarch64/aarch64-sve-builtins-sme.def (svwrite_zt): New function shape.
	(svwrite_lane_zt): Likewise.
	(svluti4_zt): Likewise.
	* config/aarch64/aarch64-sve-builtins-sme.h: New function base.
	* config/aarch64/aarch64-sve-builtins.h: Mention the arrays of function_group_info by name.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/sme2/acle-asm/svluti4_zt_1.c: New test.
	* gcc.target/aarch64/sme2/acle-asm/svwrite_lane_zt_1.c: New test.
	* gcc.target/aarch64/sme2/acle-asm/svwrite_zt_1.c: New test.
	* gcc.target/aarch64/sve/acle/general-c/svluti4_zt_1.c: New test.
	* gcc.target/aarch64/sve/acle/general-c/svwrite_lane_zt_1.c: New test.
	* gcc.target/aarch64/sve/acle/general-c/svwrite_zt_1.c: New test.
2025-09-18 15:15:49 +01:00
Karl Meakin 45ddf55353 AArch64: Add SME LUTv2 architecture extension
Add the SME LUTv2 architecture extension. Users can enable the extension
by adding `+sme-lutv2` to `-march` or `-mcpu`, and test for its presence
with the `__ARM_FEATURE_SME_LUTv2` macro. The intrinsics will be added
in the next commit.

gcc/ChangeLog:

	* config/aarch64/aarch64-c.cc (aarch64_update_cpp_builtins): Conditonally define
	`__ARM_FEATURE_SME_LUTv2" macro.
	* config/aarch64/aarch64-option-extensions.def (AARCH64_OPT_EXTENSION("sme-lutv2")): New
	optional architecture extension.
	* config/aarch64/aarch64.h (TARGET_SME_LUTv2): New macro.
	* doc/invoke.texi: Document `+sme-lutv2` flag.
2025-09-18 15:15:45 +01:00
Pan Li 80e85c627a RISC-V: Add test case of unsigned scalar SAT_MUL form 5 for widen-mul
The form 5 of unsigned scalar SAT_MUL is covered in middle-expand
alreay, add test case here to cover form 5.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/sat/sat_arith.h: Add test helper macros.
	* gcc.target/riscv/sat/sat_u_mul-6-u16-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u32-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u64-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-6-u8-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u16-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u32-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u64-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-6-u8-from-u128.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-18 21:47:25 +08:00
Pan Li f9c72bc02a Match: Add form 5 of unsigned SAT_MUL for widen-mul
This patch would like to try to match the the unsigned
SAT_MUL form 4, aka below:

  #define DEF_SAT_U_MUL_FMT_5(NT, WT)             \
  NT __attribute__((noinline))                    \
  sat_u_mul_##NT##_from_##WT##_fmt_5 (NT a, NT b) \
  {                                               \
    WT x = (WT)a * (WT)b;                         \
    NT hi = x >> (sizeof(NT) * 8);                \
    NT lo = (NT)x;                                \
    return lo | -!!hi;                            \
  }

  while WT is uint128_t, T is uint8_t, uint16_t, uint32_t or uint64_t.

gcc/ChangeLog:

	* match.pd: Add pattern for SAT_MUL form 5.
	* tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children):
	Try match pattern for IOR.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-18 21:47:25 +08:00
Jan Hubicka 8c6b6adce4 Fix verification ICE after ipa-cp
I managed to reproduce the ICE.  The error is verification error about
callgraph edge count being different from basic block count of the
corresponding call stmt.  This verification is only done for local profiles,
since IPA profiles are scaled during inlining, cloning and other
transformations.

Ipa-cp has logic special casis self recursive functions and it adjust
probability of the recursion to avoid non-sential IPA profiles.  Normally
this is not done for local profiles, however in case the IPA profile
is broken enought the earlier logic will push clone profiles to be local
which in turn causes the verifier error.

This patch simply disables the update.  Its main purpose is to keep IPA
profile seemingly meaningful and the upate is never applied back to
gimple code.  Alternative would be to add machinery to adjust frequencies
of call edges, but I do not think it is worth the effort at this moment.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

	* ipa-cp.cc (update_counts_for_self_gen_clones): Do not update
	call frequency for local profiles.
2025-09-18 14:16:30 +02:00
Richard Biener d5e80bf757 tree-optimization/87615 - VN predication is expensive
The following restricts the number of locations we register a predicate
as valid which avoids the expensive linear search for cases like

   if (a)
     A;
   if (a)
     B;
   if (a)
     C;
   ...

where we register a != 0 as true for locations A, B, C ... in an
unlimited way.  The patch simply choses 8 as limit.  The underlying
issue for this case is the data structure which does not allow for
easy "forgetting" or more optimal searching when locations become
no longer relevant (the whole point of the location list is to
represent where predicates are relevant).

The patch also splits the search/copy loop into two to avoid copying
stuff that we'll not need when finding an existing better entry or,
new now, when we figure we run over the limit.

	PR tree-optimization/87615
	* tree-ssa-sccvn.cc (vn_nary_op_insert_into): When inserting
	a new predicate or location into an existing predicate list
	make sure to not exceed 8 locations.  Avoid copying things
	when we later eventually throw them away.
	(vn_nary_op_insert_pieces_predicated): Avoid expensive check
	when not checking.
	(dominated_by_p_w_unex): Apply the limit on a single successors
	predecessor count consistently.
2025-09-18 13:09:33 +02:00
Tobias BurnusandSandra Loosemore 97c1d2fa97 OpenMP: Unshare expr in context-selector condition [PR121922]
As the testcase shows, a missing unshare_expr caused that the condition
was only evaluated once instead of every time when a 'declare variant'
was resolved.

	PR middle-end/121922

gcc/ChangeLog:

	* omp-general.cc (omp_dynamic_cond): Use 'unshare_expr' for
	the user condition.

libgomp/ChangeLog:

	* testsuite/libgomp.c-c++-common/declare-variant-1.c: New test.

Co-authored-by: Sandra Loosemore <sloosemore@baylibre.com>
2025-09-18 11:07:50 +02:00
Richard Biener c30f58c3f7 tree-optimization/121720 - missed PRE hoisting
The following re-implements the fix for PR84830 where the original
fix causes missed optimizations.  The issue with PR84830 is that
we end up growing ANTIC_IN value set during iteration which happens
because we conditionally prune values based on ANTIC_OUT - TMP_GEN
expressions.  But when ANTIC_OUT was computed including the
MAX set on one edge we fail to take into account the implicitly
represented MAX expression set.  The following rectifies this by
not pruning the value set in bitmap_set_subtract_expressions in
such case.  This avoids the pruning from the ANTIC_IN value
set when MAX is involved and thus later growing, removing the
need to explicitly prune it with the last iteration set.

	PR tree-optimization/121720
	* tree-ssa-pre.cc (bitmap_set_subtract_expressions): Add
	flag to tell whether we should copy instead of prune the
	value set.
	(compute_antic_aux): Remove intersection of ANTIC_IN with
	the old solution.  When subtracting TMP_GEN from
	ANTIC_OUT do not prune the value set when MAX was involved
	in the ANTIC_OUT computation.

	* gcc.dg/tree-ssa/ssa-pre-36.c: New testcase.
2025-09-18 09:44:15 +02:00
Jakub Jelinek c1e1691b95 libstdc++: Implement C++23 P2590R2 - Explicit lifetime management [PR106658]
As I can't think of how the middle-end would treat
__builtin_start_lifetime_as other than a blackbox and probably would
need to be implemented as such inline asm in RTL, this patch
just implements it using inline asm in the library.
If not anything else, it can serve as fallback before we and/or clang
get some builtin for it.

Right now the inline asms pretend (potential) read from and write to the whole
memory region and make optimizers forget where the return value points to.
If the optimizers don't know where it points to, I think that should be
good enough, but I'm a little bit afraid of possibly future optimizations
trying to optimize
  q->c = 1;
  q->d = 2;
  auto p = std::start_lifetime_as<S>(q);
  if (p == reinterpret_cast<decltype (p)>(q))
    return p->a + p->b;
that because of the guarding condition or perhaps assertion we could
simply use the q pointer in MEM_REFs with S type and be surprised by TBAA.
Though if it is a must-alias case, then we should be fine as well.
Though guess that would be the same case with a builtin.

2025-09-18  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106658
	* include/bits/version.def: Implement C++23 P2590R2 - Explicit
	lifetime management.
	(start_lifetime_as): New.
	* include/bits/version.h: Regenerate.
	* include/std/memory (std::start_lifetime_as,
	std::start_lifetime_as_array): New function templates.
	* src/c++23/std.cc.in (std::start_lifetime_as,
	std::start_lifetime_as_array): Export.
	* testsuite/std/memory/start_lifetime_as/start_lifetime_as.cc: New test.
2025-09-18 07:44:54 +02:00
hongtao.liu dd713d0f3f Remove SPR/GNR/DMR from avx512_{move,store}_by pieces tune.
Align move_max with prefer_vector_width for SPR/GNR/DMR similar as
below commit.

commit 6ea25c0419
Author: liuhongt <hongtao.liu@intel.com>
Date:   Thu Aug 15 12:54:07 2024 +0800

    Align ix86_{move_max,store_max} with vectorizer.

    When none of mprefer-vector-width, avx256_optimal/avx128_optimal,
    avx256_store_by_pieces/avx512_store_by_pieces is specified, GCC will
    set ix86_{move_max,store_max} as max available vector length except
    for AVX part.

                  if (TARGET_AVX512F_P (opts->x_ix86_isa_flags)
                      && TARGET_EVEX512_P (opts->x_ix86_isa_flags2))
                    opts->x_ix86_move_max = PVW_AVX512;
                  else
                    opts->x_ix86_move_max = PVW_AVX128;

    So for -mavx2, vectorizer will choose 256-bit for vectorization, but
    128-bit is used for struct copy, there could be a potential STLF issue
    due to this "misalign".

gcc/ChangeLog:

	* config/i386/x86-tune.def (X86_TUNE_AVX512_MOVE_BY_PIECES):
	Remove SPR/GNR/DMR.
	(X86_TUNE_AVX512_STORE_BY_PIECES): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pieces-memcpy-18.c: Use -mtune=znver5
	instead of -mtune=sapphirerapids.
	* gcc.target/i386/pieces-memcpy-21.c: Ditto.
	* gcc.target/i386/pieces-memset-46.c: Ditto.
	* gcc.target/i386/pieces-memset-49.c: Ditto.
2025-09-17 18:35:52 -07:00
GCC Administrator 9bd24f83a1 Daily bump. 2025-09-18 00:20:40 +00:00
David Malcolm 41f071a64f c++: improve nesting in print_z_candidate [PR121966]
Comment #2 of PR c++/121966 notes that the "inherited here" messages
should be nested *within* the note they describe.

Implemented by this patch, which also nests other notes emitted for
rejection_reason within the first note of print_z_candidate.

gcc/cp/ChangeLog:
	PR c++/121966
	* call.cc (print_z_candidate): Consolidate instances of
	auto_diagnostic_nesting_level into one, above the "inherited here"
	message so that any such message is nested within the note,
	and any messages emitted due to the switch on rejection_reason are
	similarly nested within the note.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-17 16:39:32 -04:00
David Malcolm c0b21d1f45 c++: fix count of z candidates for non-viable candidates, nesting [PR121966]
In r15-6116-gd3dd24acd74605 I updated print_z_candidates to show the
number of candidates, and a number for each candidate.

PR c++/121966 notes that the printed count is sometimes higher than
what's actually printed: I missed the case where candidates in the
list aren't printed due to not being viable.

Fixed thusly.

gcc/cp/ChangeLog:
	PR c++/121966
	* call.cc (print_z_candidates): Copy the filtering logic on viable
	candidates from the printing loop to the counting loop, so that
	num_candidates matches the number of iterations of the latter
	loop.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-17 16:39:31 -04:00
David Malcolm 76fd69ef3d testsuite: add 'std-' prefix to c++ analyzer test cases
gcc/testsuite/ChangeLog:
	* g++.dg/analyzer/unique_ptr-1.C: Rename to...
	* g++.dg/analyzer/std-unique_ptr-1.C: ...this.
	* g++.dg/analyzer/unique_ptr-2.C: Rename to...
	* g++.dg/analyzer/std-unique_ptr-2.C: ...this.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-17 16:39:31 -04:00
David Malcolm ddabda614f sarif-replay: fix uninitialized m_debug_physical_locations
In r16-2766-g7969e4859ed007 I added a new field to replay_opts
but forgot to initialize it in set_defaults.

Fixed thusly.

Spotted thanks to valgrind.

gcc/ChangeLog:
	* sarif-replay.cc (set_defaults): Initialize
	m_debug_physical_locations.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-17 16:39:31 -04:00
Andrew Pinski 2664206495 uninclude: Add lib/gcc/<anything>/include as an possible include dir
While running uninclude on PR99912's preprocessed source uninclude
didn't uninclude some of the x86_64 target headers. This was because
`lib/gcc/<anything>/include` was not noticed as an possible system
include dir. It supported `gcc-lib/<anything>/include` though.

contrib/ChangeLog:

	* uninclude: Add `lib/gcc/<anything>/include`.
2025-09-17 13:15:26 -07:00
Andrew Pinski a7a9f0de4f forwprop: Fix up "nop" copies after recent changes [PR121962]
After r16-3887-g597b50abb0d2fc, the check to see if the copy is
a nop copy becomes inefficient. The code going into an infinite
loop as the copy keeps on being propagated over and over again.

That is if we have:
```
  struct s1 *b = &a.t;
  a.t = *b;
  p = *b;
```

This goes into an infinite loop propagating over and over again the
`MEM[&a]`.
To solve this a new function is needed for the comparison that is
similar to new_src_based_on_copy.

	PR tree-optimization/121962

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (same_for_assignment): New function.
	(optimize_agr_copyprop_1): Use same_for_assignment to check for
	nop copies.
	(optimize_agr_copyprop): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-17 11:36:42 -07:00
Andrew Pinski 4b83df548f forwprop: Add a quick out for new_src_based_on_copy when both are decls
If both operands that are being compared are decls, operand_equal_p will already
handle that case so an early out can be done here.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (new_src_based_on_copy): An early out
	if both are decls.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-17 11:36:05 -07:00
Andrew Pinski 09e1ba1cc0 forwprop: Handle memcpy for arguments with respect to copies
This moves the code used in optimize_agr_copyprop_1 (r16-3887-g597b50abb0d)
to handle this same case into its new function and use it inside
optimize_agr_copyprop_arg. This allows to remove more copies that show up only
in arguments.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_agr_copyprop_1): Split out
	the case where `operand_equal_p (dest, src2)` is false into ...
	(new_src_based_on_copy): This. New function.
	(optimize_agr_copyprop_arg): Use new_src_based_on_copy
	instead of operand_equal_p to find the new src.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/copy-prop-aggregate-arg-2.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-17 11:35:39 -07:00
Patrick Palka 3268c47c08 libstdc++/ranges: Fix more wrong value type init from reference type [PR111861]
As in r16-3912-g412a1f78b53709, this fixes some other spots where we
wrongly use a deduced type and non-direct-initialization when trying
to initialize a value type from an iterator's reference type.

	PR libstdc++/111861

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h (ranges::unique_copy): When
	initializing a value type object from *iter, use
	direct-initialization and don't use a deduced type.
	(ranges::push_heap): Use direct-initialization when initializing
	a value type object from ranges::iter_move.
	(ranges::max): As in ranges::unique_copy.
	* include/bits/ranges_util.h (ranges::min): Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-09-17 14:14:37 -04:00
Thomas Koenig 9a68895fee Implement -fexternal-blas64 option.
Libraries like Intel MKL use 64-bit integers in their API, but gfortran
up to now only provides external BLAS for matmul with 32-bit
integers.  This straightforward patch provides a new option -fexternal-blas64
to remedy that situation.

gcc/fortran/ChangeLog:

	* frontend-passes.cc (optimize_namespace): Handle
	flag_external_blas64.
	(call_external_blas): If flag_external_blas is set, use
	gfc_integer_4_kind as the argument kind, gfc_integer_8_kind otherwise.
	* gfortran.h (gfc_integer_8_kind): Define.
	* invoke.texi: Document -fexternal-blas64.
	* lang.opt: Add -fexternal-blas64.
	* lang.opt.urls: Regenerated.
	* options.cc (gfc_post_options): -fexternal-blas is incompatible
	with -fexternal-blas64.

gcc/testsuite/ChangeLog:

	* gfortran.dg/matmul_blas_3.f90: New test.
2025-09-17 18:50:22 +02:00
Shreya Munnangi cda451531c [PR tree-optimization/58727] Don't over-simplify constants`
Here's Shreya's next patch.

In pr58727 we have a case where the tree/gimple optimizers have decided to
"simplify" constants involved in logical ops by turning off as many bits as
they can in the hope that the simplified constant will be easier/smaller to
encode.  That "simplified" constant gets passed down into the RTL optimizers
where it can ultimately cause a missed optimization.

Concretely let's assume we have insns 6, 7, 8 as shown in the combine dump
below:

> Trying 6, 7 -> 9:
>     6: r139:SI=r141:SI&0xfffffffffffffffd
>       REG_DEAD r141:SI
>     7: r140:SI=r139:SI&0xffffffffffbfffff
>       REG_DEAD r139:SI
>     9: r137:SI=r140:SI|0x2
>       REG_DEAD r140:SI

We can obviously see that insn 6 is redundant as the bit we turn off would be
turned on by insn 9.  But combine ultimately tries to generate:

> (set (reg:SI 137 [ _3 ])
>     (ior:SI (and:SI (reg:SI 141 [ a ])
>             (const_int -4194305 [0xffffffffffbffffd]))
>         (const_int 2 [0x2])))

That does actually match a pattern on RISC-V, but it's a pattern that generates
two bit-clear insns (or a bit-clear followed by andi and a pattern we'll be
removing someday).  But if instead we IOR 0x2 back into the simplified constant
we get:

> (set (reg:SI 137 [ _3 ])
>     (ior:SI (and:SI (reg:SI 141 [ a ])
>             (const_int -4194305 [0xffffffffffbfffff]))
>         (const_int 2 [0x2])))

That doesn't match, but when split by generic code in the combiner we get:

> Successfully matched this instruction:
> (set (reg:SI 140)
>     (and:SI (reg:SI 141 [ a ])
>         (const_int -4194305 [0xffffffffffbfffff])))
> Successfully matched this instruction:
> (set (reg:SI 137 [ _3 ])
>     (ior:SI (reg:SI 140)
>         (const_int 2 [0x2])))

Which is bclr+bset/ori.  ie, we dropped one of the logical AND operations.

Bootstrapped and regression tested on x86 and riscv.  Regression tested on the
30 or so embedded targets as well without new failures.

I'll give this a couple days for folks to chime in before pushing on Shreya's
behalf.  This doesn't fix pr58727 for the other targets as they would need
target dependent hackery.

Jeff

	PR tree-optimization/58727
gcc/
	* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
	In (A & C1) | C2, if (C1|C2) results in a constant with a single bit
	clear, then adjust C1 appropriately.

gcc/testsuite/
	* gcc.target/riscv/pr58727.c: New test.
2025-09-17 07:43:48 -06:00
Richard Biener f8cf09130b [gimplefe] fix SSA operand creation
When transitioning gcc.dg/torture/pr84830.c to a GIMPLE testcase to
feed the IL into PRE that caused the original issue (and verify it's
still there with the fix reverted), I noticed we put up SSA operands
before having fully parsed the function and thus with not all
variables having the final TREE_ADDRESSABLE state.  The following
fixes this, delaying update_stmt calls to when we create PHI nodes.
It also makes the pr84830.c not rely on the particular fake exit
edge source location by making the loop have an exit.

gcc/c/
	* gimple-parser.cc (c_parser_parse_gimple_body): Initialize
	SSA operands for each stmt.
	(c_parser_gimple_compound_statement): Append stmts without
	updating SSA operands.

gcc/testsuite/
	* gcc.dg/torture/pr84830.c: Turn into GIMPLE unit test for PRE.
2025-09-17 15:36:44 +02:00
Stefan Schulze Frielinghaus 282c1e682e s390: testsuite: Fix bitops-{1,2}.c and andc-splitter-2.c
After r16-2649-g0340177d54d tests fail for
gcc.target/s390/arch13/bitops-{1,2}.c since sign extends in conjunction
with (subreg (not a)) are folded, now.  That is, of course, wanted.
Since the original tests were about 32-bit operations, circumvent the
sign extend by not returning a value but rather writing it to memory.

Similar for andc-splitter-2.c sign extends are folded there, too.  Since
the test is not about 32- or 64-bit adjust the scan assembler directives
only.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/arch13/bitops-1.c: Do not return a 32bit value
	but write it to memory.
	* gcc.target/s390/arch13/bitops-2.c: Ditto.
	* gcc.target/s390/md/andc-splitter-2.c: Adjust scan assembler
	directive because sign extends are folded, now.
2025-09-17 13:12:30 +02:00
Eric Botcazou d81e24bbb9 Preserve TREE_THIS_NOTRAP during inlining in more cases
For parameters passed by reference, the Ada compiler sets TREE_THIS_NOTRAP
on their dereference to prevent tree_could_trap_p from returning true and
then causing a new basic block to be created for every access to them,
given that in Ada the -fnon-call-exceptions flag is enabled by default.

However, when the subprogram is inlined, this TREE_THIS_NOTRAP flag cannot
be blindly preserved because the call may pass the dereference of a pointer
as the argument: even if the compiler generates a check that the pointer is
not null just before, preserving TREE_THIS_NOTRAP could cause an access to
be hoisted before the check; therefore it gets cleared for parameters.

Now that's suboptimal if the argument is a full object because accessing it
through the dereference of the parameter cannot trap, which causes MEM_REFs
of the form MEM_REF [&DECL] to be considered as trapping in the case where
the nominal subtype of DECL is self-referential.

gcc/
	* tree-inline.cc (maybe_copy_this_notrap): New function.  Also copy
	the TREE_THIS_NOTRAP flag for parameters when the argument is a full
	object and the parameter's type is self-referential.
	(remap_gimple_op_r): Call maybe_copy_this_notrap.
	(copy_tree_body_r): Likewise.
2025-09-17 11:38:26 +02:00
Iain Sandoe 8a7346964d testsuite, objective-c: Fix duplicate test names in 'special'.
For macOS/Darwin, we run Objective-C tests for both the GNU and
NeXT runtimes (and these runs are usually differentiated by
identifying the runtime in the test name).

However, the 'special' sub-set of tests had a non-standard driver
since it needs two sources for each test (but did not report the
runtime in the test name and so shows duplicates).

We can now automate the multi-source case with dg-additional-sources
but need to do a little work to filter these additional sources
from the set (since they also have a .m suffix).

This addresses the FIXME in the original driver.

To resolve the duplicated names, means amending the reported name
to include the runtime as a differentiator, this means that test
comparisons will temporarily report new and missing tests for any
comparison that includes this change.

gcc/testsuite/ChangeLog:

	* objc.dg/special/load-category-1.m: Add second source.
	* objc.dg/special/load-category-2.m: Likewise.
	* objc.dg/special/load-category-3.m: Likewise.
	* objc.dg/special/unclaimed-category-1.m: Likewise.
	* objc.dg/special/special.exp: Rewrite to make use of generic
	testsuite facilities.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-09-17 09:03:58 +01:00
Torbjörn SVENSSON 1cf8cb45d8 testsuite: arm: Simplify fp16-aapcs tests
Reduce fp16-aapcs testcases to return value testing since parameter
passing are already tested in aapcs/vfp*.c

gcc/testsuite/ChangeLog:
	* gcc.target/arm/fp16-aapcs.c: New test.
	* gcc.target/arm/fp16-aapcs-1.c: Removed.
	* gcc.target/arm/fp16-aapcs-2.c: Likewise.
	* gcc.target/arm/fp16-aapcs-3.c: Likewise.
	* gcc.target/arm/fp16-aapcs-4.c: Likewise.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2025-09-17 09:56:11 +02:00
Tobias Burnus da5803c794 libgomp: Init hash table for 'indirect'-clause of 'declare target' on the host [PR114445, PR119857]
Especially with unified-shared memory and especially with C++'s virtual
functions, it is not uncommon to have on the device a function pointer
that points to the host function - but has an associated device.
If the pointed-to function is (explicitly or implicitly) 'declare target'
with the 'indirect' clause, it is added to the lookup table.

Before this commit, the conversion of the lookup table into a lookup
hash table happened every time a device kernel was launched on the first
team - albeit if already converted, the function immediately returned.

Ignoring the overhead, there was also a race: If multiple teams were
launched, it could happen that another team of the same target region
already tried to use the lookup table which it was still being created.
Likewise when lauching a kernel with 'nowait' and directly afterward
another kernel, there could be a race of creating the table.

With this commit, the creating of the kernel has been moved to the
host-plugin's GOMP_OFFLOAD_load_image. The previous code stored a
pointer to the host/device pointer array, which makes it hard when
creating the hash table on the host (data is needed for finding the
slot) - but accessing it on the device (where the lookup has to work
as well). As the hash-table implementation (only) supports integral
value as payload (0 and 1 having special meaning), the solution was
to move to an uint128_t variable to store both the host and device
address.

As the host-side library is typically dynamically linked and the
device-side one statically, there is the problem of backward
compatibility. The current implementation permits both older
binaries and newer libgomp and newer binaries with older libgomp.
I could imagine us breaking the latter eventually, but for now
there is up and downward compatibility. (Obviously, the race is
only fixed if new + new is combined.)

Code wise, on the device exist GOMP_INDIRECT_ADDR_MAP which was
updated to point to the host/device-address array. Now additionally
GOMP_INDIRECT_ADDR_HMAP exists, which contains the hash-table map.

If the latter exists, libgomp only updates it and the former remains
a NULL pointer; it is also untouched if there are no indirect functions.
Being NULL therefore avoids the call to the device-side build_indirect_map.
The code also currently supports to have no hash and a linear walk. I think
that remained from testing; due to the backward-compat feature, it can
actually be turned of on either side.

libgomp/ChangeLog:

	PR libgomp/119857
	PR libgomp/114445
	* config/accel/target-indirect.c: Change to use uint128_t instead
	of a struct as data structure and add GOMP_INDIRECT_ADDR_HMAP as
	host-accessible variable.
	(struct indirect_map_t): Remove.
	(USE_HASHTAB_LOOKUP, INDIRECT_DEV_ADDR, INDIRECT_HOST_ADDR,
	SET_INDIRECT_HOST_ADDR, SET_INDIRECT_ADDRS): Define.
	(htab_free): Use __builtin_unreachable.
	(htab_hash, htab_eq, GOMP_target_map_indirect_ptr,
	build_indirect_map): Update for new representation and new
	pointer-to-hash variable.
	* config/gcn/team.c (gomp_gcn_enter_kernel): Only call
	build_indirect_map when GOMP_INDIRECT_ADDR_MAP.
	* config/nvptx/team.c (gomp_nvptx_main): Likewise.
	* libgomp-plugin.h (GOMP_INDIRECT_ADDR_HMAP): Define.
	* plugin/plugin-gcn.c: Conditionally include
	build-target-indirect-htab.h.
	(USE_HASHTAB_LOOKUP_FOR_INDIRECT): Define.
	(create_target_indirect_map): New prototype.
	(GOMP_OFFLOAD_load_image): Update to create the device's
	indirect-function hash table on the host.
	* plugin/plugin-nvptx.c: Conditionally include
	build-target-indirect-htab.h.
	(USE_HASHTAB_LOOKUP_FOR_INDIRECT): Define.
	(create_target_indirect_map): New prototype.
	(GOMP_OFFLOAD_load_image): Update to create the device's
	indirect-function hash table on the host.
	* plugin/build-target-indirect-htab.h: New file.
2025-09-17 08:47:36 +02:00
Tobias Burnus 16d2b8881c libgomp: Add Fortran version of acc_copyout_finalize_async and acc_delete_finalize_async
OpenACC 2.5 added several functions for C and Fortran; while
acc_{copyout,delete}{,_finalize,_async} exist for both, for some
reasons only the C version of acc_{copyout,delete}_finalize_async
was actually added, even though the documentation (.texi) and
the .map file listed also the auxiliar Fortran functions!

OpenACC 2.5 added the Fortran version with the following odd
interface:  'type, dimension(:[,:]...)'. In OpenACC 2.6, it
was then updated to the Fortran 2018 syntax:
'type(*), dimension(..)', which is also used in openacc.f90
internally.
This commit now also updates the documentation to the newer
syntax - plus fixes a function-name typo: acc_delete_async_finalize
should have the _async at the end not in the middle!

libgomp/ChangeLog:

	* libgomp.map (OACC_2.5): Move previously unimplemented
	acc_{copyout,delete}_finalize_async_{32,64,array}_h_ to ...
	(OACC_2.6.1): ... here.
	* libgomp.texi (acc_copyin, acc_present_or_copyin, acc_create,
	acc_present_or_create, acc_copyout, acc_update_device,
	acc_update_self, acc_is_present): Use 'type(*), dimension(..)'
	instead of 'type, dimension(:[,:]...)' for Fortran.
	(acc_delete): Likewise; change acc_delete_async_finalize to
	acc_delete_finalize_async.
	* openacc.f90 (openacc_internal): Add interfaces for
	acc_{copyout,delete}_finalize_async_{{32,64,array}_h,_l}.
	(openacc): Add generic interfaces for
	acc_copyout_finalize_async and acc_delete_finalize_async.
	(acc_{copyout,delete}_finalize_async_{32,64,array}_h): New.
	* openacc_lib.h: Add generic interfaces for
	acc_copyout_finalize_async and acc_delete_finalize_async.
	* testsuite/libgomp.oacc-fortran/pr92970-1.f90: New test.
2025-09-17 08:43:58 +02:00
Pan Li f666b14cf1 RISC-V: Add test for vec_duplicate + vwmulu.vv signed combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vwmulu.vv
combine to vwmulu.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
	for vwmulu.vx.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen.h: Add test helper
	macros.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen_data.h: Add test
	data for vwmulu.vx run test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vwmulu-run-1-u64.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-17 11:42:20 +08:00
Pan Li f3d6d41abf RISC-V: Add test for vec_duplicate + vwsubu.vv signed combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vwsubu.vv
combine to vwsubu.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
	for vwsubu.vx.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen.h: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen_data.h: Add test
	data for run test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vwsubu-run-1-u64.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-17 11:42:20 +08:00
Pan Li b653093572 RISC-V: Add test for vec_duplicate + vwaddu.vv signed combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vwaddu.vv
combine to vwaddu.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
	for vwaddu.vx.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vwaddu-run-1-u64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen.h: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen_data.h: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_widen_vx_run.h: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-17 11:42:19 +08:00
Pan Li 638320686c RISC-V: Combine vec_duplicate + vwaddu.vv to vwaddu.vx on GR2VR cost
This patch would like to combine the vec_duplicate + vwaddu.vv to the
vwaddu.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

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

Before this patch:
  11       beq a3,zero,.L8
  12       vsetvli a5,zero,e32,m1,ta,ma
  13       vmv.v.x v2,a2
  ...
  16   .L3:
  17       vsetvli a5,a3,e32,m1,ta,ma
  ...
  22       vwaddu.vv v1,v2,v3
  ...
  25       bne a3,zero,.L3

After this patch:
  11       beq a3,zero,.L8
  ...
  14    .L3:
  15       vsetvli a5,a3,e32,m1,ta,ma
  ...
  20       vwaddu.vx v1,a2,v3
  ...
  23       bne a3,zero,.L3

The pattern of this patch only works on DImode, aka below pattern.
v1:RVVM1DImode = (zero_extend:RVVM1DImode v2:RVVM1SImode)
  + (vec_dup:RVVM1DImode (zero_extend:DImode x2:SImode));

Unfortunately, for uint16_t to uint32_t or uint8_t to uint16_t, we loss
this extend op after expand.

For uint16_t => uint32_t we have:
(set (reg:SI 149) (subreg/s/v:SI (reg/v:DI 146 [ rs1 ]) 0))

For uint32_t => uint64_t we have:
(set (reg:DI 148 [ _6 ])
     (zero_extend:DI (subreg/s/u:SI (reg/v:DI 146 [ rs1 ]) 0)))

We can see there is no zero_extend for uint16_t to uint32_t, and we
cannot hit the pattern above.  So the combine will try below pattern
for uint16_t to uint32_t.

v1:RVVM1SImode = (zero_extend:RVVM1SImode v2:RVVM1HImode)
  + (vec_dup:RVVM1SImode (subreg:SIMode (:DImode x2:SImode)))

But it cannot match the vwaddu sematics, thus we need another handing
for the vwaddu.vv for uint16_t to uint32_t, as well as the uint8_t to
uint16_t.

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*widen_first_<any_extend:su>_vx_<mode>):
	Add helper bridge pattern for vwaddu.vx combine.
	(*widen_<any_widen_binop:optab>_<any_extend:su>_vx_<mode>): Add
	new pattern to match vwaddu.vx combine.
	* config/riscv/iterators.md: Add code attr to get extend CODE.
	* config/riscv/vector-iterators.md: Add Dmode iterator for
	widen.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-17 11:42:19 +08:00
Haochen Jiang 39c7b08d4e i386/testsuite: Correct res_ref2 array size for avx512bw-vpmov{,us}wb-2.c
Both of the tests under 128 bit are raising:

warning: writing 16 bytes into a region of size 8 [-Wstringop-overflow=]

when compiling, leading to a test fail. The warning is caused by the
incorrect array size for res_ref2. The wrong size caused the overflow.

Correct them in this patch to fix the test fail.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/avx512bw-vpmovuswb-2.c: Correct res_ref2
	array size.
	* gcc.target/i386/avx512bw-vpmovwb-2.c: Ditto.
2025-09-17 11:03:34 +08:00
Haochen Jiang 0aef0232ee i386/testsuite: Fix scan tree dump in vect-epilogue-4.c
vect-epilogue-4.c uses mask 64 byte to vectorize in epilogue part.
Similar as r16-876 fix for vect-epilogue-5.c, we need to adjust the
scan tree dump.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/vect-epilogues-4.c: Fix for epilogue
	vect tree dump.
2025-09-17 11:03:27 +08:00
Patrick Palka e690b97761 libstdc++: Explicitly pass -Wsystem-headers in tests that need it
When running libstdc++ tests using an installed gcc (as opposed to an
in-tree gcc), we naturally use system stdlib headers instead of the
in-tree headers.  But warnings from within system headers are suppressed
by default, so tests that check for such warnings spuriously fail in such
a setup.  This patch makes us compile such tests with -Wsystem-headers so
that they consistently pass.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/bind/dangling_ref.cc: Compile with
	-Wsystem-headers.
	* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Likewise.
	* testsuite/20_util/unique_ptr/lwg4148.cc: Likewise.
	* testsuite/29_atomics/atomic/operators/pointer_partial_void.cc:
	Likewise.
	* testsuite/30_threads/packaged_task/cons/dangling_ref.cc:
	Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-09-16 20:59:10 -04:00
GCC Administrator 02666ff894 Daily bump. 2025-09-17 00:20:31 +00:00
Andrew Pinski df5088e9a2 c: Reject gimple and rtl functions as needed functions [PR121421]
These two don't make sense as nested functions as they both don't handle
the unnesting and/or have support for the static chain.

So let's reject them.

Bootstrapped and tested on x86_64-linux-gnu.

	PR c/121421

gcc/c/ChangeLog:

	* c-parser.cc (c_parser_declaration_or_fndef): Error out for gimple
	and rtl functions as nested functions.

gcc/testsuite/ChangeLog:

	* gcc.dg/gimplefe-error-16.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-16 15:28:48 -07:00
Jakub Jelinek 5eb86c29d2 docs: Adjust -Wimplicit-fallthrough= documentation for C23
I've noticed in -Wimplicit-fallthrough= documentation we talk about
[[fallthrough]]; for C++17 but don't mention that it is also standard
way to suppress the warning for C23.

2025-09-16  Jakub Jelinek  <jakub@redhat.com>

	* doc/invoke.texi (Wimplicit-fallthrough=): Document that also C23
	provides a standard way to suppress the warning with [[fallthrough]];.
2025-09-16 19:26:48 +02:00
Jonathan Wakely 5d774ec80b libstdc++: Optimize determination of std::tuple_cat return type
The std::tuple_cat function has to determine a std::tuple return type
from zero or more tuple-like arguments. This uses the __make_tuple class
template to transform a tuple-like type into a std::tuple, and the
__combine_tuples class template to combine zero or more std::tuple types
into a single std::tuple type.

This change optimizes the __make_tuple class template to use an
_Index_tuple and pack expansion instead of recursive instantiation, and
optimizes __combine_tuples to use fewer levels of recursion.

For ranges::adjacent_view's __detail::__repeated_tuple helper we can
just use the __make_tuple class template directly, instead of doing
overload resolution on std::tuple_cat to get its return type.

libstdc++-v3/ChangeLog:

	* include/std/ranges (__detail::__repeated_tuple): Use
	__make_tuple helper alias directly, instead of doing overload
	resolution on std::tuple_cat.
	* include/std/tuple (__make_tuple_impl): Remove.
	(__do_make_tuple): Replace recursion with _Index_tuple and pack
	expansion.
	(__make_tuple): Adjust to new __do_make_tuple definition.
	(__combine_tuples<tuple<T1s...>, tuple<T2s...>, Rem...>): Replace
	with a partial specialization for exactly two tuples and a
	partial specialization for three or more tuples.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-09-16 18:25:02 +01:00
Jonathan Wakely 412a1f78b5 libstdc++: ranges::rotate should not use 'auto' with ranges::iter_move [PR121913]
The r16-3835-g7801236069a95c change to use ranges::iter_move should also
have used iter_value_t<_Iter> to ensure we get an object of the value
type, not a proxy reference.

libstdc++-v3/ChangeLog:

	PR libstdc++/121913
	* include/bits/ranges_algo.h (__rotate_fn::operator()): Use
	auto_value_t<_Iter> instead of deduced type.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-09-16 17:38:56 +01:00
Jonathan Wakely 0c762f79a9 libstdc++: Fix missing change to views::pairwise from P2165R4 [PR121956]
ranges::adjacent_view::_Iterator::value_type should have been changed by
r14-8710-g65b4cba9d6a9ff to always produce std::tuple, even for the
N == 2 views::pairwise specialization.

libstdc++-v3/ChangeLog:

	PR libstdc++/121956
	* include/std/ranges (adjacent_view::_Iterator::value_type):
	Always define as std::tuple<T, N>, not std::pair<T, T>.
	* testsuite/std/ranges/adaptors/adjacent/1.cc: Check value type
	of views::pairwise.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-09-16 17:38:41 +01:00
Takayuki 'January June' Suwa fe7cf719a9 xtensa: Simplify the definition of REGNO_OK_FOR_BASE_P() and avoid calling it directly
In recent gcc versions, REGNO_OK_FOR_BASE_P() is not called directly, but
rather via regno_ok_for_base_p() which is a wrapper in gcc/addresses.h.
The wrapper obtains a hard register number from pseudo via reg_renumber
array, so REGNO_OK_FOR_BASE_P() does not need to take this into
consideration.

On the other hand, since there is only one use of REGNO_OK_FOR_BASE_P()
in the target-specific code, it would make more sense to simplify the
definition of REGNO_OK_FOR_BASE_P() and replace its call with that of
regno_ok_for_base_p().

gcc/ChangeLog:

	* config/xtensa/xtensa.cc (#include):
	Add "addresses.h".
	* config/xtensa/xtensa.h (REGNO_OK_FOR_BASE_P):
	Simplify to just a call to GP_REG_P().
	(BASE_REG_P): Replace REGNO_OK_FOR_BASE_P() with the equivalent
	call to regno_ok_for_base_p().
2025-09-16 09:08:30 -07:00
Wilco Dijkstra 5b531aa5cc AArch64: Add isnan expander [PR 66462]
Add an expander for isnan using integer arithmetic.  Since isnan is
just a compare, enable it only with -fsignaling-nans to avoid
generating spurious exceptions.  This fixes part of PR66462.

int isnan1 (float x) { return __builtin_isnan (x); }

Before:
	fcmp	s0, s0
	cset	w0, vs
	ret

After:
	fmov	w1, s0
	mov	w0, -16777216
	cmp	w0, w1, lsl 1
	cset	w0, cc
	ret

gcc:
	PR middle-end/66462
	* config/aarch64/aarch64.md (isnan<mode>2): Add new expander.

gcc/testsuite:
	PR middle-end/66462
	* gcc.target/aarch64/pr66462.c: Update test.
2025-09-16 12:31:13 +00:00
Richard Biener e717aabb6e Unify last two vect_transform_slp_perm_load calls
The following unifies the vect_transform_slp_perm_load call done
in vectorizable_load with that eventually done in get_load_store_type.
On the way it fixes the conditions on which we can allow
VMAT_ELEMENTWISE or VMAT_GATHER_SCATTER when there's a SLP permutation
(and we arrange to not code generate that).  In particular that only
works for single-lane SLP of non-grouped loads or groups of size one.
VMAT_ELEMENTWISE does not (yet?) materialize a permutation upon
vector build but still relies on vect_transform_slp_perm_load.

	* tree-vect-stmts.cc (get_load_store_type): Get in a flag
	whether a SLP_TREE_LOAD_PERMUTATION on the node can be
	code generated and use it.  Fix the condition on using
	strided gather/scatter to avoid dropping a meaningful
	permutation.
	(vectorizable_store): Adjust.
	(vectorizable_load): Analyze the permutation early and
	pass the result down to get_load_store_type.  Fix the
	condition on when we are allowed to elide a load permutation.
2025-09-16 13:27:38 +02:00
Jonathan Wakely 0810be83c1 libstdc++: Do not use _GLIBCXX_MAKE_MOVE_ITERATOR for C++17
The _GLIBCXX_MAKE_MOVE_ITERATOR macro is needed for code that needs to
compile as C++98, where it just produces the original iterator. In
std::uninitialized_move and std::uninitialized_move_n we can just call
std::make_move_iterator directly.

libstdc++-v3/ChangeLog:

	* include/bits/stl_uninitialized.h (uninitialized_move)
	(uninitialized_move_n): Replace _GLIBCXX_MAKE_MOVE_ITERATOR with
	std::make_move_iterator.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-09-16 10:57:36 +01:00
Jonathan Wakely 0067696c67 libstdc++: Fix more missing uses of iter_difference_t [PR119820]
libstdc++-v3/ChangeLog:

	PR libstdc++/119820
	* include/bits/ranges_algo.h (__shuffle_fn): Use
	ranges::distance to get difference type value to add to
	iterator.
	* include/std/format (__formatter_str::_M_format_range):
	Use ranges::next to increment iterator by a size_t value.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-09-16 10:57:36 +01:00
Jennifer Schmitz 5690b710a1 aarch64: Force vector in SVE gimple_folder::fold_active_lanes_to.
An ICE was reported in the following test case:
svint8_t foo(svbool_t pg, int8_t op2) {
      return svmul_n_s8_z(pg, svdup_s8(1), op2);
}
with a type mismatch in 'vec_cond_expr':
_4 = VEC_COND_EXPR <v16_2(D), v32_3(D), { 0, ... }>;

The reason is that svmul_impl::fold folds calls where one of the operands
is all ones to the other operand using
gimple_folder::fold_active_lanes_to. However, we implicitly assumed
that the argument that is passed to fold_active_lanes_to is a vector
type. In the given test case op2 is a scalar type, resulting in the type
mismatch in the vec_cond_expr.

This patch fixes the ICE by forcing a vector type of the argument
in fold_active_lanes_to before the statement with the vec_cond_expr.

In the initial version of this patch, the force_vector statement was placed in
svmul_impl::fold, but it was moved to fold_active_lanes_to to align it with
fold_const_binary which takes care of the fixup from scalar to vector
type using vector_const_binop.

The patch was bootstrapped and tested on aarch64-linux-gnu, no regression.
OK for trunk?
OK to backport to GCC 15?

Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>

gcc/
	PR target/121602
	* config/aarch64/aarch64-sve-builtins.cc
	(gimple_folder::fold_active_lanes_to): Add force_vector
	statement.

gcc/testsuite/
	PR target/121602
	* gcc.target/aarch64/sve/acle/asm/mul_s16.c: New test.
	* gcc.target/aarch64/sve/acle/asm/mul_s32.c: Likewise.
	* gcc.target/aarch64/sve/acle/asm/mul_s64.c: Likewise.
	* gcc.target/aarch64/sve/acle/asm/mul_s8.c: Likewise.
	* gcc.target/aarch64/sve/acle/asm/mul_u16.c: Likewise.
	* gcc.target/aarch64/sve/acle/asm/mul_u32.c: Likewise.
	* gcc.target/aarch64/sve/acle/asm/mul_u64.c: Likewise.
	* gcc.target/aarch64/sve/acle/asm/mul_u8.c: Likewise.
2025-09-16 10:58:56 +02:00
Ronan Desplanques df2538ea76 ada: Fix error message for Stream_Size
Before this patch, confirming Stream_Size aspect specifications on
elementary types were incorrectly rejected when the stream size was 128,
and the error messages emitted for Stream_Size aspect errors gave
incorrect possible values.

This patch fixes this. The most significant part of the fix is a new
subprogram in Exp_Strm, Get_Primitives, that makes it possible to
retrieve a precise list of supported stream sizes, but also to select
the right runtime streaming primitives for a given type. Using the
latter, this patch factorizes code that was present in both
Build_Elementary_Input_Call and Build_Elementary_Write_Call.

gcc/ada/ChangeLog:

	* exp_strm.ads (Get_Primitives): New function.
	* exp_strm.adb (Get_Primitives): Likewise.
	(Build_Elementary_Input_Call, Build_Elementary_Write_Call): use
	Get_Primitives.
	(Has_Stream_Standard_Rep): Add formal parameter and rename to...
	(Is_Stream_Standard_Rep): New function.
	* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Fix error
	emission.
2025-09-16 10:18:51 +02:00
Gary Dismukes bc4d53dadb ada: Revert "Remove dependence on secondary stack for type with controlled component"
This reverts commit 91b51fc42b.
2025-09-16 10:18:51 +02:00
Iain Sandoe f94a461641 Ada, libgnarl: Fix Ada bootstrap for Darwin.
Recent changes to Ada have produced a new diagnostic:
s-osinte.adb:34:18: warning: unit "Interfaces.C.Extensions"...
which causes a bootstrap fail on Darwin when Ada is enabled.

Fixed thus.

	PR ada/114065

gcc/ada/ChangeLog:

	* libgnarl/s-osinte__darwin.adb: Add and reference clause
	for Interfaces.C, remove clause for Interfaces.C.Extensions.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-09-16 08:24:56 +01:00
Jiawei 41d8c4e150 RISC-V: Allow profiles input in '--with-arch' option.
Allows profiles input in '--with-arch'. Check profiles with
'riscv-profiles.def'.

gcc/ChangeLog:

	* config.gcc: Accept RISC-V profiles in `--with-arch`.
	* config/riscv/arch-canonicalize: Add profile detection and
	skip canonicalization for profiles.
2025-09-15 21:56:05 -06:00
Jiawei 3e59b15a53 RISC-V: Configure Profiles definitions in the definition file.
Moving RISC-V Profiles definations into 'riscv-profiles.def'. Add comments for
'riscv_profiles'.

gcc/ChangeLog:

	* common/config/riscv/riscv-common.cc (struct riscv_profiles): Add comments.
	(RISCV_PROFILE): Removed.
	* config/riscv/riscv-profiles.def: New file.
2025-09-15 21:54:32 -06:00
Dongyan Chen 3e932d6384 RISC-V: Imply zicsr for sdtrig and ssstrict extensions.
This patch implies zicsr for sdtrig and ssstrict extensions.
According to the riscv-privileged spec, the sdtrig and ssstrict extensions
are privileged extensions, so they should imply zicsr.

gcc/ChangeLog:

	* config/riscv/riscv-ext.def: Imply zicsr.
2025-09-15 21:49:15 -06:00
Haochen Jiang 89a7d765ec i386/testsuite: Fix non unique name tests
After r16-3651, compare_tests script will explicitly mention those
tests have the same name. This helps us review all the tests we have.

Among them, most of them are unintentional typos (e.g., keep testing
the same vector size for scan-assembler). Fix them through this commit.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/avx512bw-vpackssdw-1.c:
	Fix xmm/ymm mask tests.
	* gcc.target/i386/avx512bw-vpacksswb-1.c: Ditto.
	* gcc.target/i386/avx512bw-vpackusdw-1.c: Ditto.
	* gcc.target/i386/avx512bw-vpackuswb-1.c: Ditto.
	* gcc.target/i386/avx512bw-vpermw-1.c: Test xmm.
	* gcc.target/i386/avx512bw-vpmulhw-1.c:
	Fix xmm/ymm mask tests.
	* gcc.target/i386/avx512f-vec-init.c: Remove duplicate test.
	* gcc.target/i386/avx512fp16-13.c: Fix test for aligned load.
	* gcc.target/i386/avx512fp16-conjugation-1.c: Revise the test
	to test more precisely on masks.
	* gcc.target/i386/avx512fp16vl-conjugation-1.c: Ditto.
	* gcc.target/i386/avx512vbmi-vpermb-1.c: Test xmm.
	* gcc.target/i386/avx512vl-vcvtpd2ps-1.c: Fix scan asm.
	* gcc.target/i386/avx512vl-vinsert-1.c: Fix typo.
	* gcc.target/i386/avx512vl-vpmulld-1.c:
	Fix xmm/ymm mask tests.
	* gcc.target/i386/avx512vl-vptestmd-1.c: Ditto.
	* gcc.target/i386/bitwise_mask_op-1.c: Fix typo.
	* gcc.target/i386/cond_op_shift_q-1.c: Test both vpsra{,v}
	and vpsll{,v}.
	* gcc.target/i386/cond_op_shift_ud-1.c: Ditto.
	* gcc.target/i386/cond_op_shift_uq-1.c: Ditto.
	* gcc.target/i386/memcpy-pr95886.c: Fix the wrong const int.
	* gcc.target/i386/part-vect-sqrtph-1.c: Remove duplicate test.
	* gcc.target/i386/pr107432-7.c: Test vpmov{s,z}xbw instead of
	vpmov{s,z}xbd.
	* gcc.target/i386/pr88828-0.c: Fix pblendw scan asm.
2025-09-16 10:53:27 +08:00
liuhongt c0cda069ba Optimize vpermpd to vbroadcastf128 for specific permutations.
gcc/ChangeLog:

	* config/i386/predicates.md (avx_vbroadcast128_operand): New
	predicate.
	* config/i386/sse.md (*avx_vbroadcastf128_<mode>_perm): New
	pre_reload splitter.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/avx_vbroadcastf128.c: New test.
2025-09-15 18:45:37 -07:00
GCC Administrator a6c1787aad Daily bump. 2025-09-16 00:20:53 +00:00
Alexandre Oliva 770cbd759d [analyzer] another function name that returns a pointer to errno
Add __get_errno_ptr() as yet another synonym for __errno_location.

for  gcc/analyzer/ChangeLog

	* kf.cc (register_known_functions): Add __get_errno_ptr.
2025-09-15 20:14:45 -03:00
Clément Chigot 2725514bfd aarch64: move pr113356.C under g++.target
This test requires a C++ compiler.

for gcc/testsuite/ChangeLog

	* gcc.target/aarch64/pr113356.C: Move to ...
	* g++.target/aarch64/pr113356.C: ... here.
2025-09-15 20:14:40 -03:00
Alexandre Oliva ba7bfdf60c [ppc] [vxworks] allow code model selection
Bring code model selection logic to vxworks.h as well.

for  gcc/ChangeLog

	* config/rs6000/vxworks.h (TARGET_CMODEL, SET_CMODEL): Define.
2025-09-15 20:14:35 -03:00
Alexandre Oliva fbbf5f0a3f [ppc] adjust configure test for large TOC support
The use of the TLS register in a TOC/GOT address computation was
probably a cut&pasto or a thinko.  It causes a linker warning and,
because the TLS access in the test is incomplete, may cause
significant confusion.  Adjust to use the TOC/GOT register as base.


for  gcc/ChangeLog

	* configure.ac: Adjust base register in linker test for large
	TOC support.
	* configure: Rebuild.
2025-09-15 20:14:32 -03:00
Pan Li 982eccec4c Match: Adjust the unsigned SAT_MUL pattern
The widen-mul removed the unnecessary cast, thus adjust the
SAT_MUL of wide-mul to a simpler form.

gcc/ChangeLog:

	* match.pd: Remove unnecessary cast of unsigned
	SAT_MUL for widen-mul.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-16 07:06:11 +08:00
Pan Li d0526e8ef0 Widening-Mul: Refine build_and_insert_cast when rhs is cast
The widening-mul will insert a cast for the widen-mul, the
function build_and_insert_cast is design to take care of it.

In some case the optimized gimple has some unnecessary cast,
for example as below code.

  #define SAT_U_MUL_FMT_5(NT, WT)                 \
  NT __attribute__((noinline))                    \
  sat_u_mul_##NT##_from_##WT##_fmt_5 (NT a, NT b) \
  {                                               \
    WT x = (WT)a * (WT)b;                         \
    NT hi = x >> (sizeof(NT) * 8);                \
    NT lo = (NT)x;                                \
    return lo | -!!hi;                            \
  }

  SAT_U_MUL_FMT_5(uint64_t, uint128_t)

There will be a additional cast to uint128_t after optimized,
this patch would like to refine this by checking the def of
the rhs cast, if it comes from a cast with less or equal
precision, the rhs of the def will be leveraged.

Before this patch:
  29   │   _1 = (__int128 unsigned) a_8(D);
  30   │   _2 = (__int128 unsigned) b_9(D);
  31   │   _35 = (unsigned long) _1;
  32   │   _34 = (unsigned long) _2;
  33   │   x_10 = _35 w* _34;

After this patch:
  27   │   _35 = (unsigned long) a_8(D);
  28   │   _34 = (unsigned long) b_9(D);
  29   │   x_10 = _35 w* _34;

gcc/ChangeLog:

	* tree-ssa-math-opts.cc (build_and_insert_cast): Refine
	the cast insert by check the rhs of val.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/sat/widen-mul-0.c: New test.
	* gcc.target/riscv/sat/widen-mul-1.c: New test.
	* gcc.target/riscv/sat/widen-mul-2.c: New test.
	* gcc.target/riscv/sat/widen-mul-3.c: New test.
	* gcc.target/riscv/sat/widen-mul.h: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-16 07:06:11 +08:00
David Faust bace01eeab ctf: Fix struct size truncation in 32-bit hosts [PR121903,PR121411]
The 'size' argument of ctf_add_sou was size_t.  After the prior fixes
for PR121411, this could cause the struct size to be truncated when
encoding extremely large structs on a host where size_t is smaller than
unsigned HOST_WIDE_INT, manifesting for example as the test failure
reported in PR121903.  Change the argument to uHWI to resolve the issue.

	PR debug/121411
	PR debug/121903

gcc/

	* ctfc.h (ctf_add_sou): Change size arg from size_t to uHWI.
	* ctfc.cc (ctf_add_sou): Likewise.
2025-09-15 15:14:59 -07:00
Eric Botcazou e97969e20b Ada: Fix GNAT build failure for x32 multilib
gcc/ada
	PR ada/114065
	PR ada/121953
	* Makefile.rtl (LIBGNAT_TARGET_PAIRS) [x32-linux]: Replace
	libgnarl/s-osinte__x32.adb with libgnarl/s-osinte__posix.adb.
	* libgnarl/s-osinte__x32.adb: Delete.
2025-09-15 23:07:14 +02:00
Andrew Pinski 597b50abb0 forwprop: Handle memcpy for copy prop [PR121418, PR121417]
It turns out easy to add support for memcpy copy prop when the memcpy
has changed into `MEM<char[N]>` copy.
Instead of rejecting right out we need to figure out that
`a` and `MEM<char[N]>[&a]` are equivalent in terms of address and size.
And then create a VIEW_CONVER_EXPR from the original src to the new type.

Note this also allows for `a.b` and `a` being considered equivalent if b is the
only field (PR 121751).

Changes since v1:
* v2: Move check for IMAG/REAL and BFR earlier.
      Add a wrapping function around get_inner_reference and use that instead
     of get_addr_base_and_unit_offset.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/121751
	PR tree-optimization/121418
	PR tree-optimization/121417
gcc/ChangeLog:

	* tree-ssa-forwprop.cc (split_core_and_offset_size): New function.
	(optimize_agr_copyprop_1): Allow for the same
	address but different type accesses via a VCE.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/copy-prop-aggregate-1.c: New test.
	* gcc.dg/tree-ssa/copy-prop-aggregate-memcpy-1.c: New test.
	* gcc.dg/tree-ssa/copy-prop-aggregate-memcpy-2.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-15 08:59:27 -07:00
Eric Botcazou de0ae1b510 ada: Fix internal error on aspect in complex object declaration
The sufficient conditions are that the aspect be deferred and the object be
rewritten as a renaming because of the complex initialization expression.

gcc/ada/ChangeLog:

	* gcc-interface/trans.cc (gnat_to_gnu)
	<N_Object_Renaming_Declaration>: Deal with objects whose elaboration
	is deferred.
	(process_freeze_entity): Deal with renamed objects whose elaboration
	is deferred.
2025-09-15 14:59:34 +02:00
Gary Dismukes 91b51fc42b ada: Remove dependence on secondary stack for type with controlled component
There are cases where GNAT introduces a dependence on the secondary stack
in a build-in-place function with a result subtype that is definite, when
this dependence could be avoided.  In particular this is done for record
types that requires finalization due to having a controlled component.

At one time such functions required the secondary stack in order to
properly handle cases where the function might raise an exception
(to avoid improper finalization in the caller), but that is no longer
necessary.  We remove the dependence of these functions on the SS,
along with the BIPalloc formal and the generation of the big if_statement
that uses that formal.

An additional small change is to revise the condition for determining when
to generate SS mark/release within functions.

gcc/ada/ChangeLog:

	* exp_ch6.ads (Make_Build_In_Place_Call_In_Allocator): Simplify comment.
	* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Remove obsolete
	comment about not being able to allocate fixed-size controlled results
	on the caller side, and replace another obsolete comment with a simpler
	comment. Call Build_Allocate_Deallocate_Proc when the function doesn't
	need a BIPalloc formal to ensure that function results with controlled
	parts allocated on the caller side will be chained for finalization.
	(Make_Build_In_Place_Call_In_Object_Declaration): Call Needs_BIP_Collection
	on the function's Entity_Id rather than the function call.
	(Needs_BIP_Collection): If a BIP function doesn't need a BIPalloc formal
	then it doesn't need a BIP collection either; return False in that case.
	(Needs_BIP_Alloc_Form): Remove test of Needs_BIP_Collection.
	* exp_ch7.adb (Expand_Cleanup_Actions): Move test of Uses_Sec_Stack
	to be the first conjunct in setting of Needs_Sec_Stack_Mark, and put
	the other tests in a disjunction subsidiary to that. Improve preceding
	comment.
2025-09-15 14:59:34 +02:00
Eric Botcazou 10cddb6ca4 ada: Fix wrong finalization of aliased array of bounded vector
The problem is that Apply_Discriminant_Check introduces an unnecessary
temporary for an assignment where both sides have the same constrained
subtype but the left-hand side is an aliased component.

This comes from an approximation in the implementation introduced long
time ago to deal with aliased unconstrained objects in Ada 95, more
specifically to still generate a check when both sides have the same
unconstrained subtype in this case; it is replaced by an explicit test
that the common subtype is constrained.

gcc/ada/ChangeLog:

	* checks.adb (Apply_Discriminant_Check): Remove undocumented test
	on Is_Aliased_View applied to the left-hand side to skip the check
	in the case where the subtypes are the same, and replace it with a
	test that the subtypes are constrained.
2025-09-15 14:59:33 +02:00
Jose Ruiz 696dc21be2 ada: Document hardening features not supported by LLVM
gcc/ada/ChangeLog:

	* doc/gnat_rm/security_hardening_features.rst:
	clarify that hardening options are not supported by the
	LLVM back end.
	* gnat_rm.texi: Regenerate.
	* gnat_ugn.texi: Regenerate.
2025-09-15 14:59:33 +02:00
Viljar Indus e8de288906 ada: Avoid ghost context errors when preanalyzing Loop_Invariant
gcc/ada/ChangeLog:

	* sem_prag.adb (Analyze_Pragma): Disable context checks for
	the preanalysis of the expression for Loop_Invariant pragmas
	as the ghost region for the pragma has not been set up yet.
2025-09-15 14:59:33 +02:00
Viljar Indus dde7f4252e ada: Match assertion levels by name
Since Assertion_Levels cannot be named after valid assertion names
we no longer need the policies to be matched by entity.

gcc/ada/ChangeLog:

	* sem_prag.adb (Get_Applicable_Policy): Match assertion levels
	by name.
2025-09-15 14:59:32 +02:00
Steve Baird 800363a1bc ada: C_Pass_By_Copy convention incorrectly ignored
In some cases involving a convention-C anonymous access-to-subprogram type
with a parameter whose type has a convention of C_Pass_By_Copy, that
C_Pass_By_Copy convention is incorrectly ignored.

gcc/ada/ChangeLog:

	* freeze.adb (Freeze_Entity): In the case of an anonymous
	access-to-subprogram type where Do_Freeze_Profile is True, freeze
	the designated subprogram type.
	(Should_Freeze_Type): Do not call Unit_Declaration_Node with
	a parentless argument.
	* sem_ch3.adb (Analyze_Object_Declaration): When calling
	Freeze_Before, override the default value for Do_Freeze_Profile.
	This is needed in some cases to prevent premature freezing in the
	case of an object of an anonymous access-to-subprogram type.
2025-09-15 14:59:32 +02:00
Viljar Indus 33f64b2378 ada: Add Assertion_Policy checks for assertion levels
Implement SPARK RM 6.9(19) check:

An Assertion_Policy pragma specifying an Assertion_Level policy shall not occur
within a ghost subprogram or package associated to an assertion level which depends
on this level.

gcc/ada/ChangeLog:

	* sem_prag.adb (Analyze_Pragma): Add ghost level check to
	Assertion_Policy.
2025-09-15 14:59:31 +02:00
Viljar Indus 89b4aa18ca ada: Fix ghost condition for level dependencies for assignments
gcc/ada/ChangeLog:

	* ghost.adb (Check_Assignment_Policies): The level of the assignee
	should depend on the level of the region.
2025-09-15 14:59:31 +02:00
Viljar Indus 6cca06865a ada: Remove checks for the old rule 20
This rule was removed. This can scenario can be detected by Rule 18.

gcc/ada/ChangeLog:

	* ghost.adb (Is_Ok_Pragma): Remove calls to Check_Policies.
2025-09-15 14:59:31 +02:00
Viljar Indus 9c79e191c0 ada: Update ghost code SPARK RM rules
gcc/ada/ChangeLog:

	* contracts.adb: Update SPARK RM reference numbers.
	* freeze.adb: Likewise.
	* ghost.adb: Likewise.
	* ghost.ads: Likewise.
	* sem_ch12.adb: Likewise.
	* sem_ch3.adb: Likewise.
	* sem_ch6.adb: Likewise.
	* sem_prag.adb: Likwise.
	* sem_res.adb: Likewise.
2025-09-15 14:59:30 +02:00
Viljar Indus 6657536db0 ada: Refactor ghost argument consistency checks
Create a new method for checking and emitting errors on pragmas
Unused, Unrefefrenced, Unreferenced_Objects, Inline and No_Return
that support specifying multiple entities as arguments.

Emit an error when one argument is ghost and the other is not and
when one argument has a ghost policy check and the other has ghost
policy ignore.

Update the Suppressed_Ghost_Policy_Check_Pragma list pragma Inline
that should be there to avoid an incorrect invalid pragma context
error.

gcc/ada/ChangeLog:

	* sem_prag.adb (Check_Inconsistent_Argument_Ghostliness):
	new method for handling the ghost constency errors between
	different arguments. Use this method in the processing for
	pragmas Unused, Unrefefrenced, Unreferenced_Objects, Inline and
	No_Return.
	* sem_prag.ads (Suppressed_Ghost_Policy_Check_Pragma): add
	missing entry for pragma Inline.
2025-09-15 14:59:30 +02:00
Viljar Indus ff94323051 ada: Fix the condition of ghost level dependencies inside assignments
The assignee should depend on the level of all of the ghost entiies
with the assignment.

gcc/ada/ChangeLog:

	* ghost.adb (Check_Assignee_Levels): Fix the condition and improve
	error message handling.
2025-09-15 14:59:30 +02:00
Nicolas Boulenguez bc4f29a191 ada: Add System.C_Time and GNAT.C_Time units to libgnat
The first unit provides the time_t, timeval and timespec types corresponding
to the C types defined by the OS, as well as various conversion functions.

The second unit is a mere renaming of the first under the GNAT hierarchy.

This removes C time types and conversions under System, and from bodies and
private parts under GNAT, while keeping visible types and conversions under
GNAT as Obsolescent.

gcc/ada/ChangeLog:

	PR ada/114065
	* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add g-c_time$(objext) and
	s-c_time$(objext).
	(Aarch64/Android): Do not use s-osinte__android.adb.
	(SPARC/Solaris): Do not use s-osprim__solaris.adb.
	(x86/Solaris): Likewise.
	(LynxOS178): Do not use s-parame__posix2008.ads.
	(RTEMS): Likewise.
	(x32/Linux): Likewise, as well as s-linux__x32.ads.  Replace
	s-osprim__x32.adb with s-osprim__posix.adb.
	(LIBGNAT_OBJS): Remove cal.o.
	* cal.c: Delete.
	* doc/gnat_rm/the_gnat_library.rst (GNAT.C_Time): New entry.
	(GNAT.Calendar): Do not mention the obsolete conversion functions.
	* impunit.adb (Non_Imp_File_Names_95): Add g-c_time.
	* libgnarl/a-exetim__posix.adb: Add with clause for System.C_Time
	(Clock): Use type and functions from System.C_Time.
	* libgnarl/s-linux.ads: Remove with clause for System.Parameters.
	Remove declarations of C time types.
	* libgnarl/s-linux__alpha.ads: Likewise.
	* libgnarl/s-linux__android-aarch64.ads: Likewise.
	* libgnarl/s-linux__android-arm.ads: Likewise.
	* libgnarl/s-linux__hppa.ads: Likewise.
	* libgnarl/s-linux__loongarch.ads: Likewise.
	* libgnarl/s-linux__mips.ads: Likewise.
	* libgnarl/s-linux__riscv.ads: Likewise.
	* libgnarl/s-linux__sparc.ads: Likewise.
	* libgnarl/s-osinte__aix.ads: Likewise.
	* libgnarl/s-osinte__android.ads: Likewise.
	* libgnarl/s-osinte__cheribsd.ads: Likewise.
	* libgnarl/s-osinte__darwin.ads: Likewise.
	* libgnarl/s-osinte__dragonfly.ads: Likewise.
	* libgnarl/s-osinte__freebsd.ads: Likewise.
	* libgnarl/s-osinte__gnu.ads: Likewise.
	* libgnarl/s-osinte__hpux.ads: Likewise.
	* libgnarl/s-osinte__kfreebsd-gnu.ads: Likewise.
	* libgnarl/s-osinte__linux.ads: Likewise.
	* libgnarl/s-osinte__lynxos178e.ads: Likewise.
	* libgnarl/s-osinte__qnx.ads: Likewise.
	* libgnarl/s-osinte__rtems.ads: Likewise.
	* libgnarl/s-osinte__solaris.ads: Likewise.
	* libgnarl/s-osinte__vxworks.ads: Likewise.
	* libgnarl/s-qnx.ads: Likewise.
	* libgnarl/s-linux__x32.ads: Delete.
	* libgnarl/s-osinte__darwin.adb (To_Duration): Remove.
	(To_Timespec): Likewise.
	* libgnarl/s-osinte__aix.adb: Likewise.
	* libgnarl/s-osinte__dragonfly.adb: Likewise.
	* libgnarl/s-osinte__freebsd.adb: Likewise.
	* libgnarl/s-osinte__gnu.adb: Likewise.
	* libgnarl/s-osinte__lynxos178.adb: Likewise.
	* libgnarl/s-osinte__posix.adb: Likewise.
	* libgnarl/s-osinte__qnx.adb: Likewise.
	* libgnarl/s-osinte__rtems.adb: Likewise.
	* libgnarl/s-osinte__solaris.adb: Likewise.
	* libgnarl/s-osinte__vxworks.adb: Likewise.
	* libgnarl/s-osinte__x32.adb: Likewise.
	* libgnarl/s-taprop__solaris.adb: Add with clause for System.C_Time.
	(Monotonic_Clock): Use type and functions from System.C_Time.
	(RT_Resolution): Likewise.
	(Timed_Sleep): Likewise.
	(Timed_Delay): Likewise.
	* libgnarl/s-taprop__vxworks.adb: Likewise.
	* libgnarl/s-tpopmo.adb: Likewise.
	* libgnarl/s-osinte__android.adb: Delete.
	* libgnat/g-c_time.ads: New file.
	* libgnat/g-calend.adb: Delegate to System.C_Time.
	* libgnat/g-calend.ads: Likewise.
	* libgnat/g-socket.adb: Likewise.
	* libgnat/g-socthi.adb: Likewise.
	* libgnat/g-socthi__vxworks.adb: Likewise.
	* libgnat/g-sothco.ads: Likewise.
	* libgnat/g-spogwa.adb: Likewise.
	* libgnat/s-c_time.adb: New file.
	* libgnat/s-c_time.ads: Likewise.
	* libgnat/s-optide.adb: Import nanosleep here.
	* libgnat/s-os_lib.ads (time_t): Remove.
	(To_Ada): Adjust.
	(To_C): Likewise.
	* libgnat/s-os_lib.adb: Likewise.
	* libgnat/s-osprim__darwin.adb: Delegate to System.C_Time.
	* libgnat/s-osprim__posix.adb: Likewise.
	* libgnat/s-osprim__posix2008.adb: Likewise.
	* libgnat/s-osprim__rtems.adb: Likewise.
	* libgnat/s-osprim__unix.adb: Likewise.
	* libgnat/s-osprim__solaris.adb: Delete.
	* libgnat/s-osprim__x32.adb: Likewise.
	* libgnat/s-parame.ads (time_t_bits): Remove.
	* libgnat/s-parame__hpux.ads: Likewise.
	* libgnat/s-parame__vxworks.ads: Likewise.
	* libgnat/s-parame__posix2008.ads: Delete.
	* s-oscons-tmplt.c (SIZEOF_tv_nsec): New constant.
	* gnat_rm.texi: Regenerate.
2025-09-15 14:59:29 +02:00
Eric Botcazou fa714c16d4 ada: Fix crash on iterator of type with Constant_Indexing aspect
This happens when the type returned by the indexing function is a private
type whose completion is derived from another private type, because the
Finalize_Address routine cannot correctly fetch the actual root type.

gcc/ada/ChangeLog:

	* exp_util.adb (Finalize_Address): In an untagged derivation, call
	Root_Type on the full view of the base type if the partial view is
	itself not a derived type.
	(Is_Untagged_Derivation): Minor formatting tweak.
2025-09-15 14:59:29 +02:00
Eric Botcazou c7ef48f2be ada: Fix missing finalization for qualified expression in conditional expression
A qualified expression around a function call may cause a temporary to be
created and, therefore, cannot be bypassed in Expand_Ctrl_Function_Call.

gcc/ada/ChangeLog:

	* exp_util.ads (Unqualified_Unconditional_Parent): New function.
	* exp_util.adb (Unconditional_Parent): Do not look through qualified
	expressions.
	(Unqualified_Unconditional_Parent): New function identical to the
	original Unconditional_Parent.
	* exp_aggr.adb (Convert_To_Assignments): Replace Unconditional_Parent
	with Unqualified_Unconditional_Parent.
	(Expand_Array_Aggregate): Likewse.
	* exp_ch4.adb (Expand_N_Case_Expression): Likewise.
	(Expand_N_If_Expression): Likewise.
	* exp_ch6.adb (Expand_Ctrl_Function_Call): Do not bypass an enclosing
	qualified expression in the parent chain.
2025-09-15 14:59:29 +02:00
Ronan Desplanques e2aab9ab8b ada: Fix section of Finalizable extension in GNAT RM
The generalized finalization extension was awarded the title of curated
extension some time ago, but this wasn't reflected in the GNAT
reference manual before this patch, which moves the documentation for
generalized finalization in the curated extension section.

gcc/ada/ChangeLog:

	* doc/gnat_rm/gnat_language_extensions.rst: Fix section of Finalizable.
	* gnat_rm.texi: Regenerate.
	* gnat_ugn.texi: Regenerate.
2025-09-15 14:59:28 +02:00
Viljar Indus dcaabdd2da ada: Avoid ghost context check in early freeze
We freeze the expression for expression functions that complete
before we have set up the ghost region from both the existing spec
and body. Avoid triggering the ghost context checks during the
analysis for this early freeze as the expression will be reanalyzed
when we analyze the new function body created for the expression
function.

gcc/ada/ChangeLog:

	* sem_ch6.adb (Analyze_Expression_Function): Disable ghost
	checks during the early freeze.
2025-09-15 14:59:28 +02:00
Steve Baird 8a787f3e44 ada: Implement Super aspect and improve implementation of related features.
Implement the GNAT-defined Super aspect (which should not be confused with
with the Super attribute). For a two-part constructor procedure declaration,
an Initialize aspect specification is permitted on the subprogram body,
and not on the subprogram specification (this reverses was what was previously
implemented). Improve the implementation of the Make attribute.

gcc/ada/ChangeLog:

	* aspects.ads: Define Super aspect; allow Initialize aspect
	specification on a subprogram body.
	* exp_attr.adb (Expand_N_Attribute_Reference): Rewrite Make
	attribute implementation.
	* exp_ch3.adb (Initialization_Control): Delete Initialization_Mode
	and Make_Mode_Literal (those declarations were moved to the spec).
	(Build_Record_Init_Proc): For a constructor type, component
	initialization (other than for the tag component, if any) must be
	performed by calling the single-argument constructor procedure.
	(Requires_Init_Proc): Return True for a constructor type.
	* exp_ch3.ads (Make_Mode_Literal, Initialization_Mode): New, moved
	from the body of this package.
	* exp_ch6.adb (Expand_N_Subprogram_Body): Declare, implement, and
	call a new local procedure, Prepend_Constructor_Procedure_Prologue
	in order to generate component initialization for a constructor
	procedure.
	* sem_attr.adb (Analyze_Attribute): Improve the error message
	generated for a 'Make attribute reference if GNAT extensions are
	not all allowed.
	* sem_ch13.adb (Analyze_One_Aspect): Improved implementation of
	aspect specifications for Initialize, Constructor, and Super
	aspects. For Super, there was no previous implementation.
2025-09-15 14:59:27 +02:00
Viljar Indus 99019f23a1 ada: Improve ghost region creation for pragmas
gcc/ada/ChangeLog:

	* atree.adb (Mark_New_Ghost_Node): Set Is_Implicit_Ghost for
	all newly created nodes.
	* gen_il-fields.ads (Is_Implicit_Ghost): New attribute.
	* gen_il-gen-gen_entities.adb (Entity_Kind): Add Is_Implicit_Ghost
	attribute.
	* ghost.adb (Ghost_Policy_In_Effect): Implicit_Ghost_Entities inside
	pragmas get the ghost mode from the region isntead of the global
	ghost policy.
	(Ghost_Assertion_Level_In_Effect): New function that returns the
	applicable assertion level for the given entity in a similar manner
	as Ghost_Policy_In_Effect.
	(Install_Ghost_Region): Set Is_Inside_Statement_Or_Pragma attribute.
	(Mark_And_Set_Ghost_Body): Update the logic for deriving the ghost
	region.
	(Set_Ghost_Mode): Ignored pragmas attached to checked ghost entities
	now create an ignored ghost region. Pragmas attached to non-ghost
	entities create the ghost region based on the policy applied to the
	given pragma.
	* opt.ads (Ghost_Config_Type): add new attribute
	Is_Inside_Statement_Or_Pragama to track whether we should take the
	active ghost mode from the ghost region for implicit ghost entities.
	* sem_prag.adb (Analyze_Pragma): Mark entities that have an explicit
	ghost pragma as non-implicit ghost.
2025-09-15 14:59:27 +02:00
Sebastian Poeplau 18f0f8024c ada: Remove the note that GNAT LLVM doesn't ship the light runtime
gcc/ada/ChangeLog:

	* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
	Remove the note on light runtimes.
2025-09-15 14:59:27 +02:00
Sebastian Poeplau f915b22580 ada: Recommend GPR's Toolchain_Name for GNAT LLVM more prominently
gcc/ada/ChangeLog:

	* doc/gnat_ugn/building_executable_programs_with_gnat.rst: Move
	recommendation of Toolchain_Name up.
	* gnat_ugn.texi: Regenerate.
2025-09-15 14:59:26 +02:00
Vadim Godunko 2c59615704 ada: Don't generate call of System.Standard_Library.Adafinal
`adafinal` is not available on targets without standard library.

gcc/ada/ChangeLog:

	* bindgen.adb (Gen_Adafinal): Don't generate call of adafinal
	when use of standard library suppressed.
2025-09-15 14:59:26 +02:00
Vadim Godunko 90997ddd7b ada: Fix code generation when there is no No_Finalization restiction
Check whether library is elaborated is not generated when there is not
standard library available on target.

gcc/ada/ChangeLog:

	* bindgen.adb (Gen_Adafinal): Don't generate code when
	use of standard library suppressed.
2025-09-15 14:59:26 +02:00
Vadim Godunko 062aeef444 ada: Add Set_[Wide_]Wide_String subprograms to auxiliary packages.
gcc/ada/ChangeLog:

	* libgnat/a-swunau.ads (Set_Wide_String): New subprogram.
	* libgnat/a-swunau.adb (Set_Wide_String): Likewise.
	* libgnat/a-swunau__shared.adb (Set_Wide_String): Likewise.
	* libgnat/a-szunau.ads (Set_Wide_Wide_String): Likewise.
	* libgnat/a-szunau.adb (Set_Wide_Wide_String): Likewise.
	* libgnat/a-szunau__shared.adb (Set_Wide_Wide_String): Likewise.
2025-09-15 14:59:25 +02:00
Viljar Indus 33876c5ea8 ada: Disable ghost context checks before context is set
There are cases where we need to analyze the argument of the pragma
in order to determine the ghostliness of the pragma. However during
that analysis the ghost region of the pragma is not set yet so we
cannot perform the ghost context checks at that moment.

This patch provides the mechanism for disabling ghost context checks
and disables them for pragma arguments that determine the ghostliness
of the pragma.

gcc/ada/ChangeLog:

	* ghost.adb (Check_Ghost_Context): Avoid context checks when they
	are globally disabled.
	* sem.ads (Ghost_Context_Checks_Disabled): New flag to control
	whether ghost context checks are activated or not.
	* sem_prag.adb (Analyze_Pragma): Disable ghost context checks for
	pragmas that determine their ghostliness based on one of its arguments.
2025-09-15 14:59:25 +02:00
Ronan Desplanques 78551d9e13 ada: Fix documentation of Is_Ancestor_Package
"Is_Ancestor_Package (E, E)" returns True and this patch fixes a comment
that claimed otherwise. This patch also renames an object local to
Is_Ancestor_Package that was misleadingly named "Par", a common
abbreviation of "Parent".

gcc/ada/ChangeLog:

	* sem_util.ads (Is_Ancestor_Package): Fix documentation comment.
	* sem_util.adb (Is_Ancestor_Package): Rename local object.
2025-09-15 14:59:24 +02:00
Alex Coplan a7a9b7badc match.pd: Add missing type check to reduc(ctor) pattern [PR121772]
In this PR we have a reduction of a vector constructor, where the
type of the constructor is int16x8_t and the elements are int16x4_t;
i.e. it is representing a concatenation of two vectors.

This triggers a match.pd pattern which looks like it was written to
handle reductions of vector constructors where the elements of the ctor
are scalars, not vectors.  There is no type check to enforce this
property, which leads to the pattern replacing a reduction to scalar
with an int16x4_t vector in this case, which of course is a type error,
leading to an invalid GIMPLE ICE.

This patch adds a type check to the pattern, only going ahead with the
transformation if the element type of the ctor matches that of the
reduction.

gcc/ChangeLog:

	PR tree-optimization/121772
	* match.pd: Add type check to reduc(ctor) pattern.

gcc/testsuite/ChangeLog:

	PR tree-optimization/121772
	* gcc.target/aarch64/torture/pr121772.c: New test.
2025-09-15 13:32:36 +01:00
Georg-Johann Lay 45f605a74f AVR: Support AVR32EB14/20/28/32.
Add support for some recent AVR devices.

gcc/
	* config/avr/avr-mcus.def: Add avr32eb14, avr32eb20,
	avr32eb28, avr32eb32.
	* doc/avr-mmcu.texi: Rebuild.
2025-09-15 14:28:24 +02:00
H.J. Lu 32b8d13123 x86: Don't align destination for a single instruction
If a single instruction can store or move the whole block of memory, use
vector instruction and don't align destination.

gcc/

	PR target/121934
	* config/i386/i386-expand.cc (ix86_expand_set_or_cpymem): If a
	single instruction can store or move the whole block of memory,
	use vector instruction and don't align destination.

gcc/testsuite/

	PR target/121934
	* gcc.target/i386/pr121934-1a.c: New test.
	* gcc.target/i386/pr121934-1b.c: Likewise.
	* gcc.target/i386/pr121934-2a.c: Likewise.
	* gcc.target/i386/pr121934-2b.c: Likewise.
	* gcc.target/i386/pr121934-3a.c: Likewise.
	* gcc.target/i386/pr121934-3b.c: Likewise.
	* gcc.target/i386/pr121934-4a.c: Likewise.
	* gcc.target/i386/pr121934-4b.c: Likewise.
	* gcc.target/i386/pr121934-5a.c: Likewise.
	* gcc.target/i386/pr121934-5b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-15 05:02:46 -07:00
Xi Ruoyao 290851e63a LoongArch: Fix wrong code from bstrpick split
After late-combine is added, split1 can see an input like

    (insn 56 55 169 5
      (set (reg/v:DI 87 [ n ])
        (ior:DI (and:DI (reg/v:DI 87 [ n ])
                        (const_int 281474976710655 [0xffffffffffff]))
                (and:DI (reg:DI 131 [ _45 ])
                        (const_int -281474976710656 [0xffff000000000000]))))
      "pr121906.c":22:8 108 {*bstrins_di_for_ior_mask}
      (nil))

And the splitter ends up emitting

    (insn 184 55 185 5
      (set (reg/v:DI 87 [ n ])
           (reg:DI 131 [ _45 ]))
      "pr121906.c":22:8 -1
      (nil))
    (insn 185 184 169 5
      (set (zero_extract:DI (reg/v:DI 87 [ n ])
                            (const_int 48 [0x30])
                            (const_int 0 [0]))
           (reg/v:DI 87 [ n ]))
      "pr121906.c":22:8 -1
      (nil))

which obviously lost everything in r87, instead of retaining its lower
bits as we expect.  It's because the splitter didn't anticipate the
output register may be one of the input registers.

	PR target/121906

gcc/

	* config/loongarch/loongarch.md (*bstrins_<mode>_for_ior_mask):
	Always create a new pseudo for the input register of the bstrins
	instruction.

gcc/testsuite/

	* gcc.target/loongarch/pr121906.c: New test.
2025-09-15 18:40:13 +08:00
Jakub Jelinek bd83c6227c expr, tree: Ensure get_range_pos_neg is called only on scalar integral types [PR121904]
The gcc.c-torture/compile/20111209-1.c testcase which uses
typedef char* char_ptr32 __attribute__ ((mode(SI)));
ICEs on s390x since my change to optimize extensions by cheaper of
signed or unsigned extension if sign bit is known from VRP not to be set.

The problem is that get_range_pos_neg uses ranger into int_range_max
and so ICEs on pointers.  All the other current callers call it from places
where only scalar integral types can appear (scalar division/modulo,
overflow ifns, etc.) I think, this spot was just testing SCALAR_INT_MODE_P.

The following patch adds check for INTEGRAL_TYPE_P, I think ranger will not
do anything useful for pointers here anyway and what is a negative pointer
is also fuzzy.  I've changed both get_range_pos_neg to punt on that and
the caller, either of those changes are sufficient to fix the ICE, but I
think it doesn't hurt to do it in both places.

2025-09-15  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/121904
	* tree.cc (get_range_pos_neg): Return 3 if arg doesn't have
	scalar integral type.
	* expr.cc (expand_expr_real_2) <CASE_CONVERT>: Only choose between
	sign and zero extension based on costs for scalar integral inner
	types.
2025-09-15 10:34:33 +02:00
Kito Cheng 6485b10565 RISC-V: Fix vendor intrinsic tests for disabled multilib configurations
Add wrapper headers that prevent vendor vector headers from including
system stdint.h, ensuring tests work correctly when multilib is disabled.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/andes_vector.h: New file.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfncvtbf16s.c
	(#include): Use local andes_vector.h instead of system header.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfwcvtsbf16.c
	(#include): Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/andes_vector.h: New file.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfncvtbf16s.c
	(#include): Use local andes_vector.h instead of system header.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfwcvtsbf16.c
	(#include): Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/andes_vector.h: New file.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfncvtbf16s.c
	(#include): Use local andes_vector.h instead of system header.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfwcvtsbf16.c
	(#include): Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/andes_vector.h: New file.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfncvtbf16s.c
	(#include): Use local andes_vector.h instead of system header.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfwcvtsbf16.c
	(#include): Likewise.
	* gcc.target/riscv/rvv/xsfvector/sifive_vector.h: New file.
	* gcc.target/riscv/rvv/xtheadvector/riscv_th_vector.h: New file.
	* gcc.target/riscv/rvv/xtheadvector/riscv_vector.h: New file.
2025-09-15 16:11:48 +08:00
Stefan Schulze Frielinghaus 4cff794ca1 Bail out early during gimplify_asm_expr [PR121391]
In case an asm operand is an error node, constraints etc. are still
validated.  Furthermore, all other operands are gimplified, although an
error is returned in the end anyway.  For hard register constraints an
operand is required in order to determine the mode from which the number
of registers follows.  Therefore, instead of adding extra guards, bail
out early.

gcc/ChangeLog:

	PR middle-end/121391
	* gimplify.cc (gimplify_asm_expr): In case an asm operand is an
	error node, bail out early.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr121391-1.c: New test.
	* gcc.dg/pr121391-2.c: New test.
2025-09-15 09:10:53 +02:00
Matthias Kretz 8d264d90a2 Fix whitespace after r16-3679-g19d1c7c28f4fd0
Signed-off-by: Matthias Kretz <m.kretz@gsi.de>

gcc/cp/ChangeLog:

	* mangle.cc (write_real_cst): Replace 8 spaces with Tab.
2025-09-15 09:07:29 +02:00
Paul Thomas 857c742e7b Fortran: Dependency check in PDT specification assignments [PR83763]
2025-09-15  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/83763
	* trans-decl.cc (gfc_trans_deferred_vars): Ensure that the
	parameterized components of PDTs that do not have allocatable
	components are deallocated on leaving scope.
	* trans-expr.cc (gfc_trans_assignment_1): Do a dependency check
	on PDT assignments. If there is a dependency between lhs and
	rhs, deallocate the lhs parameterized components after the rhs
	has been evaluated.

gcc/testsuite/
	PR fortran/83763
	* gfortran.dg/pdt_46.f03: New test.
2025-09-15 06:49:54 +01:00
GCC Administrator 32fbfbe630 Daily bump. 2025-09-15 00:17:47 +00:00
Richard Biener 38666cbccf lto/121935 - visit all DECL_ARGUMENTS in free-lang-data
With no longer visiting TREE_CHAIN for decls we have to visit
the DECL_ARGUMENT chain manually.

	PR lto/121935
	* ipa-free-lang-data.cc (find_decls_types_r): Visit DECL_ARGUMENTS
	chain manually.

	* g++.dg/lto/pr121935_0.C: New testcase.
2025-09-14 13:24:48 +02:00
Yuao Ma af53cfeb83 fortran: implement conditional expression for fortran 2023
This patch adds support for conditional expressions in Fortran 2023 for a
limited set of types (logical, numerical), and also includes limited support
for conditional arguments without `.nil.` support.

gcc/fortran/ChangeLog:

	* dump-parse-tree.cc (show_expr): Add support for EXPR_CONDITIONAL.
	* expr.cc (gfc_get_conditional_expr): Add cond-expr constructor.
	(gfc_copy_expr, free_expr0, gfc_is_constant_expr,
	simplify_conditional, gfc_simplify_expr, gfc_check_init_expr,
	check_restricted, gfc_traverse_expr): Add support for EXPR_CONDITIONAL.
	* frontend-passes.cc (gfc_expr_walker): Ditto.
	* gfortran.h (enum expr_t): Add EXPR_CONDITIONAL.
	(gfc_get_operator_expr): Format fix.
	(gfc_get_conditional_expr): New decl.
	* matchexp.cc
	(match_conditional, match_primary): Parsing for EXPR_CONDITIONAL.
	* module.cc (mio_expr): Add support for EXPR_CONDITIONAL.
	* resolve.cc (resolve_conditional, gfc_resolve_expr): Ditto.
	* trans-array.cc (gfc_walk_conditional_expr, gfc_walk_subexpr): Ditto.
	* trans-expr.cc
	(gfc_conv_conditional_expr): Codegen for EXPR_CONDITIONAL.
	(gfc_apply_interface_mapping_to_expr, gfc_conv_expr,
	gfc_conv_expr_reference): Add support for EXPR_CONDITIONAL.

gcc/testsuite/ChangeLog:

	* gfortran.dg/conditional_1.f90: New test.
	* gfortran.dg/conditional_2.f90: New test.
	* gfortran.dg/conditional_3.f90: New test.
	* gfortran.dg/conditional_4.f90: New test.
	* gfortran.dg/conditional_5.f90: New test.
	* gfortran.dg/conditional_6.f90: New test.
	* gfortran.dg/conditional_7.f90: New test.
	* gfortran.dg/conditional_8.f90: New test.
	* gfortran.dg/conditional_9.f90: New test.
2025-09-14 18:24:50 +08:00
Richard Biener 21d1bb1922 Integrate SLP permute transform into vect_transform_stmt
This adds permute_info_type and removes the duplication from
vect_schedule_slp_node.

	* tree-vectorizer.h (stmt_vec_info_type::permute_info_type): Add.
	(vectorizable_slp_permutation): Declare.
	* tree-vect-slp.cc (vectorizable_slp_permutation): Export.
	(vect_slp_analyze_node_operations_1): Set permute_info_type
	on permute nodes successfully analyzed.
	(vect_schedule_slp_node): Dispatch to vect_transform_stmt
	for all nodes.
	* tree-vect-stmts.cc (vect_transform_stmt): Remove redundant
	dump, handle permute_info_type.

	* gcc.dg/vect/vect-reduc-chain-2.c: Adjust.
	* gcc.dg/vect/vect-reduc-chain-3.c: Likewise.
2025-09-14 11:08:10 +02:00
Richard Biener 57c97de978 Avoid VMAT_ELEMENTWISE for negative stride SLP
The following makes us always use VMAT_STRIDED_SLP for negative
stride multi-element accesses.  That handles falling back to
single element accesses transparently.

	* tree-vect-stmts.cc (get_load_store_type): Use VMAT_STRIDED_SLP
	for negative stride accesses when VMAT_CONTIGUOUS_REVERSE
	isn't applicable.
2025-09-14 11:05:42 +02:00
Richard Biener 80f9440b5e Do less redundant vect_transform_slp_perm_load calls
The following tries to do vect_transform_slp_perm_load exactly
once during analysis and once during transform.  There's a 2nd
case left during analysis in get_load_store_type.  Temporarily
this records n_perms in the load-store info and verifies that
against the value computed at transform stage.

	* tree-vectorizer.h (vect_load_store_data::n_perms): New.
	* tree-vect-stmts.cc (vectorizable_load): Analyze
	SLP_TREE_LOAD_PERMUTATION only once and remember n_perms.
	Verify the transform-time n_perms against the value stored
	during analysis.
2025-09-14 11:05:42 +02:00
GCC Administrator 1744dc23b3 Daily bump. 2025-09-14 00:17:51 +00:00
Gerald Pfeifer 8c23566d94 target.def: Properly mark up __cxa_atexit as code
gcc:
	* target.def (dtors_from_cxa_atexit): Properly mark up
	__cxa_atexit as code.
	* doc/tm.texi: Regenerate.
2025-09-14 01:06:51 +02:00
Patrick Palka 349affa42c libstdc++: Fix ranges::shuffle for non-sized range [PR121917]
ranges::shuffle has a two-at-a-time PRNG optimization (copied from
std::shuffle) that considers the PRNG width vs the size of the range.
But in C++20 a random access sentinel isn't always sized so we can't
unconditionally do __last - __first to obtain the size in constant
time.

We could instead use ranges::distance, but that'd take linear time for a
non-sized sentinel which makes the optimization less clear of a win.  So
this patch instead makes us only consider this optimization for sized
ranges.

	PR libstdc++/121917

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h (__shuffle_fn::operator()): Only
	consider the two-at-a-time PRNG optimization if the range is
	sized.
	* testsuite/25_algorithms/shuffle/constrained.cc (test03): New
	test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-09-13 10:44:12 -04:00
Stefan Schulze Frielinghaus f8b6f1d83b lra: Stop constraint processing on error [PR121205]
It looks like we didn't have a test so far reaching this point which
changed with the new hard register constraint tests.  Bootstrap and
regtest are still running on x86_64.  If they succeed, ok for mainline?

-- >8 --

As noted by Sam in the PR, with checking enabled tests
gcc.target/i386/asm-hard-reg-{1,2}.c fail with an ICE.  If an error is
detected in curr_insn_transform(), lra_asm_insn_error() is called and
deletes the current insn.  However, afterwards processing continues with
the deleted insn and via lra_process_new_insns() we finally call recog()
for NOTE_INSN_DELETED which ICEs in case of a checking build.  Thus, in
case of an error during curr_insn_transform() bail out and stop
processing.

gcc/ChangeLog:

	PR rtl-optimization/121205
	* lra-constraints.cc (curr_insn_transform): Stop processing on
	error.
2025-09-13 05:19:10 -07:00
Gerald Pfeifer 205b5a5741 doc: Editorial changes around -fprofile-partial-training
gcc:
	* doc/invoke.texi (Optimize Options): Editorial changes around
	-fprofile-partial-training.
2025-09-13 12:40:38 +02:00
Dimitar Dimitrov d020b73ce0 testsuite: Port asm-hard-reg tests for PRU
Add the necessary register definitions for PRU, so that asm-hard-reg
tests can pass for PRU.

gcc/testsuite/ChangeLog:

	* gcc.dg/asm-hard-reg-error-1.c: Enable test for PRU, and define
	registers for PRU.
	* gcc.dg/asm-hard-reg-error-4.c: Define hard regs for PRU.
	* gcc.dg/asm-hard-reg-error-5.c: Ditto.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2025-09-13 11:37:24 +03:00
Joseph Myers 908edc1309 c: Implement C2y N3517 array subscripting without decay
N3517 (array subscripting without decay) has been added to C2y (via a
remote vote in May, not at a meeting).  Implement this in GCC.

The conceptual change, that the array subscripting operator [] no
longer involves an array operand decaying to a pointer, is something
GCC has done for a very long time.  The main effect in terms of what
is made possible in the language, subscripting a register array
(undefined behavior in C23 and before), was available as a GNU
extension, but only with constant indices.  There is also a new
constraint that array indices must not be negative when they are
integer constant expressions and the array operand has array type
(negative indices are fine with pointers) - an access out of bounds of
an array (even when contained within a larger object) has undefined
behavior at runtime when not a constraint violation.

Thus, the previous GCC extension is adapted to allow the cases of
register arrays not previously allowed, clearing DECL_REGISTER on them
as needed (similar to what is done with register declarations of
structures with volatile members) and restricting the pedwarn to
pedwarn_c23.  That pedwarn_c23 is also extended to cover the C23 case
of register compound literals (although not strictly needed since it
was undefined behavior rather than a constraint violation in C23).
The new error is added (only for flag_isoc2y) for negative array
indices with an operand of array type.

N3517 has some specific wording about the type of the result of
non-lvalue array element access.  It's unclear what's actually desired
there in the case where the array element is itself of array type; see
C23 issue 1001 regarding types of qualified members of rvalue
structures and unions more generally.  Rather than implementing the
specific wording about this in N3517, that is deferred until there's
an accepted resolution to issue 1001 and can be dealt with as part of
implementing such a resolution.

Nothing specific is done about the obsolescence in that paper of
writing index[array] or index[pointer] as opposed to array[index] or
pointer[index], although that seems like a reasonable enough thing to
warn about.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c/
	* c-typeck.cc (c_mark_addressable): New parameter
	override_register.
	(build_array_ref): Update calls to c_mark_addressable.  Give error
	in C2Y mode for negative array indices when array expression is an
	array not a pointer.  Use pedwarn_c23 for subscripting register
	array; diagnose that also for register compound literal.
	* c-tree.h (c_mark_addressable): Update prototype.

gcc/testsuite/
	* gcc.dg/c23-array-negative-1.c, gcc.dg/c23-register-array-1.c,
	gcc.dg/c23-register-array-2.c, gcc.dg/c23-register-array-3.c,
	gcc.dg/c23-register-array-4.c, gcc.dg/c2y-array-negative-1.c,
	gcc.dg/c2y-register-array-2.c, gcc.dg/c2y-register-array-3.c: New
	tests.
2025-09-13 00:21:58 +00:00
GCC Administrator 54efca1730 Daily bump. 2025-09-13 00:19:19 +00:00
Jeff Law 0c6ad3f5df Fix latent LRA bug
Shreya's work to add the addptr pattern on the RISC-V port exposed a latent bug
in LRA.

We lazily allocate/reallocate the ira_reg_equiv structure and when we do
(re)allocation we'll over-allocate and zero-fill so that we don't have to
actually allocate and relocate the data so often.

In the case exposed by Shreya's work we had N requested entries at the last
rellocation step.  We actually allocate N+M entries.  During LRA we allocate
enough new pseudos and thus have N+M+1 pseudos.

In get_equiv we read ira_reg_equiv[regno] without bounds checking so we read
past the allocated part of the array and get back junk which we use and
depending on the precise contents we fault in various fun and interesting ways.

We could either arrange to re-allocate ira_reg_equiv again on some path through
LRA (possibly in get_equiv itself).  We could also just insert the bounds check
in get_equiv like is done elsewhere in LRA.  Vlad indicated no strong
preference in an email last week.

So this just adds the bounds check in a manner similar to what's done elsewhere
in LRA.  Bootstrapped and regression tested on x86_64 as well as RISC-V with
Shreya's work enabled and regtested across the various embedded targets.

gcc/
	* lra-constraints.cc (get_equiv): Bounds check before accessing
	data in ira_reg_equiv.
2025-09-12 16:10:27 -06:00
Jonathan Wakely 7801236069 libstdc++: ranges::rotate should use ranges::iter_move [PR121913]
Using std::move(*it) is incorrect for iterators that use proxy refs, we
should use ranges::iter_move(it) instead.

libstdc++-v3/ChangeLog:

	PR libstdc++/121913
	* include/bits/ranges_algo.h (__rotate_fn::operator()): Use
	ranges::iter_move(it) instead of std::move(*it).
	* testsuite/25_algorithms/rotate/121913.cc: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-09-12 21:46:51 +01:00
Jonathan Wakely 7b99d184bc libstdc++: Fix algorithms to use iterators' difference_type for arithmetic [PR121890]
Whenever we use operator+ or similar operators on random access
iterators we need to be careful to use the iterator's difference_type
rather than some other integer type. It's not guaranteed that an
expression with an arbitrary integer type, such as `it + 1u`, has the
same effects as `it + iter_difference_t<It>(1)`.

Some of our algorithms need changes to cast values to the correct type,
or to use std::next or ranges::next instead of `it + n`. Several tests
also need fixes where the arithmetic occurs directly in the test.

The __gnu_test::random_access_iterator_wrapper class template is
adjusted to have deleted operators that make programs ill-formed if the
argument to relevant operators is not the difference_type. This will
make it easier to avoid regressing in future.

libstdc++-v3/ChangeLog:

	PR libstdc++/121890
	* include/bits/ranges_algo.h (ranges::rotate, ranges::shuffle)
	(__insertion_sort, __unguarded_partition_pivot, __introselect):
	Use ranges::next to advance iterators. Use local variables in
	rotate to avoid duplicate expressions.
	(ranges::push_heap, ranges::pop_heap, ranges::partial_sort)
	(ranges::partial_sort_copy): Use ranges::prev.
	(__final_insertion_sort): Use iter_difference_t<Iter>
	for operand of operator+ on iterator.
	* include/bits/ranges_base.h (ranges::advance): Use iterator's
	difference_type for all iterator arithmetic.
	* include/bits/stl_algo.h (__search_n_aux, __rotate)
	(__insertion_sort, __unguarded_partition_pivot, __introselect)
	(__final_insertion_sort, for_each_n, random_shuffle): Likewise.
	Use local variables in __rotate to avoid duplicate expressions.
	* include/bits/stl_algobase.h (__fill_n_a, __lc_rai::__newlast1):
	Likewise.
	* include/bits/stl_heap.h (push_heap): Likewise.
	(__is_heap_until): Add static_assert.
	(__is_heap): Convert distance to difference_type.
	* include/std/functional (boyer_moore_searcher::operator()): Use
	iterator's difference_type for iterator arithmetic.
	* testsuite/util/testsuite_iterators.h
	(random_access_iterator_wrapper): Add deleted overloads of
	operators that should be called with difference_type.
	* testsuite/24_iterators/range_operations/advance.cc: Use
	ranges::next.
	* testsuite/25_algorithms/heap/constrained.cc: Use ranges::next
	and ranges::prev.
	* testsuite/25_algorithms/nth_element/58800.cc: Use std::next.
	* testsuite/25_algorithms/nth_element/constrained.cc: Use
	ptrdiff_t for loop variable.
	* testsuite/25_algorithms/nth_element/random_test.cc: Use
	iterator's difference_type instead of int.
	* testsuite/25_algorithms/partial_sort/check_compare_by_value.cc:
	Use std::next.
	* testsuite/25_algorithms/partial_sort/constrained.cc: Use
	ptrdiff_t for loop variable.
	* testsuite/25_algorithms/partial_sort/random_test.cc: Use
	iterator's difference_type instead of int.
	* testsuite/25_algorithms/partial_sort_copy/constrained.cc:
	Use ptrdiff_t for loop variable.
	* testsuite/25_algorithms/partial_sort_copy/random_test.cc:
	Use iterator's difference_type instead of int.
	* testsuite/std/ranges/adaptors/drop.cc: Use ranges::next.
	* testsuite/25_algorithms/fill_n/diff_type.cc: New test.
	* testsuite/25_algorithms/lexicographical_compare/diff_type.cc:
	New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-12 21:46:48 +01:00
Eric Botcazou f6e00192cd Testsuite: Fix more spurious failure of ACATS-4 tests
This tentatively applies the same tweak to twin testcases.

gcc/testsuite/
	PR ada/121532
	* ada/acats-4/tests/cxa/cxai034.a: Use Long_Switch_To_New_Task
	constant instead of Switch_To_New_Task in delay statements.
	* ada/acats-4/tests/cxa/cxai035.a: Likewise.
	* ada/acats-4/tests/cxa/cxai036.a: Likewise.
2025-09-12 20:53:35 +02:00
Patrick Palka 8e3230f4fe c++: pack indexing is a non-deduced context [PR121795]
We weren't explicitly treating a pack index specifier as a non-deduced
context (as per [temp.deduct.type]/5), leading to an ICE for the first
testcase below.

	PR c++/121795

gcc/cp/ChangeLog:

	* pt.cc (unify) <case PACK_INDEX_TYPE>: New non-deduced context
	case.

gcc/testsuite/ChangeLog:

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

Reviewed-by: Marek Polacek <polacek@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-09-12 14:21:25 -04:00
Edwin Lu d0c0841531 RISC-V: Support vnclip idiom testcase [PR120378]
This patch contains testcases for PR120378 after the change made to
support the vnclipu variant of the SAT_TRUNC pattern.

	PR target/120378

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/pr120378-1.c: New test.
	* gcc.target/riscv/rvv/autovec/pr120378-2.c: New test.
	* gcc.target/riscv/rvv/autovec/pr120378-3.c: New test.
	* gcc.target/riscv/rvv/autovec/pr120378-4.c: New test.

Signed-off-by: Edwin Lu <ewlu@rivosinc.com>
2025-09-12 10:34:13 -07:00
Edwin Lu bf257c548c Match: Support SAT_TRUNC variant NARROW_CLIP
This patch tries to add support for a variant of SAT_TRUNC where
negative numbers are clipped to 0 instead of NARROW_TYPE_MAX_VALUE.
This form is seen in x264, aka

UT clip (T a)
{
  return a & (UT)(-1) ? (-a) >> 31 : a;
}

Where sizeof(UT) < sizeof(T)

I'm unable to get the SAT_TRUNC pattern to appear on x86_64, however it
does appear when building for riscv as seen below:

Before this patch:
  <bb 3> [local count: 764504183]:
  # i_21 = PHI <i_14(8), 0(15)>
  # vectp_x.10_54 = PHI <vectp_x.10_55(8), x_10(D)(15)>
  # vectp_res.20_66 = PHI <vectp_res.20_67(8), res_11(D)(15)>
  # ivtmp_70 = PHI <ivtmp_71(8), _69(15)>
  _72 = .SELECT_VL (ivtmp_70, POLY_INT_CST [4, 4]);
  _1 = (long unsigned int) i_21;
  _2 = _1 * 4;
  _3 = x_10(D) + _2;
  ivtmp_53 = _72 * 4;
  vect__4.12_57 = .MASK_LEN_LOAD (vectp_x.10_54, 32B, { -1, ... }, _56(D), _72, 0);
  vect_x.13_58 = VIEW_CONVERT_EXPR<vector([4,4]) unsigned int>(vect__4.12_57);
  vect__38.15_60 = -vect_x.13_58;
  vect__15.16_61 = VIEW_CONVERT_EXPR<vector([4,4]) int>(vect__38.15_60);
  vect__16.17_62 = vect__15.16_61 >> 31;
  mask__29.14_59 = vect_x.13_58 > { 255, ... };
  vect__17.18_63 = VEC_COND_EXPR <mask__29.14_59, vect__16.17_62, vect__4.12_57>;
  vect__18.19_64 = (vector([4,4]) unsigned char) vect__17.18_63;
  _4 = *_3;
  _5 = res_11(D) + _1;
  x.0_12 = (unsigned int) _4;
  _38 = -x.0_12;
  _15 = (int) _38;
  _16 = _15 >> 31;
  _29 = x.0_12 > 255;
  _17 = _29 ? _16 : _4;
  _18 = (unsigned char) _17;
  .MASK_LEN_STORE (vectp_res.20_66, 8B, { -1, ... }, _72, 0, vect__18.19_64);
  i_14 = i_21 + 1;
  vectp_x.10_55 = vectp_x.10_54 + ivtmp_53;
  vectp_res.20_67 = vectp_res.20_66 + _72;
  ivtmp_71 = ivtmp_70 - _72;
  if (ivtmp_71 != 0)
    goto <bb 8>; [89.00%]
  else
    goto <bb 17>; [11.00%]

After this patch:

 <bb 3> [local count: 764504183]:
  # i_21 = PHI <i_14(8), 0(15)>
  # vectp_x.10_68 = PHI <vectp_x.10_69(8), x_10(D)(15)>
  # vectp_res.15_75 = PHI <vectp_res.15_76(8), res_11(D)(15)>
  # ivtmp_79 = PHI <ivtmp_80(8), _78(15)>
  _81 = .SELECT_VL (ivtmp_79, POLY_INT_CST [4, 4]);
  _1 = (long unsigned int) i_21;
  _2 = _1 * 4;
  _3 = x_10(D) + _2;
  ivtmp_67 = _81 * 4;
  vect__4.12_71 = .MASK_LEN_LOAD (vectp_x.10_68, 32B, { -1, ... }, _70(D), _81, 0);
  vect_patt_37.13_72 = MAX_EXPR <{ 0, ... }, vect__4.12_71>;
  vect_patt_39.14_73 = .SAT_TRUNC (vect_patt_37.13_72);
  _4 = *_3;
  _5 = res_11(D) + _1;
  x.0_12 = (unsigned int) _4;
  _38 = -x.0_12;
  _15 = (int) _38;
  _16 = _15 >> 31;
  _29 = x.0_12 > 255;
  _17 = _29 ? _16 : _4;
  _18 = (unsigned char) _17;
  .MASK_LEN_STORE (vectp_res.15_75, 8B, { -1, ... }, _81, 0, vect_patt_39.14_73);
  i_14 = i_21 + 1;
  vectp_x.10_69 = vectp_x.10_68 + ivtmp_67;
  vectp_res.15_76 = vectp_res.15_75 + _81;
  ivtmp_80 = ivtmp_79 - _81;
  if (ivtmp_80 != 0)
    goto <bb 8>; [89.00%]
  else
    goto <bb 17>; [11.00%]

gcc/ChangeLog:

	* match.pd: New NARROW_CLIP variant for SAT_TRUNC.
	* tree-vect-patterns.cc (gimple_unsigned_integer_narrow_clip):
	Add new decl for NARROW_CLIP.
	(vect_recog_sat_trunc_pattern): Add NARROW_CLIP check.

Signed-off-by: Edwin Lu <ewlu@rivosinc.com>
2025-09-12 10:34:13 -07:00
H.J. Lu 5d6ddba764 sparc: Compile TLS LD tests with -fPIC
After

commit 8cad8f94b4
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Sep 5 15:40:51 2025 -0700

    c: Update TLS model after processing a TLS variable

GCC will upgrade local-dynamic TLS model to local-exec without -fPIC.
Compile TLS LD tests with -fPIC to keep local-dynamic TLS model.

	PR testsuite/121888
	* gcc.target/sparc/tls-ld-int16.c: Compile with -fPIC.
	* gcc.target/sparc/tls-ld-int32.c: Likewise.
	* gcc.target/sparc/tls-ld-int64.c: Likewise.
	* gcc.target/sparc/tls-ld-int8.c: Likewise.
	* gcc.target/sparc/tls-ld-uint16.c: Likewise.
	* gcc.target/sparc/tls-ld-uint32.c: Likewise.
	* gcc.target/sparc/tls-ld-uint8.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-12 08:28:54 -07:00
David Malcolm 259347de43 diagnostics: handle fatal_error in SARIF output [PR120063]
gcc/ChangeLog:
	PR diagnostics/120063
	* diagnostics/context.cc (context::execution_failed_p): Also treat
	any kind::fatal errors as leading to failed execution.
	* diagnostics/sarif-sink.cc (maybe_get_sarif_level): Handle
	kind::fatal as SARIF level "error".

gcc/testsuite/ChangeLog:
	PR diagnostics/120063
	* gcc.dg/fatal-error.c: New test.
	* gcc.dg/fatal-error-html.py: New test.
	* gcc.dg/fatal-error-sarif.py: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-12 10:24:36 -04:00
David Malcolm 38cb428918 diagnostics: fix crash-handling inside nested diagnostics [PR121876]
PR diagnostics/121876 tracks an issue inside our crash-handling, where
if an ICE happens when we're within a nested diagnostic, an assertion
fails inside diagnostic::context::set_diagnostic_buffer, leading to
a 2nd ICE.  Happily, this does not infinitely recurse, but it obscures
the original ICE and the useful part of the backtrace, and any SARIF or
HTML sinks we were writing to are left as empty files.

This patch tweaks the above so that the assertion doesn't fail, and adds
test coverage (via a plugin) to ensure that such ICEs/crashes are
gracefully handled and e.g. captured in SARIF/HTML output.

gcc/ChangeLog:
	PR diagnostics/121876
	* diagnostics/buffering.cc (context::set_diagnostic_buffer): Add
	early reject of the no-op case.

gcc/testsuite/ChangeLog:
	PR diagnostics/121876
	* gcc.dg/plugin/crash-test-nested-ice-html.py: New test.
	* gcc.dg/plugin/crash-test-nested-ice-sarif.py: New test.
	* gcc.dg/plugin/crash-test-nested-ice.c: New test.
	* gcc.dg/plugin/crash-test-nested-write-through-null-html.py: New test.
	* gcc.dg/plugin/crash-test-nested-write-through-null-sarif.py: New test.
	* gcc.dg/plugin/crash-test-nested-write-through-null.c: New test.
	* gcc.dg/plugin/crash_test_plugin.cc: Add "nested" argument, and when
	set, inject the problem within a nested diagnostic.
	* gcc.dg/plugin/plugin.exp: Add crash-test-nested-ice.c and
	crash-test-nested-write-through-null.c.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-12 10:24:36 -04:00
David Malcolm 85a97e1a8e testsuite: fix typo in name of plugin test file
gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/crash-test-write-though-null-sarif.c: Rename to...
	* gcc.dg/plugin/crash-test-write-through-null-sarif.c: ...this.
	* gcc.dg/plugin/crash-test-write-though-null-stderr.c: Rename to...
	* gcc.dg/plugin/crash-test-write-through-null-stderr.c: ...this.
	* gcc.dg/plugin/plugin.exp: Update for above renamings.  Sort the
	test files for crash_test_plugin.cc alphabetically.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-09-12 10:24:35 -04:00
Jeff Law e3ade1b989 [RISC-V] Adjust ABI specification in recently added Andes tests
Another lp64 vs lp64d issue.  This time adjusting a #include in the test isn't
sufficient.  So instead this sets the ABI to lp64d instead of lp64.  I don't
think that'll impact the test materially.

Tested on the BPI and Pioneer systems where it fixes the failures with the
Andes tests.  Pushing to the trunk.

gcc/testsuite
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vd4dots.c:
	Adjust ABI specification.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vd4dotsu.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vd4dotu.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfncvtbf16s.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfpmadb.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfpmadt.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfwcvtsbf16.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vln8.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vd4dots.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vd4dotsu.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vd4dotu.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfncvtbf16s.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfpmadb.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfpmadt.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfwcvtsbf16.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vln8.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vd4dots.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vd4dotsu.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vd4dotu.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfncvtbf16s.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfpmadb.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfpmadt.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfwcvtsbf16.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vln8.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vd4dots.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vd4dotsu.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vd4dotu.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfncvtbf16s.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfpmadb.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfpmadt.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfwcvtsbf16.c:
	Likewise.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vln8.c:
	Likewise.
2025-09-12 07:17:56 -06:00
Jonathan Wakely d8f1655a78 libstdc++: Fix memory leak in PSTL TBB backend [PR117276]
Backport of upstream patch:
https://github.com/uxlfoundation/oneDPL/pull/1589

libstdc++-v3/ChangeLog:

	PR libstdc++/117276
	* include/pstl/parallel_backend_tbb.h (__func_task::finalize):
	Make deallocation unconditional.
2025-09-12 14:09:33 +01:00
Jonathan Wakely f534db54a6 libstdc++: Constrain __gnu_debug::bitset(const CharT*) constructor [PR121046]
The r16-3435-gbbc0e70b610f19 change (for LWG 4294) needs to be applied
to the debug mode __gnu_debug::bitset as well as the normal one.

libstdc++-v3/ChangeLog:

	PR libstdc++/121046
	* include/debug/bitset (bitset(const CharT*, ...)): Add
	constraints on CharT type.
2025-09-12 14:08:23 +01:00
Nathaniel Shead 85409b9d6a c++/modules: Fix missed unwrapping of STAT_HACK in ADL [PR121893]
My r16-3559-gc2e567a6edb563 reworked ADL for modules, including a change
to allow seeing module-linkage declarations if they only exist on the
instantiation path.  This caused a crash however as I neglected to
unwrap the stat hack wrapper when we were happy to see all declarations,
allowing search_adl to add non-functions to the overload set.

	PR c++/121893

gcc/cp/ChangeLog:

	* name-lookup.cc (name_lookup::adl_namespace_fns): Unwrap the
	STAT_HACK also when on_inst_path.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/adl-10_a.C: New test.
	* g++.dg/modules/adl-10_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-09-12 22:50:39 +10:00
Nathaniel Shead b9fde0219f ipa-free-lang-data: Don't walk into DECL_CHAIN when finding decls/types [PR121865]
On a DECL, TREE_CHAIN will find any other declarations in the same
binding level.  This caused an ICE in PR121865 because the next entity
in the binding level was the uninstantiated unique friend 'foo', for
which after being found the compiler tries to generate a mangled name
for it and crashes.

This didn't happen in non-modules testcases only because normally the
unique friend function would have been chained after its template_decl,
and find_decl_types_r bails on lang-specific nodes so it never saw the
uninstantiated decl.  With modules however the order of chaining
changed, causing the error.

I don't think it's ever necessary to walk into the DECL_CHAIN, from what
I can see; other cases where it might be useful (block vars or type
fields) are already handled explicitly elsewhere, and only one test
fails because of the change, due to accidentally relying on this "walk
into the next in-scope declaration" behaviour.

	PR c++/121865

gcc/ChangeLog:

	* ipa-free-lang-data.cc (find_decls_types_r): Don't walk into
	DECL_CHAIN for any DECL.

gcc/testsuite/ChangeLog:

	* g++.dg/lto/pr101396_0.C: Ensure A will be walked into (and
	isn't constant-folded out of the GIMPLE for the function).
	* g++.dg/lto/pr101396_1.C: Add message.
	* g++.dg/modules/lto-4_a.C: New test.
	* g++.dg/modules/lto-4_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Richard Biener <rguenther@suse.de>
2025-09-12 21:58:09 +10:00
Jonathan Wakely 4fe3b8b8db libstdc++: Fix bootstrap failure in atomicity.cc
My r16-3810-g6456da6bab8a2c changes broke bootstrap for targets that use
the mutex-based atomic helpers. This fixes it by casting away the
unnecessary volatile-qualification on the _Atomic_word* before passing
it to __exchange_and_add_single.

libstdc++-v3/ChangeLog:

	* config/cpu/generic/atomicity_mutex/atomicity.h
	(__exchange_and_add): Use const_cast to remove volatile.
2025-09-12 11:35:41 +01:00
Eric Botcazou 1d866f3b1c Minor tweaks to ipa-pure-const.cc
gcc/
	* ipa-pure-const.cc (check_stmt): Minor formatting tweaks.
	(pass_data_nothrow): Fix pasto in description.
2025-09-12 11:31:27 +02:00
Tamar Christina 443fc6ade9 middle-end: Use addhn for compression instead of inclusive OR when reducing comparison values
Given a sequence such as

int foo ()
{
#pragma GCC unroll 4
  for (int i = 0; i < N; i++)
    if (a[i] == 124)
      return 1;

  return 0;
}

where a[i] is long long, we will unroll the loop and use an OR reduction for
early break on Adv. SIMD.  Afterwards the sequence is followed by a compression
sequence to compress the 128-bit vectors into 64-bits for use by the branch.

However if we have support for add halving and narrowing then we can instead of
using an OR, use an ADDHN which will do the combining and narrowing.

Note that for now I only do the last OR, however if we have more than one level
of unrolling we could technically chain them.  I will revisit this in another
up coming early break series, however an unroll of 2 is fairly common.

gcc/ChangeLog:

	* internal-fn.def (VEC_TRUNC_ADD_HIGH): New.
	* doc/generic.texi: Document it.
	* optabs.def (vec_trunc_add_high): New.
	* doc/md.texi: Document it.
	* tree-vect-stmts.cc (vectorizable_early_exit): Use addhn if supported.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/vect-early-break-addhn_1.c: New test.
	* gcc.target/aarch64/vect-early-break-addhn_2.c: New test.
	* gcc.target/aarch64/vect-early-break-addhn_3.c: New test.
	* gcc.target/aarch64/vect-early-break-addhn_4.c: New test.
2025-09-12 08:30:55 +01:00
Tamar Christina 4ce2556991 Aarch64: Add support for addhn vectorizer optabs for Adv.SIMD
This implements the new vector optabs vec_<su>addh_narrow<mode>
adding support for in-vectorizer use for early break.

gcc/ChangeLog:

	* config/aarch64/aarch64-simd.md (vec_addh_narrow<mode>): New.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/vect-addhn_1.c: New test.
2025-09-12 08:29:46 +01:00
Tamar Christina 0ee908659e middle-end: clear the user unroll flag if the cost model has overriden it
If the user has requested loop unrolling through pragma GCC unroll then at the
moment we only set LOOP_VINFO_USER_UNROLL if the vectorizer has not overrode the
unroll factor (through backend costing) or if the VF made the requested unroll
factor be 1.

When we have a loop of say int and a pragma unroll 4

If the vectorizer picks V4SI as the mode, the requested unroll ended up exactly
matching the VF. As such the requested unroll is 1 and we don't clear the pragma.

So it did honor the requested unroll factor. However since we didn't set the
unroll amount back and left it at 4 the rtl unroller won't use the rtl cost
model at all and just unroll the vector loop 4 times.

But of these events are costing related, and so it stands to reason that we
should set LOOP_VINFO_USER_UNROLL to we return the RTL unroller to use the
backend costing for any further unrolling.

gcc/ChangeLog:

	* tree-vect-loop.cc (vect_analyze_loop_1): If the unroll pragma was set
	mark it as handled.
	* doc/extend.texi (pragma GCC unroll): Update documentation.
2025-09-12 08:28:44 +01:00
GCC Administrator 2343cc8d04 Daily bump. 2025-09-12 00:20:54 +00:00
Trevor Gross 9b6df34aa5 doc: Correct the return type of float comparison
Documentation for `__cmpsf2` and similar functions currently indicate a
return type of `int`. This is not correct however; the `libgcc`
functions return `CMPtype`, the size of which is determined by the
`libgcc_cmp_return` mode.

Update documentation to use `CMPtype` and indicate that this is
target-dependent, also mentioning the usual modes.

Reported-by: beetrees <b@beetr.ee>
Fixes: https://github.com/rust-lang/compiler-builtins/issues/919#issuecomment-2905347318
Signed-off-by: Trevor Gross <tmgross@umich.edu>

	* doc/libgcc.texi (Comparison functions): Document functions as
	returning CMPtype.
2025-09-11 20:52:27 +00:00
Harald Anlauf 0899b826f7 Fortran: fix assignment to allocatable scalar polymorphic component [PR121616]
PR fortran/121616

gcc/fortran/ChangeLog:

	* primary.cc (gfc_variable_attr): Properly set dimension attribute
	from a component ref.

gcc/testsuite/ChangeLog:

	* gfortran.dg/alloc_comp_assign_17.f90: New test.
2025-09-11 20:17:31 +02:00
Jonathan Wakely 9a2b1acda0 libstdc++: Trap on std::shared_ptr reference count overflow [PR71945]
This adds checks when incrementing the shared count and weak count and
will trap if they would be be incremented past its maximum. The maximum
value is the value at which incrementing it produces an invalid
use_count(). So that is either the maximum positive value of
_Atomic_word, or for targets where we now allow the counters to wrap
around to negative values, the "maximum" value is -1, because that is
the value at which one more increment overflows the usable range and
resets the counter to zero.

For the weak count the maximum is always -1 as we always allow that
count to use nagative values, so we only tap if it wraps all the way
back to zero.

libstdc++-v3/ChangeLog:

	PR libstdc++/71945
	* include/bits/shared_ptr_base.h (_Sp_counted_base::_S_chk):
	Trap if a reference count cannot be incremented any higher.
	(_Sp_counted_base::_M_add_ref_copy): Use _S_chk.
	(_Sp_counted_base::_M_add_weak_ref): Likewise.
	(_Sp_counted_base<_S_mutex>::_M_add_ref_lock_nothrow): Likewise.
	(_Sp_counted_base<_S_atomic>::_M_add_ref_lock_nothrow): Likewise.
	(_Sp_counted_base<_S_single>::_M_add_ref_copy): Use _S_chk.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-11 14:43:57 +01:00
Jonathan Wakely faae3692f7 libstdc++: Allow std::shared_ptr reference counts to be negative [PR71945]
This change doubles the effective range of the std::shared_ptr and
std::weak_ptr reference counts for most 64-bit targets.

The counter type, _Atomic_word, is usually a signed 32-bit int (except
on Solaris v9 where it is a signed 64-bit long). The return type of
std::shared_ptr::use_count() is long. For targets where long is wider
than _Atomic_word (most 64-bit targets) we can treat the _Atomic_word
reference counts as unsigned and allow them to wrap around from their
most positive value to their most negative value without any problems.
The logic that operates on the counts only cares if they are zero or
non-zero, and never performs relational comparisons. The atomic
fetch_add operations on integers are required by the standard to behave
like unsigned types, so that overflow is well-defined:

  "the result is as if the object value and parameters were converted to
  their corresponding unsigned types, the computation performed on those
  types, and the result converted back to the signed type."

So if we allow the counts to wrap around to negative values, all we need
to do is cast the value to make_unsigned_t<_Atomic_word> before
returning it as long from the use_count() function.

In practice even exceeding INT_MAX is extremely unlikely, as it would
require billions of shared_ptr or weak_ptr objects to have been
constructed and never destroyed. However, if that happens we now have
double the range before the count returns to zero and causes problems.

Some of the member functions for the _Sp_counted_base<_S_single>
specialization are adusted to use the __atomic_add_single and
__exchange_and_add_single helpers instead of plain ++ and -- operations.
This is done because those helpers use unsigned arithmetic, where the
plain increments and decrements would have undefined behaviour on
overflow.

libstdc++-v3/ChangeLog:

	PR libstdc++/71945
	* include/bits/shared_ptr_base.h
	(_Sp_counted_base::_M_get_use_count): Cast _M_use_count to
	unsigned before returning as long.
	(_Sp_counted_base<_S_single>::_M_add_ref_copy): Use atomic
	helper function to adjust ref count using unsigned arithmetic.
	(_Sp_counted_base<_S_single>::_M_weak_release): Likewise.
	(_Sp_counted_base<_S_single>::_M_get_use_count): Cast
	_M_use_count to unsigned before returning as long.
	(_Sp_counted_base<_S_single>::_M_add_ref_lock_nothrow): Use
	_M_add_ref_copy to do increment using unsigned arithmetic.
	(_Sp_counted_base<_S_single>::_M_release): Use atomic helper and
	_M_weak_release to do decrements using unsigned arithmetic.
	(_Sp_counted_base<_S_mutex>::_M_release): Add comment.
	(_Sp_counted_base<_S_single>::_M_weak_add_ref): Remove
	specialization.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-11 14:43:56 +01:00
Jonathan Wakely 6456da6bab libstdc++: Make atomicity helpers use unsigned arithmetic [PR121148]
The standard requires that std::atomic<integral-type>::fetch_add does
not have undefined behaviour for signed overflow, instead it wraps like
unsigned integers. The compiler ensures this is true for the atomic
built-ins that std::atomic uses, but it's not currently true for the
__gnu_cxx::__exchange_and_add and __gnu_cxx::__atomic_add functions
defined in libstdc++, which operate on type _Atomic_word.

For the inline __exchange_and_add_single function (used when there's
only one thread in the process), we can copy the value to an unsigned
long and do the addition on that, then assign it back to the
_Atomic_word variable.

The __exchange_and_add in config/cpu/generic/atomicity_mutex/atomicity.h
locks a mutex and then performs exactly the same steps as
__exchange_and_add_single.  Calling __exchange_and_add_single instead of
duplicating the code benefits from the fix just made to
__exchange_and_add_single.

For the remaining config/cpu/$arch/atomicity.h implementations, they
either use inline assembly which uses wrapping instructions (so no
changes needed), or we can fix them by compiling with -fwrapv.

After ths change, UBsan no longer gives an error for:

  _Atomic_word i = INT_MAX;
  __gnu_cxx::__exchange_and_add_dispatch(&i, 1);

/usr/include/c++/14/ext/atomicity.h:85:12: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'

libstdc++-v3/ChangeLog:

	PR libstdc++/121148
	* config/cpu/generic/atomicity_mutex/atomicity.h
	(__exchange_and_add): Call __exchange_and_add_single.
	* include/ext/atomicity.h (__exchange_and_add_single): Use an
	unsigned type for the addition.
	* libsupc++/Makefile.am (atomicity.o): Compile with -fwrapv.
	* libsupc++/Makefile.in: Regenerate.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-11 14:43:55 +01:00
H.J. Lu 46028a2f40 pr107421.f90: Require PIE and pass -fPIE for non-x86 targets
-mno-direct-extern-access is used to disable direct access to external
symbol from executable with and without PIE for x86.  Require PIE and
pass -fPIE to disable direct access to external symbol for other targets.

	PR fortran/107421
	PR testsuite/121848
	* gfortran.dg/gomp/pr107421.f90: Require PIE and pass -fPIE for
	non-x86 targets.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-11 06:40:47 -07:00
Jonathan Wakely d99c6786c3 libstdc++: Use consteval for _S_noexcept() helper functions
These _S_noexcept() functions are only used in noexcept-specifiers and
never need to be called at runtime. They can be immediate functions,
i.e. consteval.

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h (_IterMove::_S_noexcept)
	(_IterSwap::_S_noexcept): Change constexpr to consteval.
	* include/bits/ranges_base.h (_Begin::_S_noexcept)
	(_End::_S_noexcept, _RBegin::_S_noexcept, _REnd::_S_noexcept)
	(_Size::_S_noexcept, _Empty::_S_noexcept, _Data::_S_noexcept):
	Likewise.
	* include/std/concepts (_Swap::_S_noexcept): Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-11 14:38:59 +01:00
Jonathan Wakely f463e6bd8e libstdc++: Add always_inline to ranges iterator ops and access functions
Most of the basis operations for ranges such as ranges::begin and
ranges::next are trivial one-line function bodies, so can be made
always_inline to reduce the abstraction penalty for -O0 code.

Now that we no longer need to support the -fconcepts-ts grammar, we can
also move some [[nodiscard]] attributes to the more natural position
before the function declaration, instead of between the declarator-id
and the function parameters, e.g. we can use:

  template<typename T> requires C<T> [[nodiscard]] auto operator()(T&&)

instead of:

  template<typename T> requires C<T> auto operator() [[nodiscard]] (T&&)

The latter form was necessary because -fconcepts-ts used a different
grammar for the requires-clause, parsing 'C<T>[[x]]' as a subscripting
operator with an ill-formed argument '[x]'. In the C++20 grammar you
would need to use parentheses to use a subscript in a constraint, so
without parentheses it's parsed as an attribute.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (__detail::__to_unsigned_like)
	(__access::__possible_const_range, __access::__as_const)
	(__distance_fn::operator(), __next_fn::operator())
	(__prev_fn::operator()): Add always_inline attribute.
	(_Begin::operator(), _End::operator(), _RBegin::operator())
	(_REnd::operator(), _Size::operator(), _SSize::operator())
	(_Empty::operator(), _Data::operator(), _SSize::operator()):
	Likewise. Move nodiscard attribute to start of declaration.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-11 14:38:58 +01:00
H.J. Lu 9eab6c6f22 testsuite: Add tests for PR c/107419 and PR c++/107393
Both C and C++ frontends should set a tentative TLS model in grokvardecl
and update TLS mode with the default TLS access model after a TLS variable
has been fully processed if the default TLS access model is stronger.

	PR c/107419
	PR c++/107393
	* c-c++-common/tls-attr-common.c: New test.
	* c-c++-common/tls-attr-le-pic.c: Likewise.
	* c-c++-common/tls-attr-le-pie.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-11 06:36:04 -07:00
Giuseppe D'Angelo b2b2ac34ba libstdc++: optimize weak_ptr converting constructor/assignment
Converting a weak_ptr<Derived> to a weak_ptr<Base> requires calling
lock() on the source object in the general case.

Although the source weak_ptr<Derived> does contain a raw pointer to
Derived, we can't just get it and (up)cast it to Base, as that will
dereference the pointer in case Base is a virtual base class of Derived.

We don't know if the managed object is still alive, and therefore if
this operation is safe to do; we therefore temporarily lock() the source
weak_ptr, do the cast using the resulting shared_ptr, and then discard
this shared_ptr. Simply checking the strong counter isn't sufficient,
because if multiple threads are involved then we'd have a race / TOCTOU
problem; the object may get destroyed after we check the strong counter
and before we cast the pointer.

However lock() is not necessary if we know that Base is *not* a virtual
base class of Derived; in this case we can avoid the relatively
expensive call to lock() and just cast the pointer. This commit uses
the newly added builtin to detect this case and optimize std::weak_ptr's
converting constructors and assignment operations.

Apart from non-virtual bases, there's also another couple of interesting
cases where we can also avoid locking. Specifically:

1) converting a weak_ptr<T[N]> to a weak_ptr<T cv[]>;
2) converting a weak_ptr<T*> to a weak_ptr<T const * const> or similar.

Since this logic is going to be used by multiple places, I've
centralized it in a new static helper.

libstdc++-v3/ChangeLog:

	* include/bits/shared_ptr_base.h (__weak_ptr): Avoid calling
	lock() when converting or assigning a weak_ptr<Derived> to
	a weak_ptr<Base> in case Base is not a virtual base of Derived.
	This logic is centralized in _S_safe_upcast, called by the
	various converting constructors/assignment operators.
	(_S_safe_upcast): New helper function.
	* testsuite/20_util/weak_ptr/cons/virtual_bases.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2025-09-11 14:56:28 +02:00
H.J. Lu 0b0ffa44c1 c++: Don't upgrade TLS model if TLS model isn't set.
Don't upgrade TLS model when cplus_decl_attributes is called on a thread
local variable whose TLS model isn't set yet.

gcc/cp/

	PR c++/121889
	* decl2.cc (cplus_decl_attributes): Don't upgrade TLS model if
	TLS model isn't set yet.

gcc/testsuite/

	PR c++/121889
	* g++.dg/tls/pr121889.C: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-11 05:33:40 -07:00
Wilco Dijkstra b996d4509f AArch64: Add isfinite expander [PR 66462]
Add an expander for isfinite using integer arithmetic.  This is
typically faster and avoids generating spurious exceptions on
signaling NaNs.  This fixes part of PR66462.

int isfinite1 (float x) { return __builtin_isfinite (x); }

Before:
	fabs    s0, s0
	mov     w0, 2139095039
	fmov    s31, w0
	fcmp    s0, s31
	cset    w0, hi
	eor     w0, w0, 1
	ret

After:
	fmov    w1, s0
	mov     w0, -16777216
	cmp     w0, w1, lsl 1
	cset    w0, hi
	ret

gcc:
	PR middle-end/66462
	* config/aarch64/aarch64.md (isfinite<mode>2): Add new expander.

gcc/testsuite:
	PR middle-end/66462
	* gcc.target/aarch64/pr66462.c: Add tests for isfinite.
2025-09-11 11:44:08 +00:00
Matteo Nicoli aa4aafbad5 tree-optimization/121595 - new fabs(a+0.0) -> fabs(a) pattern
With -fno-trapping-math it is safe to optimize fabs(a + 0.0) as
fabs (a).

	PR tree-optimization/121595
	* match.pd (fabs(a + 0.0) -> fabs (a)): Optimization pattern limited to
	the -fno-trapping-math case.

	* gcc.dg/fabs-plus-zero-1.c: New testcase.
	* gcc.dg/fabs-plus-zero-2.c: Likewise.

Signed-off-by: Matteo Nicoli <matteo.nicoli001@gmail.com>
Reviewed-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-11 13:19:03 +02:00
Xi Ruoyao 4bed08beba testsuite: LoongArch: Enable 16B atomic tests if the test machine supports LSX and SCQ
Enable those tests so we won't make too stupid mistakes in 16B atomic
implementation anymore.

All these test passed on a Loongson 3C6000/S except
atomic-other-int128.c.  With GDB patched to support sc.q
(https://sourceware.org/pipermail/gdb-patches/2025-August/220034.html)
this test also XPASS.

gcc/testsuite/ChangeLog:

	* lib/target-supports.exp
	(check_effective_target_loongarch_scq_hw): New.
	(check_effective_target_sync_int_128_runtime): Return 1 on
	loongarch64-*-* if hardware supports both LSX and SCQ.
	* gcc.dg/atomic-compare-exchange-5.c: Pass -mlsx -mscq for
	loongarch64-*-*.
	* gcc.dg/atomic-exchange-5.c: Likewise.
	* gcc.dg/atomic-load-5.c: Likewise.
	* gcc.dg/atomic-op-5.c: Likewise.
	* gcc.dg/atomic-store-5.c: Likewise.
	* gcc.dg/atomic-store-6.c: Likewise.
	* gcc.dg/simulate-thread/atomic-load-int128.c: Likewise.
	* gcc.dg/simulate-thread/atomic-other-int128.c: Likewise.
	(dg-final): xfail on loongarch64-*-* because  gdb does not
	handle sc.q properly yet.
2025-09-11 18:49:36 +08:00
Xi Ruoyao 4fcb26a357 LoongArch: Fix the semantic of 16B CAS
In a CAS operation, even if expected != *memory we still need to do an
atomic load of *memory into output.  But I made a mistake in the initial
implementation, causing the output to contain junk in this situation.

Like a normal atomic load, the atomic load embedded in the CAS semantic
is required to work on read-only page.  Thus we cannot rely on sc.q to
ensure the atomicity of the load.  Use LSX to perform the load instead,
and also use LSX to compare the 16B values to keep the ll-sc loop body
short.

gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_compare_and_swapti_scq):
	Require LSX.  Change the operands for the output, the memory,
	and the expected value to LSX vector modes.  Add a FCCmode
	output to indicate if CAS has written the desired value into
	memory.  Use LSX to atomically load both words of the 16B value
	in memory.
	(atomic_compare_and_swapti): Pun the modes to satisify
	the new atomic_compare_and_swapti_scq implementation.  Read the
	bool return value from the FCC instead of performing a
	comparision.
2025-09-11 18:49:36 +08:00
Xi Ruoyao 13ec1769fa LoongArch: Fix the "%t" modifier handling for (const_int 0)
This modifier is intended to output $r0 for (const_int 0), but the
logic:

GET_MODE (op) != TImode || (op != CONST0_RTX (TImode) && code != REG)

will reject (const_int 0) because (const_int 0) actually does not have
a mode and GET_MODE will return VOIDmode for it.

Use reg_or_0_operand instead to fix the issue.

gcc/ChangeLog:

	* config/loongarch/loongarch.cc (loongarch_print_operand): Call
	reg_or_0_operand for checking the sanity of %t.
2025-09-11 18:49:33 +08:00
Jonathan Wakely 1b27e84713 libstdc++: Remove trailing whitespace in <syncstream>
libstdc++-v3/ChangeLog:

	* include/std/syncstream: Remove trailing whitespace.
2025-09-11 10:36:56 +01:00
Richard Biener 0887961f9e tree-optimization/121703 - UBSAN error with moving from uninit data
The PR reports

vectorizer.h:276:3: runtime error: load of value 32695, which is not a valid value for type 'internal_fn'

which I believe is from

      slp_node->data = new vect_load_store_data (std::move (ls));

where 'ls' can be partly uninitialized (and that data will be not
used, but of course the move CTOR doesn't know this).  The following
tries to fix that by using value-initialization of 'ls'.

	PR tree-optimization/121703
	* tree-vect-stmts.cc (vectorizable_store): Value-initialize ls.
	(vectorizable_load): Likewise.
2025-09-11 11:26:24 +02:00
Tsukasa OI ebd64a4251 RISC-V: Suppress cross CC sibcall optimization from vector
In general, tail call optimization requires that the callee's saved
registers are a superset of the caller's.

The Standard Vector Calling Convention Variant (assembler: .variant_cc)
requires that a function with this calling convention preserves vector
registers v1-v7 and v24-v31 across calls (i.e. callee-saved).  However,
the same set of registers are (function-local) temporary registers
(i.e. caller-saved) on the normal (non-vector) calling convention.

Even if a function with this calling convention variant calls another
function with a non-vector calling convention, those vector registers
are correctly clobbered -- except when the sibling (tail) call
optimization occurs as it violates the general rule mentioned above.

If this happens, following function body:

1.  Save v1-v7 and v24-v31 for clobbering
2.  Call another function with a non-vector calling convention
    (which may destroy v1-v7 and/or v24-v31)
3.  Restore v1-v7 and v24-v31
4.  Return.

may be incorrectly optimized into the following sequence:

1.  Save v1-v7 and v24-v31 for clobbering
2.  Restore v1-v7 and v24-v31 (?!)
3.  Jump to another function with a non-vector calling convention
    (which may destroy v1-v7 and/or v24-v31).

This commit suppresses cross CC sibling call optimization from
the vector calling convention variant.

gcc/ChangeLog:

	* config/riscv/riscv.cc (riscv_function_ok_for_sibcall):
	Suppress cross calling convention sibcall optimization from
	the vector calling convention variant.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/base/abi-call-variant_cc-sibcall.c: New test.
	* gcc.target/riscv/rvv/base/abi-call-variant_cc-sibcall-indirect-1.c: Ditto.
	* gcc.target/riscv/rvv/base/abi-call-variant_cc-sibcall-indirect-2.c: Ditto.
2025-09-11 09:19:08 +00:00
Richard Biener e9c2a69fe6 tree-optimization/121829 - bogus CFG with asm goto
When the vectorizer removes a forwarder created earlier by split_edge
it uses redirect_edge_pred for convenience and efficiency.  That breaks
down when the edge split is originating from an asm goto as that is
a jump that needs adjustments from redirect_edge_and_branch.  The
following factores a simple vect_remove_forwarder handling this
situation appropriately.

	PR tree-optimization/121829
	* cfgloopmanip.cc (create_preheader): Ensure we can insert
	at the end of a preheader.

	* gcc.dg/torture/pr121829.c: New testcase.
2025-09-11 11:16:58 +02:00
Richard Biener 5c4f1313e7 Deal with prior EH/abormal cleanup when fixing up noreturn calls
When a dead EH or abnormal edge makes a call queued for noreturn fixup
unreachable, just skip processing it.

	PR tree-optimization/121870
	* tree-ssa-propagate.cc
	(substitute_and_fold_engine::substitute_and_fold): Skip
	removed stmts from noreturn fixup.

	* g++.dg/torture/pr121870.C: New testcase.
2025-09-11 11:12:13 +02:00
Marc Poulhiès 165b029d4d ada: add BACKLOG_MAX OS constant
BACKLOG_MAX represents the number of outstanding connections in the
socket's listen queue.

gcc/ada/ChangeLog:

	* libgnat/g-socket.adb (Listen_Socket): Change default value.
	* libgnat/g-socket.ads (Listen_Socket): Likewise.
	* s-oscons-tmplt.c (BACKLOG_MAX): New.
2025-09-11 11:10:50 +02:00
Marc Poulhiès 195b495917 ada: Minor comment tweaks
gcc/ada/ChangeLog:

	* env.c (__gnat_clearenv): Adjust comment.
	* libgnarl/a-intnam__bsd.ads: Fix copyright date.
2025-09-11 11:10:50 +02:00
Eric Botcazou 7efa3b5b2f ada: Give a warning for huge imported objects
This is a follow-up to a recent change, where a warning was implemented
for huge library-level objects.  However it is not given if the objects
are imported, although an indirection is also added for them under the
hood to match the export side.

gcc/ada/ChangeLog:

	* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Give a
	warning for huge imported objects as well.
2025-09-11 11:10:50 +02:00
Eric Botcazou 88a389ac86 ada: Get rid of TYPE_ALIGN_OK flag in gcc-interface
The TYPE_ALIGN_OK flag had originally been a GCC flag tested in the RTL
expander and was at some point kicked out of the middle-end to become a
pure Gigi flag.  But it's only set for tagged types and CW-equivalent
types and can be replaced by a explicit predicate without too much work.

gcc/ada/ChangeLog:

	* gcc-interface/ada-tree.h (TYPE_ALIGN_OK): Delete.
	* gcc-interface/decl.cc (gnat_to_gnu_entity): Do not set it.
	* gcc-interface/gigi.h (standard_datatypes): Add ADT_tag_name_id.
	(tag_name_id): New macro.
	(type_is_tagged_or_cw_equivalent): New inline predicate.
	* gcc-interface/trans.cc (gigi): Initialize tag_name_id.
	(gnat_to_gnu) <N_Unchecked_Type_Conversion>: Replace tests on
	TYPE_ALIGN_OK with calls to type_is_tagged_or_cw_equivalent.
	(addressable_p): Likewise.
	* gcc-interface/utils.cc (convert): Likewise.
	* gcc-interface/utils2.cc (build_binary_op): Likewise.
2025-09-11 11:10:50 +02:00
Eric Botcazou c93fe0be50 ada: Fix crash on reference to aliased object of packed array type with -g
This happens when the object is declared in another compilation unit.

gcc/ada/ChangeLog:

	* gcc-interface/misc.cc (gnat_get_array_descr_info): In the record
	type case, bail out if the original array type cannot be retrieved.
2025-09-11 11:10:50 +02:00
Eric Botcazou 3a3854f3ea ada: Implement overflow checking for unsigned types
The implementation is essentially mirrored from the one for signed types.

gcc/ada/ChangeLog:

	* gcc-interface/gigi.h (standard_datatypes): Add ADT_uns_mulv64_decl
	and ADT_uns_mulv128_decl.
	(uns_mulv64_decl): New macro.
	(uns_mulv128_decl): Likewise.
	* gcc-interface/trans.cc (gigi): Create the uns_mulv64_decl and
	uns_mulv128_decl declarations.
	(gnat_to_gnu) <N_Op_Add>: Perform an overflow check for unsigned
	integer addition, subtraction and multiplication if required.
	<N_Op_Minus>: Perform an overflow check for unsigned integer
	negation if required.
	(build_unary_op_trapv): Add support for unsigned types.
	(build_binary_op_trapv): Likewise.
	<MINUS_EXPR>: Perform the check if the LHS is zero in the signed
	case as well.
2025-09-11 11:10:49 +02:00
Steve Baird 571088f4d6 ada: Perform predicate check before, not after, parameter copy back.
In the case of a call to a subprogram that has an out (or in-out) parameter
that is passed by copy, the caller performs copy-back after the call returns.
If the actual parameter is a view conversion to a subtype that has an enabled
predicate, then the predicate check performed at that point should be
performed before, not after, the operand of the view conversion is updated.

gcc/ada/ChangeLog:

	* exp_ch6.adb (Expand_Actuals): After building the tree for a
	predicate check, call Prepend_To instead of Append_To so that the
	check is performed before, instead of after, the corresponding
	parameter copy-back.
2025-09-11 11:10:49 +02:00
Viljar Indus b69dbe06f9 ada: Create a ghost region for pragma annotate
Create a ghost region for pragma annotate so that we are able to analyze
the entity references correctly inside the pragma.

gcc/ada/ChangeLog:

	* sem_prag.adb: Create a ghost region for pragma annotate before
	analyzing its arguments.
2025-09-11 11:10:49 +02:00
Viljar Indus 4183b13f04 ada: Check instantces of ghost iterator functions
Since we do not analyze the policy errors for expanded code we need to
check the functions specified in the Iterable aspect whenever we are
analyzing an iterator spcification with that aspect.

gcc/ada/ChangeLog:

	* sem_ch5.adb (Analyze_Iterator_Specification): Check ghost context
	of Iterable functions when handling iterator specifications with an
	Iterable aspect.
2025-09-11 11:10:49 +02:00
Viljar Indus 6989e0f3f8 ada: Update coding style
gcc/ada/ChangeLog:

	* ghost.adb (Check_Ghost_Policy): Update coding style.
2025-09-11 11:10:49 +02:00
Viljar Indus 354a1c35a2 ada: Ignore ghost policy errors inside aspect Iterable
It is OK to define a checked ghost type with an iterable aspect
that has ignored Iterable functions.

gcc/ada/ChangeLog:

	* ghost.adb (Check_Ghost_Policy): Avoid triggering a ghost
	policy error if the policy is referenced within the Iterable
	aspect.
2025-09-11 11:10:49 +02:00
Viljar Indus 28b38b266d ada: Check ghost level dependencies inside assignments
Check that entities on the RHS are ghost level dependent on the
entities on the LHS of the assignemnt.

gcc/ada/ChangeLog:

	* ghost.adb (Is_OK_Statement): Check the levels of the
	assignee with the levels of the entity are ghost level dependent.
	(Check_Assignement_Levels): New function for checking the level
	dependencies.
2025-09-11 11:10:49 +02:00
Piotr Trojanek 48f8e30279 ada: Tune description of Ghost_Assertion_Level
Fix grammar in comment.

gcc/ada/ChangeLog:

	* einfo.ads (Ghost_Assertion_Level): Fix comment.
2025-09-11 11:10:48 +02:00
Viljar Indus dded20c146 ada: Apply ghost regions for assigmnents correctly
When frontend is operating in GNATprove mode (where expander is disabled), it
should check ghost policy for assignment statements just like it does for other
statements. This is because we want ghost policy errors to be reported not just
by GNAT, but also by GNATprove.

Additionally we need to perform the checks for valid location of ghost assigments
based on the region around the assigment before we create the region for
the assignment itself.

gcc/ada/ChangeLog:

	* ghost.adb (Mark_And_Set_Ghost_Assignment): Create a ghost region
	for an assigment irregardless of whether the expander is active.
	Relocate the Assignment validity checks from Is_OK_Statement to
	this subprogram.
2025-09-11 11:10:48 +02:00
Gary Dismukes 767fce326e ada: Compiler crash on container aggregate association with nonstatic key choice
The compiler blows up on a container aggregate with a container element
association that has a key_choice given by a nonstatic key expression.
This happens in the size computation for the aggregate due to calling
Update_Choices with the nonstatic expression.  The fix is simply to
condition the call to Update_Choices on whether the choice expression
is static.

gcc/ada/ChangeLog:

	* exp_aggr.adb (Build_Container_Aggr_Code.Build_Size_Expr): In the case
	of an association with a single choice, only call Update_Choices when
	the choice expression is nonstatic.
2025-09-11 11:10:48 +02:00
Bob Duff 629f1de233 ada: Fix visibility bug related to target name
This patch fixes the following bug:
If the right-hand side of an expression contains a target name
(i.e. "@"), and also contains a reference to a user-defined operator
that is directly visible because of a "use type" clause on a renaming of
the package where the operator is declared, the compiler gives an
incorrect error saying that the renamed package is not visible.

It turns out that setting Entity of resolved nodes is unnecessary
and wrong; the fix is to simply remove that code.

gcc/ada/ChangeLog:

	* exp_ch5.adb
	(Expand_Assign_With_Target_Names.Replace_Target):
	Remove code setting Entity to Empty.
	* sinfo.ads (Has_Target_Names):
	Improve comment: add "@" to clarify what "target name"
	means, and remove the content-free phrase "and must
	be expanded accordingly."
2025-09-11 11:10:48 +02:00
Bob Duff f1887efb6d ada: Fix regression in Root_Type -- adjustment
Recent changes "Fix regression in Root_Type" and
"Crash on b3a1004 with assertions enabled" are partially
redundant; they are addressing the same bug.
This patch adjusts the former in the case of Root_Type.
But we leave Root_Type_If_Set alone; debugging printouts
should survive bugs when possible.

gcc/ada/ChangeLog:

	* einfo-utils.adb (Root_Type): Do not deal with missing Etype.
2025-09-11 11:10:48 +02:00
Bob Duff 61645a4f05 ada: Fix regression in Root_Type
Previous change, "Make pp and friends more robust (base type only)"
introduced a bug in Root_Type. Etype (T) can, in fact, be Empty
(but only in case of errors.) This patch fixes it.

gcc/ada/ChangeLog:

	* einfo-utils.adb (Root_Type): Deal with missing Etype.
	(Root_Type_If_Set): Likewise.
2025-09-11 11:10:48 +02:00
Javier Miranda ffcd00c6f1 ada: Crash on b3a1004 with assertions enabled
The compilation of files b3a10041.ads and b3a10042.adb crash when
the compiler is built with assertions enabled.

gcc/ada/ChangeLog:

	* freeze.adb (Freeze_Entity): Protect call to Associated_Storage_Pool
	since it cannot be used when the Etype is not set.
	* sem_ch3.adb (Access_Type_Declaration): Ditto.
	* sem_aux.adb (Is_Derived_Type): Protect call to Root_Type since it
	cannot be used when the Etype is not set.
2025-09-11 11:10:48 +02:00
Tonu Naks bca81f45b9 ada: Fix argument type of read() and write() on windows
gcc/ada/ChangeLog:

	* libgnat/s-crtl.ads: define unsigned
	* libgnat/s-crtl__mingw.adb (read, write): change arg type
2025-09-11 11:10:47 +02:00
Bob Duff e39c326733 ada: Allow implicit packing of arrays when larger than needed
For Implicit_Packing, do not require the Size clause to exactly match
the packed size.

For example, an array of 7 Booleans will fit in
7 bits if packed, or 7*8=56 bits if not packed.
This patch allows "for T'Size use 8;" to force packing
in Implicit_Packing mode; previously, the compiler
ignored Implicit_Packing unless it was exactly "use 7".

Apparently, customers have that sort of code, and the
whole point of Implicit_Packing is to allow such legacy
code to work.

We already do the right thing for records, at least in
cases tested.

We deliberately avoid changing the error messages given here.
They could possibly use some work, but there are subtle interactions
with the messages given in Sem_Ch13 for the same thing.

gcc/ada/ChangeLog:

	* freeze.adb (Freeze_Entity): Change "=" to ">=" in
	size comparison for Implicit_Packing mode.
	Keep it as "=" for giving error messages.
	* opt.ads (Implicit_Packing): Minor: correct obsolete
	comment.
2025-09-11 11:10:47 +02:00
Javier Miranda f2ba38d3ba ada: Crash on null aggregate of multidimensional type
A compiler built with assertions enabled crashes processing
a null aggregate of multidimensional type.

gcc/ada/ChangeLog:

	* sem_aggr.adb (Report_Null_Array_Constraint_Error): Adjust code
	for reporting the error on enumeration types.
	(Resolve_Null_Array_Aggregate): On multidimiensional arrays, avoid
	reporting the same error several times. Flag the node as raising
	constraint error when the bounds are known and some of them is
	known to raise constraint error.
2025-09-11 11:10:47 +02:00
Bob Duff a1b966f27a ada: Make pp and friends more robust (base type only)
Prior to this fix, if pp(N) tried to print a "base type only" field, and
Base_Type(N) was not yet set, it would raise an exception, which was
confusing. This patch makes it simply ignore such fields. Similarly
for Impl_Base_Type_Only and Root_Type_Only fields.

We do this by having alternative versions of Base_Type,
Implementation_Base_Type, and Root_Type that return Empty
in error cases, and call these alteratives from Treepr.
We don't want to Base_Type and friends to return Empty;
we want them to blow up when called from anywhere but
Treepr.

gcc/ada/ChangeLog:

	* atree.ads (Node_To_Fetch_From_If_Set): Alternative to
	Node_To_Fetch_From that returns Empty in error cases.
	For use only in Treepr.
	* treepr.adb (Print_Entity_Field): Avoid printing field
	if Node_To_Fetch_From_If_Set returns Empty.
	* einfo-utils.ads (Base_Type_If_Set): Alternative to
	Base_Type that returns Empty in error cases.
	(Implementation_Base_Type_If_Set): Likewise.
	(Root_Type_If_Set): Likewise.
	(Underlying_Type): Use more accurate result subtype.
	* einfo-utils.adb (Base_Type): Add Asserts.
	(Implementation_Base_Type): Add Assert; minor cleanup.
	(Root_Type): Add Assert; minor cleanup. Remove Assert that
	is redundant with predicate.
	(Base_Type_If_Set): Body of new function.
	(Implementation_Base_Type_If_Set): Body of new function.
	(Root_Type_If_Set): Body of new function.
2025-09-11 11:10:47 +02:00
Johannes Kliemann 7cbf4b85b2 ada: Disable signals when calling pthread_create on QNX
The QNX Certified Products Defect Notification from February 2025
mentions a potential memory leak when pthread_create is interrupted by a
signal. It recommends to disable signals for this function call.

gcc/ada/ChangeLog:

	* adaint.c: Add functions to disable and enable signals on QNX.
	* libgnarl/s-taprop__qnx.adb (Create_Task): Disable
	signals when calling pthread_create.
2025-09-11 11:10:47 +02:00
Gary Dismukes 6332005e91 ada: Refine condition for reporting warnings on components with abstract equality
The initial implementation of the warning resulted in unwanted false
positives for types that have a user-defined equality function (in
which case abstract equality on components will typically not ever
be invoked).  The conditions for reporting the warning are refined
by this change to exclude checking for presence of abstract component
equality functions in the case where the containing type has a user-defined
equality.

gcc/ada/ChangeLog:

	* exp_ch4.adb (Expand_N_Op_Eq): Test for absence of user-defined
	equality on type being compared (for both array and record types)
	as a condition for checking for abstract equality on component
	types. Add a "???" comment about current limitations on issuing
	the new warning.
	(Warn_On_Abstract_Equality_For_Component): Remove temporary disabling
	of the warning. Improve comment on declaration.
2025-09-11 11:10:47 +02:00
Ronan Desplanques 6b74844753 ada: Fix comments
This patch fixes a reference to an Ada RM clause, fixes an occurrence of
"unconstrained" that should have been "indefinite", and removes an
incorrect claim that completing a partial view without discriminants
with a full view with defaulted discriminants is an error situation.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Process_Discriminants, Process_Full_View): Fix
	comments.
2025-09-11 11:10:46 +02:00
Denis Mazzucato 405aeb22de ada: Fix compile time evaluation needed for static unfoldings
Unfolding of static expressions is needed when evaluating static bounds, even in
the presence of strict analysis. Otherwise, we may wrongly identify static
predicates as dynamic ones, and thus require unnecessary "others" default case.

gcc/ada/ChangeLog:

	* sem_attr.adb (Eval_Attribute): Remove strict analysis condition.
2025-09-11 11:10:46 +02:00
Denis Mazzucato a570b74074 ada: Better warning when single letter package conflicts with predefined unit naming
This patch improves the warning message when the actual file name of a child
package with a single letter parent isn't the expected one because it may
collide with a predefined unit name. The warning explain why in this specific
case the expected name is not the standard one using the minus to separate
parents with children.

gcc/ada/ChangeLog:

	* par-load.adb (Load): Better warning message.
2025-09-11 11:10:46 +02:00
Tucker Taft 017aad48e8 ada: Set Related_Expression on compiler-generated Valid_Scalars functions
When creating the local functions to implement the Valid_Scalars
attribute for array and record types, set a Related_Expression that
points to the original attribute reference (blah'Valid_Scalars).
This allows the Inspector to give a more user-friendly name
when these functions are called and they are known, for example,
to always return True.

gcc/ada/ChangeLog:

	* exp_attr.adb
	(Build_Array_VS_Func and Build_Record_VS_Func): Pass in the
	Attr as the Related_Node parametr when calling
	Make_Temporary for the Func_Id for the array and record
	Valid_Scalars local functions.
2025-09-11 11:10:46 +02:00
Ronan Desplanques e3b66ea7d8 ada: Improve documentation comment of Find_Type_Name
The meaning of the return value of Find_Type_Name depends greatly on
whether the declaration it's passed is a completion. This patch adds a
description of this to the documentation comment of Find_Type_Name.

gcc/ada/ChangeLog:

	* sem_ch3.ads (Find_Type_Name): Improve documentation comment.
2025-09-11 11:10:46 +02:00
Gary Dismukes 0e0b43564a ada: Disable new warning for composite equality ops that can raise Program_Error
The new warning is spuriously flagged on membership tests in
vss-xml-implementation-html_writer_data.adb, leading to the GNAT CB
failing, so we disable it until that issue can be resolved.

gcc/ada/ChangeLog:

	* exp_ch4.adb (Warn_On_Abstract_Equality_For_Component): Temporarily
	disable warning.
2025-09-11 11:10:46 +02:00
Tomasz Kamiński 61ce720b14 libstdc++: Tests of %W/%V/%U and %G for !ok date values.
libstdc++-v3/ChangeLog:

	* testsuite/std/time/year_month_day/io.cc: Additional tests.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-11 11:05:01 +02:00
Robin Dapp 75cad4640c RISC-V: Add min/max patterns for ifcvt.
ifcvt likes to emit

(set
  (if_then_else)
    (ge (reg 1) (reg2))
    (reg 1)
    (reg 2))

which can be recognized as min/max patterns in the backend.
This patch adds such patterns and the respective iterators as well as a
test.

gcc/ChangeLog:

	* config/riscv/bitmanip.md (*<bitmanip_minmax_cmp_insn>_cmp_<mode>3):
	New min/max ifcvt pattern.
	* config/riscv/iterators.md (minu): New iterator.
	* config/riscv/riscv.cc (riscv_noce_conversion_profitable_p):
	Remove riscv-specific adjustment.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/zbb-min-max-04.c: New test.
2025-09-11 10:20:15 +02:00
Robin Dapp 9ff5cadac4 ifcvt: Clarify if_info.original_cost.
Before noce_find_if_block processes a block it sets up an if_info
structure that holds the original costs.  At that point the costs of
the then/else blocks have not been added so we only care about the
"if" cost.

The code originally used BRANCH_COST for that but was then changed
to COST_N_INSNS (2) - a compare and a jump.

This patch computes the jump costs via
  insn_cost (if_info.jump, ...)
under the assumption that the target takes BRANCH_COST into account
when costing a jump instruction.

In noce_convert_multiple_sets we keep track of the need for the initial
CC comparison.  If needed for the generated sequence we add its
cost in default_noce_conversion_profitable_p.

gcc/ChangeLog:

	* ifcvt.cc (noce_convert_multiple_sets_1): Add use_cond_earliest
	param.
	(noce_convert_multiple_sets): Set use_cond_earliest.
	(noce_process_if_block): Just use original cost.
	(noce_find_if_block): Use insn_cost (jump_insn).

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/addsieq.c: Remove xfail and expect conversion
	through noce_convert_multiple_sets.
	* gcc.target/riscv/addsifeq.c: Ditto.
	* gcc.target/riscv/addsifge.c: Ditto.
	* gcc.target/riscv/addsifgt.c: Ditto.
	* gcc.target/riscv/addsifle.c: Ditto.
	* gcc.target/riscv/addsiflt.c: Ditto.
	* gcc.target/riscv/addsifne.c: Ditto.
	* gcc.target/riscv/addsige.c: Ditto.
	* gcc.target/riscv/addsigeu.c: Ditto.
	* gcc.target/riscv/addsigt.c: Ditto.
	* gcc.target/riscv/addsigtu.c: Ditto.
	* gcc.target/riscv/addsile.c: Ditto.
	* gcc.target/riscv/addsileu.c: Ditto.
	* gcc.target/riscv/addsilt.c: Ditto.
	* gcc.target/riscv/addsiltu.c: Ditto.
2025-09-11 10:20:14 +02:00
Stefan Schulze Frielinghaus e63d9f9de8 testsuite: Fix asm-hard-reg-error-{4,5}.c for non-LRA targets
Hard register constraints are only supported for LRA and not old reload.
Targets hppa, m68k, pdp11, rx, sh, vax do not default to LRA which is
why these tests fail there.  Limit the tests to LRA targets, although,
this means that currently on these targets the tests are skipped by
default.  Since the tests are about general logic, the extra coverage we
loose by skipping these targets is negligible.

For hppa, register 0 cannot be used as a general register.  Therefore,
use temporary registers r20 and r21 instead.  Likewise, for AVR use r20
and r24 instead.

gcc/testsuite/ChangeLog:

	* gcc.dg/asm-hard-reg-error-4.c: Limit the test to LRA targets.
	Use registers r20 and r21 for hppa.  Likewise, for AVR use r20
	and r24 instead.
	* gcc.dg/asm-hard-reg-error-5.c: Ditto.
2025-09-11 10:04:04 +02:00
Kito Cheng 827e8ae402 RISC-V: Fix can_find_related_mode_p for VLS types
can_find_related_mode_p incorrectly handled VLS (Vector Length Specific)
types by using TARGET_MIN_VLEN directly, which is in bits, instead of
converting it to bytes as required.

This patch fixes the issue by dividing TARGET_MIN_VLEN by 8 to convert
from bits to bytes when calculating the number of units for VLS modes.

The fix enables proper vectorization for several test cases:
- zve32f-1.c: Now correctly finds vector mode for SF mode in foo3,
  enabling vectorization of an additional loop.
- zve32f_zvl256b-1.c and zve32x_zvl256b-1.c: Added -mrvv-max-lmul=m2
  option to handle V8SI[2] (vector array mode) requirements during
  vectorizer analysis, which needs V16SI to pass, and V16SI was enabled
  incorrectly before.

Changes since V4:
- Fix testsuite, also triaged why changed.

gcc/ChangeLog:

	* config/riscv/riscv-selftests.cc (riscv_run_selftests): Call
	run_vectorize_related_mode_selftests.
	(test_vectorize_related_mode): New function to test
	vectorize_related_mode behavior.
	(run_vectorize_related_mode_selftests): New function to run all
	vectorize_related_mode tests.
	(run_vectorize_related_mode_vla_selftests): New function to test
	VLA modes.
	(run_vectorize_related_mode_vls_rv64gcv_selftests): New function to
	test VLS modes on rv64gcv.
	(run_vectorize_related_mode_vls_rv32gc_zve32x_zvl256b_selftests):
	New function to test VLS modes on rv32gc_zve32x_zvl256b.
	(run_vectorize_related_mode_vls_selftests): New function to run all
	VLS mode tests.
	* config/riscv/riscv-v.cc (can_find_related_mode_p): Fix VLS type
	handling by converting TARGET_MIN_VLEN from bits to bytes.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/zve32f-1.c: Update expected
	vectorization count from 2 to 3.
	* gcc.target/riscv/rvv/autovec/zve32f_zvl256b-1.c: Add
	-mrvv-max-lmul=m2 option.
	* gcc.target/riscv/rvv/autovec/zve32x_zvl256b-1.c: Add
	-mrvv-max-lmul=m2 option.
2025-09-11 15:17:32 +08:00
Lulu Cheng ffbbeeec04 LoongArch: testsuite: Modify the tests to make the test pass.
Committing r16-3673 cause the test cases in the list to fail.
Make the test pass by modifying the test case or adding compilation
options.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/cmodel-extreme-1.c: Add -fPIC.
	* gcc.target/loongarch/cmodel-extreme-2.c: Likewise.
	* gcc.target/loongarch/tls-gd-noplt.c: Likewise.
	* gcc.target/loongarch/tls-extreme-macro.c: Likewise.
	* gcc.target/loongarch/func-call-medium-2.c: Modify.
	* gcc.target/loongarch/func-call-medium-3.c: Modify.
	* gcc.target/loongarch/func-call-medium-4.c: Removed.
2025-09-11 09:08:57 +08:00
GCC Administrator e24a539367 Daily bump. 2025-09-11 00:20:14 +00:00
Jonathan Wakely 1532792085 libstdc++: Remove blank line from bits/unique_ptr.h
libstdc++-v3/ChangeLog:

	* include/bits/unique_ptr.h: Remove blank line.
2025-09-10 23:24:10 +01:00
Jonathan Wakely a559f1423c libstdc++: Enforce Mandates: for Boyer-Moore searchers
C++17 has a 'Requires:' precondition that the two random access iterator
types have the same value type. In C++20 that is a 'Mandates:'
requirement which we must diagnose.

Although we could diagnose it in C++17, that might be a breaking change
for any users relying on it today. Also I am lazy and wanted to use
C++20's std::iter_value_t for the checks. So this only enforces the
requirement for C++20 and later.

libstdc++-v3/ChangeLog:

	* include/std/functional (boyer_moore_searcher::operator()): Add
	static_assert.
	(boyer_moore_horspool_searcher::operator()): Likewise.
	* testsuite/20_util/function_objects/121782.cc: New test.
2025-09-10 23:24:10 +01:00
Joseph Myers 3723edc87c c: Add tests for some C2Y removals of undefined behavior
C2Y removes various instances of undefined behavior, typically making
them either constraint violations or implementation-defined.

In many but not all such cases, GCC's existing behavior is compatible
with the C2Y changes.  For an initial batch of such cases, add
explicit tests for how GCC behaves in C2Y mode; more such cases will
need tests added in future patches, and there are also some such
changes that will need changes to how GCC behaves, not just new tests.
(Some of the individual examples in these tests may have been
constraint violations even before C2Y.)

Tested for x86_64-pc-linux-gnu.

	* gcc.dg/c2y-function-qual-1.c, gcc.dg/c2y-incomplete-1.c,
	gcc.dg/c2y-inline-1.c, gcc.dg/c2y-pointer-1.c,
	gcc.dg/c2y-register-array-1.c, gcc.dg/c2y-storage-class-1.c,
	gcc.dg/c2y-struct-empty-1.c: New tests.
2025-09-10 20:48:05 +00:00
Georg-Johann Lay 912159d2b5 AVR: Disable tree-switch-conversion per default.
There are at least two cases where tree-switch-conversion leads
to unpleasant resource allocation:

PR49857
    The lookup table lives in RAM.  This is the case for all
    devices that locate .rodata in RAM, which is for almost
    all AVR devices.

PR81540
    Code is bloated for 64-bit inputs.

As far as PR49857 is concerned, a target hook that may add an
address-space qualifier to the lookup table is the obvious
solution, though a respective patch has always been rejected by
global maintainers for non-technical reasons.

gcc/
	PR target/81540
	PR target/49857
	* common/config/avr/avr-common.cc: Disable -ftree-switch-conversion.
2025-09-10 21:09:24 +02:00
Takayuki 'January June' Suwa 220e4d2df7 xtensa: Correct a typo
That was introduced in commit 42db504c2f,
over 15 years ago!

gcc/ChangeLog:

	* config/xtensa/xtensa.h (TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P):
	Change "Xtrnase" in the comment to "Xtensa".
2025-09-10 10:24:39 -07:00
Peter Bergner 09864c7cd0 RISC-V: Fix typo in tt-ascalon-d8's pipeline description [PR121878]
PR121878 shows a typo in the tt-ascalon-d8's pipeline description that
leads to an ICE.  The problem is that the vector define_insn_reservation
patterns test for scalar modes rather than vector modes, meaning the
insns don't get handled correctly.  We could correct the modes, but given
we could have multiple VLEN values, the number of modes we'd have to check
can be large and mode iterators are not allowed in the mode attribute check.
Instead, I've removed the mode check and replaced it with a test of the
Selected Elenent Width (SEW).

2025-09-09  Peter Bergner  <bergner@tenstorrent.com>

gcc/
	PR target/121878
	* config/riscv/tt-ascalon-d8.md (tt_ascalon_d8_vec_idiv_half): Test the
	Selected Element Width (SEW) rather than the mode.
	(tt_ascalon_d8_vec_idiv_single): Likewise.
	(tt_ascalon_d8_vec_idiv_double): Likewise.
	(tt_ascalon_d8_vec_float_divsqrt_half): Likewise.
	(tt_ascalon_d8_vec_float_divsqrt_single): Likewise.
	(tt_ascalon_d8_vec_float_divsqrt_double): Likewise.

gcc/testsuite/
	PR target/121878
	* gcc.target/riscv/pr121878.c: New test.

Signed-off-by: Peter Bergner <bergner@tenstorrent.com>
2025-09-10 10:56:29 -05:00
Eric Botcazou 06628704c6 Fix -Wlto-type-mismatch warning during GNAT LTO build
The recent addition of Pragma_Unsigned_Base_Range to the enumeration type
Pragma_Id has made it exceed 256 enumeration values and thus overflow the
unsigned 8-bit type used for it on the C side.  This should have stopped
the build, except that a glitch in the Snames machinery causes one value
to be dropped on the C side, leaving it at just 256 enumeration values.

This fixes both issues, i.e. ensures that the number of enumeration values
is the same on both sides and bumps the size of the C type to 16 bits.

gcc/ada/
	PR ada/121885
	* snames.ads-tmpl (Pragma_Id): Rename Unknown_Pragma to
	Pragma_Unknown for the sake of XSnamesT.
	* snames.adb-tmpl (Get_Pragma_Id): Adjust to above renaming.
	* snames.h-tmpl (Attribute_Id): Change underlying type to Byte.
	(Get_Attribute_Id): Use Byte as return value.
	(Pragma_Id): Change underlying type to Word.
	(Get_Pragma_Id): Use Word as return value.
	* types.h (Word): New typedef.
	* exp_prag.adb (Expand_N_Pragma): Remove useless comment.
	* par-prag.adb (Prag): Adjust to above renaming.
	* sem_prag.adb (Analyze_Pragma): Likewise.
	(Sig_Flags): Likewise.
2025-09-10 16:15:29 +02:00
Juergen Christ 64abb12aac Fix load/store bias handling for extractlast.
The length returned by vect_get_loop_len is REALLEN + BIAS, but was
assumed to be REALLEN - BIAS.  If BIAS is -1, this leads to wrong
code.

gcc/ChangeLog:

	* tree-vect-loop.cc (vectorizable_live_operation_1): Fix
	load/store bias handling.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/nodump-extractlast-1.c: New test.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2025-09-10 15:57:14 +02:00
Martin Uecker afa74d37e8 c: Warn when returning nested functions that require a non-local context.
This patch adds a mechanism to keep track whether nested functions require
non-local context because they reference a variable of an enclosing
scope.  This is used for extending the existing -Wreturn-address warning
to also warn for such nested functions.  Certain exceptions are implemented
for functions that do not requite a non-local context, because they reference
only static variables, named constants, non-local variables in unevaluated
sizeof, typeof or countof operators, or typedef.  The logic is based on the
existing infrastructure for determining use of undeclared static functions.
Finally, To make sure that no trampolines are generated even when not using
optimization, we mark the exempt functions with TREE_NO_TRAMPOLINE.

gcc/c/ChangeLog:
	* c-tree.h: Add new macro C_DECL_NONLOCAL_CONTEXT and prototype
	for mark_decl_used.
	* c-typeck.cc (mark_decl_used): New function.
	(function_to_pointer_conversion): Mark exempt functions.
	(record_maybe_used_decl): Add `address' parameter.
	(build_external_ref): Change to mark_decl_used.
	(pop_maybe_used): Call mark_decl_used.
	(c_mark_addressable): Ditto.
	(c_finish_goto_label): Ditto.
	(c_finish_return): Add warning.
	* c-decl.cc (declspecs_add_type): Ditto.
	(grokdeclarator): Don't set C_DECL_REGISTER on function
	declarators.

gcc/testsuite/ChangeLog:
	* gcc.dg/Wreturn-nested-1.c: New test.
	* gcc.dg/Wreturn-nested-2.c: New test.
	* gcc.dg/Wtrampolines-2.c: New test.
	* gcc.dg/Wtrampolines-3.c: New test.
2025-09-10 15:48:24 +02:00
Paul-Antoine Arras e18285867e RISC-V: Add pattern for vector-scalar single widening floating-point sub
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a float_extend'ed vec_duplicate into a minus RTL instruction. The other
minus operand is already wide.

Before this patch, we have four instructions, e.g.:
  fcvt.d.s        fa0,fa0
  vsetvli         a5,zero,e64,m1,ta,ma
  vfmv.v.f        v2,fa0
  vfsub.vv        v1,v1,v2

After, we get only one:
  vfwsub.wf       v1,v1,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfwsub_wf_<mode>): New pattern to
	combine float_extend + vec_duplicate + vfsub.vv into vfwsub.wf.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfwsub.wf.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop.h
	(DEF_VF_BINOP_WIDEN_CASE_2, DEF_VF_BINOP_WIDEN_CASE_3): Swap operands.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwsub-run-2-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwsub-run-2-f32.c: New test.
2025-09-10 15:34:10 +02:00
Christophe Lyon 21d4a0b08a compare_tests: Improve non-unique tests report
If the results include several configurations (schedule of
variations), do not report summary lines as duplicates.  Indeed with
several configurations, it's likely that the results contain the same

   # of expected passes            XXXXX

The patch just keeps lines starting with test state prefix to avoid
this problem.

contrib/ChangeLog:

	* compare_tests: Improve non-unique tests report when testing
	several configurations.
2025-09-10 12:48:24 +00:00
Nathaniel Shead 7fc9265ee5 c++: Fix null deref in maybe_diagnose_standard_trait [PR121859]
A static member template doesn't always have a DECL_INITIAL, as in the
below testcase, and so checking its TREE_CODE performs a null-pointer
dereference.  I don't think we need to specially detect this case as
traits we care about are unlikely to be members, so this just adds the
missing null check.

	PR c++/121859

gcc/cp/ChangeLog:

	* constraint.cc (maybe_diagnose_standard_trait): Check if expr
	is non-null.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-traits5.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-09-10 22:22:33 +10:00
Luc Grosheintz 008ad1c6ba libstdc++: Rename _S-prefixed identifiers in <mdspan>.
In libstdc++ the prefix _S is used for static members only. In <mdspan>
there's several type aliases that also used the prefix _S. They now use
a single leading underscore follow by a capital letter instead.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (_ExtentsStorage::_Base): New name for
	_S_base.
	(_ExtentsStorage::_Storage): New name for _S_storage.
	(extents::_Storage): New name for _S_storage.
	(layout_stride::mapping::_Strides): New name for
	_S_stries_t.
	* testsuite/23_containers/mdspan/class_mandate_neg.cc: Update
	test to the new error message.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-09-10 12:51:38 +02:00
Luc Grosheintz 54cc2cb7bc libstdc++: Apply LWG4351 to CTAD of span/mdspan.
The concept __integral_constant_like doesn't consider traits with a
boolean member `value` as an integer constant. This is done to reject
various completely unrelated traits like is_const, is_abstract, etc.

LWG4351 adjusts the check to strip references and cv qualifiers before
checking if `value` is bool. The immediate context is constant_wrapper
which defines:

    template<...>
    struct constant_wrapper
    {
      static constexpr const auto& value = ...;
    };

Without LWG4351, std::cw<true> and std::cw<false> would both be
considered integer constants (by __integral_constant_like); but both
std::{true,false}_type are not considered integer constants. Hence,
LWG4351 removes inconsistent behaviour between std::integral_constant
and std::constant_wrapper.

libstdc++-v3/ChangeLog:

	* include/std/span (__integral_constant_like): Use
	remove_cvref_t before checking if _Tp::value is boolean.
	* testsuite/23_containers/mdspan/extents/misc.cc: Update test.
	* testsuite/23_containers/mdspan/mdspan.cc: Ditto.
	* testsuite/23_containers/span/deduction.cc: Ditto.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-09-10 12:46:57 +02:00
Jakub Jelinek 2bb8cd3609 testsuite: Only scan for known file extensions in lto.exp
This is something that has bothered me for a few years but I've only found
time for it now.
The glob used for finding *_1.* etc. counterparts to the *_0.* tests is too
broad, so if one has say next to *_1.c file also *_1.c~ or *_1.c.~1~
or *_1.c.orig or *_1.c.bak etc. files, lto.exp will report a warning and the
test will fail.
So, e.g. in rpm build if some backported commit in patch form adds some
gcc/testsuite/*.dg/lto/ test and one uses -b option to patch, if one doesn't
remove the backup files, the test will fail.

Looking through all the *.dg/lto/ directories, I only see c, C, ii, f, f90
and d extensions used right now for the *_1.* files (and higher), while for
the *_0.* files also m, mm and f03 extensions are used.

So, the following patch only searches for those (plus for Fortran uses the
extensions searched by the gfortran.dg/lto/ driver, i.e. \[fF\]{,90,95,03,08}
, not just f, f90 and f03).

Tested on x86_64-linux and verified I got exactly the same number of
grep '^Executing.on.host.*_[1-9]\.' testsuite/*/*.log
before/after this patch when doing make check RUNTESTFLAGS=lto.exp
except for 2 new ones which were previously failed because I had backup
files for 2 tests.

2025-09-10  Jakub Jelinek  <jakub@redhat.com>

	* lib/lto.exp (lto-execute-1): Search for _1.* etc. files
	only with a list of known extensions.
2025-09-10 12:39:11 +02:00
Jakub Jelinek 29a8ce3b0b bitint: Fix up lowering optimization of .*_OVERFLOW ifns [PR121828]
THe lowering of .{ADD,SUB,MUL}_OVERFLOW ifns is optimized, so that we don't
in the common cases uselessly don't create a large _Complex _BitInt
temporary with the first (real) part being the result and second (imag) part
just being a huge 0 or 1, although we still do that if it can't be done.
The optimizable_arith_overflow function checks when that is possible, like
whether the ifn result is used at most twice, once in REALPART_EXPR and once
in IMAGPART_EXPR in the same bb, etc.  For IMAGPART_EXPR it then checks
if it has a single use which is a cast to some integral non-bitint type
(usually bool or int etc.).  The final check is whether that cast stmt
appears after the REALPART_EXPR (the usual case), in that case it is
optimizable, otherwise it is not (because the lowering for optimizable
ifns of this kind is done at the location of the REALPART_EXPR and it
tweaks the IMAGPART_EXPR cast location at that point, so otherwise it
would be set after use.

Now, we also have an optimization for the REALPART_EXPR lhs being used
in a single stmt - store in the same bb, in that case we don't have to
store the real part result in a temporary but it can go directly into
memory.
Except that nothing checks for the IMAGPART_EXPR cast being before or after
the store in this case, so the following testcase ICEs because we have
a use before a def stmt.

In bar (the function handled right already before this patch) we have
  _6 = .SUB_OVERFLOW (y_4(D), x_5(D));
  _1 = REALPART_EXPR <_6>;
  _2 = IMAGPART_EXPR <_6>;
  a = _1;
  _3 = (int) _2;
  baz (_3);
before the lowering, so we can just store the limbs of the .SUB_OVERFLOW
into the limbs of a variable and while doing that compute the value we
eventually store into _3 instead of the former a = _1; stmt.
In foo we have
  _5 = .SUB_OVERFLOW (y_3(D), x_4(D));
  _1 = REALPART_EXPR <_5>;
  _2 = IMAGPART_EXPR <_5>;
  t_6 = (int) _2;
  baz (t_6);
  a = _1;
and we can't do that because the lowering would be at the a = _1; stmt
and would try to set t_6 to the overflow flag at that point.  We don't
need to punt completely and mark _5 as _Complex _BitInt VAR_DECL though
in this case, all we need is not merge the a = _1; store with the
.SUB_OVERFLOW and REALPART_EXPR/IMAGPART_EXPR lowering.  So, add _1
to m_names and lower the first 3 stmts at the _1 = REALPART_EXPR <_5>;
location, optimizable_arith_overflow returned non-zero and so the
cast after IMAGPART_EXPR was after it and then a = _1; will copy from
the temporary VAR_DECL to memory.

2025-09-10  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/121828
	* gimple-lower-bitint.cc (gimple_lower_bitint): For REALPART_EXPR
	consumed by store in the same bb and with REALPART_EXPR from
	optimizable_arith_overflow, don't add REALPART_EXPR lhs to
	the m_names bitmap only if the cast from IMAGPART_EXPR doesn't
	appear in between the REALPART_EXPR and the store.

	* gcc.dg/bitint-126.c: New test.
2025-09-10 12:34:50 +02:00
Jakub Jelinek 225d13c01d expr: Handle RAW_DATA_CST in store_constructor [PR121831]
I thought this wouldn't be necessary because RAW_DATA_CST can only appear
inside of (array) CONSTRUCTORs within DECL_INITIAL of TREE_STATIC vars,
so there shouldn't be a need to expand it.  Except that we have an
optimization when reading ARRAY_REF from such a CONSTRUCTOR which will
try to expand the constructor if it either can be stored by pieces
(I think that is just fine) or if it is mostly zeros (which is at least
75% of the initializer zeros).  Now the second case is I think in some
cases desirable (say 256MB initializer and just 20 elements out of that
non-zero, so clear everything and store 20 elements must be fastest and
short), but could be really bad as well (say 40GB initializer with
10GB non-zero in it, especially if it doesn't result in the original
variable being optimized away).  Maybe it would help if expand_constructor
and store_constructor* etc. had some optional argument with addresses into
the original VAR_DECL so that it could be copying larger amounts of data
like larger RAW_DATA_CSTs from there instead of pushing those into new
.rodata again.  And another problem is that we apparently expand the
initializes twice, expand_constructor in store_constructor can expand
the stores one and if expand_constructor returns non-NULL, we then
expand_expr the CONSTRUCTOR again. to the same location.

This patch doesn't address either of those issues, just adds RAW_DATA_CST
support to store_constructor for now.  For the can_store_by_pieces
cases it stores those by pieces using a new callback very similar to
string_cst_read_str, for the rest (unfortunately) forces it into a memory
and copies from there.

2025-09-10  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/121831
	* expr.cc (raw_data_cst_read_str): New function.
	(store_constructor) <case ARRAY_TYPE>: Handle RAW_DATA_CST.

	* g++.dg/lto/pr121831_0.C: New test.
	* g++.dg/lto/pr121831_1.C: New test.
2025-09-10 12:33:14 +02:00
Tomasz Kamiński ac16659540 libstdc++: Use _Drop_iter<_CharT> for formattable concept checking [PR121765]
When producing output, the libstdc++ format implementation only uses _Sink_iter
specializations. Since users cannot construct basic_format_context, this is the
only iterator type actually used. The __format_padded helper relies on this
property to efficiently pad sequences from tuples and ranges.

However, the standard's formattable concept requires a generic format function
in formatters that works with any iterator type. This is intended to
future-proof the implementation by allowing new format_context types. Previously,
libstdc++ used back_insert_iterator<basic_string<_CharT>> for this purpose.

Normally, concept checks only instantiate function signatures, but with
user-defined formatters and deduced return types, the function body and all
called functions are instantiated. This could trigger a static assertion error
in the range/tuple formatter that assumed the iterator was a _Sink_iter
(see included test).

This patch resolves the issue by replacing the _Iter_for_t alias with the
internal _Drop_iter. This iterator's sematnics is to drop elements, so
__format_padded can handle it by simply returning the input iterator, which
still produces the required behavior [1].

An alternative of using _Sink_iter was considered but rejected because it would
allow formatters to pass formattable requirements while only supporting
format_context and wformat_context, which seems counter to the design intent
(the std/format/formatter/concept.cc fails).

[1] The standard's wording defines format functions as producing an output
representation, but does not explicitly require a formatter to be invoked
for each element. This allows the use of _Drop_iter to pass the concept check
without generating any output.

	PR libstdc++/121765

libstdc++-v3/ChangeLog:

	* include/std/format (__format::_Drop_iter): Define.
	(_Iter_for_t::type): Change alias to _Drop_iter.
	(__format::__format_padded): Return __fc.out() for
	_Drop_iter.
	* testsuite/std/format/pr121765.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-10 11:44:33 +02:00
Juergen Christ f50cff9766 s390: Implement clz and ctz for SI mode
To properly implement __builtin_ffs for SI mode, implement clz and
(for >= z17) ctz for SI mode.  Otherwise, gcc falls back to a libcall
which causes problems for Linux kernel code.

Also adjust the C?Z_DEFINED_VALUE_AT_ZERO macros to return 2.  Since
the optabs now return exactly the value set by these macros, return
value 2 is more appropriate and leads to better code.

gcc/ChangeLog:

	* config/s390/s390.h (CLZ_DEFINED_VALUE_AT_ZERO): Adjust and
	return 2.
	(CTZ_DEFINED_VALUE_AT_ZERO): Return 2.
	* config/s390/s390.md (clzsi2): Implement.
	(ctzsi2): Implement.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/pr109011-2.c: Fix expected outcome.
	* gcc.dg/vect/pr109011-4.c: Fix expected outcome.
	* gcc.target/s390/ffs-1.c: New test.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2025-09-10 11:21:21 +02:00
Jakub Jelinek 2dfff4ffe8 c++: Change mangling of Intel/Motorola extended long double literals
On Fri, Sep 05, 2025 at 09:57:06PM +0200, Matthias Kretz wrote:
> > Hmm, would this fail for x86 long double, which is 80 bits? OK, just
> > checked. It's mangled as 12/16 bytes on i686/x86_64.
>
> It seems that Clang and GCC disagree on mangling 80-Bit long double:
>
> I like Clang's interpretation of https://itanium-cxx-abi.github.io/cxx-abi/
> abi.html#mangle.float better.

This patch changes the mangling of 80-bit long double literals from
24 or 32 digits (on m68k with padding bits in the middle, on x86
at the start) to just 20 hex digits.

2025-09-10  Jakub Jelinek  <jakub@redhat.com>

	* mangle.cc (write_real_cst): Mangle Intel/Motorola extended
	80-bit formats using 20 hex digits instead of 24 or 32.

	* g++.target/i386/mangle-ldbl-1.C: New test.
	* g++.target/i386/mangle-ldbl-2.C: New test.
	* g++.target/m68k/mangle-ldbl-1.C: New test.
	* g++.target/m68k/mangle-ldbl-2.C: New test.
2025-09-10 10:48:31 +02:00
Maximilian Immanuel Brandtner 7a49952100 s390: fix vec_extract_plus define insn
Because of a wrong define_insn for vec_extract_plus a vector access wasn't
combined with a preceeding plus operation which set the offset at which
to perform the vector access even though the instruction offers that capability.

Bootstrapped and regtested on s390x.

gcc/ChangeLog:

	* config/s390/vector.md (*vec_extract<mode>_plus_zero_extend):
	Fix define insn.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/vector/vec-extract-3.c: New test.

Signed-off-by: Maximilian Immanuel Brandtner <maxbr@linux.ibm.com>
2025-09-10 10:14:46 +02:00
Tomasz Kamiński 2ec29759ba libstdc++: Document remaining C++20 implementation-defined behavior.
I have double checked that implementation-defined behavior in the [compliance]
(whether the implementation is freestanding) and [stringbuf.const] (initialization
of sequence pointers) are indeed null, and there are no corresponding entires in
earlier standards.

libstdc++-v3/ChangeLog:

	* doc/html/manual/status.html: Regenerate.
	* doc/xml/manual/status_cxx2020.xml: Add more entires.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-10 09:43:43 +02:00
Tomasz Kamiński 88d4738ddc libstdc++: Document C++20 atomic_ref implementation-defined behavior.
Also introduce Implementation Specific Behavior section for C++20.

libstdc++-v3/ChangeLog:

	* doc/html/index.html: Regenerated.
	* doc/html/manual/index.html: Regenerated.
	* doc/html/manual/intro.html: Regenerated.
	* doc/html/manual/status.html: Regenatered.
	* doc/xml/manual/status_cxx2020.xml: Add iso.2020.specific
	section with atomic_ref documentation.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-10 09:15:16 +02:00
GCC Administrator 45e5b65be2 Daily bump. 2025-09-10 00:22:24 +00:00
Nathaniel Shead bdfcb808f8 c++/modules: Cleanup import handling [PR99682]
This patch fixes some issues with import handling.

The main functional change is to allow importing a module's interface
file into its implementation file indirectly.  [module.import] p9
forbids an explicit 'import M;' declaration, but there's no provision
against having 'import X;' where module X itself imports M, so this
patch splits up the detection of circular imports to handle this better.
I also updated the errors to be closer to the standard wording.

A second issue I found while testing this is that we don't properly
handle name visibility when a partition implementation unit imports its
primary module interface (g++.dg/modules/part-10).  This is resolved by
setting 'module_p' on the primary interface when it gets imported.

Solving this I incidentally removed the assertion that PR121808 was
failing on, which was never valid: we can enter import_module for a
module previously seen as a module-declaration if parsing bails before
declare_module is called.  I experimented with guaranteeing that
declare_module always gets called for a module_state generated during
preprocessing if at all possible, but the resulting errors didn't seem a
lot better so I've left it as-is for now.

I did make a small adjustment so that a direct import of a module
doesn't overwrite the location of a module-declaration from earlier in
the file; this is important because preprocessing (and thus the
assigning of these locations) seems to happen for the whole file before
parsing begins, which can otherwise cause confusing locations referring
to later in the file than parsing would otherwise indicate.

	PR c++/99682
	PR c++/121808

gcc/cp/ChangeLog:

	* module.cc (class module_state): Add comment to 'parent'.
	(module_state::check_not_purview): Rename to...
	(module_state::check_circular_import): ...this.  Only handle
	interface dependencies, adjust diagnostic message.
	(module_state::read_imports): Use new function.  Pass location
	of import as from_loc instead of the module location.
	(module_state::do_import): Set module_p when importing the
	primary interface for the current module.
	(import_module): Split out check for imports in own unit.
	Remove incorrect assertion.
	(preprocess_module): Don't overwrite module-decl location with
	later import.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/circ-1_c.C: Adjust diagnostic.
	* g++.dg/modules/mod-decl-1.C: Likewise.
	* g++.dg/modules/mod-decl-2_b.C: Likewise.
	* g++.dg/modules/pr99174.H: Likewise.
	* g++.dg/modules/import-3_a.C: New test.
	* g++.dg/modules/import-3_b.C: New test.
	* g++.dg/modules/import-3_c.C: New test.
	* g++.dg/modules/mod-decl-9.C: New test.
	* g++.dg/modules/part-10_a.C: New test.
	* g++.dg/modules/part-10_b.C: New test.
	* g++.dg/modules/part-10_c.C: New test.
	* g++.dg/modules/part-10_d.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-09-10 09:11:09 +10:00
Nathaniel Shead a4db64237d c++/modules: Create helper to get current TU's module_state
A lot of places use (*modules)[0] to refer to the module state for the
current TU.  This is a bit awkward to type and not particularly clear
what it represents; make a helper function to clarify it.

gcc/cp/ChangeLog:

	* module.cc (this_module): New function.
	(import_entity_module): Use it.
	(trees_out::decl_node): Likewise.
	(get_module): Likewise.
	(module_state::check_not_purview): Likewise.
	(module_state::read_imports): Likewise.
	(module_state::read_using_directives): Likewise.
	(module_state::read_initial): Likewise.
	(get_import_bitmap): Likewise.
	(module_may_redeclare): Likewise.
	(direct_import): Likewise.
	(declare_module): Likewise.
	(name_pending_imports): Likewise.
	(preprocess_module): Likewise.
	(finish_module_processing): Likewise.
	(late_finish_module): Likewise.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-09-10 09:11:08 +10:00
Nathaniel Shead 86e470b259 testsuite: Fix UNRESOLVEDs for mistakenly dg-run test [PR121872]
PR testsuite/121872

gcc/testsuite/ChangeLog:

	* g++.dg/modules/default-arg-4_b.C: Change run to compile.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-09-10 09:10:56 +10:00
Harald Anlauf a107168367 Fortran: fix bootstrap with -Werror=maybe-uninitialized
gcc/fortran/ChangeLog:

	* trans-intrinsic.cc (conv_intrinsic_fstat_lstat_stat_sub): Init
	some variables.
2025-09-09 21:30:07 +02:00
Patrick Palka f2fddc4b84 c++: non-dep cmp op rewritten from <=> returning int [PR121779]
Apparently an explicitly defined operator<=> isn't required to return
std::foo_ordering, so build_min_non_dep_op_overload needs to be able
to rebuild forms of (x <=> y) @ 0 where the @ resolved to a built-in and
in turn isn't expressed as a function call.

	PR c++/121779

gcc/cp/ChangeLog:

	* tree.cc (build_min_non_dep_op_overload): Handle comparison
	operator expressions rewritten from a <=> that returns a
	non-class type.

gcc/testsuite/ChangeLog:

	* g++.dg/lookup/operator-8.C: Remove outdated comment about
	this test failing.
	* g++.dg/lookup/operator-8a.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-09-09 14:39:57 -04:00
Andrew Stubbs 7bc2e31168 amdgcn: fix GFX10/GFX11 VGPR counts
The previous definition had all the GFX11 register counts doubled to fix a bug
that was encountered in early testing.  This seems to have been a
misunderstanding of the problem (which is no longer reproducible).

gcc/ChangeLog:

	* config/gcn/gcn-devices.def: Correct the Max ISA VGPRs counts for
	GFX10 and GFX11 devices.
	* config/gcn/gcn.cc (gcn_hsa_declare_function_name): Remove the wave64
	VGPR count fudge.
2025-09-09 16:43:21 +00:00
Andrew Stubbs 0d56fb2639 amdgcn: fix builtin codegen at -O0
Fix an unrecognised insn ICE that only shows while using builtins at -O0.

gcc/ChangeLog:

	* config/gcn/gcn.cc (gcn_expand_builtin_1): Enable the "mode" parameter
	and ensure that "target" is a register for most of the builtins.
2025-09-09 16:43:20 +00:00
Harald Anlauf 52d754a1a6 Fortran: make STAT/LSTAT/FSTAT intrinsics generic [PR82480]
PR fortran/82480

gcc/fortran/ChangeLog:

	* check.cc (error_unsupported_kind): Helper function to report an
	unsupported kind of an argument.
	(check_minrange4): Helper function to report if an integer variable
	does not have a decimal range of at least four.
	(gfc_check_fstat): Adjust checks for generalization of instrinsic
	function FSTAT.
	(gfc_check_fstat_sub): Likewise for subroutine FSTAT.
	(gfc_check_stat): Likewise for functio STAT.
	(gfc_check_stat_sub): Likewise for subroutine STAT.
	* intrinsic.texi: Document generalized versions of intrinsics
	STAT/LSTAT/FSTAT.
	* iresolve.cc (gfc_resolve_stat): STAT function result shall have
	the same kind as the VALUES argument.
	(gfc_resolve_lstat): Likewise for LSTAT.
	(gfc_resolve_fstat): Likewise for FSTAT.
	(gfc_resolve_stat_sub): Resolve proper library subroutine for STAT.
	(gfc_resolve_lstat_sub): Likewise for LSTAT.
	* trans-decl.cc (gfc_build_intrinsic_function_decls): Declare
	fndecls for required subroutines in runtine library.
	* trans-intrinsic.cc (conv_intrinsic_fstat_lstat_stat_sub): Emit
	runtime wrapper code for the library functions, taking care of
	possible kind conversion of the optional STATUS argument of the
	subroutine versions of the intrinsics.
	(gfc_conv_intrinsic_subroutine): Use it.
	* trans.h (GTY): Declare prototypes.

gcc/testsuite/ChangeLog:

	* gfortran.dg/stat_3.f90: Extend argument checking.
	* gfortran.dg/stat_4.f90: New test.
2025-09-09 18:11:24 +02:00
David Faust 50efa788a4 ctf: fix integer truncations in very large structs [PR121411]
DWARF to CTF translation for type bit sizes was using uint32_t, and for
member offsets was inadvertently using unsigned int via get_AT_unsigned.
For very large struct types, at least one of these could be truncated
causing incorrect encoding of the struct type and member offsets.

Use HOST_WIDE_INT to avoid these truncation issues and fix the encoding
for large structs.

	PR debug/121411

gcc/

	* dwarf2ctf.cc (ctf_get_AT_data_member_location) Use AT_unsigned
	when fetching AT_bit_offset and AT_data_member_location.  Simplify.
	(ctf_die_bitsize): Return unsigned HOST_WIDE_INT instead of
	uint32_t.
	(gen_ctf_base_type, gen_ctf_sou_type, gen_ctf_enumeration_type):
	Adapt accordingly.

gcc/testsuite/

	* gcc.dg/debug/ctf/ctf-struct-3.c: New test.
2025-09-09 08:56:54 -07:00
Paul-Antoine Arras fce05f607c RISC-V: Add pattern for vector-scalar dual widening floating-point sub
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a float_extend'ed vec_duplicate into a minus RTL instruction. Both
minus operands are widened.

Before this patch, we have six instructions, e.g.:
  fcvt.d.s        fa0,fa0
  vsetvli         a5,zero,e64,m1,ta,ma
  vfmv.v.f        v3,fa0
  vfwcvt.f.f.v    v1,v2
  vsetvli         zero,zero,e64,m1,ta,ma
  vfsub.vv        v1,v1,v3

After, we get only one:
  vfwsub.vf       v1,v2,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfwsub_vf_<mode>): New pattern to
	combine float_extend + vec_duplicate + vfwsub.vv into vfwsub.vf.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfwsub.vf.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop.h
	(DEF_VF_BINOP_WIDEN_CASE_0, DEF_VF_BINOP_WIDEN_CASE_1): Swap operands.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_widen_run.h: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwsub-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwsub-run-1-f32.c: New test.
2025-09-09 17:10:41 +02:00
Jakub Jelinek 6e4e6883d4 c, c++: Allow &__real__ static_var in constant expressions [PR121678]
When looking at constexpr references, I've noticed staticp handles
COMPONENT_REFs and ARRAY_REFs (the latter if the index is INTEGER_CST),
but not {REAL,IMAG}PART_EXPR.  I think that is incorrect and causes
rejection of constexpr (for C++) or static const (for C) addresses
of __real__ or __imag__ parts of static vars.

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

	PR c++/121678
	* tree.cc (staticp): Handle REALPART_EXPR and IMAGPART_EXPR.

	* g++.dg/ext/pr121678.C: New test.
	* gcc.dg/pr121678.c: New test.
2025-09-09 16:44:48 +02:00
Jonathan Wakely 39c003c0ec libstdc++: Rename _CwFixedValue::_S_type member
Rename _S_type to __type as it's not a static member.

Also rename _Tp to _Xv because it's not a type.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (_CwFixedValue::_S_type): Rename to
	__type.
	(constant_wrapper): Rename template parameter in declaration to
	match later definition.
2025-09-09 14:26:15 +01:00
Jonathan Wakely 53452be13b doc: Adjust -Wextra description for -Wunterminated-string-initialization
Say that -Wunterminated-string-initialization is for C and ObjC only
when it appears in the -Wextra documentation.

gcc/ChangeLog:

	* doc/invoke.texi (Warning Options): Note that an option
	enabled by -Wextra is for C and ObjC only.
2025-09-09 14:26:15 +01:00
Paul-Antoine Arras 01827a3f65 RISC-V: Add pattern for vector-scalar single widening floating-point add
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a float_extend'ed vec_duplicate into a plus RTL instruction. The other
plus operand is already wide.

Before this patch, we have four instructions, e.g.:
  fcvt.d.s        fa0,fa0
  vsetvli         a5,zero,e64,m1,ta,ma
  vfmv.v.f        v2,fa0
  vfadd.vv        v1,v1,v2

After, we get only one:
  vfwadd.wf       v1,v1,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfwadd_wf_<mode>): New pattern to
	combine float_extend + vec_duplicate + vfadd.vv into vfwadd.wf.
	* config/riscv/vector.md
	(@pred_single_widen_<plus_minus:optab><mode>_scalar): Swap and reorder
	operands to match the RTL emitted by expand.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfwadd.wf.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop.h: Add support for single
	widening variants.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_widen_run.h: Add support
	for single widening variants.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwadd-run-2-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwadd-run-2-f32.c: New test.
2025-09-09 15:24:16 +02:00
Kyrylo Tkachov 768f3610e2 Revert "aarch64: Handle DImode BCAX operations"
This reverts commit 1b7bcac032.

PR target/121785

gcc/

	* config/aarch64/aarch64-simd.md (*bcaxqdi4): Delete.

gcc/testsuite/

	* gcc.target/aarch64/simd/bcax_d.c: Remove tests for DImode arguments.
2025-09-09 15:14:51 +02:00
Tamar Christina beb9073dcd Revert "tree-optimization/121829 - bogus CFG with asm goto"
This reverts commit a632becefa.
2025-09-09 13:51:37 +01:00
Gary Dismukes 369b7ed801 ada: Warning for composite equality that calls an abstract equality function
When equality is tested for a composite type that has any record
components whose type has an abstract equality function that will
be called as part of the enclosing type's equality, Program_Error
will be raised.  We now issue a warning on the equality test,
mentioning the component type whose abstract equality function
will trigger the exception.  Note that this is currently only
done for top-level components of the composite type.  Another
limitation is that the warning is not issued when the outer
composite type is tagged.

gcc/ada/ChangeLog:

	* exp_ch4.adb (Expand_N_Op_Eq): Check for warning about call to
	the abstract equality function of a component type, for both array
	and record enclosing types.
	(Warn_On_Abstract_Equality_For_Component): New procedure to issue
	a warning when an abstract equality function of a component type
	will be called and result in Program_Error.
2025-09-09 14:40:01 +02:00
Ronan Desplanques 42cc047419 ada: Fix spurious warning for procedure named "Continue"
The recent addition of a language extension for the "continue"
nonreserved keyword caused spurious warnings about unreferenced
subprograms for procedures named "Continue", because the call
statements that are generated when identifiers are determined not to
refer to the keyword were considered to come from expansion.

This patch fixes this by marking those generated calls as coming from
source instead.

gcc/ada/ChangeLog:

	* sem_ch5.adb (Make_Call): Mark generated nodes as coming from source.
2025-09-09 14:40:01 +02:00
Ronan Desplanques bda7699648 ada: Remove incorrect comment
gcc/ada/ChangeLog:

	* sem_ch3.adb (Analyze_Incomplete_Type_Decl): Remove incorrect
	comment.
2025-09-09 14:40:00 +02:00
Viljar Indus 9d4e02a442 ada: Ignore Ghost policy checks for some pragmas
Some pragmas where the ghostness is based on the argument of
the pragma triggered ghost policy errors because we had not marked
the pragmas as ghost. However we could only do so once the argument
of the pragma was analyzed.

We can safely ignore the policy checks for those pragmas since
if the argument was ghost then the pragma also had to be ghost.

Marking the pragma afterwards as ghost is only for the cleanup of
ignored ghost purposes.

gcc/ada/ChangeLog:

	* ghost.adb (Is_OK_Pragma): Use the
	Suppressed_Ghost_Policy_Check_Pragma list for ignoring certain
	pragmas.
	* sem_prag.ads (Suppressed_Ghost_Policy_Check_Pragma): New variable
	to store the pragmas that could be ignored when checking for
	consitant ghost policy.
2025-09-09 14:40:00 +02:00
Tonu NaksandEric Botcazou 360a779f07 ada: Platform-specific import for read() and write()
read() and write() return int on windows, whereas
on Posix systems the return type is ssize_t (effectively long_int).

The object file was added to GNAT_ADA_OBJS only, although the unit is also
in the compilation closure of GNATbind, but this was harmless because the
object file was essentially empty; that is no longer the case.

gcc/ada/ChangeLog:

	* libgnat/s-crtl.ads (read, write): remove import
	* libgnat/s-crtl__mingw.adb: body for windows
	* libgnat/s-crtl.adb: body for all the other targets
	* Makefile.rtl: configure s-crtl.adb/libgnat/s-crtl__mingw.adb
	* gcc-interface/Make-lang.in (GNAT_ADA_OBJS): Alphabetize.
	(GNATBIND_OBJS): Add ada/libgnat/s-crtl.o.

Co-authored-by: Eric Botcazou <ebotcazou@adacore.com>
2025-09-09 14:40:00 +02:00
Viljar Indus b7019e9895 ada: Update the uses of Is_Ignored*_In_Codegen
Replace calls to Is_Ignored_Ghost_Entity and
Predicates_Ignored with their In_Codegen versions in places where
we would analyze those nodes differently from checked nodes.

Describe the motive and use cases for those In_Codegen functions.

gcc/ada/ChangeLog:

	* contracts.adb: Use the In_Codegen function instead.
	* exp_ch3.adb: Likewise.
	* exp_ch5.adb: Likewise.
	* exp_ch6.adb: Likewise.
	* exp_ch7.adb: Likewise.
	* exp_ch9.adb: Likewise.
	* exp_disp.adb: Likewise.
	* exp_util.adb: Likewise.
	* freeze.adb: Likewise.
	* ghost.adb: Likewise.
	* inline.adb: Likewise.
	* repinfo.adb: Likewise.
	* sem_ch10.adb: Likewise.
	* sem_ch13.adb: Likewise.
	* sem_ch3.adb: Likewise.
	* sem_ch6.adb: Likewise.
	* sem_elab.adb: Likewise.
	* sem_res.adb: Likewise.
	* sem_util.adb (Predicates_Ignored_In_Codegen): Add new function for
	the Predicates_Ignored property.
	(Predicates_Enabled): Use Predicates_Ignored_In_Codegen instead.
	* sem_util.ads (Predicates_Ignored_In_Codegen): New function.
	(Is_Ignored_In_Codegen): Add documentation on how _In_Codegen
	functions should be used.
2025-09-09 14:39:59 +02:00
Ronan Desplanques c3ef51e28d ada: Improve comments in Copy_And_Swap
This patch replaces usages of "attribute" with the more appropriate
"field" when referring to Gen_IL fields, to avoid confusion with Ada's
concept of attributes.

This patch also makes comments more explicit about Gen_IL IDs and slots
around a call to the low-level Atree.Exchange_Entities, and makes a few
other minor comment changes.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Copy_And_Swap): Improve comments.
2025-09-09 14:39:59 +02:00
Javier Miranda e7c526a40c ada: Spurious error on generalized prefix notation
The compiler reports a spurious error when a primitive function of
an untagged type that returns an array type is invoked using the
prefix notation, and the sources are compiled with language
extensions enabled.

gcc/ada/ChangeLog:

	* sem_util.adb (Needs_One_Actual): Add support for untagged record
	types when the sources are compiled with Core Extensions allowed.
2025-09-09 14:39:58 +02:00
Ronan Desplanques 0cdb59dcce ada: Fix comment in Find_Type_Name
The comment this patch changes was made incorrect by the possibility of
completing an incomplete view with a private type declaration in Ada
2012. To avoid any possible confusion, this patch brings the comment up
to date.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Find_Type_Name): Fix comment.
2025-09-09 14:39:58 +02:00
Ronan Desplanques 97b771f90a ada: Remove unnecessary if statement
Calling Check_Nonoverridable_Aspects only makes sense when the full type
declaration being analyzed is the completion of a partial view, and the
one call site of this procedure ensures this. Therefore the handling of
all the possible cases of completion in the procedure that this patch
removes was useless.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Check_Nonoverridable_Aspects): Remove if statement.
2025-09-09 14:39:58 +02:00
Ronan Desplanques ad410118a7 ada: Improve documentation comment
The new version of the comment makes it clearer that
Check_Nonoverridable_Aspects is only concerned with cases where a partial
view is present.

This patch also fixes a reference to an ARM clause in the comment.

gcc/ada/ChangeLog:

	* sem_ch3.adb (Check_Nonoverridable_Aspects): Improve documentation
	comment.
2025-09-09 14:39:57 +02:00
Viljar Indus a1b7ea3ef9 ada: Add location info to policy difference errors
gcc/ada/ChangeLog:

	* ghost.adb (Check_Ghost_Completion): Add location info
	to the policy messages.
	(Check_Ghost_Policy): Likwise.
2025-09-09 14:39:57 +02:00
Javier Miranda 54cb541d28 ada: Adding support to defer the addition of extra formals (part 2)
Adjust previous patch to improve the support for AI05-0151-1/08.

gcc/ada/ChangeLog:

	* exp_attr.adb (Rewrite_Attribute_Proc_Call): Add new parameter
	to calls to Create_Extra_Formals.
	(Expand_N_Attribute_Reference): Ditto.
	* exp_ch3.adb (Expand_Freeze_Record_Type): Ditto.
	* exp_ch6.adb (Expand_Call_Helper): Ditto.
	* exp_disp.adb (Expand_Dispatching_Call): Ditto.
	* freeze.adb (Check_Itype): Ditto.
	(Freeze_Expression): Ditto.
	* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Ditto.
	(Create_Extra_Formals): Add new formal, and use it to determine
	if the creation of the extra formals can be deferred. Add the
	new parameter to calls to Create_Extra_Formals.
	(Is_Unsupported_Extra_Actuals_Call): Adjust the code to improve
	its performance when the result is known.
	(Is_Unsupported_Extra_Formals_Entity): Ditto. Add new formal
	* sem_ch6.ads (Create_Extra_Formals): Add new formal.
	(Is_Unsupported_Extra_Formals_Entity): Ditto.
2025-09-09 14:39:57 +02:00
Viljar Indus 297241e4ac ada: Improve error message in the case of missing indices
When both a missing index and an out of bounds error are present then
we should also mention the error on out of bounds index as it suggests
removing the index that is out of bounds rather than suggesting adding
indices that are also out of bounds.

gcc/ada/ChangeLog:

	* sem_aggr.adb (Resolve_Array_Aggregate): Indicate an out of
	bounds index error also in the case of a missing index.
2025-09-09 14:39:56 +02:00
Viljar Indus b3d991e3d0 ada: Create a pragma to emit a misplaced Storage_Size aspect error
We do not emit an error on misplaced Strorage_Size error when
the aspect is not applied to a task (or an access type). We
instead create an attribute definition which is ignored most of the
time. Create a temporary pragma for the aspect specification to
emit the same misplaced aspect error as we do for pragmas.

gcc/ada/ChangeLog:

	* sem_ch13.adb (Analyze_Aspect_Definitions): Create a temporary
	pragma for the non-task and access type cases.
2025-09-09 14:39:56 +02:00
Ronan Desplanques 4f5025391a ada: Remove useless statements
The initial value of fields of type Elist_Id is No_Elist, therefore the
statements this patch removes were useless.

gcc/ada/ChangeLog:

	* sem_ch7.adb (New_Private_Type): Remove useless statements.
2025-09-09 14:39:56 +02:00
Denis Mazzucato 7a097ce43f ada: Replace Preelaborable_Initialization pragmas with equivalent aspect specs
All Preelaborable_Initialization pragmas in the language-defined units are
replaced by the equivalent Preelaborable_Initialization aspect.

gcc/ada/ChangeLog:

	* targparm.adb (Get_Target_Parameters): Address type declaration doesn't
	ends anymore with a semicolon.
	* libgnat/a-cdlili.ads: Replace Preelaborable_Initialization.
	* libgnat/a-cidlli.ads: Likewise.
	* libgnat/a-cihama.ads: Likewise.
	* libgnat/a-cihase.ads: Likewise.
	* libgnat/a-cimutr.ads: Likewise.
	* libgnat/a-ciorma.ads: Likewise.
	* libgnat/a-ciormu.ads: Likewise.
	* libgnat/a-ciorse.ads: Likewise.
	* libgnat/a-cohama.ads: Likewise.
	* libgnat/a-cohase.ads: Likewise.
	* libgnat/a-coinho.ads: Likewise.
	* libgnat/a-coinho__shared.ads: Likewise.
	* libgnat/a-coinve.ads: Likewise.
	* libgnat/a-comutr.ads: Likewise.
	* libgnat/a-convec.ads: Likewise.
	* libgnat/a-coorma.ads: Likewise.
	* libgnat/a-coormu.ads: Likewise.
	* libgnat/a-coorse.ads: Likewise.
	* libgnat/a-crdlli.ads: Likewise.
	* libgnat/a-except.ads: Likewise.
	* libgnat/a-finali.ads: Likewise.
	* libgnat/a-ngcoty.ads: Likewise.
	* libgnat/a-strbou.ads: Likewise.
	* libgnat/a-stream.ads: Likewise.
	* libgnat/a-strmap.ads: Likewise.
	* libgnat/a-strunb.ads: Likewise.
	* libgnat/a-strunb__shared.ads: Likewise.
	* libgnat/a-ststio.ads: Likewise.
	* libgnat/a-stwibo.ads: Likewise.
	* libgnat/a-stwima.ads: Likewise.
	* libgnat/a-stwiun.ads: Likewise.
	* libgnat/a-stwiun__shared.ads: Likewise.
	* libgnat/a-stzbou.ads: Likewise.
	* libgnat/a-stzmap.ads: Likewise.
	* libgnat/a-stzunb.ads: Likewise.
	* libgnat/a-stzunb__shared.ads: Likewise.
	* libgnat/a-tags.ads: Likewise.
	* libgnat/i-cstrin.ads: Likewise.
	* libgnat/s-stopoo.ads: Likewise.
	* libgnat/s-stposu.ads: Likewise.
	* libgnat/system-aix.ads: Likewise.
	* libgnat/system-darwin-arm.ads: Likewise.
	* libgnat/system-darwin-ppc.ads: Likewise.
	* libgnat/system-darwin-x86.ads: Likewise.
	* libgnat/system-djgpp.ads: Likewise.
	* libgnat/system-dragonfly-x86_64.ads: Likewise.
	* libgnat/system-freebsd.ads: Likewise.
	* libgnat/system-gnu.ads: Likewise.
	* libgnat/system-hpux-ia64.ads: Likewise.
	* libgnat/system-hpux.ads: Likewise.
	* libgnat/system-linux-alpha.ads: Likewise.
	* libgnat/system-linux-arm.ads: Likewise.
	* libgnat/system-linux-hppa.ads: Likewise.
	* libgnat/system-linux-ia64.ads: Likewise.
	* libgnat/system-linux-loongarch.ads: Likewise.
	* libgnat/system-linux-m68k.ads: Likewise.
	* libgnat/system-linux-mips.ads: Likewise.
	* libgnat/system-linux-ppc.ads: Likewise.
	* libgnat/system-linux-riscv.ads: Likewise.
	* libgnat/system-linux-s390.ads: Likewise.
	* libgnat/system-linux-sh4.ads: Likewise.
	* libgnat/system-linux-sparc.ads: Likewise.
	* libgnat/system-linux-x86.ads: Likewise.
	* libgnat/system-lynxos178-ppc.ads: Likewise.
	* libgnat/system-lynxos178-x86.ads: Likewise.
	* libgnat/system-mingw.ads: Likewise.
	* libgnat/system-qnx-arm.ads: Likewise.
	* libgnat/system-rtems.ads: Likewise.
	* libgnat/system-solaris-sparc.ads: Likewise.
	* libgnat/system-solaris-x86.ads: Likewise.
	* libgnat/system-vxworks-ppc-kernel.ads: Likewise.
	* libgnat/system-vxworks-ppc-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks-ppc-rtp.ads: Likewise.
	* libgnat/system-vxworks7-aarch64-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-aarch64.ads: Likewise.
	* libgnat/system-vxworks7-arm-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-arm.ads: Likewise.
	* libgnat/system-vxworks7-ppc-kernel.ads: Likewise.
	* libgnat/system-vxworks7-ppc-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-ppc64-kernel.ads: Likewise.
	* libgnat/system-vxworks7-ppc64-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-x86-kernel.ads: Likewise.
	* libgnat/system-vxworks7-x86-rtp-smp.ads: Likewise.
	* libgnat/system-vxworks7-x86_64-kernel.ads: Likewise.
	* libgnat/system-vxworks7-x86_64-rtp-smp.ads: Likewise.
2025-09-09 14:39:55 +02:00
Marc Poulhiès a2ee4707c1 ada: Typo fix in comment
gcc/ada/ChangeLog:

	* s-pack.adb.tmpl: Typo fix in comment.
2025-09-09 14:39:55 +02:00
Viljar Indus 43b631530d ada: Avoid marking a ghost pragma twice
Previously all assertion level pragmas were marked based on the
current scope. Additionally some pragmas were marked afterwards
based on the relevant entity e.g. Pre. This would lead to cases
where a pragma was marked as both ignored and checked ghost pragma.

Each pragma should get marked only once based on their individual
semantics.

gcc/ada/ChangeLog:

	* sem_prag.adb (Analyze_Pragma): Set Mark_Ghost_Code individually
	based on the semantics of each pragma.
2025-09-09 14:39:55 +02:00
Viljar Indus db243f7f41 ada: Avoid renamed declaration becoming both ignored and checked
gcc/ada/ChangeLog:

	* ghost.adb (Mark_Ghost_Declaration_Or_Body): Mark ghost
	entity explicitly as ignored or checked.
2025-09-09 14:39:54 +02:00
Viljar Indus bdb29aa4e5 ada: The policy of a generic can be different within a instantiation
gcc/ada/ChangeLog:

	* ghost.adb (Check_Ghost_Policy): ignore ghost policy changes
	within instantiation statements.
2025-09-09 14:39:54 +02:00
Viljar Indus 2a30a4b62c ada: Fix ghost policy change detection for procedure calls
gcc/ada/ChangeLog:

	* ghost.adb (Check_Ghost_Policy): Use the policy in affect for
	the identifier at the current moment instead of the region
	around it when checking a policy change for a procedure call.
2025-09-09 14:39:54 +02:00
Viljar Indus 1612b4ea74 ada: Fix ghost policy detection for declarations
Declarations should take the ghost policy from the region if
they do not have an explicit ghost aspect/pragam themselves.

gcc/ada/ChangeLog:

	* ghost.adb (Mark_And_Set_Ghost_Declaration): apply the
	ghost policy and level from the declaration only if the declaration
	has an explicit ghost aspect/pragma.
2025-09-09 14:39:53 +02:00
Denis Mazzucato 54baf2a92b ada: Fix inheritance of Is_Primitive and legality check for nonoverridable aspects
This patch fixes the identification of inherited subprograms as primitive
operations via the Is_Primitive flag. This is essential in the context of the
new legality check which makes sure that, if any subprogram denoted by a
nonoverridable aspect of a type T with formal or return of either type T or
access T, then all denoted subprograms should be primitive operations. Note
that all valid interpretations of a subprogram are denoted by the aspect under
evaluation, all of these needs to be primitive then.

This is a respin of eng/toolchain/gnat!2039

gcc/ada/ChangeLog:

	* sem_ch13.adb (Check_Nonoverridable_Aspect_Subprograms): Add the new
	legality check in Check_Nonoverridable_Aspect_Subprograms for
	nonoverridable aspects to check whether the denoted subprograms satisfy
	MR 13.1.1(18.4/6), otherwise we emit an error. Fix spacing.
	* sem_ch6.adb (New_Overloaded_Entity): Set Is_Primitive flag
	for inherited primitives, and filter out homonym candidates without a
	function specification as parents.
2025-09-09 14:39:53 +02:00
Piotr Trojanek 77db91aae8 ada: Reject pragma Attach_Handler on procedures in protected bodies
Pragma Attach_Handler and Interrupt_Handler are only legal for procedures
declared in protected definition. When given for procedures declared in
protected body, they were wrongly accepted and triggered an odd error message
from expansion.

gcc/ada/ChangeLog:

	* sem_prag.adb (Check_Interrupt_Or_Attach_Handler): Refine test for
	protected procedures; fix typo in comment.
2025-09-09 14:39:53 +02:00
Viljar Indus 03286f6873 ada: Avoid performing policy checks on ignored ghost pragmas
These pragamas are already disabled if the relative ghost entity
is disabled.

gcc/ada/ChangeLog:

	* ghost.adb (Is_OK_Pragma): mark the context of ignored ghost
	pragmas as OK.
2025-09-09 14:39:52 +02:00
Viljar Indus 17fd732c48 ada: Fix resolution of assertion levels
Unsuccessful preanalyze_and_resolve still marks identifiers as Any_Id.
Override that result if an identifier matched an assertion level.

gcc/ada/ChangeLog:

	* ghost.adb (Assertion_Level_From_Arg): Ensure that assertion level
	is stored as the entity for its reference.
	(Enables_Ghostness): Derive the result from whether or not the
	an argument indicated an assertion level.
	* tbuild.adb (Make_Assertion_Level): ensure that assertion levels
	have a standard scope.
2025-09-09 14:39:52 +02:00
Piotr Trojanek 59ca6e0372 ada: Check restriction No_Secondary_Stack for overflow elimination
When overflow checks are eliminated using System.Bignums package, we must
check if secondary stack that is necessary for this package is available.

gcc/ada/ChangeLog:

	* checks.adb (Make_Bignum_Block): Check restriction No_Secondary_Stack.
2025-09-09 14:39:52 +02:00
Viljar Indus b0b81e8e20 ada: Add special handling for Runtime and Static in Policy_In_Effect
When one of those levels is present then we should not look
for the policy in the policy stack but rather determine the
policy immidiately like we do in Check_Applicable_Policy.

gcc/ada/ChangeLog:

	* sem_util.adb (Policy_In_Effect): Add special handling
	for Runtime and Static values.
2025-09-09 14:39:51 +02:00
Denis Mazzucato ed2a7045a2 ada: Fix crash with global No_Tasking and async delays
When optimizations are enabled, the runtime for delays is inlined and expanded.
If No_Tasking is set globally, for instance via a configuration file, then the
initialization of _Master, _Chain, and _Task_Name formals is skipped for task
entities. Later during expansion, these identifiers are expected but won't be
found, crashing the compiler. This patch fixes Init_Formals by removing the
check on Global_No_Tasking. If a No_Tasking restriction applies, then a
violation error will be raised when analyzing the task type.

gcc/ada/ChangeLog:

	* exp_ch3.adb (Init_Formals): Remove the check on Global_No_Tasking.
	* sem.adb: Fix typo.
2025-09-09 14:39:51 +02:00
Gary Dismukes 3921122c0f ada: Compiler crash on container aggregate with constant element choice
The compiler fails when compiling a container aggregate with
an element association with a key choice that denotes a constant
object.  The code for getting the value of the choice was only
accounting for the possibility of integer and enumeration literals,
and is corrected to handle static expressions generally.

gcc/ada/ChangeLog:

	* exp_aggr.adb (Build_Container_Aggr_Code.To_Int): Replace existing
	conditional expression with call to Expr_Value.
2025-09-09 14:39:51 +02:00
Viljar Indus d57092f2f3 ada: Add default assertion level for assertions
To standardize the comparisson between the levels of ghost
entities and levels of assertion pragmasTo standardize the comparisson
between the levels of ghost
entities and levels of assertion pragmas.

gcc/ada/ChangeLog:

	* sem_ch13.adb (Analyze_Aspect_Specifications): add default
	assertion level to assertion aspects.
	* sem_prag.adb (Analyze_Pragma): Likewise.
2025-09-09 14:39:50 +02:00
Ghjuvan Lacambre 3b0aebd70d ada: exp_ch6.adb: perform less checks in CodePeer_Mode
As explained in the comments, the CodePeer_Mode AST isn't well-formed
for a GCC back-end, but is fine for a CodePeer one. The checks ensuring
that the AST is well-formed thus need to be disabled.

gcc/ada/ChangeLog:

	* exp_ch6.adb (Check_BIP_Actuals, Process_Node): Disable checks.
2025-09-09 14:39:50 +02:00
Javier Miranda 8d5816539d ada: Unsigned_Base_Range aspect
This patch adds support for a new GNAT aspect/pragma for integer
type definitions to explicitly enforce the use of an unsigned
base type.

gcc/ada/ChangeLog:

	* aspects.ads (Aspect_Unsigned_Base_Range): New aspect.
	* checks.adb (Determine_Range): Handle types with unsigned base range aspect.
	(Enable_Overflow_Check): ditto
	(Apply_Arithmetic_Overflow_Strict): ditto
	* debug.adb (d_o): Document new usage.
	* einfo.ads (Has_Unsigned_Base_Range_Aspect): New flag.
	* exp_attr.adb (Expand_N_Attribute_Reference): No action since
	it has been already handled at this stage.
	* exp_ch4.adb (Expand_N_Op_Add): Generate aritmetic overflow check on
	unsigned base range type operands.
	(Expand_N_Op_Subtract): ditto
	(Expand_N_Op_Multiply): ditto
	(Expand_N_Op_Minus): ditto
	* gen_il-fields.ads (Has_Unsigned_Base_Range_Aspect): New flag.
	* gen_il-gen-gen_entities.adb (Has_Unsigned_Base_Range_Aspect): New flag.
	* gen_il-internals.adb (Has_Unsigned_Base_Range_Aspect): New flag.
	* gnat1drv.adb (Adjust_Global_Switches): Handle -gnatd_o
	* par-prag.adb (Pragma_Unsigned_Base_Range): No action since it will
	be entirely handled by the semantic analyzer.
	* rtsfind.ads (RE_Id): Add RE_Uns_[Add|Subtract|Multiply]_With_ Ovflo_Check
	* sem_attr.ads (Attribute_Unsigned_Base_Range): Added to the set of
	implementation defined attributes.
	* sem_attr.adb (Analyze_Attribute): Analyze attribute Unsigned_Base_Range.
	(Eval_Attribute): Evaluate attribute Unsigned_Base_Range.
	* sem_ch13.adb (Analyze_One_Aspect): Defer checks for this aspect to
	the analysis of the corresponding pragma.
	* sem_ch3.ads (Unsigned_Base_Range_Type_Declaration): New subprogram.
	* sem_ch3.adb (Build_Derived_Numeric_Type): Inherit flag
	Has_Unsigned_Base_Range_Aspect.
	(Unsigned_Base_Range_Type_Declaration): New subprogram.
	(Has_Pragma_Unsigned_Base_Range): New subprogram.
	* sem_prag.adb (Analyze_Pragma): Handle Pragma_Unsigned_Base_Range.
	* snames.adb-tmpl (Get_Pragma_Id): Handle Name_Unsigned_Base_Range.
	(Is_Pragma_Name): ditto.
	* snames.ads-tmpl (Name_Unsigned_Base_Range): New name.
	(Attribute_Unsigned_Base_Range): New attribute.
	(Pragma_Unsigned_Base_Range): New pragma.
	* libgnat/s-aridou.ads (Add_With_Ovflo_Check): New routine for Double_Uns.
	(Subtract_With_Ovflo_Check): ditto.
	(Multiply_With_Ovflo_Check): ditto.
	* libgnat/s-aridou.adb (Add_With_Ovflo_Check): ditto.
	(Subtract_With_Ovflo_Check): ditto.
	(Multiply_With_Ovflo_Check): ditto.
	* libgnat/s-arit64.ads (Uns_Add_With_Ovflo_Check64): New subprogram.
	(Uns_Subtract_With_Ovflo_Check64): ditto.
	(Uns_Multiply_With_Ovflo_Check64): ditto.
	* libgnat/s-arit64.adb (Uns_Add_With_Ovflo_Check64): New subprogram.
	(Uns_Subtract_With_Ovflo_Check64): ditto.
	(Uns_Multiply_With_Ovflo_Check64): ditto.
	* libgnat/s-arit128.ads (Uns_Add_With_Ovflo_Check128): New subprogram.
	(Uns_Subtract_With_Ovflo_Check128): ditto.
	(Uns_Multiply_With_Ovflo_Check128): ditto.
	* libgnat/s-arit128.adb (Uns_Add_With_Ovflo_Check128): New subprogram.
	(Uns_Subtract_With_Ovflo_Check128): ditto.
	(Uns_Multiply_With_Ovflo_Check128): ditto.
	* doc/gnat_rm/gnat_language_extensions.rst: Document unsigned
	base range.
	* gnat_rm.texi: Regenerate.
	* gnat_ugn.texi: Regenerate.
2025-09-09 14:39:50 +02:00
Viljar Indus 5d52904553 ada: Multiple levels of ghost code
Adds support for the new language feature that allows ghost enties and
assertion pragmas and aspects to be associated with a new entity called
assertion level.

Added support for a new pragma Assertion_Level that declares new
assertion levels. This pragma consists of the level name and assertion
levels it depends on.

pragma Assertion_Level (L1);
pragma Assertion_Level (L2);
pragma Assertion_Level (L3, Depends => [L1, L2]);

There are two special assertion levels that are considered to be
declared in the Standard package that have unique properties.

Assertion level Runtime is always considered to be Checked. Its
assertion policy cannot be changed and it is considered that all other
assertion levels depend on this level.

Assertion level Static is always considered to be Ignored. Its assertion
policy cannot be changed. All assertion levels that depend on this
level can also never be activated.

Aspect Ghost now supports the assertion level as a possible argument:

... with Ghost => Level;

All pragmas and aspects which were considered to be valid assertion
kinds for pragma Assertion_Policy now support assertion level
associations. The association consists of an assertion level and a set
of existing arguments. Note that you can have multiple assertion level
associations in a given pragma or aspect. e.g.

pragma Assert (Level1 => (Check => Expr1, Message => "Msg1",
               Level2 => (Check => Expr2, Message => "Msg2"));

It is possible to set an explicit Assertion_Policy for those levels
which can control the policies for all entities associated with those
levels.

Setting the policy Check for a given level means also that policy Check
is set for all of the policies that it depends on. From the previous
example.

pragma Assertion_Policy (L3 => Check);

is equivalent to:

pragma Assertion_Policy (L1 => Check);
pragma Assertion_Policy (L2 => Check);
pragma Assertion_Policy (L3 => Check);

Setting the policy Ignore for a given level means that the policy Ignore
is also applied to all the levels that depend on it. e.g

pragma Assertion_Policy (L2 => Ignore);

is equivalent to:

pragma Assertion_Policy (L2 => Ignore);
pragma Assertion_Policy (L3 => Ignore);

Since now ghost regions can contain other ghost regions with a different
assertion policy then new rules needed to be added for those situations
to ensure valid compilation.

Additionally all rules where we checked for compatible assertion
policies have an additional check for a compatible assertion level dependencies.

Ghost entities A and B are considered assertion level dependent when
* A or B does not have an associated assertion level.
* Both A and B have an assertion level and either
  * the level of A is or depends on the level of B.
  * the level of B cannot be enabled (is or depends on Static)

gcc/ada/ChangeLog:

	* atree.adb (Mark_New_Ghost_Node): Store the assertion level on the
	entity.
	* contracts.adb (Analyze_Package_Contract): Add support for multiple
	pragma Initial_Condition orginating from multiple assertion levels.
	* cstand.adb (Make_Assertion_Level_Definition): New function that
	creates a new Assertion_Level and adds it to the Assertion_Levels
	table.
	(Create_Standard): Add definitions for assertion levels defined in
	Standard.
	(Print_Standard): Add assertion level pragmas do the output.
	* exp_ch6.adb (Check_Subprogram_Variant): Add support for multiple
	Subprogram_Variant pragmas created by assertion levels.
	* einfo.ads: add info for the new nodes and attributes.
	* exp_prag.adb (Consequence_Error): Fix error message string
	corruption caused by another call to the internal strings during
	the call to Make_Procedure_Call_Statement.
	(Expand_Pragma_Initial_Condition): Ensure all ghost related
	attributes are copied to the new pragma.
	(Expand_Pragma_Loop_Variant): Likewise.
	(Expand_Pragma_Subprogram_Variant). Likewise. Additionally
	create a new Subprogram_Variant function for each pragma associated
	with an assertion level.
	* exp_util.adb (Add_DIC_Check): Ensure all ghost related attributes
	are copied to the new pragma.
	(Build_DIC_Procedure_Body): Add support for mutliple DIC pragmas
	created from assertion levels.
	* gen_il-fields.ads:
	(Aspect_Ghost_Assertion_Level): New field.
	(Original_Aspect): New field.
	(Original_Pragma): New field.
	(Pragma_Ghost_Assertion_Level): New field.
	(Child_Levels): New field.
	(Ghost_Assertion_Level): New field.
	(Parent_Levels): New field.
	* gen_il-gen-gen_entities.adb:
	Add Ghost_Assertion_Level field for all entities
	Add new E_Assertion_Level entity for storing assertion levels.
	* gen_il-gen-gen_nodes.adb:
	Add Aspect_Ghost_Assertion_Level for N_Aspect to store the
	assertion level associated with the aspect.
	Add Original_Aspect to store the original aspect where the aspect
	that was transformed from an aspect with an assertion level
	origninated from.
	Add Pragma_Ghost_Assertion_Level and Original_Pragma to store
	the same information for N_Prama nodes.
	* gen_il-types.ads: Add new entity kind E_Assertion_Level
	* ghost.adb (Assertion_Level_Error_Msg): Create constant for
	error messages using the same main error message.
	(Ghost_Policy_Error_Msg): Likewise.
	(Assertion_Level_To_Name): New subprogram.
	(Check_Valid_Ghost_Declaration): New subprogram.
	(Get_Ghost_Aspect): New subprogram.
	(Get_Ghost_Assertion_Level): New subprogram.
	(Ghost_Policy_In_Effect): New subprogram.
	(Install_Ghost_Region): New subprogram.
	(Mark_And_Set_Ghost_Region): New subprogram.
	(Mark_Ghost_Declaration_Or_Body): Add new argument for assertion
	levels.
	(Check_Ghost_Completion): Update ghost policy calculation with
	assertion levels. Refactor error message.
	(Is_OK_Statement): Add new checks for valid assertion policies and
	assertion levels.
	(Is_OK_Pragma): Refactor the calculation of valid ghost pragmas.
	(Check_Ghost_Policy): Make the checks ghost region based.
	(Check_Ghost_Context): Refactor the order of checks.
	(Check_Ghost_Formal_Procedure_Or_Package): Relax the checks for
	overriding procedures. Now only ignored subprograms cannot be
	overridden by checked or non-ghost subprograms.
	(Check_Ghost_Primitive): Relax conditions for primitve operations.
	Now only checked primitive subprograms are considered invalid for
	ignored tagged types. Add assertion level compatibility checks.
	(Check_Ghost_Refinement): Relax conditions for ghost refinements.
	Add assertion level compatibility checks for refinements.
	(Install_Ghost_Region): Store the current region and the assertion
	for that region in the ghost config.
	(Enables_Ghostness): Refactor implementation to support assertion
	levels.
	(Is_Subject_To_Ghost): Simplify implementation.
	(Mark_And_Set_Ghost_Assignment): Refactor implementation.
	(Mark_And_Set_Ghost_Body): Add support for assertion levels.
	(Mark_And_Set_Ghost_Completion): Likewise.
	(Mark_And_Set_Ghost_Declaration): Likwise.
	(Mark_And_Set_Ghost_Instantiation): Likwise.
	(Mark_And_Set_Ghost_Procedure_Call): Refactor implementation.
	(Mark_Ghost_Declaration_Or_Body): Add support for assertion levels.
	(Set_Ghost_Mode): Likwise.
	* ghost.ads (Assertion_Level_From_Arg): New subprogram.
	(Install_Ghost_Region): Add argument Level for assertrion levels.
	(Is_Assertion_Level_Dependent): New subprogram.
	* lib-xref.ads: Add new mapping for E_Assertion_Level entities.
	* opt.ads (Ghost_Config_Type): Add new members Ghost_Assertion_Mode
	and Current_Region to the structure.
	* par-prag.adb (Prag): Add new pragma name Assertion_Level.
	* rtsfind.adb (Load_RTU): Update the arguments for the call to
	Install_Ghost_Region.
	* sem.adb (Do_Analyze): Likewise.
	* sem_ch13.adb (Convert_Aspect_With_Assertion_Levels): New
	subprogram.
	(Make_Aitem_Pragma): Copy ghost mode attributes from the aspect to
	the pragma.
	(Analyze_Aspect_Specifications): Convert aspects that have an
	assertion level association in the aspects without the association
	and the original supported syntax and with the assertion level
	stored on the aspect node.
	Updated duplicate detection to avoid duplicates being called on
	aspects with assertion levels that orginated from the same aspect.
	* sem_prag.adb (Apply_Check_Policy): New subprogram.
	(Get_Applicable_Policy): New subprogram.
	(Mark_Is_Checked): New subprogram.
	(Mark_Is_Disabled): New subprogram.
	(Mark_Is_Ignored): New subprgram.
	(Check_Arg_Is_One_Of): Remove versions that had a specific number
	of arguments and replace them with a list one.
	(Create_Pragma_Without_Assertion_Level): New subprogram.
	(Assertion_Level_Pragma_Comes_From_Source): New subprogram.
	(Analyze_Pragma): Replace aspects that have an assertion level
	with aspects without them where the level is stored on the pragma
	node.
	(Abstract_State): Add support for assertion levels in ghost
	Abstract_State pragmas.
	(Assert): Update argument handling for Assert like pragmas.
	(Assertion_Level): Add a new section to support the analysis of
	pragma Assertion_Level.
	(Assertion_Policy): Add support for setting the policy for assertion
	levels.
	(Check): Update argument handling. Update the assertion policy
	application process.
	(Check_Policy): Add support for assertion levels. Add check_policy
	pragmas for assertion_level dependencis also to the stack of
	known Check_Policy pragmas.
	(Default_Initial_Condition): Reject the use of DIC with assertion
	levels. Update duplication checks.
	(Ghost): Add support for assertion levels. Fix issue where
	assertion levels with Ghost => False were treated as ghost.
	(Predicate): Update the policy handling of Ghost_Predicate.
	(Analyze_Refined_State_In_Decl_Part): Create a new ghost region
	for analyzing Refined_State.
	(Check_Applicable_Policy): Refactor the implementation. Break it
	down to Get_Applicable_Policy and Apply_Check_Policy.
	(Check_Kind): Removed. Replaced by Get_Applicable_Policy and
	Apply_Check_Policy.
	(Initialize): Initialize the table storing all know assertion
	levels.
	* sem_prag.ads (Find_Assertion_Level): New subprogram.
	(Insert_Assertion_Level): New subprogram.
	(Check_Applicable_Policy): Add new argument Level.
	(Check_Kind): Removed. Merged with Get_Applicable_Policy.
	(Get_Assertion_Level): New subprogram.
	(Is_Valid_Assertion_Level): New subprogram.
	* sem_util.adb (Copy_Assertion_Policy_Attributes): New function
	for copying the ghost related attributes from one pragma to
	another.
	(Copy_Subprogram_Spec): Additionally copy the level from the spec.
	(Depends_On_Level): New function for checking if one level depends
	on another level.
	(From_Same_Aspect): New function for checking whether the aspects
	orignate from the same original aspect.
	(From_Same_Pragma): New function for checking whether the pragmas
	originate from the same original aspect or pragma.
	(Get_Subprogram_Entity): Avoid crash when being called when the
	entity has not been set for the subprogram.
	(Has_Assertion_Level_Argument): New function for checking whether
	the aspect or a pragma has an argument that is using an assertion
	level association.
	(Policy_In_Effect): add an additional argument for the level that
	should be checked along with the assertion name.
	* sem_util.ads (Copy_Assertion_Policy_Attributes): New function.
	(Depends_On_Level): Likewise.
	(From_Same_Aspect): Likewise.
	(From_Same_Pragma): Likewise.
	(Has_Assertion_Level_Argument): Likewise.
	(Is_Same_Or_Depends_On_Level): Likewise.
	(Policy_In_Effect): Add new argument Level.
	* sinfo.ads: Add documentation for all the new attributes that
	were added to the nodes and entities.
	* snames.ads-tmpl: Add new entries for Name_Assertion_Level,
	Name_uDefault_Assertion_Level and Pragma_Assertion_Level.
	* stand.ads: Add new entities for the predefined assertion levels.
	(Standard_Level_Static): Definition for the predefined Static
	level that is always ignored.
	(Standard_Level_Runtime): Defintion for the predefined Runtime
	level that is always checked.
	(Standard_Level_Default): Definition for the implicit Default
	level that is given for ghost entities that were not associated
	with an assertion level (e.g. Ghost => True).
	* tbuild.adb (Make_Assertion_Level): New function for constructin
	an assertion level.
	* tbuild.ads (Make_Assertion_Level): Likewise.
2025-09-09 14:39:49 +02:00
Arsen Arsenović c7e9d256fb libstdc++: Replace "Tunables" link with one that does not have an anchor
This works around a dblatex bug, where dblatex emits invalid TeX, by
placing a raw "#" in a \href.

Fixes: f6ff531d90 ("libstdc++: Update link to "Tunables" in Glibc manual")

libstdc++-v3/ChangeLog:

	* doc/xml/manual/using_exceptions.xml: Replace "Tunables" link
	with one that does not have an anchor.
	* doc/html/manual/using_exceptions.html: Regenerate.
2025-09-09 13:04:57 +02:00
Matthias Kretz 19d1c7c28f c++: Fix mangling of _Float16 template args [PR121801]
Signed-off-by: Matthias Kretz <m.kretz@gsi.de>

gcc/testsuite/ChangeLog:

	PR c++/121801
	* g++.dg/abi/pr121801.C: New test.

gcc/cp/ChangeLog:

	PR c++/121801
	* mangle.cc (write_real_cst): Handle 16-bit real and assert
	that reals have 16 bits or a multiple of 32 bits.
2025-09-09 07:57:59 +02:00
H.J. Lu 1d1396559e x86: Enable SSE4.1 ceil/floor/trunc for -Os
Enable SSE4.1 ceil/floor/trunc for -Os to replace a function call with
roundss or roundsd by dropping the !flag_trapping_math check.

gcc/

	PR target/121861
	* config/i386/i386.cc (ix86_optab_supported_p): Drop
	!flag_trapping_math check for floor_optab, ceil_optab and
	btrunc_optab.

gcc/testsuite/

	PR target/121861
	* gcc.target/i386/pr121861-1a.c: New file.
	* gcc.target/i386/pr121861-1b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-08 20:22:05 -07:00
liuhongt 7a527754fd Use vpermil{ps,pd} instead of vperm{d,q} when permutation is in-lane.
gcc/ChangeLog:

	* config/i386/i386-expand.cc (expand_vec_perm_vpermil): Extend
	to handle V8SImode.
	* config/i386/i386.cc (avx_vpermilp_parallel): Extend to
	handle vector integer modes with same vector size and same
	component size.
	* config/i386/sse.md
	(<sse2_avx_avx512f>_vpermilp<mode><mask_name>): Ditto.
	(V48_AVX): New mode iterator.
	(ssefltmodesuffix): Extend for V16SI/V8DI/V16SF/V8DF.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/avx256_avoid_vec_perm-3.c: New test.
	* gcc.target/i386/avx256_avoid_vec_perm-4.c: New test.
	* gcc.target/i386/avx512bw-vpalignr-4.c: Adjust testcase.
	* gcc.target/i386/avx512vl-vpalignr-4.c: Ditto.
2025-09-08 18:58:55 -07:00
liuhongt f4154da555 Exclude fake cross-lane permutation from avx256_avoid_vec_perm.
SLP may take a broadcast as kind of vec_perm, the patch checks the
permutation index to exclude those false positive.

gcc/ChangeLog:

	* config/i386/i386.cc (ix86_vector_costs::add_stmt_cost):
	Check permutation index for vec_perm, don't count it if we
	know it's not a cross-lane permutation.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/avx256_avoid_vec_perm.c: Adjust testcase.
	* gcc.target/i386/avx256_avoid_vec_perm-2.c: New test.
	* gcc.target/i386/avx256_avoid_vec_perm-5.c: New test.
2025-09-08 18:58:51 -07:00
GCC Administrator bc5781e76f Daily bump. 2025-09-09 00:23:09 +00:00
Jonathan Wakely f65747d0d9 libstdc++: Rename template parameter of std::constant_wrapper
This fixes:
FAIL: 17_intro/badnames.cc  -std=gnu++26 (test for excess errors)

libstdc++-v3/ChangeLog:

	* include/std/type_traits (constant_wrapper): Rename template
	parameter to avoid BADNAME.
2025-09-09 00:36:16 +01:00
H.J. Lu 8cad8f94b4 c: Update TLS model after processing a TLS variable
Set a tentative TLS model in grokvardecl and update TLS mode with the
default TLS access model after a TLS variable has been fully processed
if the default TLS access model is stronger.

gcc/c/

	PR c/107419
	* c-decl.cc (c_decl_attributes): Update TLS model with the
	default TLS access model if the default TLS access model is
	stronger.
	(grokdeclarator): Set a tentative TLS model which will be
	updated by c_decl_attributes later.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-08 14:11:17 -07:00
Jonathan Wakely d199a9c7c5 libstdc++: Fix docs for --enable-vtable-verify [PR120698]
libstdc++-v3/ChangeLog:

	PR libstdc++/120698
	* doc/xml/manual/configure.xml: Do not claim that vtv is enabled
	by default.
	* doc/html/manual/configure.html: Regenerate.
2025-09-08 21:54:32 +01:00
Nathan Myers de35b739a8 libstdc++: fix makefile.in for syncbuf.lo
This patch fixes Makefile.in to include mention of new syncbuf.lo.

libstdc++-v3/Changelog:
	* src/c++20/Makefile.in: Mention syncbuf.lo.
2025-09-08 15:41:14 -04:00
Eric Botcazou 5ee35b12de Ada: Make -fdump-ada-spec deal with pointers to anonymous structure
This is about -fdump-ada-spec not generating the definition of the structure
for pointers to anonymous structure as structure elements.

gcc/c-family:
	PR ada/121544
	* c-ada-spec.cc (dump_ada_node) <POINTER_TYPE>: Dump the name of
	anonymous tagged pointed-to types specially.
	(dump_nested_type) <POINTER_TYPE>: Recurse on anonymous pointed-to
	types declared in the same file.
	Set TREE_VISITED on the underlying DECL of the field type, if any.
2025-09-08 19:41:20 +02:00
Eric Botcazou 7640cc5ef8 Testsuite: Fix spurious of ACATS-4 test cxai033
This tentatively applies the same tweak as in other similar cases.

gcc/testsuite/
	PR ada/121532
	* ada/acats-4/tests/cxa/cxai033.a: Use Long_Switch_To_New_Task
	constant instead of Switch_To_New_Task in delay statements.
2025-09-08 19:18:59 +02:00
Nathan Myers 4eb12ddd32 libstdc++: Make syncbuf _S_get_mutex definition extern.
This patch creates a global function __syncbuf_get_mutex, gated by
_GLIBCXX_HAS_GTHREADS, replacing a static instantiated member
_S_get_mutex used in syncbuf<> construction, and makes the global
symbol visible. A static local table of 16 mutexes is shared among
all specializations of syncbuf<>, chosen on construction by a hash
of the wrapped streambuf's address.

It detaches the implementation of _S_get_mutex from the C++20 ABI.

libstdc++-v3/ChangeLog:
	* include/std/syncstream: (syncbuf<>::__mutex) Remove _S_get_mutex,
	use extern function instead.
	* src/c++20/syncbuf.cc: Define global __syncbuf_get_mutex.
	* src/c++20/Makefile.am: Mention syncbuf.cc.
	* src/c++20/Makefile.in: Regenerate.
	* config/abi/pre/gnu.ver: Mention mangled __syncbuf_get_mutex.
2025-09-08 10:19:10 -04:00
Xi Ruoyao cdb76f4bee testsuite: Another fixup for fixed-point/bitint-1.c test
Besides r16-3595, there's another bug in this test: with -std=c23 the
token _Sat isn't recognized as a keyword at all, thus an error massage
different from the expected will be outputted.

Fix it by using -std=gnu23 instead.

gcc/testsuite:

	* gcc.dg/fixed-point/bitint-1.c (dg-options): Use -std=gnu23
	instead of -std=c23.
2025-09-08 22:03:04 +08:00
Richard Biener 00cd34b104 tree-optimization/121844 - IVOPTs and asm goto in latch
When there's an asm goto in the latch of a loop we may not use
IP_END IVs since instantiating those would (need to) split the
latch edge which in turn invalidates IP_NORMAL position handling.
This is a revision of the PR107997 fix.

	PR tree-optimization/107997
	PR tree-optimization/121844
	* tree-ssa-loop-ivopts.cc (allow_ip_end_pos_p): Do not allow
	IP_END for latches ending with a control stmt.
	(create_new_iv): Do not split the latch edge, instead assert
	that's not necessary.

	* gcc.dg/torture/pr121844.c: New testcase.
2025-09-08 16:01:22 +02:00
Paul-Antoine Arras 2abfcc6cfc RISC-V: Add pattern for vector-scalar widening floating-point add
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a float_extend'ed vec_duplicate into a plus RTL instruction.

Before this patch, we have four instructions, e.g.:
  fcvt.d.s        fa0,fa0
  vsetvli         a5,zero,e64,m1,ta,ma
  vfmv.v.f        v3,fa0
  vfwadd.wv       v1,v3,v2

After, we get only one:
  vfwadd.vf       v1,v2,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfwadd_vf_<mode>): New pattern to
	combine float_extend + vec_duplicate + vfwadd.vv into vfwadd.vf.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfwadd.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop.h
	(DEF_VF_BINOP_WIDEN_CASE_0): Fix OP.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwadd-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwadd-run-1-f32.c: New test.
2025-09-08 15:37:30 +02:00
Anton Blanchard 11171cb980 RISC-V: Adjust tt-ascalon-d8 branch cost
If-conversion isn't being applied to this nbench code:

 #include <stdint.h>
 #define INTERNAL_FPF_PRECISION 4
 typedef uint16_t u16;

 void ShiftMantLeft1(u16 *carry, u16 *mantissa)
 {
         int i;
         int new_carry;
         u16 accum;

         for(i=INTERNAL_FPF_PRECISION-1;i>=0;i--)
         {       accum=mantissa[i];
                 new_carry=accum & 0x8000;
                 accum=accum<<1;
                 if(*carry)
                         accum|=1;
                 *carry=new_carry;
                 mantissa[i]=accum;
         }
         return;
 }

Bumping branch_cost from 3 to 4 triggers if-conversion, improving the
nbench FP EMULATION result on Ascalon significantly. There's a risk
that more aggressive use of conditional zero instructions will negatively
impact workloads that predict well, but we haven't seen anything obvious.

gcc/ChangeLog:
	* config/riscv/riscv.cc (tt_ascalon_d8_tune_info): Increase branch_cost
	from 3 to 4.
2025-09-08 07:36:39 -06:00
Richard Biener f7426ba6c0 tree-optimization/121830 - SLP cycle detection confused by nested cycle
The SLP reduc-index computation is confused by having an outer reduction
inner loop nested cycle fed by another non-reduction nested cycle.
Instead of undoing the unfortunate mixing of outer reduction inner
cycles with general nested cycles the following instead distinguishes
them by not setting STMT_VINFO_REDUC_DEF on the non-reduction nested
cycles.

	PR tree-optimization/121830
	* tree-vect-loop.cc (vect_analyze_scalar_cycles_1): Only
	set STMT_VINFO_REDUC_DEF on reductions.
	* tree-vect-slp.cc (vect_build_slp_tree_2): Identify reduction
	PHIs by a set STMT_VINFO_REDUC_DEF instead of their def type.

	* gcc.dg/vect/pr121830.c: New testcase.
2025-09-08 14:40:18 +02:00
Richard Biener a632becefa tree-optimization/121829 - bogus CFG with asm goto
When the vectorizer removes a forwarder created earlier by split_edge
it uses redirect_edge_pred for convenience and efficiency.  That breaks
down when the edge split is originating from an asm goto as that is
a jump that needs adjustments from redirect_edge_and_branch.  The
following factores a simple vect_remove_forwarder handling this
situation appropriately.

	PR tree-optimization/121829
	* tree-vect-loop-manip.cc (vect_remove_forwarder): New
	function.
	(slpeel_tree_duplicate_loop_to_edge_cfg): Use it.

	* gcc.dg/torture/pr121829.c: New testcase.
2025-09-08 14:40:18 +02:00
Alex Coplan 4f91825436 doc: Document the -folding option for -fdump-tree-* [PR114892]
I noticed that the -fdump-tree-*-folding flag isn't documented in
the Developer options section of invoke.texi; this patch fixes that.

gcc/ChangeLog:

	PR tree-optimization/114892
	* doc/invoke.texi (Developer Options): Document -folding option
	for -fdump-tree-*.
2025-09-08 12:25:03 +01:00
Kugan Vivekanandarajah 80b453d5e4 [AutoFDO] Check count initialization to fix ICE with AutoFDO
Fix ICE with AutoFDO by adding initialization check
before accessing IPA counts to avoid issues with uninitialized profile
counts in self-recursive clone processing.

gcc/ChangeLog:

2025-09-08  Kugan Vivekanandarajah  <kvivekananda@nvidia.com>

	* ipa-cp.cc (gather_count_of_non_rec_edges): Check count
	initialization before adding to total.

Signed-off-by: Kugan Vivekanandarajah <kvivekananda@nvidia.com>
2025-09-08 20:37:48 +10:00
Paul-Antoine Arras c2048dae34 RISC-V: Add pattern for vector-scalar single-width floating-point reverse sub
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into a minus RTL instruction. The vec_duplicate is the
minuend operand.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f       v2,fa0
  vfsub.vv       v1,v2,v1

After, we get only one:
  vfrsub.vf      v1,v1,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfrsub_vf_<mode>): New pattern to
	combine vec_duplicate + vfsub.vv into vfrsub.vf.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfrsub.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_data.h: Add data for
	vfrsub.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfrsub-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfrsub-run-1-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfrsub-run-1-f64.c: New test.
2025-09-08 12:26:10 +02:00
Paul-Antoine Arras 1f01c51abf RISC-V: Add pattern for vector-scalar single-width floating-point sub
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into a minus RTL instruction. The vec_duplicate is the
subtrahend operand.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f       v2,fa0
  vfsub.vv       v1,v1,v2

After, we get only one:
  vfsub.vf       v1,v1,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfsub_vf_<mode>): New pattern to
	combine vec_duplicate + vfsub.vv into vfsub.vf.
	* config/riscv/vector.md (@pred_<optab><mode>_scalar): Allow VLS modes.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vls/floating-point-sub-2.c: Adjust scan
	dumps.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfsub.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_data.h: Add data for
	vfsub.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfsub-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfsub-run-1-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfsub-run-1-f64.c: New test.
2025-09-08 12:26:10 +02:00
Paul-Antoine Arras ff6d07960c RISC-V: Add pattern for vector-scalar single-width floating-point add
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into a plus RTL instruction.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f       v2,fa0
  vfadd.vv       v1,v1,v2

After, we get only one:
  vfadd.vf       v1,v1,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfadd_vf_<mode>): New pattern to
	combine vec_duplicate + vfadd.vv into vfadd.vf.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vls/floating-point-add-2.c: Adjust scan
	dump.
	* gcc.target/riscv/rvv/autovec/vls/floating-point-add-3.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vls/floating-point-sub-3.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfadd.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_data.h: Add data for
	vfadd.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfadd-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfadd-run-1-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfadd-run-1-f64.c: New test.
2025-09-08 12:26:10 +02:00
Paul-Antoine Arras 4488152579 RISC-V: Add pattern for vector-scalar widening floating-point multiply
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a float_extend'ed vec_duplicate into a mult RTL instruction.

Before this patch, we have six instructions, e.g.:
  fcvt.d.s        fa0,fa0
  vsetvli         a5,zero,e64,m1,ta,ma
  vfmv.v.f        v3,fa0
  vfwcvt.f.f.v    v1,v2
  vsetvli         zero,zero,e64,m1,ta,ma
  vfmul.vv        v1,v3,v1

After, we get only one:
  vfwmul.vf       v1,v2,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfwmul_vf_<mode>): New pattern to
	combine float_extend + vec_duplicate + vfmul.vv into vfmul.vf.
	* config/riscv/vector.md (*@pred_dual_widen_<optab><mode>_scalar):
	Swap operands to match the RTL emitted by expand, i.e. first
	float_extend then vec_duplicate.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfwmul.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop.h: Add support for
	widening variants.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_widen_run.h: New test
	helper.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwmul-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwmul-run-1-f32.c: New test.
2025-09-08 12:26:09 +02:00
Paul-Antoine Arras f8a1436462 RISC-V: Add patterns for vector-scalar IEEE floating-point max
These patterns enable the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into an unspec_vfmax RTL instruction.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f       v2,fa0
  vfmax.vv       v1,v2,v1

After, we get only one:
  vfmax.vf       v1,v1,fa0

In some cases, it also shaves off one vsetvli.

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfmin_vf_ieee_<mode>): Rename into...
	(*v<ieee_fmaxmin_op>_vf_<mode>): New pattern to combine vec_duplicate +
	vf{max,min}.vv (unspec) into vf{max,min}.vf.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-5-f16.c: Add vfmax.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-5-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-5-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-6-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-6-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-6-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-7-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-7-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-7-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-8-f16.c: Add vfmax. Also add
	missing -fno-fast-math.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-8-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-8-f64.c: Likewise.
2025-09-08 12:26:09 +02:00
Jakub Jelinek 592bafb26e libstdc++: Fix up <ext/pointer.h> [PR121827]
During the tests mentioned in
https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692482.html
(but dunno why I haven't noticed it back in August but only when testing
https://gcc.gnu.org/pipermail/gcc-patches/2025-September/694527.html )
I've noticed two ext header problems.
One is that #include <ext/pointer.h> got broken with the
r13-3037-g18f176d0b25591e28 change and since then is no longer
self-contained, as it includes iosfwd only if _GLIBCXX_HOSTED is defined
but doesn't actually include bits/c++config.h to make sure it is defined,
then includes a bunch of headers which do include bits/c++config.h and
finally uses in #if _GLIBCXX_HOSTED guarded code what is declared in iosfwd.
The other problem is that ext/cast.h is also not a self-contained header,
but that one has
/** @file ext/cast.h
 *  This is an internal header file, included by other library headers.
 *  Do not attempt to use it directly. @headername{ext/pointer.h}
 */
comment, so I think we just shouldn't include it in extc++.h and let
ext/pointer.h include it.

2025-09-08  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/121827
	* include/precompiled/extc++.h: Don't include ext/cast.h which is an
	internal header.
	* include/ext/pointer.h: Include bits/c++config.h before
	#if _GLIBCXX_HOSTED.
2025-09-08 11:49:58 +02:00
Gerald Pfeifer f6ff531d90 libstdc++: Update link to "Tunables" in Glibc manual
libstdc++-v3:
	* doc/xml/manual/using_exceptions.xml: Update link to "Tunables"
	section in the Glibc manual.
	* doc/html/manual/using_exceptions.html: Regenerate.
2025-09-08 11:07:25 +02:00
Gerald Pfeifer e394c5d84b doc: Remove references to Binutils 2.7 requirements
GNU Binutils 2.7 was released in 1996, no realistic need to point it
out as a minimal requirement.

gcc:
	* doc/extend.texi (SH Function Attributes): Remove reference to
	GNU Binutils 2.7 requirement.
	(H8/300 Variable Attributes): Ditto.
2025-09-08 10:52:27 +02:00
Christophe Lyon 750346a763 compare_tests: Report non-unique test names
Test "names" (the string after 'PASS:' or 'FAIL:' etc...  is expected
to be unique, otherwise this will confuse comparison scripts.

This patch displays the lists of non-unique test names in the 'before'
and in the 'now' results.

contrib/ChangeLog:

	* compare_tests: Report non-unique test names.
2025-09-08 07:45:01 +00:00
Luc Grosheintz 71711f8ac3 libstdc++: Adjust span/mdspan CTAD for P2781R9.
A usecase for P2781R9 is more ergonomic creation of span and mdspan with
mixed static and dynamic extents, e.g.:

    span(ptr, cw<3>)
    extents(cw<3>, 5, cw<7>)
    mdspan(ptr, cw<3>, 5, cw<7>)

should be deduced as:
    span<..., 3>
    extents<..., 3, dyn, 7>
    mdspan<..., extents<..., 3, dyn, 7>>

The change required is to strip cv-qualifiers and references from
`_Tp::value`, because of:

    template<_CwFixedValue _X, typename>
      struct constant_wrapper : _CwOperators
      {
	static constexpr const auto& value = _X._M_data;

libstdc++-v3/ChangeLog:

	* include/std/span (__integral_constant_like): Allow the member
	`value` of a constant wrapping type to be a const reference of
	an integer.
	* testsuite/23_containers/mdspan/extents/misc.cc: Add test for
	cw and constant_wrapper.
	* testsuite/23_containers/mdspan/mdspan.cc: Ditto.
	* testsuite/23_containers/span/deduction.cc: Ditto.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-09-08 09:40:15 +02:00
Luc GrosheintzandTomasz Kamiński c440b585ba libstdc++: Implement constant_wrapper, cw from P2781R9.
This is a partial implementation of P2781R9. It adds std::cw and
std::constant_wrapper, but doesn't modify __integral_constant_like for
span/mdspan.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (constant_wrapper): Add.
	* include/bits/version.h: Regenerate.
	* include/std/type_traits (_CwFixedValue): New class.
	(_IndexSequence): New struct.
	(_BuildIndexSequence): New struct.
	(_ConstExprParam): New concept.
	(_CwOperators): New struct.
	(constant_wrapper): New struct.
	(cw): New global constant.
	* src/c++23/std.cc.in (constant_wrapper): Add.
	(cw): Add.
	* testsuite/20_util/constant_wrapper/adl.cc: New test.
	* testsuite/20_util/constant_wrapper/ex.cc: New test.
	* testsuite/20_util/constant_wrapper/generic.cc: New test.
	* testsuite/20_util/constant_wrapper/instantiate.cc: New test.
	* testsuite/20_util/constant_wrapper/op_comma_neg.cc: New test.
	* testsuite/20_util/constant_wrapper/version.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-08 09:38:53 +02:00
Paul Thomas 565d9a3617 Fortran: Correct variable typespec in PDT specification exprs [PR84008]
2025-09-08  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/84008
	* decl.cc (insert_parameter_exprs): Correct the typespec of new
	variable declarations, where the type is set to BT_PROCEDURE as
	a precaution for resolution of the whole program unit.

gcc/testsuite/
	PR fortran/84008
	* gfortran.dg/pdt_45.f03: New test.
2025-09-08 08:13:07 +01:00
Andrew Pinski ed264541c3 strlen: Handle empty constructor as memset for combining with malloc to calloc [PR87900]
This was noticed when turning memset (with constant size) into a store of an empty constructor
but can be reproduced without that.
In this case we have the following IR:
```
  p_3 = __builtin_malloc (4096);
  *p_3 = {};
```

Which we can treat the store as a memset.
So this patch adds the similar optimization as memset/malloc now for malloc/constructor.
This patch is on top of https://gcc.gnu.org/pipermail/gcc-patches/2025-April/681439.html
(it calls allow_memset_malloc_to_calloc but that can be removed if that patch is rejected).

Changes since v1:
* v2: Correctly return false from handle_assign after removing stmt.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/87900

gcc/ChangeLog:

	* tree-ssa-strlen.cc  (strlen_pass::handle_assign): Add RHS argument.
	For empty constructor RHS, see if can combine with a previous malloc into
	a calloc.
	(strlen_pass::check_and_optimize_call): Update call to handle_assign;
	passing NULL_TREE for RHS.
	(strlen_pass::check_and_optimize_stmt): Update call to handle_assign.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/calloc-10.c: New test.
	* gcc.dg/tree-ssa/calloc-11.c: New test.
	* gcc.dg/tree-ssa/calloc-12.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-09-07 23:56:59 -07:00
Andrew Pinski d8c407a7c8 strlen: Don't do the malloc+memset->calloc optimization in some cases [PR83022]
This fixes a long standing (since GCC 5) issue where the malloc+memset->calloc
optimization would happen even if the memset was not always executed.
This is a varient of Nathan's patch: https://inbox.sourceware.org/gcc-patches/f4b5d106-8176-b7bd-709b-d435188783b0@acm.org/
Jeff Law had suggested to look at probabilities of the basic blocks to see
if it is profitable or not; I am not totally convinced that is a good idea.
Though this is an extended version of Nathan's patch as it uses post domination to see
if the memset is always called after the condition of null-ness.

	PR tree-optimization/83022

gcc/ChangeLog:

	* tree-ssa-strlen.cc (last_stmt_ptr_check): New function.
	(allow_memset_malloc_to_calloc): New function.
	(strlen_pass::handle_builtin_memset): Check to see if it is a good
	idea to do the malloc+memset->calloc optimization.
	(printf_strlen_execute): Free post dom info.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/calloc-6.c: New test.
	* gcc.dg/tree-ssa/calloc-7.c: New test.
	* gcc.dg/tree-ssa/calloc-8.c: New test.
	* gcc.dg/tree-ssa/calloc-9.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-09-07 23:56:58 -07:00
Sam James b1659de20e gcc: regenerate common.opt.urls
Needed to add -fdep-fusion.

gcc/ChangeLog:

	* common.opt.urls: Regenerate.
2025-09-08 01:30:42 +01:00
GCC Administrator 033d178600 Daily bump. 2025-09-08 00:20:50 +00:00
Andrew Pinski 7e1143abd3 forwprop: Improve rejection of overlapping for copyprop of aggregates [PR121841]
Here we have:
tmp = src1[0];
dest1[0] = tmp;
where src1 and dest1 are decls.
We currently reject this as the bases are different but since the bases
are decls we know they won't overlap.
This adds the extra check to allow this.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/121841

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_agr_copyprop_1): Allow
	two different decls as bases as non-overlapping bases.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/copy-prop-aggregate-struct-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-07 13:46:39 -07:00
Jeff Law 1b9c218d14 gcc: introduce the dep_fusion pass
>> +
>> +  // opt_pass methods:
>> +  opt_pass *clone () override { return new pass_dep_fusion (m_ctxt); }
>> +  bool gate (function *) override;
>> +  unsigned int execute (function *) override;
>
> Wouldn't it be better to add 'final' along with 'override' to opt_pass
> vfuncs?
> (See commit 725793af78, etc.)Yea.  It's easily missed.  Fixed in the obvious way.

Bootstrapped and regression tested on x86_64.  Pushed to the trunk.

gcc/
	* dep-fusion.cc: Mark clone, gate and execute methods as final.
2025-09-07 12:28:23 -06:00
Kuan-Lin Chen c4d5383b1d RISC-V: Add support for the XAndesvdot ISA extension.
This extension defines vector instructions to calculae of the signed/unsigned
dot product of four SEW/4-bit data and accumulate the result into a SEWbit
element for all elements in a vector register.

gcc/ChangeLog:

	* config/riscv/andes-vector-builtins-bases.cc (nds_vd4dot): New class.
	(class nds_vd4dotsu): New class.
	* config/riscv/andes-vector-builtins-bases.h: New def.
	* config/riscv/andes-vector-builtins-functions.def (nds_vd4dots): Ditto.
	(nds_vd4dotsu): Ditto.
	(nds_vd4dotu): Ditto.
	* config/riscv/andes-vector.md
	(@pred_nds_vd4dot<su><mode>): New pattern.
	(@pred_nds_vd4dotsu<mode>): New pattern.
	* config/riscv/genrvv-type-indexer.cc (main): Modify sew of QUAD_FIX,
	QUAD_FIX_SIGNED and QUAD_FIX_UNSIGNED.
	* config/riscv/riscv-vector-builtins.cc
	(qexti_vvvv_ops): New operand information.
	(qexti_su_vvvv_ops): New operand information.
	(qextu_vvvv_ops): New operand information.
	* config/riscv/riscv-vector-builtins.h (XANDESVDOT_EXT): New def.
	(required_ext_to_isa_name): Add case XANDESVDOT_EXT.
	(required_extensions_specified): Ditto.
	(struct function_group_info): Ditto.
	* config/riscv/vector-iterators.md (NDS_QUAD_FIX): New iterator.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vd4dots.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vd4dotsu.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vd4dotu.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vd4dots.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vd4dotsu.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vd4dotu.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vd4dots.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vd4dotsu.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vd4dotu.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vd4dots.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vd4dotsu.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vd4dotu.c: New test.
2025-09-07 12:17:27 -06:00
Jeff Law 2b7afb69ab [RISC-V] Fix ordering of pipeline models
I missed that the new ascalon pipeline description was put into the wrong place
during review.  The net is tests which wanted to use generic-ooo explicitly for
stability in the test output ended up getting  a different pipeline model and
different codegen than the test expected.

This tripped a small number of vsetvl failures in the testsuite.

This has spun on riscv64-elf and riscv32-elf in my tester and fixes the
regression.  I'm going to go ahead and push it as I'm likely offline this
afternoon/evening and don't want anyone else to waste their time chasing the
regression down.

gcc/
	* config/riscv/riscv-opts.h (riscv_microarchitecture_type): Fix ordering.
2025-09-07 12:11:55 -06:00
Sam James 35cf8d8584 libphobos: enable for more hppa tuples
Gentoo uses hppa1.1*-*-linux* and hppa2.0*-*-linux* instead of Debian's
hppa-*-linux*.

libphobos/ChangeLog:

	* configure.tgt: Add hppa[12]*-*-linux* as a supported target.
2025-09-07 18:04:19 +01:00
Kuan-Lin Chen d21713b3bc RISC-V: Add support for the XAndesvpackfph ISA extension.
This extension defines vector instructions to extract a pair of FP16 data from
a floating-point register. Multiply the top FP16 data with the FP16 elements
and add the result with the bottom FP16 data.

gcc/ChangeLog:

	* common/config/riscv/riscv-common.cc:
	Turn on VECTOR_ELEN_FP_16 for XAndesvpackfph.
	* config/riscv/andes-vector-builtins-bases.cc (nds_vfpmad): New class.
	* config/riscv/andes-vector-builtins-bases.h: New def.
	* config/riscv/andes-vector-builtins-functions.def (nds_vfpmadt): Ditto.
	(nds_vfpmadb): Ditto.
	(nds_vfpmadt_frm): Ditto.
	(nds_vfpmadb_frm): Ditto.
	* config/riscv/andes-vector.md (@pred_nds_vfpmad<nds_tb><mode>):
	New pattern.
	* config/riscv/riscv-vector-builtins-types.def
	(DEF_RVV_F16_OPS): New def.
	* config/riscv/riscv-vector-builtins.cc (f16_ops): Ditto
	* config/riscv/riscv-vector-builtins.def (float32_type_node): Ditto.
	* config/riscv/riscv-vector-builtins.h (XANDESVPACKFPH_EXT): Ditto.
	(required_ext_to_isa_name): Add case XANDESVPACKFPH_EXT.
	(required_extensions_specified): Ditto.
	* config/riscv/vector-iterators.md (VHF): New iterator.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfpmadb.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfpmadt.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfpmadb.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfpmadt.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfpmadb.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfpmadt.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfpmadb.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfpmadt.c: New test.
2025-09-07 09:42:42 -06:00
H.J. Lu a0344144db c++: Update TLS model after processing a TLS variable
Set a tentative TLS model in grokvardecl and update TLS mode with the
default TLS access model after a TLS variable has been fully processed
if the default TLS access model is stronger.

gcc/cp/

	PR c++/107393
	* decl.cc (grokvardecl): Set a tentative TLS model which will be
	updated by cplus_decl_attributes later.
	* decl2.cc (cplus_decl_attributes): Update TLS model with the
	default TLS access model if the default TLS access model is
	stronger.
	* pt.cc (tsubst_decl): Set TLS model only after processing a
	variable.

gcc/testsuite/

	PR c++/107393
	* g++.dg/tls/pr107393-1.C: New test.
	* g++.dg/tls/pr107393-2.C: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-07 07:02:58 -07:00
Georg-Johann Lay 93af5f69d1 AVR: ad target/121794 - Invoke zero_reg less.
gcc/
	PR target/121794
	* config/avr/avr.md (cmpqi3): Use cpi R,0 if possible.
2025-09-07 12:37:08 +02:00
Matthias Klose cd404684a9 libphobos: enable for powerpc64le-linux-gnu
libphobos/ChangeLog:

	* configure.tgt: Add powerpc64le-linux-gnu as a supported target
	when configured with --with-long-double-format=ieee.
2025-09-07 10:41:09 +02:00
Pan Li 409a3c2a35 RISC-V: Add test for vec_duplicate + vnmsub.vv unsigned combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vnmsub.vvm
combine to vnmsub.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
	for vnmsub.vx.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsub-run-1-u16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsub-run-1-u32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsub-run-1-u64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsub-run-1-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-07 15:53:35 +08:00
Pan Li 85ff9207c4 RISC-V: Add test for vec_duplicate + vnmsub.vv signed combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vnmsub.vv
combine to vnmsub.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c: Add asm check
	for vnmsub.vx.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary.h: Add test
	helper macros.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary_data.h: Add test
	data for run test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsub-run-1-i16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsub-run-1-i32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsub-run-1-i64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsub-run-1-i8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-07 15:53:35 +08:00
Pan Li 7c2c5ac9c7 RISC-V: Combine vec_duplicate + vnmsub.vv to vnmsub.vx on GR2VR cost
This patch would like to combine the vec_duplicate + vnmsub.vv to the
vnmsub.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

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

Before this patch:
  11   │     beq a3,zero,.L8
  12   │     vsetvli a5,zero,e32,m1,ta,ma
  13   │     vmv.v.x v2,a2
  ...
  16   │ .L3:
  17   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  22   │     vnmsub.vv v1,v2,v3
  ...
  25   │     bne a3,zero,.L3

After this patch:
  11   │     beq a3,zero,.L8
  ...
  14   │ .L3:
  15   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  20   │     vnmsub.vx v1,a2,v3
  ...
  23   │     bne a3,zero,.L3

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vnmsac_vx_<mode>): Rename from.
	(*mul_minus_vx_<mode>): Rename to and add nmsub support.
	* config/riscv/vector.md (@pred_vnmsac_vx_<mode>): Rename from.
	(@pred_mul_minus_vx_<mode>): Rename to and add nmsub support.
	(*pred_nmsac_<mode>_scalar_undef): Rename from.
	(*pred_mul_minus_vx<mode>_undef): Rename to and add nmsub support.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-07 15:53:35 +08:00
GCC Administrator 3b7f0be2d5 Daily bump. 2025-09-07 00:20:16 +00:00
Sam James 634d9f9986 doc: drop verify-canonical-types=1 ref
--param verify-canonical-types was removed back in r0-81986-g7313518b90b280.

The same verification is controlled via our generic checking framework
these days.

gcc/ChangeLog:

	* doc/generic.texi (TYPE_CANONICAL): Don't mention long-removed
	--param verify-canonical-types.
2025-09-07 00:20:31 +01:00
Andrew Pinski 7b8c45d48f dep_fusion: Fix if target does not have macro fusion [PR121835]
This new pass will ICE if the target does not define the macro_fusion_pair_p
pass. The pass will not be useful in that case so it is best to return
early.

Pushed as obvious after a bootstrap on x86_64-linux-gnu.

	PR rtl-optimization/121835
gcc/ChangeLog:

	* dep-fusion.cc (pass_dep_fusion::execute): Return early if
	macro_fusion_pair_p is null.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-06 15:29:16 -07:00
Artemiy Volkov 41b0c7a674 gcc: introduce the dep_fusion pass
Presently, the scheduler code only considers consecutive instructions
for macro-op fusion (see sched-deps.cc::sched_macro_fuse_insns () for
details).  This patch introduces the new dep_fusion pass, which is
intended to uncover more fusion opportunities by reordering eligible
instructions to form fusible pairs (based solely on the value of the
TARGET_SCHED_MACRO_FUSION_PAIR_P hook).  This is achieved by using
the RTL-SSA framework, and only the single-use instructions are
considered for the first instruction of a pair.

Aside from reordering instructions, this pass also sets the SCHED_GROUP
flag for the second instruction so that following passes can implement
special handling of the fused pairs.  For instance, RA and regrename
should make use of this information to preserve single-output property
for some of such pairs.  Accordingly, in passes.def, this patch adds two
invocations of the new pass: just before IRA and just before regrename.

The new pass is enabled at -O2+ and -Os.

gcc/ChangeLog:

	* Makefile.in (OBJS): Add dep-fusion.o.
	* common.opt (fdep-fusion): Add option.
	* dep-fusion.cc: New pass.
	* doc/invoke.texi: Document it.
	* opts.cc (default_options_table): Enable it at -O2+ and -Os.
	* passes.def: Insert two instances of dep_fusion.
	* tree-pass.h (make_pass_dep_fusion): Declare new function.
2025-09-06 15:07:27 -06:00
Sam James 044d828724 doc: fix -momit-leaf-frame-pointer typo
For x86, the option is -momit-leaf-frame-pointer, not -fomit-leaf-frame-pointer.

gcc/ChangeLog:

	* doc/invoke.texi (x86 Options): Fix '-momit-leaf-frame-pointer' typo.
2025-09-06 21:40:02 +01:00
Andrew Pinski 8d381528c7 forwprop: Factor out the memcpy followed by memset optimization
As simplify_builtin_call adds more and more optimization, it is
getting bigger and bigger and easier to misunderstand, so this
factors out the memcpy followed by memset optimization (which
was the original optimization added).

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (simplify_builtin_call): Factor out
	the memcpy followed by a memset optimization to ...
	(simplify_builtin_memcpy_memset): Here. New function.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-06 13:19:57 -07:00
Andrew Pinski ffc25308ac forwprop: Factor out memchr optimization to its own function
As more optimizations are added to forwprop's simplify_builtin_call,
this function is becoming harder and harder to understand. To help
simplify things, this factors out the memchr optimization to its own
function like what was done when memcmp optimization was added.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (simplify_builtin_call): Factor out the memchr
	optimization to ...
	(simplify_builtin_memchr): Here. New function.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-06 13:19:56 -07:00
Simon Martin 8ab5b7f590 ipa: Fix build on MacOS
The build is broken on MacOS since r16-3581-g1da3c4d90e678a because
ipa-inline-transform.cc uses std::max but does not include <algorithm>.

This patch fixes it by defining INCLUDE_ALGORITHM in that file.

gcc/ChangeLog:

	* ipa-inline-transform.cc: Define INCLUDE_ALGORITHM.
2025-09-06 22:12:41 +02:00
Gerald Pfeifer 23f659f61e install: Properly capitalize GNU Binutils
gcc:
	PR target/69374
	* doc/install.texi (Prerequisites): Properly capitalize
	GNU Binutils.
	(Configuration): Ditto.
	(Building): Ditto.
	(Specific): Ditto.
2025-09-06 21:55:06 +02:00
Sam James 99e8a24084 doc: consistently say 'whole-program' where appropriate
Unchanged instances are deliberate.

gcc/ChangeLog:

	* doc/invoke.texi: Say 'whole-program' consistently where
	appropriate.
2025-09-06 19:41:05 +01:00
Sam James 57e7176e9a doc: consistently spell 'GNU Binutils'
gcc/ChangeLog:

	* doc/invoke.texi: Capitalize 'GNU Binutils' consistently.
2025-09-06 19:41:04 +01:00
Sam James a2a4a6c057 doc: update incremental link vs binutils information
GNU Binutils now supports linking LTO and non-LTO objects into a single
mixed object file as of 2.44. Update the text to reflect this and fix
some minor grammar issues while at it.

gcc/ChangeLog:
	PR ipa/116410

	* doc/invoke.texi (Link Options): Update -flinker-output= text
	to reflect GNU Binutils changes. Fix grammar.
2025-09-06 19:41:03 +01:00
Kuan-Lin Chen e9a7140993 RISC-V: Add support for the XAndesvsintload ISA extension.
This extension defines vector load instructions to move sign-extended or
zero-extended INT4 data into 8-bit vector register elements.

gcc/ChangeLog:

	* config/riscv/andes-vector-builtins-bases.cc
	(nds_nibbleload): New class.
	* config/riscv/andes-vector-builtins-bases.h (nds_vln8): New def.
	(nds_vlnu8): Ditto.
	* config/riscv/andes-vector-builtins-functions.def (nds_vln8): Ditto.
	(nds_vlnu8): Ditto.
	* config/riscv/andes-vector.md (@pred_intload_mov<su><mode>): New pattern.
	* config/riscv/riscv-vector-builtins-types.def (DEF_RVV_Q_OPS): New def.
	(DEF_RVV_QU_OPS): Ditto.
	* config/riscv/riscv-vector-builtins.cc
	(q_v_void_const_ptr_ops): New operand information.
	(qu_v_void_const_ptr_ops): Ditto.
	* config/riscv/riscv-vector-builtins.def (void_const_ptr): New def.
	* config/riscv/riscv-vector-builtins.h (enum required_ext): Ditto.
	(required_ext_to_isa_name): Add case XANDESVSINTLOAD_EXT.
	(required_extensions_specified): Ditto.
	* config/riscv/vector-iterators.md (NDS_QVI): New iterator.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vln8.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vln8.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vln8.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vln8.c: New test.
2025-09-06 12:34:28 -06:00
Kuan-Lin Chen 726006cd69 RISC-V: Add support for the XAndesvbfhcvt ISA extension.
This patch add support for XAndesvbfhcvt ISA extension.
This extension defines instructions to perform vector floating-point
conversion between the BFLOAT16 floating-point data and the IEEE-754 32-bit
single-precision floating-point (SP) data in a vector register.

gcc/ChangeLog:

	* common/config/riscv/riscv-common.cc:
	Turn on VECTOR_ELEN_BF_16 for XAndesvbfhcvt.
	* config.gcc: Add extra_objs andes-vector-builtins-bases.o
	and extra_headers andes_vector.h.
	* config/riscv/riscv-vector-builtins-shapes.cc
	(BASE_NAME_MAX_LEN): Increase size to 20.
	* config/riscv/riscv-vector-builtins.cc
	(f32_to_bf16_nf_w_ops): New operand information.
	(f32_to_bf16_nf_w_ops): New operand information.
	(DEF_RVV_FUNCTION): New def.
	* config/riscv/riscv-vector-builtins.def (bf16): Ditto.
	* config/riscv/riscv-vector-builtins.h (enum required_ext): Ditto.
	(required_ext_to_isa_name): Add case XANDESVBFHCVT_EXT.
	(required_extensions_specified): Ditto.
	* config/riscv/t-riscv: Add andes-vector-builtins-functions.def,
	andes-vector-builtins-bases.h and andes-vector-builtins-bases.o.
	* config/riscv/vector-iterators.md (NDS_VWEXTBF): New iterator.
	(NDS_V_DOUBLE_TRUNC_BF): New attr.
	* config/riscv/andes-vector-builtins-bases.cc: New file.
	* config/riscv/andes-vector-builtins-bases.h: New file.
	* config/riscv/andes-vector-builtins-functions.def: New file.
	* config/riscv/andes_vector.h: New file.
	* config/riscv/andes-vector.md: New file.
	* config/riscv/vector.md: Include andes_vector.md.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/rvv.exp: Add regression for xandesvector.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfncvtbf16s.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/non-overloaded/nds_vfwcvtsbf16.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfncvtbf16s.c: New test.
	* gcc.target/riscv/rvv/xandesvector/non-policy/overloaded/nds_vfwcvtsbf16.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfncvtbf16s.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/non-overloaded/nds_vfwcvtsbf16.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfncvtbf16s.c: New test.
	* gcc.target/riscv/rvv/xandesvector/policy/overloaded/nds_vfwcvtsbf16.c: New test.
2025-09-06 12:31:01 -06:00
Anton Blanchard 1ac463fc89 RISC-V: Add tt-ascalon-d8 pipeline description
Add pipeline description for the Tenstorrent Ascalon 8 wide CPU.

gcc/ChangeLog
	* config/riscv/riscv-cores.def (RISCV_TUNE): Update.
	* config/riscv/riscv-opts.h (enum riscv_microarchitecture_type):
	Add tt_ascalon_d8.
	* config/riscv/riscv.md: Update tune attribute and include
	tt-ascalon-d8.md.
	* config/riscv/tt-ascalon-d8.md: New file.
2025-09-06 11:21:06 -06:00
Paul Thomas 3d2783673d Fortran: Implement correct form of PDT constructors [PR84119]
2025-09-06  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/84119
	* resolve.cc (reset_array_ref_to_scalar): New function using
	chunk broken out from gfc_resolve_ref.
	(gfc_resolve_ref): Call the new function, the first time for
	PDT type parameters and the second time for LEN inquiry refs.

gcc/testsuite/
	PR fortran/84119
	* gfortran.dg/pdt_20.f03: Modify to deal with scalar type parm.
2025-09-06 17:39:25 +01:00
Andrew Pinski 8bd31f9248 phiopt: Improve locations for factor out conditional operation [PR108466]
This improves the locations for the phi args and the newly created statement.
Since this is a factorization/commonizing in one case the location for the new
statement will not always be set correctly either way.
The new locations on the new phi will either be the old location of the argument
to the phi or the location of the defining statement (if it exists).
The new statement will be either the location of the phi or the location
of the defining statements if the location of the phi is unknown.

This fixes the location of an uninitialized variable warning too.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/108466
gcc/ChangeLog:

	* tree-ssa-phiopt.cc (factor_out_conditional_operation): Give better
	locations to the new phi args and the new statement.

gcc/testsuite/ChangeLog:

	* gcc.dg/uninit-pr108466-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-06 09:19:00 -07:00
Jeff Law 477868c59e [RISC-V] Adjust recently added test
The recently added zbb-sext test includes stdint.h and explicitly asks for the
lp64 abi (not lp64d!).

This will fail on a native riscv system as the system headers don't support
lp64 -- they assume "d" is included.

It looks like most tests are including stdint-gcc instead of stdint.  Not a fan
of that, but it seems to be how we've been handling this kind of issue to-date.

gcc/testsuite
	* gcc.target/riscv/zbb-sext.c: Include stdint-gcc.h instead of
	stdint.h.
2025-09-06 08:34:03 -06:00
Nathaniel Shead 014873fdf4 c++/modules: Fix exported using-directive of imported namespace [PR121702]
Currently we represent exported using-directives as a list of indices
into the namespace array that we stream.  However this list of
namespaces doesn't include any namespaces that we don't expose in this
module's purview, and so we ICE.

This patch reworks the handling to instead use the existing depset
tracking for namespaces directly.  This means that we don't need to
build up a second lookup map when streaming, and we can reuse the logic
in {read,write}_namespace.  We do need to make sure that we create a
depset for namespaces only referenced by a using-directive, though.

I don't expect to be exporting large numbers of using-directives from a
namespace, so for simplicity we stream the names as {parent, target}
pairs.

This also adjusts read handling so that we load the using-directives for
any import (including indirect) if it's in the import list for the
current TU.  Otherwise we run into issues if the using-directive is in
a namespace that is otherwise never referenced in the 'export import'ing
module, because we never walk this namespace and so never know that we
need to emit it.  To do this the patch ensures that we calculate the
import list before read_language is called.

As a drive-by fix, I noticed that with modules 'add_using_namespace'
will add duplicate using-directives because we compare usings against
the target namespace, but we then push a wrapping USING_DECL instead.
This reworks so that the contents of the structure is equivalent between
modules and non-modules code.

	PR c++/121702

gcc/cp/ChangeLog:

	* module.cc (enum module_state_counts): New counter.
	(depset::hash::add_namespace_entities): Seed using-directive
	targets for later streaming.
	(module_state::write_namespaces): Don't handle using-directives
	here.
	(module_state::read_namespaces): Likewise.
	(module_state::write_using_directives): New function.
	(module_state::read_using_directives): New function.
	(module_state::write_counts): Log using-directives.
	(module_state::read_counts): Likewise.
	(module_state::write_begin): Stream using-directives.
	(module_state::read_language): Read using-directives if
	directly importing.
	(module_state::direct_import): Update current TU import list
	before calling read_language.
	* name-lookup.cc (add_using_namespace): Fix lookup of previous
	using-directives.
	* parser.cc (cp_parser_import_declaration): Don't set
	MK_EXPORTING when performing import_module.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/namespace-10_c.C: Add check for log dump.
	* g++.dg/modules/namespace-13_a.C: New test.
	* g++.dg/modules/namespace-13_b.C: New test.
	* g++.dg/modules/namespace-13_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-09-06 22:00:39 +10:00
Nathaniel Shead c39dbb652f c++/modules: Support ADL on non-discarded GM entities [PR121705]
[basic.lookup.argdep] p4 says that ADL also finds declarations of
functions or function templates from a point of lookup within the
module, only ignoring discarded (or internal) GM entities.

To implement this we need to create bindings for these entities so that
we can guarantee that name lookup will discover they exist.  This raises
some complications, though, as we ideally would like to avoid having
bindings that contain no declarations, or emitting GM namespaces that
only contain discarded or internal functions.

This patch does this by additionally creating a new binding whenever we
call make_dependency on a non-EK_FOR_BINDING decl.  We don't do this for
using-decls, as at the point of use of a GM entity we no longer know
whether we called through a using-decl or the declaration directly;
however, this behaviour is explicitly supported by [module.global.frag]
p3.6.

Creating these bindings caused g++.dg/modules/default-arg-4_* to fail.
It turns out that this makes the behaviour look identical to
g++.dg/modules/default-arg-5, which is incorrectly dg-error-ing default
value redeclarations (we only currently error because of PR c++/99000).
This patch removes the otherwise identical test and turns the dg-errors
into xfailed dg-bogus.

As a drive-by fix this also fixes an ICE when debug printing friend
function instantiations.

	PR c++/121705
	PR c++/117658

gcc/cp/ChangeLog:

	* module.cc (depset::hash::make_dependency): Make bindings for
	GM functions.
	(depset::hash::add_binding_entity): Adjust comment.
	(depset::hash::add_deduction_guides): Add log.
	* ptree.cc (cxx_print_xnode): Handle friend functions where
	TI_TEMPLATE is an OVERLOAD or IDENTIFIER.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/default-arg-4_a.C: XFAIL bogus errors.
	* g++.dg/modules/default-arg-4_b.C: Likewise.
	* g++.dg/modules/default-arg-5_a.C: Remove duplicate test.
	* g++.dg/modules/default-arg-5_b.C: Likewise.
	* g++.dg/modules/adl-9_a.C: New test.
	* g++.dg/modules/adl-9_b.C: New test.
	* g++.dg/modules/gmf-5.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-09-06 20:38:14 +10:00
Jakub Jelinek db7a807ef2 libgomp: Use consistent formatting in <omp.h>
I've noticed the new C++ part of omp.h uses libstdc++ coding conventions,
while the rest of the header (and libgomp) is formatted using the normal
gcc coding conventions like gcc/.

This patch makes it consistent.

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

	* omp.h.in: Fix up formatting of __cplusplus >= 201103L
	guarded code from libstc++ style to GCC/libgomp style.
2025-09-06 12:24:31 +02:00
GCC Administrator 1179ac1fab Daily bump. 2025-09-06 00:20:34 +00:00
Sam James 070e691dc0 gcc: PR121757 test needs LTO effective target
gcc/testsuite/ChangeLog:
	PR rtl-optimization/121757

	* g++.dg/pr121757.C: Add dg-require-effective-target for lto.
2025-09-05 23:18:22 +01:00
Andre Vehreschild 6b008944e7 Fix uninitialized variable in frontend [PR121806]
gcc/ChangeLog:
	PR middle-end/121806
	* gcc.cc (for_each_path): Initialize return value.
2025-09-05 23:01:48 +01:00
Robin Dapp a6bf07653c RISC-V: Check if we can vec_extract [PR121510].
For Zvfhmin a vector mode exists but the corresponding vec_extract does
not.  This patch checks that a vec_extract is available and otherwise
falls back to standard handling.

	PR target/121510

gcc/ChangeLog:

	* config/riscv/riscv.cc (riscv_legitimize_move): Check if we can
	vec_extract.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/pr121510.c: New test.
2025-09-05 22:25:25 +02:00
Jakub Jelinek 41ea930546 c: Allow translations of a lot of C FE messages
I've noticed a lot of diagnostic messages in the C FE aren't marked
for translation.
The reason is some weird coding style which wraps the string
literals into (), especially when they don't fit on a single line.
With that fixed, there were 83 unique similar messages
"both %<something%> and %<something%> in declaration specifiers"
marked for translation, which is very unfriendly to translators,
the patch brings that down to 4 (if it was ok to change order,
it could be even 3):
msgid "both %qs and %qs in declaration specifiers"
msgid "both %qs and %<__int%d%> in declaration specifiers"
msgid "both %qs and %<_Float%d%s%> in declaration specifiers"
msgid "both %<__int%d%> and %qs in declaration specifiers"

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

	* c-decl.cc (pushtag): Remove ()s around string literal
	in call to diagnostic function.
	(diagnose_mismatched_decls): Likewise.
	(c_check_switch_jump_warnings): Likewise.
	(grokdeclarator): Likewise.
	(warn_cxx_compat_finish_struct): Likewise.
	(build_enumerator): Formatting fix.
	(declspecs_add_type): Remove ()s around string literal
	in call to diagnostic function, simplify
	"both %<something%> and %<something%>" starting format
	strings to "both %qs and %qs" with appropriate arguments.
	Formatting fixes.
	* c-typeck.cc (build_external_ref): Remove ()s around string
	literal in call to diagnostic function.
	(build_conditional_expr): Likewise.
	* c-parser.cc (c_parser_transaction): Use G_() around string
	literals.  Formatting fix.
	(c_parser_transaction_expression): Likewise.
2025-09-05 20:03:09 +02:00
Richard Sandiford 168cdfd137 rtl-ssa: Maintain clobber_group invariant [PR121757]
In order to reduce time complexity, rtl-ssa groups consecutive
clobbers together.  Each group of clobbers has a splay tree for
lookup and manipulation purposes.

This arrangement means that we might need to split a group (when
inserting a new non-clobber definition between two clobbers) or
to join consecutive groups together (when deleting an intervening
non-clobber definition).  To reduce the time complexity of these updates,
the back pointer from a clobber to its group is only updated lazily.
The invariant is supposed to be that the first clobber, last clobber,
and splay tree root have the right group at all times, whereas other
members of the group can have identifiably stale group pointers.

However, a lack of abstraction meant that only some splay tree lookups
correctly maintained this invariant.  Others did not update the group
pointer after installing a new root.

This patch adds a helper that maintains the invariant and uses it in
three places, one that was already correct and two that were wrong.
The original lookup_clobber is still used in other code that
manipulates groups as a whole.

gcc/
	PR rtl-optimization/121757
	* rtl-ssa/accesses.h (clobber_group::lookup_clobber): New member
	function.
	* rtl-ssa/accesses.cc (clobber_group::lookup_clobber): Likewise.
	(clobber_group::prev_clobber, clobber_group::next_clobber)
	(function_info::add_clobber): Use it.

gcc/testsuite/
	PR rtl-optimization/121757
	* g++.dg/pr121757.C: New test.
2025-09-05 18:38:13 +01:00
Patrick Palka 8e971d665a libstdc++: Make join_view::_Iterator::_M_get_inner noexcept [PR121804]
Since this helper (added in r16-3576-g7f7f1878eedd80) is used in the
noexcept-spec of iter_move and iter_swap, it in turn needs an accurate
noexcept-spec.

	PR libstdc++/121804

libstdc++-v3/ChangeLog:

	* include/std/ranges (join_view::_Iterator::_M_get_inner):
	Mark noexcept.
	* testsuite/std/ranges/adaptors/join.cc (test16): New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-09-05 13:14:16 -04:00
Robert Dubner dc20fa683d cobol: Improved handling of COBOL Special Registers.
COBOL Special Registers (e.g., RETURN-CODE; DEBUG-ITEM) are implemented as
global variables.  These changes define them with the prefix "__ggsr__" in
their variable names so that the GDB-COBOL debugger can identify them.

The creation and handling of such variables has been streamlined with the
introduction of the "register_e" cbl_field_t::attr bit.

gcc/cobol/ChangeLog:

	* genapi.cc (trace1_init): Prepend two internal variables with
	underscore.
	(initialize_variable_internal): Use new register_e attribute.
	(psa_global): Use "__ggsr__" prefix to identify special registers
	(parser_symbol_add): Use new register_e attribute.
	* symbols.cc (cbl_field_attr_str): Likewise.
	(symbol_table_init): Likewise.
	(is_register_field): Eliminated in favor of (attr & register_e).
	* symbols.h (is_register_field): Likewise.

libgcobol/ChangeLog:

	* common-defs.h (enum cbl_field_attr_t): Define register_e.
	* constants.cc (struct cblc_field_t): Define special registers with
	"__ggsr__" prefix.
2025-09-05 11:08:27 -04:00
Tomasz Kamiński 39d7c4d42a libstdc++: Document remaining C++17 implementation-defined behavior.
This also covers bad_function_call::what from C++11.

libstdc++-v3/ChangeLog:

	* doc/html/manual/status.html: Regenerate.
	* doc/xml/manual/status_cxx2011.xml: Add entry for bad_function_call.
	* doc/xml/manual/status_cxx2017.xml: Add entries for bad_any_cast
	and nullptr_t output. Update entry for sf.cmath. Fix stable name for
	mem.res.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-05 16:54:10 +02:00
Georg-Johann Lay 052c1d8284 testsuite: Fix gcc.dg/torture/pr121695-1.c
This test case fails on int < 32-bit platforms obviously.
This patch undoes the macro expansion from stdint.h.

gcc/testsuite/
	PR testsuite/121695
	PR testsuite/52641
	* gcc.dg/torture/pr121695-1.c: int -> int32_t etc.
2025-09-05 15:56:21 +02:00
Tomasz Kamiński d6c370b8e9 libstdc++: Document missing implementation defined behavior for std::filesystem.
libstdc++-v3/ChangeLog:

	* doc/html/manual/status.html: Regenerate the file.
	* doc/xml/manual/status_cxx2017.xml: Addd more entires.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-05 14:50:42 +02:00
Georg-Johann Lay e3d14112b2 AVR: target/121794 - Invoke zero_reg less.
There are some cases where involing zero_reg is not needed and
where there are other sequences with the same efficiency.
An example is to use SBCI R,0 instead of SBC R,__zero_reg__
when R >= R16.  This may turn out to be better for small ISRs.

	PR target/121794
gcc/
	* config/avr/avr.cc (avr_out_compare): Only use zero_reg
	when there is no other sequence of the same length.
	(avr_out_plus_ext): Same.
	(avr_out_plus_1): Same.
2025-09-05 14:38:31 +02:00
Richard Biener 2965a67c7e Avoid costing vector stmts with count == 0
This avoids confusing the backends.

	* tree-vect-slp.cc (vectorizable_bb_reduc_epilogue): Do not
	cost zero remaining scalar stmts.
	(vectorizable_slp_permutation): Do not cost zero actual
	permutations.
	* tree-vect-stmts.cc (vectorizable_load): Likewise.
2025-09-05 13:11:39 +02:00
Richard Biener dad6f6eb9b tree-optimization/121802 - fix vect_setup_realignment
The following avoids looking at STMT_VINFO_VECTYPE in
vect_setup_realignment and instead passes down the relevant vector
type.

	PR tree-optimization/121802
	* tree-vectorizer.h (vect_setup_realignment): Add vectype
	argument.
	* tree-vect-data-refs.cc (vect_setup_realignment): Replace
	local vectype with argument.
	* tree-vect-stmts.cc (vectorizable_load): Adjust.
2025-09-05 12:35:00 +02:00
Jakub Jelinek 911ec2e09b c++: Fix cxx_eval_cxa_builtin_fn diagnostic message
Marek Polacek reported to me internally that I've messed up one diagnostic
message in this function, with one word before final double quote on one
line and another word right after opening double quote on the next line,
with no space in between.

Fixed thusly.

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

	* constexpr.cc (cxx_eval_cxa_builtin_fn): Add missing word separating
	space into invalid_nargs diagnostics.
2025-09-05 11:55:01 +02:00
Jakub Jelinek 4c08331595 testsuite: Fix up fixed-point/bitint-1.c test
This test was written without _BitInt support on any target with
fixed-point support as well, so was actually never tested.

Now that it can be tested on loongarch64-linux, there is a missing
expected error, so this patch adds it.

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

	* gcc.dg/fixed-point/bitint-1.c: Expect also error about _Sat used
	without _Fract/_Accum.
2025-09-05 11:52:13 +02:00
Jakub Jelinek 99e76f7ef4 Remove file that shouldn't have been committed.
2025-09-05  Jakub Jelinek  <jakub@redhat.com>

	* J: Remove.
2025-09-05 11:29:35 +02:00
Jakub Jelinek 8d8b6249d8 testsuite, powerpc, v2: Fix vsx-vectorize-* after alignment peeling [PR118567]
On Tue, Jul 01, 2025 at 02:50:40PM -0500, Segher Boessenkool wrote:
> No tests become good tests without effort.  And tests that are not good
> tests require constant maintenance!

Here are two patches, either just the first one or both can be used
and both were tested on powerpc64le-linux.

The second one adds further 8 tests, which are dg-do run which #include
the former tests, don't do any dump tests and just define the checking/main
for those.

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

	PR testsuite/118567
	* gcc.target/powerpc/vsx-vectorize-9.c: New test.
	* gcc.target/powerpc/vsx-vectorize-10.c: New test.
	* gcc.target/powerpc/vsx-vectorize-11.c: New test.
	* gcc.target/powerpc/vsx-vectorize-12.c: New test.
	* gcc.target/powerpc/vsx-vectorize-13.c: New test.
	* gcc.target/powerpc/vsx-vectorize-14.c: New test.
	* gcc.target/powerpc/vsx-vectorize-15.c: New test.
	* gcc.target/powerpc/vsx-vectorize-16.c: New test.
2025-09-05 10:59:42 +02:00
Jakub Jelinek 193b286499 testsuite, powerpc, v2: Fix vsx-vectorize-* after alignment peeling [PR118567]
On Tue, Jul 01, 2025 at 02:50:40PM -0500, Segher Boessenkool wrote:
> No tests become good tests without effort.  And tests that are not good
> tests require constant maintenance!

Here are two patches, either just the first one or both can be used
and both were tested on powerpc64le-linux.

The first one removes all the checking etc. stuff from the testcases,
as they are just dg-do compile, for the vectorize dump checks all we
care about are the vectorized loops they want to test.

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

	PR testsuite/118567
	* gcc.target/powerpc/vsx-vectorize-1.c: Remove includes, checking
	part of main1 and main.
	* gcc.target/powerpc/vsx-vectorize-2.c: Remove includes, replace
	bar definition with declaration, remove main.
	* gcc.target/powerpc/vsx-vectorize-3.c: Likewise.
	* gcc.target/powerpc/vsx-vectorize-4.c: Likewise.
	* gcc.target/powerpc/vsx-vectorize-5.c: Likewise.
	* gcc.target/powerpc/vsx-vectorize-6.c: Likewise.
	* gcc.target/powerpc/vsx-vectorize-7.c: Likewise.
	* gcc.target/powerpc/vsx-vectorize-8.c: Likewise.
2025-09-05 10:54:53 +02:00
Kyrylo Tkachov ed9612bad7 aarch64: Use SVE for V2DImode integer min/max operations
Unlike Advanced SIMD, SVE has instruction to perform smin, smax, umin, umax
on 64-bit elements.  Thus, we can use them with the fixed-width V2DImode
expander.  Most of the machinery is already there on the define_insn side,
supporting V2DImode operands of the SVE pattern.  We just need to wire up
the RTL emission to the v2di standard names for the TARGET_SVE case.

So for the smin case we now generate:
min_di:
        ldr     q30, [x0]
        ptrue   p7.b, all
        ldr     q31, [x1]
        smin    z30.d, p7/m, z30.d, z31.d
        str     q30, [x2]
        ret

min_imm_di:
        ldr     q31, [x0]
        smin    z31.d, z31.d, #5
        str     q31, [x2]
        ret

instead of the previous:
min_di:
        ldr     q30, [x0]
        ldr     q31, [x1]
        cmgt    v29.2d, v30.2d, v31.2d
        bsl     v29.16b, v31.16b, v30.16b
        str     q29, [x2]
        ret

min_imm_di:
        ldr     q31, [x0]
        mov     z30.d, #5
        cmgt    v29.2d, v30.2d, v31.2d
        bsl     v29.16b, v31.16b, v30.16b
        str     q29, [x2]
        ret

The register operand case is the same length, though the new ptrue can now be
shared and moved away.  But the immediate operand case is obviously better
as the SVE immediate form doesn't require a predicate operand.

Bootstrapped and tested on aarch64-none-linux-gnu.

Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com>

gcc/

	* config/aarch64/iterators.md (sve_di_suf): New mode attribute.
	* config/aarch64/aarch64-sve.md (<optab><mode>3 SVE_INT_BINARY_MULTI):
	Rename to...
	(<optab><mode>3<sve_di_suf>): ... This.  Use SVE_I_SIMD_DI mode
	iterator.
	* config/aarch64/aarch64-simd.md (<su><maxmin>v2di3): Use the above
	for TARGET_SVE.

gcc/testsuite/

	* gcc.target/aarch64/sve/usminmax_di.c: New test.
2025-09-05 10:49:22 +02:00
Paul Thomas 6b6a2d461b Fortran: Check PDT parameters are of integer type [PR84432, PR114815]
2025-09-04  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/84432
	PR fortran/114815
	* expr.cc (gfc_check_assign_symbol): Check that components in a
	PDT with a default initializer have type and length parameters
	that reduce to constant integer expressions.
	* trans-expr.cc (gfc_trans_assignment_1): Parameterized
	components cannot have default initializers so they must be
	allocated after initialization.

gcc/testsuite/
	PR fortran/84432
	PR fortran/114815
	* gfortran.dg/pdt_26.f03: Update with default no initializer.
	* gfortran.dg/pdt_27.f03: Change to test non-conforming
	initializers.
2025-09-05 07:22:01 +01:00
Paul Thomas 86353186dc Fortran: Check PDT parameters are of integer type [PR83762, PR102457]
2025-09-05  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/83762
	PR fortran/102457
	* decl.cc (gfc_get_pdt_instance): Check that variable PDT parm
	expressions are of type integer. Note that the symbol must be
	tested since the expression often appears as BT_PROCEDURE.

gcc/testsuite/
	PR fortran/83762
	PR fortran/102457
	* gfortran.dg/pdt_44.f03: New test.
	* gfortran.dg/pr95090.f90: Give the PDT parameter a value to
	suppress the type error.
2025-09-05 07:19:01 +01:00
GCC Administrator e4755f9523 Daily bump. 2025-09-05 00:19:51 +00:00
Pan Li d6f31c8d57 RISC-V: Add test for vec_duplicate + vmadd.vv unsigned combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vmadd.vvm
combine to vmadd.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
	for vmadd.vx.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary.h: Add test
	helper macros.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary_data.h: Add test
	data for run test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmadd-run-1-u16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmadd-run-1-u32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmadd-run-1-u64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmadd-run-1-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-05 06:15:05 +08:00
Pan Li 0f65bb7653 RISC-V: Add test for vec_duplicate + vmadd.vv signed combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vmadd.vv
combine to vmadd.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c: Add asm check
	for vmadd.vx.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary.h: Add test
	helper macros.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary_data.h: Add test
	data for run test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmadd-run-1-i16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmadd-run-1-i32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmadd-run-1-i64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmadd-run-1-i8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-05 06:15:05 +08:00
Pan Li 927ba84ec2 RISC-V: Adjust the vmacc.vx combine test cases
To avoid generating the vmadd.vx code.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary.h: Adjust the
	vmacc.vx to avoid generating vmadd.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-05 06:15:04 +08:00
Pan Li 6630945212 RISC-V: Combine vec_duplicate + vmadd.vv to vmadd.vx on GR2VR cost
This patch would like to combine the vec_duplicate + vmadd.vv to the
vmadd.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

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

Before this patch:
  11   │     beq a3,zero,.L8
  12   │     vsetvli a5,zero,e32,m1,ta,ma
  13   │     vmv.v.x v2,a2
  ...
  16   │ .L3:
  17   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  22   │     vmadd.vv v1,v2,v3
  ...
  25   │     bne a3,zero,.L3

After this patch:
  11   │     beq a3,zero,.L8
  ...
  14   │ .L3:
  15   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  20   │     vmadd.vx v1,a2,v3
  ...
  23   │     bne a3,zero,.L3

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vmacc_vx_<mode>): Rename to
	handle both the macc and madd.
	(*mul_plus_vx_<mode>): Add madd pattern.
	* config/riscv/vector.md (@pred_mul_plus_vx_<mode>): Rename to
	handle both the macc and madd.
	(*pred_macc_<mode>_scalar_undef): Remove.
	(*pred_nmsac_<mode>_scalar_undef): Remove.
	(*pred_mul_plus_vx<mode>_undef): Add new pattern to handle
	both the vmacc and vmadd.
	(@pred_mul_plus_vx<mode>): Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-09-05 06:15:04 +08:00
Jakub Jelinek e2e01a893c aarch64: Adjust aarch64/spaceship_1.C testcase for recent changes [PR121732]
In r16-3414 libstdc++ changed ABI for (still experimental C++20) and uses
unordered value -128 instead of 2.  Generally the change improved code
generation on all targets tested, see
https://gcc.gnu.org/pipermail/gcc-patches/2025-August/693534.html
for details.
In r16-3474 I've adjusted the middle-end and backends to use that value.
This apparently broke the spaceship_1.C test on aarch64 which scans the
exact function bodies which are now different.

The following patch adjusts the full body patterns to match.  On these
2 routines, the generated code is 1 insn longer than in the past, so if
you have ideas how to change the code generation for the common case of
-1, 0, 1, -128 value, maybe it could be improved.

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

	PR testsuite/121732
	PR target/117013
	* g++.target/aarch64/spaceship_1.C: Adjust expected fn bodies
	for _Z8ss_floatff and _Z9ss_doubledd.
2025-09-04 18:52:47 +02:00
Jan Hubicka 79d9ff28c2 Fix ICE with auto-fdo and -fpartial-profiling
With -fpartial-profling we ICE building perlbench and gcc from spec2k17 since
afdo_annotate_cfg applies knowlede about zero profiles too early.  This patch
moves it after the early exit when profile is 0 everywhere and also fixes
formatting issue in the next block.

gcc/ChangeLog:

	* auto-profile.cc (afdo_annotate_cfg): Apply zero_bbs after early
	exit for missing profile; fix formating
2025-09-04 17:29:07 +02:00
Jan Hubicka 1da3c4d90e Fix scalng of auto-fdo profiles in liner
with auto-fdo it is possible that function bar with non-zero profile is inlined
into foo with zero profile and foo is the only caller of it.  In this case
we currently scale bar to also have zero profile which makes it optimized
for size.  With normal profiles this does not happen, since basic blocks with
non-zero count must have some way to be reached.

This patch makes inliner to scale caller in this case which mitigates the
problem (to some degree).

Bootstrapped/regtested x86_64-linux, plan to commit it shortly.

gcc/ChangeLog:

	* ipa-inline-transform.cc (inline_call): If function with
	AFDO profile is inlined into function with
	GUESSED_GLOBAL0_AFDO or GUESSED_GLOBAL0_ADJUSTED, scale
	caller to AFDO profile.
	* profile-count.h (profile_count::apply_scale): If num is AFDO
	and den is not GUESSED, make result AFDO rather then GUESSED.
2025-09-04 17:25:26 +02:00
Wilco Dijkstra 640fd2f0cc MAINTAINERS: Add myself as an aarch64 port reviewer
Following on from the announcement here:
https://gcc.gnu.org/pipermail/gcc/2025-July/246267.html
adding myself as an aarch64 port reviewer.

ChangeLog:

	* MAINTAINERS (Reviewers): Add myself for the aarch64 port.
2025-09-04 14:35:30 +00:00
Wilco Dijkstra e494101a23 optab: Add optab for isnan
Add an optab for isnan.  This requires changes to the existing folding code
to extend the interclass_mathfn infrastructure to support BUILT_IN_ISNAN.
It now checks for a valid optab before emitting the generic expansion.
There is no change if no optab is defined.  Update documentation.

gcc:
	* builtins.cc (interclass_mathfn_icode): Add support for isnan
	optab.
	(expand_builtin): Add BUILT_IN_ISNAN to expand isnan optab.
	(fold_builtin_interclass_mathfn): Expand BUILT_IN_ISNAN only after
	checking for a valid optab.
	(fold_builtin_classify): Move generic BUILT_IN_ISNAN expansion
	to fold_builtin_interclass_mathfn.
	(fold_builtin_1): For BUILT_IN_ISNAN first try fold_builtin_classify,
	then fold_builtin_interclass_mathfn.
	* optabs.def: Add isnan optab.
	* doc/md.texi: Document isnan.
2025-09-04 14:35:30 +00:00
Richard Biener bad57f7867 TLC to vect_create_epilog_for_reduction
The following removes back-and-forth of state in
vect_create_epilog_for_reduction and code that's pointless, in
particular around double reduction handling which isn't that
special as it seems.

	* tree-vect-loop.cc (vect_create_epilog_for_reduction):
	Remove unnecessary code around double reductions.
2025-09-04 16:11:57 +02:00
Richard Earnshaw 593e9ee05d arm: wrong code from vset_lane_* [PR121775]
Insufficient validation of the operands in vec_set_<mode>_internal
means that the optimizers can transform the exanded code into
something that is invalid.  We then emit code based on the incorrect
RTL assuming that it is still valid.  A valid pattern can only have a
single bit set in the immediate operand, representing the lane to be
written.

gcc/ChangeLog:

	PR target/121775
	* config/arm/neon.md (vec_set<mode>_internal, all variants):
	validate the immediate operand that indicates the lane to
	modify.

gcc/testsuite/ChangeLog:

	PR target/121775
	* gcc.target/arm/simd/vset_lane_u8.c: New test.
2025-09-04 14:58:59 +01:00
Patrick Palka 7f7f1878ee libstdc++: Conditionalize LWG 3569 changes to join_view
LWG 3569 adjusted join_view's iterator specification to handle non
default-constructible iterators by wrapping the corresponding data member
in std::optional, which we followed suit in r13-2649-g7aa80c82ecf3a3.

But this wrapping is unnecessary for iterators that are already
default-constructible.  Rather than unconditionally using std::optional
here, which introduces time/space overhead, this patch conditionalizes
our LWG 3569 changes on the iterator in question being non-forward (and
thus non default-constructible).  We check forwardness instead of
default-constructibility in order to accommodate input-only iterators
that satisfy but do not model default_initializable, e.g. whose default
constructor is underconstrained.

libstdc++-v3/ChangeLog:

	* include/std/ranges (join_view::_Iterator::_M_satisfy):
	Adjust to handle non-std::optional _M_inner as per before LWG 3569.
	(join_view::_Iterator::_M_get_inner): New.
	(join_view::_Iterator::_M_inner): Don't wrap in std::optional if
	the iterator is forward.  Initialize.
	(join_view::_Iterator::operator*): Use _M_get_inner instead
	of *_M_inner.
	(join_view::_Iterator::operator++): Likewise.
	(join_view::_Iterator::iter_move): Likewise.
	(join_view::_Iterator::iter_swap): Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-09-04 09:57:36 -04:00
Tomasz Kamiński 1a41e52d7e libstdc++: Reuse _Bind_back_t functor in ranges::_Partial
This patch refactors ranges::_Partial to be implemented using _Bind_back_t.
This allows it to benefit from the changes in r16-3398-g250dd5b5604fbc,
specifically making the closure trivially copyable. Since _Bind_back_t
already provides an optimized implementation for a single bound argument,
specializations for _Partial with a single argument are now removed.

We still preserve a specialization of _Partial for trivially copy-constructible
arguments that define only a const overload of operator(). To avoid
re-checking invocability constraints, this specialization calls the now-public,
unconstrained _Binder::_S_call static method instead of the constrained
_Binder::operator().

The primary specialization of _Partial retains its operator(), which
uses a simpler __adaptor_invocable constraint that does not consider
member pointers, as they are not relevant here. This implementation also
calls _Binder::_S_call to avoid re-performing overload resolution and
invocability checks for _Binder::operator().

Finally, the _M_binder member (_Bind_back_t) is now marked
[[no_unique_address]]. This is beneficial as ranges::_Partial is used with
ranges::to, which commonly has zero or empty bound arguments (e.g., stateless
allocators, comparators, or hash functions).

libstdc++-v3/ChangeLog:

	* include/bits/binders.h (_Binder::_S_call): Make public.
	* include/std/ranges (ranges::_Partial<_Adaptor, _Args...>):
	Replace tuple<_Args...> with _Bind_back_t<_Adaptor, _Args...>.
	(ranges::_Partial<_Adaptor, _Arg>): Remove.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-04 15:30:00 +02:00
Tomasz Kamiński b2adb7712c libstdc++: Move _Binder and related aliases to separate file.
bits/binders.h is already mapped in libstdc++-v3/doc/doxygen/stdheader.cc.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add bits/binders.h
	* include/Makefile.in: Add bits/binders.h
	* include/std/functional (std::_Indexed_bound_arg, std::_Binder)
	(std::__make_bound_args, std::_Bind_front_t, std::_Bind_back_t):
	Moved to bits/binders.h file, that is now included.
	* include/bits/binders.h: New file.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-04 15:29:36 +02:00
Tomasz Kamiński 2c2df024df libstdc++: Merge bind_front and bind_back binders
The _Bind_front and _Bind_back class templates are now merged into a single
_Binder implementation that accepts _Back as a template parameter. This makes
the bind_back implementation available in C++20 mode, allowing it to be used
for range adaptor closures.

With zero bound arguments, bind_back and bind_front have equivalent
functionality. Consequently, _Bind_back_t now produces the same type as
bind_front (_Binder<false, _Fd>). A simple copy of the functor cannot be
returned in this case, as it would visibly affect overload resolution
(see included test cases).

We also replace std::invoke in internal functions, with std::__invoke.

libstdc++-v3/ChangeLog:

	* include/std/functional: (std::_Indexed_bound_arg): Fixed
	indentation.
	(__Bound_arg_storage::_S_apply_front)
	(__Bound_arg_storage::_S_apply_front): Merged into _S_apply.
	(__Bound_arg_storage::_S_apply): Merged above, add _Back template
	parameter, replace std::invoke with std::__invoke.
	(std::_Bind_front): Renamed to std::_Binder and add _Back
	template parameter.
	(std::_Binder): Renamed from std::_Bind_front.
	(_Binder::_Result_t, _Binder::_S_noexcept_invoke): Define.
	(_Binder::operator()): Use _Result_t and _S_noexcept_invoke.
	(_Binder::_S_call): Handle zero args specially, replace std::invoke
	with std::__invoke.
	(std::_Bind_front_t, std::_Bind_back_t): Defined in terms
	of _Binder.
	(std::_Bind_back): Merged into _Binder.
	* testsuite/20_util/function_objects/bind_back/1.cc: New tests.
	* testsuite/20_util/function_objects/bind_back/111327.cc: Updated
	error messages.
	* testsuite/20_util/function_objects/bind_front/1.cc: New tests.
	* testsuite/20_util/function_objects/bind_front/111327.cc: Updated
	error messages.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-04 15:28:57 +02:00
Richard Biener 6cc5328cd6 TLC for vectorizable_reduction
The following removes never taken paths and consolidates the
nested_cycle and double_reduc variables which are the same.

	* tree-vect-loop.cc (vectorizable_reduction): Eliminate
	nested_cycle in favor of double_reduc and set that where
	it makes most sense.  Remove never taken paths and always
	true conditions.
2025-09-04 15:23:07 +02:00
Robin Dapp e3d5e9f0c8 RISC-V: Use correct target in expand_vec_perm [PR121780].
This fixes a glaring mistake in yesterday's change to the expansion of
vec_perm.  We should of course move tmp_target into the real target
and not the other way around.  I wonder why my testing hasn't
caught this...

	PR target/121742
	PR target/121780
	PR target/121781

gcc/ChangeLog:

	* config/riscv/riscv-v.cc (expand_vec_perm): Swap target and
	tmp_target.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/pr121780.c: New test.
	* gcc.target/riscv/rvv/autovec/pr121781.c: New test.
2025-09-04 12:48:40 +02:00
Robin Dapp 8bb076ac0d vect: Use poly_int64 for prolog bound.
Since peeling and version for alignment for VLA modes was introduced
(r16-3065-geee51f9a4b6) we have been seeing a lot of test suite failures
like

  internal compiler error: in apply_scale, at profile-count.h:1187

This is because vect_gen_prolog_loop_niters sets the prolog bound to -1
in case align_in_elems is a non-constant poly_int.
bound - 1 is later used to scale the loop profile in scale_loop_profile
so we try to calculate with an assumed -2 iterations.

This patch changes bound_prolog to poly_int64, using a poly estimate for
frequency scaling but only records an iteration bound for the prolog if
the bound is a scalar.

	PR/tree-optimization 121523

gcc/ChangeLog:

	* tree-vect-loop-manip.cc (vect_gen_prolog_loop_niters):
	Change prolog bound to poly_int64.
	(vect_gen_scalar_loop_niters): Ditto.
	(vect_do_peeling): Use poly estimate for frequency scaling.
2025-09-04 12:48:40 +02:00
Richard Biener 56e7010eef tree-optimization/121768 - bogus double reduction detected
The following changes how we detect double reductions, in particular
not setting vect_double_reduction_def on the outer PHIs when the inner
loop doesn't satisfy double reduction constraints.  It also simplifies
the setup a bit by not having to detect wheter we process an inner
loop of a double reduction.

	PR tree-optimization/121768
	* tree-vect-loop.cc (vect_inner_phi_in_double_reduction_p): Remove.
	(vect_analyze_scalar_cycles_1): Analyze inner loops of
	double reductions immediately and only mark fully recognized
	double reductions.  Skip already analyzed inner loops.
	(vect_is_simple_reduction): Change double_reduc from a flag
	to an output of the inner loop PHI and to whether we are
	processing an inner loop of a double reduction.

	* gcc.dg/vect/pr121768.c: New testcase.
2025-09-04 12:36:30 +02:00
Richard Biener e8969a86c1 tree-optimization/121685 - accesses to *this are not trapping
When inside a method then we know the this pointer points to
an object of at least the size of the methods base type.  We
can use this to compute more references as not trapping and
enable invariant motion and in turn vectorization as for a
slightly modified version of the testcase in the PR.

	PR tree-optimization/121685
	* tree-eh.cc (ref_outside_object_p): Split out from ...
	(tree_could_trap_p): ... here.  Assume the this pointer
	of a method refers to an object of at least size of its
	base type.

	* g++.dg/vect/pr121685-1.cc: New testcase.
2025-09-04 12:36:30 +02:00
Andrew Pinski adfe96eb61 forwprop: Improve the reject case for copy prop [PR107051]
Currently the code rejects:
```
tmp = *a;
*b = tmp;
```
(unless *a == *b). This can be improved such that if a and b are known to
share the same base, then only reject it if they overlap; that is the
difference of the offsets (from the base) is maybe less than the size.

This fixes the testcase in comment #0 of PR 107051.

Changes since v1:
* v2: Use ranges_maybe_overlap_p instead of manually checking the overlap.
      Allow for the case where the alignment is known to be greater than
      the size.

	PR tree-optimization/107051

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_agr_copyprop_1): Allow for
	memory sharing the same base if they known not to overlap over
	the size.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/copy-prop-aggregate-union-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-04 03:12:43 -07:00
Luc Grosheintz 43a8c0f8e6 libstdc++: Add _GLIBCXX_RESOLVE_LIB_DEFECTS for 4314 in <mdspan>.
In r16-2328-g29d53f6213e0a1 we fixed a bug related to user-defined
objects that can convert to an integers only via an rvalue reference.
The same commit also implemented LWG 4314 [1], but didn't mark it with
_GLIBCXX_RESOLVE_LIB_DEFECTS. This commit adds the missing markers.

[1]: https://cplusplus.github.io/LWG/issue4314

It also fixes one cases of trailing white-space near a ctor for
aligned_accessor.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (layout_left::mapping::operator()): Add
	_GLIBCXX_RESOLVE_LIB_DEFECTS marker for 4314.
	(layout_left::mapping::operator()): Ditto.
	(layout_stride::mapping::operator()): Ditto.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-09-04 11:55:02 +02:00
Kito Cheng a7fe8f83bf RISC-V: Always register vector built-in functions during LTO [PR110812]
Previously, vector built-in functions were not properly registered during
the LTO pipeline, causing link failures when vector intrinsics were used
in LTO builds with mixed architecture options.  This patch ensures all
vector built-in functions are always registered during LTO compilation.

The key changes include:
- Moving pragma intrinsic flag manipulation from riscv-c.cc to
  riscv-vector-builtins.cc for better encapsulation
- Registering all vector built-in functions regardless of current ISA
  extensions, deferring the actual extension checking to expansion time
- Adding proper support for built-in type registration during LTO

This approach is safe because we already perform extension requirement
checking at expansion time.  The trade-off is a slight increase in
bootstrap time for LTO builds due to registering more built-in functions.

	PR target/110812

gcc/ChangeLog:

	* config/riscv/riscv-c.cc (pragma_intrinsic_flags): Remove struct.
	(riscv_pragma_intrinsic_flags_pollute): Remove function.
	(riscv_pragma_intrinsic_flags_restore): Remove function.
	(riscv_pragma_intrinsic): Simplify to only call handle_pragma_vector.
	* config/riscv/riscv-vector-builtins.cc (pragma_intrinsic_flags):
	Move struct definition here from riscv-c.cc.
	(riscv_pragma_intrinsic_flags_pollute): Move and adapt from
	riscv-c.cc, add zvfbfmin, zvfhmin and vector_elen_bf_16 support.
	(riscv_pragma_intrinsic_flags_restore): Move from riscv-c.cc.
	(rvv_switcher::rvv_switcher): Add pollute_flags parameter to
	control flag manipulation.
	(rvv_switcher::~rvv_switcher): Restore flags conditionally.
	(register_builtin_types): Use rvv_switcher without polluting flags.
	(get_required_extensions): Remove function.
	(check_required_extensions): Simplify to only check type validity.
	(function_instance::function_returns_void_p): Move implementation
	from header.
	(function_builder::add_function): Register placeholder for LTO.
	(init_builtins): Simplify and handle LTO case.
	(reinit_builtins): Remove function.
	(handle_pragma_vector): Remove extension checking.
	* config/riscv/riscv-vector-builtins.h
	(function_instance::function_returns_void_p): Add declaration.
	(function_call_info::function_returns_void_p): Remove inline
	implementation.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/lto/pr110812_0.c: New test.
	* gcc.target/riscv/lto/pr110812_1.c: New test.
	* gcc.target/riscv/lto/riscv-lto.exp: New test driver.
	* gcc.target/riscv/lto/riscv_vector.h: New header wrapper.
2025-09-04 17:05:57 +08:00
Kito Cheng 9df4edf0af RISC-V: Fix extension subset check in riscv_can_inline_p
The extension subset check logic in riscv_ext_is_subset was incorrectly
inverted, causing functions with more extensions to be incorrectly
rejected from being inlined into functions with fewer extensions.

This patch fixes the logic to correctly check if the callee's required
extensions are a subset of the caller's extensions. The corrected logic
now properly allows inlining when the caller has all the extensions that
the callee requires.

gcc/
	* common/config/riscv/riscv-common.cc (riscv_ext_is_subset): Fix
	inverted logic in extension subset check.

gcc/testsuite/
	* gcc.target/riscv/can_inline_p_test-01.c: New test.
	* gcc.target/riscv/can_inline_p_test-02.c: New test.
	* gcc.target/riscv/can_inline_p_test-03.c: New test.
	* gcc.target/riscv/can_inline_p_test-04.c: New test.
	* gcc.target/riscv/riscv_vector.h: New header wrapper for vector
	tests.
2025-09-04 17:05:57 +08:00
Jakub Jelinek b55277a4f8 bitint: Fix torture/bitint-14.c on bitint_extended targets [PR117599]
This patch fixes regressions of the gcc.dg/torture/bitint-* tests
caused by r16-3036-ga76a032354ee48 with --enable-checking=all.

The errors are similar to the following:

../../gcc/testsuite/gcc.dg/torture/bitint-14.c:54:1: error: type mismatch in 'array_ref'
<unnamed-signed:63>

unsigned long

_42 = VIEW_CONVERT_EXPR<unsigned long[10]>(r575[i_10])[8];
during GIMPLE pass: bitintlower0
../../gcc/testsuite/gcc.dg/torture/bitint-14.c:54:1: internal compiler error: verify_gimple failed

The first two hunks aren't strictly necessary, I'm just trying to
avoid calling build_qualified_type when it won't be needed.

At least on s390x-linux (tried cross) bitint-14.c doesn't ICE with it
anymore.

Though, I must say the more I look at the limb_access changes, the less
I like the abi_load_p stuff, so I think what we eventually should do instead
is return values with m_limb_type always.
For bitint_extended case (but only if we can prove that the extension there
is for the right precision and right sign) or !write_p just return it,
otherwise cast to lower precision and back to m_limb_type.
And on the other side on stores, for !bitint_extended happily store whatever
the whole m_limb_type value contains, for bitint_extended do the cast to
smaller precision and back on the writes.

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

	PR target/117599
	* gimple-lower-bitint.cc (bitint_large_huge::limb_access): Move
	build_qualified_type calls into the if/else if/else bodies, for
	the last one set ltype to m_limb_type first, drop limb_type_a
	and use ltype instead.
2025-09-04 10:45:17 +02:00
Richard Biener cba74d2cde tree-optimization/61247 - handle peeled converted IV in SCEV
The following handles SCEV analysis of a peeled converted IV if
that IV is known to not overflow.  For

  # _15 = PHI <_4(6), 0(5)>
  # i_18 = PHI <i_11(6), 0(5)>
  i_11 = i_18 + 1;
  _4 = (long unsigned int) i_11;

we cannot analyze _15 directly since the SCC has a widening
conversion.  But we can analyze _4 to (long unsigned int) {1, +, 1}_1
which is "peeled" (it's from after the first iteration of _15).
If the un-peeled IV {0, +, 1}_1 has the same initial value as _15
and it does not overflow then _15 can be analyzed as
{0ul, +, 1ul}_1.

The following implements this in simplify_peeled_chrec.

	PR tree-optimization/61247
	* tree-scalar-evolution.cc (simplify_peeled_chrec):
	Handle the case of a converted peeled chrec.

	* gcc.dg/vect/vect-pr61247.c: New testcase.
2025-09-04 10:14:26 +02:00
Richard Biener 95afbe4c76 tree-optimization/121740 - handle aggregate zeroing as skipped may-def
The following makes value-numbering handle a situation like

  D.58046 = {};
  SR.83_44->i = {};
  pretmp_41 = MEM[(struct _Optional_payload_base &)&D.58046 + 8]._M_engaged;

where the intermediate may-def SR.83_44->i = {} prevents CSE of the
load to zero.  The problem is two-fold here, one is that the code
skipping may-defs does not handle zeroing via a CTOR, the other is that
(partial) must-defs can be better handled by later code as otherwise
we may not find an appropriate definition to CSE to.

I've noticed we fail to guard against storage-order issues, so fixed
that on the fly.

	PR tree-optimization/121740
	* tree-ssa-sccvn.cc (vn_reference_lookup_3): Allow skipping
	may-defs from CTORs.  Do not skip may-defs with storage-order
	issues or (partial) must-defs.

	* gcc.dg/tree-ssa/ssa-fre-104.c: Un-XFAIL.
	* gcc.dg/tree-ssa/ssa-fre-110.c: New testcase.
2025-09-04 10:03:32 +02:00
Tomasz Kamiński b26033d579 libstdc++: Add stable names to C++98 implementation-defined docs.
Stable names are based on C++03 standard document, and some of then were
changed since then.

libstdc++-v3/ChangeLog:

	* doc/html/manual/status.html: Regenerated the file.
	* doc/xml/manual/status_cxx1998.xml: Add stable name to
	each entry.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-04 09:57:05 +02:00
Nathaniel Shead c2e567a6ed c++/modules: Fix ADL [PR117658]
On looking again at [basic.lookup.argdep] p4, I believe GCC hasn't fully
implemented the wording here for ADL.  This patch fixes two issues.

First, 4.3 indicates that a function exported from a named module should
be visible to ADL regardless of whether it's visible to normal name
lookup, as long as some restrictions are followed.

This patch implements this; for skipping declarations that "do not
appear in the TU containing the point of lookup" I don't think there's
anything special we need to do, as any declarations before the point of
lookup will be found in other ways anyway, and any remaining
declarations from the current TU cannot be seen regardless.

Secondly, currently we only add the exported functions along the
instantiation path of a lookup.  But I don't think this is intended by
the current wording, so this patch adjusts that.  I also clean up the
logic to do all different module processing in adl_namespace_fns so that
we don't duplicate work in traversing the module binding list
unnecessarily.

This new handling means we need to do some extra work to properly error
on overload sets containing TU-local entities (as this might actually
come up now!) but I'm leaving that for a later patch.

As a drive-by fix this also fixes an ICE for C++26 expansion statements
with finding the instantiation path.

	PR c++/117658

gcc/cp/ChangeLog:

	* cp-tree.h (get_originating_module): Adjust parameter names.
	* module.cc (path_of_instantiation): Handle C++26 expansion
	statements.
	* name-lookup.cc (name_lookup::adl_namespace_fns): Handle
	exported declarations attached to the same module of an
	associated entity with the same innermost non-inline namespace,
	and non-exported functions on the instantiation path.
	(name_lookup::search_adl): Build mapping of namespace to modules
	that associated entities are attached to; remove now-unneeded
	instantiation path handling.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/adl-4_a.C: Test should pass.
	* g++.dg/modules/adl-4_b.C: Test should pass.
	* g++.dg/modules/adl-6_a.C: New test.
	* g++.dg/modules/adl-6_b.C: New test.
	* g++.dg/modules/adl-6_c.C: New test.
	* g++.dg/modules/adl-7_a.C: New test.
	* g++.dg/modules/adl-7_b.C: New test.
	* g++.dg/modules/adl-7_c.C: New test.
	* g++.dg/modules/adl-8_a.C: New test.
	* g++.dg/modules/adl-8_b.C: New test.
	* g++.dg/modules/adl-8_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-09-04 17:42:47 +10:00
Nathaniel Shead 03505e5b93 c++/modules: Mark implicit inline namespaces as purview [PR121724]
When we push an existing namespace within the module purview for the
first time, we also need to mark any parent inline namespaces as purview
to not confuse the streaming logic.

	PR c++/121724

gcc/cp/ChangeLog:

	* name-lookup.cc (push_namespace): Mark inline namespace
	contexts as purview if needed.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/namespace-12_a.C: New test.
	* g++.dg/modules/namespace-12_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-09-04 17:42:25 +10:00
Iain Sandoe 6ce76052ae testsuite, darwin: Suppress unwind frames in scantest-lto.c.
Currently, for Darwin unwind and EH frames are emitted without use
of .cfi_xxx instructions; the emitted frames also contain the
string 'ascii'.  For the purpose of this test, omit them.

	PR testsuite/112728

gcc/testsuite/ChangeLog:

	* gcc.dg/scantest-lto.c: Omit unwind frames.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-09-04 07:36:55 +01:00
GCC Administrator a803d5b9cd Daily bump. 2025-09-04 00:20:48 +00:00
Kuan-Lin Chen 2963f5f7bd RISC-V: Add support for the XAndesbfhcvt ISA extension.
This extension defines instructions to perform scalar floating-point
conversion between the BFLOAT16 floating-point data and the IEEE-754
32-bit single-precision floating-point (SP) data in a scalar
floating point register.

gcc/ChangeLog:

	* config/riscv/andes.def: Add nds_fcvt_s_bf16 and nds_fcvt_bf16_s.
	* config/riscv/riscv.md (truncsfbf2): Add TARGET_XANDESBFHCVT support.
	(extendbfsf2): Ditto.
	* config/riscv/riscv-builtins.cc: New AVAIL andesbfhcvt.
	Add new define RISCV_ATYPE_BF and RISCV_ATYPE_SF.
	* config/riscv/riscv-ftypes.def: New DEF_RISCV_FTYPE.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/xandes/xandesbfhcvt-1.c: New test.
	* gcc.target/riscv/xandes/xandesbfhcvt-2.c: New test.
2025-09-03 17:03:05 -06:00
Kuan-Lin Chen e1fb7db695 RISC-V: Add support for the XAndesperf ISA extension.
This patch adds support for the XAndesperf ISA extension.
The 32-bit AndeStar V5 extension includes branch instructions,
load effective address instructions, and string processing
instructions for performance improvement.
New INSN patterns are added into the new file andes.md
as a seprated vender extension.

gcc/ChangeLog:

	* config/riscv/constraints.md (Ou07): New constraint.
	(ads_Bext): New constraint.
	* config/riscv/iterators.md (ANYLE32): New iterator.
	(sizen): New iterator.
	(sh_limit): New iterator.
	(sh_bit): New iterator.
	(cs): New iterator.
	* config/riscv/predicates.md (ads_branch_bbcs_operand): New predicate.
	(ads_branch_bimm_operand): New predicate.
	(ads_imm_extract_operand): New predicate.
	(ads_extract_size_imm_si): New predicate.
	(ads_extract_size_imm_di): New predicate.
	(const_int5_operand): New predicate.
	* config/riscv/riscv-builtins.cc:
	Add new AVAIL andesperf32 and andesperf64.
	Add new define RISCV_ATYPE_DI.
	* config/riscv/riscv-ftypes.def: New DEF_RISCV_FTYPE.
	* config/riscv/riscv.cc
	(riscv_extend_cost): Cost for pattern 'bfo'.
	(riscv_rtx_costs): Cost for XAndesperf extension.
	* config/riscv/riscv.md: Add support for XAndesperf to patterns
	zero_extendsidi2_internal, zero_extendhi2, extendsidi2_internal,
	extend<SHORT:mode><SUPERQI:mode>2, <any_extract:optab><GPR:mode>3
	and branch_on_bit.
	* config/riscv/vector-iterators.md
	(sz): Add sign_extract and zero_extract.
	* config/riscv/andes.def: New file for vender Andes.
	* config/riscv/andes.md: New file for vender Andes.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/riscv.exp: Add runtest for subdir xandes.
	* gcc.target/riscv/xandes/xandesperf-1.c: New test.
	* gcc.target/riscv/xandes/xandesperf-10.c: New test.
	* gcc.target/riscv/xandes/xandesperf-2.c: New test.
	* gcc.target/riscv/xandes/xandesperf-3.c: New test.
	* gcc.target/riscv/xandes/xandesperf-4.c: New test.
	* gcc.target/riscv/xandes/xandesperf-5.c: New test.
	* gcc.target/riscv/xandes/xandesperf-6.c: New test.
	* gcc.target/riscv/xandes/xandesperf-7.c: New test.
	* gcc.target/riscv/xandes/xandesperf-8.c: New test.
	* gcc.target/riscv/xandes/xandesperf-9.c: New test.
2025-09-03 16:53:27 -06:00
Kuan-Lin Chen fdcab34932 RISC-V: Add basic XAndes vendor extension support.
This patch add basic support for the following XAndes ISA extensions:

XANDESPERF
XANDESBFHCVT
XANDESVBFHCVT
XANDESVSINTLOAD
XANDESVPACKFPH
XANDESVDOT

gcc/ChangeLog:

	* config/riscv/riscv-ext.def: Include riscv-ext-andes.def.
	* config/riscv/riscv-ext.opt (riscv_xandes_subext): New variable.
	(XANDESPERF) : New mask.
	(XANDESBFHCVT): Ditto.
	(XANDESVBFHCVT): Ditto.
	(XANDESVSINTLOAD): Ditto.
	(XANDESVPACKFPH): Ditto.
	(XANDESVDOT): Ditto.
	* config/riscv/t-riscv: Add riscv-ext-andes.def.
	* doc/riscv-ext.texi: Regenerated.
	* config/riscv/riscv-ext-andes.def: New file.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/xandes/xandes-predef-1.c: New test.
	* gcc.target/riscv/xandes/xandes-predef-2.c: New test.
	* gcc.target/riscv/xandes/xandes-predef-3.c: New test.
	* gcc.target/riscv/xandes/xandes-predef-4.c: New test.
	* gcc.target/riscv/xandes/xandes-predef-5.c: New test.
	* gcc.target/riscv/xandes/xandes-predef-6.c: New test.

	Co-author: Lino Hsing-Yu Peng (linopeng@andestech.com)
	Co-author: Kai Kai-Yi Weng (kaiweng@andestech.com).
2025-09-03 16:39:32 -06:00
Paul-Antoine Arras f6e6224236 RISC-V: Add pattern for vector-scalar floating-point max
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into an smax RTL instruction.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f       v2,fa0
  vfmax.vv       v1,v1,v2

After, we get only one:
  vfmax.vf       v1,v1,fa0

In some cases, it also shaves off one vsetvli.

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfmax_vf_<mode>): Rename into...
	(*vf<optab>_vf_<mode>): New pattern to combine vec_duplicate +
	vf{min,max}.vv into vf{max,min}.vf.

gcc/testsuite/ChangeLog:
	* gcc.target/riscv/rvv/autovec/vls/floating-point-max-2.c: Adjust scan
	dump.
	* gcc.target/riscv/rvv/autovec/vls/floating-point-max-4.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfmax. Also add
	missing scan-dump for vfmul.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Add vfmax.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop.h: Add max functions.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_data.h: Add data for
	vfmax.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmax-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmax-run-1-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmax-run-1-f64.c: New test.
2025-09-03 16:34:53 -06:00
Harald Anlauf 692281a387 Fortran: fix TRANSFER with rank 1 unlimited polymorphic SOURCE [PR121263]
PR fortran/121263

gcc/fortran/ChangeLog:

	* trans-intrinsic.cc (gfc_conv_intrinsic_transfer): For an
	unlimited polymorphic SOURCE to TRANSFER use saved descriptor
	if possible.

gcc/testsuite/ChangeLog:

	* gfortran.dg/transfer_class_5.f90: New test.
2025-09-03 20:41:20 +02:00
Yihan Wang 589f3cd183 libstdc++: Implement LWG4222 'expected' constructor from a single value missing a constraint
libstdc++-v3/ChangeLog:

	* include/std/expected (expected(U&&)): Add missing constraint
	as per LWG 4222.
	* testsuite/20_util/expected/lwg4222.cc: New test.

Signed-off-by: Yihan Wang <yronglin777@gmail.com>
2025-09-03 19:12:15 +01:00
Austin Law b790606e49 [RISC-V][PR target/121213] Avoid unnecessary sign extension in amoswap sequence
This is Austin's work to remove the redundant sign extension seen in pr121213.

--

The .w form of amoswap will sign extend its result from 32 to 64 bits, thus any
explicit sign extension insn doing the same is redundant.

This uses Jivan's approach of allocating a DI temporary for an extended result
and using a promoted subreg extraction to get that result into the final
destination.

Tested with no regressions on riscv32-elf and riscv64-elf and bootstrapped on
the BPI and pioneer systems.

	PR target/121213
gcc/
	* config/riscv/sync.md (amo_atomic_exchange_extended<mode>):
	Separate insn with sign extension for 64 bit targets.

gcc/testsuite
	* gcc.target/riscv/amo/pr121213.c: Remove xfail.
2025-09-03 10:41:17 -06:00
Jan Hubicka bda76b479d Dump profile_info in ipa-profile dump
WPA currently does not print profile_info which might have been modified
by profile merging logic.  this patch adds dumping logic to ipa-profile pass.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

	* ipa-profile.cc (ipa_profile): Dump profile_info.
2025-09-03 18:00:42 +02:00
Jan Hubicka 2c4fcab25f Do not auto-enable loop optimizations with AutoFDO
With -O2 we automatically enable several loop optimizations with -fprofile-use.
The rationale is that those optimizations at -O3 only mainly since they may
hurt performance or not pay back in code size when used blindly on all loops.
Profile feedback gives us data on number of iterations which is used by heuristics
controlling those optimizations.

Currently auto-FDO is not that good on determining number of iterations so I think we
do not want to enable them until we can prove that those are useful.
This is affecting primarily -O2 codegen.

Theoretically auto-FdO with lbr can be pretty good on estimating # of
iterations, but to make it useful we will need to implement multiplicity for
discriminators at least.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

	* opts.cc (enable_fdo_optimizations): Do not auto-enabele loop
	optimizations with AutoFDO.
2025-09-03 17:56:22 +02:00
Kyrylo Tkachov 2b8256d0ce aarch64: PR target/121749: Use dg-assemble in testcase
Committing as obvious.

Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com>

gcc/testsuite/

	PR target/121749
	* gcc.target/aarch64/simd/pr121749.c: Use dg-assemble directive.
2025-09-03 17:46:50 +02:00
Jan Hubicka 7e2fdee3e2 Increase default number of LTO partitions
The number of LTO partitions should exceed number of CPUs (or hyper-threads) of
commonly used CPUs.  I think it is time to increase it again and as discussed
in the LTO and toplevel asm thread, doing so scales quite well. Tmp file usage
grows from 2.7 to 2.9MB which seems acceptable.  Overall build time on machine
with 256 hyperthreads is comparable.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

	* params.opt (-param=lto-partitions=): INcrease default value from 128 to 512.
2025-09-03 17:45:32 +02:00
Kyrylo Tkachov cb508e5414 aarch64: PR target/121749: Use correct predicate for narrowing shift amounts
With g:d20b2ad845876eec0ee80a3933ad49f9f6c4ee30 the narrowing shift instructions
are now represented with standard RTL and more merging optimisations occur.
This exposed a wrong predicate for the shift amount operand.
The shift amount is the number of bits of the narrow destination, not the input
sources.
Correct this by using the vn_mode attribute when specifying the predicate, which
exists for this purpose.

I've spotted a few more narrowing shift patterns that need the restriction, so
they are updated as well.

Bootstrapped and tested on aarch64-none-linux-gnu.

Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com>

gcc/

	PR target/121749
	* config/aarch64/aarch64-simd.md (aarch64_<shrn_op>shrn_n<mode>):
	Use aarch64_simd_shift_imm_offset_<vn_mode> instead of
	aarch64_simd_shift_imm_offset_<ve_mode> predicate.
	(aarch64_<shrn_op>shrn_n<mode> VQN define_expand): Likewise.
	(*aarch64_<shrn_op>rshrn_n<mode>_insn): Likewise.
	(aarch64_<shrn_op>rshrn_n<mode>): Likewise.
	(aarch64_<shrn_op>rshrn_n<mode> VQN define_expand): Likewise.
	(aarch64_sqshrun_n<mode>_insn): Likewise.
	(aarch64_sqshrun_n<mode>): Likewise.
	(aarch64_sqshrun_n<mode> VQN define_expand): Likewise.
	(aarch64_sqrshrun_n<mode>_insn): Likewise.
	(aarch64_sqrshrun_n<mode>): Likewise.
	(aarch64_sqrshrun_n<mode>): Likewise.
	* config/aarch64/iterators.md (vn_mode): Handle DI, SI, HI modes.

gcc/testsuite/

	PR target/121749
	* gcc.target/aarch64/simd/pr121749.c: New test.
2025-09-03 17:21:35 +02:00
Patrick Palka 3e2077d8c7 c++: constant non-dep init folding vs FIELD_DECL access [PR97740]
Here although the local templated variables x and y have the same
reduced constant value, only x's initializer {a.get()} is well-formed
as written since A::m has private access.  We correctly reject y's
initializer {&a.m} (at instantiation time), but we also reject x's
initializer because we happen to constant fold it ahead of time, which
means at instantiation time it's already represented as a COMPONENT_REF
to a FIELD_DECL, and so when substituting this COMPONENT_REF we naively
double check that the given FIELD_DECL is accessible, which fails.

This patch sidesteps around this particular issue by not checking access
when substituting a COMPONENT_REF to a FIELD_DECL.  If the target of a
COMPONENT_REF is already a FIELD_DECL (i.e. before substitution), then I
think we can assume access has been already checked appropriately.

	PR c++/97740

gcc/cp/ChangeLog:

	* pt.cc (tsubst_expr) <case COMPONENT_REF>: Don't check access
	when the given member is already a FIELD_DECL.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-97740a.C: New test.
	* g++.dg/cpp0x/constexpr-97740b.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-09-03 10:10:00 -04:00
Richard Biener df64893e70 tree-optimization/121756 - handle irreducible regions when sinking
The sinking code currently does not heuristically avoid placing
code into an irreducible region in the same way it avoids placing
into a deeper loop nest.  Critically for the PR we may not insert
a VDEF into a irreducible region that does not contain a virtual
definition.  The following adds the missing heuristic and also
a stop-gap for the VDEF issue - since we cannot determine
validity inside an irreducible region we have to reject any
VDEF movement with destination inside such region, even when
it originates there.  In particular irreducible sub-cycles are
not tracked separately and can cause issues.

I chose to not complicate the already partly incomplete assert
but prune it down to essentials.

	PR tree-optimization/121756
	* tree-ssa-sink.cc (select_best_block): Avoid irreducible
	regions in otherwise same loop depth.
	(statement_sink_location): When sinking a VDEF, never place
	that into an irreducible region.

	* gcc.dg/torture/pr121756.c: New testcase.
2025-09-03 14:33:36 +02:00
Jonathan Wakely c8a24f60b6 libstdc++: Fix std::get<T> for std::pair with reference members [PR121745]
Make the std::get<T> overloads for rvalues use std::forward<T>(p.first)
not std::move(p.first), so that lvalue reference members are not
incorrectly converted to rvalues.

It might appear that std::move(p).first would also work, but the
language rules say that for std::pair<T&&, U> that would produce T&
rather than the expected T&& (see the discussion in P2445R1 §8.2).

Additional tests are added to verify all combinations of reference
members, value categories, and const-qualification.

libstdc++-v3/ChangeLog:

	PR libstdc++/121745
	* include/bits/stl_pair.h (get): Use forward instead of move in
	std::get<T> overloads for rvalue pairs.
	* testsuite/20_util/pair/astuple/get_by_type.cc: Check all value
	categories and cv-qualification.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-03 12:16:18 +01:00
Richard Biener dd6fe9f557 Remove vector type setting from vect_recog_cond_expr_convert_pattern
This pattern doesn't do any target support check so no need to set
a vector type.

	* tree-vect-patterns.cc (vect_recog_cond_expr_convert_pattern):
	Do not set any vector types.
2025-09-03 13:05:02 +02:00
Richard Biener 6acd5534ad tree-optimization/121767 - modvar pattern breaking reductions
The a % b -> a - a / b pattern breaks reduction constraints, disable it
for reduction stmts.

	PR tree-optimization/121767
	* tree-vect-patterns.cc (vect_recog_mod_var_pattern): Disable
	for reductions.

	* gcc.dg/vect/pr121767.c: New testcase.
2025-09-03 13:02:35 +02:00
Richard Biener 41e2fe9be1 tree-optimization/121758 - fix pattern stmt REDUC_IDX updating
The following fixes a corner case of pattern stmt STMT_VINFO_REDUC_IDX
updating which happens auto-magically.  When a 2nd pattern sequence
uses defs from inside a prior pattern sequence then the first guess
for the lookfor can be off.  This happens when for example widening
patterns use vect_get_internal_def, which looks into earlier patterns.

	PR tree-optimization/121758
	* tree-vect-patterns.cc (vect_mark_pattern_stmts): Try
	harder to find a reduction continuation.

	* gcc.dg/vect/pr121758.c: New testcase.
2025-09-03 13:02:35 +02:00
Alice Carlotti b905810be2 MAINTAINERS: Add myself as an aarch64 port reviewer
Changelog:

	* MAINTAINERS: Add myself as an aarch64 port reviewer.
2025-09-03 11:18:16 +01:00
Jonathan Wakely 0bb0d1d288 libstdc++: Make CTAD ignore pair(const T1&, const T2&) constructor [PR110853]
For the pair(T1, T2) explicit deduction type to decay its arguments as
intended, we need the pair(const T1&, const T2&) constructor to not be
used for CTAD. Otherwise we try to instantiate pair<T1, T2> without
decaying, which is ill-formed for function lvalues.

Use std::type_identity_t<T1> to make the constructor unusable for an
implicit deduction guide.

libstdc++-v3/ChangeLog:

	PR libstdc++/110853
	* include/bits/stl_pair.h [C++20] (pair(const T1&, const T2&)):
	Use std::type_identity_t<T1> for first parameter.
	* testsuite/20_util/pair/cons/110853.cc: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-03 10:49:12 +01:00
Jonathan Wakely 381dbd4a95 libstdc++: Restore C++20 <chrono> support for old std::string ABI
The r16-3416-g806de30f51c8b9 change to use __cpp_lib_chrono in
preprocessor conditions broke support for <chrono> for freestanding and
the COW std::string ABI. That happened because __cpp_lib_chrono is only
defined to the C++20 value for hosted and for the new ABI, because the
full set of C++20 features are not defined for freestanding and tzdb is
not defined for the old ABI.

This introduces a new internal feature test macro that corresponds to
the features that are always supported (e.g. chrono::local_time,
chrono::year, chrono::weekday).

libstdc++-v3/ChangeLog:

	* include/bits/version.def (chrono_cxx20): Define.
	* include/bits/version.h: Regenerate.
	* include/std/chrono: Check __glibcxx_chrono_cxx20 instead of
	__cpp_lib_chrono for C++20 features that don't require the new
	std::string ABI and/or can be used for freestanding.
	* src/c++20/clock.cc: Adjust preprocessor condition.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-03 10:49:06 +01:00
Andrew Pinski 9f94029829 fold: Unwrap MEM_REF after get_inner_reference in split_address_to_core_and_offset [PR121355]
Inside split_address_to_core_and_offset, this calls get_inner_reference.

Take:
```
  _6 = t_3(D) + 12;
  _8 = &MEM[(struct s1 *)t_3(D) + 4B].t;
  _1 = _6 - _8;
```

On the assignement of _8, get_inner_reference will return `MEM[(struct s1 *)t_3(D) + 4B]`
and an offset but that does not match up with `t_3(D)` which is how split_address_to_core_and_offset
handles pointer plus.
So this patch adds the unwrapping of the MEM_REF after the call to get_inner_reference
and have it act like a pointer plus.

Changes since v1:
* v2: Remove check on operand 1 for poly_int_tree_p, it is always.
      Add before the check to see if it fits in shwi instead of after.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/121355

gcc/ChangeLog:

	* fold-const.cc (split_address_to_core_and_offset): Handle an MEM_REF after the call
	to get_inner_reference.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-03 00:01:26 -07:00
GCC Administrator 23d5056310 Daily bump. 2025-09-03 00:20:18 +00:00
Andrew Pinski 97e77f567c Move the folding of memcmpy to memcmpy_eq to fold all builtins
This is a small cleanup by moving the optimization of memcmp to
memcmp_eq to fab from strlen pass. Since the copy of the other
part of the memcmp strlen optimization to forwprop, this was the
only thing left that strlen can do memcmp.

Note this move will cause memcmp_eq to be used for -Os too.

It also removes the optimization from strlen since both are now
handled elsewhere.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-ccp.cc (optimize_memcmp_eq): New function.
	(pass_fold_builtins::execute): Call optimize_memcmp_eq
	for memcmp.
	* tree-ssa-strlen.cc (strlen_pass::handle_builtin_memcmp): Remove.
	(strlen_pass::check_and_optimize_call): Don't call handle_builtin_memcmp.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-02 14:36:53 -07:00
Andrew Pinski caa1c2f426 strlen: Fixup load alignment for memcmp
Like the previous commit but for strlen copy so we can backport
this commit. The loads should have the correct alignment on them
so we need to create newly aligned types when the alignment of the
pointer is less than the alignment of the current type.

Pushed as pre-approved by https://gcc.gnu.org/pipermail/gcc-patches/2025-September/694016.html
after a bootstrap/test on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-strlen.cc (strlen_pass::handle_builtin_memcmp): Create
	unaligned types if the alignment of the pointers is less
	than the alignment of the new type.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-02 14:06:14 -07:00
Andrew Pinski a6e0a610e6 forwprop: Fix alignment of types in expansion of memcmp
I noticed that when looking into g++.dg/tree-ssa/vector-compare-1.C
failure on arm, the wrong alignment was being used for the load.
There needs to be an unaligned type here to get the correct alignment.

NOTE this means the code in strlen is also wrong but that is on its way
out so I am not sure if we should update it or not to backport to the
release branches; there could be wrong code happening too.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (simplify_builtin_memcmp): Create
	unaligned types if the alignment of the pointers is less
	than the alignment of the new type.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-02 14:06:14 -07:00
Paul Thomas f7dee170ba Fortran: Allow PDT parameterized procedure pointer components [PR89707]
2025-09-02  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/89707
	* decl.cc (gfc_get_pdt_instance): Copy the typebound procedure
	field from the PDT template. If the template interface has
	kind=0, provide the new instance with an interface with a type
	spec that points to that of the parameterized component.
	(match_ppc_decl): When 'saved_kind_expr' this is a PDT and the
	expression should be copied to the component kind_expr.
	* gfortran.h: Define gfc_get_tbp.

gcc/testsuite/
	PR fortran/89707
	* gfortran.dg/pdt_43.f03: New test.
2025-09-02 21:51:33 +01:00
Paul Thomas 2d93be8907 Fortran: Handle PDTs correctly with unlimited selector [PR87669]
2025-09-02  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/87669
	* expr.cc (gfc_spec_list_type): If no LEN components are seen,
	unconditionally return 'SPEC_ASSUMED'. This suppresses an
	invalid error in match.cc(gfc_match_type_is).

gcc/testsuite/
	PR fortran/87669
	* gfortran.dg/pdt_42.f03: New test.

libgfortran/
	PR fortran/87669
	* intrinsics/extends_type_of.c (is_extension_of): Use the vptr
	rather than the hash value to identify the types.
2025-09-02 21:48:55 +01:00
Richard Earnshaw 4ce7722c02 arm: testsuite: improve test compatibility of asm-hard-reg-... tests
On arm, overriding -march can lead to warnings if the testsuite
options try to pass -mcpu.  Avoid these by ensuring the -mcpu is unset
before adding the architecture.

Also, improve the compatibility of asm-hard-reg-error-3.c for
hard-float environment by allowing FP instructions in the
architecture.

gcc/testsuite:

	* gcc.dg/asm-hard-reg-4.c: On Arm, unset the CPU before
	setting the arch.
	* gcc.dg/asm-hard-reg-error-3.c: Similarly.  Also add
	floating-point instructions to aid hard-float variants.
	Match on arm* not just arm.
2025-09-02 17:20:16 +01:00
Richard Biener edeb5b8258 tree-optimization/121753 - ICE with pattern breaking reduction constraints
The recent change to vect_synth_mult_by_constant missed to handle
the synth_shift_p case for alg_shift, so we still changed c * 4
to c + c + c + c.  The following also amends alg_add_t2_m, alg_sub_t2_m,
alg_add_factor and alg_sub_factor appropriately.

	PR tree-optimization/121753
	* tree-vect-patterns.cc (vect_synth_mult_by_constant): Properly
	bail when synth_shift_p and an alg_shift use.  Handle other
	problematic cases.
2025-09-02 18:14:13 +02:00
Robin Dapp 9bbf0996bf RISC-V: Fix is_vlmax_len_p and use for strided ops.
This patch changes is_vlmax_len_p to handle VLS modes properly.

Before we would check if len == GET_MODE_NUNITS (mode).  This works vor
VLA modes but not necessarily for VLS modes.  We regularly have e.g.
small VLS modes where LEN equals their number of units but which do not
span a full vector.  Therefore now check if len * GET_MODE_UNIT_SIZE
(mode) equals BYTES_PER_RISCV_VECTOR * TARGET_MAX_LMUL.

Changing this uncovered an oversight in avlprop where we used
GET_MODE_NUNITS as AVL when GET_MODE_NUNITS / NF would be correct.

The testsuite is unchanged.  I didn't bother to add a dedicated test
because we would have seen the fallout any way once the gather patch
lands.

gcc/ChangeLog:

	* config/riscv/riscv-v.cc (is_vlmax_len_p): Properly handle VLS
	modes.
	(imm_avl_p): Fix VLS length check.
	(expand_strided_load): Use is_vlmax_len_p.
	(expand_strided_store): Ditto.
	* config/riscv/riscv-avlprop.cc (pass_avlprop::execute):
	Use GET_MODE_NUNITS / NF as avl.
2025-09-02 17:24:40 +02:00
Robin Dapp f957d352bd RISC-V: Handle overlap in expand_vec_perm PR121742.
In a two-source gather we unconditionally overwrite target with the
first gather's result already.  If op1 == target this clobbers the
source operand for the second gather.  This patch uses a temporary in
that case.

	PR target/121742

gcc/ChangeLog:

	* config/riscv/riscv-v.cc (expand_vec_perm): Use temporary if
	op1 and target overlap.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/pr121742.c: New test.
2025-09-02 17:24:34 +02:00
Andrew Stubbs 6e0590ba45 docs: Add NoOffload option flag to the internals manual
The NoOffload flag was introduced recently (commit "Don't pass vector params
through to offload targets").

gcc/ChangeLog:

	* doc/options.texi: Document NoOffload.
2025-09-02 15:10:25 +00:00
Jakub Jelinek a41d8edf30 s390: Adjust s390/spaceship-fp-*.c tests for recent changes
In r16-3414 libstdc++ changed ABI for (still experimental C++20) and uses
unordered value -128 instead of 2.  Generally the change improved code
generation on all targets tested, see
https://gcc.gnu.org/pipermail/gcc-patches/2025-August/693534.html
for details.
In r16-3474 I've adjusted the middle-end and backends to use that value.
This apparently broke the gcc.target/s390/spaceship-fp-2.c test,
with -ffast-math the 2 value is unreachable and so the .SPACESHIP last
argument in that case is the default, which changed from 2 to -128.
But spaceship-fp-1.c test also doesn't test what libstdc++ uses anymore,
so the following patch uses -128 in all the spots.

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

	* gcc.target/s390/spaceship-fp-1.c: Expect .SPACESHIP call with
	-128 as last argument instead of 2.
	(TEST): Use -128 instead of 2.
	* gcc.target/s390/spaceship-fp-2.c: Expect .SPACESHIP call with
	-128 as last argument instead of 2.
	(TEST): Use -128 instead of 2.
2025-09-02 17:02:52 +02:00
Iain Sandoe ff9e44ee31 c++, contracts: Simplify contracts headers [NFC].
We have contracts-related declarations and macros split between contracts.h
and cp-tree.h, and then contracts.h is included in the latter, which means
that it is included in all c++ front end files.

This patch:
 - moves all the contracts-related material to contracts.h.
 - makes some functions that are only used in contracts.cc static.
 - tries to group the external API for contracts into related topics.
 - includes contracts.h in the front end sources that need it.

gcc/cp/ChangeLog:

	* constexpr.cc: Include contracts.h
	* coroutines.cc: Likewise.
	* cp-gimplify.cc: Likewise.
	* decl.cc: Likewise.
	* decl2.cc: Likewise.
	* mangle.cc: Likewise.
	* module.cc: Likewise.
	* pt.cc: Likewise.
	* search.cc: Likewise.
	* semantics.cc: Likewise.
	* contracts.cc (validate_contract_role, setup_default_contract_role,
	add_contract_role, get_concrete_axiom_semantic,
	get_default_contract_role): Make static.
	* cp-tree.h (make_postcondition_variable, grok_contract,
	finish_contract_condition, find_contract, set_decl_contracts,
	get_contract_semantic, set_contract_semantic): Move to contracts.h.
	* contracts.h (get_contract_role, add_contract_role,
	validate_contract_role, setup_default_contract_role,
	lookup_concrete_semantic, get_default_contract_role): Remove.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-09-02 16:01:33 +01:00
Iain Sandoe 2552c73c7c D, Darwin, Powerpc: Fix build error.
osthread.d is trying to use PPC_THREAD_STATE32 which is not defined
in thread_act.d (PPC_THREAD_STATE is defined for the 32b case).  This
leads to a build fail for libdruntime.

libphobos/ChangeLog:

	* libdruntime/core/thread/osthread.d: Use PPC_THREAD_STATE
	instead of PPC_THREAD_STATE32.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-09-02 15:57:33 +01:00
Jiawei b839cac4d6 RISC-V: Add Zbb extension sext testcase.
This patch update RISC-V Zba extension 'sext' instructions generation.
Supplemented the instruction generation detection of 'sext.h' and
'sext.b'.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/zbb-sext.c: New test.
2025-09-02 07:51:54 -06:00
Jiawei 0ffe59c0b9 RISC-V: Update Zba 'shNadd.uw' testcase.`
This patch update RISC-V Zba extension 'shNadd.uw' instruction generation.
Supplemented the instruction generation detection of 'sh1add.uw' and
'sh3add.uw'.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/zba-shadd.c: New test functions.
2025-09-02 07:49:47 -06:00
Luc Grosheintz dea668daa2 libstdc++: Move _Index_tuple, _Build_index_tuple to <type_traits>.
As preparation for implementing std::constant_wrapper that's part of the
C++26 version of the <type_traits> header, the two classes _Index_tuple
and _Build_index_tuple are moved to <type_traits>. These two helpers are
needed by std::constant_wrapper to initialize the elements of one C
array with another.

Since, <bits/utility.h> already includes <type_traits> this solution
avoids creating a very small header file for just these two internal
classes. This approach doesn't move std::index_sequence and related code
to <type_traits> and therefore doesn't change which headers provide
user-facing features.

libstdc++-v3/ChangeLog:

	* include/bits/utility.h (_Index_tuple): Move to <type_traits>.
	(_Build_index_tuple): Ditto.
	* include/std/type_traits (_Index_tuple): Ditto.
	(_Build_index_tuple): Ditto.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-09-02 13:27:45 +02:00
Rainer Orth cfc9a42e8b testsuite: i386: Fix gcc.target/i386/memset-strategy-1[03].c on Solaris/x86
The new gcc.target/i386/memset-strategy-1[03].c tests FAIL on
Solaris/x86:

FAIL: gcc.target/i386/memset-strategy-10.c check-function-bodies foo
FAIL: gcc.target/i386/memset-strategy-13.c check-function-bodies foo

The issue is the same as several times previously: they need to be
compiled with -fasynchronous-unwind-tables -fdwarf2-cfi-asm, which this
patch does.

Tested on i386-pc-solaris2.11 (as and gas) and x86_64-pc-linux-gnu.

2025-09-01  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gcc/testsuite:
	* gcc.target/i386/memset-strategy-10.c (dg-options): Add
	-fasynchronous-unwind-tables -fdwarf2-cfi-asm.
	* gcc.target/i386/memset-strategy-13.c: Likewise.
2025-09-02 13:19:00 +02:00
Richard Biener 3f868fb150 Restore STMT_VINFO_VECTYPE during analysis, set to NULL for all stmts
The following makes vect_analyze_stmt call vectorizable_* with all
STMT_VINFO_VECTYPE NULL_TREE but restores the value for eventual
iteration with single-lane SLP.  It clears it for every stmt during
vect_transform_stmt.

	* tree-vect-stmts.cc (vect_transform_stmt): Clear
	STMT_VINFO_VECTYPE for all stmts.
	(vect_analyze_stmt): Likewise.  But restore at the end again.
2025-09-02 12:53:08 +02:00
Richard Biener 861b7c054e tree-optimization/121754 - ICE with vect_reduc_type and nested cycle
The reduction guard isn't correct, STMT_VINFO_REDUC_DEF also exists
for nested cycles not part of reductions but there's no reduction
info for them.

	PR tree-optimization/121754
	* tree-vectorizer.h (vect_reduc_type): Simplify to not ICE
	on nested cycles.

	* gcc.dg/vect/pr121754.c: New testcase.
	* gcc.target/aarch64/vect-pr121754.c: Likewise.
2025-09-02 12:51:12 +02:00
Richard Biener 0b6f1de05e Avoid touching STMT_VINFO_VECTYPE in bump_vector_ptr
bump is always specified, so remove the STMT_VINFO_VECTYPE touching
path.

	* tree-vect-data-refs.cc (bump_vector_ptr): Remove the
	STMT_VINFO_VECTYPE use, bump is always specified.
2025-09-02 12:51:12 +02:00
Richard Biener d5b1baa7f2 Pass vectype to vect_check_gather_scatter
The strided-store path needs to have the SLP trees vector type so
the following patch passes dowm the vector type to be used to
vect_check_gather_scatter and adjusts all other callers.  This
removes one of the last pieces requiring STMT_VINFO_VECTYPE
during SLP stmt analysis.

	* tree-vectorizer.h (vect_check_gather_scatter): Add
	vectype parameter.
	* tree-vect-data-refs.cc (vect_check_gather_scatter): Get
	vectype as parameter.
	(vect_analyze_data_refs): Adjust.
	* tree-vect-patterns.cc (vect_recog_gather_scatter_pattern): Likewise.
	* tree-vect-slp.cc (vect_get_and_check_slp_defs): Get vectype
	as parameter, pass down.
	(vect_build_slp_tree_2): Adjust.
	* tree-vect-stmts.cc (vect_mark_stmts_to_be_vectorized): Likewise.
	(vect_use_strided_gather_scatters_p): Likewise.
2025-09-02 12:51:12 +02:00
Tomasz Kamiński d9a4c7158a libstdc++: Rename __cmp_cat::__unspec to __cmp_cat::__literal_zero.
This slightly improve the readability of error message, by suggesting
that 0 (literal) is expected as argument:
  invalid conversion from 'int' to 'std::__cmp_cat::__literal_zero*'

libstdc++-v3/ChangeLog:

	* libsupc++/compare (__cmp_cat::__literal_zero): Rename
	from __unspec.
	(__cmp_cat::__unspec): Rename to __literal_zero.
	(operator==, operator<, operator>, operator<=, operator>=):
	Replace __cmp_cat::__unspec to __cmp_cat::__literal_zero.
2025-09-02 12:47:43 +02:00
Jonathan Wakely 1aa755f51a doc: Fix sort order for counted_by attribute
gcc/ChangeLog:

	* doc/extend.texi (Common Variable Attributes): Put counted_by
	in alphabetical order.
2025-09-02 11:22:44 +01:00
Jakub Jelinek 5440f4ceee tree-cfg: Fix up assign_discriminator ICE with too large #line [PR121663]
As mentioned in the PR, LOCATION_LINE is represented in an int,
and while we have -pedantic diagnostics (and -pedantic-error error)
for too large #line, we can still overflow into negative line
numbers up to -2 and -1.  We could overflow to that even with valid
source if it says has #line 2147483640 and then just has
2G+ lines after it.
Now, the ICE is because assign_discriminator{,s} uses a hash_map
with int_hash <int64_t, -1, -2>, so values -2 and -1 are reserved
for deleted and empty entries.  We just need to make sure those aren't
valid.  One possible fix would be just that
-  discrim_entry &e = map.get_or_insert (LOCATION_LINE (loc), &existed);
+  discrim_entry &e
+    = map.get_or_insert ((unsigned) LOCATION_LINE (loc), &existed);
by adding unsigned cast when the key is signed 64-bit, it will never
be -1 or -2.
But I think that is wasteful, discrim_entry is a struct with 2 unsigned
non-static data members, so for lines which can only be 0 to 0xffffffff
(sure, with wrap-around), I think just using a hash_map with 96bit elts
is better than 128bit.
So, the following patch just doesn't assign any discriminators for lines
-1U and -2U, I think that is fine, normal programs never do that.
Another possibility would be to handle lines -1U and -2U as if it was say
-3U.

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

	PR middle-end/121663
	* tree-cfg.cc (assign_discriminator): Change map argument type
	from hash_map with int_hash <int64_t, -1, -2> to one with
	int_hash <unsigned, -1U, -2U>.  Cast LOCATION_LINE to unsigned.
	Return early for (unsigned) LOCATION_LINE above -3U.
	(assign_discriminators): Change map type from hash_map with
	int_hash <int64_t, -1, -2> to one with int_hash <unsigned, -1U, -2U>.

	* gcc.dg/pr121663.c: New test.
2025-09-02 12:18:52 +02:00
Rainer Orth 13eee16e92 testsuite: Fix gcc.dg/tree-ssa/cswtch-[67].c on Solaris/SPARC with as
The gcc.dg/tree-ssa/cswtch-[67].c tests FAIL on Solaris/SPARC with the
native as:

FAIL: gcc.dg/tree-ssa/cswtch-6.c scan-assembler .rodata.cst16
FAIL: gcc.dg/tree-ssa/cswtch-7.c scan-assembler .rodata.cst32

The issue is the same in both cases: compared to the gas version, with
as there's only

-	.section	.rodata.cst32,"aM",@progbits,32
+	.section	".rodata"

It turns out that varasm.c (mergeable_constant_section) only emits the
former if HAVE_GAS_SHF_MERGE, which is 0 with the native as.

Fixed by xfailing the tests in this case.

Tested on sparc-sun-solaris2.11 with both as and gas.

2025-07-30  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gcc/testsuite:
	* gcc.dg/tree-ssa/cswtch-6.c (dg-final): xfail on
	sparc*-*-solaris2* && !gas.
	* gcc.dg/tree-ssa/cswtch-7.c: Likewise.
2025-09-02 09:28:40 +02:00
Kito Cheng a1fe3311dd RISC-V: Remove unused print_ext_doc_entry function [NFC]
The print_ext_doc_entry function and associated version_t struct in
gen-riscv-ext-opt.cc were not being used anywhere in the codebase.
Remove them to clean up the code.

gcc/
	* config/riscv/gen-riscv-ext-opt.cc (version_t): Remove unused
	struct.
	(print_ext_doc_entry): Remove unused function.
2025-09-02 11:10:30 +08:00
Andrew Pinski db195c5381 Testsuite: Don't test vector-compare-1.C on strict alignment targets
This testcase will fail on strict alignment targets due to
the requirement of doing a possible unaligned load. This fixes
that.

Note this testcase still fails on arm (and maybe riscv) targets while
having unaligned loads, they have slow ones.

Pushed as obvious after testing on x86_64-linux-gnu to make sure it
is still testing.

gcc/testsuite/ChangeLog:

	* g++.dg/tree-ssa/vector-compare-1.C: Restrict to
	non_strict_align targets.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-01 17:25:53 -07:00
GCC Administrator 6adf8e424d Daily bump. 2025-09-02 00:19:26 +00:00
Jonathan Grant 217008f737 install: Fix spelling of "support" and "arithmetic"
gcc:
	* doc/install.texi (Configuration): Fix spelling of "support"
	and "floating-point arithmetic".

Signed-off-by: Jonathan Grant <jg@jguk.org>
2025-09-01 23:55:08 +01:00
Mark Harmstone 3b3f336af2 Fix assertion when trying to represent Ada arrays in CodeView
The LF_ARRAY CodeView type represents a C- or C++-style array, which a
length known at compile time. We were crashing when using -gcodeview
with Ada (bug #121157), as the DW_AT_upper_bound value is not an
unsigned integer but something more complicated:

0x00000123:   DW_TAG_array_type
                DW_AT_type      (0x0000014d "character")
                DW_AT_sibling   (0x00000142)

0x0000012c:     DW_TAG_subrange_type
                  DW_AT_type    (0x00000142 "integer")
                  DW_AT_lower_bound     (DW_OP_push_object_address, DW_OP_plus_uconst 0x8, DW_OP_deref, DW_OP_deref_size 0x4)
                  DW_AT_upper_bound     (DW_OP_push_object_address, DW_OP_plus_uconst 0x8, DW_OP_deref, DW_OP_plus_uconst 0x4, DW_OP_deref_size 0x4)

It doesn't look like we can represent Ada arrays in CodeView, so return
0 in get_type_num_array_type so that they come through as an unknown
type.

gcc/
	* dwarf2codeview.cc (get_type_num_array_type): Don't try to
	encode non-C-style arrays.
2025-09-01 21:58:44 +01:00
Gerald Pfeifer 7095465952 maintainer-scripts: Improve syncing of libstdc++ docs
rsync generally is a more commonly used tool for syncing data - among
others it retains time stamps and is able to remove orphaned files on
the receiver side.

We just need to exclude some directories and a symlink from being
removed as "orphaned", since they originate elsewhere.

maintainer-scripts:
	* update_web_docs_libstdcxx_git: Copy our "inner" documentation
	into the web area using rsync instead of cpio and remove orphaned
	files.
2025-09-01 20:58:02 +01:00
Jakub Jelinek a4d066f364 c: Implement C2Y N3457 - The __COUNTER__ predefined macro
The following patch implements the
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3457.htm
paper without the first 3 lines in Recommended practice.
Seems GCC behavior already matches the expected behavior except for
diagnostics of more than 2147483648 __COUNTER__ expansions, so the
patch adds a diagnostic for that (but not testcase because
 #define A __COUNTER__ __COUNTER__ __COUNTER__ __COUNTER__ __COUNTER__ __COUNTER__ __COUNTER__ __COUNTER__
 #define B A A A A A A A A
 #define C B B B B B B B B
 #define D C C C C C C C C
 #define E D D D D D D D D
 #define F E E E E E E E E
 #define G F F F F F F F F
 #define H G G G G G G G G
 #define I H H H H H H H H
 #define J I I I I I I I I
 J J J J
 __COUNTER__
just takes too long to preprocess).
Plus I've included all the snippets from the paper into one testcase.

2025-09-01  Jakub Jelinek  <jakub@redhat.com>

	* macro.cc: Implement C2Y N3457 - The __COUNTER__ predefined macro.
	(_cpp_builtin_macro_text): Diagnose if __COUNTER__ reaches
	2147483648 value.

	* gcc.dg/cpp/c2y-counter-1.c: New test.
2025-09-01 21:55:49 +02:00
Jakub Jelinek 086d0d8c9c c: Rename uimaxabs to umaxabs
The following patch implements
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3577.txt
No big deal on the GCC side, for uimaxabs we just won't
recognize it as builtin and I don't see it worth preserving
__builtin_uimaxabs, I doubt anything but gcc testsuite used
that.
But on the glibc side I think it will need to remain exported
for ABI compatibility :(

2025-09-01  Jakub Jelinek  <jakub@redhat.com>

	* builtins.def: Implement C2Y N3577 - Rename s/uimaxabs/umaxabs/.
	(BUILT_IN_UIMAXABS): Rename to ...
	(BUILT_IN_UMAXABS): ... this.  Change second argument to "umaxabs".
	* builtins.cc (fold_builtin_1): Use BUILT_IN_UMAXABS rather than
	BUILT_IN_UIMAXABS.

	* gcc.c-torture/execute/builtins/lib/abs.c (uimaxabs): Rename to ...
	(umaxabs): ... this.
	* gcc.c-torture/execute/builtins/uabs-2.c (uimaxabs): Rename to ...
	(umaxabs): ... this.
	(main_test): Use umaxabs instead of uimaxabs.
	* gcc.c-torture/execute/builtins/uabs-3.c (main_test): Use umaxabs
	instead of uimaxabs.
2025-09-01 21:55:17 +02:00
Harald Anlauf 082483dd79 Fortran: truncate constant string passed to character,value dummy [PR121727]
PR fortran/121727

gcc/fortran/ChangeLog:

	* trans-expr.cc (gfc_const_length_character_type_p): New helper
	function.
	(conv_dummy_value): Use it to determine if a character actual
	argument has a constant length.  If a character actual argument is
	constant and longer than the dummy, truncate it at compile time.

gcc/testsuite/ChangeLog:

	* gfortran.dg/value_10.f90: New test.
2025-09-01 21:51:17 +02:00
Gerald Pfeifer 188be0dff0 doc: Update perfwiki web address
gcc:
	* doc/invoke.texi (Optimize Options): Update the perfwiki web
	address.
2025-09-01 20:46:17 +01:00
Iain Sandoe f852d2b010 diagnostics: Fix bootstrap fail on Darwin 32b hosts.
The use of HOST_SIZE_T_PRINT_HEX needs to be paired with a c-style
cast to (fmt_size_t) otherwise the detection mechanisms in hwint.h
are not sufficient to deal with size_t defined as 'long unsigned int'
which is done on Darwin (and I think on Windows).

This patch just makes that update.

gcc/ChangeLog:

	* diagnostics/logging.h (log_param_location_t): Cast
	location_t value to fmt_size_t.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-09-01 19:17:13 +01:00
Iain Sandoe 4a84a19674 configure, Darwin: Do not claim .cfi_xxx instruction support.
While the assemblers used by Darwin that are based on LLVM, do
support .cfi_ instructions, their use triggers production of
compact unwind which currently does not interwork properly with
GCC's output.

When the system objdump is used in the configure process this is
currently working by good fortune (the objdump does not recognise
the command and we fail to detect the cfi_advance.

However, if a user has binutils objdump earlier in thier PATH then
we will detect support and try to use .cfi_ which will cause later
and hard-to-diagnose issues.

Until we have this resolved, force cfi instruction use off for
Darwin.

gcc/ChangeLog:

	* configure: Regenerate.
	* configure.ac: Do not claim cfi instruction support even
	if the assembler has it.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-09-01 19:13:42 +01:00
Yoshinori Sato 7132990774 PR target/89828 Inernal compiler error on "-fno-omit-frame-pointer"
The problem was caused by an erroneous note about creating a stack frame,
which caused the cur_cfa reg to fail to assert with a value other than
the frame pointer.

This fix will generate notes that correctly update cur_cfa.

v2 changes.
Add testcase.
All tests that failed with
"internal compiler error: in dwarf2out_frame_debug_adjust_cfa, at dwarf2cfi.cc"
now pass.

	PR target/89828
gcc
	* config/rx/rx.cc (add_pop_cfi_notes): Release the frame pointer if it is
	used.
	(rx_expand_prologue): Redesigned stack pointer and frame pointer update
	process.

gcc/testsuite/
	* gcc.dg/pr89828.c: New.
2025-09-01 11:13:32 -06:00
Andi Kleen cf7dc77ac2 Add default arch/tuning to shift-gf2p8affine test cases
This makes them not fail during test suite runs with overriden arch or
tunings.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/shift-gf2p8affine-1.c: Use -march=x86-64
	-mtune-generic.
	* gcc.target/i386/shift-gf2p8affine-2.c: Dito.
	* gcc.target/i386/shift-gf2p8affine-3.c: Dito.
	* gcc.target/i386/shift-gf2p8affine-5.c: Dito.
	* gcc.target/i386/shift-gf2p8affine-6.c: Dito.
	* gcc.target/i386/shift-gf2p8affine-7.c: Dito.
2025-09-01 08:22:27 -07:00
Christophe Lyon 32d3f5744a testsuite: arm: factorize arm_v8_neon_ok flags
Like we do in other effective-targets, add
"-mcpu=unset -march=armv8-a"
directly when setting et_arm_v8_neon_flags in arm_v8_neon_ok_nocache,
to avoid having to add these two flags in all users of arm_v8_neon_ok.

This avoids duplication and possible typos / oversights.

gcc/testsuite/ChangeLog:
	* lib/target-supports.exp
	(check_effective_target_arm_v8_neon_ok_nocache): Add "-mcpu=unset
	-march=armv8-a" to et_arm_v8_neon_flags.
	(add_options_for_vect_early_break): Remove useless "-mcpu=unset
	-march=armv8-a".
	(add_options_for_arm_v8_neon): Likewise.
2025-09-01 14:57:16 +00:00
Christophe Lyon 3cb6c01d2a testsuite: arm: remove arm32 check from a few effective-targets
A few arm effective-targets call check_effective_target_arm32 even
though they would force a -march=XXX flag which supports Arm and/or
Thumb-2, thus making the arm32 check useless.  This has an impact when
the toolchain is configured with a default -march or -mcpu which
supports Thumb-1 only: in such a case, arm32 is false and we skip many
tests, thus reducing coverage.

This patch removes the call to check_effective_target_arm32 where it
is useless, enabling about 2000 tests.

In addition, add an early exit if the target is not an arm one, thus
saving a few compilation cycles where not needed.  In all callers of
arm_neon_ok, remove the now useless "istarget arm*-*-*.

gcc/testsuite/ChangeLog:

	* lib/target-supports.exp
	(check_effective_target_arm_neon_ok_nocache): Remove arm32 check.
	Add istarget arm*-*-* check.
	(check_effective_target_arm_neon_fp16_ok_nocache): Likewise.
	(check_effective_target_arm_neon_softfp_fp16_ok_nocache): Likewise.
	(check_effective_target_arm_v8_neon_ok_nocache): Likewise.
	(check_effective_target_arm_neonv2_ok_nocache): Likewise.
	(check_effective_target_vect_pack_trunc): Remove istarget arm*-*-*
	check.
	(check_effective_target_vect_unpack): Likewise.
	(check_effective_target_vect_condition): Likewise.
	(check_effective_target_vect_cond_mixed): Likewise.
	(available_vector_sizes): Likewise.
2025-09-01 14:56:43 +00:00
Richard Biener 20cd438f2f tree-optimization/121744 - handle CST << var in shift pattern recog
We currently do not handle promotion/demotion of 'var' when the
left operand of a variable shift is constant.  There's no good
reason why, so the following fixes this omission.

	PR tree-optimization/121744
	* tree-vect-patterns.cc (vect_recog_vector_vector_shift_pattern):
	Allow constant left operand.

	* gcc.dg/vect/pr121744-1.c: New testcase.
2025-09-01 15:18:17 +02:00
Richard Biener 7dff87e0f5 Eliminate some STMT_VINFO_REDUC_IDX for SLP_TREE_REDUC_IDX
The following uses SLP_TREE_REDUC_IDX where it looks more appropriate.

	* tree-vect-loop.cc (vect_create_epilog_for_reduction):
	Use SLP_TREE_REDUC_IDX for following the SLP graph and
	for identifying whether we use the 'else' in a COND.
	(vectorizable_lane_reducing): Simplify check of whether
	we are in a reduction.
	(vectorizable_reduction): Add sanity checking around
	SLP_TREE_REDUC_IDX and use it where it looks appropriate.
	(vect_transform_reduction): Use SLP_TREE_REDUC_IDX.
	* tree-vect-stmts.cc (vectorizable_call): Likewise.
	(vectorizable_operation): Likewise.
	(vectorizable_condition): Likewise.
2025-09-01 14:04:25 +02:00
Richard Biener 3b83232c67 Remove no longer needed STMT_VINFO_REDUC_DEF sets
The following removes no longer needed extra sets of STMT_VINFO_REDUC_DEF
and replaces a single remaining one with a more appropriate check.

	* tree-vect-loop.cc (vectorizable_live_operation): Check
	vect_is_reduction on the SLP node rather than
	STMT_VINFO_REDUC_DEF on the stmt.
	(vectorizable_reduction): Do not set STMT_VINFO_REDUC_DEF
	on live stmts.
2025-09-01 14:04:24 +02:00
Richard Biener b3355804c7 Introduce abstraction for vect reduction info, tracked from SLP nodes
While we have already the accessor info_for_reduction, its result
is a plain stmt_vec_info.  The following turns that into a class
for the purpose of changing accesses to reduction info to a new
set of accessors prefixed with VECT_REDUC_INFO and removes
the corresponding STMT_VINFO prefixed accessors where possible.

There is few reduction related things that are used by scalar
cycle detection and thus have to stay as-is for now and as
copies in future.

This also separates reduction info into one object per reduction
and associate it with SLP nodes, splitting it out from
stmt_vec_info, retaining (and duplicating) parts used by scalar
cycle analysis.  The data is then associated with SLP nodes
forming reduction cycles and accessible via info_for_reduction.
The data is created at SLP discovery time as we look at it even
pre-vectorizable_reduction analysis, but most of the data is
only populated by the latter.  There is no reduction info with
nested cycles that are not part of an outer reduction.
In the process this adds cycle info to each SLP tree, notably
the reduc-idx and a way to identify the reduction info.

	* tree-vectorizer.h (vect_reduc_info): New.
	(create_info_for_reduction): Likewise.
	(VECT_REDUC_INFO_TYPE): Likewise.
	(VECT_REDUC_INFO_CODE): Likewise.
	(VECT_REDUC_INFO_FN): Likewise.
	(VECT_REDUC_INFO_SCALAR_RESULTS): Likewise.
	(VECT_REDUC_INFO_INITIAL_VALUES): Likewise.
	(VECT_REDUC_INFO_REUSED_ACCUMULATOR): Likewise.
	(VECT_REDUC_INFO_INDUC_COND_INITIAL_VAL): Likewise.
	(VECT_REDUC_INFO_EPILOGUE_ADJUSTMENT): Likewise.
	(VECT_REDUC_INFO_FORCE_SINGLE_CYCLE): Likewise.
	(VECT_REDUC_INFO_RESULT_POS): Likewise.
	(VECT_REDUC_INFO_VECTYPE): Likewise.
	(STMT_VINFO_VEC_INDUC_COND_INITIAL_VAL): Remove.
	(STMT_VINFO_REDUC_EPILOGUE_ADJUSTMENT): Likewise.
	(STMT_VINFO_FORCE_SINGLE_CYCLE): Likewise.
	(STMT_VINFO_REDUC_FN): Likewise.
	(STMT_VINFO_REDUC_VECTYPE): Likewise.
	(vect_reusable_accumulator::reduc_info): Adjust.
	(vect_reduc_type): Adjust.
	(_slp_tree::cycle_info): New member.
	(SLP_TREE_REDUC_IDX): Likewise.
	(vect_reduc_info_s): Move/copy data from ...
	(_stmt_vec_info): ... here.
	(_loop_vec_info::redcu_infos): New member.
	(info_for_reduction): Adjust to take SLP node.
	(vect_reduc_type): Adjust.
	(vect_is_reduction): Add overload for SLP node.
	* tree-vectorizer.cc (vec_info::new_stmt_vec_info):
	Do not initialize removed members.
	(vec_info::free_stmt_vec_info): Do not release them.
	* tree-vect-stmts.cc (vectorizable_condition): Adjust.
	* tree-vect-slp.cc (_slp_tree::_slp_tree): Initialize
	cycle info.
	(vect_build_slp_tree_2): Compute SLP reduc_idx and store
	it.  Create, populate and propagate reduction info.
	(vect_print_slp_tree): Print cycle info.
	(vect_analyze_slp_reduc_chain): Set cycle info on the
	manual added conversion node.
	(vect_optimize_slp_pass::start_choosing_layouts): Adjust.
	* tree-vect-loop.cc (_loop_vec_info::~_loop_vec_info):
	Release reduction infos.
	(info_for_reduction): Get the reduction info from
	the vector in the loop_vinfo.
	(vect_create_epilog_for_reduction): Adjust.
	(vectorizable_reduction): Likewise.
	(vect_transform_reduction): Likewise.
	(vect_transform_cycle_phi): Likewise, deal with nested
	cycles not part of a double reduction have no reduction info.
	* config/aarch64/aarch64.cc (aarch64_force_single_cycle):
	Use VECT_REDUC_INFO_FORCE_SINGLE_CYCLE, get SLP node and use
	that.
	(aarch64_vector_costs::count_ops): Adjust.
2025-09-01 14:04:24 +02:00
Tobias Burnus 42bcdfa5cb install.texi: For amdgcn, update Newlib version recommendation
Add two Newlib commits to the recommended Newlib version,
fixing two other SIMD issues.
Cf. PR target/121392 and Newlib Bug 33272.

gcc/ChangeLog:

	PR target/121392
	* doc/install.texi (amdgcn): Mention Newlib commit
	that fixes another SIMD issue.
2025-09-01 12:41:41 +02:00
Richard Biener 5f127979f3 Simplify vectorizer IV analysis
The following simplifies the flow of IV analysis a bit.

	* tree-vect-loop.cc (vect_is_simple_iv_evolution): Get
	stmt_info and store into STMT_VINFO_LOOP_PHI_EVOLUTION_BASE_UNCHANGED
	and STMT_VINFO_LOOP_PHI_EVOLUTION_PART here.  Drop unused
	output parameters.
	(vect_is_nonlinear_iv_evolution): Likewise.
	(vect_analyze_scalar_cycles_1): Remove redundant setting
	of STMT_VINFO_LOOP_PHI_EVOLUTION_BASE_UNCHANGED and
	STMT_VINFO_LOOP_PHI_EVOLUTION_PART.
2025-09-01 12:25:27 +02:00
Cui, Lili ae689f89fb ira: Remove soft conflict related code in improve_allocation. [PR117838]
The original intention of this code was to allow more allocnos
to share the same register, but this led to expensive allocno
overflows. Extracted a small case (a bit large, see Bugzilla
PR117838 for details) from 548.exchange2_r to analyze this
register allocation issue.

Before improve_allocation function:

a537 (cost 1896, reg42)
a20  (cost 270, reg1)
a13  (cost 144, spill)
a551 (cost 70, reg40)
a5   (cost 43, spill)
a493 (cost 30, reg42)
a499 (cost 12, reg40)

------------------------------
Dump info in improve_allocation function:

Base:
Spilling a493r125 for a5r113
Spilling a573r202 for a5r113
Spilling a499r248 for a13r106
Spilling a551r120 for a13r106
Spilling a20r237 for a551r120

With patch:
Spilling a499r248 for a13r106
Spilling a551r120 for a13r106
Spilling a493r125 for a551r120
------------------------------

After assign_hard_reg (at the end of improve_allocation):

Base:
a537 (cost 1896, reg1)
a20  (cost 270, spill) -----> This is unreasonable
a13  (cost 144, reg40)
a551 (cost 70, reg1)
a5   (cost 43, reg42)
a493 (cost 30, spill)
a499 (cost 12, reg1)

With patch:
a537 (cost 1896, reg42)
a20  (cost 270, reg1)
a13  (cost 144, reg40)
a551 (cost 70, reg42)
a5   (cost 43, spill)
a493 (cost 30, spill)
a499 (cost 12, reg42)
-----------------------------

Collected spec2017 performance on Znver3/Graviton4/EMR/SRF for O2 and Ofast.
No performance regression was observed.

FOR multi-copy O2
SRF: 548.exchange2_r increased by 7.5%, 500.perlbench_r increased by 2.0%.
EMR: 548.exchange2_r increased by 4.5%, 500.perlbench_r increased by 1.7%.
Graviton4: 548.exchange2_r Increased by 2.2%, 511.povray_r increased by 2.8%.
Znver3 : 500.perlbench_r increased by 2.0%.

gcc/ChangeLog:

	PR rtl-optimization/117838
	* ira-color.cc (improve_allocation): Remove soft conflict related code.
2025-09-01 14:35:59 +08:00
liuhongt 7c6fefedce Fix ICE due to wrong operand is passed to ix86_vgf2p8affine_shift_matrix.
1) Fix predicate of operands[3] in cond_<insn><mode> since only
const_vec_dup_operand is excepted for masked operations, and pass real
count to ix86_vgf2p8affine_shift_matrix.

2) Pass operands[2] instead of operands[1] to
gen_vgf2p8affineqb_<mode>_mask which excepted the operand to shifted,
but operands[1] is mask operand in cond_<insn><mode>.

gcc/ChangeLog:

	PR target/121699
	* config/i386/predicates.md (const_vec_dup_operand): New
	predicate.
	* config/i386/sse.md (cond_<insn><mode>): Fix predicate of
	operands[3], and fix wrong operands passed to
	ix86_vgf2p8affine_shift_matrix and
	gen_vgf2p8affineqb_<mode>_mask.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr121699.c: New test.
2025-08-31 21:43:23 -07:00
GCC Administrator a954b961d5 Daily bump. 2025-09-01 00:18:18 +00:00
Takayuki 'January June' Suwa 4553eccd23 xtensa: Optimize branch whether (reg:SI) is within/out the range handled by CLAMPS instruction
The CLAMPS instruction in Xtensa ISA, provided when the TARGET_CLAMPS
configuration is enabled (and also requires TARGET_MINMAX), returns a
value clamped the number in the specified register to between -(1<<N) and
(1<<N)-1 inclusive, where N is an immediate value from 7 to 22.

Therefore, when the above configurations are met, by comparing the clamped
result with the original value for equality, branching whether the value
is within the range mentioned above or not is implemented with fewer
instructions, especially when the upper and lower bounds of the range are
too large to fit into a single immediate assignment.

     /* example (TARGET_MINMAX and TARGET_CLAMPS) */
     extern void foo(void);
     void test0(int a) {
       if (a >= -(1 << 9) && a < (1 << 9))
         foo();
     }
     void test1(int a) {
       if (a < -(1 << 20) || a >= (1 << 20))
         foo();
     }

     ;; before
     test0:
     	entry	sp, 32
     	addmi	a2, a2, 0x200
     	movi	a8, 0x3ff
     	bltu	a8, a2, .L1
     	call8	foo
     .L1:
     	retw.n
     test1:
     	entry	sp, 32
     	movi.n	a9, 1
     	movi.n	a8, -1
     	slli	a9, a9, 20
     	srli	a8, a8, 11
     	add.n	a2, a2, a9
     	bgeu	a8, a2, .L4
     	call8	foo
     .L4:
     	retw.n

     ;; after
     test0:
     	entry	sp, 32
     	clamps	a8, a2, 9
     	bne	a2, a8, .L1
     	call8	foo
     .L1:
     	retw.n
     test1:
     	entry	sp, 32
     	clamps	a8, a2, 20
     	beq	a2, a8, .L4
     	call8	foo
     .L4:
     	retw.n

(note: Currently, in the RTL instruction combination pass, the possible
const_int values ​​are fundamentally constrained by
TARGET_LEGITIMATE_CONSTANT_P() if no bare large constant assignments are
possible (i.e., neither -mconst16 nor -mauto-litpools), so limiting N to
a range of 7 to only 10 instead of to 22.  A series of forthcoming
patches will introduce an entirely new "xt_largeconst" pass that will
solve several issues including this.)

gcc/ChangeLog:

	* config/xtensa/predicates.md (alt_ubranch_operator):
	New predicate.
	* config/xtensa/xtensa.md (*eqne_in_range):
	New insn_and_split pattern.
2025-08-31 16:39:01 -07:00
Paul Thomas d21f10259f Fortran: Pass PDTs to dummies with VALUE attribute [PR99709]
2025-08-31  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/99709
	* trans-array.cc (structure_alloc_comps): For the case
	COPY_ALLOC_COMP, do a deep copy of non-allocatable PDT arrays
	Suppress the use of 'duplicate_allocatable' for PDT arrays.
	* trans-expr.cc (conv_dummy_value): When passing to a PDT dummy
	with the VALUE attribute, do a deep copy to ensure that
	parameterized components are reallocated.

gcc/testsuite/
	PR fortran/99709
	* gfortran.dg/pdt_41.f03: New test.
2025-08-31 16:47:18 +01:00
Shreya Munnangi 095700c4cc [RISC-V] Improve initial RTL generation for SImode adds on rv64
So this is the next chunk of Shreya's work to adjust our add expanders. In this
patch we're adding support for adding a 2*s12 immediate in SI for rv64.

To recap, the basic idea is reduce our reliance on the define_insn_and_split
that was added a year or so ago by synthesizing the more efficient sequence at
expansion time.  By handling this early rather than late the synthesized
sequence participates in the various optimizer passes in the natural way.  In
contrast using the define_insn_and_split bypasses the cost modeling in combine
and hides the synthesis until after reload as completed (which in turn leads to
the problems seen in pr120811).

This doesn't solve pr120811, but it is the last prerequisite patch before
directly tackling pr120811.

This has been bootstrapped & regression tested on the pioneer & bpi and been
through the usual testing on riscv32-elf and riscv64-elf.  Waiting on
pre-commit CI before moving forward.

gcc/
	* config/riscv/riscv-protos.h (synthesize_add_extended): Prototype.
	* config/riscv/riscv.cc (synthesize_add_extended): New function.
	* config/riscv/riscv.md (addsi3): For RV64, try synthesize_add_extended.

gcc/testsuite/
	* gcc.target/riscv/add-synthesis-2.c: New test.
2025-08-31 07:48:21 -06:00
Gerald Pfeifer a4ec06656d install: Drop MinGW binaries download link
This has been unavailable for well over a year.

gcc:
	* doc/install.texi (Binaries): Drop MinGW.
2025-08-31 12:14:30 +02:00
Gerald Pfeifer 6094b4de7b libstdc++: Update link to Boost "Exception-Safety"
libstdc++-v3:
	* doc/xml/manual/using_exceptions.xml: Update link to
	Boost's "Exception-Safety"
	* doc/html/manual/using_exceptions.html: Rebuild.
2025-08-31 12:13:45 +02:00
Jonathan Wakely fb80a5f4c3 libstdc++: Fix bootstrap failures in src/c++26/debugging.cc
ptrace on Darwin requires <sys/types.h>.

The inline x86 asm doesn't work with the Solaris assembler.

libstdc++-v3/ChangeLog:

	* src/c++26/debugging.cc [_GLIBCXX_HAVE_SYS_PTRACE_H]: Include
	<sys/types.h>.
	(breakpoint) [__i386__ || __x86_64__]: Use "int 0x03" instead of
	"int3".
2025-08-31 10:16:19 +01:00
Pan Li af97962412 RISC-V: Add test case for unsigned scalar SAT_MUL form 4
The form 4 of unsigned scalar SAT_MUL is covered in middle-expand
alreay, add test case here to cover form 4.

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

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/sat/sat_arith.h: Add test helper macros.
	* gcc.target/riscv/sat/sat_u_mul-5-u16-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u16-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u16-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u16-from-u64.rv64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u32-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u32-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u32-from-u64.rv64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u64-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u8-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u8-from-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u8-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u8-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-5-u8-from-u64.rv64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u16-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u16-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u16-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u32-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u32-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u64-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u8-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u8-from-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u8-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-5-u8-from-u64.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-31 09:41:25 +08:00
GCC Administrator f485138167 Daily bump. 2025-08-31 00:18:58 +00:00
Jakub Jelinek 4ee9e8319a phiopt, math-opts: Adjust spaceship_replacement and optimize_spaceship for recent libstdc++ changes [PR121698]
libstdc++ changed its ABI in <compare> for C++20 recently (under the
C++20 is still experimental rule).  In addition to the -1, 0, 1 values
for less, equal, greater it now uses -128 for unordered instead of
former 2 and changes some of the operators, instead of checks like
(_M_value & ~1) == _M_value in some cases it now uses _M_reverse()
which is negation in unsigned char type + conversion back to the original
type. _M_reverse() thus turns the -1, 0, 1, -128 values into
1, 0, -1, -128.  Note libc++ uses value -127 instead of 2/-128.

Now, the middle-end has some optimizations which rely on the particular
implementation and don't optimize if not.  One is optimize_spaceship
which on some targets (currently x86, aarch64 and s390) attempts to use
better comparison instructions (ideally just one floating point comparison
to get all 4 possible outcomes plus some flag tests or magic instead of
2 or 3 floating point comparisons).  This one can actually handle
arbitrary int non-[-1,1] values for unordered but still has a default
of 2.  The patch changes that default to -128 so that even if something
is expanded as branches if it is later during RTL optimizations determined
to convert that into partial_ordering we get better code.

The other optimization (phiopt one) is about optimizing (x <=> y) < 0
etc. into just x < y.  This one actually relies on the exact unordered
value (2) and has code to deal with that (_M_value & ~1) == _M_value
kind of tests and whatever match.pd lowers it.  So, this patch partially
rewrites it to look for -128 instead of 2, drop those
(_M_value & ~1) == _M_value pattern recognitions and instead introduces
pattern recognition of _M_reverse(), i.e. cast to unsigned char, negation
in that type and cast back to the original signed type.

With all these changes we get back the desired optimizations for all
the cases we could optimize previously (note, for HONOR_NANS case
we don't try to optimize say (x <=> y) == 0 because the original
will raise exception if either x or y is a NaN, while turning it into
x == y will not, but (x <=> y) <= 0 is fine (x <= y), because it
does raise those exceptions.

2025-08-30  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/121698
	* tree-ssa-phiopt.cc (spaceship_replacement): Adjust
	to handle spaceship unordered value -128 rather than 2 and
	stmts from the new std::partial_order::_M_reverse() instead
	of (_M_value & ~1) == _M_value etc.
	* doc/md.texi (spaceship@var{m}4): Use -128 instead of 2.
	* tree-ssa-math-opts.cc (optimize_spaceship): Adjust comments
	that libstdc++ unordered value is -128 rather than 2 and use
	that as the default unordered value.
	* config/i386/i386-expand.cc (ix86_expand_fp_spaceship): Use
	GEN_INT (-128) instead of const2_rtx and adjust comment accordingly.
	* config/aarch64/aarch64.cc (aarch64_expand_fp_spaceship): Likewise.
	* config/s390/s390.cc (s390_expand_fp_spaceship): Likewise.

	* gcc.dg/pr94589-2.c: Adjust for expected unordered value -128
	rather than 2 and negations in unsigned char instead of and with
	~1 and comparison against original value.
	* gcc.dg/pr94589-4.c: Likewise.
	* gcc.dg/pr94589-5.c: Likewise.
	* gcc.dg/pr94589-6.c: Likewise.
2025-08-30 18:29:04 +02:00
Gerald Pfeifer 3e2f2b5939 doc: Improve markup for list of vector operators
gcc:
	* doc/extend.texi (Vector Extensions): Improve markup for list
	of operators.
2025-08-30 16:58:32 +02:00
Gerald Pfeifer 9281fd9570 doc: Update Objective-C language reference
gcc:
	* doc/standards.texi (Standards): Update "Object-Oriented
	Programming and the Objective-C Language" reference.
2025-08-30 15:49:47 +02:00
H.J. Lu e91990c1bc x86-64: Use UNSPEC_DTPOFF to check source operand in TLS64_COMBINE
Since the first operand of PLUS in the source of TLS64_COMBINE pattern:

(set (reg/f:DI 128)
    (plus:DI (unspec:DI [
                (symbol_ref:DI ("_TLS_MODULE_BASE_") [flags 0x10])
                (reg:DI 126)
                (reg/f:DI 7 sp)
            ] UNSPEC_TLSDESC)
        (const:DI (unspec:DI [
                    (symbol_ref:DI ("bfd_error") [flags 0x1a] <var_decl 0x7fffe99d6e40 bfd_error>)
                ] UNSPEC_DTPOFF))))

is unused, use the second operand of PLUS:

(const:DI (unspec:DI [
            (symbol_ref:DI ("bfd_error") [flags 0x1a] <var_decl 0x7fffe99d6e40 bfd_error>)
        ] UNSPEC_DTPOFF))

to check if 2 TLS_COMBINE patterns have the same source.

gcc/

	PR target/121725
	* config/i386/i386-features.cc
	(pass_x86_cse::candidate_gnu2_tls_p): Use the UNSPEC_DTPOFF
	operand to check source operand in TLS64_COMBINE pattern.

gcc/testsuite/

	PR target/121725
	* gcc.target/i386/pr121725-1a.c: New test.
	* gcc.target/i386/pr121725-1b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-30 06:10:27 -07:00
Andrew Pinski bfa70ddb65 forwprop: Copy the memcmp optimization from strlen to forwprop [PR116651]
To better optimize code dealing with `memcmp == 0` where we have
a small constant size, we can inline the memcmp in those cases.
There is code to do this in strlen but that is run too late in
the case where we can figure out the value of one of the arguments
to memcmp. So this copies the optimization to forwprop.

An example of where this helps is:
```
bool cmpvect(const std::vector<int> &a) { return a == std::vector<int>{10}; }
```

Where the above should be optimized to just `return a.size() == 1 && a[0] == 10;`.

Note pr44130.c testcase needed to change as now it will be optimized away otherwise.
Note the loop in pr44130.c os also vectorized which it was not before.

Note the optimization remains in strlen as the other part (memcmp -> memcmp_eq)
should move to either isel or fab and I didn't want to remove it just yet.

Bootstrapped and tested on x86_64-linux-gnu.

Changes since v1:
* v2: Add verification of arguments to memcmp to simplify_builtin_memcmp.

	PR tree-optimization/116651
	PR tree-optimization/93265
	PR tree-optimization/103647
	PR tree-optimization/52171

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (simplify_builtin_memcmp): New function.
	(simplify_builtin_call): Call simplify_builtin_memcmp for memcmp
	memcmp_eq builtins.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr44130.c: Add an inline-asm clobber.
	* g++.dg/tree-ssa/vector-compare-1.C: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-29 20:13:00 -07:00
liuhongt 668e607efe Revert "Fix _Decimal128 arithmetic error under FE_UPWARD."
This reverts commit 50064b2898.
2025-08-29 19:22:40 -07:00
GCC Administrator fdb499c2f6 Daily bump. 2025-08-30 00:19:51 +00:00
Gaius Mulley 8ab3bbadef PR modula2/121709: Failed bootstrap in m2
This patch is a followup to PR modula2/121629 which uses
the cpp_include_defaults array to configure the default search path
entries.  In particular it creates default search paths
based on LOCAL_INCLUDE_DIR, PREFIX_INCLUDE_DIR, gcc version path
and NATIVE_SYSTEM_HEADER_DIR.

gcc/m2/ChangeLog:

	PR modula2/121709
	* gm2-lang.cc (concat_component): New function.
	(find_cpp_entry): Ditto.
	(lookup_cpp_default): Ditto.
	(add_default_include_paths): Rewrite.
	(m2_pathname_root): Remove.

gcc/ChangeLog:

	PR modula2/121709
	* doc/gm2.texi (Module Search Path): Reflect the new
	search order.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-08-29 22:10:29 +01:00
Sirui Mu 78d19ea3fe c++: array subscript with COND_EXPR as the array
The following minimum reproducer would miscompile with vanilla gcc:

  extern int x[10], y[10];
  bool g();
  void f() { 0[g() ? x : y] = 1; }

gcc would mistakenly treat the subexpression (g() ? x : y) as a prvalue and
move that array to stack. The following assignment would then write to the
stack instead of to the global arrays. When optimizations are enabled, this
assignment is discarded by dse and gcc generates the following code for the
f function:

  "_Z1fi":
        jmp     "_Z1gv"

The miscompilation requires all the following conditions to be met:

  - The array subscription expression is written as idx[array], instead of
    the usual form array[idx];
  - The "array" part must be a ternary expression (COND_EXPR in gcc tree)
    and it must be an lvalue.
  - The code must be compiled with -fstrong-eval-order which is the default
    for -std=c++17 or later.

The cause of the issue lies in cp_build_array_ref, where it mistakenly
generates a COND_EXPR with ARRAY_TYPE to the IL when all the criteria above
are met. This patch tries to resolve this issue. It moves the
canonicalization step that transforms idx[array] to array[idx] early in
cp_build_array_ref to ensure we handle these two forms of array subscription
consistently.

Tested on x86_64-linux.

gcc/cp/ChangeLog:

	* typeck.cc (cp_build_array_ref): Handle 0[arr] earlier.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1z/array-condition-expr.C: New test.

Signed-off-by: Sirui Mu <msrlancern@gmail.com>
2025-08-29 21:51:29 +02:00
David Malcolm 9e98b37f32 diagnostics: add GCC_DIAGNOSTICS_LOG
Whilst experimenting with PR diagnostics/121039 (potentially capturing
suppressed diagnostics in SARIF output), I found it very useful to have
a text log from the diagnostic subsystem to track what it's doing and
the decisions it's making (e.g. exactly when and why a diagnostic is
being rejected).

This patch adds a simple logging mechanism to the diagnostics subsystem,
enabled by setting GCC_DIAGNOSTICS_LOG in the environment, which emits
nested text like this to stderr (or a named file):

warning (option_id: 668, gmsgid: "%<-Wformat-security%> ignored without %<-Wformat%>")
  diagnostics::context::diagnostic_impl (option_id: 668, kind: warning, gmsgid: "%<-Wformat-security%> ignored without %<-Wformat%>")
    diagnostics::context::report_diagnostic
    rejecting: diagnostic not enabled
    false <- diagnostics::context::diagnostic_impl
  false <- warning

This logging mechanism doesn't use pretty_printer because it can be
helpful to use it to debug pretty_printer itself.

gcc/ChangeLog:
	* Makefile.in (OBJS-libcommon): Add diagnostics/logging.o.
	* diagnostic-global-context.cc: Include "diagnostics/logging.h".
	(log_function_params, auto_inc_log_depth): New "using" decls.
	(verbatim): Add logging.
	(emit_diagnostic): Likewise.
	(emit_diagnostic_valist): Likewise.
	(emit_diagnostic_valist_meta): Likewise.
	(inform): Likewise.
	(inform_n): Likewise.
	(warning): Likewise.
	(warning_at): Likewise.
	(warning_meta): Likewise.
	(warning_n): Likewise.
	(pedwarn): Likewise.
	(permerror): Likewise.
	(permerror_opt): Likewise.
	* diagnostics/context.cc: Include "diagnostics/logging.h".
	(context::initialize): Initialize m_logger.  Add logging.
	(context::finish): Add logging.  Clean up m_logger.
	(context::dump): Add indent param.
	(context::set_sink): Add logging.
	(context::add_sink): Add logging.
	(diagnostic_kind_debug_text): New.
	(get_debug_string_for_kind): New.
	(context::report_diagnostic): Add logging.
	(context::diagnostic_impl): Likewise.
	(context::diagnostic_n_impl): Likewise.
	(context::end_group): Likewise.
	* diagnostics/context.h: Include "diagnostics/logging.h".
	(context::dump): Add indent param.
	(context::get_logger): New accessor.
	(context::classify_diagnostics): Add logging.
	(context::push_diagnostics): Likewise.
	(context::pop_diagnostics): Likewise.
	(context::m_logger): New field.
	* diagnostics/html-sink.cc: Include "diagnostics/logging.h".
	(html_builder::flush_to_file): Add logging.
	(html_sink::on_report_diagnostic): Likewise.
	* diagnostics/kinds.h (get_debug_string_for_kind): New decl.
	* diagnostics/logging.cc: New file.
	* diagnostics/logging.h: New file.
	* diagnostics/output-file.h: Include "label-text.h".
	* diagnostics/sarif-sink.cc: Include "diagnostics/logging.h".
	(sarif_builder::flush_to_object): Add logging.
	(sarif_builder::flush_to_file): Likewise.
	(sarif_sink::on_report_diagnostic): Likewise.
	* diagnostics/sink.h (sink::get_logger): New.
	* diagnostics/text-sink.cc: Include "diagnostics/logging.h".
	(text_sink::on_report_diagnostic): Add logging.
	* doc/invoke.texi (Environment Variables): Document
	GCC_DIAGNOSTICS_LOG.
	* opts-diagnostic.cc: Include "diagnostics/logging.h".
	(handle_OPT_fdiagnostics_add_output_): Add loggging.
	(handle_OPT_fdiagnostics_set_output_): Likewise.

gcc/analyzer/ChangeLog:
	* pending-diagnostic.cc: Include "diagnostics/logging.h".
	(diagnostic_emission_context::warn): Add logging.
	(diagnostic_emission_context::inform): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-29 14:39:37 -04:00
Takayuki 'January June' Suwa ba9d4b3ce5 xtensa: Rewrite bswapsi2_internal with compact syntax
Also, the omission of the instruction that sets the shift amount register
(SAR) to 8 is now more efficient: it is omitted if there was a previous
bswapsi2 in the same BB, but not omitted if no bswapsi2 is found or another
insn that modifies SAR is found first (see below).

Note that the five instructions for writing to SAR are as follows, along
with the insns that use them (except for bswapsi2_internal itself):

- SSA8B
    *shift_per_byte, *shlrd_per_byte
- SSA8L
    *shift_per_byte, *shlrd_per_byte
- SSR
    ashrsi3 (alt 1), lshrsi3 (alt 1), *shlrd_reg, rotrsi3 (alt 1)
- SSL
    ashlsi3_internal (alt 1), *shlrd_reg, rotlsi3 (alt 1)
- SSAI
    *shlrd_const, rotlsi3 (alt 0), rotrsi3 (alt 0)

gcc/ChangeLog:

	* config/xtensa/xtensa-protos.h (xtensa_bswapsi2_output):
	New function prototype.
	* config/xtensa/xtensa.cc
	(xtensa_bswapsi2_output_1, xtensa_bswapsi2_output):
	New functions.
	* config/xtensa/xtensa.md (bswapsi2_internal):
	Rewrite in compact syntax and use xtensa_bswapsi2_output() as asm
	output.

gcc/testsuite/ChangeLog:

	* gcc.target/xtensa/bswap-SSAI8.c: New.
2025-08-29 10:54:32 -07:00
Jeff Law 25bbc0f20a [RISC-V][PR target/121548] Avoid bogus index into recog operand cache
So the RISC-V port has attributes which indicate the index within the
recog_data where certain operands will be found.

For this BZ the default value for the merge_op_idx attribute on the given insn
is "2".  But the insn only has operands 0 & 1.  So we do an out of bounds array
access and boom the ICE/valgrind failure.

As we discussed in the patchwork meeting, this is all a bit clunky and has been
fairly error prone.  This doesn't add any massive checking, but does introduce
some asserts to help catch problems a bit earlier and clearer.

In particular in cases where we're already asserting that the returned index is
valid (!= INVALID_ATTRIBUTE) we also assert that the index is less than the
total number of operands.

In the get_vlmax_ta_preferred_avl routine it appears like we need to handle
these two cases more gracefully as we apparently legitimately query for the
merge_op_idx on a fairly arbitrary insn.  We just have to make sure to not
*use* the result if it's INVALID_ATTRIBUTE.  So for that code we assert that
merge_op_idx is either INVALID_ATTRIBUTE or smaller than the number of
operands.

This patch also adds overrides for 3 patterns to return INVALID_ATTRIBUTE for
merge_op_idx, similar to how they already do for mode_idx and avl_type_idx.

This has been bootstrapped and regression tested on the bpi & pioneer systems
and regression tested for riscv32-elf and riscv64-elf.  Waiting on CI before
pushing.

	PR target/121548
gcc/
	* config/riscv/riscv-avlprop.cc (get_insn_vtype_mode): Assert
	MODE_IDX is smaller than the number of operands.
	(simplify_replace_vlmax_avl): Similarly.
	(pass_avlprop::get_vlmax_ta_preferred_avl): Similarly.
	* config/riscv/vector.md: Override merge_op_idx computation
	for simple moves, just like is done for avl_type_idx and mode_idx.
2025-08-29 11:43:30 -06:00
Harald Anlauf 18e49f19f5 Fortran: improve compile-time checking of character dummy arguments [PR93330]
PR fortran/93330

gcc/fortran/ChangeLog:

	* interface.cc (get_sym_storage_size): Add argument size_known to
	indicate that the storage size could be successfully determined.
	(get_expr_storage_size): Likewise.
	(gfc_compare_actual_formal): Use them to handle zero-sized dummy
	and actual arguments.
	If a character formal argument has the pointer or allocatable
	attribute, or is an array that is not assumed or explicit size,
	we generate an error by default unless -std=legacy is specified,
	which falls back to just giving a warning.
	If -Wcharacter-truncation is given, warn on a character actual
	argument longer than the dummy.  Generate an error for too short
	scalar character arguments if -std=f* is given instead of just a
	warning.

gcc/testsuite/ChangeLog:

	* gfortran.dg/argument_checking_15.f90: Adjust dg-pattern.
	* gfortran.dg/bounds_check_strlen_7.f90: Add dg-pattern.
	* gfortran.dg/char_length_3.f90: Adjust options.
	* gfortran.dg/whole_file_24.f90: Add dg-pattern.
	* gfortran.dg/whole_file_29.f90: Likewise.
	* gfortran.dg/argument_checking_27.f90: New test.
2025-08-29 18:42:38 +02:00
Paul-Antoine Arras 79e0dbf1c4 RISC-V: Add patterns for vector-scalar IEEE floating-point min
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into an unspec_vfmin RTL instruction.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f       v2,fa0
  vfmin.vv       v1,v1,v2

After, we get only one:
  vfmin.vf       v1,v1,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md
	(*vfmin_vf_ieee_<mode>): Add new patterns to combine vec_duplicate +
	vfmin.vv (unspec) into vfmin.vf.
	(*vfmul_vf_<mode>, *vfrdiv_vf_<mode>, *vfmin_vf_<mode>): Fix attribute
	types.
	* config/riscv/vector.md (@pred_<ieee_fmaxmin_op><mode>_scalar): Allow
	VLS modes.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Add vfmin.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-5-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-5-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-5-f64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-6-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-6-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-6-f64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-7-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-7-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-7-f64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-8-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-8-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-8-f64.c: New test.
2025-08-29 15:33:41 +02:00
H.J. Lu 881df7a0b1 x86: Allow by_pieces op when expanding memcpy/memset epilogue
Since

commit 401199377c
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Jun 17 10:17:17 2025 +0800

    x86: Improve vector_loop/unrolled_loop for memset/memcpy

uses move_by_pieces and store_by_pieces to expand memcpy/memset epilogue
with vector_loop even when targetm.use_by_pieces_infrastructure_p returns
false, which triggers

  gcc_assert (targetm.use_by_pieces_infrastructure_p
                (len, align,
                 memsetp ? SET_BY_PIECES : STORE_BY_PIECES,
                 optimize_insn_for_speed_p ()));

in store_by_pieces.  Fix it by:

1. Add by_pieces_in_use to machine_function to indicate that by_pieces op
is currently in use.
2. Set and clear by_pieces_in_use when expanding memcpy/memset epilogue
with move_by_pieces and store_by_pieces.
3. Define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P to return true if
by_pieces_in_use is true.

gcc/

	PR target/121096
	* config/i386/i386-expand.cc (expand_cpymem_epilogue): Set and
	clear by_pieces_in_use when using by_pieces op.
	(expand_setmem_epilogue): Likewise.
	* config/i386/i386.cc (ix86_use_by_pieces_infrastructure_p): New.
	(TARGET_USE_BY_PIECES_INFRASTRUCTURE_P): Likewise.
	* config/i386/i386.h (machine_function): Add by_pieces_in_use.

gcc/testsuite/

	PR target/121096
	* gcc.target/i386/memcpy-strategy-14.c: New test.
	* gcc.target/i386/memcpy-strategy-15.c: Likewise.
	* gcc.target/i386/memset-strategy-10.c: Likewise.
	* gcc.target/i386/memset-strategy-11.c: Likewise.
	* gcc.target/i386/memset-strategy-12.c: Likewise.
	* gcc.target/i386/memset-strategy-13.c: Likewise.
	* gcc.target/i386/memset-strategy-14.c: Likewise.
	* gcc.target/i386/memset-strategy-15.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-29 05:21:14 -07:00
H.J. Lu 207a506ee5 x86: Handle constant in any modes in setmem_epilogue_gen_val
Since the constant passed to setmem_epilogue_gen_val may not be in
word_mode, update setmem_epilogue_gen_val to handle any integer modes.

gcc/

	PR target/121108
	* config/i386/i386-expand.cc (setmem_epilogue_gen_val): Don't
	assert op_mode == word_mode and handle any integer modes.

gcc/testsuite/

	PR target/121108
	* gcc.target/i386/memset-strategy-16.c: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-29 05:14:08 -07:00
H.J. Lu 62843b3453 x86-64: Improve source operand check for TLS_CALL
Source operands of 2 TLS_CALL patterns in

(insn 10 9 11 3 (set (reg:DI 100)
        (unspec:DI [
                (symbol_ref:DI ("caml_state") [flags 0x10]  <var_decl 0x7fe10e1d9e40 caml_state>)
            ] UNSPEC_TLSDESC)) "x.c":7:16 1674 {*tls_dynamic_gnu2_lea_64_di}
     (nil))
(insn 11 10 12 3 (parallel [
            (set (reg:DI 99)
                (unspec:DI [
                        (symbol_ref:DI ("caml_state") [flags 0x10]  <var_decl 0x7fe10e1d9e40 caml_state>)
                        (reg:DI 100)
                        (reg/f:DI 7 sp)
                    ] UNSPEC_TLSDESC))
            (clobber (reg:CC 17 flags))
        ]) "x.c":7:16 1676 {*tls_dynamic_gnu2_call_64_di}
     (expr_list:REG_DEAD (reg:DI 100)
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))

and

(insn 19 17 20 4 (set (reg:DI 104)
        (unspec:DI [
                (symbol_ref:DI ("caml_state") [flags 0x10]  <var_decl 0x7fe10e1d9e40 caml_state>)
            ] UNSPEC_TLSDESC)) "x.c":6:10 discrim 1 1674 {*tls_dynamic_gnu2_lea_64_di}
     (nil))
(insn 20 19 21 4 (parallel [
            (set (reg:DI 103)
                (unspec:DI [
                        (symbol_ref:DI ("caml_state") [flags 0x10]  <var_decl 0x7fe10e1d9e40 caml_state>)
                        (reg:DI 104)
                        (reg/f:DI 7 sp)
                    ] UNSPEC_TLSDESC))
            (clobber (reg:CC 17 flags))
        ]) "x.c":6:10 discrim 1 1676 {*tls_dynamic_gnu2_call_64_di}
     (expr_list:REG_DEAD (reg:DI 104)
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))

are the same even though rtx_equal_p returns false since (reg:DI 100)
and (reg:DI 104) are set from the same symbol.  Use the UNSPEC_TLSDESC
symbol

(unspec:DI [(symbol_ref:DI ("caml_state") [flags 0x10])] UNSPEC_TLSDESC))

to check if 2 TLS_CALL patterns have the same source.

For TLS64_COMBINE, use both UNSPEC_TLSDESC and UNSPEC_DTPOFF unspecs to
check if 2 TLS64_COMBINE patterns have the same source.

gcc/

	PR target/121694
	* config/i386/i386-features.cc (redundant_pattern): Add
	tlsdesc_val.
	(pass_x86_cse): Likewise.
	(pass_x86_cse::tls_set_insn_from_symbol): New member function.
	(pass_x86_cse::candidate_gnu2_tls_p): Set tlsdesc_val.  For
	TLS64_COMBINE, match both UNSPEC_TLSDESC and UNSPEC_DTPOFF
	symbols.  For TLS64_CALL, match the UNSPEC_TLSDESC sumbol.
	(pass_x86_cse::x86_cse): Initialize the tlsdesc_val field in
	load.  Pass the tlsdesc_val field to ix86_place_single_tls_call
	for X86_CSE_TLSDESC.

gcc/testsuite/

	PR target/121694
	* gcc.target/i386/pr121668-1b.c: New test.
	* gcc.target/i386/pr121694-1a.c: Likewise.
	* gcc.target/i386/pr121694-1b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-29 05:14:02 -07:00
Jason Merrill 34262b9835 c++: -fimplicit-constexpr testcase tweak
If B::get is (implictly or explicitly) constexpr the individual b bindings
have constant initialization and get optimized away, so their symbols don't
appear in the assembly.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp26/decomp26.C: Add -fimplicit-constexpr.
2025-08-29 10:11:11 +02:00
Tobias Burnus 5a7e3d44ba invoke.texi: AMD GCN - remove '(experimental)' from some gfx*-generic
GCC added generic support in r15-7406-gb5a29a93ee29a8 (Feb 2025) with an
'(experimental)' marker, also because ROCm only supported it in their
git repository and not in a released version. Since ROCm 6.4 (Apr 2025),
generic is also supported in released ROCm versions - and has been
meanwhile tested by us.

For architectures that have a well tested architecture, there is no
reason that a binary, compiled for the associated generic architecture,
performs any different to the specific version. Hence, this commit
removes the marker for gfx-9-generic (gfx900, gfx906, gfx90c are known
to work specific architectures), gfx10-3-generic (likewise for gfx1030
and gfx1036), and gfx11-generic (gfx1100 and gfx1103).

gcc/ChangeLog:

	* doc/invoke.texi (AMD GCN Options: -march): Remove '(experimental)'
	from gfx-{9,10-3,11}-generic.
2025-08-29 09:51:06 +02:00
Tobias Burnus aa8ba1b0d9 install.texi: For amdgcn, clarify which llvm-* binaries are required
Also remove future tense for ROCm as 6.4.0 has been released in April 2025
and it supports generic architectures.

gcc/ChangeLog:

	* doc/install.texi (amdgcn): Clarify which binaries must be the
	LLVM version and which must be installed. Update version data for
	ROCm for generic architectures.
2025-08-29 09:47:52 +02:00
Andrew Pinski 595bc6263a i386: Fix vect-pragma-target-[12].c testcase for -march=XYZ [PR120643]
These 2 testcases were originally designed for the default -march= of
x86_64 so if you pass -march=native (on a target with AVX512 enabled),
they will fail. It fix this, we add `-mno-sse3 -mtune=generic`
to the options to force a specific arch to the testcase.

Changes since v1:
* v2: Use -mtune=generic instead of -mprefer-vector-width=512.

Tested on a skylake-avx512 machine with -march=native.

	PR testsuite/120643
gcc/testsuite/ChangeLog:

	* gcc.target/i386/vect-pragma-target-1.c: Add `-mno-sse3 -mtune=generic`
	to the options.
	* gcc.target/i386/vect-pragma-target-2.c: Likewise.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-29 00:38:30 -07:00
Andrew Pinski 944c3225b3 aarch64/testsuite: Fix vld2-1.c after r16-3201 [PR121713]
After r16-3201-gee67004474d521, this testcase started to fail as
we can copy prop into arguments now so the number of "after previous"
check has doubled.

Pushed after a quick check to make sure the testcase is now passing.

	PR testsuite/121713
gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/vld2-1.c: Update the number of "after previous"
	checks.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-28 22:30:56 -07:00
liuhongt 2cb3fb032d Document -param=ix86-vect-unroll-limit.
gcc/ChangeLog:

	* doc/invoke.texi: Document -param=ix86-vect-unroll-limit.
2025-08-28 19:30:19 -07:00
Pan Li 0a44e22df9 RISC-V: Add test for vec_duplicate + vnmsac.vv unsigned combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vnmsac.vvm
combine to vnmsac.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
	for vnmsac.vx.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsac-run-1-u16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsac-run-1-u32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsac-run-1-u64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsac-run-1-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-29 10:05:23 +08:00
Pan Li 52d5fc64a4 RISC-V: Add test for vec_duplicate + vnmsac.vv signed combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vnmsac.vvm
combine to vnmsac.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c: Add asm check
	for vnmsac.vx.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary.h: Add test
	helper macros.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary_data.h: Add test
	data for run test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsac-run-1-i16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsac-run-1-i32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsac-run-1-i64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vnmsac-run-1-i8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-29 10:05:23 +08:00
Pan Li 44054e6206 RISC-V: Combine vec_duplicate + vnmsac.vv to vnmsac.vx on GR2VR cost
This patch would like to combine the vec_duplicate + vnmsac.vv to the
vnmsac.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

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

  #define DEF_VX_TERNARY_CASE_0(T, OP_1, OP_2, NAME)
\
  void
\
  test_vx_ternary_##NAME##_##T##_case_0 (T * restrict vd, T * restrict
vs2, \NAME                                         T rs1, unsigned n)
\
  {
\
    for (unsigned i = 0; i < n; i++)
\
      vd[i] = vd[i] OP_2 vs2[i] OP_1 rs1;
\
  }

  DEF_VX_TERNARY_CASE_0(int32_t, *, +, macc)

Before this patch:
  11   │     beq a3,zero,.L8
  12   │     vsetvli a5,zero,e32,m1,ta,ma
  13   │     vmv.v.x v2,a2
  ...
  16   │ .L3:
  17   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  22   │     vnmsac.vv v1,v2,v3
  ...
  25   │     bne a3,zero,.L3

After this patch:
  11   │     beq a3,zero,.L8
  ...
  14   │ .L3:
  15   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  20   │     vnmsac.vx v1,a2,v3
  ...
  23   │     bne a3,zero,.L3

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vnmsac_vx_<mode>): Add new
	pattern to combine to vx.
	* config/riscv/vector.md (@pred_vnmsac_vx_<mode>): Add new
	pattern to generate rtl.
	(*pred_nmsac_<mode>_scalar_undef): Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-29 10:05:23 +08:00
liuhongt 50064b2898 Fix _Decimal128 arithmetic error under FE_UPWARD.
libgcc/config/libbid/ChangeLog:

	PR target/120691
	* bid128_div.c: Fix _Decimal128 arithmetic error under
	FE_UPWARD.
	* bid128_rem.c: Ditto.
	* bid128_sqrt.c: Ditto.
	* bid64_div.c (bid64_div): Ditto.
	* bid64_sqrt.c (bid64_sqrt): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr120691.c: New test.
2025-08-28 19:02:21 -07:00
GCC Administrator a15bdc66d2 Daily bump. 2025-08-29 00:19:55 +00:00
Jonathan Wakely 59db4ce2df fixincludes: Skip pthread_incomplete_struct_argument for modern glibc [PR118009]
The pthread_incomplete_struct_argument fix was intended for ancient
versions of Glibc (only 2.3.3 and 2.3.4, I believe). From Glibc 2.3.5
the pthread.h header already included the change to use a pointer
instead of an array, so the fixinclude was no longer used.

However, the https://sourceware.org/bugzilla/show_bug.cgi?id=26647 fix
changed the __setjmpbuf declaration to use struct __jmp_buf_tag __env[1]
again, which caused this fixinclude to start matching again. This means
that GCC now installs a "fixed" pthread.h with a change to a declaration
that guarded by #if ! __GNUC_PREREQ (11, 0), i.e. it's not even relevant
for modern versions of GCC. The "fixed" pthread.h causes problems for
users because of changes to internal implementation details of the
pthread_cond_t type, which require the "fixed" pthread.h to be updated
with mkheaders if Glibc is updated.

This change adds a bypass to the fixinclude, so that it no longer
matches modern Glibc versions, and only applies to glibc versions 2.3.3
and 2.3.4 as originally intended.

Also remove outdated reference to svn in the comment at the top of the
generated file.

fixincludes/ChangeLog:

	PR bootstrap/118009
	PR bootstrap/119089
	* inclhack.def (pthread_incomplete_struct_argument): Add bypass.
	* fixincl.tpl: Remove reference to svn in comment.
	* fixincl.x: Regenerate.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-28 17:48:03 +01:00
Jonathan Wakely 3c95766e92 libstdc++: Implement C++26 <debugging> features [PR119670]
This implements P2546R5 (Debugging Support), including the P2810R4
(is_debugger_present is_replaceable) changes, allowing
std::is_debugger_present to be replaced by the program.

It would be good to provide a macOS definition of is_debugger_present as
per https://developer.apple.com/library/archive/qa/qa1361/_index.html
but that isn't included in this change.

The src/c++26/debugging.cc file defines a global volatile int which can
be set by debuggers to indicate when they are attached and detached from
a running process. This allows std::is_debugger_present() to give a
reliable answer, and additionally allows a debugger to choose how
std::breakpoint() should behave. Setting the global to a positive value
will cause std::breakpoint() to use that value as an argument to
std::raise, so debuggers that prefer SIGABRT for breakpoints can select
that. By default std::breakpoint() will use a platform-specific action
such as the INT3 instruction on x86, or GCC's __builtin_trap().

On Linux the std::is_debugger_present() function checks whether the
process is being traced by a process named "gdb", "gdbserver" or
"lldb-server", to try to avoid interpreting other tracing processes
(such as strace) as a debugger. There have been comments suggesting this
isn't desirable and that std::is_debugger_present() should just return
true for any tracing process (which is the case for non-Linux targets
that support the ptrace system call).

libstdc++-v3/ChangeLog:

	PR libstdc++/119670
	* acinclude.m4 (GLIBCXX_CHECK_DEBUGGING): Check for facilities
	needed by <debugging>.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Use GLIBCXX_CHECK_DEBUGGING.
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/bits/version.def (debugging): Add.
	* include/bits/version.h: Regenerate.
	* include/precompiled/stdc++.h: Add new header.
	* src/c++26/Makefile.am: Add new file.
	* src/c++26/Makefile.in: Regenerate.
	* include/std/debugging: New file.
	* src/c++26/debugging.cc: New file.
	* testsuite/19_diagnostics/debugging/breakpoint.cc: New test.
	* testsuite/19_diagnostics/debugging/breakpoint_if_debugging.cc:
	New test.
	* testsuite/19_diagnostics/debugging/is_debugger_present.cc: New
	test.
	* testsuite/19_diagnostics/debugging/is_debugger_present-2.cc:
	New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-28 17:47:00 +01:00
Jason Merrill 00e8690ef0 c++: > in lambda in template arg [PR107953]
As with PR116928, we need to set greater_than_is_operator_p within the
lambda delimiters.

	PR c++/107953

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_lambda_expression): Set
	greater_than_is_operator_p.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/lambda-targ18.C: New test.
2025-08-28 17:50:06 +02:00
Andrew Pinski 6750f5902c passes: Move cleanup_eh before first tailr [PR115201]
So the current pass order is:
```
          NEXT_PASS (pass_tail_recursion);
          NEXT_PASS (pass_if_to_switch);
          NEXT_PASS (pass_convert_switch);
          NEXT_PASS (pass_cleanup_eh);
```
But nothing in if_to_switch nor convert_switch will change the IR
such that cleanup eh will take into account.
tail_recusion benifits the most by not having "almost" empty landing pads.
This order was originally done when cleanup_eh was added in r0-92178-ga8da523f8a442f
but it looks like it was just done just before inlining rather than thinking it
could improve passes before hand.

An example where this helps is PR 115201 where we have:
```
;;   basic block 5, loop depth 0, maybe hot
;;    prev block 4, next block 6, flags: (NEW, REACHABLE, VISITED)
;;    pred:       4 (TRUE_VALUE,EXECUTABLE)
  [LP 1] # .MEM_19 = VDEF <.MEM_45>
  # USE = nonlocal escaped
  # CLB = nonlocal escaped
  D.4770 = _Z12binarySearchIi2itIiEET0_RKT_S2_S2_D.4690 (item_15(D), startD.4711, midD.4717);
  goto <bb 7>; [INV]
;;    succ:       8 (EH,EXECUTABLE)
;;                7 (FALLTHRU,EXECUTABLE)
...

;;   basic block 8, loop depth 0, maybe hot
;;    prev block 7, next block 1, flags: (NEW, REACHABLE, VISITED)
;;    pred:       5 (EH,EXECUTABLE)
;;                6 (EH,EXECUTABLE)
  # .MEM_7 = PHI <.MEM_19(5), .MEM_18(6)>
<L6>: [LP 1]
  # .MEM_20 = VDEF <.MEM_7>
  midD.4717 ={v} {CLOBBER(eos)};
  resx 1
;;    succ:
```

As you can see the empty landing pad should be able to remove away and
then a tail recursion can happen.

Bootstrapped and tested x86_64-linux-gnu.

	PR tree-optimization/115201
gcc/ChangeLog:

	* passes.def: Move cleanup_eh before first tail_recursion.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-28 08:34:00 -07:00
Yuao Ma 0545b6507e MAINTAINERS: add myself to write after approval
ChangeLog:

	* MAINTAINERS: add myself to write after approval
2025-08-28 23:23:13 +08:00
Paul-Antoine Arras 31a180d8a4 RISC-V: Add pattern for vector-scalar floating-point min
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into an smin RTL instruction.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f       v2,fa0
  vfmin.vv       v1,v1,v2

After, we get only one:
  vfmin.vf       v1,v1,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfmin_vf_<mode>): Add new pattern to
	combine vec_duplicate + vfmin.vv into vfmin.vf.
	* config/riscv/vector.md (@pred_<optab><mode>_scalar): Allow VLS modes.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vls/floating-point-min-2.c: Adjust scan
	dump.
	* gcc.target/riscv/rvv/autovec/vls/floating-point-min-4.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfmin.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop.h: Add support for
	function variants.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_data.h: Add data for
	vfmin.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmin-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmin-run-1-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmin-run-1-f64.c: New test.
2025-08-28 16:58:46 +02:00
Richard Biener 48ef4af227 Dump niter assumption versioning when vectorizing
The following emits the assumption that is used for versioning from
niter analysis.

	* tree-vect-loop.cc (vect_analyze_loop_form): Dump
	niter assumption used for versioning.
2025-08-28 16:25:32 +02:00
Wilco Dijkstra 8187d2630f AArch64: Add isinf expander [PR 66462]
Add an expander for isinf using integer arithmetic.  This is
typically faster and avoids generating spurious exceptions on
signaling NaNs.  This fixes part of PR66462.

int isinf1 (float x) { return __builtin_isinf (x); }

Before:
	fabs	s0, s0
	mov	w0, 2139095039
	fmov	s31, w0
	fcmp	s0, s31
	cset	w0, le
	eor	w0, w0, 1
	ret

After:
	fmov	w1, s0
	mov	w0, -16777216
	cmp	w0, w1, lsl 1
	cset	w0, eq
	ret

gcc:
	PR middle-end/66462
	* config/aarch64/aarch64.md (isinf<mode>2): Add new expander.
	* config/aarch64/iterators.md (mantissa_bits): Add new mode_attr.

gcc/testsuite:
	PR middle-end/66462
	* gcc.target/aarch64/pr66462.c: Add new test.
2025-08-28 14:12:04 +00:00
Tomasz Kamiński f4b96998f1 libstdc++: Test comparing ordering with type convertible to any pointer.
libstdc++-v3/ChangeLog:

	* testsuite/18_support/comparisons/categories/zero_neg.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-28 15:57:06 +02:00
Richard Biener 2649c79496 Compute reduction var in vectorize_fold_left_reduction
Instead of going via the PHI node accessible through the reduc-dec
link, use the scalar def of the reduction SLP node.  Compute this
in vectorize_fold_left_reduction itself.

	* tree-vect-loop.cc (vectorize_fold_left_reduction): Do not get
	reduc_var as argument, instead compute it here.
	(vect_transform_reduction): Adjust.
2025-08-28 15:33:32 +02:00
Weslley da Silva Pereira 33cb72fafe libstdc++: Remove implicit type conversions in std::complex
The current implementation of `complex<_Tp>` assumes that int
`int` is implicitly convertible to `_Tp`, e.g., when using
`complex<_Tp>(1)`.

This patch transforms the implicit conversions into explicit type casts.
As a result, `std::complex` is now able to support more types. One
example is the type `Eigen::Half` from
https://eigen.tuxfamily.org/dox-devel/Half_8h_source.html which does not
implement implicit type conversions.

libstdc++-v3/ChangeLog:

	* include/std/complex (polar, __complex_sqrt, pow)
	(__complex_pow_unsigned): Use explicit conversions from int to
	the complex value_type.
2025-08-28 14:00:48 +01:00
Jonathan Wakely bbc0e70b61 libstdc++: Constrain bitset(const CharT*) constructor [PR121046]
Asking std::is_constructible_v<std::bitset<1>, NonTrivial*> gives an
error, rather than answering the query. The problem is that the
constructor for std::bitset("010101") is not constrained to only accept
pointers to char-like types, and for the second parameter (which has a
default argument) std::basic_string_view<CharT> gets instantiated. If
the type is not char-like then that has undefined behaviour, and might
trigger a static_assert to fail in the body of std::basic_string_view.

We can fix it by constraining that constructor using the requirements
for char-like types from [strings.general] p1.  I've submitted LWG 4294
and proposed making this change in the standard.

libstdc++-v3/ChangeLog:

	PR libstdc++/121046
	* include/std/bitset (bitset(const CharT*, ...)): Add
	constraints on CharT type.
	* testsuite/23_containers/bitset/lwg4294.cc: New test.
2025-08-28 14:00:48 +01:00
Tomasz Kamiński fcb5cd8e94 libstdc++: Provide helpers to interoperate between __cmp_cat::_Ord and ordering types.
This patch adds two new internal helpers for ordering types:
* __cmp_cat::__ord to retrieve an internal _Ord value,
* __cmp_cat::__make<Ordering> to create an ordering from an _Ord value.

Conversions between ordering types are now handled by __cmp_cat::__make. As a
result, ordering types no longer need to befriend each other, only the new
helpers.

The __fp_weak_ordering implementation has also been simplified by:
* using the new helpers to convert partial_ordering to weak_ordering,
* using strong_ordering to weak_ordering conversion operator,
  for the __isnan_sign comparison,
* removing the unused __cat local variable.

Finally, the _Ncmp enum is removed, and the unordered enumerator is added
to the existing _Ord enum.

libstdc++-v3/ChangeLog:

	* libsupc++/compare (__cmp_cat::_Ord): Add unordered enumerator.
	(__cmp_cat::_Ncmp): Remove.
	(__cmp_cat::__ord, __cmp_cat::__make):  Define.
	(partial_ordering::partial_ordering(__cmp_cat::_Ncmp)): Remove.
	(operator<=>(__cmp_cat::__unspec, partial_ordering))
	(partial_ordering::unordered): Replace _Ncmp with _Ord.
	(std::partial_ordering, std::weak_ordering, std::strong_ordering):
	Befriend __ord and __make helpers, remove friend declartions for
	other orderings.
	(__compare::__fp_weak_ordering): Remove unused __cat variable.
	Simplify ordering conversions.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-28 14:40:48 +02:00
Nathaniel Shead 10418a6cbd c++/modules: Add explanatory note for incomplete types with definition in different module [PR119844]
The confusion in the PR arose because the definition of 'User' in a
separate named module did not provide an implementation for the
forward-declaration in the global module.  This seems likely to be a
common mistake while people are transitioning to modules, so this patch
adds an explanatory note.

While I was looking at this I also noticed that the existing handling of
partial specialisations for this note was wrong (we pointed at the
primary template declaration rather than the relevant partial spec), so
this patch fixes that up, and also gives a more precise error message
for using a template other than by self-reference while it's being
defined.

	PR c++/119844

gcc/cp/ChangeLog:

	* typeck2.cc (cxx_incomplete_type_inform): Add explanation when
	a similar type is complete but attached to a different module.
	Also fix handling of partial specs and templates.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/pr119844_a.C: New test.
	* g++.dg/modules/pr119844_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-08-28 22:33:25 +10:00
Gaius Mulley 69faef01df PR modula2/121629: adding third party modules
This patch makes it easier to add third party modules.
cc1gm2 now appends the search directory prefix/include/m2
to the search path for non dialect specific modules.
Prior to this it appends the dialect specific subdirectories
{m2pim,m2iso,m2log,m2min} with the appropriate dialect pathname.
The patch also includes a new option -fm2-pathname-root=prefix
which allow additional prefix/m2 directories to be searched
before the default.

gcc/ChangeLog:

	PR modula2/121629
	* doc/gm2.texi (Module Search Path): New section.
	(Compiler options): New option -fm2-pathname-root=.
	New option -fm2-pathname-rootI.

gcc/m2/ChangeLog:

	PR modula2/121629
	* gm2-compiler/PathName.mod: Add copyright notice.
	* gm2-lang.cc (named_path): Add field lib_root.
	(push_back_Ipath): Set lib_root false.
	(push_back_lib_root): New function.
	(get_dir_sep_size): Ditto.
	(add_path_component): Ditto.
	(add_one_import_path): Ditto.
	(add_non_dialect_specific_path): Ditto.
	(foreach_lib_gen_import_path): Ditto.
	(get_module_source_dir): Ditto.
	(add_default_include_paths): Ditto.
	(assign_flibs): Ditto.
	(m2_pathname_root): Ditto.
	(add_m2_import_paths): Remove function.
	(gm2_langhook_post_options): Call assign_flibs.
	Check np.lib_root and call foreach_lib_gen_import_path.
	Replace call to add_m2_import_paths with a call to
	add_default_include_paths.
	(gm2_langhook_handle_option): Add case OPT_fm2_pathname_rootI_.
	* gm2spec.cc (named_path): Add field lib_root.
	(push_back_Ipath): Set lib_root false.
	(push_back_lib_root): New function.
	(add_m2_I_path): Add OPT_fm2_pathname_rootI_ option
	if np.lib_root.
	(lang_specific_driver): Add case OPT_fm2_pathname_root_.
	* lang.opt (fm2-pathname-root=): New option.
	(fm2-pathname-rootI=): Ditto.

gcc/testsuite/ChangeLog:

	PR modula2/121629
	* gm2/switches/pathnameroot/pass/switches-pathnameroot-pass.exp: New test.
	* gm2/switches/pathnameroot/pass/test.mod: New test.
	* gm2/switches/pathnameroot/pass/testlib/m2/foo.def: New test.
	* gm2/switches/pathnameroot/pass/testlib/m2/foo.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-08-28 12:08:33 +01:00
Tobias Burnus 098cf06777 [gcn] gcc/configure.ac + install.texi - changes to detect HAVE_AS_LEB128 [PR119367]
The llvm-mc linker by default assemblies to another assembly file and not to an ELF
binary; that usually does not matter – but for the LEB128 check, additionally, the
resulting binary is checked. Hence, when using llvm-mc as target linker for
amdgcn-*-*, we better add the "--filetype=obj -triple=amdgcn--amdhsa" flags. The
current patch does so unconditionally, assuming that always llvm-mc is used.

Additionally, the resulting ELF file is checked, which requires an ELF reader such
as objdump. This commit adds llvm-objdump to the build documentation for amdgcn,
albeit also, e.g., Binutil's 'objdump' would do - as long as either
amdgcn-amdhsa-objdump or amdgcn-amdhsa/bin/objdump is found during the amdgcn
cross build.

gcc/ChangeLog:

	PR debug/119367
	* acinclude.m4 (gcc_GAS_FLAGS): For gcn, use "--filetype=obj
	-triple=amdgcn--amdhsa", if supported.
	* configure: Regenerate.
	* doc/install.texi (amdgcn-*-*): Also add llvm-objdump to the list of
	to-be-copied files.
2025-08-28 11:01:56 +02:00
Jakub Jelinek cddae3e175 c++: Fix auto return type deduction with expansion statements [PR121583]
The following testcase ICEs during expansion, because cfun->returns_struct
wasn't cleared, despite auto being deduced to int.

The problem is that check_return_type -> apply_deduced_return_type
is called when parsing the expansion stmt body, at that time
processing_template_decl is non-zero and apply_deduced_return_type
in that case doesn't do the
     if (function *fun = DECL_STRUCT_FUNCTION (fco))
       {
         bool aggr = aggregate_value_p (result, fco);
 #ifdef PCC_STATIC_STRUCT_RETURN
         fun->returns_pcc_struct = aggr;
 #endif
         fun->returns_struct = aggr;
       }
My assumption is that !processing_template_decl in that case
is used in the sense "the fco function is not a function template",
for function templates no reason to bother with fun->returns*struct,
nothing will care about that.
When returning a type dependent expression in the expansion stmt
body, apply_deduced_return_type just won't be called during parsing,
but when instantiating the body and all will be fine.  But when
returning a non-type-dependent expression, while check_return_type
will be called again during instantiation of the body, as the return
type is no longer auto in that case apply_deduced_return_type will not
be called again and so nothing will fix up fun->returns*struct.

The following patch fixes that by using !uses_template_parms (fco)
check instead of !processing_template_decl.

2025-08-28  Jakub Jelinek  <jakub@redhat.com>

	PR c++/121583
	* semantics.cc (apply_deduced_return_type): Adjust
	fun->returns*_struct when !uses_template_parms (fco) instead of
	when !processing_template_decl.

	* g++.dg/cpp26/expansion-stmt23.C: New test.
	* g++.dg/cpp26/expansion-stmt24.C: New test.
2025-08-28 10:51:09 +02:00
Jakub Jelinek cc85998ba7 c++: Fix ICE with parameter uses in expansion stmts [PR121575]
The following testcase shows an ICE when a parameter of a non-template
function is referenced in expansion stmt body.

tsubst_expr in that case assumes that either the PARM_DECL has registered
local specialization, or is this argument or it is in unevaluated context.
Parameters are always defined outside of the expansion statement
for-range-declaration or body, so for the instantiation of the body
outside of templates should always map to themselves.
It could be fixed by registering local self-specializations for all the
function parameters, but just handling it in tsubst_expr seems to be easier
and less costly.
Some PARM_DECLs, e.g. from concepts, have NULL DECL_CONTEXT, those are
handled like before (and assert it is unevaluated operand), for others
this checks if the PARM_DECL is from a non-template and in that case it
will just return t.

2025-08-28  Jakub Jelinek  <jakub@redhat.com>
	    Jason Merrill  <jason@redhat.com>

	PR c++/121575
	* pt.cc (tsubst_expr) <case PARM_DECL>: If DECL_CONTEXT (t) isn't a
	template return t for PARM_DECLs without local specialization.

	* g++.dg/cpp26/expansion-stmt20.C: New test.
2025-08-28 10:46:51 +02:00
Richard BienerandJakub Jelinek fa03e49399 Avoid mult pattern if that will break reduction constraints
synth-mult introduces multiple uses of a reduction variable
in some cases which will ultimatively fail vectorization (or ICE
with a pending change).  So avoid applying the pattern in such case.

	* tree-vect-patterns.cc (vect_synth_mult_by_constant): Avoid
	in cases that introduce multiple uses of reduction operands.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
2025-08-28 10:30:18 +02:00
Richard Biener 674b1d73e4 The divmod pattern will break reduction constraints
When we apply a divmod pattern this will break reductions by introducing
multiple uses of the reduction var, so avoid this pattern in reductions.

	* tree-vect-patterns.cc (vect_recog_divmod_pattern): Avoid
	for stmts participating in a reduction.
2025-08-28 10:30:18 +02:00
Jakub Jelinek 866697bac2 configure: Add readelf fallback for HAVE_AS_ULEB128 test [PR119367]
The following patch adds a readelf fallback if objdump nor otool don't
exist.  All of GNU binutils readelf, eu-readelf and llvm-readelf can
handle it with those options.

2025-08-28  Jakub Jelinek  <jakub@redhat.com>

	PR debug/119367
	* configure.ac (gcc_cv_as_leb128): Add fallback using readelf.
	Grammar fix in comment.
	* configure: Regenerate.
2025-08-28 10:10:28 +02:00
Jakub Jelinek b7f5a73cc1 dwarf2out: Use DW_LNS_advance_pc instead of DW_LNS_fixed_advance_pc if possible [PR119367]
In the usual case we use .loc directives and don't emit the line table
manually.  And assembler usually uses DW_LNS_advance_pc which has
uleb128 argument and in most cases will have just a single byte operand.
But if we do emit it for whatever reason (old or buggy assembler or
-gno-as-loc{,view}-support option), we do use DW_LNS_fixed_advance_pc
instead, which has fixed 2 byte operand.  That is both wasteful
in the usual case of very small advances, and more importantly will
just result in assembler errors if we need to advance over more than 65535
bytes.
The following patch uses DW_LNS_advance_pc instead if assembler supports
.uleb128 directive with a difference of two labels in the same section.
This is only possible if Minimum Instruction Length in the .debug_line
header is 1 (otherwise DW_LNS_advance_pc operand is multiplied by that
value and DW_LNS_fixed_advance_pc is not), but we emit 1 for that
on all targets.
Looking at dwarf2out.o (from dwarf2out.cc with this patch)
compiled with compilers before/after this change with additional -fpic
-gno-as-loc{,view}-support options, I see .debug_line section shrunk from
878067 bytes to 773381 bytes, so shrink by 12%.
Admittedly gas generated .debug_line is even smaller, 501374 bytes (with
-fpic and without -gno-as-loc{,view}-support options).

2025-08-28  Jakub Jelinek  <jakub@redhat.com>

	PR debug/119367
	* dwarf2out.cc (output_one_line_info_table) <case LI_adv_address>: If
	HAVE_AS_LEB128, use DW_LNS_advance_pc with dw2_asm_output_delta_uleb128
	instead of DW_LNS_fixed_advance_pc with dw2_asm_output_delta.
2025-08-28 10:09:14 +02:00
Paul Thomas fbaaefa0ce Fortran: Constructors with PDT components did not work [PR82843]
2025-08-28  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/82843
	* intrinsic.cc (gfc_convert_type_warn): If the 'from_ts' is a
	PDT instance, copy the derived type to the target ts.
	* resolve.cc (gfc_resolve_ref): A PDT component in a component
	reference can be that of the pdt_template. Unconditionally use
	component of the PDT instance to ensure that the backend_decl
	is set during translation. Likewise if a component is
	encountered that is a PDT template type, use the component
	parmeters to convert to the correct PDT instance.

gcc/testsuite/
	PR fortran/82843
	* gfortran.dg/pdt_40.f03: New test.
2025-08-28 08:17:14 +01:00
Paul Thomas 68700cafd1 Fortran: Implement correct form of PDT constructors [PR82205]
2025-08-28  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/82205
	* decl.cc (gfc_get_pdt_instance): Copy the default initializer
	for components that are not PDT parameters or parameterized. If
	any component is a pointer or allocatable set the attributes
	'pointer_comp' or 'alloc_comp' of the new PDT instance.
	* primary.cc (gfc_match_rvalue): Implement the correct form of
	PDT constructors with 'name (type parms)(component values)'.
	* trans-array.cc (structure_alloc_comps): Apply scalar default
	initializers. Array initializers await the coming change in PDT
	representation.
	* trans-io.cc (transfer_expr): Do not output the type parms of
	a PDT in list directed output.

gcc/testsuite/
	PR fortran/82205
	* gfortran.dg/pdt_22.f03: Use the correct for PDT constructors.
	* gfortran.dg/pdt_23.f03: Likewise.
	* gfortran.dg/pdt_3.f03: Likewise.
2025-08-28 08:10:04 +01:00
GCC Administrator 6aa1cbb140 Daily bump. 2025-08-28 00:20:23 +00:00
Jeff Law 58a8ecc1e9 Remove xfail marker on RISC-V test
So yet another testsuite hygiene patch.  This time turning XPASS -> PASS.  My
tester treats those cases the same so I didn't get notified that nozicond-2.c
was passing after some recent changes.

This removes the xfail marker on that test and thus the test is expected to
pass now.

Pushing to the trunk momentarily.

gcc/testsuite/
	* gcc.target/riscv/nozicond-2.c: Remove xfails.
2025-08-27 16:37:19 -06:00
Jerry DeLisle 3fb7bedb21 Fortran: H edit descriptor error with -std=f95
PR fortran/114611

gcc/fortran/ChangeLog:

	* io.cc: Issue an error on use of the H descriptor in
	a format with -std=f95 or higher. Otherwise, issue a
	warning.

gcc/testsuite/ChangeLog:

	* gfortran.dg/aliasing_dummy_1.f90: Accommodate errors
	and warnings as needed.
	* gfortran.dg/eoshift_8.f90: Likewise.
	* gfortran.dg/g77/f77-edit-h-out.f: Likewise.
	* gfortran.dg/hollerith_1.f90: Likewise.
	* gfortran.dg/io_constraints_1.f90: Likewise.
	* gfortran.dg/io_constraints_2.f90: Likewise.
	* gfortran.dg/longline.f: Likewise.
	* gfortran.dg/pr20086.f90: Likewise.
	* gfortran.dg/unused_artificial_dummies_1.f90: Likewise.
	* gfortran.dg/x_slash_1.f: Likewise.
2025-08-27 14:25:23 -07:00
Andrew Pinski a78f34b6d2 ifcvt: fix factor_out_operators (again) [PR121695]
r16-2648-gaebbc90d8c7c70 had a copy and pasto where
the second statement was supposed to be setting
the operand 1 of the phi but it was setting operand 0 instead.
This fixes typo.

Push as obvious after a quick build test for x86_64-linux-gnu.

	PR tree-optimization/121695

gcc/ChangeLog:

	* tree-if-conv.cc (factor_out_operators): Fix typo
	in assignment of the phi.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-27 12:04:56 -07:00
Paul-Antoine Arras 6fd3f8c8ba RISC-V: testsuite: Fix vf_vfmul and vf_vfrdiv
Fix type and remove useless DejaGnu directives.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmul-run-1-f64.c: Fix type.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfrdiv-run-1-f32.c: Remove
	useless dg directives.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfrdiv-run-1-f64.c: Likewise.
2025-08-27 20:25:57 +02:00
Tomasz Kamiński b3038e1ace libstdc++: Use _M_reverse to reverse partial_ordering using operator<=>
The patch r16-3414-gfcb3009a32dc33 changed the representation of unordered to
optimize reversing of order, but it did not update implementation of reversing
operator<=>(0, partial_order).

libstdc++-v3/ChangeLog:

	* libsupc++/compare
	(operator<=>(__cmp_cat::__unspec, partial_ordering)):
	Implement using _M_reverse.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-27 17:09:07 +02:00
Nathan Myers 806de30f51 libstdc++: Move tai_- and gps_clock::now impls out of ABI
This patch moves std::tai_clock::now() and std::tai_clock::now()
definitions from header inlines to static members invoked via a
normal function call, in service of stabilizing the C++20 ABI.

It also changes #if guards to mention the actual __cpp_lib_*
feature gated, not just the language version, for clarity.

New global function symbols std::chrono::tai_clock::now
and std::chrono::gps_clock::now are exported.

libstdc++-v3/ChangeLog:
	* include/std/chrono (gps_clock::now, tai_clock::now): Remove
	inline definitions.
	* src/c++20/clock.cc (gps_clock::now, tai_clock::now): New file
	for out-of-line now() impls.
	* src/c++20/Makefile.am: Mention clock.cc.
	* src/c++20/Makefile.in: Regenerate.
	* config/abi/pre/gnu.ver: add mangled now() symbols.
2025-08-27 09:50:33 -04:00
Richard Biener 5de587c1f7 Remove dead code
The following removes trivially dead code.

	* tree-vect-loop.cc (vect_transform_cycle_phi): Remove
	unused reduc_stmt_info.
2025-08-27 15:26:50 +02:00
Tomasz Kamiński fcb3009a32 libsupc++: Change _Unordered comparison value to minimum value of signed char.
For any minimum value of a signed type, its negation (with wraparound) results
in the same value, behaving like zero. Representing the unordered result with
this minimum value, along with 0 for equal, 1 for greater, and -1 for less
in partial_ordering, allows its value to be reversed using unary negation.

The operator<=(partial_order, 0) now checks if the reversed value is positive.
This works correctly because the unordered value remains unchanged and thus
negative.

libstdc++-v3/ChangeLog:

	* libsupc++/compare (_Ncmp::_Unordered): Rename and change the value
	to minimum value of signed char.
	(_Ncomp::unordered): Renamed from _Unordered, the name is reserved
	by partial_ordered::unordered.
	(partial_ordering::_M_reverse()): Define.
	(operator<=(partial_ordering, __cmp_cat::__unspec))
	(operator>=(__cmp_cat::__unspec, partial_ordering)): Implemented
	in terms of negated _M_value.
	(operator>=(partial_ordering, __cmp_cat::__unspec))
	(operator<=(__cmp_cat::__unspec, partial_ordering)): Directly
	compare _M_value, as unordered value is negative.
	(partial_ordering::unordered): Handle _Ncmp::unoredred rename.
	* python/libstdcxx/v6/printers.py: Add -128 as integer value
	for unordered, keeping 2 to preserve backward compatibility.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-27 14:50:20 +02:00
Jakub Jelinek f707c093de c++: Fix up cpp_warn on __STDCPP_FLOAT*_T__ [PR121520]
I got the cpp_warn on __STDCPP_FLOAT*_T__ if we aren't predefining those
wrong, so e.g. on powerpc64le we don't diagnose #undef __STDCPP_FLOAT16_T__.
I've added it as else if on the
if (c_dialect_cxx () && cxx_dialect > cxx20 && !floatn_nx_types[i].extended)
condition, which means cpp_warn is called in case a target supports some
extended type like _Float32x, cpp_warn is called on __STDCPP_FLOAT32_T__
(where when it supported _Float32 as well it did cpp_define_warn
(pfile, "__STDCPP_FLOAT32_T__=1") earlier).
On targets where the types aren't supported the earlier
if (FLOATN_NX_TYPE_NODE (i) == NULL_TREE) continue;
path is taken.

This patch fixes it to cpp_warn on the non-extended types for C++23
if the target doesn't support them and cpp_define_warn as before if it does.

2025-08-27  Jakub Jelinek  <jakub@redhat.com>

	PR target/121520
	* c-cppbuiltin.cc (c_cpp_builtins): Properly call cpp_warn
	for __STDCPP_FLOAT<NN>_T__ if FLOATN_NX_TYPE_NODE (i) is NULL
	for C++23 for non-extended types and don't call cpp_warn for
	extended types.
2025-08-27 14:00:51 +02:00
Richard Biener 2027574bac tree-optimization/121686 - failed SLP discovery for live recurrence
The following adjusts the SLP build for only-live stmts to not
only consider vect_induction_def and vect_internal_def that are
not part of a reduction but instead consider all non-reduction
defs that are not part of a reduction, specifically in this case
a recurrence def.  This is also a missed optimization on the
gcc-15 branch (but IMO a very minor one).

	PR tree-optimization/121686
	* tree-vect-slp.cc (vect_analyze_slp): Consider all only-live
	non-reduction defs for discovery.

	* gcc.dg/vect/pr121686.c: New testcase.
2025-08-27 11:22:24 +02:00
Andrew Pinski 18d44963e0 testsuite; Fix unprotected-allocas-1.c at -O3 [PR121684]
The problem here is after  r16-101, the 2 functions containing alloca/VLA
start to be cloned and then we un-VLA happens in using_vararray so this
is no longer testing what it should be testing.
The obvious fix is to mark using_vararray and using_alloca as noclone too.

Pushed as obvious after a quick test to make sure it is now working.

gcc/testsuite/ChangeLog:

	PR testsuite/121684
	* c-c++-common/hwasan/unprotected-allocas-0.c: Mark
	using_vararray and using_alloca as noclone too.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-26 22:13:12 -07:00
Tomasz Kamiński 45ea1c542e libstdc++: Reduce chances of object aliasing for function wrapper.
Previously, an empty functor (EmptyIdFunc) stored inside a
std::move_only_function being first member of a Composite class could have the
same address as the base of the EmptyIdFunc type (see included test cases),
resulting in two objects of the same type at the same address.

This commit addresses the issue by moving the internal buffer from the start
of the wrapper object to a position after the manager function pointer. This
minimizes aliasing with the stored buffer but doesn't completely eliminate it,
especially when multiple empty base objects are involved (PR121180).

To facilitate this member reordering, the private section of _Mo_base was
eliminated, and the corresponding _M_manager and _M_destroy members were made
protected. They remain inaccessible to users, as user-facing wrappers derive
from _Mo_base privately.

libstdc++-v3/ChangeLog:

	* include/bits/funcwrap.h (__polyfunc::_Mo_base): Reorder _M_manage
	and _M_storage members. Make _M_destroy protected and remove friend
	declaration.
	* testsuite/20_util/copyable_function/call.cc: Add test for aliasing
	base class.
	* testsuite/20_util/move_only_function/call.cc: Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-27 06:35:04 +02:00
H.J. Lu a9509987d1 x86-64: Emit the TLS call after debug marker
For a basic block with only a debug marker:

(note 3 0 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 2 3 5 2 NOTE_INSN_FUNCTION_BEG)
(debug_insn 5 2 16 2 (debug_marker) "x.c":6:3 -1 (nil))

emit the TLS call after debug marker.

gcc/

	PR target/121668
	* config/i386/i386-features.cc (ix86_emit_tls_call): Emit the
	TLS call after debug marker.

gcc/testsuite/

	PR target/121668
	* gcc.target/i386/pr121668-1a.c: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-26 21:13:27 -07:00
H.J. Lu 775ecdb237 Move pr121656.c to gcc.dg/torture
Move pr121656.c to gcc.dg/torture and replace weak attribute with noipa
attribute.  Verified by reverting

56ca14c4c4 Fix invalid right shift count with recent ifcvt changes

to trigger

FAIL: gcc.dg/torture/pr121656.c   -O1  execution test
FAIL: gcc.dg/torture/pr121656.c   -O2  execution test
FAIL: gcc.dg/torture/pr121656.c   -O3 -g  execution test
FAIL: gcc.dg/torture/pr121656.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test

on Linux/x86-64.

	PR tree-optimization/121656
	* gcc.dg/pr121656.c: Moved to ...
	* gcc.dg/torture/pr121656.c: Here.
	(dg-options): Removed.
	(foo): Replace weak attribute with noipa attribute.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-26 18:05:40 -07:00
Jeff Law edcbec0577 More RISC-V testsuite hygiene
More testsuite hygiene.  Some of the thead tests are expecting to find
xtheadvdot in the extension set, but it's not defined as a valid extension
anywhere.  I'm just removing xtheadvdot.  Someone more familiar with these
cores can add it back properly if they're so inclined.

Second, there's a space after the zifencei in a couple of the thead arch
strings.  Naturally that causes failures as well.  That's a trivial fix, just
remove the bogus whitespace.

That gets us clean on riscv.exp on the pioneer system.

The pioneer is happy, as is riscv32-elf and riscv64-elf.  Pushing to the trunk.

gcc/
	* config/riscv/riscv-cores.def (xt-c908v): Drop xtheadvdot.
	(xt-c910v2): Remove extraenous whitespace.
	(xt-c920v2): Drop xtheadvdot and remove extraeonous whitespace.

gcc/testsuite/

	* gcc.target/riscv/mcpu-xt-c908v.c: Drop xtheadvdot.
	* gcc.target/riscv/mcpu-xt-c920v2.c: Drop xtheadvdot.
2025-08-26 18:57:46 -06:00
GCC Administrator 29787cfcc2 Daily bump. 2025-08-27 00:20:22 +00:00
Sandra Loosemore a43c30cb6f OpenMP: give error when variant is the same as the base function [PR118839]
As noted in the issue, the C++ front end has deeper problems: it's
supposed to do the name lookup of the variant at the call site but is
instead doing it when parsing the "declare variant" construct, before
registering the decl for the base function.  The C++ part of the
patch is a band-aid to catch the case where there is a previous declaration
of the function and it doesn't give an undefined symbol error instead.
Some real solution ought to be included as part of fixing PR118791.

gcc/c/
	PR middle-end/118839
	* c-parser.cc (c_finish_omp_declare_variant): Error if variant
	is the same as base.

gcc/cp/
	PR middle-end/118839
	* decl.cc (omp_declare_variant_finalize_one): Error if variant
	is the same as base.

gcc/fortran/
	PR middle-end/118839
	* trans-openmp.cc (gfc_trans_omp_declare_variant): Error if variant
	is the same as base.

gcc/testsuite/
	PR middle-end/118839
	* gcc.dg/gomp/declare-variant-3.c: New.
	* gfortran.dg/gomp/declare-variant-22.f90: New.
2025-08-26 23:39:23 +00:00
Sandra Loosemore 445ce98489 OpenMP: Improve front-end error-checking for "declare variant"
This patch fixes a number of problems with parser error checking of
"declare variant", especially in the C front end.

The new C testcase unprototyped-variant.c added by this patch used to
ICE when gimplifying the call site, at least in part because the
variant was being recorded even after it was diagnosed as invalid.
There was also a large block of dead code in the C front end that was
supposed to fix up an unprototyped declaration of a variant function
to match the base function declaration, that was never executed because
it was nested in a conditional that could never be true.  I've fixed those
problems by rearranging the code and only recording the variant if it
passes the correctness checks.  I also tried to add some comments and
re-work some particularly confusing bits of code, so that it's easier to
understand.

The OpenMP specification doesn't say what the behavior of "declare
variant" with the "append_args" clause should be when the base
function is unprototyped.  The additional arguments are supposed to be
inserted between the last fixed argument of the base function and any
varargs, but without a prototype, for any given call we have no idea
which arguments are fixed and which are varargs, and therefore no idea
where to insert the additional arguments.  This used to trigger some
other diagnostics (which one depending on whether the variant was also
unprototyped), but I thought it was better to just reject this with an
explicit "sorry".

Finally, I also observed that a missing "match" clause was only
rejected if "append_args" or "adjust_args" was present.  Per the spec,
"match" has the "required" property, so if it's missing it should be
diagnosed unconditionally.  The C++ and Fortran front ends had the same
issue so I fixed this one there too.

gcc/c/ChangeLog
	* c-parser.cc (c_finish_omp_declare_variant): Rework diagnostic
	code.  Do not record variant if there are errors.  Make check for
	a missing "match" clause unconditional.

gcc/cp/ChangeLog
	* parser.cc (cp_finish_omp_declare_variant): Structure diagnostic
	code similarly to C front end.  Make check for a missing "match"
	clause unconditional.

gcc/fortran/ChangeLog
	* openmp.cc (gfc_match_omp_declare_variant): Make check for a
	missing "match" clause unconditional.

gcc/testsuite/ChangeLog
	* c-c++-common/gomp/append-args-1.c: Adjust expected output.
	* g++.dg/gomp/adjust-args-1.C: Likewise.
	* g++.dg/gomp/adjust-args-3.C: Likewise.
	* gcc.dg/gomp/adjust-args-1.c: Likewise:
	* gcc.dg/gomp/append-args-1.c: Likewise.
	* gcc.dg/gomp/unprototyped-variant.c: New.
	* gfortran.dg/gomp/adjust-args-1.f90: Adjust expected output.
	* gfortran.dg/gomp/append_args-1.f90: Likewise.
2025-08-26 23:39:22 +00:00
Jeff Law 06d5889de1 [committed] RISC-V Testsuite hygiene
Shreya and I were working through some testsuite failures and noticed that many
of the current failures on the pioneer were just silly.  We have tests that
expect to see full architecture strings in their expected output when the bulk
(some might say all) of the architecture string is irrelevant.

Worse yet, we'd have different matching lines.  ie we'd have one that would
machine rv64gc_blah_blah and another for rv64imfa_blah_blah.  Judicious
wildcard usage cleans this up considerably.

This fixes ~80 failures in the riscv.exp testsuite. Pushing to the trunk as
it's happy on the pioneer native, riscv32-elf and riscv64-elf.

gcc/testsuite/
	* gcc.target/riscv/arch-25.c: Use wildcards to simplify/eliminate
	dg-error directives.
	* gcc.target/riscv/arch-ss-2.c: Similarly.
	* gcc.target/riscv/arch-zilsd-2.c: Similarly.
	* gcc.target/riscv/arch-zilsd-3.c: Similarly.
2025-08-26 16:50:02 -06:00
Patrick Palka 06e627e1e2 libstdc++/ranges: Prefer using offset-based _CachedPosition
The offset-based partial specialization of _CachedPosition for
random-access iterators is currently only selected if the offset type is
smaller than the iterator type.  Before r12-1018-g46ed811bcb4b86 this
made sense since the main partial specialization only stored the
iterator (incorrectly).  After that bugfix, the main partial
specialization now effectively stores a std::optional<iter> so the
size constraint is inaccurate.  And this main partial specialization
must invalidate itself upon copy/move unlike the offset-based partial
specialization.  So I think we should just always prefer the
offset-based _CachedPosition for a random-access iterator, even if the
offset type happens to be larger than the iterator type.

libstdc++-v3/ChangeLog:

	* include/std/ranges (__detail::_CachedPosition): Remove
	additional size constraint on the offset-based partial
	specialization.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-08-26 15:45:57 -04:00
David Faust de04eb4cca testsuite: restrict ctf-array-7 test to 64-bit targets [PR121411]
The test fails to compile on 32-bit targets because the arrays are too
large.  Restrict to targets where the array index type is 64-bits.
Also note the relevant PR in the test comment.

	PR debug/121411

gcc/testsuite/

	* gcc.dg/debug/ctf/ctf-array-7.c: Restrict to lp64,llp64
	targets.
2025-08-26 12:18:49 -07:00
Torbjörn SVENSSON 4b4ee2fa4a testsuite: arm: Disable sched2 and sched3 in unsigned-extend-2.c
Disable sched2 and sched3 to only have one order of instructions to
consider.

gcc/testsuite/ChangeLog:

	* gcc.target/arm/unsigned-extend-2.c: Disable sched2 and sched3
	and update function body to match.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2025-08-26 20:51:56 +02:00
Tomasz Kamiński 390f3a690c libstdc++: Do not require assignment for vector::resize(n, v) [PR90192]
This patch introduces a new function, _M_fill_append, which is invoked when
copies of the same value are appended to the end of a vector. Unlike
_M_fill_insert(end(), n, v), _M_fill_append never permute elements in place,
so it does not require:
* vector element type to be assignable;
* a copy of the inserted value, in the case where it points to an
  element of the vector.

vector::resize(n, v) now uses _M_fill_append, fixing the non-conformance where
element types were required to be assignable.

In addition, _M_fill_insert(end(), n, v) now delegates to _M_fill_append, which
eliminates an unnecessary copy of v when the existing capacity is used.

	PR libstdc++/90192

libstdc++-v3/ChangeLog:

	* include/bits/stl_vector.h (vector<T>::_M_fill_append): Declare.
	(vector<T>::fill): Use _M_fill_append instead of _M_fill_insert.
	* include/bits/vector.tcc (vector<T>::_M_fill_append): Define
	(vector<T>::_M_fill_insert): Delegate to _M_fill_append when
	elements are appended.
	* testsuite/23_containers/vector/modifiers/moveable.cc: Updated
	copycount for inserting at the end (appending).
	* testsuite/23_containers/vector/modifiers/resize.cc: New test.
	* testsuite/backward/hash_set/check_construct_destroy.cc: Updated
	copycount, the hash_set constructor uses insert to fill buckets
	with nullptrs.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-26 18:18:32 +02:00
Tomasz Kamiński 250dd5b560 libstdc++: Refactor bound arguments storage for bind_front/back
This patch refactors the implementation of bind_front and bind_back to avoid
using std::tuple for argument storage. Instead, bound arguments are now:
* stored directly if there is only one,
* within a dedicated _Bound_arg_storage otherwise.

_Bound_arg_storage is less expensive to instantiate and access than std::tuple.
It can also be trivially copyable, as it doesn't require a non-trivial assignment
operator for reference types. Storing a single argument directly provides similar
benefits compared to both one element tuple or _Bound_arg_storage.

_Bound_arg_storage holds each argument in an _Indexed_bound_arg base object.
The base class is parameterized by both type and index to allow storing
multiple arguments of the same type. Invocations are handled by _S_apply_front
amd _S_apply_back static functions, which simulate explicit object parameters.
To facilitate this, the __like_t alias template is now unconditionally available
since C++11 in bits/move.h.

libstdc++-v3/ChangeLog:

	* include/bits/move.h (std::__like_impl, std::__like_t): Make
	available in c++11.
	* include/std/functional (std::_Indexed_bound_arg)
	(std::_Bound_arg_storage, std::__make_bound_args): Define.
	(std::_Bind_front, std::_Bind_back): Use _Bound_arg_storage.
	* testsuite/20_util/function_objects/bind_back/1.cc: Expand
	test to cover cases of 0, 1, many bound args.
	* testsuite/20_util/function_objects/bind_back/111327.cc: Likewise.
	* testsuite/20_util/function_objects/bind_front/1.cc: Likewise.
	* testsuite/20_util/function_objects/bind_front/111327.cc: Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-26 18:16:04 +02:00
Tomasz Kamiński 36ab9b9c67 libstdc++: Specialize _Never_valueless_alt for jthread, stop_token and stop_source
The move constructors for stop_source and stop_token are equivalent to
copying and clearing the raw pointer, as they are wrappers for a
counted-shared state.

For jthread, the move constructor performs a member-wise move of stop_source
and thread. While std::thread could also have a _Never_valueless_alt
specialization due to its inexpensive move (only moving a handle), doing
so now would change the ABI. This patch takes the opportunity to correct
this behavior for jthread, before C++20 API is marked stable.

libstdc++-v3/ChangeLog:

	* include/std/stop_token (__variant::_Never_valueless_alt): Declare.
	(__variant::_Never_valueless_alt<std::stop_token>)
	(__variant::_Never_valueless_alt<std::stop_source>): Define.
	* include/std/thread: (__variant::_Never_valueless_alt): Declare.
	(__variant::_Never_valueless_alt<std::jthread>): Define.
2025-08-26 15:21:41 +02:00
liuhongt 9823624395 Enable unroll in the vectorizer when there's reduction for FMA/DOT_PROD_EXPR/SAD_EXPR
The patch is trying to unroll the vectorized loop when there're
FMA/DOT_PRDO_EXPR/SAD_EXPR reductions, it will break cross-iteration dependence
and enable more parallelism(since vectorize will also enable partial
sum).

When there's gather/scatter or scalarization in the loop, don't do the
unroll since the performance bottleneck is not at the reduction.

The unroll factor is set according to FMA/DOT_PROX_EXPR/SAD_EXPR
CEIL ((latency * throught), num_of_reduction)
.i.e
For fma, latency is 4, throught is 2, if there's 1 FMA for reduction
then unroll factor is 2 * 4 / 1 = 8.

There's also a vect_unroll_limit, the final suggested_unroll_factor is
set as MIN (vect_unroll_limix, 8).

The vect_unroll_limit is mainly for register pressure, avoid to many
spills.
Ideally, all instructions in the vectorized loop should be used to
determine unroll_factor with their (latency * throughput) / number,
but that would too much for this patch, and may just GIGO, so the
patch only considers 3 kinds of instructions: FMA, DOT_PROD_EXPR,
SAD_EXPR.

Note when DOT_PROD_EXPR is not native support,
m_num_reduction += 3 * count which almost prevents unroll.

There's performance boost for simple benchmark with DOT_PRDO_EXPR/FMA
chain, slight improvement in SPEC2017 performance.

gcc/ChangeLog:

	* config/i386/i386.cc (ix86_vector_costs::ix86_vector_costs):
	Addd new memeber m_num_reduc, m_prefer_unroll.
	(ix86_vector_costs::add_stmt_cost): Set m_prefer_unroll and
	m_num_reduc
	(ix86_vector_costs::finish_cost): Determine
	m_suggested_unroll_vector with consideration of
	reduc_lat_mult_thr, m_num_reduction and
	ix86_vect_unroll_limit.
	* config/i386/i386.h (enum ix86_reduc_unroll_factor): New
	enum.
	(processor_costs): Add reduc_lat_mult_thr and
	vect_unroll_limit.
	* config/i386/x86-tune-costs.h: Initialize
	reduc_lat_mult_thr and vect_unroll_limit.
	* config/i386/i386.opt: Add -param=ix86-vect-unroll-limit.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/vect_unroll-1.c: New test.
	* gcc.target/i386/vect_unroll-2.c: New test.
	* gcc.target/i386/vect_unroll-3.c: New test.
	* gcc.target/i386/vect_unroll-4.c: New test.
	* gcc.target/i386/vect_unroll-5.c: New test.
2025-08-26 05:52:38 -07:00
Paul-Antoine Arras 7c2ab5865c [PATCH] RISC-V: Add pattern for reverse floating-point divide
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into a div RTL instruction. The vec_duplicate is the
dividend operand.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f       v2,fa0
  vfdiv.vv       v1,v2,v1

After, we get only one:
  vfrdiv.vf      v1,v1,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfrdiv_vf_<mode>): Add new pattern to
	combine vec_duplicate + vfdiv.vv into vfrdiv.vf.
	* config/riscv/vector.md (@pred_<optab><mode>_reverse_scalar): Allow VLS
	modes.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfrdiv.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop.h: Add support for reverse
	variants.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_data.h: Add data for
	reverse variants.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfrdiv-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfrdiv-run-1-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfrdiv-run-1-f64.c: New test.
2025-08-26 06:19:53 -06:00
Tamar Christina 28ab83367e AArch64: extend cost model to cost outer loop vect where the inner loop is invariant [PR121290]
Consider the example:

void
f (int *restrict x, int *restrict y, int *restrict z, int n)
{
  for (int i = 0; i < 4; ++i)
    {
      int res = 0;
      for (int j = 0; j < 100; ++j)
        res += y[j] * z[i];
      x[i] = res;
    }
}

we currently vectorize as

f:
        movi    v30.4s, 0
        ldr     q31, [x2]
        add     x2, x1, 400
.L2:
        ld1r    {v29.4s}, [x1], 4
        mla     v30.4s, v29.4s, v31.4s
        cmp     x2, x1
        bne     .L2
        str     q30, [x0]
        ret

which is not useful because by doing outer-loop vectorization we're performing
less work per iteration than we would had we done inner-loop vectorization and
simply unrolled the inner loop.

This patch teaches the cost model that if all your leafs are invariant, then
adjust the loop cost by * VF, since every vector iteration has at least one lane
really just doing 1 scalar.

There are a couple of ways we could have solved this, one is to increase the
unroll factor to process more iterations of the inner loop.  This removes the
need for the broadcast, however we don't support unrolling the inner loop within
the outer loop.  We only support unrolling by increasing the VF, which would
affect the outer loop as well as the inner loop.

We also don't directly support costing inner-loop vs outer-loop vectorization,
and as such we're left trying to predict/steer the cost model ahead of time to
what we think should be profitable.  This patch attempts to do so using a
heuristic which penalizes the outer-loop vectorization.

We now cost the loop as

note:  Cost model analysis:
  Vector inside of loop cost: 2000
  Vector prologue cost: 4
  Vector epilogue cost: 0
  Scalar iteration cost: 300
  Scalar outside cost: 0
  Vector outside cost: 4
  prologue iterations: 0
  epilogue iterations: 0
missed:  cost model: the vector iteration cost = 2000 divided by the scalar iteration cost = 300 is greater or equal to the vectorization factor = 4.
missed:  not vectorized: vectorization not profitable.
missed:  not vectorized: vector version will never be profitable.
missed:  Loop costings may not be worthwhile.

And subsequently generate:

.L5:
        add     w4, w4, w7
        ld1w    z24.s, p6/z, [x0, #1, mul vl]
        ld1w    z23.s, p6/z, [x0, #2, mul vl]
        ld1w    z22.s, p6/z, [x0, #3, mul vl]
        ld1w    z29.s, p6/z, [x0]
        mla     z26.s, p6/m, z24.s, z30.s
        add     x0, x0, x8
        mla     z27.s, p6/m, z23.s, z30.s
        mla     z28.s, p6/m, z22.s, z30.s
        mla     z25.s, p6/m, z29.s, z30.s
        cmp     w4, w6
        bls     .L5

and avoids the load and replicate if it knows it has enough vector pipes to do
so.

gcc/ChangeLog:

	PR target/121290
	* config/aarch64/aarch64.cc
	(class aarch64_vector_costs ): Add m_loop_fully_scalar_dup.
	(aarch64_vector_costs::add_stmt_cost): Detect invariant inner loops.
	(adjust_body_cost): Adjust final costing if m_loop_fully_scalar_dup.

gcc/testsuite/ChangeLog:

	PR target/121290
	* gcc.target/aarch64/pr121290.c: New test.
2025-08-26 13:19:15 +01:00
Paul-Antoine Arras f864fc36fe [PATCH] RISC-V: Add pattern for vector-scalar single-width floating-point multiply
This pattern enables the combine pass (or late-combine, depending on the case)
to merge a vec_duplicate into a mult RTL instruction.

Before this patch, we have two instructions, e.g.:
  vfmv.v.f       v2,fa0
  vfmul.vv       v1,v1,v2

After, we get only one:
  vfmul.vf       v2,v2,fa0

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*vfmul_vf_<mode>): Add new pattern to
	combine vec_duplicate + vfmul.vv into vfmul.vf.
	* config/riscv/vector.md (@pred_<optab><mode>_scalar): Allow VLS modes.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f16.c: Add vfmul.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-1-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-2-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f32.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-4-f64.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop.h: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_data.h: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_binop_run.h: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmul-run-1-f16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmul-run-1-f32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmul-run-1-f64.c: New test.
	* gcc.target/riscv/rvv/autovec/vls/floating-point-mul-2.c: Adjust scan
	dump.
	* gcc.target/riscv/rvv/autovec/vls/floating-point-mul-3.c: Likewise.
2025-08-26 06:16:04 -06:00
Jeff Law 86a5e7770c Fix RISC-V bootstrap
Recent changes from Kito have an unused parameter.  On the assumption that he's
going to likely want it as part of the API, I've simply removed the parameter's
name until such time as Kito needs it.

This should restore bootstrapping to the RISC-V port.  Committing now rather
than waiting for the CI system given bootstrap builds currently fail.

	* config/riscv/riscv.cc (riscv_arg_partial_bytes): Remove name
	from unused parameter.
2025-08-26 06:11:05 -06:00
Richard Earnshaw 7c510fdcf1 arm: testsuite: make gcc.target/arm/bics_3.c generate bics again
The compiler is getting too smart!  But this test is really intended
to test that we generate BICS instead of BIC+CMP, so make the test use
something that we can't subsequently fold away into a bit minipulation
of a store-flag value.

I've also added a couple of extra tests, so we now cover both the
cases where we fold the result away and where that cannot be done.
Also add a test that we don't generate a compare against 0, since
that's really part of what this test is covering.

gcc/testsuite:

	* gcc.target/arm/bics_3.c: Add some additional tests that
	cannot be folded to a bit manipulation.
2025-08-26 13:03:15 +01:00
Richard Biener 670e2b4d3e Compute vect_reduc_type off SLP node instead of stmt-info
The following changes the vect_reduc_type API to work on the SLP node.
The API is only used from the aarch64 backend, so all changes are there.
In particular I noticed aarch64_force_single_cycle is invoked even
for scalar costing (where the flag tested isn't computed yet), I
figured in scalar costing all reductions are a single cycle.

	* tree-vectorizer.h (vect_reduc_type): Get SLP node as argument.
	* config/aarch64/aarch64.cc (aarch64_sve_in_loop_reduction_latency):
	Take SLO node as argument and adjust.
	(aarch64_in_loop_reduction_latency): Likewise.
	(aarch64_detect_vector_stmt_subtype): Adjust.
	(aarch64_vector_costs::count_ops): Likewise.  Treat reductions
	during scalar costing as single-cycle.
2025-08-26 13:13:55 +02:00
Richard Biener 68e692eed9 tree-optimization/121659 - bogus swap of reduction operands
The following addresses a bogus swapping of SLP operands of a
reduction operation which gets STMT_VINFO_REDUC_IDX out of sync
with the SLP operand order.  In fact the most obvious mistake is
that we simply swap operands even on the first stmt even when
there's no difference in the comparison operators (for == and !=
at least).  But there are more latent issues that I noticed and
fixed up in the process.

	PR tree-optimization/121659
	* tree-vect-slp.cc (vect_build_slp_tree_1): Do not allow
	matching up comparison operators by swapping if that would
	disturb STMT_VINFO_REDUC_IDX.  Make sure to only
	actually mark operands for swapping when there was a
	mismatch and we're not processing the first stmt.

	* gcc.dg/vect/pr121659.c: New testcase.
2025-08-26 13:00:16 +02:00
Richard Biener b01ae7a2b5 Fix UBSAN issue with load-store data refactoring
The following makes sure to read from the lanes_ifn member only
when necessary (and thus it was set).

	* tree-vect-stmts.cc (vectorizable_store): Access lanes_ifn
	only when VMAT_LOAD_STORE_LANES.
	(vectorizable_load): Likewise.
2025-08-26 13:00:15 +02:00
Richard Biener 0240c52eb6 Remove STMT_VINFO_REDUC_VECTYPE_IN
This was added when invariants/externals outside of SLP didn't have
an easily accessible vector type.  Now it's redundant so the
following removes it.

	* tree-vectorizer.h (stmt_vec_info_::reduc_vectype_in): Remove.
	(STMT_VINFO_REDUC_VECTYPE_IN): Likewise.
	* tree-vect-loop.cc (vect_is_emulated_mixed_dot_prod): Get
	at the input vectype via the SLP node child.
	(vectorizable_lane_reducing): Likewise.
	(vect_transform_reduction): Likewise.
	(vectorizable_reduction): Do not set STMT_VINFO_REDUC_VECTYPE_IN.
2025-08-26 08:51:41 +02:00
Jakub Jelinek d551f88f88 i386: Fix up recent changes to use GFNI for rotates/shifts [PR121658]
The vgf2p8affineqb_<mode><mask_name> pattern uses "register_operand"
predicate for the first input operand, so using "general_operand"
for the rotate operand passed to it leads to ICEs, and so does
the "nonimmediate_operand" in the <insn>v16qi3 define_expand.
The following patch fixes it by using "register_operand" in the former
case (that pattern is TARGET_GFNI only) and using force_reg in
the latter case (the pattern is TARGET_XOP || TARGET_GFNI and for XOP
we can handle MEM operand).

The rest of the changes are small formatting tweaks or use of const0_rtx
instead of GEN_INT (0).

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

	PR target/121658
	* config/i386/sse.md (<insn><mode>3 any_shift): Use const0_rtx
	instead of GEN_INT (0).
	(cond_<insn><mode> any_shift): Likewise.  Formatting fix.
	(<insn><mode>3 any_rotate): Use register_operand predicate instead of
	general_operand for match_operand 1.  Use const0_rtx instead of
	GEN_INT (0).
	(<insn>v16qi3 any_rotate): Use force_reg on operands[1].  Formatting
	fix.
	* config/i386/i386.cc (ix86_shift_rotate_cost): Comment formatting
	fixes.

	* gcc.target/i386/pr121658.c: New test.
2025-08-26 06:43:39 +02:00
GCC Administrator 2dfd2779e3 Daily bump. 2025-08-26 00:21:05 +00:00
Pan Li 74f139fa21 RISC-V: Add test for vec_duplicate + vmacc.vv unsigned combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vmacc.vvm
combine to vmacc.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
	for vx combine.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmacc-run-1-u16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmacc-run-1-u32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmacc-run-1-u64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmacc-run-1-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-26 08:18:26 +08:00
Pan Li ed2f4bff8b RISC-V: Add test for vec_duplicate + vmacc.vv signed combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vmacc.vvm
combine to vmacc.vx, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c: Add asm check
	for vx combine.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary.h: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary_data.h: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_ternary_run.h: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmacc-run-1-i16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmacc-run-1-i32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmacc-run-1-i64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmacc-run-1-i8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-26 08:18:26 +08:00
Pan Li 25037a0271 RISC-V: Combine vec_duplicate + vmacc.vv to vmacc.vx on GR2VR cost
This patch would like to combine the vec_duplicate + vmacc.vv to the
vmacc.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

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

  #define DEF_VX_TERNARY_CASE_0(T, OP_1, OP_2, NAME)                        \
  void                                                                      \
  test_vx_ternary_##NAME##_##T##_case_0 (T * restrict vd, T * restrict vs2, \
                                         T rs1, unsigned n)                 \
  {                                                                         \
    for (unsigned i = 0; i < n; i++)                                        \
      vd[i] = vd[i] OP_2 vs2[i] OP_1 rs1;                                   \
  }

  DEF_VX_TERNARY_CASE_0(int32_t, *, +, macc)

Before this patch:
  11   │     beq a3,zero,.L8
  12   │     vsetvli a5,zero,e32,m1,ta,ma
  13   │     vmv.v.x v2,a2
  ...
  16   │ .L3:
  17   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  22   │     vmacc.vv v1,v2,v3
  ...
  25   │     bne a3,zero,.L3

After this patch:
  11   │     beq a3,zero,.L8
  ...
  14   │ .L3:
  15   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  20   │     vmacc.vx v1,a2,v3
  ...
  23   │     bne a3,zero,.L3

gcc/ChangeLog:

	* config/riscv/vector.md (@pred_mul_plus_vx_<mode>): Add new pattern to
	generate vmacc rtl.
	(*pred_macc_<mode>_scalar_undef): Ditto.
	* config/riscv/autovec-opt.md (*vmacc_vx_<mode>): Add new
	pattern to match the vmacc vx combine.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-26 08:18:25 +08:00
Jakub Jelinek 948f20cc52 omp-expand: Initialize fd->loop.n2 if needed for the zero iter case [PR121453]
When expand_omp_for_init_counts is called from expand_omp_for_generic,
zero_iter1_bb is NULL and the code always creates a new bb in which it
clears fd->loop.n2 var (if it is a var), because it can dominate code
with lastprivate guards that use the var.
When called from other places, zero_iter1_bb is non-NULL and so we don't
insert the clearing (and can't, because the same bb is used also for the
non-zero iterations exit and in that case we need to preserve the iteration
count).  Clearing is also not necessary when e.g. outermost collapsed
loop has constant non-zero number of iterations, in that case we initialize the
var to something already earlier.  The following patch makes sure to clear
it if it hasn't been initialized yet before the first check for zero iterations.

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

	PR middle-end/121453
	* omp-expand.cc (expand_omp_for_init_counts): Clear fd->loop.n2
	before first zero count check if zero_iter1_bb is non-NULL upon
	entry and fd->loop.n2 has not been written yet.

	* gcc.dg/gomp/pr121453.c: New test.
2025-08-26 00:28:10 +02:00
H.J. Lu 1b6b275363 Add a test for PR tree-optimization/121656
PR tree-optimization/121656
	* gcc.dg/pr121656.c: New file.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-25 13:03:31 -07:00
David Faust c77d79785d ctf: avoid overflow for array num elements [PR121411]
CTF array encoding uses uint32 for number of elements.  This means there
is a hard upper limit on array types which the format can represent.

GCC internally was also using a uint32_t for this, which would overflow
when translating from DWARF for arrays with more than UINT32_MAX
elements.  Use an unsigned HOST_WIDE_INT instead to fetch the array
bound, and fall back to CTF_K_UNKNOWN if the array cannot be
represented in CTF.

	PR debug/121411

gcc/

	* dwarf2ctf.cc (gen_ctf_subrange_type): Use unsigned HWI for
	array_num_elements.  Fallback to CTF_K_UNKNOWN if the array
	type has too many elements for CTF to represent.

gcc/testsuite/

	* gcc.dg/debug/ctf/ctf-array-7.c: New test.
2025-08-25 12:01:17 -07:00
Andrew Pinski 490948d951 forwprop: Boolify simplify_permutation
After the return type of remove_prop_source_from_use was changed to void,
simplify_permutation only returns 1 or 0 so it can be boolified.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (simplify_permutation): Boolify.
	(pass_forwprop::execute): No longer handle 2 as the return
	from simplify_permutation.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-25 08:29:25 -07:00
Andrew Pinski b74fcd0330 Forwprop: boolify forward_propagate_into_comparison
After changing the return type of remove_prop_source_from_use,
forward_propagate_into_comparison will never return 2. So boolify
forward_propagate_into_comparison.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (forward_propagate_into_comparison): Boolify.
	(pass_forwprop::execute): Don't handle return of 2 from
	forward_propagate_into_comparison.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-25 08:29:25 -07:00
Andrew Pinski dbed17b1ee forwprop: Remove return type of remove_prop_source_from_use
Since r5-4705-ga499aac5dfa5d9, remove_prop_source_from_use has always
return false. This removes the return type of remove_prop_source_from_use
and cleans up the usage of remove_prop_source_from_use.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (remove_prop_source_from_use): Remove
	return type.
	(forward_propagate_into_comparison): Update dealing with
	no return type of remove_prop_source_from_use.
	(forward_propagate_into_gimple_cond): Likewise.
	(simplify_permutation): Likewise.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-25 08:29:24 -07:00
Andrew Pinski 22d623dca3 forwprop: Mark the old switch index for (maybe) dceing
While looking at this code I noticed that we don't remove
the old switch index assignment if it is only used in the switch
after it is modified in simplify_gimple_switch.
This fixes that by marking the old switch index for the dce worklist.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (simplify_gimple_switch): Add simple_dce_worklist
	argument. Mark the old index when doing the replacement.
	(pass_forwprop::execute): Update call to simplify_gimple_switch.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-25 08:29:24 -07:00
Andrew Pinski 7269aa0765 Rewrite bool loads for undefined case [PR121279]
Just like r16-465-gf2bb7ffe84840d8 but this time
instead of a VCE there is a full on load from a boolean.
This showed up when trying to remove the extra copy
in the testcase from the revision mentioned above (pr120122-1.c).
So when moving loads from a boolean type from being conditional
to non-conditional, the load needs to become a full load and then
casted into a bool so that the upper bits are correct.

Bitfields loads will always do the truncation so they don't need to
be rewritten. Non boolean types always do the truncation too.

What we do is wrap the original reference with a VCE which causes
the full load and then do a casting to do the truncation. Using
fold_build1 with VCE will do the correct thing if there is a secondary
VCE and will also fold if this was just a plain MEM_REF so there is
no need to handle those 2 cases special either.

Changes since v1:
* v2: Use VIEW_CONVERT_EXPR instead of doing a manual load.
      Accept all non mode precision loads rather than just
      boolean ones.
* v3: Move back to checking boolean type. Don't handle BIT_FIELD_REF.
      Add asserts for IMAG/REAL_PART_EXPR.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/121279

gcc/ChangeLog:

	* gimple-fold.cc (gimple_needing_rewrite_undefined): Return
	true for non mode precision boolean loads.
	(rewrite_to_defined_unconditional): Handle non mode precision loads.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-25 08:26:34 -07:00
Andrew Pinski 2e1dfaad2a LIM: Manually put uninit decl into ssa
When working on PR121279, I noticed that lim
would create an uninitialized decl and marking
it with supression for uninitialization warning.
This is fine but then into ssa would just call
get_or_create_ssa_default_def on that new decl which
could in theory take some extra compile time to figure
that out.
Plus when doing the rewriting for undefinedness, there
would now be a VCE around the decl. This means the ssa
name is kept around and not propagated in some cases.
So instead this patch manually calls get_or_create_ssa_default_def
to get the "uninitalized" ssa name for this decl and
no longer needs the write into ssa nor for undefined ness.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-loop-im.cc (execute_sm): Call
	get_or_create_ssa_default_def for the new uninitialized
	decl.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-25 08:26:34 -07:00
Takayuki 'January June' Suwa e2533e488f xtensa: Make use of compact insn definition syntax for insns whose have multiple alternatives
The use of compact syntax makes the relationship between asm output,
operand constraints, and insn attributes easier to understand and modify,
especially for "mov<mode>_internal".

gcc/ChangeLog:

	* config/xtensa/xtensa.md (addsi3, <u>mulhisi3, andsi3,
	zero_extend<mode>si2, extendhisi2_internal, movsi_internal,
	movhi_internal, movqi_internal, movsf_internal, ashlsi3_internal,
	ashrsi3, lshrsi3, rotlsi3, rotrsi3):
	Rewrite in compact syntax.
2025-08-25 07:55:09 -07:00
Takayuki 'January June' Suwa b11ee352ca xtensa: Simplify "*masktrue_const_bitcmpl" insn pattern
gcc/ChangeLog:

	* config/xtensa/xtensa.md
	(The auxiliary define_split for *masktrue_const_bitcmpl):
	Use a more concise function call, i.e.,
	(1 << GET_MODE_BITSIZE (mode)) - 1 is equivalent to
	GET_MODE_MASK (mode).
2025-08-25 07:55:08 -07:00
Takayuki 'January June' Suwa ee8f20d61d xtensa: Simplify "zero_extend[hq]isi2" insn patterns
gcc/ChangeLog:

	* config/xtensa/xtensa.md (mode_bits):
	New mode attribute.
	(zero_extend<mode>si2): Use the appropriate mode iterator and
	attribute to unify "zero_extend[hq]isi2" to this description.
2025-08-25 07:55:08 -07:00
Jakub Jelinek 05baaa6feb c++: Implement C++ CWG3048 - Empty destructuring expansion statements
The following patch implements the proposed resolution of
https://cplusplus.github.io/CWG/issues/3048.html
Instead of rejecting structured binding size it just builds a normal
decl rather than structured binding declaration.

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

	* pt.cc (finish_expansion_stmt): Implement C++ CWG3048
	- Empty destructuring expansion statements.  Don't error for
	destructuring expansion stmts if sz is 0, don't call
	fit_decomposition_lang_decl if n is 0 and pass NULL rather than
	this_decomp to cp_finish_decl.

	* g++.dg/cpp26/expansion-stmt15.C: Don't expect error on
	destructuring expansion stmts with structured binding size 0.
	* g++.dg/cpp26/expansion-stmt21.C: New test.
	* g++.dg/cpp26/expansion-stmt22.C: New test.
2025-08-25 16:29:17 +02:00
Jakub Jelinek 52c29a6a9d c++: Check for *jump_target earlier in cxx_bind_parameters_in_call [PR121601]
The following testcase ICEs, because the
      /* Check we aren't dereferencing a null pointer when calling a non-static
         member function, which is undefined behaviour.  */
      if (i == 0 && DECL_OBJECT_MEMBER_FUNCTION_P (fun)
          && integer_zerop (arg)
          /* But ignore calls from within compiler-generated code, to handle
             cases like lambda function pointer conversion operator thunks
             which pass NULL as the 'this' pointer.  */
          && !(TREE_CODE (t) == CALL_EXPR && CALL_FROM_THUNK_P (t)))
        {
          if (!ctx->quiet)
            error_at (cp_expr_loc_or_input_loc (x),
                      "dereferencing a null pointer");
          *non_constant_p = true;
        }
checking is done before testing if (*jump_target).  Especially when
throws (jump_target), arg can be (and is on this testcase) NULL_TREE,
so calling integer_zerop on it ICEs.

Fixed by moving the if (*jump_target) test earlier.

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

	PR c++/121601
	* constexpr.cc (cxx_bind_parameters_in_call): Move break
	if *jump_target before the check for null this object pointer.

	* g++.dg/cpp26/constexpr-eh16.C: New test.
2025-08-25 16:27:35 +02:00
Richard Biener 2d4b7b983c tree-optimization/121638 - missed SLP discovery of live induction
The following fixes a missed SLP discovery of a live induction.
Our pattern matching of those fails because of the PR81529 fix
which I think was misguided and should now no longer be relevant.
So this essentially reverts that fix.  I have added a GIMPLE
testcase to increase the chance the particular IL is preserved
through the future.

This shows that how we make some IVs live because of early-break
isn't quite correct, so I had to preserve a hack here.  Hopefully
to be investigated at some point.

	PR tree-optimization/121638
	* tree-vect-stmts.cc (process_use): Do not make induction
	PHI backedge values relevant.

	* gcc.dg/vect/pr121638.c: New testcase.
2025-08-25 14:44:33 +02:00
Indu BhagatandClaudiu Zissulescu 79e22e16f6 targhooks: i386: rename TAG_SIZE to TAG_BITSIZE
gcc/Changelog:

	* asan.h (HWASAN_TAG_SIZE): Use targetm.memtag.tag_bitsize.
	* config/i386/i386.cc (ix86_memtag_tag_size): Rename to
	ix86_memtag_tag_bitsize.
	(TARGET_MEMTAG_TAG_SIZE): Renamed to TARGET_MEMTAG_TAG_BITSIZE.
	* doc/tm.texi (TARGET_MEMTAG_TAG_SIZE): Likewise.
	* doc/tm.texi.in (TARGET_MEMTAG_TAG_SIZE): Likewise.
	* target.def (tag_size): Rename to tag_bitsize.
	* targhooks.cc (default_memtag_tag_size): Rename to
	default_memtag_tag_bitsize.
	* targhooks.h (default_memtag_tag_size): Likewise.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Co-authored-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
2025-08-25 14:17:32 +03:00
Kito Cheng d914cb6743 RISC-V: Replace deprecated FUNCTION_VALUE/LIBCALL_VALUE macros with target hooks
The FUNCTION_VALUE and LIBCALL_VALUE macros are deprecated in favor of
the TARGET_FUNCTION_VALUE and TARGET_LIBCALL_VALUE target hooks.  This
patch replaces the macro definitions with proper target hook implementations.

This change is also a preparatory step for VLS calling convention support,
which will require additional information that is more easily handled
through the target hook interface.

gcc/ChangeLog:

	* config/riscv/riscv-protos.h (riscv_init_cumulative_args): Change
	fntype parameter from tree to const_tree.
	* config/riscv/riscv.cc (riscv_init_cumulative_args): Likewise.
	(riscv_function_value): Replace with new implementation that
	conforms to TARGET_FUNCTION_VALUE hook signature.
	(riscv_libcall_value): New function implementing TARGET_LIBCALL_VALUE.
	(TARGET_FUNCTION_VALUE): Define.
	(TARGET_LIBCALL_VALUE): Define.
	* config/riscv/riscv.h (FUNCTION_VALUE): Remove.
	(LIBCALL_VALUE): Remove.
2025-08-25 17:07:03 +08:00
Andi Kleen 001cd39749 Use x86 GFNI for vectorized constant byte shifts/rotates
The GFNI AVX gf2p8affineqb instruction can be used to implement
vectorized byte shifts or rotates. This patch uses them to implement
shift and rotate patterns to allow the vectorizer to use them.
Previously AVX couldn't do rotates (except with XOP) and had to handle
8 bit shifts with a half throughput 16 bit shift.

This is only implemented for constant shifts. In theory it could
be used with a lookup table for variable shifts, but it's unclear
if it's worth it.

The vectorizer cost model could be improved, but seems to work for now.
It doesn't model the true latencies of the instructions. Also it doesn't
account for the memory loading of the mask, assuming that for a loop
it will be loaded outside the loop.

The instructions would also support more complex patterns
(e.g. arbitary bit movement or inversions), so some of the tricks
applied to ternlog could be applied here too to collapse
more code. It's trickier because the input patterns
can be much longer since they can apply to every bit individually. I didn't
attempt any of this.

There's currently no test case for the masked/cond_ variants, they seem
to be difficult to trigger with the vectorizer. Suggestions for a test
case for them welcome.

gcc/ChangeLog:

	* config/i386/i386-expand.cc (ix86_vgf2p8affine_shift_matrix):
	New function to lookup shift/rotate matrixes for gf2p8affine.
	* config/i386/i386-protos.h (ix86_vgf2p8affine_shift_matrix):
	Declare new function.
	* config/i386/i386.cc (ix86_shift_rotate_cost): Add cost model
	for shift/rotate implemented using gf2p8affine.
	* config/i386/sse.md (VI1_AVX512_3264): New mode iterator.
	(<insn><mode>3): Add GFNI case for shift patterns.
	(cond_<insn><mode>3): New pattern.
	(<insn><mode>3<mask_name>): Dito.
	(<insn>v16qi): New rotate pattern to handle XOP V16QI case
	and GFNI.
	(rotl<mode>3, rotr<mode>3): Exclude V16QI case.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/shift-gf2p8affine-1.c: New test
	* gcc.target/i386/shift-gf2p8affine-2.c: New test
	* gcc.target/i386/shift-gf2p8affine-3.c: New test
	* gcc.target/i386/shift-v16qi-4.c: New test
	* gcc.target/i386/shift-gf2p8affine-5.c: New test
	* gcc.target/i386/shift-gf2p8affine-6.c: New test
	* gcc.target/i386/shift-gf2p8affine-7.c: New test
2025-08-25 00:12:10 -07:00
Xi Ruoyao 64932714a0 LoongArch: Fix ICE in highway-1.3.0 testsuite [PR121634]
I can't believe I made such a stupid pasto and the regression test
didn't detect anything wrong.

	PR target/121634

gcc/

	* config/loongarch/simd.md (simd_maddw_evod_<mode>_<su>): Use
	WVEC_HALF instead of WVEC for the mode of the sign_extend for
	the rhs of multiplication.

gcc/testsuite/

	* gcc.target/loongarch/pr121634.c: New test.
2025-08-25 11:08:46 +08:00
Jeff Law 56ca14c4c4 Fix invalid right shift count with recent ifcvt changes
I got too clever trying to simplify the right shift computation in my recent
ifcvt patch.  Interestingly enough, I haven't seen anything but the Linaro CI
configuration actually trip the problem, though the code is clearly wrong.

The problem I was trying to avoid were the leading zeros when calling clz on a
HWI when the real object is just say 32 bits.

The net is we get a right shift count of "2" when we really wanted a right
shift count of 30.  That causes the execution aspect of bics_3 to fail.

The scan failures are due to creating slightly more efficient code. THe new
code sequences don't need to use conditional execution for selection and thus
we can use bic rather bics which requires a twiddle in the scan.

I reviewed recent bug reports and haven't seen one for this issue.  So no new
testcase as this is covered by the armv7 testsuite in the right configuration.

Bootstrapped and regression tested on x86_64, also verified it fixes the Linaro
reported CI failure and verified the crosses are still happy.  Pushing to the
trunk.

gcc/
	* ifcvt.cc (noce_try_sign_bit_splat): Fix right shift computation.

gcc/testsuite/
	* gcc.target/arm/bics_3.c: Adjust expected output
2025-08-24 19:56:59 -06:00
GCC Administrator e855cd3b44 Daily bump. 2025-08-25 00:17:39 +00:00
Joseph Myers abf51b3886 Update gcc de.po
* de.po: Update.
2025-08-24 16:46:31 +00:00
Sam James b38bffddd2 i386: fix ChangeLog entry
Fix a typo in the ChangeLog entry from r16-3355-g96a291c4bb0b8a.
2025-08-24 04:09:30 +01:00
GCC Administrator c196048782 Daily bump. 2025-08-24 00:18:15 +00:00
Eczbek 37b5126f5e c++: Fix greater-than operator in braced-init-lists [PR116928]
PR c++/116928

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_braced_list): Set greater_than_is_operator_p.

gcc/testsuite/ChangeLog:

	* g++.dg/parse/template33.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-23 17:57:39 -04:00
H.J. Lu 05b1727c06 x86: Compile noplt-(g|l)d-1.c with -mtls-dialect=gnu
Compile noplt-gd-1.c and noplt-ld-1.c with -mtls-dialect=gnu to support
the --with-tls=gnu2 configure option since they scan the assembly output
for the __tls_get_addr call which is generated by -mtls-dialect=gnu.

	PR target/120933
	* gcc.target/i386/noplt-gd-1.c (dg-options): Add
	-mtls-dialect=gnu.
	* gcc.target/i386/noplt-ld-1.c (dg-options): Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-23 12:50:33 -07:00
Sam James 96a291c4bb i386: wire up --with-tls to control -mtls-dialect= default
Allow passing --with-tls= at configure-time to control the default value
of -mtls-dialect= for i386 and x86_64. The default itself (gnu) is not changed
unless --with-tls= is passed.

--with-tls= is already wired up for ARM and RISC-V.

gcc/ChangeLog:
	PR target/120933

	* config.gcc (supported_defaults): Add tls for i386, x86_64.
	* config/i386/i386.h (host_detect_local_cpu): Add tls.
	* doc/install.texi: Document --with-tls= for i386, x86_64.
2025-08-23 11:13:50 +01:00
John Ericson f23bac62f4 driver: Rework for_each_path using C++
The old C-style was cumbersome make making one responsible for manually
creating and passing in two parts a closure (separate function and
*_info class for closed-over variables).

With C++ lambdas, we can just:

- derive environment types implicitly
- have fewer stray static functions

Also thanks to templates we can
- make the return type polymorphic, to avoid casting pointee types.

Note that `struct spec_path` was *not* converted because it is used
multiple times. We could still convert to a lambda, but we would want to
put the for_each_path call with that lambda inside a separate function
anyways, to support the multiple callers. Unlike the other two
refactors, it is not clear that this one would make anything shorter.
Instead, I define the `operator()` explicitly. Keeping the explicit
struct gives us some nice "named arguments", versus the wrapper function
alternative, too.

gcc/ChangeLog:

	* gcc.cc (for_each_path): templated, to make passing lambdas
	possible/easy/safe, and to have a polymorphic return type.
	(struct add_to_obstack_info): Deleted, lambda captures replace
	it.
	(add_to_obstack): Moved to lambda in build_search_list.
	(build_search_list): Has above lambda now.
	(struct file_at_path_info):  Deleted, lambda captures replace
	it.
	(file_at_path): Moved to lambda in find_a_file.
	(find_a_file): Has above lambda now.
	(struct spec_path_info): Reamed to just struct spec_path.
	(struct spec_path): New name.
	(spec_path): Rnamed to spec_path::operator()
	(spec_path::operator()): New name
	(do_spec_1): Updated for_each_path call sites.

Signed-off-by: John Ericson <git@JohnEricson.me>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-22 22:25:03 -04:00
Nathaniel Shead 5b85364a6d c++/modules: Provide definitions of synthesized methods outside their defining module [PR120499]
In the PR, we're getting a linker error from _Vector_impl's destructor
never getting emitted.  This is because of a combination of factors:

1. in imp-member-4_a, the destructor is not used and so there is no
   definition generated.

2. in imp-member-4_b, the destructor gets synthesized (as part of the
   synthesis for Coll's destructor) but is not ODR-used and so does not
   get emitted.  Despite there being a definition provided in this TU,
   the destructor is still considered imported and so isn't streamed
   into the module body.

3. in imp-member-4_c, we need to ODR-use the destructor but we only got
   a forward declaration from imp-member-4_b, so we cannot emit a body.

The point of failure here is step 2; this function has effectively been
declared in the imp-member-4_b module, and so we shouldn't treat it as
imported.  This way we'll properly stream the body so that importers can
emit it.

	PR c++/120499

gcc/cp/ChangeLog:

	* method.cc (synthesize_method): Set the instantiating module.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/imp-member-4_a.C: New test.
	* g++.dg/modules/imp-member-4_b.C: New test.
	* g++.dg/modules/imp-member-4_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-08-23 11:51:43 +10:00
GCC Administrator 64d9e5ab61 Daily bump. 2025-08-23 00:17:47 +00:00
Kishan Parmar 9d63110c43 rs6000: Add shift count guards to avoid undefined behavior [PR118890]
This patch adds missing guards on shift amounts to prevent UB when the
shift count equals or exceeds HOST_BITS_PER_WIDE_INT.

In the patch (r16-2666-g647bd0a02789f1), shift counts were only checked
for nonzero but not for being within valid bounds. This patch tightens
those conditions by enforcing that shift counts are greater than zero
and less than HOST_BITS_PER_WIDE_INT.

2025-08-23  Kishan Parmar  <kishan@linux.ibm.com>

gcc/
	PR target/118890
	* config/rs6000/rs6000.cc (can_be_rotated_to_negative_lis): Add bounds
	checks for shift counts to prevent undefined behavior.
	(rs6000_emit_set_long_const): Likewise.
2025-08-23 00:28:09 +05:30
Jeff Law ebbeaf490c [PR rtl-optimization/120553] Improve selecting between constants based on sign bit test
While working to remove mvconst_internal I stumbled over a regression in
the code to handle signed division by a power of two.

In that sequence we want to select between 0, 2^n-1 by pairing a sign
bit splat with a subsequent logical right shift.  This can be done
without branches or conditional moves.

Playing with it a bit made me realize there's a handful of selections we
can do based on a sign bit test.  Essentially there's two broad cases.

Clearing bits after the sign bit splat.  So we have 0, -1, if we clear
bits the 0 stays as-is, but the -1 could easily turn into 2^n-1, ~2^n-1,
or some small constants.

Setting bits after the sign bit splat. If we have 0, -1, setting bits
the -1 stays as-is, but the 0 can turn into 2^n, a small constant, etc.

Shreya and I originally started looking at target patterns to do this,
essentially discovering conditional move forms of the selects and
rewriting them into something more efficient.  That got out of control
pretty quickly and it relied on if-conversion to initially create the
conditional move.

The better solution is to actually discover the cases during
if-conversion itself.  That catches cases that were previously being
missed, checks cost models, and is actually simpler since we don't have
to distinguish between things like ori and bseti, instead we just emit
the natural RTL and let the target figure it out.

In the ifcvt implementation we put these cases just before trying the
traditional conditional move sequences.  Essentially these are a last
attempt before trying the generalized conditional move sequence.

This as been bootstrapped and regression tested on aarch64, riscv,
ppc64le, s390x, alpha, m68k, sh4eb, x86_64 and probably a couple others
I've forgotten.  It's also been tested on the other embedded targets.
Obviously the new tests are risc-v specific, so that testing was
primarily to make sure we didn't ICE, generate incorrect code or regress
target existing specific tests.

Raphael has some changes to attack this from the gimple direction as
well.  I think the latest version of those is on me to push through
internal review.

	PR rtl-optimization/120553
gcc/
	* ifcvt.cc (noce_try_sign_bit_splat): New function.
	(noce_process_if_block): Use it.

gcc/testsuite/

	* gcc.target/riscv/pr120553-1.c: New test.
	* gcc.target/riscv/pr120553-2.c: New test.
	* gcc.target/riscv/pr120553-3.c: New test.
	* gcc.target/riscv/pr120553-4.c: New test.
	* gcc.target/riscv/pr120553-5.c: New test.
	* gcc.target/riscv/pr120553-6.c: New test.
	* gcc.target/riscv/pr120553-7.c: New test.
	* gcc.target/riscv/pr120553-8.c: New test.
2025-08-22 11:57:12 -06:00
Richard Biener bd7c238e3c Pass representative of live SLP node to vect_create_epilog_for_reduction
We passed the reduc_info which is close, but the representative is
more spot on and will not collide with making the reduc_info a
distinct type.

	* tree-vect-loop.cc (vectorizable_live_operation): Pass
	the representative of the PHIs node to
	vect_create_epilog_for_reduction.
2025-08-22 15:45:11 +02:00
Richard Biener af0af4cf81 Fixups around reduction info and STMT_VINFO_REDUC_VECTYPE_IN
STMT_VINFO_REDUC_VECTYPE_IN exists on relevant reduction stmts, not
the reduction info.  And STMT_VINFO_DEF_TYPE exists on the
reduction info.  The following fixes up a few places.

	* tree-vect-loop.cc (vectorizable_lane_reducing): Get
	reduction info properly.  Adjust checks according to
	comments.
	(vectorizable_reduction): Do not set STMT_VINFO_REDUC_VECTYPE_IN
	on the reduc info.
	(vect_transform_reduction): Query STMT_VINFO_REDUC_VECTYPE_IN
	on the actual reduction stmt, not the info.
2025-08-22 15:43:15 +02:00
Pan Li 06e6154893 RISC-V: Add testcase for scalar unsigned SAT_MUL form 3
Add run and asm check test cases for scalar unsigned SAT_MUL form 3.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/sat/sat_arith.h: Add test helper macros.
	* gcc.target/riscv/sat/sat_u_mul-4-u16-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u16-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u16-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u16-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u32-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u32-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u32-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u64-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u8-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u8-from-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u8-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u8-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-4-u8-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u16-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u16-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u16-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u16-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u32-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u32-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u32-from-u64.rv32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u64-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u8-from-u128.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u8-from-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u8-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u8-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-4-u8-from-u64.rv32.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-22 21:16:40 +08:00
Pan Li f2794c206f Match: Add form 3 for unsigned SAT_MUL
This patch would like to try to match the the unsigned
SAT_MUL form 3, aka below:

  #define DEF_SAT_U_MUL_FMT_3(NT, WT)             \
  NT __attribute__((noinline))                    \
  sat_u_mul_##NT##_from_##WT##_fmt_3 (NT a, NT b) \
  {                                               \
    WT x = (WT)a * (WT)b;                         \
    if ((x >> sizeof(a) * 8) == 0)                \
      return (NT)x;                               \
    else                                          \
      return (NT)-1;                              \
  }

While WT is  T is uint16_t, uint32_t, uint64_t and uint128_t,
and NT is is uint8_t, uint16_t, uint32_t and uint64_t.

gcc/ChangeLog:

	* match.pd: Add form 3 for unsigned SAT_MUL.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-22 21:16:40 +08:00
H.J. Lu e12208722d Emit the TLS call after NOTE_INSN_FUNCTION_BEG
For the beginning basic block:

(note 4 0 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 2 4 26 2 NOTE_INSN_FUNCTION_BEG)

emit the TLS call after NOTE_INSN_FUNCTION_BEG.

gcc/

	PR target/121635
	* config/i386/i386-features.cc (ix86_emit_tls_call): Emit the
	TLS call after NOTE_INSN_FUNCTION_BEG.

gcc/testsuite/

	PR target/121635
	* gcc.target/i386/pr121635-1a.c: New test.
	* gcc.target/i386/pr121635-1b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-22 06:12:36 -07:00
Richard Biener 60fca68165 Use REDUC_GROUP_FIRST_ELEMENT less
REDUC_GROUP_FIRST_ELEMENT is often checked to see whether we are
dealing with a SLP reduction or a reduction chain.  When we are
in the context of analyzing the reduction (so we are sure
the SLP instance we see is correct), then we can use the SLP
instance kind instead.

	* tree-vect-loop.cc (get_initial_defs_for_reduction): Adjust
	comment.
	(vect_create_epilog_for_reduction): Get at the reduction
	kind via the instance, re-use the slp_reduc flag instead
	of checking REDUC_GROUP_FIRST_ELEMENT again.
	Remove unreachable code.
	(vectorizable_reduction): Compute a reduc_chain flag from
	the SLP instance kind, avoid REDUC_GROUP_FIRST_ELEMENT
	checks.
	(vect_transform_cycle_phi): Likewise.
	(vectorizable_live_operation): Check the SLP instance
	kind instead of REDUC_GROUP_FIRST_ELEMENT.
2025-08-22 15:10:37 +02:00
Nathaniel Shead 62beefc475 testsuite: Fix g++.dg/abi/mangle83.C for -fshort-enums
Linaro CI informed me that this test fails on ARM thumb-m7-hard-eabi.
This appears to be because the target defaults to -fshort-enums, and so
the mangled names are inaccurate.

This patch just disables the implicit type enum test for this case.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle83.C: Disable implicit enum test for
	-fshort-enums.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-08-22 22:18:58 +10:00
Richard Biener 3858dcd7a0 Decouple parloops from vect reduction infra some more
The following removes the use of STMT_VINFO_REDUC_* from parloops,
also fixing a mistake with analyzing double reductions which rely
on the outer loop vinfo so the inner loop is properly detected as
nested.

	* tree-parloops.cc (parloops_is_simple_reduction): Pass
	in double reduction inner loop LC phis and query that.
	(parloops_force_simple_reduction): Similar, but set it.
	Check for valid reduction types here.
	(valid_reduction_p): Remove.
	(gather_scalar_reductions): Adjust, fixup double
	reduction inner loop processing.
2025-08-22 12:30:18 +02:00
Sebastian Huber 73a2a9d6c2 RTEMS: Add riscv multilibs
gcc/ChangeLog:

	* config/riscv/t-rtems: Add -mstrict-align multilibs for
	targets without support for misaligned access in hardware.
2025-08-22 07:10:30 +02:00
Alexandre Oliva d94eb26871 [arm] require armv7 support for [PR120424]
Without stating the architecture version required by the test, test
runs with options that are incompatible with the required
architecture version fail, e.g. -mfloat-abi=hard.

armv7 was not covered by the long list of arm variants in
target-supports.exp, so add it, and use it for the effective target
requirement and for the option.


for  gcc/testsuite/ChangeLog

	PR rtl-optimization/120424
	* lib/target-supports.exp (arm arches): Add arm_arch_v7.
	* g++.target/arm/pr120424.C: Require armv7 support.  Use
	dg-add-options arm_arch_v7 instead of explicit -march=armv7.
2025-08-21 21:46:22 -03:00
GCC Administrator c6d9b8023b Daily bump. 2025-08-22 00:20:38 +00:00
Steven G. Kargl 2c1fd2fdb3 Fortran: Fix NULL pointer issue.
PR fortran/121627

gcc/fortran/ChangeLog:

	* module.cc (create_int_parameter_array):  Avoid NULL
	pointer dereference and enhance error message.

gcc/testsuite/ChangeLog:

	* gfortran.dg/pr121627.f90: New test.
2025-08-21 14:36:49 -07:00
Dimitar Dimitrov 625af54662 pru: libgcc: Add software implementation for multiplication
For cores without a hardware multiplier, set respective optabs
with library functions which use software implementation of
multiplication.

The implementation was copied from the RL78 backend.

gcc/ChangeLog:

	* config/pru/pru.cc (pru_init_libfuncs): Set softmpy libgcc
	functions for optab multiplication entries if TARGET_OPT_MUL
	option is not set.

libgcc/ChangeLog:

	* config/pru/libgcc-eabi.ver: Add __pruabi_softmpyi and
	__pruabi_softmpyll symbols.
	* config/pru/t-pru: Add softmpy source files.
	* config/pru/pru-softmpy.h: New file.
	* config/pru/softmpyi.c: New file.
	* config/pru/softmpyll.c: New file.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2025-08-21 21:43:05 +03:00
Dimitar Dimitrov 352cc9b57b pru: Define multilib for different core variants
Enable multilib builds for contemporary PRU core versions (AM335x and
later), and older versions present in AM18xx.

gcc/ChangeLog:

	* config.gcc: Include pru/t-multilib.
	* config/pru/pru.h (MULTILIB_DEFAULTS): Define.
	* config/pru/t-multilib: New file.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2025-08-21 21:43:05 +03:00
Dimitar Dimitrov 7968ba80b9 pru: Add options to disable MUL/FILL/ZERO instructions
Older PRU core versions (e.g. in AM1808 SoC) do not support
XIN, XOUT, FILL, ZERO instructions.  Add GCC command line options to
optionally disable generation of those instructions, so that code
can be executed on such older PRU cores.

gcc/ChangeLog:

	* common/config/pru/pru-common.cc (TARGET_DEFAULT_TARGET_FLAGS):
	Keep multiplication, FILL and ZERO instructions enabled by
	default.
	* config/pru/pru.md (prumov<mode>): Gate code generation on
	TARGET_OPT_FILLZERO.
	(mov<mode>): Ditto.
	(zero_extendqidi2): Ditto.
	(zero_extendhidi2): Ditto.
	(zero_extendsidi2): Ditto.
	(@pru_ior_fillbytes<mode>): Ditto.
	(@pru_and_zerobytes<mode>): Ditto.
	(@<code>di3): Ditto.
	(mulsi3): Gate code generation on TARGET_OPT_MUL.
	* config/pru/pru.opt: Add mmul and mfillzero options.
	* config/pru/pru.opt.urls: Regenerate.
	* config/rl78/rl78.opt.urls: Regenerate.
	* doc/invoke.texi: Document new options.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2025-08-21 21:43:05 +03:00
Andrew Pinski 8b41e021ba c: Add folding of nullptr_t in some cases [PR121478]
The middle-end does not fully understand NULLPTR_TYPE. So it
gets confused a lot of the time when dealing with it.
This adds the folding that is similarly done in the C++ front-end already.
In some cases it should produce slightly better code as there is no
reason to load from a nullptr_t variable as it is always NULL.

The following is handled:
nullptr_v ==/!= nullptr_v -> true/false
(ptr)nullptr_v -> (ptr)0, nullptr_v
f(nullptr_v) -> f ((nullptr, nullptr_v))

The last one is for conversion inside ... .

Bootstrapped and tested on x86_64-linux-gnu.

	PR c/121478
gcc/c/ChangeLog:

	* c-fold.cc (c_fully_fold_internal): Fold nullptr_t ==/!= nullptr_t.
	* c-typeck.cc (convert_arguments): Handle conversion from nullptr_t
	for varargs.
	(convert_for_assignment): Handle conversions from nullptr_t to
	pointer type specially.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-21 11:35:52 -07:00
Jason Merrill 70f33ad677 c++: constexpr clobber of const [PR121068]
Since r16-3022, 20_util/variant/102912.cc was failing in C++20 and above due
to wrong errors about destruction modifying a const object; destruction is
OK.

	PR c++/121068

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_eval_store_expression): Allow clobber of a const
	object.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/constexpr-dtor18.C: New test.
2025-08-21 13:52:48 -04:00
Paul-Antoine Arras 4196389cd2 RISC-V: testsuite: Fix DejaGnu support for riscv_zvfh
Call check_effective_target_riscv_zvfh_ok rather than
check_effective_target_riscv_zvfh in vx_vf_*run-1-f16.c run tests and ensure
that they are actually run.
Also fix remove_options_for_riscv_zvfh.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmacc-run-1-f16.c: Call
	check_effective_target_riscv_zvfh_ok rather than
	check_effective_target_riscv_zvfh.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmadd-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmsac-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfmsub-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmacc-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmadd-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmsac-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfnmsub-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwmacc-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwmsac-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwnmacc-run-1-f16.c: Likewise.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf_vfwnmsac-run-1-f16.c: Likewise.
	* lib/target-supports.exp (check_effective_target_riscv_zvfh_ok): Append
	zvfh instead of v to march.
	(remove_options_for_riscv_zvfh): Remove duplicate and
	call remove_ rather than add_options_for_riscv_z_ext.
2025-08-21 17:17:56 +02:00
Richard Sandiford 0d34e73b71 rtl-ssa: Add missing live-out uses [PR121619]
This PR is another bug in the rtl-ssa code to manage live-out uses.
It seems that this didn't get much coverage until recently.

In the testcase, late-combine first removed a register-to-register
move by substituting into all uses, some of which were in other EBBs.
This was done after checking make_uses_available, which (as expected)
says that single dominating definitions are available everywhere
that the definition dominates.  But the update failed to add
appropriate live-out uses, so a later parallelisation attempt
tried to move the new destination into a later block.

gcc/
	PR rtl-optimization/121619
	* rtl-ssa/functions.h (function_info::commit_make_use_available):
	Declare.
	* rtl-ssa/blocks.cc (function_info::commit_make_use_available):
	New function.
	* rtl-ssa/changes.cc (function_info::apply_changes_to_insn): Use it.

gcc/testsuite/
	PR rtl-optimization/121619
	* gcc.dg/pr121619.c: New test.
2025-08-21 16:16:02 +01:00
Jonathan Wakely fb7c62f7a8 libstdc++: Use pthread_mutex_clocklock when TSan is active [PR121496]
This reverts r14-905-g3b7cb33033fbe6 which disabled the use of
pthread_mutex_clocklock when TSan is active. That's no longer needed,
because GCC has TSan interceptors for pthread_mutex_clocklock since GCC
15.1 and Clang has them since 18.1.0 (released March 2024).

The interceptor was added by https://github.com/llvm/llvm-project/pull/75713

libstdc++-v3/ChangeLog:

	PR libstdc++/121496
	* acinclude.m4 (GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK): Do not
	use _GLIBCXX_TSAN in _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK macro.
	* configure: Regenerate.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-21 13:26:17 +01:00
Jonathan Wakely d1dec30445 libstdc++: Check _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK with #if [PR121496]
The change in r14-905-g3b7cb33033fbe6 to disable the use of
pthread_mutex_clocklock when TSan is active assumed that the
_GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK macro was always checked with #if
rather than #ifdef, which was not true.

This makes the checks use #if consistently.

libstdc++-v3/ChangeLog:

	PR libstdc++/121496
	* include/std/mutex (__timed_mutex_impl::_M_try_wait_until):
	Change preprocessor condition to use #if instead of #ifdef.
	(recursive_timed_mutex::_M_clocklock): Likewise.
	* testsuite/30_threads/timed_mutex/121496.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-21 13:26:10 +01:00
Richard Biener 3182e95eda tree-optimization/111494 - reduction vectorization with signed UB
The following makes sure to pun arithmetic that's used in vectorized
reduction to unsigned when overflow invokes undefined behavior.

	PR tree-optimization/111494
	* gimple-fold.h (arith_code_with_undefined_signed_overflow): Declare.
	* gimple-fold.cc (arith_code_with_undefined_signed_overflow): Export.
	* tree-vect-stmts.cc (vectorizable_operation): Use unsigned
	arithmetic for operations participating in a reduction.
2025-08-21 13:53:02 +02:00
H.J. Lu 7dfb3a59fe x86-64: Emit the TLS call after NOTE_INSN_BASIC_BLOCK
For a basic block with only a label:

(code_label 78 11 77 3 14 (nil) [1 uses])
(note 77 78 54 3 [bb 3] NOTE_INSN_BASIC_BLOCK)

emit the TLS call after NOTE_INSN_BASIC_BLOCK, instead of before
NOTE_INSN_BASIC_BLOCK, to avoid

x.c: In function ‘aout_16_write_syms’:
x.c:54:1: error: NOTE_INSN_BASIC_BLOCK is missing for block 3
   54 | }
      | ^
x.c:54:1: error: NOTE_INSN_BASIC_BLOCK 77 in middle of basic block 3
during RTL pass: x86_cse
x.c:54:1: internal compiler error: verify_flow_info failed

gcc/

	PR target/121607
	* config/i386/i386-features.cc (ix86_emit_tls_call): Emit the
	TLS call after NOTE_INSN_BASIC_BLOCK in a basic block with only
	a label.

gcc/testsuite/

	PR target/121607
	* gcc.target/i386/pr121607-1a.c: New test.
	* gcc.target/i386/pr121607-1b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-21 04:42:00 -07:00
Luc Grosheintz d147e7a20a libstdc++: Implement aligned_accessor from mdspan [PR120994]
This commit completes the implementation of P2897R7 by implementing and
testing the template class aligned_accessor.

	PR libstdc++/120994

libstdc++-v3/ChangeLog:

	* include/bits/version.def (aligned_accessor): Add.
	* include/bits/version.h: Regenerate.
	* include/std/mdspan (aligned_accessor): New class.
	* src/c++23/std.cc.in (aligned_accessor): Add.
	* testsuite/23_containers/mdspan/accessors/generic.cc: Add tests
	for aligned_accessor.
	* testsuite/23_containers/mdspan/accessors/aligned_neg.cc: New test.
	* testsuite/23_containers/mdspan/version.cc: Add test for
	__cpp_lib_aligned_accessor.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 11:55:02 +02:00
Luc Grosheintz 5227ec972a libstdc++: Implement is_sufficiently_aligned [PR120994]
This commit implements and tests the function is_sufficiently_aligned
from P2897R7.

	PR libstdc++/120994

libstdc++-v3/ChangeLog:

	* include/bits/align.h (is_sufficiently_aligned): New function.
	* include/bits/version.def (is_sufficiently_aligned): Add.
	* include/bits/version.h: Regenerate.
	* include/std/memory: Add __glibcxx_want_is_sufficiently_aligned.
	* src/c++23/std.cc.in (is_sufficiently_aligned): Add.
	* testsuite/20_util/headers/memory/version.cc: Add test for
	__cpp_lib_is_sufficiently_aligned.
	* testsuite/20_util/is_sufficiently_aligned/1.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 11:54:41 +02:00
Jonathan Wakely cf88ed5bf2 libstdc++: Fix std::numeric_limits<__float128>::max_digits10 [PR121374]
When I added this explicit specialization in r14-1433-gf150a084e25eaa I
used the wrong value for the number of mantissa digits (I used 112
instead of 113). Then when I refactored it in r14-1582-g6261d10521f9fd I
used the value calculated from the incorrect value (35 instead of 36).

libstdc++-v3/ChangeLog:

	PR libstdc++/121374
	* include/std/limits (numeric_limits<__float128>::max_digits10):
	Fix value.
	* testsuite/18_support/numeric_limits/128bit.cc: Check value.
2025-08-21 10:04:45 +01:00
Jonathan Wakely 889a1352a2 libstdc++: Suppress some more additional diagnostics [PR117294]
libstdc++-v3/ChangeLog:

	PR c++/117294
	* testsuite/20_util/optional/cons/value_neg.cc: Prune additional
	output for C++20 and later.
	* testsuite/20_util/scoped_allocator/69293_neg.cc: Match
	additional error for C++20 and later.
2025-08-21 10:03:19 +01:00
Luc Grosheintz 985684e9b3 libstdc++: Implement std::dims from <mdspan>.
This commit implements the C++26 feature std::dims described in P2389R2.
It sets the feature testing macro to 202406 and adds tests.

Also fixes the test mdspan/version.cc

libstdc++-v3/ChangeLog:

	* include/bits/version.def (mdspan): Set value for C++26.
	* include/bits/version.h: Regenerate.
	* include/std/mdspan (dims): Add.
	* src/c++23/std.cc.in (dims): Add.
	* testsuite/23_containers/mdspan/extents/misc.cc: Add tests.
	* testsuite/23_containers/mdspan/version.cc: Update test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:45:17 +02:00
Luc Grosheintz 4959739d83 libstdc++: Simplify precomputed partial products in <mdspan>.
Prior to this commit, the partial products of static extents in <mdspan>
was done in a loop that calls a function that computes the partial
product. The complexity is quadratic in the rank.

This commit removes the quadratic complexity.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__static_prod): Delete.
	(__fwd_partial_prods): Compute at compile-time in O(rank), not
	O(rank**2).
	(__rev_partial_prods): Ditto.
	(__size): Inline __static_prod.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:41:53 +02:00
Luc Grosheintz d6ed0658f7 libstdc++: Reduce size static storage for __fwd_prod in mdspan.
This fixes an oversight in a previous commit that improved mdspan
related code. Because __size doesn't use __fwd_prod, __fwd_prod(__rank)
is not needed anymore. Hence, one can shrink the size of
__fwd_partial_prods.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__fwd_partial_prods): Reduce size of the
	array by 1 element.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:41:53 +02:00
Takayuki 'January June' Suwa 6190513486 xtensa: Small improvement to "*btrue_INT_MIN"
This patch changes the implementation of the insn to test whether the
result itself is negative or not, rather than the MSB of the result of
the ABS machine instruction.  This eliminates the need to consider bit-
endianness and allows for longer branch distances.

     /* example */
     extern void foo(int);
     void test0(int a) {
       if (a == -2147483648)
         foo(a);
     }
     void test1(int a) {
       if (a != -2147483648)
         foo(a);
     }

     ;; before (endianness: little)
     test0:
     	entry	sp, 32
     	abs	a8, a2
     	bbci	a8, 31, .L1
     	mov.n	a10, a2
     	call8	foo
     .L1:
     	retw.n
     test1:
     	entry	sp, 32
     	abs	a8, a2
     	bbsi	a8, 31, .L4
     	mov.n	a10, a2
     	call8	foo
     .L4:
     	retw.n

     ;; after (endianness-independent)
     test0:
     	entry	sp, 32
     	abs	a8, a2
     	bgez	a8, .L1
     	mov.n	a10, a2
     	call8	foo
     .L1:
     	retw.n
     test1:
     	entry	sp, 32
     	abs	a8, a2
     	bltz	a8, .L4
     	mov.n	a10, a2
     	call8	foo
     .L4:
     	retw.n

gcc/ChangeLog:

	* config/xtensa/xtensa.md (*btrue_INT_MIN):
	Change the branch insn condition to test for a negative number
	rather than testing for the MSB.
2025-08-21 01:29:02 -07:00
Luc Grosheintz 1a17fd2826 libstdc++: Replace numeric_limit with __int_traits in mdspan.
Using __int_traits avoids the need to include <limits> from <mdspan>.
This in turn should reduce the size of the pre-compiled <mdspan>.
Similar refactoring was carried out for PR92546. Unfortunately,

  ./gcc/xgcc -std=c++23 -P -E -x c++ - -include mdspan | wc -l

shows a decrease by 1(!) line. This is due to bits/max_size_type.h which
includes <limits>.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__valid_static_extent): Replace
	numeric_limits with __int_traits.
	(extents::_S_ctor_explicit): Ditto.
	(extents::__static_quotient): Ditto.
	(layout_stride::mapping::mapping): Ditto.
	(mdspan::size): Ditto.
	* testsuite/23_containers/mdspan/extents/class_mandates_neg.cc:
	Update test with additional diagnostics.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:26:10 +02:00
Luc Grosheintz 6dd2a42ab6 libstdc++: Improve extents::operator==.
An interesting case to consider is:

  bool same11(const std::extents<int, dyn,   2, 3>& e1,
              const std::extents<int, dyn, dyn, 3>& e2)
  { return e1 == e2; }

Which has the following properties:

  - There's no mismatching static extents, preventing any
    short-circuiting.

  - There's a comparison between dynamic and static extents.

  - There's one trivial comparison: ... && 3 == 3.

Let E[i] denote the array of static extents, D[k] denote the array of
dynamic extents and k[i] be the index of the i-th extent in D.
(Naturally, k[i] is only meaningful if i is a dynamic extent).

The previous implementation results in assembly that's more or less a
literal translation of:

  for (i = 0; i < 3; ++i)
    e1 = E1[i] == -1 ? D1[k1[i]] : E1[i];
    e2 = E2[i] == -1 ? D2[k2[i]] : E2[i];
    if e1 != e2:
      return false
  return true;

While the proposed method results in assembly for

  if(D1[0] == D2[0]) return false;
  return 2 == D2[1];

i.e.

  110:  8b 17                  mov    edx,DWORD PTR [rdi]
  112:  31 c0                  xor    eax,eax
  114:  39 16                  cmp    DWORD PTR [rsi],edx
  116:  74 08                  je     120 <same11+0x10>
  118:  c3                     ret
  119:  0f 1f 80 00 00 00 00   nop    DWORD PTR [rax+0x0]
  120:  83 7e 04 02            cmp    DWORD PTR [rsi+0x4],0x2
  124:  0f 94 c0               sete   al
  127:  c3                     ret

It has the following nice properties:

  - It eliminated the indirection D[k[i]], because k[i] is known at
    compile time. Saving us a comparison E[i] == -1 and conditionally
    loading k[i].

  - It eliminated the trivial condition 3 == 3.

The result is code that only loads the required values and performs
exactly the number of comparisons needed by the algorithm. It also
results in smaller object files. Therefore, this seems like a sensible
change. We've check several other examples, including fully statically
determined cases and high-rank examples. The example given above
illustrates the other cases well.

The constexpr condition:

  if constexpr (!_S_is_compatible_extents<...>)
    return false;

is no longer needed, because the optimizer correctly handles this case.
However, it's retained for clarity/certainty.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (extents::operator==): Replace loop with
	pack expansion.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:24:23 +02:00
Luc Grosheintz 2d3282663c libstdc++: Reduce indirection in extents::extent.
In both fully static and dynamic extents the comparison
  static_extent(i) == dynamic_extent
is known at compile time. As a result, extents::extent doesn't
need to perform the check at runtime.

An illustrative example is:

  using E = std::extents<int, 3, 5, 7, 11, 13, 17>;
  int required_span_size(const typename Layout::mapping<E>& m)
  { return m.required_span_size(); }

Prior to this commit the generated code (on -O2) is:

 2a0:  b9 01 00 00 00         mov    ecx,0x1
 2a5:  31 d2                  xor    edx,edx
 2a7:  66 66 2e 0f 1f 84 00   data16 cs nop WORD PTR [rax+rax*1+0x0]
 2ae:  00 00 00 00
 2b2:  66 66 2e 0f 1f 84 00   data16 cs nop WORD PTR [rax+rax*1+0x0]
 2b9:  00 00 00 00
 2bd:  0f 1f 00               nop    DWORD PTR [rax]
 2c0:  48 8b 04 d5 00 00 00   mov    rax,QWORD PTR [rdx*8+0x0]
 2c7:  00
 2c8:  48 83 f8 ff            cmp    rax,0xffffffffffffffff
 2cc:  0f 84 00 00 00 00      je     2d2 <required_span_size_6d_static+0x32>
 2d2:  83 e8 01               sub    eax,0x1
 2d5:  0f af 04 97            imul   eax,DWORD PTR [rdi+rdx*4]
 2d9:  48 83 c2 01            add    rdx,0x1
 2dd:  01 c1                  add    ecx,eax
 2df:  48 83 fa 06            cmp    rdx,0x6
 2e3:  75 db                  jne    2c0 <required_span_size_6d_static+0x20>
 2e5:  89 c8                  mov    eax,ecx
 2e7:  c3                     ret

which is a scalar loop, and notably includes the check

  308:  48 83 f8 ff            cmp    rax,0xffffffffffffffff

to assert that the static extent is indeed not -1. Note, that on -O3 the
optimizer eliminates the comparison; and generates a sequence of scalar
operations: lea, shl, add and mov. The aim of this commit is to
eliminate this comparison also for -O2. With the optimization applied we
get:

  2e0:  f3 0f 6f 0f            movdqu xmm1,XMMWORD PTR [rdi]
  2e4:  66 0f 6f 15 00 00 00   movdqa xmm2,XMMWORD PTR [rip+0x0]
  2eb:  00
  2ec:  8b 57 10               mov    edx,DWORD PTR [rdi+0x10]
  2ef:  66 0f 6f c1            movdqa xmm0,xmm1
  2f3:  66 0f 73 d1 20         psrlq  xmm1,0x20
  2f8:  66 0f f4 c2            pmuludq xmm0,xmm2
  2fc:  66 0f 73 d2 20         psrlq  xmm2,0x20
  301:  8d 14 52               lea    edx,[rdx+rdx*2]
  304:  66 0f f4 ca            pmuludq xmm1,xmm2
  308:  66 0f 70 c0 08         pshufd xmm0,xmm0,0x8
  30d:  66 0f 70 c9 08         pshufd xmm1,xmm1,0x8
  312:  66 0f 62 c1            punpckldq xmm0,xmm1
  316:  66 0f 6f c8            movdqa xmm1,xmm0
  31a:  66 0f 73 d9 08         psrldq xmm1,0x8
  31f:  66 0f fe c1            paddd  xmm0,xmm1
  323:  66 0f 6f c8            movdqa xmm1,xmm0
  327:  66 0f 73 d9 04         psrldq xmm1,0x4
  32c:  66 0f fe c1            paddd  xmm0,xmm1
  330:  66 0f 7e c0            movd   eax,xmm0
  334:  8d 54 90 01            lea    edx,[rax+rdx*4+0x1]
  338:  8b 47 14               mov    eax,DWORD PTR [rdi+0x14]
  33b:  c1 e0 04               shl    eax,0x4
  33e:  01 d0                  add    eax,edx
  340:  c3                     ret

Which shows eliminating the trivial comparison, unlocks a new set of
optimizations, i.e. SIMD-vectorization. In particular, the loop has been
vectorized by loading the first four constants from aligned memory; the
first four strides from non-aligned memory, then computes the product
and reduction. It interleaves the above with computing 1 + 12*S[4] +
16*S[5] (as scalar operations) and then finishes the reduction.

A similar effect can be observed for fully dynamic extents.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__mdspan::__all_static): New function.
	(__mdspan::_StaticExtents::_S_is_dyn): Inline and eliminate.
	(__mdspan::_ExtentsStorage::_S_is_dynamic): New method.
	(__mdspan::_ExtentsStorage::_M_extent): Use _S_is_dynamic.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:22:11 +02:00
Luc Grosheintz 0197c3b158 libstdc++: Improve nearly fully dynamic extents in mdspan.
One previous commit optimized fully dynamic extents; and another
refactored __size such that __fwd_prod is valid for __r = 0, ..., rank
(exclusive).

Therefore, by noticing that __rev_prod (and __fwd_prod) never accesses
the first (or last) extent, one can avoid pre-computing partial products
of static extents in those cases, if all other extents are dynamic.

We check that the size of the reference object file decreases further
and the .rodata sections for

  __fwd_prod<dyn, ..., dyn, 11>
  __rev_prod<3, dyn, ..., dyn>

are absent.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__fwd_prods): Relax condition for fully-dynamic
	extents to cover (dyn, ..., dyn, X).
	(__rev_partial_prods): Analogous for (X, dyn, ..., dyn).

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:20:57 +02:00
Luc Grosheintz 5bcaee96c6 libstdc++: Improve fully dynamic extents in mdspan.
In mdspan related code, for extents with no static extents, i.e. only
dynamic extents, the following simplifications can be made:

  - The array of dynamic extents has size rank.
  - The two arrays dynamic-index and dynamic-index-inv become
  trivial, e.g. k[i] == i.
  - All elements of the arrays __{fwd,rev}_partial_prods are 1.

This commits eliminates the arrays for dynamic-index, dynamic-index-inv
and __{fwd,rev}_partial_prods. It also removes the indirection k[i] == i
from the source code, which isn't as relevant because the optimizer is
(often) capable of eliminating the indirection.

To check if it's working we look at:

  using E2 = std::extents<int, dyn, dyn, dyn, dyn>;

  int stride_left_E2(const std::layout_left::mapping<E2>& m, size_t r)
  { return m.stride(r); }

which generates the following

  0000000000000190 <stride_left_E2>:
  190:  48 c1 e6 02            shl    rsi,0x2
  194:  74 22                  je     1b8 <stride_left_E2+0x28>
  196:  48 01 fe               add    rsi,rdi
  199:  b8 01 00 00 00         mov    eax,0x1
  19e:  66 90                  xchg   ax,ax
  1a0:  48 63 17               movsxd rdx,DWORD PTR [rdi]
  1a3:  48 83 c7 04            add    rdi,0x4
  1a7:  48 0f af c2            imul   rax,rdx
  1ab:  48 39 fe               cmp    rsi,rdi
  1ae:  75 f0                  jne    1a0 <stride_left_E2+0x10>
  1b0:  c3                     ret
  1b1:  0f 1f 80 00 00 00 00   nop    DWORD PTR [rax+0x0]
  1b8:  b8 01 00 00 00         mov    eax,0x1
  1bd:  c3                     ret

We see that:

  - There's no code to load the partial product of static extents.
  - There's no indirection D[k[i]], it's just D[i] (as before).

On a test file which computes both mapping::stride(r) and
mapping::required_span_size, we check for static storage with

  objdump -h

we don't see the NTTP _Extents, anything (anymore) related to
_StaticExtents, __fwd_partial_prods or __rev_partial_prods. We also
check that the size of the reference object file (described three
commits prior) reduced by a few percent from 41.9kB to 39.4kB.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__mdspan::__all_dynamic): New function.
	(__mdspan::_StaticExtents::_S_dynamic_index): Convert to method.
	(__mdspan::_StaticExtents::_S_dynamic_index_inv): Ditto.
	(__mdspan::_StaticExtents): New specialization for fully dynamic
	extents.
	(__mdspan::__fwd_prod): New constexpr if branch to avoid
	instantiating __fwd_partial_prods.
	(__mdspan::__rev_prod): Ditto.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:19:13 +02:00
Luc Grosheintz db563993b6 libstdc++: Improve low-rank layout_{left,right}::stride.
The methods layout_{left,right}::mapping::stride are defined
as

  \prod_{i = 0}^r E[i]
  \prod_{i = r+1}^n E[i]

This is computed as the product of a precomputed static product and the
product of the required dynamic extents.

Disassembly shows that even for low-rank extents, i.e. rank == 1 and
rank == 2, with at least one dynamic extent, the generated code loads
two values; and then runs the loop over at most one element, e.g. for
stride_left_d5 defined below the generated code is:

 220:  48 8b 04 f5 00 00 00   mov    rax,QWORD PTR [rsi*8+0x0]
 227:  00
 228:  31 d2                  xor    edx,edx
 22a:  48 85 c0               test   rax,rax
 22d:  74 23                  je     252 <stride_left_d5+0x32>
 22f:  48 8b 0c f5 00 00 00   mov    rcx,QWORD PTR [rsi*8+0x0]
 236:  00
 237:  48 c1 e1 02            shl    rcx,0x2
 23b:  74 13                  je     250 <stride_left_d5+0x30>
 23d:  48 01 f9               add    rcx,rdi
 240:  48 63 17               movsxd rdx,DWORD PTR [rdi]
 243:  48 83 c7 04            add    rdi,0x4
 247:  48 0f af c2            imul   rax,rdx
 24b:  48 39 f9               cmp    rcx,rdi
 24e:  75 f0                  jne    240 <stride_left_d5+0x20>
 250:  89 c2                  mov    edx,eax
 252:  89 d0                  mov    eax,edx
 254:  c3                     ret

If there's no dynamic extents, it simply loads the precomputed product
of static extents.

For rank == 1 the answer is the constant `1`; for rank == 2 it's either 1 or
extents.extent(k), with k == 0 for layout_left and k == 1 for
layout_right.

Consider,

  using Ed = std::extents<int, dyn>;
  int stride_left_d(const std::layout_left::mapping<Ed>& m, size_t r)
  { return m.stride(r); }

  using E3d = std::extents<int, 3, dyn>;
  int stride_left_3d(const std::layout_left::mapping<E3d>& m, size_t r)
  { return m.stride(r); }

  using Ed5 = std::extents<int, dyn, 5>;
  int stride_left_d5(const std::layout_left::mapping<Ed5>& m, size_t r)
  { return m.stride(r); }

The optimized code for these three cases is:

  0000000000000060 <stride_left_d>:
  60:  b8 01 00 00 00         mov    eax,0x1
  65:  c3                     ret

  0000000000000090 <stride_left_3d>:
  90:  48 83 fe 01            cmp    rsi,0x1
  94:  19 c0                  sbb    eax,eax
  96:  83 e0 fe               and    eax,0xfffffffe
  99:  83 c0 03               add    eax,0x3
  9c:  c3                     ret

  00000000000000a0 <stride_left_d5>:
  a0:  b8 01 00 00 00         mov    eax,0x1
  a5:  48 85 f6               test   rsi,rsi
  a8:  74 02                  je     ac <stride_left_d5+0xc>
  aa:  8b 07                  mov    eax,DWORD PTR [rdi]
  ac:  c3                     ret

For rank == 1 it simply returns 1 (as expected). For rank == 2, it
either implements a branchless formula, or conditionally loads one
value. In all cases involving a dynamic extent this seems like it's
always doing clearly less work, both in terms of computation and loads.
In cases not involving a dynamic extent, it replaces loading one value
with a branchless sequence of four instructions.

This commit also refactors __size to no use any of the precomputed
arrays. This prevents instantiating __{fwd,rev}_partial_prods for
low-rank extents. This results in a further size reduction of a
reference object file (described two commits prior) by 9% from 46.0kB to
41.9kB.

In a prior commit we optimized __size to produce better object code by
precomputing the static products. This refactor enables the optimizer to
generate the same optimized code.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__mdspan::__fwd_prod): Optimize
	for rank <= 2.
	(__mdspan::__rev_prod): Ditto.
	(__mdspan::__size): Refactor to use a pre-computed product, not
	a partial product.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:17:23 +02:00
Luc Grosheintz 3134742307 libstdc++: Precompute products of static extents.
Let E denote an multi-dimensional extent; n the rank of E; r = 0, ...,
n; E[i] the i-th extent; and D[k] be the (possibly empty) array of
dynamic extents.

The two partial products for r = 0, ..., n:

  \prod_{i = 0}^r E[i]     (fwd)
  \prod_{i = r+1}^n E[i]   (rev)

can be computed as the product of static and dynamic extents. The static
fwd and rev product can be computed at compile time for all values of r.

Three methods are directly affected by this optimization:

  layout_left::mapping::stride
  layout_right::mapping::stride
  mdspan::size

We'll check the generated code (-O2) for all three methods for a generic
(artificially) high-dimensional multi-dimensional extents.

Consider a generic case:

  using Extents = std::extents<int, 3, 5, dyn, dyn, dyn, 7, dyn>;

  int stride_left(const std::layout_left::mapping<Extents>& m, size_t r)
  { return m.stride(r); }

The code generated prior to this commit:

  4f0:  66 0f 6f 05 00 00 00   movdqa xmm0,XMMWORD PTR [rip+0x0]        # 4f8
  4f7:  00
  4f8:  48 83 c6 01            add    rsi,0x1
  4fc:  48 c7 44 24 e8 ff ff   mov    QWORD PTR [rsp-0x18],0xffffffffffffffff
  503:  ff ff
  505:  48 8d 04 f5 00 00 00   lea    rax,[rsi*8+0x0]
  50c:  00
  50d:  0f 29 44 24 b8         movaps XMMWORD PTR [rsp-0x48],xmm0
  512:  66 0f 76 c0            pcmpeqd xmm0,xmm0
  516:  0f 29 44 24 c8         movaps XMMWORD PTR [rsp-0x38],xmm0
  51b:  66 0f 6f 05 00 00 00   movdqa xmm0,XMMWORD PTR [rip+0x0]        # 523
  522:  00
  523:  0f 29 44 24 d8         movaps XMMWORD PTR [rsp-0x28],xmm0
  528:  48 83 f8 38            cmp    rax,0x38
  52c:  74 72                  je     5a0 <stride_right_E1+0xb0>
  52e:  48 8d 54 04 b8         lea    rdx,[rsp+rax*1-0x48]
  533:  4c 8d 4c 24 f0         lea    r9,[rsp-0x10]
  538:  b8 01 00 00 00         mov    eax,0x1
  53d:  0f 1f 00               nop    DWORD PTR [rax]
  540:  48 8b 0a               mov    rcx,QWORD PTR [rdx]
  543:  49 89 c0               mov    r8,rax
  546:  4c 0f af c1            imul   r8,rcx
  54a:  48 83 f9 ff            cmp    rcx,0xffffffffffffffff
  54e:  49 0f 45 c0            cmovne rax,r8
  552:  48 83 c2 08            add    rdx,0x8
  556:  49 39 d1               cmp    r9,rdx
  559:  75 e5                  jne    540 <stride_right_E1+0x50>
  55b:  48 85 c0               test   rax,rax
  55e:  74 38                  je     598 <stride_right_E1+0xa8>
  560:  48 8b 14 f5 00 00 00   mov    rdx,QWORD PTR [rsi*8+0x0]
  567:  00
  568:  48 c1 e2 02            shl    rdx,0x2
  56c:  48 83 fa 10            cmp    rdx,0x10
  570:  74 1e                  je     590 <stride_right_E1+0xa0>
  572:  48 8d 4f 10            lea    rcx,[rdi+0x10]
  576:  48 01 d7               add    rdi,rdx
  579:  0f 1f 80 00 00 00 00   nop    DWORD PTR [rax+0x0]
  580:  48 63 17               movsxd rdx,DWORD PTR [rdi]
  583:  48 83 c7 04            add    rdi,0x4
  587:  48 0f af c2            imul   rax,rdx
  58b:  48 39 f9               cmp    rcx,rdi
  58e:  75 f0                  jne    580 <stride_right_E1+0x90>
  590:  c3                     ret
  591:  0f 1f 80 00 00 00 00   nop    DWORD PTR [rax+0x0]
  598:  c3                     ret
  599:  0f 1f 80 00 00 00 00   nop    DWORD PTR [rax+0x0]
  5a0:  b8 01 00 00 00         mov    eax,0x1
  5a5:  eb b9                  jmp    560 <stride_right_E1+0x70>
  5a7:  66 0f 1f 84 00 00 00   nop    WORD PTR [rax+rax*1+0x0]
  5ae:  00 00

which seems to be performing:

  preparatory_work();
  ret = 1
  for(i = 0; i < rank; ++i)
    tmp = ret * E[i]
    if E[i] != -1
      ret = tmp
  for(i = 0; i < rank_dynamic; ++i)
    ret *= D[i]

This commit reduces it down to:

  270:  48 8b 04 f5 00 00 00   mov    rax,QWORD PTR [rsi*8+0x0]
  277:  00
  278:  31 d2                  xor    edx,edx
  27a:  48 85 c0               test   rax,rax
  27d:  74 33                  je     2b2 <stride_right_E1+0x42>
  27f:  48 8b 14 f5 00 00 00   mov    rdx,QWORD PTR [rsi*8+0x0]
  286:  00
  287:  48 c1 e2 02            shl    rdx,0x2
  28b:  48 83 fa 10            cmp    rdx,0x10
  28f:  74 1f                  je     2b0 <stride_right_E1+0x40>
  291:  48 8d 4f 10            lea    rcx,[rdi+0x10]
  295:  48 01 d7               add    rdi,rdx
  298:  0f 1f 84 00 00 00 00   nop    DWORD PTR [rax+rax*1+0x0]
  29f:  00
  2a0:  48 63 17               movsxd rdx,DWORD PTR [rdi]
  2a3:  48 83 c7 04            add    rdi,0x4
  2a7:  48 0f af c2            imul   rax,rdx
  2ab:  48 39 f9               cmp    rcx,rdi
  2ae:  75 f0                  jne    2a0 <stride_right_E1+0x30>
  2b0:  89 c2                  mov    edx,eax
  2b2:  89 d0                  mov    eax,edx
  2b4:  c3                     ret

Loosely speaking this does the following:

  1. Load the starting position k in the array of dynamic extents; and
     return if possible.
  2. Load the partial product of static extents.
  3. Computes the \prod_{i = k}^d D[i] where d is the number of
  dynamic extents in a loop.

It shows that the span used for passing in the dynamic extents is
completely eliminated; and the fact that the product always runs to the
end of the array of dynamic extents is used by the compiler to eliminate
one indirection to determine the end position in the array of dynamic
extents.

The analogous code is generated for layout_left.

Next, consider

  using E2 = std::extents<int, 3, 5, dyn, dyn, 7, dyn, 11>;
  int size2(const std::mdspan<double, E2>& md)
  { return md.size(); }

on immediately preceding commit the generated code is

  10:  66 0f 6f 05 00 00 00   movdqa xmm0,XMMWORD PTR [rip+0x0]        # 18
  17:  00
  18:  49 89 f8               mov    r8,rdi
  1b:  48 8d 44 24 b8         lea    rax,[rsp-0x48]
  20:  48 c7 44 24 e8 0b 00   mov    QWORD PTR [rsp-0x18],0xb
  27:  00 00
  29:  48 8d 7c 24 f0         lea    rdi,[rsp-0x10]
  2e:  ba 01 00 00 00         mov    edx,0x1
  33:  0f 29 44 24 b8         movaps XMMWORD PTR [rsp-0x48],xmm0
  38:  66 0f 76 c0            pcmpeqd xmm0,xmm0
  3c:  0f 29 44 24 c8         movaps XMMWORD PTR [rsp-0x38],xmm0
  41:  66 0f 6f 05 00 00 00   movdqa xmm0,XMMWORD PTR [rip+0x0]        # 49
  48:  00
  49:  0f 29 44 24 d8         movaps XMMWORD PTR [rsp-0x28],xmm0
  4e:  66 66 2e 0f 1f 84 00   data16 cs nop WORD PTR [rax+rax*1+0x0]
  55:  00 00 00 00
  59:  0f 1f 80 00 00 00 00   nop    DWORD PTR [rax+0x0]
  60:  48 8b 08               mov    rcx,QWORD PTR [rax]
  63:  48 89 d6               mov    rsi,rdx
  66:  48 0f af f1            imul   rsi,rcx
  6a:  48 83 f9 ff            cmp    rcx,0xffffffffffffffff
  6e:  48 0f 45 d6            cmovne rdx,rsi
  72:  48 83 c0 08            add    rax,0x8
  76:  48 39 c7               cmp    rdi,rax
  79:  75 e5                  jne    60 <size2+0x50>
  7b:  48 85 d2               test   rdx,rdx
  7e:  74 18                  je     98 <size2+0x88>
  80:  49 63 00               movsxd rax,DWORD PTR [r8]
  83:  49 63 48 04            movsxd rcx,DWORD PTR [r8+0x4]
  87:  48 0f af c1            imul   rax,rcx
  8b:  41 0f af 40 08         imul   eax,DWORD PTR [r8+0x8]
  90:  0f af c2               imul   eax,edx
  93:  c3                     ret
  94:  0f 1f 40 00            nop    DWORD PTR [rax+0x0]
  98:  31 c0                  xor    eax,eax
  9a:  c3                     ret

which is needlessly long. The current commit reduces it down to:

  10:  48 63 07               movsxd rax,DWORD PTR [rdi]
  13:  48 63 57 04            movsxd rdx,DWORD PTR [rdi+0x4]
  17:  48 0f af c2            imul   rax,rdx
  1b:  0f af 47 08            imul   eax,DWORD PTR [rdi+0x8]
  1f:  69 c0 83 04 00 00      imul   eax,eax,0x483
  25:  c3                     ret

Which simply computes the product:

  D[0] * D[1] * D[2] * const

where const is the product of all static extents. Meaning the loop to
compute the product of dynamic extents has been fully unrolled and
all constants are perfectly precomputed.

The size of the object file described in the previous commit reduces
by 17% from 55.8kB to 46.0kB.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__mdspan::__static_prod): New function.
	(__mdspan::__fwd_partial_prods): Constexpr array of partial
	forward products.
	(__mdspan::__fwd_partial_prods): Same for reverse partial
	products.
	(__mdspan::__static_extents_prod): Delete function.
	(__mdspan::__extents_prod): Renamed from __exts_prod and refactored.
	include/std/mdspan (__mdspan::__fwd_prod): Compute as the
	product of pre-computed static static and the product of dynamic
	extents.
	(__mdspan::__rev_prod): Ditto.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:16:22 +02:00
Luc Grosheintz 997cd37809 libstdc++: Reduce template instantiations in <mdspan>.
In mdspan related code involving static extents, often the IndexType is
part of the template parameters, even though it's not needed.

This commit extracts the parts of _ExtentsStorage not related to
IndexType into a separate class _StaticExtents.

It also prefers passing the array of static extents, instead of the
whole extents object where possible.

The size of an object file compiled with -O2 that instantiates
  Layout::mapping<extents<IndexType, Indices...>::stride
  Layout::mapping<extents<IndexType, Indices...>::required_span_size
for the product of
  - eight IndexTypes
  - three Layouts,
  - nine choices of Indices...
decreases by 19% from 69.2kB to 55.8kB.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__mdspan::_StaticExtents): Extract non IndexType
	related code from _ExtentsStorage.
	(__mdspan::_ExtentsStorage): Use _StaticExtents.
	(__mdspan::__static_extents): Return reference to NTTP of _StaticExtents.
	(__mdspan::__contains_zero): New overload.
	(__mdspan::__exts_prod, __mdspan::__static_quotient): Use span to avoid
	copying __sta_exts.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-08-21 10:11:36 +02:00
Richard Biener bf864b450e Merge BB and loop path in vect_analyze_stmt
We have now common patterns for most of the vectorizable_* calls, so
merge.  This also avoids calling vectorizable_early_exit for BB
vect and clarifies signatures of it and vectorizable_phi.

	* tree-vectorizer.h (vectorizable_phi): Take bb_vec_info.
	(vectorizable_early_exit): Take loop_vec_info.
	* tree-vect-loop.cc (vectorizable_phi): Adjust.
	* tree-vect-slp.cc (vect_slp_analyze_operations): Likewise.
	(vectorize_slp_instance_root_stmt): Likewise.
	* tree-vect-stmts.cc (vectorizable_early_exit): Likewise.
	(vect_transform_stmt): Likewise.
	(vect_analyze_stmt): Merge the sequences of vectorizable_*
	where common.
2025-08-21 09:25:22 +02:00
Richard Sandiford e56e05bca4 MAINTAINERS: Update my email address and stand down as AArch64 maintainer
Today is my last working day at Arm, so this patch switches my
MAINTAINERS entries to my personal email address.  (It turns out
that I never updated some of the later entries...oops)

In order to avoid setting false expectations, and to try to avoid
getting in the way, I'm also standing down as an AArch64 maintainer,
effective EOB today.  I might still end up reviewing the odd AArch64
patch under global reviewership though, depending on how things go :)

ChangeLog:

	* MAINTAINERS: Update my email address and stand down as AArch64
	maintainer.
2025-08-21 07:51:56 +01:00
Paul Thomas 243b5b23c7 Fortran: gfortran PDT component access [PR84122, PR85942]
2025-08-21  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/84122
	* parse.cc (parse_derived): PDT type parameters are not allowed
	an explicit access specification and must appear before a
	PRIVATE statement. If a PRIVATE statement is seen, mark all the
	other components as PRIVATE.

	PR fortran/85942
	* simplify.cc (get_kind): Convert a PDT KIND component into a
	specification expression using the default initializer.

gcc/testsuite/
	PR fortran/84122
	* gfortran.dg/pdt_38.f03: New test.

	PR fortran/85942
	* gfortran.dg/pdt_39.f03: New test.
2025-08-21 07:24:02 +01:00
Jason Merrill ea6ef13d0f c++: pointer to auto member function [PR120757]
Here r13-1210 correctly changed &A<int>::foo to not be considered
type-dependent, but tsubst_expr of the OFFSET_REF got confused trying to
tsubst a type that involved auto.  Fixed by getting the type from the
member rather than tsubst.

	PR c++/120757

gcc/cp/ChangeLog:

	* pt.cc (tsubst_expr) [OFFSET_REF]: Don't tsubst the type.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1y/auto-fn66.C: New test.
2025-08-20 22:47:09 -04:00
GCC Administrator d670769bf6 Daily bump. 2025-08-21 00:20:43 +00:00
Marek Polacek 51fbd1e4ea c++: lambda capture and shadowing [PR121553]
P2036 says that this:

  [x=1]{ int x; }

should be rejected, but with my P2036 we started giving an error
for the attached testcase as well, breaking Dolphin.  So let's
keep the error only for init-captures.

	PR c++/121553

gcc/cp/ChangeLog:

	* name-lookup.cc (check_local_shadow): Check !is_normal_capture_proxy.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Wshadow-19.C: Revert P2036 changes.
	* g++.dg/warn/Wshadow-6.C: Likewise.
	* g++.dg/warn/Wshadow-20.C: New test.
	* g++.dg/warn/Wshadow-21.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-20 16:28:57 -04:00
Qing Zhao 6747672747 Regenerate common.opt.urls for -fdiagnostics-show-context
When -fdiagnostics-show-context[=DEPTH] was added, they were documented, but
common.opt.urls wasn't regenerated.

gcc/ChangeLog:

	* common.opt.urls: Regenerate.
2025-08-20 18:43:01 +00:00
Qing Zhao 6faa3cfe60 Provide new option -fdiagnostics-show-context=N for -Warray-bounds, -Wstringop-* warnings [PR109071,PR85788,PR88771,PR106762,PR108770,PR115274,PR117179]
'-fdiagnostics-show-context[=DEPTH]'
'-fno-diagnostics-show-context'
     With this option, the compiler might print the interesting control
     flow chain that guards the basic block of the statement which has
     the warning.  DEPTH is the maximum depth of the control flow chain.
     Currently, The list of the impacted warning options includes:
     '-Warray-bounds', '-Wstringop-overflow', '-Wstringop-overread',
     '-Wstringop-truncation'.  and '-Wrestrict'.  More warning options
     might be added to this list in future releases.  The forms
     '-fdiagnostics-show-context' and '-fno-diagnostics-show-context'
     are aliases for '-fdiagnostics-show-context=1' and
     '-fdiagnostics-show-context=0', respectively.

For example:

$ cat t.c
extern void warn(void);
static inline void assign(int val, int *regs, int *index)
{
  if (*index >= 4)
    warn();
  *regs = val;
}
struct nums {int vals[4];};

void sparx5_set (int *ptr, struct nums *sg, int index)
{
  int *val = &sg->vals[index];

  assign(0,    ptr, &index);
  assign(*val, ptr, &index);
}

$ gcc -Wall -O2  -c -o t.o t.c
t.c: In function ‘sparx5_set’:
t.c:12:23: warning: array subscript 4 is above array bounds of ‘int[4]’ [-Warray-bounds=]
   12 |   int *val = &sg->vals[index];
      |	       ~~~~~~~~^~~~~~~
t.c:8:18: note: while referencing ‘vals’
    8 | struct nums {int vals[4];};
      |		  ^~~~

In the above, Although the warning is correct in theory, the warning message
itself is confusing to the end-user since there is information that cannot
be connected to the source code directly.

It will be a nice improvement to add more information in the warning message
to report where such index value come from.

With the new option -fdiagnostics-show-context=1, the warning message for
the above testing case is now:

$ gcc -Wall -O2 -fdiagnostics-show-context=1 -c -o t.o t.c
t.c: In function ‘sparx5_set’:
t.c:12:23: warning: array subscript 4 is above array bounds of ‘int[4]’ [-Warray-bounds=]
   12 |   int *val = &sg->vals[index];
      |	       ~~~~~~~~^~~~~~~
  ‘sparx5_set’: events 1-2
    4 |   if (*index >= 4)
      |      ^
      |      |
      |      (1) when the condition is evaluated to true
......
   12 |   int *val = &sg->vals[index];
      |	       ~~~~~~~~~~~~~~~
      |		       |
      |		       (2) warning happens here
t.c:8:18: note: while referencing ‘vals’
    8 | struct nums {int vals[4];};
      |		  ^~~~

	PR tree-optimization/109071
	PR tree-optimization/85788
	PR tree-optimization/88771
	PR tree-optimization/106762
	PR tree-optimization/108770
	PR tree-optimization/115274
	PR tree-optimization/117179

gcc/ChangeLog:

	* Makefile.in (OBJS): Add diagnostic-context-rich-location.o.
	* common.opt (fdiagnostics-show-context): New option.
	(fdiagnostics-show-context=): New option.
	* diagnostic-context-rich-location.cc: New file.
	* diagnostic-context-rich-location.h: New file.
	* doc/invoke.texi (fdiagnostics-details): Add
	documentation for the new options.
	* gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add
	one new parameter. Use rich location with details for warning_at.
	(array_bounds_checker::check_array_ref): Use rich location with
	ditails for warning_at.
	(array_bounds_checker::check_mem_ref): Add one new parameter.
	Use rich location with details for warning_at.
	(array_bounds_checker::check_addr_expr): Use rich location with
	move_history_diagnostic_path for warning_at.
	(array_bounds_checker::check_array_bounds): Call check_mem_ref with
	one more parameter.
	* gimple-array-bounds.h: Update prototype for check_mem_ref.
	* gimple-ssa-warn-access.cc (warn_string_no_nul): Use rich location
	with details for warning_at.
	(maybe_warn_nonstring_arg): Likewise.
	(maybe_warn_for_bound): Likewise.
	(warn_for_access): Likewise.
	(check_access): Likewise.
	(pass_waccess::check_strncat): Likewise.
	(pass_waccess::maybe_check_access_sizes): Likewise.
	* gimple-ssa-warn-restrict.cc (pass_wrestrict::execute): Calculate
	dominance info for diagnostics show context.
	(maybe_diag_overlap): Use rich location with details for warning_at.
	(maybe_diag_access_bounds): Use rich location with details for
	warning_at.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr109071.c: New test.
	* gcc.dg/pr109071_1.c: New test.
	* gcc.dg/pr109071_10.c: New test.
	* gcc.dg/pr109071_11.c: New test.
	* gcc.dg/pr109071_12.c: New test.
	* gcc.dg/pr109071_2.c: New test.
	* gcc.dg/pr109071_3.c: New test.
	* gcc.dg/pr109071_4.c: New test.
	* gcc.dg/pr109071_5.c: New test.
	* gcc.dg/pr109071_6.c: New test.
	* gcc.dg/pr109071_7.c: New test.
	* gcc.dg/pr109071_8.c: New test.
	* gcc.dg/pr109071_9.c: New test.
	* gcc.dg/pr117375.c: New test.
2025-08-20 15:57:10 +00:00
Andrew Pinski 39acf3c9dd sra: Make build_ref_for_offset static [PR121568]
build_ref_for_offset was originally made external
with r0-95095-g3f84bf08c48ea4. The call was extracted
out into ipa_get_jf_ancestor_result by r0-110216-g310bc6334823b9.
Then the call was removed by r10-7273-gf3280e4c0c98e1.
So there is no use of build_ref_for_offset outside of SRA, so
let's make it static again.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/121568
gcc/ChangeLog:

	* ipa-prop.h (build_ref_for_offset): Remove.
	* tree-sra.cc (build_ref_for_offset): Make static.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-20 05:41:15 -07:00
Richard Sandiford 724d88900b Merge aarch64-cc-fusion into late-combine
I'd added the aarch64-specific CC fusion pass to fold a PTEST
instruction into the instruction that feeds the PTEST, in cases
where the latter instruction can set the appropriate flags as a
side-effect.

Combine does the same optimisation.  However, as explained in the
comments, the PTEST case often has:

  A: set predicate P based on inputs X
  B: clobber X
  C: test P

and so the fusion is only possible if we move C before B.
That's something that combine currently can't do (for the cases
that we needed).

The optimisation was never really AArch64-specific.  It's just that,
in an all-too-familiar fashion, we needed it in stage 3, when it was
too late to add something target-independent.

late-combine adds a convenient place to do the optimisation in a
target-independent way, just as combine is a convenient place to
do its related optimisation.

gcc/
	* config.gcc (aarch64*-*-*): Remove aarch64-cc-fusion.o from
	extra_objs.
	* config/aarch64/aarch64-passes.def (pass_cc_fusion): Delete.
	* config/aarch64/aarch64-protos.h (make_pass_cc_fusion): Delete.
	* config/aarch64/t-aarch64 (aarch64-cc-fusion.o): Delete.
	* config/aarch64/aarch64-cc-fusion.cc: Delete.
	* late-combine.cc (late_combine::optimizable_set): Take a set_info *
	rather than an insn_info * and move destination tests from...
	(late_combine::combine_into_uses): ...here. Take a set_info * rather
	an insn_info *.  Take the rtx set.
	(late_combine::parallelize_insns, late_combine::combine_cc_setter)
	(late_combine::combine_insn): New member functions.
	(late_combine::m_parallel): New member variable.
	* rtlanal.cc (pattern_cost): Handle sets of CC registers in the
	same way as comparisons.
2025-08-20 13:20:02 +01:00
Richard Sandiford 481f96296e rtl-ssa: Fix thinko when adding live-out uses
While testing a later patch, I found that create_degenerate_phi
had an inverted test for bitmap_set_bit.  It was assuming that
the return value was the previous bit value, rather than a
"something changed" value. :(

Also, the call to add_live_out_use shouldn't be conditional
on the DF_LR_OUT operation, since the register could be live-out
because of uses later in the same EBB (which do not require a
live-out use to be added to the rtl-ssa instruction).  Instead,
add_live_out should itself check whether a live-out use already exists.

gcc/
	* rtl-ssa/blocks.cc (function_info::create_degenerate_phi): Fix
	inverted test of bitmap_set_bit.  Call add_live_out_use even
	if the register was previously live-out from the predecessor block.
	Instead...
	(function_info::add_live_out_use): ...check here whether a live-out
	use already exists.
2025-08-20 13:20:02 +01:00
Richard Sandiford 39e8224460 rtl-ssa: Add a find_uses function
rtl-ssa already has a find_def function for finding the definition
of a particular resource (register or memory) at a particular point
in the program.  This patch adds a similar function for looking
up uses.  Both functions have amortised logarithmic complexity.

gcc/
	* rtl-ssa/accesses.h (use_lookup): New class.
	* rtl-ssa/functions.h (function_info::find_def): Expand comment.
	(function_info::find_use): Declare.
	* rtl-ssa/member-fns.inl (use_lookup::prev_use, use_lookup::next_use)
	(use_lookup::matching_use, use_lookup::matching_or_prev_use)
	(use_lookup::matching_or_next_use): New member functions.
	* rtl-ssa/accesses.cc (function_info::find_use): Likewise.
2025-08-20 13:20:01 +01:00
Richard Biener fc23b539ca tree-optimization/114480 - speedup IDF compute
The testcase in the PR shows that it's worth splitting the processing
of the initial workset, which is def_blocks from the main iteration.
This reduces SSA incremental update time from 44.7s to 32.9s.  Further
changing the workset bitmap of the main iteration to a vector
speeds up things further to 23.5s for an overall nearly halving of
the SSA incremental update compile-time and an overall 12% compile-time
saving at -O1.

Using bitmap_ior in the first loop or avoiding (immediate) re-processing
of blocks in def_blocks does not make a measurable difference for the
testcase so I left this as-is.

	PR tree-optimization/114480
	* cfganal.cc (compute_idf): Split processing of the initial
	workset from the main iteration.  Use a vector for the
	workset of the main iteration.
2025-08-20 13:34:11 +02:00
Georg-Johann Lay 0f15ff7b51 AVR: target/121608 - Don't add --relax when linking with -r.
The linker rejects --relax in relocatable links (-r), hence only
add --relax when -r is not specified.

gcc/
	PR target/121608
	* config/avr/specs.h (LINK_RELAX_SPEC): Wrap in %{!r...}.
2025-08-20 11:17:34 +02:00
Richard Biener c548abddf5 Thread the remains of vect_analyze_slp_instance
vect_analyze_slp_instance still handles stores and reduction chains.
The following threads the special handling of those two kinds,
duplicating vect_build_slp_instance into two specialized entries.

	* tree-vect-slp.cc (vect_analyze_slp_reduc_chain): New,
	copied from vect_analyze_slp_instance and only handle
	slp_inst_kind_reduc_chain.  Inline vect_build_slp_instance.
	(vect_analyze_slp_instance): Only handle slp_inst_kind_store.
	Inline vect_build_slp_instance.
	(vect_build_slp_instance): Remove now unused stmt_info parameter,
	remove special code for store groups and reduction chains.
	(vect_analyze_slp): Call vect_analyze_slp_reduc_chain
	for reduction chain SLP build and adjust.
2025-08-20 08:56:39 +02:00
Richard Biener 1bf102afed Enable gather/scatter for epilogues of vector epilogues
The restriction no longer applies, so remove it.

	* tree-vect-data-refs.cc (vect_check_gather_scatter):
	Remove restriction on epilogue of epilogue vectorization.
2025-08-20 08:53:23 +02:00
Richard Biener 893d29cf16 Remove most of the epilogue vinfo fixup
The following removes the fixup we apply to pattern stmt operands
before code generating vector epilogues.  This isn't necessary anymore
since the SLP graph now exclusively records the data flow.  Similarly
fixing up of SSA references inside DR_REF of gather/scatter isn't
necessary since we now record the analysis result and avoid re-doing
it during transform.

What we still need to keep is the adjustment of the actual pointers
to gimple stmts from stmt_vec_info and the back-reference from the DRs.

	* tree-vect-loop.cc (update_epilogue_loop_vinfo): Remove
	fixing up pattern stmt operands and gather/scatter DR_REFs.
	(find_in_mapping): Remove.
2025-08-20 08:53:23 +02:00
Richard Biener f30aa394e4 Record get_load_store_info results from analysis
The following is a patch to make us record the get_load_store_info
results from load/store analysis and re-use them during transform.
In particular this moves where SLP_TREE_MEMORY_ACCESS_TYPE is stored.

A major hassle was (and still is, to some extent), gather/scatter
handling with it's accompaning gather_scatter_info.  As
get_load_store_info no longer fully re-analyzes them but parts of
the information is recorded in the SLP tree during SLP build the
following goes and eliminates the use of this data in
vectorizable_load/store, instead recording the other relevant
part in the load-store info (namely the IFN or decl chosen).
Strided load handling keeps the re-analysis but populates the
data back to the SLP tree and the load-store info.  That's something
for further improvement.  This also shows that early classifying
a SLP tree as load/store and allocating the load-store data might
be a way to move back all of the gather/scatter auxiliary data
into one place.

Rather than mass-replacing references to variables I've kept the
locals but made them read-only, only adjusting a few elsval setters
and adding a FIXME to strided SLP handling of alignment (allowing
local override there).

The FIXME shows that while a lot of analysis is done in
get_load_store_type that's far from all of it.  There's also
a possibility that splitting up the transform phase into
separate load/store def types, based on VMAT choosen, will make
the code more maintainable.

	* tree-vectorizer.h (vect_load_store_data): New.
	(_slp_tree::memory_access_type): Remove.
	(SLP_TREE_MEMORY_ACCESS_TYPE): Turn into inline function.
	* tree-vect-slp.cc (_slp_tree::_slp_tree): Do not
	initialize SLP_TREE_MEMORY_ACCESS_TYPE.
	* tree-vect-stmts.cc (check_load_store_for_partial_vectors):
	Remove gather_scatter_info pointer argument, instead get
	info from the SLP node.
	(vect_build_one_gather_load_call): Get SLP node and builtin
	decl as argument and remove uses of gather_scatter_info.
	(vect_build_one_scatter_store_call): Likewise.
	(vect_get_gather_scatter_ops): Remove uses of gather_scatter_info.
	(vect_get_strided_load_store_ops): Get SLP node and remove
	uses of gather_scatter_info.
	(get_load_store_type): Take pointer to vect_load_store_data
	instead of individual pointers.
	(vectorizable_store): Adjust.  Re-use get_load_store_type
	result from analysis time.
	(vectorizable_load): Likewise.
2025-08-20 08:53:23 +02:00
Robert Dubner e78eb2f85b cobol: Eliminate errors that cause valgrind messages.
gcc/cobol/ChangeLog:

	* genutil.cc (get_binary_value): Fix a comment.
	* parse.y: udf_args_valid(): Fix loc calculation.
	* symbols.cc (assert): extend_66_capacity(): Avoid assert(e < e2) in
	-O0 build until symbol_table expansion is fixed.

libgcobol/ChangeLog:

	* libgcobol.cc (format_for_display_internal): Handle NumericDisplay
	properly.
	(compare_88): Fix memory access error.
	(__gg__unstring): Likewise.
2025-08-19 23:29:43 -04:00
Jerry DeLisle 2478bdf175 Fortran: Clean up and fix some refs.
gcc/fortran/ChangeLog:

	* intrinsic.texi: Correct the example given for FRACTION.
	Move the TEAM_NUMBER section to after the TANPI to align
	with the order gven in the index.
2025-08-19 18:38:07 -07:00
H.J. Lu 2ecaeee924 x86: Place the TLS call before all register setting BBs
We can't place a TLS call before a conditional jump in a basic block like

(code_label 13 11 14 4 2 (nil) [1 uses])
(note 14 13 16 4 [bb 4] NOTE_INSN_BASIC_BLOCK)
(jump_insn 16 14 17 4 (set (pc)
        (if_then_else (le (reg:CCNO 17 flags)
                (const_int 0 [0]))
            (label_ref 27)
            (pc))) "x.c":10:21 discrim 1 1462 {*jcc}
     (expr_list:REG_DEAD (reg:CCNO 17 flags)
        (int_list:REG_BR_PROB 628353713 (nil)))
 -> 27)

since the TLS call will clobber flags register nor place a TLS call in a
basic block if any live caller-saved registers aren't dead at the end of
the basic block:

;; live  in      6 [bp] 7 [sp] 16 [argp] 17 [flags] 19 [frame] 104
;; live  gen     0 [ax] 102 106 108 116 117 118 120
;; live  kill    5 [di]

Instead, we should place such call before all register setting basic
blocks which dominate the current basic block.

Keep track the replaced GNU and GNU2 TLS instructions.  Use these info to
place the __tls_get_addr call and mark FLAGS register as dead.

gcc/

	PR target/121572
	* config/i386/i386-features.cc (replace_tls_call): Add a bitmap
	argument and put the updated TLS instruction in the bitmap.
	(ix86_get_dominator_for_reg): New.
	(ix86_check_flags_reg): Likewise.
	(ix86_emit_tls_call): Likewise.
	(ix86_place_single_tls_call): Add 2 bitmap arguments for updated
	GNU and GNU2 TLS instructions.  Call ix86_emit_tls_call to emit
	TLS instruction.  Correct debug dump for before instruction.

gcc/testsuite/

	PR target/121572
	* gcc.target/i386/pr121572-1a.c: New test.
	* gcc.target/i386/pr121572-1b.c: Likewise.
	* gcc.target/i386/pr121572-2a.c: Likewise.
	* gcc.target/i386/pr121572-2b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-19 18:04:45 -07:00
GCC Administrator 4931fc20f4 Daily bump. 2025-08-20 00:19:40 +00:00
Jason Merrill 273a4d3775 c++: testcase tweak for -fimplicit-constexpr
This testcase is testing the difference between functions that are or are
not declared constexpr.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp26/expansion-stmt16.C: Add -fno-implicit-constexpr.
2025-08-19 13:49:59 -04:00
Ben Wu 54bf72ebfe c++: Fix ICE on mangling invalid compound requirement [PR120618]
This testcase caused an ICE when mangling the invalid type-constraint in
write_requirement since write_type_constraint expects a TEMPLATE_TYPE_PARM.

Setting the trailing return type to NULL_TREE when a
return-type-requirement is found in place of a type-constraint prevents the
failed assertion in write_requirement. It also allows the invalid
constraint to be satisfied in some contexts to prevent redundant errors,
e.g. in concepts-requires5.C.

Bootstrapped and tested on x86_64-linux-gnu.

	PR c++/120618

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_compound_requirement): Set type to
	NULL_TREE for invalid type-constraint.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-requires5.C: Don't require
	redundant diagnostic in static assertion.
	* g++.dg/concepts/pr120618.C: New test.

Suggested-by: Jason Merrill <jason@redhat.com>
2025-08-19 13:49:50 -04:00
Andrew Pinski 6ece2d7274 middle-end: Fix malloc like functions when calling with void "return" [PR120024]
When expanding malloc like functions, we copy the return register into a temporary
and then mark that temporary register with a noalias regnote and the alignment.
This works fine unless you are calling the function with a return type of void.
At this point then the valreg will be null and a crash will happen.

A few cleanups are included in this patch because it was easier to do the fix
with the cleanups added.
The start_sequence/end_sequence for ECF_MALLOC is no longer needed; I can't tell
if it was ever needed.
The emit_move_insn function returns the last emitted instruction anyways so
there is no reason to call get_last_insn as we can just use the return value
of emit_move_insn. This has been true since this code was originally added
so I don't understand why it was done that way beforehand.

Bootstrapped and tested on x86_64-linux-gnu.

	PR middle-end/120024

gcc/ChangeLog:

	* calls.cc (expand_call): Remove start_sequence/end_sequence
	for ECF_MALLOC.
	Check valreg before deferencing it when it comes to malloc like
	functions. Use the return value of emit_move_insn instead of
	calling get_last_insn.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-19 08:55:14 -07:00
Patrick Palka 0ab1e31807 c++: constrained corresponding using from partial spec [PR121351]
When comparing constraints during correspondence checking for a using
from a partial specialization, we need to substitute the partial
specialization arguments into the constraints rather than the primary
template arguments.  Otherwise we incorrectly reject e.g. the below
testcase as ambiguous since we substitute T=int* instead of T=int
into #1's constraints and don't notice the correspondence.

This patch corrects the recent r16-2771-gb9f1cc4e119da9 fix by using
outer_template_args instead of TI_ARGS of the DECL_CONTEXT, which
should always give the correct outer arguments for substitution.

	PR c++/121351

gcc/cp/ChangeLog:

	* class.cc (add_method): Use outer_template_args when
	substituting outer template arguments into constraints.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-using7.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-19 11:07:14 -04:00
Richard Biener f647d4f58a Remove reduction chain detection from parloops
Historically SLP reduction chains were the only multi-stmt reductions
supported.  But since we have check_reduction_path more complicated
cases are handled.  As parloops doesn't do any specific chain
processing it can solely rely on that functionality instead.

	* tree-parloops.cc (parloops_is_slp_reduction): Remove.
	(parloops_is_simple_reduction): Do not call it.
2025-08-19 15:14:09 +02:00
Richard Biener 3bc63918ce A few missing SLP node passings to vector costing
The following fixes another few missed cases to pass a SLP node
instead of a stmt_info.

	* tree-vect-loop.cc (vectorizable_reduction): Pass the
	appropriate SLP node for costing of single-def-use-cycle
	operations.
	(vectorizable_live_operation): Pass the SLP node to the
	costing hook.
	* tree-vect-stmts.cc (vectorizable_bswap): Likewise.
	(vectorizable_store): Likewise.
2025-08-19 14:40:50 +02:00
Richard Biener 05284f73cf tree-optimization/121592 - failed reduction SLP discovery
The testcase in the PR shows that when we have a reduction chain
with a wrapped conversion we fail to properly fall back to a
regular reduction, resulting in wrong-code.  The following fixes
this by failing discovery.  The testcase has other issues, so
I'm not including it here.

	PR tree-optimization/121592
	* tree-vect-slp.cc (vect_analyze_slp): When SLP reduction chain
	discovery fails, fail overall when the tail of the chain
	isn't also the entry for the non-SLP reduction.
2025-08-19 13:45:58 +02:00
Richard Biener fc8e2846c2 Fix riscv build, no longer works with python2
Building riscv no longer works with python2:

> python ./config/riscv/arch-canonicalize -misa-spec=20191213 rv64gc
  File "./config/riscv/arch-canonicalize", line 229
    print(f"ERROR: Unhandled conditional dependency: '{ext_name}' with condition:", file=sys.stderr)
                                                                                 ^
SyntaxError: invalid syntax

On systems that have python aliased to python2 we chose that, even
when python3 is available.  Don't.

	* config.gcc (riscv*-*-*): Look for python3, then fall back
	to python.  Never use python2.
2025-08-19 12:37:42 +02:00
Richard Biener 1d0a0173cd tree-optimization/121527 - wrong SRA with aggregate copy
SRA handles outermost VIEW_CONVERT_EXPRs but it wrongly ignores
those when building an access which leads to the wrong size
used when the VIEW_CONVERT_EXPR does not have the same size as
its operand which is valid GENERIC and is used by Ada upcasting.

	PR tree-optimization/121527
	* tree-sra.cc (build_access_from_expr_1): Do not strip an
	outer VIEW_CONVERT_EXPR as it's relevant for the size of
	the access.
	(get_access_for_expr): Likewise.
2025-08-19 12:37:42 +02:00
Tamar Christina 7d72cad143 AArch64: Use vectype from SLP node instead of stmt_info [PR121536]
commit g:1786be14e94bf1a7806b9dc09186f021737f0227 stops storing in
STMT_VINFO_VECTYPE the vectype of the current stmt being vectorized and instead
requires the use of SLP_TREE_VECTYPE for everything but data-refs.

This means that STMT_VINFO_VECTYPE (stmt_info) will always be NULL and so
aarch64_bool_compound_p will never properly cost predicate AND operations
anymore resulting in less vectorization.

This patch changes it to use SLP_TREE_VECTYPE and pass the slp_node to
aarch64_bool_compound_p.

gcc/ChangeLog:

	PR target/121536
	* config/aarch64/aarch64.cc (aarch64_bool_compound_p): Use
	SLP_TREE_VECTYPE instead of STMT_VINFO_VECTYPE.
	(aarch64_adjust_stmt_cost, aarch64_vector_costs::count_ops): Pass SLP
	node to aarch64_bool_compound_p.

gcc/testsuite/ChangeLog:

	PR target/121536
	* g++.target/aarch64/sve/pr121536.cc: New test.
2025-08-19 10:18:04 +01:00
Tamar Christina 08cdd61e70 middle-end: Fix costing hooks of various vectorizable_* [PR121536]
commit g:1786be14e94bf1a7806b9dc09186f021737f0227 stops storing in
STMT_VINFO_VECTYPE the vectype of the current stmt being vectorized and instead
requires the use of SLP_TREE_VECTYPE for everything but data-refs.

However contrary to what the commit says not all usages of STMT_VINFO_VECTYPE
have been purged from vectorizable_* as the costing hooks which don't pass the
SLP tree as an agrument will extract vectype using STMT_VINFO_VECTYPE.

This results in no vector type being passed to the backends and results in a few
costing test failures in AArch64.

This commit replaces the last few cases I could find, all except for in
vectorizable_reduction when single_defuse_cycle where the stmt being costed is
not the representative of the PHI in the SLP tree but rather the out of tree
reduction statement.  So I've left that alone, but it does mean vectype is NULL.

Most likely this needs to use the overload where we pass an explicit vectype but
I wasn't sure so left it for now.

gcc/ChangeLog:

	PR target/121536
	* tree-vect-loop.cc (vectorizable_phi, vectorizable_recurr,
	vectorizable_nonlinear_induction, vectorizable_induction): Pass slp_node
	instead of stmt_info to record_stmt_cost.
2025-08-19 10:17:17 +01:00
Tamar Christina 4982644625 AArch64: Fix scalar costing after removal of vectype from mid-end [PR121536]
commit g:fb59c5719c17a04ecfd58b5e566eccd6d2ac583a stops passing the scalar type
(confusingly named vectype) to the costing hook when doing scalar costing.

As a result, we could no longer distinguish between FPR and GPR scalar stmts.
A later commit also removed STMT_VINFO_VECTYPE from stmt_info.

This leaves the only remaining option to get the type of the original stmt in
the stmt_info.  This patch does this when we're performing scalar costing.

Ideally I'd refactor this a bit because a lot of the hooks just need to know if
it's FP or not, but this seems pointless with the ongoing costing churn.  So for
now this restores our costing.

gcc/ChangeLog:

	PR target/121536
	* config/aarch64/aarch64.cc (aarch64_vector_costs::add_stmt_cost): Set
	vectype from type of lhs of gimple stmt.
2025-08-19 10:15:54 +01:00
Tomasz Kamiński 8c2b3377a2 libstdc++: Restore call to test6642 in string_vector_iterators.cc test [PR104874]
The test call was accidentally omitted in r16-2484-gdc49c0a46ec96e,
a commit that refactored this test file. This patch adds it back.

	PR libstdc++/104874

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/random_access/string_vector_iterators.cc:
	Call test6642.
2025-08-19 11:03:15 +02:00
Nathaniel Shead b514cd7a4b testsuite: Fix g++.dg/abi/mangle83.C [PR121578]
This testcase (added in r16-3233-g7921bb4afcb7a3) mistakenly only
required C++14, but auto template paramaters are a C++17 feature.

	PR c++/121578

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle83.C: Requires C++17.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-08-19 15:08:21 +10:00
Nathaniel Shead f0c7611659 c++/modules: Fix exporting using-decls of unattached purview functions [PR120195]
We have logic to adjust a function decl if it gets re-declared as a
using-decl with different purviewness, but we also need to do the same
if it gets redeclared with different exportedness.

	PR c++/120195

gcc/cp/ChangeLog:

	* name-lookup.cc (do_nonmember_using_decl): Also handle change
	in exportedness of a function.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/using-32_a.C: New test.
	* g++.dg/modules/using-32_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-08-19 12:32:17 +10:00
Nathaniel Shead 82e4932623 testsuite: Fix PR108080 testcase for some targets [PR121396]
I added a testcase for the (temporary) warning that we don't currently
support the 'gnu::optimize' or 'gnu::target' attributes in r15-10183;
however, some targets produce target nodes even when only an optimize
attribute is present.  This adjusts the warning.

	PR c++/108080
	PR c++/121396

gcc/testsuite/ChangeLog:

	* g++.dg/modules/pr108080.H: Also allow target warnings.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-08-19 12:32:16 +10:00
GCC Administrator 3b58b78f1a Daily bump. 2025-08-19 00:20:02 +00:00
Andrew Pinski 2be801a805 docs: Fix __builtin_object_size example [PR121581]
This example used to work (with C) in GCC 14 before the
warning for different pointer types without a cast was changed
to an error.
The fix is to make the q variable `int*` rather than the current `char*`.
This also fixes the example for C++ too.

Pushed as obvious after doing a `make html`.

	PR middle-end/121581
gcc/ChangeLog:

	* doc/extend.texi (__builtin_object_size): Fix example.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-18 12:20:32 -07:00
Indu Bhagat 0e09be99c0 opts: use sanitize_code_type for sanitizer flags
Currently, the data type of sanitizer flags is unsigned int, with
SANITIZE_SHADOW_CALL_STACK (1UL << 31) being highest individual
enumerator for enum sanitize_code.  Use 'sanitize_code_type' data type
to allow for more distinct instrumentation modes be added when needed.

gcc/ChangeLog:

	* flag-types.h (sanitize_code_type): Define.
	* asan.h (sanitize_flags_p): Use 'sanitize_code_type' instead of
	'unsigned int'.
	* common.opt: Likewise.
	* dwarf2asm.cc (dw2_output_indirect_constant_1): Likewise.
	* opts.cc (find_sanitizer_argument): Likewise.
	(report_conflicting_sanitizer_options): Likewise.
	(parse_sanitizer_options): Likewise.
	(parse_no_sanitize_attribute): Likewise.
	* opts.h (parse_sanitizer_options): Likewise.
	(parse_no_sanitize_attribute): Likewise.
	* tree-cfg.cc (print_no_sanitize_attr_value): Likewise.
	* tree.cc (tree_fits_sanitize_code_type_p): Define.
	(tree_to_sanitize_code_type): Likewise.
	* tree.h (tree_fits_sanitize_code_type_p): Declare.
	(tree_to_sanitize_code_type): Likewise.

gcc/c-family/ChangeLog:

	* c-attribs.cc (add_no_sanitize_value): Use 'sanitize_code_type'
	instead of 'unsigned int'.
	(handle_no_sanitize_attribute): Likewise.
	(handle_no_sanitize_address_attribute): Likewise.
	(handle_no_sanitize_thread_attribute): Likewise.
	(handle_no_address_safety_analysis_attribute): Likewise.
	* c-common.h (add_no_sanitize_value): Likewise.

gcc/c/ChangeLog:

	* c-parser.cc (c_parser_declaration_or_fndef): Use
	'sanitize_code_type' instead of 'unsigned int'.

gcc/cp/ChangeLog:

	* typeck.cc (get_member_function_from_ptrfunc): Use
	'sanitize_code_type' instead of 'unsigned int'.

gcc/d/ChangeLog:

	* d-attribs.cc (d_handle_no_sanitize_attribute): Use
	'sanitize_code_type' instead of 'unsigned int'.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
2025-08-18 18:09:07 +03:00
Indu Bhagat f88e1fa41e aarch64: add new constants for MTE insns
Define new constants to be used by the MTE pattern definitions.

gcc/

	* config/aarch64/aarch64.md (MEMTAG_TAG_MASK): New define
	constant.
	(MEMTAG_ADDR_MASK): Likewise.
	(irg, subp, ldg): Use new constants.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
2025-08-18 18:01:29 +03:00
Spencer Abson 1cc21cb516 MAINTAINERS: Update my email address
ChangeLog:

	* MAINTAINERS: Update my email address.

Signed-off-by: Spencer Abson <spencer.abson@student.manchester.ac.uk>
2025-08-18 14:32:04 +01:00
Tomasz Kamiński ea8ef43971 libstdc++: Add nodiscard attribute for ranges algorithm [PR121476]
This patch adds the [[nodiscard]] attribute to the operator() of ranges
algorithm function objects if their std counterpart has it.

Furthermore, we [[nodiscard]] the operator() of the following ranges
algorithms that lack a std counterpart:
* find_last, find_last_if, find_last_if_not (to match other find
  algorithms)
* contains, contains_subrange (to match find/any_of and search)

Finally, [[nodiscard]] is added to std::min and std::max overloads
that accept std::initializer_list. This appears to be an oversight,
as std::minmax is already marked, and other min overloads are as well.
The same applies to corresponding operator() overloads of ranges::min and
ranges::max.

	PR libstdc++/121476

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h (__all_of_fn::operator()):
	(__any_of_fn::operator(), __none_of_fn::operator())
	(__find_first_of_fn::operator(), __count_fn::operator())
	(__find_end_fn::operator(), __remove_if_fn::operator())
	(__remove_fn::operator(), __unique_fn::operator())
	(__is_sorted_until_fn::operator(), __is_sorted_fn::operator())
	(__lower_bound_fn::operator(), __upper_bound_fn::operator())
	(__equal_range_fn::operator(), __binary_search_fn::operator())
	(__is_partitioned_fn::operator(), __partition_point_fn::operator())
	(__minmax_fn::operator(), __min_element_fn::operator())
	(__includes_fn::operator(), __max_fn::operator())
	(__lexicographical_compare_fn::operator(), __clamp__fn::operator())
	(__find_last_fn::operator(), __find_last_if_fn::operator())
	(__find_last_if_not_fn::operator()): Add [[nodiscard]] attribute.
	* include/bits/ranges_algobase.h (__equal_fn::operator()):
	Add [[nodiscard]] attribute.
	* include/bits/ranges_util.h (__find_fn::operator())
	(__find_if_fn::operator(), __find_if_not_fn::operator())
	(__mismatch_fn::operator(), __search_fn::operator())
	(__min_fn::operator(), __adjacent_find_fn::operator()):
	Add [[nodiscard]] attribute.
	* include/bits/stl_algo.h (std::min(initializer_list<T>))
	(std::min(initializer_list<T>, _Compare))
	(std::max(initializer_list<T>))
	(std::mmax(initializer_list<T>, _Compare)): Add _GLIBCXX_NODISCARD.
	* testsuite/25_algorithms/min/constrained.cc: Silence nodiscard
	warning.
	* testsuite/25_algorithms/max/constrained.cc: Likewise.
	* testsuite/25_algorithms/minmax/constrained.cc: Likewise.
	* testsuite/25_algorithms/minmax_element/constrained.cc: Likewise.
2025-08-18 14:05:06 +02:00
Richard Sandiford 4a56ba8c8e gcse: Fix handling of partial clobbers [PR97497]
This patch fixes an internal disagreement in gcse about how to
handle partial clobbers.  Like many passes, gcse doesn't track
the modes of live values, so if a call clobbers only part of
a register, the pass has to make conservative assumptions.
As the comment in the patch says, this means:

(1) ignoring partial clobbers when computing liveness and reaching
    definitions

(2) treating partial clobbers as full clobbers when computing
    availability

DF is mostly concerned with (1), so ignores partial clobbers.

compute_hash_table_work did (2) when calculating kill sets,
but compute_transp didn't do (2) when computing transparency.
This led to a nonsensical situation of a register being in both
the transparency and kill sets.

gcc/
	PR rtl-optimization/97497
	* function-abi.h (predefined_function_abi::only_partial_reg_clobbers)
	(function_abi::only_partial_reg_clobbers): New member functions.
	* gcse-common.cc: Include regs.h and function-abi.h.
	(compute_transp): Check for partially call-clobbered registers
	and treat them as not being transparent in blocks with calls.
2025-08-18 11:12:57 +01:00
Tomasz Kamiński cc54f2f47e libstdc++: Fix-self element self-assigments when inserting an empty range [PR121313]
For __n == 0, the elements were self move-assigned by
std::move_backward(__ins, __old_finish - __n, __old_finish).

	PR libstdc++/121313

libstdc++-v3/ChangeLog:

	* include/bits/vector.tcc (vector::insert_range): Add check for
	empty size.
	* testsuite/23_containers/vector/modifiers/insert/insert_range.cc:
	New tests.
2025-08-18 10:32:01 +02:00
Xi Ruoyao 534276f1e5 LoongArch: Implement 16-byte atomic add, sub, and, or, xor, and nand with sc.q
gcc/ChangeLog:

	* config/loongarch/sync.md (UNSPEC_TI_FETCH_ADD): New unspec.
	(UNSPEC_TI_FETCH_SUB): Likewise.
	(UNSPEC_TI_FETCH_AND): Likewise.
	(UNSPEC_TI_FETCH_XOR): Likewise.
	(UNSPEC_TI_FETCH_OR): Likewise.
	(UNSPEC_TI_FETCH_NAND_MASK_INVERTED): Likewise.
	(ALL_SC): New define_mode_iterator.
	(_scq): New define_mode_attr.
	(atomic_fetch_nand<mode>): Accept ALL_SC instead of only GPR.
	(UNSPEC_TI_FETCH_DIRECT): New define_int_iterator.
	(UNSPEC_TI_FETCH): New define_int_iterator.
	(amop_ti_fetch): New define_int_attr.
	(size_ti_fetch): New define_int_attr.
	(atomic_fetch_<amop_ti_fetch>ti_scq): New define_insn.
	(atomic_fetch_<amop_ti_fetch>ti): New define_expand.
2025-08-18 09:09:38 +08:00
Xi Ruoyao 54a3853e5f LoongArch: Implement 16-byte atomic exchange with sc.q
gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_exchangeti_scq): New
	define_insn.
	(atomic_exchangeti): New define_expand.
2025-08-18 09:09:37 +08:00
Xi Ruoyao 5527195f35 LoongArch: Implement 16-byte CAS with sc.q
gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_compare_and_swapti_scq): New
	define_insn.
	(atomic_compare_and_swapti): New define_expand.
2025-08-18 09:09:37 +08:00
Xi Ruoyao 2aca41ba97 LoongArch: Implement 16-byte atomic store with sc.q
When LSX is not available but sc.q is (for example on LA664 where the
SIMD unit is not enabled), we can use a LL-SC loop for 16-byte atomic
store.

gcc/ChangeLog:

	* config/loongarch/loongarch.cc (loongarch_print_operand_reloc):
	Accept "%t" for printing the number of the 64-bit machine
	register holding the upper half of a TImode.
	* config/loongarch/sync.md (atomic_storeti_scq): New
	define_insn.
	(atomic_storeti): expand to atomic_storeti_scq if !ISA_HAS_LSX.
2025-08-18 09:09:37 +08:00
Xi Ruoyao 0f3c1b71da LoongArch: Add -m[no-]scq option
We'll use the sc.q instruction for some 16-byte atomic operations, but
it's only added in LoongArch 1.1 evolution so we need to gate it with
an option.

gcc/ChangeLog:

	* config/loongarch/genopts/isa-evolution.in (scq): New evolution
	feature.
	* config/loongarch/loongarch-evolution.cc: Regenerate.
	* config/loongarch/loongarch-evolution.h: Regenerate.
	* config/loongarch/loongarch-str.h: Regenerate.
	* config/loongarch/loongarch.opt: Regenerate.
	* config/loongarch/loongarch.opt.urls: Regenerate.
	* config/loongarch/loongarch-def.cc: Make -mscq the default for
	-march=la664 and -march=la64v1.1.
	* doc/invoke.texi (LoongArch Options): Document -m[no-]scq.
2025-08-18 09:09:37 +08:00
Xi Ruoyao 8735a4feca LoongArch: Implement 16-byte atomic store with LSX
If the vector is naturally aligned, it cannot cross cache lines so the
LSX store is guaranteed to be atomic.  Thus we can use LSX to do the
lock-free atomic store, instead of using a lock.

gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_storeti_lsx): New
	define_insn.
	(atomic_storeti): New define_expand.
2025-08-18 09:09:36 +08:00
Xi Ruoyao 89c8638deb LoongArch: Implement 16-byte atomic load with LSX
If the vector is naturally aligned, it cannot cross cache lines so the
LSX load is guaranteed to be atomic.  Thus we can use LSX to do the
lock-free atomic load, instead of using a lock.

gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_loadti_lsx): New define_insn.
	(atomic_loadti): New define_expand.
2025-08-18 09:09:36 +08:00
Xi Ruoyao c9374dbf9d LoongArch: Implement atomic_fetch_nand<GPR:mode>
Without atomic_fetch_nandsi and atomic_fetch_nanddi, __atomic_fetch_nand
is expanded to a loop containing a CAS in the body, and CAS itself is a
LL-SC loop so we have a nested loop.  This is obviously not a good idea
as we just need one LL-SC loop in fact.

As ~(atom & mask) is (~mask) | (~atom), we can just invert the mask
first and the body of the LL-SC loop would be just one orn instruction.

gcc/ChangeLog:

	* config/loongarch/sync.md
	(atomic_fetch_nand_mask_inverted<GPR:mode>): New define_insn.
	(atomic_fetch_nand<GPR:mode>): New define_expand.
2025-08-18 09:09:35 +08:00
Xi Ruoyao 6d67bbce34 LoongArch: Don't expand atomic_fetch_sub_{hi, qi} to LL-SC loop if -mlam-bh
With -mlam-bh, we should negate the addend first, and use an amadd
instruction.  Disabling the expander makes the compiler do it correctly.

gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_fetch_sub<SHORT:mode>):
	Disable if ISA_HAS_LAM_BH.
2025-08-18 09:09:35 +08:00
Xi Ruoyao cff7790016 LoongArch: Implement subword atomic_fetch_{and, or, xor} with am*.w instructions
We can just shift the mask and fill the other bits with 0 (for ior/xor)
or 1 (for and), and use an am*.w instruction to perform the atomic
operation, instead of using a LL-SC loop.

gcc/ChangeLog:

	* config/loongarch/sync.md (UNSPEC_COMPARE_AND_SWAP_AND):
	Remove.
	(UNSPEC_COMPARE_AND_SWAP_XOR): Remove.
	(UNSPEC_COMPARE_AND_SWAP_OR): Remove.
	(atomic_test_and_set): Rename to ...
	(atomic_fetch_<any_bitwise:amop><SHORT:mode>): ... this, and
	adapt the expansion to use it for any bitwise operations and any
	val, instead of just ior 1.
	(atomic_test_and_set): New define_expand.
2025-08-18 09:09:35 +08:00
Xi Ruoyao 1f1ab36058 LoongArch: Remove unneeded "andi offset, addr, 3" instruction in atomic_test_and_set
On LoongArch sll.w and srl.w instructions only take the [4:0] bits of
rk (shift amount) into account, and we've already defined
SHIFT_COUNT_TRUNCATED to 1 so the compiler knows this fact, thus we
don't need this instruction.

gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_test_and_set): Remove
	unneeded andi instruction from the expansion.
2025-08-18 09:09:35 +08:00
Xi Ruoyao 2ac0e38a30 LoongArch: Remove unneeded "b 3f" instruction after LL-SC loops
This instruction is used to skip an redundant barrier if -mno-ld-seq-sa
or the memory model requires a barrier on failure.  But with -mld-seq-sa
and other memory models the barrier may be nonexisting at all, and we
should remove the "b 3f" instruction as well.

The implementation uses a new operand modifier "%T" to output a comment
marker if the operand is a memory order for which the barrier won't be
generated.  "%T", and also "%t", are not really used before and the code
for them in loongarch_print_operand_reloc is just some MIPS legacy.

gcc/ChangeLog:

	* config/loongarch/loongarch.cc (loongarch_print_operand_reloc):
	Make "%T" output a comment marker if the operand is a memory
	order for which the barrier won't be generated; remove "%t".
	* config/loongarch/sync.md (atomic_cas_value_strong<mode>): Add
	%T before "b 3f".
	(atomic_cas_value_cmp_and_7_<mode>): Likewise.
2025-08-18 09:09:35 +08:00
Xi Ruoyao 9b55cd0405 LoongArch: Don't emit overly-restrictive barrier for LL-SC loops
For LL-SC loops, if the atomic operation has succeeded, the SC
instruction always imply a full barrier, so the barrier we manually
inserted only needs to take the account for the failure memorder, not
the success memorder (the barrier is skipped with "b 3f" on success
anyway).

Note that if we use the AMCAS instructions, we indeed need to consider
both the success memorder an the failure memorder deciding if "_db"
suffix is needed.  Thus the semantics of atomic_cas_value_strong<mode>
and atomic_cas_value_strong<mode>_amcas start to be different.  To
prevent the compiler from being too clever, use a different unspec code
for AMCAS instructions.

gcc/ChangeLog:

	* config/loongarch/sync.md (UNSPEC_COMPARE_AND_SWAP_AMCAS): New
	UNSPEC code.
	(atomic_cas_value_strong<mode>): NFC, update the comment to note
	we only need to consider failure memory order.
	(atomic_cas_value_strong<mode>_amcas): Use
	UNSPEC_COMPARE_AND_SWAP_AMCAS instead of
	UNSPEC_COMPARE_AND_SWAP.
	(atomic_compare_and_swap<mode:GPR>): Pass failure memorder to
	gen_atomic_cas_value_strong<mode>.
	(atomic_compare_and_swap<mode:SHORT>): Pass failure memorder to
	gen_atomic_cas_value_cmp_and_7_si.
2025-08-18 09:09:34 +08:00
Xi Ruoyao 91f00a7553 LoongArch: Allow using bstrins for masking the address in atomic_test_and_set
We can use bstrins for masking the address here.  As people are already
working on LA32R (which lacks bstrins instructions), for future-proofing
we check whether (const_int -4) is an and_operand and force it into an
register if not.

gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_test_and_set): Use bstrins
	for masking the address if possible.
2025-08-18 09:09:34 +08:00
Xi Ruoyao d1d7ecfbc6 LoongArch: Don't use "+" for atomic_{load, store} "m" constraint
Atomic load does not modify the memory.  Atomic store does not read the
memory, thus we can use "=" instead.

gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_load<mode>): Remove "+" for
	the memory operand.
	(atomic_store<mode>): Use "=" instead of "+" for the memory
	operand.
2025-08-18 09:09:34 +08:00
Xi Ruoyao b8e147d46e LoongArch: (NFC) Remove amo and use size instead
They are the same.

gcc/ChangeLog:

	* config/loongarch/sync.md: Use <size> instead of <amo>.
	(amo): Remove.
2025-08-18 09:09:34 +08:00
Xi Ruoyao 77abaa72ed LoongArch: (NFC) Remove atomic_optab and use amop instead
They are the same.

gcc/ChangeLog:

	* config/loongarch/sync.md (atomic_optab): Remove.
	(atomic_<atomic_optab><mode>): Change atomic_optab to amop.
	(atomic_fetch_<atomic_optab><mode>): Likewise.
2025-08-18 09:09:33 +08:00
GCC Administrator 0f9ce736b8 Daily bump. 2025-08-18 00:18:52 +00:00
Austin Law 6f63044a7a [PR target/121213] Avoid unnecessary constant load in amoswap
PR 121213 shows an unnecessary "li target,0" in an atomic exchange loop
on RISC-V.

The source operand for an amoswap instruction should allow (const_int 0)
in addition to GPRs.  So the operand's predicate is changed to
"reg_or_0_operand".   The corresponding constraint is also changed to
allow a reg or the constant 0.

With the source operand no longer tied to the destination operand we do
not need the earlyclobber for the destination, so the destination
operand's constraint is adjusted accordingly.

This patch does not address the unnecessary sign extension reported in
the PR.

Tested with no regressions on riscv32-elf and riscv64-elf.

	PR target/121213
gcc/
	* config/riscv/sync.md (amo_atomic_exchange<mode>): Allow
	(const_int 0) as input operand. Do not tie input to output.
	No longer earlyclobber the output.

gcc/testsuite
	* gcc.target/riscv/amo/pr121213.c: New test.
2025-08-17 09:04:47 -06:00
dragan.mladjenovic 80f6911ed3 Add test for spill failure
Adding the float-agnostic reproducer as test-case.

gcc/testsuite/

	* gcc.target/mips/tls-1.c: New file.
2025-08-17 08:52:36 -06:00
Matthew Fortune bd29cbf666 Testsuite: Use HAS_LDC instead of a specific ISA
The call-clobbered-1.c test has both reasons to be above a certain
ISA and below a certain ISA level.  The option based ISA min/max
code only triggers if there is no isa level request.

gcc/testsuite/
	* gcc.target/mips/call-clobbered-1.c: Use HAS_LDC ghost
	option instead of isa>=2.
2025-08-17 08:47:02 -06:00
Andrew Bennett 24a34a7efa Testsuite: Fix tests properly for compact-branches
Compact-branches use the balc opcode, this patch adjusts the testsuite
to handle that correctly.

gcc/testsuite
	* gcc.target/mips/near-far-1.c: Fix tests properly for
	compact-branches (jals and balc).
	* gcc.target/mips/near-far-2.c: Likewise.
	* gcc.target/mips/near-far-3.c: Likewise.
	* gcc.target/mips/near-far-4.c: Likewise.
2025-08-17 08:42:43 -06:00
Jeff Law f05a284db7 Testsuite: Adjust tests to cope with -mips16
Various tests are missing NOMIPS16 markers or can be safely
skipped via -mno-mips16.  Adjust them appropriately.

gcc/testsuite/

	* gcc.target/mips/call-clobbered-2.c: Add a NOMIPS16 attribute.
	* gcc.target/mips/call-clobbered-3.c: Likewise.
	* gcc.target/mips/call-clobbered-5.c: Likewise.
	* gcc.target/mips/ds-schedule-2.c: Add an -mno-mips16 option.
	* gcc.target/mips/interrupt_handler-bug-1.c: Same as
	call-clobbered-*.c tests.
	* gcc.target/mips/movdf-1.c: Likewise.
	* gcc.target/mips/movdf-2.c: Likewise.
	* gcc.target/mips/movdf-3.c: Likewise.
	* gcc.target/mips/msa-builtins.c: Same as ds-schedule-2.c.
	Remove a NOMIPS16 attribute from builtins.
	* gcc.target/mips/msa.c: Likewise.
2025-08-17 08:34:22 -06:00
Matthew Fortune c9c767468c Testsuite: Fix insn-*.c tests from trunk
Ensure micromips test does not get confused about library support.
Ensure insn-casesi.c and insn-tablejump.c can be executed.

Move the micromips/mips16 selection into the file as per function
attributes so that there is no requirement on having a full
micromips or mips16 runtime to execute the test.

gcc/testsuite/

	* gcc.target/mips/insn-casesi.c: Require mips16 support but
	not the command line option.
	* gcc.target/mips/insn-tablejump.c: Force o32 ABI as
	we do not really support n32/n64 microMIPS.  Require micromips
	support but not the command line option.
2025-08-17 08:26:12 -06:00
Artemiy Volkov 21251fe7ff regrename: treat writes as reads for fused instruction pairs
Consider the following (RISC-V) instruction pair:

mul s6,a1,a2
add s6,a4,s6

Without this patch, while handling the second instruction, (a) the
existing chain for s6 will first be closed (upon the terminate_write
action for the input operand), then (b) a new one will be opened (upon
the mark_write action for the output operand).  This will likely lead to
the two output operands being different physical registers, breaking the
single-output property required for some macro-op fusion pairs.

This patch, using the single_output_fused_pair_p () predicate introduced
earlier, changes the regrename behavior for such pairs to append the
input and the output operands to the existing chain (as if both actions
were mark_read), instead of breaking the current renaming chain and
starting a new one.  This ensures that the output operands of both fused
instructions are kept in the same hard register, and that the
single-output property of the insn pair is preserved.

gcc/ChangeLog:

	* regrename.cc (scan_rtx_reg): Handle fused insn pairs.
2025-08-17 08:08:29 -06:00
Jan Dubiec 15dc059bd7 [PR target/109324] H8/300: Fix genrecog warnings about operands missing modes.
This patch fixes genrecog warnings about operands missing modes. This is
done by explicitly specifying modes of operations.

	PR target/109324

gcc/ChangeLog:

	* config/h8300/addsub.md: Explicitly specify mode for plus operation.
	* config/h8300/jumpcall.md: Explicitly specify modes for eq and
	match_operand operations.
	* config/h8300/testcompare.md: Explicitly specify modes for eq, ltu
	and compare operations.
2025-08-17 08:04:15 -06:00
Filip Kastl baa5cc8230 MAINTAINERS, contrib: Appease check-MAINTAINERS.py (email order)
The contrib/check-MAINTAINERS.py script sorts by surname, name, bugzilla
handle and email (in this order).  Document this.  Switch around Andrew
Pinski's entries in Contributing under DCO.

Pushing as obvious.

ChangeLog:

	* MAINTAINERS: Switch around Andrew Pinski's entries in
	Contributing under DCO.

contrib/ChangeLog:

	* check-MAINTAINERS.py: Document the way the script sorts
	entries.

Signed-off-by: Filip Kastl <fkastl@suse.cz>
2025-08-17 12:56:03 +02:00
Artemiy Volkov 07a0baa760 ira: tie output allocnos for fused instruction pairs
Some of the instruction pairs recognized as fusible by a preceding
invocation of the dep_fusion pass require that both components of a pair
have the same hard register output for the fusion to work in hardware.
(An example of this would be a multiply-add operation, or a zero-extract
operation composed of two shifts.)

For all such pairs, the following conditions will hold:
  (a) Both insns are single_sets
  (b) Both insns have a register destination
  (c) The pair has been marked as fusible by setting the second insn's
SCHED_GROUP flag
  (d) Additionally, post-RA, both instructions' destination regnos are
equal

(All of these conditions are encapsulated in the newly created
single_output_fused_pair_p () predicate.)

During IRA, if conditions (a)-(c) above hold, we need to tie the two
instructions' destination allocnos together so that they are allocated
to the same hard register.  We do this in add_insn_allocno_copies () by
adding a constraint conflict to the output operands of the two
instructions.

gcc/ChangeLog:

	* ira-conflicts.cc (add_insn_allocno_copies): Handle fused insn pairs.
	* rtl.h (single_output_fused_pair_p): Declare new function.
	* rtlanal.cc (single_output_fused_pair_p): Define it.
2025-08-16 20:40:28 -06:00
Dimitar Dimitrov 14b15a9a47 [PATCH] RISC-V: Fix block matching in arch-canonicalize [PR121538]
Commit r16-3028-g0c517ddf9b136c introduced parsing of conditional blocks
in riscv-ext*.def.  For simplicity, it used a simple regular expression
to match the C++ lambda function for each condition.  But the regular
expression is too simple - it matches only the first scoped code block,
without any trailing closing braces.

The "c" dependency for the "zca" extension has two code blocks inside
its conditional.  One for RV32 and one for RV64.  The script matches
only the RV32 block, and leaves the RV64 one.  Any strings left, in turn,
are considered a list of non-conditional extensions.  Thus the quoted
strings "d" and "zcd" from that block are taken as "simple" (non-conditional)
dependencies:

  if (subset_list->xlen () == 64)
    {
      if (subset_list->lookup ("d"))
        return subset_list->lookup ("zcd");

As a result, arch-canonicalize erroneously adds "d" extension:
  $ ./config/riscv/arch-canonicalize rv32ec
  rv32efdc_zicsr_zca_zcd_zcf

  Before r16-3028-g0c517ddf9b136c the command returned:
  $ ./config/riscv/arch-canonicalize rv32ec
  rv32ec

Fix by extending the conditional block match until the number of opening
and closing braces is equal.  This change might seem crude, but it does
save us from introducing a full C++ parser into the simple
arch-canonicalize python script.  With this patch the script now
returns:

  $ ./config/riscv/arch-canonicalize rv32ec
  rv32ec_zca

Ok for trunk?

	PR target/121538

gcc/ChangeLog:

	* config/riscv/arch-canonicalize (parse_dep_exts):
	Match condition block up to closing brace.
	(test_parse_long_condition_block): New test.
2025-08-16 20:30:14 -06:00
H.J. Lu 38e8115dd2 x86: Add target("80387") function attribute
Add target("80387") attribute to enable and disable x87 instructions in a
function.

gcc/

	PR target/121541
	* config/i386/i386-options.cc
	(ix86_valid_target_attribute_inner_p): Add target("80387")
	attribute.  Set the mask bit in opts_set->x_target_flags if the
	mask bit in opts->x_target_flags is updated.
	* doc/extend.texi: Document target("80387") function attribute.

gcc/testsuite/

	PR target/121541
	* gcc.target/i386/pr121541-1a.c: New test.
	* gcc.target/i386/pr121541-1b.c: Likewise.
	* gcc.target/i386/pr121541-2.c: Likewise.
	* gcc.target/i386/pr121541-3.c: Likewise.
	* gcc.target/i386/pr121541-4.c: Likewise.
	* gcc.target/i386/pr121541-5a.c: Likewise.
	* gcc.target/i386/pr121541-5b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-16 18:29:16 -07:00
GCC Administrator b42c5ee445 Daily bump. 2025-08-17 00:19:17 +00:00
Nathaniel Shead 7921bb4afc c++: Implement P2115R0 linkage changes for unnamed unscoped enums [PR120503]
We currently list P2115R0 as implemented, but only the modules changes
had been done.  This patch implements the linkage changes so that
unnamed unscoped enums will use the name of the first enumerator for
linkage purposes.

This is (strictly speaking) a breaking change, as code that previously
relied on unnamed enumerations being internal linkage may have overloads
using those types become exposed and clash with other functions in a
different TU that have been similarly exposed.  As such this feature is
only implemented for C++20.

No ABI flag warning is provided, partly because C++20 is still an
experimental standard, but also because any affected functions could not
have been part of an ABI until this change anyway.

A number of testcases that are testing for behaviour of no-linkage types
are adjusted to use an enumeration with no values, so that the pre-C++20
and post-C++20 behaviour is equivalently tested.

In terms of implementation, I had originally considered adjusting the
DECL_NAME of the enum, as with 'name_unnamed_type', but this ended up
being more complicated as it had unwanted interactions with the existing
modules streaming and with name lookup and diagnostic messages.  This
patch instead uses a new function to derive this case.

The standard says that ([dcl.enum] p11) such an enum "...is denoted, for
linkage purposes, by its underlying type and its first enumerator", so
we need to add a new mangling production as well to handle this.

	PR c++/120503
	PR c++/120824

gcc/cp/ChangeLog:

	* cp-tree.h (TYPE_UNNAMED_P): Adjust for enums with enumerators
	for linkage purposes.
	(enum_with_enumerator_for_linkage_p): Declare.
	* decl.cc (name_unnamed_type): Adjust assertions to handle enums
	with enumerators for linkage purposes.
	(grokdeclarator): Use a typedef name for enums with enumerators
	for linkage purposes.
	(enum_with_enumerator_for_linkage_p): New function.
	(finish_enum_value_list): Reset type linkage for enums with
	enumerators for linkage purposes.
	* mangle.cc (write_unnamed_enum_name): New function.
	(write_unqualified_name): Handle enums with enumerators for
	linkage purposes.
	* tree.cc (decl_linkage): Fixup unnamed enums.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle32.C: Remove enumerator list.
	* g++.dg/cpp0x/linkage2.C: Likewise.
	* g++.dg/ext/vector26.C: Likewise.
	* g++.dg/other/anon3.C: Likewise.
	* g++.dg/abi/mangle83.C: New test.
	* g++.dg/modules/enum-15_a.C: New test.
	* g++.dg/modules/enum-15_b.C: New test.

include/ChangeLog:

	* demangle.h (enum demangle_component_type): Add enumeration
	DEMANGLE_COMPONENT_UNNAMED_ENUM.

libiberty/ChangeLog:

	* cp-demangle.c (d_unnamed_enum): New function.
	(d_unqualified_name): Call it.
	(cplus_demangle_type): Handle unscoped unnamed types
	(Ue, Ul, etc.)
	(d_count_templates_scopes): Handle unnamed enums.
	(d_find_pack): Likewise.
	(d_print_comp_inner): Print unnamed enums.
	* testsuite/demangle-expected: Add tests.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-17 10:14:14 +10:00
Pan Li 38d76a4e60 RISC-V: Update the comments of vx combine [NFC]
The supported insn of vx combine is out of date, update all
insn supported for now.

gcc/ChangeLog:

	* config/riscv/autovec-opt.md: Add supported insn
	of vx combine.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-17 08:07:15 +08:00
Pan Li 756f771f58 RISC-V: Add missed DONE for vx combine pattern [NFC]
The previous patch missed the DONE indicator of the vx
combine pattern.  Thus add it back.

gcc/ChangeLog:

	* config/riscv/autovec-opt.md: Add missed DONE
	for vx combine pattern.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-17 08:07:15 +08:00
H.J. Lu 2e567a0655 fortran: Set DECL_TLS_MODEL after processing a variable
Call set_decl_tls_model only after a variable has been fully processed,
not in the middle of processing it.

gcc/fortran/

	PR fortran/107421
	* trans-common.cc (build_common_decl): Call set_decl_tls_model
	after processing a variable.
	* trans-decl.cc (gfc_finish_var_decl): Likewise.
	(get_proc_pointer_decl): Likewise.

gcc/testsuite/

	PR fortran/107421
	* gfortran.dg/gomp/pr107421.f90: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-16 14:24:09 -07:00
Mikael Pettersson dc3d8daa4a MAINTAINERS: Add myself to write after approval
ChangeLog:

	* MAINTAINERS: Add myself to write after approval.
2025-08-16 11:08:58 +02:00
GCC Administrator 5529a1d36f Daily bump. 2025-08-16 00:19:12 +00:00
Jakub Jelinek 9a8b436b00 c++: Implement __builtin_structured_binding_size trait
clang++ apparently added a SFINAE-friendly __builtin_structured_binding_size
trait to return the structured binding size (or error if not in SFINAE
contexts if a type doesn't have a structured binding size).

The expansion statement patch already anticipated this through adding
complain argument to cp_finish_decomp.

The following patch implements it.

2025-08-15  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* doc/extend.texi (Type Traits): Document
	__builtin_structured_binding_size.
gcc/cp/
	* cp-trait.def (STRUCTURED_BINDING_SIZE): New unary trait.
	* cp-tree.h (finish_structured_binding_size): Declare.
	* semantics.cc (trait_expr_value): Handle
	CPTK_STRUCTURED_BINDING_SIZE.
	(finish_structured_binding_size): New function.
	(finish_trait_expr): Handle CPTK_RANK and CPTK_TYPE_ORDER
	in the switch instead of just doing break; for those and
	ifs at the end to handle them.  Handle CPTK_STRUCTURED_BINDING_SIZE.
	* pt.cc (tsubst_expr): Likewise.
	* constraint.cc (diagnose_trait_expr): Likewise.
	* decl.cc (get_tuple_size): Use mce_true for maybe_const_value.
	(cp_decomp_size): Diagnose incomplete types not just if
	processing_template_decl, and use error_at instead of pedwarn.
	If btype is NULL, just return 0 instead of diagnosing an error.
gcc/testsuite/
	* g++.dg/cpp26/expansion-stmt15.C: Expect different diagnostics
	for zero size destructuring expansion statement.
	* g++.dg/ext/builtin-structured-binding-size1.C: New test.
	* g++.dg/ext/builtin-structured-binding-size2.C: New test.
	* g++.dg/ext/builtin-structured-binding-size3.C: New test.
	* g++.dg/ext/builtin-structured-binding-size4.C: New test.
2025-08-15 22:38:41 +02:00
Jakub Jelinek 91b5fc4ae2 c++: Add testcases for the defarg part of P1766R1 [PR121552]
The following patch adds some testcases for the default argument (function
and template) part of the paper, making sure we diagnose multiple defargs
in the same TU and when visible in modules and DTRT when some aren't visible
and some are visible and they are equal.  Not testing when they are
different since that is IFNDR.

2025-08-15  Jakub Jelinek  <jakub@redhat.com>

	PR c++/121552
	* g++.dg/parse/defarg21.C: New test.
	* g++.dg/template/defarg24.C: New test.
	* g++.dg/modules/default-arg-4_a.C: New test.
	* g++.dg/modules/default-arg-4_b.C: New test.
	* g++.dg/modules/default-arg-5_a.C: New test.
	* g++.dg/modules/default-arg-5_b.C: New test.
2025-08-15 22:37:42 +02:00
Jakub Jelinek 828c48f068 c++: Implement C++20 P1766R1 - Mitigating minor modules maladies [PR121552]
The following patch attempts to implement the
C++20 P1766R1 - Mitigating minor modules maladies
paper.
clang++ a few years ago introduced for the diagnostics required in
the paper -Wnon-c-typedef-for-linkage pedwarn and the following patch
does that too.
The paper was accepted as a DR, the patch enables the warning
also for C++98, dunno whether it might not be better to do it only
for C++11 onwards.

The paper is also about differences in default arguments of functions
in different TUs and in modules, I think within the same TU we diagnose
it correctly (maybe I should add some testcase) and perhaps try
something with modules as well.  But in different TUs it is IFNDR.

2025-08-15  Jakub Jelinek  <jakub@redhat.com>

	PR c++/121552
gcc/
	* doc/invoke.texi (-Wno-non-c-typedef-for-linkage): Document.
gcc/c-family/
	* c.opt (Wnon-c-typedef-for-linkage): New option.
	* c.opt.urls: Regenerate.
gcc/cp/
	* decl.cc: Implement C++20 P1766R1 - Mitigating minor modules maladies.
	(diagnose_non_c_class_typedef_for_linkage,
	maybe_diagnose_non_c_class_typedef_for_linkage): New functions.
	(name_unnamed_type): Call
	maybe_diagnose_non_c_class_typedef_for_linkage.
gcc/testsuite/
	* g++.dg/cpp2a/typedef1.C: New test.
	* g++.dg/debug/dwarf2/typedef5.C: Add -Wno-non-c-typedef-for-linkage
	to dg-options.
	* g++.dg/inherit/typeinfo1.C: Add -Wno-non-c-typedef-for-linkage
	to dg-additional-options.
	* g++.dg/parse/ctor2.C: Likewise.
	* g++.dg/ext/anon-struct9.C: Add -Wno-non-c-typedef-for-linkage to
	dg-options.
	* g++.dg/ext/visibility/anon11.C: Add -Wno-non-c-typedef-for-linkage
	to dg-additional-options.
	* g++.dg/lto/pr69137_0.C: Add -Wno-non-c-typedef-for-linkage
	to dg-lto-options.
	* g++.dg/other/anon8.C: Add -Wno-non-c-typedef-for-linkage
	to dg-additional-options.
	* g++.dg/template/pr84973.C: Likewise.
	* g++.dg/template/pr84973-2.C: Likewise.
	* g++.dg/template/pr84973-3.C: Likewise.
	* g++.dg/abi/anon2.C: Likewise.
	* g++.dg/abi/anon3.C: Likewise.
	* g++.old-deja/g++.oliva/linkage1.C: Likewise.
2025-08-15 22:36:18 +02:00
Jakub Jelinek 4bed19cf61 c++: Fix default argument parsing in non-comma variadic methods [PR121539]
While the non-comma variadic functions/methods were deprecated in C++26,
they are still valid and they are valid without deprecation in C++98 to
C++23.
We parse default arguments followed by ...) outside of classes or
for out of class definitions of methods, but I think since C++11 support
in GCC 4.9 or so we consider ... to be a part of a default argument and
error on it.
I think a default argument can't validly contain a pack expansion
that ends the expression with ..., so I think we can simply handle
...) if at depth 0 as not part of the default argument.

2025-08-15  Jakub Jelinek  <jakub@redhat.com>

	PR c++/121539
	* parser.cc (cp_parser_cache_defarg): Set done to true for
	CPP_ELLIPSIS followed by CPP_CLOSE_PAREN in !nsdmi at depth 0.

	* g++.dg/parse/defarg20.C: New test.
2025-08-15 22:34:59 +02:00
Jakub Jelinek cdd015c4dd c++: Warn on #undef/#define of remaining cpp.predefined macros [PR120778]
We already warn on #undef or pedwarn on #define (but not on #define
after #undef) of some builtin macros mentioned in cpp.predefined.

The C++26 P2843R3 paper changes it from (compile time) undefined behavior
to ill-formed.  The following patch arranges for warning (for #undef)
and pedwarn (on #define) for the remaining cpp.predefined macros.
__cpp_* feature test macros only for C++20 which added some of them
to cpp.predefined, in earlier C++ versions it was just an extension and
for pedantic diagnostic I think we don't need to diagnose anything,
__STDCPP_* and __cplusplus macros for all C++ versions where they appeared.

Like the earlier posted -Wkeyword-macro diagnostics (which is done
regardless whether the identifier is defined as a macro or not, obviously
most likely none of the keywords are defined as macros initially), this
one also warns on #undef when a macro isn't defined or later #define
after #undef.

2025-08-15  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/120778
	PR target/121520
gcc/c-family/
	* c-cppbuiltin.cc (c_cpp_builtins): Implement C++26 DR 2581.  Add
	cpp_define_warn lambda and use it as well as cpp_warn where needed.
	In the if (c_dialect_cxx ()) block with __cpp_* predefinitions add
	cpp_define lambda.  Formatting fixes.
gcc/c/
	* c-decl.cc (c_init_decl_processing): Use cpp_warn instead of
	cpp_lookup and NODE_WARN bit setting.
gcc/cp/
	* lex.cc (cxx_init): Remove warn_on lambda.  Use cpp_warn instead of
	cpp_lookup and NODE_WARN bit setting or warn_on.
gcc/testsuite/
	* g++.dg/DRs/dr2581-1.C: New test.
	* g++.dg/DRs/dr2581-2.C: New test.
	* c-c++-common/cpp/pr92296-2.c: Expect warnings also on defining
	special macros after undefining them.
libcpp/
	* include/cpplib.h (struct cpp_options): Add
	suppress_builtin_macro_warnings member.
	(cpp_warn): New inline functions.
	* init.cc (cpp_create_reader): Clear suppress_builtin_macro_warnings.
	(cpp_init_builtins): Call cpp_warn on __cplusplus, __STDC__,
	__STDC_VERSION__, __STDC_MB_MIGHT_NEQ_WC__ and
	__STDCPP_STRICT_POINTER_SAFETY__ when appropriate.
	* directives.cc (do_undef): Warn on undefining NODE_WARN macros if
	not cpp_keyword_p.  Don't emit any NODE_WARN related diagnostics
	if CPP_OPTION (pfile, suppress_builtin_macro_warnings).
	(cpp_define, _cpp_define_builtin, cpp_undef): Temporarily set
	CPP_OPTION (pfile, suppress_builtin_macro_warnings) around
	run_directive calls.
	* macro.cc (_cpp_create_definition): Warn on defining NODE_WARN
	macros if they weren't previously defined and not cpp_keyword_p.
	Ignore NODE_WARN for diagnostics if
	CPP_OPTION (pfile, suppress_builtin_macro_warnings).
2025-08-15 22:31:27 +02:00
Robert Dubner 87f354ca75 cobol: Eliminate a run-time structure type that is no longer used.
gcc/cobol/ChangeLog:

	* genapi.h (parser_call_exception_end): Remove obsolete comment.
	* structs.cc (create_cbl_enabled_exception_t):
	Remove cbl_enabled_exception_type_node;
	remove create_cbl_enabled_exception_t().
	(create_our_type_nodes): Likewise.
	* structs.h (GTY): Likewise.
2025-08-15 15:41:07 -04:00
Robert Dubner 810340f9fe real: Eliminate access to uninitialized memory.
When compiling this program with gcobol:

        identification division.
        program-id. prog.
        data division.
        working-storage section.
        01 val pic v9(5) value .001.
        procedure division.
            display val
            goback.

the rounding up of .99999...9999 to 1.000...0000 causes a read of the
first byte of the output buffer.  Although harmless, it generates a
valgrind warning.  The following change clears that warning.

gcc/ChangeLog:

	* real.cc (real_to_decimal_for_mode): Set str[0] to known value.
2025-08-15 15:40:07 -04:00
Vineet Gupta f5696e9b11 RISC-V: fix __builtin_round clobbering FP exceptions flags [PR121534]
__builtin_round() fails to save/restore FP exception flags around the FP
compare insn which can potentially clobber the same.

Worth noting that the fflags restore bracketing is slightly different
than the glibc implementation. Both FLT and FCVT can potentially clobber
fflags. gcc generates below where even if branch is not taken and FCVT
is not executed, FLT still executed. Thus FSFLAGS is placed AFTER the
label 'L3'. glibc implementation FLT can't clobber due to early NaN check,
so FSFLAGS can be moved under the branch, before the label.

| convert_float_to_float_round
| ...
|   frflags	a5
|   fabs.s	fa5,fa0
|   flt.s	a4,fa5,fa4    <--- can clobber fflags
|   beq	a4,zero,.L3
|     fcvt.w.s a4,fa0,rmm     <--- also
|     fcvt.s.w	fa5,a4
|     fsgnj.s	fa0,fa5,fa0
| .L3:
|    fsflags	a5            <-- both code paths

Fixes: f652a35877 ("This is almost exclusively Jivan's work....")

	PR target/121534

gcc/ChangeLog:

	* config/riscv/riscv.md (round_pattern): save/restore fflags.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vls/math-nearbyint-1.c: Adjust
	scan pattern for additional instances of frflags/fsrflags.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
2025-08-15 10:40:35 -07:00
Francois-Xavier Coudert e905d7ee2b fixincludes: skip stdio_va_list on modern darwin
Complement to the previous commit in fixincludes
(b1f9ab40cb), for the MacOSX12.3 SDK, it
is necessary to also bypass the stdio_va_list fix. The same bypass is
used, namely, the inclusion of <_stdio.h>.

fixincludes/ChangeLog:

	* fixincl.x: Regenerate.
	* inclhack.def (stdio_va_list): Skip on recent darwin.
2025-08-15 17:34:35 +02:00
Qing Zhao 1b34664c62 Generate a call to a .ACCESS_WITH_SIZE for a FAM with counted_by attribute only when it's read from.
Currently, we generate a call to a .ACCESS_WITH_SIZE for a FAM with counted_by
attribute for every component_ref that corresponds to such an object.
Actually, such .ACCESS_WITH_SIZE calls are useless when they are generated
for a written site or an address taken site.

In this patch, we only generate a call to .ACCESS_WITH_SIZE for a FAM with
counted_by attribute when it's a read.

gcc/c/ChangeLog:

	* c-tree.h (handle_counted_by_for_component_ref): New prototype of
	build_component_ref and handle_counted_by_for_component_ref.
	* c-parser.cc (c_parser_postfix_expression): Call the new prototypes
	of build_component_ref and handle_counted_by_for_component_ref,
	update comments.
	* c-typeck.cc (default_function_array_read_conversion): Likewise.
	(convert_lvalue_to_rvalue): Likewise.
	(default_conversion): Likewise.
	(handle_counted_by_p): Update comments.
	(handle_counted_by_for_component_ref): Delete one argument.
	(build_component_ref): Delete one argument. Delete the call to
	handle_counted_by_for_component_ref completely.
	(build_array_ref): Generate call to .ACCESS_WITH_SIZE for array.

gcc/testsuite/ChangeLog:

	* gcc.dg/flex-array-counted-by-2.c: Adjust testing case.
2025-08-15 15:28:10 +00:00
Qing Zhao 9e7f8568f7 Use the counted_by attribute of pointers in array bound checker.
Current array bound checker only instruments ARRAY_REF, and the INDEX
information is the 2nd operand of the ARRAY_REF.

When extending the array bound checker to pointer references with
counted_by attributes, the hardest part is to get the INDEX of the
corresponding array ref from the offset computation expression of
the pointer ref.  I.e.

Given an OFFSET expression, and the ELEMENT_SIZE,
get the index expression from the OFFSET.
For example:
  OFFSET:
   ((long unsigned int) m * (long unsigned int) SAVE_EXPR <n>) * 4
  ELEMENT_SIZE:
   (sizetype) SAVE_EXPR <n> * 4
get the index as (long unsigned int) m.

gcc/c-family/ChangeLog:

	* c-gimplify.cc (is_address_with_access_with_size): New function.
	(ubsan_walk_array_refs_r): Instrument an INDIRECT_REF whose base
	address is .ACCESS_WITH_SIZE or an address computation whose base
	address is .ACCESS_WITH_SIZE.
	* c-ubsan.cc (ubsan_instrument_bounds_pointer_address): New function.
	(struct factor_t): New structure.
	(get_factors_from_mul_expr): New function.
	(get_index_from_offset): New function.
	(get_index_from_pointer_addr_expr): New function.
	(is_instrumentable_pointer_array_address): New function.
	(ubsan_array_ref_instrumented_p): Change prototype.
	Handle MEM_REF in addtional to ARRAY_REF.
	(ubsan_maybe_instrument_array_ref): Handle MEM_REF in addtional
	to ARRAY_REF.

gcc/testsuite/ChangeLog:

	* gcc.dg/ubsan/pointer-counted-by-bounds-2.c: New test.
	* gcc.dg/ubsan/pointer-counted-by-bounds-3.c: New test.
	* gcc.dg/ubsan/pointer-counted-by-bounds-4.c: New test.
	* gcc.dg/ubsan/pointer-counted-by-bounds-5.c: New test.
	* gcc.dg/ubsan/pointer-counted-by-bounds.c: New test.
2025-08-15 15:28:10 +00:00
Qing Zhao c49bbcad60 Use the counted_by attribute of pointers in builtinin-object-size. No need to change anything in middle-end. Add the testing case for PR120929.
gcc/testsuite/ChangeLog:

	* gcc.dg/pointer-counted-by-4-char.c: New test.
	* gcc.dg/pointer-counted-by-4-float.c: New test.
	* gcc.dg/pointer-counted-by-4-struct.c: New test.
	* gcc.dg/pointer-counted-by-4-union.c: New test.
	* gcc.dg/pointer-counted-by-4.c: New test.
	* gcc.dg/pointer-counted-by-5.c: New test.
	* gcc.dg/pointer-counted-by-6.c: New test.
	* gcc.dg/pointer-counted-by-7.c: New test.
	* gcc.dg/pr120929.c: New test.
2025-08-15 15:28:09 +00:00
Qing Zhao bddb7b2528 Extend "counted_by" attribute to pointer fields of structures. Convert a pointer reference with counted_by attribute to .ACCESS_WITH_SIZE. Fix PR120929.
For example:

struct PP {
  size_t count2;
  char other1;
  char *array2 __attribute__ ((counted_by (count2)));
  int other2;
} *pp;

specifies that the "array2" is an array that is pointed by the
pointer field, and its number of elements is given by the field
"count2" in the same structure.

In order to fix PR120929, we agreed on the following solution:

for a pointer field with counted_by attribute:

struct S {
  int n;
  int *p __attribute__((counted_by(n)));
} *f;

when generating call to .ACCESS_WITH_SIZE for f->p, instead of generating
 *.ACCESS_WITH_SIZE (&f->p, &f->n,...)

We should generate
 .ACCESS_WITH_SIZE (f->p, &f->n,...)

i.e.,
the return type and the type of the first argument of the call is the
   original pointer type in this version.

However, this code generation might bring undefined behavior into the
applicaiton if the call to .ACCESS_WITH_SIZE is generated for a pointer
field reference when this refernece is written to.

For example:

f->p = malloc (size);

***** the IL for the above is:

  tmp1 = f->p;
  tmp2 = &f->n;
  tmp3 = .ACCESS_WITH_SIZE (tmp1, tmp2, ...);
  tmp4 = malloc (size);
  tmp3 = tmp4;

In the above, in order to generate a call to .ACCESS_WITH_SIZE for the pointer
reference f->p,  the new GIMPLE tmp1 = f->p is necessary to pass the value of
the pointer f->p to the call to .ACCESS_WITH_SIZE. However, this new GIMPLE is
the one that brings UB into the application since the value of f->p is not
initialized yet when it is assigned to "tmp1".

the above IL will be expanded to the following when .ACCESS_WITH_SIZE is
expanded to its first argument:

  tmp1 = f->p;
  tmp2 = &f->n;
  tmp3 = tmp1;
  tmp4 = malloc (size);
  tmp3 = tmp4;

the final optimized IL will be:

  tmp3 = f->p;
  tmp3 = malloc (size);;

As a result, the f->p will NOT be set correctly to the pointer
returned by malloc (size).

Due to this potential issue, We will need to selectively generate the call to
.ACCESS_WITH_SIZE for f->p according to whether it's a read or a write.

We will only generate call to .ACCESS_WITH_SIZE for f->p when it's a read in
C FE.

gcc/c-family/ChangeLog:

	* c-attribs.cc (handle_counted_by_attribute): Accept counted_by
	attribute for pointer fields.

gcc/c/ChangeLog:

	* c-decl.cc (verify_counted_by_attribute): Change the 2nd argument
	to a vector of fields with counted_by attribute. Verify all fields
	in this vector.
	(finish_struct): Collect all the fields with counted_by attribute
	to a vector and pass this vector to verify_counted_by_attribute.
	* c-tree.h (handle_counted_by_for_component_ref): New prototype of
	handle_counted_by_form_component_ref.
	* c-parser.cc (c_parser_postfix_expression): Call the new prototype
	of handle_counted_by_for_component_ref.
	* c-typeck.cc (default_function_array_read_conversion): Only generate
	call to .ACCESS_WITH_SIZE for a pointer field when it's a read.
	(convert_lvalue_to_rvalue): Likewise.
	(default_conversion): Likewise.
	(handle_counted_by_p): New routine.
	(check_counted_by_attribute): New routine.
	(build_counted_by_ref): Handle pointers with counted_by.
	(build_access_with_size_for_counted_by): Handle pointers with counted_by.
	(handle_counted_by_for_component_ref): Add one more argument.
	(build_component_ref): Call the new prototype of
	handle_counted_by_for_component_ref.

gcc/ChangeLog:

	* doc/extend.texi: Extend counted_by attribute to pointer fields in
	structures. Add one more requirement to pointers with counted_by
	attribute.

gcc/testsuite/ChangeLog:

	* gcc.dg/flex-array-counted-by.c: Update test.
	* gcc.dg/pointer-counted-by-1.c: New test.
	* gcc.dg/pointer-counted-by-2.c: New test.
	* gcc.dg/pointer-counted-by-3.c: New test.
	* gcc.dg/pointer-counted-by-8.c: New test.
	* gcc.dg/pointer-counted-by-9.c: New test.
	* gcc.dg/pointer-counted-by.c: New test.
2025-08-15 15:27:41 +00:00
Umesh Kalappa ef5f0e9c51 RISC-V: MIPS prefetch extensions for MIPS RV64 P8700 and can be enabled with xmipscbop.
Addressed the comments and tested "runtest --tool gcc --target_board='riscv-sim/-march=rv64gc_zba_zbb_zbc_zbs/-mabi=lp64/-mcmodel=medlow' riscv.exp" and 32 bit too

lint warnings can be ignored for riscv-ext.opt.

gcc/ChangeLog:

	* config/riscv/riscv-ext-mips.def (DEFINE_RISCV_EXT):
	Added mips prefetch extension.
	* config/riscv/riscv-ext.opt: Generated file.
	* config/riscv/riscv.md (prefetch):
	Added mips prefetch address operand constraint.
	* config/riscv/constraints.md: Added mips specific constraint.
	* config/riscv/predicates.md (prefetch_operand):
	Updated for mips nine bits offset.
	* config/riscv/riscv.cc (riscv_prefetch_offset_address_p):
	Legitimate address with offset for prefetch check.
	* config/riscv/riscv-protos.h: Likewise.
	* config/riscv/riscv.h:
	Macros to support for mips cached type.
	* doc/riscv-ext.texi: Updated for mips prefetch.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/mipsprefetch.c: Test file for mips.pref.
2025-08-15 07:36:29 -06:00
Richard Sandiford 7232a131d7 testsuite: Add a test for [PR119156]
PR119156 was fixed by g:f702b593e7268ab161053bafd097f1b09933b783.
This patch adds a test for it.

gcc/testsuite/
	PR target/119156
	* gcc.target/aarch64/sve/pr119156_1.c: New test.
2025-08-15 14:22:23 +01:00
Richard Sandiford 84628fdbe5 RISC-V: Allow errors to be suppressed when parsing architectures
One of Alfie's FMV patches adds a hook that, in some cases,
is used to silently query a target_version (with no diagnostics
expected).  In the review, I'd suggested handling this using
a location_t *, with null meaning "suppress diagnostics":

   https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692113.html

This patch tries to propagate that through the RISC-V parsing code.
I realise this isn't very elegant, sorry.

I think riscv_compare_version_priority should also logically suppress
diagnostics, since it's supposed to be a pure query function.  (From
that point of view, advocating for this change for Alfie's patch might
have been a bit unfair.)

gcc/
	* config/riscv/riscv-protos.h
	(riscv_process_target_version_attr): Change location_t argument
	to location_t *.
	* config/riscv/riscv-subset.h
	(riscv_subset_list::riscv_subset_list): Change location_t argument
	to location_t *.
	(riscv_subset_list::parse): Likwise.
	(riscv_subset_list::set_loc): Likewise.
	(riscv_minimal_hwprobe_feature_bits): Likewise.
	(riscv_subset_list::m_loc): Change type to location_t.
	* common/config/riscv/riscv-common.cc
	(riscv_subset_list::riscv_subset_list): Change location_t argument
	to location_t *.
	(riscv_subset_list::add): Suppress diagnostics when m_loc is null.
	(riscv_subset_list::parsing_subset_version): Likewise.
	(riscv_subset_list::parse_profiles): Likewise.
	(riscv_subset_list::parse_base_ext): Likewise.
	(riscv_subset_list::parse_single_std_ext): Likewise.
	(riscv_subset_list::check_conflict_ext): Likewise.
	(riscv_subset_list::parse_single_multiletter_ext): Likewise.
	(riscv_subset_list::parse): Change location_t argument to location_t *.
	(riscv_subset_list::set_loc): Likewise.
	(riscv_minimal_hwprobe_feature_bits): Likewise.
	(riscv_parse_arch_string): Update call accordingly.
	* config/riscv/riscv-target-attr.cc
	(riscv_target_attr_parser::m_loc): Change type to location_t *.
	(riscv_target_attr_parser::riscv_target_attr_parser): Change
	location_t argument to location_t *.
	(riscv_process_one_target_attr): Likewise.
	(riscv_process_target_attr): Likewise.
	(riscv_process_target_version_attr): Likewise.
	(riscv_target_attr_parser::parse_arch): Suppress diagnostics when
	m_loc is null.
	(riscv_target_attr_parser::handle_arch): Likewise.
	(riscv_target_attr_parser::handle_cpu): Likewise.
	(riscv_target_attr_parser::handle_tune): Likewise.
	(riscv_target_attr_parser::handle_priority): Likewise.
	(riscv_option_valid_attribute_p): Update call accordingly.
	(riscv_option_valid_version_attribute_p): Likewise.
	* config/riscv/riscv.cc (parse_features_for_version): Add a
	location_t * argument.
	(dispatch_function_versions): Update call accordingly.
	(riscv_compare_version_priority): Likewise, suppressing diagnostics.
2025-08-15 14:15:35 +01:00
Francois-Xavier Coudert b1f9ab40cb fixincludes: skip stdio_stdarg_h on modern darwin
All macOS SDK since at least macOS 10.9, and until macOS 10.12
(included), feature these lines in <stdio.h>:

/* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:
 * __gnuc_va_list and include <stdarg.h> */

The clear intent (and effect) was to bypass gcc’s stdio_stdarg_h
fixinclude.

However, since macOS 10.13, these lines have been moved to <_stdio.h>,
which is itself included at the top of <stdio.h>. The unintended
consequence is that the stdio_stdarg_h fixinclude is now applied to
macOS <stdio.h>, where it is not needed. This useless fixinclude makes
the compiler more fragile and less portable.

A previous attempt to skip the stdio_stdarg_h fix entirely had to be
reverted, since it broken some very old macOS versions. The new fix is
to bypass the fix based on the detection of <_stdio.h> inclusion, which
is more robust.

fixincludes/ChangeLog:

	* fixincl.x: Regenerate.
	* inclhack.def (stdio_stdarg_h): Skip on darwin.
2025-08-15 08:54:29 +02:00
Kito Cheng 5b60bb6dc7 Use gimple_call_fntype rather than gimple_call_fndecl in pass_return_slot::execute
Call with funciton pointer might not able to get the fndecl, but fntype
so use gimple_call_fntype instead of gimple_call_fndecl.

aggregate_value_p can handle fndecl and fntype right (and even CALL_EXPR), so I
think this change is safe.

gcc/ChangeLog:

	* tree-nrv.cc (pass_return_slot::execute): Use
	gimple_call_fntype instead of gimple_call_fndecl.
2025-08-15 14:35:32 +08:00
Lulu Cheng d1c207a65d LoongArch: Fix ICE caused by function add_stmt_cost[PR121542].
PR target/121542

gcc/ChangeLog:

	* config/loongarch/loongarch.cc
	(loongarch_vector_costs::add_stmt_cost): When using vectype,
	first determine whether it is NULL.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/pr121542.c: New test.
2025-08-15 08:35:08 +08:00
GCC Administrator b703356808 Daily bump. 2025-08-15 00:17:03 +00:00
Jakub Jelinek b125eee2d8 c++: Fix up build_cplus_array_type [PR121524]
The following testcase is miscompiled since my r15-3046 change
to properly apply std attributes after closing ] for arrays to the
array type.
Array type is not a class type, so when cplus_decl_attribute is
called on the ARRAY_TYPE, it doesn't do ATTR_FLAG_TYPE_IN_PLACE.
Though, for alignas/gnu::aligned/deprecated/gnu::unavailable/gnu::unused
attributes the handlers of those attributes for non-ATTR_FLAG_TYPE_IN_PLACE
on types call build_variant_type_copy and modify some flags on the new
variant type.  They also usually don't clear *no_add_attrs, so the caller
then checks if the attributes are present on the new type and if not, calls
build_type_attribute_variant.
On the following testcase, it results in the B::foo type to be properly
32 byte aligned.
The problem happens later when we build_cplus_array_type for C::a.
elt_type is T (typedef, or using works likewise), we get as m
main variant type with unsigned int element type but because elt_type
is different, build_cplus_array_type searches the TYPE_NEXT_VARIANT chain
to find if there isn't already a useful ARRAY_TYPE to reuse.
It checks for NULL TYPE_NAME, NULL TYPE_ATTRIBUTES and the right TREE_TYPE.
Unfortunately this is not good enough, build_variant_type_copy above created
a variant type on which it modified TYPE_USER_ALIGN and TYPE_ALIGN, but
TYPE_ATTRIBUTES is still NULL, only the build_type_attribute_variant call
later adds attributes.
The problem is that the intermediate type is found in the TYPE_NEXT_VARIANT
chain and reused.

The following patch adds conditions to prevent problems with the affected
attributes (except gnu::unused, I think whether TREE_USED is set or not
shouldn't prevent sharing).  In particular, if TYPE_USER_ALIGN is not
set on the variant, it wasn't user realigned, if it is set, it verifies
it has it set because the elt_type has been user aligned and TYPE_ALIGN
is the expected one.  For deprecated it punts on the flag being set and
for gnu::unavailable as well.

2025-08-14  Jakub Jelinek  <jakub@redhat.com>

	PR c++/121524
	* tree.cc (build_cplus_array_type): Don't reuse variant type
	if it has TREE_DEPRECATED or TREE_UNAVAILABLE flags set or,
	unless elt_type has TYPE_USER_ALIGN set and TYPE_ALIGN is
	TYPE_ALIGN of elt_type, TYPE_USER_ALIGN is not set.

	* g++.dg/cpp0x/gen-attrs-89.C: New test.
2025-08-14 22:30:45 +02:00
Jeff Law 44cd33881f [PR target/119275][RISC-V] Avoid calling gen_lowpart in cases where it would ICE
So this is a minor bug in the riscv move expanders.  It has a special cases for
extraction from vector objects which makes assumptions that it can use
gen_lowpart unconditionally.  That's not always the case.

We can just bypass that special code for cases where we can't use gen_lowpart
and let the more generic code run. If gen_lowpart_common indicates we've got a
case that can't be handled we just bypass the special extraction code.

Tested on riscv64-elf and riscv32-elf.  Waiting for pre-commit CI to do its
thing.

	PR target/119275
gcc/
	* config/riscv/riscv.cc (riscv_legitimize_move): Avoid calling
	gen_lowpart for cases where it'll fail.  Just use standard expander
	paths for those cases.

gcc/testsuite/
	* gcc.target/riscv/pr119275.c: New test.
2025-08-14 14:15:40 -06:00
Mikael Pettersson ead213a9b0 fix cris-elf build with binutils-2.45
Since the cris port was added to gcc it has passed --em=criself
to gas, as an abbreviation for --emulation=criself.  Starting with
binutils-2.45 that causes a hard error in gas due to ambiguity with
another option.

Fixed by replacing the abbreviation with the complete option.

Tested by building a cross to cris-elf with binutils-2.45, which
failed before but now succeeds.

gcc/
	PR target/121336
	* config/cris/cris.h: Do not abbreviate --emulation.

Signed-off-by: Mikael Pettersson <mikpelinux@gmail.com>
2025-08-14 16:22:43 +02:00
Richard Sandiford 2934d4eea7 powerpc: Add missing modes to P9 if_then_elses [PR121501]
These patterns had one (if_then_else ...) nested within another.
The outer if_then_else had SImode, which means that the "then"
and "else" should also be SImode (unless they're const_ints).
However, the inner if_then_else was modeless, which led to an
assertion failure when trying to take a subreg of it.

gcc/
	PR target/121501
	* config/rs6000/rs6000.md (cmprb, setb_signed, setb_unsigned)
	(cmprb2, cmpeqb): Add missing modes to nested if_then_elses.
2025-08-14 13:36:40 +01:00
Avinash Jayakar 5eccc9f4db MAINTAINERS: Add myself to write after approval
2025-08-12  Avinash Jayakar  <avinashd@linux.ibm.com>

	* MAINTAINERS: Add myself to write after approval.
2025-08-14 16:28:40 +05:30
Andrew Pinski df9635322a forwprop: Limit alias walk in some cases [PR121474]
https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692091.html
pointed out:
'''
Oh, as we now do alias walks in forwprop maybe we should make this
conditional and do
this not for all pass instances, since it makes forwprop possibly a lot slower?
'''

This does patch limits the walk in a few different ways.
First only allow for a full walk in the first 2 forwprop (the one before inlining
and the one after inlining).  The other 2 forwprop are less likely to find any extra
zero prop so limit them so there is no walk.

There is an exception to the rule though, allowing to skip over clobbers still since those
will not take a long time for the walk and from when looking at benchmarks the only place
where forwprop3/4 would cause a zero prop.

The other thing is limit a full walk only if flag_expensive_optimizations is true.
This limits the walk for -O1 since flag_expensive_optimizations is turned on at -O2+.

Bootstrapped and tested on x86_64-linux-gnu.

	PR tree-optimization/121474
gcc/ChangeLog:

	* passes.def: Update forwprop1/2 to have full_walk to be true.
	* tree-ssa-forwprop.cc (optimize_aggr_zeroprop): Add new argument
	full_walk. Take into account the full_walk and clobbers at the end
	of the limit can be done always.
	(simplify_builtin_call): Add new argument, full_walk.
	Update call to optimize_aggr_zeroprop.
	(pass_forwprop): Add m_full_walk field.
	(pass_forwprop::set_pass_param): Update for m_full_walk.
	(pass_forwprop::execute): Update call to simplify_builtin_call
	and optimize_aggr_zeroprop.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-14 00:32:18 -07:00
Andrew Pinski ee67004474 forwprop: Copy prop aggregates into args
This implements the simple copy prop of aggregates into
arguments of function calls. This can reduce the number of copies
done. Just like removing of an extra copy in general, this can and
will help out SRA; since we might not need to do a full scalarization
of the aggregate now.

This is the simpliest form of this copy prop of aggregates into function arguments.

Changes since v1:
* v2: Merge in the changes of r16-3160-g2fe432175ef135.
      Move the checks for assignment and call statement into optimize_agr_copyprop
      rather than having it in optimize_agr_copyprop_1 and optimize_agr_copyprop_arg.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_agr_copyprop_1): New function split out of ...
	(optimize_agr_copyprop): Here. Also try calling optimize_agr_copyprop_arg.
	(optimize_agr_copyprop_arg): New function.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/copy-prop-aggregate-arg-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-08-14 00:28:20 -07:00
Stefan Schulze Frielinghaus 82d1617551 s390: Fix zero extend patterns using vlgv
In commit r16-2316-gc6676092318 mistakenly patterns were introduced
which actually should have been merged as alternatives to existing zero
extend patterns.

While on it, generalize the vec_extract patterns and also allow
registers for the index.  A subsequent patch will add
register+immediate support.

gcc/ChangeLog:

	* config/s390/s390.md: Merge movdi<mode>_zero_extend_A and
	movsi<mode>_zero_extend_A into zero_extendsidi2 and
	zero_extendhi<mode>2_z10 and
	zero_extend<HQI:mode><GPR:mode>2_extimm.
	* config/s390/vector.md (*movdi<mode>_zero_extend_A): Remove.
	(*movsi<mode>_zero_extend_A): Remove.
	(*movdi<mode>_zero_extend_B): Move to vec_extract patterns and
	rename to *vec_extract<mode>_zero_extend.
	(*movsi<mode>_zero_extend_B): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/vector/vlgv-zero-extend-1.c: Require target
	s390_mvx.
	* gcc.target/s390/vector/vlgv-zero-extend-2.c: New test.
2025-08-14 08:18:27 +02:00
Stefan Schulze Frielinghaus 11e8671365 testsuite: Fix asm-hard-reg-error-3.c for arm [PR121511]
This test is about register pairs.  On arm a long long is accepted in
thumb mode in any register 0-6 whereas in arm mode this is restricted to
even register pairs.  Thus, in order to trigger the error even if gcc is
configured with --with-mode=thumb, add option -marm.

gcc/testsuite/ChangeLog:

	PR target/121511
	* gcc.dg/asm-hard-reg-error-3.c: Add additional option -marm for
	target arm.
2025-08-14 08:07:15 +02:00
H.J. Lu 9d7f45e980 x86: Disallow MMX and 80387 in no_caller_saved_registers function
commit 9804b23198
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Apr 13 11:38:24 2025 -0700

    x86: Add preserve_none and update no_caller_saved_registers attributes

allowed MMX/80387 instructions in functions with no_caller_saved_registers
attribute by accident.  Update ix86_set_current_function to properly
check if MMX and 80387 are enabled.

gcc/

	PR target/121540
	* config/i386/i386-options.cc (ix86_set_current_function):
	Properly check if MMX and 80387 are enabled.

gcc/testsuite/

	PR target/121540
	* gcc.target/i386/no-callee-saved-19a.c (dg-options): Add
	"-mno-avx -mno-mmx -mno-80387"
	* gcc.target/i386/no-callee-saved-19b.c: Likewise.
	* gcc.target/i386/no-callee-saved-19c.c: Likewise.
	* gcc.target/i386/no-callee-saved-19d.c: Likewise.
	* gcc.target/i386/no-callee-saved-19e.c: Likewise.
	* gcc.target/i386/pr121208-1a.c: Likewise.
	* gcc.target/i386/pr121208-1b.c: Likewise.
	* gcc.target/i386/pr121540-1.c: New test.
	* gcc.target/i386/pr121540-2.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-13 19:31:45 -07:00
GCC Administrator 6520bb9efb Daily bump. 2025-08-14 00:20:55 +00:00
Jeff Law 07b74430df [RISC-V][PR target/121531] Cover missing insn types in p400 and p600 scheduler models
So the usual problems, DFAs without full coverage.  I took the output of Kito's
checker and use that to construct a dummy reservation for the p400 and p600
sifive models.

Tested on riscv32-elf and riscv64-elf with no regressions.

Pushing to the trunk once pre-commit CI gives the green light.

	PR target/121531
gcc/
	* config/riscv/sifive-p400.md (sifive_p400_unknown): New reservation.
	* config/riscv/sifive-p600.md (sifive_p600_unkonwn): Likewise.

gcc/testsuite/
	* gcc.target/riscv/pr121531.c: New test.
2025-08-13 17:16:41 -06:00
Marek Polacek d2dccd1bf7 c++: P2036R3 - Change scope of lambda trailing-return-type [PR102610]
This patch is an attempt to implement P2036R3 along with P2579R0, fixing
build breakages caused by P2036R3.

The simplest example is:

  auto counter1 = [j=0]() mutable -> decltype(j) {
      return j++;
  };

which currently doesn't compile because the 'j' in the capture isn't
visible in the trailing return type.  With these proposals, the 'j'
will be in a lambda scope which spans the trailing return type, so
this test will compile.

This oughtn't be difficult but decltype and other issues made this patch
much more challenging.

We have to push the explicit captures before going into
_lambda_declarator_opt because that is what parses the trailing return
type.  Yet we can't build any captures until after _lambda_body ->
start_lambda_function which creates the lambda's operator(), without
which we can't build a proxy, but _lambda_body happens only after
parsing the declarator.  This patch works around it by creating a fake
operator() and adding it to the capture and then removing it when we
have the real operator().

Another thing is that in "-> decltype(j)" we don't have the right
current_function_decl yet.  If current_lambda_expr gives us a lambda,
we know this decltype appertains to a lambda.  But we have to know if we
are in a parameter-declaration-clause: as per [expr.prim.id.unqual]/4.4,
if we are, we shouldn't be adding "const".  The new LAMBDA_EXPR_CONST_QUAL_P
flag tracks this.  But it doesn't handle nested lambdas yet, specifically,
[expr.prim.id.unqual]/14.

I don't think this patch changes behavior for the tests in
"capture-default with [=]" as the paper promises; clang++ behaves the
same as gcc with this patch.

	PR c++/102610

gcc/cp/ChangeLog:

	* cp-tree.h (LAMBDA_EXPR_CONST_QUAL_P): Define.
	(maybe_add_dummy_lambda_op): Declare.
	(remove_dummy_lambda_op): Declare.
	(push_capture_proxies): Adjust.
	* lambda.cc (build_capture_proxy): No longer static.  New early_p
	parameter.  Use it.
	(add_capture): Adjust the call to build_capture_proxy.
	(resolvable_dummy_lambda): Check DECL_LAMBDA_FUNCTION_P.
	(push_capture_proxies): New.
	(start_lambda_function): Use it.
	* name-lookup.cc (check_local_shadow): Give an error for
	is_capture_proxy.
	(cp_binding_level_descriptor): Add lambda-scope.
	(begin_scope) <case sk_lambda>: New case.
	* name-lookup.h (enum scope_kind): Add sk_lambda.
	(struct cp_binding_level): Widen kind.
	* parser.cc (cp_parser_lambda_expression): Create a new (lambda) scope
	after the lambda-introducer.
	(cp_parser_lambda_declarator_opt): Set LAMBDA_EXPR_CONST_QUAL_P.
	Create a dummy operator() if needed.  Inject the captures into the
	lambda scope.  Remove the dummy operator().
	(make_dummy_lambda_op): New.
	(maybe_add_dummy_lambda_op): New.
	(remove_dummy_lambda_op): New.
	* pt.cc (tsubst_lambda_expr): Begin/end a lambda scope.  Push the
	capture proxies.  Build/remove a dummy operator() if needed.  Set
	LAMBDA_EXPR_CONST_QUAL_P.
	* semantics.cc (parsing_lambda_declarator): New.
	(outer_var_p): Also consider captures as outer variables if in a lambda
	declarator.
	(process_outer_var_ref): Reset containing_function when
	parsing_lambda_declarator.
	(finish_decltype_type): Process decls in the lambda-declarator as well.
	Look at LAMBDA_EXPR_CONST_QUAL_P unless we have an xobj function.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/lambda/lambda-decltype3.C: Remove xfail.
	* g++.dg/warn/Wshadow-19.C: Add -Wpedantic.  Adjust a dg-warning.
	* g++.dg/warn/Wshadow-6.C: Adjust expected diagnostics.
	* g++.dg/cpp23/lambda-scope1.C: New test.
	* g++.dg/cpp23/lambda-scope2.C: New test.
	* g++.dg/cpp23/lambda-scope3.C: New test.
	* g++.dg/cpp23/lambda-scope4.C: New test.
	* g++.dg/cpp23/lambda-scope4b.C: New test.
	* g++.dg/cpp23/lambda-scope5.C: New test.
	* g++.dg/cpp23/lambda-scope6.C: New test.
	* g++.dg/cpp23/lambda-scope7.C: New test.
	* g++.dg/cpp23/lambda-scope8.C: New test.
	* g++.dg/cpp23/lambda-scope9.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-13 18:49:30 -04:00
David Malcolm 1da90c533f diagnostics/output-spec.cc: simplify implementation
No functional change intended.

gcc/ChangeLog:
	* diagnostics/output-spec.cc (sarif_scheme_handler::make_sink):
	Populate sarif_generation_options instance directly, rather than
	through local variables.
	(sarif_scheme_handler::make_sarif_gen_opts): Drop.
	(html_scheme_handler::make_sink): Populate html_generation_options
	instance directly, rather than through local variables.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-13 17:29:22 -04:00
Jakub Jelinek 0f665822a0 libiberty: Fix comment typo
This patch fixes a comment typo, whaever -> whatever, prompted by the
recent hae -> has typo fix.

2025-08-13  Jakub Jelinek  <jakub@redhat.com>

	* cp-demangle.c (d_encoding): Fix a comment typo, whaever -> whatever.
2025-08-13 22:26:54 +02:00
Jakub Jelinek 458773ac7b c++: Implement C++26 P1306R5 - Expansion statements [PR120776]
The following patch implements the C++26 P1306R5 - Expansion statements
paper.
When expansion statements are used outside of templates, the lowering
of the statement uses push_tinst_level_loc and instantiates the body
multiple times, otherwise when the new TEMPLATE_FOR_STMT statement is
being instantiated and !processing_template_decl, it instantiates the
body several times with just local_specialization_stack around each
iteration but with the original args.
Because the lowering of these statements is mostly about instantiation,
I've put the lowering code into pt.cc rather than semantics.cc.
Only destructuring expansion statements currently use in the patch
temporary lifetime extension which matches the proposed resolution of
https://cplusplus.github.io/CWG/issues/3043.html
I'm not sure what will CWG decide about that if there will be some
temporary lifetime extension for enumerating expansion statements and if
yes, under what exact rules (e.g. whether it extends all the temporaries
across one iteration of the body, or only if a reference is initialized
or nothing at all).  And for iterating expansion statements, I think I
don't understand the P2686R4 rules well yet, I think if the
expansion-initializer is used in static constexpr rvalue reference, then
it isn't needed, but not sure if it won't be needed if static would be
dropped (whether
struct S { constexpr S () : s (0) {} constexpr ~S () {} int s; };
struct T { const S &t, &u; };
void foo () { constexpr T t = { S {}, S {} }; use (t.t, t.u); }
is ok under P2686R4; though without constexpr before T I see S::~S () being
called after use, not at the end of the t declaration, so maybe it is
fine also without static).
As per
https://cplusplus.github.io/CWG/issues/3044.html
the patch uses build_int_cst (ptrdiff_type_node, i) to create second
operand of begin + i and doesn't lookup overloaded comma operator (note, I'm
actually not even creating a lambda there, just using TARGET_EXPRs).
I guess my preference would be dropping those 4 static keywords from
[stmt.expand] but the patch does use those for now and it won't be possible
to change that until the rest of P2686R4 is implemented.
As per
https://cplusplus.github.io/CWG/issues/3045.html
it treats sk_template_for like sk_for for the purpose of redeclaration of
vars in the body but doesn't yet reject [[fallthrough]]; in the expansion
stmt body (when not nested in another switch).
I'm not sure if cp_perform_range_for_lookup used in the patch is exactly
what we want for the https://eel.is/c++draft/stmt.expand#3.2
- it does finish_call_expr on the perform_koenig_lookup as well, shouldn't
for the decision whether it is iterating or destructing (i.e. tf_none)
just call perform_koenig_lookup and check if it found some
FUNCTION_DECL/OVERLOAD/TEMPLATE_DECL?
cp_decomp_size in the patch has tsubst_flags_t argument and attempts to be
SFINAE friendly, even when it isn't needed strictly for this patch.
This is with PR96185 __builtin_structured_binding_size implementation in
mind (to follow clang).
The new TEMPLATE_FOR_STMT statement is expected to be lowered to something
that doesn't use the statement at all, I've implemented break/continue
discovery in the body, so all I needed was to punt on TEMPLATE_FOR_STMT
in potential_constant_expression_1 so that we don't try to constant evaluate
it when it is still dependent (and cxx_eval_constant_expression rejects
it without any extra code).
I think only enumerating and iterating expansion statements can have zero
iteration, because for destructuring ones it doesn't use a structured
binding pack and so valid structured binding has to have at least one
iteration.  Though
https://cplusplus.github.io/CWG/issues/3048.html
could change that, this patch currently rejects it though.

2025-08-13  Jakub Jelinek  <jakub@redhat.com>

	PR c++/120776
gcc/c-family/
	* c-cppbuiltin.cc (c_cpp_builtins): Predefine
	__cpp_expansion_statements=202506L for C++26.
gcc/cp/
	* cp-tree.def: Implement C++26 P1306R5 - Expansion statements.
	(TEMPLATE_FOR_STMT): New tree code.
	* cp-tree.h (struct saved_scope): Add expansion_stmt.
	(in_expansion_stmt): Define.
	(TEMPLATE_FOR_DECL, TEMPLATE_FOR_EXPR, TEMPLATE_FOR_BODY,
	TEMPLATE_FOR_SCOPE, TEMPLATE_FOR_INIT_STMT): Define.
	(struct tinst_level): Adjust comment.
	(cp_decomp_size, finish_expansion_stmt, do_pushlevel,
	cp_build_range_for_decls, build_range_temp,
	cp_perform_range_for_lookup, begin_template_for_scope): Declare.
	(finish_range_for_stmt): Remove declaration.
	* cp-objcp-common.cc (cp_common_init_ts): Handle TEMPLATE_FOR_STMT.
	* name-lookup.h (enum scope_kind): Add sk_template_for enumerator.
	(struct cp_binding_level): Enlarge kind bitfield from 4 to 5 bits.
	Adjust comment with remaining space bits.
	* name-lookup.cc (check_local_shadow): Handle sk_template_for like
	sk_for.
	(cp_binding_level_descriptor): Add entry for sk_template_for.
	(begin_scope): Handle sk_template_for.
	* parser.h (IN_EXPANSION_STMT): Define.
	* parser.cc (cp_debug_parser): Print IN_EXPANSION_STMT bit.
	(cp_parser_lambda_expression): Temporarily clear in_expansion_stmt.
	(cp_parser_statement): Handle RID_TEMPLATE followed by RID_FOR for
	C++11.
	(cp_parser_label_for_labeled_statement): Complain about named labels
	inside of expansion stmt body.
	(cp_hide_range_decl): New function.
	(cp_parser_range_for): Use it.  Adjust do_range_for_auto_deduction
	caller.  Remove second template argument from auto_vecs bindings and
	names.
	(build_range_temp): No longer static.
	(do_range_for_auto_deduction): Add expansion_stmt argument.
	(cp_build_range_for_decls): New function.
	(cp_convert_range_for): Use it.  Call cp_perform_range_for_lookup
	rather than cp_parser_perform_range_for_lookup.
	(cp_parser_perform_range_for_lookup): Rename to ...
	(cp_perform_range_for_lookup): ... this.  No longer static.  Add
	complain argument and handle it.
	(cp_parser_range_for_member_function): Rename to ...
	(cp_range_for_member_function): ... this.
	(cp_parser_expansion_statement): New function.
	(cp_parser_jump_statement): Handle IN_EXPANSION_STMT.
	(cp_convert_omp_range_for): Adjust do_range_for_auto_deduction caller.
	Call cp_perform_range_for_lookup rather than
	cp_parser_perform_range_for_lookup.
	* error.cc (print_instantiation_full_context): Handle tldcl being
	TEMPLATE_FOR_STMT.
	(print_instantiation_partial_context_line): Likewise.
	* constexpr.cc (potential_constant_expression_1): Handle
	TEMPLATE_FOR_STMT.
	* decl.cc (poplevel_named_label_1): Use obl instead of bl->level_chain.
	(finish_case_label): Diagnose case labels inside of template for.
	(find_decomp_class_base): Add complain argument, don't diagnose
	anything and just return error_mark_node if tf_none, adjust recursive
	call.
	(cp_decomp_size): New function.
	(cp_finish_decomp): Adjust find_decomp_class_base caller.
	* semantics.cc (do_pushlevel): No longer static.
	(begin_template_for_scope): New function.
	* pt.cc (push_tinst_level_loc): Handle TEMPLATE_FOR_STMT.
	(reopen_tinst_level): Likewise.
	(tsubst_stmt): Handle TEMPLATE_FOR_STMT.
	(struct expansion_stmt_bc): New type.
	(expansion_stmt_find_bc_r, finish_expansion_stmt): New functions.
	* decl2.cc (decl_dependent_p): Return true for current function's decl
	if in_expansion_stmt.
	* call.cc (extend_ref_init_temps): Don't extend_all_temps if
	TREE_STATIC (decl).
	* cxx-pretty-print.cc (cxx_pretty_printer::statement): Handle
	TEMPLATE_FOR_STMT.
gcc/testsuite/
	* g++.dg/cpp1z/decomp64.C: New test.
	* g++.dg/cpp26/expansion-stmt1.C: New test.
	* g++.dg/cpp26/expansion-stmt2.C: New test.
	* g++.dg/cpp26/expansion-stmt3.C: New test.
	* g++.dg/cpp26/expansion-stmt4.C: New test.
	* g++.dg/cpp26/expansion-stmt5.C: New test.
	* g++.dg/cpp26/expansion-stmt6.C: New test.
	* g++.dg/cpp26/expansion-stmt7.C: New test.
	* g++.dg/cpp26/expansion-stmt8.C: New test.
	* g++.dg/cpp26/expansion-stmt9.C: New test.
	* g++.dg/cpp26/expansion-stmt10.C: New test.
	* g++.dg/cpp26/expansion-stmt11.C: New test.
	* g++.dg/cpp26/expansion-stmt12.C: New test.
	* g++.dg/cpp26/expansion-stmt13.C: New test.
	* g++.dg/cpp26/expansion-stmt14.C: New test.
	* g++.dg/cpp26/expansion-stmt15.C: New test.
	* g++.dg/cpp26/expansion-stmt16.C: New test.
	* g++.dg/cpp26/expansion-stmt17.C: New test.
	* g++.dg/cpp26/expansion-stmt18.C: New test.
	* g++.dg/cpp26/expansion-stmt19.C: New test.
	* g++.dg/cpp26/feat-cxx26.C: Add __cpp_expansion_statements
	tests.
2025-08-13 22:10:18 +02:00
Andrew Pinski 5fedaa2347 Mark epiphany and rl78 as obsolete targets
rl78 still uses reload rather than LRA.
epiphany still uses reload and causes ICEs during reload.

Both don't have a maintainer. epiphany has been without one since
2024 (2023 email) while rl78 has been without one since 2018.

gcc/ChangeLog:

	* config.gcc: Mark epiphany*-*-* and rl78*-*-* as
	obsolete targets.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-13 20:07:42 +00:00
H.J. Lu 5cf1b9a03e x86-64: Remove redundant TLS calls
For TLS calls:

1. UNSPEC_TLS_GD:

  (parallel [
    (set (reg:DI 0 ax)
   	 (call:DI (mem:QI (symbol_ref:DI ("__tls_get_addr")))
		  (const_int 0 [0])))
    (unspec:DI [(symbol_ref:DI ("e") [flags 0x50])
                (reg/f:DI 7 sp)] UNSPEC_TLS_GD)
    (clobber (reg:DI 5 di))])

2. UNSPEC_TLS_LD_BASE:

  (parallel [
    (set (reg:DI 0 ax)
	 (call:DI (mem:QI (symbol_ref:DI ("__tls_get_addr")))
		  (const_int 0 [0])))
    (unspec:DI [(reg/f:DI 7 sp)] UNSPEC_TLS_LD_BASE)])

3. UNSPEC_TLSDESC:

  (parallel [
     (set (reg/f:DI 104)
	   (plus:DI (unspec:DI [
		       (symbol_ref:DI ("_TLS_MODULE_BASE_") [flags 0x10])
                       (reg:DI 114)
                       (reg/f:DI 7 sp)] UNSPEC_TLSDESC)
                    (const:DI (unspec:DI [
				 (symbol_ref:DI ("e") [flags 0x1a])
			      ] UNSPEC_DTPOFF))))
     (clobber (reg:CC 17 flags))])

  (parallel [
    (set (reg:DI 101)
	 (unspec:DI [(symbol_ref:DI ("e") [flags 0x50])
                     (reg:DI 112)
                     (reg/f:DI 7 sp)] UNSPEC_TLSDESC))
    (clobber (reg:CC 17 flags))])

they return the same value for the same input value.  But multiple calls
with the same input value may be generated for simple programs like:

void a(long *);
int b(void);
void c(void);
static __thread long e;
long
d(void)
{
  a(&e);
  if (b())
    c();
  return e;
}

When compiled with -O2 -fPIC -mtls-dialect=gnu2, the following codes are
generated:

	.type	d, @function
d:
.LFB0:
	.cfi_startproc
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	e@TLSDESC(%rip), %rbx
	movq	%rbx, %rax
	call	*e@TLSCALL(%rax)
	addq	%fs:0, %rax
	movq	%rax, %rdi
	call	a@PLT
	call	b@PLT
	testl	%eax, %eax
	jne	.L8
	movq	%rbx, %rax
	call	*e@TLSCALL(%rax)
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	movq	%fs:(%rax), %rax
	ret
	.p2align 4,,10
	.p2align 3
.L8:
	.cfi_restore_state
	call	c@PLT
	movq	%rbx, %rax
	call	*e@TLSCALL(%rax)
	popq	%rbx
	.cfi_def_cfa_offset 8
	movq	%fs:(%rax), %rax
	ret
	.cfi_endproc

There are 3 "call *e@TLSCALL(%rax)".  They all return the same value.
Rename the remove_redundant_vector pass to the x86_cse pass, for 64bit,
extend it to also remove redundant TLS calls to generate:

d:
.LFB0:
	.cfi_startproc
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	e@TLSDESC(%rip), %rax
	movq	%fs:0, %rdi
	call	*e@TLSCALL(%rax)
	addq	%rax, %rdi
	movq	%rax, %rbx
	call	a@PLT
	call	b@PLT
	testl	%eax, %eax
	jne	.L8
	movq	%fs:(%rbx), %rax
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L8:
	.cfi_restore_state
	call	c@PLT
	movq	%fs:(%rbx), %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc

with only one "call *e@TLSCALL(%rax)".  This reduces the number of
__tls_get_addr calls in libgcc.a by 72%:

__tls_get_addr calls     before         after
libgcc.a                 868            243

gcc/

	PR target/81501
	* config/i386/i386-features.cc (x86_cse_kind): Add X86_CSE_TLS_GD,
	X86_CSE_TLS_LD_BASE and X86_CSE_TLSDESC.
	(redundant_load): Renamed to ...
	(redundant_pattern): This.
	(ix86_place_single_vector_set): Replace redundant_load with
	redundant_pattern.
	(replace_tls_call): New.
	(ix86_place_single_tls_call): Likewise.
	(pass_remove_redundant_vector_load): Renamed to ...
	(pass_x86_cse): This.  Add val, def_insn, mode, scalar_mode, kind,
	x86_cse, candidate_gnu_tls_p, candidate_gnu2_tls_p and
	candidate_vector_p.
	(pass_x86_cse::candidate_gnu_tls_p): New.
	(pass_x86_cse::candidate_gnu2_tls_p): Likewise.
	(pass_x86_cse::candidate_vector_p): Likewise.
	(remove_redundant_vector_load): Renamed to ...
	(pass_x86_cse::x86_cse): This.  Extend to remove redundant TLS
	calls.
	(make_pass_remove_redundant_vector_load): Renamed to ...
	(make_pass_x86_cse): This.
	* config/i386/i386-passes.def: Replace
	pass_remove_redundant_vector_load with pass_x86_cse.
	* config/i386/i386-protos.h (ix86_tls_get_addr): New.
	(make_pass_remove_redundant_vector_load): Renamed to ...
	(make_pass_x86_cse): This.
	* config/i386/i386.cc (ix86_tls_get_addr): Remove static.
	* config/i386/i386.h (machine_function): Add
	tls_descriptor_call_multiple_p.
	* config/i386/i386.md (tls64): New attribute.
	(@tls_global_dynamic_64_<mode>): Set tls_descriptor_call_multiple_p.
	(@tls_local_dynamic_base_64_<mode>): Likewise.
	(@tls_dynamic_gnu2_64_<mode>): Likewise.
	(*tls_global_dynamic_64_<mode>): Set tls64 attribute to gd.
	(*tls_local_dynamic_base_64_<mode>): Set tls64 attribute to ld_base.
	(*tls_dynamic_gnu2_lea_64_<mode>): Set tls64 attribute to lea.
	(*tls_dynamic_gnu2_call_64_<mode>): Set tls64 attribute to call.
	(*tls_dynamic_gnu2_combine_64_<mode>): Set tls64 attribute to
	combine.

gcc/testsuite/

	PR target/81501
	* g++.target/i386/pr81501-1.C: New test.
	* gcc.target/i386/pr81501-1a.c: Likewise.
	* gcc.target/i386/pr81501-1b.c: Likewise.
	* gcc.target/i386/pr81501-2a.c: Likewise.
	* gcc.target/i386/pr81501-2b.c: Likewise.
	* gcc.target/i386/pr81501-3.c: Likewise.
	* gcc.target/i386/pr81501-4a.c: Likewise.
	* gcc.target/i386/pr81501-4b.c: Likewise.
	* gcc.target/i386/pr81501-5.c: Likewise.
	* gcc.target/i386/pr81501-6a.c: Likewise.
	* gcc.target/i386/pr81501-6b.c: Likewise.
	* gcc.target/i386/pr81501-7.c: Likewise.
	* gcc.target/i386/pr81501-8a.c: Likewise.
	* gcc.target/i386/pr81501-8b.c: Likewise.
	* gcc.target/i386/pr81501-9a.c: Likewise.
	* gcc.target/i386/pr81501-9b.c: Likewise.
	* gcc.target/i386/pr81501-10a.c: Likewise.
	* gcc.target/i386/pr81501-10b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-13 12:34:13 -07:00
Iain Sandoe 90238c0f17 Darwin: Handle linker '-no_deduplicate' option.
Newer linker support an option to disable deduplication of entities.
This speeds up linking and can improve debug experience.  Adopting the
same criteria as clang in adding the option.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

gcc/ChangeLog:

	* config.in: Regenerate.
	* config/darwin.h (DARWIN_LD_NO_DEDUPLICATE): New.
	(LINK_SPEC): Handle -no_deduplicate.
	* configure: Regenerate.
	* configure.ac: Detect linker support for -no_deduplicate.
2025-08-13 18:26:14 +01:00
Iain Sandoe 4db9571488 Darwin: Handle string constants specially when asan is enabled.
The Darwin ABI uses a different section for string constants when
address sanitizing is enabled.  This adds defintions of the asan-
specific sections and switches string constants to the correct
section.

It also makes the string constant symbols linker-visible when
asan is enabled, but not otherwise.

gcc/ChangeLog:

	* config/darwin-sections.def (asan_string_section,
	asan_globals_section, asan_liveness_section): New.
	* config/darwin.cc (objc_method_decl): Use asan sections
	when asan is enabled.
	(darwin_encode_section_info): Alter string constant
	linker visibility depending on asan.
	(machopic_select_section): Use the asan sections when
	asan is enabled.

gcc/testsuite/ChangeLog:

	* gcc.dg/torture/darwin-cfstring-3.c: Adjust for amended
	string labels.
	* g++.dg/torture/darwin-cfstring-3.C: Likewise.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-08-13 18:23:12 +01:00
Jeff Law e31a353f1e [RISC-V][PR target/121160] Avoid bogus force_reg call
When we canonicalize the comparison for a czero sequence we need to handle both
integer and fp comparisons.  Furthermore, within the integer space we want to
make sure we promote any sub-word objects to a full word.

All that is working fine.  After promotion we then force the value into a
register if it is not a register or constant already.   The idea is not to have
to special case subregs in subsequent code.  This works fine except when we're
presented with a floating point object that would be a subword.  (subreg:SF
(reg:SI)) on rv64 for example.

So this tightens up that force_reg step.   Bootstapped and regression tested on
riscv64-linux-gnu and tested on  riscv32-elf and riscv64-elf.

Pushing to the trunk after pre-commit verifies no regressions.

Jeff

	PR target/121160
gcc/
	* config/riscv/riscv.cc (canonicalize_comparands); Tighten check for
	forcing value into a GPR.

gcc/testsuite/
	* gcc.target/riscv/pr121160.c: New test.
2025-08-13 11:17:52 -06:00
Andrew Pinski 11f7d5648c forwprop: Move check of limit first [PR121474]
This is the first step in handling the review part of:
https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692091.html
'''
Oh, as we now do alias walks in forwprop maybe we should make this
conditional and do
this not for all pass instances, since it makes forwprop possibly a lot slower?
'''

The check of the limit was after the alias check which could slow down things.
This moves the check of the limit to begining of the if.

Bootstrapped and tested on x86_64-linux-gnu.

Pushed as obvious.

	PR tree-optimization/121474
gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_aggr_zeroprop): Move the check
	for limit before the alias check.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-13 09:29:46 -07:00
Mark Wielaard eecff13cdc Regenerate libgcobol/configure
Use autoconf 2.69 to regenerate libgcobol/configure

Fixes: 9992c0a0e1 ("cobol: Bring EBCDIC NumericDisplay variables into IBM compliance.")

libgcobol/ChangeLog:

	* configure: Regenerate.
2025-08-13 17:53:27 +02:00
Robert Dubner 33e26a071f cobol: Implement and use faster __gg__packed_to_binary() routine.
The new routine uses table lookups more effectively, and avoids __int128
arithmetic until necessary.

gcc/cobol/ChangeLog:

	* genutil.cc (get_binary_value): Use the new routine.

libgcobol/ChangeLog:

	* libgcobol.cc (get_binary_value_local): Use the new routine.
	* stringbin.cc (int_from_string): Removed.
	(__gg__packed_to_binary): Implement new routine.
	* stringbin.h (__gg__packed_to_binary): Likewise.
2025-08-13 11:33:41 -04:00
Benjamin Wu 236633fd74 c++: fix typo in comment
gcc/cp/ChangeLog:

	* lex.cc (init_operators): Fix typo.
2025-08-13 10:49:42 -04:00
Richard Biener be65c9f13d Introduce SLP_TREE_PERMUTE_P
The following wraps SLP_TREE_CODE checks against VEC_PERM_EXPR
(the only relevant code) in a new SLP_TREE_PERMUTE_P predicate.
Most places guard against SLP_TREE_REPRESENTATIVE being NULL.

	* tree-vectorizer.h (SLP_TREE_PERMUTE_P): New.
	* tree-vect-slp-patterns.cc (linear_loads_p): Adjust.
	(vect_detect_pair_op): Likewise.
	(addsub_pattern::recognize): Likewise.
	* tree-vect-slp.cc (vect_print_slp_tree): Likewise.
	(vect_gather_slp_loads): Likewise.
	(vect_is_slp_load_node): Likewise.
	(optimize_load_redistribution_1): Likewise.
	(vect_optimize_slp_pass::is_cfg_latch_edge): Likewise.
	(vect_optimize_slp_pass::internal_node_cost): Likewise.
	(vect_optimize_slp_pass::start_choosing_layouts): Likewise.
	(vect_optimize_slp_pass::backward_cost): Likewise.
	(vect_optimize_slp_pass::forward_pass): Likewise.
	(vect_optimize_slp_pass::get_result_with_layout): Likewise.
	(vect_optimize_slp_pass::materialize): Likewise.
	(vect_optimize_slp_pass::dump): Likewise.
	(vect_optimize_slp_pass::decide_masked_load_lanes): Likewise.
	(vect_update_slp_vf_for_node): Likewise.
	(vect_slp_analyze_node_operations_1): Likewise.
	(vect_schedule_slp_node): Likewise.
	(vect_schedule_scc): Likewise.
	* tree-vect-stmts.cc (vect_analyze_stmt): Likewise.
	(vect_transform_stmt): Likewise.
	(vect_is_simple_use): Likewise.
2025-08-13 15:18:39 +02:00
Richard Biener 7f6da2623b Remove use of STMT_VINFO_DEF_TYPE in vect_analyze_stmt
This removes a use of STMT_VINFO_DEF_TYPE.

	* tree-vect-stmts.cc (vect_analyze_stmt): Use
	SLP_TREE_DEF_TYPE instead of STMT_VINFO_DEF_TYPE.
2025-08-13 14:45:17 +02:00
Richard Biener b8ccad471e Fold GATHER_SCATTER_*_P into vect_memory_access_type
The following splits up VMAT_GATHER_SCATTER into
VMAT_GATHER_SCATTER_LEGACY, VMAT_GATHER_SCATTER_IFN and
VMAT_GATHER_SCATTER_EMULATED.  The main motivation is to reduce
the uses of (full) gs_info, but it also makes the kind representable
by a single entry rather than the ifn and decl tristate.

The strided load with gather case gets to use VMAT_GATHER_SCATTER_IFN,
since that's what we end up checking.

	* tree-vectorizer.h (vect_memory_access_type): Replace
	VMAT_GATHER_SCATTER with three separate access types,
	VMAT_GATHER_SCATTER_LEGACY, VMAT_GATHER_SCATTER_IFN and
	VMAT_GATHER_SCATTER_EMULATED.
	(mat_gather_scatter_p): New predicate.
	(GATHER_SCATTER_LEGACY_P): Remove.
	(GATHER_SCATTER_IFN_P): Likewise.
	(GATHER_SCATTER_EMULATED_P): Likewise.
	* tree-vect-stmts.cc (check_load_store_for_partial_vectors):
	Adjust.
	(get_load_store_type): Likewise.
	(vect_get_loop_variant_data_ptr_increment): Likewise.
	(vectorizable_store): Likewise.
	(vectorizable_load): Likewise.
	* config/i386/i386.cc (ix86_vector_costs::add_stmt_cost):
	Likewise.
	* config/riscv/riscv-vector-costs.cc
	(costs::need_additional_vector_vars_p): Likewise.
	* config/aarch64/aarch64.cc (aarch64_detect_vector_stmt_subtype):
	Likewise.
	(aarch64_vector_costs::count_ops): Likewise.
	(aarch64_vector_costs::add_stmt_cost): Likewise.
2025-08-13 12:39:31 +02:00
Richard Biener 2c0ce83c9f Simplify vect_supportable_dr_alignment API
The gather_scatter_info pointer is only used as flag, so pass down
a flag.

	* tree-vectorizer.h (vect_supportable_dr_alignment): Pass
	a bool instead of a pointer to gather_scatter_info.
	* tree-vect-data-refs.cc (vect_supportable_dr_alignment):
	Likewise.
	* tree-vect-stmts.cc (get_load_store_type): Adjust.
2025-08-13 09:53:49 +02:00
Paul Thomas e6f4543f63 Fortran: Use associated TBP subroutine not found [PR89092]
2025-08-13  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/89092
	* resolve.cc (was_declared): Add subroutine attribute.

gcc/testsuite/
	PR fortran/89092
	* gfortran.dg/pr89092.f90: New test.
2025-08-13 07:16:31 +01:00
Lulu Cheng d94178d9b3 LoongArch: Define hook TARGET_COMPUTE_PRESSURE_CLASSES[PR120476].
The rtx cost value defined by the target backend affects the
calculation of register pressure classes in the IRA, thus affecting
scheduling.  This may cause program performance degradation.
For example, OpenSSL 3.5.1 SHA512 and SPEC CPU 2017 exchange_r.

This problem can be avoided by defining a set of register pressure
classes in the target backend instead of using the default IRA to
automatically calculate them.

gcc/ChangeLog:

	PR target/120476
	* config/loongarch/loongarch.cc
	(loongarch_compute_pressure_classes): New function.
	(TARGET_COMPUTE_PRESSURE_CLASSES): Define.
2025-08-13 11:19:28 +08:00
Yang Yujie 8079e96eb7 LoongArch: Add support for _BitInt [PR117599]
This patch adds support for C23's _BitInt for LoongArch.

From the LoongArch psABI[1]:

> _BitInt(N) objects are stored in little-endian order in memory
> and are signed by default.
>
> For N ≤ 64, a _BitInt(N) object have the same size and alignment
> of the smallest fundamental integral type that can contain it.
> The unused high-order bits within this containing type are filled
> with sign or zero extension of the N-bit value, depending on whether
> the _BitInt(N) object is signed or unsigned. The _BitInt(N) object
> propagates its signedness to the containing type and is laid out
> in a register or memory as an object of this type.
>
> For N > 64, _BitInt(N) objects are implemented as structs of 64-bit
> integer chunks. The number of chunks is the smallest even integer M
> so that M * 64 ≥ N. These objects are of the same size of the struct
> containing the chunks, but always have 16-byte alignment. If there
> are unused bits in the highest-ordered chunk that contains used
> bits, they are defined as the sign- or zero- extension of the used
> bits depending on whether the _BitInt(N) object is signed or
> unsigned. If an entire chunk is unused, its bits are undefined.

[1] https://github.com/loongson/la-abi-specs

	PR target/117599

gcc/ChangeLog:

	* config/loongarch/loongarch.h: Define a PROMOTE_MODE case for
	small _BitInts.
	* config/loongarch/loongarch.cc (loongarch_promote_function_mode):
	Same.
	(loongarch_bitint_type_info): New function.
	(TARGET_C_BITINT_TYPE_INFO): Declare.

libgcc/ChangeLog:

	* config/loongarch/t-softfp-tf: Enable _BitInt helper functions.
	* config/loongarch/t-loongarch: Same.
	* config/loongarch/libgcc-loongarch.ver: New file.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/bitint-alignments.c: New test.
	* gcc.target/loongarch/bitint-args.c: New test.
	* gcc.target/loongarch/bitint-sizes.c: New test.
2025-08-13 11:01:55 +08:00
Yang Yujie 8a7a433e86 LoongArch: Prioritize target-specific makefile fragments
libgcc/ChangeLog:

	* config.host: Remove unused code. Include LoongArch-specific
	tmake_files after the OS-specific ones.
2025-08-13 11:01:49 +08:00
Jeff Law 2e2589616a [RISC-V][PR target/121113] Handle HFmode in various insn reservations
So this is a minor bug in a few DFA descriptions such as the Xiangshan and a
couple of the SiFive descriptions.

While Xiangshan covers every insn type, some of the reservations check the mode
of the operation.   Concretely the fdiv/fsqrt unit reservations vary based on
the mode.  They handled DF/SF, but not HF (the relevant iterators don't include
BF).

This patch just adds HF support with the same characteristics as SF. Those who
know these designs better could perhaps improve the reservation, but this at
least keeps us from aborting.

I did check the other published DFAs for mode dependent reservations. That's
show I found the p400/p600 issue.

Tested in my tester, waiting for CI to render its verdict before pushing.

	PR target/121113
gcc/
	* config/riscv/sifive-p400.md: Handle HFmode for fdiv/fsqrt.
	* config/riscv/sifive-p600.md: Likewise.
	* config/riscv/xiangshan.md: Likewise.

gcc/testsuite/
	* gcc.target/riscv/pr121113.c: New test.
2025-08-12 20:31:34 -06:00
Robert Dubner 67e0490922 cobol: Implement faster zoned decimal to binary conversion.
Replace " value *= 10; value += digit" routines with a new one that does two
digits at a time and avoids __int128 calculations until they are necessary.

These changes also clean up the conversion behavior when a digit is not valid.

gcc/cobol/ChangeLog:

	* genutil.cc (get_binary_value): Use the new routine.

libgcobol/ChangeLog:

	* libgcobol.cc (int128_to_field): Use the new routine.
	(get_binary_value_local): Use the new routine.
	(format_for_display_internal): Formatting.
	(__gg__get_file_descriptor): Likewise.
	* stringbin.cc (string_from_combined): Formatting.
	(packed_from_combined): Likewise.
	(int_from_string): New routine.
	(__gg__numeric_display_to_binary): Likewise.
	* stringbin.h (__gg__numeric_display_to_binary): Likewise.
2025-08-12 22:23:47 -04:00
David Malcolm f622df9af2 testsuite: fix jit.dg/test-error-impossible-must-tail-call.c [PR119783]
I added this test back in r7-934-g15c671a79ca66d, but it looks like
r15-2125-g81824596361cf4 changed the error message.

gcc/testsuite/ChangeLog:
	PR testsuite/119783
	jit.dg/test-error-impossible-must-tail-call.c
	* jit.dg/test-error-impossible-must-tail-call.c (verify_code):
	Check that we get a suitable-looking error message, but don't
	try to specify exactly what the message is.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-12 21:46:41 -04:00
David Malcolm d6d1fa0039 jit: don't use &vect[0] in libgccjit++.h [PR121516]
gcc/jit/ChangeLog:
	PR jit/121516
	* libgccjit++.h (context::new_struct_type): Replace use of
	&fields[0] with fields.data ().
	(context::new_function): Likewise for params.
	(context::new_rvalue): Likewise for elements.
	(context::new_call): Likewise for args.
	(block::end_with_switch): Likewise for cases.
	(block::end_with_extended_asm_goto): Likewise for goto_blocks.
	(context::new_struct_ctor): Likewise for fields and values.
	(context::new_array_ctor): Likewise for values.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-12 21:46:41 -04:00
H.J. LuandLiu, Hongtao 9e30860f8c x86: Convert integer constant to mode of move
For

(set (reg/v:DI 106 [ k ])
     (const_int 3000000000 [0xb2d05e00]))
...
(set (reg:V4SI 115 [ _13 ])
     (vec_duplicate:V4SI (subreg:SI (reg/v:DI 106 [ k ]) 0)))
...
(set (reg:V2SI 118 [ _9 ])
     (vec_duplicate:V2SI (subreg:SI (reg/v:DI 106 [ k ]) 0)))

we should generate

(set (reg:SI 125)
     (const_int -1294967296 [0xffffffffb2d05e00]))
(set (reg:V4SI 124)
     (vec_duplicate:V4SI (reg:VSI 125))
...
(set (reg:V4SI 115 [ _13 ])
     (reg:V4SI 124)
...
(set (reg:V2SI 118 [ _9 ])
     (subreg:V2SI (reg:V4SI 124))

by converting integer constant to mode of move.

gcc/

	PR target/121497
	* config/i386/i386-features.cc (ix86_broadcast_inner): Convert
	integer constant to mode of move

gcc/testsuite/

	PR target/121497
	* gcc.target/i386/pr121497.c: New test.

Co-authored-by: Liu, Hongtao <hongtao.liu@intel.com>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-12 18:01:47 -07:00
GCC Administrator 28c0d45201 Daily bump. 2025-08-13 00:19:57 +00:00
Pan Li 4453610469 RISC-V: RISC-V: Add test for vec_duplicate + vmerge.vvm combine with GR2VR cost 0, 1 and 15
Add asm dump check and run test for vec_duplicate + vmerge.vvm
combine to vmerge.vxm, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary.h: Add test
	helper macros.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_data.h: Add test
	data for run test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-1-i16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-1-i32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-1-i64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-1-i8.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-2-i16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-2-i32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-2-i64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-2-i8.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-3-i16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-3-i32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-3-i64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-3-i8.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmerge-run-1-i16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmerge-run-1-i32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmerge-run-1-i64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmerge-run-1-i8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-13 07:38:07 +08:00
Pan Li f1ac0f805e RISC-V: Combine vec_duplicate + vmerge.vv to vmerge.vx on GR2VR cost
This patch would like to combine the vec_duplicate + vaadd.vv to the
vaadd.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

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

  #define DEF_VX_MERGE_0(T)                                      \
  void                                                           \
  test_vx_merge_##T##_case_0 (T * restrict out, T * restrict in, \
                              T x,  unsigned n)                  \
  {                                                              \
    for (unsigned i = 0; i < n; i++)                             \
      {                                                          \
        if (i % 2 == 0)                                          \
          out[i] = x;                                            \
        else                                                     \
          out[i] = in[i];                                        \
      }                                                          \
  }

  DEF_VX_MERGE_0(int32_t)

Before this patch:
  11   │     beq a3,zero,.L8
  12   │     vsetvli a5,zero,e32,m1,ta,ma
  13   │     vmv.v.x v2,a2
  ...
  16   │ .L3:
  17   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  22   │     vmerge.vvm v1,v1,v2,v0
  ...
  25   │     bne a3,zero,.L3

After this patch:
  11   │     beq a3,zero,.L8
  ...
  14   │ .L3:
  15   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  20   │     vmerge.vxm v1,v1,a2,v0
  ...
  23   │     bne a3,zero,.L3

gcc/ChangeLog:

	* config/riscv/autovec-opt.md (*merge_vx_<mode>): Add new
	pattern to combine the vmerge.vxm.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-13 07:38:07 +08:00
Robin Dapp 980e1fc195 RISC-V: Expand const_vector with 2 elts per pattern.
Hi,

In PR121334 we are asked to expand a const_vector of size 4 with
poly_int elements.  It has 2 elts per pattern so is neither a
const_vector_duplicate nor a const_vector_stepped.

We don't allow this kind of constant in legitimate_constant_p but expr
apparently still wants us to expand it under certain conditions.

This patch implements a basic expander for such kinds of patterns.
As slide1up is used to build the individual vectors it also adds
a helper function expand_slide1up.

I regtested on rv64gcv_zvl512b but unfortunately the newly created pattern is
not even executed.  I tried some variations of the original code but didn't
manage to trigger it.

Regards
 Robin

	PR target/121334

gcc/ChangeLog:

	* config/riscv/riscv-v.cc (expand_slide1up): New function.
	(expand_vector_init_trailing_same_elem): Use new function.
	(expand_const_vector_onestep): New function.
	(expand_const_vector): Uew expand_slide1up.
	(expand_vector_init_merge_repeating_sequence): Ditto.
	(shuffle_off_by_one_patterns): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/pr121334.c: New test.
2025-08-12 15:37:23 -06:00
mengqinggang 9467435253 LoongArch: macro instead enum for base abi type
enum can't be used in #if.
For #if expression, identifiers that are not macros,
which are all considered to be the number zero.

This patch may fix https://sourceware.org/bugzilla/show_bug.cgi?id=32776.

gcc/ChangeLog:

	* config/loongarch/loongarch-def.h (ABI_BASE_LP64D): New macro.
	(ABI_BASE_LP64F): New macro.
	(ABI_BASE_LP64S): New macro.
	(N_ABI_BASE_TYPES): New macro.
2025-08-12 19:08:07 +08:00
Richard Biener 6405c5c441 Cleanup SLP decision during loop analysis
The following refactors the now misleading slp_done_for_suggested_uf
and slp states kept during vectorizer loop analysis.

	* tree-vect-loop.cc (vect_analyze_loop_2): Change
	slp_done_for_suggested_uf to a boolean
	single_lane_slp_done_for_suggested_uf.  Change slp
	to force_single_lane boolean.
	(vect_analyze_loop_1): Adjust similarly.
2025-08-12 12:48:26 +02:00
Richard Sandiford e82c8413ed fwprop: Don't propagate asms [PR121253]
For the reasons explained in the comment, fwprop shouldn't even
try to propagate an asm definition.

gcc/
	PR rtl-optimization/121253
	* fwprop.cc (forward_propagate_into): Don't propagate asm defs.

gcc/testsuite/
	PR rtl-optimization/121253
	* gcc.target/aarch64/pr121253.c: New test.
2025-08-12 10:21:47 +01:00
Richard Biener c5dab6fb40 tree-optimization/121509 - failure to detect unvectorizable loop
With the hybrid stmt detection no longer working as a gate-keeper
to detect unhandled stmts we have to, and can, detect those earlier.
The appropriate place is vect_mark_stmts_to_be_vectorized where
for trivially relevant PHIs we can stop analyzing when the PHI
wasn't classified as a known def during vect_analyze_scalar_cycles.

	PR tree-optimization/121509
	* tree-vect-stmts.cc (vect_mark_stmts_to_be_vectorized):
	Fail early when we detect a relevant but not handled PHI.

	* gcc.dg/vect/pr121509.c: New testcase.
2025-08-12 11:05:35 +02:00
Richard Biener a440b382e4 tree-optimization/121514 - ICE with recent VN improvement
When inserting a compensation stmt during VN we are making sure to
register the result for the original stmt into the hashtable so
VN iteration has the chance to converge and we avoid inserting
another copy each time.  But the implementation doesn't work for
non-SSA name values, and is also not necessary for constants since
we did not insert anything for them.  The following appropriately
guards the calls to vn_nary_op_insert_stmt as was already done
in one place.

	PR tree-optimization/121514
	* tree-ssa-sccvn.cc (visit_nary_op): Only call
	vn_nary_op_insert_stmt for SSA name result.

	* gcc.dg/torture/pr121514.c: New testcase.
2025-08-12 10:19:46 +02:00
Andrew Pinski 2fe432175e forwprop: Fix non-call exceptions some more with copy prop for aggregates [PR121494]
Note this conflicts with my not yet approved patch for copy prop for aggregates into
function arguments (I will get back to that soon).

So the problem here is that I assumed if:
*a = decl1;
would not cause an exception that:
decl2 = *a;
would cause not cause one too.

I was wrong, in some cases where the Ada front-end marks `*a` in the store
as TREE_THIS_NOTRAP (due to knowing never be null or some other cases).
So that means when we prop decl1 into the statement storing decl2, we need to
mark that statement as possible to cleanup for eh.

Bootstraped and tested on x86_64-linux-gnu.
Also tested on x86_64-linux-gnu with a hack to force generate LC constant decls in the gimplifier.

	PR tree-optimization/121494
gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_agr_copyprop): Mark the bb of the use
	stmt if needed for eh cleanup.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-12 08:06:23 +00:00
Richard Biener 1786be14e9 Do not set STMT_VINFO_VECTYPE for non-dataref stmts
Now that all STMT_VINFO_VECTYPE uses from vectorizable_* have been
pruged there's no longer a need to have STMT_VINFO_VECTYPE set.
We still rely on it being present on data-ref stmts and there it
can differ between different SLP instances when doing BB vectorization.
The following removes the setting from vect_analyze_stmt and
vect_transform_stmt.

Note the following clears STMT_VINFO_VECTYPE from pattern stmts (the
vector type should have moved to the SLP tree by this time).

	* tree-vect-stmts.cc (vect_analyze_stmt): Only set
	STMT_VINFO_VECTYPE for dataref SLP representatives.
	Clear it for others and do not restore the original value.
	(vect_transform_stmt): Likewise.
2025-08-12 09:11:30 +02:00
Richard Biener 5e76090d32 Pass down vector type to avoid STMT_VINFO_VECTYPE on reduc-info
The following passes down the vector type to functions instead of
querying it from the reduc-info stmt-info.

	* tree-vect-loop.cc (get_initial_defs_for_reduction):
	Get vector type as argument.
	(vect_find_reusable_accumulator): Likewise.
	(vect_transform_cycle_phi): Adjust.
2025-08-12 09:11:30 +02:00
Richard Biener bceae48c3c Do not use STMT_VINFO_VECTYPE in vectorizable_reduction
There's one use of STMT_VINFO_VECTYPE in vectorizable_reduction
where I'm only 99% sure which SLP_TREE_VECTYPE to replace it with
(vectorizable_reduction needs a lot of post-only-SLP TLC).  The
following replaces it with the hopefully appropriate one.

	* tree-vect-loop.cc (vectorizable_reduction): Replace
	STMT_VINFO_VECTYPE use with SLP_TREE_VECTYPE.
2025-08-12 09:11:30 +02:00
Richard Biener 5294840e3c tree-optimization/121493 - another missed VN with aggregate copy
This is another case where opportunistically handling a first
aggregate copy where we failed to match up the refs exactly
(as we don't insert missing handling components) yields to a
failure in the second aggregate copy that we visit.  Add another
fixup to deal with such situations, in-line with that present
opportunistic handling.

	PR tree-optimization/121493
	* tree-ssa-sccvn.cc (vn_reference_lookup_3): Opportunistically
	strip components with known offset.

	* gcc.dg/tree-ssa/ssa-fre-109.c: New testcase.
2025-08-12 08:36:56 +02:00
Richard Biener 6d9c1aad2c Restrict aggregate copy VN generalization
The following avoids ending up with a MEM_REF as component to apply.

	* tree-ssa-sccvn.cc (vn_reference_lookup_3): When we fail to
	match up the two base MEM_REFs, fail.
2025-08-12 08:36:55 +02:00
Yuao Ma 587b8a62f5 fortran: add optional lower arg to c_f_pointer
This patch adds support for the optional lower argument in intrinsic
c_f_pointer specified in Fortran 2023. Test cases and documentation have also
been updated.

gcc/fortran/ChangeLog:

	* check.cc (gfc_check_c_f_pointer): Check lower arg legitimacy.
	* intrinsic.cc (add_subroutines): Teach c_f_pointer about lower arg.
	* intrinsic.h (gfc_check_c_f_pointer): Add lower arg.
	* intrinsic.texi: Update lower arg for c_f_pointer.
	* trans-intrinsic.cc (conv_isocbinding_subroutine): Add logic handle lower.

gcc/testsuite/ChangeLog:

	* gfortran.dg/c_f_pointer_shape_tests_7.f90: New test.
	* gfortran.dg/c_f_pointer_shape_tests_8.f90: New test.
	* gfortran.dg/c_f_pointer_shape_tests_9.f90: New test.

Signed-off-by: Yuao Ma <c8ef@outlook.com>
2025-08-12 08:13:13 +02:00
1b5b461428 Improve initial code generation for addsi/adddi
This is a patch primarily from Shreya, though I think she cribbed some
code from Philipp that we had internally within Ventana and I made some
minor adjustments as well.

So the basic idea here is similar to her work on logical ops --
specifically when we can generate more efficient code at expansion time,
then do so.  In some cases the net is better code; in other cases we
lessen reliance on mvconst_internal and finally it provides
infrastructure that I think will help address an issue Paul Antoine
reported a little while back.

The most obvious case is using paired addis from initial code generation
for some constants.  It will also use a shNadd insn when the cost to
synthesize the original value is higher than the right-shifted value.
Finally it will negate the constant and use "sub"  if the negated
constant is cheaper than the original constant.

There's more work to do in here, particularly WRT 32 bit objects for
rv64.  Shreya is looking at that right now.  There may also be cases
where another shNadd or addi would be profitable.  We haven't really
explored those cases in any detail, while there may be cases to handle,
it's unclear how often they occur in practice.

I don't want to remove the define_insn_and_split for the paired addi
cases yet.  I think that likely happens as a side effect of fixing Paul
Antoine's issue.

Bootstrapped and regression tested on a BPI & Pioneer box.  Will
obviously wait for the pre-commit tester before moving forward.

Jeff
PR target/120603
gcc/
	* config/riscv/riscv-protos.h (synthesize_add): Add prototype.
	* config/riscv/riscv.cc (synthesize_add): New function.
	* config/riscv/riscv.md (addsi3): Allow any constant as operands[2]
	in the expander.  Force the constant into a register as needed for
	TARGET_64BIT.  Use synthesize_add for !TARGET_64BIT.
	(*adddi3): Renamed from adddi3.
	(adddi3): New expander.  Use synthesize_add.

gcc/testsuite
	* gcc.target/riscv/add-synthesis-1.c: New test.

Co-authored-by: Jeff Law  <jlaw@ventanamicro.com>
Co-authored-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
2025-08-11 21:46:04 -06:00
Robert Dubner 9992c0a0e1 cobol: Bring EBCDIC NumericDisplay variables into IBM compliance.
The internal representation of Numeric Display (ND) zoned decimal variables
when operating in EBCDIC mode has been brought into compliance with IBM
conventions.  This requires changes to data input, data output, internal
conversion of zoned decimal to binary, and variable assignment.

gcc/cobol/ChangeLog:

	* genapi.cc (compare_binary_binary): Formatting.
	(cobol_compare): Formatting.
	(mh_numeric_display): Rewrite "move ND to ND" algorithm.
	(initial_from_initial): Proper initialization of EBCDIC ND variables.
	* genmath.cc (fast_add): Delete comment.
	* genutil.cc (get_binary_value): Modify for updated EBCDIC.

libgcobol/ChangeLog:

	* common-defs.h (NUMERIC_DISPLAY_SIGN_BIT): New comment; new constant.
	(EBCDIC_MINUS): New constant.
	(EBCDIC_PLUS): Likewise.
	(EBCDIC_ZERO): Likewise.
	(EBCDIC_NINE): Likewise.
	(PACKED_NYBBLE_PLUS): Likewise.
	(PACKED_NYBBLE_MINUS): Likewise.
	(PACKED_NYBBLE_UNSIGNED): Likewise.
	(NUMERIC_DISPLAY_SIGN_BIT_ASCII): Likewise.
	(NUMERIC_DISPLAY_SIGN_BIT_EBCDIC): Likewise.
	(SEPARATE_PLUS): Likewise.
	(SEPARATE_MINUS): Likewise.
	(ZONED_ZERO): Likewise.
	(ZONE_SIGNED_EBCDIC): Likewise.
	* configure: Regenerate.
	* libgcobol.cc (turn_sign_bit_on): Handle new EBCDIC sign convention.
	(turn_sign_bit_off): Likewise.
	(is_sign_bit_on): Likewise.
	(int128_to_field): EBCDIC NumericDisplay conversion.
	(get_binary_value_local): Likewise.
	(format_for_display_internal): Likewise.
	(normalize_id): Likewise.
	(__gg__inspect_format_1): Convert EBCDIC negative numbers to positive.
	* stringbin.cc (packed_from_combined): Quell cppcheck warning.

gcc/testsuite/ChangeLog:

	* cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.out:
	Change test for updated handling of Numeric Display variables.
2025-08-11 21:22:57 -04:00
GCC Administrator 1afd70fa2e Daily bump. 2025-08-12 00:20:17 +00:00
Richard Henderson bc11cbff9e aarch64: Fix condition accepted by mov<ALLI>cc
Reject QI/HImode conditions, which would require extension in
order to compare.  Fixes

z.c:10:1: error: unrecognizable insn:
   10 | }
      | ^
(insn 23 22 24 2 (set (reg:CC 66 cc)
        (compare:CC (reg:HI 128)
            (reg:HI 127))) "z.c":6:6 -1
     (nil))
during RTL pass: vregs

gcc:
	* config/aarch64/aarch64.md (mov<ALLI>cc): Accept MODE_CC
	conditions directly; reject QI/HImode conditions.

gcc/testsuite:
	* gcc.target/aarch64/cmpbr-3.c: New.
	* gcc.target/aarch64/ifcvt_multiple_sets_rewire.c: Simplify
	test for csel by ignoring the actual registers used.
2025-08-11 23:25:10 +00:00
Richard Henderson afd6aa80b3 aarch64: CMPBR branches must be invertable
Restrict the immediate range to the intersection of LT/GE and GT/LE
so that cfglayout can invert the condition to redirect any branch.

gcc:
	PR target/121388
	* config/aarch64/aarch64.cc (aarch64_cb_rhs): Restrict the
	range of LT/GE and GT/LE to their intersections.
	* config/aarch64/aarch64.md (*aarch64_cb<INT_CMP><GPI>): Unexport.
	Use cmpbr_imm_predicate instead of aarch64_cb_rhs.
	* config/aarch64/constraints.md (Uc1): Accept 0..62.
	(Uc2): Remove.
	* config/aarch64/iterators.md (cmpbr_imm_predicate): New.
	(cmpbr_imm_constraint): Update to match aarch64_cb_rhs.
	* config/aarch64/predicates.md (aarch64_cb_reg_i63_operand): New.
	(aarch64_cb_reg_i62_operand): New.

gcc/testsuite:
	PR target/121388
	* gcc.target/aarch64/cmpbr.c (u32_x0_ult_64): XFAIL.
	(i32_x0_slt_64, u64_x0_ult_64, i64_x0_slt_64): XFAIL.
	* gcc.target/aarch64/cmpbr-2.c: New.
2025-08-11 23:25:10 +00:00
Richard Henderson 2af897e11b aarch64: Consider TARGET_CMPBR in rtx costs
gcc:
	* config/aarch64/aarch64.cc (aarch64_if_then_else_costs):
	Use aarch64_cb_rhs to match CB insns.
2025-08-11 23:25:09 +00:00
Richard Henderson 23b878dfa2 aarch64: Fix gcc.target/aarch64/cmpbr.c enable
gcc/testsuite:
	* gcc.target/aarch64/cmpbr.c: Only compile, not assemble,
	since we want to scan the assembly.
2025-08-11 23:25:09 +00:00
Richard Henderson 976bad6ea4 aarch64: Remove cc clobber from *aarch64_tbz<LTGE><ALLI>1
There is a conflict between aarch64_tbzltdi1 and aarch64_cbltdi
with respect to pnum_clobbers, resulting in a recog failure:

0xa1fffe fancy_abort(char const*, int, char const*)
        ../../gcc/diagnostics/context.cc:1640
0x81340e patch_jump_insn
        ../../gcc/cfgrtl.cc:1303
0xc0eafe redirect_branch_edge
        ../../gcc/cfgrtl.cc:1330
0xc0f372 cfg_layout_redirect_edge_and_branch
        ../../gcc/cfgrtl.cc:4736
0xbfb6b9 redirect_edge_and_branch(edge_def*, basic_block_def*)
        ../../gcc/cfghooks.cc:391
0x1fa9310 try_forward_edges
        ../../gcc/cfgcleanup.cc:561
0x1fa9310 try_optimize_cfg
        ../../gcc/cfgcleanup.cc:2931
0x1fa9310 cleanup_cfg(int)
        ../../gcc/cfgcleanup.cc:3143
0x1fe11e8 rest_of_handle_cse
        ../../gcc/cse.cc:7591
0x1fe11e8 execute
        ../../gcc/cse.cc:7622

The simplest solution is to remove the clobber from aarch64_tbz.
This removes the possibility of expansion via TST+B.cond, which
will merely fall back to TBNZ+B on shorter branches.

gcc:
	PR target/121385
	* config/aarch64/aarch64.md (*aarch64_tbz<LTGE><ALLI>1): Remove
	cc clobber and expansion via TST+Bcond.

gcc/testsuite:
	PR target/121385
	* gcc.target/aarch64/cmpbr-1.c: New.
2025-08-11 23:25:09 +00:00
Richard Henderson 5a2d86939c aarch64: Disable TARGET_CMPBR with aarch64_track_speculation
With -mtrack-speculation, CC_REGNUM must be used at every
conditional branch.

gcc:
	* config/aarch64/aarch64.h (TARGET_CMPBR): False when
	aarch64_track_speculation is true.
2025-08-11 23:25:09 +00:00
Richard Henderson 21d94bf16f aarch64: Fix aarch64_split_imm24 patterns
Both patterns used !reload_completed as a condition, which is
questionable at best.  The branch pattern failed to include a
clobber of CC_REGNUM.  Both problems were unlikely to trigger
in practice, due to how the optimization pipeline is organized,
but let's fix them anyway.

gcc:
	* config/aarch64/aarch64.cc (aarch64_gen_compare_split_imm24): New.
	* config/aarch64/aarch64-protos.h: Update.
	* config/aarch64/aarch64.md (*aarch64_bcond_wide_imm<GPI>): Use it.
	Add match_scratch and cc clobbers.  Use match_operator instead of
	iterator expansion.
	(*compare_cstore<GPI>_insn): Likewise.
2025-08-11 23:25:09 +00:00
Richard Henderson ed101b98e2 aarch64: Rename and improve aarch64_split_imm24
Two of the three uses of aarch64_imm24 included the important follow-up
tests vs aarch64_move_imm and aarch64_plus_operand.  Lack of the exclusion
within aarch64_if_then_else_costs produced incorrect costing.

Since aarch64_split_imm24 has already matched a non-negative CONST_INT,
drill down from aarch64_plus_operand to aarch64_uimm12_shift.

gcc:
	* config/aarch64/predicates.md (aarch64_split_imm24): Rename from
	aarch64_imm24; exclude aarch64_move_imm and aarch64_uimm12_shift.
	* config/aarch64/aarch64.md (*aarch64_bcond_wide_imm<GPI>):
	Update for aarch64_split_imm24.
	(*compare_cstore<GPI>_insn): Likewise.
	* config/aarch64/aarch64.cc (aarch64_if_then_else_costs): Likewise.
2025-08-11 23:25:09 +00:00
Richard Henderson 75097ad09e aarch64: Fix gcs save/restore_stack_nonlocal
The save/restore_stack_nonlocal patterns passed a DImode rtx to
gen_tbranch_neqi3 for a QImode compare.  But since we're seeding
r16 with 1, GCSEnabled will clear the only set bit in r16, so we
can use CBNZ instead of TBNZ.

gcc:
	* config/aarch64/aarch64.md (tbranch_<EQL><SHORT>3): Remove.
	(save_stack_nonlocal): Use aarch64_gen_compare_zero_and_branch.
	(restore_stack_nonlocal): Likewise.

gcc/testsuite:
	* gcc.target/aarch64/gcs-nonlocal-3.c: Match cbnz.
2025-08-11 23:25:08 +00:00
Richard Henderson d91b9432f3 aarch64: Use aarch64_gen_compare_zero_and_branch in aarch64_restore_za
With -mtrack-speculation, the pattern that was directly expanded by
aarch64_restore_za is disabled.  Use the helper function instead.

gcc:
	* config/aarch64/aarch64.cc
	(aarch64_gen_compare_zero_and_branch): Export.
	* config/aarch64/aarch64-protos.h
	(aarch64_gen_compare_zero_and_branch): Declare it.
	* config/aarch64/aarch64-sme.md (aarch64_restore_za): Use it.
	* config/aarch64/aarch64.md (*aarch64_cbz<EQL><GPI>): Unexport.
2025-08-11 23:25:08 +00:00
Richard Henderson aa14b355ca aarch64: Reorg aarch64_if_the_else_costs, conditional branch
gcc:
	* config/aarch64/aarch64.cc (aarch64_if_the_else_costs): Reorg to
	include the cost of inner within TBZ sign-bit test, only match
	CBZ/CBNZ with valid modes, and both for the aarch64_imm24 test.
2025-08-11 23:25:08 +00:00
Richard Henderson dd9f0d402b aarch64: Remove an indentation level from aarch64_if_then_else_costs
gcc:
	* config/aarch64/aarch64.cc (aarch64_if_then_else_costs): Remove
	else after return and re-indent.
2025-08-11 23:25:08 +00:00
Richard Henderson fb3be07b05 aarch64: Fix spelling of BRANCH_LEN_N_1KiB
One kilobyte not one kilobit.

gcc:
	* config/aarch64/aarch64.md (BRANCH_LEN_N_1KiB): Rename
	from BRANCH_LEN_N_1Kib.
2025-08-11 23:25:08 +00:00
Nicolas Werner 041248ca43 c++: Quoting in -fmodules-mapper
Users might be using a space in their build directory path. To allow
specifying such a root for the module mapper started by GCC, we need the
command to allow quotes. Previously quoting a path passed to the module
mapper was not possible, so replace the custom argv parsing with
the argv parsing logic from libiberty, that supports fairly standard
shell quoting using single and double quotes.

The primary purpose of this patch is to allow passing paths with spaces
to the --root parameter of the module mapper.

No test is included as spaces in build directories are tricky cross
platform. The patch was tested manually on my system.

gcc/cp/ChangeLog:

	* mapper-client.cc (spawn_mapper_program): change argv parsing

Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>
2025-08-11 16:06:00 -07:00
Joseph Myers 7fe1caf81f Update gcc .po files
* be.po, da.po, de.po, el.po, es.po, fi.po, fr.po, hr.po, id.po,
	ja.po, ka.po, nl.po, ru.po, sr.po, sv.po, tr.po, uk.po, vi.po,
	zh_CN.po, zh_TW.po: Update.
2025-08-11 20:53:40 +00:00
Paul Thomas 2aac5a6fa7 Fortran: gfortran rejects procedure binding on PDT [PR121398]
2025-08-11  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/121398
	* resolve.cc (check_pdt_args): New function.
	(check_generic_tbp_ambiguity): Use it to ensure that args to
	typebound procedures that do not have the same declared type as
	the containing derived type have 'pass1/2' set to null. This
	avoids false ambiguity errors.
	(resolve_typebound_procedure): Do not generate a wrong type
	error for typebound procedures marked as pass if they are of a
	different declared type to the containing pdt_type.

gcc/testsuite/
	PR fortran/121398
	* gfortran.dg/pdt_generic_1.f90: New test.
2025-08-11 21:34:07 +01:00
Iain Sandoe b0927c5c8c D: Adjust the code-gen for a string constant.
In this function, we are generating a string constant but do so with
a mismatch between the actual string length and the length specified
in the type.  This causes Darwin, at least, to place the string in an
unexpected section (since the parameters do not match, it is rejected
as a cstring).

Use build_string_literal() to construct a consistent null-terminated
string.

gcc/d/ChangeLog:

	* d-codegen.cc (build_filename_from_loc): Use
	build_string_literal() to build a null-terminated string for
	the filename.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-08-11 20:41:59 +01:00
Andrew Pinski 127c05f493 forwprop: Recongize a store of integral zero for optimize_aggr_zeroprop.
While looking into the gimple level after optimization of the highway code
from google, I noticed in .optimized we still have:
```
  MEM <vector(8) short int> [(short int *)&a] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  D.4398 = a;
  a ={v} {CLOBBER(eos)};
  D.4389 = D.4398;
  D.4390 = D.4389;
  D.4361 = D.4390;
  D.4195 = D.4361;
  return D.4195;
```
Note this is with SRA disabled since I noticed there is better code generation with
SRA disabled but that is a different story and I will get to that later on.

Which could be just optimized to a single store of `{}` .

The reason why the optimize_agr_copyprop does not handle the above is there was clobbers
inbetween the store in the last forwprop pass and currently don't copy after the first use.
While optimize_aggr_zeroprop does handle copying over clobbers just fine.

So this allows the recognization of the store to a to be like a memset to optimize_aggr_zeroprop
and then the result just falls through.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_aggr_zeroprop): Recognize stores
	of integer_zerop as memset of 0.

gcc/testsuite/ChangeLog:

	* gcc.dg/torture/copy-prop-aggr-zero-1.c: New test.
	* gcc.dg/torture/copy-prop-aggr-zero-2.c: New test.
	* gcc.dg/tree-ssa/copy-prop-aggregate-zero-1.c: New test.
	* gcc.dg/tree-ssa/copy-prop-aggregate-zero-2.c: New test.
	* gcc.dg/tree-ssa/copy-prop-aggregate-zero-3.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-08-11 08:39:57 -07:00
Jeff Law f82227cc36 Don't run tests requiring "B" on designs without "B"
So I resurrected our milkv pioneer over the weekend.  While we had the
tell-tale signs of PCIE switch issues, it actually appears that the NMVE drive
was failing.  I had an NVME that was going to be installed in a different
system, so I threw it into the Pioneer as a last ditch effort to get it
functional again.  Voila!  It's a happy camper (so far).

Naturally I don't like manual testing, so cobbled together a new target for my
tester.  I forgot to update one field when doing that and as a result it picked
up testsuite prior test results from the job that runs on the BPI.

So comparing test results from a BPI to the Pioneer wouldn't normally be
interesting.  We'd expect to see a whole bunch of tests disappear as the
Pioneer doesn't have all kinds of extensions that the BPI does (and that does
indeed happen).

As it turns out we have a handful of tests which need bitmanip to run, but
which don't restrict themselves to only run on appropriate hardware.  So we
might as well fix that.

Given the Pioneer/BPI take 6/24 hours to cycle through respectively I just spot
checked the testsuite changes. Pushing to the trunk.

gcc/
	* doc/sourcebuild.texi: Add riscv_b_ok and riscv_v_ok target selectors.

gcc/testsuite/
	* lib/target-supports.exp (check_effective_target_riscv_b_ok): New.
	* gcc.target/riscv/pr116085.c: Use new target selector.
	* gcc.target/riscv/pr117690.c: Use new target selector.
	* gcc.target/riscv/pr120333.c: Use new target selector.
	* gcc.target/riscv/zba-shNadd-10.c: Use new target selector.
2025-08-11 08:13:51 -06:00
Richard Biener f2a85db9ee tree-optimization/121488 - improve BIT_FIELD_REF lookup in VN
When a BIT_FIELD_REF lookup combined with a defining load RHS results
in a wrongly typed result, try looking up or inserting a VIEW_CONVERT_EXPR
to the desired type.

	PR tree-optimization/121488
	* tree-ssa-sccvn.cc (visit_nary_op): If the BIT_FIELD_REF
	result is of wrong type, try a VIEW_CONVERT_EXPR around it.

	* gcc.dg/tree-ssa/ssa-fre-108.c: New testcase.
2025-08-11 15:44:23 +02:00
Richard Biener 45a56f42b4 tree-optimization/121362 - fixup thinko in earlier change
The following fixes the index guards on the component stripping
loops, I swapped them it seems.

	PR tree-optimization/121362
	* tree-ssa-sccvn.cc (vn_reference_lookup_3): Swap index
	guards on component stripping loops.
2025-08-11 15:42:07 +02:00
Pan Li 86abacb710 RISC-V: Add testcase for scalar unsigned SAT_MUL form 2
Add run and asm check test cases for scalar unsigned
SAT_MUL form 2.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/sat/sat_arith.h: Add test helper macros.
	* gcc.target/riscv/sat/sat_u_mul-3-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-3-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-3-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-3-u8.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-3-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-3-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-3-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-3-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-11 21:10:09 +08:00
Pan Li 7d2daedde2 Widening-Mul: Support unsigned scalar SAT_MUL 2
For mul_overflow api, we will have PHI node similar as below:

  _6 = .MUL_OVERFLOW (a_4(D), b_5(D));
  _2 = IMAGPART_EXPR <_6>;
  if (_2 != 0)
    goto <bb 4>; [35.00%]
  else
    goto <bb 3>; [65.00%]

  <bb 3> [local count: 697932184]:
  _1 = REALPART_EXPR <_6>;

  <bb 4> [local count: 1073741824]:
  # _3 = PHI <18446744073709551615(2), _1(3)>

Based on the help of match.pd pattern match, the widening-mul will
try to convert it to below:

  _3 = .SAT_MUL (a_4(D), b_5(D));

gcc/ChangeLog:

	* tree-ssa-math-opts.cc (match_saturation_mul): Add new func
	to emit IFN_SAT_MUL if matched.
	(math_opts_dom_walker::after_dom_children): Try to match
	the phi node for SAT_MUL.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-11 21:10:09 +08:00
Pan Li deb0a4c804 Match: Add form 2 for unsigned SAT_MUL
This patch would like to try to match the the unsigned
SAT_MUL form 2, aka below:

  #define DEF_SAT_U_MUL_FMT_2(T)               \
  T __attribute__((noinline))                  \
  sat_u_mul_##T##_fmt_2 (T a, T b)             \
  {                                            \
    T result;                                  \
    if (__builtin_mul_overflow(a, b, &result)) \
      return -1;                               \
    else                                       \
      return result;                           \
  }

While T is uint8_t, uint16_t, uint32_t and uint64_t.

gcc/ChangeLog:

	* match.pd: Add form 2 for unsigned SAT_MUL.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-11 21:10:09 +08:00
Pan Li 3889846934 RISC-V: Refactor the vec_duplicate cost on gpr/fpr2vr-cost param
The previous cost value for vec_duplicate almost bases on the operators
like add/minus.  The rtx_cost function try to match them case by case
and find if it has vec_duplicate, then update the cost values.

It is Ok when we initially add it but looks confused/redundant as more
and more operators are involved.  As Robin's suggestion, we only care
about the sub-rtx has vec_duplicate or not, instead of take care of
it by operators.

Thus, this PR would like to refactor that and get rid of the operators
when compute the vec_duplicate cost.

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

gcc/ChangeLog:

	* config/riscv/riscv.cc (get_vector_binary_rtx_cost): Remove.
	(riscv_rtx_costs): Refactor to serach vec_duplicate on the
	sub rtx.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/binop/vadd-rv32gcv-nofm.c: Update
	asm check due to above change.
	* gcc.target/riscv/rvv/autovec/binop/vadd-rv64gcv-nofm.c: Ditto.
	* gcc.target/riscv/rvv/autovec/binop/vmul-rv32gcv-nofm.c: Ditto.
	* gcc.target/riscv/rvv/autovec/binop/vmul-rv64gcv-nofm.c: Ditto.
	* gcc.target/riscv/rvv/autovec/binop/vsub-rv32gcv-nofm.c: Ditto.
	* gcc.target/riscv/rvv/autovec/binop/vsub-rv64gcv-nofm.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_copysign-rv32gcv.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_copysign-rv64gcv.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fadd-1.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fadd-2.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fadd-3.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fadd-4.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fma_fnma-1.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fma_fnma-3.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fma_fnma-4.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fma_fnma-5.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fma_fnma-6.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmax-1.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmax-2.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmax-3.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmax-4.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmax_zvfh-1.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmax_zvfh-2.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmax_zvfh-3.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmax_zvfh-4.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmin-1.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmin-2.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmin-3.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmin-4.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmin_zvfh-1.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmin_zvfh-2.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmin_zvfh-3.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmin_zvfh-4.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fms_fnms-1.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fms_fnms-3.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fms_fnms-4.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fms_fnms-5.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fms_fnms-6.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmul-1.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmul-2.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmul-3.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmul-4.c: Ditto.
	* gcc.target/riscv/rvv/autovec/cond/cond_fmul-5.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vf-3-f64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i8.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-11 21:05:27 +08:00
Andre Vieira b29abdc333 arm: Fix operand check for __arm_{mrrc{2},mcrr{2]} intrinsics [PR 121464]
Fix the bound checking for the opc1  operand of the following intrinsics:
  __arm_mcrr
  __arm_mcrr2
  __arm_mrrc
  __arm_mrrc2

gcc/ChangeLog:

	PR target/121464
	* config/arm/arm.md (arm_<mrrc>, arm_<mcrr>): Fix operand check.

gcc/testsuite/ChangeLog:

	PR target/121464
	* gcc.target/arm/acle/mcrr.c: Update testcase.
	* gcc.target/arm/acle/mcrr2.c: Likewise.
	* gcc.target/arm/acle/mrrc.c: Likewise.
	* gcc.target/arm/acle/mrrc2.c: Likewise.
2025-08-11 09:49:18 +01:00
Richard Sandiford 3e6e885beb simplify-rtx: Distribute some non-narrowing subregs [PR121306]
In g:965564eafb721f8000013a3112f1bba8d8fae32b I'd added code
to try distributing non-widening subregs through logic ops,
in cases where that would eliminate a term of the logic op.

For "reasons", this indirectly caused combine to generate:

  (set (zero_extract:SI (reg/v:SI 101 [ a ])
	  (const_int 8 [0x8])
	  (const_int 8 [0x8]))
      (not:SI (sign_extract:SI (reg:SI 107 [ b ])
	      (const_int 8 [0x8])
	      (const_int 8 [0x8]))))

instead of:

  (set (zero_extract:SI (reg/v:SI 101 [ a ])
	  (const_int 8 [0x8])
	  (const_int 8 [0x8]))
      (subreg:SI (not:QI (subreg:QI (sign_extract:SI (reg:SI 107 [ b ])
		      (const_int 8 [0x8])
		      (const_int 8 [0x8])) 0)) 0))

for some tests that were intended to match x86's *one_cmplqi_ext<mode>_1
(see g:a58d770fa1d17ead3c38417b299cce3f19f392db).  However, other more
direct ways of generating the pattern continued to have the unsimplified
(subreg:SI (not:QI (subreg:QI (...:SI ...)))) structure, since that
structure wasn't the focus of the original patch.

This patch tries to tackle that simplification head-on.  It's another
case of distributing subregs, but this time for non-narrowing rather
than non-widening subregs.  We already do the same distribution for
word_mode:

  /* Attempt to simplify WORD_MODE SUBREGs of bitwise expressions.  */
  if (outermode == word_mode
      && (GET_CODE (op) == IOR || GET_CODE (op) == XOR || GET_CODE (op) == AND)
      && SCALAR_INT_MODE_P (innermode))
    {
      rtx op0 = simplify_subreg (outermode, XEXP (op, 0), innermode, byte);
      rtx op1 = simplify_subreg (outermode, XEXP (op, 1), innermode, byte);
      if (op0 && op1)
	return simplify_gen_binary (GET_CODE (op), outermode, op0, op1);
    }

which g:0340177d54d08b6375391ba164a878e6a596275e extended to NOT.
For word_mode, there are (reasonably) no restrictions on the inner
mode other than that it is an integer.  Doing word_mode logic ops
should be at least as efficient as subword logic ops (if the target
provides subword ops at all).  And word_mode logic ops should be
cheaper than multi-word logic ops.

But here we need the distribution for SImode rather than word_mode
(DImode).  The patch therefore extends the word_mode distributions
to non-narrowing subregs in which the two modes occupy the same
number of words.  This should hopefully be relatively conservative.
It prevents the new rule from going away from word_mode, and attempting
to convert (say) a QImode subreg of a word_mode AND into a QImode AND.
It should be suitable for both CISCy and RISCy targets, including
those that define WORD_REGISTER_OPERATIONS.

The patch also fixes some overlong lines in related code.

gcc/
	PR rtl-optimization/121306
	* simplify-rtx.cc (simplify_context::simplify_subreg): Distribute
	non-narrowing integer-to-integer subregs through logic ops,
	in a similar way to the existing word_mode handling.
2025-08-11 09:24:10 +01:00
Jakub Jelinek 1138d716c4 Fix comment typos
This patch fixes some comment typos, singe -> single and unsinged -> unsigned.

2025-08-11  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* tree-cfg.cc (find_case_label_for_value): Fix comment typo,
	singe-valued -> single-valued.
	* config/arc/arc.md: Fix comment typos, unsinged -> unsigned.
gcc/fortran/
	* gfortran.h (gfc_case): Fix comment typo, singe -> single.
gcc/testsuite/
	* g++.dg/warn/template-1.C: Fix comment typo, unsinged -> unsigned.
	* gcc.target/powerpc/builtins-2-p9-runnable.c (main): Likewise.
	* gcc.dg/graphite/id-30.c: Likewise.
2025-08-11 09:05:46 +02:00
Jakub Jelinek b7e4b5e862 c++: Fix up handling of name independent structured binding packs [PR117783]
I've realized I haven't added testsuite coverage for name independent
structured binding packs.  And the
  auto [i, ..._, j] = T {};
  auto [k, ..._, l] = T {};
case shows a problem with that.  The elements of the structured binding
pack have #i appended to their names, so for the _ case e.g. _#0, _#1
etc. (to print something useful in diagnostics, perhaps debug info later
on).  The above is valid though as long as one doesn't use _ (which is
ambiguous), but we were emitting errors on redeclaration of _#0, _#1
etc.

The following patch uses DECL_NAME (decl) = NULL_TREE; for the
name independent decl case so that the false positive redeclaration
errors aren't emitted.

2025-08-11  Jakub Jelinek  <jakub@redhat.com>

	PR c++/117783
	* decl.cc (set_sb_pack_name): For name independent decls
	just clear DECL_NAME instead of appending #i to it.

	* g++.dg/cpp26/name-independent-decl11.C: New test.
2025-08-11 09:05:45 +02:00
Jakub Jelinek 5274f490fa c++: Implement mangling for structured binding packs [PR117783]
On Wed, Aug 06, 2025 at 11:53:55AM -0700, Jason Merrill wrote:
> The Clang mangling of the underlying variable seems fine, just mentioning
> the bound names; we can't get mangling collisions between pack and non-pack
> versions of the same name.
>
> But It looks like they use .N discriminators for the individual elements,
> which is wrong because . is reserved for implementation details.  But I'd
> think it should be fine to use [<discriminator>] instead.

If you want the whole structured bindings to be mangled normally as if the
pack isn't a pack and the individual vars of the structured binding pack
mangled as multiple occurrences of the named entities, the following
patch does that.

2025-08-11  Jakub Jelinek  <jakub@redhat.com>

	PR c++/117783
	* decl.cc (cp_finish_decomp): Don't sorry on tuple static
	structured bindings with a pack, instead temporarily reset
	DECL_NAME of the individual vars in the pack to the name
	of the pack for cp_finish_decl time and force mangling.

	* g++.dg/cpp26/decomp19.C: Don't expect sorry on tuple static
	structured bindings with a pack.
	* g++.dg/cpp26/decomp26.C: New test.
2025-08-11 09:05:23 +02:00
Jakub Jelinek af31db6461 c++: Fix structured binding redeclaration error recovery [PR121442]
My C++26 P2686R4 PR117784 caused ICE on the following testcase.
While the earlier conditions guarantee decl2 is not error_mark_node,
decl can be (that is used when something erroneous has been seen earlier
and the whole structured bindings will be ignored after parsing).

So, the following patch avoids the copying of constexpr/constinit flags
if decl is error_mark_node.

2025-08-11  Jakub Jelinek  <jakub@redhat.com>

	PR c++/121442
	* parser.cc (cp_parser_decomposition_declaration): Don't copy
	DECL_DECLARED_CONST{EXPR,INIT}_P bits from decl to decl2 if
	decl is error_mark_node.

	* g++.dg/cpp1z/decomp65.C: New test.
2025-08-11 09:05:20 +02:00
GCC Administrator e5bb389603 Daily bump. 2025-08-11 00:16:52 +00:00
Matthew Fortune 767f65cf82 Add -mgrow-frame-downwards
Grow the local frame down instead of up for mips16 code size.

By growing the frame downwards we get spill slots created at the lowest
address rather than highest address in a local frame. The benefit being
that when the frame is large the spill slots can still be accessed using
a 16bit instruction whereas it is less important for large local
variables to be accessed using short instructions as they are (probably)
accessed less frequently.

This is default on for MIPS16.

gcc/
	* config/mips/mips.h (FRAME_GROWS_DOWNWARD) Allow the frame to
	grow downwards for mips16 when -mgrow-frame-downwards is set.
	* config/mips/mips.opt: Add -mgrow-frame-downwards option.
2025-08-10 11:20:30 -06:00
Andrew Pinski 14ad799ae1 varasm: Redo mergeable section support [PR121438]
We increased the switch conversion array decl alignment
for better mergeability but it turns out that we increase
the alignment on targets which don't support mergeable sections
(e.g. NVPTX). Also after the fix for PR 121394, it becomes
obvious that we can place any sized into the mergeable section
instead of increasing the alignment.
This implements that and now also fixes PR 121438 as we don't
need to increase the alignment for the mergeable decls that
were being created by the C++ front-end.

Bootstrapped and tested on x86_64-linux-gnu.

	PR middle-end/121438
	PR middle-end/121444
gcc/ChangeLog:

	* output.h (MAX_ALIGN_MERGABLE): Rename to ...
	(MAX_MERGEABLE_BITSIZE): This.
	* tree-switch-conversion.cc (switch_conversion::build_one_array): Don't
	increase the alignment.
	* varasm.cc (mergeable_string_section): Use MAX_MERGEABLE_BITSIZE
	instead of MAX_ALIGN_MERGABLE. Also replace `/ 8` with `/ BITS_PER_UNIT`.
	(mergeable_constant_section): Select the mergeable section based on
	the bitsize rather than the alignment. Make sure the align is less
	than the entity size.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-08-10 09:36:48 -07:00
Andrew Pinski 405f45aae7 varasm: Ensure each variable in mergeable section is the entity size [PR121394]
Now there are mergeable sections which have an entity size, we can place
decls (constants) that are smaller in size in these sections.
An example is an `long double` which has a size of 12 bytes on i686 and is
placed in the 16 bytes shareable section.

For an example with the following C++ code:
```
std::initializer_list<long double> a = {0.3l};
```

We place the constant array in the .rodata.cst16 section but we don't add a padding to 16 bytes.
```
        .section        .rodata.cst16,"aM",@progbits,16
        .align 16
        .type   _ZGR1a_, @object
        .size   _ZGR1a_, 12
_ZGR1a_:
        .long   -1717986918
        .long   -1717986919
        .long   16381
        .text
```
GAS has a workaround added to do the padding but other assemblers don't.
The gas workaround was added with https://sourceware.org/legacy-ml/binutils/2002-11/msg00615.html .
Now for the constant pool, GCC does emit a `.align` to padd out the size correctly.
This was done in r0-46282-gf41115930523b3.
The same padding should be done when emitting a variable contents when in a mergeable section.

This patch implements the padding and we now get an addition `.zero 4` which pads out the section.

Bootstrapped and tested on x86_64-linux-gnu.

	PR middle-end/121394
gcc/ChangeLog:

	* varasm.cc (assemble_variable_contents): Pad out
	mergeable sections if needed.
	(output_constant_pool_1): Change the padding to be explicit
	zeroing for mergeable sections.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-08-10 09:36:48 -07:00
H.J. Lu 59dbef0764 Regenerate configure files
Regenerate configure files after

commit 8a3ad190c1
Author: Ijaz, Abdul B <abdul.b.ijaz@intel.com>
Date:   Sun Aug 10 08:33:30 2025 -0600

    config: Handle dash in library name for AC_LIB_LINKAGEFLAGS_BODY

gcc/

	* configure: Regenerated.

libcpp/

	* configure: Regenerated.

libgcobol/

	* configure: Regenerated.

libstdc++-v3/

	* configure: Regenerated.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-10 08:01:02 -07:00
Ijaz, Abdul B 8a3ad190c1 config: Handle dash in library name for AC_LIB_LINKAGEFLAGS_BODY
For a library with dash in the name like yaml-cpp the AC_LIB_LINKAGEFLAGS_BODY
function generates a with_libname_type argument variable name with a dash but
this results in configure error.  Since dashes are not allowed in the variable
name.

This change handles such cases and in case input library for the
AC_LIB_HAVE_LINKFLAGS has dash then it replaces it with the underscore "_".

Example of an error for yaml-cpp library before the change using gcc config
scripts in gdb:
gdb/gdb/configure: line 22868: with_libyaml-cpp_type=auto: command not found

After having underscore for this variable name:

checking whether to use yaml-cpp... yes
checking for libyaml-cpp... yes
checking how to link with libyaml-cpp... -lyaml-cpp

config/ChangeLog:

	* lib-link.m4: Handle dash in the library name for
	AC_LIB_LINKFLAGS_BODY.
2025-08-10 08:33:30 -06:00
H.J. Lu 57ea630ecd asm-hard-reg-6.c: Adjust scan for x86 with ia32, lp64 and x32
Since i?86 and x86_64 GCC can generate codes for ia32, x32 and lp64, adjust
asm-hard-reg-6.c scan for x86 with ia32, lp64 and x32.

	PR testsuite/121205
	* gcc.dg/asm-hard-reg-6.c: Adjust scan for x86 with ia32, lp64 and
	x32.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-10 06:02:55 -07:00
H.J. Lu a4ca04c4a8 asm-hard-reg-5.c: Compile for x86 !ia32
Since i?86 and x86_64 GCC can generate codes for ia32, x32 and lp64,
compile asm-hard-reg-5.c for x86 !ia32.

	PR testsuite/121205
	* gcc.dg/asm-hard-reg-5.c: Compile for x86 !ia32.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-10 06:02:54 -07:00
H.J. Lu f6718f9ac2 asm-hard-reg-4.c: Compile for x86 with -msse2 and scan x86
Since i?86 and x86_64 GCC can generate codes for ia32, x32 and lp64,
compile asm-hard-reg-4.c for x86 with -msse2 and scan x86

	PR testsuite/121205
	* gcc.dg/asm-hard-reg-4.c: Compile with -msse2 for x86 and scan
	x86.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-10 06:02:54 -07:00
H.J. Lu d9cb1da4d7 asm-hard-reg-2.c: Compile for x86 !ia32 and scan x86
Since i?86 and x86_64 GCC can generate codes for ia32, x32 and lp64,
compile asm-hard-reg-2.c for x86 !ia32 and scan x86.

	PR testsuite/121205
	* gcc.dg/asm-hard-reg-2.c: Compile for x86 !ia32 and scan x86.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-10 06:02:54 -07:00
H.J. Lu 07ad8f1298 asm-hard-reg-1.c: Adjust scan for x86 with ia32, x32 and lp64
Since i?86 and x86_64 GCC can generate codes for ia32, x32 and lp64, adjust
asm-hard-reg-1.c scan for x86 with ia32, x32 and lp64.

	PR testsuite/121205
	* gcc.dg/asm-hard-reg-1.c: Adjust scan for x86 with ia32, x32 and
	lp64.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-10 06:02:54 -07:00
Harish Sadineni 679e24f5a7 testsuite: i386: Fix gcc.target/i386/pr90579.c when PIE is enabled [PR118885]
When gcc build with --enable-deafult-pie the following tests
were getting failed:
 FAIL: gcc.target/i386/pr90579.c scan-assembler vaddsd\tr\\+40
 FAIL: gcc.target/i386/pr90579.c scan-assembler vaddsd\tr\\+32
 FAIL: gcc.target/i386/pr90579.c scan-assembler vaddsd\tr\\+24
 FAIL: gcc.target/i386/pr90579.c scan-assembler vaddsd\tr\\+16

	PR target/118885

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr90579.c: add -fno-pie to dg-options
	to fix tests when PIE is enabled.

Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
2025-08-10 20:28:32 +08:00
Torbjörn SVENSSON 7494e197e4 testsuite: handle-multiline-outputs must allow both cc1 and cc1.exe
Prior to 14-2027-g985d6480fe5, the input text had the file extensions
pruned. In 14-2027-g985d6480fe5, due to the move of the call, the
pruning is never done. This change restores the pruning of the file
extension to allow multiline test to pass on both Windows and other
platforms like Linux.

gcc/testsuite/ChangeLog:

	* lib/multiline.exp: Added pruning of .exe.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2025-08-10 13:14:27 +02:00
GCC Administrator 53c64dc5a8 Daily bump. 2025-08-10 00:18:41 +00:00
H.J. Lu 07959996dd asm-hard-reg-2.c: Use long long on z to trigger RA error
Use long long on z to trigger

error: 'asm' operand has impossible constraints or there are not enough registers

for -m32 on asm statements like:

  __asm__ __volatile__ ("" : "=A" (z), "={rax}" (y));

	PR testsuite/121205
	* gcc.target/i386/asm-hard-reg-2.c (z): Use long long for -m32
	to trigger RA error.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-09 14:00:47 -07:00
Paul Thomas 3e3f452a93 Fortran: Correct wrong PR numbers 2025-08-09 16:00:10 +01:00
Iain Sandoe e38a8582d5 Darwin: Anchor block internal symbols must not be linker-visible.
When we are using section anchors, there's a requirement that the
sequence of the content is an unbroken block.  If we allow linker-
visible symbols in that block, ld(64) would be able to break it
into sub-sections on those symbol boundaries.

Do not allow symbols that should be visible to be anchored.
Do not make anchor block internal symbols linker-visible.

gcc/ChangeLog:

	* config/darwin.cc (darwin_encode_section_info): Do not
	make anchored symbols linker-visible.
	(darwin_use_anchors_for_symbol_p): Disallow anchoring on
	symbols that must be linker-visible (or external), even
	if the definitions are in this TU.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-08-09 15:13:30 +01:00
Iain Sandoe d950ba6e51 Darwin: Section anchors must be linker-visible.
In principle, these begin (or at least delineate) a region that
could be split by the static linker.  If the symbols are hidden
to newer linkers they produce diagnostics about the temporary
symbol generated.

gcc/ChangeLog:

	* config/darwin.h (ASM_GENERATE_INTERNAL_LABEL): New
	entry for LANCHOR.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-08-09 15:12:57 +01:00
David Malcolm 7c02f01150 diagnostics: fix build on hosts where unsigned == size_t
Looks like I broke the build with r16-3091-gac4e7455a33237 on hosts
where unsigned == size_t.

../../gcc/gcc/diagnostics/dumping.cc:98:1: error: redefinition of ‘void diagnostics::dumping::emit_field(FILE*, int, const char*, T) [with T = unsigned int; FILE = FILE]’
   98 | emit_field<unsigned> (FILE *outfile, int indent,
      | ^~~~~~~~~~~~~~~~~~~~
../../gcc/gcc/diagnostics/dumping.cc:80:1: note: ‘void diagnostics::dumping::emit_field(FILE*, int, const char*, T) [with T = unsigned int; FILE = FILE]’ previously declared here
   80 | emit_field<size_t> (FILE *outfile, int indent,
      | ^~~~~~~~~~~~~~~~~~

Sorry about this.

Should be fixed by the following patch, which avoids templates here
in favor of being explicit about types, avoids the use of "%zi" with
fprintf in various places, and fixes some other minor issues in the
dumping logic that I noticed whilst testing the patch.

gcc/ChangeLog:
	* diagnostics/context.cc (context::dump): Bulletproof against
	m_reference_printer being null.
	* diagnostics/dumping.cc (emit_field<const char *>): Replace
	with...
	(emit_string_field): ...this.
	(emit_field<char *>): Eliminate.
	(emit_field<bool>): Replace with...
	(emit_bool_field): ...this.
	(emit_field<size_t>): Replace with...
	(emit_size_t_field): ...this, and use HOST_SIZE_T_PRINT_DEC rather
	than %zi in fprintf call.
	(emit_field<int>): Replace with...
	(emit_int_field): ...this.
	(emit_field<unsigned>): Replace with...
	(emit_unsigned_field): ...this.
	* diagnostics/dumping.h (emit_field): Replace this template decl
	with...
	(emit_string_field): ...this,
	(emit_bool_field): ...this,
	(emit_size_t_field): ...this,
	(emit_int_field): ...this,
	(emit_unsigned_field): ... and this.
	(DIAGNOSTICS_DUMPING_EMIT_FIELD): Rename to...
	(DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD): ...this and update for
	above change.
	* diagnostics/file-cache.cc (file_cache_slot::dump): Replace
	emit_field calls with calls that explicitly state the type.  Fix
	type of dump of m_missing_trailing_newline to use bool.
	(file_cache_slot::dump): Use HOST_SIZE_T_PRINT_DEC rather than
	%zi in fprintf call.
	* diagnostics/html-sink.cc (html_generation_options::dump): Update
	for macro renaming.
	* diagnostics/sarif-sink.cc
	(sarif_serialization_format_json::dump): Likewise.
	(sarif_generation_options::dump): Likewise, and for function
	renaming.
	* diagnostics/text-sink.cc (text_sink::dump): Update for macro
	renaming.
	* libgdiagnostics.cc (diagnostic_manager_debug_dump_file): Use
	HOST_SIZE_T_PRINT_DEC rather than %zi in fprintf call.
	* pretty-print.cc: Include "diagnostics/dumping.h".
	(pp_formatted_chunks::dump): Use it.
	(get_url_format_as_string): New.
	(pretty_printer::dump): Use diagnostics::dumping.  Bulletproof
	against m_buffer being null.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-09 09:15:04 -04:00
Dimitar Dimitrov 8ad36426c7 testsuite: Skip class-11_a.H for default_packed targets
The g++.dg/modules/class-11_a.H test expects structs to have a padding.
Skip this test for targets which have packed structs by default.

This patch fixes the test for pru-unknown-elf from FAIL to UNSUPPORTED.
The test still passes on x86_64-linux-gnu.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/class-11_a.H: Skip test for effective
	default_packed targets.
	* g++.dg/modules/class-11_b.C: Ditto.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2025-08-09 14:17:47 +03:00
Paul Thomas 9e584501f6 Fortran: F2018 GENERIC statement is missing [PR121182]
2025-08-09  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
	PR fortran/121182
	* decl.cc (match_generic_stmt): New function based on original
	gfc_match_generic but feeding namespace rather than typebound
	generics.
	(match_typebound_generic): Renamed original gfc_match_generic.
	(gfc_match_generic): New function that selects between type
	bound generic and other generic statements and calls one of the
	above two functions as appropriate.
	* parse.cc (decode_specification_statement): Allow generic
	statements.
	(parse_spec): Accept a generic statement in a specification
	block.

gcc/testsuite/
	PR fortran/121182
	* gfortran.dg/generic_stmt_1.f90: New test.
	* gfortran.dg/generic_stmt_2.f90: New test.
	* gfortran.dg/generic_stmt_3.f90: New test.
	* gfortran.dg/generic_stmt_4.f90: New test.
2025-08-09 11:40:09 +01:00
Dimitar Dimitrov fe837dc02b testsuite: Require atomic operations for hardbool-ai.c
The test uses _Atomic int type, so add a filter to ensure the target
supports it.

This fixes a spurious test failure on pru-unknown-elf, which lacks
atomic ops.  The test still passes on x86_64-linux-gnu.

gcc/testsuite/ChangeLog:

	* gcc.dg/torture/hardbool-ai.c: Require target that supports
	atomic operations on int types.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2025-08-09 13:25:08 +03:00
Takayuki 'January June' Suwa ffc867844c xtensa: Refine constraint "T" to define_special_memory_constraint
References to literal pool entries do not need to be reloaded or converted
to "(mem (reg X))" to load via base register.

gcc/ChangeLog:

	* config/xtensa/constraints.md (T):
	Change define_memory_constraint to define_special_memory_constraint.
2025-08-08 22:01:05 -07:00
GCC Administrator b0940964f1 Daily bump. 2025-08-09 00:19:57 +00:00
Andrew Pinski 644a264d16 forwprop: Don't do copy-prop-aggregates from statements that could throw [PR120599]
In the testcase provided, currently we lose the landing pad for the exception that could
throw from the aggregate load as we remove one copy and the second statement where load
happens was not marked as throwable before so the landing pad for that internal throw is
now gone.

The fix is to ignore statements that could throw (internally or externally).

	PR tree-optimization/120599

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_agr_copyprop): Don't try to copy
	from statements that throw.

gcc/testsuite/ChangeLog:

	* g++.dg/torture/noncall-eh-1.C: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-08-08 14:30:28 -07:00
Andrew Pinski 899e7284bf forwprop: Change proping memset into memcpy into a forwprop rather than a backwalk
One thing I noticed while working on copy prop for aggregates is that we start with
a memcpy like statement and then walk backwards. This means we could have a few walks
backwards to see there was no statement for zeroing. Instead this changes the walk
backwards into a true forwprop. In the future we can expand to forwprop the zeroing
into say an function argument or something more than memcpy like statement.

This should speed up slightly the compile time performance since there will be less
memsets like statements than memcpy and there is only one walk forwards for memset like
staments instead of multiple walk backwards to find the memset.

Note this does add one extra improvement, the memcpy now does not need to have an address
as its dest argument; this could have been done before too but it was even more noticable
now because of the variable became only set so it was removed and the check was removed
as well.

There is also a fix on how ao_ref for the memset/memcpy is done, before it was just using
ao_ref_init which is wrong since it should instead of used ao_ref_init_from_ptr_and_size.
This part fixes PR 121422.

Changes since v1:
* v2: Add back limit on the walk which was missed in v1.
      Move the call to get_addr_base_and_unit_offset outside
	of the vuse loop.
* v3: Remove extra check before the call to optimize_aggr_zeroprop_1.
      Fix setting up of ao_ref for memset (PR121422).

	PR tree-optimization/118946
	PR tree-optimization/121422

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_memcpy_to_memset): Remove.
	(optimize_aggr_zeroprop_1): New function.
	(optimize_aggr_zeroprop): New function.
	(simplify_builtin_call): Don't call optimize_memcpy_to_memset
	for memcpy but call optimize_aggr_zeroprop for memset.
	(pass_forwprop::execute): Don't call optimize_memcpy_to_memset
	for aggregate copies but rather call optimize_aggr_zeroprop
	for aggregate stores.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr118946-1.c: New test.
	* gcc.dg/torture/pr121422-1.c: New test.
	* gcc.dg/torture/pr121422-2.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-08-08 14:30:28 -07:00
Andrew Pinski c7de7ddbfa forwprop: Change optimize_agr_copyprop into forward walk instead of backwards
While thinking about how to implement the rest of the copy prop and makes sure not
to introduce some compile time problems, optimize_agr_copyprop should be changed
into a forwproping rather than looking backwards.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-forwprop.cc (optimize_agr_copyprop): Change into a
	forward looking (looking at vdef's uses) instead of a back
	looking (vuse's def).

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-08-08 14:30:27 -07:00
David Malcolm d3fe5a560f diagnostics: enable nested diagnostics by default [PR116253]
In GCC 15 I added an experimental nesting view in text sinks
for hierarchical diagnostics, such as C++ template problems.

This patch enables it for text sinks by default.  The old
behavior can be restored via -fno-diagnostics-show-nesting,
which the patch also adds to -fdiagnostics-plain-output.

The patch does not yet enable it for text sinks in sarif-replay.

gcc/ChangeLog:
	PR diagnostics/116253
	* common.opt (fdiagnostics-show-nesting): New option.
	(fdiagnostics-show-nesting-locations): New option.
	(fdiagnostics-show-nesting-levels): New option.
	* common.opt.urls: Regenerate.
	* diagnostics/context.cc (context::set_show_nesting): New.
	(context::set_show_nesting_locations): New.
	(context::set_show_nesting_levels): New.
	* diagnostics/context.h (context::set_show_nesting): New decl.
	(context::set_show_nesting_locations): New decl.
	(context::set_show_nesting_levels): New decl.
	* diagnostics/html-sink.cc: Tweak comment.
	* diagnostics/output-spec.cc (text_scheme_handler::make_sink):
	Rename "experimental-nesting" to "show-nesting" and enable by
	default.  Rename "experimental-nesting-show-locations" to
	"show-nesting-locations".  Rename
	"experimental-nesting-show-levels" to "show-nesting-levels".
	* diagnostics/sink.h (sink::dyn_cast_text_sink): New.
	* diagnostics/text-sink.h (text_sink::dyn_cast_text_sink): New.
	* doc/invoke.texi: Add -fdiagnostics-show-nesting,
	-fdiagnostics-show-nesting-locations, and
	-fdiagnostics-show-nesting-levels.  Update for changes to
	output-spec.cc above.
	* lto-wrapper.cc (merge_and_complain): Ignore
	OPT_fdiagnostics_show_nesting,
	OPT_fdiagnostics_show_nesting_locations, and
	OPT_fdiagnostics_show_nesting_levels.
	(append_compiler_options): Likewise.
	(append_diag_options): Likewise.
	* opts-common.cc (decode_cmdline_options_to_array): Add
	"-fno-diagnostics-show-nesting" to -fdiagnostics-plain-output.
	* opts.cc (common_handle_option): Handle the new options.
	(gen_command_line_string): Ignore the new options.
	* toplev.cc (general_init): Call set_show_nesting,
	set_show_nesting_locations, and set_show_nesting_levels on
	global_dc.

gcc/testsuite/ChangeLog:
	PR diagnostics/116253
	* g++.dg/concepts/nested-diagnostics-1-truncated.C: Update for
	renamed keys to -fdiagnostics-set-output=text
	* g++.dg/concepts/nested-diagnostics-1.C: Likewise.
	* g++.dg/concepts/nested-diagnostics-2.C: Likewise.
	* gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c: New
	test.
	* gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c: New test.
	* gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c:
	Update for renamed keys to -fdiagnostics-set-output=text.
	* gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c:
	Likewise.
	* gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: Likewise.
	* gcc.dg/plugin/plugin.exp: Add the new tests.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-08 16:55:46 -04:00
David Malcolm ac4e7455a3 diagnostics: revamp of dumping of "diagnostics" internal state
The diagnostics subsystem has a handy dump feature, usable
during debugging via

  (gdb) call global_dc->dump ()

which prints copious amounts of information about the state
of the diagnostics subsystem to stderr.

This patch consolidates the implementation and extends it, adding
various per-sink data (generation options specific to each of text,
SARIF, and HTML).

No functional difference intended outside of the debugger.

gcc/ChangeLog:
	* Makefile.in (OBJS-libcommon): Add diagnostics/dumping.o.
	* diagnostics/buffering.cc: Include "diagnostics/dumping.h".
	(buffer::dump): Reimplement using diagnostics::dumping.
	* diagnostics/context.cc: Include "diagnostics/dumping.h".
	(context::dump): Reimplement using diagnostics::dumping.
	Use sink::dump_kind when listing the sinks.
	(sink::dump): Reimplement using diagnostics::dumping.
	(counters::dump): Likewise.
	* diagnostics/dumping.cc: New file.
	* diagnostics/dumping.h: New file.
	* diagnostics/file-cache.cc: Include "diagnostics/dumping.h".
	(file_cache::dump): Reimplement using diagnostics::dumping.
	(file_cache_slot::dump): Likewise.
	* diagnostics/html-sink.cc: Include "diagnostics/dumping.h".
	(html_generation_options::dump): New.
	(html_sink_buffer::dump): Reimplement using diagnostics::dumping.
	(html_builder::dump): New.
	(html_sink::dump): Reimplement using diagnostics::dumping.
	Add dump of the html_builder.
	(html_file_sink::dump): Replace with...
	(html_file_sink::dump_kind): ...this.
	(html_buffered_sink::dump_kind): New.
	* diagnostics/html-sink.h (html_generation_options::dump): New
	decl.
	* diagnostics/sarif-sink.cc: Include "diagnostics/dumping.h".
	(sarif_serialization_format_json::dump): New.
	(sarif_builder::dump): New.
	(sarif_sink_buffer::dump): Reimplement using diagnostics::dumping.
	(sarif_sink::dump): Likewise.  Add dump of the sarif_builder.
	(sarif_stream_sink::dump_kind): New.
	(sarif_file_sink::dump): Replace with...
	(sarif_file_sink::dump_kind): ...this.
	(get_dump_string_for_sarif_version): New.
	(sarif_generation_options::dump): New.
	(class buffered_sink): Rename to...
	(class sarif_buffered_sink): ...this.
	(sarif_buffered_sink::dump_kind): New.
	* diagnostics/sarif-sink.h (sarif_serialization_format::dump):
	New.
	(sarif_serialization_format_json::dump): New decl.
	(sarif_generation_options::dump): New decl.
	* diagnostics/sink.h (sink::dump_kind): New.
	* diagnostics/text-sink.cc: Include "diagnostics/dumping.h".
	(text_sink_buffer::dump): Reimplement using diagnostics::dumping.
	(text_sink::dump): Likewise.  Emit fields m_show_nesting,
	m_show_locations_in_nesting, and m_show_nesting_levels.
	* diagnostics/text-sink.h (text_sink::dump_kind): New.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-08 16:55:45 -04:00
David Malcolm f14fee14d4 diagnostics: minor cleanups
No functional change intended.

gcc/ChangeLog:
	* diagnostic.h (diagnostics::get_cwe_url): Move decl to
	diagnostics/metadata.h.
	(diagnostics::maybe_line_and_column): Move into
	diagnostics::text_sink.
	* diagnostics/context.cc: Update for maybe_line_and_column
	becoming a static member of text_sink.
	* diagnostics/metadata.h (diagnostics::get_cwe_url): Move decl
	here from diagnostic.h.
	* diagnostics/text-sink.cc (maybe_line_and_column): Convert to...
	(text_sink::maybe_line_and_column): ...this.
	* diagnostics/text-sink.h (text_sink::maybe_line_and_column): Move
	here from diagnostic.h.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-08 16:55:45 -04:00
David Malcolm d7d0ea918f diagnostics: update signature of some callbacks
No functional change intended.

gcc/cp/ChangeLog:
	* error.cc (cp_adjust_diagnostic_info): Convert "context" arg from
	ptr to const &.

gcc/ChangeLog:
	* diagnostics/context.cc (context::get_any_inlining_info): Convert
	"context" arg of m_set_locations_cb from ptr to const &.
	(context::report_diagnostic): Convert "context" arg of
	m_adjust_diagnostic_info from ptr to const &.
	* diagnostics/context.h (context::set_locations_callback_t):
	Likewise.
	(context::set_adjust_diagnostic_info_callback): Likewise.
	(context::m_adjust_diagnostic_info): Likewise.
	* tree-diagnostic.cc (set_inlining_locations): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-08 16:55:44 -04:00
David Malcolm 5edb251951 diagnostics: introduce struct column_options
Consolidate 3 fields in diagnostics::context and
diagnostics::column_policy into a new struct
diagnostics::column_options.

No functional change intended; reduces the number of public
fields in diagnostics::context.

gcc/c-family/ChangeLog:
	* c-indentation.cc (should_warn_for_misleading_indentation):
	Update for moving diagnostics::context::m_tabstop into
	diagnostics::column_options.
	* c-opts.cc (c_common_post_options): Likewise.

gcc/ChangeLog:
	* diagnostics/column-options.h: New file, adding struct
	diagnostics::column_options, taken from fields in
	diagnostics::context and diagnostics::column_policy.
	* diagnostics/context.cc (context::initialize): Update for moving
	fields of diagnostics::context into diagnostics::column_options.
	(column_policy::column_policy): Likewise.
	(column_policy::converted_column): Move implementation to...
	(column_options::convert_column): ...this new function.
	(context::report_diagnostic): Update for moving fields of
	diagnostics::context into diagnostics::column_options.
	(assert_location_text): Likewise.
	* diagnostics/context.h: Include "diagnostics/column-options.h".
	(class column_policy): Replace fields m_column_unit,
	m_column_origin, and m_tabstop with m_column_options.
	(context::get_column_options): New accessors.
	(context::m_column_unit): Move to struct column_options and
	replace with m_column_options.
	(context::m_column_origin): Likewise.
	(context::m_tabstop): Likewise.
	* diagnostics/sarif-sink.cc (sarif_builder::sarif_builder): Update
	for moving fields of diagnostics::context into
	diagnostics::column_options.
	* diagnostics/source-printing.cc: Likewise.
	* opts.cc (common_handle_option): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-08 16:55:43 -04:00
Robert Dubner 435e09e05c cobol: Divide-and-conquer conversion from binary to packed-decimal.
The legacy routine for converting a binary integer to a packed-decimal
representaion peeled two digits at a time from the bottom of an _int128 value.
These changes replace that routine with a divide-and-conquer algorithm that
runs about ten times faster.

libgcobol/ChangeLog:

	* libgcobol.cc (int128_to_field): Switch to the new routine.
	* stringbin.cc (packed_from_combined): Implement the new routine.
	(__gg__binary_to_packed): Likewise.
	* stringbin.h (__gg__binary_to_packed): Likewise.
2025-08-08 13:53:59 -04:00
Andrew Pinski e49bdf2c6c Update my maintainer entry email
Just updating with my new email address.

ChangeLog:

	* MAINTAINERS (Andrew Pinski): Update email address.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-08 17:37:08 +00:00
Christophe Lyon fdc560aaae aarch64: libgcc: Honor disable-werror [PR117600]
In commit r15-4417-g71c7b446b98aa5, I made -werror mandatory when
building libgcc for aarch64.

While it achieved its goal (make us fix problems unnoticed so far),
there has a been a lot of debate because it couldn't be disabled
easily.

This patch adds support for --enable-werror/--disable-werror in
libgcc, defaulting to --enable-werror for aarch64.

Tested on non-bootstrap builds on aarch64-linux-gnu (with
-Wno-prio-ctor-dtor removed in order to get an error).

libgcc/ChangeLog:

	PR libgcc/117600
	* Makefile.in (WERROR): New.
	* config/aarch64/t-aarch64: Handle WERROR.
	* configure: Regenerate.
	* configure.ac: Add support for --enable-werror.
2025-08-08 14:46:57 +00:00
Christophe Lyon ed520bfcf4 arm: Fix CMSE nonecure calls [PR 120977]
As discussed in https://gcc.gnu.org/pipermail/gcc-patches/2025-June/685733.html
the operand of the call should be a mem rather than an unspec.

This patch moves the unspec to an additional argument of the parallel
and adjusts cmse_nonsecure_call_inline_register_clear accordingly.

The scan-rtl-dump in cmse-18.c needs a fix since we no longer emit the
'unspec' part.

In addition, I noticed that since arm_v8_1m_mve_ok is always true in
the context of the test (we know we support CMSE as per cmse.exp, and
arm_v8_1m_mve_ok finds the adequate options), we actually only use the
more permissive regex.  To improve that, the patch duplicates the
test, such that cmse-18.c forces -march=armv8-m.main+fp (so FPCXP is
disabled), and cmse-19.c forces -march=armv8.1-m.main+mve (so FPCXP is
enabled).  Each test uses the appropriate scan-rtl-dump, and also
checks we are using UNSPEC_NONSECURE_MEM (we need to remove -slim for
that).  The tests enable an FPU via -march so that the test passes
whether the testing harness forces -mfloat-abi or not.

2025-07-08  Christophe Lyon  <christophe.lyon@linaro.org>

	PR target/120977
	gcc/
	* config/arm/arm.md (call): Move unspec parameter to parallel.
	(nonsecure_call_internal): Likewise.
	(call_value): Likewise.
	(nonsecure_call_value_internal): Likewise.
	* config/arm/thumb1.md (nonsecure_call_reg_thumb1_v5): Likewise.
	(nonsecure_call_value_reg_thumb1_v5): Likewise.
	* config/arm/thumb2.md (nonsecure_call_reg_thumb2_fpcxt):
	Likewise.
	(nonsecure_call_reg_thumb2): Likewise.
	(nonsecure_call_value_reg_thumb2_fpcxt): Likewise.
	(nonsecure_call_value_reg_thumb2): Likewise.
	* config/arm/arm.cc (cmse_nonsecure_call_inline_register_clear):
	Likewise.

	gcc/testsuite
	* gcc.target/arm/cmse/cmse-18.c: Check only the case when FPCXT is
	not enabled.
	* gcc.target/arm/cmse/cmse-19.c: New test.
2025-08-08 14:20:18 +00:00
Pengfei Li aa1e7dd6a3 AArch64: Fix invalid immediate offsets in SVE gather/scatter [PR121449]
This patch fixes incorrect constraints in RTL patterns for AArch64 SVE
gather/scatter with type widening/narrowing and vector-plus-immediate
addressing. The bug leads to below "immediate offset out of range"
errors during assembly, eventually causing compilation failures.

/tmp/ccsVqBp1.s: Assembler messages:
/tmp/ccsVqBp1.s:54: Error: immediate offset out of range 0 to 31 at operand 3 -- `ld1b z1.d,p0/z,[z1.d,#64]'

Current RTL patterns for such instructions incorrectly use vgw or vgd
constraints for the immediate operand, base on the vector element type
in Z registers (zN.s or zN.d). However, for gather/scatter with type
conversions, the immediate range for vector-plus-immediate addressing is
determined by the element type in memory, which differs from that in
vector registers. Using the wrong constraint can produce out-of-range
offset values that cannot be encoded in the instruction.

This patch corrects the constraints used in these patterns. A test case
that reproduces the issue is also included.

Bootstrapped and regression-tested on aarch64-linux-gnu.

gcc/ChangeLog:
	PR target/121449
	* config/aarch64/aarch64-sve.md
	(mask_gather_load<mode><v_int_container>): Use vg<Vesize>
	constraints for alternatives with immediate offset.
	(mask_scatter_store<mode><v_int_container>): Likewise.

gcc/testsuite/ChangeLog:
	PR target/121449
	* g++.target/aarch64/sve/pr121449.C: New test.
2025-08-08 13:42:25 +00:00
Richard Biener c9d0953ec8 Add subsections for vectorization and OpenMP/OpenACC target hooks
Currently they are grouped under Addressing Modes which is quite misleading.

gcc/
	* doc/tm.texi.in: Add Vectorization and OpenMP and OpenACC
	sub-sections to the list of target macros and functions.
	* doc/tm.texi: Re-generate.
2025-08-08 15:40:54 +02:00
Richard Biener 8ee642035b Remove setting of STMT_VINFO_VECTYPE on non-dataref stmts
The following removes early setting of STMT_VINFO_VECTYPE and as
side-effect early failing if we fail to compute a vector type.  The
latter is now ensured by SLP build.  The former is still temporarily
copied from the SLP tree during stmt analysis, and data reference
stmts will still have STMT_VINFO_VECTYPE given existing uses in
dependence and alignment analysis and peeling.

	* tree-vect-loop.cc (vect_determine_vectype_for_stmt_1): Remove.
	(vect_determine_vectype_for_stmt): Likewise.
	(vect_set_stmts_vectype): Likewise.
	(vect_analyze_loop_2): Do not call vect_set_stmts_vectype.
	* tree-vect-stmts.cc (vect_mark_stmts_to_be_vectorized): Detect
	irregular stmts early here.
2025-08-08 15:20:58 +02:00
Alex Coplan 80b0e4ad2f aarch64: Relax fpm_t assert to allow const_ints [PR120986]
This relaxes an overzealous assert that required the fpm_t argument to
be in DImode when expanding FP8 intrinsics.  Of course this fails to
account for modeless const_ints.

gcc/ChangeLog:

	PR target/120986
	* config/aarch64/aarch64-sve-builtins.cc
	(function_expander::expand): Relax fpm_t assert to allow
	modeless const_ints.

gcc/testsuite/ChangeLog:

	PR target/120986
	* gcc.target/aarch64/torture/pr120986-2.c: New test.
2025-08-08 12:07:26 +01:00
Alex Coplan 75eabf69d8 aarch64: Fix predication of FP8 FDOT insns [PR120986]
The predication of the SVE2 FP8 dot product insns was relying on the
architectural dependency:

FEAT_FP8DOT2 => FEAT_FP8DOT4

which was relaxed in GCC as of
r15-7480-g299a8e2dc667e795991bc439d2cad5ea5bd379e2, thus leading to
unrecognisable insn ICEs when compiling a two-way FDOT with just
+fp8dot2.  This patch introduces a new mode iterator which selectively
enables the appropriate mode(s) depending on which of the FP8DOT{2,4}
features are available, and uses it to fix the predication of the
patterns.

gcc/ChangeLog:

	PR target/120986
	* config/aarch64/aarch64-sve2.md (@aarch64_sve_dot<mode>):
	Switch mode iterator from SVE_FULL_HSF to new iterator;
	remove insn predicate as this is now taken care of by conditions
	in the mode iterator.
	(@aarch64_sve_dot_lane<mode>): Likewise.
	* config/aarch64/iterators.md (SVE_FULL_HSF_FP8_FDOT): New.

gcc/testsuite/ChangeLog:

	PR target/120986
	* gcc.target/aarch64/pr120986-1.c: New test.
2025-08-08 12:07:08 +01:00
Richard Biener 43949a5271 tree-optimization/121454 - ICE building libgo
The following avoids building BIT_FIELD_REFs of reference trees
that are unexpected by nonoverlapping_refs_since_match_p and
while being there also those declared invalid by IL verification.

	PR tree-optimization/121454
	* tree-ssa-sccvn.cc (visit_nary_op): Avoid unexpected
	BIT_FIELD_REFs.
2025-08-08 11:17:40 +02:00
Jakub Jelinek 18c32a3916 tailc: Handle other forms of finally_tmp.N conditional cleanups after musttail [PR121389]
My earlier r16-1886 PR120608 change incorrectly assumed that the
finally_tmp.N vars introduced by eh pass will be only initialized
to values 0 and 1 and there will be only EQ_EXPR/NE_EXPR comparisons
of those.

The following testcases show that is a bad assumption, the eh pass
sets finally_tmp.N vars to 0 up to some highest index depending on
hoiw many different exits there are from the finally region.
And it emits then switch (finally_tmp.N) statement for all the
different cases.  So, if it uses more than 0/1 indexes, the lowering
of the switch can turn it into a series of GIMPLE_CONDs,
  if (finally_tmp.N_M > 15)
    goto ...
  else
    goto ...

  if (finally_tmp.N_M > 7)
    goto ...
  else
    goto ...
etc. (and that also means no longer single uses).  And if unlucky,
we can see a non-lowered GIMPLE_SWITCH as well.

So, the following patch removes the assumption that it has to be 0/1
and EQ_EXPR/NE_EXPR, allows all the normal integral comparisons
and handles GIMPLE_SWITCH too.

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

	PR middle-end/121389
	* tree-tailcall.cc (find_tail_calls): For finally_tmp.N
	handle not just GIMPLE_CONDs with EQ_EXPR/NE_EXPR and only
	values 0 and 1, but arbitrary non-negative values, arbitrary
	comparisons in conditions and also GIMPLE_SWITCH next to
	GIMPLE_CONDs.

	* c-c++-common/asan/pr121389-1.c: New test.
	* c-c++-common/asan/pr121389-2.c: New test.
	* c-c++-common/asan/pr121389-3.c: New test.
	* c-c++-common/asan/pr121389-4.c: New test.
2025-08-08 09:20:51 +02:00
Richard Biener 19102eab72 Modernize vectorizable_lane_reducing
The following avoids STMT_VINFO_VECTYPE usage in
vect_is_emulated_mixed_dot_prod and makes sure to register the SLP
node when costing in vectorizable_lane_reducing.

	* tree-vect-loop.cc (vect_is_emulated_mixed_dot_prod): Get
	the SLP node rather than the stmt_info.
	(vectorizable_lane_reducing): Adjust, pass SLP node to costing.
	(vect_transform_reduction): Adjust.
2025-08-08 09:06:50 +02:00
Richard Biener f38ebe459a Pass SLP node to promotion/demotion costing
This one was forgotten.  Also constants/externals are costed explicitly
with SLP.

	* tree-vect-stmts.cc (vect_model_promotion_demotion_cost): Pass
	in SLP node and drop unused dr argument.  Use SLP node for
	costing, drop costing of constant/external operands.
	(vectorizable_conversion): Adjust.
2025-08-08 09:05:00 +02:00
Richard Biener e4678c4cf8 Fix typo in getting SLP_TREE_VECTYPE
It was applied on the stmt_info rather than the slp_node.

	* tree-vect-stmts.cc (vectorizable_store): Apply SLP_TREE_VECTYPE
	to slp_node rather than stmt_info.
2025-08-08 09:04:09 +02:00
GCC Administrator 030d9dd0f6 Daily bump. 2025-08-08 00:18:50 +00:00
Robert Dubner c684053fc0 cobol: Improve binary-to-string conversion.
COBOL often requires the conversion of binary integers to string of characters.
These changes replace a naive routine that peels decimal digits from a binary
value one digit at a time, with a divide-and-conquer algorithm that is twice as
fast even for a couple of digits, and is about eight times faster past ten
digits.

Included here are some minor fixes to the lexer and parser.

gcc/cobol/ChangeLog:

	* cbldiag.h (location_dump): Source code formatting.
	* parse.y: error_msg formatting.
	* scan.l: Remove UTF-8 character from regex pattern.
	* scan_ante.h (numstr_of): error_msg formatting.
	* show_parse.h (class ANALYZE): Suppress cppcheck error.
	* util.cc (cbl_field_t::report_invalid_initial_value):
	error_msg formatting.

libgcobol/ChangeLog:

	* Makefile.am: Include new stringbin.cc file.
	* Makefile.in: Regenerated.
	* libgcobol.cc (__gg__power_of_ten): Improve error message.
	(__gg__binary_to_string): Deleted.
	(__gg__binary_to_string_internal): Deleted.
	(int128_to_field): Use new conversion routine.
	(__gg__move): Use new conversion routine.
	* stringbin.cc: New file. Implements new conversion routine.
	* stringbin.h: New file. Likewise.
2025-08-07 16:12:32 -04:00
Patrick Palka 932b764be4 c++: extract_call_expr and C++20 rewritten ops
After r16-2519-gba5a6787374dea, we'll never express a C++20 rewritten
comparison operator as a built-in operator acting on an operator<=>
call, e.g. operator<=>(x, y) @ 0.  This is because operator<=> always
returns a class type (std::foo_ordering), so the outer operator@ will
necessarily resolve to a non-built-in operator@ for that class type
(even in the non-dependent templated case, after that commit).

So the corresponding handling in extract_call_expr is basically dead
code, except for the TRUTH_NOT_EXPR case where we can plausibly still
have !(operator==(x, y)), but it doesn't make sense to recognize just
that one special case of operator rewriting.  So let's just remove it
altogether; apparently it's no longer needed.

Also, the handling is imprecise: it recognizes expressions such as
0 < f() which never corresponded to a call in the first place.  All
the more reason to remove it.

gcc/cp/ChangeLog:

	* call.cc (extract_call_expr): Remove handling of C++20
	rewritten comparison operators.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-07 15:43:22 -04:00
Gerald Pfeifer b163ea73dc libstdc++: Switch gcc.gnu.org installation docs to https
libstdc++-v3:
	* doc/xml/manual/build_hacking.xml: Switch gcc.gnu.org installation
	docs to https.
	* doc/html/manual/appendix_porting.html: Regenerate.
2025-08-07 17:36:25 +02:00
Jakub Jelinek dff57d76ad c++: Implement C++26 P1061R10 - Structured Bindings can introduce a Pack [PR117783]
The following patch implements the C++26
P1061R10 - Structured Bindings can introduce a Pack
paper.
One thing unresolved in the patch is mangling, I've raised
https://github.com/itanium-cxx-abi/cxx-abi/issues/200
for that but no comments there yet.  One question is if it is ok
not to mention the fact that there is a structured binding pack in
the mangling of the structured bindings but more important is in case
of std::tuple* we might need to mangle individual structured binding
pack elements separately (each might need an exported name for the
var itself and perhaps its guard variable as well).  The patch just
uses the normal mangling for the whole structured bindings and emits
sorry if we need to mangle the structured binding pack elements.
The patch just marks the structured binding pack specially (considered
e.g. using some bit on it, but in the end I'm identifying it using
a made up type which causes DECL_PACK_P to be true; it is kind of
self-referential solution, because the type on the pack mentions the
DECL_DECOMPOSITION_P VAR_DECL on which the type is attached as its pack,
so it needs to be handled carefully during instantiation to avoid infinite
recursion, but it is the type that should be used if something else actually
needs to use the same type as the structured binding pack, e.g. a capture
proxy), and stores the pack elements when actually processed through
cp_finish_decomp with non-dependent initializer into a TREE_VEC used as
DECL_VALUE_EXPR of the pack; though because several spots use the
DECL_VALUE_EXPR and assume it is ARRAY_REF from which they can find out the
base variable and the index, it stores the base variable and index in the
first 2 TREE_VEC elts and has the structured binding elements only after
that.
https://eel.is/c++draft/temp.dep.expr#3.6 says the packs are type dependent
regardless of whether the initializer of the structured binding is type
dependent or not, so I hope having a dependent type on the structured
binding VAR_DECL is ok.
The paper also has an exception for sizeof... which is then not value
dependent when the structured bindings are initialized with non-dependent
initializer: https://eel.is/c++draft/temp.dep.constexpr#4
The patch special cases that in 3 spots (I've been wondering if e.g. during
parsing I couldn't just fold the sizeof... to the INTEGER_CST right away,
but guess I'd need to repeat that also during partial instantiation).

And one thing still unresolved is debug info, I've just added DECL_IGNORED_P
on the structured binding pack VAR_DECL because there were ICEs with -g
for now, hope it can be fixed incrementally but am not sure what exactly
we should emit in the debug info for that.

Speaking of which, I see
DW_TAG_GNU_template_parameter_pack
DW_TAG_GNU_formal_parameter_pack
etc. DIEs emitted regardless of DWARF version, shouldn't we try to upstream
those into DWARF 6 or check what other compilers emit for the packs?
And bet we'd need DW_TAG_GNU_structured_binding_pack as well.

2025-08-07  Jakub Jelinek  <jakub@redhat.com>

	PR c++/117783
gcc/c-family/
	* c-cppbuiltin.cc (c_cpp_builtins): Change __cpp_structured_bindings
	predefined value for C++26 from 202403L to 202411L.
gcc/cp/
	* parser.cc: Implement C++26 P1061R10 - Structured Bindings can
	introduce a Pack.
	(cp_parser_range_for): Also handle TREE_VEC as DECL_VALUE_EXPR
	instead of ARRAY_REF.
	(cp_parser_decomposition_declaration): Use sb-identifier-list instead
	of identifier-list in comments.  Parse structured bindings with
	structured binding pack.  Don't emit pedwarn about structured
	binding attributes in structured bindings inside of a condition.
	(cp_convert_omp_range_for): Also handle TREE_VEC as DECL_VALUE_EXPR
	instead of ARRAY_REF.
	* decl.cc (get_tuple_element_type): Change i argument type from
	unsigned to unsigned HOST_WIDE_INT.
	(get_tuple_decomp_init): Likewise.
	(set_sb_pack_name): New function.
	(cp_finish_decomp): Handle structured binding packs.
	* pt.cc (tsubst_pack_expansion): Handle structured binding packs
	and capture proxies for them.  Formatting fixes.
	(tsubst_decl): For structured binding packs don't tsubst TREE_TYPE
	first, instead recreate the type after r is created.
	(tsubst_omp_for_iterator): Also handle TREE_VEC as DECL_VALUE_EXPR
	instead of ARRAY_REF.
	(tsubst_expr): Handle sizeof... on non-dependent structure binding
	packs.
	(value_dependent_expression_p): Return false for sizeof... on
	non-dependent structure binding packs.
	(instantiation_dependent_r): Don't recurse on sizeof... on
	non-dependent structure binding packs.
	* constexpr.cc (potential_constant_expression_1): Also handle
	TREE_VEC on DECL_VALUE_EXPR of structure binding packs.
gcc/testsuite/
	* g++.dg/cpp26/decomp13.C: New test.
	* g++.dg/cpp26/decomp14.C: New test.
	* g++.dg/cpp26/decomp15.C: New test.
	* g++.dg/cpp26/decomp16.C: New test.
	* g++.dg/cpp26/decomp17.C: New test.
	* g++.dg/cpp26/decomp18.C: New test.
	* g++.dg/cpp26/decomp19.C: New test.
	* g++.dg/cpp26/decomp20.C: New test.
	* g++.dg/cpp26/decomp21.C: New test.
	* g++.dg/cpp26/feat-cxx26.C (__cpp_structured_bindings): Expect
	202411 rather than 202403.
2025-08-07 16:38:51 +02:00
Richard Sandiford 851cbdca88 aarch64: Mark SME functions as .variant_pcs [PR121414]
Unlike base PCS functions, __arm_streaming and __arm_streaming_compatible
functions allow/require PSTATE.SM to be 1 on entry, so they need to
be treated as STO_AARCH64_VARIANT_PCS.

Similarly, functions that share ZA or ZT0 with their callers require
ZA to be active on entry, whereas the base PCS requires ZA to be
dormant or off.  These functions too need to be marked as having
a variant PCS.

gcc/
	PR target/121414
	* config/aarch64/aarch64.cc (aarch64_is_variant_pcs): New function,
	split out from...
	(aarch64_asm_output_variant_pcs): ...here.  Handle various types
	of SME function type.

gcc/testsuite/
	PR target/121414
	* gcc.target/aarch64/sme/pr121414_1.c: New test.
2025-08-07 15:15:00 +01:00
Richard Sandiford 8e3239e3e9 Remove MODE_COMPOSITE_P test from simplify_gen_subreg [PR120718]
simplify_gen_subreg rejected subregs of literal constants if
MODE_COMPOSITE_P.  This was added by the fix for PR96648 in
g:c0f772894b6b3cd8ed5c5dd09d0c7917f51cf70f.  Jakub said:

  As for the simplify_gen_subreg change, I think it would be desirable
  to just avoid creating SUBREGs of constants on all targets and for all
  constants, if simplify_immed_subreg simplified, fine, otherwise punt,
  but as we are late in GCC11 development, the patch instead guards this
  behavior on MODE_COMPOSITE_P (outermode) - i.e. only conversions to
  powerpc{,64,64le} double double long double - and only for the cases where
  simplify_immed_subreg was called.

I'm not sure about relaxing the codes further, since subregs might
be wanted for CONST, SYMBOL_REF and LABEL_REF.  But removing the
MODE_COMPOSITE_P is needed to fix PR120718, where we get an ICE
from generating a subreg of a V2SI const_vector.

gcc/
	PR rtl-optimization/120718
	* simplify-rtx.cc (simplify_context::simplify_gen_subreg):
	Remove MODE_COMPOSITE_P condition.

gcc/testsuite/
	PR rtl-optimization/120718
	* gcc.target/aarch64/sve/acle/general/pr120718.c: New test.
2025-08-07 14:19:03 +01:00
Richard Biener 53f491ccd1 tree-optimization/121405 - missed VN with aggregate copy
The following handles value-numbering of a BIT_FIELD_REF of
a register that's defined by a load by looking up a subset
load similar to how we handle bit-and masked loads.  This
allows the testcase to be simplified by two FRE passes,
the first one will create the BIT_FIELD_REF.

	PR tree-optimization/121405
	* tree-ssa-sccvn.cc (visit_nary_op): Handle BIT_FIELD_REF
	with reference def by looking up a combination of both.

	* gcc.dg/tree-ssa/ssa-fre-107.c: New testcase.
	* gcc.target/i386/pr90579.c: Adjust.
2025-08-07 13:57:18 +02:00
Pengfei Li eee51f9a4b vect: Extend peeling and versioning for alignment to VLA modes
This patch extends the support for peeling and versioning for alignment
from VLS modes to VLA modes. The key change is allowing the DR target
alignment to be set to a non-constant poly_int. Since the value must be
a power-of-two, for variable VFs, the power-of-two check is deferred to
runtime through loop versioning. The vectorizable check for speculative
loads is also refactored in this patch to handle both constant and
variable target alignment values.

Additional changes for VLA modes include:

1) Peeling

In VLA modes, we use peeling with masking - using a partial vector in
the first iteration of the vectorized loop to ensure aligned DRs in
subsequent iterations. It was already enabled for VLS modes to avoid
scalar peeling. This patch reuses most of the existing logic and just
fixes a small issue of incorrect IV offset in VLA code path. This also
removes a power-of-two rounding when computing the number of iterations
to peel, as power-of-two VF has been guaranteed by a new runtime check.

2) Versioning

The type of the mask for runtime alignment check is updated to poly_int
to support variable VFs. After this change, both standalone versioning
and peeling with versioning are available in VLA modes. This patch also
introduces another runtime check for speculative read amount, to ensure
that all speculative loads remain within current valid memory page. We
plan to remove these runtime checks in the future by introducing capped
VF - using partial vectors to limit the actual VF value at runtime.

3) Speculative read flag

DRs whose scalar accesses are known to be in-bounds will be considered
unaligned unsupported with a variable target alignment. But in fact,
speculative reads can be naturally avoided for in-bounds DRs as long as
partial vectors are used. Therefore, this patch clears the speculative
flags and sets the "must use partial vectors" flag for these cases.

This patch is bootstrapped and regression-tested on x86_64-linux-gnu,
arm-linux-gnueabihf and aarch64-linux-gnu with bootstrap-O3.

gcc/ChangeLog:

	* tree-vect-data-refs.cc (vect_compute_data_ref_alignment):
	Allow DR target alignment to be a poly_int.
	(vect_enhance_data_refs_alignment): Support peeling and
	versioning for VLA modes.
	* tree-vect-loop-manip.cc (get_misalign_in_elems): Remove
	power-of-two rounding in peeling.
	(vect_create_cond_for_align_checks): Update alignment check
	logic for poly_int mask.
	(vect_create_cond_for_vla_spec_read): New runtime checks.
	(vect_loop_versioning): Support new runtime checks.
	* tree-vect-loop.cc (_loop_vec_info::_loop_vec_info): Add a new
	loop_vinfo field.
	(vectorizable_induction): Fix wrong IV offset issue.
	* tree-vect-stmts.cc (get_load_store_type): Refactor
	vectorizable checks for speculative loads.
	* tree-vectorizer.h (LOOP_VINFO_MAX_SPEC_READ_AMOUNT): New
	macro for new runtime checks.
	(LOOP_REQUIRES_VERSIONING_FOR_SPEC_READ): Likewise
	(LOOP_REQUIRES_VERSIONING): Update macro for new runtime checks.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/sve/peel_ind_11.c: New test.
	* gcc.target/aarch64/sve/peel_ind_11_run.c: New test.
	* gcc.target/aarch64/sve/peel_ind_12.c: New test.
	* gcc.target/aarch64/sve/peel_ind_12_run.c: New test.
	* gcc.target/aarch64/sve/peel_ind_13.c: New test.
	* gcc.target/aarch64/sve/peel_ind_13_run.c: New test.
2025-08-07 11:10:10 +00:00
Pengfei Li b7fd1fe6cf MAINTAINERS: Add myself to write after approval
ChangeLog:

	* MAINTAINERS: Add myself.
2025-08-07 10:29:05 +00:00
Tobias Burnus b399a0084b contrib/download_prerequisites: Update GMP, MPFR, MPC [PR120237]
Download newer versions of GMP, MPFR and MPC (the latest); besides the usual
bug fixes and smaller features, MPFR adds new functions for C23, some of
which are already used in GCC in the middle (fold-const-call.cc) and in
Fortran 2023 for the 'pi' trignonometric functions, if MPFR is new enough.

contrib/ChangeLog:

	PR other/120237
	* download_prerequisites: Update to download GMP 6.3.0 (before 6.2.1),
	MPFR 4.2.2 (before 4.1.0), and MPC 1.3.1 (before 1.2.1).
	* prerequisites.md5: Update hash.
	* prerequisites.sha512: Likewise.
2025-08-07 09:19:03 +02:00
Jakub Jelinek 6026a54f2f c++: Add testcase for CWG2577 [PR120778]
And here is the last part of the paper.  Contrary what the paper claims
(clearly they haven't tried -pedantic nor -pedantic-errors), I think we
already diagnose everything we should.

2025-08-07  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/120778
	* g++.dg/DRs/dr2577-1.C: New test.
	* g++.dg/DRs/dr2577-2.C: New test.
	* g++.dg/DRs/dr2577-2.h: New file.
	* g++.dg/DRs/dr2577-3.C: New test.
	* g++.dg/DRs/dr2577-3.h: New file.
2025-08-07 08:54:11 +02:00
Jakub Jelinek 3b66a2a789 c++: Add testcase for CWG2575 [PR120778]
From the paper it isn't clear what caused the decision changes, not to drop
the "the token defined is generated as a result of this replacement process or"
part and make [cpp.cond]/10 violations IFNDR rather than ill-formed (the
latter maybe so that the extension to handle e.g. !A(A) below etc. can be
accepted).

Anyway, because that case hasn't been dropped and we pedwarn on it already,
and diagnose everything else the way it should, the following patch just
adds testcase for it.

2025-08-07  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/120778
	* g++.dg/DRs/dr2575.C: New test.
2025-08-07 08:52:38 +02:00
Jakub Jelinek 2c5bd8e9fb c++: Add testcase for CWG2576 [PR120778]
Another part of the C++26 P2843R3, this time in https://eel.is/c++draft/cpp.include#7
changing former (compile time) undefined behavior to IFNDR.
With IFNDR we wouldn't have to test anything I guess, but this still adds
the cases from the 3.4 section of the paper plus related tests.
The paper wonders about implementation divergence between most compilers and
gcc in the case of glueing tokens together with <> around from multiple
macros, GCC doesn't add CPP_PADDING macros in that case (and even if it
would, it would ignore them through get_token_no_padding).
But I think this behavior is allowed by
https://eel.is/c++draft/cpp.include#7.sentence-3
and changing it now after 25+ years of such behavior might break real-world
stuff, especially making it really hard to construct the <> includes from
some name and adding < and > from some other macro around that.  We handle
  #define A <cstd def>
  #include A
like clang++ and try to open 'cstd def' file.  But not adding spaces for
all the padding means handling even stuff where nothing else can help,
while for cstd def coming from different macros one can use token pasting
to combine them together, e.g. < and following identifier or identifier
followed by . or . followed by identifier or identifier followed by > can't
be pasted together.

2025-08-07  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/120778
	* g++.dg/DRs/dr2576.C: New test.
2025-08-07 08:51:00 +02:00
Jakub Jelinek 64859dc6e2 c++, c: Introduce -Wkeyword-macro warning/pedwarn - part of C++26 P2843R3 [PR120778]
The following patch introduces a -Wkeyword-macro warning that clang has
since 2014 to implement part of C++26 P2843R3 Preprocessing is never undefined
paper.
The relevant change in the paper is moving [macro.names]/2 paragraph to
https://eel.is/c++draft/cpp.replace.general#9 :
"A translation unit shall not #define or #undef names lexically identical to
keywords, to the identifiers listed in Table 4, or to the attribute-tokens
described in [dcl.attr], except that the names likely and unlikely may be
defined as function-like macros."

Now, my understanding of the paper is that in [macro.names] and surrounding
sections the word shall bears different meaning from [cpp.replace.general],
where only the latter location implies ill-formed, diagnostic required.

The warning in clang when introduced diagnosed all #define/#undef directives
on keywords, but shortly after introduction has been changed not to
diagnose #undef at all (with "#undef a keyword is generally harmless but used
often in configuration scripts" message) and later on even the #define
part tweaked - not warn about say
  #define inline
(or const, extern, static), or
  #define keyword keyword
or
  #define keyword __keyword
or
  #define keyword __keyword__
Later on the warning has been moved to be only pedantic diagnostic unless
requested by users.  Clearly some code in the wild does e.g.
  #define private public
and similar games, or e.g. Linux kernel (sure, C) does
  #define inline __inline__ __attribute__((__always_inline__))
etc.
Now, I believe at least with the current C++26 wording such exceptions
aren't allowed (unless it is changed to IFNDR).  But given that this is just
pedantic stuff, the following patch makes the warning off by default for
C and C++ before C++26 and even for C++26 it enables it by default only
if -pedantic/-pedantic-errors (in that case it pedwarns, otherwise it
warns).  And it diagnoses both #define and #undef without exceptions.

From what I can see, all the current NODE_WARN cases are macros starting
with __ with one exception (_Pragma).  As the NODE_* flags seem to be a
limited resource, I chose to just use NODE_WARN as well and differentiate
on the node names (if they don't start with __ or _P, they are considered
to be -Wkeyword-macro registered ones, otherwise old NODE_WARN cases,
typically builtin macros or __STDC* macros).

2025-08-07  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/120778
gcc/
	* doc/invoke.texi (Wkeyword-macro): Document.
gcc/c-family/
	* c.opt (Wkeyword-macro): New option.
	* c.opt.urls: Regenerate.
	* c-common.h (cxx_dialect): Comment formatting fix.
	* c-opts.cc (c_common_post_options): Default to
	-Wkeyword-macro for C++26 if pedantic.
gcc/c/
	* c-decl.cc (c_init_decl_processing): Mark cpp nodes corresponding
	to keywords as NODE_WARN if warn_keyword_macro.
gcc/cp/
	* lex.cc (cxx_init): Mark cpp nodes corresponding
	to keywords, identifiers with special meaning and standard
	attribute identifiers as NODE_WARN if warn_keyword_macro.
gcc/testsuite/
	* gcc.dg/Wkeyword-macro-1.c: New test.
	* gcc.dg/Wkeyword-macro-2.c: New test.
	* gcc.dg/Wkeyword-macro-3.c: New test.
	* gcc.dg/Wkeyword-macro-4.c: New test.
	* gcc.dg/Wkeyword-macro-5.c: New test.
	* gcc.dg/Wkeyword-macro-6.c: New test.
	* gcc.dg/Wkeyword-macro-7.c: New test.
	* gcc.dg/Wkeyword-macro-8.c: New test.
	* gcc.dg/Wkeyword-macro-9.c: New test.
	* g++.dg/warn/Wkeyword-macro-1.C: New test.
	* g++.dg/warn/Wkeyword-macro-2.C: New test.
	* g++.dg/warn/Wkeyword-macro-3.C: New test.
	* g++.dg/warn/Wkeyword-macro-4.C: New test.
	* g++.dg/warn/Wkeyword-macro-5.C: New test.
	* g++.dg/warn/Wkeyword-macro-6.C: New test.
	* g++.dg/warn/Wkeyword-macro-7.C: New test.
	* g++.dg/warn/Wkeyword-macro-8.C: New test.
	* g++.dg/warn/Wkeyword-macro-9.C: New test.
	* g++.dg/warn/Wkeyword-macro-10.C: New test.
	* g++.dg/opt/pr82577.C: Don't #define register to nothing for
	C++17 and later.  Instead define reg macro to nothing for C++17
	and later or to register and use it instead of register.
	* g++.dg/modules/atom-preamble-3.C: Add -Wno-keyword-macro to
	dg-additional-options.
	* g++.dg/template/sfinae17.C (static_assert): Rename macro to ...
	(my_static_assert): ... this.
	(main): Use my_static_assert instead of static_assert.
libcpp/
	* include/cpplib.h (struct cpp_options): Add cpp_warn_keyword_macro.
	(enum cpp_warning_reason): Add CPP_W_KEYWORD_MACRO enumerator.
	(cpp_keyword_p): New inline function.
	* directives.cc (do_undef): Support -Wkeyword-macro diagnostics.
	* macro.cc (warn_of_redefinition): Ignore NODE_WARN flag on nodes
	registered for -Wkeyword-macro.
	(_cpp_create_definition): Support -Wkeyword-macro diagnostics.
	Formatting fixes.
2025-08-07 08:47:44 +02:00
Stefan Schulze Frielinghaus 48787c734e s390: Add _BitInt support
gcc/ChangeLog:

	* config/s390/s390.cc (print_operand): Allow arbitrary wide_int
	constants for _BitInt.
	(s390_bitint_type_info): Implement target hook
	TARGET_C_BITINT_TYPE_INFO.

libgcc/ChangeLog:

	* config/s390/libgcc-glibc.ver: Export _BitInt support
	functions.
	* config/s390/t-softfp (softfp_extras): Add fixtfbitint
	floatbitinttf.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/bitint-1.c: New test.
	* gcc.target/s390/bitint-2.c: New test.
	* gcc.target/s390/bitint-3.c: New test.
	* gcc.target/s390/bitint-4.c: New test.
2025-08-07 08:39:11 +02:00
Stefan Schulze Frielinghaus 872b002b9f s390: libgcc: Enable soft-fp
Enable soft-fp for -m64 only.

libgcc/ChangeLog:

	* config.host: Include makefiles t-softfp for -m64.
	* config/s390/sfp-exceptions.c: New file.
	* config/s390/sfp-machine.h: New file.
	* config/s390/t-softfp: New file.
2025-08-07 08:39:11 +02:00
GCC Administrator ca2169c65b Daily bump. 2025-08-07 00:20:46 +00:00
Sam James e5ba0f6cc1 testsuite: fix escaping of square brackets
This fails for me as:
+ERROR: g++.dg/cpp26/constexpr-new3.C -std=c++26: unknown dg option: 2 for "
  dg-error 40 "accessing value of 'int [2]' object through a 'long int' glvalue in a constant expression" "
otherwise.

Escape '[' and ']'.

gcc/testsuite/ChangeLog:
	* g++.dg/cpp26/constexpr-new3.C: Escape '[' and ']'.
2025-08-06 23:28:05 +01:00
Uros Bizjak 84476b4c88 i386: Fix invalid RTX mode in the unnamed rotate splitter.
The following splitter from the commit r11-5747:

(define_split
  [(set (match_operand:SWI 0 "register_operand")
        (any_rotate:SWI
          (match_operand:SWI 1 "const_int_operand")
          (subreg:QI
            (and
              (match_operand 2 "int248_register_operand")
              (match_operand 3 "const_int_operand")) 0)))]
 "(INTVAL (operands[3]) & (GET_MODE_BITSIZE (<MODE>mode) - 1))
   == GET_MODE_BITSIZE (<MODE>mode) - 1"
 [(set (match_dup 4) (match_dup 1))
  (set (match_dup 0)
       (any_rotate:SWI (match_dup 4)
                       (subreg:QI
                         (and:SI (match_dup 2) (match_dup 3)) 0)))]
 "operands[4] = gen_reg_rtx (<MODE>mode);")

matches any mode of (and ...) on input, but hard-codes (and:SI ...)
in the output.  This causes an ICE if the incoming (and ...) is DImode
rather than SImode.

Co-developed-by: Richard Sandiford <richard.sandiford@arm.com>

	PR target/96226

gcc/ChangeLog:

	* config/i386/predicates.md (and_operator): New operator.
	* config/i386/i386.md (splitter after *<rotate_insn><mode>3_mask):
	Use and_operator to match AND RTX and use its mode
	in the split pattern.
2025-08-07 00:08:46 +02:00
Alexandre Oliva 01a523943c [hardbool] implement OP=, ++ and --, volatile and atomics
hardbools didn't behave quite like bools when incremented,
decremented, or otherwise modified using their previous value, as in
+= et al.  Fix that.

Also fix some checking errors that come up when using qualified base
types.


for  gcc/c-family/ChangeLog

	* c-attribs.cc (handle_hardbool_attribute): Create distinct
	enumeration types, with structural equality.  Handle
	base type qualifiers.

for  gcc/c/ChangeLog

	* c-tree.h (C_BOOLEAN_TYPE_P): Cover hardbools as well.
	* c-typeck.cc (convert_lvalue_to_rvalue): New overload and
	wrapper.
	(build_atomic_assign, build_modify_expr): Use it.
	(build_asm_expr, handle_omp-array_sections_1): Simplify with
	it.
	(build_unary_op): Handle hardbools.

for  gcc/testsuite/ChangeLog

	* gcc.dg/torture/hardbool-ai.c: New.
	* gcc.dg/torture/hardbool-vi.c: New.
	* gcc.dg/torture/hardbool.c: Handle NO_BITFIELDS.
	(add1, preinc, postinc, sub1, predec, postdec): New.
	(main): Exercise them.
2025-08-06 16:31:50 -03:00
Gerald Pfeifer 88732d9eb8 install: Replace bzip2 by xz
In addition to gzip format our snapshots and releases have been using
xz instead of bzip2 for a while.

gcc:
	PR target/69374
	* doc/install.texi (Prerequisites): Replace bzip2 by xz.
2025-08-06 21:17:22 +02:00
Yangyu Chen 7c8f47e17d i386: Add missing PTA_POPCNT and PTA_LZCNT with PTA_ABM
This patch adds the missing PTA_POPCNT and PTA_LZCNT with the PTA_ABM
bitmask definition for the bdver1, btver1, and lujiazui architectures
in the i386 architecture configuration file.

Although these two features were not present in the original definition,
their absence does not affect the functionality of these architectures
because the POPCNT and LZCNT bits are set when ABM is enabled in the
ix86_option_override_internal function. However, including them in these
definitions improves consistency and clarity. This issue was discovered
while writing a script to extract these bitmasks from the i386.h file
referenced in [1].

Additionally, the PTA_YONGFENG bitmask appears incorrect as it includes
PTA_LZCNT while already inheriting PTA_ABM from PTA_LUJIAZUI. This seems
to be a typo and should be corrected.

[1] https://github.com/cyyself/x86-pta

gcc/ChangeLog:

	* config/i386/i386.h (PTA_BDVER1):
	Add missing PTA_POPCNT and PTA_LZCNT with PTA_ABM.
	(PTA_ZNVER1): Ditto.
	(PTA_BTVER1): Ditto.
	(PTA_LUJIAZUI): Ditto.
	(PTA_YONGFENG): Do not include extra PTA_LZCNT.

Signed-off-by: Yangyu Chen <cyy@cyyself.name>
2025-08-06 18:51:29 +02:00
Sam James 612194c064 gcc: drop placement new workaround for old bootstrap compilers
Since r15-4719-ga9ec1bc06bd3cc, we require GCC 5.4, so a workaround for
< GCC 4.3 is long-obsolete. Before that, we required GCC 4.8.3 too.

i.e. it shouldn't be possible to build GCC with such a compiler for
quite some time.

gcc/ChangeLog:
	PR libstdc++/29286
	* Makefile.in (ALIASING_FLAGS): Drop.
	* configure: Regenerate.
	* configure.ac: Drop -fno-strict-aliasing workaround for < GCC 4.3.

gcc/d/ChangeLog:

	* Make-lang.in (ALL_DFLAGS): Don't use ALIASING_FLAGS.
2025-08-06 17:46:06 +01:00
Martin Uecker d4ad085839 c2y: Evaluate size expression only in the active branch of conditional operator [PR108931]
For size expressions in the branches of the conditional operator should
be evaluated only for the active branch.  To achieve this, construct
also the size expressions for the composite type as conditional
expressions depending on the condition of the conditional operator.
The change avoids some undefined behavior removed by N3652, but the
new constraints for C2Y are not yet implemented.

	PR c/108931

gcc/c/ChangeLog:
	* c-typeck.cc (composite_type_cond): Renamed from
	composite_type with argument for condition
	(composite_type): New function.
	(composite_type_internal): Implement new logic.
	(build_conditional_expr): Pass condition.
	(common_pointer_type): Adapt.
	(pointer_diff): Adapt.
	(build_binary_op): Adapt.

gcc/testsuite/ChangeLog:
	* gcc.dg/vla-tert-1.c: New test.
2025-08-06 18:02:35 +02:00
Matthieu Longo 0d0837df69 libiberty: disable logging of list content for doubly-linked list tests
When the doubly-linked list tests were introduced, the tests were
printing the content of the list forward and backward. However, this
printing is not needed outside of debugging, and confuses people because
the output is not only composed of PASS: lines.

This patch disables the printing of the list content by default. If
one wants to re-enable it for debugging, he can set the macro DUMP_LIST
to 1.

libiberty/ChangeLog:

	* testsuite/test-doubly-linked-list.c: disable debug logging on
	stdout.
2025-08-06 15:25:22 +01:00
Richard Biener 54edbeeaac Simplify vect_supportable_dr_alignment
The following simplifies vect_supportable_dr_alignment based on
the observation that we always dereference dr_info so it cannot
be NULL, likewise we always dereference dr so that cannot be NULL
either.

	* tree-vect-data-refs.cc (vect_supportable_dr_alignment):
	Prune dead code.
2025-08-06 15:58:22 +02:00
Patrick Palka 0a7eae02de c++: mangling cNTTP object w/ implicit non-trailing zeros [PR121231]
Here the results of A::make(0, 0, 1), (0, 1, 0) and (1, 0, 0) are each
represented as a single-element CONSTRUCTOR with CONSTRUCTOR_NO_CLEARING
cleared, and when used as as a class NTTP argument we end up mangling them
all as A{1}, i.e. eliding both the implicit initial and trailing zeros.
Mangling them all the same seems clearly wrong since they're logically
different values.

It turns out the mangling also omits intermediate zeros, e.g.
A::make(1, 0, 1) is mangled as A{1, 1}, the same as A::make(1, 1, 0).

It seems we can't omit both trailing and non-trailing implicit zeros
without introducing mangling ambiguities.  This patch makes us include
non-trailing zeros in these manglings (while continuing to omit trailing
zeros).

This also manifests as a wrong-code bug where the specializations table
would conflate different specializations that are in terms of different
class NTTP arguments, since the identity of such arguments is tied to
their mangling.

	PR c++/121231
	PR c++/119688
	PR c++/94511

gcc/ChangeLog:

	* common.opt: Document additional ABI version 21 change.
	* doc/invoke.texi: Likewise.

gcc/cp/ChangeLog:

	* mangle.cc (write_expression): Write out implicit non-trailing
	zeroes of a CONSTRUCTOR when the ABI version is at least 21.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle82.C: New test.
	* g++.dg/cpp2a/nontype-class73.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-06 09:41:01 -04:00
Jason Merrill ce7a22bd26 c++: improve constexpr type mismatch diagnostic
This diagnostic failed to specify the actual type of the object being
accessed through a glvalue of an incompatible type, and could also use to
indicate where that object comes from.

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_eval_indirect_ref): Improve diagnostic.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp26/constexpr-new3.C: Tweak diagnostic.
2025-08-06 06:21:01 -07:00
Richard Biener 79e4f386ad Record gather/scatter scale and base in the SLP tree
The main gather/scatter discovery happens at SLP discovery time,
the base address and the offset scale are currently not explicitly
represented in the SLP tree.  This requires re-discovery of them
during vectorizable_store/load.  The following fixes this by
recording this info into the SLP tree.  This allows the main
vect_check_gather_scatter call to be elided from get_load_store_type
and replaced with target support checks for IFN/decl or fallback
emulated mode.

There's vect_check_gather_scatter left in the path using gather/scatter
for strided load/store.  I hope to deal with this later.

	* tree-vectorizer.h (_slp_tree::gs_scale): New.
	(_slp_tree::gs_base): Likewise.
	(SLP_TREE_GS_SCALE): Likewise.
	(SLP_TREE_GS_BASE): Likewise.
	(vect_describe_gather_scatter_call): Declare.
	* tree-vect-slp.cc (_slp_tree::_slp_tree): Initialize
	new members.
	(vect_build_slp_tree_2): Record gather/scatter base and scale.
	(vect_get_and_check_slp_defs): For gather/scatter IFNs
	describe the call to first_gs_info.
	* tree-vect-data-refs.cc (vect_gather_scatter_fn_p): Add
	mode of operation with fixed offset vector type.
	(vect_describe_gather_scatter_call): Export.
	* tree-vect-stmts.cc (get_load_store_type): Do not call
	vect_check_gather_scatter to fill gs_info, instead populate
	from the SLP tree.  Check which of, IFN, decl or fallback
	is supported and record that decision.
2025-08-06 15:17:04 +02:00
Richard Biener 3da5038ed5 Use proper alias type for gather/scatter with SLP
Both vectorizable_load and vectorizable_store compute an alias
type commoning differences between SLP lanes.  The following
makes sure to use that for gather/scatter rather than the
random one from the representative created during scalar stmt
gather/scatter analysis.

	* tree-vect-stmts.cc (vectorizable_store): Build proper
	alias + align pointer value for gather/scatter and SLP
	and use it.
	(vectorizable_load): Likewise.
2025-08-06 15:17:04 +02:00
Richard Biener 50b1959cab Allow fully masked loops with legacy gather/scatter
The following removes the redundant check on supported gather/scatter
IFN in check_load_store_for_partial_vectors which is already done
and adjusts those to check the recorded ifn, also allowing legacy
gather/scatter which all handle masking.

	* tree-vect-stmts.cc (check_load_store_for_partial_vectors):
	Remove redundant gather/scatter target support check, instead
	check the recorded ifns.  Also allow legacy gather/scatter
	with loop masking.

	* gcc.dg/vect/vect-gather-1.c: Adjust to hide N.
2025-08-06 15:17:04 +02:00
Jakub Jelinek 685527a408 bitint: Fix build [PR121413]
Sorry, my bootstrap failed last night because of this, I've fixed it
up and it bootstrapped/regtested fine overnight, but in the morning
forgot to adjust the patch before committing.

Without this there is
.../gimple-lower-bitint.cc:7678:36: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare]
 7678 |                       if (min_prec > limb_prec && abi_limb_prec > limb_prec)
      |                           ~~~~~~~~~^~~~~~~~~~~

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

	PR tree-optimization/121413
	* gimple-lower-bitint.cc (gimple_lower_bitint): Fix up last
	commit, cast limb_prec to unsigned before comparison.
2025-08-06 12:56:23 +02:00
Tejas Belagod 297a1d1cb1 AArch64: Fix test for vector length safety
The test was unsafe when tested on different vector lengths.  This patch
fixes it to work on all lengths.

gcc/testsuite/ChangeLog

	* gcc.target/aarch64/sve/acle/general/cops.c: Fix test.
2025-08-06 11:33:23 +01:00
Yang Yujie ed1ee23117 bitint: Do not optimize away conversion to _BitInt before a VCE
A _BitInt value may rely on a conversion to become properly extended.
So a conversion to _BitInt is not trivially removable even if the
types of the result and the operand have the same precision and size.

This patch fixes gcc.dg/torture/bitint-64.c at -O2 on LoongArch,
which fails because extension of the result is dropped in a
compare-and-swap loop generated for incrementing an _Atomic _BitInt,
causing an ABI violation.

	* match.pd: Preserve conversion to _BitInt before a VCE
	if the _BitInt is extended.

	* gcc.dg/torture/bitint-84.c: New test.
2025-08-06 12:04:51 +02:00
Yang Yujie 94d2bc6d08 bitint: Zero-extend the result of a signed->unsigned widening cast
A widening cast from a signed _BitInt operand to an unsigned _BitInt
type involves filling the extra limb(s) with sign extension.
On a target that wants _BitInts extended in memory, if this unsigned
type has a partial limb, the unused part of it should be zeroed.

e.g. Assuming limb_mode == E_DImode, at the end of

  void
  test (unsigned _BitInt(519) *t, _BitInt(512) x)
  {
    *t = -x;
  }

the most significant limb of *t should be masked with 0x7f.

This patch also fixes gcc.dg/torture/bitint-16.c, which aborts at -O2
when the extension on load is optimized away.

	* gimple-lower-bitint.cc (bitint_large_huge::lower_mergeable_stmt):
	Zero-extend the partial limb of any unsigned _BitInt LHS assigned
	with a widening sign-extension.

	* gcc.dg/torture/bitint-83.c: New test.
2025-08-06 12:03:39 +02:00
Yang Yujie 88f638e276 bitint: Make sure BEXTC checks extension when optimized
In BEXTC, whether a _BitInt object is properly extended is examined
by a value comparison against a copied object in a wider _BitInt
type that utilizes all of the partial limb.

Since the (implicit) conversion to the wider type may be optimized
away now and cause the result of the comparison to always be true,
we need to cast the copied object down to the original type to
force a extension, so that it can serve as our reference.

	* gcc.dg/bitintext.h (BEXTC1): Define.  Convert the copied
	object back to the original type before comparison.
	(BEXTC): Use BEXTC1 for both the signed and the unsigned case.
2025-08-06 12:02:44 +02:00
Yang Yujie a76a032354 bitint: Avoid extending ABI-extended large/huge _BitInts on load
This patch also make casts of ABI-extended large/huge _BitInts
behave the same as the small/middle case, i.e. no-op for casts
to a higher precision _BitInt with the same number of limbs /
extension for casts that turns a full top limb into a partial limb.
This conveniently helps keep some code with implementation-specific
extension semantics (e.g. BEXTC from gcc.dg/bitintext.h) the same
for _BitInts of any precision.

	* gimple-lower-bitint.cc (bitint_large_huge::limb_access):
	Add a parameter abi_load_p.  If set, load a limb directly
	in its actual precision without casting from m_limb_type.
	(struct bitint_large_huge): Same.
	(bitint_large_huge::handle_load): Use.
2025-08-06 12:01:33 +02:00
Jakub Jelinek a107b01da4 libgcc: Remove useless forward declaration [PR121397]
aarch64 for some strange reason unconditionally enables -Werror for libgcc
building and this particular file for some strange reason contains
a useless static forward declaration of a function only defined in the
  #if defined __sun__ && defined __svr4__
block and not otherwise (with __attribute__((constructor))).
And we warn (with -Werror error) in the non-__sun__/__svr4__ case because
it declares a static function that is never defined.
The forward declaration makes no sense to me, for static functions
forward declarations shouldn't be needed even for -Wstrict-prototypes,
and AFAIK we don't warn on static __attribute__((constructor)) void foo (void) {}
being unused.  And the function isn't used before being defined.

So, the following patch just removes the forward declaration.

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

	PR libgcc/121397
	* enable-execute-stack-mprotect.c (check_enabling): Remove useless
	forward declaration.
2025-08-06 11:30:48 +02:00
Jakub Jelinek 70aff5112e bitint: Fix up INTEGER_CST PHI handling [PR121413]
The following testcase is miscompiled on aarch64-linux.
The problem is in the optimization to shorten large constants
in PHI arguments.
In a couple of places during bitint lowering we compute
minimal precision of constant and if it is significantly
smaller than the precision of the type, store smaller constant
in memory and extend it at runtime (zero or all ones).
Now, in most places that works fine, we handle the stored number
of limbs by loading them from memory and then the rest is
extended.  In the PHI INTEGER_CST argument handling we do
it differently, we don't form there any loops (because we
insert stmt sequences on the edges).
The problem is that we copy the whole _BitInt variable from
memory to the PHI VAR_DECL + initialize the rest to = {} or
memset to -1.  It has
min_prec = CEIL (min_prec, limb_prec) * limb_prec;
precision, so e.g. on x86_64 there is no padding and it works
just fine.  But on aarch64 which has abi_limb_mode TImode
and limb_mode DImode it doesn't in some cases.
In the testcase the constant has 408 bits min precision, rounded up
to limb_prec (64) is 448, i.e. 7 limbs.  But aarch64 with TImode
abi_limb_mode will actually allocate 8 limbs and the most significant
limb is solely padding.  As we want to extend the constant with all
ones, copying the padding (from memory, so 0s) will result in
64 0 bits where 1 bits were needed.

The following patch fixes it by detecting this case and setting
min_prec to a multiple of abi limb precision so that it has
no padding.

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

	PR tree-optimization/121413
	* gimple-lower-bitint.cc (abi_limb_prec): New variable
	(bitint_precision_kind): Initialize it.
	(gimple_lower_bitint): Clear it at the start.  For
	min_prec > limb_prec descreased precision vars for
	INTEGER_CST PHI arguments ensure min_prec is either
	prec or multiple of abi_limb_prec.

	* gcc.dg/torture/bitint-85.c: New test.
2025-08-06 11:30:08 +02:00
Jakub Jelinek d175a6b119 bitint: Fix up handling of uninitialized mul/div/float cast operands [PR121127]
handle_operand_addr (used for the cases where we use libgcc APIs, so
multiplication, division, modulo, casts of _BitInt to float/dfp) when it
sees default definition of an SSA_NAME which is not PARM_DECL (i.e.
uninitialized one) just allocates single uninitialized limb, there is no
need to waste more memory on it, it can just tell libgcc that it has
64-bit precision, not say 1024 bit etc.
Unfortunately, doing this runs into some asserts when we have a narrowing
cast of the uninitialized SSA_NAME (but still large/huge _BitInt).

The following patch fixes that by using a magic value in *prec_stored
for the uninitialized cases (0) and just don't do any *prec tweaks for
narrowing casts from that.  precs still needs to be maintained as before,
that one is used for big endian adjustment.

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

	PR tree-optimization/121127
	* gimple-lower-bitint.cc (bitint_large_huge::handle_operand_addr): For
	uninitialized SSA_NAME, set *prec_stored to 0 rather than *prec.
	Handle that case in narrowing casts.  If prec_stored is non-NULL,
	set *prec_stored to prec_stored_val.

	* gcc.dg/bitint-125.c: New test.
2025-08-06 11:29:32 +02:00
Jakub Jelinek 4f2cd5a888 gengtype: Include system.h earlier in gengtype-lex.cc [PR121386]
OpenBSD headers apparently instead of just
 #define SIZE_MAX something
do
 #ifndef SIZE_MAX
 #define SIZE_MAX something
 #endif
This causes problem with gengtype-lex.cc, where the flex generated
code has
 #ifndef SIZE_MAX
 #define SIZE_MAX (~(size_t)0)
 #endif
and system.h is included only after that and since my changes for
host size_t *printf printing SIZE_MAX is used in preprocessor
expressions,
 #if SIZE_MAX <= UINT_MAX
etc.
In the preprocessor, identifiers are replaced with 0 and so
it is (~(0)0) <= 0xffffffffU
or so and thus invalid.

Now, normally we want to include system.h early, ideally immediately
after config.h or bconfig.h, but in gengtype-lex.cc case we have
 #ifdef HOST_GENERATOR_FILE
 #include "config.h"
 #define GENERATOR_FILE 1
 #else
 #include "bconfig.h"
 #endif

 // flex generated start of file, including
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <inttypes.h>
 #ifndef SIZE_MAX
 #define SIZE_MAX (~(size_t)0)
 #endif

 // start of gengtype-lex.l %{} section
 #ifdef HOST_GENERATOR_FILE
 #include "config.h"
 #define GENERATOR_FILE 1
 #else
 #include "bconfig.h"
 #endif
 #include "system.h"

 #define malloc xmalloc
 #define realloc xrealloc

 #include "gengtype.h"

As I'm not sure what flex we require for building gcc (%top{} which COBOL FE
*.l uses is only in flex from 2003-04-01), the patch keeps using the %top{}
done by hand in Makefile.in, but includes system.h in the top part, with
FLEX_SCANNER temporarily defined (I'm undefining it afterwards because
flex generated code defines it again and I don't want to guarantee it is
defined to the same value) so that malloc/realloc poisoning doesn't happen
and #define malloc xmalloc and realloc xrealloc are done in system.h.
Note, system.h already includes all the 5 headers flex generated code
includes.

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

	PR bootstrap/121386
	* Makefile.in (gengtype-lex.cc): Append #define FLEX_SCANNER,
	#include "system.h" and #undef FLEX_SCANNER to the prepended lines.
	* gengtype-lex.l: Remove inclusion of config.h or bconfig.h, system.h
	and definition of malloc/realloc from %{} section.
2025-08-06 11:27:00 +02:00
Yuao Ma de2eaf63ad fortran: cleanup duplicate tests for c_f_pointer_shape_driver
tests_2_driver and tests_4_driver are identical, and tests_4_driver is not used
at all. This patch clean this up, and format the driver with gcc style.

gcc/testsuite/ChangeLog:

	* gfortran.dg/c_f_pointer_shape_tests_2.f03: Use the new driver.
	* gfortran.dg/c_f_pointer_shape_tests_4.f03: Ditto.
	* gfortran.dg/c_f_pointer_shape_tests_4_driver.c: Removed.
	* gfortran.dg/c_f_pointer_shape_tests_2_driver.c: Renamed to ...
	* gfortran.dg/c_f_pointer_shape_tests_driver.c: ... this; format
	with gcc style.
2025-08-06 11:15:34 +02:00
Jakub Jelinek 43472f2cc0 c++: Add test for vt/ff in line comments
P2843R3 dropped the
"If there is a form-feed or a vertical-tab character in such a comment, only
whitespace characters shall appear between it and the new-line that terminates
the comment; no diagnostic is required."
sentence from [lex.comment].  AFAIK we've never diagnosed nor checked for
that and C23 doesn't have anything like that, so the following testcase
merely tests that we don't diagnose anything on it.

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

	PR preprocessor/120778
	* c-c++-common/cpp/comment-ff-1.c: New test.
	* c-c++-common/cpp/comment-vtab-1.c: New test.
2025-08-06 10:44:09 +02:00
Martin Uecker f1ab4c518c c: Fix ICE on invalid code involving bit fields [PR121217]
Under some error condition we can end up with NULL_TREEs for
the type of bitfields, which can cause an ICE when testing for
type compatibility.  Add the missing check.

	PR c/121217

gcc/c/ChangeLog:
	* c-typeck.cc (tagged_types_tu_compatible_p): Add check.

gcc/testsuite/ChangeLog:
	* gcc.dg/pr121217.c: New test.
2025-08-06 09:09:48 +02:00
Kito Cheng 0c517ddf9b RISC-V: Read extension data from riscv-ext*.def for arch-canonicalize
Previously, arch-canonicalize used hardcoded data to handle IMPLIED_EXT.
But this data often got out of sync with the actual C++ implementation.
Earlier, we introduced riscv-ext.def to keep track of all extension info
and generate docs. Now, arch-canonicalize also uses this same data to handle
extension implication rules directly.

One limitation is that conditional implication rules still need to be written
manually. Luckily, there aren't many of them for now, so it's still manageable.
I really wanted to avoid writing a C++ + Python binding or trying to parse C++
logic in Python...

This version also adds a `--selftest` option to run some unit tests.

gcc/ChangeLog:

	* config/riscv/arch-canonicalize: Read extension data from
	riscv-ext*.def and adding unittest.
2025-08-06 14:52:50 +08:00
Kito Cheng aa1ae5284d RISC-V: Support -march=unset
This patch introduces a new `-march=unset` option for RISC-V GCC that
allows users to explicitly ignore previous `-march` options and derive
the architecture string from the `-mcpu` option instead.

This feature is particularly useful for build systems and toolchain
configurations where you want to ensure the architecture is always
derived from the CPU specification rather than relying on potentially
conflicting `-march` options.

gcc/ChangeLog:

	* common/config/riscv/riscv-common.cc (riscv_expand_arch):
	Ignore `unset`.
	* config/riscv/riscv.h (OPTION_DEFAULT_SPECS): Handle
	`-march=unset`.
	(ARCH_UNSET_CLEANUP_SPECS): New.
	(DRIVER_SELF_SPECS): Handle -march=unset.
	* doc/invoke.texi (RISC-V Options): Update documentation for
	`-march=unset`.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/arch-unset-1.c: New test.
	* gcc.target/riscv/arch-unset-2.c: New test.
	* gcc.target/riscv/arch-unset-3.c: New test.
	* gcc.target/riscv/arch-unset-4.c: New test.
	* gcc.target/riscv/arch-unset-5.c: New test.
2025-08-06 14:50:28 +08:00
Kwok Cheung Yeung 87262627fd openmp: Add support for iterators in 'target update' clauses (C/C++)
This adds support for iterators in 'to' and 'from' clauses in the
'target update' OpenMP directive.

gcc/c/

	* c-parser.cc (c_parser_omp_clause_from_to): Parse 'iterator' modifier.
	* c-typeck.cc (c_finish_omp_clauses): Finish iterators for to/from
	clauses.

gcc/cp/

	* parser.cc (cp_parser_omp_clause_from_to): Parse 'iterator' modifier.
	* semantics.cc (finish_omp_clauses): Finish iterators for to/from
	clauses.

gcc/

	* gimplify.cc (remove_unused_omp_iterator_vars): Display unused
	variable warning for 'to' and 'from' clauses.
	(gimplify_scan_omp_clauses): Add argument for iterator loop sequence.
	Gimplify the clause decl and size into the iterator loop if iterators
	are used.
	(gimplify_omp_workshare): Add argument for iterator loops sequence
	in call to gimplify_scan_omp_clauses.
	(gimplify_omp_target_update): Call remove_unused_omp_iterator_vars and
	build_omp_iterators_loops.  Add loop sequence as argument when calling
	gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses and building
	the Gimple statement.
	* tree-pretty-print.cc (dump_omp_clause): Call dump_omp_iterators
	for to/from clauses with iterators.
	* tree.cc (omp_clause_num_ops): Add extra operand for OMP_CLAUSE_FROM
	and OMP_CLAUSE_TO.
	* tree.h (OMP_CLAUSE_HAS_ITERATORS): Add check for OMP_CLAUSE_TO and
	OMP_CLAUSE_FROM.
	(OMP_CLAUSE_ITERATORS): Likewise.

gcc/testsuite/

	* c-c++-common/gomp/target-update-iterators-1.c: New.
	* c-c++-common/gomp/target-update-iterators-2.c: New.
	* c-c++-common/gomp/target-update-iterators-3.c: New.

libgomp/

	* target.c (gomp_update): Call gomp_merge_iterator_maps.  Free
	allocated variables.
	* testsuite/libgomp.c-c++-common/target-update-iterators-1.c: New.
	* testsuite/libgomp.c-c++-common/target-update-iterators-2.c: New.
	* testsuite/libgomp.c-c++-common/target-update-iterators-3.c: New.
2025-08-06 01:37:10 +01:00
Kwok Cheung YeungandAndrew Stubbs 8b8b0eada6 openmp: Add support for iterators in map clauses (C/C++)
This adds preliminary support for iterators in map clauses within OpenMP
'target' constructs (which includes constructs such as 'target enter data').

Iterators with non-constant loop bounds are not currently supported.

gcc/c/

	* c-parser.cc (c_parser_omp_variable_list): Use location of the
	map expression as the clause location.
	(c_parser_omp_clause_map): Parse 'iterator' modifier.
	* c-typeck.cc (c_finish_omp_clauses): Finish iterators.  Apply
	iterators to generated clauses.

gcc/cp/

	* parser.cc (cp_parser_omp_clause_map): Parse 'iterator' modifier.
	* semantics.cc (finish_omp_clauses): Finish iterators.  Apply
	iterators to generated clauses.

gcc/

	* gimple-pretty-print.cc (dump_gimple_omp_target): Print expanded
	iterator loops.
	* gimple.cc (gimple_build_omp_target): Add argument for iterator
	loops sequence.  Initialize iterator loops field.
	* gimple.def (GIMPLE_OMP_TARGET): Set GSS symbol to GSS_OMP_TARGET.
	* gimple.h (gomp_target): Set GSS symbol to GSS_OMP_TARGET.  Add extra
	field for iterator loops.
	(gimple_build_omp_target): Add argument for iterator loops sequence.
	(gimple_omp_target_iterator_loops): New.
	(gimple_omp_target_iterator_loops_ptr): New.
	(gimple_omp_target_set_iterator_loops): New.
	* gimplify.cc (find_var_decl): New.
	(copy_omp_iterator): New.
	(remap_omp_iterator_var_1): New.
	(remap_omp_iterator_var): New.
	(remove_unused_omp_iterator_vars): New.
	(struct iterator_loop_info_t): New type.
	(iterator_loop_info_map_t): New type.
	(build_omp_iterators_loops): New.
	(enter_omp_iterator_loop_context_1): New.
	(enter_omp_iterator_loop_context): New.
	(enter_omp_iterator_loop_context): New.
	(exit_omp_iterator_loop_context): New.
	(gimplify_adjust_omp_clauses): Add argument for iterator loop
	sequence.  Gimplify the clause decl and size into the iterator
	loop if iterators are used.
	(gimplify_omp_workshare): Call remove_unused_omp_iterator_vars and
	build_omp_iterators_loops for OpenMP target expressions.  Add
	loop sequence as argument when calling gimplify_adjust_omp_clauses
	and building the Gimple statement.
	* gimplify.h (enter_omp_iterator_loop_context): New prototype.
	(exit_omp_iterator_loop_context): New prototype.
	* gsstruct.def (GSS_OMP_TARGET): New.
	* omp-low.cc (lower_omp_map_iterator_expr): New.
	(lower_omp_map_iterator_size): New.
	(finish_omp_map_iterators): New.
	(lower_omp_target): Add sorry if iterators used with deep mapping.
	Call lower_omp_map_iterator_expr before assigning to sender ref.
	Call lower_omp_map_iterator_size before setting the size.  Insert
	iterator loop sequence before the statements for the target clause.
	* tree-nested.cc (convert_nonlocal_reference_stmt): Walk the iterator
	loop sequence of OpenMP target statements.
	(convert_local_reference_stmt): Likewise.
	(convert_tramp_reference_stmt): Likewise.
	* tree-pretty-print.cc (dump_omp_iterators): Dump extra iterator
	information if present.
	(dump_omp_clause): Call dump_omp_iterators for iterators in map
	clauses.
	* tree.cc (omp_clause_num_ops): Add operand for OMP_CLAUSE_MAP.
	(walk_tree_1): Do not walk last operand of OMP_CLAUSE_MAP.
	* tree.h (OMP_CLAUSE_HAS_ITERATORS): New.
	(OMP_CLAUSE_ITERATORS): New.

gcc/testsuite/

	* c-c++-common/gomp/map-6.c (foo): Amend expected error message.
	* c-c++-common/gomp/target-map-iterators-1.c: New.
	* c-c++-common/gomp/target-map-iterators-2.c: New.
	* c-c++-common/gomp/target-map-iterators-3.c: New.
	* c-c++-common/gomp/target-map-iterators-4.c: New.

libgomp/

	* target.c (kind_to_name): New.
	(gomp_merge_iterator_maps): New.
	(gomp_map_vars_internal): Call gomp_merge_iterator_maps.  Copy
	address of only the first iteration to target vars.  Free allocated
	variables.
	* testsuite/libgomp.c-c++-common/target-map-iterators-1.c: New.
	* testsuite/libgomp.c-c++-common/target-map-iterators-2.c: New.
	* testsuite/libgomp.c-c++-common/target-map-iterators-3.c: New.

Co-authored-by: Andrew Stubbs <ams@baylibre.com>
2025-08-06 01:37:10 +01:00
Jerry DeLisle 3d496ed9a5 Fortran: Fix runtime bogus diagnostic with ';'
PR libfortran/121234

libgfortran/ChangeLog:

	* io/list_read.c (read_character): Add checks to bypass eating
	semicolons when reading strings with decimal mode 'point'
	(list_formatted_read_scalar): Likewise.

gcc/testsuite/ChangeLog:

	* gfortran.dg/pr121234.f90: New test.
2025-08-05 17:34:47 -07:00
GCC Administrator 10b8ba6f0f Daily bump. 2025-08-06 00:21:26 +00:00
Jason Merrill bc42128330 c++: clobber object on placement new [PR121068]
My r16-2432 patch addressed the original testcase involving an array of
scalars, but not this additional testcase involving an array of classes.

This patch addresses the issue more thoroughly, by having placement new
first clobber the new object, and improving cxx_eval_store_expression to
implement initial clobbers as well.

My earlier attempt to do this clobbered the array as a whole, which broke
construct_at after the resolution of LWG3436 due to trying to create a
multidimensional array over the top of a single-dimensional array.  To
side-step that issue, this patch instead clobbers the individual elements of
an array, taking advantage of the earlier change to let that activate the
array member of a union.

	PR c++/121068

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_eval_store_expression): Handle clobbers.
	(potential_constant_expression_1): Handle clobbers more.
	* decl.cc (build_clobber_this): Use INIT_EXPR for initial clobber.
	* init.cc (build_new_1): Clobber on placement new.
	(build_vec_init): Don't clean up after clobber.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp26/constexpr-new5.C: New test.
2025-08-05 15:16:50 -07:00
Mikael Morin 14ca064696 fortran: Remove overwrite of polymorphic associate variable offset
The array descriptor returned by gfc_conv_expr_descriptor should be
usable as is.  No need to overwrite the offset.

gcc/fortran/ChangeLog:

	* trans-stmt.cc (trans_associate_var): Remove overwrite of
	the polymorphic associate variable's array descriptor offset.
2025-08-05 22:35:07 +02:00
Mikael Morin 0634bd5697 fortran: Remove array bound update after constructor expansion
The array constructor expansion extends the size of the array
dynamically, and sets the upper bound appropriately every time it
does.  There is no need to do it again at the end of expansion.

gcc/fortran/ChangeLog:

	* trans-array.cc (trans_array_constructor): Remove the update of
	the array descriptor upper bound after array constructor
	expansion.
2025-08-05 22:35:07 +02:00
Mikael Morin 8d2e44fa19 fortran: Remove premature initialization of a function result's span
Setting just the span in an otherwise uninitialized array descriptor to
pass to a function that will use the descriptor for its result (thus do
the initialization) doesn't seem to be useful.

gcc/fortran/ChangeLog:

	* trans-array.cc (gfc_conv_expr_descriptor): Remove
	isolated initialization of the span field before passing to
	the function that will do the initialization.
2025-08-05 22:35:07 +02:00
Mikael Morin acb0fa251a fortran: Remove default initialization of local pointers's span
A pointer has no default initialization; it is invalid to use it before
it is associated to a target.  We can just as well leave its span field
uninitialized, and wait for the first pointer association to define a
span value.  The value of zero was an invalid span value anyway.

gcc/fortran/ChangeLog:

	* trans-decl.cc (gfc_trans_deferred_vars): Don't default
	initialize the span of local pointer arrays.
2025-08-05 22:35:07 +02:00
Mikael Morin 914b7296eb fortran: Remove redundant initialisation of associate variable span
In the initialization of associate variable array descriptors, remove
an overwrite of the span field.  The descriptor that is returned by
gfc_conv_expr_descriptor should already be usable without it.

The range of cases where the code was in effect is not completely
clear.  The span overwrite looks redundant, and the conditional guarding
it seems to make it dead.  However, the conditions governing
gfc_conv_expr_descriptor, gfc_get_array_span and trans_associate_var
make it difficult to track what is possible and what isn't.  Trying to
investigate the case where the target is an array subreference wrapped
in parenthesis, I encountered a wrong-code issue, PR121384.  Let's
remove all this and see what happens.

gcc/fortran/ChangeLog:

	* trans-stmt.cc (trans_associate_var): Remove overwrite of the
	span field of the associate variable's array descriptor.
2025-08-05 22:35:07 +02:00
Mikael Morin d358dc6f33 fortran: Remove span overwrite with pointer assignments
Remove an overwrite of the array descriptor span field when pointer-
assigning from a polymorphic function result to a non-polymorphic
pointer.  That overwrite doesn't make sense because the span is
determined by the memory layout of the array; we can't change it
without also changing the data pointer.

gcc/fortran/ChangeLog:

	* trans-expr.cc (gfc_trans_pointer_assignment): Remove overwrite
	of the span after assignment of the array descriptor in the
	polymorphic function result to non-polymorphic pointer case.

gcc/testsuite/ChangeLog:

	* gfortran.dg/pointer_assign_16.f90: New test.
2025-08-05 22:35:06 +02:00
H.J. Lu 40da83e4a7 x86: Get the widest vector mode from STORE_MAX_PIECES for memset
commit 050b1708ea
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Jun 19 05:03:48 2025 +0800

    x86: Get the widest vector mode from MOVE_MAX

gets the widest vector mode from MOVE_MAX.  But for memset, it should
use STORE_MAX_PIECES.

gcc/

	PR target/121410
	* config/i386/i386-expand.cc (ix86_expand_set_or_cpymem): Use
	STORE_MAX_PIECES to get the widest vector mode in vector loop
	for memset.

gcc/testsuite/

	PR target/121410
	* gcc.target/i386/pr121410.c: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-05 12:12:12 -07:00
Georg-Johann Lay 59236d56ee AVR: Allow combination of sign_extend with ashift.
gcc/
	* config/avr/avr.cc (avr_rtx_costs_1) [SIGN_EXTEND]: Adjust cost.
	* config/avr/avr.md (*sext.ashift<QIPSI:mode><HISI:mode>2): New
	insn and a cc split.
2025-08-05 17:53:58 +02:00
Mikael Morin c9da74d5ad fortran: Remove unused field use_offset
The gfc_se::use_offset field is set in a few places, but is nowhere
used.  Remove it.

gcc/fortran/ChangeLog:

	* trans.h (gfc_se): Remove field use_offset.
	* trans-expr.cc (gfc_conv_intrinsic_to_class): Remove use_offset
	initialization.
	(gfc_conv_procedure_call): Likewise.
	* trans-stmt.cc (trans_associate_var): Likewise.
2025-08-05 17:11:03 +02:00
Ryutaro Okada 04effdd023 gccrs: Add read-only check on HIR
gcc/rust/ChangeLog:

	* Make-lang.in (rust-readonly-check2.cc):
	Add read-only check on HIR
	* checks/errors/rust-readonly-check2.cc (ReadonlyChecker):
	Add read-only check on HIR
	* checks/errors/rust-readonly-check2.h (ReadonlyChecker):
	Add read-only check on HIR

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05 16:37:04 +02:00
Ryutaro Okada ea83b1a9d4 gccrs: Call base class's accept_vis method
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk):
	Call base class's  accept_vis method

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05 16:37:04 +02:00
Ryutaro Okada 73def70e34 gccrs: Add check before calling get_trait_ref()
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk):
	Add check before calling  `get_trait_ref()`

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05 16:37:03 +02:00
Owen Avery 9938133aca gccrs: Remove undefined behavior with static_cast
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-helpers.cc
	(try_extract_string_literal_from_fragment): Perform static_cast
	to AST::LiteralExpr only after it's verified that an AST::Expr
	is a literal.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:37:03 +02:00
Owen Avery 95c619976f gccrs: Recognize rustc_args_required_const attribute
This doesn't handle rustc_args_required_const, but it does allow us to
recognize it as a valid attribute.

gcc/rust/ChangeLog:

	* util/rust-attribute-values.h
	(Attributes::RUSTC_ARGS_REQUIRED_CONST): New constexpr variable.
	* util/rust-attributes.cc (__definitions): New entry for
	RUSTC_ARGS_REQUIRED_CONST.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:37:03 +02:00
Owen Avery d2140c7d5c gccrs: Make AttributeParser rely more on Parser
gcc/rust/ChangeLog:

	* ast/rust-ast.cc (AttributeParser::parse_meta_item_inner):
	Handle removal of AttributeParser-specific functions.
	(AttributeParser::parse_path_meta_item): Likewise.
	(AttributeParser::parse_meta_item_seq): Likewise.
	(AttributeParser::parse_meta_item_lit): Likewise.
	(AttributeParser::parse_literal): Remove function.
	(AttributeParser::parse_simple_path): Likewise.
	(AttributeParser::parse_simple_path_segment): Likewise.
	(AttributeParser::peek_token): Likewise.
	(AttributeParser::skip_token): Likewise.
	* ast/rust-macro.h (AttributeParser::parse_simple_path):
	Likewise.
	(AttributeParser::parse_simple_path_segment): Likewise.
	(AttributeParser::parse_literal): Likewise.
	(AttributeParser::peek_token): Likewise.
	(AttributeParser::skip_token): Likewise.
	* parse/rust-parse.h (Parser): Make AttributeParser a friend
	class.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:37:03 +02:00
Arthur Cohen eb54ab61fd gccrs: offset_of: Compile the offset properly
gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): Add proper handling
	of the node.
	* rust-backend.h (lookup_field): Declare it.
	* rust-gcc.cc (lookup_field): Add forked implementation from gcc/c/.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/offset_of1.rs: New test.
2025-08-05 16:37:03 +02:00
Owen Avery 2f054b8db9 gccrs: Catch parse failure in parse_path_meta_item
gcc/rust/ChangeLog:

	* ast/rust-ast.cc (AttributeParser::parse_path_meta_item): Catch
	parse_expr returning nullptr and remove defunct comment.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:37:03 +02:00
Owen Avery 715849d86f gccrs: Avoid including rust-parse-impl.h in rust-parse.h
This should reduce incremental compile times when modifying
rust-parse-impl.h and not rust-parse.h.

gcc/rust/ChangeLog:

	* Make-lang.in (GRS_OBJS): Add entries.
	* parse/rust-parse-impl.h: Adjust header comment.
	(Parser::parse_lifetime_params_objs): Fix bug and add comment.
	(Parser::unexpected_token): Likewise.
	* parse/rust-parse.h: Remove inclusion of "rust-parse-impl.h".
	* parse/rust-parse-impl-lexer.cc: New file.
	* parse/rust-parse-impl-macro.cc: New file.
	* parse/rust-parse-impl-proc-macro.cc: New file.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:37:03 +02:00
Ryutaro Okada 759e57acac gccrs: Fix object copying issue causing pointer inconsistency
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit):
	Fix object copying issue causing pointer inconsistency

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05 16:37:03 +02:00
Pierre-Emmanuel Patry 35d2c4cfe3 gccrs: Parse expression instead of literal in attributes
gcc/rust/ChangeLog:

	* ast/rust-ast.cc (AttributeParser::parse_path_meta_item): Parse
	expression instead of literal. Update variant name.
	(MetaItemPathLit::to_attribute): Remove function.
	(AttributeParser::parse_path_meta_item): Update name.
	(MetaItemPathLit::check_cfg_predicate): Likewise.
	(MetaItemPathExpr::check_cfg_predicate): Likewise.
	(MetaItemPathLit::accept_vis): Likewise.
	(MetaItemPathExpr::accept_vis): Likewise.
	* ast/rust-ast-collector.h: Update prototype and adapt code to new
	expression.
	* ast/rust-ast-collector.cc: Update code to expr.
	* ast/rust-ast-full-decls.h (class MetaItemPathLit): Likewise.
	(class MetaItemPathExpr): Likewise.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
	* ast/rust-ast-visitor.h: Likewise.
	* ast/rust-ast.h (class MetaItemPathLit): Rename class from here...
	(class MetaItemPathExpr): ... to here.
	* ast/rust-expr.h (class MetaItemPathLit): Rename class from here...
	(class MetaItemPathExpr): ...to here.
	* expand/rust-derive.h: Update class name.
	* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
	* expand/rust-expand-visitor.h: Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
	* hir/rust-ast-lower-base.h: Likewise.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
	* resolve/rust-ast-resolve-base.h: Likewise.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Likewise.
	* resolve/rust-early-name-resolver.h: Likewise.
	* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
	* util/rust-attributes.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:37:03 +02:00
Philip Herron 3d42d4fdf1 gccrs: Add test case showing method resolution with const-generics
gcc/testsuite/ChangeLog:

	* rust/execute/torture/const-generics-1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:02 +02:00
Philip Herron 90070a8f45 gccrs: remove old debug
gcc/rust/ChangeLog:

	* typecheck/rust-tyty-subst.cc (SubstitutionRef::infer_substitions): remove debug

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:02 +02:00
Philip Herron 4d9a4c08a6 gccrs: improve debug logging for unify site
gcc/rust/ChangeLog:

	* typecheck/rust-type-util.cc (unify_site_and): improve debug

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:02 +02:00
Philip Herron f52be4bf85 gccrs: Remove more calls to the old TyTy::BaseType::can_eq interface
This old can_eq interface was an old method to try and check if types can match up
by taking into account generics but its not maintained properly and we already have
a new wrapper Resolver::types_compatable (type, type, locus, emit_errors) which
just calls unify_site_and infer with commit false. There are only a few places left
to update.

One minor downside is that i need to remove const in some places because the unify
interface is non const. Ideally we would want to avoid writing a seperate const unify
anyway so i think this is not ideal but fine for us.

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: remove useless assertion
	* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsafe_ptr): refactor
	(TypeCoercionRules::coerce_borrowed_pointer): remove FIXME this is fine
	* typecheck/rust-hir-inherent-impl-overlap.h: use types_compatable
	* typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): remove const
	(PathProbeType::Probe): likewise
	(PathProbeImplTrait::PathProbeImplTrait): likewise
	(PathProbeImplTrait::Probe): likewise
	* typecheck/rust-hir-path-probe.h: likewise
	* typecheck/rust-hir-type-check-base.cc (walk_types_to_constrain): likewise
	* typecheck/rust-hir-type-check-base.h: likewise
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): use types_compatable
	* typecheck/rust-hir-type-check.h: remove const
	* typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_associated_impl_mapping):
	likewise
	(TypeCheckContext::lookup_associated_impl_mapping_for_self): remove can_Eq
	* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::is_equal): likewise
	* typecheck/rust-tyty-subst.cc (SubstitutionArg::get_tyty): remove const version
	* typecheck/rust-tyty-subst.h: likewise
	* typecheck/rust-tyty.cc (BaseType::get_root): likewise
	* typecheck/rust-tyty.h: likewise

gcc/testsuite/ChangeLog:

	* rust/compile/generics8.rs: extra error message

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:02 +02:00
Philip Herron 481cb635fe gccrs: Ensure we track the const generic substitution on the param mappings
gcc/rust/ChangeLog:

	* typecheck/rust-tyty-subst.cc: track the const generic
	* typecheck/rust-tyty.cc (ConstType::is_equal): finish the is_equal

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:02 +02:00
Pierre-Emmanuel Patry 2605542301 gccrs: Initialize boolean flag correctly
Flag was left uninitialized within default constructor.

gcc/rust/ChangeLog:

	* hir/rust-hir-dump.cc (Dump::Dump): Initialize flag.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:37:02 +02:00
Pierre-Emmanuel Patry d44420f3f3 gccrs: Initialize boolean flag correctly
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::ASTLoweringPattern):
	flag was not initialized in the constructor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:37:02 +02:00
Pierre-Emmanuel Patry 6aeedda541 gccrs: Prevent used after move on self param
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): Remove
	use after move.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:37:02 +02:00
Pierre-Emmanuel Patry 73a77277d1 gccrs: Retrieve token stream before vector move
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-helpers.cc: Remove use after move.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:37:02 +02:00
Yap Zhi Heng a22c11304c gccrs: Add rest pattern support for AST::SlicePattern
The main change can be found in ast/rust-pattern.h, which introduces 2 item types for
AST::SlicePattern - one without rest pattern (SlicePatternItemsNoRest) & the other with
it (SlicePatternItemsHasRest). This led to a number of cascading changes as seen in the
changelog.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc: Add support for the 2 new classes.
	* ast/rust-ast-collector.h: Header file update for above.
	* ast/rust-ast-full-decls.h: Add forward decls for the 2 new classes.
	* ast/rust-ast-visitor.cc: Add visit support for the 2 new classes.
	* ast/rust-ast-visitor.h: Header file update for above.
	* ast/rust-pattern.cc: Implementation of certain methods for the 2 new classes.
	* ast/rust-pattern.h: Define the 2 new classes. Update SlicePattern to be able to hold
	2 kinds of items - SlicePatternItemsNoRest or SlicePatternItemsRest.
	* expand/rust-cfg-strip.cc: Add support for the 2 new classes.
	* expand/rust-cfg-strip.h: Header file update for above.
	* expand/rust-derive.h: Add visits for the 2 new classes.
	* hir/rust-ast-lower-base.cc: Add visits for the 2 new classes.
	* hir/rust-ast-lower-base.h: Header file update for above.
	* hir/rust-ast-lower-pattern.cc: Update lowering of SlicePattern to support
	SlicePatternItemsNoRest.
	* parse/rust-parse-impl.h (parse_slice_pattern()): Add support for parsing DOT_DOT into
	respective SlicePatternItems.
	* resolve/rust-ast-resolve-base.cc: Add visits for the 2 new classes.
	* resolve/rust-ast-resolve-base.h: Header file update for above.
	* resolve/rust-ast-resolve-pattern.cc: Update SlicePattern resolution to support new
	classes.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:37:01 +02:00
Philip Herron ad8393db6b gccrs: Fix ICE when extra const arguments supplied
The substitution code was not taking into account the const generic
arguments for checking the max bounds of total available parameters.

Fixes Rust-GCC#3546

gcc/rust/ChangeLog:

	* typecheck/rust-tyty-subst.cc: fix check for total arguments

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:01 +02:00
Philip Herron 13d6c61231 gccrs: Support const generic inference variables
We already support const infer so this just creates a fresh tyty::infer_var
for the const element type and then a ConstKind::Infer type for the const
type wrapper and the existing plumbing handles this.

Fixes Rust-GCC#3885

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): create infer variable

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:01 +02:00
Philip Herron 3e141c0cd3 gccrs: Fix ICE during hir dump of deferred anon constant
gcc/rust/ChangeLog:

	* hir/rust-hir-dump.cc (Dump::visit): check for expression
	* hir/tree/rust-hir.cc (AnonConst::as_string): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:01 +02:00
Philip Herron 7f0fed0bfe gccrs: Fix ICE for ast dump of deferred anon const
gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): check for value

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:01 +02:00
Philip Herron 1e7a193af1 gccrs: fix clang formatting
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): formatting
	* typecheck/rust-tyty-variance-analysis-private.h: likewise
	* typecheck/rust-tyty.cc (VariantDef::clone): likewise
	(VariantDef::monomorphized_clone): likewise
	* typecheck/rust-tyty.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:01 +02:00
Philip Herron 91126cb80e gccrs: Add initial support for const generics
In order to support const generics we map the declarations to a ConstType this
means we reuse all our existing type coercion, unification code and generic
substitutions code to support this with minimal impact.

This patch adds support for:

1. Default const generics
2. Infer const generics
3. ADTType suport
4. unconstrained checks
5. ensure types of the const generic and default
6. validation if passing a const argument to a type argument

Lots of test cases now work and new ones added. More work is needed to support this
on functions and method resolution of impls like Foo<1> vs Foo<2> once thats in we
can look to support some of the const generic array impls next.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc: useful debug
	* backend/rust-compile-stmt.cc (CompileStmt::visit): likewise
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): fold the capacity into ConstType
	* hir/tree/rust-hir-generic-param.h: make const
	* hir/tree/rust-hir-path.h: take into account const arguments now
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): needs const
	* typecheck/rust-hir-type-check-base.h: add error handling for const supported locations
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): const type the arrays
	* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): update
	(TypeCheckImplItem::visit): likewise
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): likewise
	(TypeCheckItem::resolve_impl_block_substitutions): likewise
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): wrap up const type
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
	(TypeResolveGenericParam::visit): likewise
	(TypeResolveGenericParam::apply_trait_bounds): remove HIR::Generic from Param
	* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): cleanup
	* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::SubstitutionParamMapping):
	handle const generics
	(SubstitutionParamMapping::get_type_representation): likewise
	(SubstitutionParamMapping::param_has_default_ty): likewise
	(SubstitutionParamMapping::get_default_ty): likewise
	(SubstitutionRef::infer_substitions): likewise
	* typecheck/rust-tyty-subst.h: likewise
	* typecheck/rust-tyty-util.cc (TyVar::get_implicit_const_infer_var): new helper
	* typecheck/rust-tyty-util.h (class ConstType): likewise
	* typecheck/rust-tyty.cc (BaseType::is_concrete): check for array const concrete
	(ArrayType::as_string): update to const
	(ArrayType::handle_substitions): likewise
	(ParamType::ParamType): likewise
	(ParamType::get_generic_param): likewise
	(ParamType::clone): likewise
	(ConstType::ConstType): likewise
	(ConstType::set_value): likewise
	(ConstType::clone): likewise
	(ConstType::get_generic_param): likewise
	(generate_tree_str): new helper to pretty print gimple
	(ConstType::get_name): uses the generate_tree_str
	(ConstType::handle_substitions): handle const infer's
	* typecheck/rust-tyty.h (RUST_TYTY): likewise
	* typecheck/rust-unify.cc (UnifyRules::expect_array): likewise
	(UnifyRules::expect_const): likewise

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_3.rs: this works now
	* rust/compile/const_generics_5.rs: likewise
	* rust/compile/const_generics_8.rs: move the failure to another test case
	* rust/compile/const_generics_10.rs: New test.
	* rust/compile/const_generics_11.rs: New test.
	* rust/compile/const_generics_12.rs: New test.
	* rust/compile/const_generics_13.rs: New test.
	* rust/compile/const_generics_14.rs: New test.
	* rust/compile/const_generics_15.rs: New test.
	* rust/compile/const_generics_16.rs: New test.
	* rust/compile/const_generics_9.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:01 +02:00
Philip Herron 0390f9422a gccrs: Add ConstType boiler plate to handle const generics
This patch is all about just putting in the boiler plate for the new
BaseGeneric TyTy::ConstType. Nothing is really change but just the
nessecary cogs added to the machine.

gcc/rust/ChangeLog:

	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): error_mark_node for const types
	* backend/rust-compile-type.h: boilerplate
	* checks/errors/borrowck/rust-bir-fact-collector.h: likewise
	* checks/errors/borrowck/rust-bir-place.h: likewise
	* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
	likewise
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): likewise
	* typecheck/rust-substitution-mapper.h: likewise
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_marker_builtins): likewise
	* typecheck/rust-tyty-call.h: likewise
	* typecheck/rust-tyty-cmp.h (class ConstCmp): likewise
	* typecheck/rust-tyty-variance-analysis-private.h: likewise
	* typecheck/rust-tyty-visitor.h: likewise
	* typecheck/rust-tyty.cc (TypeKindFormat::to_string): likewise
	(BaseType::is_unit): likewise
	(BaseType::has_substitutions_defined): likewise
	(BaseType::needs_generic_substitutions): likewise
	(ConstType::ConstType): likewise
	(ConstType::accept_vis): likewise
	(ConstType::as_string): likewise
	(ConstType::can_eq): likewise
	(ConstType::clone): likewise
	(ConstType::get_symbol): likewise
	(ConstType::get_generic_param): likewise
	(ConstType::can_resolve): likewise
	(ConstType::resolve): likewise
	(ConstType::get_name): likewise
	(ConstType::is_equal): likewise
	(ConstType::handle_substitions): likewise
	* typecheck/rust-tyty.h (enum TypeKind): new tyty_kind
	(class ConstType): new type
	* typecheck/rust-unify.cc (UnifyRules::go): Handle a const type unify
	(UnifyRules::expect_inference_variable): likewise
	(UnifyRules::expect_adt): likewise
	(UnifyRules::expect_str): likewise
	(UnifyRules::expect_reference): likewise
	(UnifyRules::expect_pointer): likewise
	(UnifyRules::expect_param): likewise
	(UnifyRules::expect_array): likewise
	(UnifyRules::expect_slice): likewise
	(UnifyRules::expect_fndef): likewise
	(UnifyRules::expect_fnptr): likewise
	(UnifyRules::expect_tuple): likewise
	(UnifyRules::expect_bool): likewise
	(UnifyRules::expect_char): likewise
	(UnifyRules::expect_int): likewise
	(UnifyRules::expect_uint): likewise
	(UnifyRules::expect_float): likewise
	(UnifyRules::expect_isize): likewise
	(UnifyRules::expect_usize): likewise
	(UnifyRules::expect_placeholder): likewise
	(UnifyRules::expect_projection): likewise
	(UnifyRules::expect_dyn): likewise
	(UnifyRules::expect_closure): likewise
	(UnifyRules::expect_const): likewise
	* typecheck/rust-unify.h: new expect_const_type handler

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:01 +02:00
Philip Herron 839e42810a gccrs: Refactor the ParamType to a BaseGeneric base-type
In order to support const generics we need to abstract away some of the specific
ParamType to a BaseGeneric type so we can easily reuse our existing substitution
bits for const generics which will mean creating a TyTy::ConstType to wrap up
the gcc tree but also represent a const inference and the const decl.

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (sizeof_handler): refactor types
	(op_with_overflow_inner): likewise
	(uninit_handler): likewise
	(move_val_init_handler): likewise
	* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): likewise
	* typecheck/rust-hir-trait-resolve.cc: likewise
	* typecheck/rust-hir-type-check-base.cc: likewise
	* typecheck/rust-hir-type-check-item.cc: likewise
	* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::is_equal): likewise
	* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_param_ty): likewise
	(SubstitutionArg::get_param_mapping): likewise
	(SubstitutionRef::prepare_higher_ranked_bounds): likewise
	(SubstitutionRef::monomorphize): likewise
	* typecheck/rust-tyty-subst.h (class BaseGeneric): new generic base
	* typecheck/rust-tyty.cc (VariantDef::clone): likewise
	(VariantDef::monomorphized_clone): refactor
	(ADTType::is_equal): likewise
	(FnType::is_equal): likewise
	(ParamType::ParamType): likewise
	* typecheck/rust-tyty.h (class ParamType): likewise
	(class BaseGeneric): new base class impl

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:01 +02:00
Philip Herron eca63cc3b4 gccrs: simplify the is_eq on ADTType
We dont need to do this resolve we can just let the ParamType's sort this
out.

gcc/rust/ChangeLog:

	* typecheck/rust-tyty.cc (ADTType::is_equal): let param::is_eq do this
	(FnType::is_equal): remove whitespace

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:00 +02:00
Philip Herron 4dc145a415 gccrs: Refactor substitution param mapping to be more abstract
This is an initial patch required to refactor our generics code to be
simpler and more abstract so we return the HIR::GenericParam in ParamMappings
instead of assuming its a TypeParam so we can slowly introduce ConstGenericParam
into this same flow.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-base.cc: check for type param
	* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::SubstitutionParamMapping):
	return HIR::GenericParam base class
	(SubstitutionParamMapping::get_generic_param): likewise
	(SubstitutionParamMapping::get_type_representation): new helper
	(SubstitutionParamMapping::param_has_default_ty): check for param type
	(SubstitutionParamMapping::get_default_ty): likewise
	* typecheck/rust-tyty-subst.h: get the locus from the subst HIR::GenericParam now
	* typecheck/rust-tyty-variance-analysis.cc (GenericTyPerCrateCtx::debug_print_solutions):
	likwise
	(GenericTyVisitorCtx::process_type): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:00 +02:00
Philip Herron 948e4a6345 gccrs: Fix ICE during const eval of const capacity
We assert that struct expressions during code-gen must be of TyTy::ADTType
but we can simply just check for this and return error_mark_node to make
this safe.

Fixes Rust-GCC#3960

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): check for ADTType instead of assert

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:37:00 +02:00
Ryutaro Okada 2dcfb123df gccrs: Remove warning for unused self parameter
gcc/testsuite/ChangeLog:

	* rust/compile/auto_traits2.rs:
	emove warning for unused `self` parameter
	* rust/compile/derive-debug1.rs:
	emove warning for unused `self` parameter
	* rust/compile/derive_macro1.rs:
	Remove warning for unused `self` parameter
	* rust/compile/format_args_basic_expansion.rs:
	Remove warning for unused `self` parameter
	* rust/compile/format_args_extra_comma.rs:
	Remove warning for unused `self` parameter
	* rust/compile/issue-2043.rs:
	Remove warning for unused `self` parameter
	* rust/compile/issue-2166.rs:
	Remove warning for unused `self` parameter
	* rust/compile/issue-2238.rs:
	Remove warning for unused `self` parameter
	* rust/compile/issue-2907.rs:
	Remove warning for unused `self` parameter
	* rust/compile/min_specialization1.rs:
	Remove warning for unused `self` parameter
	* rust/compile/name_resolution2.rs:
	Remove warning for unused `self` parameter
	* rust/compile/name_resolution4.rs:
	Remove warning for unused `self` parameter
	* rust/compile/torture/generics29.rs:
	Remove warning for unused `self` parameter
	* rust/compile/torture/generics30.rs:
	Remove warning for unused `self` parameter
	* rust/compile/torture/traits3.rs:
	Remove warning for unused `self` parameter
	* rust/compile/torture/traits7.rs:
	Remove warning for unused `self` parameter
	* rust/execute/torture/impl_trait3.rs:
	Remove warning for unused `self` parameter
	* rust/execute/torture/min_specialization2.rs:
	Remove warning for unused `self` parameter
	* rust/execute/torture/trait10.rs:
	Remove warning for unused `self` parameter
	* rust/execute/torture/trait11.rs:
	Remove warning for unused `self` parameter
	* rust/execute/torture/trait12.rs:
	Remove warning for unused `self` parameter
	* rust/execute/torture/trait13.rs:
	Remove warning for unused `self` parameter
	* rust/execute/torture/trait9.rs:
	Remove warning for unused `self` parameter

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05 16:37:00 +02:00
Ryutaro Okada f77ca6f8ce gccrs: Do not warn about unused self parameter
gcc/rust/ChangeLog:

	* checks/lints/rust-lint-unused-var.cc (check_decl):
	Do not warn about unused `self` parameter.

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05 16:37:00 +02:00
Arthur Cohen bdb6f7f2c0 gccrs: desugar: Add base for desugaring while-let loops
gcc/rust/ChangeLog:

	* Make-lang.in:
	* ast/rust-expression-yeast.cc (ExpressionYeast::dispatch_loops): Call DesugarWhileLet.
	* ast/rust-desugar-while-let.cc: New file.
	* ast/rust-desugar-while-let.h: New file.

gcc/testsuite/ChangeLog:

	* rust/compile/while_let1.rs: New test.
2025-08-05 16:37:00 +02:00
Pierre-Emmanuel Patry e705ad248a gccrs: Fix AttrInputMacro operator= overloading.
gcc/rust/ChangeLog:

	* ast/rust-ast.cc (AttrInputMacro::operator=): Add return type.
	* ast/rust-expr.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:37:00 +02:00
Arthur Cohen ba7f3c6d3b gccrs: desugar: Cleanup for-loop desugar implementation.
gcc/rust/ChangeLog:

	* ast/rust-desugar-for-loops.cc: Remove functions implemented in AST::Builder.
	* ast/rust-desugar-for-loops.h: Likewise.
2025-08-05 16:37:00 +02:00
Arthur Cohen 78b6af888e gccrs: lower: Add assertions for desugared nodes
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-base.cc: Add rust_unreachable() when lowering desugared exprs.
	* hir/rust-ast-lower-base.h: Mention this.
	* hir/rust-ast-lower-block.h: Remove existing definitions.
	* hir/rust-ast-lower-expr.cc: Likewise.
	* hir/rust-ast-lower-expr.h: Likewise.
	* hir/rust-ast-lower.cc: Likewise.
2025-08-05 16:37:00 +02:00
Arthur Cohen eba7cd78dd gccrs: desugar: Add assertions for try-blocks and question-mark
gcc/rust/ChangeLog:

	* ast/rust-desugar-question-mark.cc (DesugarQuestionMark::go): Add assertion for the
	expr's type.
	* ast/rust-desugar-try-block.cc (DesugarTryBlock::go): Likewise.
2025-08-05 16:36:59 +02:00
Arthur Cohen 40754a08e5 gccrs: desugar: Add for-loop desugar to ExpressionYeast
gcc/rust/ChangeLog:

	* ast/rust-desugar-for-loops.h: Adapt API and remove visitor.
	* ast/rust-desugar-for-loops.cc: Likewise.
	* ast/rust-expression-yeast.cc: Call DesugarForLoop.
	* ast/rust-expression-yeast.h: Declare dispatch_loops function.
	* rust-session-manager.cc (Session::expansion): Do not call for-loop desugar.
2025-08-05 16:36:59 +02:00
Arthur Cohen 8a3cac82cc gccrs: hir: Add OffsetOf node
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-expr.h (class OffsetOf): New.
	* hir/tree/rust-hir-expr.cc: Define its methods.
	* hir/tree/rust-hir-expr-abstract.h: Add ExprType::OffsetOf.
	* hir/tree/rust-hir-full-decls.h (class OffsetOf): Declare it.
	* backend/rust-compile-block.h: Add handling for OffsetOf.
	* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
	* backend/rust-compile-expr.h: Likewise.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.h (RUST_BIR_BUILDER_EXPR_H): Likewise.
	* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise.
	* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
	* checks/errors/borrowck/rust-function-collector.h: Likewise.
	* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
	* checks/errors/privacy/rust-privacy-reporter.h (RUST_PRIVACY_REPORTER_H): Likewise.
	* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
	* checks/errors/rust-const-checker.h: Likewise.
	* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Likewise.
	* checks/errors/rust-hir-pattern-analysis.h: Likewise.
	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
	* checks/errors/rust-unsafe-checker.h: Likewise.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
	* hir/rust-hir-dump.cc (Dump::visit): Likewise.
	* hir/rust-hir-dump.h: Likewise.
	* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise.
	* hir/tree/rust-hir-visitor.h: Likewise.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
	* typecheck/rust-hir-type-check-expr.h (RUST_HIR_TYPE_CHECK_EXPR): Likewise.

gcc/testsuite/ChangeLog:

	* rust/compile/offset_of2.rs: New test.
2025-08-05 16:36:59 +02:00
Arthur Cohen 689f2ffb73 gccrs: expand: Add parser for offset_of!() and builtin resolution.
gcc/rust/ChangeLog:

	* Make-lang.in: Compile the offset_of handler.
	* lang.opt: Add -frust-assume-builtin-offset-of option.
	* ast/rust-ast.h: Add has_str() for const_TokenPtr.
	* expand/rust-macro-builtins.cc: Map offset_of as builtin.
	* expand/rust-macro-builtins.h: Declare it.
	* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Add hack for calling builtin
	offset_of!().
	* resolve/rust-early-name-resolver-2.0.cc (Early::visit):  Likewise.
	* expand/rust-macro-builtins-offset-of.cc: New file.

gcc/testsuite/ChangeLog:

	* rust/compile/offset_of1.rs: New test.
2025-08-05 16:36:59 +02:00
Arthur Cohen aa57360f26 gccrs: ast: Add OffsetOf node
gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add OffsetOf expression kind.
	* ast/rust-builtin-ast-nodes.h (class OffsetOf): Add node.
	* ast/rust-ast.cc: Define it.
	* ast/rust-ast-collector.cc: Add visitor for OffsetOf.
	* ast/rust-ast-collector.h: Likewise.
	* ast/rust-ast-visitor.cc: Likewise.
	* ast/rust-ast-visitor.h: Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
	* hir/rust-ast-lower-base.h: Likewise.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
	* hir/rust-ast-lower-expr.h: Likewise.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
	* resolve/rust-ast-resolve-base.h: Likewise.
	* resolve/rust-early-name-resolver-2.0.cc: Likewise.
	* expand/rust-derive.h:
2025-08-05 16:36:59 +02:00
Pierre-Emmanuel Patry 7f520ecc0c gccrs: Error message field member was not properly updated
gcc/rust/ChangeLog:

	* rust-diagnostics.h (struct Error): Add disambiguation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:59 +02:00
Pierre-Emmanuel Patry 697025acf8 gccrs: Fix infinite loop with missing comma
A missing comma between inline assembly templates did not throw an error
and looped indefinitely.

gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_format_strings): Emit an
	error when expecting a comma.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:59 +02:00
Pierre-Emmanuel Patry a9fdfc065c gccrs: Fix semicolon after some namespace
Remove namespace comment after classes and structs.

gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-fact-collector.h: Remove spurious
	comment.
	* checks/errors/rust-feature.cc: Likewise.
	* util/optional.h: Likewise.
	* expand/rust-token-tree-desugar.cc (TokenTreeDesugar::visit): Remove
	semicolons on namespace.
	* expand/rust-token-tree-desugar.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:59 +02:00
Owen Avery 611b74cffe gccrs: nr1.0: Remove rust/typecheck support
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-base.cc
	(TypeCheckBase::TypeCheckBase): Remove initialization of
	resolver field.
	* typecheck/rust-hir-type-check-base.h
	(TypeCheckBase::resolver): Remove field.
	* typecheck/rust-hir-trait-resolve.cc: Remove "options.h"
	include.
	(TraitResolver::resolve_path_to_trait): Assume name resolution
	2.0 is always enabled.
	* typecheck/rust-hir-type-check-enumitem.cc: Remove "options.h"
	include.
	(TypeCheckEnumItem::visit): Assume name resolution 2.0 is always
	enabled.
	* typecheck/rust-hir-type-check-expr.cc: Remove "options.h"
	include.
	(TypeCheckExpr::visit): Assume name resolution 2.0 is always
	enabled.
	(TypeCheckExpr::resolve_operator_overload): Likewise.
	(TypeCheckExpr::resolve_fn_trait_call): Likewise.
	* typecheck/rust-hir-type-check-implitem.cc: Remove "options.h"
	include.
	(TypeCheckImplItem::visit): Assume name resolution 2.0 is always
	enabled.
	* typecheck/rust-hir-type-check-item.cc: Remove "options.h"
	include.
	(TypeCheckItem::visit): Assume name resolution 2.0 is always
	enabled.
	* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit):
	Likewise.
	(TypeCheckExpr::resolve_root_path): Likewise.
	(TypeCheckExpr::resolve_segments): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc: Remove "options.h"
	include.
	(TypeCheckPattern::visit): Assume name resolution 2.0 is always
	enabled.
	* typecheck/rust-hir-type-check-type.cc
	(TypeCheckType::resolve_root_path): Likewise.
	(ResolveWhereClauseItem::visit): Likewise.
	* typecheck/rust-hir-type-check.cc: Remove "options.h" include.
	(TraitItemReference::get_type_from_fn): Assume name resolution
	2.0 is always enabled.
	* typecheck/rust-type-util.cc (query_type): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:59 +02:00
Pierre-Emmanuel Patry 71a121c2c6 gccrs: Add execute test for variable and identifiers
gcc/testsuite/ChangeLog:

	* rust/execute/inline_asm_inout_ident.rs: New test.
	* rust/execute/inline_asm_inout_var.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:58 +02:00
Pierre-Emmanuel Patry 68287a532c gccrs: Add input/output from inout and split in out
Inline assembly was incomplete and input/output from inout or split in
out were not handled.

gcc/rust/ChangeLog:

	* backend/rust-compile-asm.cc (get_out_expr): Return valid output from
	an operand.
	(CompileAsm::asm_construct_outputs): Handle every output
	(get_in_expr): Return valid input from an operand.
	(CompileAsm::asm_construct_inputs): Handle every input

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:58 +02:00
Pierre-Emmanuel Patry a527e317a0 gccrs: Parse input and output expression
Previously inline assembly expected identifiers instead of expression.

gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_reg_operand_inout): Parse
	expressions and build split in out.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:58 +02:00
Pierre-Emmanuel Patry 37ecb97134 gccrs: Add pretty hir dump for inline assembly
gcc/rust/ChangeLog:

	* hir/rust-hir-dump.cc (Dump::visit): Dump inline assembly fields
	* hir/tree/rust-hir-expr.h: Add non const getter and avoid operand copy
	from getters.
	* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Use non const
	reference.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:58 +02:00
Pierre-Emmanuel Patry 75a2441254 gccrs: Add indexed positional argument support in asm
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings): Handle
	transformation for indexed positional arguments.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:58 +02:00
Yap Zhi Heng e80e577df7 gccrs: Implement compilation for SlicePattern against SliceType scrutinee
006t.original output from compiling testsuite/rust/compile/match-slicepattern-slice.rs:

...
  RUSTTMP.3 = slice;
  if (RUSTTMP.3.len == 1 && *(RUSTTMP.3.data + 0 * 4) == 1)
    {
      {
                struct () RUSTTMP.4;
        {

        }
        goto <D.129>;
      }
    }
  if (RUSTTMP.3.len == 2 && *(RUSTTMP.3.data + 1 * 4) == 2)
    {
      {
                struct () RUSTTMP.5;
        {

        }
        goto <D.129>;
      }
    }
  if (1)
    {
      {
                struct () RUSTTMP.6;
        {

        }
        goto <D.129>;
      }
    }
  <D.129>:;
...

gcc/rust/ChangeLog:

	* rust-backend.h: New slice_index_expression function.
	* rust-gcc.cc: Implementation of slice_index_expression to generate tree node for
		accessing slice elements.
	* backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding
		compilation against SliceType scrutinee.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:58 +02:00
Yap Zhi Heng 495765758a gccrs: Update SlicePattern typechecking against slice reference parents
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(SlicePattern)):
		Add new type check case for SliceType wrapped in ReferenceType.
	* backend/rust-compile-pattern.cc: Adjusted the asserts accordingly for
		CompilePatternCheckExpr(SlicePattern) & CompilePatternBindings(SlicePattern).

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:58 +02:00
Arthur Cohen 499a70699b gccrs: desugar: Handle try-blocks
gcc/rust/ChangeLog:

	* Make-lang.in: Compile it.
	* ast/rust-expression-yeast.cc (ExpressionYeast::dispatch): Dispatch to try-block
	desugar.
	* ast/rust-desugar-try-block.cc: New file.
	* ast/rust-desugar-try-block.h: New file.

gcc/testsuite/ChangeLog:

	* rust/compile/try_block1.rs: New test.
2025-08-05 16:36:58 +02:00
Arthur Cohen ba00ed0976 gccrs: ast: Add Expr::Kind::Try
gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add the new variant.
	* ast/rust-expr.h: Use it for TryExpr class.
2025-08-05 16:36:58 +02:00
Owen Avery 3c18f1e487 gccrs: Handle IfLetExprConseqElse in DefaultResolver
This relies on the DefaultASTVisitor visitor for IfLetExprConseqElse
performing a virtual call of the visitor for IfLetExpr, which doesn't
hold when DefaultASTVisitor is generated by the X-macro-DSL-system I
have in another patch.

gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add
	visitor for IfLetExprConseqElse.
	* resolve/rust-default-resolver.h (DefaultResolver::visit):
	Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:57 +02:00
Arthur Cohen d8224f0222 gccrs: ast: Visit block labels if they are present
gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit a block's loop label if it
	exists.
2025-08-05 16:36:57 +02:00
Arthur Cohen 5594047290 gccrs: desugar: Add desugar dispatch for all desugars
Since we are doing more and more "external" desugars, as in desugars
that take a pointer and replace it with another one, rather than
modifying it from within, having an external visitor dispatch to the
proper desugar helps with code clarity.

gcc/rust/ChangeLog:

	* Make-lang.in: Compile it.
	* rust-session-manager.cc: Call the expression desugar dispatcher.
	* ast/rust-desugar-question-mark.cc: Rework class API.
	* ast/rust-desugar-question-mark.h: Likewise.
	* ast/rust-expression-yeast.cc: New file.
	* ast/rust-expression-yeast.h: New file.
2025-08-05 16:36:57 +02:00
Arthur Cohen f735d62958 gccrs: chore: ast: Fix formatting in rust-expr.h
gcc/rust/ChangeLog:

	* ast/rust-expr.h: Fix formatting.
2025-08-05 16:36:57 +02:00
Arthur Cohen 03cdb5236c gccrs: hir: Handle deferred const inference variables
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Handle defered consts.
	* hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise.
	(AnonConst::operator=): Likewise.
	* hir/tree/rust-hir-expr.h: Likewise.
	* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.

gcc/testsuite/ChangeLog:

	* rust/compile/deferred_const_inference.rs: New test.
2025-08-05 16:36:57 +02:00
Arthur Cohen 796f8f6944 gccrs: ast: Use AnonConst for array type sizes
gcc/rust/ChangeLog:

	* ast/rust-expr.h: Add handling for deferred consts.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
	* ast/rust-ast.cc (AnonConst::as_string): Likewise.
	(ArrayType::as_string): Likewise.
	* ast/rust-type.h (class ArrayType): Use AnonConst for sizes.
	* parse/rust-parse-impl.h (Parser::parse_anon_const): New function.
	(Parser::parse_slice_or_array_type): Call it.
	* parse/rust-parse.h: Declare it.
2025-08-05 16:36:57 +02:00
Arthur Cohen 04c0a86515 gccrs: nr2.0: Handle glob imports of enum variants.
gcc/rust/ChangeLog:

	* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Adapt for enums.
	(Early::finalize_glob_import): Likewise.
	* resolve/rust-early-name-resolver-2.0.h: Likewise.
	* resolve/rust-finalize-imports-2.0.cc (GlobbingVisitor::go): Likewise.
	(GlobbingVisitor::visit_module_container): New function.
	(GlobbingVisitor::visit_enum_container): New function.
	* resolve/rust-finalize-imports-2.0.h: Declare them.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Insert enums as potential
	containers.

gcc/testsuite/ChangeLog:

	* rust/compile/glob_import_enum.rs: New test.
2025-08-05 16:36:57 +02:00
Arthur Cohen b67f134688 gccrs: mappings: Change mappings to allow other items as item containers.
This is important for importing enum variants as items.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_ast_module): Rename to...
	(Mappings::insert_glob_container): ...this.
	(Mappings::lookup_ast_module): Rename to...
	(Mappings::lookup_glob_container): ...this.
	* util/rust-hir-map.h: Change declarations.
2025-08-05 16:36:57 +02:00
Owen Avery 9862af0658 gccrs: Load modules during CfgStrip phase
TopLevel would ignore just-loaded modules but Early and ExpandVisitor
wouldn't. The latter would produce errors when it hit attributes which
should have been indirectly CfgStrip'd away.

gcc/rust/ChangeLog:

	* expand/rust-cfg-strip.cc (CfgStrip::visit): Load unloaded
	modules.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
	Assume modules have been loaded by CfgStrip.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:57 +02:00
Owen Avery d957db9385 gccrs: Specialize ExpandVisitor::expand_macro_children
gcc/rust/ChangeLog:

	* expand/rust-expand-visitor.cc
	(ExpandVisitor::expand_inner_items): Adjust call to
	expand_macro_children.
	(ExpandVisitor::expand_inner_stmts): Likewise.
	(ExpandVisitor::visit): Likewise.
	* expand/rust-expand-visitor.h
	(ExpandVisitor::expand_macro_children): Take a pointer to member
	function instead of a std::function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:57 +02:00
Philip Herron 97f6ec0b88 gccrs: fix bad monomophization of generic paths
When we have generic paths like T::foobar during codegen sometimes we need
to enforce an extra lookup for this generic parameter type to the mono
morphized underlying type.

Fixes Rust-GCC#3915
Fixes Rust-GCC#1247

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): do another lookup

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3915.rs: New test.
	* rust/execute/torture/sip-hasher.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:56 +02:00
Owen Avery 9eec8c94ff gccrs: Use MacroInvocLexer in AttributeParser
This should make it easier for us to handle attribute meta items of the
form <SimplePath> '=' <Expression> where the expression isn't a literal.
Some low hanging fruit remains here, but I think I should keep this
patch small as I had some trouble debugging it as-is (see:
Rust::Token::as_string vs Rust::Token::get_str vs
Rust::AST::Token::as_string).

gcc/rust/ChangeLog:

	* ast/rust-ast.cc: Include "rust-macro-invoc-lexer.h".
	(AttributeParser::~AttributeParser): Move function definition
	here.
	(AttributeParser::AttributeParser): Likewise and adjust member
	initialization.
	(AttributeParser::parse_meta_item_inner): Handle changes to
	peek_token.
	(AttributeParser::parse_literal): Likewise.
	(AttributeParser::parse_simple_path_segment): Likewise.
	(AttributeParser::parse_meta_item_seq): Handle changes to
	AttributeParser fields.
	(AttributeParser::peek_token): Move function definition here and
	wrap MacroInvocLexer.
	(AttributeParser::skip_token): Likewise.
	* ast/rust-macro.h (class MacroInvocLexer): Forward declare.
	(class Parser): Likewise.
	(AttributeParser::token_stream): Remove field.
	(AttributeParser::stream_pos): Likewise.
	(AttributeParser::lexer): New field.
	(AttributeParser::parser): Likewise.
	(AttributeParser::AttributeParser): Move definition to
	"rust-ast.cc".
	(AttributeParser::~AttributeParser): Likewise.
	(AttributeParser::peek_token): Likewise.
	(AttributeParser::skip_token): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:56 +02:00
Philip Herron 1490b80bd1 gccrs: return error node when this fails during constexpr case
Not adding the test case here we emit more errors than rustc for the error
type node so its just noisy and dejagnu is being a pain.

Fixes Rust-GCC#3933

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): return error_mark_node

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:56 +02:00
Philip Herron 9076a8f688 gccrs: Add initial support for deffered operator overload resolution
In the test case:

  fn test (len: usize) -> u64 {
     let mut i = 0;
     let mut out = 0;
     if i + 3 < len {
        out = 123;
     }
     out
  }

The issue is to determine the correct type of 'i', out is simple because it hits a
coercion site in the resturn position for u64. But 'i + 3', 'i' is an integer infer
variable and the same for the literal '3'. So when it comes to resolving the type for
the Add expression we hit the resolve the operator overload code and because of this:

  macro_rules! add_impl {
      ($($t:ty)*) => ($(
          impl Add for $t {
              type Output = $t;

              #[inline]
              #[rustc_inherit_overflow_checks]
              fn add(self, other: $t) -> $t { self + other }
          }
      )*)
  }

  add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }

This means the resolution for 'i + 3' is ambigious because it could be any of these Add
implementations. But because we unify against the '< len' where len is defined as usize
later in the resolution we determine 'i' is actually a usize. Which means if we defer the
resolution of this operator overload in the ambigious case we can simply resolve it at the
end.

Fixes Rust-GCC#3916

gcc/rust/ChangeLog:

	* hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): track the rhs
	* hir/tree/rust-hir-expr.h: likewise
	* hir/tree/rust-hir-path.h: get rid of old comments
	* typecheck/rust-hir-trait-reference.cc (TraitReference::get_trait_substs): return
	references instead of copy
	* typecheck/rust-hir-trait-reference.h: update header
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::ResolveOpOverload): write ambigious
	operator overloads to a table and try to resolve it at the end
	* typecheck/rust-hir-type-check-expr.h: new static helper
	* typecheck/rust-hir-type-check.h (struct DeferredOpOverload): new model to defer resolution
	* typecheck/rust-typecheck-context.cc (TypeCheckContext::lookup_operator_overload): new
	(TypeCheckContext::compute_ambigious_op_overload): likewise
	(TypeCheckContext::compute_inference_variables): likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:56 +02:00
Philip Herron c3642a2cde gccrs: Fix ICE with duplicate root item main function
Rust seems to allow duplicate HIR::Item 'main' functions but it needs
to be a root item to be the true main entry point. This means we can
use the canonical path to determine if this is a root one where
its CrateName::main or CrateName::Module::main.

Fixes Rust-GCC#3978

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc: check the canonical path

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:56 +02:00
Owen Avery cfa1e8f973 gccrs: Improve parsing of simple paths
gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_simple_path): Be more
	careful about skipping SCOPE_RESOLUTION tokens.
	(Parser::parse_simple_path_segment): Allow parsing from a
	starting offset.
	(Parser::parse_use_tree): Handle a non-skipped SCOPE_RESOLUTION
	token.
	* parse/rust-parse.h (Parser::parse_simple_path_segment): Add
	parameter for parsing from a starting offset.

gcc/testsuite/ChangeLog:

	* rust/compile/parse_simple_path_fail_1.rs: New test.
	* rust/compile/parse_simple_path_fail_2.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:56 +02:00
Philip Herron 1420d244ee gccrs: Add test case to show issue is fixed
Fixes Rust-GCC#3524

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:56 +02:00
lishin ecb3582903 gccrs: Reject loop in const/static context
gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): Add a catch for const/static.

gcc/testsuite/ChangeLog:

	* rust/compile/loop_constant_context.rs: New test.
	* rust/compile/issue-3618.rs:

Signed-off-by: lishin <lishin1008@gmail.com>
2025-08-05 16:36:56 +02:00
Yap Zhi Heng 39aa96ce93 gccrs: Implement compilation for SlicePattern matching against ArrayType scrutinee
Example GIMPLE output from compiling testsuite/rust/compile/match-pattern-array.rs:

  ...
  a[0] = 0;
  a[1] = 1;
  RUSTTMP.3 = a;
  _1 = RUSTTMP.3[0];
  _2 = _1 == 0;
  _3 = RUSTTMP.3[1];
  _4 = _3 == 1;
  _5 = _2 & _4;
  if (_5 != 0) goto <D.122>; else goto <D.123>;
  <D.122>:
  {
    {

		}
	}
  goto <D.117>;
  }
  <D.123>:
	...

gcc/rust/ChangeLog:

	* rust-backend.h: New size_constant_expression function.
	* rust-gcc.cc: Implementation of size_constant_expression function to generate tree node
		for array access.
	* backend/rust-compile-pattern.h: Remove empty visits for SlicePattern.
	* backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding
		compilation against ArrayType scrutinee.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:56 +02:00
Yap Zhi Heng 72eb21fdf9 gccrs: Add size checking to SlicePattern
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc(TypeCheckPattern::visit(SlicePattern)):
		Implement size checking for SlicePattern when type checking against array parent

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:55 +02:00
Philip Herron a7c999f8fe gccrs: Add test case showing all derives working on enum
We have more complex test cases already but this will close out this issue.

Fixes Rust-GCC#2005

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:55 +02:00
Arthur Cohen cf8a078221 gccrs: attributes: Add #[test] and #[simd_test]
gcc/rust/ChangeLog:

	* util/rust-attribute-values.h: Add declarations for them.
	* util/rust-attributes.cc: Add definitions.
2025-08-05 16:36:55 +02:00
Philip Herron 65b8519344 gccrs: Add test case to show issue is fixed
Fixes Rust-GCC#1048

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:55 +02:00
Philip Herron 4d57fe1a44 gccrs: Add test case to show we emit better errors now
Fixes Rust-GCC#3144

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:55 +02:00
Philip Herron 24efd3aa45 gccrs: add test case to show issue is fixed
Fixes Rust-GCC#3599

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:55 +02:00
Philip Herron 79ce69f728 gccrs: Fix ICE when handling bad constructor
We just had a typo returning ok true when it should have been false.

Fixes Rust-GCC#3876

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): fix typo

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:55 +02:00
Philip Herron 04b29afcee gccrs: Fix cast rules logic to try simple casts then fall back to coercions
This case:

    let i = 1;
    let j = i as i64;

'i' is meant to default to i32 but the inference was making both of these
i64 because the code was prefering coercion logic which can end up with a
default unify which causes the ?integer to unify with i64 making them both
i64.

But all we need to do is allow the simple cast rules to run first then
fallback to coercions but special consideration has to be made to ensure
that if there are dyn objects needed then this needs a unsize coercion, but
also we need to ensure the underlying types are a valid simple cast too
otherwise these also need to fallback to the coercion code.

Fixes Rust-GCC#2680

gcc/rust/ChangeLog:

	* typecheck/rust-casts.cc (TypeCastRules::resolve): optional emit_error flag
	(TypeCastRules::check): try the simple cast rules then fallback to coercions
	(TypeCastRules::check_ptr_ptr_cast): ensure the underlying's
	(TypeCastRules::emit_cast_error): make this a static helper
	* typecheck/rust-casts.h: new emit_error prototype

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:55 +02:00
Arthur Cohen eea4cce969 gccrs: nr2.0: Check before visiting a for-loop's label
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check for a label
	before visiting it.
2025-08-05 16:36:55 +02:00
Philip Herron d8d02332bc gccrs: Fix bad bounds checking for PartialOrd
This was a nasty issue to debug, the issue was very eager type bounds
checking. So for example:

  pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs>

The super trait of PartialEq<Rhs> is a generic substitution and we reuse
our bounds code here for normal generic bounds and generics an invalid
bounds check was occuring when PartialEq<Rhs> was getting substituted becase
this is a trait doing proper bounds checking is not valid here because this
is telling us about the bounds in this case.

Fixes Rust-GCC#3836

gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): track is super trait
	* typecheck/rust-hir-type-bounds.h: refactor bounds scan
	* typecheck/rust-hir-type-check-base.h: track from super trait
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::is_bound_satisfied_for_type): refactor
	(TypeBoundsProbe::scan): likewise
	(TypeBoundPredicate::apply_generic_arguments): likewise
	* typecheck/rust-tyty-subst.cc: optional bounds checking on parm subst
	* typecheck/rust-tyty-subst.h: likewise
	* typecheck/rust-tyty.h: likewise

gcc/testsuite/ChangeLog:

	* rust/compile/derive_partial_ord1.rs: this is now fully supported
	* rust/execute/torture/basic_partial_ord1.rs: add missing i32 impl
	* rust/execute/torture/basic_partial_ord2.rs: likewise
	* rust/compile/issue-3836.rs: New test.
	* rust/execute/torture/issue-3836.rs: New test.
	* rust/execute/torture/partial-ord-6.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:54 +02:00
Marc Poulhiès a887f69e96 gccrs: Fix narrowing of Loan (size_t) into LoanId (uint32)
Fix narrowing:

  -../../gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc:145:46:
  warning: narrowing conversion of ‘loan’ from ‘Rust::Polonius::Loan’ {aka
  ‘long unsigned int’} to ‘uint32_t’ {aka ‘unsigned int’} [-Wnarrowing]

gcc/rust/ChangeLog:
	* checks/errors/borrowck/rust-bir-place.h (LoanId::value): Make
	it size_t to match Loan's base type.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2025-08-05 16:36:54 +02:00
Yap Zhi Heng ca34282cc7 gccrs: Improve LiteralPattern type checking
This change is made to ensure that LiteralPatterns in SlicePattern are type-checked
against the scrutinee array/slice's element type properly.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc(TypeCheckPattern::visit(LiteralPattern)):
		Check LiteralPattern's type against its parent.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:54 +02:00
Yap Zhi Heng 42cf04c2b8 gccrs: Add type checking for SlicePattern
This commit implements basic type checking support for SlicePattern, based on rustc's
check_pat_slice function.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(SlicePattern)):
		Implement initial type checking for SlicePattern.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:54 +02:00
Philip Herron 4d3f4efc93 gccrs: Fix ice with invalid borrow expression
This is an invalid test case but we just need a guard for the missing
borrow expression.

Fixes Rust-GCC#3874

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): check for missing borrow
	* ast/rust-expr.h: add helper

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:54 +02:00
Philip Herron b42c7041ae gccrs: Do proper const folding during typechecking for array capacities
This patch adds proper folding to the const expression for array capacity we
already have the const folding mechanics and the query system needed to handle cases
where the capacity is a function call in a const context. This leverages and pulls the
gcc tree capacity into the TyTy::ArrayType so it can be used for more typechecking and
eventually doing more const generics work.

Addresses Rust-GCC#3885
Fixes Rust-GCC#3882

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::query_compile_const_expr): new wrapper
	* backend/rust-compile-base.h: add prototype
	* backend/rust-compile-context.cc (Context::get): singleton helper
	* backend/rust-compile-context.h: likewise
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): handle infer's that can default
	* rust-session-manager.cc (Session::compile_crate): create the gcc context earlier for tychk
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): const fold it
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
	* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): fix constructor call
	(ArrayType::as_string): print capacity
	(ArrayType::clone): fix constructor call
	* typecheck/rust-tyty.h: track capacity
	* typecheck/rust-unify.cc (UnifyRules::expect_array): check the capacities

gcc/testsuite/ChangeLog:

	* rust/compile/all-cast.rs: shows array capacity now
	* rust/compile/arrays2.rs: likewise
	* rust/compile/const3.rs: fix error message
	* rust/compile/const_generics_3.rs: disable until typecheck we get proper errors now!
	* rust/compile/usize1.rs: proper capacity error message

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:54 +02:00
Arthur Cohen 1c22584fee gccrs: nr2.0: Add proper handling for WhileLet loops.
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc (Late::visit): New visitor.
	* resolve/rust-late-name-resolver-2.0.h: Declare it.
	* resolve/rust-name-resolution-context.h (enum class): New binding context.
2025-08-05 16:36:54 +02:00
Arthur Cohen 4e06ba151c gccrs: ast: Check before visiting a while-let's label
gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check that the WhileLet has a label
	before visiting it.

gcc/testsuite/ChangeLog:

	* rust/compile/while_let_without_label.rs: New test.
2025-08-05 16:36:54 +02:00
Owen Avery 528dd22fd9 gccrs: Parse try expressions
This doesn't do anything beyond creating TryExpr and parsing them, so
try expressions shouldn't be able to make it past AST lowering yet.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor
	for TryExpr.
	* ast/rust-ast-collector.h (TokenCollector::visit): Likewise.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
	* ast/rust-ast-visitor.h (ASTVisitor::visit): Likewise.
	(DefaultASTVisitor::visit): Likewise.
	* expand/rust-derive.h (DeriveVisitor::visit): Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
	* hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::visit):
	Likewise.
	* resolve/rust-ast-resolve-base.h (ResolverBase::visit):
	Likewise.
	* ast/rust-ast-full-decls.h (class TryExpr): New forward class
	declaration.
	* ast/rust-ast.cc (TryExpr::as_string): New function.
	(TryExpr::accept_vis): Likewise.
	* ast/rust-expr.h (class TryExpr): New class.
	* parse/rust-parse.h (Parser::parse_try_expr): New function.
	* parse/rust-parse-impl.h (Parser::parse_try_expr): Likewise.
	(Parser::null_denotation_not_path): Use parse_try_expr to parse
	try expressions.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:54 +02:00
Owen Avery 8122f4de72 gccrs: Allow format_args to accept a raw string literal
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-format-args.cc
	(format_args_parse_arguments): Accept a RAW_STRING_LITERAL token
	as the first argument.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:53 +02:00
Pierre-Emmanuel Patry df0fd3ad84 gccrs: Change enum to enum class
gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h: Add enum prefix.
	* parse/rust-parse.h (enum ParseSelfError): Change from enum...
	(enum class): To enum class.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:53 +02:00
Owen Avery b790c4a2f3 gccrs: Remove reinterpret_cast usages in DefaultASTVisitor
gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Replace
	usages of reinterpret_cast with static_cast.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:53 +02:00
Owen Avery 7ff7ac9ea3 gccrs: Remove Late visitor override for StructStruct
DefaultResolver already handles StructStruct in a more correct fashion.

gcc/rust/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:53 +02:00
Owen Avery c5d5bc1b41 gccrs: nr1.0: Remove rust/backend support
This is the first patch in a set intended to fully remove name
resolution 1.0. As such, it should leave name resolution 1.0 technically
available but broken.

gcc/rust/ChangeLog:

	* backend/rust-compile-context.cc (Context::Context): Remove
	initialization of resolver field.
	* backend/rust-compile-context.h (Context::get_resolver): Remove
	function.
	(Context::resolver): Remove field.
	* backend/rust-compile-expr.cc (CompileExpr::visit): Assume name
	resolution 2.0 is always enabled.
	(CompileExpr::generate_closure_function): Likewise.
	* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
	Likewise.
	* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
	* backend/rust-compile-resolve-path.cc
	(ResolvePathRef::resolve): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:53 +02:00
Owen Avery 0d542c18c6 gccrs: Remove -frust-name-resolution-2.0 usage in tests
gcc/testsuite/ChangeLog:

	* rust/compile/additional-trait-bounds2nr2.rs: Remove
	-frust-name-resolution-2.0 usage.
	* rust/compile/const_generics_3.rs: Likewise.
	* rust/compile/enum_variant_name.rs: Likewise.
	* rust/compile/generics9.rs: Likewise.
	* rust/compile/invalid_label_name.rs: Likewise.
	* rust/compile/issue-3304.rs: Likewise.
	* rust/compile/macros/mbe/macro-issue3708.rs: Likewise.
	* rust/compile/macros/mbe/macro-issue3709-2.rs: Likewise.
	* rust/compile/name_resolution10.rs: Likewise.
	* rust/compile/name_resolution11.rs: Likewise.
	* rust/compile/name_resolution12.rs: Likewise.
	* rust/compile/name_resolution13.rs: Likewise.
	* rust/compile/name_resolution14.rs: Likewise.
	* rust/compile/name_resolution15.rs: Likewise.
	* rust/compile/name_resolution16.rs: Likewise.
	* rust/compile/name_resolution17.rs: Likewise.
	* rust/compile/name_resolution18.rs: Likewise.
	* rust/compile/name_resolution20.rs: Likewise.
	* rust/compile/name_resolution22.rs: Likewise.
	* rust/compile/name_resolution23.rs: Likewise.
	* rust/compile/name_resolution24.rs: Likewise.
	* rust/compile/name_resolution25.rs: Likewise.
	* rust/compile/name_resolution6.rs: Likewise.
	* rust/compile/name_resolution7.rs: Likewise.
	* rust/compile/name_resolution8.rs: Likewise.
	* rust/compile/name_resolution9.rs: Likewise.
	* rust/compile/nested_macro_definition.rs: Likewise.
	* rust/compile/pub_restricted_1.rs: Likewise.
	* rust/compile/pub_restricted_2.rs: Likewise.
	* rust/compile/self-in-impl.rs: Likewise.
	* rust/compile/self_import_namespace.rs: Likewise.
	* rust/compile/use_1.rs: Likewise.
	* rust/compile/xfail/name_resolution21.rs: Likewise.
	* rust/execute/torture/name_resolution.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:53 +02:00
Owen Avery 6f7a094656 gccrs: nr2.0: Enable by default
gcc/rust/ChangeLog:

	* lang.opt (frust-name-resolution-2.0): Enable by default.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/compile.exp: Removed.
	* rust/compile/nr2/exclude: Removed.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:53 +02:00
Zhi Heng b42078879d gccrs: Implement compilation support for TuplePatternItems::RANGED
Example GIMPLE output of the match statement for match-restpattern-tuple-1.rs:

...
RUSTTMP.2 = x;
_1 = RUSTTMP.2.__0;
_2 = _1 == 1;
_3 = RUSTTMP.2.__3;
_4 = _3 == 4;
_5 = _2 & _4;
if (_5 != 0) goto <D.109>; else goto <D.110>;
<D.109>:
{
    {

    }
    goto <D.104>;
}
<D.110>:
if (1 != 0) goto <D.111>; else goto <D.112>;
<D.111>:
{
    {

    }
    goto <D.104>;
}
<D.112>:
<D.104>:
...

gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit(TuplePattern)):
		Implement check expression compilation for TuplePatternItems::RANGED.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:53 +02:00
Zhi Heng 0803c00cdd gccrs: Fix type checking logic for TuplePattern
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc (visit(TuplePattern)): Fix
		incorrect logic for field size checking.

gcc/testsuite/ChangeLog:

	* rust/compile/tuple_mismatch.rs: Include RestPattern in test.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:53 +02:00
Arthur Cohen 794b084ba2 gccrs: chore: ast: Fix formatting and includes
gcc/rust/ChangeLog:

	* ast/rust-ast-builder.cc: Remove extra include, fix new formatting.
2025-08-05 16:36:52 +02:00
Arthur Cohen 1c4521b397 gccrs: reconstruct_vec: Allocate size when creating the vector
gcc/rust/ChangeLog:

	* ast/rust-ast.h (reconstruct_vec): Pre-allocate size of vector.
2025-08-05 16:36:52 +02:00
Arthur Cohen 4c4efadd0f gccrs: ast: builder: Remove ASTTypeBuilder
gcc/rust/ChangeLog:

	* Make-lang.in: Remove object file for ASTTypeBuilder.
	* ast/rust-ast-builder.h: Remove function.
	* ast/rust-ast-builder.cc (Builder::new_type): Likewise.
	(Builder::new_const_param): Use reconstruct_type() instead.
	(Builder::new_generic_args): Likewise.
	* expand/rust-derive-default.cc (DeriveDefault::visit_struct): Likewise.
	(DeriveDefault::visit_tuple): Likewise.
	* expand/rust-derive-eq.cc (DeriveEq::visit_tuple): Likewise.
	(DeriveEq::visit_struct): Likewise.
	(DeriveEq::visit_enum): Likewise.
	(DeriveEq::visit_union): Likewise.
	* ast/rust-ast-builder-type.cc: Removed.
	* ast/rust-ast-builder-type.h: Removed.
2025-08-05 16:36:52 +02:00
Arthur Cohen f4b8b8332f gccrs: ast: Add reconstruct() method for Type nodes
gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add reconstruct() and reconstruct_impl() for Type nodes.
	* ast/rust-type.h: Implement them.
	* ast/rust-macro.h: Likewise.
	* ast/rust-path.h: Likewise.
2025-08-05 16:36:52 +02:00
Arthur Cohen 1c0b98dedc gccrs: ast: reconstruct: Add base for reconstructing and asserting different IDs
gcc/rust/ChangeLog:

	* ast/rust-ast.h (reconstruct): New function for calling the `reconstruct_*_impl` method
	and asserting that the new NodeId is different, and then wrap it in a unique_ptr<T>.
	(reconstruct_vec): Likewise, but for vectors of unique_ptr<T>
2025-08-05 16:36:52 +02:00
Owen Avery abdac0332a gccrs: nr2.0: Adjust resolution of modules
This prioritizes resolution in the language prelude over resolution as a
module.

gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.hxx (ForeverStack::resolve_path):
	Resolve final segments which point to modules.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
	Avoid inserting module names into ribs in the type namespace.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove issue-3315-2.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:52 +02:00
Owen Avery ffda76709d gccrs: nr2.0: Add more checks for alternate patterns
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc
	(visit_identifier_as_pattern): Handle is_ref and is_mut.
	(Late::visit): Likewise.
	* resolve/rust-name-resolution-context.cc
	(BindingLayer::insert_ident): Likewise.
	(BindingLayer::bind_test): Handle changes to BindingLayer
	fields.
	(BindingLayer::merge): Likewise and emit more error messages.
	* resolve/rust-name-resolution-context.h
	(struct IdentifierMode): New.
	(Binding::has_expected_bindings): New field.
	(Binding::set): Rename field to...
	(Binding::idents): ...here and convert from a set to a map.
	(Binding::Binding): Initialize has_expected_bindings.
	(BindingLayer::insert_ident): Adjust parameters.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove torture/alt_patterns1.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:52 +02:00
Pierre-Emmanuel Patry 352f980360 gccrs: Add locus getters
gcc/rust/ChangeLog:

	* ast/rust-expr.h: Add getter to locus field.
	* ast/rust-pattern.h (tokenid_to_rangekind): Likewise.
	* hir/tree/rust-hir-item.h: Likewise.
	* hir/tree/rust-hir-visibility.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:52 +02:00
Owen Avery 046992d053 gccrs: nr2.0: Adjust resolution of external crates
This ensures Session::load_extern_crate doesn't try to use the old name
resolver when nr2.0 is enabled, while also ensuring that nr2.0 handles
external crates.

gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc
	(DefaultResolver::visit_extern_crate): New function.
	(DefaultResolver::visit): New visitor function for ExternCrate.
	* resolve/rust-default-resolver.h
	(DefaultResolver::visit_extern_crate): New function.
	(DefaultResolver::visit): New visitor function for ExternCrate.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
	Adjust ExternCrate visitor and rename to...
	(TopLevel::visit_extern_crate): ...here.
	* resolve/rust-toplevel-name-resolver-2.0.h (TopLevel::visit):
	Remove ExternCrate visitor override.
	(TopLevel::visit_extern_crate): New function.
	* rust-session-manager.cc (Session::load_extern_crate): Only run
	name resolution 1.0 if name resolution 2.0 is disabled.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:52 +02:00
Zhi Heng 59c81cdfea gccrs: Implement type checking for ItemType::RANGED in TuplePattern
This patch implements the previously unimplemented type checking for RANGED item
type for TuplePattern, which serves as the start for implementing compilation of
RestPattern.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(TuplePattern)):
		Implement type checking for ItemType::RANGED.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:51 +02:00
Owen Avery 08011fc3d8 gccrs: Update C++ version check in rust-lang.cc
gcc/rust/ChangeLog:

	* rust-lang.cc: Move version check from C++11 to C++14.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:51 +02:00
Ryutaro Okada b01fc11358 gccrs: Implement default HIR visitor class
gcc/rust/ChangeLog:

	* Make-lang.in: Scaffolding new rust-hir-visitor files
	* hir/tree/rust-hir-visitor.h (DefaultHIRVisitor): Declare default HIR visitor
	* hir/tree/rust-hir-visitor.cc  (DefaultHIRVisitor): Define default HIR visitor

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05 16:36:51 +02:00
Owen Avery ae031e3801 gccrs: Create Rust::GGC::Ident
This should make it easier for us to hand identifiers off to the
back end.

gcc/rust/ChangeLog:

	* Make-lang.in (GRS_OBJS): Add rust-ggc.o.
	* backend/rust-compile-base.cc
	(HIRCompileBase::compile_function): Adjust call to
	Backend::function.
	(HIRCompileBase::compile_constant_item): Likewise and adjust
	initialization of Backend::typed_identifier.
	* backend/rust-compile-expr.cc (CompileExpr::visit): Adjust call
	to Backend::label.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit):
	Adjust initialization of Backend::typed_identifier.
	* rust-backend.h: Add includes.
	(Backend::GGC::Ident): Use Rust::GGC::Ident.
	(struct typed_identifier): Store name as a GGC::Ident rather
	than a std::string and adjust constructors.
	(named_type): Take GGC::Ident/tl::optional<GGC::Ident> rather
	than std::string.
	(global_variable): Likewise.
	(local_variable): Likewise.
	(parameter_variable): Likewise.
	(static_chain_variable): Likewise.
	(label): Likewise.
	(function): Likewise.
	* rust-gcc.cc (named_type): Likewise.
	(global_variable): Likewise.
	(local_variable): Likewise.
	(parameter_variable): Likewise.
	(static_chain_variable): Likewise.
	(label): Likewise.
	(function): Likewise.
	(function_defer_statement): Adjust call to Backend::label.
	(get_identifier_from_string): Remove function.
	(fill_in_fields): Handle adjustments to typed_identifier.
	* util/rust-ggc.cc: New file.
	* util/rust-ggc.h: New file.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:51 +02:00
Ryutaro Okada 8c05bfc153 gccrs: Add getter for non const lifetime object
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-item.h (SelfParam::get_lifetime): Add getter
	for non const lifetime object

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05 16:36:51 +02:00
Ryutaro Okada 5b9ef28055 gccrs: Add getter for outer attributions
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-expr.h (MatchArm::get_outer_attrs): Add getter for outer attributions

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05 16:36:51 +02:00
Owen Avery 6ced463762 gccrs: Fix scan-assembler regexp in recurse2.rs
gcc/testsuite/ChangeLog:

	* rust/compile/macros/builtin/recurse2.rs: Match "abheyho\0" as
	well as "abheyho", to handle slight differences in assembly
	output for null-terminated strings.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:51 +02:00
Philip Herron 6e5e0c1fd9 gccrs: Fix bug with non compiled const decl
There was a sily bug where if you reorder this test case to declare A before B
this test would work but its meant to work in any order. So this fixes the bug
during code gen to fall back to our query compile system if this is needed.

Fixes Rust-GCC#3525

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc: if this fails fall back to query compile

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:51 +02:00
Philip Herron dd4eabb87b gccrs: check for invalid const calls during code-gen
Closure calls are not const so this is invalid. This patch fixes two bugs

  1. Make the look at the parent context optional for generics
  2. Ensure we look for non const calls during call expr code-gen

Fixes Rust-GCC#3551

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): add const call check
	* backend/rust-compile-item.cc (CompileItem::visit): ensure we upfront compile types where
	possible
	* backend/rust-compile-item.h: update header
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): make parent ctx optional

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:51 +02:00
Zhi Heng 866510c83a gccrs: Fix TupleStructPattern compilation throwing error
Code for TupleStructPattern compilation previously only assumes that it is derived from
an enum. This commit adds a check for that, and compiles non-enum TupleStructPatterns
similarly to TuplePatterns if it is not an enum.

gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc(CompilePatternCheckExpr::visit(TupleStructPattern)):
		Fix error thrown when compiling non-enum TupleStructPattern.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:51 +02:00
Owen Avery 79fc731015 gccrs: nr2.0: Fix resolution of constant items
gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc (DefaultResolver::visit):
	Call DefaultASTVisitor::visit even on ConstantItem instances
	without expressions.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove issue-3642.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:50 +02:00
Philip Herron 86c14f5228 gccrs: Add unify rules for fnptr and closures
Its valid to unify a closure to an fnptr as we are working on the
fn traits. There are still other issues but this is part of the patch set.

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::expect_fnptr): add unify rules

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:50 +02:00
Philip Herron 2746b97a7d gccrs: Fix silly ordering bug in trait reference resolution
Ensure proper ordering when resolving trait references to prevent
incorrect type resolution in certain contexts.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-reference.cc (TraitReference::on_resolved): ensure associated
	types are done first
	* typecheck/rust-hir-type-check-type.cc: Update call site.

gcc/testsuite/ChangeLog:

	* rust/compile/silly-order-bug.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:50 +02:00
Philip Herron 8ddeba50f4 gccrs: Fix bug with bad type bindings not looking at super traits
When resolving type bounds, we need to examine super traits to properly
determine if type bindings are valid in the current context.

gcc/rust/ChangeLog:

	* typecheck/rust-tyty-bounds.cc: Check super traits for type bindings.
	* typecheck/rust-tyty.h: Add helper methods for bound checking.
2025-08-05 16:36:50 +02:00
Philip Herron 72c8362630 gccrs: Refactor marker builtin trait assembly
Rename assemble_sized_builtin to assemble_marker_builtins and reorganize
the type matching to properly handle function pointers and closures with
their associated traits (Fn, FnMut, FnOnce).

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-bounds.h: Rename method.
	* typecheck/rust-tyty-bounds.cc: Refactor marker trait assembly
	and add proper Fn trait handling for function types.
2025-08-05 16:36:50 +02:00
Philip Herron e59986b523 gccrs: Cleanup and refactor method resolution
Refactor the dot operator implementation to improve code organization
and maintainability while preserving existing functionality.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-dot-operator.cc: Major refactoring and cleanup.
	* typecheck/rust-hir-dot-operator.h: Add new helper methods.
2025-08-05 16:36:50 +02:00
Philip Herron d5c85e2484 gccrs: Fix cyclical projection to placeholder
Prevent infinite loops when projecting associated types by properly
handling cyclical references with placeholder types.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-resolve.cc: Add cyclical projection
	protection.
2025-08-05 16:36:50 +02:00
Philip Herron 29e6cfbd27 gccrs: Ensure we look at the bounds behind a reference
When type checking expressions that involve references, we need to
examine the bounds of the referenced type to properly resolve traits
and methods.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc: Look at bounds behind
	references.
	* typecheck/rust-hir-type-check-expr.h: Add helper method.
2025-08-05 16:36:50 +02:00
Owen Avery 3aac3dfec9 gccrs: Move AST desugaring into expansion phase
This fixes some issues with name resolution 2.0.

gcc/rust/ChangeLog:

	* rust-session-manager.cc (Session::compile_crate): Move
	AST desugaring to...
	(Session::expansion): ...here and add a final TopLevel pass
	afterwards.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:50 +02:00
Philip Herron a0b8b76c8c gccrs: Add test case showing RPIT working to close issue
Fixes Rust-GCC#1486

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:49 +02:00
Philip Herron 886eaa244a gccrs: Fix ICE when constant is missing and expression
This is an invalid test case and doesnt work with rustc, we dont fully pick
up the errors. Nr2 does handle this and puts out an extra good diagnostic
but the old NR doesnt so for now i added this to the exclude list and then
when we remove old name resolver this issue goes away.

Fixes Rust-GCC#3642

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): check for has_expr
	* hir/rust-hir-dump.cc (Dump::visit): likewise
	* hir/tree/rust-hir-item.h: add has_expr helper
	* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): check for has_expr
	* resolve/rust-ast-resolve-stmt.h: likewise
	* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): likewise

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: nr2 puts out an extra error
	* rust/compile/issue-3642.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:49 +02:00
Owen Avery 3dd992925f gccrs: Adjust external crate lowering and type checking
The 2.0 name resolver is provided through
ImmutableNameResolutionContext after it is done being mutated. The
typechecker attempts to use ImmutableNameResolutionContext, so it needs
to be run after ImmutableNameResolutionContext has been initialized
(after all name resolution has been completed). Additionally, although I
haven't seen any issues with lowering AST to HIR before name resolution
2.0 is complete, it makes sense to perform all lowering in lockstep as
well.

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Add
	visitor for ExternCrate.
	* hir/rust-ast-lower-item.h (ASTLoweringItem::visit): Likewise.
	* rust-session-manager.cc (Session::load_extern_crate): Avoid
	lowering or type resolving external crates here.
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
	Add visitor for ExternCrate.
	* typecheck/rust-hir-type-check-item.h (TypeCheckItem::visit):
	Replace empty definition with a declaration.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:49 +02:00
Owen Avery aeb9d51334 gccrs: Fix execute testsuite
Our non-torture execute tests haven't actually been running.

gcc/testsuite/ChangeLog:

	* rust/execute/black_box.rs: Return 0 from main.
	* rust/execute/match-identifierpattern-enum.rs: Move to...
	* rust/execute/xfail/match-identifierpattern-enum.rs: ...here.
	* rust/execute/execute.exp: New file.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:49 +02:00
Philip Herron 1223585918 gccrs: Fix issues around PartialEq Eq Ord Partial Ord
There is still an issue with derive on PartialOrd but this adds good tests
and fixes a bug we had handling the default Rhs = Self generic type param
substitutions on the comparison traits.

gcc/rust/ChangeLog:

	* typecheck/rust-tyty.cc (ParamType::handle_substitions): make this consistent

gcc/testsuite/ChangeLog:

	* rust/compile/bug-with-default-generic.rs: New test.
	* rust/execute/torture/partial-eq-1.rs: New test.
	* rust/execute/torture/partial-eq-2.rs: New test.
	* rust/execute/torture/partial-eq-3.rs: New test.
	* rust/execute/torture/partial-eq-4.rs: New test.
	* rust/execute/torture/partial-ord-1.rs: New test.
	* rust/execute/torture/partial-ord-2.rs: New test.
	* rust/execute/torture/partial-ord-3.rs: New test.
	* rust/execute/torture/partial-ord-4.rs: New test.
	* rust/execute/torture/partial-ord-5.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:49 +02:00
Zhi Heng a0ada5fb1b gccrs: nr2.0: Update IdentifierPattern's subpattern name resolution
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc (Late::visit(IdentifierPattern)):
	Remove redundant subpattern check.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:49 +02:00
Zhi Heng c11c65378d gccrs: Implement compilation of IdentifierPattern's subpattern bindings
gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc: Add support for IdentifierPattern's
		subpattern under CompilePatternBindings.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:49 +02:00
Zhi Heng aec1942c84 gccrs: Implement name resolution for IdentifierPattern's subpattern
gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-pattern.cc: Implement name resolution for
		IdentifierPattern's subpattern.
	* resolve/rust-late-name-resolver-2.0.cc: Ditto, but for nr2.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:49 +02:00
Zhi Heng efd1c71a22 gccrs: Rename get_pattern_to_bind to get_subpattern
gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc: Rename get_pattern_to_bind to get_subpattern
	* ast/rust-ast-visitor.cc: Ditto.
	* ast/rust-pattern.h: Ditto.
	* expand/rust-cfg-strip.cc: Ditto.
	* hir/rust-ast-lower-pattern.cc: Ditto.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:49 +02:00
Owen Avery 48d28a5801 gccrs: nr2.0: Adjust lookup of associated items
gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc (DefaultResolver::visit):
	Adjust scoping of trait definitions and their generic
	parameters.
	* resolve/rust-forever-stack.hxx (ForeverStack::get): Prevent
	lookups inside TraitOrImpl ribs.
	(ForeverStack::resolve_segments): Prevent lookups of the first
	segment inside TraitOrImpl ribs.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:49 +02:00
Zhi Heng 20efd782e3 gccrs: Improve HIR dumps for patterns
gcc/rust/ChangeLog:

	* hir/rust-hir-dump.cc: Change pattern dumps to use visit_field.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:48 +02:00
Arthur Cohen 83a80fe42a gccrs: chore: Fix formatting
gcc/rust/ChangeLog:

	* expand/rust-derive.cc: Fix formatting after fork update.
2025-08-05 16:36:48 +02:00
Arthur Cohen cfd2dd925d gccrs: derive(Ord, Eq): Use different node IDs for variant paths
gcc/rust/ChangeLog:

	* expand/rust-derive-cmp-common.cc (EnumMatchBuilder::tuple): Create two different
	variant paths.
	(EnumMatchBuilder::strukt): Likewise.
	* expand/rust-derive-cmp-common.h: Change API.
	* expand/rust-derive-ord.cc (DeriveOrd::visit_enum): Use new EnumMatchBuilder API.
	* expand/rust-derive-partial-eq.cc (DerivePartialEq::visit_enum): Likewise.

gcc/testsuite/ChangeLog:

	* rust/compile/derive_partial_ord1.rs: New test.
2025-08-05 16:36:48 +02:00
Arthur Cohen b9c51cb043 gccrs: derive(Ord): Handle unit structs properly
gcc/rust/ChangeLog:

	* expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): Use new make_equal function.
	(DeriveOrd::make_equal): New function.
	(DeriveOrd::recursive_match): Handle the unit struct/tuple case.
	* expand/rust-derive-ord.h: Declare make_equal.
2025-08-05 16:36:48 +02:00
Arthur Cohen 0194d12d27 gccrs: derive(Ord): Fix cmp call to use references instead of values
gcc/rust/ChangeLog:

	* expand/rust-derive-ord.cc (DeriveOrd::cmp_call): Use references.
2025-08-05 16:36:48 +02:00
Arthur Cohen 45730080b2 gccrs: derive(Ord): Fix condition for matching on Option::Some instead
gcc/rust/ChangeLog:

	* expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): Fix condition.
2025-08-05 16:36:48 +02:00
Arthur Cohen db4ee95302 gccrs: derive(Ord, PartialOrd): Finish implementation
gcc/rust/ChangeLog:

	* expand/rust-derive-ord.cc: Finish implementation for enums.
	* expand/rust-derive-ord.h: Likewise.
2025-08-05 16:36:48 +02:00
Arthur Cohen 7e48be1af7 gccrs: derive(PartialEq): Implement proper discriminant comparison
And use the new EnumMatchBuilder class to do so.

gcc/rust/ChangeLog:

	* expand/rust-derive-partial-eq.cc (DerivePartialEq::eq_fn): Change signature.
	(DerivePartialEq::visit_tuple): Use new eq_fn API.
	(DerivePartialEq::visit_struct): Likewise.
	(DerivePartialEq::visit_enum): Implement proper discriminant comparison.
	* expand/rust-derive-partial-eq.h: Change eq_fn signature.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/derive-partialeq2.rs: Add declaration for
	discriminant_value.
2025-08-05 16:36:48 +02:00
Arthur Cohen 714a56ca67 gccrs: derive-cmp: Add EnumMatchBuilder class
gcc/rust/ChangeLog:

	* expand/rust-derive-cmp-common.h (class EnumMatchBuilder): New helper class.
	* expand/rust-derive-cmp-common.cc (EnumMatchBuilder::tuple): New function.
	(EnumMatchBuilder::strukt): New function.
2025-08-05 16:36:48 +02:00
Arthur Cohen efdbea3b2b gccrs: ast-builder: Make location public
gcc/rust/ChangeLog:

	* ast/rust-ast-builder.h: Put `loc` member in public.
2025-08-05 16:36:47 +02:00
Arthur Cohen 33d713f039 gccrs: derive(Ord): Add handling for ordering of discriminant values
gcc/rust/ChangeLog:

	* expand/rust-derive-ord.cc (DeriveOrd::cmp_call): New function.
	(DeriveOrd::recursive_match): Use it.
	(DeriveOrd::visit_enum): Likewise.
	* expand/rust-derive-ord.h: Declare it.
2025-08-05 16:36:47 +02:00
Arthur Cohen 54b7f68b45 gccrs: derive(Hash): Use new Builder API
gcc/rust/ChangeLog:

	* expand/rust-derive-hash.cc (DeriveHash::visit_enum): Use new APIs.
2025-08-05 16:36:47 +02:00
Arthur Cohen 837189032b gccrs: builder: Add Builder::discriminant_value
gcc/rust/ChangeLog:

	* ast/rust-ast-builder.cc (Builder::discriminant_value): New function.
	* ast/rust-ast-builder.h: Declare it.
2025-08-05 16:36:47 +02:00
Arthur Cohen 2cf21f8995 gccrs: derive(Ord, PartialOrd): Handle tuples properly
gcc/rust/ChangeLog:

	* expand/rust-derive-ord.cc (is_last): Remove.
	(DeriveOrd::visit_tuple): Fix implementation.
2025-08-05 16:36:47 +02:00
Arthur Cohen e188ba2fd7 gccrs: derive(PartialEq): chore: Refactor using new SelfOther APIs
gcc/rust/ChangeLog:

	* expand/rust-derive-cmp-common.cc (SelfOther::indexes): Fix formatting.
	(SelfOther::fields): Make iterator const.
	* expand/rust-derive-cmp-common.h (struct SelfOther): New declaration for indexes.
	* expand/rust-derive-partial-eq.cc (DerivePartialEq::visit_tuple): Use the new API.
	(DerivePartialEq::visit_struct): Likewise.
2025-08-05 16:36:47 +02:00
Arthur Cohen b21e3e1d44 gccrs: derive(Ord, PartialOrd): Implement proper recursive match logic
gcc/rust/ChangeLog:

	* expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): New function.
	(is_last): Likewise.
	(recursive_match): Likewise.
	(DeriveOrd::recursive_match): Likewise.
	(DeriveOrd::visit_struct): Add proper implementation.
	(DeriveOrd::visit_union): Likewise.
	* expand/rust-derive-ord.h: Declare these new functions.
2025-08-05 16:36:47 +02:00
Arthur Cohen c886a1f65c gccrs: derive(PartialEq): Use that common class
gcc/rust/ChangeLog:

	* expand/rust-derive-partial-eq.cc (DerivePartialEq::tuple_indexes): Remove.
	(DerivePartialEq::field_acccesses): Remove.
	(DerivePartialEq::visit_tuple): Use new API.
	(DerivePartialEq::visit_struct): Likewise.
	* expand/rust-derive-partial-eq.h: Remove declarations.
2025-08-05 16:36:47 +02:00
Arthur Cohen 6892dbf3a5 gccrs: derive: Add common comparison derive class
gcc/rust/ChangeLog:

	* expand/rust-derive-cmp-common.cc: New file.
	* expand/rust-derive-cmp-common.h: New file.
	* Make-lang.in: Compile them.
2025-08-05 16:36:47 +02:00
Arthur Cohen 5ea7f9cf61 gccrs: builder: Add match_case() function and new block() one
gcc/rust/ChangeLog:

	* ast/rust-ast-builder.cc (Builder::block): New function.
	(Builder::match_case): Likewise.
	* ast/rust-ast-builder.h: Declare them.
2025-08-05 16:36:47 +02:00
Arthur Cohen e07ed4f016 gccrs: derive: Add const generics when deriving impls
gcc/rust/ChangeLog:

	* ast/rust-ast-builder.cc (Builder::new_const_param): New function.
	* ast/rust-ast-builder.h (vec): New function for creating 3 elts vector.
	* expand/rust-derive.cc: Use the new_const_param builder.
	* ast/rust-path.h: Add get_default_value() method.
2025-08-05 16:36:46 +02:00
Arthur Cohen 535aaf9882 gccrs: derive(Ord, PartialOrd): Add base for deriving them.
gcc/rust/ChangeLog:

	* Make-lang.in: Compile it.
	* expand/rust-derive.cc (DeriveVisitor::derive): Call them.
	* expand/rust-derive-ord.cc: New file.
	* expand/rust-derive-ord.h: New file.
2025-08-05 16:36:46 +02:00
Arthur Cohen a88309509b gccrs: derive: chore: Add missing override qualifiers
gcc/rust/ChangeLog:

	* expand/rust-derive-clone.h: Add missing override qualifiers to DeriveVisitor methods.
	* expand/rust-derive-copy.h: Likewise.
	* expand/rust-derive-eq.h: Likewise.
	* expand/rust-derive-hash.h: Likewise.
	* expand/rust-derive-partial-eq.h: Likewise.
2025-08-05 16:36:46 +02:00
Arthur Cohen e244696872 gccrs: rib: Add all kinds of Ribs to pretty-printing
gcc/rust/ChangeLog:

	* resolve/rust-rib.h: Add missing switch cases.
2025-08-05 16:36:46 +02:00
Philip Herron e0ad76bf33 gccrs: Fix bug in query type stopping PartialOrd
There was a complex recurisve type query hierarchy here but the type was
resolved so we can just do an early return here

gcc/rust/ChangeLog:

	* typecheck/rust-type-util.cc (query_type): early return.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/basic_partial_ord1.rs: New test.
	* rust/execute/torture/basic_partial_ord2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:46 +02:00
Philip Herron 82fabf7c9c gccrs: Fix bad type canonicalization on ARRAY_TYPES
Fixes Rust-GCC#3660

gcc/rust/ChangeLog:

	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): reuse GCC's build_array_type

gcc/testsuite/ChangeLog:

	* rust/compile/const_generics_3.rs:
	* rust/compile/issue-3660.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:46 +02:00
Owen Avery 4351f50995 gccrs: nr2.0: Adjust alternate identifier handling
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc
	(visit_identifier_as_pattern): Make sure to map identifiers
	inside or-bindings to prior identifiers.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:46 +02:00
Zhi Heng 7f5e6b5312 gccrs: Rename IdentifierPattern's to_bind to subpattern
gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc: Rename to_bind to subpattern.
	* ast/rust-ast-visitor.cc: Ditto.
	* ast/rust-pattern.cc: Ditto.
	* ast/rust-pattern.h: Ditto.
	* backend/rust-compile-pattern.cc: Ditto.
	* expand/rust-cfg-strip.cc: Ditto.
	* hir/rust-ast-lower-pattern.cc: Ditto.
	* hir/rust-hir-dump.cc: Ditto.
	* hir/tree/rust-hir-pattern.h: Ditto.
	* hir/tree/rust-hir.cc: Ditto.
	* typecheck/rust-hir-type-check-pattern.cc: Ditto.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:46 +02:00
Zhi Heng 0613241c5e gccrs: Support compilation of IdentifierPattern's subpatterns
gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc: Add CheckExpr compilation for
		IdentifierPattern with subpattern.
	* backend/rust-compile-pattern.h: Modify IdentifierPattern's
		visit func to support the above.
	* typecheck/rust-hir-type-check-pattern.cc: Add typechecking
		support for the changes above.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:46 +02:00
Owen Avery a709ad493a gccrs: nr2.0: Fix closure parameter scoping
gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc
	(DefaultResolver::visit_closure_params): New member function
	definition.
	(DefaultResolver::visit): New visiting function definition for
	ClosureExpr called from visiting functions for ClosureExprInner
	and ClosureExprInnerTyped.
	* resolve/rust-default-resolver.h
	(DefaultResolver::visit_closure_params): New member function
	declaration.
	(DefaultResolver::visit): New visiting function declaration for
	ClosureExpr.
	* resolve/rust-late-name-resolver-2.0.cc (add_captures): Remove
	function.
	(Late::visit): New visiting function definition for ClosureExpr,
	remove visiting function definitions for ClosureExprInner and
	ClosureExprInnerTyped.
	(Late::visit_closure_params): New member function definition.
	* resolve/rust-late-name-resolver-2.0.h (Late::visit): New
	visiting function declaration for ClosureExpr, remove visiting
	function declarations for ClosureExprInner and
	ClosureExprInnerTyped.
	(Late::visit_closure_params): New member function declaration.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:45 +02:00
Owen Avery f75b10f848 gccrs: nr2.0: Improve handling of single segment paths
gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.hxx (ForeverStack::resolve_path):
	Handle single segment paths "crate", "self", and "super".

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:45 +02:00
Owen Avery 9a9d97b694 gccrs: nr2.0: Adjust pub_restricted tests
gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove entries.
	* rust/compile/pub_restricted_1.rs: Adjust expected error
	messages and only run with name resolution 2.0 enabled.
	* rust/compile/pub_restricted_2.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:45 +02:00
Owen Avery 0aa558c1cc gccrs: nr2.0: Improve StructPatternFieldIdent handling
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Use
	visit_identifier_as_pattern to handle IdentifierPattern and
	StructPatternFieldIdent.
	(visit_identifier_as_pattern): New function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:45 +02:00
Owen Avery 471dfeee5f gccrs: Add new function ClosureExpr::get_definition_expr
gcc/rust/ChangeLog:

	* ast/rust-expr.h (ClosureExpr::get_definition_expr): New
	virtual member function.
	(ClosureExprInner::get_definition_expr): Add override specifier.
	(ClosureExprInnerTyped::get_definition_block): Rename to...
	(ClosureExprInnerTyped::get_definition_expr): ...here and add
	override specifier.

	* ast/rust-ast-collector.cc (TokenCollector::visit): Handle
	rename of ClosureExprInnerTyped::get_definition_block to
	ClosureExprInnerTyped::get_definition_expr.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
	* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
	* expand/rust-expand-visitor.cc (ExpandVisitor::visit):
	Likewise.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
	* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit):
	Likewise.
	* resolve/rust-late-name-resolver-2.0.cc (Late::visit):
	Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:45 +02:00
Owen Avery c0d42a5eba gccrs: nr2.0: Separate out canonical path handling
This should improve our canonical path handling, without requiring
further tweaks to ForeverStack. This may also help if, in the future, we
have to move canonical path calculation to later compilation phases for
proper handling of generics.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc
	(HIRCompileBase::compile_function): Since canonical paths
	returned from nr2.0 now include the crate name, avoid prepending
	the crate name again.

	* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
	Use NameResolutionContext::to_canonical_path instead of
	ForeverStack::to_canonical_path.
	* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
	* typecheck/rust-hir-type-check-enumitem.cc
	(TypeCheckEnumItem::visit): Likewise.
	* typecheck/rust-hir-type-check-implitem.cc
	(TypeCheckImplItem::visit): Likewise.
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
	Likewise.
	* typecheck/rust-hir-type-check.cc
	(TraitItemReference::get_type_from_fn): Likewise.

	* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add
	Crate and EnumItem instance visitors, handle canonical path
	context scoping.
	* resolve/rust-default-resolver.h (DefaultResolver::visit): Add
	Crate and EnumItem instance visitors.
	* resolve/rust-early-name-resolver-2.0.cc (Early::go): Visit
	instances of Crate using the virtual member function visit.
	* resolve/rust-forever-stack.h
	(ForeverStack::to_canonical_path): Remove function declaration.
	* resolve/rust-forever-stack.hxx
	(ForeverStack::to_canonical_path): Remove function definition.
	* resolve/rust-late-name-resolver-2.0.cc (Late::go): Visit
	instances of Crate using the virtual member function visit.
	* resolve/rust-name-resolution-context.cc
	(CanonicalPathRecordCrateRoot::as_path): New function definition.
	(CanonicalPathRecordNormal::as_path): Likewise.
	(CanonicalPathRecordLookup::as_path): Likewise.
	(CanonicalPathRecordImpl::as_path): Likewise.
	(CanonicalPathRecordTraitImpl::as_path): Likewise.
	(NameResolutionContext::NameResolutionContext): Initialize
	member variable canonical_ctx.
	* resolve/rust-name-resolution-context.h: Include "rust-item.h".
	(class NameResolutionContext): Forward declare class.
	(class CanonicalPathRecord): New class.
	(class CanonicalPathRecordWithParent): Likewise.
	(class CanonicalPathRecordCrateRoot): Likewise.
	(class CanonicalPathRecordNormal): Likewise.
	(class CanonicalPathRecordLookup): Likewise.
	(class CanonicalPathRecordImpl): Likewise.
	(class CanonicalPathRecordTraitImpl): Likewise.
	(class CanonicalPathCtx): Likewise.
	(NameResolutionContext::canonical_ctx): New member variable.
	(NameResolutionContext::to_canonical_path): New member function.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
	Visit instances of Crate with the virtual member function visit.
	(TopLevel::visit): Handle canonical path context scoping for
	external crates, use DefaultResolver::visit when visiting
	instances of StructStruct.
	* util/rust-canonical-path.h (CanonicalPath::new_seg): Take path
	parameter by-value, as a duplicate instance will be constructed
	regardless.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove canonical_paths1.rs.
2025-08-05 16:36:45 +02:00
Zhi Heng 3d50a05bba gccrs: Lower IdentifierPattern's to_bind to HIR
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-pattern.cc: Lower of IdentifierPattern's to_bind to HIR.
	* hir/rust-hir-dump.cc: Update IdentifierPattern's dump to properly show to_bind's full
	full properties.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05 16:36:45 +02:00
Vishruth-Thimmaiah 4cd0f0c6d3 gccrs: fix: ICE when parsing unterminated raw byte strings
Fixes an ICE when a raw byte string is not terminated

Fixes Rust-GCC#3731

gcc/rust/ChangeLog:

	* lex/rust-lex.cc (Lexer::parse_raw_byte_string):
	Fix infinite looping when a raw byte string is not terminated.

gcc/testsuite/ChangeLog:

	* rust/compile/torture/unended-raw-byte-string.rs:
	New test to ensure correct error message for unended raw byte string.

Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
2025-08-05 16:36:45 +02:00
Owen Avery af13b316e2 gccrs: nr2.0: Catch Self in impl block self types
gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc (DefaultResolver::visit): Use
	visit_impl_type to visit the self types of impl blocks.
	* resolve/rust-default-resolver.h
	(DefaultResolver::visit_impl_type): New member function
	declaration.
	* resolve/rust-late-name-resolver-2.0.cc (Late::Late):
	Initialize member variable block_big_self.
	(Late::visit_impl_type): New member function definition.
	(Late::visit): Check for Self while inside impl block self
	types.
	* resolve/rust-late-name-resolver-2.0.h (Late::visit_impl_type):
	New member function.
	(Late::block_big_self): New member variable.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3671.rs: Remove usage of Self.
	* rust/compile/nr2/exclude: Remove issue-3671.rs.
	* rust/compile/self-in-impl.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:45 +02:00
Owen Avery e2e16df3b1 gccrs: nr2.0: Improve visibility path handling
gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.h
	(enum ResolutionMode): New.
	(ForeverStack::get): Add a private overload that takes a
	starting node as a parameter.
	(ForeverStack::resolve_path): Replace boolean parameter
	has_opening_scope_resolution with ResolutionMode parameter mode.
	* resolve/rust-forever-stack.hxx
	(ForeverStack::resolve_path): Likewise.
	(ForeverStack::get): Add a private overload that takes a
	starting node as a parameter.
	* resolve/rust-late-name-resolver-2.0.cc
	(Late::visit): Add Visibility visitor.
	* resolve/rust-late-name-resolver-2.0.h
	(Late::visit): Likewise.
	* resolve/rust-name-resolution-context.h
	(NameResolutionContext::resolve_path): Rework overloading a bit
	and accept ResolutionMode parameter.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:44 +02:00
Vishruth-Thimmaiah 0bfd81883e gccrs: parser: fix ICE std::out_of_range with path attrs to nonexisting path
Stops an ICE from occuring when path attribute is empty

Fixes Rust-GCC#3607.

gcc/rust/ChangeLog:

	* parse/rust-parse.cc (Rust::extract_module_path):
	Handle empty or whitespace-only path attributes.

gcc/testsuite/ChangeLog:

	* rust/compile/torture/extern_mod2.rs:
	New test to ensure an error is emitted for empty path attributes.

Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
2025-08-05 16:36:44 +02:00
Owen Avery 93c36bbcb3 gccrs: Make ConstantItem use Identifier
The change to ASTLoweringExternItem is necessary, since with this patch
Identifier can be implicitly converted to std::string.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Handle
	changed type of ConstantItem::identifier.
	* ast/rust-ast.cc (ConstantItem::as_string): Likewise.
	* ast/rust-ast.h (operator const std::string &): New member
	function.
	* ast/rust-item.h (ConstantItem::identifier): Change type from
	std::string to Identifier.
	(ConstantItem::ConstantItem): Handle changed type of identifier
	field.
	(ConstantItem::is_unnamed): Likewise.
	(ConstantItem::get_identifier): Likewise.
	* hir/rust-ast-lower-extern.h (ASTLoweringExternItem::visit):
	Avoid discarding location of wildcard patterns.
	* lex/rust-token.cc: Include "rust-ast.h".
	(Token::make_identifier): Add overload accepting an Identifier
	instance.
	* lex/rust-token.h (class Identifier): Add forward declaration
	in order to...
	(Token::make_identifier): ...declare an overload for this static
	member function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:44 +02:00
Arthur Cohen 954afe2d85 gccrs: const-block: Add testcase
gcc/testsuite/ChangeLog:

	* rust/execute/torture/const_block1.rs: New test.
2025-08-05 16:36:44 +02:00
Arthur Cohen 0789f683ff gccrs: hir: Add const blocks
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-expr.h: New classes.
	* hir/tree/rust-hir-full-decls.h: Likewise.
	* hir/tree/rust-hir.cc: Handle AnonConst and ConstBlock.
	* backend/rust-compile-block.cc: Likewise.
	* backend/rust-compile-block.h: Likewise.
	* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
	* backend/rust-compile-expr.h: Likewise.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise.
	* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise.
	* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
	* checks/errors/borrowck/rust-function-collector.h: Likewise.
	* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
	* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
	* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
	* checks/errors/rust-const-checker.h: Likewise.
	* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Likewise.
	* checks/errors/rust-hir-pattern-analysis.h: Likewise.
	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
	* checks/errors/rust-unsafe-checker.h: Likewise.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
	(translate_operand_out): Likewise.
	(translate_operand_inout): Likewise.
	(translate_operand_const): Likewise.
	* hir/rust-ast-lower-expr.h: Likewise.
	* hir/rust-hir-dump.cc (Dump::visit): Likewise.
	* hir/rust-hir-dump.h: Likewise.
	* hir/tree/rust-hir-expr-abstract.h: Likewise.
	* hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise.
	(AnonConst::operator=): Likewise.
	(ConstBlock::ConstBlock): Likewise.
	(ConstBlock::operator=): Likewise.
	* hir/tree/rust-hir-visitor.h:
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
	(typecheck_inline_asm_operand): Likewise.
	* typecheck/rust-hir-type-check-expr.h: Likewise.
2025-08-05 16:36:44 +02:00
Arthur Cohen 6e4f14d2a7 gccrs: parser: Add base for parsing const blocks
gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_const_block_expr): New function.
	* parse/rust-parse.h: Declare it.
2025-08-05 16:36:44 +02:00
Arthur Cohen 55279e66f0 gccrs: ast: Add ConstBlock and AnonConst nodes
gcc/rust/ChangeLog:

	* ast/rust-expr.h: Declare AnonConst and ConstBlock and use them.
	* ast/rust-ast-full-decls.h: Likewise.
	* ast/rust-ast.cc: Add implementation for AnonConst and ConstBlock.
	* ast/rust-ast.h: Likewise.
	* ast/rust-ast-collector.cc (TokenCollector::visit): Likewise.
	* ast/rust-ast-collector.h: Likewise.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
	* ast/rust-ast-visitor.h: Likewise.
	* expand/rust-derive.h: Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
	* hir/rust-ast-lower-base.h: Likewise.
	* hir/rust-ast-lower-expr.cc (translate_operand_const): Likewise.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
	* resolve/rust-ast-resolve-base.h: Likewise.
	* resolve/rust-ast-resolve-expr.h: Likewise.
	* resolve/rust-ast-resolve-expr.cc: Likewise.
2025-08-05 16:36:44 +02:00
Philip Herron a283674556 gccrs: Always emit the error highest in the type hierarchy
The unify code was a bit dumb here where we always set emit_error to false for any
subtypes for example in comparing tuples we always emitted the whole tuple didnt
match the other tuple but really its much better to say expected bool got i32 because
the element types didn't match.

gcc/rust/ChangeLog:

	* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsized): dont emit error here
	* typecheck/rust-unify.cc (UnifyRules::resolve_subtype): new helper to handle emit error
	(UnifyRules::expect_adt): call resolve_subtype
	(UnifyRules::expect_reference): likewise
	(UnifyRules::expect_pointer): likewise
	(UnifyRules::expect_array): likewise
	(UnifyRules::expect_slice): likewise
	(UnifyRules::expect_fndef): likewise
	(UnifyRules::expect_fnptr): likewise
	(UnifyRules::expect_tuple): likewise
	(UnifyRules::expect_closure): likewise
	(UnifyRules::expect_opaque): likeiwse
	* typecheck/rust-unify.h: add new helper to header

gcc/testsuite/ChangeLog:

	* rust/compile/traits9.rs: update errors
	* rust/compile/unify-errors1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:44 +02:00
Owen Avery 2a09128fce gccrs: nr2.0: Fix IfLet pattern handling
gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc
	(DefaultResolver::visit_if_let_patterns): New function
	definition.
	(DefaultResolver::visit): New IfLetExpr visitor definition.
	* resolve/rust-default-resolver.h
	(DefaultResolver::visit_if_let_patterns): New function
	declaration.
	(DefaultResolver::visit): New IfLetExpr visitor declaration.
	* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
	IfLetExpr visitor definition.
	(Late::visit_if_let_patterns): New function definition.
	* resolve/rust-late-name-resolver-2.0.h (Late::visit): Remove
	IfLetExpr visitor declaration.
	(Late::visit_if_let_patterns): New function declaration.
	* resolve/rust-name-resolution-context.h (BindingSource::IfLet):
	New enumerator.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:44 +02:00
Philip Herron 7aa2529591 gccrs: Initial support for Return Position Impl Trait
This is the initial patch for RPIT, we can build on this to handle the
more complex cases but there are enough distinct changes going on here
that it should just get merged now.

RPIT is really a sneaky generic so for example:

  fn foo() -> impl Bar {
      Baz
  }

This is represented as: fn () -> OpaqueType Bar. But when we handle the
coercion site for Baz on impl Bar when we type resolve the function we
know that the underlying type  is Baz. Note this function is _not_ generic
so its using this special OpaqueType and keeping track of the underlying type
in its ty_ref reference hir-id which will resolve to Baz.

This also means if we have a case where maybe this was in an if statement:

  fn foo(a: i32) -> impl Bar {
      if a > 10 {
        Baz
      } else {
        Qux
      }
  }

The rules of impl Bar is that Baz is handled but Baz and Qux are different
underlying types so this is not allowed. The reason is impl traits are not
generic and although from a programmer perspective the callers dont know what
the underlying type is, the compiler _knows_ what it is. So really when
you call a function and get its return position impl trait the compiler knows
what to do and does all whats nessecary to handle calling functions using that
type etc.

gcc/rust/ChangeLog:

	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): we need to resolve the
	underlying type
	* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): just clone
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
	ensure we monomphize to get the underlying
	* typecheck/rust-tyty.cc (BaseType::destructure): handle opaque types
	(OpaqueType::resolve): this is much simpler now
	(OpaqueType::handle_substitions): no longer needed
	* typecheck/rust-tyty.h: update header
	* typecheck/rust-unify.cc (UnifyRules::expect_opaque): unify rules for opaque

gcc/testsuite/ChangeLog:

	* rust/compile/bad-rpit1.rs: New test.
	* rust/execute/torture/impl_rpit1.rs: New test.
	* rust/execute/torture/impl_rpit2.rs: New test.
	* rust/execute/torture/impl_rpit3.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:44 +02:00
Philip Herron f4a6ab3e76 gccrs: Fix non canonical type bug with tuples
When working on rpit we needed to change to use a monomorphized clone of
the result of function calls. This ended up causing a verify gimple issue
with tuples because:

  fn test<A, B>(a: A, b: B) -> (A, B)

When passing for example:

  let a = test::<i32, i32> (123, 456) -> (A=i32, B=i32)

The resulting gimple types became:

  const struct (A=i32, B=i32) vs struct (i32, i32)

We removed the VIEW_CONVERT_EXPR support to auto fix this stuff a good
while ago because it hides these kinds of issues because the type hasher
included the A=i32, B=i32 vs the i32, i32 name so updating this to use
get_name instead keeps the naming the same as well as the fields meaning
these types are 100% equivilant and therefore no conversion is required.
This only occurs because tuples are not named types we should really add
more rust specific info on our gimple TYPES.

gcc/rust/ChangeLog:

	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): use get_name
	* typecheck/rust-tyty.cc (TupleType::get_name): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:43 +02:00
Philip Herron 3c72ed2e71 gccrs: Remove unneeded clones untill we have an arena allocator for these tmps
Cloning inference variables is very expensive because it means we are indirectly
creating an implicit new inference variable added to the reference chain.

gcc/rust/ChangeLog:

	* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
	no need for unreachable here
	* typecheck/rust-unify.cc (UnifyRules::commit): dont clone infer vars
	(UnifyRules::expect_inference_variable): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:43 +02:00
Philip Herron af9aef5500 gccrs: refactor default infer vars to be its own function
This is just a simple refactor to pull all the logic outside of the
closure which makes it more readable.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check.h: new function
	* typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_inference_variables):
	call the new helper
	(TypeCheckContext::compute_infer_var): refactored code

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:43 +02:00
Parthib 41b45c5ed6 gccrs: Revert 10-second timeout for each test
gcc/testsuite/ChangeLog:

	* lib/rust.exp: Remove timeout.

Signed-off-by: Parthib <parthibdutta02@gmail.com>
2025-08-05 16:36:43 +02:00
Owen Avery 4b7fd08a41 gccrs: nr2.0: Fix some paths in test files
This is similar to 9faba024ef, but it
applies to execute tests.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/for-loop1.rs: Adjust paths.
	* rust/execute/torture/for-loop2.rs: Likewise.
	* rust/execute/torture/iter1.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:43 +02:00
Owen Avery 79c6dde777 gccrs: nr2.0: Fix test builtin_abort.rs
gcc/testsuite/ChangeLog:

	* rust/execute/torture/builtin_abort.rs: Fix path to
	intrinsics::abort.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:43 +02:00
Tom Schollenberger 6524c0687a gccrs: Fix NR2 ICE in visit_attributes
Undefined attribute macros have no proc macro definition, which results
in a failing `rust_assert`. This changes that assert to an if statement,
that returns early if there is no proc macro definition. Fixes #3661.

gcc/rust/ChangeLog:

	* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): rust_assert to if

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3661.rs: Test NR2 has expected behavior

Signed-off-by: Tom Schollenberger <tss2344@g.rit.edu>
2025-08-05 16:36:43 +02:00
Owen Avery 51089b89bd gccrs: Remove rvalue reference binding
This should be unnecessary, since even C++11 has implicit move.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_expr_stmt): Avoid
	reference binding and remove std::move in return statements.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:43 +02:00
Thomas Schwinge e66defecdb Rust: Move 'libformat_parser' build into the GCC build directory
Fixes Rust-GCC#2883.

	* .gitignore: Remove 'libgrust/*/target/'.
2025-08-05 16:36:43 +02:00
Owen Avery 99e7f6fea6 gccrs: Small improvements to DefaultASTVisitor and nr2.0
gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc
	(DefaultASTVisitor::visit): Only visit the path of an instance
	of Visibility if the instance has a path.
	* ast/rust-ast.h
	(SimplePath::SimplePath): Make sure constructors are explicit.
	* resolve/rust-early-name-resolver-2.0.cc
	(Early::visit_attributes): Pass entire paths to
	NameResolutionContext::resolve_path.
	(Early::visit): Likewise and avoid copying a path.
	* resolve/rust-forever-stack.hxx
	(ForeverStack::resolve_path): Assert that at least one path
	segment has been passed in.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:42 +02:00
Marc Poulhiès 94389da3bd gccrs: remove now useless clang-format comments
Config has been updated upstream to correctly indent declaration.

gcc/rust/ChangeLog:

	* rust-attribs.cc (handle_hot_attribute): Remove clang-format comment.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2025-08-05 16:36:42 +02:00
Marc Poulhiès dd65cf1df9 gccrs: Reindent using last clang-format configuration
It changes declaration and switch case indentation to follow GNU coding
style.

gcc/rust/ChangeLog:

	* ast/rust-ast-builder-type.cc (ASTTypeBuilder::visit): Reindent.
	* ast/rust-ast-builder.cc (Builder::new_generic_args): Likewise.
	* ast/rust-ast-collector.cc (TokenCollector::visit): Likewise.
	* ast/rust-ast-dump.h (debug): Likewise.
	* ast/rust-ast-formatting.h (indent_spaces): Likewise.
	(get_string_in_delims): Likewise.
	(get_mode_dump_desc): Likewise.
	(append_attributes): Likewise.
	(unquote_string): Likewise.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
	* ast/rust-ast.cc (Attribute::get_traits_to_derive): Likewise.
	(UseTreeGlob::as_string): Likewise.
	(UseTreeList::as_string): Likewise.
	(AttributeParser::parse_path_meta_item): Likewise.
	(FormatArgs::set_outer_attrs): Likewise.
	* ast/rust-ast.h (operator<<): Likewise.
	* ast/rust-cond-compilation.h: Likewise.
	* ast/rust-desugar-apit.cc: Likewise.
	* ast/rust-fmt.h (collect_pieces): Likewise.
	(clone_pieces): Likewise.
	* ast/rust-pattern.h (tokenid_to_rangekind): Likewise.
	* backend/rust-compile-context.cc (Context::type_hasher): Likewise.
	* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
	* backend/rust-compile-intrinsic.cc (get_identifier): Likewise.
	(offset_handler): Likewise.
	(sizeof_handler): Likewise.
	(transmute_handler): Likewise.
	(rotate_handler): Likewise.
	(wrapping_op_handler_inner): Likewise.
	(op_with_overflow_inner): Likewise.
	(uninit_handler): Likewise.
	(move_val_init_handler): Likewise.
	(assume_handler): Likewise.
	(discriminant_value_handler): Likewise.
	(variant_count_handler): Likewise.
	(prefetch_data_handler): Likewise.
	(atomic_store_handler_inner): Likewise.
	(atomic_load_handler_inner): Likewise.
	(unchecked_op_inner): Likewise.
	(copy_handler_inner): Likewise.
	(expect_handler_inner): Likewise.
	(try_handler_inner): Likewise.
	* backend/rust-compile-pattern.cc (compile_range_pattern_bound): Likewise.
	(CompilePatternCheckExpr::visit): Likewise.
	(CompilePatternBindings::visit): Likewise.
	(CompilePatternLet::visit): Likewise.
	* backend/rust-compile-var-decl.h: Likewise.
	* backend/rust-constexpr.cc (verify_constant): Likewise.
	(find_array_ctor_elt): Likewise.
	(array_index_cmp): Likewise.
	(potential_constant_expression_1): Likewise.
	(unshare_constructor): Likewise.
	(maybe_save_constexpr_fundef): Likewise.
	(returns): Likewise.
	(breaks): Likewise.
	(continues): Likewise.
	(switches): Likewise.
	(constant_value_1): Likewise.
	(decl_constant_value): Likewise.
	(non_const_var_error): Likewise.
	(eval_constant_expression): Likewise.
	(constexpr_fn_retval): Likewise.
	(eval_store_expression): Likewise.
	(eval_call_expression): Likewise.
	(eval_binary_expression): Likewise.
	(get_function_named_in_call): Likewise.
	(eval_statement_list): Likewise.
	(extract_string_elt): Likewise.
	(eval_conditional_expression): Likewise.
	(eval_bit_field_ref): Likewise.
	(eval_loop_expr): Likewise.
	(eval_switch_expr): Likewise.
	(eval_unary_expression): Likewise.
	(get_or_insert_ctor_field): Likewise.
	(eval_and_check_array_index): Likewise.
	* backend/rust-constexpr.h (maybe_save_constexpr_fundef): Likewise.
	* backend/rust-mangle-v0.cc (v0_path): Likewise.
	(v0_complex_type_prefix): Likewise.
	* backend/rust-mangle.h (legacy_mangle_item): Likewise.
	(v0_mangle_item): Likewise.
	* backend/rust-tree.cc (convert_to_void): Likewise.
	(find_parameter_packs_r): Likewise.
	(rs_tree_equal): Likewise.
	(publicly_uniquely_derived_p): Likewise.
	(instantiation_dependent_expression_p): Likewise.
	(type_has_nontrivial_copy_init): Likewise.
	(is_normal_capture_proxy): Likewise.
	(is_bitfield_expr_with_lowered_type): Likewise.
	(undeduced_auto_decl): Likewise.
	(require_deduced_type): Likewise.
	(gt_pch_nx): Likewise.
	(lvalue_kind): Likewise.
	* backend/rust-tree.h (LANG_DECL_MIN_CHECK): Likewise.
	(LANG_DECL_FN_CHECK): Likewise.
	(LANG_DECL_NS_CHECK): Likewise.
	(LANG_DECL_PARM_CHECK): Likewise.
	(LANG_DECL_DECOMP_CHECK): Likewise.
	(resort_type_member_vec): Likewise.
	(convert_to_void): Likewise.
	(mark_discarded_use): Likewise.
	(mark_exp_read): Likewise.
	(mark_use): Likewise.
	(mark_rvalue_use): Likewise.
	(mark_lvalue_use): Likewise.
	(mark_lvalue_use_nonread): Likewise.
	(convert_from_reference): Likewise.
	(maybe_warn_nodiscard): Likewise.
	(expr_loc_or_loc): Likewise.
	(expr_loc_or_input_loc): Likewise.
	(get_fndecl_from_callee): Likewise.
	(pointer_offset_expression): Likewise.
	(is_empty_class): Likewise.
	(is_really_empty_class): Likewise.
	(rs_type_quals): Likewise.
	(init_modules): Likewise.
	(lookup_add): Likewise.
	(ovl_make): Likewise.
	(struct c_fileinfo): Likewise.
	(get_fileinfo): Likewise.
	(cxx_make_type): Likewise.
	(build_cplus_array_type): Likewise.
	(comptypes): Likewise.
	(rs_build_qualified_type_real): Likewise.
	(vector_targets_convertible_p): Likewise.
	(get_class_binding_direct): Likewise.
	(lang_check_failed): Likewise.
	(check_for_uninitialized_const_var): Likewise.
	(cp_fold_maybe_rvalue): Likewise.
	(fold_offsetof): Likewise.
	(fold_non_dependent_expr): Likewise.
	(in_immediate_context): Likewise.
	(cxx_mark_addressable): Likewise.
	(decl_constant_value): Likewise.
	(is_class_type): Likewise.
	(fold_builtin_is_pointer_inverconvertible_with_class): Likewise.
	(c_common_type_for_mode): Likewise.
	(next_common_initial_seqence): Likewise.
	(fold_builtin_is_corresponding_member): Likewise.
	(maybe_constant_value): Likewise.
	(rs_walk_subtrees): Likewise.
	(make_tree_vector): Likewise.
	(release_tree_vector): Likewise.
	(location_of): Likewise.
	(maybe_constant_init): Likewise.
	(explain_invalid_constexpr_fn): Likewise.
	(literal_type_p): Likewise.
	(maybe_constexpr_fn): Likewise.
	(fold_non_dependent_init): Likewise.
	* checks/errors/borrowck/polonius/rust-polonius.h (polonius_run): Likewise.
	(FFIVector__new): Likewise.
	(FFIVector__new_vec_pair): Likewise.
	(FFIVector__new_vec_triple): Likewise.
	(FFIVector__push): Likewise.
	(FFIVector__push_vec_triple): Likewise.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
	(ExprStmtBuilder::visit): Likewise.
	* checks/errors/borrowck/rust-bir-builder-pattern.cc
	(PatternBindingBuilder::visit): Likewise.
	* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): Likewise.
	* checks/errors/borrowck/rust-bir-fact-collector.h (points): Likewise.
	* checks/errors/borrowck/rust-bir-place.h: Likewise.
	* checks/errors/borrowck/rust-bir-visitor.h: Likewise.
	* checks/errors/privacy/rust-privacy-check.cc (saw_errors): Likewise.
	* checks/errors/privacy/rust-privacy-ctx.h (rust_privacy_ctx_test): Likewise.
	* checks/errors/privacy/rust-privacy-reporter.cc
	(PrivacyReporter::check_for_privacy_violation): Likewise.
	(PrivacyReporter::check_base_type_privacy): Likewise.
	(PrivacyReporter::visit): Likewise.
	* checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise.
	* checks/errors/privacy/rust-visibility-resolver.cc
	(VisibilityResolver::resolve_visibility): Likewise.
	* checks/errors/rust-hir-pattern-analysis.cc (Constructor::is_covered_by): Likewise.
	(PlaceInfo::specialize): Likewise.
	(WitnessPat::to_string): Likewise.
	(WitnessMatrix::apply_constructor): Likewise.
	(lower_pattern): Likewise.
	(lower_tuple_pattern): Likewise.
	(lower_struct_pattern): Likewise.
	* checks/errors/rust-hir-pattern-analysis.h (check_match_usefulness): Likewise.
	* expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_generic_args): Likewise.
	* expand/rust-derive-eq.cc (DeriveEq::visit_enum): Likewise.
	* expand/rust-derive.cc: Likewise.
	* expand/rust-expand-format-args.cc (expand_format_args): Likewise.
	* expand/rust-expand-visitor.h (is_derive): Likewise.
	(is_builtin): Likewise.
	* expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings): Likewise.
	* expand/rust-macro-builtins-asm.h (parse_asm): Likewise.
	(check_identifier): Likewise.
	(check_and_set): Likewise.
	(parse_label): Likewise.
	(parse_llvm_outputs): Likewise.
	(parse_llvm_inputs): Likewise.
	(parse_llvm_clobbers): Likewise.
	(parse_llvm_options): Likewise.
	* expand/rust-macro-builtins-helpers.h (make_macro_path_str): Likewise.
	(make_token): Likewise.
	(make_string): Likewise.
	(macro_end_token): Likewise.
	(parse_single_string_literal): Likewise.
	(source_relative_path): Likewise.
	(load_file_bytes): Likewise.
	* expand/rust-macro-expand.cc (MacroExpander::match_fragment): Likewise.
	(MacroExpander::match_matcher): Likewise.
	(MacroExpander::match_n_matches): Likewise.
	* expand/rust-macro-substitute-ctx.cc (SubstituteCtx::substitute_token): Likewise.
	* expand/rust-proc-macro.h (load_macros): Likewise.
	(generate_proc_macro_decls_symbol): Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args): Likewise.
	(ASTLoweringBase::lower_range_pattern_bound): Likewise.
	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
	* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise.
	* hir/rust-ast-lower.h (struct_field_name_exists): Likewise.
	(translate_visibility): Likewise.
	* hir/rust-hir-dump.cc (Dump::visit): Likewise.
	* hir/rust-hir-dump.h (debug): Likewise.
	* hir/tree/rust-hir.cc (UseTreeGlob::as_string): Likewise.
	(UseTreeList::as_string): Likewise.
	* lex/rust-lex.cc (Lexer::parse_escape): Likewise.
	(Lexer::parse_utf8_escape): Likewise.
	* lex/rust-lex.h (rust_input_source_test): Likewise.
	* lex/rust-token.cc (RS_TOKEN_KEYWORD_2015): Likewise.
	* lex/rust-token.h (get_token_description): Likewise.
	(token_id_to_str): Likewise.
	(token_id_is_keyword): Likewise.
	(token_id_keyword_string): Likewise.
	(get_type_hint_string): Likewise.
	(nfc_normalize_token_string): Likewise.
	* metadata/rust-export-metadata.cc (PublicInterface::write_to_path): Likewise.
	* metadata/rust-import-archive.cc: Likewise.
	* metadata/rust-imports.h (add_search_path): Likewise.
	* parse/rust-cfg-parser.h (parse_cfg_option): Likewise.
	(rust_cfg_parser_test): Likewise.
	* parse/rust-parse-impl.h (Parser::skip_generics_right_angle): Likewise.
	(Parser::parse_attr_input): Likewise.
	(Parser::parse_macro_match): Likewise.
	(Parser::parse_visibility): Likewise.
	(Parser::parse_module): Likewise.
	(Parser::parse_use_tree): Likewise.
	(Parser::parse_generic_param): Likewise.
	(Parser::parse_struct): Likewise.
	(Parser::parse_enum_item): Likewise.
	(Parser::parse_inherent_impl_item): Likewise.
	(Parser::parse_external_item): Likewise.
	(Parser::parse_generic_arg): Likewise.
	(Parser::parse_type_path_segment): Likewise.
	(Parser::parse_expr_stmt): Likewise.
	(Parser::parse_if_expr): Likewise.
	(Parser::parse_if_let_expr): Likewise.
	(Parser::parse_type): Likewise.
	(Parser::parse_for_prefixed_type): Likewise.
	(Parser::parse_slice_or_array_type): Likewise.
	(Parser::parse_type_no_bounds): Likewise.
	(Parser::parse_range_pattern_bound): Likewise.
	(Parser::parse_pattern_no_alt): Likewise.
	(Parser::parse_grouped_or_tuple_pattern): Likewise.
	(Parser::parse_ident_leading_pattern): Likewise.
	(Parser::parse_tuple_struct_items): Likewise.
	(Parser::parse_stmt_or_expr): Likewise.
	(Parser::parse_struct_expr_field): Likewise.
	(Parser::null_denotation): Likewise.
	(Parser::left_denotation): Likewise.
	(Parser::parse_closure_expr_pratt): Likewise.
	* parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewise.
	(is_match_compatible): Likewise.
	* parse/rust-parse.h (extract_module_path): Likewise.
	(is_match_compatible): Likewise.
	* resolve/rust-ast-resolve-expr.cc (translate_operand): Likewise.
	* resolve/rust-ast-resolve-item.cc (flatten_glob): Likewise.
	(flatten_rebind): Likewise.
	(flatten_list): Likewise.
	(flatten): Likewise.
	* resolve/rust-ast-resolve-item.h (rust_simple_path_resolve_test): Likewise.
	* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise.
	(resolve_range_pattern_bound): Likewise.
	* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise.
	(ResolveTypeToCanonicalPath::visit): Likewise.
	* resolve/rust-ast-resolve.cc (saw_errors): Likewise.
	* resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import): Likewise.
	* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
	* resolve/rust-toplevel-name-resolver-2.0.cc (flatten_glob): Likewise.
	* rust-backend.h (init): Likewise.
	(debug): Likewise.
	(get_identifier_node): Likewise.
	(wchar_type): Likewise.
	(get_pointer_size): Likewise.
	(raw_str_type): Likewise.
	(integer_type): Likewise.
	(float_type): Likewise.
	(pointer_type): Likewise.
	(reference_type): Likewise.
	(immutable_type): Likewise.
	(function_type): Likewise.
	(function_type_variadic): Likewise.
	(function_ptr_type): Likewise.
	(struct_type): Likewise.
	(union_type): Likewise.
	(array_type): Likewise.
	(named_type): Likewise.
	(type_field_offset): Likewise.
	(var_expression): Likewise.
	(float_constant_expression): Likewise.
	(string_constant_expression): Likewise.
	(char_constant_expression): Likewise.
	(wchar_constant_expression): Likewise.
	(boolean_constant_expression): Likewise.
	(convert_expression): Likewise.
	(struct_field_expression): Likewise.
	(compound_expression): Likewise.
	(conditional_expression): Likewise.
	(negation_expression): Likewise.
	(arithmetic_or_logical_expression): Likewise.
	(arithmetic_or_logical_expression_checked): Likewise.
	(comparison_expression): Likewise.
	(lazy_boolean_expression): Likewise.
	(constructor_expression): Likewise.
	(array_constructor_expression): Likewise.
	(array_initializer): Likewise.
	(array_index_expression): Likewise.
	(call_expression): Likewise.
	(init_statement): Likewise.
	(assignment_statement): Likewise.
	(return_statement): Likewise.
	(if_statement): Likewise.
	(loop_expression): Likewise.
	(exit_expression): Likewise.
	(statement_list): Likewise.
	(exception_handler_statement): Likewise.
	(block): Likewise.
	(block_add_statements): Likewise.
	(global_variable): Likewise.
	(global_variable_set_init): Likewise.
	(local_variable): Likewise.
	(parameter_variable): Likewise.
	(static_chain_variable): Likewise.
	(temporary_variable): Likewise.
	(label): Likewise.
	(function): Likewise.
	(function_defer_statement): Likewise.
	(function_set_parameters): Likewise.
	(write_global_definitions): Likewise.
	(fill_in_fields): Likewise.
	* rust-diagnostics.cc (expand_format): Likewise.
	(expand_message): Likewise.
	(va_constructor): Likewise.
	* rust-diagnostics.h (RUST_ATTRIBUTE_GCC_DIAG): Likewise.
	(rust_open_quote): Likewise.
	(rust_close_quote): Likewise.
	(rust_debug_loc): Likewise.
	* rust-gcc.cc (non_zero_size_type): Likewise.
	* rust-object-export.h (rust_field_alignment): Likewise.
	(rust_read_export_data): Likewise.
	(rust_write_export_data): Likewise.
	* rust-session-manager.cc (saw_errors): Likewise.
	(rust_get_linemap): Likewise.
	(validate_crate_name): Likewise.
	(Session::load_extern_crate): Likewise.
	* rust-session-manager.h (rust_crate_name_validation_test): Likewise.
	* rust-system.h (rust_preserve_from_gc): Likewise.
	(rust_localize_identifier): Likewise.
	* rust-target.h (rust_add_target_info): Likewise.
	* typecheck/rust-autoderef.cc:
	* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Likewise.
	* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Likewise.
	(TypeCoercionRules::coerce_unsafe_ptr): Likewise.
	(TypeCoercionRules::coerce_borrowed_pointer): Likewise.
	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Likewise.
	(TraitItemReference::is_object_safe): Likewise.
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
	(typecheck_inline_asm_operand): Likewise.
	* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise.
	(TypeCheckImplItemWithTrait::visit): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise.
	* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): Likewise.
	* typecheck/rust-hir-type-check-type.cc
	(TypeResolveGenericParam::apply_trait_bounds): Likewise.
	(ResolveWhereClauseItem::visit): Likewise.
	* typecheck/rust-hir-type-check.cc (saw_errors): Likewise.
	(TraitItemReference::get_type_from_fn): Likewise.
	* typecheck/rust-type-util.h (query_type): Likewise.
	(types_compatable): Likewise.
	(unify_site): Likewise.
	(unify_site_and): Likewise.
	(coercion_site): Likewise.
	(try_coercion): Likewise.
	(cast_site): Likewise.
	* typecheck/rust-tyty-bounds.cc:
	* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise.
	* typecheck/rust-tyty-cmp.h:
	* typecheck/rust-tyty-variance-analysis.h (query_field_regions): Likewise.
	* typecheck/rust-tyty.cc (BaseType::is_unit): Likewise.
	(BaseType::has_substitutions_defined): Likewise.
	(BaseType::needs_generic_substitutions): Likewise.
	(BaseType::get_subst_argument_mappings): Likewise.
	(InferType::default_type): Likewise.
	(InferType::apply_primitive_type_hint): Likewise.
	* typecheck/rust-tyty.h (is_primitive_type_kind): Likewise.
	* typecheck/rust-unify.cc (UnifyRules::expect_inference_variable): Likewise.
	(UnifyRules::expect_adt): Likewise.
	(UnifyRules::expect_str): Likewise.
	(UnifyRules::expect_reference): Likewise.
	(UnifyRules::expect_pointer): Likewise.
	(UnifyRules::expect_param): Likewise.
	(UnifyRules::expect_array): Likewise.
	(UnifyRules::expect_slice): Likewise.
	(UnifyRules::expect_fndef): Likewise.
	(UnifyRules::expect_fnptr): Likewise.
	(UnifyRules::expect_tuple): Likewise.
	(UnifyRules::expect_bool): Likewise.
	(UnifyRules::expect_char): Likewise.
	(UnifyRules::expect_int): Likewise.
	(UnifyRules::expect_uint): Likewise.
	(UnifyRules::expect_float): Likewise.
	(UnifyRules::expect_isize): Likewise.
	(UnifyRules::expect_usize): Likewise.
	(UnifyRules::expect_never): Likewise.
	(UnifyRules::expect_placeholder): Likewise.
	(UnifyRules::expect_projection): Likewise.
	(UnifyRules::expect_dyn): Likewise.
	(UnifyRules::expect_closure): Likewise.
	(UnifyRules::expect_opaque): Likewise.
	* util/rust-abi.h (get_abi_from_string): Likewise.
	(get_string_from_abi): Likewise.
	* util/rust-attributes.cc (check_doc_attribute): Likewise.
	* util/rust-base62.h (base62_integer): Likewise.
	* util/rust-dir-owner.h (get_file_subdir): Likewise.
	* util/rust-edition.h (get_rust_edition): Likewise.
	* util/rust-punycode.h (encode_punycode): Likewise.
	(rust_punycode_encode_test): Likewise.
	* util/rust-token-converter.cc (convert): Likewise.
	(from_tokenstream): Likewise.
	* util/rust-token-converter.h (convert): Likewise.
	(convert_literal): Likewise.
	* util/rust-unicode.h (is_alphabetic): Likewise.
	(is_ascii_only): Likewise.
	(is_numeric): Likewise.
	(is_nfc_qc_no): Likewise.
	(is_nfc_qc_maybe): Likewise.
	(nfc_quick_check): Likewise.
	(rust_nfc_qc_test): Likewise.
	(rust_utf8_normalize_test): Likewise.
	(rust_utf8_property_test): Likewise.
	* util/rust-unwrap-segment.h (unwrap_segment_node_id): Likewise.

libgrust/ChangeLog:

	* libproc_macro_internal/ffistring.h (FFIString__new): Likewise.
	(FFIString__drop): Likewise.
	* libproc_macro_internal/ident.h (Ident__new): Likewise.
	(Ident__new_raw): Likewise.
	(Ident__drop): Likewise.
	(Ident__clone): Likewise.
	* libproc_macro_internal/literal.h (Literal__from_string): Likewise.
	* libproc_macro_internal/proc_macro.h (bridge_is_available): Likewise.
	* libproc_macro_internal/tokenstream.h (TokenStream__new): Likewise.
	(TokenStream__with_capacity): Likewise.
	(TokenSream__push): Likewise.
	(TokenStream__from_string): Likewise.
	(TokenStream__clone): Likewise.
	(TokenStream__drop): Likewise.
2025-08-05 16:36:42 +02:00
Marc Poulhiès e44b0b5111 gccrs: remove unused file
gcc/rust/ChangeLog:

	* Make-lang.in (GRS_OBJS): Remove rust-macro.o.
	* ast/rust-macro.cc: Removed.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2025-08-05 16:36:42 +02:00
Owen Avery 449378d843 gccrs: Fix Attr metavariable binding
gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h
	(Parser::parse_attr_input): Handle more delimeter tokens and the
	END_OF_FILE token.
	(Parser::skip_after_end_attribute): Handle the END_OF_FILE
	token.

gcc/testsuite/ChangeLog:

	* rust/compile/macros/mbe/meta-param.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:42 +02:00
Owen Avery 8e454ab6e1 gccrs: Fix test same_field_name.rs
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-item.cc
	(ASTLoweringItem::visit): Keep going after a duplicate field is
	found.

gcc/testsuite/ChangeLog:

	* rust/execute/same_field_name.rs: Move to...
	* rust/compile/same_field_name.rs: ...here and adjust expected
	errors.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:42 +02:00
Owen Avery f79beeae1f gccrs: nr2.0: Fix borrow checking
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-builder-internal.h: Include
	"rust-immutable-name-resolution-context.h" and "options.h".
	(AbstractBuilder::resolve_label): Use the 2.0 name resolver when
	it's enabled.
	(AbstractBuilder::resolve_variable): Likewise.
	(AbstractBuilder::resolve_variable_or_fn): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:42 +02:00
Philip Herron 97fc34aab8 gccrs: We cant clone types as it will dup the node-id
This patch ensuers we reuse the Builder for new type to
ensure we create a new type from scratch ensuring consistent
new node-ids.

gcc/rust/ChangeLog:

	* expand/rust-derive-default.cc (DeriveDefault::visit_struct): use builder
	(DeriveDefault::visit_tuple): likewise
	* expand/rust-derive-eq.cc (DeriveEq::visit_tuple): likewise
	(DeriveEq::visit_struct): likewise
	(DeriveEq::visit_enum): likewise
	(DeriveEq::visit_union): likewise

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: these are fixed now

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:42 +02:00
Marc Poulhiès 7e38e0ca35 gccrs: Adapt attribute lang hook and do some cleanup
Since r14-6076, the LANG_HOOKS_COMMON_ATTRIBUTE_TABLE should not be used and
LANG_HOOKS_ATTRIBUTE_TABLE replaces it.

Add the "cold" attribute to fix PR120018 (and the matching "hot" attribute).

Replace some gcc_assert() by explicit warnings (same as D frontend).

Add some clang-format off/on comment around code that's not correctly
formatted.

gcc/rust/ChangeLog:
	PR rust/120018

	* rust-attribs.cc (handle_noreturn_attribute): Reindent declaration.
	(handle_leaf_attribute): Likewise.
	(handle_const_attribute): Likewise.
	(handle_malloc_attribute): Likewise.
	(handle_pure_attribute): Likewise.
	(handle_novops_attribute): Likewise.
	(handle_nonnull_attribute): Likewise.
	(handle_nothrow_attribute): Likewise.
	(handle_type_generic_attribute): Likewise.
	(handle_transaction_pure_attribute): Likewise.
	(handle_returns_twice_attribute): Likewise.
	(handle_fnspec_attribute): Likewise.
	(handle_omp_declare_simd_attribute): Likewise.
	(handle_cold_attribute): New.
	(handle_hot_attribute): New.
	(attribute_spec::exclusions attr_cold_hot_exclusions): New.
	(grs_langhook_common_attributes): Make it static.
	(grs_langhook_common_attribute_table): New.
	(grs_langhook_gnu_attributes): New.
	(grs_langhook_gnu_attribute_table): New.
	(handle_malloc_attribute): Make it static.
	(handle_fnspec_attribute): Likewise.
	(handle_pure_attribute): Replace gcc_assert by explicit warning.
	(handle_novops_attribute): Likewise.
	(handle_nothrow_attribute): Likewise.
	(handle_returns_twice_attribute): Likewise.
	(handle_omp_declare_simd_attribute): Likewise and make it static.
	* rust-lang.cc (grs_langhook_gnu_attribute_table): New.
	(grs_langhook_common_attribute_table): Adjust type to new hook.
	(LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): Remove.
	(LANG_HOOKS_ATTRIBUTE_TABLE): New.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2025-08-05 16:36:42 +02:00
Owen Avery f90a4d7711 gccrs: nr2.0: Adjust resolution of impl items
gcc/rust/ChangeLog:

	* ast/rust-path.cc
	(TypePath::make_debug_string): Add definition.
	* ast/rust-path.h
	(TypePath::make_debug_string): Add declaration.
	* resolve/rust-default-resolver.cc
	(DefaultResolver::visit): Adjust InherentImpl and TraitImpl
	visitors to better handle associated item scope.
	* resolve/rust-default-resolver.h
	(DefaultResolver::maybe_insert_big_self): Add.
	* resolve/rust-late-name-resolver-2.0.cc
	(Late::visit): Adjust type path resolution errors.
	* resolve/rust-rib.h
	(Rib::Kind): Add Generics kind.
	* resolve/rust-toplevel-name-resolver-2.0.cc
	(TopLevel::visit): Remove InherentImpl and TraitImpl visitor
	overrides.
	(TopLevel::maybe_insert_big_self): Add override in order to add
	a definition of 'Self'.
	* resolve/rust-toplevel-name-resolver-2.0.h
	(TopLevel::visit): Remove InherentImpl and TraitImpl visitor
	overrides.
	(TopLevel::maybe_insert_big_self): Add override.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:41 +02:00
0xn4utilus 7189044886 gccrs: ast: collector: visit InlineAsm node during ast dump
gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Implement for InlineAsm.
	* ast/rust-ast-full-decls.h (enum class): Move InlineAsmOption enum inside InlineAsm.
	* ast/rust-expr.h (enum class): Likewise.
	(class InlineAsm): Likewise.
	* expand/rust-macro-builtins-asm.cc (check_and_set): Likewise.
	(parse_options): Likewise.
	* expand/rust-macro-builtins-asm.h (check_and_set): Likewise.
	* hir/tree/rust-hir-expr.cc (InlineAsm::InlineAsm): Likewise.
	* hir/tree/rust-hir-expr.h: Likewise.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
2025-08-05 16:36:41 +02:00
Tom Schollenberger 5d658d8b62 gccrs: fix ICE on empty constexpr loops
Empty loops have no body which means this is a NULL_TREE during const
evaluation which needs a check. Fixes Rust-GCC #3618.

gcc/rust/ChangeLog:

	* backend/rust-constexpr.cc (eval_constant_expression):  Check if t is a NULL_TREE

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3618.rs: Test empty loops error properly.

Signed-off-by: Tom Schollenberger <tss2344@g.rit.edu>
2025-08-05 16:36:41 +02:00
Philip Herron 9819ac4641 gccrs: Prevent passing generic arguments to impl traits in argument position
When using impl traits in argument position (APIT), they are desugared into generics,
and supplying explicit generic arguments is not allowed. This commit adds the error
diagnostic E0632 for attempting to pass generic arguments to impl traits, completing
the implementation of the APIT feature.

gcc/rust/ChangeLog:

	* ast/rust-desugar-apit.cc: track if this is a impl-trait generic
	* ast/rust-item.h (class TypeParam): add field to track if from impl trait
	* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): likewise
	* hir/tree/rust-hir-item.cc (TypeParam::TypeParam): upate hir as well
	(TypeParam::operator=): likewise
	* hir/tree/rust-hir-item.h (class TypeParam): likewise
	* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): add error
	* typecheck/rust-tyty-subst.h: add const getter for the associated TypeParm

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: nr2 cant handle this
	* rust/compile/impl_trait_generic_arg.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:41 +02:00
Owen Avery 17a863d7ac gccrs: nr2.0: Adjust enum item visitors
gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc
	(DefaultASTVisitor::visit): Make call to EnumItem visitor from
	EnumItem derived class visitors non-virtual.
	* ast/rust-collect-lang-items.cc
	(CollectLangItems::visit): Handle visitation of classes derived
	from EnumItem.
	* ast/rust-collect-lang-items.h
	(CollectLangItems::visit): Likewise.
	* resolve/rust-toplevel-name-resolver-2.0.cc
	(TopLevel::visit): Call DefaultResolver::visit on EnumItem
	instances.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:41 +02:00
Owen Avery 66cf64e9d2 gccrs: Improve struct pattern compilation
gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc
	(CompilePatternCheckExpr::visit): Fix GENERIC generation in
	light of enum layout changes since this code was written.
	(CompilePatternBindings::handle_struct_pattern_ident_pat):
	Delegate handling of child patterns to another
	CompilePatternBindings::Compile call.
	(CompilePatternBindings::make_struct_access): Make field name
	parameter const qualified.
	* backend/rust-compile-pattern.h
	(CompilePatternBindings::make_struct_access): Likewise.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/struct-pattern-match.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:41 +02:00
Owen Avery f70757fb59 gccrs: Improve canonical path handling for impl items
gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-item.cc
	(ResolveItem::visit): Use the return values of
	CanonicalPath::inherent_impl_seg and
	CanonicalPath::trait_impl_projection_seg more directly.
	* util/rust-canonical-path.h
	(CanonicalPath::trait_impl_projection_seg): Append "<impl "
	instead of "<" to the beginning of the returned path segment.
	(CanonicalPath::inherent_impl_seg): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05 16:36:41 +02:00
Philip Herron f45eaca3a3 gccrs: desugar APIT impl traits
Argument position impl traits are simply syntatic sugar for generics. This
adds a new desugar pass to do this. So for example:

    fn foo(a: impl Value, b: impl Value) -> i32

Is desugared into:

    fn foo<T: Value, U: Value> (a: T, b: U) -> i32

So it just works like any normal generic function. There are more complex cases such as:

    fn foo(_value: impl Bar<Baz = impl Foo>) -> i32

Which has a generic argument binding which needs to be turned into a where constraint:

    fn foo<T, U>(_value: T) -> i32
        where
            T: Bar<Baz = U>,
            U: Foo,

Fixes Rust-GCC#2015
Fixes Rust-GCC#1487
Fixes Rust-GCC#3454
Fixes Rust-GCC#1482

gcc/rust/ChangeLog:

	* Make-lang.in: new desugar file
	* ast/rust-ast.cc (ImplTraitTypeOneBound::as_string): its a unique_ptr now
	(FormatArgs::set_outer_attrs): reformat
	* ast/rust-path.h: remove has_generic_args assertion (can be empty because of desugar)
	* ast/rust-type.h (class ImplTraitTypeOneBound): add copy ctor and use unique_ptr
	* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): update to use unique_ptr
	* parse/rust-parse-impl.h (Parser::parse_type): reuse the existing unique_ptr instead
	(Parser::parse_type_no_bounds): likewise
	(Parser::parse_pattern): likewise
	* resolve/rust-ast-resolve-type.cc (ResolveType::visit): its a unique_ptr now
	* rust-session-manager.cc (Session::compile_crate): call desugar
	* ast/rust-desugar-apit.cc: New file.
	* ast/rust-desugar-apit.h: New file.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2015.rs: fully supported now
	* rust/compile/nr2/exclude: nr2 cant handle some of these
	* rust/compile/issue-1487.rs: New test.
	* rust/compile/issue-3454.rs: New test.
	* rust/execute/torture/impl_desugar-2.rs: New test.
	* rust/execute/torture/impl_desugar.rs: New test.
	* rust/execute/torture/impl_trait1.rs: New test.
	* rust/execute/torture/impl_trait2.rs: New test.
	* rust/execute/torture/impl_trait3.rs: New test.
	* rust/execute/torture/impl_trait4.rs: New test.
	* rust/execute/torture/issue-1482.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:41 +02:00
Philip Herron 97a7ae2039 gccrs: Emit error diagnostic for bad impl type usage
Rust only allows impl traits to be used in the return position of
functions.

Fixes Rust-GCC#1485

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): allow impl type
	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): likewise
	* hir/rust-ast-lower-type.cc (ASTLoweringType::ASTLoweringType): new flag for impl trait
	(ASTLoweringType::translate): pass flag
	(ASTLoweringType::visit): track impl trait tag
	(ASTLoweringType::emit_impl_trait_error): new diagnostic
	* hir/rust-ast-lower-type.h: add new field

gcc/testsuite/ChangeLog:

	* rust/compile/impl_trait_diag.rs: New test.
	* rust/compile/issue-1485.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05 16:36:41 +02:00
CohenArthurandPierre-Emmanuel Patry 652732d49d gccrs: derive(PartialEq): Fix raw strings in test
gcc/testsuite/ChangeLog:

	* rust/execute/torture/derive-partialeq2.rs: Add missing terminating nul char.

Co-authored-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05 16:36:40 +02:00
Arthur Cohen 8517601c81 gccrs: derive(PartialEq): Allow deriving enum structs
gcc/rust/ChangeLog:

	* expand/rust-derive-partial-eq.cc (DerivePartialEq::match_enum_tuple): Remove debug call.
	(DerivePartialEq::match_enum_struct): Add proper implementation.
	(DerivePartialEq::visit_enum): Call it.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/derive-partialeq2.rs: New test.
2025-08-05 16:36:40 +02:00
Arthur Cohen ba94b1e2f8 gccrs: ast: builder: Allow building struct ident patterns
gcc/rust/ChangeLog:

	* ast/rust-ast-builder.cc (Builder::struct_pattern_ident_pattern): New.
	* ast/rust-ast-builder.h: New declaration.
2025-08-05 16:36:40 +02:00
Arthur Cohen 5ef9ef5b88 gccrs: backend: Compile struct rebinding patterns
Allow matching on a struct instance and rebinding its fields to new names:

match X {
	Foo {
		field0: new_name0,
		field1: new_name1,
	} => {
		do_something(new_name0, new_name1);
	},
}

This will enable us to finish derives for PartialEq and PartialOrd but
isn't a complete implementation of these patterns yet.

gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.cc (CompilePatternBindings::make_struct_access):
	New function.
	(CompilePatternBindings::visit): Properly implement patterns mentioned above
	and call make_struct_accesss.
	* backend/rust-compile-pattern.h: New declaration.

gcc/testsuite/ChangeLog:

	* rust/execute/torture/struct_pattern1.rs: New test.
2025-08-05 16:36:40 +02:00
Arthur Cohen e5be440ecf gccrs: backend: Refactor struct pattern compilation
gcc/rust/ChangeLog:

	* backend/rust-compile-pattern.h: Split struct pattern compilation into three functions.
	* backend/rust-compile-pattern.cc: Implement them.
2025-08-05 16:36:40 +02:00
Arthur Cohen afe024047b gccrs: nr2.0: late: Correctly initialize funny_error member
gcc/rust/ChangeLog:

	* resolve/rust-late-name-resolver-2.0.cc (Late::Late): False initialize the
	funny_error field.
2025-08-05 16:36:40 +02:00
Mikael Morin 55434a57e5 fortran: Use array descriptor offset setter when possible
Regression-tested on x86_64-pc-linux-gnu.
OK for master?

-- >8 --

    In some places, a write to an array descriptor offset field was
    generated simply by adding a modification of a reference to it that
    was already available.  This change uses the existing setter
    function instead in those places, to generate the same code.  It
    makes it more explicit that in those areas a write to the field is
    generated.

gcc/fortran/ChangeLog:

	* trans-array.cc (gfc_alloc_allocatable_for_assignment): Use the
	offset setter instead of generating a write to the offset.
	(gfc_conv_array_parameter): Use the offset setter instead of
	generating a write to the value returned by the offset getter.
	* trans-expr.cc (gfc_trans_alloc_subarray_assign): Likewise.
2025-08-05 16:20:40 +02:00
Mikael Morin 9021a43608 fortran: Remove array descriptor data address accessor function
Regression-tested on x86_64-pc-linux-gnu.
OK for master?

-- >8 --

The function gfc_conv_descriptor_data_addr generates an address to the
data field of an array descriptor.  It is only used once, and in the
single place where it is used, the address is immediately dereferenced.

This change replaces the single usage with a plain access to the data
field, and removes the function.  As the previous patch removed the
usage of the data field to write to it, the data getter can be used.

gcc/fortran/ChangeLog:

	* trans-array.cc (gfc_conv_descriptor_data_addr): Remove.
	* trans-array.h (gfc_conv_descriptor_data_addr): Remove.
	* trans-decl.cc (gfc_trans_deferred_vars): Use
	gfc_conv_descriptor_data_get.
2025-08-05 16:20:40 +02:00
Mikael Morin d993f5e492 fortran: Use array descriptor data setter when possible
Regression-tested on x86_64-pc-linux-gnu.
OK for master?

-- >8 --

In some places, a write to an array descriptor data field was generated
simply by adding a modification of a reference to it that was already
available.  This change uses the existing setter function instead in
those places, to generate the same code.  It makes it more explicit that
in those areas a write to the field is generated.

We have to be careful because in some of the places, the pointer that is
to be modified is an array descriptor field only under some conditions.
Add a conditional in those places to separate the cases, and keep
generating the reference modification as before if the conditions are
not met.

gcc/fortran/ChangeLog:

	* trans.cc (gfc_finalize_tree_expr): Use the data setter instead
	of writing to the value returned by the data getter.
	* trans-decl.cc (gfc_trans_deferred_vars): Likewise.
	* trans-stmt.cc (trans_associate_var): Use the data setter
	instead of writing to the value dereferenced from the data
	address.
2025-08-05 16:20:40 +02:00
Richard Sandiford 5305f84c3b i386: Extend recognition of high-reg rvalues [PR121306]
The i386 high-register patterns used things like:

    (match_operator:SWI248 2 "extract_operator"
      [(match_operand 0 "int248_register_operand" "Q")
       (const_int 8)
       (const_int 8)])

to match an extraction of a high register such as AH from AX/EAX/RAX.

This construct is used in contexts where only the low 8 bits of the
value matter.  This is either done explicitly using a (subreg:QI ... 0)
or implicitly by assigning to an 8-bit zero_extract destination.

extract_operator therefore matches both sign_extract and zero_extract,
since the signedness of the extension beyond 8 bits is irrelevant.

But the fact that only the low 8 bits of the value are significant
means that a shift right by 8 is as good as an extraction.  Shifts
right would already be used for things like:

  struct s {
    long a:8;
    long b:8;
    long c:48;
  };

  struct s f(struct s x, long y, long z) {
    x.b = (y & z) >> 8;
    return x;
  }

but are used more after g:965564eafb721f8000013a3112f1bba8d8fae32b.

This patch therefore replaces extract_operator with a new predicate
called extract_high_operator that matches both extractions and shifts.
The predicate checks the extraction field and shift amount itself,
so that patterns only need to match the first operand.

Splitters used match_op_dup to preserve the choice of extraction.
But the fact that the extractions (and now shifts) are equivalent
means that we can just as easily canonicalise on one of them.
(In theory, canonicalisation would also promote CSE, although
that's unlikely in practice.)  The patch goes for zero_extract,
for consistency with destinations.

gcc/
	PR target/121306
	* config/i386/predicates.md (extract_operator): Replace with...
	(extract_high_operator): ...this new predicate.
	* config/i386/i386.md (*cmpqi_ext<mode>_1, *cmpqi_ext<mode>_2)
	(*cmpqi_ext<mode>_3, *cmpqi_ext<mode>_4, *movstrictqi_ext<mode>_1)
	(*extzv<mode>, *insvqi_2, *extendqi<SWI24:mode>_ext_1)
	(*addqi_ext<mode>_1_slp, *addqi_ext<mode>_1_slp, *addqi_ext<mode>_0)
	(*addqi_ext2<mode>_0, *addqi_ext<mode>_1, *<insn>qi_ext<mode>_2)
	(*subqi_ext<mode>_1_slp, *subqi_ext<mode>_2_slp, *subqi_ext<mode>_0)
	(*subqi_ext2<mode>_0, *subqi_ext<mode>_1, *testqi_ext<mode>_1)
	(*testqi_ext<mode>_2, *<code>qi_ext<mode>_1_slp)
	(*<code>qi_ext<mode>_2_slp. *<code>qi_ext<mode>_0)
	(*<code>qi_ext2<mode>_0, *<code>qi_ext<mode>_1)
	(*<code>qi_ext<mode>_1_cc, *<code>qi_ext<mode>_1_cc)
	(*<code>qi_ext<mode>_2, *<code>qi_ext<mode>_3, *negqi_ext<mode>_1)
	(*one_cmplqi_ext<mode>_1, *ashlqi_ext<mode>_1, *<insn>qi_ext<mode>_1)
	(define_peephole2): Replace uses of extract_operator with
	extract_high_operator, matching only the first operand.
	Use zero_extract rather than match_op_dup when splitting.
2025-08-05 14:42:34 +01:00
Richard Biener df86ac52fc Remove hybrid SLP detection
The following removes hybrid SLP detection - it existed as sanity
check that all stmts are covered by SLP, but it proved itself
incomplete at that.  Its job is taken by early terminating SLP
build when SLP discovery fails for one root and the hope that
we now do catch all of them.

	* tree-vectorizer.h (vect_relevant::hybrid): Remove.
	* tree-vect-loop.cc (vect_analyze_loop_2): Do not call
	vect_detect_hybrid_slp.
	* tree-vect-slp.cc (maybe_push_to_hybrid_worklist): Remove.
	(vect_detect_hybrid_slp): Likewise.
2025-08-05 15:12:36 +02:00
Georg-Johann Lay 7e8d89ee82 AVR: target/121359: Remove -mlra and remains of reload.
PR target/121359
gcc/
	* config/avr/avr.h: Remove -mlra and remains of reload.
	* config/avr/avr.cc: Same.
	* config/avr/avr.md: Same.
	* config/avr/avr-log.cc: Same.
	* config/avr/avr-protos.h: Same.
	* config/avr/avr.opt: Same.
	* config/avr/avr.opt.urls: Same.
gcc/testsuite/
	* gcc.target/avr/torture/pr118591-1.c: Remove -mlra.
	* gcc.target/avr/torture/pr118591-2.c: Same.
2025-08-05 14:56:25 +02:00
H.J. Lu a58d770fa1 x86: Update *one_cmplqi_ext<mode>_1
After

commit 965564eafb
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Tue Jul 29 15:58:34 2025 +0100

    simplify-rtx: Simplify subregs of logic ops

combine generates

(set (zero_extract:SI (reg/v:SI 101 [ a ])
        (const_int 8 [0x8])
        (const_int 8 [0x8]))
    (not:SI (sign_extract:SI (reg:SI 107 [ b ])
            (const_int 8 [0x8])
            (const_int 8 [0x8]))))

instead of

(set (zero_extract:SI (reg/v:SI 101 [ a ])
        (const_int 8 [0x8])
        (const_int 8 [0x8]))
    (subreg:SI (not:QI (subreg:QI (sign_extract:SI (reg:SI 107 [ b ])
                    (const_int 8 [0x8])
                    (const_int 8 [0x8])) 0)) 0))

Update *one_cmplqi_ext<mode>_1 to support the new pattern.

	PR target/121306
	* config/i386/i386.md (*one_cmplqi_ext<mode>_1): Updated to
	support the new pattern.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-05 05:54:03 -07:00
Richard Biener 32b1be7eb4 tree-optimization/121395 - SLP of SIMD calls w/o LHS
The following records the alternate SLP instance entries coming from
stmts with stores that have no SSA def, like OMP SIMD calls without LHS.
There's a bit of fallout with having a SLP tree with a NULL vectype,
but nothing too gross.

	PR tree-optimization/121395
	* tree-vectorizer.h (_loop_vec_info::alternate_defs): New member.
	(LOOP_VINFO_ALTERNATE_DEFS): New.
	* tree-vect-stmts.cc (vect_stmt_relevant_p): Populate it.
	(vectorizable_simd_clone_call): Do not register a SLP def
	when there is none.
	* tree-vect-slp.cc (vect_build_slp_tree_1): Allow a NULL
	vectype when there's no LHS.  Allow all calls w/o LHS.
	(vect_analyze_slp): Process LOOP_VINFO_ALTERNATE_DEFS as
	SLP graph entries.
	(vect_make_slp_decision): Handle a NULL SLP_TREE_VECTYPE.
	(vect_slp_analyze_node_operations_1): Likewise.
	(vect_schedule_slp_node): Likewise.

	* gcc.dg/vect/pr59984.c: Adjust.
2025-08-05 13:10:25 +02:00
Richard Biener 9732b57443 Rename loop_vect SLP_TYPE and clarify docs
The following renames loop_vect to not_vect, removes the unused
HYBRID_SLP_STMT macro and rewords the slp_vect_type docs to clarify
STMT_SLP_TYPE is mainly used for BB vectorization, tracking what is
vectorized and what not.

	* tree-vectorizer.h (enum slp_vect_type): Rename loop_vect
	to not_vect, clarify docs.
	(HYBRID_SLP_STMT): Remove.
	* tree-vectorizer.cc (vec_info::new_stmt_vec_info): Adjust.
	* tree-vect-loop.cc (vect_analyze_loop_2): Likewise.
2025-08-05 13:09:32 +02:00
Richard Biener 11be9390a7 Prune some unnecessary PURE_SLP_STMT checks
We now never have hybrid SLP (if we have, we fail immediately).

	* tree-vect-data-refs.cc (vect_get_data_access_cost): Use
	ncopies == 1.
	* tree-vect-slp.cc (vect_remove_slp_scalar_calls): Remove
	hybrid/loop SLP skip.
	* tree-vect-stmts.cc (vectorizable_store): Remove pure SLP assert.
2025-08-05 13:09:32 +02:00
Richard Biener 5d55cd95e2 tree-optimization/121382 - avoid UB in IVOPTs inserted step computation
IVOPTs, when replacing an IV, inserts the computation of the new IVs
step in the loop preheader without considering the case of the loop
not iterating.  This means we have to ensure the step computation
does not invoke UB.  There is also SCEV which does not care about
signed arithmetic UB when re-associating expressions to form CHRECs,
so even when we know the loop iterates this is required.

	PR tree-optimization/121382
	* tree-ssa-loop-ivopts.cc (create_new_iv): Rewrite the IV
	step to defined form.

	* gcc.dg/torture/pr121382.c: New testcase.
2025-08-05 13:03:50 +02:00
Richard Biener afafae0972 tree-optimization/121370 - avoid UB in building a CHREC
When there is obvious UB involved in the process of re-associating
a series of IV increments to build up a CHREC, fail.  This catches
a few degenerate cases where SCEV introduces UB with its inherent
re-associating of IV increments.

	PR tree-optimization/121370
	* tree-scalar-evolution.cc (scev_dfs::add_to_evolution_1):
	Avoid UB integer overflow in accumulating CHREC_RIGHT.

	* gcc.dg/torture/pr121370.c: New testcase.
2025-08-05 13:03:50 +02:00
Yang Yujie bc97874bec bitint: Allow unused bits when testing extended _BitInt ABIs
In LoongArch psABI, large _BitInt(N) (N > 64) objects are only
extended to fill the highest 8-byte chunk that contains any used bit,
but the size of such a large _BitInt type is a multiple of their
16-byte alignment.  So there may be an entire unused 8-byte
chunk that is not filled by extension, and this chunk shouldn't be
checked when testing if the object is properly extended.

The original bitintext.h assumed that all bits within
sizeof(_BitInt(N)) beyond used bits are filled by extension.
This patch changes that for LoongArch and possibly
any future ports with a similar behavior.

P.S. For encoding this test as well as type-generic programming,
it would be nice to have a builtin function to obtain "N" at
compile time from _BitInt(N)-typed expressions.  But here
we stick to existing ones (__builtin_clrsbg / __builtin_clzg).

	* gcc.dg/bitintext.h (S, CEIL, PROMOTED_SIZE): Define.
	(BEXTC): Generalize to only check extension within PROMOTED_SIZE bits.
2025-08-05 12:59:30 +02:00
Yang Yujie eed0f5fa0e expand: Reduce unneeded _BitInt extensions
For targets that set the "extended" flag in TARGET_C_BITINT_TYPE_INFO,
we assume small _BitInts to be internally extended after arithmetic
operations. In this case, an extra extension during RTL expansion
can be avoided.

	* expr.cc (expand_expr_real_1): Do not call
	reduce_to_bit_field_precision if the target assumes the _BitInt
	results to be already extended.
	(EXTEND_BITINT): Same.
	* expr.h (bitint_extended): Declare the cache variable.
	* function.cc (prepare_function_start): Initialize it.
2025-08-05 12:57:27 +02:00
Yang Yujie a9b96c63d9 bitint: Allow mode promotion of _BitInt types
For targets that treat small _BitInts like the fundamental
integral types, we should allow their machine modes to be promoted
in the same way.

	* explow.cc (promote_function_mode): Add a case for
	small/medium _BitInts.
	(promote_mode): Same.
2025-08-05 12:52:27 +02:00
Jakub Jelinek 1e8ee6fa93 libstdc++: Remove 2 exports [PR121373]
On Mon, Aug 04, 2025 at 11:33:17AM -0400, Patrick Palka wrote:
> > @@ -1693,6 +1697,8 @@ export namespace std
> >    {
> >      using std::ranges::advance;
> >      using std::ranges::distance;
> > +    using std::ranges::iter_move;
> > +    using std::ranges::iter_swap;
>
> Actually a few lines above we already do:
>
>   // _Cpo is an implementation detail we can't avoid exposing; if we do the
>   // using in ranges directly, it conflicts with any friend functions of the
>   // same name, which is why the customization points are in an inline
>   // namespace in the first place.
>   namespace ranges::inline _Cpo
>   {
>     using _Cpo::iter_move;
>     using _Cpo::iter_swap;
>   }
>
> So I think we don't want to export iter_move and iter_swap directly...  Sorry
> for not catching this sooner :/

Here is a patch which does that.

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

	PR libstdc++/121373
	* src/c++23/std.cc.in (std::ranges::iter_move, std::ranges::iter_swap):
	Remove exports.
2025-08-05 08:27:05 +02:00
Jakub Jelinek ab7c16990f libcpp: Add testcase for CWG2579 [PR120778]
Another easy part from the paper.

Part of the CWG2579 has been already done in an earlier paper (with
test commits by Marek) and the remaining part is implemented correctly,
we diagnose as error when token pasting doesn't form a valid token.

Except that message
pasting """" and """" does not give a valid preprocessing token
looked weird and so I've updated the message to use %< and %> instead
of \" quoting.

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

	PR preprocessor/120778
	* macro.cc (paste_tokens): Use %< and %> instead of \" in
	diagnostics around %.*s.

	* g++.dg/DRs/dr2579.C: New test.
	* c-c++-common/cpp/va-opt-6.c: Expect ' rather than \" around
	tokens in incorrect pasting diagnostics.
	* gcc.dg/c23-attr-syntax-6.c: Likewise.
	* gcc.dg/cpp/paste12.c: Likewise.
	* gcc.dg/cpp/paste12-2.c: Likewise.
	* gcc.dg/cpp/paste14.c: Likewise.
	* gcc.dg/cpp/paste14-2.c: Likewise.
2025-08-05 08:21:55 +02:00
Gerald Pfeifer 2361b20f7a doc: Mark up function name in installation docs
gcc:
	PR target/69374
	* doc/install.texi (Configuration): Mark up atexit as code.
2025-08-05 07:44:47 +02:00
Pan Li 01a784e7c5 RISC-V: Fix scalar code-gen of unsigned SAT_MUL
The previous code-gen of scalar unsigned SAT_MUL, aka usmul.
Leverage the mulhs by mistake, it should be mulhu for the
hight bit result of mul.  Thus, this patch would like to make
it correct.

gcc/ChangeLog:

	* config/riscv/riscv.cc (riscv_expand_xmode_usmul): Take
	umulhu for high bits mul result.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/sat/sat_u_mul-1-u32-from-u64.c: Add mulhu
	asm check.
	* gcc.target/riscv/sat/sat_u_mul-1-u64-from-u128.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-08-05 09:37:10 +08:00
GCC Administrator aa558046c0 Daily bump. 2025-08-05 00:19:57 +00:00
Patrick Palka b9da8541c4 c++: add another testcase [PR121351]
Here's a previously accepted testcase that is now ambiguous after
r16-2771-gb9f1cc4e119da, since the uninstantiated constraints are
equivalent but the partially instantiated constraints aren't, so
the two member functions no longer correspond.

	PR c++/121351

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-using6.C: New test.
2025-08-04 17:09:28 -04:00
Patrick Palka b9f1cc4e11 c++: constrained memfn vs corresponding using [PR121351]
The b.f(42) calls in the below testcases started to get rejected as
ambiguous after r15-3740 which corrected our inheritedness tiebreaker to
only apply to constructors (and not all member functions) as per CWG2273.

But arguably these calls should still be valid regardless of the
tiebreaker because B::f corresponds to and therefore hides A::f, so
there should only be a single candidate in the first place.  This
doesn't happen because when determining correspondence we compare
the members' uninstantiated constraints instead of their partially
substituted constraints as in other declaration matching situations.
It doesn't really make sense to compare uninstantiated constraints
from two different template contexts.

This patch fixes this by substituting in outer template arguments before
comparing constraints of two potentially corresponding member functions.

	PR c++/121351
	PR c++/119859

gcc/cp/ChangeLog:

	* class.cc (add_method): Substitute outer template arguments
	into constraints before comparing them if the declarations are
	from different classes.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-using5.C: New test.
	* g++.dg/cpp2a/concepts-using5a.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-04 16:51:00 -04:00
Patrick Palka b51ca7d2f5 c++: constexpr evaluation of abi::__dynamic_cast [PR120620]
r13-3299 changed our internal declaration of __dynamic_cast to reside
inside the abi/__cxxabiv1:: namespace instead of the global namespace,
matching the real declaration.  This inadvertently made us now attempt
constexpr evaluation of user-written calls to abi::__dynamic_cast since
cxx_dynamic_cast_fn_p now also returns true for them, but we're not
prepared to handle arbitrary calls to __dynamic_cast, and therefore ICE.

This patch restores cxx_dynamic_cast_fn_p to return true only for
synthesized calls to __dynamic_cast, which can be distinguished by
DECL_ARTIFICIAL, since apparently the synthesized declaration of
__dynamic_cast doesn't get merged with the actual declaration.

	PR c++/120620

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_dynamic_cast_fn_p): Return true only
	for synthesized __dynamic_cast.

gcc/testsuite/ChangeLog:

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

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-04 16:43:33 -04:00
Hans-Peter Nilsson ac421ac33e defaults.h: Default MAX_FIXED_MODE_SIZE to MAX (BITS_PER_WORD * 2, 64)
The old GET_MODE_SIZE (DImode) (i.e. 64) made sense before
64-bitters.  Now the default is just a trap: when using the
default 64, things like TImode (128 bits) still mostly works,
but general corner cases related to computing large-size objects
numbers, like (1 << 64)/8 break, as exposed by
gcc.dg/pr105094.c.

So, keep the floor at 64 for 32-bitters and smaller targets, but
for larger targets, make it 2 * BITS_PER_WORD.  Also, express it
more directly with focus on BITS_PER_WORD, not the size of a
mode.  Add "by GCC internally" in an attempt to tell that this
is when gcc cooks something up, not when plain input uses a type
with such a mode.

	* defaults.h (MAX_FIXED_MODE_SIZE): Default to 2 * BITS_PER_WORD
	for larger-than-32-bitters.
	* doc/tm.texi.in (MAX_FIXED_MODE_SIZE): Adjust accordingly.  Tweak
	wording.
	* doc/tm.texi: Regenerate.
2025-08-04 18:02:50 +02:00
Jakub Jelinek 490c2c885e libstdc++: Add various missing exports [PR121373]
On Sat, Aug 02, 2025 at 09:05:07PM +0200, Jakub Jelinek wrote:
> Wonder how to automatically discover other missing exports (like in PR121373
> std::byteswap), maybe one could dig that stuff somehow from the raw
> dump (look for identifiers in std namespace (and perhaps inlined namespaces
> thereof at least) which don't start with underscore.

To answer that question, I wrote a simple plugin which just dumps the names
(which do not start with underscore) in std namespace (and its inlined
namespaces) and for non-inline namespaces in there which do not start with
underscore also recurses on those namespaces.

Plugin source in
https://gcc.gnu.org/pipermail/libstdc++/2025-August/062859.html

I went through it all now, using cppreference as a quick check for stuff
removed in C++17/C++20 and for everything added verified it is in
corresponding eel.is/c++-draft/*.syn etc. and looked it up in the libstdc++
headers for guarding macros.

After all the additions I've compiled std.cc with -std=c++20, -std=c++23 and
-std=c++26, the first one revealed std::ranges::shift_{left,right} emitted an
error in that case, the patch fixes that too.

2025-08-04  Jakub Jelinek  <jakub@redhat.com>
	    hexne  <printfne@gmail.com>

	PR libstdc++/121373
	* src/c++23/std.cc.in (std::ranges::shift_left,
	std::ranges::shift_right): Only export for C++23 and later.
	(std::ranges::fold_left_first_with_iter_result,
	std::ranges::fold_left_with_iter_result): Export.
	(std::byteswap): Export for C++23 and later.
	(std::ranges::iter_move, std::ranges::iter_swap): Export.
	(std::projected_value_t): Export for C++26 and later.
	(std::out_ptr_t, std::inout_ptr_t): Export.
	(std::ranges::iota_result): Export.
	(std::regex_constants): Export a lot of constants.
	(std::is_scoped_enum, std::is_scoped_enum_v): Export.
2025-08-04 17:19:30 +02:00
David Malcolm b963237a90 optinfo: use enum class
Modernization; no functional change intended.

gcc/ChangeLog:
	* dump-context.h: Convert "enum optinfo_item_kind" into
	"enum class kind" within class optinfo_item.
	* dumpfile.cc: Likewise.  Use "auto" in a few places.
	Convert "enum optinfo_kind" to "enum class kind" within
	class optinfo.
	* opt-problem.cc: Likewise.
	* optinfo-emit-json.cc: Likewise.
	* optinfo.cc: Likewise.
	* optinfo.h: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04 10:45:31 -04:00
David Malcolm 7969e4859e diagnostics: improve support for nesting levels [PR116253]
This patch adds support to sarif-replay for "nestingLevel"
from "P3358R0 SARIF for Structured Diagnostics"
https://wg21.link/P3358R0

Doing so revealed a bug where libgdiagnostics was always
creating new location_t values (and thus also
diagnostic_physical_location instances), rather than reusing
existing location_t values, leading to excess source printing.
The patch also fixes this bug, adding a new flag to libgdiagnostics
for debugging physical locations, and exposing this in sarif-replay
via a new "-fdebug-physical-locations" maintainer option.

Finally, the patch adds test coverage for the HTML sink's output
of nested diagnostics (both from a GCC plugin, and from sarif-replay).

gcc/ChangeLog:
	PR diagnostics/116253
	* diagnostics/context.cc (context::set_nesting_level): New.
	* diagnostics/context.h (context::set_nesting_level): New decl.
	* doc/libgdiagnostics/topics/compatibility.rst
	(LIBGDIAGNOSTICS_ABI_5): New.
	* doc/libgdiagnostics/topics/physical-locations.rst
	(diagnostic_manager_set_debug_physical_locations): New.
	* libgdiagnostics++.h (manager::set_debug_physical_locations):
	New.
	* libgdiagnostics-private.h
	(private_diagnostic_set_nesting_level): New decl.
	* libgdiagnostics.cc (diagnostic_manager::diagnostic_manager):
	Initialize m_debug_physical_locations.
	(diagnostic_manager::new_location_from_file_and_line): Add debug
	printing.
	(diagnostic_manager::new_location_from_file_line_column):
	Likewise.
	(diagnostic_manager::new_location_from_range): Likewise.
	(diagnostic_manager::set_debug_physical_locations): New.
	(diagnostic_manager::ensure_linemap_for_file_and_line): Avoid
	redundant calls to linemap_add.
	(diagnostic_manager::new_location): Add debug printing.
	(diagnostic_manager::m_debug_physical_locations): New field.
	(diagnostic::diagnostic): Initialize m_nesting_level.
	(diagnostic::get_nesting_level): New accessor.
	(diagnostic::set_nesting_level): New.
	(diagnostic::m_nesting_level): New field.
	(diagnostic_manager::emit_va): Set and reset the nesting level
	of the context from that of the diagnostic.
	(diagnostic_manager_set_debug_physical_locations): New.
	(private_diagnostic_set_nesting_level): New.
	* libgdiagnostics.h
	(diagnostic_manager_set_debug_physical_locations): New decl.
	* libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_5): New.
	* libsarifreplay.cc (sarif_replayer::handle_result_obj): Support
	the "nestingLevel" property.
	* libsarifreplay.h (replay_options::m_debug_physical_locations):
	New field.
	* sarif-replay.cc: Add -fdebug-physical-locations.

gcc/testsuite/ChangeLog:
	PR diagnostics/116253
	* gcc.dg/plugin/diagnostic-test-nesting-html.c: New test.
	* gcc.dg/plugin/diagnostic-test-nesting-html.py: New test script.
	* gcc.dg/plugin/plugin.exp: Add it.
	* libgdiagnostics.dg/test-multiple-lines.c: Update expected output
	to show fix-it hint.
	* sarif-replay.dg/2.1.0-valid/nested-diagnostics-1.sarif: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04 10:45:31 -04:00
David Malcolm 0fb3000386 diagnostics: avoid stray trailing space in html sink in sarif-replay [PR116792]
For the common case where a diagnostic has no metadata, sarif-replay's
html output was adding a stray space followed by an empty <div> for
the metadata.

Fixed thusly.

gcc/ChangeLog:
	PR diagnostics/116792
	* diagnostics/html-sink.cc
	(html_builder::make_element_for_diagnostic): Don't add the
	metadata element if it's empty.
	(html_builder::make_element_for_metadata): Return null rather than
	an empty element.

gcc/testsuite/ChangeLog:
	PR diagnostics/116792
	* gcc.dg/plugin/diagnostic-test-graphs-html.py: Remove trailing
	space from expected text of message.
	* sarif-replay.dg/2.1.0-valid/embedded-links-check-html.py:
	Likewise.
	* sarif-replay.dg/2.1.0-valid/graphs-check-html.py: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04 10:45:31 -04:00
David Malcolm 74f59bf10d diagnostics: move diagnostics::counters to its own header
gcc/ChangeLog:
	* diagnostics/context.h: Move struct counters to its own header
	and include it.
	* diagnostics/counters.h: New file, from the above.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04 10:45:30 -04:00
David Malcolm 7dea2582b3 diagnostics: split source_printing_options out into its own header
No functional change intended.

gcc/ChangeLog:
	* diagnostics/context.h: Split struct source_printing_options out
	into "diagnostics/source-printing-options.h" and include it.
	* diagnostics/source-printing-options.h: New file, from the above.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04 10:45:30 -04:00
David Malcolm 268ec60da0 diagnostics: rename option_manager to option_id_manager and split out from context.h
This patch splits out class option_manager to its own header,
and renames it to class option_id_manager to better describe its
purpose.

No functional change intended.

gcc/ChangeLog:
	* diagnostics/context.cc: Update for renaming of option_manager to
	option_id_manager and of context::m_option_mgr to
	context::m_option_id_mgr.
	* diagnostics/context.h: Likewise, moving class declaration to a
	new diagnostics/option-id-manager.h.
	* diagnostics/lazy-paths.cc: Likewise.
	* diagnostics/option-id-manager.h: New file, from material in
	diagnostics/context.h.
	* lto-wrapper.cc: Update for renaming of option_manager to
	option_id_manager.
	* opts-common.cc: Likewise.
	* opts-diagnostic.h: Likewise.
	* opts.cc: Likewise.
	* toplev.cc: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04 10:45:30 -04:00
David Malcolm 3cff171b24 diagnostics: fix comment in buffering.h
gcc/ChangeLog:
	* diagnostics/buffering.h: Update comment to refer to output sinks
	rather than output formats.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04 10:45:30 -04:00
David Malcolm c125e86853 gimple-warn-recursion.cc: add missing auto_diagnostic_group
gcc/ChangeLog:
	* gimple-warn-recursion.cc (pass_warn_recursion::execute): Add
	missing auto_diagnostic_group.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04 10:45:29 -04:00
Konstantinos Eleftheriou be377ef9ce asf: Fix null pointer dereference in is_store_forwarding [PR121303]
We were calling `is_store_forwarding` with a NULL value for `off_val`,
which was causing a null pointer dereference in `is_constant`, leading
to an ICE.

This patch updates the call to `is_constant` in `is_store_forwarding`
and adds a check for `off_val`, in order to update it with the right
value.

Bootstrapped/regtested on AArch64 and x86_64.

	PR rtl-optimization/121303

gcc/ChangeLog:

	* avoid-store-forwarding.cc (is_store_forwarding): Add check
	for `off_val` in `is_store_forwarding`.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr121303.c: New test.
2025-08-04 15:34:03 +02:00
Jakub Jelinek 102179f11d c++: Add #line testcase for CWG2580 [PR120778]
Contrary to what the paper says, I think for #line directives we diagnose
everything we should (sure, some diagnostics are pedwarns).

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

	PR preprocessor/120778
	* g++.dg/DRs/dr2580.C: New test.
2025-08-04 15:28:29 +02:00
Viljar Indus bb80bcec3b ada: Update Assertion_Policy handling in GNATProve mode
Previously in GNATProve_Mode the frontend would overwrite all of
the assertion policies to check in order to force the generation
of all of the assertions.

This however prevents GNATProve from performing policy related
checks in the tool. Since they are all artificially changed to
check.

This patch removes the modifications to the applicable assertion
policies and instead prevents code from ignored entities being
removed when in GNATProve_Mode.

gcc/ada/ChangeLog:

	* contracts.adb: Use Is_Ignored_In_Codegen instead of just
	using Is_Ignored.
	* exp_ch6.adb: Likewise.
	* exp_prag.adb: Likewise.
	* exp_util.adb: Likewise.
	* frontend.adb: Avoid removal of ignored nodes in GNATProve_Mode.
	* gnat1drv.adb: Avoid forcing Assertions_Enabled in GNATProve_Mode.
	* lib-writ.adb (Write_With_File_Names): Avoid early exit
	with ignored entities in GNATProve_Mode.
	* lib-xref.adb: Likewise.
	* opt.adb: Remove check for Assertions_Enabled.
	* sem_attr.adb: Use Is_Ignored_In_Codegen instead of Is_Ignored.
	* sem_ch13.adb: Likewise. Additionally always add predicates in
	GNATProve_Mode.
	* sem_prag.adb: Likewise. Additionally remove modifications
	to applied policies in GNATProve_Mode.
	* sem_util.adb (Is_Ignored_In_Codegen): New function that overrides
	Is_Ignored in GNATProve_Mode and Codepeer_Mode.
	(Is_Ignored_Ghost_Pragma_In_Codegen): Likewise for
	Is_Ignored_Ghost_Pragma.
	(Is_Ignored_Ghost_Entity_In_Codegen): Likewise for
	Is_Ignored_Ghost_Entity.
	(Policy_In_List): Remove overriding of policies in GNATProve_Mode.
	* sem_util.ads: Add specs for new functions.
	* (Predicates_Enabled): Always generate predicates in
	GNATProve_Mode.
2025-08-04 15:04:12 +02:00
Bob Duff b0e249afc6 ada: Make pp and friends more robust
Print_Node_Ref, which is called by pp, sometimes calls
Compile_Time_Known_Value, which blows up if Entity (N)
is empty. Rearrange the tests here, and test for
Present (Entity (N)) before calling Compile_Time_Known_Value.
Remove test "Nkind (N) in N_Subexpr", which is redundant with other
tests.

We don't want to make Compile_Time_Known_Value more
robust; you shouldn't call it on half-baked nodes.
But ideally pp should be able to print such nodes.

This change fixes one of many such cases.

gcc/ada/ChangeLog:

	* treepr.adb (Print_Node_Ref): Protect against
	Entity (N) being empty before calling
	Compile_Time_Known_Value.
2025-08-04 15:04:11 +02:00
Viljar Indus 0f048a6840 ada: Check Compile_Time_Errors removed in Ghost code
gcc/ada/ChangeLog:

	* sem_prag.adb (Validate_Compile_Time_Warning_Errors):
	Check if the original compile time pragma was replaced and
	validate the original node instead.
2025-08-04 15:04:11 +02:00
Viljar Indus bc2edee538 ada: Refactor Validate_Compile_Time_Warning_Or_Error
Simplify the creation of the control characters in
Validate_Compile_Time_Warning_Or_Error.

gcc/ada/ChangeLog:

	* sem_prag.adb (Validate_Compile_Time_Warning_Or_Error):
	simplify the implementation.
2025-08-04 15:04:10 +02:00
Steve Baird 0aebb77ced ada: Implement accessibility legality check for discriminated function result.
If a function result type has an access discriminant, then we already
generate a run-time accessibility check for a return statement. But if
we know statically that the check (if executed) is going to fail, then
that should be rejected at compile-time as a violation of RM 6.5(5.9).
Add this additional compile-time check.

gcc/ada/ChangeLog:

	* exp_ch6.adb (Apply_Access_Discrims_Accessibility_Check): If the
	accessibility level being checked is known statically, then
	statically check it against the level of the function being
	returned from.
2025-08-04 15:04:10 +02:00
Viljar Indus bad0a5c562 ada: Keep Ghost_Mode related variables in a record
Simplify the storing process for ghost mode related variables and
make the process more extendable if new ghost mode related features
are added.

gcc/ada/ChangeLog:

	* atree.adb: update references to Ghost_Mode.
	* exp_ch3.adb: use a structure type to store all of the existing
	ghost mode related state variables.
	* exp_disp.adb: Likewise.
	* exp_spark.adb: Likewise.
	* exp_util.adb: Likewise.
	* expander.adb: Likewise.
	* freeze.adb: Likewise and replace references to existing ghost
	mode variables.
	* ghost.adb (Install_Ghost_Region): install the changes of
	the region in to the new Ghost_Config structure.
	(Restore_Ghost_Region): Use the new Ghost_Config instead.
	In general replace all references to the existing ghost mode
	variables with the new structure equivalent.
	* ghost.ads (Restore_Ghost_Region): update the spec.
	* opt.ads (Ghost_Config_Type): A new type that has two of the
	previous ghost code related global variables as memembers -
	Ghost_Mode and Ignored_Ghost_Region.
	(Ghost_Config) New variable to store the previous Ghost_Mode and
	Ignored_Ghost_Region info.
	* rtsfind.adb: Replace references to existing ghost mode variables.
	* sem.adb: Likewise.
	* sem_ch12.adb: Likewise.
	* sem_ch13.adb: Likewise.
	* sem_ch3.adb: Likewise.
	* sem_ch5.adb: Likewise.
	* sem_ch6.adb: Likewise.
	* sem_ch7.adb: Likewise.
	* sem_prag.adb: Likewise.
	* sem_util.adb: Likewise.
2025-08-04 15:04:10 +02:00
Steve Baird 96613a6e3e ada: Avoid generating incorrect warning
Do not generate a warning stating that the size of a formal parameter
is 8 bits unless the size of the formal parameter is 8 bits.

gcc/ada/ChangeLog:

	* freeze.adb (Freeze_Profile): Do not emit a warning stating that
	a formal parameter's size is 8 if the parameter's size is not 8.
2025-08-04 15:04:09 +02:00
Viljar Indus a550f2309c ada: Fix code quality issue in table.adb
gcc/ada/ChangeLog:

	* table.adb (Max): Move variable to the body and initialize
	it with the same value as in the Init function.
	* table.ads (Max): Likewise.
2025-08-04 15:04:09 +02:00
Bob Duff 3c3192bcfe ada: Misc parser cleanup
...which might make it easier to deal with incorrectly shared
subtrees created during parsing.

There were several Idents arrays, with duplicated code and commentary.
And the related code had somewhat diverged -- different comments,
different index subtypes (Pos vs. Int), etc.

DRY: Move at least some of the code into Par.Util. Raise
Program_Error if the array overflows; there is really no
reason not to check, along with several comments saying
we don't check. In the unlikely event that the array
overflows, the compiler will now crash, which seems better
than erroneous execution (which could conceivably cause
bad code to be generated).

Move the block comments titled
"Handling Semicolon Used in Place of IS" and
"Handling IS Used in Place of Semicolon" so they
are together, which seems obviously desirable.
Rewrite the latter comment.
No need to denigrate other parsers.

gcc/ada/ChangeLog:

	* par.adb: Move and rewrite some comments.
	(Util): Shared code and comments for dealing with
	defining_identifier_lists.
	* par-util.adb (Append): Shared code for appending
	one identifier onto Defining_Identifiers.
	(P_Def_Ids): Shared code for parsing a defining_identifier_list.
	Unfortunately, this is not used in all cases, because some of
	them mix in sophisticated error recovery, which we do not
	modify here.
	* par-ch12.adb (P_Formal_Object_Declarations):
	Use Defining_Identifiers and related code.
	* par-ch3.adb (P_Identifier_Declarations): Likewise.
	(P_Known_Discriminant_Part_Opt): Likewise.
	(P_Component_Items): Likewise.
	* par-ch6.adb (P_Formal_Part): Likewise.
2025-08-04 15:04:08 +02:00
Richard Biener 446aac86a4 Fail early when SLP instance build fails
The following makes us fail earlier when parts of the SLP build fails.
Currently we rely on hybrid stmt detection later to discover not all
stmts are covered by SLP, but this code should go away.  I've also
seen a case of a missed gcond SLP build that went undetected.  So
the following makes us fail during vect_analyze_slp if any of the
SLP instances we expect to discover fails.

	* tree-vect-slp.cc (vect_analyze_slp): When analyzing a loop
	and slp instance discovery fails, immediately fail the whole
	process.
2025-08-04 14:56:14 +02:00
Jakub Jelinek b9f443b617 libcpp: Use pedwarn instead of warning for CWG2578 diagnostics [PR120778]
This is another case which changed from compile time undefined behavior
to ill-formed, diagnostic required.  Now, we warn on this, so pedantically
that is good enough, maybe all we need is a testcase, but the following
patch changes it to a pedwarn for C++26.

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

	PR preprocessor/120778
	* macro.cc (stringify_arg): For C++26 emit a pedarn instead of warning
	for \ at the end of stringification.

	* g++.dg/DRs/dr2578.C: New test.
2025-08-04 14:27:14 +02:00
Tomasz Kamiński d49d359b0c libstdc++: Fix dereferencing of std::indirect xvalues [PR121128]
Forr rvalues the _Self parameter deduces a non-reference type. Consequently,
((_Self)__self) moved the object to a temporary, which then destroyed on
function exit.

This patch fixes this by using a C-style cast __self to (const indirect&).
This not only resolves the above issue but also correctly handles types that
are derived (publicly and privately) from indirect. Allocator requirements in
[allocator.requirements.general] p22 guarantee that dereferencing const _M_objp
works with equivalent semantics to dereferencing _M_objp.

	PR libstdc++/121128

libstdc++-v3/ChangeLog:

	* include/bits/indirect.h (indirect::operator*):
	Cast __self to approparietly qualified indirect.
	* testsuite/std/memory/indirect/access.cc: New test.
	* testsuite/std/memory/polymorphic/access.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-04 13:19:24 +02:00
Richard Sandiford d9f34c951a aarch64: Check the mode of SVE ACLE function results
After previous patches, we should always get a VNx16BI result
for ACLE intrinsics that return svbool_t.  This patch adds
an assert that checks a more general condition than that.

gcc/
	* config/aarch64/aarch64-sve-builtins.cc
	(function_expander::expand): Assert that the return value
	has an appropriate mode.
2025-08-04 11:45:36 +01:00
Richard Sandiford f4915d9b66 aarch64: Use VNx16BI for svdupq_b*
This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the predicate forms of svdupq.

The general predicate expansion builds an equivalent integer vector
and then compares it with zero.  This patch therefore relies on
the earlier patches to the comparison patterns.

gcc/
	* config/aarch64/aarch64-protos.h
	(aarch64_convert_sve_data_to_pred): Remove the mode argument.
	* config/aarch64/aarch64.cc
	(aarch64_sve_emit_int_cmp): Allow PRED_MODE to be VNx16BI or
	the natural predicate mode for the data mode.
	(aarch64_convert_sve_data_to_pred): Remove the mode argument
	and instead always create a VNx16BI result.
	(aarch64_expand_sve_const_pred): Update call accordingly.
	* config/aarch64/aarch64-sve-builtins-base.cc
	(svdupq_impl::expand): Likewise, ensuring that the result
	has mode VNx16BI.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/dupq_13.c: New test.
2025-08-04 11:45:36 +01:00
Richard Sandiford b768e2786f aarch64: Use VNx16BI for svdup_b*
This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the predicate forms of svdup.

gcc/
	* config/aarch64/aarch64-protos.h
	(aarch64_emit_sve_pred_vec_duplicate): Declare.
	* config/aarch64/aarch64.cc
	(aarch64_emit_sve_pred_vec_duplicate): New function.
	* config/aarch64/aarch64-sve.md (vec_duplicate<PRED_ALL:mode>): Use it.
	* config/aarch64/aarch64-sve-builtins-base.cc
	(svdup_impl::expand): Handle boolean values specially.  Check for
	constants and fall back on aarch64_emit_sve_pred_vec_duplicate
	for the variable case, ensuring that the result has mode VNx16BI.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/dup_1.c: New test.
2025-08-04 11:45:35 +01:00
Richard Sandiford 4ff15c5a99 aarch64: Use VNx16BI for svpnext*
This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the svpnext* intrinsics.

gcc/
	* config/aarch64/iterators.md (PNEXT_ONLY): New int iterator.
	* config/aarch64/aarch64-sve.md
	(@aarch64_sve_<sve_pred_op><mode>): Restrict SVE_PITER pattern
	to VNx16BI_ONLY.
	(@aarch64_sve_<sve_pred_op><mode>): New PNEXT_ONLY pattern for
	PRED_HSD.
	(*aarch64_sve_<sve_pred_op><mode>): Likewise.
	(*aarch64_sve_<sve_pred_op><mode>_cc): Likewise.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/pnext_3.c: New test.
2025-08-04 11:45:34 +01:00
Richard Sandiford 28a4dfe807 aarch64: Use VNx16BI for sv(n)match*
This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the svmatch* and svnmatch*
intrinsics.

gcc/
	* config/aarch64/aarch64-sve2.md (@aarch64_pred_<sve_int_op><mode>):
	Split SVE2_MATCH pattern into a VNx16QI_ONLY define_ins and a
	VNx8HI_ONLY define_expand.  Use a VNx16BI destination for the latter.
	(*aarch64_pred_<sve_int_op><mode>): New SVE2_MATCH pattern for
	VNx8HI_ONLY.
	(*aarch64_pred_<sve_int_op><mode>_cc): Likewise.

gcc/testsuite/
	* gcc.target/aarch64/sve2/acle/general/match_4.c: New test.
	* gcc.target/aarch64/sve2/acle/general/nmatch_1.c: Likewise.
2025-08-04 11:45:34 +01:00
Richard Sandiford 6e26bf6900 aarch64: Use VNx16BI for svac*
This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the svac* intrinsics (floating-
point compare absolute).

gcc/
	* config/aarch64/aarch64-sve.md (@aarch64_pred_fac<cmp_op><mode>):
	Replace with...
	(@aarch64_pred_fac<cmp_op><mode>_acle): ...this new expander.
	(*aarch64_pred_fac<cmp_op><mode>_strict_acle): New pattern.
	* config/aarch64/aarch64-sve-builtins-base.cc
	(svac_impl::expand): Update accordingly.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/acge_1.c: New test.
	* gcc.target/aarch64/sve/acle/general/acgt_1.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/acle_1.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/aclt_1.c: Likewise.
2025-08-04 11:45:33 +01:00
Richard Sandiford 2cf2cc8183 aarch64: Use VNx16BI for floating-point svcmp*
This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the floating-point forms of svcmp*.

gcc/
	* config/aarch64/aarch64-sve.md (@aarch64_pred_fcm<cmp_op><mode>_acle)
	(*aarch64_pred_fcm<cmp_op><mode>_acle, @aarch64_pred_fcmuo<mode>_acle)
	(*aarch64_pred_fcmuo<mode>_acle): New patterns.
	* config/aarch64/aarch64-sve-builtins-base.cc
	(svcmp_impl::expand, svcmpuo_impl::expand): Use them.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/cmpeq_6.c: New test.
	* gcc.target/aarch64/sve/acle/general/cmpge_9.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpgt_9.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmple_9.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmplt_9.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpne_5.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpuo_1.c: Likewise.
2025-08-04 11:45:33 +01:00
Richard Sandiford 690586e796 aarch64: Use VNx16BI for svcmp*_wide
This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the svcmp*_wide intrinsics.

Since the only uses of these patterns are for ACLE intrinsics,
there didn't seem much point adding an "_acle" suffix.

gcc/
	* config/aarch64/aarch64-sve.md (@aarch64_pred_cmp<cmp_op><mode>_wide):
	Split into VNx16QI_ONLY and SVE_FULL_HSI patterns.  Use VNx16BI
	results for both.
	(*aarch64_pred_cmp<cmp_op><mode>_wide): New pattern.
	(*aarch64_pred_cmp<cmp_op><mode>_wide_cc): Likewise.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/cmpeq_5.c: New test.
	* gcc.target/aarch64/sve/acle/general/cmpge_7.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpge_8.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpgt_7.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpgt_8.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmple_7.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmple_8.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmplt_7.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmplt_8.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpne_4.c: Likewise.
2025-08-04 11:45:32 +01:00
Richard Sandiford dec30d6f9b aarch64: Drop unnecessary GPs in svcmp_wide PTEST patterns
Patterns that fuse a predicate operation P with a PTEST use
aarch64_sve_same_pred_for_ptest_p to test whether the governing
predicates of P and the PTEST are compatible.  Most patterns were also
written as define_insn_and_rewrites, with the rewrite replacing P's
original governing predicate with PTEST's.  This ensures that we don't,
for example, have both a .H PTRUE for the PTEST and a .B PTRUE for a
comparison that feeds the PTEST.

The svcmp_wide* patterns were missing this rewrite, meaning that we did
have redundant PTRUEs.

gcc/
	* config/aarch64/aarch64-sve.md
	(*aarch64_pred_cmp<cmp_op><mode>_wide_cc): Turn into a
	define_insn_and_rewrite and rewrite the governing predicate
	of the comparison so that it is identical to the PTEST's.
	(*aarch64_pred_cmp<cmp_op><mode>_wide_ptest): Likewise.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/cmpeq_1.c: Check the number
	of PTRUEs.
	* gcc.target/aarch64/sve/acle/general/cmpge_5.c: New test.
	* gcc.target/aarch64/sve/acle/general/cmpge_6.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpgt_5.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpgt_6.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmple_5.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmple_6.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmplt_5.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmplt_6.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpne_3.c: Likewise.
2025-08-04 11:45:32 +01:00
Richard Sandiford 5e6ccffab9 aarch64: Use the correct GP mode in the svcmp_wide patterns
The patterns for the svcmp_wide intrinsics used a VNx16BI
input predicate for all modes, instead of the usual <VPRED>.
That unnecessarily made some input bits significant, but more
importantly, it triggered an ICE in aarch64_sve_same_pred_for_ptest_p
when testing whether a comparison pattern could be fused with a PTEST.

A later patch will add tests for other comparisons.

gcc/
	* config/aarch64/aarch64-sve.md (@aarch64_pred_cmp<cmp_op><mode>_wide)
	(*aarch64_pred_cmp<cmp_op><mode>_wide_cc): Use <VPRED> instead of
	VNx16BI for the governing predicate.
	(*aarch64_pred_cmp<cmp_op><mode>_wide_ptest): Likewise.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/cmpeq_1.c: Add more tests.
2025-08-04 11:45:31 +01:00
Richard Sandiford c17b47b9c0 aarch64: Use VNx16BI for non-widening integer svcmp*
This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the non-widening integer forms
of svcmp*.  The handling of the PTEST patterns is similar to that
for the earlier svwhile* patch.

Unfortunately, on its own, this triggers a failure in the
pred_clobber_*.c tests.  The problem is that, after the patch,
we have a comparison instruction followed by a move into p0.
Combine combines the instructions together, so that the destination
of the comparison is the hard register p0 rather than a pseudo.
This defeats IRA's make_early_clobber_and_input_conflicts, which
requires the source and destination to be pseudo registers.

Before the patch, there was a subreg move between the comparison
and the move into p0, so it was that subreg move that ended up
with a hard register destination.

Arguably the fix for PR87600 should be extended to destination
registers as well as source registers, but in the meantime,
the patch just disables combine for these tests.  The tests are
really testing the constraints and register allocation.

gcc/
	* config/aarch64/aarch64-sve.md (@aarch64_pred_cmp<cmp_op><mode>_acle)
	(*aarch64_pred_cmp<cmp_op><mode>_acle, *cmp<cmp_op><mode>_acle_cc)
	(*cmp<cmp_op><mode>_acle_and): New patterns that yield VNx16BI
	results for all element types.
	* config/aarch64/aarch64-sve-builtins-base.cc
	(svcmp_impl::expand): Use them.
	(svcmp_wide_impl::expand): Likewise when implementing an svcmp_wide
	against an in-range constant.

gcc/testsuite/
	* gcc.target/aarch64/sve/pred_clobber_1.c: Disable combine.
	* gcc.target/aarch64/sve/pred_clobber_2.c: Likewise.
	* gcc.target/aarch64/sve/pred_clobber_3.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpeq_2.c: Add more cases.
	* gcc.target/aarch64/sve/acle/general/cmpeq_4.c: New test.
	* gcc.target/aarch64/sve/acle/general/cmpge_1.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpge_2.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpge_3.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpge_4.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpgt_1.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpgt_2.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpgt_3.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpgt_4.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmple_1.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmple_2.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmple_3.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmple_4.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmplt_1.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmplt_2.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmplt_3.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmplt_4.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpne_1.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/cmpne_2.c: Likewise.
2025-08-04 11:45:31 +01:00
Richard Sandiford 2b419b7091 aarch64: Use VNx16BI for svunpklo/hi_b
This patch continues the work of making ACLE intrinsics use VNx16BI
for svbool_t results.  It deals with the svunpk* intrinsics.

gcc/
	* config/aarch64/aarch64-sve.md (@aarch64_sve_punpk<perm_hilo>_acle)
	(*aarch64_sve_punpk<perm_hilo>_acle): New patterns.
	* config/aarch64/aarch64-sve-builtins-base.cc
	(svunpk_impl::expand): Use them for boolean svunpk*.

gcc/testsuite/
	* gcc.target/aarch64/sve/acle/general/unpkhi_1.c: New test.
	* gcc.target/aarch64/sve/acle/general/unpklo_1.c: Likewise.
2025-08-04 11:45:30 +01:00
Richard Sandiford dcb02ff822 aarch64: Use VNx16BI for svrev_b* [PR121294]
The previous patch for PR121294 handled svtrn1/2, svuzp1/2, and svzip1/2.
This one extends it to handle svrev intrinsics, where the same kind of
wrong code can be generated.

gcc/
	PR target/121294
	* config/aarch64/aarch64.md (UNSPEC_REV_PRED): New unspec.
	* config/aarch64/aarch64-sve.md (@aarch64_sve_rev<mode>_acle)
	(*aarch64_sve_rev<mode>_acle): New patterns.
	* config/aarch64/aarch64-sve-builtins-base.cc
	(svrev_impl::expand): Use the new patterns for boolean svrev.

gcc/testsuite/
	PR target/121294
	* gcc.target/aarch64/sve/acle/general/rev_2.c: New test.
2025-08-04 11:45:29 +01:00
Richard Sandiford 13c8c9d8d1 aarch64: Use VNx16BI for more permutations [PR121294]
The patterns for the predicate forms of svtrn1/2, svuzp1/2,
and svzip1/2 are shared with aarch64_vectorize_vec_perm_const.
The .H, .S, and .D forms operate on VNx8BI, VNx4BI, and VNx2BI
respectively.  Thus, for all four element widths, there is one
significant bit per element, for both the inputs and the output.

That's appropriate for aarch64_vectorize_vec_perm_const but not
for the ACLE intrinsics, where every bit of the output is
significant, and where every bit of the selected input elements
is therefore also significant.  The current expansion can lead
the optimisers to simplify inputs by changing the upper bits
of the input elements (since the current patterns claim that
those bits don't matter), which in turn leads to wrong code.

The ACLE expansion should operate on VNx16BI instead, for all
element widths.

There was already a pattern for a VNx16BI-only form of TRN1, for
constructing certain predicate constants.  The patch generalises it to
handle the other five permutations as well.  For the reasons given in
the comments, this is done by making the permutation unspec an operand
to a new UNSPEC_PERMUTE_PRED, rather than overloading the existing
unspecs, and rather than adding a new unspec for each permutation.

gcc/
	PR target/121294
	* config/aarch64/iterators.md (UNSPEC_TRN1_CONV): Delete.
	(UNSPEC_PERMUTE_PRED): New unspec.
	* config/aarch64/aarch64-sve.md (@aarch64_sve_trn1_conv<mode>):
	Replace with...
	(@aarch64_sve_<perm_insn><mode>_acle)
	(*aarch64_sve_<perm_insn><mode>_acle): ...these new patterns.
	* config/aarch64/aarch64.cc (aarch64_expand_sve_const_pred_trn):
	Update accordingly.
	* config/aarch64/aarch64-sve-builtins-functions.h
	(binary_permute::expand): Use the new _acle patterns for
	predicate operations.

gcc/testsuite/
	PR target/121294
	* gcc.target/aarch64/sve/acle/general/perm_2.c: New test.
	* gcc.target/aarch64/sve/acle/general/perm_3.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/perm_4.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/perm_5.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/perm_6.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/perm_7.c: Likewise.
2025-08-04 11:45:29 +01:00
Richard Sandiford f702b593e7 aarch64: Use VNx16BI for more SVE WHILE* results [PR121118]
PR121118 is about a case where we try to construct a predicate
constant using a permutation of a PFALSE and a WHILELO.  The WHILELO
is a .H operation and its result has mode VNx8BI.  However, the
permute instruction expects both inputs to be VNx16BI, leading to
an unrecognisable insn ICE.

VNx8BI is effectively a form of VNx16BI in which every odd-indexed
bit is insignificant.  In the PR's testcase that's OK, since those
bits will be dropped by the permutation.  But if the WHILELO had been a
VNx4BI, so that only every fourth bit is significant, the input to the
permutation would have had undefined bits.  The testcase in the patch
has an example of this.

This feeds into a related ACLE problem that I'd been meaning to
fix for a long time: every bit of an svbool_t result is significant,
and so every ACLE intrinsic that returns an svbool_t should return a
VNx16BI.  That doesn't currently happen for ACLE svwhile* intrinsics.

This patch fixes both issues together.

We still need to keep the current WHILE* patterns for autovectorisation,
where the result mode should match the element width.  The patch
therefore adds a new set of patterns that are defined to return
VNx16BI instead.  For want of a better scheme, it uses an "_acle"
suffix to distinguish these new patterns from the "normal" ones.

The formulation used is:

  (and:VNx16BI (subreg:VNx16BI normal-pattern 0) C)

where C has mode VNx16BI and is a canonical ptrue for normal-pattern's
element width (so that the low bit of each element is set and the upper
bits are clear).

This is a bit clunky, and leads to some repetition.  But it has two
advantages:

* After g:965564eafb721f8000013a3112f1bba8d8fae32b, converting the
  above expression back to normal-pattern's mode will reduce to
  normal-pattern, so that the pattern for testing the result using a
  PTEST doesn't change.

* It gives RTL optimisers a bit more information, as the new tests
  demonstrate.

In the expression above, C is matched using a new "special" predicate
aarch64_ptrue_all_operand, where "special" means that the mode on the
predicate is not necessarily the mode of the expression.  In this case,
C always has mode VNx16BI, but the mode on the predicate indicates which
kind of canonical PTRUE is needed.

gcc/
	PR testsuite/121118
	* config/aarch64/iterators.md (VNx16BI_ONLY): New mode iterator.
	* config/aarch64/predicates.md (aarch64_ptrue_all_operand): New
	predicate.
	* config/aarch64/aarch64-sve.md
	(@aarch64_sve_while_<while_optab_cmp><GPI:mode><VNx16BI_ONLY:mode>_acle)
	(@aarch64_sve_while_<while_optab_cmp><GPI:mode><PRED_HSD:mode>_acle)
	(*aarch64_sve_while_<while_optab_cmp><GPI:mode><PRED_HSD:mode>_acle)
	(*while_<while_optab_cmp><GPI:mode><PRED_HSD:mode>_acle_cc): New
	patterns.
	* config/aarch64/aarch64-sve-builtins-functions.h
	(while_comparison::expand): Use the new _acle patterns that
	always return a VNx16BI.
	* config/aarch64/aarch64-sve-builtins-sve2.cc
	(svwhilerw_svwhilewr_impl::expand): Likewise.
	* config/aarch64/aarch64.cc
	(aarch64_sve_move_pred_via_while): Likewise.

gcc/testsuite/
	PR testsuite/121118
	* gcc.target/aarch64/sve/acle/general/pr121118_1.c: New test.
	* gcc.target/aarch64/sve/acle/general/whilele_13.c: Likewise.
	* gcc.target/aarch64/sve/acle/general/whilelt_6.c: Likewise.
	* gcc.target/aarch64/sve2/acle/general/whilege_1.c: Likewise.
	* gcc.target/aarch64/sve2/acle/general/whilegt_1.c: Likewise.
	* gcc.target/aarch64/sve2/acle/general/whilerw_5.c: Likewise.
	* gcc.target/aarch64/sve2/acle/general/whilewr_5.c: Likewise.
2025-08-04 11:45:28 +01:00
Richard Sandiford fcfbe83d88 aarch64: Improve svdupq_lane expension for big-endian [PR121293]
If the index to svdupq_lane is variable, or is outside the range of
the .Q form of DUP, the fallback expansion is to convert to VNx2DI and
use TBL.  The problem in this PR was that the conversion used subregs,
and on big-endian targets, a bitcast from VNx2DI to another element size
requires a REV[BHW] in the best case or a spill and reload in the worst
case.  (See the comment at the head of aarch64-sve.md for details.)

Here we want the conversion to act like svreinterpret, so it should
use aarch64_sve_reinterpret instead of subregs.

gcc/
	PR target/121293
	* config/aarch64/aarch64-sve-builtins-base.cc (svdupq_lane::expand):
	Use aarch64_sve_reinterpret instead of subregs.  Explicitly
	reinterpret the result back to the required mode, rather than
	leaving the caller to take a subreg.

gcc/testsuite/
	PR target/121293
	* gcc.target/aarch64/sve/acle/general/dupq_lane_9.c: New test.
2025-08-04 11:45:28 +01:00
Richard Biener 0d276cd378 tree-optimization/121362 - missed FRE through aggregate copy
The following streamlines and generalizes how we find the common
base of the lookup ref and a kill ref when looking through
aggregate copies.  In particular this tries to deal with all
variants of punning that happens on the inner MEM_REF after
forwarding of address taken components of the common base.

	PR tree-optimization/121362
	* tree-ssa-sccvn.cc (vn_reference_lookup_3): Generalize
	aggregate copy handling.

	* gcc.dg/tree-ssa/ssa-fre-105.c: New testcase.
	* gcc.dg/tree-ssa/ssa-fre-106.c: Likewise.
2025-08-04 11:44:42 +02:00
Filip Kastl 57a97725a5 invoke.texi: Update docs of -fdump-{rtl,tree}-<pass>-<options>
This patch changes two things.  Firstly, we document
-fdump-rtl-<whatever>-graph and other such options under -fdump-tree.
At least write a remark about this under -fdump-rtl.  Secondly, the
documentation incorrectly says that -fdump-tree-<whatever>-graph is not
implemented.  Change that.

gcc/ChangeLog:

	* doc/invoke.texi: Add remark about -options being documented
	under -fdump-tree.  Remove remark about -graph working only for
	RTL.

Signed-off-by: Filip Kastl <fkastl@suse.cz>
2025-08-04 08:32:39 +02:00
H.J. Lu 09f0768b55 x86: Don't hoist non all 0s/1s vector set outside of loop
Don't hoist non all 0s/1s vector set outside of the loop to avoid extra
spills.

gcc/

	PR target/120941
	* config/i386/i386-features.cc (x86_cse_kind): Moved before
	ix86_place_single_vector_set.
	(redundant_load): Likewise.
	(ix86_place_single_vector_set): Replace the last argument to the
	pointer to redundant_load.  For X86_CSE_VEC_DUP, don't place the
	vector set outside of the loop to avoid extra spills.
	(remove_redundant_vector_load): Pass load to
	ix86_place_single_vector_set.

gcc/testsuite/

	PR target/120941
	* gcc.target/i386/pr120941-1.c: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-03 19:10:09 -07:00
GCC Administrator 10075fb355 Daily bump. 2025-08-04 00:17:36 +00:00
Jakub Jelinek 625d5776f9 c++: Add stringification testcase for CWG1709 [PR120778]
The CWG1709 just codifies existing GCC (and clang) behavior, so this
just adds a testcase for that.

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

	PR preprocessor/120778
	* g++.dg/DRs/dr1709.C: New test.
2025-08-03 18:32:19 +02:00
Jakub Jelinek a68f416a70 libcpp: Fix up cpp_maybe_module_directive [PR120845]
My changes for "Module Declarations Shouldn’t be Macros" paper broke
the following testcase.  The backup handling intentionally tries to
drop CPP_PRAGMA_EOL token if things go wrong, which is desirable for the
case where we haven't committed to the module preprocessing directive
(i.e. changed the first token to the magic one).  In that case there is
no preprocessing directive start and so CPP_PRAGMA_EOL would be wrong.
If there is a premature new-line after we've changed the first token though,
we shouldn't drop CPP_PRAGMA_EOL, because otherwise we ICE in the FE.

While clang++ and MSVC accept the testcase, in my reading it is incorrect
at least in the C++23 and newer wordings and I think the changes have been
a DR, https://eel.is/c++draft/cpp.module has no exception for new-lines
and https://eel.is/c++draft/cpp.pre#1.sentence-2 says that new-line (unless
deleted during phase 2 when after backslash)  ends the preprocessing
directive.

The patch arranges for eol being set only in the not_module case.

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

	PR c++/120845
libcpp/
	* lex.cc (cpp_maybe_module_directive): Move eol variable declaration
	to the start of the function, initialize to false and only set it to
	peek->type == CPP_PRAGMA_EOL in the not_module case.  Formatting fix.
gcc/testsuite/
	* g++.dg/modules/cpp-21.C: New test.
2025-08-03 18:27:42 +02:00
Jakub Jelinek 5ecbe70d0f libstdc++: Export std::owner_equal and std::owner_hash from std.cc
I've tried compiling
  #include <bits/stdc++.h>
with -std=c++26 -fdump-lang-all
and
for i in `grep ^Class.std::[^_] *.C.001l.class | sed 's/^Class //;s/[< ].*$//' | sort -u | grep -v ::.*::`; do grep -q $i /usr/src/gcc/libstdc++-v3/src/c++23/std.cc.in || echo $i;
+done
This printed
std::auto_ptr
std::binary_function
std::owner_equal
std::owner_hash
std::unary_function
where auto_ptr, binary_function and unary_function have been removed in earlier
versions of C++ and owner_equal and owner_hash are missing.

The following patch adds them.

Wonder how to automatically discover other missing exports (like in PR121373
std::byteswap), maybe one could dig that stuff somehow from the raw
dump (look for identifiers in std namespace (and perhaps inlined namespaces
thereof at least) which don't start with underscore.

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

	* src/c++23/std.cc.in (std::owner_equal, std::owner_hash): Export.
2025-08-03 17:15:20 +02:00
Georg-Johann Lay 835595d43e AVR: Use avr_add_ccclobber / DONE_ADD_CCC in md instead of repeats.
There are many post-reload define_insn_and_split's that just append
a  (clobber (reg:CC REG_CC))  to the pattern.  Instead of repeating
the original patterns, avr_add_ccclobber (curr_insn) is used to do
that job.

This avoids repeating patterns all over the place, and splits that do
something different (like using a canonical form) stand out clearly.

gcc/
	* config/avr/avr.md (define_insn_and_split) [reload_completed]:
	For splits that just append a (clobber (reg:CC REG_CC)) to
	the pattern, use avr_add_ccclobber (curr_insn) instead of
	repeating the original pattern.
	* config/avr/avr-dimode.md: Same.
	* config/avr/avr-fixed.md: Same.
2025-08-03 10:47:57 +02:00
Georg-Johann Lay d0e62f3783 AVR: Add avr.cc::avr_add_ccclobber().
gcc/
	* config/avr/avr.cc (avr_add_ccclobber): New function.
	* config/avr/avr-protos.h (avr_add_ccclobber): New proto.
	(DONE_ADD_CCC): New define.
2025-08-03 10:47:21 +02:00
Richard Biener 7c99de1c43 tree-optimization/90242 - UBSAN error in vn_reference_compute_hash
The following plugs possible overflow issues in vn_reference_compute_hash
and possibly in vn_reference_eq.  The inchash "integer" adds are a bit
of a mess, but I know overloads with different integer types can get
messy, so not this time.  For hashing simply truncate to 64bits.

	PR tree-optimization/90242
	* tree-ssa-sccvn.cc (vn_reference_compute_hash): Use
	poly_offset_int for offset accumulation.  For hashing
	truncate to 64 bits and also hash 64 bits.
	(vn_reference_eq): Likewise.
2025-08-03 09:25:46 +02:00
GCC Administrator 94edbc153a Daily bump. 2025-08-03 00:17:28 +00:00
Gerald Pfeifer b97461dfb2 doc: Drop note on 16-bit Windows support
gcc:
	PR target/69374
	* doc/install.texi (Specific) <windows>: Drop note on 16-bit
	Windows support. Streamline note on 32-bit support.
2025-08-03 01:43:03 +02:00
Jakub Jelinek efc4c77282 cobol: Use %td in error_msg in 3 spots
On Thu, Jul 31, 2025 at 11:33:07PM +0200, Jakub Jelinek via Gcc wrote:
> > this was all described in excruciating detail in the patch submission
> >
> >     https://gcc.gnu.org/pipermail/gcc-patches/2025-June/687385.html
> >
> > and the commit message.
>
> Looking at that patch, the dbgmsg change looks correct (dbgmsg is
> ATTRIBUTE_PRINTF_1), while the last 3 hunks are suboptimal, they should
> really use %td and keep the ptrdiff_t arguments without casts.

Here it is in patch form.
I couldn't find other similar casts in calls to ATTRIBUTE_GCOBOL_DIAG
functions.

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

	* parse.y (intrinsic): Use %td format specifier with no cast on
	argument instead of %ld with cast to long.
	* scan_ante.h (numstr_of): Likewise.
	* util.cc (cbl_field_t::report_invalid_initial_value): Likewise.
2025-08-02 09:14:14 +02:00
Martin Uecker 09a3da8212 c: rewrite implementation of `arg spec' attribute
Rewrite the implementation of the `arg spec' attribute to pass the the
original type of an array parameter instead of passing a string description
and a list of bounds.  The string and list are then created
from this type during the integration of the information of `arg spec'
into the access attribute because it still needed later for various
warnings.  This change makes the implementation simpler and more robust
as the declarator is not processed and information that is already encoded
in the type is not duplicated.  A similar change to the access attribute
could then completely remove the string processing.  With this change, the
original type is now available and can be used for other warnings or for
_Countof.  The new implementation tries to be faithful to the original,
but this is not entirely true as it fixes a bug in the old implementation.

gcc/c-family/ChangeLog:
	* c-attribs.cc (handle_argspec_attribute): Update.
	(build_arg_spec): New function.
	(build_attr_access_from_parms): Rewrite `arg spec' handling.

gcc/c/ChangeLog:
	* c-decl.cc (get_parm_array_spec): Remove.
	(push_parm_decl): Do not add `arg spec` attribute.
	(build_arg_spec_attribute): New function.
	(grokdeklarator): Add `arg spec` attribute.

gcc/testsuite/ChangeLog:
	* gcc.dg/Warray-parameter-11.c: Change Warray-parameter to
	-Wvla-parameter as these are VLAs.
	* gcc.dg/Warray-parameter.c: Remove xfail.
2025-08-02 09:06:49 +02:00
GCC Administrator 3e4ced9de1 Daily bump. 2025-08-02 00:20:17 +00:00
Artemiy Granat 5b3f42dcae i386: Fix incorrect attributes-error.c test
gcc/testsuite/ChangeLog:

	* gcc.target/i386/attributes-error.c: Change incorrect
	sseregparm,fastcall combination to cdecl,fastcall.
2025-08-01 19:55:42 +03:00
Robert Dubner 8b06c58c4a cobol: Minor changes to quiet cppcheck warnings. [PR119324]
gcc/cobol/ChangeLog:

	PR cobol/119324
	* cbldiag.h (location_dump): Inline suppression of knownConditionTrueFalse.
	* genapi.cc (parser_statement_begin): Combine two if() statements.
	* genutil.cc (get_binary_value): File-level suppression of duplicateBreak.
	* symbols.cc (symbol_elem_cmp): File-level suppression of duplicateBreak.
2025-08-01 12:34:53 -04:00
Gaius Mulley 08196f0440 PR modula2/121354: ICE when attempting to fold HIGH from an unbounded array in a nested procedure
The bug fix re-implements gcc/m2/gm2-compiler/M2GenGCC.mod:FoldHigh
to ignore any attempt to constant fold HIGH if it has an unbounded
array operand.

gcc/m2/ChangeLog:

	PR modula2/121354
	* gm2-compiler/M2GenGCC.mod (FoldHigh): Rewrite.
	(IsUnboundedArray): New procedure function.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-08-01 15:16:37 +01:00
Mikael Morin db39ace3c1 fortran: Fix closing brace in comment
In a comment, fix the closing brace of the tree layout definition of the
openmp allocate clause.  It was confusing vim's matching brace support.

gcc/fortran/ChangeLog:

	* trans-decl.cc (gfc_trans_deferred_vars): Fix closing brace in
	a comment.
2025-08-01 15:10:35 +02:00
Richard Biener 39d429631f Properly record SLP node when costing a vectorized store
Even when we emit scalar stores we should pass down the SLP node.

	PR tree-optimization/121350
	* tree-vect-stmts.cc (vectorizable_store): Pass down SLP
	node when costing scalar stores in vect_body.
2025-08-01 14:54:11 +02:00
Richard Biener 95aecacc8d Avoid representing SLP mask by scalar op
The following removes the scalar mask output from vect_check_scalar_mask
and deals with the fallout, eliminating uses of it.  That's mostly
replacing checks on 'mask' by checks on 'mask_node' but also realizing
PR121349 and fixing that up a bit in check_load_store_for_partial_vectors.

	PR tree-optimization/121349
	* tree-vect-stmts.cc (check_load_store_for_partial_vectors):
	Get full SLP mask, reduce to uniform scalar_mask for further
	processing if possible.
	(vect_check_scalar_mask): Remove scalar mask output, remove
	code conditional on slp_mask.
	(vectorizable_call): Adjust.
	(check_scan_store): Get and check SLP mask.
	(vectorizable_store): Eliminate scalar mask variable.
	(vectorizable_load): Likewise.
2025-08-01 14:17:52 +02:00
Gerald Pfeifer c2b11b7471 doc: mdocml.bsd.lv is now mandoc.bsd.lv
On the way switch from http to https.

gcc:
	* doc/install.texi (Prerequisites): mdocml.bsd.lv is now
	mandoc.bsd.lv.
2025-08-01 13:15:57 +02:00
Richard Biener 86011bba93 Merge get_group_load_store_type into get_load_store_type
The following merges back get_group_load_store_type into
get_load_store_type, it gets easier to follow that way.  I've
removed the unused ncopies parameter as well.

	* tree-vect-stmts.cc (get_group_load_store_type): Remove,
	inline into ...
	(get_load_store_type): ... this.  Remove ncopies parameter.
	(vectorizable_load): Adjust.
	(vectorizable_store): Likewise.
2025-08-01 12:15:26 +02:00
Richard Biener 06cd2994cc Some TLC to vectorizable_store
The following removes redundant checks and scalar operand uses.

	* tree-vect-stmts.cc (get_group_load_store_type): Remove
	checks performed at SLP build time.
	(vect_check_store_rhs): Remove scalar RHS output.
	(vectorizable_store): Remove uses of scalar RHS.
2025-08-01 12:15:26 +02:00
Richard Biener 8308de8cc9 Add VMAT_UNINITIALIZED
We're using VMAT_INVARIANT as default, but we should simply have
an uninitialized state.

	* tree-vectorizer.h (VMAT_UNINITIALIZED): New
	vect_memory_access_type.
	* tree-vect-slp.cc (_slp_tree::_slp_tree): Use it.
2025-08-01 11:06:05 +02:00
Richard Biener 7d66563e81 tree-optimization/121338 - UBSAN error in adjust_setup_cost
The following avoids possibly overflowing adds for rounding.  We
know cost is bound, so it's enough to do this simple test.

	PR tree-optimization/121338
	* tree-ssa-loop-ivopts.cc (avg_loop_niter): Return an
	unsigned.
	(adjust_setup_cost): When niters is so large the division
	result is one or zero avoid it.
	(create_new_ivs): Adjust.
2025-08-01 10:49:35 +02:00
Richard Biener 1586a8d707 Put SLP_TREE_SIMD_CLONE_INFO into type specifc data
The following adds vect_simd_clone_data as a container for vect
type specific data for vectorizable_simd_clone_call and moves
SLP_TREE_SIMD_CLONE_INFO there.

	* tree-vectorizer.h (vect_simd_clone_data): New.
	(_slp_tree::simd_clone_info): Remove.
	(SLP_TREE_SIMD_CLONE_INFO): Likewise.
	* tree-vect-slp.cc (_slp_tree::_slp_tree): Adjust.
	(_slp_tree::~_slp_tree): Likewise.
	* tree-vect-stmts.cc (vectorizable_simd_clone_call): Use
	tyupe specific data to store SLP_TREE_SIMD_CLONE_INFO.
2025-08-01 09:28:05 +02:00
Richard Biener 7a08afbc78 Use a class hierarchy for vect specific data
The following turns the union into a class hierarchy.  One completed
SLP_TREE_TYPE could move into the base class.

	* tree-vect-slp.cc (_slp_tree::_slp_tree): Adjust.
	(_slp_tree::~_slp_tree): Likewise.
	* tree-vectorizer.h (vect_data): New base class.
	(_slp_tree::u): Remove.
	(_slp_tree::data): Add pointer to vect_data.
	(_slp_tree::get_data): New helper template.
2025-08-01 09:28:05 +02:00
Jakub Jelinek d8fc7bce9c bswap: Fix up ubsan detected UB in find_bswap_or_nop [PR121322]
The following testcase results in compiler UB as detected by ubsan.
find_bswap_or_nop first checks is_bswap_or_nop_p and if that fails
on the tmp_n value, tries some rotation of that if possible.
The discovery what rotate count to use ignores zero bytes from
the least significant end (those mean zero bytes and so can be masked
away) and on the first non-zero non-0xff byte (0xff means don't know),
1-8 means some particular byte of the original computes count (the rotation
count) from that byte + the byte index.
Now, on the following testcase we have tmp_n 0x403020105060700, i.e.
the least significant byte is zero, then the msb from the original value,
byte below it, another one below it, then the low 32 bits of the original
value.  So, we stop at count 7 with i 1, it wraps around and we get count
0.
Then we invoke UB on
          tmp_n = tmp_n >> count | tmp_n << (range - count);
because count is 0 and range is 64.
Now, of course I could fix it up by doing tmp_n << ((range - count) % range)
or something similar, but that is just wasted compile time, if count is 0,
we already know that is_bswap_or_nop_p failed on that tmp_n value and
so it will fail again if the value is the same.  So I think better
just return NULL (i.e. punt).

2025-08-01  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/121322
	* gimple-ssa-store-merging.cc (find_bswap_or_nop): Return NULL if
	count is 0.

	* gcc.dg/pr121322.c: New test.
2025-08-01 08:41:54 +02:00
Luis Machado 911cad743b MAINTAINERS: Update my e-mail address.
ChangeLog/
	* MAINTAINERS: Update my e-mail address.
2025-08-01 06:57:35 +01:00
Nathaniel Shead 643c5b42e2 c++/modules: Warn for optimize attributes instead of ICEing [PR108080]
This PR is the most frequently reported modules bug for 15, as the ICE
message does not indicate the issue at all and reducing to find the
underlying cause can be tricky.

I have a WIP patch to fix this issue by just reconstructing these nodes
on stream-in from any attributes applied to the functions, but since at
this stage it may still take a while to be ready, it seems useful to me
to at least make the error here more friendly and guide users to what
they could do to work around this issue.

In fact, as noted on the PR, a lot of the time it should be harmless to
just ignore the optimize etc. attribute and continue translation, at the
user's own risk; this patch as such turns the ICE into a warning with no
option to silence.

	PR c++/108080

gcc/cp/ChangeLog:

	* module.cc (trees_out::core_vals): Warn when streaming
	target/optimize node; adjust comments.
	(trees_in::core_vals): Don't stream a target/optimize node.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/pr108080.H: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-08-01 10:35:16 +10:00
Nathaniel Shead 70136bdc76 c++/modules: Merge PARM_DECL properties from function definitions [PR121238]
When we merge a function definition, if there already exists a forward
declaration in the importing TU we use the PARM_DECLs belonging to that
decl.  This usually works fine, except as noted in the linked PR there
are some flags (such as TREE_ADDRESSABLE) that only get set on a
PARM_DECL once a definition is provided.

This patch fixes the wrong-code issues by propagating any properties on
PARM_DECLs I could find that may affect codegen.

	PR c++/121238

gcc/cp/ChangeLog:

	* module.cc (trees_in::fn_parms_fini): Merge properties for
	definitions.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/merge-19.h: New test.
	* g++.dg/modules/merge-19_a.H: New test.
	* g++.dg/modules/merge-19_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-08-01 10:24:46 +10:00
GCC Administrator b6d4eaa96d Daily bump. 2025-08-01 00:20:20 +00:00
Gaius Mulley aa19c1076f PR modula2/121314: quotes appearing in concatenated error strings
This patch fixes the addition of strings so that no extraneous quotes
appear in the result string.  The fix is made to the bootstrap tool mc
and it has been rebuilt.

gcc/m2/ChangeLog:

	PR modula2/121314
	* mc-boot/GFormatStrings.cc (PerformFormatString): Rebuilt.
	* mc-boot/GM2EXCEPTION.cc (M2EXCEPTION_M2Exception): Rebuilt.
	* mc-boot/GSFIO.cc (SFIO_GetFileName): Rebuilt.
	* mc-boot/GSFIO.h (SFIO_GetFileName): Rebuilt.
	* mc-boot/Gdecl.cc: Rebuilt.
	* mc-boot/GmcFileName.h: Rebuilt.
	* mc/decl.mod (getStringChar): New procedure function.
	(getStringContents): Call getStringChar.
	(addQuotes): New procedure function.
	(foldBinary): Call addQuotes to add delimiting quotes
	to the new string.

gcc/testsuite/ChangeLog:

	PR modula2/121314
	* gm2/errors/fail/badindrtype.mod: New test.
	* gm2/errors/fail/badindrtype2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-07-31 23:28:53 +01:00
Mikael Morin 04a1259ffe fortran: Evaluate class function bounds in the scalarizer [PR121342]
There is code in gfc_conv_procedure_call that, for polymorphic
functions, initializes the scalarization array descriptor
information and forcedfully sets loop bounds.  This code is changing
the decisions made by the scalarizer behind his back, and the test shows
an example where the consequences are (badly) visible.  In the test, for
one of the actual arguments to an elemental subroutine, an offset to the
loop variable is missing to access the array, as it was the one
originally chosen to set the loop bounds from.

This could theoretically be fixed by just clearing the array of choice
for the loop bounds.  This change takes instead the harder path of
adding the missing information to the scalarizer's knowledge so that its
decision doesn't need to be forced to something else after the fact.
The array descriptor information initialisation for polymorphic
functions is moved to gfc_add_loop_ss_code (after the function call
generation), and the loop bounds initialization to a new function called
after that.

As the array chosen to set the loop bounds from is no longer forced
to be the polymorphic function result, we have to let the scalarizer set
a delta for polymorphic function results.  For regular non-polymorphic
function result arrays, they are zero-based and the temporary creation
makes the loop zero-based as well, so we can continue to skip the delta
calculation.

In the cases where a temporary is created to store the result of the
array function, the creation of the temporary shifts the loop bounds
to be zero-based.  As there was no delta for polymorphic result arrays,
the function result descriptor offset was set to zero in that case for
a zero-based array reference to be correct.  Now that the scalarizer
sets a delta, those forced offset updates have to go because they can
make the descriptor invalid and cause erroneous array references.

	PR fortran/121342

gcc/fortran/ChangeLog:

	* trans-expr.cc (gfc_conv_subref_array_arg): Remove offset
	update.
	(gfc_conv_procedure_call): For polymorphic functions, move the
	scalarizer descriptor information...
	* trans-array.cc (gfc_add_loop_ss_code): ... here, and evaluate
	the bounds to fresh variables.
	(get_class_info_from_ss): Remove offset update.
	(gfc_conv_ss_startstride): Don't set a zero value for function
	result upper bounds.
	(late_set_loop_bounds): New.
	(gfc_conv_loop_setup): If the bounds of a function result have
	been set, and no other array provided loop bounds for a
	dimension, use the function result bounds as loop bounds for
	that dimension.
	(gfc_set_delta): Don't skip delta setting for polymorphic
	function results.

gcc/testsuite/ChangeLog:

	* gfortran.dg/class_elemental_1.f90: New test.
2025-07-31 22:05:01 +02:00
Georg-Johann Lay 86cdd2ad0a AVR: avr.opt.urls: Add -mfuse-move2
PR rtl-optimization 121340
gcc/
	* config/avr/avr.opt.urls (-mfuse-move2): Add url.
2025-07-31 21:10:10 +02:00
Georg-Johann Lay 33d02f3f13 AVR: Set .type of jump table label.
gcc/
	* config/avr/avr.cc (avr_output_addr_vec) <labl>: Asm out its .type.
2025-07-31 20:32:53 +02:00
Georg-Johann Lay 7d75e87f30 AVR: rtl-optimization/121340 - New mini-pass to undo superfluous moves from insn combine.
Insn combine may come up with superfluous reg-reg moves, where the combine
people say that these are no problem since reg-alloc is supposed to optimize
them.  The issue is that the lower-subreg pass sitting between combine and
reg-alloc may split such moves, coming up with a zoo of subregs which are
only handled poorly by the register allocator.

This patch adds a new avr mini-pass that handles such cases.

As an example, take

int f_ffssi (long x)
{
    return __builtin_ffsl (x);
}

where the two functions have the same interface, i.e. there are no extra
moves required for the argument or for the return value. However,

$ avr-gcc -S -Os -dp -mno-fuse-move ...

f_ffssi:
	mov r20,r22	 ;  29	[c=4 l=1]  movqi_insn/0
	mov r21,r23	 ;  30	[c=4 l=1]  movqi_insn/0
	mov r22,r24	 ;  31	[c=4 l=1]  movqi_insn/0
	mov r23,r25	 ;  32	[c=4 l=1]  movqi_insn/0
	mov r25,r23	 ;  33	[c=4 l=4]  *movsi/0
	mov r24,r22
	mov r23,r21
	mov r22,r20
	rcall __ffssi2	 ;  34	[c=16 l=1]  *ffssihi2.libgcc
	ret		 ;  37	[c=0 l=1]  return

where all the moves add up to a no-op.  The -mno-fuse-move option
stops any attempts by the avr backend to clean up that mess.

	PR rtl-optimization/121340
gcc/
	* config/avr/avr.opt (-mfuse-move2): New option.
	* config/avr/avr-passes.def (avr_pass_2moves): Insert after combine.
	* config/avr/avr-passes.cc (make_avr_pass_2moves): New function.
	(pass_data avr_pass_data_2moves): New static variable.
	(avr_pass_2moves): New rtl_opt_pass.
	* config/avr/avr-protos.h (make_avr_pass_2moves): New proto.
	* common/config/avr/avr-common.cc
	(default_options avr_option_optimization_table) <-mfuse-move2>:
	Set for -O1 and higher.
	* doc/invoke.texi (AVR Options) <-mfuse-move2>: Document.
2025-07-31 20:31:30 +02:00
Jason Merrill f6462f6647 c++: constexpr, array, private ctor [PR120800]
Here cxx_eval_vec_init_1 wants to recreate the default constructor call that
we previously built and threw away in build_vec_init_elt, but we aren't in
the same access context at this point.  Since we already checked access,
let's just suppress access control here.

Redoing overload resolution at constant evaluation time is sketchy, but
should usually be fine for a default/copy constructor.

	PR c++/120800

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_eval_vec_init_1): Suppress access control.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-array30.C: New test.
2025-07-31 14:23:10 -04:00
Eric Botcazou d3828e64a8 Revert "Ada: Add System.C_Time and GNAT.C_Time units to libgnat"
This reverts commit 41974d6ed3.
2025-07-31 17:47:07 +02:00
Eric Botcazou 0cd52ca158 Ada: Fix miscompilation of GNAT tools with -march=znver3
The throw and catch sides of the Ada exception machinery disagree about
the BIGGEST_ALIGNMENT setting.

gcc/ada/
	PR ada/120440
	* gcc-interface/Makefile.in (GNATLINK_OBJS): Add s-excmac.o.
	(GNATMAKE_OBJS): Likewise.
2025-07-31 17:41:31 +02:00
Nicolas Boulenguez 41974d6ed3 Ada: Add System.C_Time and GNAT.C_Time units to libgnat
The first unit provides the time_t, timeval and timespec types corresponding
to the C types defined by the OS, as well as various conversion functions.

The second unit is a mere renaming of the first under the GNAT hierarchy.

This removes C time types and conversions under System, and from bodies and
private parts under GNAT, while keeping visible types and conversions under
GNAT as Obsolescent.

[changelog]
	PR ada/114065
	* Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add g-c_time$(objext) and
	s-c_time$(objext).
	(Aarch64/Android): Do not use s-osinte__android.adb.
	(SPARC/Solaris): Do not use s-osprim__solaris.adb.
	(x86/Solaris): Likewise.
	(LynxOS178): Do not use s-parame__posix2008.ads.
	(RTEMS): Likewise.
	(x32/Linux): Likewise, as well as s-linux__x32.ads.  Replace
	s-osprim__x32.adb with s-osprim__posix.adb.
	(LIBGNAT_OBJS): Remove cal.o.
	* cal.c: Delete.
	* doc/gnat_rm/the_gnat_library.rst (GNAT.C_Time): New entry.
	(GNAT.Calendar): Do not mention the obsolete conversion functions.
	* impunit.adb (Non_Imp_File_Names_95): Add g-c_time.
	* libgnarl/a-exetim__posix.adb: Add with clause for System.C_Time
	(Clock): Use type and functions from System.C_Time.
	* libgnarl/s-linux.ads: Remove with clause for System.Parameters.
	Remove declarations of C time types.
	* libgnarl/s-linux__alpha.ads: Likewise.
	* libgnarl/s-linux__android-aarch64.ads: Likewise.
	* libgnarl/s-linux__android-arm.ads: Likewise.
	* libgnarl/s-linux__hppa.ads: Likewise.
	* libgnarl/s-linux__loongarch.ads: Likewise.
	* libgnarl/s-linux__mips.ads: Likewise.
	* libgnarl/s-linux__riscv.ads: Likewise.
	* libgnarl/s-linux__sparc.ads: Likewise.
	* libgnarl/s-osinte__aix.ads: Likewise.
	* libgnarl/s-osinte__android.ads: Likewise.
	* libgnarl/s-osinte__cheribsd.ads: Likewise.
	* libgnarl/s-osinte__darwin.ads: Likewise.
	* libgnarl/s-osinte__dragonfly.ads: Likewise.
	* libgnarl/s-osinte__freebsd.ads: Likewise.
	* libgnarl/s-osinte__gnu.ads: Likewise.
	* libgnarl/s-osinte__hpux.ads: Likewise.
	* libgnarl/s-osinte__kfreebsd-gnu.ads: Likewise.
	* libgnarl/s-osinte__linux.ads: Likewise.
	* libgnarl/s-osinte__lynxos178e.ads: Likewise.
	* libgnarl/s-osinte__qnx.ads: Likewise.
	* libgnarl/s-osinte__rtems.ads: Likewise.
	* libgnarl/s-osinte__solaris.ads: Likewise.
	* libgnarl/s-osinte__vxworks.ads: Likewise.
	* libgnarl/s-qnx.ads: Likewise.
	* libgnarl/s-linux__x32.ads: Delete.
	* libgnarl/s-osinte__darwin.adb (To_Duration): Remove.
	(To_Timespec): Likewise.
	* libgnarl/s-osinte__aix.adb: Likewise.
	* libgnarl/s-osinte__dragonfly.adb: Likewise.
	* libgnarl/s-osinte__freebsd.adb: Likewise.
	* libgnarl/s-osinte__gnu.adb: Likewise.
	* libgnarl/s-osinte__lynxos178.adb: Likewise.
	* libgnarl/s-osinte__posix.adb: Likewise.
	* libgnarl/s-osinte__qnx.adb: Likewise.
	* libgnarl/s-osinte__rtems.adb: Likewise.
	* libgnarl/s-osinte__solaris.adb: Likewise.
	* libgnarl/s-osinte__vxworks.adb: Likewise.
	* libgnarl/s-osinte__x32.adb: Likewise.
	* libgnarl/s-taprop__solaris.adb: Add with clause for System.C_Time.
	(Monotonic_Clock): Use type and functions from System.C_Time.
	(RT_Resolution): Likewise.
	(Timed_Sleep): Likewise.
	(Timed_Delay): Likewise.
	* libgnarl/s-taprop__vxworks.adb: Likewise.
	* libgnarl/s-tpopmo.adb: Likewise.
	* libgnarl/s-osinte__android.adb: Delete.
	* libgnat/g-c_time.ads: New file.
	* libgnat/g-calend.adb: Delegate to System.C_Time.
	* libgnat/g-calend.ads: Likewise.
	* libgnat/g-socket.adb: Likewise.
	* libgnat/g-socthi.adb: Likewise.
	* libgnat/g-socthi__vxworks.adb: Likewise.
	* libgnat/g-sothco.ads: Likewise.
	* libgnat/g-spogwa.adb: Likewise.
	* libgnat/s-c_time.adb: New file.
	* libgnat/s-c_time.ads: Likewise.
	* libgnat/s-optide.adb: Import nanosleep here.
	* libgnat/s-os_lib.ads (time_t): Remove.
	(To_Ada): Adjust.
	(To_C): Likewise.
	* libgnat/s-os_lib.adb: Likewise.
	* libgnat/s-osprim__darwin.adb: Delegate to System.C_Time.
	* libgnat/s-osprim__posix.adb: Likewise.
	* libgnat/s-osprim__posix2008.adb: Likewise.
	* libgnat/s-osprim__rtems.adb: Likewise.
	* libgnat/s-osprim__unix.adb: Likewise.
	* libgnat/s-osprim__solaris.adb: Delete.
	* libgnat/s-osprim__x32.adb: Likewise.
	* libgnat/s-parame.ads (time_t_bits): Remove.
	* libgnat/s-parame__hpux.ads: Likewise.
	* libgnat/s-parame__vxworks.ads: Likewise.
	* libgnat/s-parame__posix2008.ads: Delete.
	* s-oscons-tmplt.c (SIZEOF_tv_nsec): New constant.
2025-07-31 17:41:00 +02:00
Marek Polacek d46d8267b5 c++: consteval blocks
This patch implements consteval blocks, as specified by P2996.
They aren't very useful without define_aggregate, but having
a reviewed implementation on trunk would be great.

consteval {} can be anywhere where a member-declaration or
block-declaration can be.  The expression corresponding to it is:

  [] -> void static consteval compound-statement ()

and it must be a constant expression.

I've used cp_parser_lambda_expression to take care of most of the
parsing.  Since a consteval block can find itself in a template, we
need a vehicle to carry the block for instantiation.  Rather than
inventing a new tree, I'm using STATIC_ASSERT.

A consteval block can't return a value but that is checked by virtue
of the lambda having a void return type.

	PR c++/120775

gcc/cp/ChangeLog:

	* constexpr.cc (cxx_eval_outermost_constant_expr): Use
	extract_call_expr.
	* cp-tree.h (CONSTEVAL_BLOCK_P, LAMBDA_EXPR_CONSTEVAL_BLOCK_P): Define.
	(finish_static_assert): Adjust declaration.
	(current_nonlambda_function): Likewise.
	* lambda.cc (current_nonlambda_function): New parameter.  Only keep
	iterating if the function represents a consteval block.
	* parser.cc (cp_parser_lambda_expression): New parameter for
	consteval blocks.  Use it.  Set LAMBDA_EXPR_CONSTEVAL_BLOCK_P.
	(cp_parser_lambda_declarator_opt): Likewise.
	(build_empty_string): New.
	(cp_parser_next_tokens_are_consteval_block_p): New.
	(cp_parser_consteval_block): New.
	(cp_parser_block_declaration): Handle consteval blocks.
	(cp_parser_static_assert): Use build_empty_string.
	(cp_parser_member_declaration): Handle consteval blocks.
	* pt.cc (tsubst_stmt): Adjust a call to finish_static_assert.
	* semantics.cc (finish_fname): Warn for consteval blocks.
	(finish_static_assert): New parameter for consteval blocks.  Set
	CONSTEVAL_BLOCK_P.  Evaluate consteval blocks specially.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp26/consteval-block1.C: New test.
	* g++.dg/cpp26/consteval-block2.C: New test.
	* g++.dg/cpp26/consteval-block3.C: New test.
	* g++.dg/cpp26/consteval-block4.C: New test.
	* g++.dg/cpp26/consteval-block5.C: New test.
	* g++.dg/cpp26/consteval-block6.C: New test.
	* g++.dg/cpp26/consteval-block7.C: New test.
	* g++.dg/cpp26/consteval-block8.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2025-07-31 10:40:28 -04:00
Pan Li 9c63518f3a RISC-V: Add testcases for signed avg ceil vx combine
The unsigned avg ceil share the vaaddx.vx for the vx combine,
so add the test case to make sure it works well as expected.

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

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i16.c: Add asm check
	for signed avg ceil.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-i8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary.h: Add test
	helper macros.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_data.h: Add
	test data for run test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vaadd-run-2-i16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vaadd-run-2-i32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vaadd-run-2-i64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vaadd-run-2-i8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-07-31 22:34:38 +08:00
Tamar Christina 4a65ae52ba vect: Don't set bogus bounds on epilogues [PR120805]
The testcases in the PR are failing due to the code trying to set a vector range
on an epilogue.

However on epilogues the range doesn't make sense.  In particular we are setting
ranged to help niters analysis. But the epilogue doesn't iterate.

Secondly the bounds variable hasn't been adjusted to vector iterations:

In the epilogue this is calculated as

  <bb 13> [local count: 81467476]:
  # i_127 = PHI <tmp.7_131(10), 0(5)>
  # _132 = PHI <_133(10), 0(5)>
  _181 = (unsigned int) n_41(D);
  bnd.31_180 = _181 - _132;

where

  _133 = niters_vector_mult_vf.6_130;

but _132 is a phi node, and if coming from the vector loop skip edge
_181 will be <1, VF>.

But this is a range VRP or Ranger can easily report due to the guard on the
skip_vector loop.

Previously, non-const VF would skip this code entirely due to the .is_constant()
check.

Non-partial vector loop would also skip it because the bounds would fold to a
constant. so it doesn't enter the !gimple_value check.

When support for partial vector ranges was added, this accidentally enabled
ranges on partial vector epilogues.

This patch now makes it explicit that ranges shouldn't be set for epilogues, as
they don't seem to be useful anyway.

gcc/ChangeLog:

	PR tree-optimization/120805
	* tree-vect-loop-manip.cc (vect_gen_vector_loop_niters): Skip setting
	bounds on epilogues.
2025-07-31 15:29:30 +01:00
Wilco Dijkstra 9996036205 libgcc: Update FMV features to latest ACLE spec 2024Q4
Update FMV features to latest ACLE spec of 2024Q4 - several features have been
removed or merged.  Add FMV support for CSSC and MOPS.  Preserve the ordering
in enum CPUFeatures.

gcc:
	* common/config/aarch64/cpuinfo.h: Remove unused features, add FEAT_CSSC
	and FEAT_MOPS.
	* config/aarch64/aarch64-option-extensions.def: Remove FMV support
	for RPRES, use PULL rather than AES, add FMV support for CSSC and MOPS.

libgcc:
	* config/aarch64/cpuinfo.c (__init_cpu_features_constructor):
	Remove unused features, add support for CSSC and MOPS.
2025-07-31 14:23:46 +00:00
Wilco Dijkstra a6bb6934a4 libgcc: Cleanup HWCAP defines in cpuinfo.c
Cleanup HWCAP defines - rather than including hwcap.h and then repeating it
using ifndef, just define the HWCAPs we need exactly as in hwcap.h.

libgcc:
	* config/aarch64/cpuinfo.c: Cleanup HWCAP defines.
2025-07-31 14:23:46 +00:00
Wilco Dijkstra 731649066f AArch64: Use correct cost for shifted halfword load/stores
Since all Armv9 cores support shifted LDRH/STRH, use the correct cost of zero
for these.

gcc:
	* config/aarch64/tuning_models/generic_armv9_a.h
	(generic_armv9_a_addrcost_table): Use zero cost for himode.
2025-07-31 14:23:46 +00:00
Richard Biener a4b5618782 Fixup wrong change to get_group_load_store_type
The following fixes up the r16-2593-g6ac78317aa6adf change which
made us match up a scalar with a vector type.  Oops.

Noticed when removing the gather/scatter pattern that creates the
IFNs early.

	* tree-vect-stmts.cc (get_group_load_store_type): Properly
	compare the scalar type of the gather/scatter offset to
	the offset vector component type.
2025-07-31 16:07:16 +02:00
Sam James 040a79586d zlib: refresh version in configure
zlib/ChangeLog:

	* configure: Regenerate.
	* configure.ac: Set version to 1.3.1.
2025-07-31 14:57:41 +01:00
Richard Biener 00726defcd Extend gimple_fold_inplace API
The following allows to specify the valueization hook to be used.

	* gimple-fold.h (fold_stmt_inplace): Add valueization hook
	argument, defaulted to no_follow_ssa_edges.
	* gimple-fold.cc (fold_stmt_inplace): Adjust.
2025-07-31 15:32:45 +02:00
Sam James 7a06d389e2 zlib: update ChangeLog
zlib/ChangeLog:
	PR other/105404
	* Import zlib-1.3.1
2025-07-31 14:28:14 +01:00
Sam James 7a79219383 zlib: import zlib-1.3.1
This is vanilla zlib-1.3.1 imported over the existing zlib/ dir with:
* README adjusted to add the GCC note at the top;
* GCC's ChangeLog merged with the upstream one, as before;
* Deleted upstream Makefile as has been done before (we use an autoconf-
  generated one)
2025-07-31 14:25:15 +01:00
Robert Dubner 0f93b29093 cobol: Eliminate various errors. [PR120244]
The following coding errors were located by running extended tests
through valgrind.  These changes repair the errors.

gcc/cobol/ChangeLog:

	PR cobol/120244
	* genapi.cc (get_level_88_domain): Increase array size for final byte.
	(psa_FldLiteralA): Use correct length in build_string_literal call.
	* scan.l: Use a loop instead of std:transform to avoid EOF overrun.
	* scan_ante.h (binary_integer_usage): Use a variable-length buffer.
2025-07-31 09:13:16 -04:00
Artemiy Granat df82965344 i386: Fix typo in diagnostic about simultaneous regparm and thiscall use
gcc/ChangeLog:

	* config/i386/i386-options.cc (ix86_handle_cconv_attribute):
	Fix typo.
2025-07-31 15:47:36 +03:00
Artemiy Granat 3b146853a3 i386: Fix incorrect handling of simultaneous regparm and thiscall use
gcc/ChangeLog:

	* config/i386/i386-options.cc (ix86_handle_cconv_attribute):
	Handle simultaneous use of regparm and thiscall attributes in
	case when regparm is set before thiscall.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/attributes-error.c: Add more attributes
	combinations.
2025-07-31 15:47:36 +03:00
Artemiy Granat 55e71d2a55 i386: Fix incorrect comment about stdcall and fastcall compatibility
gcc/ChangeLog:

	* config/i386/i386-options.cc (ix86_handle_cconv_attribute):
	Fix comments which state that combination of stdcall and fastcall
	attributes is valid but redundant.
2025-07-31 15:47:36 +03:00
Artemiy Granat ccead81bbc i386: Ignore regparm attribute and warn for it in 64-bit mode
The regparm attribute does not affect code generation on x86-64 target.
Despite this, regparm was accepted silently, unlike other calling
convention attributes handled in the ix86_handle_cconv_attribute
function.

Due to lack of diagnostics, Linux kernel attempted to specify regparm(0)
on vmread_error_trampoline declaration, which is supposed to be invoked
with all arguments on stack:
https://lore.kernel.org/all/20220928232015.745948-1-seanjc@google.com/

To produce a warning for regparm in 64-bit mode, simply move the block
that produces diagnostics above the block that handles the regparm
attribute.

gcc/ChangeLog:

	* config/i386/i386-options.cc (ix86_handle_cconv_attribute):
	Move 64-bit mode check before regparm handling.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/regparm1.C: Require ia32 target.
	* gcc.target/i386/20020224-1.c: Likewise.
	* gcc.target/i386/pr103785.c: Use regparm attribute only if
	not in 64-bit mode.
	* gcc.target/i386/pr36533.c: Likewise.
	* gcc.target/i386/pr59099.c: Likewise.
	* gcc.target/i386/sibcall-8.c: Likewise.
	* gcc.target/i386/sw-1.c: Likewise.
	* gcc.target/i386/pr15184-2.c: Fix invalid comment.
	* gcc.target/i386/attributes-ignore.c: New test.
2025-07-31 15:47:33 +03:00
Richard Biener ff6f7d8e00 tree-optimization/121320 - UBSAN error in ao_ref_init_from_vn_reference
The multiplication by BITS_PER_UNIT should be done in poly_offset_int.

	PR tree-optimization/121320
	* tree-ssa-sccvn.cc (ao_ref_init_from_vn_reference): Convert
	op->off to poly_offset_int before multiplying by
	BITS_PER_UNIT.
2025-07-31 14:12:50 +02:00
Richard Biener 0be8ffbc85 tree-optimization/121323 - UBSAN error in ao_ref_init_from_ptr_and_range
We should check the offset fits a HWI when multiplied to be in bits.

	PR tree-optimization/121323
	* tree-ssa-alias.cc (ao_ref_init_from_ptr_and_range): Check
	the pointer offset fits in a HWI when represented in bits.
2025-07-31 14:12:50 +02:00
Yury Khrustalev 479446beb4 testsuite: Add runtime test for FMV resolvers
gcc/testsuite/ChangeLog:

	* g++.target/aarch64/mv-cpu-features.C: new test.
2025-07-31 12:39:10 +01:00
Yury Khrustalev ccffdcbbe9 testsuite: Add tests for __init_cpu_features_constructor
Add tests that would call __init_cpu_features_resolver() directly
from an ifunc resolver that would in tern call the function under
test __init_cpu_features_constructor() using synthetic parameters
for different sizes of the 2nd argument.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/ifunc-resolver.in: add core test functions.
	* gcc.target/aarch64/ifunc-resolver-0.c: new test.
	* gcc.target/aarch64/ifunc-resolver-1.c: ditto.
	* gcc.target/aarch64/ifunc-resolver-2.c: ditto.
	* gcc.target/aarch64/ifunc-resolver-3.c: ditto.
	* gcc.target/aarch64/ifunc-resolver-4.c: as above.
2025-07-31 12:39:10 +01:00
Yury Khrustalev a8461846ad aarch64: Stop using sys/ifunc.h header in libatomic and libgcc
This optional header is used to bring in the definition of the
struct __ifunc_arg_t type. Since it has been added to glibc only
recently, the previous implementation had to check whether this
header is present and, if not, it provide its own definition.

This creates dead code because either one of these two parts would
not be tested. The ABI specification for ifunc resolvers allows to
create own ABI-compatible definition for this type, which is the
right way of doing it.

In addition to improving consistency, the new approach also helps
with addition of new fields to struct __ifunc_arg_t type without
the need to work-around situations when the definition imported
from the header lacks these new fields.

ABI allows to define as many hwcap fields in this struct as needed,
provided that at runtime we only access the fields that are permitted
by the _size value.

gcc/
	* config/aarch64/aarch64.cc (build_ifunc_arg_type):
	Add new fields _hwcap3 and _hwcap4.

libatomic/
	* config/linux/aarch64/host-config.h (__ifunc_arg_t):
	Remove sys/ifunc.h and add new fields _hwcap3 and _hwcap4.

libgcc/
	* config/aarch64/cpuinfo.c (__ifunc_arg_t): Likewise.
	(__init_cpu_features): obtain and assign values for the
	fields _hwcap3 and _hwcap4.
	(__init_cpu_features_constructor): check _size in the
	arg argument.
2025-07-31 12:39:10 +01:00
Kishan Parmar 647bd0a027 rs6000: Avoid undefined behavior caused by overflow and invalid shifts
While building GCC with --with-build-config=bootstrap-ubsan on
powerpc64le-unknown-linux-gnu, multiple UBSAN runtime errors were
encountered in rs6000.cc and rs6000.md due to undefined behavior
involving left shifts on negative values and shift exponents equal to
or exceeding the type width.

The issue was in bit pattern recognition code
(in can_be_rotated_to_negative_lis and can_be_built_by_li_and_rldic),
where signed values were shifted without handling negative inputs or
guarding against shift counts equal to the type width, causing UB.
The fix ensures shifts and rotations are done unsigned HOST_WIDE_INT,
and casting back only where needed (like for arithmetic right shifts)
with proper guards to prevent shift-by-64.

2025-07-31  Kishan Parmar  <kishan@linux.ibm.com>

gcc:
	PR target/118890
	* config/rs6000/rs6000.cc (can_be_rotated_to_negative_lis): Avoid left
	shift of negative value and guard shift count.
	(can_be_built_by_li_and_rldic): Likewise.
	(rs6000_emit_set_long_const): Likewise.
	* config/rs6000/rs6000.md (splitter for plus into two 16-bit parts): Fix
	UB from overflow in addition.
2025-07-31 17:05:02 +05:30
Richard Biener 51c03570b3 Add checks for node in aarch64 vector cost modeling
After removing STMT_VINFO_MEMORY_ACCESS_TYPE we now ICE when costing
for scalar stmts required in the epilog since the cost model tries
to pattern-match gathers (an earlier patch tried to improve this
by introducing stmt groups, but that was on hold due to negative
feedback).  The following shot-cuts those attempts when node is NULL
as that then cannot be a vector stmt.  Another possibility would be
to gate on vect_body, or restructure everything.

Note we now ensure that when m_costing_for_scalar node is NULL.

	* config/aarch64/aarch64.cc (aarch64_detect_vector_stmt_subtype):
	Check for node before dereferencing.
	(aarch64_vector_costs::add_stmt_cost): Likewise.
2025-07-31 13:33:17 +02:00
Spencer Abson d52e9ef98b aarch64: Prevent streaming-compatible code from assembler rejection [PR121028]
Streaming-compatible functions can be compiled without SME enabled, but need
to use "SMSTART SM" and "SMSTOP SM" to temporarily switch into the streaming
state of a callee.  These switches are conditional on the current mode being
opposite to the target mode, so no SME instructions are executed if SME is not
available.

However, in GAS, "SMSTART SM" and "SMSTOP SM" always require +sme.  A call
from a streaming-compatible function, compiled without SME enabled, to a non
-streaming function will be rejected as:

Error: selected processor does not support `smstop sm'..

To work around this, we make use of the .inst directive to insert the literal
encodings of "SMSTART SM" and "SMSTOP SM".

gcc/ChangeLog:
	PR target/121028
	* config/aarch64/aarch64-sme.md (aarch64_smstart_sm): Use the .inst
	directive if !TARGET_SME.
	(aarch64_smstop_sm): Likewise.

gcc/testsuite/ChangeLog:
	PR target/121028
	* gcc.target/aarch64/sme/call_sm_switch_1.c: Tell check-function
	-bodies not to ignore .inst directives, and replace the test for
	"smstart sm" with one for it's encoding.
	* gcc.target/aarch64/sme/call_sm_switch_11.c: Likewise.
	* gcc.target/aarch64/sme/pr121028.c: New test.
2025-07-31 10:29:49 +00:00
Richard Biener a5aa73e547 Remove STMT_VINFO_MEMORY_ACCESS_TYPE
This should be present only on SLP nodes now.  The RISC-V changes
are mechanical along the line of the SLP_TREE_TYPE changes.

	* tree-vectorizer.h (_stmt_vec_info::memory_access_type): Remove.
	(STMT_VINFO_MEMORY_ACCESS_TYPE): Likewise.
	(vect_mem_access_type): Likewise.
	* tree-vect-stmts.cc (vectorizable_store): Do not set
	STMT_VINFO_MEMORY_ACCESS_TYPE.  Fix SLP_TREE_MEMORY_ACCESS_TYPE
	usage.
	* tree-vect-loop.cc (update_epilogue_loop_vinfo): Remove
	checking of memory access type.
	* config/riscv/riscv-vector-costs.cc (costs::compute_local_live_ranges):
	Use SLP_TREE_MEMORY_ACCESS_TYPE.
	(costs::need_additional_vector_vars_p): Likewise.
	(segment_loadstore_group_size): Get SLP node as argument,
	use SLP_TREE_MEMORY_ACCESS_TYPE.
	(costs::adjust_stmt_cost): Pass down SLP node.
	* config/aarch64/aarch64.cc (aarch64_ld234_st234_vectors): Use
	SLP_TREE_MEMORY_ACCESS_TYPE instead of vect_mem_access_type.
	(aarch64_detect_vector_stmt_subtype): Likewise.
	(aarch64_vector_costs::count_ops): Likewise.
	(aarch64_vector_costs::add_stmt_cost): Likewise.
2025-07-31 12:14:36 +02:00
Richard Biener 60b1938de0 Do not bother with fake verifying of shared DRs
The following avoids comparing the shared DRs against their unmodified
copy for epilogues during loop transform since they are actually
modified by update_epilogue_loop_vinfo.  Avoid the pointless faking
of the original DRs there.

	* tree-vect-loop.cc (vect_transform_loop): Do not verify DRs
	have not been modified for epilogue loops.
	(update_epilogue_loop_vinfo): Do not copy modified DRs to
	the originals.
2025-07-31 12:11:21 +02:00
Jakub Jelinek e624d5559d change get_best_mode args int -> HOST_WIDE_INT [PR121264]
The following testcase is miscompiled, because byte 0x20000000
is bit 0x100000000 and ifcombine incorrectly combines the two loads
into a BIT_FIELD_REF even when they are very far away.
The problem is that gimple-fold.cc ifcombine uses get_best_mode heavily,
and that function has just int bitsize and int bitpos arguments, so
when called e.g. with
  if (get_best_mode (end_bit - first_bit, first_bit, 0, ll_end_region,
                     ll_align, BITS_PER_WORD, volatilep, &lnmode))
where end_bit - first_bit doesn't fit into int, it is silently truncated.
If there was just a single problematic get_best_mode call, I would probably
just check for overflows in the caller, but there are many.
And the two arguments are used solely as arguments to
bit_field_mode_iterator constructor which has HOST_WIDE_INT arguments,
so I think the easiest fix is just make the get_best_mode arguments
also HOST_WIDE_INT.

2025-07-31  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/121264
	* machmode.h (get_best_mode): Change type of first 2 arguments
	from int to HOST_WIDE_INT.
	* stor-layout.cc (get_best_mode): Likewise.

	* gcc.dg/tree-ssa/pr121264.c: New test.
2025-07-31 12:10:45 +02:00
Spencer Abson 9793ffce93 aarch64: testsuite: Fix do-assemble tests for SME
GCC doesn't support SME without SVE2, so the -march=armv8-a+<ext> argument to
check_no_compiler_messages causes aarch64_asm_<ext>_ok to return zero for SME
and any <ext> that implies it.  This patch changes the baseline architecure to
armv9-a for these extensions.

The tests for ACLE SME2 intrinsics that require FEAT_FAMINMAX were configured
to do-assemble if aarch64_asm_sme2_ok returned 1 (by default), but they really
need to check if +faminmax is supported too.  The fix above exposed this, so
we also fix the do-assemble/do-compile choice for those tests here.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/sme2/acle-asm/amax_f16_x2.c: Gate do-assemble on
	assembler support for +faminmax and +sme2.
	* gcc.target/aarch64/sme2/acle-asm/amax_f16_x4.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amax_f32_x2.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amax_f32_x4.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amax_f64_x2.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amax_f64_x4.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amin_f16_x2.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amin_f16_x4.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amin_f32_x2.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amin_f32_x4.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amin_f64_x2.c: Likewise.
	* gcc.target/aarch64/sme2/acle-asm/amin_f64_x4.c: Likewise.
	* lib/target-supports.exp: Split the extensions that require SME into
	a separate set, and use armv9-a as their baseline.
2025-07-31 10:08:18 +00:00
Jakub Jelinek 6e6cc1deb9 Fix comment typos - hanlde -> handle
2025-07-31  Jakub Jelinek  <jakub@redhat.com>

	* gimple-ssa-store-merging.cc (find_bswap_or_nop): Fix comment typos,
	hanlde -> handle.
	* config/i386/i386.cc (ix86_gimple_fold_builtin, ix86_rtx_costs):
	Likewise.
	* config/i386/i386-features.cc (remove_partial_avx_dependency):
	Likewise.

	* gcc.target/i386/apx-1.c (apx_hanlder): Rename to ...
	(apx_handler): ... this.
	* gcc.target/i386/uintr-2.c (UINTR_hanlder): Rename to ...
	(UINTR_handler): ... this.
	* gcc.target/i386/uintr-5.c (UINTR_hanlder): Rename to ...
	(UINTR_handler): ... this.
2025-07-31 10:48:45 +02:00
Richard Biener 8cae7cc099 Disallow scan-store vectorization in epilogues
The following disallows vectorizing epilogues containing scan-stores.
Since code generation works by walking gimple stmts it is not ready
for this when cleaning up epilogue vectorization.  I believe
scan-store vectorization needs most of the work done during SLP
discovery to reflect the data flow.

	* tree-vect-stmts.cc (check_scan_store): Remove redundant
	slp_node check.  Disallow epilogue vectorization.
2025-07-31 08:35:37 +02:00
Richard Biener fb59c5719c Avoid passing vectype != NULL when costing scalar IL
The following makes sure to not leak a set vectype on a stmt when
doing scalar IL costing as this can confuse vector cost models
which do not look at m_costing_for_scalar most of the time.

	* tree-vectorizer.h (vector_costs::costing_for_scalar): New
	accessor.
	(add_stmt_cost): For scalar costing force vectype to NULL.
	Verify we do not pass in a SLP node.
2025-07-31 08:31:17 +02:00
Kito Cheng da88f9bd9e RISC-V: Adding H to the canonical order [PR121312]
We added H into canonical order before, but forgot to add it to
arch-canonicalize as well...

gcc/ChangeLog:

	PR target/121312
	* config/riscv/arch-canonicalize: Add H extension to the
	canonical order.
2025-07-31 11:08:26 +08:00
GCC Administrator bec414d1b9 Daily bump. 2025-07-31 00:21:08 +00:00
Sam James dbe0ba6c90 [sanitizer_common] Remove reference to obsolete termio ioctls (#138822)
Cherry picked from LLVM commit c99b1bcd505064f2e086e6b1034ce0b0c91ea5b9.

The termio ioctls are no longer used after commit 59978b21ad9c
("[sanitizer_common] Remove interceptors for deprecated struct termio
(#137403)"), remove them.  Fixes this build error:

../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:765:27: error: invalid application of ‘sizeof’ to incomplete type ‘__sanitizer::termio’
  765 |   unsigned IOCTL_TCGETA = TCGETA;
      |                           ^~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:769:27: error: invalid application of ‘sizeof’ to incomplete type ‘__sanitizer::termio’
  769 |   unsigned IOCTL_TCSETA = TCSETA;
      |                           ^~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:770:28: error: invalid application of ‘sizeof’ to incomplete type ‘__sanitizer::termio’
  770 |   unsigned IOCTL_TCSETAF = TCSETAF;
      |                            ^~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:771:28: error: invalid application of ‘sizeof’ to incomplete type ‘__sanitizer::termio’
  771 |   unsigned IOCTL_TCSETAW = TCSETAW;
      |                            ^~~~~~~
2025-07-30 23:29:52 +01:00
Joseph Myers 3d44db05f0 Update cpplib sr.po
* sr.po: Update.
2025-07-30 22:12:41 +00:00
Nathaniel Shead bfb8615031 c++: Don't assume trait funcs return error_mark_node when tf_error is passed [PR121291]
For the sake of determining if there are other errors in user code to
report early, many trait functions don't always return error_mark_node
if not called in a SFINAE context (i.e., tf_error is set).  This patch
removes some assumptions on this behaviour I'd made when improving
diagnostics of builtin traits.

	PR c++/121291

gcc/cp/ChangeLog:

	* constraint.cc (diagnose_trait_expr): Remove assumption about
	failures returning error_mark_node.
	* except.cc (explain_not_noexcept): Allow expr not being
	noexcept.
	* method.cc (build_invoke): Adjust comment.
	(is_trivially_xible): Always note non-trivial components if expr
	is not null or error_mark_node.
	(is_nothrow_xible): Likewise for non-noexcept components.
	(is_nothrow_convertible): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/is_invocable7.C: New test.
	* g++.dg/ext/is_nothrow_convertible5.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-07-31 07:55:32 +10:00
François Dumont ec7244e6e0 libstdc++: Fix test when dual abi disabled
When !_GLIBCXX_USE_DUAL_ABI the old COW std::string implementation is being used
which do not generate the expected error diagnostics.

libstdc++-v3/ChangeLog:

	* testsuite/std/time/format/data_not_present_neg.cc: Remove _GLIBCXX_USE_DUAL_ABI
	check.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-07-30 21:16:31 +02:00
Jason Merrill d7cd6b0df5 c++: improve non-constant template arg diagnostic
A conversation today pointed out that the current diagnostic for this case
doesn't mention the constant evaluation failure, it just says e.g.

"'p' is not a valid template argument for 'int*' because it is not the
address of a variable"

This patch improves the diagnostic in C++17 and above (post-N4268) to
diagnose failed constant-evaluation.

gcc/cp/ChangeLog:

	* pt.cc (convert_nontype_argument_function): Check
	cxx_constant_value on failure.
	(invalid_tparm_referent_p): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/tc1/dr49.C: Adjust diagnostic.
	* g++.dg/template/func2.C: Likewise.
	* g++.dg/cpp1z/nontype8.C: New test.
2025-07-30 12:00:06 -04:00
Andrew Pinski 0340177d54 simplify-rtx: Add (subreg (not a)) simplification for word_mode [PR121308]
Right now in simplify_subreg, there is code to try to simplify for word_mode
with the binary bitwise operators. The unary bitwise operator is not handle,
this causes an odd mix match and the new self testing code that was added with
r16-2614-g965564eafb721f was not expecting.

The self testing code was for testing the newly added code but since there
was already code that handles word_mode, we hit the mismatch but only
for targets where word_mode is SImode (or smaller).

This adds the code to handle `not` in a similar fashion as the other
bitwise operators for word_mode.

Changes since v1:
* v2: add `&& SCALAR_INT_MODE_P (innermode)` to the conditional.

Bootstrapped and tested on x86_64-linux-gnu.

	PR rtl-optimization/121308
gcc/ChangeLog:

	* simplify-rtx.cc (simplify_context::simplify_subreg): Handle
	subreg of `not` with word_mode to make it symmetric with the
	other bitwise operators.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-07-30 08:27:51 -07:00
Andrew Pinski aebbc90d8c IFCVT: Fix factor_out_operators correctly for more than 1 phi [PR121295]
r16-2590-ga51bf9e10182cf was not the correct fix for this in the end.
Instead a much simplier and localized fix is needed, just change the phi
that is being worked on with the new result and arguments that is from the
factored out operator.
This solves the issue of not having result in the IR and causing issues that way.

Bootstrapped and tested on x86_64-linux-gnu.
Note this depends on reverting r16-2590-ga51bf9e10182cf.

	PR tree-optimization/121236
	PR tree-optimization/121295

gcc/ChangeLog:

	* tree-if-conv.cc (factor_out_operators): Change the phi node
	to the new result and args.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-07-30 08:19:07 -07:00
Andrew Pinski 0ab20ee0ea Revert "ifcvt: Fix ifcvt for multiple phi nodes after factoring operator [PR121236]"
This reverts commit a51bf9e101.
2025-07-30 08:19:07 -07:00
Jan Hubicka 994feb9edd Report read errors when reading auto-profile
currently -fauto-profile will happily read truncated file without any warning
and interpret it as a zero profile which will in turn result in slow code.
This patch exports gcov_is_error and adds checks so truncated files are detected.

gcc/ChangeLog:

	* auto-profile.cc (string_table::read): Check gcov_is_error.
	(read_profile): Likewise.
	* gcov-io.cc (gcov_is_error): Export for gcc linkage.
	* gcov-io.h (gcov_is_error): Declare.
2025-07-30 16:09:35 +02:00
Richard Biener e9ad533dd2 [x86] factor out worker from ix86_builtin_vectorization_cost
The following factors out a worker that gets a mode argument
rather than a vectype argument.  That makes a difference when
we hit the fallback in add_stmt_cost for scalar stmts where
vectype might be NULL and thus mode is derived from the scalar
stmt there.  But ix86_builtin_vectorization_cost does not
have access to the stmt.  So the patch instead dispatches
to the new ix86_default_vector_cost there, passing down the mode
we derived from the stmt.

This is to avoid regressions with a patch that makes even more
scalar stmt costings have a vectype passed.

	* config/i386/i386.cc (ix86_default_vector_cost): Split
	out from ...
	(ix86_builtin_vectorization_cost): ... this and use
	mode instead of vectype as argument.
	(ix86_vector_costs::add_stmt_cost): Call
	ix86_default_vector_cost instead of ix86_builtin_vectorization_cost.
2025-07-30 15:46:19 +02:00
Stefan Schulze Frielinghaus f61fb5ab83 s390: Implement spaceship optab [PR117015]
gcc/ChangeLog:

	PR target/117015
	* config/s390/s390-protos.h (s390_expand_int_spaceship): New
	function.
	(s390_expand_fp_spaceship): New function.
	* config/s390/s390.cc (s390_expand_int_spaceship): New function.
	(s390_expand_fp_spaceship): New function.
	* config/s390/s390.md (spaceship<mode>4): New expander.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/spaceship-fp-1.c: New test.
	* gcc.target/s390/spaceship-fp-2.c: New test.
	* gcc.target/s390/spaceship-fp-3.c: New test.
	* gcc.target/s390/spaceship-fp-4.c: New test.
	* gcc.target/s390/spaceship-int-1.c: New test.
	* gcc.target/s390/spaceship-int-2.c: New test.
	* gcc.target/s390/spaceship-int-3.c: New test.
2025-07-30 15:25:54 +02:00
Stefan Schulze Frielinghaus 22141f856d cprop: Allow jump bypassing for single set insns
During jump bypassing also consider insns of the form

(insn 25 57 26 9 (parallel [
            (set (reg:CCZ 33 %cc)
                (compare:CCZ (reg:SI 60 [ _9 ])
                    (const_int 0 [0])))
            (clobber (scratch:SI))
        ]) "spaceship-fp-4.c":27:1 1746 {*tstsi_cconly_extimm}
     (nil))

by testing for a single set insn during bypass_conditional_jumps().
This is a requirement for test gcc.target/s390/spaceship-fp-4.c of the
subsequent commit.

In order to silence

cprop.cc:1621:40: error: 'setcc_dest' may be used uninitialized [-Werror=maybe-uninitialized]
 1621 |             src = simplify_replace_rtx (src, setcc_dest, setcc_src);
      |                   ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

initialize setcc_{dest,src} in bypass_block() although this is not
really required.

gcc/ChangeLog:

	* cprop.cc (bypass_block): Extract single set.
	(bypass_conditional_jumps): Ditto.
2025-07-30 15:25:54 +02:00
H.J. Lu 71dae74158 x86: Transform to "pushq $-1; popq reg" for -Oz
commit 4c80062d7b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun May 25 07:40:29 2025 +0800

    x86: Enable *mov<mode>_(and|or) only for -Oz

disabled transformation from "movq $-1,reg" to "pushq $-1; popq reg" for
-Oz.  But for legacy integer registers, the former is 4 bytes and the
latter is 3 bytes.  Enable such transformation for -Oz.

gcc/

	PR target/120427
	* config/i386/i386.md (peephole2): Transform "movq $-1,reg" to
	"pushq $-1; popq reg" for -Oz if reg is a legacy integer register.

gcc/testsuite/

	PR target/120427
	* gcc.target/i386/pr120427-5.c: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-07-30 06:15:38 -07:00
Jan Hubicka 7827ae8e61 auto-profile fixes
This patch silences warning about bad location in function_instance::match
warning about profile containing record for line numbers that are not matched
by the function body.  While this is a bogus profile (and we will end up losing
the profile data), create_gcov does not have enough information to output them
correctly in all contexts since in dwarf5 we output multiple locations per single
instructions (possibly comming from different inlines) while it can only represent
one inline stack.

The patch also fixes issue with profile scaling.   By making force_nonzero to
take into account cutoffs, I made the test for counter being non-zero before scaling
too agressive.

gcc/ChangeLog:

	* auto-profile.cc (function_instance::match): Disable warning
	about bogus locations since dwarf does not represent enough
	info to output them correctly in all cases.
	(add_scale): Use nonzero_p instead of orig.force_nonzero () == orig.
	(afdo_adjust_guessed_profile): Add missing newline in dump
	file.
2025-07-30 15:05:45 +02:00
Jan Hubicka 05e4bb8829 Fix symbol_table::change_decl_assembler_name when DECL_RTL is already computed
while working on patch assigning unique names to static symbols I noticed that
fortran symbols are not renamed since the frontend calls make_decl_rtl.  This
gets DECL_ASSEMBBLER_NAME and DECL_RTL out of sync. I think we can drop that
call, but it is also good idea to avoid this inconsistence, so this patch makes
symbol_table::change_decl_assembler_name to recompute DECL_RTL in this case.

gcc/ChangeLog:

	* symtab.cc (symbol_table::change_decl_assembler_name): Recompute DECL_RTL
	in case it is already computed.
2025-07-30 15:05:44 +02:00
Jan Hubicka 1d3e713dda Fix fasle profile insonsistency error
This patch fixes false incosistent profile error message seen when building SPEC with
-fprofile-use -fdump-ipa-profile.
The problem is that with dumping tree_esitmate_probability is run in dry run
mode to report success rates of heuristics.  It however runs determine_unlikely_bbs
which ovewrites some counts to profile_count::zero and later value profiling sees
the mismatch.

In sane profile determine_unlikely_bbs should be almost always no-op since it
should only drop to 0 things that are known to be unlikely executed. What
happens here is that there is a comdat where profile is lost and we see a
call with non-zero count calling function with zero count and "fix" the profile
by making the call to have zero count, too.

I also extended unlikely prediates to avoid tampering with predictions when
prediciton is believed to be reliable.  This also avoids us from dropping all
EH regions to 0 count as tested by the testcase.

gcc/ChangeLog:

	* predict.cc (unlikely_executed_edge_p): Ignore EDGE_EH if profile
	is reliable.
	(unlikely_executed_stmt_p): special case builtin_trap/unreachable and
	ignore other heuristics for reliable profiles.
	(tree_estimate_probability): Disable unlikely bb detection when
	doing dry run

gcc/testsuite/ChangeLog:

	* g++.dg/tree-prof/eh1.C: New test.
2025-07-30 15:05:18 +02:00
Andrew StubbsandJulian Brown 36c5a7aa9a vect: Add target hook to prefer gather/scatter instructions
For AMD GCN, the instructions available for loading/storing vectors are
always scatter/gather operations (i.e. there are separate addresses for
each vector lane), so the current heuristic to avoid gather/scatter
operations with too many elements in get_group_load_store_type is
counterproductive. Avoiding such operations in that function can
subsequently lead to a missed vectorization opportunity whereby later
analyses in the vectorizer try to use a very wide array type which is
not available on this target, and thus it bails out.

This patch adds a target hook to override the "single_element_p"
heuristic in the function as a target hook, and activates it for GCN. This
allows much better code to be generated for affected loops.

Co-authored-by:  Julian Brown  <julian@codesourcery.com>

gcc/
	* doc/tm.texi.in (TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Add
	documentation hook.
	* doc/tm.texi: Regenerate.
	* target.def (prefer_gather_scatter): Add target hook under vectorizer.
	* hooks.cc (hook_bool_mode_int_unsigned_false): New function.
	* hooks.h (hook_bool_mode_int_unsigned_false): New prototype.
	* tree-vect-stmts.cc (vect_use_strided_gather_scatters_p): Add
	parameters group_size and single_element_p, and rework to use
	targetm.vectorize.prefer_gather_scatter.
	(get_group_load_store_type): Move some of the condition into
	vect_use_strided_gather_scatters_p.
	* config/gcn/gcn.cc (gcn_prefer_gather_scatter): New function.
	(TARGET_VECTORIZE_PREFER_GATHER_SCATTER): Define hook.
2025-07-30 12:48:25 +00:00
Andrew Stubbs b31fa1ce19 Don't pass vector params through to offload targets
The optimization options are deliberately passed through to the LTO compiler,
but when the same mechanism is reused for offloading it ends up forcing the
host compiler settings onto the device compiler.  Maybe this should be removed
completely, but this patch just fixes a few of them.  In particular,
param_vect_partial_vector_usage is disabled by x86 and this really hurts amdgcn.

I also fixed an ambiguous else warning in the generated file by adding braces.

gcc/ChangeLog:

	* config/gcn/gcn.cc (gcn_option_override): Add note to set default for
	param_vect_partial_vector_usage to "1".
	* optc-save-gen.awk: Don't pass through options marked "NoOffload".
	* params.opt (-param=vect-epilogues-nomask): Add NoOffload.
	(-param=vect-partial-vector-usage): Likewise.
	(-param=vect-inner-loop-cost-factor): Likewise.
2025-07-30 12:47:32 +00:00
Richard Biener a0d2de441e tree-optimization/121130 - vectorizable_call cannot handle .MASK_CALL
The following makes it correctly reject them,
vectorizable_simd_clone_call is solely responsible for them.

	PR tree-optimization/121130
	* tree-vect-stmts.cc (vectorizable_call): Bail out for
	.MASK_CALL.

	* gcc.dg/vect/vect-simd-pr121130.c: New testcase.
2025-07-30 13:40:05 +02:00
Jakub Jelinek fac66b476a c++: Make __extension__ silence -Wlong-long pedwarns/warnings [PR121133]
The PR13358 r0-92909 change changed the diagnostics on long long
in C++ (either with -std=c++98 or -Wlong-long), but unlike the
C FE we unfortunately warn even in the
__extension__ long long a;
etc. cases.  The C FE in that case in
disable_extension_diagnostics saves and clears not just
pedantic flag but also warn_long_long (and several others), while
C++ FE only temporarily disables pedantic.

The following patch makes it behave like the C FE in this regard,
though (__extension__ 1LL) still doesn't work because of the
separate lexing (and I must say I have no idea how to fix that).

Or do you prefer a solution closer to the C FE, cp_parser_extension_opt
saving the values into a bitfield and have another function to restore
the state (or use RAII)?

2025-07-30  Jakub Jelinek  <jakub@redhat.com>

	PR c++/121133
	* parser.cc (cp_parser_unary_expression): Adjust
	cp_parser_extension_opt caller and restore warn_long_long.
	(cp_parser_declaration): Likewise.
	(cp_parser_block_declaration): Likewise.
	(cp_parser_member_declaration): Likewise.
	(cp_parser_extension_opt): Add SAVED_LONG_LONG argument,
	save previous warn_long_long state into it and clear it
	for __extension__.

	* g++.dg/warn/pr121133-1.C: New test.
	* g++.dg/warn/pr121133-2.C: New test.
	* g++.dg/warn/pr121133-3.C: New test.
	* g++.dg/warn/pr121133-4.C: New test.
2025-07-30 13:23:56 +02:00
Jakub Jelinek 8f185d3d7a libcpp: Fix up comma diagnostics in preprocessor for C++ [PR120778]
The P2843R3 Preprocessing is never undefined paper contains comments
that various compilers handle comma operators in preprocessor expressions
incorrectly and I think they are right.

In both C and C++ the grammar uses constant-expression non-terminal
for #if/#elif and in both C and C++ that NT is conditional-expression,
so
  #if 1, 2
is IMHO clearly wrong in both languages.

C89 then says for constant-expression
"Constant expressions shall not contain assignment, increment, decrement,
function-call, or comma operators, except when they are contained within the
operand of a sizeof operator."
Because all the remaining identifiers in the #if/#elif expression are
replaced with 0 I think assignments, increment, decrement and function-call
aren't that big deal because (0 = 1) or ++4 etc. are all invalid, but
for comma expressions I think it matters.  In r0-56429 PR456 Joseph has
added !CPP_OPTION (pfile, c99) to handle that correctly.
Then C99 changed that to:
"Constant expressions shall not contain assignment, increment, decrement, function-call,
or comma operators, except when they are contained within a subexpression that is not
evaluated."
That made for C99+
  #if 1 || (1, 2)
etc. valid but
  #if (1, 2)
is still invalid, ditto
  #if 1 ? 1, 2 : 3

In C++ I can't find anything like that though, and as can be seen on say
int a[(1, 2)];
int b[1 ? 1, 2 : 3];
being accepted by C++ and rejected by C while
int c[1, 2];
int d[1 ? 2 : 3, 4];
being rejected in both C and C++, so I think for C++ it is indeed just the
grammar that prevents #if 1, 2.  When it is the second operand of ?: or
inside of () the grammar just uses expression and that allows comma
operator.

So, the following patch uses different decisions for C++ when to diagnose
comma operator in preprocessor expressions, for C++ tracks if it is inside
of () (obviously () around #embed clauses don't count unless one uses
limit ((1, 2)) etc.) or inside of the second ?: operand and allows comma
operator there and disallows elsewhere.

BTW, I wonder if anything in the standard disallows <=> in the preprocessor
expressions.  Say
  #if (0 <=> 1) < 0
etc.
  #include <compare>
  constexpr int a = (0 <=> 1) < 0;
is valid (but not valid without #include <compare>) and the expressions
don't use any identifiers.

2025-07-30  Jakub Jelinek  <jakub@redhat.com>

	PR c++/120778
	* internal.h (struct lexer_state): Add comma_ok member.
	* expr.cc (_cpp_parse_expr): Initialize it to 0, increment on
	CPP_OPEN_PAREN and CPP_QUERY, decrement on CPP_CLOSE_PAREN
	and CPP_COLON.
	(num_binary_op): For C++ pedwarn on comma operator if
	pfile->state.comma_ok is 0 instead of !c99 or skip_eval.

	* g++.dg/cpp/if-comma-1.C: New test.
2025-07-30 13:20:59 +02:00
Pengfei Li 28310b3ff8 vect: Add missing skip-vector check for peeling with versioning [PR121020]
This fixes a miscompilation issue introduced by the enablement of
combined loop peeling and versioning. A test case that reproduces the
issue is included in the patch.

When performing loop peeling, GCC usually inserts a skip-vector check.
This ensures that after peeling, there are enough remaining iterations
to enter the main vectorized loop. Previously, the check was omitted if
loop versioning for alignment was applied. It was safe before because
versioning and peeling for alignment were mutually exclusive.

However, with combined peeling and versioning enabled, this is not safe
any more. A loop may be peeled and versioned at the same time. Without
the skip-vector check, the main vectorized loop can be entered even if
its iteration count is zero. This can cause the loop running many more
iterations than needed, resulting in incorrect results.

To fix this, the patch updates the condition of omitting the skip-vector
check to when versioning is performed alone without peeling.

gcc/ChangeLog:

	PR tree-optimization/121020
	* tree-vect-loop-manip.cc (vect_do_peeling): Update the
	condition of omitting the skip-vector check.
	* tree-vectorizer.h (LOOP_VINFO_USE_VERSIONING_WITHOUT_PEELING):
	Add a helper macro.

gcc/testsuite/ChangeLog:

	PR tree-optimization/121020
	* gcc.dg/vect/vect-early-break_138-pr121020.c: New test.
2025-07-30 10:54:14 +01:00
Pengfei Li 46a862ef08 vect: Fix insufficient alignment requirement for speculative loads [PR121190]
This patch fixes a segmentation fault issue that can occur in vectorized
loops with an early break. When GCC vectorizes such loops, it may insert
a versioning check to ensure that data references (DRs) with speculative
loads are aligned. The check normally requires DRs to be aligned to the
vector mode size, which prevents generated vector load instructions from
crossing page boundaries.

However, this is not sufficient when a single scalar load is vectorized
into multiple loads within the same iteration. In such cases, even if
none of the vector loads crosses page boundaries, subsequent loads after
the first one may still access memory beyond current valid page.

Consider the following loop as an example:

	while (i < MAX_COMPARE) {
	  if (*(p + i) != *(q + i))
	    return i;
	  i++;
	}

When compiled with "-O3 -march=znver2" on x86, the vectorized loop may
include instructions like:

	vmovdqa (%rcx,%rax), %ymm0
	vmovdqa 32(%rcx,%rax), %ymm1
	vpcmpeqq (%rdx,%rax), %ymm0, %ymm0
	vpcmpeqq 32(%rdx,%rax), %ymm1, %ymm1

Note two speculative vector loads are generated for each DR (p and q).
The first vmovdqa and vpcmpeqq are safe due to the vector size (32-byte)
alignment, but the following ones (at offset 32) may not be safe because
they could read from the beginning of the next memory page, potentially
leading to segmentation faults.

To avoid the issue, this patch increases the alignment requirement for
speculative loads to DR_TARGET_ALIGNMENT. It ensures all vector loads in
the same vector iteration access memory within the same page.

gcc/ChangeLog:

	PR tree-optimization/121190
	* tree-vect-data-refs.cc (vect_enhance_data_refs_alignment):
	Increase alignment requirement for speculative loads.

gcc/testsuite/ChangeLog:

	PR tree-optimization/121190
	* gcc.dg/vect/vect-early-break_52.c: Update an unsafe test.
	* gcc.dg/vect/vect-early-break_137-pr121190.c: New test.
2025-07-30 10:53:10 +01:00
Alfie Richards 483326615e aarch64: Fix sme2+faminmax intrisic gating (PR 121300)
Fixes the feature gating for the SME2+FAMINMAX intrinsics.

	PR target/121300

gcc/ChangeLog:

	* config/aarch64/aarch64-sve-builtins-sme.def (svamin/svamax): Fix
	arch gating.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/pr121300.c: New test.
2025-07-30 09:17:32 +00:00
Richard Biener 10a5762984 tree-optimization/121304 - set memory_access_type before reading it
The following re-orders gather/scatter handling back to be before
we check for fallback situations, specifically make sure to set
memory_access_type before reading it.

	* tree-vect-stmts.cc (get_group_load_store_type):
	Process STMT_VINFO_GATHER_SCATTER before reading
	memory_access_type.
2025-07-30 11:15:21 +02:00
Spencer Abson 45fd943eab aarch64: Add support for unpacked SVE FP conditional ternary arithmetic
This patch extends the expander for fma, fnma, fms, and fnms to support
partial SVE FP modes.

We add the missing BF16 tests, which we can now trigger for having
implemented the conditional expander.

We also add tests for the 'merging with multiplicand' case, which this
expander canonicalizes (albeit under SVE_STRICT_GP).

gcc/ChangeLog:

	* config/aarch64/aarch64-sve.md (@cond_<optab><mode>): Extend
	to support partial FP modes.
	(*cond_<optab><mode>_2_strict): Extend from SVE_FULL_F to SVE_F,
	use aarch64_predicate_operand.
	(*cond_<optab><mode>_4_strict): Extend from SVE_FULL_F_B16B16 to
	SVE_F_B16B16, use aarch64_predicate_operand.
	(*cond_<optab><mode>_any_strict):  Likewise.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/sve/unpacked_cond_fmla_1.c: Add test cases
	for merging with multiplcand.
	* gcc.target/aarch64/sve/unpacked_cond_fmls_1.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fnmla_1.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fnmls_1.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fmla_2.c: New test.
	* gcc.target/aarch64/sve/unpacked_cond_fmls_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fnmla_2.c: Likewise..
	* gcc.target/aarch64/sve/unpacked_cond_fnmls_2.c: Likewise.
	* g++.target/aarch64/sve/unpacked_cond_ternary_bf16_1.C: Likewise.
	* g++.target/aarch64/sve/unpacked_cond_ternary_bf16_2.C: Likewise.
2025-07-30 08:58:50 +00:00
Spencer Abson 84f8f1ff6a aarch64: Relaxed SEL combiner patterns for unpacked SVE FP ternary arithmetic
Extend the ternary op/UNSPEC_SEL combiner patterns from SVE_FULL_F/
SVE_FULL_F_BF to SVE_F/SVE_F_BF, where the strictness value is
SVE_RELAXED_GP.

We can only reliably test the 'merging with the third input' (addend)
and 'independent value' patterns at this stage as the canocalisation that
reorders the multiplicands based on the second SEL input would be performed
by the conditional expander.

Another difficulty is that we can't test these fused multiply/SEL combines
without using __builtin_fma and friends.  The reason for this is as follows:

We support COND_ADD, COND_SUB, and COND_MUL optabs, so match.pd will
canonicalize patterns like ADD/SUB/MUL combined with a VEC_COND_EXPR into
these conditional forms.  Later, when widening_mul tries to fold these into
conditional fused multiply operations, the transformation fails - simply
because we haven’t implemented those conditional fused multiply optabs yet.

Hence why this patch lacks tests for BFloat16...

gcc/ChangeLog:

	* config/aarch64/aarch64-sve.md (*cond_<optab><mode>_2_relaxed):
	Extend from SVE_FULL_F to SVE_F.
	(*cond_<optab><mode>_4_relaxed): Extend from SVE_FULL_F_B16B16
	to SVE_F_B16B16.
	(*cond_<optab><mode>_any_relaxed): Likewise.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/sve/unpacked_cond_fmla_1.c: New test.
	* gcc.target/aarch64/sve/unpacked_cond_fmls_1.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fnmla_1.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fnmls_1.c: Likewise.
2025-07-30 08:40:27 +00:00
Mikael Morin 25593e5554 fortran: Remove useless elements count variable
The function gfc_array_init_size evaluates the number of array elements
to a variable from a caller, but the single caller providing the
variable actually doesn't use it.

This change removes the variable and the function arguments passing its
address down the call chain.

gcc/fortran/ChangeLog:

	* trans-array.cc (gfc_array_init_size): Remove the nelems
	argument.
	(gfc_array_allocate): Update caller.  Remove the nelems
	argument.
	* trans-stmt.cc (gfc_trans_allocate): Update caller.  Remove the
	nelems variable.
	* trans-array.h (gfc_array_allocate): Update prototype.
2025-07-30 10:35:12 +02:00
Yuao Ma fa6c9c2e48 fortran: implement split for fortran 2023
This patch includes the implementation, documentation, and test case for SPLIT.

gcc/fortran/ChangeLog:

	* check.cc (gfc_check_split): Argument check for SPLIT.
	* gfortran.h (enum gfc_isym_id): Define GFC_ISYM_SPLIT.
	* intrinsic.cc (add_subroutines): Register SPLIT intrinsic.
	* intrinsic.h (gfc_check_split): New decl.
	(gfc_resolve_split): Ditto.
	* intrinsic.texi: SPLIT documentation.
	* iresolve.cc (gfc_resolve_split): Add resolved_sym for SPLIT.
	* trans-decl.cc (gfc_build_intrinsic_function_decls): Add decl for
	SPLIT in libgfortran.
	* trans-intrinsic.cc (conv_intrinsic_split): SPLIT codegen.
	(gfc_conv_intrinsic_subroutine): Handle SPLIT case.
	* trans.h (GTY): Declare gfor_fndecl_string_split{, _char4}.

libgfortran/ChangeLog:

	* gfortran.map: Add split symbol.
	* intrinsics/string_intrinsics_inc.c (string_split):
	Runtime support for SPLIT.

gcc/testsuite/ChangeLog:

	* gfortran.dg/split_1.f90: New test.
	* gfortran.dg/split_2.f90: New test.
	* gfortran.dg/split_3.f90: New test.
	* gfortran.dg/split_4.f90: New test.

Signed-off-by: Yuao Ma <c8ef@outlook.com>
2025-07-30 10:30:46 +02:00
Spencer Abson e16fac19a2 aarch64: Add support for unpacked SVE FP ternary arithmetic
This patch extends the expander for unconditional fma, fnma, fms, and
fnms, so that it supports partial SVE FP modes.

gcc/ChangeLog:

	* config/aarch64/aarch64-sve.md (<optab><mode>4): Extend from
	SVE_FULL_F_B16B16 to SVE_F_B16B16.  Use aarch64_sve_fp_pred instead
	of aarch64_ptrue_reg.
	(@aarch64_pred_<optab><mode>): Extend from SVE_FULL_F_B16B16 to
	SVE_F_B16B16.  Use aarch64_predicate_operand.

gcc/testsuite/ChangeLog:

	* g++.target/aarch64/sve/unpacked_ternary_bf16_1.C: New test.
	* g++.target/aarch64/sve/unpacked_ternary_bf16_2.C: Likewise.
	* gcc.target/aarch64/sve/unpacked_fmla_1.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_fmla_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_fmls_1.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_fmls_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_fnmla_1.c: Likeiwse.
	* gcc.target/aarch64/sve/unpacked_fnmla_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_fnmls_1.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_fnmls_2.c: Likewise.
2025-07-30 07:59:42 +00:00
liuhongt 9d4a193181 Remove V64SFmode and V64SImode.
It's needed by avx5124vnniw/avx5124fmaps which have been removed by
r15-656-ge1a7e2c54d52d0.

gcc/ChangeLog:

	* config/i386/i386-modes.def: Remove VECTOR_MODES(FLOAT, 256)
	and VECTOR_MODE (INT, SI, 64).
	* config/i386/i386.cc (ix86_hard_regno_nregs): Remove related
	code for V64SF/V64SImode.
2025-07-30 00:41:49 -07:00
liuhongt 6a46683934 Eliminate redundant vpextrq/vpinsrq when move TI to V4SI.
r14-1902-g96c3539f2a3813 split TImode move with 2 DImode move, it's
supposed to optimize TImode in parameter/return since accoring to
psABI it's stored into 2 general registers.

But when TImode is not in parameter/return, it could create redundancy
in the PR.

The patch add a splitter to handle that.

.i.e.
(insn 10 9 14 2 (set (subreg:V2DI (reg:V4SI 98 [ <retval> ]) 0)
		     (vec_concat:V2DI (subreg:DI (reg:TI 101) 0)
			 (subreg:DI (reg:TI 101) 8)))
			 8442 {vec_concatv2di}
			(expr_list:REG_DEAD (reg:TI 101)

gcc/ChangeLog:

	PR target/121274
	* config/i386/sse.md (*vec_concatv2di_0): Add a splitter
	before it.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr121274.c: New test.
2025-07-30 00:35:00 -07:00
Pan Li 7aa9565a62 RISC-V: Add testcases for unsigned avg ceil vx combine.
The unsigned avg ceil share the vaaddux.vx for the vx combine,
so add the test case to make sure it works well as expected.

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

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Add asm check
	for unsigned avg ceil.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u16.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u32.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u64.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u8.c: Ditto.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary.h: Add test
	helper macros.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_data.h: Add
	test data.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vaadd-run-2-u16.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vaadd-run-2-u32.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vaadd-run-2-u64.c: New test.
	* gcc.target/riscv/rvv/autovec/vx_vf/vx_vaadd-run-2-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-07-30 09:29:12 +08:00
GCC Administrator b9d36b9ae9 Daily bump. 2025-07-30 00:19:13 +00:00
Andrew Pinski ef49f8e948 simplify-rtx: Fix Distribute subregs over logic ops [PR121302]
r16-2614-g965564eafb721f had a typo where it would assume byte==0
rather than use the byte (offset) that was passed.

This fixes that typo and also fixes the comment since it is not just
about lowerpart subregs but all non-paradoxical subregs.

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

	PR rtl-optimization/121302
gcc/ChangeLog:

	* simplify-rtx.cc (simplify_context::simplify_subreg): Use
	byte instead of 0 when calling simplify_subreg.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-07-29 17:09:04 -07:00
Andrew Pinski 688f1947bd testsuite: Cleanup after auto-profile testcases when auto-profile is not supported [PR121215]
The problem here is that in tree-prof.exp does not cleanup if requiring auto-profile
but it is not supported and the testcase uses dg-additional-sources. Currently additional_sources
is not reset to "" and then another testcase comes along and thinks that is the additional source
to be added.

Committed as obvious after testing:
make check-gcc RUNTESTFLAGS="tree-prof.exp=afdo-crossmodule-1.c tree-ssa.exp=pr67891.c"
to make sure pr67891.c now no longer uses the additional source.

	PR testsuite/121215
gcc/testsuite/ChangeLog:

	* lib/profopt.exp (profopt-execute): Call cleanup-after-saved-dg-test
	if returning early for the -fauto-profile case failing case.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-07-29 11:00:26 -07:00
Spencer Abson 241380c6d6 aarch64: Add support for unpacked SVE FP conditional binary arithmetic
This patch extends the expander for conditional smax, smin, add, sub, mul,
min, max, and div to support partial SVE FP modes.

If exceptions from undefined vector elements must be suppressed, this
expansion converts the container-level predicate to an element-level one, and
ensures that these elements are inactive for the operation.  In practice, this
is a predicate AND with the existing mask and a container-size PTRUE.

gcc/ChangeLog:

	* config/aarch64/aarch64-protos.h (aarch64_sve_emit_masked_fp_pred):
	Declare.
	* config/aarch64/aarch64-sve.md (and<mode>3):  Change this to...
	(@and<mode>3): ...this, so that we can use gen_and3.
	(@cond_<optab><mode>): Extend from SVE_FULL_F_B16B16 to SVE_F_B16B16,
	use aarch64_predicate_operand.
	(*cond_<optab><mode>_2_strict): Likewise.
	(*cond_<optab><mode>_3_strict): Likewise.
	(*cond_<optab><mode>_any_strict): Likwise.
	(*cond_<optab><mode>_2_const_strict): Extend from SVE_FULL_F to SVE_F,
	use aarch64_predicate_operand.
	(*cond_<optab><mode>_any_const_strict): Likewise.
	(*cond_sub<mode>_3_const_strict): Likwise.
	(*cond_sub<mode>_const_strict): Likewise.
	(*vcond_mask_<mode><vpred>): Use aarch64_predicate_operand, and update
	the comment here.
	* config/aarch64/aarch64.cc (aarch64_sve_emit_masked_fp_pred): New
	function.  Helper to mask the predicate in conditional expanders.

gcc/testsuite/ChangeLog:

	* g++.target/aarch64/sve/unpacked_cond_binary_bf16_2.C: New test.
	* gcc.target/aarch64/sve/unpacked_cond_builtin_fmax_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_builtin_fmin_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fadd_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fdiv_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fmaxnm_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fminnm_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fmul_2.c: Likewise.
	* gcc.target/aarch64/sve/unpacked_cond_fsubr_2.c: Likewise.
2025-07-29 17:21:02 +00:00
H.J. Lu c6d1f58da7 x86: Pass -mno-80387 to compile pr121208-1(a|b).c
Pass -mno-80387 to compile pr121208-1(a|b).c to silence

.../pr121208-1a.c:11:1: sorry, unimplemented: 80387 instructions aren’t allowed in a function with the ‘no_caller_saved_registers’ attribute

	PR target/121208
	* gcc.target/i386/pr121208-1a.c (dg-options): Add -mno-80387.
	* gcc.target/i386/pr121208-1b.c (dg-options): Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-07-29 09:18:15 -07:00
Juergen Christ 9e91a99b2b testsuite: Adjust s390x params for vector tests.
Loop peeling and minimal loop vectorization threshold prevented loop
vectorization in these examples.  Adjust parameters in the test to
make the test pass.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>

	PR testsuite/121286
	PR testsuite/121288

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/pr112325.c: Adjust parameters for s390.
	* gcc.dg/vect/pr117888-1.c: Ditto.
2025-07-29 17:41:38 +02:00
Dongyan Chen b752a4df12 RISC-V: Generate -mcpu and -mtune options from riscv-cores.def.
Automatically generate -mcpu and -mtune options in invoke.texi from
the unified riscv-cores.def metadata, ensuring documentation stays in sync
with definitions and reducing manual maintenance.

gcc/ChangeLog:

	* Makefile.in: Add riscv-mcpu.texi and riscv-mtune.texi to the list
	of files to be processed by the Texinfo generator.
	* config/riscv/t-riscv: Add rule for generating riscv-mcpu.texi
	and riscv-mtune.texi.
	* doc/invoke.texi: Replace hand‑written extension table with
	`@include riscv-mcpu.texi` and `@include riscv-mtune.texi` to
	pull in auto‑generated entries.
	* config/riscv/gen-riscv-mcpu-texi.cc: New file.
	* config/riscv/gen-riscv-mtune-texi.cc: New file.
	* doc/riscv-mcpu.texi: New file.
	* doc/riscv-mtune.texi: New file.
2025-07-29 23:02:21 +08:00
Richard Sandiford 965564eafb simplify-rtx: Simplify subregs of logic ops
This patch adds a new rule for distributing lowpart subregs through
ANDs, IORs, and XORs with a constant, in cases where one of the terms
then disappears.  For example:

  (lowart-subreg:QI (and:HI x 0x100))

simplifies to zero and

  (lowart-subreg:QI (and:HI x 0xff))

simplifies to (lowart-subreg:QI x).

This would often be handled at some point using nonzero bits.  However,
the specific case I want the optimisation for is SVE predicates,
where nonzero bit tracking isn't currently an option.  Specifically:
the predicate modes VNx8BI, VNx4BI and VNx2BI have the same size as
VNx16BI, but treat only every second, fourth, or eighth bit as
significant.  Thus if we have:

  (subreg:VNx8BI (and:VNx16BI x C))

where C is the repeating constant { 1, 0, 1, 0, ... }, then the
AND only clears bits that are made insignificant by the subreg,
and so the result is equal to (subreg:VNx8BI x).  Later patches
rely on this.

gcc/
	* simplify-rtx.cc (simplify_context::simplify_subreg): Distribute
	lowpart subregs through AND/IOR/XOR, if doing so eliminates one
	of the terms.
	(test_scalar_int_ext_ops): Add some tests of the above for integers.
	* config/aarch64/aarch64.cc (aarch64_test_sve_folding): Likewise
	add tests for predicate modes.
2025-07-29 15:58:34 +01:00
Richard Sandiford cc9c041fd1 testsuite: Generalise aarch64/saturating_arithmetic*.c
gcc.target/aarch64/saturating_arithmetic_{1,2}.c expect w0 and w1 to
be duplicated into vectors.  The tests expected the duplication of w1
to happen first, but the other order would be fine too.  A later
simplify-rtx.cc patch happens to change the order.

gcc/testsuite/
	* gcc.target/aarch64/saturating_arithmetic_1.c: Allow w0 and w1
	to be duplicated in either order.
	* gcc.target/aarch64/saturating_arithmetic_2.c: Likewise.
2025-07-29 15:58:33 +01:00
Richard Sandiford 9c3f2cb35d testsuite: Make aarch64/cmpbr.c more forgiving
The 8-bit and 16-bit tests in cmpbr.c assumed an inverted operand
order ("w1, w0"), but it's possible to use the uninverted operand
order too.  This patch generalises the tests to support both forms.

This is a prerequisite for a later patch that adds a new
simplify-rtx.cc rule.

gcc/testsuite/
	* gcc.target/aarch64/cmpbr.c: Support both operand orders
	for 8-bit and 16-bit comparisons.
2025-07-29 15:58:33 +01:00
Richard Sandiford 668936caf0 aarch64: Fix function_expander::get_reg_target
function_expander::get_reg_target didn't actually check for a register,
meaning that it could return a memory target instead.  That doesn't
really matter for the current direct and indirect uses (svundef*,
svcreate*, and svset*) but it will for later patches.

gcc/
	* config/aarch64/aarch64-sve-builtins.cc
	(function_expander::get_reg_target): Check whether the target
	is a valid register_operand.
2025-07-29 15:58:32 +01:00
Gaius Mulley 21e16e4a1a [modula2] Tidyup remove unused local variables
This patch removes unused local variables from three procedures.

gcc/m2/ChangeLog:

	* gm2-compiler/M2GenGCC.mod (FoldBecomes): Remove all
	local variables.
	(CodeIndrX): Remove length.
	Remove newstr.
	* gm2-compiler/M2Range.mod (FoldTypeIndrX): Remove desType.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-07-29 15:52:58 +01:00
Konstantinos Eleftheriou fa1919d321 asf: Fix case of multiple stores with base offset [PR120660]
When having multiple stores with the same offset as the load, in the
case that we are eliminating the load, we were generating a mov instruction
for both of them, leading to the overwrite of the register containing the
loaded value.

This patch fixes this issue by generating a mov instruction only for the
first store in the store-load sequence that has the same offset as the load.
For the next ones that might be encountered, we use bit-field insertion.

Bootstrapped/regtested on AArch64 and x86_64.

	PR rtl-optimization/120660

gcc/ChangeLog:

	* avoid-store-forwarding.cc (process_store_forwarding):
	Fix instruction generation when haveing multiple stores with
	base offset.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr120660.c: New test.
2025-07-29 16:27:16 +02:00
Tomasz Kamiński 689ee39f7b libsdc++: Test using range_format::map as format_kind.
This adderess TODO from the test file.

libstdc++-v3/ChangeLog:

	* testsuite/std/format/ranges/format_kind.cc: New test.

Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-07-29 16:08:46 +02:00
Christoph Müllner b267361f23 RISC-V: Remove use of structured binding to fix compiler warning
Function riscv_ext_is_subset () uses structured bindings to iterate over
all keys and values of an unordered map.  However, this is only
available since C++17 and causes a warning like this:
  warning: structured bindings only available with ‘-std=c++17’
This patch addresses the warning.

gcc/ChangeLog:

	* common/config/riscv/riscv-common.cc (riscv_ext_is_subset):
	Remove use of structured binding to fix compiler warning.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2025-07-29 15:53:16 +02:00
Konstantinos Eleftheriou 04f33a2785 asf: Skip when an instruction doesn't satisfy the constraints [PR119795]
While scanning the instructions and upon reaching an instruction that
doesn't satisfy the constraints that we have set, we were removing the
already detected stores, but we were continuing adding stores from that
point onward. This was causing issues when the address ranges from later
stores overlapped with the load's address, leading to partial and wrong
update of the register containing the loaded value.

With this patch, we are skipping the tranformation for stores that operate
on the load's address range, when stores that operate on the same range
have been deleted due to constraint violations.

	PR rtl-optimization/119795

gcc/ChangeLog:

	* avoid-store-forwarding.cc
	(store_forwarding_analyzer::avoid_store_forwarding): Skip
	transformations for stores that operate on the same address
	range as deleted ones.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr119795.c: New test.
2025-07-29 15:46:58 +02:00
Pan Li 8166458f19 RISC-V: Add test cases for mul based unsigned scalar SAT_MUL
Add run and tree-optimized check for mul based unsigned scalar SAT_MUL
instead of the widen_mul.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/sat/sat_u_mul-run-1-u16-from-u64.c: Add rv64
	target for run.
	* gcc.target/riscv/sat/sat_u_mul-run-1-u32-from-u64.c: Ditto.
	* gcc.target/riscv/sat/sat_u_mul-run-1-u8-from-u64.c: Ditto.
	* gcc.target/riscv/sat/sat_u_mul-1-u16-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-1-u8-from-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-1-u8-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-2-u16-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-2-u32-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-2-u8-from-u64.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-1-u16-from-u32.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-1-u8-from-u16.c: New test.
	* gcc.target/riscv/sat/sat_u_mul-run-1-u8-from-u32.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-07-29 21:03:12 +08:00
Pan Li a481f299b3 Match: Introduce mul based pattern for unsigned SAT_MUL
Like widen_mul based pattern, we would like introduce the mul based
pattern as well.  The pattern is quite simple compares to the
widen_mul, thus add new instead of the for loop in match.pd.

gcc/ChangeLog:

	* match.pd: Add mul based unsigned SAT_MUL.

Signed-off-by: Pan Li <pan2.li@intel.com>
2025-07-29 21:03:12 +08:00
Richard Biener 9c48cbb259 Another testcase for PR120687
This shows reassoc is harmful even with len == 3.

	PR tree-optimization/120687
	* gcc.dg/vect/pr120687-3.c: New testcase.
2025-07-29 14:03:27 +02:00
Nathaniel Shead 3f2ff7b106 testsuite: Fix C++14 test failure with modules test [PR121285]
I hadn't validated this test worked in C++14 before submitting, fixed
thusly.

	PR testsuite/121285

gcc/testsuite/ChangeLog:

	* g++.dg/modules/class-11_a.H: Make static_asserts valid for
	C++14.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2025-07-29 21:36:19 +10:00
Richard Biener e8a51144c0 tree-optimization/120687 - avoid disturbing reduction chains in reassoc
Reassoc carefully ranks operands to form reduction chains for
vectorization so we are careful to not apply any width related
changes in the early pass.  Unfortunately we are not careful
enough.  The following gates fma related re-ordering and also
the >= 3 ops tail "optimization" which is the culprit here.

This does not fix the reported inefficient vectorization when
using signed integer reductions yet.

	PR tree-optimization/120687
	* tree-ssa-reassoc.cc (reassociate_bb): Do not disturb
	the sorted operand order in the early pass.
	* tree-vect-slp.cc (vect_analyze_slp): Dump when a detected
	reduction chain fails SLP discovery.

	* gcc.dg/vect/pr120687-1.c: New testcase.
	* gcc.dg/vect/pr120687-2.c: Likewise.
2025-07-29 12:13:00 +02:00
Alfie Richards c1102be3b2 Fix UB in string_slice::operator== (PR 121261)
This adds a nullptr check to fix a regression where it is possible to call
`memcmp (NULL, NULL, 0)` which is UB prior to C26.

This fixes the bootstrap-ubsan build.

gcc/ChangeLog:
	PR middle-end/121261
	* vec.h: Add null ptr check.
2025-07-29 08:25:45 +00:00
Gaius Mulley e79e0fe2b1 PR modula2/121289 Poor warning location when using Wstyle option
This patch adds a token location parameter to CheckVariableAgainstKeyword
and dependants ensuring that the warning is generated from the
token associated with the variable rather than the end of the statement.

gcc/m2/ChangeLog:

	PR modula2/121289
	* gm2-compiler/M2Students.def (CheckVariableAgainstKeyword): New
	parameter tok.
	* gm2-compiler/M2Students.mod (CheckVariableAgainstKeyword): New
	parameter tok.
	Pass tok to PerformVariableKeywordCheck.
	(PerformVariableKeywordCheck): New parameter tok.
	Pass tok to MetaErrorStringT0.
	* gm2-compiler/P2SymBuild.mod (BuildVariable): Pass tok to
	CheckVariableAgainstKeyword.
	* gm2-libs-iso/LowLong.mod (except): Replace with ...
	(exceptSrc): ... this.
	* gm2-libs-iso/LowReal.mod (except): Replace with ...
	(exceptSrc): ... this.
	* gm2-libs-iso/LowShort.mod (except): Replace with ...
	(exceptSrc): ... this.
	* gm2-libs-iso/Processes.mod (Wait): Replace from with fromCor.
	* gm2-libs-iso/RndFile.mod (EndPos): Replace end with endP.
	* gm2-libs/SCmdArgs.mod (GetArg): Replace start with startPos.
	Replace end with endPos.
	(NArg): Replace start with startPos.
	Replace end with endPos.

gcc/testsuite/ChangeLog:

	PR modula2/121289
	* gm2/warnings/style/fail/badvarname.mod: New test.
	* gm2/warnings/style/fail/warnings-style-fail.exp: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2025-07-29 09:09:58 +01:00
Christophe Lyon 5f022a75b6 testsuite: Restore dg-do run on pr116906 and pr78185 tests
Commit r15-7152-g57b706d141b87c removed
/* { dg-do run { target*-*-linux* *-*-gnu* *-*-uclinux* } } */

from these tests, turning them into 'compile' only tests, even when
they could be executed.

This patch adds
/* { dg-do run } */

which is OK since the tests are correctly skipped if needed thanks to
the following effective-targets (alarm and signal).

With this patch we have again two entries for these tests on linux targets:
* compile (test for excess errors)
* execution test

gcc/testsuite/ChangeLog:
	* gcc.dg/pr116906-1.c: Add 'dg-do run'.
	* gcc.dg/pr116906-2.c: Likewise.
	* gcc.dg/pr78185.c: Likewise.
2025-07-29 08:07:04 +00:00
Jakub Jelinek f4abe21619 calls: Allow musttail calls to noreturn [PR121159]
In the PR119483 r15-9003 change we've allowed musttail calls to noreturn
functions, after all the decision not to normally tail call noreturn
functions is not because it is not possible to tail call those, but because
it screws up backtraces.  As the following testcase shows, we've done that
only for functions not declared [[noreturn]]/_Noreturn but later on
discovered through IPA as noreturn.  Functions explicitly declared
[[noreturn]] have (for historical reasons) volatile FUNCTION_TYPE and
the FUNCTION_DECLs are volatile as well, so in order to support those
we shouldn't complain on ECF_NORETURN (we've stopped doing so for musttail
in PR119483) but also shouldn't complain about TYPE_VOLATILE on their
FUNCTION_TYPE (something that IPA doesn't change, I think it only sets
TREE_THIS_VOLATILE on the FUNCTION_DECL).  volatile on function type
really means noreturn as well, it has no other meaning.

2025-07-29  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/121159
	* calls.cc (can_implement_as_sibling_call_p): Don't reject declared
	noreturn functions in musttail calls.

	* c-c++-common/pr121159.c: New test.
	* gcc.dg/plugin/must-tail-call-2.c (test_5): Don't expect an error.
2025-07-29 09:49:55 +02:00
Andrew Pinski ea588988c1 output: Move an special # (256) to a new macro
This is a followup to the review of mergability of CSWTCH patch
located at https://gcc.gnu.org/pipermail/gcc-patches/2025-July/690810.html.
Moves the special # (256) to a macro so it is not used bare in the source
and there is only the need to change it in one place.
This special # was added with r0-37392-g201556f0e00580 which added the original mergeable
section support to gcc.

Pushed as obvious after build and test on x86_64.

gcc/ChangeLog:

	* output.h (MAX_ALIGN_MERGABLE): New define.
	* tree-switch-conversion.cc (switch_conversion::build_one_array):
	Use MAX_ALIGN_MERGABLE instead of 256.
	* varasm.cc (mergeable_string_section): Likewise
	(mergeable_constant_section): Likewise

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-07-28 23:43:33 -07:00
Andrew Pinski f1c8014764 Improve mergability of CSWTCH [PR120523]
When I did r16-1067-gaa935ce40a7, I thought it would be
enough to mark the decl as mergable to get it to merge on
all targets. Turns out a few things needed to be changed
to support it being mergable on all targets.
The first thing is improve the selecting of the mergable
section and instead of basing it on the DECL's mode, it
should be based on the size instead.
The second thing that needed to be happen is change the
alignment of the CSWTCH decl to be aligned to the next power
of 2 compared to the size if the size is less than 32bytes
(the max mergable size that is supported).

With these changes, cswtch-6.c passes on ia32 and other targets.
And the new testcase cswtch-7.c will pass now too.

Note I noticed the darwin's darwin_mergeable_constant_section could
be "fixed" up to use DECL_SIZE instead of the DECL_MODE but I am not
sure it makes a huge difference.

Bootstrapped and tested on x86_64-linux-gnu.

	PR middle-end/120523
gcc/ChangeLog:

	* output.h (mergeable_constant_section): New declaration taking
	unsigned HOST_WIDE_INT for the size.
	* tree-switch-conversion.cc (switch_conversion::build_one_array):
	Increase the alignment of CSWTCH for sizes less than 32bytes.
	* varasm.cc (mergeable_constant_section): Split out twice.
	One that takes the size in unsigned HOST_WIDE_INT and the
	other size in a tree.
	(default_elf_select_section): Pass DECL_SIZE instead of
	DECL_MODE to mergeable_constant_section.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-07-28 23:43:32 -07:00
Richard Biener a1ad36f5a8 Un-factor vectorizable_load parts
When the costing refactoring happened we ended up with some strange
inter-mixing of VMAT unrelated code.  The following moves stuff
closer to where it's actually used, at the expense of duplicating
some lines.

	* tree-vect-stmts.cc (vectorizable_load): Un-factor VMAT
	specific code to their handling blocks.
2025-07-29 08:40:07 +02:00
Richard Biener 6ac78317aa Eliminate gather-scatter-info offset_dt member
The following removes this only set member.  Sligthly complicated
by the hoops get_group_load_store_type jumps through.  I've simplified
that, noting the offset vector type that's relevant is that of the
actual offset SLP node, not of what vect_check_gather_scatter (re-)computes.

	* tree-vectorizer.h (gather_scatter_info::offset_dt): Remove.
	* tree-vect-data-refs.cc (vect_describe_gather_scatter_call):
	Do not set it.
	(vect_check_gather_scatter): Likewise.
	* tree-vect-stmts.cc (vect_truncate_gather_scatter_offset):
	Likewise.
	(get_group_load_store_type): Use the vector type of the offset
	SLP child.  Do not re-check vect_is_simple_use validated by
	SLP build.
2025-07-29 08:38:14 +02:00
GCC Administrator b87d6ae398 Daily bump. 2025-07-29 00:19:24 +00:00
Georg-Johann Lay 089faf54fa AVR: target/121277 - Don't load 0x800000 with const __flashx *x = NULL.
Converting from generic AS to __flashx used the same rule like
for __memx, which tags RAM (generic AS) locations by setting bit 23.
The justification was that generic isn't a subset of __flashx, though
that lead to surprises with code like const __flashx *x = NULL.

The natural thing to do is to just load 0x000000 in that case,
so that the null pointer works in __flashx as expected.

Apart from that, converting NULL to __flashx (or __flash) no more
raises a -Waddr-space-convert diagnostic.

gcc/
	PR target/121277
	* config/avr/avr.cc (avr_addr_space_convert): When converting
	from generic AS to __flashx, don't set bit 23.
	(avr_convert_to_type): Don't -Waddr-space-convert when NULL
	is converted to __flashx or to __flash.
2025-07-28 22:06:08 +02:00
3628 changed files with 292611 additions and 154636 deletions
+38
View File
@@ -0,0 +1,38 @@
# top-most EditorConfig file for gcc
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.{h,cc}]
charset = utf-8
indent_style = tab
indent_size = 2
tab_width = 8
trim_trailing_whitespace = true
[{Makefile,ChangeLog}*]
indent_style = tab
indent_size = 8
trim_trailing_whitespace = true
[ChangeLog*]
charset = utf-8
[*.texi]
charset = utf-8
indent_size = 2
tab_width = 8
trim_trailing_whitespace = true
[*.py]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.exp]
indent_style = tab
indent_size = 4
tab_width = 8
trim_trailing_whitespace = true
-3
View File
@@ -71,6 +71,3 @@ stamp-*
/gmp*
/isl*
/gettext*
# ADDITIONS from GCCRS front-end
libgrust/*/target/
+58
View File
@@ -1,3 +1,61 @@
2025-09-23 Richard Earnshaw <rearnsha@arm.com>
* .editorconfig: Fix glob patterns.
2025-09-22 Jonathan Wakely <jwakely@redhat.com>
* .editorconfig: New file.
2025-09-04 Wilco Dijkstra <wilco.dijkstra@arm.com>
* MAINTAINERS (Reviewers): Add myself for the aarch64 port.
2025-09-03 Alice Carlotti <alice.carlotti@arm.com>
* MAINTAINERS: Add myself as an aarch64 port reviewer.
2025-08-28 Yuao Ma <c8ef@outlook.com>
* MAINTAINERS: add myself to write after approval
2025-08-21 Richard Sandiford <rdsandiford@googlemail.com>
* MAINTAINERS: Update my email address and stand down as AArch64
maintainer.
2025-08-18 Spencer Abson <spencer.abson@student.manchester.ac.uk>
* MAINTAINERS: Update my email address.
2025-08-17 Filip Kastl <fkastl@suse.cz>
* MAINTAINERS: Switch around Andrew Pinski's entries in
Contributing under DCO.
2025-08-16 Mikael Pettersson <mikpelinux@gmail.com>
* MAINTAINERS: Add myself to write after approval.
2025-08-14 Avinash Jayakar <avinashd@linux.ibm.com>
* MAINTAINERS: Add myself to write after approval.
2025-08-08 Andrew Pinski <andrew.pinski@oss.qualcomm.com>
* MAINTAINERS (Andrew Pinski): Update email address.
2025-08-07 Pengfei Li <Pengfei.Li2@arm.com>
* MAINTAINERS: Add myself.
2025-08-05 Thomas Schwinge <tschwinge@baylibre.com>
* .gitignore: Remove 'libgrust/*/target/'.
2025-08-01 Luis Machado <luis.machado.foss@gmail.com>
* MAINTAINERS: Update my e-mail address.
2025-07-22 Patrick Palka <ppalka@redhat.com>
* MAINTAINERS: Add myself as C++ front end reviewer.
+15 -7
View File
@@ -40,7 +40,7 @@ Michael Meissner <gnu@the-meissners.org>
Jason Merrill <jason@redhat.com>
David S. Miller <davem@redhat.com>
Joseph Myers <josmyers@redhat.com>
Richard Sandiford <richard.sandiford@arm.com>
Richard Sandiford <rdsandiford@googlemail.com>
Bernd Schmidt <bernds_cb1@t-online.de>
Ian Lance Taylor <ian@airs.com>
Jim Wilson <wilson@tuliptree.org>
@@ -56,7 +56,6 @@ docs, and the testsuite related to that.
aarch64 ldp/stp Alex Coplan <alex.coplan@arm.com>
aarch64 port Richard Earnshaw <richard.earnshaw@arm.com>
aarch64 port Richard Sandiford <richard.sandiford@arm.com>
aarch64 port Tamar Christina <tamar.christina@arm.com>
aarch64 port Kyrylo Tkachov <ktkachov@nvidia.com>
alpha port Richard Henderson <rth@gcc.gnu.org>
@@ -275,8 +274,10 @@ check in changes outside of the parts of the compiler they maintain.
Reviewers
aarch64 port Alice Carlotti <alice.carlotti@arm.com>
aarch64 port Alex Coplan <alex.coplan@arm.com>
aarch64 port Andrew Pinski <pinskia@gmail.com>
aarch64 port Andrew Pinski <andrew.pinski@oss.qualcomm.com>
aarch64 port Wilco Dijkstra <wilco.dijkstra@arm.com>
arm port (MVE) Christophe Lyon <christophe.lyon@arm.com>
callgraph Martin Jambor <mjambor@suse.cz>
C front end Marek Polacek <polacek@redhat.com>
@@ -333,7 +334,7 @@ from other maintainers or reviewers.
Name BZ account Email
Soumya AR soumyaa <soumyaa@nvidia.com>
Spencer Abson sabson <spencer.abson@arm.com>
Spencer Abson sabson <spencer.abson@student.manchester.ac.uk>
Mark G. Adams mgadams <mark.g.adams@sympatico.ca>
Ajit Kumar Agarwal aagarwa <aagarwa1@linux.ibm.com>
Pedro Alves palves <palves@redhat.com>
@@ -447,7 +448,7 @@ Jerry DeLisle jvdelisle <jvdelisle@gcc.gnu.org>
DJ Delorie dj <dj@delorie.com>
Chris Demetriou cgd <cgd@google.com>
Sameera Deshpande sameerad <sameera.deshpande@linaro.org>
Wilco Dijkstra wilco <wdijkstr@arm.com>
Wilco Dijkstra wilco <wilco.dijkstra@arm.com>
Dimitar Dimitrov dimitar <dimitar@dinux.eu>
Benoit Dupont de Dinechin bd3 <benoit.dupont-de-dinechin@st.com>
Lehua Ding - <lehua.ding@rivai.ai>
@@ -566,6 +567,7 @@ Fariborz Jahanian - <fjahanian@apple.com>
Martin Jambor jamborm <mjambor@suse.cz>
Sam James sjames <sam@gentoo.org>
Surya Kumari Jangala jskumari <jskumari@linux.ibm.com>
Avinash Jayakar avinashd <avinashd@linux.ibm.com>
Jakub Jelinek jakub <jakub@redhat.com>
Andrew Jenner andrewjenner <andrew@codesourcery.com>
Saurabh Jha saurabhjha <saurabh.jha@arm.com>
@@ -628,6 +630,7 @@ James Lemke jwlemke <jim@lemke.org>
Ilya Leoshkevich iii <iii@linux.ibm.com>
Kriang Lerdsuwanakij lerdsuwa <lerdsuwa@users.sourceforge.net>
Pan Li - <pan2.li@intel.com>
Pengfei Li pfustc <pengfei.li2@arm.com>
Renlin Li renlin <renlin.li@arm.com>
Xinliang David Li davidxl <davidxl@google.com>
Kewen Lin linkw <linkw@gcc.gnu.org>
@@ -652,8 +655,9 @@ Bin Bin Lv shlb <shlb@linux.ibm.com>
Christophe Lyon clyon <christophe.lyon@arm.com>
Jin Ma majin <jinma@linux.alibaba.com>
Jun Ma junma <junma@linux.alibaba.com>
Yuao Ma - <yuao@gcc.gnu.org>
Andrew MacLeod - <amacleod@redhat.com>
Luis Machado luisgpm <luisgpm@br.ibm.com>
Luis Machado luisgpm <luis.machado.foss@gmail.com>
Ziga Mahkovec ziga <ziga.mahkovec@klika.si>
Vladimir Makarov vmakarov <vmakarov@redhat.com>
David Malcolm dmalcolm <dmalcolm@redhat.com>
@@ -730,10 +734,11 @@ Fernando Pereira pronesto <pronesto@gmail.com>
Nicola Pero nicola <nicola.pero@meta-innovation.com>
Sebastian Perta - <sebastian.perta@renesas.com>
Sebastian Peryt speryt <sebastian.peryt@intel.com>
Mikael Pettersson mikpe <mikpelinux@gmail.com>
Johannes Pfau jpfau <johannespfau@gmail.com>
Gerald Pfeifer gerald <gerald@pfeifer.com>
Kaushik Phatak kaushikp <kaushik.phatak@kpitcummins.com>
Andrew Pinski pinskia <pinskia@gmail.com>
Andrew Pinski pinskia <andrew.pinski@qualcomm.com>
Nicolas Pitre nico <nico@cam.org>
Michael Ploujnikov plouj <michael.ploujnikov@oracle.com>
Paul Pluzhnikov ppluzhnikov <ppluzhnikov@google.com>
@@ -953,10 +958,13 @@ Jeff Law <jeffreyalaw@gmail.com>
Jeff Law <jlaw@tachyum.com>
Jeff Law <jlaw@ventanamicro.com>
H.J. Lu <hjl.tools@gmail.com>
Yuao Ma <yuao@gcc.gnu.org>
Matthew Malcomson <mmalcomson@nvidia.com>
Immad Mir <mir@sourceware.org>
Gaius Mulley <gaiusmod2@gmail.com>
Szabolcs Nagy <nsz@gcc.gnu.org>
Mikael Pettersson <mikpelinux@gmail.com>
Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Andrew Pinski <quic_apinski@quicinc.com>
Siddhesh Poyarekar <siddhesh@gotplt.org>
Ramana Radhakrishnan <ramanara@nvidia.com>
+5
View File
@@ -1,3 +1,8 @@
2025-08-10 Ijaz, Abdul B <abdul.b.ijaz@intel.com>
* lib-link.m4: Handle dash in the library name for
AC_LIB_LINKFLAGS_BODY.
2025-05-23 Andi Kleen <ak@gcc.gnu.org>
* bootstrap-native.mk: New file.
+3 -2
View File
@@ -126,6 +126,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
[
define([NAME],[translit([$1],[abcdefghijklmnopqrstuvwxyz./-],
[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])])
define([Name],[translit([$1],[./-], [___])])
dnl By default, look in $includedir and $libdir.
use_additional=yes
AC_LIB_WITH_FINAL_PREFIX([
@@ -152,8 +153,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
])
AC_LIB_ARG_WITH([lib$1-type],
[ --with-lib$1-type=TYPE type of library to search for (auto/static/shared) ],
[ with_lib$1_type=$withval ], [ with_lib$1_type=auto ])
lib_type=`eval echo \$with_lib$1_type`
[ with_lib[]Name[]_type=$withval ], [ with_lib[]Name[]_type=auto ])
lib_type=`eval echo \$with_lib[]Name[]_type`
dnl Search the library and its dependencies in $additional_libdir and
dnl $LDFLAGS. Using breadth-first-seach.
+41
View File
@@ -1,3 +1,44 @@
2025-09-23 Jonathan Wakely <jwakely@redhat.com>
* unicode/gen_libstdcxx_unicode_data.py: Fix comment type.
2025-09-22 Jonathan Wakely <jwakely@redhat.com>
* unicode/gen_libstdcxx_unicode_data.py: Update comment at the
top of the file to mention DerivedGeneralCategory.txt
prerequisite.
2025-09-17 Andrew Pinski <andrew.pinski@oss.qualcomm.com>
* uninclude: Add `lib/gcc/<anything>/include`.
2025-09-10 Christophe Lyon <christophe.lyon@linaro.org>
* compare_tests: Improve non-unique tests report when testing
several configurations.
2025-09-08 Christophe Lyon <christophe.lyon@linaro.org>
* compare_tests: Report non-unique test names.
2025-08-17 Filip Kastl <fkastl@suse.cz>
* check-MAINTAINERS.py: Document the way the script sorts
entries.
2025-08-07 Tobias Burnus <tburnus@baylibre.com>
PR other/120237
* download_prerequisites: Update to download GMP 6.3.0 (before 6.2.1),
MPFR 4.2.2 (before 4.1.0), and MPC 1.3.1 (before 1.2.1).
* prerequisites.md5: Update hash.
* prerequisites.sha512: Likewise.
2025-07-28 David Malcolm <dmalcolm@redhat.com>
* gcc-changelog/git_commit.py: Add "diagnostics" to bug
components.
2025-07-25 David Malcolm <dmalcolm@redhat.com>
* filter-clang-warnings.py: Update for move of
+2 -2
View File
@@ -19,8 +19,8 @@
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
# Check that names in the file are sorted
# alphabetically by surname.
# Check that names in the file are sorted alphabetically by surname, name
# bugzilla handle and email (in this order).
import locale
import sys
+33 -1
View File
@@ -41,6 +41,8 @@ tmp1=$TMPDIR/$tool-testing.$$a
tmp2=$TMPDIR/$tool-testing.$$b
now_s=$TMPDIR/$tool-testing.$$d
before_s=$TMPDIR/$tool-testing.$$e
now_u=$TMPDIR/$tool-uniq.$$d
before_u=$TMPDIR/$tool-uniq.$$e
lst1=$TMPDIR/$tool-lst1.$$
lst2=$TMPDIR/$tool-lst2.$$
lst3=$TMPDIR/$tool-lst3.$$
@@ -48,7 +50,7 @@ lst4=$TMPDIR/$tool-lst4.$$
lst5=$TMPDIR/$tool-lst5.$$
sum1=$TMPDIR/$tool-sum1.$$
sum2=$TMPDIR/$tool-sum2.$$
tmps="$tmp1 $tmp2 $now_s $before_s $lst1 $lst2 $lst3 $lst4 $lst5 $sum1 $sum2"
tmps="$tmp1 $tmp2 $now_s $before_s $now_u $before_u $lst1 $lst2 $lst3 $lst4 $lst5 $sum1 $sum2"
[ "$1" = "-strict" ] && strict=$1 && shift
[ "$1" = "-?" ] && usage
@@ -124,6 +126,36 @@ fi
sort -t ':' $skip1 "$now" > "$now_s"
sort -t ':' $skip1 "$before" > "$before_s"
# Report non-unique test names and print the diff between the two
# lists if they are different.
#
# If the results include several configurations (schedule of
# variations), we report duplicates several times with different
# target/tool prefixes because at this stage we do not know if the
# target and/or tool prefix was inserted.
# If we used the input files (so generally several times the same
# results in one section per target), we would incorreclty detect
# duplicates (as many as targets)
grep -E '^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|UNSUPPORTED|UNTESTED|ERROR):' "$now_s" | uniq -cd > "$now_u"
grep -E '^(PASS|XPASS|FAIL|XFAIL|UNRESOLVED|UNSUPPORTED|UNTESTED|ERROR):' "$before_s" | uniq -cd > "$before_u"
same_uniq=" now"
cmp -s "$before_u" "$now_u" && same_uniq=""
if [ -s "$now_u" ]; then
echo "Non-unique test names$same_uniq: (Eeek!)"
cat "$now_u"
echo
exit_status=1
fi
if [ -s "$before_u" -a "x$same_uniq" != "x" ]; then
echo "Changes to non-unique test names:"
diff -u "$before_u" "$now_u" | grep -E '^[-\\+] '
echo
exit_status=1
fi
grep '^FAIL:' "$now_s" | sed 's/^[^:]*:[ ]//' >$tmp1
grep '^PASS' "$before_s" | sed 's/^[^:]*:[ ]//' | comm -12 $tmp1 - >$tmp2
+3 -3
View File
@@ -27,9 +27,9 @@ version='(unversioned)'
# remember to also update the files `contrib/prerequisites.sha512` and
# `contrib/prerequisites.md5` with the new checksums.
gmp='gmp-6.2.1.tar.bz2'
mpfr='mpfr-4.1.0.tar.bz2'
mpc='mpc-1.2.1.tar.gz'
gmp='gmp-6.3.0.tar.bz2'
mpfr='mpfr-4.2.2.tar.bz2'
mpc='mpc-1.3.1.tar.gz'
isl='isl-0.24.tar.bz2'
gettext='gettext-0.22.tar.gz'
+3 -3
View File
@@ -1,5 +1,5 @@
28971fc21cf028042d4897f02fd355ea gmp-6.2.1.tar.bz2
44b892bc5a45bafb4294d134e13aad1d mpfr-4.1.0.tar.bz2
9f16c976c25bb0f76b50be749cd7a3a8 mpc-1.2.1.tar.gz
c1cd6ef33085e9cb818b9b08371f9000 gmp-6.3.0.tar.bz2
afe8268360bc8702fbc8297d351c8b5e mpfr-4.2.2.tar.bz2
5c9bc658c9fd0f940e8e3e0f09530c62 mpc-1.3.1.tar.gz
dd2f7b78e118c25bd96134a52aae7f4d isl-0.24.tar.bz2
c092102240f8f66134d22718421d5115 gettext-0.22.tar.gz
+3 -3
View File
@@ -1,5 +1,5 @@
8904334a3bcc5c896ececabc75cda9dec642e401fb5397c4992c4fabea5e962c9ce8bd44e8e4233c34e55c8010cc28db0545f5f750cbdbb5f00af538dc763be9 gmp-6.2.1.tar.bz2
410208ee0d48474c1c10d3d4a59decd2dfa187064183b09358ec4c4666e34d74383128436b404123b831e585d81a9176b24c7ced9d913967c5fce35d4040a0b4 mpfr-4.1.0.tar.bz2
3279f813ab37f47fdcc800e4ac5f306417d07f539593ca715876e43e04896e1d5bceccfb288ef2908a3f24b760747d0dbd0392a24b9b341bc3e12082e5c836ee mpc-1.2.1.tar.gz
3b684c9bcb9ede2b7e54d0ba4c9764bfa17c20d4f3000017c553b6f1e135b536949580ff37341680c25dc236cfe0ba1db8cfdfe619ce013656189ef0871b89f8 gmp-6.3.0.tar.bz2
0176e50808dcc07afbf5bc3e38bf9b7b21918e5f194aa0bfd860d99b00c470630aef149776c4be814a61c44269c3a5b9a4b0b1c0fcd4c9feb1459d8466452da8 mpfr-4.2.2.tar.bz2
4bab4ef6076f8c5dfdc99d810b51108ced61ea2942ba0c1c932d624360a5473df20d32b300fc76f2ba4aa2a97e1f275c9fd494a1ba9f07c4cb2ad7ceaeb1ae97 mpc-1.3.1.tar.gz
aab3bddbda96b801d0f56d2869f943157aad52a6f6e6a61745edd740234c635c38231af20bc3f1a08d416a5e973a90e18249078ed8e4ae2f1d5de57658738e95 isl-0.24.tar.bz2
e2a58dde1cae3e6b79c03e7ef3d888f7577c1f4cba283b3b0f31123ceea8c33d7c9700e83de57104644de23e5f5c374868caa0e091f9c45edbbe87b98ee51c04 gettext-0.22.tar.gz
@@ -23,6 +23,7 @@
# ftp://ftp.unicode.org/Public/UNIDATA/DerivedCoreProperties.txt
# ftp://ftp.unicode.org/Public/UNIDATA/auxiliary/GraphemeBreakProperty.txt
# ftp://ftp.unicode.org/Public/UNIDATA/emoji/emoji-data.txt
# ftp://ftp.unicode.org/Public/UNIDATA/extracted/DerivedGeneralCategory.txt
# Then run this script and save the output to
# ../../libstdc++-v3/include/bits/unicode-data.h
@@ -148,7 +149,7 @@ escaped_general_categories = {
"Cc", "Cf", "Cs", "Co", "Cn",
}
# Extract General_Category and detrmine if it should be escaped
# Extract General_Category and determine if it should be escaped
# for all code points.
for line in open("DerivedGeneralCategory.txt", "r"):
# Example lines:
+3 -2
View File
@@ -27,13 +27,14 @@
# Header files whose pathnames contain any of the following patterns
# are considered as standard headers: usr/include, g++-include,
# include/g++, include/c++/<version>, gcc-lib/<anything>/include.
# include/g++, include/c++/<version>, gcc-lib/<anything>/include,
# lib/gcc/<anything>/include.
gawk ${EXCLUDEPATT+-vexclude="$EXCLUDEPATT"} \
${INCLUDEPATT+-vinclude="$INCLUDEPATT"} '
BEGIN {
skipping = 0;
cppline = "^# [0-9]+ \"[^\"]*/(usr/include|g\\+\\+-include|include/g\\+\\+|include/c\\+\\+/[^/]+|gcc-lib/[^\"]+/include|gcc/include)/([^\"]+)\"( [1-4])*$"
cppline = "^# [0-9]+ \"[^\"]*/(usr/include|g\\+\\+-include|include/g\\+\\+|include/c\\+\\+/[^/]+|gcc-lib/[^\"]+/include|lib/gcc/[^\"]+/include|gcc/include)/([^\"]+)\"( [1-4])*$"
}
!skipping && $0 ~ cppline &&
(exclude == "" || $3 !~ exclude) && (include == "" || $3 ~ include) {
+18
View File
@@ -1,3 +1,21 @@
2025-08-28 Jonathan Wakely <jwakely@redhat.com>
PR bootstrap/118009
PR bootstrap/119089
* inclhack.def (pthread_incomplete_struct_argument): Add bypass.
* fixincl.tpl: Remove reference to svn in comment.
* fixincl.x: Regenerate.
2025-08-15 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
* fixincl.x: Regenerate.
* inclhack.def (stdio_va_list): Skip on recent darwin.
2025-08-15 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
* fixincl.x: Regenerate.
* inclhack.def (stdio_stdarg_h): Skip on darwin.
2024-07-11 Iain Sandoe <iain@sandoe.co.uk>
Revert:
+1 -1
View File
@@ -5,7 +5,7 @@ x=fixincl.x =]
(dne "-D" " * " "/* ")
(dne " * " "/* ") ) =]
*/
/* DO NOT SVN-MERGE THIS FILE, EITHER [=
/* DO NOT MERGE THIS FILE, EITHER [=
(define re-ct 0) (define max-mach 0) (define ct 0)
(define HACK "") (define Hack "") (define tmp "")
(shell "date") =]
+13 -6
View File
@@ -2,11 +2,11 @@
*
* DO NOT EDIT THIS FILE (fixincl.x)
*
* It has been AutoGen-ed July 10, 2024 at 02:49:05 PM by AutoGen 5.18.16
* It has been AutoGen-ed August 28, 2025 at 04:10:25 PM by AutoGen 5.18.16
* From the definitions inclhack.def
* and the template file fixincl
*/
/* DO NOT SVN-MERGE THIS FILE, EITHER Wed Jul 10 14:49:05 CEST 2024
/* DO NOT MERGE THIS FILE, EITHER Thu Aug 28 16:10:25 BST 2025
*
* You must regenerate it. Use the ./genfixes script.
*
@@ -7547,8 +7547,15 @@ tSCC zPthread_Incomplete_Struct_ArgumentList[] =
tSCC zPthread_Incomplete_Struct_ArgumentSelect0[] =
"struct __jmp_buf_tag";
#define PTHREAD_INCOMPLETE_STRUCT_ARGUMENT_TEST_CT 1
/*
* content bypass pattern - skip fix if pattern found
*/
tSCC zPthread_Incomplete_Struct_ArgumentBypass0[] =
"bits/types/struct___jmp_buf_tag.h";
#define PTHREAD_INCOMPLETE_STRUCT_ARGUMENT_TEST_CT 2
static tTestDesc aPthread_Incomplete_Struct_ArgumentTests[] = {
{ TT_NEGREP, zPthread_Incomplete_Struct_ArgumentBypass0, (regex_t*)NULL },
{ TT_EGREP, zPthread_Incomplete_Struct_ArgumentSelect0, (regex_t*)NULL }, };
/*
@@ -8981,7 +8988,7 @@ tSCC* apzStdio_Stdarg_HMachs[] = {
* content bypass pattern - skip fix if pattern found
*/
tSCC zStdio_Stdarg_HBypass0[] =
"include.*(stdarg.h|machine/ansi.h)";
"include.*(stdarg.h|machine/ansi.h|_stdio.h)";
#define STDIO_STDARG_H_TEST_CT 1
static tTestDesc aStdio_Stdarg_HTests[] = {
@@ -9019,7 +9026,7 @@ tSCC* apzStdio_Va_ListMachs[] = {
* content bypass pattern - skip fix if pattern found
*/
tSCC zStdio_Va_ListBypass0[] =
"__gnuc_va_list|_BSD_VA_LIST_|__DJ_va_list|_G_va_list";
"__gnuc_va_list|_BSD_VA_LIST_|__DJ_va_list|_G_va_list|_stdio.h";
#define STDIO_VA_LIST_TEST_CT 1
static tTestDesc aStdio_Va_ListTests[] = {
@@ -11202,7 +11209,7 @@ static const char* apzX11_SprintfPatch[] = {
*
* List of all fixes
*/
#define REGEX_COUNT 318
#define REGEX_COUNT 319
#define MACH_LIST_SIZE_LIMIT 187
#define FIX_COUNT 274
+6 -5
View File
@@ -3803,6 +3803,7 @@ fix = {
hackname = pthread_incomplete_struct_argument;
files = pthread.h;
select = "struct __jmp_buf_tag";
bypass = "bits/types/struct___jmp_buf_tag.h";
c_fix = format;
c_fix_arg = "%1 *%2%3";
c_fix_arg = "^(extern int __sigsetjmp \\(struct __jmp_buf_tag) "
@@ -4472,13 +4473,13 @@ fix = {
/*
* Arrange for stdio.h to use stdarg.h to define __gnuc_va_list.
* On 4BSD-derived systems, stdio.h defers to machine/ansi.h; that's
* OK too.
* On 4BSD-derived systems, stdio.h defers to machine/ansi.h, that's
* OK too. Modern macOS includes _stdio.h, and does not need the fix.
*/
fix = {
hackname = stdio_stdarg_h;
files = stdio.h;
bypass = "include.*(stdarg\.h|machine/ansi\.h)";
bypass = "include.*(stdarg\.h|machine/ansi\.h|_stdio\.h)";
/*
* On Solaris 10, this fix is unncessary; <stdio.h> includes
* <iso/stdio_iso.h>, which includes <sys/va_list.h>.
@@ -4499,12 +4500,12 @@ fix = {
* of __gnuc_va_list, __DJ_va_list, or _G_va_list is taken to
* indicate that the header knows what it's doing -- under SUSv2,
* stdio.h is required to define va_list, and we shouldn't break
* that.
* that. Modern macOS includes _stdio.h, and does not need the fix.
*/
fix = {
hackname = stdio_va_list;
files = stdio.h;
bypass = '__gnuc_va_list|_BSD_VA_LIST_|__DJ_va_list|_G_va_list';
bypass = '__gnuc_va_list|_BSD_VA_LIST_|__DJ_va_list|_G_va_list|_stdio.h';
/*
* On Solaris 10, the definition in
* <stdio.h> is guarded appropriately by the _XPG4 feature macro;
+5766
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1 +1 @@
20250728
20250928
+8 -3
View File
@@ -187,8 +187,6 @@ C_STRICT_WARN = @c_strict_warn@
NOEXCEPTION_FLAGS = @noexception_flags@
ALIASING_FLAGS = @aliasing_flags@
# This is set by --disable-maintainer-mode (default) to "#"
# FIXME: 'MAINT' will always be set to an empty string, no matter if
# --disable-maintainer-mode is used or not. This is because the
@@ -1450,6 +1448,7 @@ OBJS = \
dce.o \
ddg.o \
debug.o \
dep-fusion.o \
df-core.o \
df-problems.o \
df-scan.o \
@@ -1622,6 +1621,7 @@ OBJS = \
mcf.o \
mode-switching.o \
modulo-sched.o \
diagnostic-context-rich-location.o \
multiple_target.o \
omp-offload.o \
omp-expand.o \
@@ -1858,12 +1858,14 @@ OBJS-libcommon = \
diagnostics/color.o \
diagnostics/context.o \
diagnostics/digraphs.o \
diagnostics/dumping.o \
diagnostics/file-cache.o \
diagnostics/output-spec.o \
diagnostics/html-sink.o \
diagnostics/sarif-sink.o \
diagnostics/text-sink.o \
diagnostics/lazy-paths.o \
diagnostics/logging.o \
diagnostics/macro-unwinding.o \
diagnostics/option-classifier.o \
diagnostics/paths.o \
@@ -3402,6 +3404,9 @@ gengtype-lex.cc : gengtype-lex.l
echo '#else' >> $@.tmp; \
echo '#include "bconfig.h"' >> $@.tmp; \
echo '#endif' >> $@.tmp; \
echo '#define FLEX_SCANNER' >> $@.tmp; \
echo '#include "system.h"' >> $@.tmp; \
echo '#undef FLEX_SCANNER' >> $@.tmp; \
cat $@ >> $@.tmp; \
mv $@.tmp $@; \
}
@@ -3720,7 +3725,7 @@ TEXI_GCC_FILES = gcc.texi gcc-common.texi gcc-vers.texi frontends.texi \
contribute.texi compat.texi funding.texi gnu.texi gpl_v3.texi \
fdl.texi contrib.texi cppenv.texi cppopts.texi avr-mmcu.texi \
implement-c.texi implement-cxx.texi gcov-tool.texi gcov-dump.texi \
lto-dump.texi riscv-ext.texi
lto-dump.texi riscv-ext.texi riscv-mcpu.texi riscv-mtune.texi
# we explicitly use $(srcdir)/doc/tm.texi here to avoid confusion with
# the generated tm.texi; the latter might have a more recent timestamp,
+5
View File
@@ -481,6 +481,11 @@ AC_DEFUN([gcc_GAS_FLAGS],
dnl Always pass -arch ppc to assembler.
gcc_cv_as_flags="-arch ppc"
;;
amdgcn*)
dnl Currently, only the llvm-mc assembler is supported.
dnl Add flags to ensure an amdgcn ELF file is written.
gcc_cv_as_flags="--filetype=obj -triple=amdgcn--amdhsa"
;;
*)
gcc_cv_as_flags=" "
;;
+1818
View File
File diff suppressed because it is too large Load Diff
+8 -10
View File
@@ -415,6 +415,7 @@ GNATRTL_NONTASKING_OBJS= \
g-busorg$(objext) \
g-byorma$(objext) \
g-bytswa$(objext) \
g-c_time$(objext) \
g-calend$(objext) \
g-casuti$(objext) \
g-catiio$(objext) \
@@ -535,6 +536,7 @@ GNATRTL_NONTASKING_OBJS= \
s-boarop$(objext) \
s-boustr$(objext) \
s-bytswa$(objext) \
s-c_time$(objext) \
s-carsi8$(objext) \
s-carun8$(objext) \
s-casi16$(objext) \
@@ -1418,7 +1420,6 @@ ifeq ($(strip $(filter-out arm% aarch64 linux-android%,$(target_cpu) $(target_os
s-inmaop.adb<libgnarl/s-inmaop__posix.adb \
s-intman.adb<libgnarl/s-intman__android.adb \
s-osinte.ads<libgnarl/s-osinte__android.ads \
s-osinte.adb<libgnarl/s-osinte__android.adb \
s-oslock.ads<libgnat/s-oslock__posix.ads \
s-osprim.adb<libgnat/s-osprim__posix.adb \
s-parame.adb<libgnat/s-parame__aarch64-linux.adb \
@@ -1531,7 +1532,7 @@ ifeq ($(strip $(filter-out sparc% sun solaris%,$(target_cpu) $(target_vendor) $(
s-osinte.adb<libgnarl/s-osinte__solaris.adb \
s-osinte.ads<libgnarl/s-osinte__solaris.ads \
s-oslock.ads<libgnat/s-oslock__solaris.ads \
s-osprim.adb<libgnat/s-osprim__solaris.adb \
s-osprim.adb<libgnat/s-osprim__unix.adb \
s-taprop.adb<libgnarl/s-taprop__solaris.adb \
s-tasinf.adb<libgnarl/s-tasinf__solaris.adb \
s-tasinf.ads<libgnarl/s-tasinf__solaris.ads \
@@ -1580,7 +1581,7 @@ ifeq ($(strip $(filter-out %86 %x86_64 solaris2%,$(target_cpu) $(target_os))),)
s-osinte.adb<libgnarl/s-osinte__solaris.adb \
s-osinte.ads<libgnarl/s-osinte__solaris.ads \
s-oslock.ads<libgnat/s-oslock__solaris.ads \
s-osprim.adb<libgnat/s-osprim__solaris.adb \
s-osprim.adb<libgnat/s-osprim__unix.adb \
s-taprop.adb<libgnarl/s-taprop__solaris.adb \
s-tasinf.adb<libgnarl/s-tasinf__solaris.adb \
s-tasinf.ads<libgnarl/s-tasinf__solaris.ads \
@@ -2146,7 +2147,6 @@ ifeq ($(strip $(filter-out lynxos178%,$(target_os))),)
ifeq ($(strip $(filter-out lynxos178e,$(target_os))),)
LIBGNAT_TARGET_PAIRS += \
s-parame.ads<libgnat/s-parame__posix2008.ads \
s-osinte.ads<libgnarl/s-osinte__lynxos178e.ads \
s-osprim.adb<libgnat/s-osprim__posix2008.adb \
s-tracon.adb<hie/s-tracon__ppc-eabi.adb
@@ -2173,7 +2173,6 @@ ifeq ($(strip $(filter-out rtems%,$(target_os))),)
s-oslock.ads<libgnat/s-oslock__posix.ads \
s-osprim.adb<libgnat/s-osprim__rtems.adb \
s-parame.adb<libgnat/s-parame__rtems.adb \
s-parame.ads<libgnat/s-parame__posix2008.ads \
s-taprop.adb<libgnarl/s-taprop__rtems.adb \
s-taspri.ads<libgnarl/s-taspri__posix.ads \
s-tpopsp.adb<libgnarl/s-tpopsp__tls.adb \
@@ -2261,6 +2260,7 @@ ifeq ($(strip $(filter-out cygwin% mingw32% pe,$(target_os))),)
endif
LIBGNAT_TARGET_PAIRS += \
a-dirval.adb<libgnat/a-dirval__mingw.adb \
s-crtl.adb<libgnat/s-crtl__mingw.adb \
s-gloloc.adb<libgnat/s-gloloc__mingw.adb \
s-inmaop.adb<libgnarl/s-inmaop__dummy.adb \
s-taspri.ads<libgnarl/s-taspri__mingw.ads \
@@ -2941,13 +2941,11 @@ ifeq ($(strip $(filter-out %x32 linux%,$(target_cpu) $(target_os))),)
a-synbar.ads<libgnarl/a-synbar__posix.ads \
s-inmaop.adb<libgnarl/s-inmaop__posix.adb \
s-intman.adb<libgnarl/s-intman__posix.adb \
s-linux.ads<libgnarl/s-linux__x32.ads \
s-mudido.adb<libgnarl/s-mudido__affinity.adb \
s-osinte.ads<libgnarl/s-osinte__linux.ads \
s-osinte.adb<libgnarl/s-osinte__x32.adb \
s-osinte.adb<libgnarl/s-osinte__posix.adb \
s-oslock.ads<libgnat/s-oslock__posix.ads \
s-osprim.adb<libgnat/s-osprim__x32.adb \
s-parame.ads<libgnat/s-parame__posix2008.ads \
s-osprim.adb<libgnat/s-osprim__posix.adb \
s-taprop.adb<libgnarl/s-taprop__linux.adb \
s-tasinf.ads<libgnarl/s-tasinf__linux.ads \
s-tasinf.adb<libgnarl/s-tasinf__linux.adb \
@@ -3194,7 +3192,7 @@ LIBGNAT_TARGET_PAIRS += \
# library. LIBGNAT_OBJS is the list of object files for libgnat.
# thread.c is special as put into GNATRTL_TASKING_OBJS
LIBGNAT_OBJS = adadecode.o adaint.o argv.o aux-io.o \
cal.o cio.o cstreams.o ctrl_c.o \
cio.o cstreams.o ctrl_c.o \
env.o errno.o exit.o expect.o final.o rtfinal.o rtinit.o \
init.o initialize.o locales.o mkdir.o \
raise.o seh_init.o socket.o sysdep.o \
+63
View File
@@ -107,6 +107,7 @@
#ifdef __QNX__
#include <sys/syspage.h>
#include <sys/time.h>
#include <signal.h>
#endif
#ifdef IN_RTS
@@ -3719,6 +3720,68 @@ void __gnat_killprocesstree (int pid, int sig_num)
*/
}
#if defined (__QNX__)
static __thread sigset_t set;
static __thread sigset_t oset;
static __thread int signals_disabled = 0;
int __gnat_disable_signals(void)
{
sigemptyset(&set);
sigaddset(&set, SIGHUP);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGQUIT);
sigaddset(&set, SIGILL);
sigaddset(&set, SIGTRAP);
sigaddset(&set, SIGIOT);
sigaddset(&set, SIGABRT);
sigaddset(&set, SIGEMT);
sigaddset(&set, SIGDEADLK);
sigaddset(&set, SIGFPE);
sigaddset(&set, SIGKILL);
sigaddset(&set, SIGBUS);
sigaddset(&set, SIGSEGV);
sigaddset(&set, SIGSYS);
sigaddset(&set, SIGPIPE);
sigaddset(&set, SIGALRM);
sigaddset(&set, SIGTERM);
sigaddset(&set, SIGUSR1);
sigaddset(&set, SIGUSR2);
sigaddset(&set, SIGCHLD);
sigaddset(&set, SIGCLD);
sigaddset(&set, SIGPWR);
sigaddset(&set, SIGWINCH);
sigaddset(&set, SIGURG);
sigaddset(&set, SIGPOLL);
sigaddset(&set, SIGIO);
sigaddset(&set, SIGSTOP);
sigaddset(&set, SIGTSTP);
sigaddset(&set, SIGCONT);
sigaddset(&set, SIGTTIN);
sigaddset(&set, SIGTTOU);
sigaddset(&set, SIGVTALRM);
sigaddset(&set, SIGPROF);
sigaddset(&set, SIGXCPU);
sigaddset(&set, SIGXFSZ);
sigaddset(&set, SIGDOOM);
int ret = sigprocmask(SIG_BLOCK, &set, &oset);
signals_disabled = !ret;
return ret;
}
int __gnat_enable_signals(void)
{
if (!signals_disabled) {
return 0;
}
signals_disabled = 0;
return sigprocmask(SIG_SETMASK, &oset, 0);
}
#endif
#ifdef __cplusplus
}
#endif
+14 -4
View File
@@ -158,6 +158,7 @@ package Aspects is
Aspect_Stream_Size,
Aspect_String_Literal,
Aspect_Subprogram_Variant, -- GNAT
Aspect_Super, -- GNAT
Aspect_Suppress,
Aspect_Synchronization,
Aspect_Test_Case, -- GNAT
@@ -240,6 +241,7 @@ package Aspects is
Aspect_Unmodified, -- GNAT
Aspect_Unreferenced, -- GNAT
Aspect_Unreferenced_Objects, -- GNAT
Aspect_Unsigned_Base_Range, -- GNAT
Aspect_Volatile,
Aspect_Volatile_Components,
Aspect_Volatile_Full_Access, -- GNAT
@@ -358,6 +360,7 @@ package Aspects is
Aspect_Unmodified => True,
Aspect_Unreferenced => True,
Aspect_Unreferenced_Objects => True,
Aspect_Unsigned_Base_Range => True,
Aspect_User_Aspect => True,
Aspect_Value_Size => True,
Aspect_Volatile_Full_Access => True,
@@ -366,9 +369,7 @@ package Aspects is
others => False);
-- The following array indicates aspects that specify operational
-- characteristics, and thus are view-specific. Representation
-- aspects break privacy, as they are needed during expansion and
-- code generation.
-- characteristics, and thus can be specified on partial views.
-- List is currently incomplete ???
Operational_Aspect : constant array (Aspect_Id) of Boolean :=
@@ -516,6 +517,7 @@ package Aspects is
Aspect_Stream_Size => Expression,
Aspect_String_Literal => Name,
Aspect_Subprogram_Variant => Expression,
Aspect_Super => Expression,
Aspect_Suppress => Name,
Aspect_Synchronization => Name,
Aspect_Test_Case => Expression,
@@ -624,11 +626,13 @@ package Aspects is
Aspect_Stream_Size => True,
Aspect_String_Literal => False,
Aspect_Subprogram_Variant => False,
Aspect_Super => False,
Aspect_Suppress => False,
Aspect_Synchronization => False,
Aspect_Test_Case => False,
Aspect_Type_Invariant => False,
Aspect_Unimplemented => False,
Aspect_Unsigned_Base_Range => True,
Aspect_Unsuppress => False,
Aspect_User_Aspect => False,
Aspect_Value_Size => True,
@@ -839,6 +843,7 @@ package Aspects is
Aspect_Stream_Size => Name_Stream_Size,
Aspect_String_Literal => Name_String_Literal,
Aspect_Subprogram_Variant => Name_Subprogram_Variant,
Aspect_Super => Name_Super,
Aspect_Suppress => Name_Suppress,
Aspect_Suppress_Debug_Info => Name_Suppress_Debug_Info,
Aspect_Suppress_Initialization => Name_Suppress_Initialization,
@@ -852,6 +857,7 @@ package Aspects is
Aspect_Unmodified => Name_Unmodified,
Aspect_Unreferenced => Name_Unreferenced,
Aspect_Unreferenced_Objects => Name_Unreferenced_Objects,
Aspect_Unsigned_Base_Range => Name_Unsigned_Base_Range,
Aspect_Unsuppress => Name_Unsuppress,
Aspect_User_Aspect => Name_User_Aspect,
Aspect_Value_Size => Name_Value_Size,
@@ -1120,6 +1126,7 @@ package Aspects is
Aspect_SPARK_Mode => Never_Delay,
Aspect_Static => Never_Delay,
Aspect_Subprogram_Variant => Never_Delay,
Aspect_Super => Never_Delay,
Aspect_Synchronization => Never_Delay,
Aspect_Test_Case => Never_Delay,
Aspect_Unimplemented => Never_Delay,
@@ -1145,6 +1152,7 @@ package Aspects is
Aspect_Size => Rep_Aspect,
Aspect_Small => Rep_Aspect,
Aspect_Storage_Size => Rep_Aspect,
Aspect_Unsigned_Base_Range => Rep_Aspect,
Aspect_Value_Size => Rep_Aspect,
Aspect_Volatile => Rep_Aspect,
Aspect_Volatile_Components => Rep_Aspect,
@@ -1188,10 +1196,12 @@ package Aspects is
-- Sem_Prag.
Aspect_On_Body_Or_Stub_OK : constant array (Aspect_Id) of Boolean :=
(Aspect_Refined_Depends => True,
(Aspect_Initialize => True,
Aspect_Refined_Depends => True,
Aspect_Refined_Global => True,
Aspect_Refined_Post => True,
Aspect_SPARK_Mode => True,
Aspect_Super => True,
Aspect_Warnings => True,
others => False);
+8 -2
View File
@@ -1802,14 +1802,20 @@ package body Atree is
-- The Ghost node is created within a Ghost region
if Ghost_Mode = Check then
if Ghost_Config.Ghost_Mode = Check then
if Nkind (N) in N_Entity then
Set_Is_Checked_Ghost_Entity (N);
Set_Ghost_Assertion_Level
(N, Ghost_Config.Ghost_Mode_Assertion_Level);
Set_Is_Implicit_Ghost (N);
end if;
elsif Ghost_Mode = Ignore then
elsif Ghost_Config.Ghost_Mode = Ignore then
if Nkind (N) in N_Entity then
Set_Is_Ignored_Ghost_Entity (N);
Set_Ghost_Assertion_Level
(N, Ghost_Config.Ghost_Mode_Assertion_Level);
Set_Is_Implicit_Ghost (N);
end if;
Set_Is_Ignored_Ghost_Node (N);
+14
View File
@@ -651,6 +651,20 @@ package Atree is
-- similarly for the other two cases. This can return something other
-- than N only if N is an Entity.
function Node_To_Fetch_From_If_Set
(N : Node_Or_Entity_Id; Field : Node_Or_Entity_Field)
return Node_Or_Entity_Id is
(case Field_Descriptors (Field).Type_Only is
when No_Type_Only => N,
when Base_Type_Only => Base_Type_If_Set (N),
when Impl_Base_Type_Only => Implementation_Base_Type_If_Set (N),
when Root_Type_Only => Root_Type_If_Set (N));
-- This is a more permissive version of Node_To_Fetch_From, which
-- returns the same value, except it returns Empty in cases where
-- Node_To_Fetch_From would crash because relevant fields are not yet
-- set. This is used in Treepr, to allow it to print half-baked nodes
-- without crashing.
-----------------------------
-- Private Part Subpackage --
-----------------------------
+10 -3
View File
@@ -476,7 +476,10 @@ package body Bindgen is
-- but False for mains in other languages.) We do not want to do this if
-- we're binding a library.
if not Bind_For_Library and not CodePeer_Mode then
if not Bind_For_Library
and not CodePeer_Mode
and not Suppress_Standard_Library_On_Target
then
WBI (" procedure s_stalib_adafinal;");
Set_String (" pragma Import (Ada, s_stalib_adafinal, ");
Set_String ("""system__standard_library__adafinal"");");
@@ -490,7 +493,9 @@ package body Bindgen is
WBI ("");
WBI (" begin");
if not CodePeer_Mode then
if not CodePeer_Mode
and not Suppress_Standard_Library_On_Target
then
WBI (" if not Is_Elaborated then");
WBI (" return;");
WBI (" end if;");
@@ -503,7 +508,9 @@ package body Bindgen is
-- on whether this is the main program or a library.
if not CodePeer_Mode then
if not Bind_For_Library then
if not Bind_For_Library
and not Suppress_Standard_Library_On_Target
then
WBI (" s_stalib_adafinal;");
elsif Lib_Final_Built then
WBI (" finalize_library;");
-74
View File
@@ -1,74 +0,0 @@
/****************************************************************************
* *
* GNAT COMPILER COMPONENTS *
* *
* C A L *
* *
* C Implementation File *
* *
* Copyright (C) 1992-2025, Free Software Foundation, Inc. *
* *
* GNAT is free software; you can redistribute it and/or modify it under *
* terms of the GNU General Public License as published by the Free Soft- *
* ware Foundation; either version 3, or (at your option) any later ver- *
* sion. GNAT is distributed in the hope that it will be useful, but WITH- *
* OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* As a special exception under Section 7 of GPL version 3, you are granted *
* additional permissions described in the GCC Runtime Library Exception, *
* version 3.1, as published by the Free Software Foundation. *
* *
* You should have received a copy of the GNU General Public License and *
* a copy of the GCC Runtime Library Exception along with this program; *
* see the files COPYING3 and COPYING.RUNTIME respectively. If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* GNAT was originally developed by the GNAT team at New York University. *
* Extensive contributions were provided by Ada Core Technologies Inc. *
* *
****************************************************************************/
/* This file contains routines marked with pragmas Import in package */
/* GNAT.Calendar. It is used to do Duration to timeval conversion. */
/* These are simple wrapper functions to abstract the fact that the C */
/* struct timeval fields are not normalized (they are generally */
/* defined as int or long values). */
#if defined (__vxworks)
#ifdef __RTP__
#include <time.h>
#include <version.h>
#if (_WRS_VXWORKS_MAJOR == 7) || (_WRS_VXWORKS_MINOR != 0)
#include <sys/time.h>
#endif
#else
#include <sys/times.h>
#endif
#elif defined (__nucleus__)
#include <time.h>
#else
#include <sys/time.h>
#endif
#ifdef __MINGW32__
#include "mingw32.h"
#include <winsock.h>
#endif
void
__gnat_timeval_to_duration (struct timeval *t, long long *sec, long *usec)
{
*sec = (long long) t->tv_sec;
*usec = (long) t->tv_usec;
}
void
__gnat_duration_to_timeval (long long sec, long usec, struct timeval *t)
{
/* here we are doing implicit conversion to the struct timeval
fields types. */
t->tv_sec = sec;
t->tv_usec = usec;
}
+65 -14
View File
@@ -970,15 +970,61 @@ package body Checks is
-- we use a different approach, expanding to:
-- typ (xxx_With_Ovflo_Check (Integer_NN (x), Integer_NN (y)))
-- or
-- typ (xxx_With_Ovflo_Check (Unsigned_NN (x), Unsigned_NN (y)))
-- where xxx is Add, Multiply or Subtract as appropriate
-- Find check type if one exists
if Dsiz <= System_Max_Integer_Size then
Ctyp := Integer_Type_For (Dsiz, Uns => False);
Ctyp := Integer_Type_For (Dsiz,
Uns => Has_Unsigned_Base_Range_Aspect (Base_Type (Typ)));
-- No check type exists, use runtime call
-- No check type exists, and the type has the unsigned base range
-- aspect; use runtime call.
elsif Has_Unsigned_Base_Range_Aspect (Base_Type (Typ)) then
if System_Max_Integer_Size = 64 then
Ctyp := RTE (RE_Unsigned_64);
else
Ctyp := RTE (RE_Unsigned_128);
end if;
if Nkind (N) = N_Op_Add then
if System_Max_Integer_Size = 64 then
Cent := RE_Uns_Add_With_Ovflo_Check64;
else
Cent := RE_Uns_Add_With_Ovflo_Check128;
end if;
elsif Nkind (N) = N_Op_Subtract then
if System_Max_Integer_Size = 64 then
Cent := RE_Uns_Subtract_With_Ovflo_Check64;
else
Cent := RE_Uns_Subtract_With_Ovflo_Check128;
end if;
else pragma Assert (Nkind (N) = N_Op_Multiply);
if System_Max_Integer_Size = 64 then
Cent := RE_Uns_Multiply_With_Ovflo_Check64;
else
Cent := RE_Uns_Multiply_With_Ovflo_Check128;
end if;
end if;
Rewrite (N,
OK_Convert_To (Typ,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (Cent), Loc),
Parameter_Associations => New_List (
OK_Convert_To (Ctyp, Left_Opnd (N)),
OK_Convert_To (Ctyp, Right_Opnd (N))))));
Analyze_And_Resolve (N, Typ);
return;
-- No check type exists, use runtime call (common case)
else
if System_Max_Integer_Size = 64 then
@@ -1539,21 +1585,18 @@ package body Checks is
return;
end if;
-- Suppress checks if the subtypes are the same. The check must be
-- preserved in an assignment to a formal, because the constraint is
-- given by the actual.
-- Suppress checks if the subtypes are the same and constrained. The
-- check must be preserved in an assignment to a formal, because the
-- constraint is given by the actual.
if Nkind (Original_Node (N)) /= N_Allocator
and then (if Do_Access then Designated_Type (Typ) else Typ) = S_Typ
and then Is_Constrained (S_Typ)
and then (No (Lhs)
or else not Is_Entity_Name (Lhs)
or else No (Param_Entity (Lhs)))
then
if (Etype (N) = Typ
or else (Do_Access and then Designated_Type (Typ) = S_Typ))
and then (No (Lhs) or else not Is_Aliased_View (Lhs))
then
return;
end if;
return;
-- We can also eliminate checks on allocators with a subtype mark that
-- coincides with the context type. The context type may be a subtype
@@ -5492,7 +5535,9 @@ package body Checks is
-- bound, because that means the result could wrap.
-- Same applies for the lower bound if it is negative.
if Is_Modular_Integer_Type (Typ) then
if Is_Modular_Integer_Type (Typ)
and then not Has_Unsigned_Base_Range_Aspect (Btyp)
then
if Lor > Lo and then Hir <= Hbound then
Lo := Lor;
end if;
@@ -6223,7 +6268,9 @@ package body Checks is
-- Nothing to do for unsigned integer types, which do not overflow
elsif Is_Modular_Integer_Type (Typ) then
elsif Is_Modular_Integer_Type (Typ)
and then not Has_Unsigned_Base_Range_Aspect (Typ)
then
return;
end if;
@@ -8114,7 +8161,9 @@ package body Checks is
elsif Nkind (Expr) = N_Selected_Component
and then Present (Component_Clause (Entity (Selector_Name (Expr))))
and then Is_Modular_Integer_Type (Typ)
and then
(Is_Modular_Integer_Type (Typ)
and then not Has_Unsigned_Base_Range_Aspect (Base_Type (Typ)))
and then Modulus (Typ) = 2 ** Esize (Entity (Selector_Name (Expr)))
then
return;
@@ -8896,6 +8945,8 @@ package body Checks is
function Make_Bignum_Block (Loc : Source_Ptr) return Node_Id is
M : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uM);
begin
Check_Restriction (No_Secondary_Stack, M);
return
Make_Block_Statement (Loc,
Declarations =>
+17 -8
View File
@@ -1131,12 +1131,12 @@ package body Contracts is
if Comes_From_Source (Obj_Id) and then Is_Ghost_Entity (Obj_Id) then
-- A Ghost object cannot be of a type that yields a synchronized
-- object (SPARK RM 6.9(21)).
-- object (SPARK RM 6.9(22)).
if Yields_Synchronized_Object (Obj_Typ) then
Error_Msg_N ("ghost object & cannot be synchronized", Obj_Id);
-- A Ghost object cannot be imported or exported (SPARK RM 6.9(7)).
-- A Ghost object cannot be imported or exported (SPARK RM 6.9(9)).
-- One exception to this is the object that represents the dispatch
-- table of a Ghost tagged type, as the symbol needs to be exported.
@@ -1278,7 +1278,12 @@ package body Contracts is
while Present (Prag) loop
Prag_Nam := Pragma_Name (Prag);
if Prag_Nam = Name_Initial_Condition then
-- When Assertion_Levels are used then the pacakage can have
-- multiple consecutive Initial_Condition pragmas.
-- Find the first one here and then iterate over all of them
-- later.
if Prag_Nam = Name_Initial_Condition and then No (Init_Cond) then
Init_Cond := Prag;
elsif Prag_Nam = Name_Initializes then
@@ -1295,9 +1300,12 @@ package body Contracts is
Analyze_Initializes_In_Decl_Part (Init);
end if;
if Present (Init_Cond) then
while Present (Init_Cond)
and then Pragma_Name (Init_Cond) = Name_Initial_Condition
loop
Analyze_Initial_Condition_In_Decl_Part (Init_Cond);
end if;
Init_Cond := Next_Pragma (Init_Cond);
end loop;
end if;
-- Restore the SPARK_Mode of the enclosing context after all delayed
@@ -2714,10 +2722,11 @@ package body Contracts is
procedure Append_Enabled_Item (Item : Node_Id; List : in out List_Id) is
begin
-- Do not chain ignored or disabled pragmas
-- Do not chain ignored or disabled pragmas. Note that disabled
-- pragmas are also considered ignored.
if Nkind (Item) = N_Pragma
and then (Is_Ignored (Item) or else Is_Disabled (Item))
and then Is_Ignored_In_Codegen (Item)
then
null;
@@ -3273,7 +3282,7 @@ package body Contracts is
-- The contract of an ignored Ghost subprogram does not need expansion,
-- because the subprogram and all calls to it will be removed.
elsif Is_Ignored_Ghost_Entity (Subp_Id) then
elsif Is_Ignored_Ghost_Entity_In_Codegen (Subp_Id) then
return;
-- No action needed for helpers and indirect-call wrapper built to
+27
View File
@@ -41,6 +41,7 @@ with Targparm; use Targparm;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Sem_Mech; use Sem_Mech;
with Sem_Prag; use Sem_Prag;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Sinfo.Nodes; use Sinfo.Nodes;
@@ -456,6 +457,11 @@ package body CStand is
procedure Make_Dummy_Index (E : Entity_Id);
-- Called to provide a dummy index field value for Any_Array/Any_String
function Make_Assertion_Level_Definition
(Nam : Name_Id) return Entity_Id;
-- Create an Assertion_Level definition with the given name in the'
-- Sandard package.
procedure Pack_String_Type (String_Type : Entity_Id);
-- Generate proper tree for pragma Pack that applies to given type, and
-- mark type as having the pragma.
@@ -558,6 +564,18 @@ package body CStand is
Set_First_Index (E, Index);
end Make_Dummy_Index;
-------------------------------------
-- Make_Assertion_Level_Definition --
-------------------------------------
function Make_Assertion_Level_Definition (Nam : Name_Id) return Entity_Id
is
Level : constant Entity_Id := Make_Assertion_Level (Stloc, Nam);
begin
Insert_Assertion_Level (Level);
return Level;
end Make_Assertion_Level_Definition;
----------------------
-- Pack_String_Type --
----------------------
@@ -1494,6 +1512,11 @@ package body CStand is
Set_Size_Known_At_Compile_Time (Standard_Duration);
end Build_Duration;
Standard_Level_Static := Make_Assertion_Level_Definition (Name_Static);
Standard_Level_Runtime := Make_Assertion_Level_Definition (Name_Runtime);
Standard_Level_Default :=
Make_Assertion_Level_Definition (Name_uDefault_Assertion_Level);
-- Build standard exception type. Note that the type name here is
-- actually used in the generated code, so it must be set correctly.
-- The type Standard_Exception_Type must be consistent with the type
@@ -1935,6 +1958,10 @@ package body CStand is
P ("-- characteristics of the Standard types for this compiler");
Write_Eol;
P ("pragma Assertion_Level (Runtime);");
P ("pragma Assertion_Level (Static);");
Write_Eol;
P ("package Standard is");
P ("pragma Pure (Standard);");
Write_Eol;
+4 -1
View File
@@ -152,7 +152,7 @@ package body Debug is
-- d_l Disable strict alignment of array types with aliased component
-- d_m Run adareducer on crash
-- d_n
-- d_o
-- d_o Disable Backend_Overflow_Checks_On_Target; used for testing.
-- d_p Ignore assertion pragmas for elaboration
-- d_q Do not enforce freezing for equality operator of boolean subtype
-- d_r Disable the use of the return slot in functions
@@ -995,6 +995,9 @@ package body Debug is
-- d_l The compiler does not enforce the strict alignment of array types
-- that are declared with an aliased component.
-- d_o The compiler disables Backend_Overflow_Checks_On_Target; used to
-- test the frontend support on targets without overflow checks.
-- d_p The compiler ignores calls to subprograms which verify the run-time
-- semantics of invariants and postconditions in both the static and
-- dynamic elaboration models.
+308 -131
View File
@@ -581,6 +581,160 @@ Restricting the position of controlling parameter offers several advantages:
* The result of a function is never a controlling result.
``Unsigned_Base_Range`` aspect
------------------------------
A new pragma/aspect, ``Unsigned_Base_Range``, is introduced to explicitly
enforce the use of an unsigned base type for signed integer types.
RM-3.5.4(9) mandates a symmetric base range for signed integer types. This
requirement often requires the use of larger data types for arithmetic
operations, potentially introducing undesirable run-time overhead and
performance penalties, particularly in embedded systems. For instance,
on a 64-bit architecture, a 64-bit multiplication can be performed with
a single hardware instruction, whereas a 128-bit multiplication requires
multiple instructions and intermediate steps.
Here is an example of this feature:
.. code-block:: ada
type Uns_64 is range 0 .. 2 ** 64 - 1
with Size => 64,
Unsigned_Base_Range => True;
It ensures that arithmetic operations of type ``Uns_64`` are carried
out using 64 bits.
Generalized Finalization
------------------------
The ``Finalizable`` aspect can be applied to any record type, tagged or not,
to specify that it provides the same level of control on the operations of
initialization, finalization, and assignment of objects as the controlled
types (see RM 7.6(2) for a high-level overview). The only restriction is
that the record type must be a root type, in other words not a derived type.
The aspect additionally makes it possible to specify relaxed semantics for
the finalization operations by means of the ``Relaxed_Finalization`` setting.
Here is the archetypal example:
.. code-block:: ada
type T is record
...
end record
with Finalizable => (Initialize => Initialize,
Adjust => Adjust,
Finalize => Finalize,
Relaxed_Finalization => True);
procedure Adjust (Obj : in out T);
procedure Finalize (Obj : in out T);
procedure Initialize (Obj : in out T);
The three procedures have the same profile, with a single ``in out`` parameter,
and also have the same dynamic semantics as for controlled types:
- ``Initialize`` is called when an object of type ``T`` is declared without
initialization expression.
- ``Adjust`` is called after an object of type ``T`` is assigned a new value.
- ``Finalize`` is called when an object of type ``T`` goes out of scope (for
stack-allocated objects) or is deallocated (for heap-allocated objects).
It is also called when the value is replaced by an assignment.
However, when ``Relaxed_Finalization`` is either ``True`` or not explicitly
specified, the following differences are implemented relative to the semantics
of controlled types:
* The compiler has permission to perform no automatic finalization of
heap-allocated objects: ``Finalize`` is only called when such an object
is explicitly deallocated, or when the designated object is assigned a new
value. As a consequence, no runtime support is needed for performing
implicit deallocation. In particular, no per-object header data is needed
for heap-allocated objects.
Heap-allocated objects allocated through a nested access type will therefore
**not** be deallocated either. The result is simply that memory will be leaked
in this case.
* The ``Adjust`` and ``Finalize`` procedures are automatically considered as
having the :ref:`No_Raise_Aspect` specified for them. In particular, the
compiler has permission to enforce none of the guarantees specified by the
RM 7.6.1 (14/1) and subsequent subclauses.
Simple example of ref-counted type:
.. code-block:: ada
type T is record
Value : Integer;
Ref_Count : Natural := 0;
end record;
procedure Inc_Ref (X : in out T);
procedure Dec_Ref (X : in out T);
type T_Access is access all T;
type T_Ref is record
Value : T_Access;
end record
with Finalizable => (Adjust => Adjust,
Finalize => Finalize);
procedure Adjust (Ref : in out T_Ref) is
begin
Inc_Ref (Ref.Value);
end Adjust;
procedure Finalize (Ref : in out T_Ref) is
begin
Def_Ref (Ref.Value);
end Finalize;
Simple file handle that ensures resources are properly released:
.. code-block:: ada
package P is
type File (<>) is limited private;
function Open (Path : String) return File;
procedure Close (F : in out File);
private
type File is limited record
Handle : ...;
end record
with Finalizable (Finalize => Close);
end P;
Finalizable tagged types
^^^^^^^^^^^^^^^^^^^^^^^^
The aspect is inherited by derived types and the primitives may be overridden
by the derivation. The compiler-generated calls to these operations are then
dispatching whenever it makes sense, i.e. when the object in question is of a
class-wide type and the class includes at least one finalizable tagged type.
Composite types
^^^^^^^^^^^^^^^
When a finalizable type is used as a component of a composite type, the latter
becomes finalizable as well. The three primitives are derived automatically
in order to call the primitives of their components. The dynamic semantics is
the same as for controlled components of composite types.
Interoperability with controlled types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Finalizable types are fully interoperable with controlled types, in particular
it is possible for a finalizable type to have a controlled component and vice
versa, but the stricter dynamic semantics, in other words that of controlled
types, is applied in this case.
.. _Experimental_Language_Extensions:
@@ -1495,137 +1649,6 @@ of the call is erroneous if the tag of the actual is changed while the formal
parameter exists (that is, before leaving the corresponding callable construct).
This is analogous to the RM 6.4.1(18) rule about discriminated parameters.
Generalized Finalization
------------------------
The ``Finalizable`` aspect can be applied to any record type, tagged or not,
to specify that it provides the same level of control on the operations of
initialization, finalization, and assignment of objects as the controlled
types (see RM 7.6(2) for a high-level overview). The only restriction is
that the record type must be a root type, in other words not a derived type.
The aspect additionally makes it possible to specify relaxed semantics for
the finalization operations by means of the ``Relaxed_Finalization`` setting.
Here is the archetypal example:
.. code-block:: ada
type T is record
...
end record
with Finalizable => (Initialize => Initialize,
Adjust => Adjust,
Finalize => Finalize,
Relaxed_Finalization => True);
procedure Adjust (Obj : in out T);
procedure Finalize (Obj : in out T);
procedure Initialize (Obj : in out T);
The three procedures have the same profile, with a single ``in out`` parameter,
and also have the same dynamic semantics as for controlled types:
- ``Initialize`` is called when an object of type ``T`` is declared without
initialization expression.
- ``Adjust`` is called after an object of type ``T`` is assigned a new value.
- ``Finalize`` is called when an object of type ``T`` goes out of scope (for
stack-allocated objects) or is deallocated (for heap-allocated objects).
It is also called when the value is replaced by an assignment.
However, when ``Relaxed_Finalization`` is either ``True`` or not explicitly
specified, the following differences are implemented relative to the semantics
of controlled types:
* The compiler has permission to perform no automatic finalization of
heap-allocated objects: ``Finalize`` is only called when such an object
is explicitly deallocated, or when the designated object is assigned a new
value. As a consequence, no runtime support is needed for performing
implicit deallocation. In particular, no per-object header data is needed
for heap-allocated objects.
Heap-allocated objects allocated through a nested access type will therefore
**not** be deallocated either. The result is simply that memory will be leaked
in this case.
* The ``Adjust`` and ``Finalize`` procedures are automatically considered as
having the :ref:`No_Raise_Aspect` specified for them. In particular, the
compiler has permission to enforce none of the guarantees specified by the
RM 7.6.1 (14/1) and subsequent subclauses.
Simple example of ref-counted type:
.. code-block:: ada
type T is record
Value : Integer;
Ref_Count : Natural := 0;
end record;
procedure Inc_Ref (X : in out T);
procedure Dec_Ref (X : in out T);
type T_Access is access all T;
type T_Ref is record
Value : T_Access;
end record
with Finalizable => (Adjust => Adjust,
Finalize => Finalize);
procedure Adjust (Ref : in out T_Ref) is
begin
Inc_Ref (Ref.Value);
end Adjust;
procedure Finalize (Ref : in out T_Ref) is
begin
Def_Ref (Ref.Value);
end Finalize;
Simple file handle that ensures resources are properly released:
.. code-block:: ada
package P is
type File (<>) is limited private;
function Open (Path : String) return File;
procedure Close (F : in out File);
private
type File is limited record
Handle : ...;
end record
with Finalizable (Finalize => Close);
end P;
Finalizable tagged types
^^^^^^^^^^^^^^^^^^^^^^^^
The aspect is inherited by derived types and the primitives may be overridden
by the derivation. The compiler-generated calls to these operations are then
dispatching whenever it makes sense, i.e. when the object in question is of a
class-wide type and the class includes at least one finalizable tagged type.
Composite types
^^^^^^^^^^^^^^^
When a finalizable type is used as a component of a composite type, the latter
becomes finalizable as well. The three primitives are derived automatically
in order to call the primitives of their components. The dynamic semantics is
the same as for controlled components of composite types.
Interoperability with controlled types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Finalizable types are fully interoperable with controlled types, in particular
it is possible for a finalizable type to have a controlled component and vice
versa, but the stricter dynamic semantics, in other words that of controlled
types, is applied in this case.
.. _No_Raise_Aspect:
No_Raise aspect
@@ -1861,3 +1884,157 @@ be private to the enclosing package. This is necessary due to the previously
mentioned legality rule, to prevent breaking the privacy of the type when
imposing that rule on outside types that derive from the private view of the
type.
Structural Generic Instantiation
--------------------------------
The compiler implements a second kind of generic instantiation, called
"structural", alongside the traditional instantiation specified by the
language, which is defined as follows: the structural instantiation of
a generic unit on given actual parameters is the anonymous instantiation
of the generic unit on the actual parameters done in the outermost scope
where it would be legal to do an identical traditional instantiation.
There is at most one structural instantiation of a generic unit on given
actual parameters done in a partition.
Structural generic instances (the product of structural instantiation)
are implicitly created whenever a reference to them is made in a place
where a name is accepted by the language.
Syntax
^^^^^^
.. code-block:: text
name ::= { set of productions specified in the RM }
| structural_generic_instance_name
structural_generic_instance_name ::= name generic_actual_part
Legality Rules
^^^^^^^^^^^^^^
The ``name`` in a ``structural_generic_instance_name`` shall denote a generic
unit that is preelaborated. Note that, unlike in a traditional instantiation,
there are no square brackets around the ``generic_actual_part`` in the second
production, which means that it is mandatory and, therefore, that the generic
unit shall have at least one generic formal parameter.
The generic unit shall not take a generic formal object of mode ``in out``.
If the generic unit takes a generic formal object of mode ``in``, then the
corresponding generic actual parameter shall be a static expression.
A ``structural_generic_instance_name`` shall not be present in a library
unit if the structural instance is also a library unit and has a semantic
dependence on the former.
Static Semantics
^^^^^^^^^^^^^^^^
A ``structural_generic_instance_name`` denotes the instance that is the
product of the structural instantiation of a generic unit on the specified
actual parameters. This instance is unique to a partition.
Example:
.. code-block:: ada
with Ada.Containers.Vectors;
procedure P is
V : Ada.Containers.Vectors(Positive,Integer).Vector;
begin
V.Append (1);
V.Append (0);
Ada.Containers.Vectors(Positive,Integer).Generic_Sorting("<").Sort (V);
end;
This procedure references two structural instantiations of two different generic
units: ``Ada.Containers.Vectors(Positive,Integer)`` is the structural instance
of the generic unit ``Ada.Containers.Vectors`` on ``Positive`` and ``Integer``
and ``Ada.Containers.Vectors(Positive,Integer).Generic_Sorting("<")`` is the
structural instance of the nested generic unit
``Ada.Containers.Vectors(Positive,Integer).Generic_Sorting`` on ``"<"``.
Note that the following example is illegal:
.. code-block:: ada
with Ada.Containers.Vectors;
package Q is
type T is record
I : Integer;
end record;
V : Ada.Containers.Vectors(Positive,T).Vector;
end Q;
The reason is that ``Ada.Containers.Vectors``, ``Positive`` and ``Q.T`` being
library-level entities, the structural instance ``Ada.Containers.Vectors(Positive,T)`` is a library unit with a dependence
on ``Q`` and, therefore, cannot be referenced from within ``Q``. The simple
way out is to declare a traditional instantiation in this case:
.. code-block:: ada
with Ada.Containers.Vectors;
package Q is
type T is record
I : Integer;
end record;
package Vectors_Of_T is new Ada.Containers.Vectors(Positive,T);
V : Vectors_Of_T.Vector;
end Q;
But the following example is legal:
.. code-block:: ada
with Ada.Containers.Vectors;
procedure P is
type T is record
I : Integer;
end record;
V : Ada.Containers.Vectors(Positive,T).Vector;
end;
because the structural instance ``Ada.Containers.Vectors(Positive,T)`` is
not a library unit.
The first example can be rewritten in a less verbose manner:
.. code-block:: ada
with Ada.Containers.Vectors; use Ada.Containers.Vectors(Positive,Integer);
procedure P is
V : Vector;
begin
V.Append (1);
V.Append (0);
Generic_Sorting("<").Sort (V);
end;
Another example, which additionally uses the inference of dependent types:
.. code-block:: ada
with Ada.Unchecked_Deallocation;
procedure P is
type Integer_Access is access all Integer;
A : Integer_Access := new Integer'(1);
begin
Ada.Unchecked_Deallocation(Name => Integer_Access) (A);
end;
@@ -267,6 +267,89 @@ or propagate an exception).
For the syntax and semantics of this aspect, see the SPARK 2014 Reference
Manual, section 6.1.10.
Aspect Extended_Access
======================
This nonoverridable boolean-valued type-related representation aspect can be
specified as part of a full_type_declaration for a general access type
designating an unconstrained array subtype.
The absence of an Extended_Access aspect specification for such a
full_type_declaration is equivalent to an explicit
"Extended_Access => False" specification. This implies
that the aspect is never unspecified for an eligible access type.
An access type for which this aspect is True is said to be an extended access
type; this includes the case of a type derived from an extended access type.
Similarly, a value of such a type is said to be an extended access value.
The representation of an extended access value is different than that of
other access values. This representation makes it possible to designate
objects that cannot be designated using the usual "thin" or "fat" access
representations for an access type designating an unconstrained array
subtype (notably slices and array objects imported from other languages).
In particular, two rules are modified in determining the legality of an Access
or Unchecked_Access attribute reference if the expected access type is
an extended access type:
* A slice of an aliased array object of a non-bitpacked type (more precisely,
of an array type having independently addressable components) is considered
to be aliased (and the accessibility level of a slice of an array object is
defined to be that of the array object); this also applies to renamings
of such slices, slices of such renamings, etc.
* The requirement that the nominal subtype of the prefix shall statically
match the designated subtype of the access type need not be met.
The Size aspect (and other aspects including Stream_Size, Object_Size,
and Alignment) of an extended access type may depend on the properties of the
designated type. Further details of this dependence are not documented.
An extended access value is not convertible to a non-extended access type,
although conversions in the opposite direction are allowed. We don't want
to allow
.. code-block:: ada
type Big_Ref is access all String with Extended_Access;
type Small_Ref is access all String;
Obj : aliased String := "abcde";
Big_Ptr : Big_Ref := Obj (2 .. 4)'Access; -- OK
Small_Ptr : Small_Ref := Small_Ref (Big_Ptr); -- ERROR: illegal conversion
because there is no way to represent the result of such a conversion.
A dereference of an extended access value (or a reference to a renaming
thereof) shall not occur in any of the following contexts:
* as an operative constituent of the prefix of an Access or
Unchecked_Access attribute reference whose expected type is not extended; or
* as an operative constituent of an actual parameter in a call where
the corresponding formal parameter is explicitly aliased.
For the same reasons that explicit conversions from an extended access type to a
non-extended access type are forbidden, we also need to disallow getting the
same effect via a Extended_Ptr.all'Access reference; this includes the case
of passing Extended_Ptr.all as an actual parameter in a call where the
corresponding formal parameter is explicitly aliased (because the callee
could evaluate Formal_Parameter'Access). This goal is accomplished by
adjusting the definition of the term "aliased". A dereference of an extended
value occurring in one of these contexts is defined to denote
a nonaliased view. This has the desired effect because these contexts require
an aliased view. Continuing the preceding example, this rule disallows
.. code-block:: ada
Sneaky_1 : Small_Ptr := Big_Ptr.all'Access; -- ERROR: illegal 'Access prefix
function Make (Str : aliased in out String) return Small_Ptr
is (Str'Access); -- OK
Sneaky_2 : Small_Ptr := Make (Str => Big_Ptr.all); -- ERROR: bad parameter
for the same reason given above in the case of an explicit type conversion.
Aspect Extensions_Visible
=========================
.. index:: Extensions_Visible
@@ -10,6 +10,8 @@ are provided by GNAT.
The features in this chapter are currently experimental and subject to
change.
These features are supported only by the GCC back end, not by LLVM.
.. Register Scrubbing:
Register Scrubbing
+12 -2
View File
@@ -663,6 +663,18 @@ sequences for various UCS input formats.
General routines for swapping the bytes in 2-, 4-, and 8-byte quantities.
Machine-specific implementations are available in some cases.
.. _`GNAT.C_Time_(g-c_time.ads)`:
``GNAT.C_Time`` (:file:`g-c_time.ads`)
======================================
.. index:: GNAT.C_Time (g-c_time.ads)
.. index:: Time
Provides the time_t, timeval and timespec types corresponding to the C
types defined by the OS, as well as various conversion functions.
.. _`GNAT.Calendar_(g-calend.ads)`:
``GNAT.Calendar`` (:file:`g-calend.ads`)
@@ -674,8 +686,6 @@ Machine-specific implementations are available in some cases.
Extends the facilities provided by ``Ada.Calendar`` to include handling
of days of the week, an extended ``Split`` and ``Time_Of`` capability.
Also provides conversion of ``Ada.Calendar.Time`` values to and from the
C ``timeval`` format.
.. _`GNAT.Calendar.Time_IO_(g-catiio.ads)`:
@@ -1608,8 +1608,12 @@ Alphabetical List of All Switches
.. index:: -gnateG (gcc)
:switch:`-gnateG`
Save result of preprocessing in a text file.
:switch:`-gnateG[bce]`
Save result of preprocessing in a text file. An optional character (b, c,
or e) can be appended to indicate that filtered lines are to be replaced by
blank lines, comment lines that include the filtered line, or empty comment
lines ("--!"), respectively. The default is to replace filtered lines with
blank lines.
.. index:: -gnateH (gcc)
@@ -8116,20 +8120,18 @@ We provide two options that you can use to build code with GNAT LLVM:
* ``gprbuild`` can detect and use GNAT LLVM when it is installed.
``gprbuild`` uses the first applicable compiler on the executable
search path, including GNAT LLVM. An easy way to build with GNAT
LLVM is to make it available on the operating system's search path
before any other Ada compiler (such as the GCC version of GNAT). To
avoid accidentally using a different compiler than the one you want
to use, we recommend generating an explicit toolchain configuration
file with ``gprconfig`` and using it with ``gprbuild``; see the
*GPRbuild and GPR Companion Tools User's Guide* for details. You
can determine from the first line of the :file:`.ali` file
which version of GNAT built that file because it contains either
:code:`GNAT` or :code:`GNAT-LLVM`.
You can also explicitly select GNAT LLVM in your existing GPR project
file by adding :code:`for Toolchain_Name("Ada") use "GNAT_LLVM";`
``gprbuild`` uses the first applicable compiler on the executable search
path, including GNAT LLVM. An easy way to build with GNAT LLVM is to make
it available on the operating system's search path before any other Ada
compiler (such as the GCC version of GNAT). To avoid accidentally using a
different compiler than the one you want to use, we recommend explicitly
selecting GNAT LLVM in your existing GPR project file by adding
:code:`for Toolchain_Name ("Ada") use "GNAT_LLVM";`. You can also
generate an explicit toolchain configuration file with ``gprconfig`` and
use it with ``gprbuild``; see the *GPRbuild and GPR Companion Tools
User's Guide* for details. You can determine from the first line of the
:file:`.ali` file which version of GNAT built that file because it
contains either :code:`GNAT` or :code:`GNAT-LLVM`.
.. only:: PRO
@@ -8145,5 +8147,4 @@ GNAT.
.. only:: PRO
It provides the same runtimes with the exception that light runtimes
are not currently included with the native compilers.
It provides the same runtimes.
@@ -2931,6 +2931,18 @@ Switches for ``gnatprep``
don't specify a value, the symbol is defined to be ``True``. You can
use this switch instead of providing a definition file.
.. index:: -e (gnatprep)
:switch:`-e`
Causes both preprocessor lines and the lines deleted by
preprocessing to be replaced by empty comment lines marked
with ``"--!"`` (and no other text) in the output source file,
preserving line numbers in the output file. This option can
be useful as an alternative to :switch:`-b` and :switch:`-c`
when compilation style switches like :switch:`-gnatyu` or
:switch:`-gnatyM` are used (to avoid warnings about multiple
blank lines or lines too long).
.. index:: -r (gnatprep)
:switch:`-r`
@@ -3248,7 +3260,7 @@ that relate to integrated preprocessing.
Causes both preprocessor lines and the lines deleted by
preprocessing to be replaced by blank lines, preserving the line number.
This switch is always implied; however, if specified after :switch:`-c`
it cancels the effect of :switch:`-c`.
or :switch:`-e` it cancels the effect of those switches.
:switch:`-c`
Causes both preprocessor lines and the lines deleted
@@ -3266,6 +3278,12 @@ that relate to integrated preprocessing.
name defined in a definition file.
:switch:`-e`
Causes both preprocessor lines and the lines deleted by
preprocessing to be replaced by empty comment lines marked
with '`--!`' (and no other text) in the output source file,
:switch:`-s`
Causes a sorted list of symbol names and values to be
listed on the standard output file.
@@ -3306,12 +3324,19 @@ that relate to integrated preprocessing.
This switch is similar to switch :switch:`-D` of ``gnatprep``.
:switch:`-gnateG`
.. index:: -gnateG (gcc)
:switch:`-gnateG[bce]`
When integrated preprocessing is performed on source file :file:`filename.extension`,
create or overwrite :file:`filename.extension.prep` to contain
the result of the preprocessing.
For example if the source file is :file:`foo.adb` then
the output file is :file:`foo.adb.prep`.
An optional character (b, c, or e) can be appended to indicate that filtered
lines are to be replaced by blank lines, comments, or empty comments (see
documentation above about :switch:`-b`, :switch:`-c`, and :switch:`-e`).
If one of those switches is given in a preprocessor data file, then it
will override any option included with :switch:`-gnateG`.
.. _Mixed_Language_Programming:
+112 -54
View File
@@ -669,6 +669,8 @@ package body Einfo.Utils is
Result := Id;
else
pragma Assert (Is_Type (Id));
-- ...because Is_Base_Type returns True for nontypes
Result := Etype (Id);
if False then
pragma Assert (Is_Base_Type (Result));
@@ -679,9 +681,29 @@ package body Einfo.Utils is
-- expect.
end if;
end if;
-- pragma Assert (Result = Base_Type_If_Set (Id));
-- Disabled; too slow
end return;
end Base_Type;
----------------------
-- Base_Type_If_Set --
----------------------
function Base_Type_If_Set (Id : E) return Opt_N_Entity_Id is
begin
return Result : Opt_N_Entity_Id do
if Is_Base_Type (Id) then
Result := Id;
elsif Field_Is_Initial_Zero (Id, F_Etype) then
Result := Empty;
else
Result := Etype (Id);
end if;
end return;
end Base_Type_If_Set;
----------------------
-- Declaration_Node --
----------------------
@@ -1374,30 +1396,43 @@ package body Einfo.Utils is
------------------------------
function Implementation_Base_Type (Id : E) return E is
Bastyp : Entity_Id;
Imptyp : Entity_Id;
begin
Bastyp := Base_Type (Id);
return Result : E := Base_Type (Id) do
if Is_Incomplete_Or_Private_Type (Result) then
Imptyp := Underlying_Type (Result);
if Is_Incomplete_Or_Private_Type (Bastyp) then
Imptyp := Underlying_Type (Bastyp);
-- If we have an implementation type, return its Base_Type.
-- If we have an implementation type, then just return it,
-- otherwise we return the Base_Type anyway. This can only
-- happen in error situations and should avoid some error bombs.
if Present (Imptyp) then
return Base_Type (Imptyp);
else
return Bastyp;
if Present (Imptyp) then
Result := Base_Type (Imptyp);
end if;
end if;
else
return Bastyp;
end if;
-- pragma Assert (Result = Implementation_Base_Type_If_Set (Id));
-- Disabled; too slow
end return;
end Implementation_Base_Type;
-------------------------------------
-- Implementation_Base_Type_If_Set --
-------------------------------------
function Implementation_Base_Type_If_Set (Id : E) return Opt_N_Entity_Id is
Imptyp : Entity_Id;
begin
return Result : Opt_N_Entity_Id := Base_Type_If_Set (Id) do
if Present (Result) and then Is_Incomplete_Or_Private_Type (Result)
then
Imptyp := Underlying_Type (Result);
if Present (Imptyp) then
Result := Base_Type_If_Set (Imptyp);
end if;
end if;
end return;
end Implementation_Base_Type_If_Set;
-------------------------
-- Invariant_Procedure --
-------------------------
@@ -2540,52 +2575,75 @@ package body Einfo.Utils is
---------------
function Root_Type (Id : E) return E is
T, Etyp : Entity_Id;
Etyp : Entity_Id;
begin
pragma Assert (Nkind (Id) in N_Entity);
return T : E := Base_Type (Id) do
if Ekind (T) = E_Class_Wide_Type then
T := Etype (T);
else
loop
Etyp := Etype (T);
T := Base_Type (Id);
exit when T = Etyp
or else
(Is_Private_Type (T) and then Etyp = Full_View (T))
or else
(Is_Private_Type (Etyp) and then Full_View (Etyp) = T);
if Ekind (T) = E_Class_Wide_Type then
return Etype (T);
T := Etyp;
-- Other cases
-- Quit if there is a circularity in the inheritance chain.
-- This happens in some error situations and we do not want
-- to get stuck in this loop.
else
loop
Etyp := Etype (T);
if T = Base_Type (Id) then
Check_Error_Detected;
exit;
end if;
end loop;
end if;
if T = Etyp then
return T;
-- Following test catches some error cases resulting from
-- previous errors.
elsif No (Etyp) then
Check_Error_Detected;
return T;
elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
return T;
elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
return T;
end if;
T := Etyp;
-- Return if there is a circularity in the inheritance chain. This
-- happens in some error situations and we do not want to get
-- stuck in this loop.
if T = Base_Type (Id) then
return T;
end if;
end loop;
end if;
-- pragma Assert (T = Root_Type_If_Set (Id));
-- Disabled; too slow
end return;
end Root_Type;
----------------------
-- Root_Type_If_Set --
----------------------
function Root_Type_If_Set (Id : E) return Opt_N_Entity_Id is
Etyp : Entity_Id;
begin
return T : Opt_N_Entity_Id := Base_Type_If_Set (Id) do
if Ekind (T) = E_Class_Wide_Type then
T := Etype (T);
else
loop
Etyp := Etype (T);
exit when No (Etyp) or else T = Etyp
or else
(Is_Private_Type (T) and then Etyp = Full_View (T))
or else
(Is_Private_Type (Etyp) and then Full_View (Etyp) = T);
T := Etyp;
-- Quit if there is a circularity in the inheritance chain.
-- This happens in some error situations and we do not want
-- to get stuck in this loop.
if T = Base_Type_If_Set (Id) then
exit;
end if;
end loop;
end if;
end return;
end Root_Type_If_Set;
---------------------
-- Safe_Emax_Value --
---------------------
@@ -3010,7 +3068,7 @@ package body Einfo.Utils is
-- Underlying_Type --
---------------------
function Underlying_Type (Id : E) return Entity_Id is
function Underlying_Type (Id : E) return Opt_N_Entity_Id is
begin
-- For record_with_private the underlying type is always the direct full
-- view. Never try to take the full view of the parent it does not make
+10 -1
View File
@@ -161,6 +161,15 @@ package Einfo.Utils is
function First_Formal (Id : E) return Entity_Id;
function First_Formal_With_Extras (Id : E) return Entity_Id;
function Base_Type_If_Set (Id : E) return Opt_N_Entity_Id;
function Implementation_Base_Type_If_Set (Id : E) return Opt_N_Entity_Id;
function Root_Type_If_Set (Id : E) return Opt_N_Entity_Id;
-- Base_Type_If_Set is a more permissive version of Base_Type, which
-- returns the same value, except it returns Empty in cases where Base_Type
-- would crash because relevant fields are not yet set. Likewise for the
-- other two. These are used in Treepr, to allow it to print half-baked
-- nodes without crashing.
function Float_Rep
(N : Entity_Id) return F with Inline, Pre =>
N in E_Void_Id
@@ -238,7 +247,7 @@ package Einfo.Utils is
function Stream_Size_Clause (Id : E) return N with Inline;
function Type_High_Bound (Id : E) return N with Inline;
function Type_Low_Bound (Id : E) return N with Inline;
function Underlying_Type (Id : E) return Entity_Id;
function Underlying_Type (Id : E) return Opt_N_Entity_Id;
function Scope_Depth (Id : Scope_Kind_Id) return U with Inline;
function Scope_Depth_Set (Id : Scope_Kind_Id) return B with Inline;
+32
View File
@@ -608,6 +608,10 @@ package Einfo is
-- determine if there actually is an active Suppress or Unsuppress pragma
-- that applies to the entity.
-- Child_Levels
-- Assrtion levels that depend on the given level are considered to be
-- the child levels of that level.
-- Class_Postconditions
-- Defined on subprogram entities. Set if the subprogram has class-wide
-- postconditions. Denotes the (and-then) expression built by merging
@@ -1461,6 +1465,12 @@ package Einfo is
-- associates generic parameters with the corresponding instances, in
-- those cases where the instance is an entity.
-- Ghost_Assertion_Level
-- Assertion level associated with the declaration of the entity. Its
-- value is either Empty for non-ghost entities, Standard_Level_Default
-- for Ghost entities without an assertion level, or a user-defined
-- assertion level.
-- Has_Aliased_Components [implementation base type only]
-- Defined in array type entities. Indicates that the component type
-- of the array is aliased. Should this also be set for records to
@@ -2164,6 +2174,11 @@ package Einfo is
-- on the partial view, to ensure that discriminants are properly
-- inherited in certain contexts.
-- Has_Unsigned_Base_Range_Aspect [base type only]
-- Defined in integer types. Set in the base type of an integer type for
-- which the type has an Unsigned_Base_Range of True (whether by an
-- aspect_specification, a pragma, or inheritance).
-- Has_Visible_Refinement
-- Defined in E_Abstract_State entities. Set when a state has at least
-- one refinement constituent and analysis is in the region between
@@ -3009,6 +3024,13 @@ package Einfo is
-- record is declared to be limited. Note that this flag is not set
-- simply because some components of the record are limited.
-- Is_Link_Once
-- Defined in all entities. Set to indicate that an entity can be defined
-- in multiple compilation units without generating a linker error. The
-- compiler guarantees that the multiple definitions are equivalent and,
-- therefore, that the linker can freely pick one of them. If this flag
-- is set on an entity, then the Is_Public flag is also set on it.
-- Is_Local_Anonymous_Access
-- Defined in access types. Set for an anonymous access type to indicate
-- that the type is created for a record component with an access
@@ -4008,6 +4030,10 @@ package Einfo is
-- used when obtaining the formal kind of a formal parameter (the result
-- is one of E_[In/Out/In_Out]_Parameter).
-- Parent_Levels
-- Assrtion levels that the given level depends on are considered to be
-- parent levels of that level.
-- Parent_Subtype [base type only]
-- Defined in E_Record_Type. Set only for derived tagged types, in which
-- case it points to the subtype of the parent type. This is the type
@@ -4971,6 +4997,7 @@ package Einfo is
-- Is_Known_Valid
-- Is_Limited_Composite
-- Is_Limited_Record
-- Is_Link_Once
-- Is_Loop_Parameter
-- Is_Obsolescent
-- Is_Package_Body_Entity
@@ -5243,6 +5270,10 @@ package Einfo is
-- Number_Dimensions (synth)
-- (plus type attributes)
-- E_Assertion_Level
-- Child_Levels
-- Parent_Levels
-- E_Block
-- Renamed_Entity $$$
-- Renamed_Object $$$
@@ -6112,6 +6143,7 @@ package Einfo is
-- Static_Discrete_Predicate
-- Has_Biased_Representation
-- Has_Shift_Operator (base type only)
-- Has_Unsigned_Base_Range_Aspect (base type only)
-- No_Predicate_On_Actual
-- No_Dynamic_Predicate_On_Actual
-- Type_Low_Bound (synth)
+2 -1
View File
@@ -229,7 +229,8 @@ void __gnat_clearenv (void)
|| defined (__CYGWIN__) \
|| defined (__NetBSD__) || defined (__OpenBSD__) || defined (__rtems__) \
|| defined (__DragonFly__) || defined (__DJGPP__)
/* On Windows, FreeBSD and MacOS there is no function to clean all the
/* On several platforms (e.g. Windows, FreeBSD, MacOS...)
there is no function to clean all the
environment but there is a "clean" way to unset a variable. So go
through the environ table and call __gnat_unsetenv on all entries */
char **env = __gnat_environ ();
+7 -7
View File
@@ -4283,7 +4283,7 @@ package body Exp_Aggr is
-- Set the Expansion_Delayed flag in the cases where the transformation
-- will be done top down from above.
Parent_Node := Unconditional_Parent (N);
Parent_Node := Unqualified_Unconditional_Parent (N);
if
-- Internal aggregates (transformed when expanding the parent),
@@ -6254,7 +6254,7 @@ package body Exp_Aggr is
-- Set the Expansion_Delayed flag in the cases where the transformation
-- will be done top down from above.
Parent_Node := Unconditional_Parent (N);
Parent_Node := Unqualified_Unconditional_Parent (N);
if
-- Internal aggregates (transformed when expanding the parent),
@@ -6984,7 +6984,9 @@ package body Exp_Aggr is
-- Choice is a single discrete value
elsif Is_Discrete_Type (Etype (Choice)) then
Update_Choices (Choice, Choice);
if Is_Static_Expression (Choice) then
Update_Choices (Choice, Choice);
end if;
Temp_Siz_Exp := Make_Integer_Literal (Loc, 1);
Set_Is_Static_Expression (Temp_Siz_Exp);
@@ -7208,13 +7210,11 @@ package body Exp_Aggr is
-- To_Int --
------------
-- The bounds of the discrete range are integers or enumeration literals
-- The bounds of the discrete range are static discrete values
function To_Int (Expr : N_Subexpr_Id) return Int is
begin
return UI_To_Int ((if Nkind (Expr) = N_Integer_Literal
then Intval (Expr)
else Enumeration_Pos (Entity (Expr))));
return UI_To_Int (Expr_Value (Expr));
end To_Int;
-- Local variables
+86 -312
View File
@@ -24,7 +24,6 @@
------------------------------------------------------------------------------
with Accessibility; use Accessibility;
with Aspects; use Aspects;
with Atree; use Atree;
with Checks; use Checks;
with Debug; use Debug;
@@ -266,6 +265,15 @@ package body Exp_Attr is
-- the implementation base type of this type (Typ). If found, return the
-- pragma node, otherwise return Empty if no pragma is found.
function Interunit_Ref_OK
(Subp_Unit, Attr_Ref_Unit : Node_Id) return Boolean;
-- Returns True if it is ok to refer to a cached subprogram declared in
-- Subp_Unit from the point of an attribute reference occurring in
-- Attr_Ref_Unit. Both arguments are usually N_Compilation_Nodes,
-- although there are cases where Subp_Unit might be a type declared in
-- package Standard (in which case the In_Same_Extended_Unit call will
-- return False).
function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean;
-- Utility for array attributes, returns true on packed constrained
-- arrays, and on access to same.
@@ -280,20 +288,6 @@ package body Exp_Attr is
-- Returns True if Typ is a user-defined enumeration type, in the sense
-- that its literals are declared in the source.
function Interunit_Ref_OK
(Subp_Unit, Attr_Ref_Unit : Node_Id) return Boolean is
(In_Same_Extended_Unit (Subp_Unit, Attr_Ref_Unit)
-- If subp declared in unit body, then we don't want to refer
-- to it from within unit spec so return False in that case.
and then not (not Is_Body (Unit (Attr_Ref_Unit))
and Is_Body (Unit (Subp_Unit))));
-- Returns True if it is ok to refer to a cached subprogram declared in
-- Subp_Unit from the point of an attribute reference occurring in
-- Attr_Ref_Unit. Both arguments are usually N_Compilation_Nodes,
-- although there are cases where Subp_Unit might be a type declared in
-- package Standard (in which case the In_Same_Extended_Unit call will
-- return False).
package body Cached_Attribute_Ops is
-------------------------------
@@ -479,7 +473,8 @@ package body Exp_Attr is
-- Local variables
Func_Id : constant Entity_Id := Make_Temporary (Loc, 'V');
Func_Id : constant Entity_Id := Make_Temporary (Loc, 'V',
Related_Node => Attr);
Indexes : constant List_Id := New_List;
Obj_Id : constant Entity_Id := Make_Temporary (Loc, 'A');
Stmts : List_Id;
@@ -836,7 +831,8 @@ package body Exp_Attr is
-- Local variables
Func_Id : constant Entity_Id := Make_Temporary (Loc, 'V');
Func_Id : constant Entity_Id := Make_Temporary (Loc, 'V',
Related_Node => Attr);
Obj_Id : constant Entity_Id := Make_Temporary (Loc, 'R');
Comps : Node_Id;
Stmts : List_Id;
@@ -2019,7 +2015,12 @@ package body Exp_Attr is
pragma Assert (Present (Insertion_Point));
end if;
Ancestor := Parent (Ancestor);
if Nkind (Ancestor) = N_Subunit then
Ancestor := Corresponding_Stub (Ancestor);
else
Ancestor := Parent (Ancestor);
end if;
end loop;
if Present (Insertion_Point) then
@@ -2171,7 +2172,7 @@ package body Exp_Attr is
-- that it has the necessary extra formals.
if not Is_Frozen (Pname) then
Create_Extra_Formals (Pname);
Create_Extra_Formals (Pname, Related_Nod => N);
end if;
-- And now rewrite the call
@@ -2648,7 +2649,7 @@ package body Exp_Attr is
Set_Extra_Formal (Extra, Empty);
end if;
Create_Extra_Formals (Subp_Typ);
Create_Extra_Formals (Subp_Typ, Related_Nod => N);
Set_Directly_Designated_Type (Typ, Subp_Typ);
end;
end if;
@@ -2679,13 +2680,13 @@ package body Exp_Attr is
if not Is_Frozen (Entity (Pref))
or else From_Limited_With (Etype (Entity (Pref)))
then
Create_Extra_Formals (Entity (Pref));
Create_Extra_Formals (Entity (Pref), Related_Nod => N);
end if;
if not Is_Frozen (Btyp_DDT)
or else From_Limited_With (Etype (Btyp_DDT))
then
Create_Extra_Formals (Btyp_DDT);
Create_Extra_Formals (Btyp_DDT, Related_Nod => N);
end if;
pragma Assert
@@ -5111,310 +5112,57 @@ package body Exp_Attr is
when Attribute_Make =>
declare
Params : List_Id;
Param : Node_Id;
Par : Node_Id;
Construct : Entity_Id;
Obj : Node_Id := Empty;
Make_Expr : Node_Id := N;
Formal : Entity_Id;
Replace_Expr : Node_Id;
Init_Param : Node_Id;
Construct_Call : Node_Id;
Curr_Nam : Node_Id := Empty;
function Replace_Formal_Ref
(N : Node_Id) return Traverse_Result;
function Replace_Formal_Ref
(N : Node_Id) return Traverse_Result is
begin
if Is_Entity_Name (N)
and then Chars (Formal) = Chars (N)
then
Rewrite (N,
New_Copy_Tree (Replace_Expr));
end if;
return OK;
end Replace_Formal_Ref;
procedure Search_And_Replace_Formal is new
Traverse_Proc (Replace_Formal_Ref);
Constructor_Params : List_Id := New_Copy_List (Expressions (N));
Constructor_Call : Node_Id;
Constructor_EWA : Node_Id;
Result_Decl : Node_Id;
Result_Id : constant Entity_Id :=
Make_Temporary (Loc, 'D', N);
begin
-- Remove side effects for constructor call
Param := First (Expressions (N));
while Present (Param) loop
if Nkind (Param) = N_Parameter_Association then
Remove_Side_Effects (Explicit_Actual_Parameter (Param),
Check_Side_Effects => False);
else
Remove_Side_Effects (Param, Check_Side_Effects => False);
end if;
Next (Param);
end loop;
-- Construct the parameters list
Params := New_Copy_List (Expressions (N));
if Is_Empty_List (Params) then
Params := New_List;
if Is_Empty_List (Constructor_Params) then
Constructor_Params := New_List;
end if;
-- Identify the enclosing parent for the non-copy cases
Result_Decl := Make_Object_Declaration (Loc,
Defining_Identifier => Result_Id,
Object_Definition =>
New_Occurrence_Of (Typ, Loc));
Par := Parent (N);
if Nkind (Par) = N_Qualified_Expression then
Par := Parent (Par);
Make_Expr := Par;
end if;
if Nkind (Par) = N_Allocator then
Par := Parent (Par);
Curr_Nam := Make_Explicit_Dereference
(Loc, Prefix => Empty);
Obj := Curr_Nam;
end if;
-- Suppress default initialization for result object.
-- Default init (except for tag, if tagged) will instead be
-- performed in the constructor procedure.
Mutate_Ekind (Result_Id, E_Variable);
Set_Suppress_Initialization (Result_Id);
-- Build a prefixed-notation call
declare
Base_Obj : Node_Id := Empty;
Typ_Comp : Entity_Id;
Agg_Comp : Entity_Id;
Comp_Nam : Node_Id := Empty;
Proc_Name : constant Node_Id :=
Make_Selected_Component (Loc,
Prefix => New_Occurrence_Of (Result_Id, Loc),
Selector_Name => Make_Identifier (Loc,
Chars (Constructor_Name (Typ))));
begin
while Nkind (Par) not in N_Object_Declaration
| N_Assignment_Statement
loop
if Nkind (Par) = N_Aggregate then
Typ_Comp := First_Entity (Etype (Par));
Agg_Comp := First (Expressions (Par));
loop
if No (Agg_Comp) then
return;
end if;
Set_Is_Prefixed_Call (Proc_Name);
if Agg_Comp = Make_Expr then
Comp_Nam :=
Make_Selected_Component (Loc,
Prefix => Empty,
Selector_Name =>
New_Occurrence_Of (Typ_Comp, Loc));
Make_Expr := Parent (Make_Expr);
Par := Parent (Par);
exit;
end if;
Next_Entity (Typ_Comp);
Next (Agg_Comp);
end loop;
elsif Nkind (Par) = N_Component_Association then
Comp_Nam :=
Make_Selected_Component (Loc,
Prefix => Empty,
Selector_Name =>
Make_Identifier (Loc,
(Chars (First (Choices (Par))))));
Make_Expr := Parent (Parent (Make_Expr));
Par := Parent (Parent (Par));
else
declare
Temp : constant Entity_Id :=
Make_Temporary (Loc, 'T', N);
begin
Rewrite (N,
Make_Expression_With_Actions (Loc,
Actions => New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition =>
New_Occurrence_Of (Typ, Loc),
Expression =>
New_Copy_Tree (N))),
Expression => New_Occurrence_Of (Temp, Loc)));
Analyze_And_Resolve (N);
return;
end;
end if;
if No (Curr_Nam) then
Curr_Nam := Comp_Nam;
Obj := Curr_Nam;
elsif Has_Prefix (Curr_Nam) then
Set_Prefix (Curr_Nam, Comp_Nam);
Curr_Nam := Comp_Nam;
end if;
end loop;
Base_Obj := (case Nkind (Par) is
when N_Assignment_Statement =>
New_Copy_Tree (Name (Par)),
when N_Object_Declaration =>
New_Occurrence_Of
(Defining_Identifier (Par), Loc),
when others => (raise Program_Error));
if Present (Curr_Nam) then
Set_Prefix (Curr_Nam, Base_Obj);
else
Obj := Base_Obj;
end if;
Constructor_Call := Make_Procedure_Call_Statement (Loc,
Parameter_Associations => Constructor_Params,
Name => Proc_Name);
end;
Prepend_To (Params, Obj);
Set_Is_Expanded_Constructor_Call (Constructor_Call, True);
-- Find the constructor we are interested in by doing a
-- pseudo-pass to resolve the constructor call.
Constructor_EWA :=
Make_Expression_With_Actions (Loc,
Actions => New_List (Result_Decl, Constructor_Call),
Expression => New_Occurrence_Of (Result_Id, Loc));
declare
Dummy_Params : List_Id := New_Copy_List (Expressions (N));
Dummy_Self : Node_Id;
Dummy_Block : Node_Id;
Dummy_Call : Node_Id;
Dummy_Id : Entity_Id := Make_Temporary (Loc, 'D', N);
begin
if Is_Empty_List (Dummy_Params) then
Dummy_Params := New_List;
end if;
Dummy_Self := Make_Object_Declaration (Loc,
Defining_Identifier => Dummy_Id,
Object_Definition =>
New_Occurrence_Of (Typ, Loc));
Prepend_To (Dummy_Params, New_Occurrence_Of (Dummy_Id, Loc));
Dummy_Call := Make_Procedure_Call_Statement (Loc,
Parameter_Associations => Dummy_Params,
Name =>
(if not Has_Prefix (Pref) then
Make_Identifier (Loc,
Chars (Constructor_Name (Typ)))
else
Make_Expanded_Name (Loc,
Chars =>
Chars (Constructor_Name (Typ)),
Prefix =>
New_Copy_Tree (Prefix (Pref)),
Selector_Name =>
Make_Identifier (Loc,
Chars (Constructor_Name (Typ))))));
Set_Is_Expanded_Constructor_Call (Dummy_Call, True);
Dummy_Block := Make_Block_Statement (Loc,
Declarations => New_List (Dummy_Self),
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (Dummy_Call)));
Expander_Active := False;
Insert_After_And_Analyze
(Enclosing_Declaration_Or_Statement (Par), Dummy_Block);
Expander_Active := True;
-- Finally, we can get the constructor based on our pseudo-pass
Construct := Entity (Name (Dummy_Call));
-- Replace the Typ'Make attribute with an aggregate featuring
-- then relevant aggregate from the correct constructor's
-- Inializeaspect if it is present - otherwise, simply use a
-- box.
if Has_Aspect (Construct, Aspect_Initialize) then
Rewrite (N,
New_Copy_Tree
(Find_Value_Of_Aspect (Construct, Aspect_Initialize)));
Param := Next (First (Params));
Formal := Next_Entity (First_Entity (Construct));
while Present (Param) loop
if Nkind (Param) = N_Parameter_Association then
Formal := Selector_Name (Param);
Replace_Expr := Explicit_Actual_Parameter (Param);
else
Replace_Expr := Param;
end if;
Init_Param := First (Component_Associations (N));
while Present (Init_Param) loop
Search_And_Replace_Formal (Expression (Init_Param));
Next (Init_Param);
end loop;
if Nkind (Param) /= N_Parameter_Association then
Next_Entity (Formal);
end if;
Next (Param);
end loop;
Init_Param := First (Component_Associations (N));
while Present (Init_Param) loop
if Nkind (Expression (Init_Param)) = N_Attribute_Reference
and then Attribute_Name
(Expression (Init_Param)) = Name_Make
then
Insert_After (Par,
Make_Assignment_Statement (Loc,
Name =>
Make_Selected_Component (Loc,
Prefix =>
New_Copy_Tree (First (Params)),
Selector_Name =>
Make_Identifier (Loc,
Chars (First (Choices (Init_Param))))),
Expression =>
New_Copy_Tree (Expression (Init_Param))));
Rewrite (Expression (Init_Param),
Make_Aggregate (Loc,
Expressions => New_List,
Component_Associations => New_List (
Make_Component_Association (Loc,
Choices =>
New_List (Make_Others_Choice (Loc)),
Expression => Empty,
Box_Present => True))));
end if;
Next (Init_Param);
end loop;
else
Rewrite (N,
Make_Aggregate (Loc,
Expressions => New_List,
Component_Associations => New_List (
Make_Component_Association (Loc,
Choices => New_List (Make_Others_Choice (Loc)),
Expression => Empty,
Box_Present => True))));
end if;
-- Rewrite this block to be null and pretend it didn't happen
Rewrite (Dummy_Block, Make_Null_Statement (Loc));
end;
Analyze_And_Resolve (N, Typ);
-- Finally, insert the constructor call
Construct_Call :=
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (Construct, Loc),
Parameter_Associations => Params);
Set_Is_Expanded_Constructor_Call (Construct_Call);
Insert_After (Par, Construct_Call);
Rewrite (N, Constructor_EWA);
end;
Analyze_And_Resolve (N, Typ);
--------------
-- Mantissa --
--------------
@@ -8883,6 +8631,7 @@ package body Exp_Attr is
| Attribute_Type_Key
| Attribute_Unconstrained_Array
| Attribute_Universal_Literal_String
| Attribute_Unsigned_Base_Range
| Attribute_Wchar_T_Size
| Attribute_Word_Size
=>
@@ -9851,6 +9600,31 @@ package body Exp_Attr is
return Empty;
end Get_Stream_Convert_Pragma;
----------------------
-- Interunit_Ref_OK --
----------------------
function Interunit_Ref_OK
(Subp_Unit, Attr_Ref_Unit : Node_Id) return Boolean is
function Unit_Is_Body_Or_Subunit (U : Node_Id) return Boolean is
(Is_Body (Unit (U)) or else Nkind (Unit (U)) = N_Subunit);
begin
if not In_Same_Extended_Unit (Subp_Unit, Attr_Ref_Unit) then
return False;
-- If subp declared in unit body, then we don't want to refer
-- to it from within unit spec so return False in that case.
elsif Unit_Is_Body_Or_Subunit (Subp_Unit)
and then not Unit_Is_Body_Or_Subunit (Attr_Ref_Unit)
then
return False;
end if;
return True;
end Interunit_Ref_OK;
---------------------------------
-- Is_Constrained_Packed_Array --
---------------------------------
+52 -50
View File
@@ -75,7 +75,6 @@ with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;
with Stand; use Stand;
with Snames; use Snames;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Validsw; use Validsw;
with Warnsw; use Warnsw;
@@ -211,32 +210,6 @@ package body Exp_Ch3 is
-- component that requires late initialization; this includes
-- components of ancestor types.
type Initialization_Mode is
(Full_Init, Full_Init_Except_Tag, Early_Init_Only, Late_Init_Only);
-- The initialization routine for a tagged type is passed in a
-- formal parameter of this type, indicating what initialization
-- is to be performed. This parameter defaults to Full_Init in all
-- cases except when the init proc of a type extension (let's call
-- that type T2) calls the init proc of its parent (let's call that
-- type T1). In that case, one of the other 3 values will
-- be passed in. In all three of those cases, the Tag component has
-- already been initialized before the call and is therefore not to be
-- modified. T2's init proc will either call T1's init proc
-- once (with Full_Init_Except_Tag as the parameter value) or twice
-- (first with Early_Init_Only, then later with Late_Init_Only),
-- depending on the result returned by Has_Late_Init_Component (T1).
-- In the latter case, the first call does not initialize any
-- components that require late initialization and the second call
-- then performs that deferred initialization.
-- Strictly speaking, the formal parameter subtype is actually Natural
-- but calls will only pass in values corresponding to literals
-- of this enumeration type.
function Make_Mode_Literal
(Loc : Source_Ptr; Mode : Initialization_Mode) return Node_Id
is (Make_Integer_Literal (Loc, Initialization_Mode'Pos (Mode)));
-- Generate an integer literal for a given mode value.
function Tag_Init_Condition
(Loc : Source_Ptr;
Init_Control_Formal : Entity_Id) return Node_Id;
@@ -2145,7 +2118,7 @@ package body Exp_Ch3 is
end if;
if Policy_In_Effect (Name_Assert) = Name_Check
and then not Predicates_Ignored (Etype (Discr))
and then not Predicates_Ignored_In_Codegen (Etype (Discr))
then
Prepend_To (Res, Make_Predicate_Check (Typ, Val));
end if;
@@ -2481,14 +2454,10 @@ package body Exp_Ch3 is
and then Nkind (Id_Ref) = N_Selected_Component
and then Chars (Selector_Name (Id_Ref)) = Name_uParent
then
declare
use Initialization_Control;
begin
Append_To (Args,
(if Present (Init_Control_Actual)
then Init_Control_Actual
else Make_Mode_Literal (Loc, Full_Init_Except_Tag)));
end;
Append_To (Args,
(if Present (Init_Control_Actual)
then Init_Control_Actual
else Make_Mode_Literal (Loc, Full_Init_Except_Tag)));
elsif Present (Constructor_Ref) then
Append_List_To (Args,
New_Copy_List (Parameter_Associations (Constructor_Ref)));
@@ -3216,6 +3185,40 @@ package body Exp_Ch3 is
if Parent_Subtype_Renaming_Discrims then
Append_List_To (Body_Stmts, Build_Init_Call_Thru (Parameters));
elsif Present (Constructor_Name (Rec_Type)) then
if Present (Default_Constructor (Rec_Type)) then
-- The 'Make attribute reference (with no arguments) will
-- generate a call to the one-parameter constructor procedure.
Append_To (Body_Stmts,
Make_Assignment_Statement (Loc,
Name => New_Occurrence_Of
(Defining_Identifier (First (Parameters)), Loc),
Expression => Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Rec_Type, Loc),
Attribute_Name => Name_Make)));
else
-- No constructor procedure with an appropriate profile
-- is available, so raise Program_Error.
--
-- We could instead do nothing here, since the absence of a
-- one-parameter constructor procedure should trigger other
-- legality checks which should statically ensure that
-- the init proc we are constructing here will never be
-- called. So a bit of "belt and suspenders" here.
-- If this raise statement is ever executed, that probably
-- means that some compile-time legality check is not
-- implemented, and that the program should have instead
-- failed to compile.
-- Because this raise statement should never be executed, it
-- seems ok to pass in a dubious Reason parameter instead of
-- declaring a new RT_Exception_Code value.
Append_To (Body_Stmts,
Make_Raise_Program_Error (Loc,
Reason => PE_Explicit_Raise));
end if;
elsif Nkind (Type_Definition (N)) = N_Record_Definition then
Build_Discriminant_Assignments (Body_Stmts);
@@ -3310,7 +3313,7 @@ package body Exp_Ch3 is
end if;
end if;
-- Add here the assignment to instantiate the Tag
-- Add here the assignment to initialize the Tag
-- The assignment corresponds to the code:
@@ -4170,7 +4173,6 @@ package body Exp_Ch3 is
if Present (Parent_Id) then
declare
Parent_Loc : constant Source_Ptr := Sloc (Parent (Parent_Id));
use Initialization_Control;
begin
-- We are building the init proc for a type extension.
-- Call the parent type's init proc a second time, this
@@ -4558,6 +4560,8 @@ package body Exp_Ch3 is
-- since the call is generated, there had better be a routine
-- at the other end of the call, even if it does nothing).
-- 10. The type has a specified Constructor aspect.
-- Note: the reason we exclude the CPP_Class case is because in this
-- case the initialization is performed by the C++ constructors, and
-- the IP is built by Set_CPP_Constructors.
@@ -4573,6 +4577,7 @@ package body Exp_Ch3 is
or else Is_Tagged_Type (Rec_Id)
or else Is_Concurrent_Record_Type (Rec_Id)
or else Has_Task (Rec_Id)
or else Present (Constructor_Name (Rec_Id))
then
return True;
end if;
@@ -5878,7 +5883,7 @@ package body Exp_Ch3 is
-- the subtype.
if not No_Exception_Handlers_Set
and then not Predicates_Ignored (Typ)
and then not Predicates_Ignored_In_Codegen (Typ)
then
Append_To (Lst,
Make_Case_Statement_Alternative (Loc,
@@ -6592,7 +6597,7 @@ package body Exp_Ch3 is
Elmt := First_Elmt (Primitive_Operations (Typ));
while Present (Elmt) loop
Create_Extra_Formals (Node (Elmt));
Create_Extra_Formals (Node (Elmt), Related_Nod => N);
Next_Elmt (Elmt);
end loop;
@@ -6609,7 +6614,7 @@ package body Exp_Ch3 is
and then Find_Dispatching_Type (E) = Typ
and then not Contains (Primitive_Operations (Typ), E)
then
Create_Extra_Formals (E);
Create_Extra_Formals (E, Related_Nod => N);
end if;
Next_Entity (E);
@@ -9601,8 +9606,7 @@ package body Exp_Ch3 is
Def_Id : constant Entity_Id := Entity (N);
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
Result : Boolean := False;
@@ -9956,13 +9960,13 @@ package body Exp_Ch3 is
end if;
end if;
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
return Result;
exception
when RE_Not_Available =>
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
return False;
end Freeze_Type;
@@ -10787,11 +10791,9 @@ package body Exp_Ch3 is
or else (Is_Record_Type (Typ)
and then Is_Protected_Record_Type (Typ));
With_Task : constant Boolean :=
not Global_No_Tasking
and then
(Has_Task (Typ)
or else (Is_Record_Type (Typ)
and then Is_Task_Record_Type (Typ)));
Has_Task (Typ)
or else (Is_Record_Type (Typ)
and then Is_Task_Record_Type (Typ));
Formals : List_Id;
begin
+27
View File
@@ -27,6 +27,7 @@
with Elists; use Elists;
with Exp_Tss; use Exp_Tss;
with Tbuild; use Tbuild;
with Types; use Types;
with Uintp; use Uintp;
@@ -194,6 +195,32 @@ package Exp_Ch3 is
-- initialized; if Variable_Comps is True then tags components located at
-- variable positions of Target are initialized.
type Initialization_Mode is
(Full_Init, Full_Init_Except_Tag, Early_Init_Only, Late_Init_Only);
-- The initialization routine for a tagged type is passed in a
-- formal parameter of this type, indicating what initialization
-- is to be performed. This parameter defaults to Full_Init in all
-- cases except when the init proc of a type extension (let's call
-- that type T2) calls the init proc of its parent (let's call that
-- type T1). In that case, one of the other 3 values will
-- be passed in. In all three of those cases, the Tag component has
-- already been initialized before the call and is therefore not to be
-- modified. T2's init proc will either call T1's init proc
-- once (with Full_Init_Except_Tag as the parameter value) or twice
-- (first with Early_Init_Only, then later with Late_Init_Only),
-- depending on the result returned by Has_Late_Init_Component (T1).
-- In the latter case, the first call does not initialize any
-- components that require late initialization and the second call
-- then performs that deferred initialization.
-- Strictly speaking, the formal parameter subtype is actually Natural
-- but calls will only pass in values corresponding to literals
-- of this enumeration type.
function Make_Mode_Literal
(Loc : Source_Ptr; Mode : Initialization_Mode) return Node_Id
is (Make_Integer_Literal (Loc, Initialization_Mode'Pos (Mode)));
-- Generate an integer literal for a given mode value.
procedure Make_Controlling_Function_Wrappers
(Tag_Typ : Entity_Id;
Decl_List : out List_Id;
+96 -8
View File
@@ -5198,7 +5198,8 @@ package body Exp_Ch4 is
if not Expansion_Delayed (N) then
declare
Uncond_Par : constant Node_Id := Unconditional_Parent (N);
Uncond_Par : constant Node_Id :=
Unqualified_Unconditional_Parent (N);
begin
if Nkind (Uncond_Par) = N_Simple_Return_Statement
or else Is_Optimizable_Declaration (Uncond_Par)
@@ -5807,7 +5808,8 @@ package body Exp_Ch4 is
if not Expansion_Delayed (N) then
declare
Uncond_Par : constant Node_Id := Unconditional_Parent (N);
Uncond_Par : constant Node_Id :=
Unqualified_Unconditional_Parent (N);
begin
if Nkind (Uncond_Par) = N_Simple_Return_Statement
or else Is_Optimizable_Declaration (Uncond_Par)
@@ -7870,9 +7872,15 @@ package body Exp_Ch4 is
end if;
end if;
-- Arithmetic overflow checks for signed integer/fixed point types
-- Arithmetic overflow checks for signed integer/fixed point types,
-- and signed integer types with unsigned base range aspect.
if Is_Signed_Integer_Type (Typ) or else Is_Fixed_Point_Type (Typ) then
if Is_Signed_Integer_Type (Typ)
or else Is_Fixed_Point_Type (Typ)
or else
(Is_Modular_Integer_Type (Typ)
and then Has_Unsigned_Base_Range_Aspect (Base_Type (Typ)))
then
Apply_Arithmetic_Overflow_Check (N);
return;
end if;
@@ -8179,6 +8187,11 @@ package body Exp_Ch4 is
-- Determines whether a type has a subcomponent of an unconstrained
-- Unchecked_Union subtype. Typ is a record type.
procedure Warn_On_Abstract_Equality_For_Component
(Comp_Type : Entity_Id);
-- If Comp_Type is a record type with a user-defined abstract primitive
-- equality, then issue a warning that Program_Error will be raised.
-------------------------
-- Build_Equality_Call --
-------------------------
@@ -8403,6 +8416,27 @@ package body Exp_Ch4 is
Unconstrained_UU_In_Component_List (Optional_Component_List);
end Has_Unconstrained_UU_Component;
---------------------------------------------
-- Warn_On_Abstract_Equality_For_Component --
---------------------------------------------
procedure Warn_On_Abstract_Equality_For_Component
(Comp_Type : Entity_Id)
is
Eq : Entity_Id;
begin
if Is_Record_Type (Underlying_Type (Comp_Type)) then
Eq := Get_User_Defined_Equality (Comp_Type);
if Present (Eq) and then Is_Abstract_Subprogram (Eq) then
Error_Msg_Warn := SPARK_Mode /= On;
Error_Msg_NE ("call to abstract equality function of "
& "component type &<<", N, Comp_Type);
Error_Msg_N ("\Program_Error [<<", N);
end if;
end if;
end Warn_On_Abstract_Equality_For_Component;
-- Local variables
Typl : Entity_Id;
@@ -8471,6 +8505,16 @@ package body Exp_Ch4 is
elsif Is_Array_Type (Typl) then
-- If the outer type doesn't have a user-defined equality operation,
-- check whether its component type has an abstract equality, and
-- warn if so. Such a component equality function will raise
-- Program_Error of objects of the outer type are compared using
-- predefined equality.
if not Present (Get_User_Defined_Equality (Typl)) then
Warn_On_Abstract_Equality_For_Component (Component_Type (Typl));
end if;
-- If we are doing full validity checking, and it is possible for the
-- array elements to be invalid then expand out array comparisons to
-- make sure that we check the array elements.
@@ -8540,6 +8584,36 @@ package body Exp_Ch4 is
elsif Is_Record_Type (Typl) then
-- When outer type doesn't have a user-defined equality operation,
-- check whether any of its components' types have an abstract
-- equality, and warn if so. Such component equality functions will
-- raise Program_Error when objects of the outer type are compared
-- using predefined equality.
-- ??? Note that this warning is currently only issued in cases of
-- top-level components of the type and not for deeper subcomponents.
-- Those could be handled with more work, such as by adding a flag
-- on record type entities, but it's not clear that it would be
-- worth the effort. Another limitation is that the warning check
-- is not done for tagged types in some cases, because equality
-- comparisons for those can be changed to calls at an earlier point
-- during analysis and resolution, and do not reach this code (but in
-- many cases tagged equality comparisons do reach the code below).
if not Present (Get_User_Defined_Equality (Typl)) then
declare
Comp : Entity_Id := First_Component (Typl);
begin
while Present (Comp) loop
if Chars (Comp) /= Name_uParent then
Warn_On_Abstract_Equality_For_Component (Etype (Comp));
end if;
Next_Component (Comp);
end loop;
end;
end if;
-- For tagged types, use the primitive "="
if Is_Tagged_Type (Typl) then
@@ -9387,7 +9461,11 @@ package body Exp_Ch4 is
end if;
if not Backend_Overflow_Checks_On_Target
and then Is_Signed_Integer_Type (Typ)
and then
(Is_Signed_Integer_Type (Typ)
or else
(Is_Modular_Integer_Type (Typ)
and then Has_Unsigned_Base_Range_Aspect (Base_Type (Typ))))
and then Do_Overflow_Check (N)
then
-- Software overflow checking expands -expr into (0 - expr)
@@ -9811,7 +9889,11 @@ package body Exp_Ch4 is
-- Non-fixed point cases, check software overflow checking required
elsif Is_Signed_Integer_Type (Etype (N)) then
elsif Is_Signed_Integer_Type (Etype (N))
or else
(Is_Modular_Integer_Type (Typ)
and then Has_Unsigned_Base_Range_Aspect (Base_Type (Typ)))
then
Apply_Arithmetic_Overflow_Check (N);
end if;
@@ -10375,9 +10457,15 @@ package body Exp_Ch4 is
return;
end if;
-- Arithmetic overflow checks for signed integer/fixed point types
-- Arithmetic overflow checks for signed integer/fixed point types,
-- and signed integer types with unsigned base range aspect.
if Is_Signed_Integer_Type (Typ) or else Is_Fixed_Point_Type (Typ) then
if Is_Signed_Integer_Type (Typ)
or else Is_Fixed_Point_Type (Typ)
or else
(Is_Modular_Integer_Type (Typ)
and then Has_Unsigned_Base_Range_Aspect (Base_Type (Typ)))
then
Apply_Arithmetic_Overflow_Check (N);
end if;
+5 -18
View File
@@ -2254,7 +2254,8 @@ package body Exp_Ch5 is
function Replace_Target (N : Node_Id) return Traverse_Result;
-- Replace occurrences of the target name by the proper entity: either
-- the entity of the LHS in simple cases, or the formal of the
-- constructed procedure otherwise.
-- constructed procedure otherwise. Mark all nodes as Analyzed=False
-- so reanalysis will occur.
--------------------
-- Replace_Target --
@@ -2264,20 +2265,6 @@ package body Exp_Ch5 is
begin
if Nkind (N) = N_Target_Name then
Rewrite (N, New_Occurrence_Of (Ent, Sloc (N)));
-- The expression will be reanalyzed when the enclosing assignment
-- is reanalyzed, so reset the entity, which may be a temporary
-- created during analysis, e.g. a loop variable for an iterated
-- component association. However, if entity is callable then
-- resolution has established its proper identity (including in
-- rewritten prefixed calls) so we must preserve it.
elsif Is_Entity_Name (N) then
if Present (Entity (N))
and then not Is_Overloadable (Entity (N))
then
Set_Entity (N, Empty);
end if;
end if;
Set_Analyzed (N, False);
@@ -4118,7 +4105,7 @@ package body Exp_Ch5 is
if Compile_Time_Known_Value (Expr)
and then Has_Predicates (Etype (Expr))
and then not Predicates_Ignored (Etype (Expr))
and then not Predicates_Ignored_In_Codegen (Etype (Expr))
and then not Is_OK_Static_Expression (Expr)
then
Rewrite (N,
@@ -4203,7 +4190,7 @@ package body Exp_Ch5 is
-- generated case statements).
if Validity_Check_Default
and then not Predicates_Ignored (Etype (Expr))
and then not Predicates_Ignored_In_Codegen (Etype (Expr))
then
-- Recognize the simple case where Expr is an object reference
-- and the case statement is directly preceded by an
@@ -4378,7 +4365,7 @@ package body Exp_Ch5 is
-- predicate, and there is no Others choice, Constraint_Error
-- must be raised (RM 4.5.7 (21/3) and 5.4 (13)).
if Predicates_Ignored (Etype (Expr)) then
if Predicates_Ignored_In_Codegen (Etype (Expr)) then
declare
Except : constant Node_Id :=
Make_Raise_Constraint_Error (Loc,
+380 -35
View File
@@ -921,7 +921,8 @@ package body Exp_Ch6 is
-- in accessibility.adb (which can cause the extra formal parameter
-- needed for the check(s) generated here to be missing in the case
-- of a tagged result type); this is a workaround and can
-- prevent generation of a required check.
-- prevent generation of a required check (or even a required
-- legality check - see "statically too deep" check below).
if No (Extra_Accessibility_Of_Result (Func)) then
return;
@@ -969,6 +970,15 @@ package body Exp_Ch6 is
Accessibility_Level (Discr_Exp, Level => Dynamic_Level);
Analyze (Discrim_Level);
if Nkind (Discrim_Level) = N_Integer_Literal
and then Intval (Discrim_Level) > Scope_Depth (Func)
then
Error_Msg_N
("level of type of access discriminant value of "
& "return expression is statically too deep",
Enclosing_Declaration_Or_Statement (Exp));
end if;
Insert_Action (Exp,
Make_Raise_Program_Error (Loc,
Condition =>
@@ -1413,13 +1423,6 @@ package body Exp_Ch6 is
Formal : Entity_Id;
begin
pragma Assert (Nkind (Subp_Call) in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement);
pragma Assert (Extra_Formals_Known (Subp_Id)
or else not Expander_Active
or else Is_Unsupported_Extra_Actuals_Call (Subp_Call, Subp_Id));
-- In CodePeer_Mode, the tree for `'Elab_Spec` procedures will be
-- malformed because GNAT does not perform the usual expansion that
-- results in the importation of external elaboration procedure symbols.
@@ -1437,6 +1440,13 @@ package body Exp_Ch6 is
return True;
end if;
pragma Assert (Nkind (Subp_Call) in N_Entry_Call_Statement
| N_Function_Call
| N_Procedure_Call_Statement);
pragma Assert (Extra_Formals_Known (Subp_Id)
or else not Expander_Active
or else Is_Unsupported_Extra_Actuals_Call (Subp_Call, Subp_Id));
Formal := First_Formal_With_Extras (Subp_Id);
Actual := First_Actual (Subp_Call);
@@ -2936,7 +2946,11 @@ package body Exp_Ch6 is
and then Predicate_Tests_On_Arguments (Subp)
then
Append_To (Post_Call,
-- If Actual is a view conversion to a by-copy subtype
-- that is subject to a predicate, then the predicate
-- check must precede copy-back. So Prepend.
Prepend_To (Post_Call,
Make_Predicate_Check (Atyp, Actual));
end if;
end By_Ref_Predicate_Check;
@@ -4017,7 +4031,8 @@ package body Exp_Ch6 is
procedure Check_Subprogram_Variant;
-- Emit a call to the internally generated procedure with checks for
-- aspect Subprogram_Variant, if present and enabled.
-- aspect Subprogram_Variant, if present and enabled. Multiple calls are
-- added when the subprogram was using Assertion_Levels.
function Inherited_From_Formal (S : Entity_Id) return Entity_Id;
-- Within an instance, a type derived from an untagged formal derived
@@ -4302,7 +4317,7 @@ package body Exp_Ch6 is
-- Local variables
Variant_Prag : constant Node_Id :=
Variant_Prag : Node_Id :=
Get_Pragma (Current_Scope, Pragma_Subprogram_Variant);
New_Call : Node_Id;
@@ -4310,8 +4325,10 @@ package body Exp_Ch6 is
Variant_Proc : Entity_Id;
begin
if Present (Variant_Prag) and then Is_Checked (Variant_Prag) then
while Present (Variant_Prag)
and then Is_Checked (Variant_Prag)
and then Pragma_Name (Variant_Prag) = Name_Subprogram_Variant
loop
Pragma_Arg1 :=
Expression (First (Pragma_Argument_Associations (Variant_Prag)));
@@ -4320,12 +4337,13 @@ package body Exp_Ch6 is
-- run-time execution.
if Nkind (Pragma_Arg1) = N_Aggregate then
pragma Assert
(Chars
(First
(Choices
(First (Component_Associations (Pragma_Arg1))))) =
Name_Structural);
pragma
Assert
(Chars
(First
(Choices
(First (Component_Associations (Pragma_Arg1)))))
= Name_Structural);
return;
end if;
@@ -4335,7 +4353,8 @@ package body Exp_Ch6 is
Variant_Proc := Entity (Pragma_Arg1);
New_Call :=
Make_Procedure_Call_Statement (Loc,
Make_Procedure_Call_Statement
(Loc,
Name =>
New_Occurrence_Of (Variant_Proc, Loc),
Parameter_Associations =>
@@ -4343,9 +4362,13 @@ package body Exp_Ch6 is
Insert_Action (Call_Node, New_Call);
pragma Assert (Etype (New_Call) /= Any_Type
or else Serious_Errors_Detected > 0);
end if;
pragma
Assert
(Etype (New_Call) /= Any_Type
or else Serious_Errors_Detected > 0);
Variant_Prag := Next_Pragma (Variant_Prag);
end loop;
end Check_Subprogram_Variant;
---------------------------
@@ -4697,7 +4720,7 @@ package body Exp_Ch6 is
-- of init procs were added when they were built.
if not Extra_Formals_Known (Subp) then
Create_Extra_Formals (Subp);
Create_Extra_Formals (Subp, Related_Nod => Call_Node);
-- If the previous call to Create_Extra_Formals could not add the
-- extra formals, then we must defer adding the extra actuals of
@@ -4766,7 +4789,7 @@ package body Exp_Ch6 is
and then Extra_Formals_Known (Subp)
and then Present (Extra_Formals (Subp))
then
Create_Extra_Actuals (N);
Create_Extra_Actuals (Call_Node);
-- Mark the call as an expanded build-in-place call; required
-- to avoid adding the extra formals twice.
@@ -5209,10 +5232,10 @@ package body Exp_Ch6 is
null;
elsif not Defer_Extra_Actuals then
Create_Extra_Formals (Subp);
Create_Extra_Formals (Subp, Related_Nod => Call_Node);
if Extra_Formals_Known (Subp) then
Create_Extra_Actuals (N);
Create_Extra_Actuals (Call_Node);
end if;
end if;
@@ -5228,7 +5251,7 @@ package body Exp_Ch6 is
-- the current subprogram is called.
if Is_Subprogram (Subp)
and then not Is_Ignored_Ghost_Entity (Subp)
and then not Is_Ignored_Ghost_Entity_In_Codegen (Subp)
and then Same_Or_Aliased_Subprograms (Subp, Current_Scope)
then
Check_Subprogram_Variant;
@@ -5770,11 +5793,14 @@ package body Exp_Ch6 is
is
Par : constant Node_Id := Parent (N);
Uncond_Par : constant Node_Id := Unconditional_Parent (N);
-- Beware that a qualified expression around a function call cannot be
-- considered as transparent (like around an aggregate) because it may
-- cause a temporary to be created.
begin
-- Optimization: if the returned value is returned again, then no need
-- to copy/readjust/finalize, we can just pass the value through (see
-- Expand_N_Simple_Return_Statement), and thus no attachment is needed.
-- Expand_Simple_Function_Return), and thus no attachment is needed.
-- Note that simple return statements are distributed into conditional
-- expressions, but we may be invoked before this distribution is done.
@@ -6221,6 +6247,14 @@ package body Exp_Ch6 is
-- returns, since they get eliminated anyway later on. Spec_Id denotes
-- the corresponding spec of the subprogram body.
procedure Prepend_Constructor_Procedure_Prologue
(Spec_Id : Entity_Id; Body_Id : Entity_Id; L : List_Id);
-- If N is the body of a constructor procedure (that is, a procedure
-- named in a Constructor aspect specification for the type of the
-- procedure's first parameter), then prepend and analyze the
-- associated initialization code for that parameter.
-- This has nothing to do with CPP constructors.
----------------
-- Add_Return --
----------------
@@ -6294,6 +6328,304 @@ package body Exp_Ch6 is
end if;
end Add_Return;
--------------------------------------------
-- Prepend_Constructor_Procedure_Prologue --
--------------------------------------------
procedure Prepend_Constructor_Procedure_Prologue
(Spec_Id : Entity_Id; Body_Id : Entity_Id; L : List_Id)
is
function First_Param_Type return Entity_Id is
(Implementation_Base_Type (Etype (First_Formal (Spec_Id))));
Is_Constructor_Procedure : constant Boolean :=
Nkind (Specification (N)) = N_Procedure_Specification
and then Present (First_Formal (Spec_Id))
and then Present (Constructor_Name (First_Param_Type))
and then Chars (Spec_Id) = Chars (Constructor_Name
(First_Param_Type))
and then Ekind (First_Formal (Spec_Id)) = E_In_Out_Parameter
and then Scope (Spec_Id) = Scope (First_Param_Type);
begin
if not Is_Constructor_Procedure then
return; -- the usual case
end if;
Push_Scope (Spec_Id);
-- Initialize the first parameter.
-- First_Param_Type is a record type (tagged or untagged) or
-- a type extension. If it is a type extension, then we begin by
-- calling the appropriate constructor procedure for the _parent
-- part. In the absence of a Super aspect specification, the
-- "appropriate" constructor is the one that takes only a single
-- parameter (the object being initialized). Additional actual
-- parameters for the constructor call may be provided via a
-- Super aspect specification, in which case a different
-- constructor procedure will be invoked.
--
-- For each remaining component we first check to see if it
-- is mentioned in the Initialize aspect specification (if any) for
-- Body_Id. If so, then evaluate the expression given for that
-- component in the aspect specification and assign it to the
-- given component of the first parameter. If not, and if an
-- explicit default initial value is provided for the given component
-- in the type declaration, then do the same thing with that
-- expression instead. Otherwise perform normal default
-- initialization for the component - invoke the init proc for the
-- component's type if one exists, and otherwise do nothing.
-- We do not perform tag initialization here. That is dealt with
-- elsewhere. The init proc for a tagged type is
-- passed an extra parameter indicating whether to perform
-- tag initialization.
-- In the case of a type (tagged or untagged) that is not
-- an extension, we could just generate a single assignment,
-- taking the RHS from the Initialize aspect value (which is an
-- N_Aggregate node). But that gets complicated in the case of
-- an extension, so we handle all cases one component at a time.
declare
Initialize_Aspect : constant Node_Id :=
Find_Aspect (Body_Id, Aspect_Initialize);
First_Initialize_Comp_Assoc : constant Node_Id :=
(if Present (Initialize_Aspect)
then First (Component_Associations
(Expression (Initialize_Aspect)))
else Empty);
Component : Entity_Id := First_Entity (First_Param_Type);
Init_List : constant List_Id := New_List;
function Init_Expression_If_Any (Component : Entity_Id)
return Node_Id;
-- If the given component is mentioned in the Initialize
-- aspect for the constructor procedure, then return the
-- initial value expression specified there.
-- Otherwise, if the component declaration includes an
-- initial value expression, then return that expression.
-- Otherwise, return Empty.
function Make_Init_Proc_Call (Component : Entity_Id;
Component_Name : Node_Id)
return Node_Id;
-- Builds and returns a call to the init proc for the type of
-- the component in order to initialize the given component.
-- The init proc must exist.
function Make_Parent_Constructor_Call (Parent_Type : Entity_Id)
return Node_Id;
-- Builds and returns a call to the appropriate constructor
-- procedure of the parent type.
-- This function is called only in the case of a
-- Constructor procedure for a type extension.
----------------------------
-- Init_Expression_If_Any --
----------------------------
function Init_Expression_If_Any (Component : Entity_Id)
return Node_Id
is
Initialize_Comp_Assoc : Node_Id := First_Initialize_Comp_Assoc;
Choice : Node_Id;
-- ??? Technically, this is quadratic (linear search called
-- a linear number of times). When/if we see performance
-- problems with hundreds of components mentioned in one
-- Initialize aspect specification, we can revisit this.
begin
while Present (Initialize_Comp_Assoc) loop
Choice := First (Choices (Initialize_Comp_Assoc));
while Present (Choice) loop
if Nkind (Choice) = N_Identifier
and then Chars (Choice) = Chars (Component)
then
return Expression (Initialize_Comp_Assoc);
end if;
Next (Choice);
end loop;
Next (Initialize_Comp_Assoc);
end loop;
if Present (Expression (Parent (Component))) then
return Expression (Parent (Component));
end if;
return Empty;
end Init_Expression_If_Any;
-------------------------
-- Make_Init_Proc_Call --
-------------------------
function Make_Init_Proc_Call (Component : Entity_Id;
Component_Name : Node_Id)
return Node_Id
is
Params : constant List_Id := New_List (Component_Name);
Init_Proc : constant Entity_Id :=
Base_Init_Proc (Etype (Component));
begin
if Is_Tagged_Type (Etype (Component)) then
Append (Make_Mode_Literal (Loc, Full_Init), Params);
end if;
return Init_Proc_Call : constant Node_Id :=
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Init_Proc, Loc),
Parameter_Associations => Params)
do
pragma Assert (Check_Number_Of_Actuals
(Subp_Call => Init_Proc_Call,
Subp_Id => Init_Proc));
end return;
end Make_Init_Proc_Call;
----------------------------------
-- Make_Parent_Constructor_Call --
----------------------------------
function Make_Parent_Constructor_Call (Parent_Type : Entity_Id)
return Node_Id
is
Actual_Parameters : List_Id := No_List;
Super_Aspect : constant Node_Id :=
Find_Aspect (Body_Id, Aspect_Super);
-- Do not confuse the Super aspect with the Super attribute.
-- Both are referenced here, but they are not related as
-- closely as some aspect/attribute homonym pairs are.
-- The attribute takes an object as a prefix. The aspect
-- can be specified for the body of a constructor procedure.
begin
if Present (Super_Aspect) then
declare
Super_Expr : constant Node_Id :=
Expression (Super_Aspect);
Expr : Node_Id;
begin
if Nkind (Super_Expr) /= N_Aggregate then
Expr := New_Copy_Tree (Super_Expr);
Set_Paren_Count (Expr, 0);
Actual_Parameters := New_List (Expr);
else
-- Interpret this "aggregate" as a list of
-- actual parameter expressions.
Actual_Parameters := New_List;
Expr := First (Expressions (Super_Expr));
while Present (Expr) loop
Append (New_Copy_Tree (Expr), Actual_Parameters);
Next (Expr);
end loop;
end if;
end;
end if;
-- Build a prefixed-notation call
declare
Proc_Name : constant Node_Id :=
Make_Selected_Component (Loc,
Prefix =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of
(First_Formal (Spec_Id), Loc),
Attribute_Name => Name_Super),
Selector_Name =>
Make_Identifier (Loc,
Chars (Constructor_Name (Parent_Type))));
begin
Set_Is_Prefixed_Call (Proc_Name);
return Make_Procedure_Call_Statement (Loc,
Name => Proc_Name,
Parameter_Associations => Actual_Parameters);
end;
end Make_Parent_Constructor_Call;
begin
while Present (Component) loop
pragma Assert (Ekind (Component) = E_Component);
if Chars (Component) = Name_uTag then
null;
elsif Chars (Component) = Name_uParent then
-- ??? Here is where we should be looking for a
-- Super aspect specification in order to call the
-- right constructor with the right parameters
-- (as opposed to unconditionally calling the
-- single-parameter constructor).
Append_To (Init_List, Make_Parent_Constructor_Call
(Parent_Type => Etype (Component)));
else
declare
Maybe_Init_Exp : constant Node_Id :=
Init_Expression_If_Any (Component);
function Make_Component_Name return Node_Id is
(Make_Selected_Component (Loc,
Prefix =>
New_Occurrence_Of (First_Formal (Spec_Id), Loc),
Selector_Name =>
Make_Identifier (Loc, Chars (Component))));
begin
-- Handle case where initial value for this component
-- is specified either in an Initialize aspect
-- specification or as part of the component declaration.
if Present (Maybe_Init_Exp) then
-- ??? Should reorganize things so that
-- procedure Build_Assignment in exp_ch3.adb
-- (which is currently declared inside of
-- Build_Record_Init_Proc) can be called from here.
-- That procedure handles some corner cases
-- that are not properly handled here (e.g.,
-- mapping current instance references to the
-- appropriate formal parameter).
if Is_Tagged_Type (Etype (Component)) then
Append_To (Init_List,
Make_Tag_Assignment_From_Type (Loc,
Target => Make_Component_Name,
Typ => Etype (Component)));
end if;
Append_To (Init_List,
Make_Assignment_Statement (Loc,
Name => Make_Component_Name,
Expression => New_Copy_Tree
(Maybe_Init_Exp,
New_Scope => Body_Id)));
-- Handle case where component's type has an init proc
elsif Has_Non_Null_Base_Init_Proc (Etype (Component)) then
Append_To (Init_List,
Make_Init_Proc_Call (
Component => Component,
Component_Name => Make_Component_Name));
else
pragma Assert (not Is_Tagged_Type (Etype (Component)));
end if;
end;
end if;
Next_Entity (Component);
end loop;
Insert_List_Before_And_Analyze (First (L), Init_List);
end;
Pop_Scope;
end Prepend_Constructor_Procedure_Prologue;
-- Local variables
Except_H : Node_Id;
@@ -6526,6 +6858,12 @@ package body Exp_Ch6 is
Detect_Infinite_Recursion (N, Spec_Id);
end if;
-- If the subprogram is a constructor procedure then prepend
-- and analyze initialization code.
Prepend_Constructor_Procedure_Prologue
(Spec_Id => Spec_Id, Body_Id => Body_Id, L => L);
-- Set to encode entity names in package body before gigi is called
Qualify_Entity_Names (N);
@@ -7255,7 +7593,7 @@ package body Exp_Ch6 is
elsif (not Needs_Secondary_Stack (R_Type)
and then not Is_Secondary_Stack_Thunk (Scope_Id))
or else Is_Ignored_Ghost_Entity (Scope_Id)
or else Is_Ignored_Ghost_Entity_In_Codegen (Scope_Id)
then
-- Mutable records with variable-length components are not returned
-- on the sec-stack, so we need to make sure that the back end will
@@ -8089,7 +8427,7 @@ package body Exp_Ch6 is
Get_Class_Wide_Pragma (Id, Pragma_Precondition);
begin
if No (Prag) or else Is_Ignored (Prag) then
if No (Prag) or else Is_Ignored_In_Codegen (Prag) then
return;
end if;
@@ -10255,11 +10593,18 @@ package body Exp_Ch6 is
begin
pragma Assert (Check_BIP_Actuals (Call_Node, Subp));
-- Build-in-place function calls return their result by
-- reference.
-- Do not attempt to verify the return type in CodePeer_Mode
-- as CodePeer_Mode is missing some expansion code that
-- results in trees that would be considered malformed for
-- GCC but aren't for GNAT2SCIL.
pragma Assert (not Is_Build_In_Place_Function (Subp)
or else Returns_By_Ref (Subp));
if not CodePeer_Mode then
-- Build-in-place function calls return their result by
-- reference.
pragma Assert (not Is_Build_In_Place_Function (Subp)
or else Returns_By_Ref (Subp));
end if;
end;
-- Skip generic bodies
+6 -6
View File
@@ -2429,7 +2429,7 @@ package body Exp_Ch7 is
-- Do not inspect an ignored Ghost package body because all
-- code found within will not appear in the final tree.
if Is_Ignored_Ghost_Entity (Defining_Entity (Decl)) then
if Is_Ignored_Ghost_Entity_In_Codegen (Defining_Entity (Decl)) then
null;
elsif Ekind (Corresponding_Spec (Decl)) /= E_Generic_Package then
@@ -2507,7 +2507,7 @@ package body Exp_Ch7 is
-- Ignored Ghost types do not need any cleanup actions because
-- they will not appear in the final tree.
if Is_Ignored_Ghost_Entity (Typ) then
if Is_Ignored_Ghost_Entity_In_Codegen (Typ) then
null;
elsif Is_Tagged_Type (Typ)
@@ -2553,7 +2553,7 @@ package body Exp_Ch7 is
-- Ignored Ghost objects do not need any cleanup actions
-- because they will not appear in the final tree.
elsif Is_Ignored_Ghost_Entity (Obj_Id) then
elsif Is_Ignored_Ghost_Entity_In_Codegen (Obj_Id) then
null;
-- Conversely, if one of the above cases created a Master_Node,
@@ -2655,7 +2655,7 @@ package body Exp_Ch7 is
-- Freeze nodes for ignored Ghost types do not need cleanup
-- actions because they will never appear in the final tree.
if Is_Ignored_Ghost_Entity (Typ) then
if Is_Ignored_Ghost_Entity_In_Codegen (Typ) then
null;
elsif (Is_Access_Object_Type (Typ)
@@ -2680,7 +2680,7 @@ package body Exp_Ch7 is
-- Do not inspect an ignored Ghost package because all code
-- found within will not appear in the final tree.
if Is_Ignored_Ghost_Entity (Pack_Id) then
if Is_Ignored_Ghost_Entity_In_Codegen (Pack_Id) then
null;
elsif Ekind (Pack_Id) /= E_Generic_Package then
@@ -5281,7 +5281,7 @@ package body Exp_Ch7 is
-- Ignored Ghost objects do not need any cleanup actions because
-- they will not appear in the final tree.
if Is_Ignored_Ghost_Entity (Obj_Id) then
if Is_Ignored_Ghost_Entity_In_Codegen (Obj_Id) then
return;
end if;
+1 -1
View File
@@ -4686,7 +4686,7 @@ package body Exp_Ch9 is
-- by a missing activation chain entity; also skip generating it when
-- it is a ghost entity.
if No (Chain) or else Is_Ignored_Ghost_Entity (Chain) then
if No (Chain) or else Is_Ignored_Ghost_Entity_In_Codegen (Chain) then
return;
-- The availability of the activation chain entity does not ensure
+4 -5
View File
@@ -971,7 +971,7 @@ package body Exp_Disp is
pragma Assert (Is_Frozen (Typ));
if Extra_Formals_Known (Subp) then
Create_Extra_Formals (Subp_Typ);
Create_Extra_Formals (Subp_Typ, Related_Nod => Call_Node);
-- Extra formals were previously deferred
@@ -4593,8 +4593,7 @@ package body Exp_Disp is
Name_TSD : constant Name_Id :=
New_External_Name (Tname, 'B', Suffix_Index => -1);
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
AI : Elmt_Id;
@@ -6057,7 +6056,7 @@ package body Exp_Disp is
-- Skip ignored Ghost subprograms as those will be removed
-- from the executable.
and then not Is_Ignored_Ghost_Entity (E)
and then not Is_Ignored_Ghost_Entity_In_Codegen (E)
then
pragma Assert
(UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
@@ -6526,7 +6525,7 @@ package body Exp_Disp is
Register_CG_Node (Typ);
<<Leave>>
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
return Result;
end Make_DT;
+74 -31
View File
@@ -134,7 +134,9 @@ package body Exp_Prag is
-- Analyze_xxx_In_Decl_Part). The second part of the analysis will
-- not happen if the pragma is rewritten.
if Assertion_Expression_Pragma (Prag_Id) and then Is_Ignored (N) then
if Assertion_Expression_Pragma (Prag_Id)
and then Is_Ignored_In_Codegen (N)
then
return;
-- Rewrite the pragma into a null statement when it is ignored using
@@ -143,7 +145,7 @@ package body Exp_Prag is
elsif Should_Ignore_Pragma_Sem (N)
or else (Prag_Id = Pragma_Default_Scalar_Storage_Order
and then Ignore_Rep_Clauses)
and then Ignore_Rep_Clauses)
then
Rewrite (N, Make_Null_Statement (Sloc (N)));
return;
@@ -189,8 +191,7 @@ package body Exp_Prag is
when Pragma_Suppress_Initialization =>
Expand_Pragma_Suppress_Initialization (N);
-- All other pragmas need no expander action (includes
-- Unknown_Pragma).
-- All other pragmas need no expander action
when others => null;
end case;
@@ -480,7 +481,7 @@ package body Exp_Prag is
begin
-- Nothing to do if pragma is ignored
if Is_Ignored (N) then
if Is_Ignored_In_Codegen (N) then
return;
end if;
@@ -1518,7 +1519,7 @@ package body Exp_Prag is
is
Cond : Node_Id;
Error : Node_Id;
Str : String_Id;
begin
-- Generate:
-- Flag and then not Conseq
@@ -1538,12 +1539,17 @@ package body Exp_Prag is
Store_String_Chars ("failed contract case at ");
Store_String_Chars (Build_Location_String (Sloc (Conseq)));
-- Store the string value as the call to RTE can cause a new unit to
-- be loaded which causes new strings to be created.
Str := End_String;
Error :=
Make_Procedure_Call_Statement (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Raise_Assert_Failure), Loc),
Parameter_Associations => New_List (
Make_String_Literal (Loc, End_String)));
Make_String_Literal (Loc, Str)));
if No (Checks) then
Checks :=
@@ -1837,7 +1843,7 @@ package body Exp_Prag is
-- Do nothing if pragma is not enabled. If pragma is disabled, it has
-- already been rewritten as a Null statement.
if Is_Ignored (CCs) then
if Is_Ignored_In_Codegen (CCs) then
return;
-- Guard against malformed contract cases
@@ -2514,6 +2520,7 @@ package body Exp_Prag is
Call : Node_Id;
Call_List : List_Id;
Call_Loc : Source_Ptr;
Check_Prag : Node_Id;
Expr : Node_Id;
Loc : Source_Ptr;
Proc_Body : Node_Id;
@@ -2538,7 +2545,7 @@ package body Exp_Prag is
-- Nothing to do when the pragma is ignored because its semantics are
-- suppressed.
if Is_Ignored (IC_Prag) then
if Is_Ignored_In_Codegen (IC_Prag) then
return;
-- Nothing to do when the pragma or its argument are illegal because
@@ -2602,6 +2609,20 @@ package body Exp_Prag is
-- pragma Check (Initial_Condition, <Expr>);
-- end <Pack_Id>Initial_Condition;
Check_Prag :=
Make_Pragma
(Loc,
Chars => Name_Check,
Pragma_Argument_Associations =>
New_List
(Make_Pragma_Argument_Association
(Loc,
Expression =>
Make_Identifier (Loc, Name_Initial_Condition)),
Make_Pragma_Argument_Association
(Loc, Expression => New_Copy_Tree (Expr))));
Copy_Assertion_Policy_Attributes (Check_Prag, IC_Prag);
Proc_Body :=
Make_Subprogram_Body (Loc,
Specification =>
@@ -2609,15 +2630,7 @@ package body Exp_Prag is
Declarations => Empty_List,
Handled_Statement_Sequence =>
Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List (
Make_Pragma (Loc,
Chars => Name_Check,
Pragma_Argument_Associations => New_List (
Make_Pragma_Argument_Association (Loc,
Expression =>
Make_Identifier (Loc, Name_Initial_Condition)),
Make_Pragma_Argument_Association (Loc,
Expression => New_Copy_Tree (Expr)))))));
Statements => New_List (Check_Prag)));
Append_To (Body_List, Proc_Body);
@@ -2941,6 +2954,7 @@ package body Exp_Prag is
Typ => Expr_Typ,
Curr_Val => New_Occurrence_Of (Curr_Id, Loc),
Old_Val => New_Occurrence_Of (Old_Id, Loc)))));
Copy_Assertion_Policy_Attributes (Prag, N);
-- Generate:
-- if Curr /= Old then
@@ -3001,7 +3015,7 @@ package body Exp_Prag is
-- Also do this in CodePeer mode, because the expanded code is too
-- complicated for CodePeer to analyse.
if Is_Ignored (N)
if Is_Ignored_In_Codegen (N)
or else Chars (Last_Var) = Name_Structural
or else CodePeer_Mode
then
@@ -3219,6 +3233,11 @@ package body Exp_Prag is
-- Prev_Decl and is stored in this parameter for a next call to this
-- routine. Is_Last is True when there are no more variants to process.
function Variants_Function_Name (Prag : Node_Id) return Name_Id;
-- The name of the variants function is either
-- * _variants: if no assertion level was associated with the pragma.
-- * _variants_<Assertion_Level> otherwise.
----------------------
-- Formal_Param_Map --
----------------------
@@ -3262,11 +3281,11 @@ package body Exp_Prag is
Expr_Typ : constant Entity_Id := Etype (Expr);
Loc : constant Source_Ptr := Sloc (Expr);
Old_Id : Entity_Id;
Old_Decl : Node_Id;
Curr_Id : Entity_Id;
Curr_Decl : Node_Id;
Prag : Node_Id;
Old_Id : Entity_Id;
Old_Decl : Node_Id;
Curr_Id : Entity_Id;
Curr_Decl : Node_Id;
Check_Prag : Node_Id;
begin
-- Create temporaries that store the old values of the associated
@@ -3306,7 +3325,7 @@ package body Exp_Prag is
-- Generate:
-- pragma Check (Variant, Curr <|> Old);
Prag :=
Check_Prag :=
Make_Pragma (Loc,
Chars => Name_Check,
Pragma_Argument_Associations => New_List (
@@ -3321,6 +3340,7 @@ package body Exp_Prag is
Typ => Expr_Typ,
Curr_Val => New_Occurrence_Of (Curr_Id, Loc),
Old_Val => New_Occurrence_Of (Old_Id, Loc)))));
Copy_Assertion_Policy_Attributes (Check_Prag, Prag);
-- Generate:
-- if Curr /= Old then
@@ -3333,7 +3353,7 @@ package body Exp_Prag is
-- pragma.
if Is_Last then
If_Stmt := Prag;
If_Stmt := Check_Prag;
else
If_Stmt :=
Make_If_Statement (Loc,
@@ -3341,7 +3361,7 @@ package body Exp_Prag is
Make_Op_Ne (Loc,
Left_Opnd => New_Occurrence_Of (Curr_Id, Loc),
Right_Opnd => New_Occurrence_Of (Old_Id, Loc)),
Then_Statements => New_List (Prag));
Then_Statements => New_List (Check_Prag));
end if;
-- Generate:
@@ -3350,7 +3370,7 @@ package body Exp_Prag is
-- end if;
elsif Is_Last then
Set_Else_Statements (If_Stmt, New_List (Prag));
Set_Else_Statements (If_Stmt, New_List (Check_Prag));
-- Generate:
-- elsif Curr /= Old then
@@ -3367,10 +3387,30 @@ package body Exp_Prag is
Make_Op_Ne (Loc,
Left_Opnd => New_Occurrence_Of (Curr_Id, Loc),
Right_Opnd => New_Occurrence_Of (Old_Id, Loc)),
Then_Statements => New_List (Prag)));
Then_Statements => New_List (Check_Prag)));
end if;
end Process_Variant;
----------------------------
-- Variants_Function_Name --
----------------------------
function Variants_Function_Name (Prag : Node_Id) return Name_Id is
begin
if Present (Pragma_Ghost_Assertion_Level (Prag))
and then Pragma_Ghost_Assertion_Level (Prag)
/= Standard_Level_Default
then
Get_Name_String (Name_uVariants);
Add_Str_To_Name_Buffer ("_");
Get_Name_String_And_Append
(Chars (Pragma_Ghost_Assertion_Level (Prag)));
return Name_Enter;
else
return Name_uVariants;
end if;
end Variants_Function_Name;
-- Local variables
Loc : constant Source_Ptr := Sloc (Prag);
@@ -3384,6 +3424,7 @@ package body Exp_Prag is
Proc_Bod : Node_Id;
Proc_Decl : Node_Id;
Proc_Id : Entity_Id;
Proc_Nam : Name_Id;
Proc_Spec : Node_Id;
Variant : Node_Id;
@@ -3391,7 +3432,7 @@ package body Exp_Prag is
-- Do nothing if pragma is not present or is disabled.
-- Also ignore structural variants for execution.
if Is_Ignored (Prag)
if Is_Ignored_In_Codegen (Prag)
or else Chars (Nlists.Last (Choices (Last_Variant))) = Name_Structural
then
return;
@@ -3409,7 +3450,9 @@ package body Exp_Prag is
-- variant expressions captured at the start of subprogram with their
-- values at the recursive call of the subprogram.
Proc_Id := Make_Defining_Identifier (Loc, Name_uVariants);
Proc_Nam := Variants_Function_Name (Prag);
Proc_Id := Make_Defining_Identifier (Loc, Proc_Nam);
Proc_Spec :=
Make_Procedure_Specification
+3
View File
@@ -363,6 +363,9 @@ package body Exp_Put_Image is
Lib_RE := RE_Put_Image_Access_Prot_Subp;
elsif Is_Access_Subprogram_Type (Base_Type (U_Type)) then
Lib_RE := RE_Put_Image_Access_Subp;
elsif Is_Extended_Access_Type (Base_Type (U_Type)) then
pragma Assert (No (P_Size));
Lib_RE := RE_Put_Image_Extended_Access_Pointer;
elsif P_Size = System_Address_Size then
Lib_RE := RE_Put_Image_Thin_Pointer;
else
+2 -3
View File
@@ -1128,8 +1128,7 @@ package body Exp_SPARK is
Wrapper_Decl_List : List_Id;
Wrapper_Body_List : List_Id := No_List;
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
begin
@@ -1253,7 +1252,7 @@ package body Exp_SPARK is
end if;
end if;
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
end SPARK_Freeze_Type;
end Exp_SPARK;
+153 -294
View File
@@ -33,7 +33,6 @@ with Mutably_Tagged; use Mutably_Tagged;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Rtsfind; use Rtsfind;
with Sem_Aux; use Sem_Aux;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
@@ -43,7 +42,6 @@ with Snames; use Snames;
with Stand; use Stand;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
package body Exp_Strm is
@@ -82,13 +80,13 @@ package body Exp_Strm is
-- Decls and Stms are the declarations and statements for the body and
-- The parameter Fnam is the name of the constructed function.
function Has_Stream_Standard_Rep (U_Type : Entity_Id) return Boolean;
-- This function is used to test the type U_Type, to determine if it has
-- a standard representation from a streaming point of view. Standard means
-- that it has a standard representation (e.g. no enumeration rep clause),
-- and the size of the root type is the same as the streaming size (which
-- is defined as value specified by a Stream_Size clause if present, or
-- the Esize of U_Type if not).
function Is_Stream_Standard_Rep
(U_Type : Entity_Id; S_Size : Uint) return Boolean;
-- This function is used to test the type U_Type, to determine whether it
-- would have a standard representation from a streaming point of view if
-- its Stream_Size attribute was set to S_Size. Standard means that it has
-- a standard representation (e.g. no enumeration rep clause), and the size
-- of the root type is the same as the stream size.
function Make_Stream_Subprogram_Name
(Loc : Source_Ptr;
@@ -436,51 +434,39 @@ package body Exp_Strm is
Build_Array_Read_Write_Procedure (Typ, Decl, Pnam, Name_Write);
end Build_Array_Write_Procedure;
---------------------------------
-- Build_Elementary_Input_Call --
---------------------------------
function Get_Primitives
(P_Type : Entity_Id; P_Size : Uint) return Primitive_Result
is
function Build_Elementary_Input_Call (N : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (N);
P_Type : constant Entity_Id := Entity (Prefix (N));
U_Type : constant Entity_Id := Underlying_Type (P_Type);
Rt_Type : constant Entity_Id := Root_Type (U_Type);
FST : constant Entity_Id := First_Subtype (U_Type);
Strm : constant Node_Id := First (Expressions (N));
Targ : constant Node_Id := Next (Strm);
P_Size : constant Uint := Get_Stream_Size (FST);
Res : Node_Id;
Lib_RE : RE_Id;
function Prims (Input, Write : RE_Id) return Primitive_Result;
function Prims (Input, Write : RE_Id) return Primitive_Result is
begin
return (Primitives, 0, Input, Write);
end Prims;
function PSizes (L : Sizes) return Primitive_Result;
function PSizes (L : Sizes) return Primitive_Result is
begin
return (Possible_Sizes, L'Length, L);
end PSizes;
U_Type : constant Entity_Id := Underlying_Type (P_Type);
FST : constant Entity_Id := First_Subtype (U_Type);
Rt_Type : constant Entity_Id := Root_Type (U_Type);
Rep_Is_Standard : constant Boolean :=
Known_RM_Size (U_Type)
and then Is_Stream_Standard_Rep (U_Type, P_Size);
begin
-- Check first for Boolean and Character. These are enumeration types,
-- but we treat them specially, since they may require special handling
-- in the transfer protocol. However, this special handling only applies
-- if they have standard representation, otherwise they are treated like
-- any other enumeration type.
if Rt_Type = Standard_Boolean
and then Has_Stream_Standard_Rep (U_Type)
if Rt_Type = Standard_Boolean and then Rep_Is_Standard then
return Prims (RE_I_B, RE_W_B);
elsif Rt_Type = Standard_Character and then Rep_Is_Standard then
return Prims (RE_I_C, RE_W_C);
elsif Rt_Type = Standard_Wide_Character and then Rep_Is_Standard then
return Prims (RE_I_WC, RE_W_WC);
elsif Rt_Type = Standard_Wide_Wide_Character and then Rep_Is_Standard
then
Lib_RE := RE_I_B;
elsif Rt_Type = Standard_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_I_C;
elsif Rt_Type = Standard_Wide_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_I_WC;
elsif Rt_Type = Standard_Wide_Wide_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_I_WWC;
-- Floating point types
return Prims (RE_I_WWC, RE_W_WWC);
elsif Is_Floating_Point_Type (U_Type) then
-- Question: should we use P_Size or Rt_Type to distinguish between
@@ -500,23 +486,30 @@ package body Exp_Strm is
-- To deal with these two requirements we add the special checks
-- on equal sizes and use the root type to distinguish.
if P_Size <= Standard_Short_Float_Size
if P_Size = Standard_Short_Float_Size
and then (Standard_Short_Float_Size /= Standard_Float_Size
or else Rt_Type = Standard_Short_Float)
then
Lib_RE := RE_I_SF;
return Prims (RE_I_SF, RE_W_SF);
elsif P_Size <= Standard_Float_Size then
Lib_RE := RE_I_F;
elsif P_Size = Standard_Float_Size then
return Prims (RE_I_F, RE_W_F);
elsif P_Size <= Standard_Long_Float_Size
elsif P_Size = Standard_Long_Float_Size
and then (Standard_Long_Float_Size /= Standard_Long_Long_Float_Size
or else Rt_Type = Standard_Long_Float)
or else Rt_Type = Standard_Long_Float)
then
Lib_RE := RE_I_LF;
return Prims (RE_I_LF, RE_W_LF);
elsif P_Size = Standard_Long_Long_Float_Size then
return Prims (RE_I_LLF, RE_W_LLF);
else
Lib_RE := RE_I_LLF;
return
PSizes
((Standard_Short_Float_Size,
Standard_Float_Size,
Standard_Long_Float_Size,
Standard_Long_Long_Float_Size));
end if;
-- Signed integer types. Also includes signed fixed-point types and
@@ -548,35 +541,42 @@ package body Exp_Strm is
-- The following set of tests gets repeated many times, we should
-- have an abstraction defined ???
and then
(Is_Fixed_Point_Type (U_Type)
or else
Is_Enumeration_Type (U_Type)
or else
(Is_Signed_Integer_Type (U_Type)
and then not Has_Biased_Representation (FST)))
and then (Is_Fixed_Point_Type (U_Type)
or else Is_Enumeration_Type (U_Type)
or else (Is_Signed_Integer_Type (U_Type)
and then not Has_Biased_Representation (FST)))
then
if P_Size <= Standard_Short_Short_Integer_Size then
Lib_RE := RE_I_SSI;
if P_Size = Standard_Short_Short_Integer_Size then
return Prims (RE_I_SSI, RE_W_SSI);
elsif P_Size <= Standard_Short_Integer_Size then
Lib_RE := RE_I_SI;
elsif P_Size = Standard_Short_Integer_Size then
return Prims (RE_I_SI, RE_W_SI);
elsif P_Size = 24 then
Lib_RE := RE_I_I24;
return Prims (RE_I_I24, RE_W_I24);
elsif P_Size <= Standard_Integer_Size then
Lib_RE := RE_I_I;
elsif P_Size = Standard_Integer_Size then
return Prims (RE_I_I, RE_W_I);
elsif P_Size <= Standard_Long_Integer_Size then
Lib_RE := RE_I_LI;
elsif P_Size = Standard_Long_Integer_Size then
return Prims (RE_I_LI, RE_W_LI);
elsif P_Size <= Standard_Long_Long_Integer_Size then
Lib_RE := RE_I_LLI;
elsif P_Size = Standard_Long_Long_Integer_Size then
return Prims (RE_I_LLI, RE_W_LLI);
elsif P_Size = Standard_Long_Long_Long_Integer_Size then
return Prims (RE_I_LLLI, RE_W_LLLI);
else
Lib_RE := RE_I_LLLI;
return
PSizes
((Standard_Short_Short_Integer_Size,
Standard_Short_Integer_Size,
24,
Standard_Integer_Size,
Standard_Long_Integer_Size,
Standard_Long_Long_Integer_Size,
Standard_Long_Long_Long_Integer_Size));
end if;
-- Unsigned integer types, also includes unsigned fixed-point types
@@ -586,41 +586,74 @@ package body Exp_Strm is
-- Also includes signed integer types that are unsigned in the sense
-- that they do not include negative numbers. See above for details.
elsif Is_Modular_Integer_Type (U_Type)
or else Is_Fixed_Point_Type (U_Type)
or else Is_Enumeration_Type (U_Type)
elsif Is_Modular_Integer_Type (U_Type)
or else Is_Fixed_Point_Type (U_Type)
or else Is_Enumeration_Type (U_Type)
or else Is_Signed_Integer_Type (U_Type)
then
if P_Size <= Standard_Short_Short_Integer_Size then
Lib_RE := RE_I_SSU;
if P_Size = Standard_Short_Short_Integer_Size then
return Prims (RE_I_SSU, RE_W_SSU);
elsif P_Size <= Standard_Short_Integer_Size then
Lib_RE := RE_I_SU;
elsif P_Size = Standard_Short_Integer_Size then
return Prims (RE_I_SU, RE_W_SU);
elsif P_Size = 24 then
Lib_RE := RE_I_U24;
return Prims (RE_I_U24, RE_W_U24);
elsif P_Size <= Standard_Integer_Size then
Lib_RE := RE_I_U;
elsif P_Size = Standard_Integer_Size then
return Prims (RE_I_U, RE_W_U);
elsif P_Size <= Standard_Long_Integer_Size then
Lib_RE := RE_I_LU;
elsif P_Size = Standard_Long_Integer_Size then
return Prims (RE_I_LU, RE_W_LU);
elsif P_Size <= Standard_Long_Long_Integer_Size then
Lib_RE := RE_I_LLU;
elsif P_Size = Standard_Long_Long_Integer_Size then
return Prims (RE_I_LLU, RE_W_LLU);
elsif P_Size = Standard_Long_Long_Long_Integer_Size then
return Prims (RE_I_LLLU, RE_W_LLLU);
else
Lib_RE := RE_I_LLLU;
return
PSizes
((Standard_Short_Short_Integer_Size,
Standard_Short_Integer_Size,
24,
Standard_Integer_Size,
Standard_Long_Integer_Size,
Standard_Long_Long_Integer_Size,
Standard_Long_Long_Long_Integer_Size));
end if;
else pragma Assert (Is_Access_Type (U_Type));
if Present (P_Size) and then P_Size > System_Address_Size then
Lib_RE := RE_I_AD;
return Prims (RE_I_AD, RE_W_AD);
else
Lib_RE := RE_I_AS;
return Prims (RE_I_AS, RE_W_AS);
end if;
end if;
end Get_Primitives;
---------------------------------
-- Build_Elementary_Input_Call --
---------------------------------
function Build_Elementary_Input_Call (N : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (N);
P_Type : constant Entity_Id := Entity (Prefix (N));
U_Type : constant Entity_Id := Underlying_Type (P_Type);
FST : constant Entity_Id := First_Subtype (U_Type);
Strm : constant Node_Id := First (Expressions (N));
Targ : constant Node_Id := Next (Strm);
P_Size : constant Uint := Get_Stream_Size (FST);
Res : Node_Id;
Prims : constant Primitive_Result := Get_Primitives (P_Type, P_Size);
Lib_RE : constant RE_Id :=
(case Prims.S is
when Primitives => Prims.Input,
when others => raise Program_Error);
begin
-- Call the function, and do an unchecked conversion of the result
-- to the actual type of the prefix. If the target is a discriminant,
-- and we are in the body of the default implementation of a 'Read
@@ -679,191 +712,22 @@ package body Exp_Strm is
function Build_Elementary_Write_Call (N : Node_Id) return Node_Id is
Loc : constant Source_Ptr := Sloc (N);
P_Type : constant Entity_Id := Entity (Prefix (N));
U_Type : constant Entity_Id := Underlying_Type (P_Type);
Rt_Type : constant Entity_Id := Root_Type (U_Type);
FST : constant Entity_Id := First_Subtype (U_Type);
Strm : constant Node_Id := First (Expressions (N));
Item : constant Node_Id := Next (Strm);
P_Size : Uint;
Lib_RE : RE_Id;
P_Type : constant Entity_Id := Entity (Prefix (N));
U_Type : constant Entity_Id := Underlying_Type (P_Type);
FST : constant Entity_Id := First_Subtype (U_Type);
Strm : constant Node_Id := First (Expressions (N));
Item : constant Node_Id := Next (Strm);
P_Size : constant Uint := Get_Stream_Size (FST);
Libent : Entity_Id;
Prims : constant Primitive_Result := Get_Primitives (P_Type, P_Size);
Lib_RE : constant RE_Id :=
(case Prims.S is
when Primitives => Prims.Write,
when others => raise Program_Error);
begin
-- Compute the size of the stream element. This is either the size of
-- the first subtype or if given the size of the Stream_Size attribute.
if Has_Stream_Size_Clause (FST) then
P_Size := Static_Integer (Expression (Stream_Size_Clause (FST)));
else
P_Size := Esize (FST);
end if;
-- Find the routine to be called
-- Check for First Boolean and Character. These are enumeration types,
-- but we treat them specially, since they may require special handling
-- in the transfer protocol. However, this special handling only applies
-- if they have standard representation, otherwise they are treated like
-- any other enumeration type.
if Rt_Type = Standard_Boolean
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_W_B;
elsif Rt_Type = Standard_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_W_C;
elsif Rt_Type = Standard_Wide_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_W_WC;
elsif Rt_Type = Standard_Wide_Wide_Character
and then Has_Stream_Standard_Rep (U_Type)
then
Lib_RE := RE_W_WWC;
-- Floating point types
elsif Is_Floating_Point_Type (U_Type) then
-- Question: should we use P_Size or Rt_Type to distinguish between
-- possible floating point types? If a non-standard size or a stream
-- size is specified, then we should certainly use the size. But if
-- we have two types the same (notably Short_Float_Size = Float_Size
-- which is close to universally true, and Long_Long_Float_Size =
-- Long_Float_Size, true on most targets except the x86), then we
-- would really rather use the root type, so that if people want to
-- fiddle with System.Stream_Attributes to get inter-target portable
-- streams, they get the size they expect. Consider in particular the
-- case of a stream written on an x86, with 96-bit Long_Long_Float
-- being read into a non-x86 target with 64 bit Long_Long_Float. A
-- special version of System.Stream_Attributes can deal with this
-- provided the proper type is always used.
-- To deal with these two requirements we add the special checks
-- on equal sizes and use the root type to distinguish.
if P_Size <= Standard_Short_Float_Size
and then (Standard_Short_Float_Size /= Standard_Float_Size
or else Rt_Type = Standard_Short_Float)
then
Lib_RE := RE_W_SF;
elsif P_Size <= Standard_Float_Size then
Lib_RE := RE_W_F;
elsif P_Size <= Standard_Long_Float_Size
and then (Standard_Long_Float_Size /= Standard_Long_Long_Float_Size
or else Rt_Type = Standard_Long_Float)
then
Lib_RE := RE_W_LF;
else
Lib_RE := RE_W_LLF;
end if;
-- Signed integer types. Also includes signed fixed-point types and
-- signed enumeration types share this circuitry.
-- Note on signed integer types. We do not consider types as signed for
-- this purpose if they have no negative numbers, or if they have biased
-- representation. The reason is that the value in either case basically
-- represents an unsigned value.
-- For example, consider:
-- type W is range 0 .. 2**32 - 1;
-- for W'Size use 32;
-- This is a signed type, but the representation is unsigned, and may
-- be outside the range of a 32-bit signed integer, so this must be
-- treated as 32-bit unsigned.
-- Similarly, the representation is also unsigned if we have:
-- type W is range -1 .. +254;
-- for W'Size use 8;
-- forcing a biased and unsigned representation
elsif not Is_Unsigned_Type (FST)
and then
(Is_Fixed_Point_Type (U_Type)
or else
Is_Enumeration_Type (U_Type)
or else
(Is_Signed_Integer_Type (U_Type)
and then not Has_Biased_Representation (FST)))
then
if P_Size <= Standard_Short_Short_Integer_Size then
Lib_RE := RE_W_SSI;
elsif P_Size <= Standard_Short_Integer_Size then
Lib_RE := RE_W_SI;
elsif P_Size = 24 then
Lib_RE := RE_W_I24;
elsif P_Size <= Standard_Integer_Size then
Lib_RE := RE_W_I;
elsif P_Size <= Standard_Long_Integer_Size then
Lib_RE := RE_W_LI;
elsif P_Size <= Standard_Long_Long_Integer_Size then
Lib_RE := RE_W_LLI;
else
Lib_RE := RE_W_LLLI;
end if;
-- Unsigned integer types, also includes unsigned fixed-point types
-- and unsigned enumeration types (note we know they are unsigned
-- because we already tested for signed above).
-- Also includes signed integer types that are unsigned in the sense
-- that they do not include negative numbers. See above for details.
elsif Is_Modular_Integer_Type (U_Type)
or else Is_Fixed_Point_Type (U_Type)
or else Is_Enumeration_Type (U_Type)
or else Is_Signed_Integer_Type (U_Type)
then
if P_Size <= Standard_Short_Short_Integer_Size then
Lib_RE := RE_W_SSU;
elsif P_Size <= Standard_Short_Integer_Size then
Lib_RE := RE_W_SU;
elsif P_Size = 24 then
Lib_RE := RE_W_U24;
elsif P_Size <= Standard_Integer_Size then
Lib_RE := RE_W_U;
elsif P_Size <= Standard_Long_Integer_Size then
Lib_RE := RE_W_LU;
elsif P_Size <= Standard_Long_Long_Integer_Size then
Lib_RE := RE_W_LLU;
else
Lib_RE := RE_W_LLLU;
end if;
else pragma Assert (Is_Access_Type (U_Type));
if Present (P_Size) and then P_Size > System_Address_Size then
Lib_RE := RE_W_AD;
else
Lib_RE := RE_W_AS;
end if;
end if;
pragma Assert (Prims.S = Primitives);
-- Unchecked-convert parameter to the required type (i.e. the type of
-- the corresponding parameter, and call the appropriate routine.
@@ -871,12 +735,15 @@ package body Exp_Strm is
Libent := RTE (Lib_RE);
return
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Libent, Loc),
Parameter_Associations => New_List (
Relocate_Node (Strm),
Unchecked_Convert_To (Etype (Next_Formal (First_Formal (Libent))),
Relocate_Node (Item))));
Make_Procedure_Call_Statement
(Loc,
Name => New_Occurrence_Of (Libent, Loc),
Parameter_Associations =>
New_List
(Relocate_Node (Strm),
Unchecked_Convert_To
(Etype (Next_Formal (First_Formal (Libent))),
Relocate_Node (Item))));
end Build_Elementary_Write_Call;
-----------------------------------------
@@ -1766,22 +1633,15 @@ package body Exp_Strm is
-- Has_Stream_Standard_Rep --
-----------------------------
function Has_Stream_Standard_Rep (U_Type : Entity_Id) return Boolean is
Siz : Uint;
function Is_Stream_Standard_Rep
(U_Type : Entity_Id; S_Size : Uint) return Boolean is
begin
if Has_Non_Standard_Rep (U_Type) then
return False;
end if;
if Has_Stream_Size_Clause (U_Type) then
Siz := Static_Integer (Expression (Stream_Size_Clause (U_Type)));
else
Siz := Esize (First_Subtype (U_Type));
end if;
return Siz = Esize (Root_Type (U_Type));
end Has_Stream_Standard_Rep;
return S_Size = Esize (Root_Type (U_Type));
end Is_Stream_Standard_Rep;
---------------------------------
-- Make_Stream_Subprogram_Name --
@@ -1827,5 +1687,4 @@ package body Exp_Strm is
return Base_Type (E);
end if;
end Stream_Base_Type;
end Exp_Strm;
+30
View File
@@ -26,7 +26,9 @@
-- Routines to build stream subprograms for composite types
with Exp_Tss; use Exp_Tss;
with Rtsfind; use Rtsfind;
with Types; use Types;
with Uintp; use Uintp;
package Exp_Strm is
@@ -138,4 +140,32 @@ package Exp_Strm is
-- always null), and Pnam is the name of the constructed procedure.
-- Used by Exp_Dist to generate stream-oriented attributes for RACWs.
type Status is (Primitives, Possible_Sizes);
type Sizes is array (Positive range <>) of Nat;
type Primitive_Result
(S : Status;
Len : Natural)
is record
case S is
when Primitives =>
Input : RE_Id;
Write : RE_Id;
when Possible_Sizes =>
List : Sizes (1 .. Len);
end case;
end record;
--------------------
-- Get_Primitives --
--------------------
function Get_Primitives
(P_Type : Entity_Id; P_Size : Uint) return Primitive_Result;
-- If P_Type supports a stream size of P_Size, returns the corresponding
-- input and write primitives. Otherwise, returns a list of the stream
-- sizes P_Type supports, in nondecreasing order and with possible
-- duplicates.
end Exp_Strm;
+102 -51
View File
@@ -1893,36 +1893,39 @@ package body Exp_Util is
-------------------
procedure Add_DIC_Check
(DIC_Prag : Node_Id;
DIC_Expr : Node_Id;
Stmts : in out List_Id)
(DIC_Prag : Node_Id; DIC_Expr : Node_Id; Stmts : in out List_Id)
is
Loc : constant Source_Ptr := Sloc (DIC_Prag);
Nam : constant Name_Id := Original_Aspect_Pragma_Name (DIC_Prag);
Loc : constant Source_Ptr := Sloc (DIC_Prag);
Nam : constant Name_Id := Original_Aspect_Pragma_Name (DIC_Prag);
Prag : Node_Id;
begin
-- The DIC pragma is ignored, nothing left to do
if Is_Ignored (DIC_Prag) then
if Is_Ignored_In_Codegen (DIC_Prag) then
null;
-- Otherwise the DIC expression must be checked at run time.
-- Generate:
--
-- pragma Check (<Nam>, <DIC_Expr>);
else
Append_New_To (Stmts,
Make_Pragma (Loc,
Pragma_Identifier =>
Make_Identifier (Loc, Name_Check),
Prag :=
Make_Pragma
(Loc,
Pragma_Identifier =>
Make_Identifier (Loc, Name_Check),
Pragma_Argument_Associations =>
New_List
(Make_Pragma_Argument_Association
(Loc, Expression => Make_Identifier (Loc, Nam)),
Make_Pragma_Argument_Association
(Loc, Expression => DIC_Expr)));
Pragma_Argument_Associations => New_List (
Make_Pragma_Argument_Association (Loc,
Expression => Make_Identifier (Loc, Nam)),
Copy_Assertion_Policy_Attributes (Prag, DIC_Prag);
Make_Pragma_Argument_Association (Loc,
Expression => DIC_Expr))));
Append_New_To (Stmts, Prag);
end if;
-- Add the pragma to the list of processed pragmas
@@ -2311,14 +2314,14 @@ package body Exp_Util is
Loc : constant Source_Ptr := Sloc (Typ);
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
DIC_Prag : Node_Id;
DIC_Typ : Entity_Id;
Dummy_1 : Entity_Id;
Dummy_2 : Entity_Id;
Prag : Node_Id;
Proc_Body : Node_Id;
Proc_Body_Id : Entity_Id;
Proc_Decl : Node_Id;
@@ -2465,12 +2468,23 @@ package body Exp_Util is
if Partial_DIC then
pragma Assert (Present (Priv_Typ));
if Has_Own_DIC (Work_Typ) then -- If we're testing this then maybe
Add_Own_DIC -- we shouldn't be calling Find_DIC_Typ above???
(DIC_Prag => DIC_Prag,
DIC_Typ => DIC_Typ, -- Should this just be Work_Typ???
Obj_Id => Obj_Id,
Stmts => Stmts);
if Has_Own_DIC (Work_Typ) then
-- If we're testing this then maybe
Prag := DIC_Prag;
while Present (Prag)
and then Nkind (Prag) = N_Pragma
and then Pragma_Name (Prag) = Name_Default_Initial_Condition
and then (Prag = DIC_Prag
or else From_Same_Pragma (Prag, DIC_Prag))
loop
Add_Own_DIC -- we shouldn't be calling Find_DIC_Typ above???
(DIC_Prag => Prag,
DIC_Typ => DIC_Typ, -- Should this just be Work_Typ???
Obj_Id => Obj_Id,
Stmts => Stmts);
Next_Rep_Item (Prag);
end loop;
end if;
-- Otherwise, the "full" DIC procedure verifies the DICs inherited from
@@ -2558,7 +2572,7 @@ package body Exp_Util is
end if;
<<Leave>>
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
end Build_DIC_Procedure_Body;
-------------------------------------
@@ -2575,8 +2589,7 @@ package body Exp_Util is
is
Loc : constant Source_Ptr := Sloc (Typ);
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
DIC_Prag : Node_Id;
@@ -2783,7 +2796,7 @@ package body Exp_Util is
end if;
<<Leave>>
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
end Build_DIC_Procedure_Declaration;
------------------------------------
@@ -3231,13 +3244,14 @@ package body Exp_Util is
Ploc : constant Source_Ptr := Sloc (Prag);
Str_Arg : constant Node_Id := Next (Next (First (Args)));
Assoc : List_Id;
Str : String_Id;
Assoc : List_Id;
Check_Prag : Node_Id;
Str : String_Id;
begin
-- The invariant is ignored, nothing left to do
if Is_Ignored (Prag) then
if Is_Ignored_In_Codegen (Prag) then
null;
-- Otherwise the invariant is checked. Build a pragma Check to verify
@@ -3275,10 +3289,14 @@ package body Exp_Util is
-- Generate:
-- pragma Check (<Nam>, <Expr>, <Str>);
Append_New_To (Checks,
Check_Prag :=
Make_Pragma (Ploc,
Chars => Name_Check,
Pragma_Argument_Associations => Assoc));
Chars => Name_Check,
Pragma_Argument_Associations => Assoc);
Copy_Assertion_Policy_Attributes (Check_Prag, Prag);
Append_New_To (Checks, Check_Prag);
end if;
-- Output an info message when inheriting an invariant and the
@@ -3709,8 +3727,7 @@ package body Exp_Util is
-- Local variables
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
Dummy : Entity_Id;
@@ -4058,7 +4075,7 @@ package body Exp_Util is
end if;
<<Leave>>
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
end Build_Invariant_Procedure_Body;
-------------------------------------------
@@ -4075,8 +4092,7 @@ package body Exp_Util is
is
Loc : constant Source_Ptr := Sloc (Typ);
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
Proc_Decl : Node_Id;
@@ -4292,7 +4308,7 @@ package body Exp_Util is
end if;
<<Leave>>
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
end Build_Invariant_Procedure_Declaration;
------------------------
@@ -6190,7 +6206,11 @@ package body Exp_Util is
Utyp := Corresponding_Record_Type (Root_Type (Btyp));
elsif Is_Implicit_Full_View (Utyp) then
Utyp := Underlying_Type (Root_Type (Btyp));
if Is_Derived_Type (Btyp) then
Utyp := Underlying_Type (Root_Type (Btyp));
else
Utyp := Underlying_Type (Root_Type (Full_View (Btyp)));
end if;
if Is_Protected_Type (Utyp) then
Utyp := Corresponding_Record_Type (Utyp);
@@ -10017,7 +10037,8 @@ package body Exp_Util is
begin
return (not Is_Tagged_Type (T) and then Is_Derived_Type (T))
or else
(Is_Private_Type (T) and then Present (Full_View (T))
(Is_Private_Type (T)
and then Present (Full_View (T))
and then not Is_Tagged_Type (Full_View (T))
and then Is_Derived_Type (Full_View (T))
and then Etype (Full_View (T)) /= T);
@@ -10640,8 +10661,7 @@ package body Exp_Util is
is
Loc : constant Source_Ptr := Sloc (Expr);
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
Call : Node_Id;
@@ -10685,7 +10705,7 @@ package body Exp_Util is
Name => New_Occurrence_Of (Func_Id, Loc),
Parameter_Associations => Param_Assocs);
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
return Call;
end Make_Predicate_Call;
@@ -13483,7 +13503,7 @@ package body Exp_Util is
-- Ignored Ghost types do not need any cleanup actions because
-- they will not appear in the final tree.
if Is_Ignored_Ghost_Entity (Typ) then
if Is_Ignored_Ghost_Entity_In_Codegen (Typ) then
null;
elsif Is_Tagged_Type (Typ)
@@ -13529,7 +13549,7 @@ package body Exp_Util is
-- Ignored Ghost objects do not need any cleanup actions because
-- they will not appear in the final tree.
elsif Is_Ignored_Ghost_Entity (Obj_Id) then
elsif Is_Ignored_Ghost_Entity_In_Codegen (Obj_Id) then
null;
-- Conversely, if one of the above cases created a Master_Node,
@@ -13625,7 +13645,7 @@ package body Exp_Util is
-- Freeze nodes for ignored Ghost types do not need cleanup
-- actions because they will never appear in the final tree.
if Is_Ignored_Ghost_Entity (Typ) then
if Is_Ignored_Ghost_Entity_In_Codegen (Typ) then
null;
elsif ((Is_Access_Object_Type (Typ)
@@ -13648,7 +13668,7 @@ package body Exp_Util is
-- Do not inspect an ignored Ghost package because all code found
-- within will not appear in the final tree.
if Is_Ignored_Ghost_Entity (Pack_Id) then
if Is_Ignored_Ghost_Entity_In_Codegen (Pack_Id) then
null;
elsif Ekind (Pack_Id) /= E_Generic_Package
@@ -13665,7 +13685,7 @@ package body Exp_Util is
-- Do not inspect an ignored Ghost package body because all code
-- found within will not appear in the final tree.
if Is_Ignored_Ghost_Entity (Defining_Entity (Decl)) then
if Is_Ignored_Ghost_Entity_In_Codegen (Defining_Entity (Decl)) then
null;
elsif Ekind (Corresponding_Spec (Decl)) /= E_Generic_Package
@@ -14888,6 +14908,37 @@ package body Exp_Util is
Node : Node_Id := N;
Parent_Node : Node_Id := Parent (Node);
begin
loop
case Nkind (Parent_Node) is
when N_Case_Expression_Alternative =>
null;
when N_Case_Expression =>
exit when Node = Expression (Parent_Node);
when N_If_Expression =>
exit when Node = First (Expressions (Parent_Node));
when others =>
exit;
end case;
Node := Parent_Node;
Parent_Node := Parent (Node);
end loop;
return Parent_Node;
end Unconditional_Parent;
--------------------------------------
-- Unqualified_Unconditional_Parent --
--------------------------------------
function Unqualified_Unconditional_Parent (N : Node_Id) return Node_Id is
Node : Node_Id := N;
Parent_Node : Node_Id := Parent (Node);
begin
loop
case Nkind (Parent_Node) is
@@ -14912,7 +14963,7 @@ package body Exp_Util is
end loop;
return Parent_Node;
end Unconditional_Parent;
end Unqualified_Unconditional_Parent;
-------------------------------
-- Update_Primitives_Mapping --
+4
View File
@@ -1344,6 +1344,10 @@ package Exp_Util is
function Unconditional_Parent (N : Node_Id) return Node_Id;
-- Return the first parent of arbitrary node N that is not a conditional
-- expression, one of whose dependent expressions is N, recursively.
function Unqualified_Unconditional_Parent (N : Node_Id) return Node_Id;
-- Return the first parent of arbitrary node N that is not a conditional
-- expression, one of whose dependent expressions is N, and that is not
-- a qualified expression, whose expression is N, recursively.
+2 -3
View File
@@ -84,8 +84,7 @@ package body Expander is
-- Ghost mode.
procedure Expand (N : Node_Id) is
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
begin
@@ -559,7 +558,7 @@ package body Expander is
end if;
<<Leave>>
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
end Expand;
---------------------------
+2
View File
@@ -315,6 +315,7 @@ extern Boolean Is_Null_Range (Node_Id, Node_Id);
#define First_Actual sem_util__first_actual
#define Has_Storage_Model_Type_Aspect sem_util__storage_model_support__has_storage_model_type_aspect
#define Has_Designated_Storage_Model_Aspect sem_util__storage_model_support__has_designated_storage_model_aspect
#define Is_Extended_Access_Type sem_util__is_extended_access_type
#define Is_Expression_Function sem_util__is_expression_function
#define Is_Variable_Size_Record sem_util__is_variable_size_record
#define Needs_Secondary_Stack sem_util__needs_secondary_stack
@@ -327,6 +328,7 @@ extern Entity_Id Defining_Entity (Node_Id);
extern Node_Id First_Actual (Node_Id);
extern Boolean Has_Storage_Model_Type_Aspect (Entity_Id);
extern Boolean Has_Designated_Storage_Model_Aspect (Entity_Id);
extern Boolean Is_Extended_Access_Type (Entity_Id);
extern Boolean Is_Expression_Function (Entity_Id);
extern Boolean Is_Variable_Size_Record (Entity_Id);
extern Boolean Needs_Secondary_Stack (Entity_Id);
+68 -35
View File
@@ -2878,8 +2878,7 @@ package body Freeze is
is
Loc : constant Source_Ptr := Sloc (N);
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
Saved_Ghost_Config : constant Ghost_Config_Type := Ghost_Config;
-- Save the Ghost-related attributes to restore on exit
Atype : Entity_Id;
@@ -4246,7 +4245,7 @@ package body Freeze is
<<Skip_Packed>>
-- A Ghost type cannot have a component of protected or task type
-- (SPARK RM 6.9(21)).
-- (SPARK RM 6.9(22)).
if Is_Ghost_Entity (Arr) and then Is_Concurrent_Type (Ctyp) then
Error_Msg_N
@@ -4686,7 +4685,9 @@ package body Freeze is
-- Declaring too big an array in disabled ghost code is OK
if Is_Array_Type (Typ) and then not Is_Ignored_Ghost_Entity (E) then
if Is_Array_Type (Typ)
and then not Is_Ignored_Ghost_Entity_In_Codegen (E)
then
Check_Large_Modular_Array (Typ);
end if;
end Freeze_Object_Declaration;
@@ -4813,6 +4814,8 @@ package body Freeze is
and then Convention (F_Type) = Convention_Ada
and then not Has_Warnings_Off (F_Type)
and then not Has_Size_Clause (F_Type)
and then Present (Esize (F_Type))
and then Esize (F_Type) = 8
then
Error_Msg_N
("& is an 8-bit Ada Boolean?x?", Formal);
@@ -5179,7 +5182,7 @@ package body Freeze is
and then Convention (Desig) /= Convention_Protected
then
Set_Is_Frozen (Desig);
Create_Extra_Formals (Desig);
Create_Extra_Formals (Desig, Related_Nod => Rec);
end if;
end Check_Itype;
@@ -6787,6 +6790,27 @@ package body Freeze is
Set_Is_Frozen (E);
-- Freeze profile of anonymous access-to-subprogram type
if Do_Freeze_Profile
and then Ekind (E) = E_Anonymous_Access_Subprogram_Type
then
declare
Skip_Because_In_Generic : constant Boolean :=
In_Generic_Scope (E) or else
(Is_Itype (E)
and then Nkind (Parent (Associated_Node_For_Itype (E)))
= N_Generic_Subprogram_Declaration);
begin
if not Skip_Because_In_Generic then
if not Freeze_Profile (Designated_Type (E)) then
goto Leave;
end if;
Freeze_Subprogram (Designated_Type (E));
end if;
end;
end if;
-- Case of entity being frozen is other than a type
if not Is_Type (E) then
@@ -7148,31 +7172,30 @@ package body Freeze is
Next_Index (Indx);
end loop;
-- What we are looking for here is the situation where
-- the RM_Size given would be exactly right if there was
-- a pragma Pack, resulting in the component size being
-- the RM_Size of the component type.
-- In Implicit_Packing mode, if the specified RM_Size
-- would be big enough if there were a pragma Pack,
-- then set the component size as if there were Pack,
-- and Freeze_Array_Type will do the rest.
if RM_Size (E) = Num_Elmts * Rsiz then
if Implicit_Packing
and then RM_Size (E) >= Num_Elmts * Rsiz
then
Set_Component_Size (Btyp, Rsiz);
-- For implicit packing mode, just set the component
-- size and Freeze_Array_Type will do the rest.
-- Otherwise, if pragma Pack would result in exactly the
-- right size, give an error message suggesting packing,
-- except that if the specified Size is zero, there is no
-- need for pragma Pack. Note that size zero is not
-- considered Addressable.
if Implicit_Packing then
Set_Component_Size (Btyp, Rsiz);
-- Otherwise give an error message, except that if the
-- specified Size is zero, there is no need for pragma
-- Pack. Note that size zero is not considered
-- Addressable.
elsif RM_Size (E) /= Uint_0 then
Error_Msg_NE
("size given for& too small", SZ, E);
Error_Msg_N -- CODEFIX
("\use explicit pragma Pack or use pragma "
& "Implicit_Packing", SZ);
end if;
elsif RM_Size (E) = Num_Elmts * Rsiz
and then RM_Size (E) /= Uint_0
then
Error_Msg_NE
("size given for& too small", SZ, E);
Error_Msg_N -- CODEFIX
("\use explicit pragma Pack or use pragma "
& "Implicit_Packing", SZ);
end if;
end if;
end;
@@ -7748,7 +7771,14 @@ package body Freeze is
-- Check restriction for standard storage pool
if No (Associated_Storage_Pool (E)) then
-- Skip this check when Etype (T) is unknown, since attribute
-- Associated_Storage_Pool is only available in the root type
-- of E, and in such case it cannot not be computed (thus
-- causing spurious errors).
if Present (Etype (E))
and then No (Associated_Storage_Pool (E))
then
Check_Restriction (No_Standard_Storage_Pools, E);
end if;
@@ -8358,12 +8388,12 @@ package body Freeze is
-- and Per-Object Expressions" will suppress the insertion, and the
-- freeze node will be dropped on the floor.
if Saved_GM = Ignore
and then Ghost_Mode /= Ignore
and then Present (Ignored_Ghost_Region)
if Saved_Ghost_Config.Ghost_Mode = Ignore
and then Ghost_Config.Ghost_Mode /= Ignore
and then Present (Ghost_Config.Ignored_Ghost_Region)
then
Insert_Actions
(Assoc_Node => Ignored_Ghost_Region,
(Assoc_Node => Ghost_Config.Ignored_Ghost_Region,
Ins_Actions => Result,
Spec_Expr_OK => True);
@@ -8371,7 +8401,7 @@ package body Freeze is
end if;
<<Leave>>
Restore_Ghost_Region (Saved_GM, Saved_IGR);
Restore_Ghost_Region (Saved_Ghost_Config);
return Result;
end Freeze_Entity;
@@ -8785,7 +8815,7 @@ package body Freeze is
and then Nkind (Parent (N)) = N_Function_Call
and then not Has_Foreign_Convention (Nam)
then
Create_Extra_Formals (Nam);
Create_Extra_Formals (Nam, Related_Nod => N);
end if;
when others =>
@@ -11023,7 +11053,10 @@ package body Freeze is
E : Entity_Id;
N : Node_Id) return Boolean
is
Decl : constant Node_Id := Original_Node (Unit_Declaration_Node (E));
Decl : constant Node_Id :=
(if Ekind (E) = E_Subprogram_Type and then No (Parent (E))
then Empty
else Original_Node (Unit_Declaration_Node (E)));
function Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate
(N : Node_Id) return Traverse_Result;
+14 -1
View File
@@ -56,6 +56,7 @@ with Scn; use Scn;
with Sem; use Sem;
with Sem_Aux;
with Sem_Ch8;
with Sem_Ch12;
with Sem_SCIL;
with Sem_Elab; use Sem_Elab;
with Sem_Prag; use Sem_Prag;
@@ -432,6 +433,18 @@ begin
Analyze_Inlined_Bodies;
end if;
-- Mark the structural instances spawned by the main unit as
-- Link Once because other units may spawn them too.
Sem_Ch12.Mark_Link_Once
(Declarations (Aux_Decls_Node (Cunit (Main_Unit))));
if Nkind (Unit (Cunit (Main_Unit))) = N_Package_Body then
Sem_Ch12.Mark_Link_Once
(Declarations
(Aux_Decls_Node (Spec_Lib_Unit (Cunit (Main_Unit)))));
end if;
-- Remove entities from program that do not have any execution
-- time references.
@@ -477,7 +490,7 @@ begin
-- executable. This action must be performed very late because it
-- heavily alters the tree.
if Operating_Mode = Generate_Code or else GNATprove_Mode then
if Operating_Mode = Generate_Code and not CodePeer_Mode then
Remove_Ignored_Ghost_Code;
end if;
+3 -2
View File
@@ -532,7 +532,6 @@ GNAT_ADA_OBJS+= \
ada/libgnat/s-carun8.o \
ada/libgnat/s-casuti.o \
ada/libgnat/s-cautns.o \
ada/libgnat/s-crtl.o \
ada/libgnat/s-conca2.o \
ada/libgnat/s-conca3.o \
ada/libgnat/s-conca4.o \
@@ -542,6 +541,7 @@ GNAT_ADA_OBJS+= \
ada/libgnat/s-conca8.o \
ada/libgnat/s-conca9.o \
ada/libgnat/s-crc32.o \
ada/libgnat/s-crtl.o \
ada/libgnat/s-excdeb.o \
ada/libgnat/s-except.o \
ada/libgnat/s-excmac.o \
@@ -690,7 +690,7 @@ GNATBIND_OBJS += \
ada/libgnat/g-cstyin.o \
ada/libgnat/g-hesora.o \
ada/libgnat/g-htable.o \
ada/libgnat/i-c.o \
ada/libgnat/i-c.o \
ada/libgnat/i-cstrin.o \
ada/libgnat/interfac.o \
ada/libgnat/s-addope.o \
@@ -707,6 +707,7 @@ GNATBIND_OBJS += \
ada/libgnat/s-conca8.o \
ada/libgnat/s-conca9.o \
ada/libgnat/s-crc32.o \
ada/libgnat/s-crtl.o \
ada/libgnat/s-excdeb.o \
ada/libgnat/s-except.o \
ada/libgnat/s-excmac.o \
+4 -4
View File
@@ -314,16 +314,16 @@ Makefile: ../config.status $(srcdir)/ada/gcc-interface/Makefile.in $(srcdir)/ada
GNATLINK_OBJS = gnatlink.o \
a-except.o ali.o alloc.o butil.o casing.o csets.o debug.o fmap.o fname.o \
gnatvsn.o hostparm.o indepsw.o interfac.o i-c.o i-cstrin.o namet.o opt.o \
osint.o output.o rident.o s-exctab.o s-secsta.o s-stalib.o s-stoele.o \
sdefault.o snames.o stylesw.o switch.o system.o table.o targparm.o \
types.o validsw.o widechar.o
osint.o output.o rident.o s-excmac.o s-exctab.o s-secsta.o s-stalib.o \
s-stoele.o sdefault.o snames.o stylesw.o switch.o system.o table.o \
targparm.o types.o validsw.o widechar.o
GNATMAKE_OBJS = a-except.o ali.o ali-util.o aspects.o s-casuti.o alloc.o \
atree.o binderr.o butil.o casing.o csets.o debug.o elists.o einfo.o errout.o \
erroutc.o errutil.o err_vars.o fmap.o fname.o fname-uf.o fname-sf.o \
gnatmake.o gnatvsn.o hostparm.o interfac.o i-c.o i-cstrin.o krunch.o lib.o \
make.o makeusg.o make_util.o namet.o nlists.o opt.o osint.o osint-m.o \
output.o restrict.o rident.o s-exctab.o s-cautns.o \
output.o restrict.o rident.o s-cautns.o s-excmac.o s-exctab.o \
s-secsta.o s-stalib.o s-stoele.o scans.o scng.o sdefault.o sfn_scan.o \
s-purexc.o s-htable.o scil_ll.o sem_aux.o sinfo.o sinput.o sinput-c.o \
snames.o stand.o stringt.o styleg.o stylesw.o system.o validsw.o \
+27 -3
View File
@@ -73,6 +73,14 @@ do { \
#define TYPE_IS_FAT_POINTER_P(NODE) \
(TREE_CODE (NODE) == RECORD_TYPE && TYPE_FAT_POINTER_P (NODE))
/* For RECORD_TYPE, UNION_TYPE, and QUAL_UNION_TYPE, nonzero if this is a
record being used as an extended access (only true for RECORD_TYPE). */
#define TYPE_EXTENDED_POINTER_P(NODE) \
TYPE_LANG_FLAG_7 (RECORD_OR_UNION_CHECK (NODE))
#define TYPE_IS_EXTENDED_POINTER_P(NODE) \
(TREE_CODE (NODE) == RECORD_TYPE && TYPE_EXTENDED_POINTER_P (NODE))
/* For integral types and array types, nonzero if this is an implementation
type for a bit-packed array type. Such types should not be extended to a
larger size or validated against a specified size. */
@@ -184,9 +192,6 @@ do { \
/* True for a dummy type if TYPE appears in a profile. */
#define TYPE_DUMMY_IN_PROFILE_P(NODE) TYPE_LANG_FLAG_6 (NODE)
/* True if objects of this type are guaranteed to be properly aligned. */
#define TYPE_ALIGN_OK(NODE) TYPE_LANG_FLAG_7 (NODE)
/* True for types that implement a packed array and for original packed array
types. */
#define TYPE_IMPL_PACKED_ARRAY_P(NODE) \
@@ -387,6 +392,25 @@ do { \
#define SET_TYPE_SCALE_FACTOR(NODE, X) \
SET_TYPE_LANG_SPECIFIC (INTEGER_TYPE_CHECK (NODE), X)
/* For an UNCONSTRAINED_ARRAY_TYPE, this is the twin UNCONSTRAINED_ARRAY_TYPE
built for extended access types. */
#define TYPE_EXTENDED_UNCONSTRAINED_ARRAY(NODE) \
GET_TYPE_LANG_SPECIFIC (TREE_CHECK2 ((NODE), UNCONSTRAINED_ARRAY_TYPE, \
ENUMERAL_TYPE))
#define SET_TYPE_EXTENDED_UNCONSTRAINED_ARRAY(NODE, X) \
SET_TYPE_LANG_SPECIFIC (TREE_CHECK2 ((NODE), UNCONSTRAINED_ARRAY_TYPE, \
ENUMERAL_TYPE), X)
/* When the compiler only has a dummy type for an unconstrained array type, we
don't build a duplicate dummy only to store the record type for the extended
access. Instead, we store it in the original dummy type, using the same
lang_type field that will hold the tree for the duplicated array type built
later. */
#define TYPE_DUMMY_EXT_POINTER_TO(NODE) \
GET_TYPE_LANG_SPECIFIC (TREE_CHECK ((NODE), ENUMERAL_TYPE))
#define SET_TYPE_DUMMY_EXT_POINTER_TO(NODE, X) \
SET_TYPE_LANG_SPECIFIC (TREE_CHECK ((NODE), ENUMERAL_TYPE), X)
/* For types with TYPE_CAN_HAVE_DEBUG_TYPE_P, this is the type to use in
debugging information. */
#define TYPE_DEBUG_TYPE(NODE) \
+440 -189
View File
@@ -201,6 +201,7 @@ static tree gnat_to_gnu_component_type (Entity_Id, bool, bool);
static tree gnat_to_gnu_subprog_type (Entity_Id, bool, bool, tree *);
static int adjust_packed (tree, tree, int);
static tree gnat_to_gnu_field (Entity_Id, tree, int, bool, bool);
static tree get_extended_unconstrained_array (Entity_Id, tree);
static enum inline_status_t inline_status_for_subprog (Entity_Id);
static Entity_Id Gigi_Cloned_Subtype (Entity_Id);
static tree gnu_ext_name_for_subprog (Entity_Id, tree);
@@ -279,6 +280,13 @@ is_artificial (Entity_Id gnat_entity)
initial value (in GCC tree form). This is optional for a variable. For
a renamed entity, GNU_EXPR gives the object being renamed.
If GNAT_ENTITY is an array type and GNU_EXPR is NULL_TREE, a GCC tree for a
regular fat pointer will be generated. However, if GNU_EXPR is not
NULL_TREE, it's an existing GCC tree for the fat pointer, and a GCC tree for
the extended pointer will be created instead. The caller must clear the
association between GNAT_ENTITY and GNU_EXPR before calling
gnat_to_gnu_entity with a non-NULL GNU_EXPR and restore it after the call.
DEFINITION is true if this call is intended for a definition. This is used
for separate compilation where it is necessary to know whether an external
declaration or a definition must be created if the GCC equivalent was not
@@ -441,7 +449,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
must be specified unless it was specified by the programmer. Exceptions
are for access-to-protected-subprogram types and all access subtypes, as
another GNAT type is used to lay out the GCC type for them, as well as
access-to-subprogram types if front-end unnesting is enabled. */
access-to-subprogram types if front-end unnesting is enabled, and also
extended access types. */
gcc_assert (!is_type
|| Known_Esize (gnat_entity)
|| Has_Size_Clause (gnat_entity)
@@ -454,6 +463,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
|| kind == E_Anonymous_Access_Subprogram_Type)
&& Unnest_Subprogram_Mode)
|| kind == E_Access_Subtype
|| Is_Extended_Access_Type (gnat_entity)
|| type_annotate_only)));
/* The RM size must be specified for all discrete and fixed-point types. */
@@ -638,7 +648,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
/* Build a CONST_DECL for debugging purposes exclusively. */
gnu_decl
= create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type,
gnu_expr, true, Is_Public (gnat_entity),
gnu_expr, true,
Is_Public (gnat_entity),
Is_Link_Once (gnat_entity),
false, false, false, artificial_p,
debug_info_p, NULL, gnat_entity);
}
@@ -1186,6 +1198,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
create_var_decl (gnu_entity_name, NULL_TREE,
TREE_TYPE (gnu_expr), gnu_expr,
const_flag, Is_Public (gnat_entity),
Is_Link_Once (gnat_entity),
imported_p, static_flag, volatile_flag,
artificial_p, debug_info_p, attr_list,
gnat_entity, false);
@@ -1254,7 +1267,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
initialize it to NULL, unless the object is declared imported as
per RM B.1(24). */
if (definition
&& (POINTER_TYPE_P (gnu_type) || TYPE_IS_FAT_POINTER_P (gnu_type))
&& (POINTER_TYPE_P (gnu_type)
|| TYPE_IS_FAT_POINTER_P (gnu_type)
|| TYPE_IS_EXTENDED_POINTER_P (gnu_type))
&& !gnu_expr
&& !Is_Imported (gnat_entity))
gnu_expr = null_pointer_node;
@@ -1388,16 +1403,15 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
}
}
/* If we are at top level and this object is of variable size,
make the actual type a hidden pointer to the real type and
make the initializer be a memory allocation and initialization.
Likewise for objects we aren't defining (presumed to be
external references from other packages), but there we do
not set up an initialization.
If the object's size overflows, make an allocator too, so that
Storage_Error gets raised. Note that we will never free
such memory, so we presume it never will get allocated. */
/* If we are at top level and this object is of variable size, make
the actual type a reference to the real type and the initializer
be a memory allocation and initialization. Likewise for an object
that we aren't defining or is imported (presumed to be an external
reference from another package), but in this case we do not set up
an initialization. Likewise if the object's size is constant but
too large. In either case, this will also cause Storage_Error to
be raised if the size ends up overflowing. Note that we will never
free such memory, but it will be allocated only at top level. */
if (!allocatable_size_p (TYPE_SIZE_UNIT (gnu_type),
global_bindings_p ()
|| !definition
@@ -1411,6 +1425,29 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
|| !definition
|| static_flag)))
{
/* Give a warning if the size is constant. */
if ((TREE_CODE (TYPE_SIZE_UNIT (gnu_type)) == INTEGER_CST
|| (gnu_size && TREE_CODE (gnu_size) == INTEGER_CST))
&& definition)
{
if (imported_p)
{
post_error
("??too large object cannot be imported directly",
gnat_entity);
post_error ("\\??indirect import will be used instead",
gnat_entity);
}
else if (global_bindings_p () || static_flag)
{
post_error
("??too large object cannot be allocated statically",
gnat_entity);
post_error ("\\??dynamic allocation will be used instead",
gnat_entity);
}
}
if (volatile_flag && !TYPE_VOLATILE (gnu_type))
gnu_type = change_qualified_type (gnu_type, TYPE_QUAL_VOLATILE);
gnu_type = build_reference_type (gnu_type);
@@ -1453,21 +1490,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
}
/* Give a warning if the size is constant but too large. */
if (TREE_CODE (TYPE_SIZE_UNIT (gnu_alloc_type)) == INTEGER_CST)
{
if (valid_constant_size_p (TYPE_SIZE_UNIT (gnu_alloc_type)))
{
post_error
("??too large object cannot be allocated statically",
gnat_entity);
post_error ("\\??dynamic allocation will be used instead",
gnat_entity);
}
else
post_error ("??Storage_Error will be raised at run time!",
gnat_entity);
}
if (TREE_CODE (TYPE_SIZE_UNIT (gnu_alloc_type)) == INTEGER_CST
&& !valid_constant_size_p (TYPE_SIZE_UNIT (gnu_alloc_type)))
post_error ("??Storage_Error will be raised at run time!",
gnat_entity);
gnu_expr
= build_allocator (gnu_alloc_type, gnu_expr, gnu_type,
@@ -1495,7 +1521,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
tree gnu_new_var
= create_var_decl (create_concat_name (gnat_entity, "ALIGN"),
NULL_TREE, gnu_new_type, NULL_TREE,
false, false, false, false, false,
false, false, false, false, false, false,
true, debug_info_p && definition, NULL,
gnat_entity);
@@ -1557,8 +1583,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
= create_var_decl (concat_name (gnu_entity_name, "UNC"),
NULL_TREE, gnu_type, gnu_expr,
const_flag, Is_Public (gnat_entity),
imported_p || !definition, static_flag,
volatile_flag, true,
Is_Link_Once (gnat_entity),
imported_p || !definition,
static_flag, volatile_flag, true,
debug_info_p && definition,
NULL, gnat_entity);
gnu_expr = build_unary_op (ADDR_EXPR, NULL_TREE, gnu_unc_var);
@@ -1604,8 +1631,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
gnu_decl
= create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type,
gnu_expr, const_flag, Is_Public (gnat_entity),
imported_p || !definition, static_flag,
volatile_flag, artificial_p,
Is_Link_Once (gnat_entity),
imported_p || !definition,
static_flag, volatile_flag, artificial_p,
debug_info_p && definition, attr_list,
gnat_entity);
DECL_BY_REF_P (gnu_decl) = used_by_ref;
@@ -1652,6 +1680,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
tree gnu_corr_var
= create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type,
gnu_expr, true, Is_Public (gnat_entity),
Is_Link_Once (gnat_entity),
!definition, static_flag, volatile_flag,
artificial_p, debug_info_p && definition,
attr_list, gnat_entity, false);
@@ -1757,7 +1786,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
tree gnu_literal
= create_var_decl (get_entity_name (gnat_literal), NULL_TREE,
gnu_type, gnu_value, true, false, false,
false, false, artificial_p, false,
false, false, false, artificial_p, false,
NULL, gnat_literal);
save_gnu_tree (gnat_literal, gnu_literal, false);
gnu_list
@@ -2154,21 +2183,28 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
have are pointers to that type. In addition to the type node itself,
4 other types associated with it are built in the process:
1. the array type (suffix XUA) containing the actual data,
1. the array type (suffix XUA for fat pointer, XUAEA for extended
access) containing the actual data,
2. the template type (suffix XUB) containing the bounds,
2. the template type (suffix XUB for fat pointer, XUBEA for extended
access) containing the bounds,
3. the fat pointer type (suffix XUP) representing a pointer or a
reference to the unconstrained array type:
XUP = struct { XUA *, XUB * }
4. the object record type (suffix XUT) containing bounds and data:
XUT = struct { XUB, XUA }
or the extended access type (suffix XUPEA) representing a pointer
or a reference to the unconstrained array type:
XUPEA = struct { XUAEA *, XUBEA }
4. the object record type (suffix XUT for fat pointer, XUTEA for
extended access) containing bounds and data:
XUT[EA] = struct { XUB[EA], XUA[EA] }
The bounds of the array type XUA (de)reference the XUB * field of a
PLACEHOLDER_EXPR for the fat pointer type XUP, so the array type XUA
is to be interpreted in the context of the fat pointer type XUB for
debug info purposes. */
debug info purposes. Likewise for the extended access case. */
case E_Array_Type:
{
@@ -2176,14 +2212,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
const Entity_Id PAT = Packed_Array_Impl_Type (gnat_entity);
const bool convention_fortran_p
= (Convention (gnat_entity) == Convention_Fortran);
const bool extended_access_p = gnu_expr != NULL_TREE;
const int ndim = Number_Dimensions (gnat_entity);
tree gnu_fat_type, gnu_template_type, gnu_ptr_template;
tree gnu_template_reference, gnu_template_fields;
tree gnu_template_reference;
tree *gnu_index_types = XALLOCAVEC (tree, ndim);
tree *gnu_temp_fields = XALLOCAVEC (tree, ndim);
tree gnu_max_size = size_one_node;
tree comp_type, fld, tem, obj;
Entity_Id gnat_index;
alias_set_type ptr_set = -1;
int index;
@@ -2203,7 +2238,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
better debugging information in DWARF by leveraging the support for
incomplete declarations of "tagged" types in the DWARF back-end. */
gnu_type = get_dummy_type (gnat_entity);
if (gnu_type && TYPE_POINTER_TO (gnu_type))
if (gnu_type && TYPE_POINTER_TO (gnu_type) && !extended_access_p)
{
gnu_fat_type = TYPE_MAIN_VARIANT (TYPE_POINTER_TO (gnu_type));
TYPE_NAME (gnu_fat_type) = NULL_TREE;
@@ -2218,10 +2253,42 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
DECL_CHAIN (TYPE_FIELDS (TYPE_POINTER_TO (gnu_type)))
= copy_node (DECL_CHAIN (TYPE_FIELDS (gnu_fat_type)));
}
/* We complete an existing dummy for extended access, but we haven't
created a specific tree yet for the array type. The extended access
type is stored directly in the original unconstrained array type,
where we will store the new array type later. */
else if (gnu_type
&& TYPE_DUMMY_EXT_POINTER_TO (gnu_type)
&& extended_access_p)
{
gnu_ptr_template = NULL_TREE;
tree gnu_ext_acc_type = TYPE_DUMMY_EXT_POINTER_TO (gnu_type);
gnu_fat_type = TYPE_MAIN_VARIANT (gnu_ext_acc_type);
TYPE_NAME (gnu_fat_type) = NULL_TREE;
/* The dummy types has a XUBEA that was only used to get the size of
the extended pointer. We now drop this type and use the XUB type
from the regular fat pointer instead. */
gnu_template_type
= TREE_TYPE (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (TREE_TYPE (gnu_expr)))));
DECL_CHAIN (TYPE_FIELDS (gnu_fat_type))
= create_field_decl (get_identifier ("BOUNDS"),
gnu_template_type, gnu_fat_type,
NULL_TREE, NULL_TREE, 0, 1);
}
else
{
gnu_fat_type = make_node (RECORD_TYPE);
gnu_template_type = make_node (RECORD_TYPE);
if (extended_access_p)
gnu_template_type
= TREE_TYPE (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (TREE_TYPE (gnu_expr)))));
else
gnu_template_type = make_node (RECORD_TYPE);
gnu_ptr_template = build_pointer_type (gnu_template_type);
}
@@ -2253,7 +2320,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
Var are also built later with the fields of the final type, the
aliasing machinery may consider that the accesses are distinct
if the FIELD_DECLs are distinct as objects. */
if (COMPLETE_TYPE_P (gnu_fat_type))
if (COMPLETE_TYPE_P (gnu_fat_type) && !extended_access_p)
{
fld = TYPE_FIELDS (gnu_fat_type);
if (TYPE_ALIAS_SET_KNOWN_P (TYPE_CANONICAL (TREE_TYPE (fld))))
@@ -2264,6 +2331,39 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
for (tree t = gnu_fat_type; t; t = TYPE_NEXT_VARIANT (t))
SET_TYPE_UNCONSTRAINED_ARRAY (t, gnu_type);
}
else if (COMPLETE_TYPE_P (gnu_fat_type) && extended_access_p)
{
fld = TYPE_FIELDS (gnu_fat_type);
if (TYPE_ALIAS_SET_KNOWN_P (TYPE_CANONICAL (TREE_TYPE (fld))))
ptr_set = TYPE_ALIAS_SET (TYPE_CANONICAL (TREE_TYPE (fld)));
TREE_TYPE (fld) = ptr_type_node;
/* For extended access, we leave the BOUNDS field alone. */
TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (gnu_fat_type)) = 0;
for (tree t = gnu_fat_type; t; t = TYPE_NEXT_VARIANT (t))
SET_TYPE_UNCONSTRAINED_ARRAY (t, gnu_type);
}
else if (extended_access_p)
{
/* We make the fields addressable for the sake of compatibility
with languages for which the regular fields are addressable. */
fld
= create_field_decl (get_identifier ("P_ARRAY"),
ptr_type_node, gnu_fat_type,
NULL_TREE, NULL_TREE, 0, 1);
/* At this step, gnu_template_type is an empty RECORD to be
be populated later. */
DECL_CHAIN (fld)
= create_field_decl (get_identifier ("BOUNDS"),
gnu_template_type, gnu_fat_type,
NULL_TREE, NULL_TREE, 0, 1);
/* Too early to finish the record, but set the fields so that
they are available through the type. */
TYPE_FIELDS (gnu_fat_type) = fld;
SET_TYPE_UNCONSTRAINED_ARRAY (gnu_fat_type, gnu_type);
}
else
{
/* We make the fields addressable for the sake of compatibility
@@ -2291,135 +2391,56 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
: gnat_entity;
tree xup_name
= gnat_encodings == DWARF_GNAT_ENCODINGS_ALL
? create_concat_name (gnat_name, "XUP")
? create_concat_name (gnat_name,
extended_access_p ? "XUPEA" : "XUP")
: gnu_entity_name;
create_type_decl (xup_name, gnu_fat_type, true, debug_info_p,
gnat_entity, false);
/* Build a reference to the template from a PLACEHOLDER_EXPR that
is the fat pointer. This will be used to access the individual
fields once we build them. */
tem = build3 (COMPONENT_REF, gnu_ptr_template,
build0 (PLACEHOLDER_EXPR, gnu_fat_type),
DECL_CHAIN (fld), NULL_TREE);
gnu_template_reference
= build_unary_op (INDIRECT_REF, gnu_template_type, tem);
TREE_READONLY (gnu_template_reference) = 1;
TREE_THIS_NOTRAP (gnu_template_reference) = 1;
/* Now create the GCC type for each index and add the fields for that
index to the template. */
for (index = (convention_fortran_p ? ndim - 1 : 0),
gnat_index = First_Index (gnat_entity);
IN_RANGE (index, 0, ndim - 1);
index += (convention_fortran_p ? - 1 : 1),
gnat_index = Next_Index (gnat_index))
is the extended/fat pointer. This will be used to access the
individual fields once we build them. */
if (extended_access_p)
{
const Entity_Id gnat_index_type = Etype (gnat_index);
const bool is_flb
= Is_Fixed_Lower_Bound_Index_Subtype (gnat_index_type);
tree gnu_index_type = get_unpadded_type (gnat_index_type);
tree gnu_orig_min = TYPE_MIN_VALUE (gnu_index_type);
tree gnu_orig_max = TYPE_MAX_VALUE (gnu_index_type);
tree gnu_index_base_type = get_base_type (gnu_index_type);
tree gnu_lb_field, gnu_hb_field;
tree gnu_min, gnu_max, gnu_high;
char field_name[16];
/* Update the maximum size of the array in elements. */
if (gnu_max_size)
gnu_max_size
= update_n_elem (gnu_max_size, gnu_orig_min, gnu_orig_max);
/* Now build the self-referential bounds of the index type. */
gnu_index_type = maybe_character_type (gnu_index_type);
gnu_index_base_type = maybe_character_type (gnu_index_base_type);
/* Make the FIELD_DECLs for the low and high bounds of this
type and then make extractions of these fields from the
template. */
sprintf (field_name, "LB%d", index);
gnu_lb_field = create_field_decl (get_identifier (field_name),
gnu_index_type,
gnu_template_type, NULL_TREE,
NULL_TREE, 0, 0);
/* Mark the field specifically for INSTANTIATE_LOAD_IN_EXPR. */
DECL_DISCRIMINANT_NUMBER (gnu_lb_field) = integer_minus_one_node;
Sloc_to_locus (Sloc (gnat_entity),
&DECL_SOURCE_LOCATION (gnu_lb_field));
field_name[0] = 'U';
gnu_hb_field = create_field_decl (get_identifier (field_name),
gnu_index_type,
gnu_template_type, NULL_TREE,
NULL_TREE, 0, 0);
/* Mark the field specifically for INSTANTIATE_LOAD_IN_EXPR. */
DECL_DISCRIMINANT_NUMBER (gnu_hb_field) = integer_minus_one_node;
Sloc_to_locus (Sloc (gnat_entity),
&DECL_SOURCE_LOCATION (gnu_hb_field));
gnu_temp_fields[index] = chainon (gnu_lb_field, gnu_hb_field);
/* We can't use build_component_ref here since the template type
isn't complete yet. */
if (!is_flb)
{
gnu_orig_min = build3 (COMPONENT_REF, TREE_TYPE (gnu_lb_field),
gnu_template_reference, gnu_lb_field,
NULL_TREE);
TREE_READONLY (gnu_orig_min) = 1;
}
gnu_orig_max = build3 (COMPONENT_REF, TREE_TYPE (gnu_hb_field),
gnu_template_reference, gnu_hb_field,
NULL_TREE);
TREE_READONLY (gnu_orig_max) = 1;
gnu_min = convert (sizetype, gnu_orig_min);
gnu_max = convert (sizetype, gnu_orig_max);
/* Compute the size of this dimension. See the E_Array_Subtype
case below for the rationale. */
if (is_flb
&& Nkind (gnat_index) == N_Subtype_Indication
&& flb_cannot_be_superflat (gnat_index))
gnu_high = gnu_max;
else
gnu_high
= build3 (COND_EXPR, sizetype,
build2 (GE_EXPR, boolean_type_node,
gnu_orig_max, gnu_orig_min),
gnu_max,
TREE_CODE (gnu_min) == INTEGER_CST
? int_const_binop (MINUS_EXPR, gnu_min, size_one_node)
: size_binop (MINUS_EXPR, gnu_min, size_one_node));
/* Make a range type with the new range in the Ada base type.
Then make an index type with the size range in sizetype. */
gnu_index_types[index]
= create_index_type (gnu_min, gnu_high,
create_range_type (gnu_index_base_type,
gnu_orig_min,
gnu_orig_max),
gnat_entity);
TYPE_NAME (gnu_index_types[index])
= create_concat_name (gnat_entity, field_name);
/* Extended pointers reference the template directly through the
BOUNDS field, which is the second field. */
gnu_template_reference
= build3 (COMPONENT_REF, gnu_template_type,
build0 (PLACEHOLDER_EXPR, gnu_fat_type),
DECL_CHAIN (fld), NULL_TREE);
TREE_READONLY (gnu_template_reference) = 1;
}
else
{
/* Fat pointers reference the template indirectly through the
P_BOUNDS field, which is the second field. */
tem = build3 (COMPONENT_REF, gnu_ptr_template,
build0 (PLACEHOLDER_EXPR, gnu_fat_type),
DECL_CHAIN (fld), NULL_TREE);
gnu_template_reference
= build_unary_op (INDIRECT_REF, gnu_template_type, tem);
TREE_READONLY (gnu_template_reference) = 1;
TREE_THIS_NOTRAP (gnu_template_reference) = 1;
}
/* Install all the fields into the template. */
TYPE_NAME (gnu_template_type)
= create_concat_name (gnat_entity, "XUB");
TYPE_NAMELESS (gnu_template_type)
= gnat_encodings != DWARF_GNAT_ENCODINGS_ALL;
gnu_template_fields = NULL_TREE;
for (index = 0; index < ndim; index++)
gnu_template_fields
= chainon (gnu_template_fields, gnu_temp_fields[index]);
finish_record_type (gnu_template_type, gnu_template_fields, 0,
debug_info_p);
TYPE_CONTEXT (gnu_template_type) = gnu_fat_type;
if (!extended_access_p)
{
/* Build the template type. */
TYPE_NAME (gnu_template_type)
= create_concat_name (gnat_entity, "XUB");
}
build_template_type (gnat_entity, gnu_template_type,
gnu_template_reference, gnu_index_types,
gnu_max_size, debug_info_p);
if (!extended_access_p)
TYPE_CONTEXT (gnu_template_type) = gnu_fat_type;
/* Now that the template type has been created, the record type for
extended access can be finished. */
if (extended_access_p)
finish_extended_pointer_type (gnu_fat_type, fld);
/* If Component_Size is not already specified, annotate it with the
size of the component. */
@@ -2499,9 +2520,11 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
TYPE_ARRAY_MAX_SIZE (tem) = gnu_max_size;
/* See the above description for the rationale. */
tree xua_name
= create_concat_name (gnat_entity,
extended_access_p ? "XUAEA" : "XUA");
tree gnu_tmp_decl
= create_type_decl (create_concat_name (gnat_entity, "XUA"), tem,
true, debug_info_p, gnat_entity);
= create_type_decl (xua_name, tem, true, debug_info_p, gnat_entity);
TYPE_CONTEXT (tem) = gnu_fat_type;
TYPE_CONTEXT (TYPE_POINTER_TO (tem)) = gnu_fat_type;
@@ -2513,7 +2536,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
If the GNAT encodings are used, give it a name. */
tree xut_name
= (gnat_encodings == DWARF_GNAT_ENCODINGS_ALL)
? create_concat_name (gnat_name, "XUT")
? create_concat_name (gnat_name,
extended_access_p ? "XUTEA" : "XUT")
: gnu_entity_name;
obj = build_unc_object_type (gnu_template_type, tem, xut_name,
artificial_p, debug_info_p);
@@ -2531,7 +2555,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
/* If this is a packed type implemented specially, then process the
implementation type so it is elaborated in the proper scope. */
if (Present (PAT))
if (Present (PAT) && !extended_access_p)
{
/* Save the XUA type as our equivalent temporarily for the call
to gnat_to_gnu_type on the OAT below. */
@@ -3731,7 +3755,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
= create_var_decl (create_concat_name (gnat_entity,
"XVZ"),
NULL_TREE, sizetype, gnu_size_unit,
true, false, false, false, false,
true, false, false, false, false, false,
true, true, NULL, gnat_entity, false);
}
@@ -3940,7 +3964,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
}
/* Access-to-unconstrained-array types need a special treatment. */
if (Is_Array_Type (gnat_desig_rep) && !Is_Constrained (gnat_desig_rep))
if (Is_Array_Type (gnat_desig_rep)
&& !Is_Constrained (gnat_desig_rep)
&& !Is_Extended_Access_Type (gnat_entity))
{
/* If the processing above got something that has a pointer, then
we are done. This could have happened either because the type
@@ -3951,6 +3977,26 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
gnu_type = TYPE_POINTER_TO (gnu_desig_type);
}
else if (Is_Array_Type (gnat_desig_rep)
&& !Is_Constrained (gnat_desig_rep)
&& Is_Extended_Access_Type (gnat_entity))
{
if (TYPE_IS_DUMMY_P (gnu_desig_type))
gnu_type
= build_dummy_unc_pointer_types_ext (gnat_desig_rep,
gnu_desig_type);
else
{
tree gnu_extended_type
= get_extended_unconstrained_array (gnat_desig_rep,
gnu_desig_type);
/* We should not get a dummy type. */
gnu_type = TYPE_POINTER_TO (gnu_extended_type);
gcc_assert (gnu_type);
}
}
/* If we haven't done it yet, build the pointer type the usual way. */
else if (!gnu_type)
{
@@ -4255,8 +4301,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
gnu_decl
= create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type,
gnu_address, false, Is_Public (gnat_entity),
extern_flag, false, false, artificial_p,
debug_info_p, NULL, gnat_entity);
Is_Link_Once (gnat_entity), extern_flag,
false, false, artificial_p, debug_info_p,
NULL, gnat_entity);
DECL_BY_REF_P (gnu_decl) = 1;
}
@@ -4285,6 +4332,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
= create_subprog_decl (gnu_entity_name, gnu_ext_name,
gnu_type, gnu_param_list, inline_status,
Is_Public (gnat_entity) || imported_p,
Is_Link_Once (gnat_entity),
extern_flag, artificial_p, debug_info_p,
definition && imported_p, attr_list,
gnat_entity);
@@ -4549,7 +4597,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
if (gnu_size)
size = gnu_size;
else if (RECORD_OR_UNION_TYPE_P (gnu_type)
&& !TYPE_FAT_POINTER_P (gnu_type))
&& !TYPE_FAT_POINTER_P (gnu_type)
&& !TYPE_EXTENDED_POINTER_P (gnu_type))
size = rm_size (gnu_type);
else
size = TYPE_SIZE (gnu_type);
@@ -4821,14 +4870,6 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
{
bool align_clause;
/* Record the property that objects of tagged types are guaranteed to
be properly aligned. This is necessary because conversions to the
class-wide type are translated into conversions to the root type,
which can be less aligned than some of its derived types. */
if (Is_Tagged_Type (gnat_entity)
|| Is_Class_Wide_Equivalent_Type (gnat_entity))
TYPE_ALIGN_OK (gnu_type) = 1;
/* Record whether the type is passed by reference. */
if (is_by_ref && !VOID_TYPE_P (gnu_type))
TYPE_BY_REFERENCE_P (gnu_type) = 1;
@@ -5134,6 +5175,22 @@ get_unpadded_type (Entity_Id gnat_entity)
return type;
}
/* Similar, but GNAT_ENTITY is assumed to refer to a GNAT type. Return
the extended version of the GCC type corresponding to that entity. */
tree
get_unpadded_extended_type (Entity_Id gnat_entity)
{
tree type = gnat_to_gnu_type (gnat_entity);
tree extended_type = get_extended_unconstrained_array (gnat_entity, type);
if (TYPE_IS_PADDING_P (extended_type))
extended_type = TREE_TYPE (TYPE_FIELDS (extended_type));
return extended_type;
}
/* Return whether the E_Subprogram_Type/E_Function/E_Procedure GNAT_ENTITY is
a C++ imported method or equivalent.
@@ -5241,6 +5298,43 @@ is_cplusplus_method (Entity_Id gnat_entity)
return false;
}
/* Get the UNCONSTRAINED_ARRAY_TYPE tree used for extended access handling,
for the unconstrained array type GNAT_ENTITY.
GNU_TYPE is the UNCONSTRAINED_ARRAY_TYPE tree used for the regular
fat/thin pointers. */
static tree
get_extended_unconstrained_array (Entity_Id gnat_entity, tree gnu_type)
{
gcc_assert (Is_Array_Type (gnat_entity)
&& TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE);
tree gnu_extended_type = TYPE_EXTENDED_UNCONSTRAINED_ARRAY (gnu_type);
/* Building the extended type is achieved by translating the array type
a second time using a special processing. */
if (!gnu_extended_type)
{
/* To have gnat_to_gnu_entity trigger the special processing for extended
access types, we pass GNU_TYPE as second parameter, we backup the
existing association for GNAT_ENTITY and clear it before the call. */
tree gnu_decl = get_gnu_tree (gnat_entity);
save_gnu_tree (gnat_entity, NULL_TREE, false);
gnu_extended_type
= TREE_TYPE (gnat_to_gnu_entity (gnat_entity, gnu_type, false));
gcc_assert (gnu_extended_type);
SET_TYPE_EXTENDED_UNCONSTRAINED_ARRAY (gnu_type, gnu_extended_type);
/* And finally, we restore the original association for GNAT_ENTITY. */
save_gnu_tree (gnat_entity, NULL_TREE, false);
save_gnu_tree (gnat_entity, gnu_decl, false);
}
return gnu_extended_type;
}
/* Return the inlining status of the GNAT subprogram SUBPROG. */
static enum inline_status_t
@@ -5463,6 +5557,7 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition,
&& !Strict_Alignment (gnat_type)
&& RECORD_OR_UNION_TYPE_P (gnu_type)
&& !TYPE_FAT_POINTER_P (gnu_type)
&& !TYPE_EXTENDED_POINTER_P (gnu_type)
&& tree_fits_uhwi_p (TYPE_SIZE (gnu_type)))
{
tree gnu_packable_type = make_packable_type (gnu_type, false, max_align);
@@ -7154,6 +7249,155 @@ elaborate_entity (Entity_Id gnat_entity)
}
}
/* Build the template type GNU_TEMPLATE_TYPE for the array type GNAT_ENTITY.
GNU_TEMPLATE_REFERENCE is an expression to access the template value from
the pointer type. If GNU_INDEX_TYPES is not null, it's an array where the
index types whose bounds are the values of the template are to be stored.
If GNU_MAX_SIZE is not NULL_TREE, it's a tree where the maximum size of
the array type is computed. DEBUG_INFO_P is true if debug info needs to
be output for this type. */
void
build_template_type (Entity_Id gnat_entity, tree gnu_template_type,
tree gnu_template_reference,
tree *gnu_index_types, tree &gnu_max_size,
bool debug_info_p)
{
const bool convention_fortran_p
= (Convention (gnat_entity) == Convention_Fortran);
const int ndim = Number_Dimensions (gnat_entity);
tree *gnu_temp_fields = XALLOCAVEC (tree, ndim);
Entity_Id gnat_index;
int index;
tree template_fields = TYPE_FIELDS (gnu_template_type);
const bool template_exists_p = template_fields != NULL_TREE;
/* Now create the GCC type for each index and add the fields for that
index to the template. */
for (index = (convention_fortran_p ? ndim - 1 : 0),
gnat_index = First_Index (gnat_entity);
IN_RANGE (index, 0, ndim - 1);
index += (convention_fortran_p ? - 1 : 1),
gnat_index = Next_Index (gnat_index))
{
const Entity_Id gnat_index_type = Etype (gnat_index);
const bool is_flb = Is_Fixed_Lower_Bound_Index_Subtype (gnat_index_type);
tree gnu_index_type = get_unpadded_type (gnat_index_type);
tree gnu_orig_min = TYPE_MIN_VALUE (gnu_index_type);
tree gnu_orig_max = TYPE_MAX_VALUE (gnu_index_type);
tree gnu_index_base_type = get_base_type (gnu_index_type);
tree gnu_lb_field, gnu_hb_field;
tree gnu_min, gnu_max, gnu_high;
char field_name[16];
/* Update the maximum size of the array in elements. */
if (gnu_max_size)
gnu_max_size
= update_n_elem (gnu_max_size, gnu_orig_min, gnu_orig_max);
/* Now build the self-referential bounds of the index type. */
gnu_index_type = maybe_character_type (gnu_index_type);
gnu_index_base_type = maybe_character_type (gnu_index_base_type);
if (template_fields != NULL_TREE)
{
gnu_lb_field = template_fields;
template_fields = DECL_CHAIN (template_fields);
gnu_hb_field = template_fields;
template_fields = DECL_CHAIN (template_fields);
}
else
{
/* Make the FIELD_DECLs for the low and high bounds of this
type and then make extractions of these fields from the
template. */
sprintf (field_name, "LB%d", index);
gnu_lb_field = create_field_decl (get_identifier (field_name),
gnu_index_type,
gnu_template_type, NULL_TREE,
NULL_TREE, 0, 0);
/* Mark the field specifically for INSTANTIATE_LOAD_IN_EXPR. */
DECL_DISCRIMINANT_NUMBER (gnu_lb_field) = integer_minus_one_node;
Sloc_to_locus (Sloc (gnat_entity), &DECL_SOURCE_LOCATION (gnu_lb_field));
field_name[0] = 'U';
gnu_hb_field = create_field_decl (get_identifier (field_name),
gnu_index_type,
gnu_template_type, NULL_TREE,
NULL_TREE, 0, 0);
/* Mark the field specifically for INSTANTIATE_LOAD_IN_EXPR. */
DECL_DISCRIMINANT_NUMBER (gnu_hb_field) = integer_minus_one_node;
Sloc_to_locus (Sloc (gnat_entity), &DECL_SOURCE_LOCATION (gnu_hb_field));
gnu_temp_fields[index] = chainon (gnu_lb_field, gnu_hb_field);
}
if (gnu_index_types)
{
/* We can't use build_component_ref here since the template type
isn't complete yet. */
if (!is_flb)
{
gnu_orig_min
= build3 (COMPONENT_REF, TREE_TYPE (gnu_lb_field),
gnu_template_reference, gnu_lb_field,
NULL_TREE);
TREE_READONLY (gnu_orig_min) = 1;
}
gnu_orig_max = build3 (COMPONENT_REF, TREE_TYPE (gnu_hb_field),
gnu_template_reference, gnu_hb_field,
NULL_TREE);
TREE_READONLY (gnu_orig_max) = 1;
gnu_min = convert (sizetype, gnu_orig_min);
gnu_max = convert (sizetype, gnu_orig_max);
/* Compute the size of this dimension. See the E_Array_Subtype
case of gnat_to_gnu_entity for the rationale. */
if (is_flb
&& Nkind (gnat_index) == N_Subtype_Indication
&& flb_cannot_be_superflat (gnat_index))
gnu_high = gnu_max;
else
gnu_high
= build3 (COND_EXPR, sizetype,
build2 (GE_EXPR, boolean_type_node,
gnu_orig_max, gnu_orig_min),
gnu_max,
TREE_CODE (gnu_min) == INTEGER_CST
? int_const_binop (MINUS_EXPR, gnu_min, size_one_node)
: size_binop (MINUS_EXPR, gnu_min, size_one_node));
/* Make a range type with the new range in the Ada base type.
Then make an index type with the size range in sizetype. */
gnu_index_types[index]
= create_index_type (gnu_min, gnu_high,
create_range_type (gnu_index_base_type,
gnu_orig_min,
gnu_orig_max),
gnat_entity);
TYPE_NAME (gnu_index_types[index])
= create_concat_name (gnat_entity, field_name);
}
}
if (!template_exists_p)
{
TYPE_NAMELESS (gnu_template_type)
= gnat_encodings != DWARF_GNAT_ENCODINGS_ALL;
tree gnu_template_fields = NULL_TREE;
for (index = 0; index < ndim; index++)
gnu_template_fields
= chainon (gnu_template_fields, gnu_temp_fields[index]);
finish_record_type (gnu_template_type, gnu_template_fields, 0, debug_info_p);
}
}
/* Prepend to ATTR_LIST an entry for an attribute with provided TYPE,
NAME, ARGS and ERROR_POINT. */
@@ -7321,8 +7565,7 @@ static tree
elaborate_expression_1 (tree gnu_expr, Entity_Id gnat_entity, const char *s,
bool definition, bool need_for_debug)
{
const bool expr_public_p = Is_Public (gnat_entity);
const bool expr_global_p = expr_public_p || global_bindings_p ();
const bool expr_global_p = Is_Public (gnat_entity) || global_bindings_p ();
bool expr_variable_p, use_variable;
/* If GNU_EXPR contains a placeholder, just return it. We rely on the fact
@@ -7372,7 +7615,7 @@ elaborate_expression_1 (tree gnu_expr, Entity_Id gnat_entity, const char *s,
if (need_for_debug
&& gnat_encodings != DWARF_GNAT_ENCODINGS_ALL
&& (TREE_CONSTANT (gnu_expr)
|| (!expr_public_p
|| (!Is_Public (gnat_entity)
&& DECL_P (gnu_expr)
&& !DECL_IGNORED_P (gnu_expr))))
need_for_debug = false;
@@ -7391,7 +7634,8 @@ elaborate_expression_1 (tree gnu_expr, Entity_Id gnat_entity, const char *s,
tree gnu_decl
= create_var_decl (create_concat_name (gnat_entity, s), NULL_TREE,
TREE_TYPE (gnu_expr), gnu_expr, true,
expr_public_p, !definition && expr_global_p,
Is_Public (gnat_entity), Is_Link_Once (gnat_entity),
!definition && expr_global_p,
expr_global_p, false, true,
Needs_Debug_Info (gnat_entity),
NULL, gnat_entity, false);
@@ -7775,6 +8019,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
if (!needs_strict_alignment
&& RECORD_OR_UNION_TYPE_P (gnu_field_type)
&& !TYPE_FAT_POINTER_P (gnu_field_type)
&& !TYPE_EXTENDED_POINTER_P (gnu_field_type)
&& tree_fits_uhwi_p (TYPE_SIZE (gnu_field_type))
&& (packed == 1
|| is_bitfield
@@ -7972,6 +8217,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
if (!needs_strict_alignment
&& RECORD_OR_UNION_TYPE_P (gnu_field_type)
&& !TYPE_FAT_POINTER_P (gnu_field_type)
&& !TYPE_EXTENDED_POINTER_P (gnu_field_type)
&& TYPE_MODE (gnu_field_type) == BLKmode
&& is_bitfield)
gnu_field_type = make_packable_type (gnu_field_type, true, 1);
@@ -9698,7 +9944,9 @@ validate_size (Uint uint_size, tree gnu_type, Entity_Id gnat_object,
/* If this is an access type or a fat pointer, the minimum size is that given
by the default pointer mode. */
if (TREE_CODE (gnu_type) == POINTER_TYPE || TYPE_IS_FAT_POINTER_P (gnu_type))
if (TREE_CODE (gnu_type) == POINTER_TYPE
|| TYPE_IS_FAT_POINTER_P (gnu_type)
|| TYPE_IS_EXTENDED_POINTER_P (gnu_type))
old_size = bitsize_int (GET_MODE_BITSIZE (ptr_mode));
/* Issue an error either if the default size of the object isn't a constant
@@ -9814,7 +10062,8 @@ set_rm_size (Uint uint_size, tree gnu_type, Entity_Id gnat_entity)
/* ...or the Ada size for record and union types. */
else if (RECORD_OR_UNION_TYPE_P (gnu_type)
&& !TYPE_FAT_POINTER_P (gnu_type))
&& !TYPE_FAT_POINTER_P (gnu_type)
&& !TYPE_EXTENDED_POINTER_P (gnu_type))
SET_TYPE_ADA_SIZE (gnu_type, size);
}
@@ -10618,6 +10867,7 @@ copy_and_substitute_in_layout (Entity_Id gnat_new_type,
gnu_size = DECL_SIZE (gnu_old_field);
if (RECORD_OR_UNION_TYPE_P (gnu_field_type)
&& !TYPE_FAT_POINTER_P (gnu_field_type)
&& !TYPE_EXTENDED_POINTER_P (gnu_field_type)
&& tree_fits_uhwi_p (TYPE_SIZE (gnu_field_type)))
gnu_field_type = make_packable_type (gnu_field_type, true, 0);
}
@@ -10990,6 +11240,7 @@ rm_size (tree gnu_type)
/* For record or union types, we store the size explicitly. */
if (RECORD_OR_UNION_TYPE_P (gnu_type)
&& !TYPE_FAT_POINTER_P (gnu_type)
&& !TYPE_EXTENDED_POINTER_P (gnu_type)
&& TYPE_ADA_SIZE (gnu_type))
return TYPE_ADA_SIZE (gnu_type);
+76 -15
View File
@@ -49,6 +49,14 @@ extern tree gnat_to_gnu_field_decl (Entity_Id gnat_entity);
the GCC type corresponding to that entity. */
extern tree gnat_to_gnu_type (Entity_Id gnat_entity);
/* Similar, but GNAT_ENTITY is assumed to refer to a GNAT type. Return
the unpadded version of the GCC type corresponding to that entity. */
extern tree get_unpadded_type (Entity_Id gnat_entity);
/* Similar, but GNAT_ENTITY is assumed to refer to a GNAT type. Return
the extended version of the GCC type corresponding to that entity. */
extern tree get_unpadded_extended_type (Entity_Id gnat_entity);
/* Update the GCC tree previously built for the profiles involving GNU_TYPE,
a dummy type which appears in profiles. */
extern void update_profiles_with (tree gnu_type);
@@ -107,8 +115,17 @@ extern Entity_Id Gigi_Equivalent_Type (Entity_Id gnat_entity);
be elaborated at the point of its definition, but do nothing else. */
extern void elaborate_entity (Entity_Id gnat_entity);
/* Get the unpadded version of a GNAT type. */
extern tree get_unpadded_type (Entity_Id gnat_entity);
/* Build the template type GNU_TEMPLATE_TYPE for the array type GNAT_ENTITY.
GNU_TEMPLATE_REFERENCE is an expression to access the template value from
the pointer type. If GNU_INDEX_TYPES is not null, it's an array where the
index types whose bounds are the values of the template are to be stored.
If GNU_MAX_SIZE is not NULL_TREE, it's a tree where the maximum size of
the array type is computed. DEBUG_INFO_P is true if debug info needs to
be output for this type. */
extern void build_template_type (Entity_Id gnat_entity, tree gnu_template_type,
tree gnu_template_reference,
tree *gnu_index_types, tree &gnu_max_size,
bool debug_info_p);
/* Create a record type that contains a SIZE bytes long field of TYPE with a
starting bit position so that it is aligned to ALIGN bits, and leaving at
@@ -388,15 +405,20 @@ enum standard_datatypes
/* Function declaration node for run-time reallocation function. */
ADT_realloc_decl,
/* Function decl node for 64-bit multiplication with overflow checking. */
/* Function decl nodes for 64-bit multiplication with overflow checking. */
ADT_mulv64_decl,
ADT_uns_mulv64_decl,
/* Function decl node for 128-bit multiplication with overflow checking. */
/* Function decl nodes for 128-bit multiplication with overflow checking. */
ADT_mulv128_decl,
ADT_uns_mulv128_decl,
/* Identifier for the name of the _Parent field in tagged record types. */
ADT_parent_name_id,
/* Identifier for the name of the _Tag field in tagged record types. */
ADT_tag_name_id,
/* Identifier for the name of the Not_Handled_By_Others field. */
ADT_not_handled_by_others_name_id,
@@ -455,8 +477,11 @@ extern GTY(()) tree gnat_raise_decls_ext[(int) LAST_REASON_CODE + 1];
#define free_decl gnat_std_decls[(int) ADT_free_decl]
#define realloc_decl gnat_std_decls[(int) ADT_realloc_decl]
#define mulv64_decl gnat_std_decls[(int) ADT_mulv64_decl]
#define uns_mulv64_decl gnat_std_decls[(int) ADT_uns_mulv64_decl]
#define mulv128_decl gnat_std_decls[(int) ADT_mulv128_decl]
#define uns_mulv128_decl gnat_std_decls[(int) ADT_uns_mulv128_decl]
#define parent_name_id gnat_std_decls[(int) ADT_parent_name_id]
#define tag_name_id gnat_std_decls[(int) ADT_tag_name_id]
#define not_handled_by_others_name_id \
gnat_std_decls[(int) ADT_not_handled_by_others_name_id]
#define reraise_zcx_decl gnat_std_decls[(int) ADT_reraise_zcx_decl]
@@ -570,6 +595,11 @@ extern tree get_dummy_type (Entity_Id gnat_type);
extern void build_dummy_unc_pointer_types (Entity_Id gnat_desig_type,
tree gnu_desig_type);
/* Build dummy extended access types whose designated type is specified by
GNAT_DESIG_TYPE/GNU_DESIG_TYPE and attach them to the latter. */
extern tree build_dummy_unc_pointer_types_ext (Entity_Id gnat_desig_type,
tree gnu_desig_type);
/* Record TYPE as a builtin type for Ada. NAME is the name of the type.
ARTIFICIAL_P is true if the type was generated by the compiler. */
extern void record_builtin_type (const char *name, tree type,
@@ -582,6 +612,10 @@ extern void finish_character_type (tree char_type);
finish constructing the record type as a fat pointer type. */
extern void finish_fat_pointer_type (tree record_type, tree field_list);
/* Given a record type RECORD_TYPE and a list of FIELD_DECL nodes FIELD_LIST,
finish constructing the record type as an extended access type. */
extern void finish_extended_pointer_type (tree record_type, tree field_list);
/* Given a record type RECORD_TYPE and a list of FIELD_DECL nodes FIELD_LIST,
finish constructing the record or union type. If REP_LEVEL is zero, this
record has no representation clause and so will be entirely laid out here.
@@ -645,6 +679,9 @@ extern tree create_type_decl (tree name, tree type, bool artificial_p,
definition to be made visible outside of the current compilation unit, for
instance variable definitions in a package specification.
LINKONCE_FLAG is true if the entity can be defined in multiple compilation
units without generating a linker error.
EXTERN_FLAG is true when processing an external variable declaration (as
opposed to a definition: no storage is to be allocated for the variable).
@@ -662,8 +699,8 @@ extern tree create_type_decl (tree name, tree type, bool artificial_p,
GNAT_NODE is used for the position of the decl. */
extern tree create_var_decl (tree name, tree asm_name, tree type, tree init,
bool const_flag, bool public_flag,
bool extern_flag, bool static_flag,
bool volatile_flag,
bool linkonce_flag, bool extern_flag,
bool static_flag, bool volatile_flag,
bool artificial_p, bool debug_info_p,
struct attrib *attr_list, Node_Id gnat_node,
bool const_decl_allowed_p = true);
@@ -696,6 +733,9 @@ extern tree create_label_decl (tree name, Node_Id gnat_node);
PUBLIC_FLAG is true if this is for a reference to a public entity or for a
definition to be made visible outside of the current compilation unit.
LINKONCE_FLAG is true if the entity can be defined in multiple compilation
units without generating a linker error.
EXTERN_FLAG is true when processing an external subprogram declaration.
ARTIFICIAL_P is true if the subprogram was generated by the compiler.
@@ -710,10 +750,11 @@ extern tree create_label_decl (tree name, Node_Id gnat_node);
extern tree create_subprog_decl (tree name, tree asm_name, tree type,
tree param_decl_list,
enum inline_status_t inline_status,
bool public_flag, bool extern_flag,
bool artificial_p, bool debug_info_p,
bool definition, struct attrib *attr_list,
Node_Id gnat_node);
bool public_flag, bool linkonce_flag,
bool extern_flag, bool artificial_p,
bool debug_info_p, bool definition,
struct attrib *attr_list = NULL,
Node_Id gnat_node = Empty);
/* Given a subprogram declaration DECL, its assembler name and its type,
finish constructing the subprogram declaration from ASM_NAME and TYPE. */
@@ -753,11 +794,9 @@ extern tree build_unc_object_type (tree template_type, tree object_type,
tree name, bool artificial_p,
bool debug_info_p);
/* Same as build_unc_object_type, but taking a thin or fat pointer type
instead of the template type. */
extern tree build_unc_object_type_from_ptr (tree thin_fat_ptr_type,
tree object_type, tree name,
bool debug_info_p);
/* Same, taking a pointer type instead of a template type. */
extern tree build_unc_object_type_from_ptr (tree ptr_type, tree object_type,
tree name, bool debug_info_p);
/* Update anything previously pointing to OLD_TYPE to point to NEW_TYPE. In
the normal case this is just two adjustments, but we have more to do
@@ -1120,6 +1159,28 @@ call_is_atomic_load (tree exp)
return BUILT_IN_ATOMIC_LOAD_N <= code && code <= BUILT_IN_ATOMIC_LOAD_16;
}
/* Return true if TYPE is a tagged type or a CW-equivalent type. */
static inline bool
type_is_tagged_or_cw_equivalent (tree type)
{
if (!RECORD_OR_UNION_TYPE_P (type))
return false;
tree field = TYPE_FIELDS (type);
if (!field)
return false;
/* The tag can be put into the REP part of a record type. */
if (DECL_INTERNAL_P (field))
return type_is_tagged_or_cw_equivalent (TREE_TYPE (field));
tree name = DECL_NAME (field);
/* See Exp_Util.Make_CW_Equivalent_Type for the CW-equivalent case. */
return name == tag_name_id || name == parent_name_id;
}
/* Return true if TYPE is padding a self-referential type. */
static inline bool
+5 -1
View File
@@ -531,7 +531,9 @@ gnat_print_type (FILE *file, tree node, int indent)
break;
case RECORD_TYPE:
if (TYPE_FAT_POINTER_P (node) || TYPE_CONTAINS_TEMPLATE_P (node))
if (TYPE_EXTENDED_POINTER_P (node)
|| TYPE_FAT_POINTER_P (node)
|| TYPE_CONTAINS_TEMPLATE_P (node))
print_node (file, "unconstrained array",
TYPE_UNCONSTRAINED_ARRAY (node), indent + 4);
else
@@ -837,6 +839,8 @@ gnat_get_array_descr_info (const_tree const_type,
if (TYPE_IMPL_PACKED_ARRAY_P (array_type)
&& TYPE_ORIGINAL_PACKED_ARRAY (array_type))
array_type = TYPE_ORIGINAL_PACKED_ARRAY (array_type);
if (TREE_CODE (array_type) != ARRAY_TYPE)
return false;
/* Shift back the address to get the address of the template. */
tree shift_amount
+151 -77
View File
@@ -319,7 +319,7 @@ gigi (Node_Id gnat_root,
{
Node_Id gnat_iter;
Entity_Id gnat_literal;
tree t, ftype, int64_type;
tree t, ftype;
struct elab_info *info;
int i;
@@ -427,14 +427,14 @@ gigi (Node_Id gnat_root,
gcc_assert (t == boolean_false_node);
t = create_var_decl (get_entity_name (gnat_literal), NULL_TREE,
boolean_type_node, t, true, false, false, false, false,
true, false, NULL, gnat_literal);
false, true, false, NULL, gnat_literal);
save_gnu_tree (gnat_literal, t, false);
gnat_literal = Next_Literal (gnat_literal);
t = UI_To_gnu (Enumeration_Rep (gnat_literal), boolean_type_node);
gcc_assert (t == boolean_true_node);
t = create_var_decl (get_entity_name (gnat_literal), NULL_TREE,
boolean_type_node, t, true, false, false, false, false,
true, false, NULL, gnat_literal);
false, true, false, NULL, gnat_literal);
save_gnu_tree (gnat_literal, t, false);
/* Declare the building blocks of function nodes. */
@@ -446,35 +446,44 @@ gigi (Node_Id gnat_root,
= create_subprog_decl (get_identifier ("__gnat_malloc"), NULL_TREE,
build_function_type_list (ptr_type_node, sizetype,
NULL_TREE),
NULL_TREE, is_default, true, true, true, false,
false, NULL, Empty);
NULL_TREE, is_default, true, false, true, true,
false, false);
DECL_IS_MALLOC (malloc_decl) = 1;
free_decl
= create_subprog_decl (get_identifier ("__gnat_free"), NULL_TREE,
build_function_type_list (void_type_node,
ptr_type_node, NULL_TREE),
NULL_TREE, is_default, true, true, true, false,
false, NULL, Empty);
NULL_TREE, is_default, true, false, true, true,
false, false);
realloc_decl
= create_subprog_decl (get_identifier ("__gnat_realloc"), NULL_TREE,
build_function_type_list (ptr_type_node,
ptr_type_node, sizetype,
NULL_TREE),
NULL_TREE, is_default, true, true, true, false,
false, NULL, Empty);
NULL_TREE, is_default, true, false, true, true,
false, false);
/* This is used for 64-bit multiplication with overflow checking. */
int64_type = gnat_type_for_size (64, 0);
tree int64_type = gnat_type_for_size (64, 0);
mulv64_decl
= create_subprog_decl (get_identifier ("__gnat_mulv64"), NULL_TREE,
build_function_type_list (int64_type, int64_type,
int64_type, NULL_TREE),
NULL_TREE, is_default, true, true, true, false,
false, NULL, Empty);
NULL_TREE, is_default, true, false, true, true,
false, false);
strub_make_callable (mulv64_decl);
tree uint64_type = gnat_type_for_size (64, 1);
uns_mulv64_decl
= create_subprog_decl (get_identifier ("__gnat_uns_mulv64"), NULL_TREE,
build_function_type_list (uint64_type, uint64_type,
uint64_type, NULL_TREE),
NULL_TREE, is_default, true, false, true, true,
false, false);
strub_make_callable (uns_mulv64_decl);
if (Enable_128bit_Types)
{
tree int128_type = gnat_type_for_size (128, 0);
@@ -484,14 +493,28 @@ gigi (Node_Id gnat_root,
int128_type,
int128_type,
NULL_TREE),
NULL_TREE, is_default, true, true, true, false,
false, NULL, Empty);
NULL_TREE, is_default, true, false, true, true,
false, false);
strub_make_callable (mulv128_decl);
tree uint128_type = gnat_type_for_size (128, 1);
uns_mulv128_decl
= create_subprog_decl (get_identifier ("__gnat_uns_mulv128"), NULL_TREE,
build_function_type_list (uint128_type,
uint128_type,
uint128_type,
NULL_TREE),
NULL_TREE, is_default, true, false, true, true,
false, false);
strub_make_callable (uns_mulv128_decl);
}
/* Name of the _Parent field in tagged record types. */
parent_name_id = get_identifier (Get_Name_String (Name_uParent));
/* Name of the _Tag field in tagged record types. */
tag_name_id = get_identifier (Get_Name_String (Name_uTag));
/* Name of the Not_Handled_By_Others field in exception record types. */
not_handled_by_others_name_id = get_identifier ("not_handled_by_others");
@@ -503,7 +526,7 @@ gigi (Node_Id gnat_root,
(get_identifier ("__gnat_set_exception_parameter"), NULL_TREE,
build_function_type_list (void_type_node, ptr_type_node, ptr_type_node,
NULL_TREE),
NULL_TREE, is_default, true, true, true, false, false, NULL, Empty);
NULL_TREE, is_default, true, false, true, true, false, false);
/* Hooks to call when entering/leaving an exception handler. */
ftype = build_function_type_list (ptr_type_node,
@@ -511,8 +534,7 @@ gigi (Node_Id gnat_root,
begin_handler_decl
= create_subprog_decl (get_identifier ("__gnat_begin_handler_v1"),
NULL_TREE, ftype, NULL_TREE,
is_default, true, true, true, false, false, NULL,
Empty);
is_default, true, false, true, true, false, false);
/* __gnat_begin_handler_v1 is not a dummy procedure, but we arrange
for it not to throw. */
TREE_NOTHROW (begin_handler_decl) = 1;
@@ -523,23 +545,20 @@ gigi (Node_Id gnat_root,
end_handler_decl
= create_subprog_decl (get_identifier ("__gnat_end_handler_v1"), NULL_TREE,
ftype, NULL_TREE,
is_default, true, true, true, false, false, NULL,
Empty);
is_default, true, false, true, true, false, false);
ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
unhandled_except_decl
= create_subprog_decl (get_identifier ("__gnat_unhandled_except_handler"),
NULL_TREE, ftype, NULL_TREE,
is_default, true, true, true, false, false, NULL,
Empty);
is_default, true, false, true, true, false, false);
/* Indicate that it never returns. */
ftype = build_qualified_type (ftype, TYPE_QUAL_VOLATILE);
reraise_zcx_decl
= create_subprog_decl (get_identifier ("__gnat_reraise_zcx"), NULL_TREE,
ftype, NULL_TREE,
is_default, true, true, true, false, false, NULL,
Empty);
is_default, true, false, true, true, false, false);
set_call_expr_flags (reraise_zcx_decl, ECF_NORETURN | ECF_XTHROW);
/* Dummy objects to materialize "others" and "all others" in the exception
@@ -549,21 +568,21 @@ gigi (Node_Id gnat_root,
= create_var_decl (get_identifier ("OTHERS"),
get_identifier ("__gnat_others_value"),
char_type_node, NULL_TREE,
true, false, true, false, false, true, false,
true, false, false, true, false, false, true, false,
NULL, Empty);
all_others_decl
= create_var_decl (get_identifier ("ALL_OTHERS"),
get_identifier ("__gnat_all_others_value"),
char_type_node, NULL_TREE,
true, false, true, false, false, true, false,
true, false, false, true, false, false, true, false,
NULL, Empty);
unhandled_others_decl
= create_var_decl (get_identifier ("UNHANDLED_OTHERS"),
get_identifier ("__gnat_unhandled_others_value"),
char_type_node, NULL_TREE,
true, false, true, false, false, true, false,
true, false, false, true, false, false, true, false,
NULL, Empty);
/* If in no exception handlers mode, all raise statements are redirected to
@@ -578,8 +597,7 @@ gigi (Node_Id gnat_root,
tree decl
= create_subprog_decl
(get_identifier ("__gnat_last_chance_handler"), NULL_TREE, ftype,
NULL_TREE, is_default, true, true, true, false, false, NULL,
Empty);
NULL_TREE, is_default, true, false, true, true, false, false);
for (i = 0; i < (int) ARRAY_SIZE (gnat_raise_decls); i++)
gnat_raise_decls[i] = decl;
}
@@ -741,8 +759,8 @@ build_raise_check (int check, enum exception_info_kind kind)
ftype = build_qualified_type (ftype, TYPE_QUAL_VOLATILE);
result
= create_subprog_decl (get_identifier (Name_Buffer), NULL_TREE, ftype,
NULL_TREE, is_default, true, true, true, false,
false, NULL, Empty);
NULL_TREE, is_default, true, false, true, true,
false, false);
strub_make_callable (result);
set_call_expr_flags (result, ECF_NORETURN | ECF_XTHROW);
@@ -1227,6 +1245,10 @@ Identifier_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p)
no order-of-elaboration issue here. */
if (Is_Subprogram (gnat_entity))
gnu_result_type = NULL_TREE;
else if (Nkind (Original_Node (gnat_node)) == N_Explicit_Dereference
&& Is_Extended_Access_Type
(Etype (Prefix (Original_Node (gnat_node)))))
gnu_result_type = get_unpadded_extended_type (gnat_result_type);
else
gnu_result_type = get_unpadded_type (gnat_result_type);
@@ -2010,7 +2032,8 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p,
tree gnu_ptr_type
= TREE_TYPE (gnat_to_gnu (Prefix (gnat_prefix)));
if (TYPE_IS_FAT_OR_THIN_POINTER_P (gnu_ptr_type))
if (TYPE_IS_FAT_OR_THIN_POINTER_P (gnu_ptr_type)
|| TYPE_IS_EXTENDED_POINTER_P (gnu_ptr_type))
gnu_type
= build_unc_object_type_from_ptr (gnu_ptr_type,
gnu_actual_obj_type,
@@ -4026,7 +4049,7 @@ Subprogram_Body_to_gnu (Node_Id gnat_node)
gnu_return_var
= create_var_decl (get_identifier ("RETVAL"), NULL_TREE,
gnu_return_type, NULL_TREE,
false, false, false, false, false,
false, false, false, false, false, false,
true, false, NULL, gnat_subprog);
TREE_VALUE (gnu_return_var_elmt) = gnu_return_var;
}
@@ -4562,7 +4585,7 @@ create_temporary (const char *prefix, tree type)
tree gnu_temp
= create_var_decl (create_tmp_var_name (prefix), NULL_TREE,
type, NULL_TREE,
false, false, false, false, false,
false, false, false, false, false, false,
true, false, NULL, Empty);
return gnu_temp;
}
@@ -5845,7 +5868,7 @@ Exception_Handler_to_gnu (Node_Id gnat_node)
tree exc_ptr
= create_var_decl (get_identifier ("EXPTR"), NULL_TREE,
ptr_type_node, gnu_current_exc_ptr,
true, false, false, false, false, true, true,
true, false, false, false, false, false, true, true,
NULL, gnat_node);
tree prev_gnu_incoming_exc_ptr = gnu_incoming_exc_ptr;
@@ -5860,7 +5883,7 @@ Exception_Handler_to_gnu (Node_Id gnat_node)
ptr_type_node,
build_call_n_expr (begin_handler_decl, 1,
exc_ptr),
true, false, false, false, false,
true, false, false, false, false, false,
true, true, NULL, gnat_node);
/* Declare and initialize the choice parameter, if present. */
@@ -5910,7 +5933,7 @@ Exception_Handler_to_gnu (Node_Id gnat_node)
build_call_expr (builtin_decl_explicit
(BUILT_IN_EH_POINTER),
1, integer_zero_node),
true, false, false, false, false,
true, false, false, false, false, false,
true, true, NULL, gnat_node);
/* CODE: __gnat_end_handler_v1 (EXPTR, EXCLN, EXPRP); */
@@ -5956,7 +5979,7 @@ Compilation_Unit_to_gnu (Node_Id gnat_node)
= create_subprog_decl
(create_concat_name (gnat_unit_entity, body_p ? "elabb" : "elabs"),
NULL_TREE, void_ftype, NULL_TREE,
is_default, true, false, false, true, false, NULL, gnat_unit);
is_default, true, false, false, false, true, false, NULL, gnat_unit);
struct elab_info *info;
vec_safe_push (gnu_elab_proc_stack, gnu_elab_proc_decl);
@@ -6870,9 +6893,22 @@ gnat_to_gnu (Node_Id gnat_node)
&& (Is_Array_Type (Etype (gnat_temp))
|| Is_Record_Type (Etype (gnat_temp))
|| Is_Concurrent_Type (Etype (gnat_temp)))))
gnat_to_gnu_entity (gnat_temp,
gnat_to_gnu (Renamed_Object (gnat_temp)),
true);
{
gnu_expr = gnat_to_gnu (Renamed_Object (gnat_temp));
/* The elaboration of object renamings present in the source code
never needs to be deferred. But regular objects may be turned
into renamings during expansion and their elaboration may need
to be deferred, in which case we expect the renamed references
to have been stabilized, so we do not do it again here. */
if (Present (Freeze_Node (gnat_temp)))
{
gcc_assert (!Comes_From_Source (gnat_node));
save_gnu_tree (gnat_node, gnu_expr, true);
}
else
gnat_to_gnu_entity (gnat_temp, gnu_expr, true);
}
break;
case N_Exception_Renaming_Declaration:
@@ -6938,7 +6974,12 @@ gnat_to_gnu (Node_Id gnat_node)
case N_Explicit_Dereference:
/* Make sure the designated type is complete before dereferencing. */
gnu_result_type = get_unpadded_type (Etype (gnat_node));
if (Is_Extended_Access_Type (Etype (Prefix (gnat_node)))
&& !Is_Constrained (Etype (gnat_node)))
gnu_result_type = get_unpadded_extended_type (Etype (gnat_node));
else
gnu_result_type = get_unpadded_type (Etype (gnat_node));
gnu_result = gnat_to_gnu (Prefix (gnat_node));
gnu_result = build_unary_op (INDIRECT_REF, NULL_TREE, gnu_result);
@@ -7171,7 +7212,7 @@ gnat_to_gnu (Node_Id gnat_node)
(Entity (Prefix (gnat_node)),
attr == Attr_Elab_Body ? "elabb" : "elabs"),
NULL_TREE, void_ftype, NULL_TREE, is_default,
true, true, true, true, false, NULL,
true, false, true, true, true, false, NULL,
gnat_node);
gnu_result = Attribute_to_gnu (gnat_node, &gnu_result_type, attr);
@@ -7284,7 +7325,12 @@ gnat_to_gnu (Node_Id gnat_node)
tree gnu_obj_type = TREE_TYPE (gnu_result_type);
unsigned int oalign = TYPE_ALIGN (gnu_obj_type);
if (align != 0 && align < oalign && !TYPE_ALIGN_OK (gnu_obj_type))
/* Skip tagged types because conversions to the class-wide type are
translated into conversions to the root type, which may be less
aligned than some of its derived types. */
if (align != 0
&& align < oalign
&& !type_is_tagged_or_cw_equivalent (gnu_obj_type))
post_error_ne_tree_2
("??source alignment (^) '< alignment of & (^)",
gnat_node, Designated_Type (Etype (gnat_node)),
@@ -7504,12 +7550,11 @@ gnat_to_gnu (Node_Id gnat_node)
gnu_max_shift = convert (gnu_type, gnu_max_shift);
}
/* For signed integer addition, subtraction and multiplication, do an
/* For integer addition, subtraction and multiplication, perform an
overflow check if required. */
if (Do_Overflow_Check (gnat_node)
&& (code == PLUS_EXPR || code == MINUS_EXPR || code == MULT_EXPR)
&& !TYPE_UNSIGNED (gnu_type)
&& !FLOAT_TYPE_P (gnu_type))
if ((code == PLUS_EXPR || code == MINUS_EXPR || code == MULT_EXPR)
&& !FLOAT_TYPE_P (gnu_type)
&& Do_Overflow_Check (gnat_node))
gnu_result
= build_binary_op_trapv (code, gnu_type, gnu_lhs, gnu_rhs,
gnat_node);
@@ -7590,11 +7635,11 @@ gnat_to_gnu (Node_Id gnat_node)
gnu_expr = gnat_to_gnu (Right_Opnd (gnat_node));
gnu_result_type = get_unpadded_type (Etype (gnat_node));
/* For signed integer negation and absolute value, do an overflow check
/* For integer negation and absolute value, perform an overflow check
if required. */
if (Do_Overflow_Check (gnat_node)
&& !TYPE_UNSIGNED (gnu_result_type)
&& !FLOAT_TYPE_P (gnu_result_type))
if ((gnu_codes[kind] == NEGATE_EXPR || gnu_codes[kind] == ABS_EXPR)
&& !FLOAT_TYPE_P (gnu_result_type)
&& Do_Overflow_Check (gnat_node))
gnu_result
= build_unary_op_trapv (gnu_codes[kind], gnu_result_type, gnu_expr,
gnat_node);
@@ -9791,10 +9836,15 @@ process_freeze_entity (Node_Id gnat_node)
}
else
{
/* For an object whose elaboration is deferred, the GCC tree of the
declaration, if any, is the initialization expression. */
const Node_Id gnat_decl = Declaration_Node (gnat_entity);
tree gnu_init
= (Nkind (Declaration_Node (gnat_entity)) == N_Object_Declaration
&& present_gnu_tree (Declaration_Node (gnat_entity)))
? get_gnu_tree (Declaration_Node (gnat_entity)) : NULL_TREE;
= (Nkind (gnat_decl) == N_Object_Declaration
|| Nkind (gnat_decl) == N_Object_Renaming_Declaration)
&& Present (Freeze_Node (gnat_entity))
&& present_gnu_tree (gnat_decl)
? get_gnu_tree (gnat_decl) : NULL_TREE;
gnu_new = gnat_to_gnu_entity (gnat_entity, gnu_init, true);
}
@@ -9959,12 +10009,25 @@ build_unary_op_trapv (enum tree_code code, tree gnu_type, tree operand,
{
gcc_assert (code == NEGATE_EXPR || code == ABS_EXPR);
tree gnu_expr, check;
operand = gnat_protect_expr (operand);
return emit_check (build_binary_op (EQ_EXPR, boolean_type_node,
operand, TYPE_MIN_VALUE (gnu_type)),
build_unary_op (code, gnu_type, operand),
CE_Overflow_Check_Failed, gnat_node);
gnu_expr = build_unary_op (code, gnu_type, operand);
if (TYPE_UNSIGNED (gnu_type))
{
if (code == ABS_EXPR)
return gnu_expr;
else
check = build_binary_op (NE_EXPR, boolean_type_node,
operand, TYPE_MIN_VALUE (gnu_type));
}
else
check = build_binary_op (EQ_EXPR, boolean_type_node,
operand, TYPE_MIN_VALUE (gnu_type));
return emit_check (check, gnu_expr, CE_Overflow_Check_Failed, gnat_node);
}
/* Make a binary operation of kind CODE using build_binary_op, but guard
@@ -10017,21 +10080,29 @@ build_binary_op_trapv (enum tree_code code, tree gnu_type, tree left,
/* Never inline a 64-bit mult for a 32-bit target, it's way too long. */
if (code == MULT_EXPR && precision == 64 && BITS_PER_WORD < 64)
{
tree int64 = gnat_type_for_size (64, 0);
tree int64 = gnat_type_for_size (64, TYPE_UNSIGNED (gnu_type));
Check_Restriction_No_Dependence_On_System (Name_Arith_64, gnat_node);
return convert (gnu_type, build_call_n_expr (mulv64_decl, 2,
convert (int64, lhs),
convert (int64, rhs)));
return
convert (gnu_type, build_call_n_expr (TYPE_UNSIGNED (gnu_type)
? uns_mulv64_decl
: mulv64_decl,
2,
convert (int64, lhs),
convert (int64, rhs)));
}
/* Likewise for a 128-bit mult and a 64-bit target. */
else if (code == MULT_EXPR && precision == 128 && BITS_PER_WORD < 128)
{
tree int128 = gnat_type_for_size (128, 0);
tree int128 = gnat_type_for_size (128, TYPE_UNSIGNED (gnu_type));
Check_Restriction_No_Dependence_On_System (Name_Arith_128, gnat_node);
return convert (gnu_type, build_call_n_expr (mulv128_decl, 2,
convert (int128, lhs),
convert (int128, rhs)));
return
convert (gnu_type, build_call_n_expr (TYPE_UNSIGNED (gnu_type)
? uns_mulv128_decl
: mulv128_decl,
2,
convert (int128, lhs),
convert (int128, rhs)));
}
enum internal_fn icode;
@@ -10065,7 +10136,7 @@ build_binary_op_trapv (enum tree_code code, tree gnu_type, tree left,
}
/* If one operand is a constant, we expose the overflow condition to enable
a subsequent simplication or even elimination. */
a subsequent simplification or even elimination. */
switch (code)
{
case PLUS_EXPR:
@@ -10085,21 +10156,24 @@ build_binary_op_trapv (enum tree_code code, tree gnu_type, tree left,
break;
case MINUS_EXPR:
if (TREE_CODE (lhs) == INTEGER_CST)
if (TREE_CODE (lhs) == INTEGER_CST && TYPE_UNSIGNED (gnu_type))
/* In the unsigned case, overflow when rhs > lhs - type_min. */
check = build_binary_op (GT_EXPR, boolean_type_node, rhs,
build_binary_op (MINUS_EXPR, gnu_type,
lhs, type_min));
else if (TREE_CODE (lhs) == INTEGER_CST)
{
sgn = tree_int_cst_sgn (lhs);
if (sgn > 0)
/* When lhs > 0, overflow when rhs < lhs - type_max. */
if (sgn >= 0)
/* When lhs >= 0, overflow when rhs < lhs - type_max. */
check = build_binary_op (LT_EXPR, boolean_type_node, rhs,
build_binary_op (MINUS_EXPR, gnu_type,
lhs, type_max));
else if (sgn < 0)
else
/* When lhs < 0, overflow when rhs > lhs - type_min. */
check = build_binary_op (GT_EXPR, boolean_type_node, rhs,
build_binary_op (MINUS_EXPR, gnu_type,
lhs, type_min));
else
return gnu_expr;
}
else
{
@@ -10569,8 +10643,8 @@ addressable_p (tree gnu_expr, tree gnu_type, bool compg)
&& (!STRICT_ALIGNMENT
|| TYPE_ALIGN (type) <= TYPE_ALIGN (inner_type)
|| TYPE_ALIGN (inner_type) >= BIGGEST_ALIGNMENT
|| TYPE_ALIGN_OK (type)
|| TYPE_ALIGN_OK (inner_type))))
|| type_is_tagged_or_cw_equivalent (type)
|| type_is_tagged_or_cw_equivalent (inner_type))))
&& addressable_p (TREE_OPERAND (gnu_expr, 0), NULL_TREE,
compg));
}
@@ -11253,7 +11327,7 @@ static bool
use_alias_for_thunk_p (tree target)
{
/* We cannot generate a local call in this case. */
if (DECL_EXTERNAL (target))
if (DECL_EXTERNAL (target) || DECL_ONE_ONLY (target))
return false;
/* The call is already local in this case. */
+250 -40
View File
@@ -392,7 +392,6 @@ static tree fold_bit_position (const_tree);
static tree compute_related_constant (tree, tree);
static tree split_plus (tree, tree *);
static tree float_type_for_precision (int, machine_mode);
static tree convert_to_fat_pointer (tree, tree);
static unsigned int scale_by_factor_of (tree, unsigned int);
/* Linked list used as a queue to defer the initialization of the DECL_CONTEXT
@@ -616,6 +615,59 @@ build_dummy_unc_pointer_types (Entity_Id gnat_desig_type, tree gnu_desig_type)
TYPE_OBJECT_RECORD_TYPE (gnu_desig_type) = gnu_object_type;
}
/* Build dummy extended access types whose designated type is specified by
GNAT_DESIG_TYPE/GNU_DESIG_TYPE and attach them to the latter. */
tree
build_dummy_unc_pointer_types_ext (Entity_Id gnat_desig_type, tree gnu_desig_type)
{
tree gnu_template_type, gnu_array_type, gnu_ptr_array;
tree gnu_ext_acc_type = make_node (RECORD_TYPE);
tree fields, dummy = NULL_TREE;
gnu_template_type = make_node (RECORD_TYPE);
TYPE_NAME (gnu_template_type) = create_concat_name (gnat_desig_type, "XUBEA");
TYPE_DUMMY_P (gnu_template_type) = 1;
/* This will also set TYPE_POINTER_TO field for the template type, even if
we don't need it here. */
build_pointer_type (gnu_template_type);
/* The following call only builds the template record, but other dependent
types or other more complex expressions for bounds are NOT created.
This allows the size of an extended access to be computed, but it must be
completed later. */
build_template_type (gnat_desig_type, gnu_template_type, NULL_TREE, NULL,
dummy, false);
TYPE_CONTEXT (gnu_template_type) = gnu_ext_acc_type;
gnu_array_type = make_node (ENUMERAL_TYPE);
TYPE_NAME (gnu_array_type) = create_concat_name (gnat_desig_type, "XUAEA");
TYPE_DUMMY_P (gnu_array_type) = 1;
gnu_ptr_array = build_pointer_type (gnu_array_type);
/* Build a stub DECL to trigger the special processing for fat pointer types
in gnat_pushdecl. */
TYPE_NAME (gnu_ext_acc_type)
= create_type_stub_decl (create_concat_name (gnat_desig_type, "XUPEA"),
gnu_ext_acc_type);
fields = create_field_decl (get_identifier ("P_ARRAY"), gnu_ptr_array,
gnu_ext_acc_type, NULL_TREE, NULL_TREE, 0, 1);
DECL_CHAIN (fields)
= create_field_decl (get_identifier ("BOUNDS"), gnu_template_type,
gnu_ext_acc_type, NULL_TREE, NULL_TREE, 0, 1);
finish_extended_pointer_type (gnu_ext_acc_type, fields);
SET_TYPE_UNCONSTRAINED_ARRAY (gnu_ext_acc_type, gnu_desig_type);
/* Suppress debug info until after the type is completed. */
TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (gnu_ext_acc_type)) = 1;
SET_TYPE_DUMMY_EXT_POINTER_TO (gnu_desig_type, gnu_ext_acc_type);
return gnu_ext_acc_type;
}
/* Return true if we are in the global binding level. */
bool
@@ -937,11 +989,13 @@ gnat_pushdecl (tree decl, Node_Id gnat_node)
}
/* Pointer types aren't named types in the C sense so we need to generate a
typedef in DWARF for them. Also do that for fat pointer types because,
even though they are named types in the C sense, they are still the XUP
types created for the base array type at this point. */
#define TYPE_IS_POINTER_P(NODE) \
(TREE_CODE (NODE) == POINTER_TYPE || TYPE_IS_FAT_POINTER_P (NODE))
typedef in DWARF for them. Also do that for fat and extended pointer types
because, even though they are named types in the C sense, they are still
the XUP[EA] types created for the base array type at this point. */
#define TYPE_IS_POINTER_P(NODE) \
(TREE_CODE (NODE) == POINTER_TYPE \
|| TYPE_IS_FAT_POINTER_P (NODE) \
|| TYPE_IS_EXTENDED_POINTER_P (NODE))
/* For the declaration of a type, set its name either if it isn't already
set or if the previous type name was not derived from a source name.
@@ -973,8 +1027,8 @@ gnat_pushdecl (tree decl, Node_Id gnat_node)
DECL_ORIGINAL_TYPE (decl) = DECL_ORIGINAL_TYPE (TYPE_NAME (t));
else
DECL_ORIGINAL_TYPE (decl) = t;
/* Remark the canonical fat pointer type as artificial. */
if (TYPE_IS_FAT_POINTER_P (t))
/* Remark the canonical fat or extended pointer type as artificial. */
if (TYPE_IS_FAT_POINTER_P (t) || TYPE_IS_EXTENDED_POINTER_P (t))
TYPE_ARTIFICIAL (t) = 1;
t = NULL_TREE;
}
@@ -1725,6 +1779,7 @@ maybe_pad_type (tree type, tree size, unsigned int align,
if (align > 0
&& RECORD_OR_UNION_TYPE_P (type)
&& !TYPE_IS_FAT_POINTER_P (type)
&& !TYPE_IS_EXTENDED_POINTER_P (type)
&& TYPE_MODE (type) == BLKmode
&& !TYPE_BY_REFERENCE_P (type)
&& TREE_CODE (orig_size) == INTEGER_CST
@@ -1795,7 +1850,7 @@ maybe_pad_type (tree type, tree size, unsigned int align,
is a compilation artifact. */
size_unit
= create_var_decl (concat_name (name, "XVZ"), NULL_TREE, sizetype,
size_unit, true, global_bindings_p (),
size_unit, true, global_bindings_p (), false,
!definition && global_bindings_p (), false,
false, true, true, NULL, gnat_entity, false);
TYPE_SIZE_UNIT (record) = size_unit;
@@ -2119,6 +2174,25 @@ finish_fat_pointer_type (tree record_type, tree field_list)
TYPE_CONTAINS_PLACEHOLDER_INTERNAL (record_type) = 2;
}
/* Given a record type RECORD_TYPE and a list of FIELD_DECL nodes FIELD_LIST,
finish constructing the record type as an extended access type. */
void
finish_extended_pointer_type (tree record_type, tree field_list)
{
/* Show what it really is. */
TYPE_EXTENDED_POINTER_P (record_type) = 1;
/* Do not emit debug info for it since the types of its fields may still be
incomplete at this point. */
finish_record_type (record_type, field_list, 0, false);
/* Force type_contains_placeholder_p to return true on it. Although the
PLACEHOLDER_EXPRs are referenced only indirectly, this isn't a pointer
type but the representation of the unconstrained array. */
TYPE_CONTAINS_PLACEHOLDER_INTERNAL (record_type) = 2;
}
/* Clear DECL_BIT_FIELD flag and associated markers on FIELD, which is a field
of aggregate type TYPE. */
@@ -2219,6 +2293,7 @@ finish_record_type (tree record_type, tree field_list, int rep_level,
if (RECORD_OR_UNION_TYPE_P (type)
&& !TYPE_FAT_POINTER_P (type)
&& !TYPE_EXTENDED_POINTER_P (type)
&& !TYPE_CONTAINS_TEMPLATE_P (type)
&& TYPE_ADA_SIZE (type))
this_ada_size = TYPE_ADA_SIZE (type);
@@ -2355,6 +2430,7 @@ finish_record_type (tree record_type, tree field_list, int rep_level,
{
/* Now set any of the values we've just computed that apply. */
if (!TYPE_FAT_POINTER_P (record_type)
&& !TYPE_EXTENDED_POINTER_P (record_type)
&& !TYPE_CONTAINS_TEMPLATE_P (record_type))
SET_TYPE_ADA_SIZE (record_type, ada_size);
}
@@ -2919,6 +2995,9 @@ create_type_decl (tree name, tree type, bool artificial_p, bool debug_info_p,
definition to be made visible outside of the current compilation unit, for
instance variable definitions in a package specification.
LINKONCE_FLAG is true if the entity can be defined in multiple compilation
units without generating a linker error.
EXTERN_FLAG is true when processing an external variable declaration (as
opposed to a definition: no storage is to be allocated for the variable).
@@ -2937,10 +3016,11 @@ create_type_decl (tree name, tree type, bool artificial_p, bool debug_info_p,
tree
create_var_decl (tree name, tree asm_name, tree type, tree init,
bool const_flag, bool public_flag, bool extern_flag,
bool static_flag, bool volatile_flag, bool artificial_p,
bool debug_info_p, struct attrib *attr_list,
Node_Id gnat_node, bool const_decl_allowed_p)
bool const_flag, bool public_flag, bool linkonce_flag,
bool extern_flag, bool static_flag, bool volatile_flag,
bool artificial_p, bool debug_info_p,
struct attrib *attr_list, Node_Id gnat_node,
bool const_decl_allowed_p)
{
/* Whether the object has static storage duration, either explicitly or by
virtue of being declared at the global level. */
@@ -2971,9 +3051,8 @@ create_var_decl (tree name, tree asm_name, tree type, tree init,
and may be used for scalars in general but not for aggregates. */
tree var_decl
= build_decl (input_location,
(constant_p
&& const_decl_allowed_p
&& !AGGREGATE_TYPE_P (type) ? CONST_DECL : VAR_DECL),
constant_p && const_decl_allowed_p && !AGGREGATE_TYPE_P (type)
? CONST_DECL : VAR_DECL,
name, type);
/* Detect constants created by the front-end to hold 'reference to function
@@ -3055,6 +3134,13 @@ create_var_decl (tree name, tree asm_name, tree type, tree init,
!= null_pointer_node))
DECL_IGNORED_P (var_decl) = 1;
/* Note that make_decl_one_only forces TREE_PUBLIC on the DECL. */
if (linkonce_flag && VAR_P (var_decl))
{
gcc_checking_assert (TREE_PUBLIC (var_decl));
make_decl_one_only (var_decl, var_decl);
}
/* ??? Some attributes cannot be applied to CONST_DECLs. */
if (VAR_P (var_decl))
process_attributes (&var_decl, &attr_list, true, gnat_node);
@@ -3591,6 +3677,9 @@ create_label_decl (tree name, Node_Id gnat_node)
PUBLIC_FLAG is true if this is for a reference to a public entity or for a
definition to be made visible outside of the current compilation unit.
LINKONCE_FLAG is true if the entity can be defined in multiple compilation
units without generating a linker error.
EXTERN_FLAG is true when processing an external subprogram declaration.
ARTIFICIAL_P is true if the subprogram was generated by the compiler.
@@ -3606,9 +3695,9 @@ create_label_decl (tree name, Node_Id gnat_node)
tree
create_subprog_decl (tree name, tree asm_name, tree type, tree param_decl_list,
enum inline_status_t inline_status, bool public_flag,
bool extern_flag, bool artificial_p, bool debug_info_p,
bool definition, struct attrib *attr_list,
Node_Id gnat_node)
bool linkonce_flag, bool extern_flag, bool artificial_p,
bool debug_info_p, bool definition,
struct attrib *attr_list, Node_Id gnat_node)
{
tree subprog_decl = build_decl (input_location, FUNCTION_DECL, name, type);
DECL_ARGUMENTS (subprog_decl) = param_decl_list;
@@ -3661,6 +3750,13 @@ create_subprog_decl (tree name, tree asm_name, tree type, tree param_decl_list,
gcc_unreachable ();
}
/* Note that make_decl_one_only forces TREE_PUBLIC on the DECL. */
if (linkonce_flag)
{
gcc_checking_assert (TREE_PUBLIC (subprog_decl));
make_decl_one_only (subprog_decl, subprog_decl);
}
process_attributes (&subprog_decl, &attr_list, true, gnat_node);
/* Once everything is processed, finish the subprogram declaration. */
@@ -4483,20 +4579,23 @@ build_unc_object_type (tree template_type, tree object_type, tree name,
return type;
}
/* Same, taking a thin or fat pointer type instead of a template type. */
/* Same, taking a pointer type instead of a template type. */
tree
build_unc_object_type_from_ptr (tree thin_fat_ptr_type, tree object_type,
tree name, bool debug_info_p)
build_unc_object_type_from_ptr (tree ptr_type, tree object_type, tree name,
bool debug_info_p)
{
tree template_type;
gcc_assert (TYPE_IS_FAT_OR_THIN_POINTER_P (thin_fat_ptr_type));
template_type
= (TYPE_IS_FAT_POINTER_P (thin_fat_ptr_type)
? TREE_TYPE (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (thin_fat_ptr_type))))
: TREE_TYPE (TYPE_FIELDS (TREE_TYPE (thin_fat_ptr_type))));
if (TYPE_IS_EXTENDED_POINTER_P (ptr_type))
template_type = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (ptr_type)));
else if (TYPE_IS_FAT_POINTER_P (ptr_type))
template_type
= TREE_TYPE (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (ptr_type))));
else if (TYPE_IS_THIN_POINTER_P (ptr_type))
template_type = TREE_TYPE (TYPE_FIELDS (TREE_TYPE (ptr_type)));
else
gcc_unreachable ();
return
build_unc_object_type (template_type, object_type, name, true,
@@ -4652,6 +4751,9 @@ convert_to_fat_pointer (tree type, tree expr)
vec<constructor_elt, va_gc> *v;
vec_alloc (v, 2);
/* We don't allow conversion from extended to fat pointers. */
gcc_assert (!TYPE_IS_EXTENDED_POINTER_P (etype));
/* If EXPR is null, make a fat pointer that contains a null pointer to the
array (compare_fat_pointers ensures that this is the full discriminant)
and a valid pointer to the bounds. This latter property is necessary
@@ -4743,6 +4845,101 @@ convert_to_fat_pointer (tree type, tree expr)
return gnat_build_constructor (type, v);
}
/* Convert EXPR, a pointer to a constrained array, into a pointer to an
unconstrained one using an extended access. This involves making or
finding a template. */
static tree
convert_to_extended_pointer (tree type, tree expr)
{
tree template_type = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (type)));
tree p_array_type = TREE_TYPE (TYPE_FIELDS (type));
tree etype = TREE_TYPE (expr);
tree template_val;
vec<constructor_elt, va_gc> *v;
vec_alloc (v, 2);
/* If EXPR is null, make a fat pointer that contains a null pointer to the
array (compare_fat_pointers ensures that this is the full discriminant)
and a valid pointer to the bounds. This latter property is necessary
since the compiler can hoist the load of the bounds done through it. */
if (integer_zerop (expr))
{
tree template_type = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (type)));
tree null_bounds, t;
null_bounds = build_constructor (template_type, NULL);
TREE_CONSTANT (null_bounds) = TREE_STATIC (null_bounds) = 1;
CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (type),
fold_convert (p_array_type, null_pointer_node));
CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (type)) , null_bounds);
t = build_constructor (type, v);
/* Do not set TREE_CONSTANT so as to force T to static memory. */
TREE_CONSTANT (t) = 0;
TREE_STATIC (t) = 1;
return t;
}
/* If EXPR is a thin pointer, make template and data from the record. */
if (TYPE_IS_THIN_POINTER_P (etype))
{
tree field = TYPE_FIELDS (TREE_TYPE (etype));
expr = gnat_protect_expr (expr);
/* If we have a TYPE_UNCONSTRAINED_ARRAY attached to the RECORD_TYPE,
the thin pointer value has been shifted so we shift it back to get
the template address. */
if (TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (etype)))
{
tree template_addr
= fold_convert (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (type))), expr);
template_val = build_unary_op (INDIRECT_REF, NULL_TREE, template_addr);
}
/* Otherwise we explicitly take the address of the fields. */
else
{
expr = build_unary_op (INDIRECT_REF, NULL_TREE, expr);
template_val = build_component_ref (expr, field, true);
expr = build_unary_op (ADDR_EXPR, NULL_TREE,
build_component_ref (expr, DECL_CHAIN (field),
false));
}
}
else if (TYPE_IS_FAT_POINTER_P (etype))
template_val
= build_unary_op (INDIRECT_REF, NULL_TREE,
build_component_ref (expr,
DECL_CHAIN (TYPE_FIELDS (etype)),
false));
/* Otherwise, build the constructor for the template. */
else
template_val = build_template (template_type, TREE_TYPE (etype), expr);
/* The final result is a constructor for the extended pointer.
If EXPR is an argument of a foreign convention subprogram, the type it
points to is directly the component type. In this case, the expression
type may not match the corresponding FIELD_DECL type at this point, so we
call "convert" here to fix that up if necessary. This type consistency is
required, for instance because it ensures that possible later folding of
COMPONENT_REFs against this constructor always yields something of the
same type as the initial reference.
Note that the call to "build_template" above is still fine because it
will only refer to the provided TEMPLATE_TYPE in this case. */
CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (type), convert (p_array_type, expr));
CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (type)), template_val);
return gnat_build_constructor (type, v);
}
/* Create an expression whose value is that of EXPR,
converted to type TYPE. The TREE_TYPE of the value
is always TYPE. This function implements all reasonable
@@ -5122,6 +5319,8 @@ convert (tree type, tree expr)
/* Check for converting to a pointer to an unconstrained array. */
if (TYPE_IS_FAT_POINTER_P (type) && !TYPE_IS_FAT_POINTER_P (etype))
return convert_to_fat_pointer (type, expr);
if (TYPE_IS_EXTENDED_POINTER_P (type) && !TYPE_IS_EXTENDED_POINTER_P (etype))
return convert_to_extended_pointer (type, expr);
/* If we are converting between two aggregate or vector types that are mere
variants, just make a VIEW_CONVERT_EXPR. Likewise when we are converting
@@ -5139,7 +5338,8 @@ convert (tree type, tree expr)
But don't do it if we are just annotating types since tagged types
aren't fully laid out in this mode. */
else if (ecode == RECORD_TYPE && code == RECORD_TYPE
&& TYPE_ALIGN_OK (etype) && TYPE_ALIGN_OK (type)
&& type_is_tagged_or_cw_equivalent (etype)
&& type_is_tagged_or_cw_equivalent (type)
&& !type_annotate_only)
{
tree child_etype = etype;
@@ -5263,7 +5463,7 @@ convert (tree type, tree expr)
/* If converting fat pointer to normal or thin pointer, get the pointer
to the array and then convert it. */
if (TYPE_IS_FAT_POINTER_P (etype))
if (TYPE_IS_FAT_POINTER_P (etype) || TYPE_IS_EXTENDED_POINTER_P (etype))
expr = build_component_ref (expr, TYPE_FIELDS (etype), false);
return fold (convert_to_pointer (type, expr));
@@ -5327,20 +5527,30 @@ convert (tree type, tree expr)
}
/* If EXPR is a constrained array, take its address, convert it to a
fat pointer, and then dereference it. Likewise if EXPR is a
record containing both a template and a constrained array.
Note that a record representing a justified modular type
always represents a packed constrained array. */
fat or extended pointer, and then dereference it. Likewise if
EXPR is a record containing both a template and a constrained
array. Note that a record representing a justified modular type
always represents a packed constrained array. */
if (ecode == ARRAY_TYPE
|| (ecode == INTEGER_TYPE && TYPE_HAS_ACTUAL_BOUNDS_P (etype))
|| (ecode == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (etype))
|| (ecode == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (etype)))
return
build_unary_op
(INDIRECT_REF, NULL_TREE,
convert_to_fat_pointer (TREE_TYPE (type),
build_unary_op (ADDR_EXPR,
NULL_TREE, expr)));
{
if (TYPE_IS_EXTENDED_POINTER_P (TREE_TYPE (type)))
return
build_unary_op
(INDIRECT_REF, NULL_TREE,
convert_to_extended_pointer (TREE_TYPE (type),
build_unary_op (ADDR_EXPR,
NULL_TREE, expr)));
else
return
build_unary_op
(INDIRECT_REF, NULL_TREE,
convert_to_fat_pointer (TREE_TYPE (type),
build_unary_op (ADDR_EXPR,
NULL_TREE, expr)));
}
/* Do something very similar for converting one unconstrained
array to another. */
+23 -10
View File
@@ -1041,9 +1041,7 @@ build_binary_op (enum tree_code op_code, tree result_type,
}
/* If a class-wide type may be involved, force use of the RHS type. */
if ((TREE_CODE (right_type) == RECORD_TYPE
|| TREE_CODE (right_type) == UNION_TYPE)
&& TYPE_ALIGN_OK (right_type))
if (type_is_tagged_or_cw_equivalent (right_type))
operation_type = right_type;
/* If we are copying between padded objects with compatible types, use
@@ -1118,7 +1116,7 @@ build_binary_op (enum tree_code op_code, tree result_type,
== TREE_CODE (operand_type (result))
&& TYPE_MODE (restype)
== TYPE_MODE (operand_type (result))))
|| TYPE_ALIGN_OK (restype))))
|| type_is_tagged_or_cw_equivalent (restype))))
result = TREE_OPERAND (result, 0);
else if (TREE_CODE (result) == VIEW_CONVERT_EXPR)
@@ -1296,6 +1294,14 @@ build_binary_op (enum tree_code op_code, tree result_type,
best_type = left_base_type;
}
else if (TYPE_IS_EXTENDED_POINTER_P (left_base_type)
&& TYPE_IS_EXTENDED_POINTER_P (right_base_type))
{
gcc_assert (TYPE_MAIN_VARIANT (left_base_type)
== TYPE_MAIN_VARIANT (right_base_type));
best_type = left_base_type;
}
else if (POINTER_TYPE_P (left_base_type)
&& POINTER_TYPE_P (right_base_type))
{
@@ -1737,7 +1743,7 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand)
/* If we want to refer to an unconstrained array, use the appropriate
expression. But this will never survive down to the back-end. */
if (TYPE_IS_FAT_POINTER_P (type))
if (TYPE_IS_FAT_POINTER_P (type) || TYPE_IS_EXTENDED_POINTER_P (type))
{
result = build1 (UNCONSTRAINED_ARRAY_REF,
TYPE_UNCONSTRAINED_ARRAY (type), operand);
@@ -1756,7 +1762,9 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand)
TREE_READONLY (result) = TYPE_READONLY (TREE_TYPE (type));
}
if (!TYPE_IS_FAT_POINTER_P (type) && TYPE_VOLATILE (TREE_TYPE (type)))
if (!TYPE_IS_FAT_POINTER_P (type)
&& !TYPE_IS_EXTENDED_POINTER_P (type)
&& TYPE_VOLATILE (TREE_TYPE (type)))
{
TREE_SIDE_EFFECTS (result) = 1;
if (INDIRECT_REF_P (result))
@@ -2609,7 +2617,8 @@ build_allocator (tree type, tree init, tree result_type, Entity_Id gnat_proc,
/* If RESULT_TYPE is a fat or thin pointer, set SIZE to be the sum of the
sizes of the object and its template. Allocate the whole thing and
fill in the parts that are known. */
else if (TYPE_IS_FAT_OR_THIN_POINTER_P (result_type))
else if (TYPE_IS_FAT_OR_THIN_POINTER_P (result_type)
|| TYPE_IS_EXTENDED_POINTER_P (result_type))
{
tree storage_type
= build_unc_object_type_from_ptr (result_type, type,
@@ -3055,7 +3064,8 @@ gnat_save_expr (tree exp)
This may be more efficient, but will also allow us to more easily find
the match for the PLACEHOLDER_EXPR. */
if (code == COMPONENT_REF
&& TYPE_IS_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (exp, 0))))
&& (TYPE_IS_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (exp, 0)))
|| TYPE_IS_EXTENDED_POINTER_P (TREE_TYPE (TREE_OPERAND (exp, 0)))))
return build3 (code, type, gnat_save_expr (TREE_OPERAND (exp, 0)),
TREE_OPERAND (exp, 1), NULL_TREE);
@@ -3124,7 +3134,8 @@ gnat_protect_expr (tree exp)
This may be more efficient, but will also allow us to more easily find
the match for the PLACEHOLDER_EXPR. */
if (code == COMPONENT_REF
&& TYPE_IS_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (exp, 0))))
&& (TYPE_IS_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (exp, 0)))
|| TYPE_IS_EXTENDED_POINTER_P (TREE_TYPE (TREE_OPERAND (exp, 0)))))
return build3 (code, type, gnat_protect_expr (TREE_OPERAND (exp, 0)),
TREE_OPERAND (exp, 1), NULL_TREE);
@@ -3132,6 +3143,7 @@ gnat_protect_expr (tree exp)
for a CALL_EXPR as large objects are returned via invisible reference
in most ABIs so the temporary will directly be filled by the callee. */
if (TYPE_IS_FAT_POINTER_P (type)
|| TYPE_IS_EXTENDED_POINTER_P (type)
|| !AGGREGATE_TYPE_P (type)
|| code == CALL_EXPR)
return save_expr (exp);
@@ -3168,7 +3180,8 @@ gnat_stabilize_reference_1 (tree e, void *data)
fat pointer. This may be more efficient, but will also allow
us to more easily find the match for the PLACEHOLDER_EXPR. */
if (code == COMPONENT_REF
&& TYPE_IS_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (e, 0))))
&& (TYPE_IS_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (e, 0)))
|| TYPE_IS_EXTENDED_POINTER_P (TREE_TYPE (TREE_OPERAND (e, 0)))))
result
= build3 (code, type,
gnat_stabilize_reference_1 (TREE_OPERAND (e, 0), data),
+11
View File
@@ -72,6 +72,7 @@ package Gen_IL.Fields is
Ancestor_Part,
Atomic_Sync_Required,
Array_Aggregate,
Aspect_Ghost_Assertion_Level,
Aspect_On_Partial_View,
Aspect_Rep_Item,
Aspect_Specifications,
@@ -281,6 +282,7 @@ package Gen_IL.Fields is
Is_SPARK_Mode_On_Node,
Is_Static_Coextension,
Is_Static_Expression,
Is_Structural,
Is_Subprogram_Descriptor,
Is_Task_Allocation_Block,
Is_Task_Body_Procedure,
@@ -336,8 +338,10 @@ package Gen_IL.Fields is
Null_Statement,
Object_Definition,
Of_Present,
Original_Aspect,
Original_Discriminant,
Original_Entity,
Original_Pragma,
Others_Discrete_Choices,
Out_Present,
Parameter_Associations,
@@ -347,6 +351,7 @@ package Gen_IL.Fields is
Parent_With,
Position,
Pragma_Argument_Associations,
Pragma_Ghost_Assertion_Level,
Pragma_Identifier,
Pragmas_After,
Pragmas_Before,
@@ -463,6 +468,7 @@ package Gen_IL.Fields is
Can_Never_Be_Null,
Can_Use_Internal_Rep,
Checks_May_Be_Suppressed,
Child_Levels,
Class_Postconditions,
Class_Preconditions,
Class_Preconditions_Subprogram,
@@ -557,6 +563,7 @@ package Gen_IL.Fields is
Full_View,
Generic_Homonym,
Generic_Renamings,
Ghost_Assertion_Level,
Has_Aliased_Components,
Has_Alignment_Clause,
Has_All_Calls_Remote,
@@ -651,6 +658,7 @@ package Gen_IL.Fields is
Has_Thunks,
Has_Unchecked_Union,
Has_Unknown_Discriminants,
Has_Unsigned_Base_Range_Aspect,
Has_Visible_Refinement,
Has_Volatile_Components,
Has_Xref_Entry,
@@ -736,6 +744,7 @@ package Gen_IL.Fields is
Is_Immediately_Visible,
Is_Implementation_Defined,
Is_Implicit_Full_View,
Is_Implicit_Ghost,
Is_Imported,
Is_Independent,
Is_Initial_Condition_Procedure,
@@ -755,6 +764,7 @@ package Gen_IL.Fields is
Is_Limited_Composite,
Is_Limited_Interface,
Is_Limited_Record,
Is_Link_Once,
Is_Local_Anonymous_Access,
Is_Loop_Parameter,
Is_Machine_Code_Subprogram,
@@ -860,6 +870,7 @@ package Gen_IL.Fields is
Overridden_Operation,
Package_Instantiation,
Packed_Array_Impl_Type,
Parent_Levels,
Parent_Subtype,
Part_Of_Constituents,
Part_Of_References,
+16
View File
@@ -63,6 +63,7 @@ begin -- Gen_IL.Gen.Gen_Entities
Sm (First_Rep_Item, Node_Id),
Sm (Freeze_Node, Node_Id),
Sm (From_Limited_With, Flag),
Sm (Ghost_Assertion_Level, Node_Id),
Sm (Has_Aliased_Components, Flag, Impl_Base_Type_Only),
Sm (Has_Alignment_Clause, Flag),
Sm (Has_All_Calls_Remote, Flag),
@@ -158,6 +159,7 @@ begin -- Gen_IL.Gen.Gen_Entities
Sm (Is_Ignored_Ghost_Entity, Flag),
Sm (Is_Immediately_Visible, Flag),
Sm (Is_Implementation_Defined, Flag),
Sm (Is_Implicit_Ghost, Flag),
Sm (Is_Imported, Flag),
Sm (Is_Independent, Flag),
Sm (Is_Inlined, Flag),
@@ -173,6 +175,7 @@ begin -- Gen_IL.Gen.Gen_Entities
Sm (Is_Limited_Composite, Flag),
Sm (Is_Limited_Interface, Flag),
Sm (Is_Limited_Record, Flag),
Sm (Is_Link_Once, Flag),
Sm (Is_Loop_Parameter, Flag),
Sm (Is_Obsolescent, Flag),
Sm (Is_Package_Body_Entity, Flag),
@@ -496,6 +499,8 @@ begin -- Gen_IL.Gen.Gen_Entities
Sm (Has_Static_Predicate, Flag),
Sm (Has_Static_Predicate_Aspect, Flag),
Sm (Has_Unknown_Discriminants, Flag),
Sm (Has_Unsigned_Base_Range_Aspect, Flag,
Pre => "Is_Type (N)"),
Sm (Interface_Name, Node_Id),
Sm (Is_Abstract_Type, Flag),
Sm (Is_Actual_Subtype, Flag),
@@ -1344,6 +1349,17 @@ begin -- Gen_IL.Gen.Gen_Entities
Sm (SPARK_Pragma, Node_Id),
Sm (SPARK_Pragma_Inherited, Flag)));
Cc (E_Assertion_Level, Entity_Kind,
-- An assertion level. Used to associate a level indicator to an
-- assertion like construct. Constructs assigned with a certain level
-- can be disabled through pragma Assertion_Policy. Levels can form a
-- hierarchy. A declaration of a level can include a list of levels
-- this level depends on known as the Parent_Levels. An opposite list
-- is also kept to store all the levels that depend on it known as the
-- Child_Levels.
(Sm (Child_Levels, Elist_Id),
Sm (Parent_Levels, Elist_Id)));
-- Union types. These don't fit into the normal parent/child hierarchy
-- above.
+7 -2
View File
@@ -687,13 +687,14 @@ begin -- Gen_IL.Gen.Gen_Nodes
(Sy (Defining_Unit_Name, Node_Id),
Sy (Name, Node_Id, Default_Empty),
Sy (Generic_Associations, List_Id, Default_No_List),
Sm (Parent_Spec, Node_Id),
Sm (Instance_Spec, Node_Id),
Sm (Is_Declaration_Level_Node, Flag),
Sm (Is_Elaboration_Checks_OK_Node, Flag),
Sm (Is_Elaboration_Warnings_OK_Node, Flag),
Sm (Is_Known_Guaranteed_ABE, Flag),
Sm (Is_SPARK_Mode_On_Node, Flag),
Sm (Parent_Spec, Node_Id)));
Sm (Is_Structural, Flag)));
Ab (N_Subprogram_Instantiation, N_Generic_Instantiation,
(Sy (Must_Override, Flag),
@@ -1127,6 +1128,7 @@ begin -- Gen_IL.Gen.Gen_Nodes
(Sy (Identifier, Node_Id, Default_Empty),
Sy (Expression, Node_Id, Default_Empty),
Sy (Class_Present, Flag),
Sm (Aspect_Ghost_Assertion_Level, Node_Id),
Sm (Aspect_On_Partial_View, Flag),
Sm (Aspect_Rep_Item, Node_Id),
Sm (Aspect_Subprograms, Elist_Id),
@@ -1137,7 +1139,8 @@ begin -- Gen_IL.Gen.Gen_Nodes
Sm (Is_Delayed_Aspect, Flag),
Sm (Is_Disabled, Flag),
Sm (Is_Ignored, Flag),
Sm (Next_Rep_Item, Node_Id)));
Sm (Next_Rep_Item, Node_Id),
Sm (Original_Aspect, Node_Id)));
Cc (N_Call_Marker, Node_Kind,
(Sm (Is_Declaration_Level_Node, Flag),
@@ -1444,6 +1447,8 @@ begin -- Gen_IL.Gen.Gen_Nodes
Sm (Is_Ignored_Ghost_Pragma, Flag),
Sm (Next_Pragma, Node_Id),
Sm (Next_Rep_Item, Node_Id),
Sm (Original_Pragma, Node_Id),
Sm (Pragma_Ghost_Assertion_Level, Node_Id),
Sm (Uneval_Old_Accept, Flag),
Sm (Uneval_Old_Warn, Flag)));
+2
View File
@@ -291,6 +291,8 @@ package body Gen_IL.Internals is
return "Has_RACW";
when Has_SP_Choice =>
return "Has_SP_Choice";
when Has_Unsigned_Base_Range_Aspect =>
return "Has_Unsigned_Base_Range_Aspect";
when Ignore_SPARK_Mode_Pragmas =>
return "Ignore_SPARK_Mode_Pragmas";
when Is_CPP_Class =>
+1
View File
@@ -445,6 +445,7 @@ package Gen_IL.Types is
-- Concrete entity types:
E_Void,
E_Assertion_Level,
E_Component,
E_Constant,
E_Discriminant,
+1126 -537
View File
File diff suppressed because it is too large Load Diff
+31 -7
View File
@@ -32,6 +32,16 @@ with Types; use Types;
package Ghost is
function Assertion_Level_From_Arg (Arg : Node_Id) return Entity_Id;
-- Returns the assertion level for the given pragma or aspect based on
-- the argument Arg. Which is either
--
-- * Standard_Level_Default if there was no argument or the argument
-- evaluated to True.
-- * Assertion_Level if the argument was referencing a user defined
-- Assertion_Level.
-- * Empty othrwise since we are not dealing with a ghost entity.
procedure Check_Ghost_Completion
(Prev_Id : Entity_Id;
Compl_Id : Entity_Id);
@@ -49,7 +59,7 @@ package Ghost is
(Actual : Node_Id;
Formal : Entity_Id);
-- Check that if Actual contains references to ghost entities, generic
-- formal parameter Formal is ghost (SPARK RM 6.9(10)).
-- formal parameter Formal is ghost (SPARK RM 6.9(13)).
procedure Check_Ghost_Formal_Procedure_Or_Package
(N : Node_Id;
@@ -58,7 +68,7 @@ package Ghost is
Is_Default : Boolean := False);
-- Verify that if generic formal procedure (resp. package) Formal is ghost,
-- then Actual is not Empty and also a ghost procedure (resp. package)
-- (SPARK RM 6.9(13-14)). The error if any is located on N. If
-- (SPARK RM 6.9(16-17)). The error if any is located on N. If
-- Is_Default is False, N and Actual represent the actual parameter in an
-- instantiation. Otherwise, they represent the default subprogram of a
-- formal subprogram declaration.
@@ -69,7 +79,7 @@ package Ghost is
Is_Default : Boolean := False);
-- Verify that if Formal (either an IN OUT generic formal parameter, or an
-- IN generic formal parameter of access-to-variable type) is ghost, then
-- Actual is a ghost object (SPARK RM 6.9(13-14)). Is_Default is True when
-- Actual is a ghost object (SPARK RM 6.9(16-17)). Is_Default is True when
-- Actual is the default expression of the formal object declaration.
procedure Check_Ghost_Overriding
@@ -90,7 +100,9 @@ package Ghost is
Constit : Node_Id;
Constit_Id : Entity_Id);
-- Verify that the Ghost policy of constituent Constit_Id is compatible
-- with the Ghost policy of abstract state State_I.
-- with the Ghost policy of abstract state State_Id.
--
-- Additionally verify that the Ghost_Assertion_Levels are compatible.
procedure Check_Ghost_Type (Typ : Entity_Id);
-- Verify that Ghost type Typ is neither concurrent, nor effectively
@@ -102,11 +114,23 @@ package Ghost is
procedure Initialize;
-- Initialize internal tables
procedure Install_Ghost_Region (Mode : Ghost_Mode_Type; N : Node_Id);
procedure Install_Ghost_Region
(Mode : Ghost_Mode_Type;
N : Node_Id;
Level : Entity_Id);
pragma Inline (Install_Ghost_Region);
-- Install a Ghost region described by mode Mode and ignored region start
-- node N.
function Is_Assertion_Level_Dependent
(Self : Entity_Id; Other : Entity_Id) return Boolean;
-- Check that assertion level Self is assertion-level-dependent with Other.
--
-- According to SPARK RM 6.9(6) this means that
-- * Either Self or Other has the default assertion level.
-- * Self either is or depends on Other
-- * Self either is or depends on Static
function Is_Ghost_Assignment (N : Node_Id) return Boolean;
-- Determine whether arbitrary node N denotes an assignment statement whose
-- target is a Ghost entity.
@@ -238,12 +262,12 @@ package Ghost is
procedure Remove_Ignored_Ghost_Code;
-- Remove all code marked as ignored Ghost from the trees of all qualifying
-- units (SPARK RM 6.9(4)).
-- units (SPARK RM 6.9(5)).
--
-- WARNING: this is a separate front end pass, care should be taken to keep
-- it optimized.
procedure Restore_Ghost_Region (Mode : Ghost_Mode_Type; N : Node_Id);
procedure Restore_Ghost_Region (Config : Ghost_Config_Type);
pragma Inline (Restore_Ghost_Region);
-- Restore a Ghost region to a previous state described by mode Mode and
-- ignored region start node N. This routine must be used in conjunction
+6 -5
View File
@@ -175,6 +175,12 @@ procedure Gnat1drv is
Disable_ALI_File := True;
end if;
-- -gnatd_o disables backend overflow checks on target; used for testing
if Debug_Flag_Underscore_O then
Backend_Overflow_Checks_On_Target := False;
end if;
-- -gnatd.E sets Error_To_Warning mode, causing selected error messages
-- to be treated as warnings instead of errors.
@@ -503,11 +509,6 @@ procedure Gnat1drv is
Operating_Mode := Check_Semantics;
-- Enable assertions, since they give valuable extra information for
-- formal verification.
Assertions_Enabled := True;
-- Disable validity checks, since it generates code raising
-- exceptions for invalid data, which confuses GNATprove. Invalid
-- data is directly detected by GNATprove's flow analysis.
+1111 -793
View File
File diff suppressed because it is too large Load Diff
+56 -20
View File
@@ -19,7 +19,7 @@
@copying
@quotation
GNAT User's Guide for Native Platforms , Jun 27, 2025
GNAT User's Guide for Native Platforms , Sep 23, 2025
AdaCore
@@ -4628,6 +4628,23 @@ don’t specify a value, the symbol is defined to be @code{True}. You can
use this switch instead of providing a definition file.
@end table
@geindex -e (gnatprep)
@table @asis
@item @code{-e}
Causes both preprocessor lines and the lines deleted by
preprocessing to be replaced by empty comment lines marked
with @code{"--!"} (and no other text) in the output source file,
preserving line numbers in the output file. This option can
be useful as an alternative to @code{-b} and @code{-c}
when compilation style switches like @code{-gnatyu} or
@code{-gnatyM} are used (to avoid warnings about multiple
blank lines or lines too long).
@end table
@geindex -r (gnatprep)
@@ -5023,7 +5040,7 @@ Finally, switches similar to those of @code{gnatprep} may optionally appear:
Causes both preprocessor lines and the lines deleted by
preprocessing to be replaced by blank lines, preserving the line number.
This switch is always implied; however, if specified after @code{-c}
it cancels the effect of @code{-c}.
or @code{-e} it cancels the effect of those switches.
@item @code{-c}
@@ -5041,6 +5058,12 @@ literal string, an Ada identifier or any Ada reserved word. A
symbol declared with this switch replaces a symbol with the same
name defined in a definition file.
@item @code{-e}
Causes both preprocessor lines and the lines deleted by
preprocessing to be replaced by empty comment lines marked
with ‘@cite{–!}’ (and no other text) in the output source file,
@item @code{-s}
Causes a sorted list of symbol names and values to be
@@ -5088,14 +5111,25 @@ symbol with the same name either in a definition file or specified with a
switch @code{-D} in the preprocessor data file.
This switch is similar to switch @code{-D} of @code{gnatprep}.
@end table
@item @code{-gnateG}
@geindex -gnateG (gcc)
@table @asis
@item @code{-gnateG[bce]}
When integrated preprocessing is performed on source file @code{filename.extension},
create or overwrite @code{filename.extension.prep} to contain
the result of the preprocessing.
For example if the source file is @code{foo.adb} then
the output file is @code{foo.adb.prep}.
An optional character (b, c, or e) can be appended to indicate that filtered
lines are to be replaced by blank lines, comments, or empty comments (see
documentation above about @code{-b}, @code{-c}, and @code{-e}).
If one of those switches is given in a preprocessor data file, then it
will override any option included with @code{-gnateG}.
@end table
@node Mixed Language Programming,GNAT and Other Compilation Models,Conditional Compilation,The GNAT Compilation Model
@@ -9155,9 +9189,13 @@ information.
@table @asis
@item @code{-gnateG}
@item @code{-gnateG[bce]}
Save result of preprocessing in a text file.
Save result of preprocessing in a text file. An optional character (b, c,
or e) can be appended to indicate that filtered lines are to be replaced by
blank lines, comment lines that include the filtered line, or empty comment
lines (”–!”), respectively. The default is to replace filtered lines with
blank lines.
@end table
@geindex -gnateH (gcc)
@@ -17653,20 +17691,18 @@ version of GNAT.
@item
@code{gprbuild} can detect and use GNAT LLVM when it is installed.
@code{gprbuild} uses the first applicable compiler on the executable
search path, including GNAT LLVM. An easy way to build with GNAT
LLVM is to make it available on the operating system’s search path
before any other Ada compiler (such as the GCC version of GNAT). To
avoid accidentally using a different compiler than the one you want
to use, we recommend generating an explicit toolchain configuration
file with @code{gprconfig} and using it with @code{gprbuild}; see the
`GPRbuild and GPR Companion Tools User’s Guide' for details. You
can determine from the first line of the @code{.ali} file
which version of GNAT built that file because it contains either
@code{GNAT} or @code{GNAT-LLVM}.
You can also explicitly select GNAT LLVM in your existing GPR project
file by adding @code{for Toolchain_Name("Ada") use "GNAT_LLVM";}
@code{gprbuild} uses the first applicable compiler on the executable search
path, including GNAT LLVM. An easy way to build with GNAT LLVM is to make
it available on the operating system’s search path before any other Ada
compiler (such as the GCC version of GNAT). To avoid accidentally using a
different compiler than the one you want to use, we recommend explicitly
selecting GNAT LLVM in your existing GPR project file by adding
@code{for Toolchain_Name ("Ada") use "GNAT_LLVM";}. You can also
generate an explicit toolchain configuration file with @code{gprconfig} and
use it with @code{gprbuild}; see the `GPRbuild and GPR Companion Tools
User’s Guide' for details. You can determine from the first line of the
@code{.ali} file which version of GNAT built that file because it
contains either @code{GNAT} or @code{GNAT-LLVM}.
@end itemize
@@ -30297,8 +30333,8 @@ to permit their use in free software.
@printindex ge
@anchor{d2}@w{ }
@anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{ }
@anchor{d2}@w{ }
@c %**end of body
@bye
+5 -1
View File
@@ -735,7 +735,7 @@ package body GPrep is
loop
begin
Switch := GNAT.Command_Line.Getopt ("D: a b c C r s T u v");
Switch := GNAT.Command_Line.Getopt ("D: a b c C e r s T u v");
case Switch is
when ASCII.NUL =>
@@ -755,6 +755,9 @@ package body GPrep is
when 'c' =>
Opt.Comment_Deleted_Lines := True;
when 'e' =>
Opt.Empty_Comment_Deleted_Lines := True;
when 'C' =>
Opt.Replace_In_Comments := True;
@@ -831,6 +834,7 @@ package body GPrep is
Write_Line (" -c Keep preprocessor lines as comments");
Write_Line (" -C Do symbol replacements within comments");
Write_Line (" -D Associate symbol with value");
Write_Line (" -e Replace preprocessor lines by empty comment lines");
Write_Line (" -r Generate Source_Reference pragma");
Write_Line (" -s Print a sorted list of symbol names and values");
Write_Line (" -T Use LF as line terminators");
+1
View File
@@ -250,6 +250,7 @@ package body Impunit is
("g-busorg", F), -- GNAT.Bubble_Sort_G
("g-byorma", F), -- GNAT.Byte_Order_Mark
("g-bytswa", F), -- GNAT.Byte_Swapping
("g-c_time", F), -- GNAT.C_Time
("g-calend", F), -- GNAT.Calendar
("g-catiio", F), -- GNAT.Calendar.Time_IO
("g-casuti", F), -- GNAT.Case_Util
+3 -1
View File
@@ -1061,7 +1061,9 @@ package body Inline is
E : constant Subprogram_Kind_Id := Inlined.Table (Index).Name;
begin
if Is_Called (E) and then not Is_Ignored_Ghost_Entity (E) then
if Is_Called (E)
and then not Is_Ignored_Ghost_Entity_In_Codegen (E)
then
Add_Inlined_Subprogram (E);
end if;
end;
+21 -9
View File
@@ -248,13 +248,21 @@ package body Layout is
end if;
-- For access types, set size/alignment. This is system address size,
-- except for fat pointers (unconstrained array access types), where the
-- size is two times the address size, to accommodate the two pointers
-- that are required for a fat pointer (data and template). Note that
-- E_Access_Protected_Subprogram_Type is not an access type for this
-- purpose since it is not a pointer but is equivalent to a record. For
-- access subtypes, copy the size from the base type since Gigi
-- represents them the same way.
-- except for unconstrained array access types:
--
-- - fat pointers where the size is two times the address size, to
-- accommodate the two pointers that are required for a fat pointer
-- (data and template).
--
-- - extended access where the size is the size of an address (data
-- pointer) plus the size of the template. The template size can't be
-- computed yet (will be done in the code generator), leave it empty
-- for now.
--
-- Note that E_Access_Protected_Subprogram_Type is not an access type
-- for this purpose since it is not a pointer but is equivalent to a
-- record. For access subtypes, copy the size from the base type since
-- the code generator represents them the same way.
if Is_Access_Type (E) then
Desig_Type := Underlying_Type (Designated_Type (E));
@@ -301,7 +309,9 @@ package body Layout is
and then not Debug_Flag_6
then
Init_Size (E, 2 * System_Address_Size);
if not Is_Extended_Access_Type (E) then
Init_Size (E, 2 * System_Address_Size);
end if;
-- Check for bad convention set
@@ -326,7 +336,9 @@ package body Layout is
N_Unconstrained_Array_Definition
and then not Debug_Flag_6
then
Init_Size (E, 2 * System_Address_Size);
if not Is_Extended_Access_Type (E) then
Init_Size (E, 2 * System_Address_Size);
end if;
-- If unnesting subprograms, subprogram access types contain the
-- address of both the subprogram and an activation record. But if we
+1 -1
View File
@@ -905,7 +905,7 @@ package body Lib.Writ is
-- Do not generate a with line for an ignored Ghost unit because
-- the unit does not have an ALI file.
if Is_Ignored_Ghost_Entity (Cunit_Entity (Unum)) then
if Is_Ignored_Ghost_Entity_In_Codegen (Cunit_Entity (Unum)) then
goto Next_With_Line;
end if;
+2 -2
View File
@@ -1729,7 +1729,7 @@ package body Lib.Xref is
-- entity because neither the entity nor its references will
-- appear in the final tree.
if Is_Ignored_Ghost_Entity (Ent) then
if Is_Ignored_Ghost_Entity_In_Codegen (Ent) then
goto Orphan_Continue;
end if;
@@ -2190,7 +2190,7 @@ package body Lib.Xref is
-- entity because neither the entity nor its references will
-- appear in the final tree.
if Is_Ignored_Ghost_Entity (Ent) then
if Is_Ignored_Ghost_Entity_In_Codegen (Ent) then
goto Continue;
end if;
+2 -1
View File
@@ -445,6 +445,7 @@ package Lib.Xref is
E_Anonymous_Access_Type => ' ',
E_Array_Subtype => 'A',
E_Array_Type => 'A',
E_Assertion_Level => 'z',
E_Block => 'q',
E_Class_Wide_Subtype => 'C',
E_Class_Wide_Type => 'C',
@@ -547,7 +548,7 @@ package Lib.Xref is
-- w protected object protected type
-- x abstract procedure exception
-- y abstract function entry or entry family
-- z generic formal parameter (unused)
-- z generic formal parameter assertion level
---------------------------------------------------
-- Handling of Imported and Exported Subprograms --
+5 -4
View File
@@ -34,8 +34,9 @@
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Unchecked_Conversion;
with System.Tasking;
with System.C_Time;
with System.OS_Interface; use System.OS_Interface;
with System.Tasking;
with System.Task_Primitives.Operations; use System.Task_Primitives.Operations;
with Interfaces.C; use Interfaces.C;
@@ -98,7 +99,7 @@ package body Ada.Execution_Time is
(T : Ada.Task_Identification.Task_Id :=
Ada.Task_Identification.Current_Task) return CPU_Time
is
TS : aliased timespec;
TS : aliased System.C_Time.timespec;
Clock_Id : aliased Interfaces.C.int;
Result : Interfaces.C.int;
@@ -112,7 +113,7 @@ package body Ada.Execution_Time is
function clock_gettime
(clock_id : Interfaces.C.int;
tp : access timespec)
tp : access System.C_Time.timespec)
return Interfaces.C.int;
pragma Import (C, clock_gettime, "clock_gettime");
-- Function from the POSIX.1b Realtime Extensions library
@@ -139,7 +140,7 @@ package body Ada.Execution_Time is
(clock_id => Clock_Id, tp => TS'Unchecked_Access);
pragma Assert (Result = 0);
return To_CPU_Time (To_Duration (TS));
return To_CPU_Time (System.C_Time.To_Duration (TS));
end Clock;
--------------------------
+1 -1
View File
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 1991-2024, Free Software Foundation, Inc. --
-- Copyright (C) 1991-2025, Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-17
View File
@@ -36,7 +36,6 @@
-- Preelaborate. This package is designed to be a bottom-level (leaf) package
with Interfaces.C;
with System.Parameters;
package System.Linux is
pragma Preelaborate;
@@ -45,24 +44,8 @@ package System.Linux is
-- Time --
----------
subtype long is Interfaces.C.long;
subtype suseconds_t is Interfaces.C.long;
type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
.. 2 ** (System.Parameters.time_t_bits - 1) - 1;
subtype clockid_t is Interfaces.C.int;
type timespec is record
tv_sec : time_t;
tv_nsec : long;
end record;
pragma Convention (C, timespec);
type timeval is record
tv_sec : time_t;
tv_usec : suseconds_t;
end record;
pragma Convention (C, timeval);
-----------
-- Errno --
-----------
-17
View File
@@ -36,7 +36,6 @@
-- Preelaborate. This package is designed to be a bottom-level (leaf) package.
with Interfaces.C;
with System.Parameters;
package System.Linux is
pragma Preelaborate;
@@ -45,24 +44,8 @@ package System.Linux is
-- Time --
----------
subtype long is Interfaces.C.long;
subtype suseconds_t is Interfaces.C.long;
type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
.. 2 ** (System.Parameters.time_t_bits - 1) - 1;
subtype clockid_t is Interfaces.C.int;
type timespec is record
tv_sec : time_t;
tv_nsec : long;
end record;
pragma Convention (C, timespec);
type timeval is record
tv_sec : time_t;
tv_usec : suseconds_t;
end record;
pragma Convention (C, timeval);
-----------
-- Errno --
-----------
@@ -36,7 +36,6 @@
-- Preelaborate. This package is designed to be a bottom-level (leaf) package
with Interfaces.C;
with System.Parameters;
package System.Linux is
pragma Preelaborate;
@@ -45,24 +44,8 @@ package System.Linux is
-- Time --
----------
subtype long is Interfaces.C.long;
subtype suseconds_t is Interfaces.C.long;
type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
.. 2 ** (System.Parameters.time_t_bits - 1) - 1;
subtype clockid_t is Interfaces.C.int;
type timespec is record
tv_sec : time_t;
tv_nsec : long;
end record;
pragma Convention (C, timespec);
type timeval is record
tv_sec : time_t;
tv_usec : suseconds_t;
end record;
pragma Convention (C, timeval);
-----------
-- Errno --
-----------
-17
View File
@@ -36,7 +36,6 @@
-- Preelaborate. This package is designed to be a bottom-level (leaf) package
with Interfaces.C;
with System.Parameters;
package System.Linux is
pragma Preelaborate;
@@ -45,24 +44,8 @@ package System.Linux is
-- Time --
----------
subtype long is Interfaces.C.long;
subtype suseconds_t is Interfaces.C.long;
type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
.. 2 ** (System.Parameters.time_t_bits - 1) - 1;
subtype clockid_t is Interfaces.C.int;
type timespec is record
tv_sec : time_t;
tv_nsec : long;
end record;
pragma Convention (C, timespec);
type timeval is record
tv_sec : time_t;
tv_usec : suseconds_t;
end record;
pragma Convention (C, timeval);
-----------
-- Errno --
-----------
-17
View File
@@ -36,7 +36,6 @@
-- Preelaborate. This package is designed to be a bottom-level (leaf) package.
with Interfaces.C;
with System.Parameters;
package System.Linux is
pragma Preelaborate;
@@ -45,24 +44,8 @@ package System.Linux is
-- Time --
----------
subtype long is Interfaces.C.long;
subtype suseconds_t is Interfaces.C.long;
type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
.. 2 ** (System.Parameters.time_t_bits - 1) - 1;
subtype clockid_t is Interfaces.C.int;
type timespec is record
tv_sec : time_t;
tv_nsec : long;
end record;
pragma Convention (C, timespec);
type timeval is record
tv_sec : time_t;
tv_usec : suseconds_t;
end record;
pragma Convention (C, timeval);
-----------
-- Errno --
-----------
-18
View File
@@ -35,7 +35,6 @@
-- Preelaborate. This package is designed to be a bottom-level (leaf) package
with Interfaces.C;
with System.Parameters;
package System.Linux is
pragma Preelaborate;
@@ -44,25 +43,8 @@ package System.Linux is
-- Time --
----------
subtype int is Interfaces.C.int;
subtype long is Interfaces.C.long;
subtype suseconds_t is Interfaces.C.long;
type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
.. 2 ** (System.Parameters.time_t_bits - 1) - 1;
subtype clockid_t is Interfaces.C.int;
type timespec is record
tv_sec : time_t;
tv_nsec : long;
end record;
pragma Convention (C, timespec);
type timeval is record
tv_sec : time_t;
tv_usec : suseconds_t;
end record;
pragma Convention (C, timeval);
-----------
-- Errno --
-----------
+2 -20
View File
@@ -35,7 +35,6 @@
-- Preelaborate. This package is designed to be a bottom-level (leaf) package
with Interfaces.C;
with System.Parameters;
package System.Linux is
pragma Preelaborate;
@@ -44,25 +43,8 @@ package System.Linux is
-- Time --
----------
subtype int is Interfaces.C.int;
subtype long is Interfaces.C.long;
subtype suseconds_t is Interfaces.C.long;
type time_t is range -2 ** (System.Parameters.time_t_bits - 1)
.. 2 ** (System.Parameters.time_t_bits - 1) - 1;
subtype clockid_t is Interfaces.C.int;
type timespec is record
tv_sec : time_t;
tv_nsec : long;
end record;
pragma Convention (C, timespec);
type timeval is record
tv_sec : time_t;
tv_usec : suseconds_t;
end record;
pragma Convention (C, timeval);
-----------
-- Errno --
-----------
@@ -125,8 +107,8 @@ package System.Linux is
-- struct_sigaction offsets
sa_handler_pos : constant := int'Size / 8;
sa_mask_pos : constant := int'Size / 8 +
sa_handler_pos : constant := Interfaces.C.int'Size / 8;
sa_mask_pos : constant := Interfaces.C.int'Size / 8 +
Standard'Address_Size / 8;
sa_flags_pos : constant := 0;

Some files were not shown because too many files have changed in this diff Show More