]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
12 days agoaarch64: Enable parsing of user-provided AArch64 CPU tuning parameters
Soumya AR [Wed, 16 Jul 2025 13:29:57 +0000 (06:29 -0700)] 
aarch64: Enable parsing of user-provided AArch64 CPU tuning parameters

This patch adds support for loading custom CPU tuning parameters from a JSON
file for AArch64 targets. The '-muser-provided-CPU=' flag accepts a user
provided JSON file and overrides the internal tuning parameters at GCC runtime.

This patch was bootstrapped and regtested on aarch64-linux-gnu, no regression.

Signed-off-by: Soumya AR <soumyaa@nvidia.com>
gcc/ChangeLog:

* config.gcc: Add aarch64-json-tunings-parser.o.
* config/aarch64/aarch64.cc (aarch64_override_options_internal): Invoke
aarch64_load_tuning_params_from_json if -muser-provided-CPU= is
(aarch64_json_tunings_tests): Extern aarch64_json_tunings_tests().
(aarch64_run_selftests): Add aarch64_json_tunings_tests().
* config/aarch64/aarch64.opt: New option.
* config/aarch64/t-aarch64 (aarch64-json-tunings-parser.o): New define.
* config/aarch64/aarch64-json-schema.h: New file.
* config/aarch64/aarch64-json-tunings-parser.cc: New file.
* config/aarch64/aarch64-json-tunings-parser.h: New file.

12 days agojson: Add get_map() method to JSON object class
Soumya AR [Fri, 11 Jul 2025 12:54:33 +0000 (05:54 -0700)] 
json: Add get_map() method to JSON object class

This patch adds a get_map () method to the JSON object class to provide access
to the underlying hash map that stores the JSON key-value pairs.

To do this, we expose the map_t typedef, the return type of get_map().

This change is needed to allow traversal of key-value pairs when parsing
user-provided JSON tuning data.

Additionally, is_a_helper template specializations for json::literal * and
const json::literal * were added to make dynamic casting in the next patch
easier.

This patch was bootstrapped and regtested on aarch64-linux-gnu, no regression.

Signed-off-by: Soumya AR <soumyaa@nvidia.com>
gcc/ChangeLog:

* json.h (class object): Add get_map () method.
(is_a_helper<json::literal *>, is_a_helper<const json::literal *>):
New template specializations.

12 days agoaarch64: Enable dumping of AArch64 CPU tuning parameters to JSON
Soumya AR [Fri, 11 Jul 2025 12:28:17 +0000 (05:28 -0700)] 
aarch64: Enable dumping of AArch64 CPU tuning parameters to JSON

This patch adds functionality to dump AArch64 CPU tuning parameters to a JSON
file. The new '-fdump-tuning-model=' flag allows users to export the current
tuning model configuration to a JSON file.

This patch was bootstrapped and regtested on aarch64-linux-gnu, no regression.

Signed-off-by: Soumya AR <soumyaa@nvidia.com>
gcc/ChangeLog:

* config.gcc: Add aarch64-json-tunings-printer.o.
* config/aarch64/aarch64.cc (aarch64_override_options_internal): Invoke
aarch64_print_tune_params if -fdump-tuning-model= is specified.
* config/aarch64/aarch64.opt: New option.
* config/aarch64/t-aarch64 (aarch64-json-tunings-printer.o): New define.
* config/aarch64/aarch64-json-tunings-printer.cc: New file.
* config/aarch64/aarch64-json-tunings-printer.h: New file.

12 days agoaarch64 + arm: Remove const keyword from tune_params members and nested members
Soumya AR [Thu, 10 Jul 2025 10:52:00 +0000 (03:52 -0700)] 
aarch64 + arm: Remove const keyword from tune_params members and nested members

To allow runtime updates to tuning parameters, the const keyword is removed from
the members of the tune_params structure and the members of its nested
structures.

Since this patch also touches tuning structures in the arm backend, it was
bootstrapped on aarch64-linux-gnu as well as arm-linux-gnueabihf.

Signed-off-by: Soumya AR <soumyaa@nvidia.com>
gcc/ChangeLog:

* config/aarch64/aarch64-protos.h
(struct scale_addr_mode_cost): Remove const from struct members.
(struct cpu_addrcost_table): Likewise.
(struct cpu_regmove_cost): Likewise.
(struct simd_vec_cost): Likewise.
(struct sve_vec_cost): Likewise.
(struct aarch64_base_vec_issue_info): Likewise.
(struct aarch64_simd_vec_issue_info): Likewise.
(struct aarch64_sve_vec_issue_info): Likewise.
(struct aarch64_vec_issue_info): Likewise.
(struct cpu_vector_cost): Likewise.
(struct cpu_branch_cost): Likewise.
(struct cpu_approx_modes): Likewise.
(struct cpu_prefetch_tune): Likewise.
* config/arm/aarch-common-protos.h
(struct alu_cost_table): Remove const from struct members.
(struct mult_cost_table): Likewise.
(struct mem_cost_table): Likewise.
(struct fp_cost_table): Likewise.
(struct vector_cost_table): Likewise.
(struct cpu_cost_table): Likewise.

12 days agolibstdc++: Hashing support for chrono value classes [PR110357]
Tomasz Kamiński [Wed, 19 Nov 2025 09:29:18 +0000 (10:29 +0100)] 
libstdc++: Hashing support for chrono value classes [PR110357]

This patch implements P2592R3 Hashing support for std::chrono value classes.

To avoid the know issues with current hashing of integer types (see PR104945),
we use chrono::__int_hash function that hash the bytes of representation,
instead of hash<T>, as the later simply cast to value. Currently _Hash_impl
it used, but we should consider replacing it (see PR55815) before C++26 ABI
is made stable. The function is declared inside <chrono> header and chrono
namespace, to make sure that only chrono components would be affected by
such change. Finally, chrono::__int_hash is made variadic, to support
combining hashes of multiple integers.

To reduce the number of calls to hasher (defined out of line), the calendar
types are packed into single unsigned integer value. This is done by
chrono::__hash helper, that calls:
* chrono::__as_int to cast the value of single component, to unsigned integer
  with size matching the one used by internal representation: unsigned short
  for year/weekday_indexed, and unsigned char in all other cases,
* chrono::__pack_ints to pack integers (if more than one) into single integer
  by performing bit shift operations,
* chrono::__int_hash to hash the value produced by above.

Hashing of duration, time_point, and zoned_time only hashes the value and
ignores any difference in the period, i.e. hashes of nanoseconds(2) and
seconds(2) are the same. This does not affect the usages inside unordered
containers, as the arguments are converted to key type first. To address
that period::num and period::den could be included in the hash, however
such approach will not make hashes of equal durations (2000ms, 2s) equal,
so they would remain unusable for precomputed hashes. In consequence,
including period in hash, would only increase runtime cost, withou any
clear benefits.

Futhermore,  chrono::__int_hash is used when the duration representation
is integral type, and for other types (floating point due special handling
of +/-0.0 and user defined types) we delegate to hash specialization.
This is automatically picked up by time_point, that delegates to hasher
of duration. Similarly for leap_second that is specified to use integer
durations, we simply hash representations of date() and value(). Finally
zoned_time in addition to handling integer durations as described above,
we also use __int_hash for const time_zone* (if used), as hash<T*> have
similar problems as hash specialization for integers. This is limited
only to _TimeZonePtr being const time_zone* (default), as user can define
hash specializations for raw pointers to they zones.

As accessing the representation for duration requires calling count()
method that returns a copy of representation by value, the noexcept
specification of the hasher needs to take into consideration copy
constructor of duration. Similar reasoning applies for time_since_epoch
for time_points, and get_sys_time, get_time_zone for zoned_time.
For all this cases we use internal __is_nothrow_copy_hashable concept.

Finally support for zoned_time is provided only for CXX11 string ABI,
__cpp_lib_chrono feature test macro cannot be bumped if COW string are used.
To indicate presence of hasher for remaining types this patch also bumps
the internal __glibcxx_chrono_cxx20 macro, and uses it as guard to new
features.

PR libstdc++/110357

libstdc++-v3/ChangeLog:

* include/bits/version.def (chrono, chrono_cxx20): Bump values.
* include/bits/version.h: Regenerate.
* include/std/chrono (__is_nothrow_copy_hashable)
(chrono::__pack_ints, chrono::__as_int, chrono::__int_hash)
(chrono::__hash): Define.
(std::hash): Define partial specialization for duration, time_point,
and zoned_time, and full specializations for calendar types and
leap_second.
(std::__is_fast_hash): Define partial specializations for duration,
time_point, zoned_time.
* testsuite/std/time/hash.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Co-authored-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
12 days agoFortran: Implement finalization PDTs [PR104650]
Paul Thomas [Wed, 26 Nov 2025 06:59:20 +0000 (06:59 +0000)] 
Fortran: Implement finalization PDTs [PR104650]

2025-11-26  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/104650
* decl.cc (gfc_get_pdt_instance): If the PDT template has
finalizers, make a new f2k_derived namespace for this intance
and copy the template namespace into it. Set the instance
template_sym field to point to the template.
* expr.cc (gfc_check_pointer_assign): Allow array value pointer
lvalues to point to scalar null expressions in initialization.
* gfortran.h : Add the template_sym field to gfc_symbol.
* resolve.cc (gfc_resolve_finalizers): For a pdt_type, copy the
final subroutines with the same type argument into the pdt_type
finalizer list. Prevent final subroutine type checking and
creation of the vtab for pdt_templates.
* symbol.cc (gfc_free_symbol): Do not call gfc_free_namespace
for pdt_type with finalizers. Instead, free the finalizers and
the namespace.

gcc/testsuite
PR fortran/104650
* gfortran.dg/pdt_70.f03: New test.

13 days agoMake better use of overflowing operations in max/min(a, add/sub(a, b)) [PR116815]
Dhruv Chawla [Wed, 23 Jul 2025 08:41:51 +0000 (01:41 -0700)] 
Make better use of overflowing operations in max/min(a, add/sub(a, b)) [PR116815]

This patch folds the following patterns:
- For add:
  - umax (a, add (a, b)) -> [sum,  ovf] = adds (a, b); !ovf ? sum : a
  - umin (a, add (a, b)) -> [sum,  ovf] = adds (a, b); !ovf ? a : sum
    ... along with the commutated versions:
  - umax (a, add (b, a)) -> [sum,  ovf] = adds (b, a); !ovf ? sum : a
  - umin (a, add (b, a)) -> [sum,  ovf] = adds (b, a); !ovf ? a : sum
- For sub:
  - umax (a, sub (a, b)) -> [diff, udf] = subs (a, b); udf ? diff : a
  - umin (a, sub (a, b)) -> [diff, udf] = subs (a, b); udf ? a : diff

Where ovf is the overflow flag and udf is the underflow flag. adds and subs are
generated by generating parallel compare+plus/minus which map to
add<mode>3_compareC and sub<mode>3_compare1.

This patch is a respin of the patch posted at
https://gcc.gnu.org/pipermail/gcc-patches/2025-May/685021.html as per
the suggestion to turn it into a target-specific transform by Richard
Biener.

FIXME: This pattern cannot currently factor multiple occurences of the
       add expression into a single adds, eg: max (a, a + b) + min (a + b, b)
       ends up generating two adds instructions. This is something that
       was lost when going from GIMPLE to target-specific transforms.

Bootstrapped and regtested on aarch64-unknown-linux-gnu.

Signed-off-by: Dhruv Chawla <dhruvc@nvidia.com>
PR middle-end/116815

gcc/ChangeLog:

* config/aarch64/aarch64.md
(*aarch64_plus_within_<optab><mode>3_<ovf_commutate>): New pattern.
(*aarch64_minus_within_<optab><mode>3): Likewise.
* config/aarch64/iterators.md (ovf_add_cmp): New code attribute.
(udf_sub_cmp): Likewise.
(UMAXMIN): New code iterator.
(ovf_commutate): New iterator.
(ovf_comm_opp): New int attribute.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/pr116815-1.c: New test.
* gcc.target/aarch64/pr116815-2.c: Likewise.
* gcc.target/aarch64/pr116815-3.c: Likewise.

13 days agoRISC-V: Add testcase for unsigned scalar SAT_MUL form 7
Pan Li [Mon, 20 Oct 2025 13:08:46 +0000 (21:08 +0800)] 
RISC-V: Add testcase for unsigned scalar SAT_MUL form 7

The form 7 of unsigned scalar SAT_MUL has supported from the
previous change.  Thus, add the test cases to make sure it
works well.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pan Li <pan2.li@intel.com>
13 days agoMatch: Add unsigned SAT_MUL for form 7
Pan Li [Tue, 25 Nov 2025 07:18:38 +0000 (15:18 +0800)] 
Match: Add unsigned SAT_MUL for form 7

This patch would like to try to match the the unsigned
SAT_MUL form 7, aka below:

  #define DEF_SAT_U_MUL_FMT_7(NT, WT)             \
  NT __attribute__((noinline))                    \
  sat_u_mul_##NT##_from_##WT##_fmt_7 (NT a, NT b) \
  {                                               \
    WT x = (WT)a * (WT)b;                         \
    NT max = -1;                                  \
    bool overflow_p = x > (WT)(max);              \
    return -(NT)(overflow_p) | (NT)x;             \
  }

while WT is uint128_t, uint64_t, uint32_t and uint16_t, and
NT is uint64_t, uint32_t, uint16_t or uint8_t.

gcc/ChangeLog:

* match.pd: Add pattern for SAT_MUL form 7 include
mul and widen_mul.

Signed-off-by: Pan Li <pan2.li@intel.com>
13 days agophiprop: Small compile time improvement for phiprop
Andrew Pinski [Tue, 25 Nov 2025 07:34:45 +0000 (23:34 -0800)] 
phiprop: Small compile time improvement for phiprop

Now that post dom information is only needed when the new store
can trap (since r16-5555-g952e145796d), only calculate it when
that is the case. It was calculated on demand by
r14-2051-g3124bfb14c0bdc. This just changes when we need to
calculate it.

Pushed as obvious.

gcc/ChangeLog:

* tree-ssa-phiprop.cc (propagate_with_phi): Only
calculate on demand post dom info when the new store
might trap.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
13 days agophiprop: Make sure types of the load match the inserted phi [PR122847]
Andrew Pinski [Tue, 25 Nov 2025 22:19:18 +0000 (14:19 -0800)] 
phiprop: Make sure types of the load match the inserted phi [PR122847]

This was introduced with r16-5556-ge94e91d6f3775, but the type
check for the delay was not happen because the type at the point
of delaying was set to NULL. It is only until a non-delayed load
when the phi is created, the type is set.

This adds the type check to the replacement for the delayed statements.

Pushed as obvious.

PR tree-optimization/122847

gcc/ChangeLog:

* tree-ssa-phiprop.cc (propagate_with_phi): Add type
check for reuse of the phi for the delayed statements.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
13 days agoDaily bump.
GCC Administrator [Wed, 26 Nov 2025 00:20:39 +0000 (00:20 +0000)] 
Daily bump.

13 days ago[PATCH] libgomp: Fix GCC build after glibc@cd748a6
Frank Scheiner [Tue, 25 Nov 2025 23:58:23 +0000 (16:58 -0700)] 
[PATCH] libgomp: Fix GCC build after glibc@cd748a6

The toolchain autobuilds for ia64 failed ([1]) yesterday with:

```
libtool: compile:  /usr/src/t2-src/src.gcc.ia64-toolchain.251121.040147.278918/gcc-16-20251116/objs/gcc/xgcc-wrapper /usr/src/t2-src/src.gcc.ia64-toolchain.251121.040147.278918/gcc-16-20251116/objs/./gcc/xgcc -B/usr/src/t2-src/src.gcc.ia64-toolchain.251121.040147.278918/gcc-16-20251116/objs/./gcc/ -B/usr/src/t2-src/build/ia64-toolchain-24-svn-generic-ia64-itanium2-cross-linux/TOOLCHAIN/cross/usr/ia64-t2-linux-gnu/bin/ -B/usr/src/t2-src/build/ia64-toolchain-24-svn-generic-ia64-itanium2-cross-linux/TOOLCHAIN/cross/usr/ia64-t2-linux-gnu/lib/ -isystem /usr/src/t2-src/build/ia64-toolchain-24-svn-generic-ia64-itanium2-cross-linux/TOOLCHAIN/cross/usr/ia64-t2-linux-gnu/include -isystem /usr/src/t2-src/build/ia64-toolchain-24-svn-generic-ia64-itanium2-cross-linux/TOOLCHAIN/cross/usr/ia64-t2-linux-gnu/sys-include --sysroot=/usr/src/t2-src/build/ia64-toolchain-24-svn-generic-ia64-itanium2-cross-linux -DHAVE_CONFIG_H -I. -I../../../libgomp -I../../../libgomp/config/linux/ia64 -I../../../libgomp/config/linux -I../../../libgomp/config/posix -I../../../libgomp -I../../../libgomp/../include -Wall -Werror -ftls-model=initial-exec -pthread -DUSING_INITIAL_EXEC_TLS -g -O2 -MT oacc-cuda.lo -MD -MP -MF .deps/oacc-cuda.Tpo -c ../../../libgomp/oacc-cuda.c -o oacc-cuda.o >/dev/null 2>&1
../../../libgomp/affinity-fmt.c: In function 'gomp_display_affinity':
../../../libgomp/affinity-fmt.c:330:25: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
  330 |               char *q = strchr (p + 1, '}');
      |                         ^~~~~~
```

[1]: https://github.com/johnny-mnemonic/toolchain-autobuilds/actions/runs/19559235881

This is not ia64-specific but due to the changes in the recent glibc
commit "Implement C23 const-preserving standard library macros" (i.e.
[2]) now requiring "char *q" to be a pointer to a const char to compile
w/o error because of the return value of strchr() .

[2]: https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690

Also see the related discussion at [3] for details.

[3]: https://sourceware.org/pipermail/libc-alpha/2025-November/172809.html

The GCC build is fixed by the attached patch, see [4] for a successful
build with the then latest snapshots of binutils, glibc and GCC.

[4]: https://github.com/johnny-mnemonic/toolchain-autobuilds/actions/runs/19585045571

Idea from Tomas, attached patch from me.

Cheers,
Frank

0001-libgomp-Fix-GCC-build-after-glibc-cd748a6.patch

From 80af9c233c694904174b54a59404d311378f41f8 Mon Sep 17 00:00:00 2001
From: Frank Scheiner <frank.scheiner@web.de>
Date: Sat, 22 Nov 2025 14:58:10 +0100
Subject: [PATCH] libgomp: Fix GCC build after glibc@cd748a6

char *q needs to be a pointer to a const char for the return value of
strchr() with glibc after "Implement C23 const-preserving standard library
macros".

[glibc@cd748a6]: https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690

libgomp/ChangeLog:
* affinity-fmt.c: Make char *q a pointer to a const char.

13 days agogccrs: Add test for issue Rust-GCC#3608
Lúcio Boari Fleury [Sat, 22 Nov 2025 14:55:39 +0000 (11:55 -0300)] 
gccrs: Add test for issue Rust-GCC#3608

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro-issue3608.rs: New Test. The test skips an issue at line 11

Signed-off-by: Lúcio Boari Fleury <lucboari@gmail.com>
13 days agogccrs: stop an infinite loop at END_OF_FILE
Lúcio Boari Fleury [Sat, 22 Nov 2025 01:04:25 +0000 (22:04 -0300)] 
gccrs: stop an infinite loop at END_OF_FILE

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h: Add early exit condition to parsing loop.

Signed-off-by: Lúcio Boari Fleury <lucboari@gmail.com>
13 days agogccrs: Add support for initial generic associated types
Philip Herron [Mon, 17 Nov 2025 21:14:44 +0000 (21:14 +0000)] 
gccrs: Add support for initial generic associated types

This patch is the initial part in supporting generic associated types. In rust we have
trait item types that get implemented for example:

  trait Foo<T> {
    type Bar
  }

  impl<T> Foo for T {
    type Bar = T
  }

The trait position uses a Ty::Placeholder which is just a thing that gets set for
lazy evaluation to the impl type alias which is actually a Ty::Projection see:

  0798add3d3c1bf4b20ecc1b4fa1047ba4ba19759

For more info the projection type needs to hold onto generics in order to properly
support generic types this GAT's support extends this all the way to the placeholder
which still needs to be done.

Fixes Rust-GCC#4276

gcc/rust/ChangeLog:

* ast/rust-ast.cc (TraitItemType::as_string): add generic params
* ast/rust-ast.h: remove old comment
* ast/rust-item.h: add generic params to associated type
* ast/rust-type.h: remove old comment
* hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): hir lowering for gat's
* hir/tree/rust-hir-item.cc (TraitItemType::TraitItemType): gat's on TraitItemType
(TraitItemType::operator=): preserve generic params
* hir/tree/rust-hir-item.h: likewise
* hir/tree/rust-hir.cc (TraitItemType::as_string): likewise
* parse/rust-parse-impl.h (Parser::parse_trait_type): hit the < and parse params
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit): typecheck
* typecheck/rust-tyty.cc (BaseType::has_substitutions_defined): dont destructure

gcc/testsuite/ChangeLog:

* rust/compile/gat1.rs: New test.
* rust/execute/torture/gat1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
13 days agogccrs: add error check if derive has wrong item
Lucas Ly Ba [Tue, 14 Oct 2025 13:40:04 +0000 (13:40 +0000)] 
gccrs: add error check if derive has wrong item

Derive may only be applied to structs, enums and unions.

gcc/rust/ChangeLog:

* expand/rust-derive.cc (DeriveVisitor::derive):
Add check and error.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
13 days agogccrs: fix segfault on empty doc attribute
Lucas Ly Ba [Fri, 7 Nov 2025 16:38:46 +0000 (16:38 +0000)] 
gccrs: fix segfault on empty doc attribute

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_doc_item_attribute): Make error.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
13 days agogccrs: Fix compile_float_literal not compiling negatives properly
Yap Zhi Heng [Sat, 15 Nov 2025 07:08:36 +0000 (15:08 +0800)] 
gccrs: Fix compile_float_literal not compiling negatives properly

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (compile_float_literal): Add is_negative
check to compile negative float literals properly.
* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit(RangePattern)):
Minor optimization to E0579 checks to reduce memory copy.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
13 days agogccrs: Improve feature handling
Owen Avery [Sun, 17 Aug 2025 18:15:35 +0000 (14:15 -0400)] 
gccrs: Improve feature handling

This includes a program, written using flex and bison, to extract
information on unstable features from rustc source code and save it to a
header file.

The script does fetch files from https://github.com/rust-lang/rust (the
official rustc git repository), which should be alright, as it's only
intended to be run by maintainers.

See https://doc.rust-lang.org/unstable-book/ for information on unstable
features.

gcc/rust/ChangeLog:

* checks/errors/feature/rust-feature-gate.cc
(FeatureGate::gate): Handle removal of Feature::create.
(FeatureGate::visit): Refer to AUTO_TRAITS as
OPTIN_BUILTIN_TRAITS.
* checks/errors/feature/rust-feature.cc (Feature::create):
Remove.
(Feature::feature_list): New static member variable.
(Feature::name_hash_map): Use "rust-feature-defs.h" to define.
(Feature::lookup): New member function definition.
* checks/errors/feature/rust-feature.h (Feature::State): Add
comments.
(Feature::Name): Use "rust-feature-defs.h" to define.
(Feature::as_string): Make const.
(Feature::name): Likewise.
(Feature::state): Likewise.
(Feature::issue): Likewise.
(Feature::description): Remove member function declaration.
(Feature::create): Remove static member function declaration.
(Feature::lookup): New member function declarations.
(Feature::Feature): Adjust arguments.
(Feature::m_rustc_since): Rename to...
(Feature::m_rust_since): ...here.
(Feature::m_description): Remove.
(Feature::m_reason): New member variable.
(Feature::feature_list): New static member variable.
* checks/errors/feature/rust-feature-defs.h: New file.
* checks/errors/feature/contrib/parse.y: New file.
* checks/errors/feature/contrib/scan.l: New file.
* checks/errors/feature/contrib/.gitignore: New file.
* checks/errors/feature/contrib/Makefile: New file.
* checks/errors/feature/contrib/fetch: New file.
* checks/errors/feature/contrib/regen: New file.
* checks/errors/feature/contrib/copyright-stub.h: New file.
* checks/errors/feature/contrib/README: New file.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 days agogccrs: fix cfg attribute without parentheses error
Lucas Ly Ba [Thu, 6 Nov 2025 15:37:52 +0000 (15:37 +0000)] 
gccrs: fix cfg attribute without parentheses error

gcc/rust/ChangeLog:

* ast/rust-ast.cc (Attribute::check_cfg_predicate): Make error when attribute has no input.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
13 days agogccrs: Create LocalVariable
Owen Avery [Sat, 28 Jun 2025 01:44:01 +0000 (21:44 -0400)] 
gccrs: Create LocalVariable

This should make it easier for us to move away from leaking pointers to
Bvariable everywhere. Since LocalVariable has a single field of type
tree, it should be the same size as a pointer to Bvariable, making the
switch to LocalVariable wherever possible strictly an improvement.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Implicitly
convert LocalVariable to pointer to Bvariable.
* rust-backend.h (local_variable): Return LocalVariable.
(parameter_variable): Likewise.
(static_chain_variable): Likewise.
(temporary_variable): Likewise.
* rust-gcc.cc (local_variable): Likewise.
(parameter_variable): Likewise.
(static_chain_variable): Likewise.
(temporary_variable): Likewise.
(LocalVariable::get_tree): New function.
(LocalVariable::error_variable): Likewise.
* rust-gcc.h (class LocalVariable): New class.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 days agogccrs: fixes previously added tests
lenny.chiadmi-delage [Wed, 12 Nov 2025 10:10:54 +0000 (10:10 +0000)] 
gccrs: fixes previously added tests

Fixes previously added tests.

Fixes Rust-GCC#4140

gcc/testsuite/ChangeLog:

* rust/compile/issue-4140-1.rs: Fixes test.
* rust/compile/issue-4140-2.rs: Likewise.

Signed-off-by: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
13 days agogccrs: adds tests from issue 4140
lenny.chiadmi-delage [Mon, 10 Nov 2025 16:00:29 +0000 (16:00 +0000)] 
gccrs: adds tests from issue 4140

Adds tests for testsuite.

Fixes Rust-GCC#4140

gcc/testsuite/ChangeLog:

* rust/compile/issue-4140-1.rs: New test.
* rust/compile/issue-4140-2.rs: Likewise.

Signed-off-by: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
13 days agogccrs: fix segfault in clone_pattern w macro
lenny.chiadmi-delage [Wed, 15 Oct 2025 15:07:05 +0000 (15:07 +0000)] 
gccrs: fix segfault in clone_pattern w macro

Check if parser throw an error to avoid cloning nullptr

Fixes Rust-GCC#4140

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (transcribe_expression): Check if
parser didn't fail.
(transcribe_type): Likewise.
(transcribe_pattern): Likewise.

Signed-off-by: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
13 days agobuild: Save/restore CXXFLAGS for zstd tests
Rainer Orth [Tue, 25 Nov 2025 21:25:48 +0000 (22:25 +0100)] 
build: Save/restore CXXFLAGS for zstd tests

I recently encountered a bootstrap failure on trunk caused by the fact
that an older out-of-tree version of ansidecl.h was found before the
in-tree one in $top_srcdir/include, so some macros from that header
that are used in gcc weren't defined.

The out-of-tree version was located in $ZSTD_INC (-I/vol/gcc/include)
which caused that directory to be included in gcc's CXXFLAGS like

CXXFLAGS='-g -O2 -fchecking=1 -I/vol/gcc/include'

causing it to be searched before $srcdir/../include.

I could trace this to the zstd.h test in gcc/configure.ac which sets
CXXFLAGS and LDFLAGS before the actual test, but doesn't reset them
afterwards.

So this patch does just that.

Bootstrapped without regressions on i386-pc-solaris2.11 and
x86_64-pc-linux-gnu.

2025-10-22  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc:
* configure.ac (gcc_cv_header_zstd_h): Save, restore CXXFLAGS,
LDFLAGS.
* configure: Regenerate.

13 days agolibstdc++: Bump libtool_VERSION for GCC 16
Jonathan Wakely [Mon, 24 Nov 2025 14:54:07 +0000 (14:54 +0000)] 
libstdc++: Bump libtool_VERSION for GCC 16

This should have been done in r16-995-gda9b2ea04c084d (or any of the
later changes that added new symbols to trunk).

libstdc++-v3/ChangeLog:

* acinclude.m4 (libtool_VERSION): Bump version.
* configure: Regenerate.

13 days agotestsuite: fix issues in gcc.dg/analyzer/strchr-1.c seen with C23 libc
David Malcolm [Tue, 25 Nov 2025 17:44:10 +0000 (12:44 -0500)] 
testsuite: fix issues in gcc.dg/analyzer/strchr-1.c seen with C23 libc

Simplify this test case in the hope of avoiding an error seen
with glibc-2.42.9000-537-gcd748a63ab1 in CI with
"Implement C23 const-preserving standard library macros".

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/strchr-1.c: Drop include of <string.h>, and use
__builtin_strchr throughout rather than strchr to avoid const
correctness issues when the header implements strchr with a C23
const-preserving macro.  Drop "const" from two vars.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
13 days agoanalyzer: add logging to deref_before_check::emit
David Malcolm [Tue, 25 Nov 2025 17:43:52 +0000 (12:43 -0500)] 
analyzer: add logging to deref_before_check::emit

gcc/analyzer/ChangeLog:
* sm-malloc.cc (deref_before_check::emit): Add logging of the
various conditions for late-rejection of a
-Wanalyzer-deref-before-check warning.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
13 days agolto/122515: Avoid using SSIZE_MAX
Siddhesh Poyarekar [Tue, 25 Nov 2025 01:32:08 +0000 (20:32 -0500)] 
lto/122515: Avoid using SSIZE_MAX

SSIZE_MAX may not always be available, so build it using (size_t) -1
instead.

gcc/lto/ChangeLog:

PR lto/122515
* lto-common.cc (lto_read_section_data): Avoid using SSIZE_MAX.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
13 days agoAArch64: Implement {cond_}vec_cbranch_{any|all} [PR118974]
Tamar Christina [Tue, 25 Nov 2025 12:52:56 +0000 (12:52 +0000)] 
AArch64: Implement {cond_}vec_cbranch_{any|all} [PR118974]

The following example:

#define N 640
int a[N] = {};
int b[N] = {};
int c[N] = {};

void f1 (int d)
{
  for (int i = 0; i < N; i++)
    {
      b[i] += a[i];
      if (a[i] != d)
        break;
    }
}

today generates with
-Ofast -march=armv8-a+sve --param aarch64-autovec-preference=asimd-only

.L6:
        ldr     q30, [x3, x1]
        cmeq    v31.4s, v30.4s, v27.4s
        not     v31.16b, v31.16b
        umaxp   v31.4s, v31.4s, v31.4s
        fmov    x4, d31
        cbz     x4, .L2

Where an we use an Adv. SIMD compare and a reduction sequence to implement
early break.  This patch implements the new optabs vec_cbranch_any and
vec_cbranch_all in order to replace the Adv. SIMD compare and reduction with
an SVE flag-setting compare.

With this patch the above generates:

        ptrue   p7.b, vl16
.L6:
        ldr     q30, [x3, x1]
        cmpne   p15.s, p7/z, z30.s, z27.s
        b.none  .L2

This optab could also be used for optimizing the Adv. SIMD Sequence when SVE
is not available.  I have a separate patch for that and will send depending on
if this approach is accepted or not.

Note that for floating-point we still need the ptest as floating point SVE
compares don't set flags.  In addition because SVE doesn't have a CMTST
equivalent instruction we have to do an explicit AND before the compares.

These two cases don't have a speed advantage, but do have a codesize one
so I've left them enabled.

This patch also eliminated PTEST on normal SVE compare and branch through
the introduction of new optabs cond_vec_cbranch_any and cond_vec_cbranch_all.

In the example

void f1 ()
{
  for (int i = 0; i < N; i++)
    {
      b[i] += a[i];
      if (a[i] > 0)
break;
    }
}

when compiled for SVE we generate:

        ld1w    z28.s, p7/z, [x4, x0, lsl 2]
        cmpgt   p14.s, p7/z, z28.s, #0
        ptest   p15, p14.b
        b.none  .L3

Where the ptest isn't needed since the branch only cares about the Z and NZ
flags.

GCC Today supports eliding this through the pattern *cmp<cmp_op><mode>_ptest
however this pattern only supports the removal when the outermost context is a
CMP where the predicate is inside the condition itself.

This typically only happens for an unpredicated CMP as a ptrue will be generated
during expand.

In the case about at the GIMPLE level we have

  mask_patt_14.15_57 = vect__2.11_52 > { 0, ... };
  vec_mask_and_58 = loop_mask_48 & mask_patt_14.15_57;
  if (vec_mask_and_58 != { 0, ... })
    goto <bb 5>; [5.50%]
  else
    goto <bb 6>; [94.50%]

where the loop mask is applied to the compare as an AND.

The loop mask is moved into the compare by the pattern *cmp<cmp_op><mode>_and
which moves the mask inside if the current mask is a ptrue since
p && true -> p.

However this happens after combine, and so we can't both move the predicate
inside AND eliminate the ptests.

To fix this the middle-end will now rewrite the mask into the compare optab
and indicate that only the CC flags are required.  This allows us to simply
not generate the ptest at all, rather than trying to eliminate it later on.

After this patch we generate

        ld1w    z28.s, p7/z, [x4, x0, lsl 2]
        cmpgt   p14.s, p7/z, z28.s, #0
        b.none  .L3

gcc/ChangeLog:

PR target/118974
* config/aarch64/aarch64-simd.md (xor<mode>3<vczle><vczbe>): Rename ...
(@xor<mode>3<vczle><vczbe>): .. to this.
(cbranch<mode>4): Update comments.
(<optab><mode>): New.
* config/aarch64/aarch64-sve.md (cbranch<mode>4): Update comment.
(<optab><mode>): New.
(aarch64_ptest<mode>): Rename to ...
(@aarch64_ptest<mode>): .. this.
* config/aarch64/iterators.md (UNSPEC_CMP_ALL, UNSPEC_CMP_ANY,
UNSPEC_COND_CMP_ALL, UNSPEC_COND_CMP_ANY): New.
(optabs): Add them.
(CBRANCH_CMP, COND_CBRANCH_CMP, cbranch_op): New.
* config/aarch64/predicates.md (aarch64_cbranch_compare_operation): New.

gcc/testsuite/ChangeLog:

PR target/118974
* gcc.target/aarch64/sve/pr119351.c: Update codegen.
* gcc.target/aarch64/sve/vect-early-break-cbranch.c: Likewise.
* gcc.target/aarch64/vect-early-break-cbranch.c: Likewise.
* gcc.target/aarch64/sve/vect-early-break-cbranch_2.c: New test.
* gcc.target/aarch64/sve/vect-early-break-cbranch_3.c: New test.
* gcc.target/aarch64/sve/vect-early-break-cbranch_4.c: New test.
* gcc.target/aarch64/sve/vect-early-break-cbranch_5.c: New test.
* gcc.target/aarch64/sve/vect-early-break-cbranch_7.c: New test.
* gcc.target/aarch64/sve/vect-early-break-cbranch_8.c: New test.
* gcc.target/aarch64/vect-early-break-cbranch_2.c: New test.
* gcc.target/aarch64/vect-early-break-cbranch_3.c: New test.

13 days agovect: check support for gcond with {cond{_len}_}vec_cbranch_{any|all} optabs [PR118974]
Tamar Christina [Tue, 25 Nov 2025 12:51:52 +0000 (12:51 +0000)] 
vect: check support for gcond with {cond{_len}_}vec_cbranch_{any|all} optabs [PR118974]

This change allows a target to only implement the explicit vec_cbranch optabs.
To do this the vectorizer is updated to check for the new optabs directly.

Targets that have a different type for BOOLEAN_VECTOR_TYPE_P for instance
can use only the new optabs.

gcc/ChangeLog:

PR target/118974
* tree-vect-stmts.cc (supports_vector_compare_and_branch): New.
(vectorizable_early_exit): Use it.

13 days agomiddle-end: support new {cond{_len}_}vec_cbranch_{any|all} optabs [PR118974]
Tamar Christina [Tue, 25 Nov 2025 12:51:31 +0000 (12:51 +0000)] 
middle-end: support new {cond{_len}_}vec_cbranch_{any|all} optabs [PR118974]

This patch introduces six new vector cbranch optabs

1. vec_cbranch_any and vec_cbranch_all.
2. cond_vec_cbranch_any and cond_vec_cbranch_all.
3. cond_len_vec_cbranch_any and cond_len_vec_cbranch_all.

Today cbranch can be used for both vector and scalar modes.  In both these
cases it's intended to compare boolean values, either scalar or vector.

The optab documentation does not however state that it can only handle
comparisons against 0.  So many targets have added code for the vector variant
that tries to deal with the case where we branch based on two non-zero
registers.

However this code can't ever be reached because the cbranch expansion only deals
with comparisons against 0 for vectors.  This is because for vectors the rest of
the compiler has no way to generate a non-zero comparison. e.g. the vectorizer
will always generate a zero comparison, and the C/C++ front-ends won't allow
vectors to be used in a cbranch as it expects a boolean value.  ISAs like SVE
work around this by requiring you to use an SVE PTEST intrinsics which results
in a single scalar boolean value that represents the flag values.

e.g. if (svptest_any (..))

The natural question is why do we not at expand time then rewrite the comparison
to a non-zero comparison if the target supports it.

The reason is we can't safely do so.  For an ANY comparison (e.g. != b) this is
trivial, but for an ALL comparison (e.g. == b) we would have to flip both branch
and invert the value being compared.  i.e. we have to make it a != b comparison.

But in emit_cmp_and_jump_insns we can't flip the branches anymore because they
have already been lowered into a fall through branch (PC) and a label, ready for
use in an if_then_else RTL expression.

Now why does any of this matter?  Well there are three optimizations we want to be
able to do.

1. Adv. SIMD does not support a vector !=, as in there's no instruction for it.
   For both Integer and FP vectors we perform the comparisons as EQ and then
   invert the resulting mask.  Ideally we'd like to replace this with just a XOR
   and the appropriate branch.

2. When on an SVE enabled system we would like to use an SVE compare + branch
   for the Adv. SIMD sequence which could happen due to cost modelling.  However
   we can only do so based on if we know that the values being compared against
   are the boolean masks.  This means we can't really use combine to do this
   because combine would have to match the entire sequence including the
   vector comparisons because at RTL we've lost the information that
   VECTOR_BOOLEAN_P would have given us.  This sequence would be too long for
   combine to match due to it having to match the compare + branch sequence
   being generated as well.  It also becomes a bit messy to match ANY and ALL
   sequences.

3. For SVE systems we would like to avoid generating the PTEST operation
   whenever possible.  Because SVE vector integer comparisons already set flags
   we don't need the PTEST on an any or all check.  Eliminating this in RTL is
   difficult, so the best approach is to not generate the PTEST at all when not
   needed.

To handle these three cases the new optabs are added and the current cbranch is
no longer required if the target does not need help in distinguishing between
boolean vector vs data vector operands.

This difference is not important for correctness, but it is for optimization.
So I've chosen not to deprecate the cbranch_optab but make it completely optional.

I'll try to explain why:

An example is when unrolling is done on Adv. SIMD early break loops.

We generate

  vect__1.8_29 = MEM <vector(4) int> [(int *)_25];
  vect__1.9_31 = MEM <vector(4) int> [(int *)_25 + 16B];
  mask_patt_10.10_32 = vect__1.8_29 == { 124, 124, 124, 124 };
  mask_patt_10.10_33 = vect__1.9_31 == { 124, 124, 124, 124 };
  vexit_reduc_34 = .VEC_TRUNC_ADD_HIGH (mask_patt_10.10_33, mask_patt_10.10_32);
  if (vexit_reduc_34 != { 0, 0, 0, 0 })
    goto <bb 4>; [5.50%]
  else
    goto <bb 18>; [94.50%]

And so the new optabs aren't immediately useful because the comparisons can't
be done by the optab itself.

As such vec_cbranch_any would be called with vexit_reduc_34 and { 0, 0, 0, 0 }
however since this expects to perform the comparison itself we end up with

        ldp     q30, q31, [x0], 32
        cmeq    v30.4s, v30.4s, v27.4s
        cmeq    v31.4s, v31.4s, v27.4s
        addhn   v31.4h, v31.4s, v30.4s
        cmtst   v31.4h, v31.4h, v31.4h
        fmov    x3, d31
        cbz     x3, .L2

instead of

        ldp     q30, q31, [x0], 32
        cmeq    v30.4s, v30.4s, v27.4s
        cmeq    v31.4s, v31.4s, v27.4s
        addhn   v31.4h, v31.4s, v30.4s
        fmov    x3, d31
        cbz     x3, .L2

because we don't know that the value is already a boolean -1/0 value.  Without
this we can't safely not perform the compare.

The conversion is needed because e.g. it's not valid to drop the compare with
zero when the vector just contains data:

v30.8h = [ 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008 ]
cmeq   v31.8h, v30.8h, #0        // -> v31.8h = [0,0,0,0,0,0,0,0]
umaxp  v31.4s, v31.4s, v31.4s    // pairwise-OR over 0/FFFF masks -> still [0,0,0,0]
fmov   x7, d31                   // x7 = 0
cbnz   x7, .L6                   // NOT taken (correct: there were no zeros)

vs

umaxp v31.4s, v31.4s, v31.4s     // pairwise unsigned max:
                                 //   [ max(0x00020001,0x00040003)=0x00040003,
                                 //     max(0x00060005,0x00080007)=0x00080007, ... ]
fmov  x7, d31                    // x7 = 0x0008000700040003  (non-zero)
cbnz  x7, .L66                   // TAKEN

As such, to avoid the extra compare on boolean vectors, we still need the
cbranch_optab or the new vec_cbranch_* optabs need an extre operand to indicate
what kind of data they hold.  Note that this isn't an issue for SVE because
SVE has BImode for booleans.

With these two optabs it's trivial to implement all the optimizations I
described above.

I.e. with them we can now generate

.L2:
        ldr     q31, [x1, x2]
        add     v29.4s, v29.4s, v25.4s
        add     v28.4s, v28.4s, v26.4s
        add     v31.4s, v31.4s, v30.4s
        str     q31, [x1, x2]
        add     x1, x1, 16
        cmp     x1, 2560
        beq     .L1
.L6:
        ldr     q30, [x3, x1]
        cmpeq   p15.s, p7/z, z30.s, z27.s
        b.none  .L2

and easily prove it correct.

gcc/ChangeLog:

PR target/118974
* optabs.def (vec_cbranch_any_optab, vec_cbranch_all_optab,
cond_vec_cbranch_any_optab, cond_vec_cbranch_all_optab,
cond_len_vec_cbranch_any_optab, cond_len_vec_cbranch_all_optab): New.
* doc/md.texi: Document them.
* optabs.cc (prepare_cmp_insn): Refactor to take optab to check for
instead of hardcoded cbranch and support mask and len.
(emit_cmp_and_jump_insn_1, emit_cmp_and_jump_insns): Implement them.
(emit_conditional_move, emit_conditional_add, gen_cond_trap): Update
after changing function signatures to support new optabs.

13 days agoc++/modules: Walk indirectly exposed namespaces [PR122699]
Nathaniel Shead [Sat, 22 Nov 2025 11:30:32 +0000 (22:30 +1100)] 
c++/modules: Walk indirectly exposed namespaces [PR122699]

In some situations, such as friend injection, we may add an entity to a
namespace without ever explicitly opening that namespace in this TU.

We currently have an additional loop to make sure the namespace is
considered purview, but this isn't sufficient to make
walk_module_binding find it, since the namspace itself is not in the
current TU's symbol table.  This patch ensures we still process the
(hidden) binding for the injected friend in this TU.

PR c++/122699

gcc/cp/ChangeLog:

* name-lookup.h (expose_existing_namespace): Declare.
* name-lookup.cc (expose_existing_namespace): New function.
(push_namespace): Call it.
* pt.cc (tsubst_friend_function): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/tpl-friend-21_a.C: New test.
* g++.dg/modules/tpl-friend-21_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
13 days agoarm: add extra sizes to Wstrinop-overflow-47.c warning tests
Andre Vieira [Tue, 25 Nov 2025 11:39:35 +0000 (11:39 +0000)] 
arm: add extra sizes to Wstrinop-overflow-47.c warning tests

A thumb2 target without a FPU like -mcpu=cortex-m3 will generate
'vector(4) char' stores which lead to warnings with sizes that weren't being
allowed before by the test.  This patch adds these sizes.

gcc/testsuite/ChangeLog:

* gcc.dg/Wstringop-overflow-47.c: Adjust warnings to allow for 32-bit
stores.

13 days agoc++/modules: Stream all REQUIRES_EXPR_PARMS [PR122789]
Nathaniel Shead [Sun, 23 Nov 2025 12:24:39 +0000 (23:24 +1100)] 
c++/modules: Stream all REQUIRES_EXPR_PARMS [PR122789]

We don't generally stream the TREE_CHAIN of a DECL, as this would cause
us to unnecessarily walk into the next member in its scope chain any
time it was referenced by an expression.

Unfortunately, REQUIRES_EXPR_PARMS is a tree chain of PARM_DECLs, so we
were only ever streaming the first parameter.  This meant that when a
parameter's type could not be tsubst'd we would ICE instead of returning
false.

This patch special-cases REQUIRES_EXPR to always stream the chain of
decls in its first operand.  As a drive-by improvement we also remove a
fixme about checking uncontexted PARM_DECLs.

PR c++/122789

gcc/cp/ChangeLog:

* module.cc (trees_out::core_vals): Treat REQUIRES_EXPR
specially and stream the chained decls of its first operand.
(trees_in::core_vals): Likewise.
(trees_out::tree_node): Check the PARM_DECLs we see are what we
expect.

gcc/testsuite/ChangeLog:

* g++.dg/modules/concept-12_a.C: New test.
* g++.dg/modules/concept-12_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
13 days agodriver/c++: add --compile-std-module
Jason Merrill [Tue, 11 Nov 2025 10:28:01 +0000 (15:58 +0530)] 
driver/c++: add --compile-std-module

For simple testcases that want to use the std module, it would be useful to
have a reasonably short way to request building the binary module form
before the testcase.  So with this patch users can write

  g++ -std=c++20 -fmodules --compile-std-module mytest.C

I expect this to be particularly useful on godbolt.org, where currently
building a modules testcase requires messing with cmake.  One complication
there is that just adding std.cc to the command line arguments hits the
"cannot specify -o with -S with multiple files" error, so I avoid counting
these added inputs as "multiple files"; in that situation each compile will
output to the same target file, with the user-specified input last so it's
the one that actually ends up in the target after the command completes.

gcc/c-family/ChangeLog:

* c.opt: Add --compile-std-module.

gcc/cp/ChangeLog:

* lang-specs.h: Add @c++-system-module.
* g++spec.cc (lang_specific_driver): Handle --compile-std-module.

gcc/ChangeLog:

* doc/invoke.texi: Document --compile-std-module.
* gcc.cc (struct infile): Add artificial field.
(add_infile): Set it.
(driver::prepare_infiles): Check it.

gcc/testsuite/ChangeLog:

* g++.dg/modules/compile-std1.C: New test.
* g++.dg/modules/modules.exp: Only run it once.

13 days agoc++: modules documentation tweak
Jason Merrill [Tue, 18 Nov 2025 17:00:06 +0000 (22:30 +0530)] 
c++: modules documentation tweak

The comment about P1815 not being implemented is obsolete since
Nathaniel's work starting with r15-6378.

gcc/ChangeLog:

* doc/invoke.texi (C++ Modules): Remove TU-local caveat.

13 days agogimplify, ubsan: Fix -fopenmp -fsanitize=bounds ICE [PR120052]
Jakub Jelinek [Tue, 25 Nov 2025 10:19:12 +0000 (11:19 +0100)] 
gimplify, ubsan: Fix -fopenmp -fsanitize=bounds ICE [PR120052]

The following testcase ICEs, because
1) -fsanitize=bounds uses TYPE_MAX_VALUE (TYPE_DOMAIN (type)) with
   1 or 2 added as last argument of .UBSAN_BOUNDS call and that
   expression at that point is some NOP_EXPR around SAVE_EXPR with
   testing for negative sizes
2) during gimplification, gimplify_type_sizes is invoked on the DECL_EXPR
   outside of an OpenMP region, and forces TYPE_MAX_VALUE into
   a pseudo instead, with the SAVE_EXPR obviously being evaluated
   before that
3) the OpenMP gimplification sees an implicit or explicit data sharing
   of a VLA and among other things arranges to firstprivatize TYPE_MAX_VALUE
4) when gimplifying the .UBSAN_BOUNDS call inside of the OpenMP region,
   it sees a SAVE_EXPR and just gimplifies it to the already initialized
   s.1 temporary; but nothing marks s.1 for firstprivatization on the
   containing construct(s).  The problem is that with SAVE_EXPR we never
   know if the first use is within the same statement (typical use) or
   somewhere earlier in the same OpenMP construct or in an outer OpenMP
   construct or its parent etc., the SAVE_EXPR temporary is a function
   local var, not something that is added to the innermost scope where
   it is used (and it can't because it perhaps could be used outside of
   it); so for OpenMP purposes, SAVE_EXPRs better should be used only
   within the same OpenMP region and not across the whole function

The following patch fixes it by deferring the addition of
TYPE_MAX_VALUE in the last argument of .UBSAN_BOUNDS until gimplification
for VLAs, if it sees a VLA, instead of making the first argument
0 with pointer to the corresponding array type, it sets the first
argument to 1 with the same type and only sets the last argument to the
addend (1 or 2).  And then gimplification can detect this case and
add the TYPE_MAX_VALUE (which in the meantime should have gone through
gimplify_type_sizes).

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

PR middle-end/120052
gcc/
* gimplify.cc (gimplify_call_expr): For IFN_UBSAN_BOUNDS
call with integer_onep first argument, change that argument
to 0 and add TYPE_MAX_VALUE (TYPE_DOMAIN (arr_type)) to
3rd argument before gimplification.
gcc/c-family/
* c-ubsan.cc (ubsan_instrument_bounds): For VLAs use
1 instead of 0 as first IFN_UBSAN_BOUNDS argument and only
use the addend without TYPE_MAX_VALUE (TYPE_DOMAIN (type))
in the 3rd argument.
gcc/testsuite/
* c-c++-common/gomp/pr120052.c: New test.

13 days agotestsuite: Fix up vla-1.c test [PR119931]
Jakub Jelinek [Tue, 25 Nov 2025 10:18:07 +0000 (11:18 +0100)] 
testsuite: Fix up vla-1.c test [PR119931]

From what I can see, the vla-1.c test has been added to test the handling
of debug info for optimized out parameters.  But recent changes don't make
the argument optimized away, but optimized away and replaced by constant 5
(even without IPA-VRP).  The function is noinline, but can't be noclone
nor noipa exactly because we want to test how it behaves when it is cloned
and the unused argument is dropped.

So, the following patch arranges to hide from the IPA optimizations the
value of x in the caller (and even make sure it is preserved in a register
or stack slot in the caller across the call).

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

PR testsuite/119931
* gcc.dg/vla-1.c (main): Hide x value from optimizers and use it after
the call as well.

13 days agotestsuite: Fix g++.dg/DRs/dr2581-1.C etc. on non-Linux
Rainer Orth [Tue, 25 Nov 2025 09:51:38 +0000 (10:51 +0100)] 
testsuite: Fix g++.dg/DRs/dr2581-1.C etc. on non-Linux

The g++.dg/DRs/dr2581-?.C tests FAIL on several targets in two ways:

* Both tests FAIL on a couple of targets in the same way:

FAIL: g++.dg/DRs/dr2581-1.C  -std=c++11  (test for warnings, line 25)
FAIL: g++.dg/DRs/dr2581-1.C  -std=c++17  (test for warnings, line 25)
FAIL: g++.dg/DRs/dr2581-1.C  -std=c++20  (test for warnings, line 25)
FAIL: g++.dg/DRs/dr2581-1.C  -std=c++23  (test for warnings, line 25)
FAIL: g++.dg/DRs/dr2581-1.C  -std=c++26  (test for warnings, line 25)
FAIL: g++.dg/DRs/dr2581-2.C  -std=c++11  (test for errors, line 25)
FAIL: g++.dg/DRs/dr2581-2.C  -std=c++14  (test for errors, line 25)
FAIL: g++.dg/DRs/dr2581-2.C  -std=c++17  (test for errors, line 25)
FAIL: g++.dg/DRs/dr2581-2.C  -std=c++20  (test for errors, line 25)
FAIL: g++.dg/DRs/dr2581-2.C  -std=c++23  (test for errors, line 25)
FAIL: g++.dg/DRs/dr2581-2.C  -std=c++26  (test for errors, line 25)

  i.e. the __STDC_ISO_10646__ warning is missing.  This happens on
  Solaris, FreeBSD, Darwin, and several embedded targets.  While
  __STDC_ISO_10646__ already exists in C99, it's optional there and
  seems to be only defined on Linux/glibc.  Thus this patch xfail's this
  check on non-Linux.

* Besides, on Solaris only there are more failures for -std=c++11 to
  c++26, like

FAIL: g++.dg/DRs/dr2581-2.C  -std=c++11  (test for warnings, line 24)
FAIL: g++.dg/DRs/dr2581-2.C  -std=c++11 (test for excess errors)

Excess errors:
g++.dg/DRs/dr2581-2.C:24:9: error: '__STDC_VERSION__' redefined

  This happens because g++ always predefines __STDC_VERSION__ on
  Solaris, so this patch expects an error instead of a warning here.

Tested on i386-pc-solaris2.11, sparc-sun-solaris2.11,
x86_64-apple-darwin25.1.0, and x86_64-pc-linux-gnu.

2025-11-20  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
* g++.dg/DRs/dr2581-1.C (__STDC_ISO_10646__): xfail on non-Linux.
* g++.dg/DRs/dr2581-2.C: Likewise.
(__STDC_VERSION__): Expect error instead of warning on Solaris.

13 days agoopenmp: Fix up OpenMP expansion of collapsed loops [PR120564]
Jakub Jelinek [Tue, 25 Nov 2025 09:30:51 +0000 (10:30 +0100)] 
openmp: Fix up OpenMP expansion of collapsed loops [PR120564]

Most of gimple_build_cond_empty callers call just build2 to prepare
condition which is put into GIMPLE_COND, but this one spot has been
using incorrectly fold_build2.  Now the arguments of the *build2 were
already gimplified, but the folding of some conditions can turn say
unsigned_var > INT_MAX into (int) unsigned_var < 0 etc. and thus
turn the condition into something invalid in gimple, because we only
try to regimplify the operands if they refer to some decl which needs
to be regimplified (has DECL_VALUE_EXPR on it).

Fixed by also using build2 instead of fold_build2.

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

PR middle-end/120564
* omp-expand.cc (extract_omp_for_update_vars): Use build2 instead of
fold_build2 to build argument for gimple_build_cond_empty.

* c-c++-common/gomp/pr120564.c: New test.

13 days agoalias: Fix comment typo
Jakub Jelinek [Tue, 25 Nov 2025 09:09:51 +0000 (10:09 +0100)] 
alias: Fix comment typo

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

* alias.cc (get_alias_set): Fix comment typo, TYPE_CANOINCAL
-> TYPE_CANONICAL.

13 days agoalias: Fix up BITINT_TYPE and non-standard INTEGER_TYPE alias handling [PR122624]
Jakub Jelinek [Tue, 25 Nov 2025 09:06:46 +0000 (10:06 +0100)] 
alias: Fix up BITINT_TYPE and non-standard INTEGER_TYPE alias handling [PR122624]

The testcase in the PR is miscompiled on aarch64 with
--param=ggc-min-expand=0 --param=ggc-min-heapsize=0 -O2
(not including it in the testsuite because it is too much of
a lottery).

Anyway, the problem is that the testcase only uses unsigned _BitInt(66)
and never uses _BitInt(66), get_alias_set remembers alias set for
ARRAY_TYPE (of its element type in ARRAY_TYPE's TYPE_ALIAS_SET),
c_common_get_alias_set does not remember in TYPE_ALIAS_SET alias of
unsigned types and instead asks for get_alias_set of corresponding
signed type and that creates a new alias set for each new canonical
type.
So, in this case, when being asked about get_alias_set on ARRAY_TYPE
unsigned _BitInt(66) [N], it recurses down to c_common_get_alias_set
which asks for alias set of at that point newly created signed type
_BitInt(66), new alias set is created for it, remembered in that
signed _BitInt(66) TYPE_ALIAS_SET, not remembered in unsigned _BitInt(66)
and remembered in ARRAY_TYPE's TYPE_ALIAS_SET.
Next a GC collection comes, signed _BitInt(66) is not used anywhere in
any reachable from GC roots, so it is removed.
Later on we ask alias oracle whether the above mentioned ARRAY_TYPE
can for TBAA alias pointer dereference with the same unsigned _BitInt(66)
type.  For the ARRAY_TYPE, we have the above created alias set remembered
in TYPE_ALIAS_SET, so that is what we use, but for the unsigned _BitInt(66)
we don't, so create a new signed _BitInt(66), create a new alias set for it
and that is what is returned, so we have to distinct alias sets and return
that they can't alias.
Now, for standard INTEGER_TYPEs this isn't a problem, because both the
signed and unsigned variants of those types are always reachable from GTY
roots.  For BITINT_TYPE (or build_nonstandard_integer_type built types)
that isn't the case.  I'm not convinced we need to fix it for
build_nonstandard_integer_type built INTEGER_TYPEs though, for bit-fields
their address can't be taken in C/C++, but for BITINT_TYPE this clearly
is a problem.

So, the following patch solves it by
1) remembering the alias set we got from get_alias_set on the signed
   _BitInt(N) type in the unsigned _BitInt(N) type
2) returning -1 for unsigned _BitInt(1), because there is no corresponding
   signed _BitInt type and so we can handle it normally
3) so that the signed _BitInt(N) type isn't later GC collected and later
   readded with a new alias set incompatible with the still reachable
   unsigned _BitInt(N) type, the patch for signed _BitInt(N) types checks
   if corresponding unsigned _BitInt(N) type doesn't already have
   TYPE_ALIAS_SET_KNOWN_P, in that case it remembers and returns that;
   in order to avoid infinite recursion, it doesn't call get_alias_set
   on the unsigned _BitInt(N) type though
4) while type_hash_canon remembers in the type_hash_table both the hash
   and the type, so what exactly we use as the hash isn't that important,
   I think using type_hash_canon_hash for BITINT_TYPEs is actually better over
   hasing TYPE_MAX_VALUE, because especially for larger BITINT_TYPEs
   TYPE_MAX_VALUE can have lots of HWIs in the number, for
   type_hash_canon_hash hashes for BITINT_TYPEs only
   i) TREE_CODE (i.e. BITINT_TYPE)
   ii) TYPE_STRUCTURAL_EQUALITY_P flag (likely false)
   iii) TYPE_PRECISION
   iv) TYPE_UNSIGNED
   so 3 ints and one flag, while the old way can hash one HWI up to
   1024 HWIs; note it is also more consistent with most other
   type_hash_canon calls, except for build_nonstandard_integer_type; for
   some reason changing that one to use also type_hash_canon_hash doesn't
   work, causes tons of ICEs

This version of the patch handles INTEGER_TYPEs the same as BITINT_TYPE.

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

PR middle-end/122624
* tree.cc (build_bitint_type): Use type_hash_canon_hash.

* c-common.cc (c_common_get_alias_set): Fix up handling of BITINT_TYPE
and non-standard INTEGER_TYPEs.  For unsigned _BitInt(1) always return
-1.  For other unsigned types set TYPE_ALIAS_SET to get_alias_set of
corresponding signed type and return that.  For signed types check if
corresponding unsigned type has TYPE_ALIAS_SET_KNOWN_P and if so copy
its TYPE_ALIAS_SET and return that.

13 days agolibgomp/oacc: fix atomic_capture-3 iteration ordering issues
Arsen Arsenović [Mon, 24 Nov 2025 12:35:18 +0000 (13:35 +0100)] 
libgomp/oacc: fix atomic_capture-3 iteration ordering issues

In r11-3059-g8183ebcdc1c843, Julian fixed a few issues with
atomic_capture-2.c relying on iteration order guarantees that do not
exist under OpenACC parallelized loops and, notably, do not happen even
by accident on AMDGCN.

The atomic_capture-3.c testcase was made by copying it from
atomic_capture-2.c and adding additional options in commit
r12-310-g4cf3b10f27b199, but from an older version of
atomic_capture-2.c, which lacked these ordering fixes fixes, so they
resurfaced in this test.

This patch ports those fixes from atomic_capture-2.c into
atomic_capture-3.c.

libgomp/ChangeLog:

* testsuite/libgomp.oacc-c-c++-common/atomic_capture-3.c: Copy
changes in r11-3059-g8183ebcdc1c843 from atomic_capture-2.c.

13 days agotestsuite: i386: Restrict pr120936-1.c etc. to Linux
Rainer Orth [Tue, 25 Nov 2025 08:23:08 +0000 (09:23 +0100)] 
testsuite: i386: Restrict pr120936-1.c etc. to Linux

After switching the i386 check-function-bodies tests to use the new
dg-add-options check_function_bodies feature, several tests still FAIL
in the same way on Solaris/x86.  E.g.

FAIL: gcc.target/i386/pr120936-1.c check-function-bodies foo

The code differs between i686-pc-linux-gnu and i386-pc-solaris2.11 like
this:

- .cfi_def_cfa_register 5
- call mcount
+ .data
+ .align 4
+.LP0:
+ .long 0
+ .text
+ movl $.LP0, %edx
+ call _mcount

i.e. the test expects a call to mcount, while on Solaris _mcount is
called instead.  MCOUNT_NAME is only defined as mcount in gnu-user.h and
x86-64.h, so the patch restricts the tests to Linux.

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

2025-11-23  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
* gcc.target/i386/pr120936-1.c: Restrict to *-*-linux*.
* gcc.target/i386/pr120936-2.c: Likewise.
* gcc.target/i386/pr120936-4.c: Likewise.
* gcc.target/i386/pr120936-5.c: Likewise.
* gcc.target/i386/pr120936-9.c: Likewise.
* gcc.target/i386/pr120936-11.c: Likewise.

13 days agotestsuite: i386: Guard NO_PROFILE_COUNTERS tests
Rainer Orth [Tue, 25 Nov 2025 08:20:54 +0000 (09:20 +0100)] 
testsuite: i386: Guard NO_PROFILE_COUNTERS tests

After switching the i386 check-function-bodies tests to use the new
dg-add-options check_function_bodies feature, several tests still FAIL
in similar ways on Solaris/x86:

* Some FAIL like this:

FAIL: gcc.target/i386/pr120936-6.c (test for excess errors)
Excess errors:
cc1: error: '-mnop-mcount' is not compatible with this target

  This happens because -mnop-mcount is only supported in
  i386/i386-options.cc (ix86_option_override_internal) if
  NO_PROFILE_COUNTERS.

* Others FAIL like

FAIL: gcc.target/i386/pr120936-10.c (test for excess errors)
Excess errors:
gcc/testsuite/gcc.target/i386/pr120936-10.c:23:1: sorry, unimplemented: profiling '-mcmodel=large' with PIC is not supported

  This error is generated in i386/i386.cc (x86_function_profiler) if
  !NO_PROFILE_COUNTERS.

NO_PROFILE_COUNTERS is only defined in dragonfly.h, x86_64.sh,
gnu-user.h, freebsd.h, cygming.h, and, netbsd-elf.h.  However, a couple
of similar tests are restricted to Linux only, so this patch follows
suit.  One could introduce a new effective-target keyword to fully
handle this, though.

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

2025-11-23  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
* gcc.target/i386/pr120936-3.c: Restrict to *-*-linux*.
* gcc.target/i386/pr120936-6.c: Likewise.
* gcc.target/i386/pr120936-10.c: Likewise.
* gcc.target/i386/pr120936-12.c: Likewise.

13 days agotestsuite: i386: Handle check-function-bodies options using dg-add-options
Rainer Orth [Tue, 25 Nov 2025 08:18:13 +0000 (09:18 +0100)] 
testsuite: i386: Handle check-function-bodies options using dg-add-options

The {gcc,g++}.target/i386 tests that use dg-final { check-function-bodies }
need addititional options on Solaris/x86.  So far, those tests have been
updated manually to add the required -fdwarf2-cfi-asm
-fasynchronous-unwind-tables.  However, this has two issues:

* Those Solaris-only options make dg-options harder to read, although
  they do no harm on other targets.

* Besides, the need for those options repeated got forgotten for each
  new bunch of such tests.

To avoid that problem in the future, this patch introduces a new
dg-add-options feature, check_function_bodies, that adds those options
exactly on the targets that need it.  It both improves readability and
will hopefully not be forgotten again for future tests.

Tested on i386-pc-solaris2.11 with as/ld and gas/ld, and
x86_64-pc-linux-gnu.

2025-11-21  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc:
* doc/sourcebuild.texi (Add Options): Document
check_function_bodies.

gcc/testsuite:
* lib/target-supports.exp (add_options_for_check_function_bodies):
New proc.

* g++.target/i386/cf_check-3.C: Add dg-add-options
check_function_bodies.
* g++.target/i386/cf_check-4.C: Likewise.
* gcc.target/i386/builtin-copysign-2.c: Likewise.
* gcc.target/i386/builtin-copysign-3.c: Likewise.
* gcc.target/i386/builtin-copysign-4.c: Likewise.
* gcc.target/i386/builtin-copysign-5.c: Likewise.
* gcc.target/i386/builtin-copysign-6.c: Likewise.
* gcc.target/i386/builtin-copysign-7.c: Likewise.
* gcc.target/i386/builtin-copysign-8a.c: Likewise.
* gcc.target/i386/builtin-copysign-8b.c: Likewise.
* gcc.target/i386/builtin-fabs-1.c: Likewise.
* gcc.target/i386/builtin-memmove-10.c: Likewise.
* gcc.target/i386/builtin-memmove-11a.c: Likewise.
* gcc.target/i386/builtin-memmove-11b.c: Likewise.
* gcc.target/i386/builtin-memmove-11c.c: Likewise.
* gcc.target/i386/builtin-memmove-12.c: Likewise.
* gcc.target/i386/builtin-memmove-13.c: Likewise.
* gcc.target/i386/builtin-memmove-14.c: Likewise.
* gcc.target/i386/builtin-memmove-15.c: Likewise.
* gcc.target/i386/builtin-memmove-1a.c: Likewise.
* gcc.target/i386/builtin-memmove-1b.c: Likewise.
* gcc.target/i386/builtin-memmove-1c.c: Likewise.
* gcc.target/i386/builtin-memmove-1d.c: Likewise.
* gcc.target/i386/builtin-memmove-2a.c: Likewise.
* gcc.target/i386/builtin-memmove-2b.c: Likewise.
* gcc.target/i386/builtin-memmove-2c.c: Likewise.
* gcc.target/i386/builtin-memmove-2d.c: Likewise.
* gcc.target/i386/builtin-memmove-3a.c: Likewise.
* gcc.target/i386/builtin-memmove-3b.c: Likewise.
* gcc.target/i386/builtin-memmove-3c.c: Likewise.
* gcc.target/i386/builtin-memmove-4a.c: Likewise.
* gcc.target/i386/builtin-memmove-4b.c: Likewise.
* gcc.target/i386/builtin-memmove-4c.c: Likewise.
* gcc.target/i386/builtin-memmove-5a.c: Likewise.
* gcc.target/i386/builtin-memmove-5b.c: Likewise.
* gcc.target/i386/builtin-memmove-5c.c: Likewise.
* gcc.target/i386/builtin-memmove-6.c: Likewise.
* gcc.target/i386/builtin-memmove-7.c: Likewise.
* gcc.target/i386/builtin-memmove-8.c: Likewise.
* gcc.target/i386/builtin-memmove-9.c: Likewise.
* gcc.target/i386/cf_check-11.c: Likewise.
* gcc.target/i386/cf_check-7.c: Likewise.
* gcc.target/i386/pr120936-1.c: Likewise.
* gcc.target/i386/pr120936-11.c: Likewise.
* gcc.target/i386/pr120936-2.c: Likewise.
* gcc.target/i386/pr120936-4.c: Likewise.
* gcc.target/i386/pr120936-5.c: Likewise.
* gcc.target/i386/pr120936-9.c: Likewise.

* g++.target/i386/memset-pr101366-1.C: Switch to dg-add-options
check_function_bodies.
* g++.target/i386/memset-pr101366-2.C: Likewise.
* g++.target/i386/memset-pr108585-1a.C: Likewise.
* g++.target/i386/memset-pr108585-1b.C: Likewise.
* g++.target/i386/memset-pr118276-1a.C: Likewise.
* g++.target/i386/memset-pr118276-1b.C: Likewise.
* g++.target/i386/memset-pr118276-1c.C: Likewise.
* gcc.target/i386/memcpy-pr120683-1.c: Likewise.
* gcc.target/i386/memcpy-pr120683-2.c: Likewise.
* gcc.target/i386/memcpy-pr120683-3.c: Likewise.
* gcc.target/i386/memcpy-pr120683-4.c: Likewise.
* gcc.target/i386/memcpy-pr120683-5.c: Likewise.
* gcc.target/i386/memcpy-pr120683-6.c: Likewise.
* gcc.target/i386/memcpy-pr120683-7.c: Likewise.
* gcc.target/i386/memcpy-strategy-12.c: Likewise.
* gcc.target/i386/memset-pr120683-1.c: Likewise.
* gcc.target/i386/memset-pr120683-10.c: Likewise.
* gcc.target/i386/memset-pr120683-11.c: Likewise.
* gcc.target/i386/memset-pr120683-12.c: Likewise.
* gcc.target/i386/memset-pr120683-13.c: Likewise.
* gcc.target/i386/memset-pr120683-14.c: Likewise.
* gcc.target/i386/memset-pr120683-15.c: Likewise.
* gcc.target/i386/memset-pr120683-16.c: Likewise.
* gcc.target/i386/memset-pr120683-17.c: Likewise.
* gcc.target/i386/memset-pr120683-18.c: Likewise.
* gcc.target/i386/memset-pr120683-19.c: Likewise.
* gcc.target/i386/memset-pr120683-2.c: Likewise.
* gcc.target/i386/memset-pr120683-20.c: Likewise.
* gcc.target/i386/memset-pr120683-21.c: Likewise.
* gcc.target/i386/memset-pr120683-22.c: Likewise.
* gcc.target/i386/memset-pr120683-23.c: Likewise.
* gcc.target/i386/memset-pr120683-3.c: Likewise.
* gcc.target/i386/memset-pr120683-4.c: Likewise.
* gcc.target/i386/memset-pr120683-5.c: Likewise.
* gcc.target/i386/memset-pr120683-6.c: Likewise.
* gcc.target/i386/memset-pr120683-7.c: Likewise.
* gcc.target/i386/memset-pr120683-8.c: Likewise.
* gcc.target/i386/memset-pr120683-9.c: Likewise.
* gcc.target/i386/memset-pr70308-1a.c: Likewise.
* gcc.target/i386/memset-pr70308-1b.c: Likewise.
* gcc.target/i386/memset-strategy-10.c: Likewise.
* gcc.target/i386/memset-strategy-13.c: Likewise.
* gcc.target/i386/memset-strategy-25.c: Likewise.
* gcc.target/i386/memset-strategy-28.c: Likewise.
* gcc.target/i386/memset-strategy-29.c: Likewise.
* gcc.target/i386/memset-strategy-30.c: Likewise.
* gcc.target/i386/pr111673.c: Likewise.
* gcc.target/i386/pr82142a.c: Likewise.
* gcc.target/i386/pr82142b.c: Likewise.
* gcc.target/i386/pr92080-17.c: Likewise.

13 days agotestsuite: Fix gcc.dg/debug/dwarf2/dwarf-btf-*-tag-*.c with Solaris/SPARC as
Rainer Orth [Tue, 25 Nov 2025 08:15:17 +0000 (09:15 +0100)] 
testsuite: Fix gcc.dg/debug/dwarf2/dwarf-btf-*-tag-*.c with Solaris/SPARC as

A couple of gcc.dg/debug/dwarf2/dwarf-btf-*-tag-*.c tests FAIL on
Solaris/SPARC when the native assembler is used:

FAIL: gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-1.c scan-assembler-times  DW_AT_const_value: "my_foo" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-1.c scan-assembler-times  DW_AT_name: "btf_decl_tag" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-type-tag-1.c scan-assembler-times  DW_AT_const_value: "__user" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-type-tag-1.c scan-assembler-times  DW_AT_name: "btf_type_tag" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-type-tag-10.c scan-assembler-times  DW_AT_name: "btf_decl_tag" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-type-tag-10.c scan-assembler-times  DW_AT_name: "btf_type_tag" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-type-tag-2.c scan-assembler-times  DW_AT_const_value: "tag1" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-type-tag-2.c scan-assembler-times  DW_AT_const_value: "tag2" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-type-tag-4.c scan-assembler-times  DW_AT_name: "btf_type_tag" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-type-tag-5.c scan-assembler-times  DW_AT_const_value: "tagged_arr" 1
FAIL: gcc.dg/debug/dwarf2/dwarf-btf-type-tag-5.c scan-assembler-times  DW_AT_name: "btf_type_tag" 1

All of them FAIL in the same way: when gas is used, the tests contain
something like

.uaword .LLASF4 ! DW_AT_const_value: "my_foo"

while for /bin/as

.ascii "my_foo\0" ! DW_AT_const_value

is emitted.  While other dwarf2 tests support both forms, the tests
above don't.  This patch fixes this. To make the regex more readable,
they are switched to using braces instead of double quotes, thus
avoiding excessive escaping.  At the same time, they now use
newline-sensitive matching to avoid .* matching across lines.

Tested on sparc-sun-solaris2.11 with as and gas, and
x86_64-pc-linux-gnu.

2025-11-22  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

* gcc.dg/debug/dwarf2/dwarf-btf-decl-tag-1.c
(scan-assembler-times): Switch to brace quotes.
Allow for alternative assembler syntax.
* gcc.dg/debug/dwarf2/dwarf-btf-type-tag-1.c: Likewise.
* gcc.dg/debug/dwarf2/dwarf-btf-type-tag-10.c: Likewise.
* gcc.dg/debug/dwarf2/dwarf-btf-type-tag-2.c: Likewise.
* gcc.dg/debug/dwarf2/dwarf-btf-type-tag-4.c: Likewise.
* gcc.dg/debug/dwarf2/dwarf-btf-type-tag-5.c: Likewise.

2 weeks agoc-family: Don't register include paths with -fpreprocessed
Kito Cheng [Mon, 24 Nov 2025 07:00:07 +0000 (15:00 +0800)] 
c-family: Don't register include paths with -fpreprocessed

This fixes a permission error that occurs when cross-compiling with
-save-temps and a relocated toolchain, where the original build path
exists but is inaccessible.

The issue occurs when:
- Building the toolchain at /home/scratch/build/
- Installing it to another location like /home/user/rv64-toolchain/
- The /home/scratch directory exists but has insufficient permissions
  (e.g. drwx------ for /home/scratch/)

Without this fix, cc1 would report errors like:
cc1: error: /home/scratch/build/install/riscv64-unknown-elf/usr/local/include: Permission denied

This occurred because the GCC driver did not pass GCC_EXEC_PREFIX and
isysroot to cc1/cc1plus in the compile stage when using -save-temps.
This caused cc1/cc1plus to search for headers from the wrong (original
build) path instead of the relocated installation path.

The fix ensures cc1/cc1plus won't try to collect include paths when
-fpreprocessed is specified.  This prevents the permission error during
cross-compilation with -save-temps, as the preprocessed file already
contains all necessary headers.

gcc/c-family/ChangeLog:

* c-opts.cc (c_common_post_options): Skip register_include_chains
when cpp_opts->preprocessed is set.

2 weeks agoDaily bump.
GCC Administrator [Tue, 25 Nov 2025 00:20:20 +0000 (00:20 +0000)] 
Daily bump.

2 weeks agoira: sort allocno_hard_regs by regset
Alexandre Oliva [Mon, 24 Nov 2025 23:07:20 +0000 (20:07 -0300)] 
ira: sort allocno_hard_regs by regset

Using hashes of data structures for tie breaking makes sorting
dependent on type sizes, padding, and endianness, i.e., unstable
across different hosts.

ira-color.cc's allocno_hard_regs_compare does that, and it causes
different register allocations to be chosen for the same target
depending on the host.  That's undesirable.

Compare the HARD_REG_SETs directly instead, looking for the
lowest-numbered difference register to use as the tie breaker for the
cost compare.

With a hardware implementation of ctz, this is likely faster than the
hash used to break ties before.

for  gcc/ChangeLog

PR rtl-optimization/122767
* ira-color.cc (allocno_hard_regs_compare): Break ties
using...
* hard-reg-set.h (hard_reg_set_first_diff): ... this.  New
HARD_REG_SET API entry point.

2 weeks agovect: Add vect-scalar-cost-multiplier for SLP.
Robin Dapp [Sun, 16 Nov 2025 17:43:15 +0000 (18:43 +0100)] 
vect: Add vect-scalar-cost-multiplier for SLP.

This adds the same vect-scalar-cost-multiplier to SLP costing that loop
costing already has.

gcc/ChangeLog:

* tree-vect-slp.cc (vect_bb_vectorization_profitable_p):
Multiply scalar cost by vect-scalar-cost-multiplier.

2 weeks agovect: Make SELECT_VL a convert optab.
Robin Dapp [Fri, 14 Nov 2025 14:01:29 +0000 (15:01 +0100)] 
vect: Make SELECT_VL a convert optab.

Currently select_vl is a direct optab with its mode always Xmode/Pmode.
This does not give us sufficient freedom to enable/disable vsetvl
(=SELECT_VL) depending on the vector mode.

This patch makes select_vl a convert optab and adjusts the associated IFN
functions as well as the query/emit code in the vectorizer.

With this patch nothing new is actually exercised yet.  This is going to
happen in a separate riscv patch that enables "VLS" select_vl.

gcc/ChangeLog:

* config/riscv/autovec.md (select_vl<mode>): Rename to...
(select_vl<V:mode><P:mode>): ...this.
* doc/md.texi: Document new behavior.
* internal-fn.cc (select_vl_direct): Make
(expand_select_vl_optab_fn): Adjust for convert optab.
(direct_select_vl_optab_supported_p): Ditto.
* internal-fn.def (SELECT_VL): Ditto.
* optabs.def (OPTAB_CD): Add select_vl.
(OPTAB_D): Remove select_vl.
* tree-vect-loop-manip.cc (vect_set_loop_controls_directly):
Adjust for convert select_vl optab.
* tree-vect-loop.cc: Ditto.

2 weeks agoRISC-V: Add BF VLS modes and document iterators.
Robin Dapp [Wed, 22 Oct 2025 19:14:36 +0000 (21:14 +0200)] 
RISC-V: Add BF VLS modes and document iterators.

We're missing some VLS BF modes, e.g. for gathers.  This patch adds them.
While at it, it adds some documentation to the iterators and corrects
the vec_set iterator (for the time being).

Regtested on rv64gcv_zvl512b but curious what the CI says.

PR/target 121582

gcc/ChangeLog:

* config/riscv/autovec.md: Use V_VLS_ZVFH for vec_set.
* config/riscv/riscv-modes.def (RVV_NF4_MODES): Add BF mdoes.
(ADJUST_PRECISION): Ditto.
(VECTOR_MODE_WITH_PREFIX): Ditto.
(VLS_MODES): Ditto.
* config/riscv/riscv-v.cc (can_be_broadcast_p): Add BF handling.
* config/riscv/riscv-vector-switch.def (VLS_ENTRY): Add BF
modes.
* config/riscv/riscv.md: Ditto.
* config/riscv/vector-iterators.md: Document modes.
* config/riscv/vector.md: Add BF modes.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr121582.c: New test.

2 weeks agovect: Use start value in vect_load_perm_consecutive_p [PR122797].
Robin Dapp [Sat, 22 Nov 2025 19:53:25 +0000 (20:53 +0100)] 
vect: Use start value in vect_load_perm_consecutive_p [PR122797].

vect_load_perm_consecutive_p is used in a spot where we want to check
that a permutation is consecutive and starting with 0.  Originally I
wanted to add this way of checking to the function but what I ended
up with is checking whether the given permutation is consecutive
starting from a certain index.  Thus, we will return true for
e.g. {1, 2, 3} which doesn't make sense in the context of the PR.
This patch corrects it.

PR tree-optimization/122797

gcc/ChangeLog:

* tree-vect-slp.cc (vect_load_perm_consecutive_p): Check
permutation start at element 0 with value instead of starting
at a given element.
(vect_optimize_slp_pass::remove_redundant_permutations):
Use start value of 0.
* tree-vectorizer.h (vect_load_perm_consecutive_p): Set default
value to to UINT_MAX.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/pr122797.c: New test.

2 weeks agoforwprop: Allow nop conversions for vector constructor.
Robin Dapp [Sun, 16 Nov 2025 17:42:04 +0000 (18:42 +0100)] 
forwprop: Allow nop conversions for vector constructor.

I observed a vect-construct forwprop opportunity in x264 that we
could handle when checking for a nop conversion instead of a useless
conversion.  IMHO a nop-conversion check is sufficient as we're only
dealing with permutations in simplify_vector_constructor.

This patch replaces uses of useless_type_conversion_p with
tree_nop_conversion_p in simplify_vector_constructor.

It was bootstrapped and regtested on x86 and power10, regtested on
aarch64 and riscv64.

There is a single scan-test failure on power
(gcc.target/powerpc/builtins-1.c).  The code actually looks better so
I took the liberty of adjusting the test expectation.

gcc/ChangeLog:

* tree-ssa-forwprop.cc (simplify_vector_constructor):
Allow nop conversions.

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/builtins-1.c: Adjust test expectation.
* gcc.target/riscv/rvv/autovec/pr118019-3.c: New test.

2 weeks agohppa: Update peephole2 patterns for scaled/unscaled indexed loads and stores
John David Anglin [Mon, 24 Nov 2025 19:38:49 +0000 (14:38 -0500)] 
hppa: Update peephole2 patterns for scaled/unscaled indexed loads and stores

The peephole2 patterns to optimize scaled/unscaled indexed loads and
stores are updated to ensure the REG_POINTER flag is set/unset in
the base/index regs on targets with non-equivalent space registers.

Previously, unscaled indexed loads and stores were only optimized on
targets with equivalent space registers.  We can now optimize these
instructions on targets with non-equivalent space registers.

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

gcc/ChangeLog:

* config/pa/pa.h (REGS_OK_FOR_BASE_INDEX): New define.
* config/pa/pa.md: Update peephole2 patterns for scaled/unscaled
indexed loads and stores.

2 weeks agoAvoid incomplete SLP handling for OMP SIMD calls with linear/invariant clause
Richard Biener [Mon, 24 Nov 2025 14:10:22 +0000 (15:10 +0100)] 
Avoid incomplete SLP handling for OMP SIMD calls with linear/invariant clause

The following restricts these cases to single-lange SLP as they look
at only the representative scalar argument.

PR tree-optimization/122826
* tree-vect-stmts.cc (vectorizable_simd_clone_call): Only
use single-lane SLP for SIMD_CLONE_ARG_TYPE_UNIFORM
and SIMD_CLONE_ARG_TYPE_LINEAR_[REF_]CONSTANT_STEP.

2 weeks agoAda: Fix incorrect handling of BOM by -r switch of gnatchop
Eric Botcazou [Mon, 24 Nov 2025 18:00:43 +0000 (19:00 +0100)] 
Ada: Fix incorrect handling of BOM by -r switch of gnatchop

As reported and analyzed in the PR, gnatchop does not correctly propagate
a BOM present in the source file to the first compilation unit it outputs,
in the case where the -r switch is specified, because it copies the BOM
for the first compilation unit as part of the chopping process instead of
copying it specifically at the start of the unit.

gcc/ada/
PR ada/81106
* gnatchop.adb (Gnatchop): If present in the source file, output
the BOM at the start of every compilation unit.

2 weeks agophiprop: Avoid proping loads into loops [PR116835]
Andrew Pinski [Fri, 21 Nov 2025 04:43:16 +0000 (20:43 -0800)] 
phiprop: Avoid proping loads into loops [PR116835]

This is v2 which uses Richi's code.
This amends "the post-dominance check to deal with
SSA cycles [...]. We need to constrain the load to
be in the same or a subloop (use
flow_loop_nested_p, not loop depth) or in the same
BB when either the load or the PHI is in an irreducible region."
(as described by Richard).

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/116835

gcc/ChangeLog:

* tree-ssa-phiprop.cc (propagate_with_phi): Admend the
post-dom check to deal with ssa cycles.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr116835.c: New test.
* gcc.dg/tree-ssa/phiprop-6.c: New test.
* gcc.dg/tree-ssa/phiprop-7.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Co-authored-by: Richard Biener <rguenther@suse.de>
2 weeks agophiprop: allowing prop into loop if there is a phi already
Andrew Pinski [Fri, 21 Nov 2025 07:14:24 +0000 (23:14 -0800)] 
phiprop: allowing prop into loop if there is a phi already

This is a small improvement over the original change
for PR60183 where if we created a phi already we can
reuse it always but since the order of this use might
be before the use which was valid to transform. we
need a vector to save the delayed ones.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/60183

gcc/ChangeLog:

* tree-ssa-phiprop.cc (propagate_with_phi): Delay the decision
of always rejecting proping into the loop until all are done.
if there was some delay stmts and a phi was created fill them in.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 weeks agophiprop: Allow non-trapping loads to be proped back into the loop
Andrew Pinski [Fri, 21 Nov 2025 06:39:48 +0000 (22:39 -0800)] 
phiprop: Allow non-trapping loads to be proped back into the loop

First the testcase for PR60183 is no longer testing that we don't
prop into the loops for possible trapping cases. This adds phiprop-4.c
that tests that.
Second we can prop back into loops if we know the load will not trap.
This adds that check. phiprop-3.c tests that.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/60183

gcc/ChangeLog:

* tree-ssa-phiprop.cc (propagate_with_phi): Allow
known non-trapping loads to happen back into the
loop.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 weeks agoforwprop: Allow mismatch clobbers in simple dse
Andrew Pinski [Mon, 24 Nov 2025 08:52:35 +0000 (00:52 -0800)] 
forwprop: Allow mismatch clobbers in simple dse

As mention in the patch that adds DSEing lhs of calls,
some testcases were xfailed due to exceptions and mismatch
of clobbers in some cases.
This allows them and un-xfails the testcase where they show
up.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* tree-ssa-forwprop.cc (do_simple_agr_dse): Allow
for mismatched clobbers.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/simple-dse-3.C: un-xfail.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 weeks agoforwprop: Add call stmt support to simple dse [PR122633]
Andrew Pinski [Mon, 24 Nov 2025 00:42:57 +0000 (16:42 -0800)] 
forwprop: Add call stmt support to simple dse [PR122633]

This adds the ability to the simple dse to remove the lhs of a
call. It can also remove a call if it was pure/const in some cases.

On trampv3, I found this happened a few times during forwprop2, 3
and 4. The one in 4 was a suprise and even more it caused a removal
of a call which gcc was not able to remove before. This is due to
the nature of DSE/DCE needs to be done iteratively together but
we currently don't do that. So it just happens the late forwprop4's
simple dse is able to remove this call.

I will fix the xfail testcases in a followup, basically there exceptions
can get a mismatch in the CLOBBER which I didn't except before and I was
being super cautious when it comes having them match but in reality
the difference in CLOBBERs don't matter.

Bootstrapped and tested on x86_64-linux-gnu

PR tree-optimization/122633
gcc/ChangeLog:

* tree-ssa-forwprop.cc (do_simple_agr_dse): Remove
lhs of dead store for a call (or the whole call stmt).

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/simple-dse-1.C: New test.
* g++.dg/tree-ssa/simple-dse-2.C: New test.
* g++.dg/tree-ssa/simple-dse-3.C: New test.
* g++.dg/tree-ssa/simple-dse-4.C: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 weeks agomatch: Move `(pointer_diff (pointer_plus @0 @2) (pointer_plus @1 @2))` pattern earlier
Andrew Pinski [Tue, 14 Oct 2025 03:42:53 +0000 (20:42 -0700)] 
match: Move `(pointer_diff (pointer_plus @0 @2) (pointer_plus @1 @2))` pattern earlier

This moves the `(pointer_diff (pointer_plus @0 @2) (pointer_plus @1 @2))` pattern
to right below the `(pointer_diff (pointer_plus @0 @1) (pointer_plus @0 @2))` pattern
to make easier to see both versions are supported.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* match.pd (`(ptr_diff (ptr_plus @0 @2) (ptr_plus @1 @2))`): Move pattern
earlier to the other `(ptr_diff (ptr_plus) (ptr_plus))` pattern.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 weeks agolibstdc++: Implement LWG 4370 for std::optional comparisons
Jonathan Wakely [Thu, 20 Nov 2025 12:19:54 +0000 (12:19 +0000)] 
libstdc++: Implement LWG 4370 for std::optional comparisons

This modifies the relational comparisons for std::optional so that they
do not use logical expressions with && or || that involve the
comparisons on the contained values, because x && (*y == *z) might do
the wrong thing if *y == *z does not return bool.

libstdc++-v3/ChangeLog:

* include/std/optional (operator==, operator!=, operator>)
(operator>, operator<=, operator>=): Do not use logical
&& and || with operands of unknown types.
* testsuite/20_util/optional/relops/lwg4370.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 weeks agolibstdc++: Implement LWG 4366 for std::expected comparisons
Jonathan Wakely [Thu, 20 Nov 2025 12:19:54 +0000 (12:19 +0000)] 
libstdc++: Implement LWG 4366 for std::expected comparisons

This modifies the equality comparisons for std::expected so that they do
not use explicit conversions to bool, to match the constraints which are
specified in terms of "convertible to" which implies implicitly
convertible. As a result of those changes, we cannot use logical
expressions with && or || that involve comparisons of the contained
values, because x && (*y == *z) might do the wrong thing if *y == *z
does not return bool.

Also add [[nodiscard]] attributes which were missing.

The new lwg4366.cc testcase is a dg-do run test not dg-do compile,
because the original example won't compile with libstdc++ even after
these fixes. We constrain the std::expected comparison operators with
std::convertible_to<bool> and the pathological Bool type in the issue
doesn't satisfy that concept. So the new test replaces the deleted
explicit conversion oeprator in the issue with one that isn't deleted
but terminates if called. This ensures we don't call it, thus ensuring
that std::expected's comparisons do implicit conversions only.

It's unclear to me whether using the convertible_to concept in
std::expected comparisons is conforming, or if we should switch to an
__implicitly_convertible_to<bool> concept which only uses
std::is_convertible_v<T, bool> and doesn't check for explicit
conversions. That can be addressed separately from this change.

libstdc++-v3/ChangeLog:

* include/std/expected (operator==): Use implicit conversion to
bool and do not use logical && and || with operands of unknown
types. Add nodiscard attributes.
* testsuite/20_util/expected/equality.cc: Test some missing
cases which were not covered previously.
* testsuite/20_util/expected/lwg4366.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 weeks agoc++: refactor maybe_delete_defaulted_fn [PR119964]
Marek Polacek [Fri, 21 Nov 2025 20:34:35 +0000 (15:34 -0500)] 
c++: refactor maybe_delete_defaulted_fn [PR119964]

This does three things:

1) [dcl.fct.def.default]/2.6 says "if F1 is explicitly defaulted on its
first declaration, it is defined as deleted;", but I wasn't heeding the
"on its first declaration" part, so fix that;

2) when the decl is actually ill-formed, don't talk about it being
implicitly deleted, because it's not;

3) there is no need to export maybe_delete_defaulted_fn.

PR c++/119964

gcc/cp/ChangeLog:

* cp-tree.h (maybe_delete_defaulted_fn): Remove.
* method.cc (maybe_delete_defaulted_fn): Make static.  Refactor.  If FN
is not explicitly defaulted on its first declaration, emit an error.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/defaulted1.C: New test.
* g++.dg/cpp1y/defaulted2.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 weeks agoMove SIMD clone rejections to SIMD clone selection
Richard Biener [Sun, 23 Nov 2025 12:57:47 +0000 (13:57 +0100)] 
Move SIMD clone rejections to SIMD clone selection

The following moves checks we used to reject SIMD clone vectorization
to selection of the SIMD clone.  It also removes unnecessary
restrictions on constant/external defs, vector types are already
determined and constraints should be not special here.

* tree-vect-stmts.cc (vectorizable_simd_clone_call): Move
all SIMD clone validity checks to SIMD clone selection.
Remove late constant/external def vector type setting and
verification.

2 weeks ago[PR rtl-optimization/122782] Fix out of range shift causing bootstrap failure with...
Jeff Law [Mon, 24 Nov 2025 13:05:27 +0000 (06:05 -0700)] 
[PR rtl-optimization/122782] Fix out of range shift causing bootstrap failure with ubsan

As noted in the PR, we're doing a bogus shift in the new code triggering a
ubsan failure.  This code works up through DImode and needs to reject attempts
at handling wider modes.  Yes, it could be extended to those wider modes and I
expect we will as int128 becomes more common, but it doesn't seem worth the
effort right now.

This patch adds the same kind of test we're using elsewhere to guard against
the bogus shift.  While I haven't been able to reproduce the ubsan bootstrap
failure, I can see the bogus shift under the debugger and I can see they no
longer occur after this patch.

This has been bootstrapped and regression tested on x86 and riscv.  It's also
been through all the crosses.  Pushing to the trunk momentarily.

jeff

PR rtl-optimization/122782
gcc/
* ext-dce.cc (ext_dct_process_uses): Guard against undefined shifts
by properly checking modes on the input object.

2 weeks agolibstdc++: Fix pretty printers for std::list
Jonathan Wakely [Mon, 24 Nov 2025 12:48:42 +0000 (12:48 +0000)] 
libstdc++: Fix pretty printers for std::list

The logs for xmethods.exp show that the std::list tests have never
worked:

gdb.error: No type named std::__cxx11::list<int, std::allocator<int> >::_Node.^M
skipping:   File "/home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/../python/libstdcxx/v6/xmethods.py", line 445, in match\r\nskipping:     node_type = gdb.lookup_type(str(class_type) + '::_Node').pointer()\r\nskipping:                 ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\nskipping: gdb.error: No type named std::__cxx11::list<int, std::allocator<int> >::_Node.\r\nlist.gdb:11: Error in sourced command file:^M
Error while looking for matching xmethod workers defined in Python.^M
skipping: list.gdb:11: Error in sourced command file:\r\nskipping: Error while looking for matching xmethod workers defined in Python.\r\nUNSUPPORTED: libstdc++-xmethods/list.cc

Because of the way the GDB tests treat errors as UNSUPPORTED (so that
the tests don't fail if the version of GDB is too old to support
xmethods) we were not getting any FAIL, even though the tests were
broken.

The std::list type does not have a nested _Node type, it only has
_Node_ptr. Instead of looking up _Node and then getting a pointer to
that type, just look up _Node_ptr instead.

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/xmethods.py (ListMethodsMatcher.match):
Fix lookup for node type.

2 weeks agolibstdc++: Fix XMethods for debug mode [PR122821]
Jonathan Wakely [Mon, 24 Nov 2025 12:36:32 +0000 (12:36 +0000)] 
libstdc++: Fix XMethods for debug mode [PR122821]

The Python GDB XMethods were not matching the debug mode containers,
because the is_specialization_of helper function matches std::(__\d::)?
and so fails to match std::__debug::deque etc.

This makes it match std::__debug:: as well as std:: and std::__8::.

Since the regex already handles the versioned namespace with (__\d::)?
we don't need to also include the _versioned_namespace variable
explicitly. This means we now match std::(__\d::|__debug::)?name<.*>
instead of matching std::(__\d::)?(__8::)?name<.*> which redundantly
included two ways to match the __8 versioned namespace.

libstdc++-v3/ChangeLog:

PR libstdc++/122821
* python/libstdcxx/v6/xmethods.py (_versioned_namespace): Remove
global variable.
(is_specialization_of): Do not use _versioned_namespace. Add
__debug:: to regex.

2 weeks agodwarf: Save bit stride information for array type entry [PR121964]
Yury Khrustalev [Wed, 3 Sep 2025 11:46:33 +0000 (12:46 +0100)] 
dwarf: Save bit stride information for array type entry [PR121964]

Lack of DW_AT_bit_stride in a DW_TAG_array_type entry causes GDB to infer
incorrect element size for vector types. The causes incorrect display of
SVE predicate variables as well as out of bounds memory access when reading
contents of SVE predicates from memory in GDB.

We also locate DIE referenced by DW_AT_type and set DW_AT_bit_size 1 in it.

PR debug/121964

gcc/
* dwarf2out.cc (gen_array_type_die): Add DW_AT_bit_stride attribute
for array types based on element type bit precision for integer and
boolean element types.

gcc/testsuite/
* g++.target/aarch64/dwarf-bit-stride-func.C: New test.
* g++.target/aarch64/dwarf-bit-stride-pragma.C: New test.
* g++.target/aarch64/dwarf-bit-stride-pragma-sme.C: New test.
* g++.target/aarch64/sve/dwarf-bit-stride.C: New test.
* gcc.target/aarch64/dwarf-bit-stride-func.c: New test.
* gcc.target/aarch64/dwarf-bit-stride-pragma.c: New test.
* gcc.target/aarch64/dwarf-bit-stride-pragma-sme.c: New test.
* gcc.target/aarch64/sve/dwarf-bit-stride.c: New test.

2 weeks agoFix comment for VECTOR_BOOL_MODE
Yury Khrustalev [Thu, 16 Oct 2025 14:54:37 +0000 (15:54 +0100)] 
Fix comment for VECTOR_BOOL_MODE

gcc/
* machmode.def (VECTOR_BOOL_MODE): Fix comment.

2 weeks agoFortran: Failure with 1st PDT example in F2018 standard [PR122766]
Paul Thomas [Mon, 24 Nov 2025 11:30:19 +0000 (11:30 +0000)] 
Fortran: Failure with 1st PDT example in F2018 standard [PR122766]

2025-11-24  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/122766
* decl.cc (gfc_match_decl_type_spec): A pdt_type found while
parsing a contains section can only arise from the typespec of
a function declaration. This can be retained in the typespec.
Once we are parsing the function, the first reference to this
derived type will find that it has no symtree. Provide it with
one so that gfc_use_derived does not complain and, again,retain
it in the typespec.

gcc/testsuite
PR fortran/122766
* gfortran.dg/pdt_69.f03: New test.

2 weeks agoAdjust gcc.dg/vect/bb-slp-41.c
Richard Biener [Mon, 24 Nov 2025 10:18:42 +0000 (11:18 +0100)] 
Adjust gcc.dg/vect/bb-slp-41.c

We now perform SLP vectorization for the scalar epilog of a vector
loop where we now unroll said scalar epilog.  The following adjusts
the testcase to look for SLP trying to vectorize a CTOR instead,
which I guessed from the topic of r10-4336-g818b3293f4545d which
added this testcase.

* gcc.dg/vect/bb-slp-41.c: Adjust dump scan.

2 weeks agolibstdc++: Mark new istream::ignore overload always_inline
Jonathan Wakely [Mon, 24 Nov 2025 10:07:03 +0000 (10:07 +0000)] 
libstdc++: Mark new istream::ignore overload always_inline

This means we don't need to add the new member to the explicit
instantiation definition.

libstdc++-v3/ChangeLog:

* include/std/istream (istream::ignore(streamsize, char)): Add
always_inline attribute.

2 weeks agoFix wrong code for indexed component with very large index type
Eric Botcazou [Mon, 24 Nov 2025 09:36:35 +0000 (10:36 +0100)] 
Fix wrong code for indexed component with very large index type

This fixes an old issue whereby we generate wrong code in Ada for an indexed
component in an array with a ludicrously large index type instead of raising
Storage_Error.  We would need the counterpart of int_const_binop for unop in
the general case, but that's not worth the hassle and int_const_convert is
good enough.

gcc/
PR ada/33994
* fold-const.h (int_const_convert): New prototype.
* fold-const.cc (fold_convert_const_int_from_int): Rename to...
(int_const_convert): ...this, remove static keyword and add third
parameter OVERFLOWABLE.
(fold_convert_const): Call int_const_convert if ARG1 is an integer
constant.

gcc/ada/
PR ada/33994
* gcc-interface/utils.cc (convert) <INTEGER_TYPE>: Call
int_const_convert if the expression is an integer constant.

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

2 weeks agogcc: Set native_system_header_dir on aarch64-mingw
Francois-Xavier Coudert [Thu, 20 Nov 2025 17:05:18 +0000 (18:05 +0100)] 
gcc: Set native_system_header_dir on aarch64-mingw

Provide a sensible default value for native_system_header_dir, namely
/mingw/include, on aarch64-mingw. This is in line with the expectations
for mingw file locations, and is already set on both x86- and
x86_64-mingw.

gcc/ChangeLog:
* config.gcc (aarch64-*-mingw*): Set native_system_header_dir.

2 weeks agoAdjust testcase.
liuhongt [Mon, 24 Nov 2025 05:46:23 +0000 (21:46 -0800)] 
Adjust testcase.

r16-3760-g9ff5cadac4579f generates more condition move for
-march=cascadelake, and causes new failures as below

FAIL: gcc.target/i386/pr116896.c scan-assembler-times \tjp\t 2
FAIL: g++.target/i386/pr116896-1.C  -std=gnu++20  scan-assembler-times \tjp\t 1
FAIL: g++.target/i386/pr116896-1.C  -std=gnu++23  scan-assembler-times \tjp\t 1
FAIL: g++.target/i386/pr116896-1.C  -std=gnu++26  scan-assembler-times \tjp\t 1

the code generated should be better than before, so just add
-mtune=generic to "fix" the testcases.

gcc/testsuite/ChangeLog:

PR target/122503
* g++.target/i386/pr116896-1.C: Add -mtune=generic to
dg-options.
* gcc.target/i386/pr116896.c: Ditto.

2 weeks agoDaily bump.
GCC Administrator [Mon, 24 Nov 2025 00:18:45 +0000 (00:18 +0000)] 
Daily bump.

2 weeks agohppa: Define GLIBC_DYNAMIC_LINKER in pa64-linux.h
John David Anglin [Sun, 23 Nov 2025 22:31:17 +0000 (17:31 -0500)] 
hppa: Define GLIBC_DYNAMIC_LINKER in pa64-linux.h

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

gcc/ChangeLog:

* config/pa/pa64-linux.h (GLIBC_DYNAMIC_LINKER): Define.

2 weeks agohppa: Enable LRA as default
John David Anglin [Sun, 23 Nov 2025 22:29:43 +0000 (17:29 -0500)] 
hppa: Enable LRA as default

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

gcc/ChangeLog:

PR target/113932
PR target/113933
* config/pa/pa.opt (mlra): Default to LRA instead of reload.

2 weeks agohppa: Fix scaled and unscaled index support on targets with non-equivalent space...
John David Anglin [Sun, 23 Nov 2025 22:27:51 +0000 (17:27 -0500)] 
hppa: Fix scaled and unscaled index support on targets with non-equivalent space registers

HP-UX targets have non-equivalent space registers.  The base register
in most loads and stores selects the space register used to calculate
the global virtual address for the instruction.

Previously, the PA-RISC backend attempted to canonicalize the
register order in INDEX + BASE register addresses.  This has always
been problematic as reload would sometimes lose the REG_POINTER
flag used to mark a base register.  As a result, we allowed any
register order after reload and prayed the registers would be
in canonical order.

This broke with the new late_combine2 pass.  It sometimes creates
new indexed instructions after reload.  pa_legitimate_address_p
needs updating to ensure the base register is marked with the
REG_POINTER flag and the index register is not marked.

If scaled index instructions are created before reload, the LRA
pass will sometimes convert it an unscaled index instruction
plus reloads and drop the REG_POINTER flag that was in the base
register.  Thus, we can't allow scaled and unscaled index loads
and stores until reload is completed.

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

gcc/ChangeLog:

* config/pa/pa.cc (pa_print_operand): Use REG_POINTER
flag to select base and index registers on targets with
non-equivalent space registers.
(pa_legitimate_address_p): Don't allow scaled and unscaled
indexed addresses until reload is complete.  Allow any
register order in unscaled addresses as long as the
REG_POINTER flag is correctly set/unset in the base/index
registers.
* config/pa/predicates.md (mem_operand): Remove code to
delay creating move insns with unscaled indexed addresses
until CSE is not expected.
(move_src_operand): Likewise.

2 weeks agomatch: Move two patterns to use fold_before_rtl_expansion_p instead of !canonicalize_...
Andrew Pinski [Thu, 20 Nov 2025 20:41:10 +0000 (12:41 -0800)] 
match: Move two patterns to use fold_before_rtl_expansion_p instead of !canonicalize_math_p

This moves 2 patterns, `1/x` and `(m1 CMP m2) * d` patterns to
use `fold_before_rtl_expansion_p()` instead of `!canonicalize_math_p ()`
it was before.

These 2 were checking !canonicalize_math_p() before because there was no
other predicate that was decent until fold_before_rtl_expansion_p was added.

Bootstrappd and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* match.pd (1/x): Use fold_before_rtl_expansion_p.
(`(m1 CMP m2) * d`): Likewise.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 weeks agoPR modula2/122801 soname bump for GCC 16
Gaius Mulley [Sun, 23 Nov 2025 17:52:47 +0000 (17:52 +0000)] 
PR modula2/122801 soname bump for GCC 16

This patch bumps the libgm2 soname to 21:0:0 ready for the release of GCC 16.

libgm2/ChangeLog:

PR modula2/122801
* configure: Regenerate.
* configure.ac (libtool_VERSION): Assign to 21:0:0.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 weeks agoMatch: Remove unnecessary convert for unsigned SAT_MUL
Pan Li [Sat, 15 Nov 2025 03:22:23 +0000 (11:22 +0800)] 
Match: Remove unnecessary convert for unsigned SAT_MUL

After we convert from bit_op outer into its captures, some
outer convert of unsigned SAT_MUL form 6 is unnecessary any
more.  Thus, remove it.  Meanwhile, add c after outer bit_ior
to make the test happy.

gcc/ChangeLog:

* match.pd: Remove unnecessary outer convert and add
c for the outer bit_ior.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 weeks agoTest: Add test case for bit_op convert folding
Pan Li [Sat, 15 Nov 2025 03:21:37 +0000 (11:21 +0800)] 
Test: Add test case for bit_op convert folding

Add test cases of all possible types of bit_op convert folding.
To check there is no tree dump like below:

   _5 = (uint8_t) _2;
   return _5;

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/bit_op_cvt.1.c: New test.
* gcc.dg/tree-ssa/bit_op_cvt.2.c: New test.
* gcc.dg/tree-ssa/bit_op_cvt.3.c: New test.
* gcc.dg/tree-ssa/bit_op_cvt.4.c: New test.
* gcc.dg/tree-ssa/bit_op_cvt.5.c: New test.
* gcc.dg/tree-ssa/bit_op_cvt.6.c: New test.
* gcc.dg/tree-ssa/bit_op_cvt.h: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 weeks agoMatch: Simplify (T1)(a bit_op (T2)b) to (T1)a bit_op (T1)b
Pan Li [Sat, 15 Nov 2025 03:20:37 +0000 (11:20 +0800)] 
Match: Simplify (T1)(a bit_op (T2)b) to (T1)a bit_op (T1)b

During the match pattern of SAT_U_MUL form 7, we found there is
a pattern like below:

(nop_convert)(a bit_op (convert b))

which result in the pattern match of SAT_U_MUL complicated and
unintuitive.  According to the suggestion of Richard, we would
like to simply it to blew:

(convert a) bit_op (convert b)

which is more friendly for reading and bit_op.  There are three
bit_op here, aka bit_ior, bit_and and bit_xor.

gcc/ChangeLog:

* match.pd: Add simplfy to fold outer convert of bit_op
to inner captures.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 weeks ago[PATCH] Run feedback directed ipa-split for flag_auto_profile
Kugan Vivekanandarajah [Sun, 23 Nov 2025 06:14:53 +0000 (17:14 +1100)] 
[PATCH] Run feedback directed ipa-split for flag_auto_profile

IPA split is now running before auto-profile annotation. Changing it
after annotation as it is done for PGO.

gcc/ChangeLog:

2025-07-21  Kugan Vivekanandarajah  <kvivekananda@nvidia.com>

* ipa-split.cc (pass_split_functions::gate): Do not run when
flag_auto_profile.
(pass_feedback_split_functions::gate): Run when flag_auto_profile.

2 weeks ago[tree-optimization] Allow LICM to hoist loads in "self write" patterns
Kugan Vivekanandarajah [Sun, 23 Nov 2025 04:27:10 +0000 (15:27 +1100)] 
[tree-optimization] Allow LICM to hoist loads in "self write" patterns

This patch enables Loop Invariant Code Motion (LICM) to hoist loads that
alias with stores when SSA def-use analysis proves the stored value comes
from the loaded value.

The pattern a[i] = a[0] is common in TSVC benchmarks (s293):

  for (int i = 0; i < N; i++)
    a[i] = a[0];

Previously, GCC conservatively rejected hoisting a[0] due to potential
aliasing when i==0. However, this is a "self write" - even when aliasing
occurs, we're writing back the same value, making hoisting safe.

The optimization checks that:
1. One reference is a load, the other is a store
2. The stored SSA value equals the loaded SSA value
3. Only simple cases with single accesses per reference

This enables vectorization of these patterns by allowing the vectorizer
to see the hoisted loop-invariant value.

With the patch, the loop now vectorizes and generates:

        .L2:
-       ldr     s31, [x1]
-       str     s31, [x0], 4
-       cmp     x0, x2
+       str     q31, [x0], 16
+       cmp     x0, x1
        bne     .L2

gcc/ChangeLog:

* tree-ssa-loop-im.cc (is_self_write): New.
(ref_indep_loop_p): Allow hoisting when aliasing references
form a self write pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-licm-hoist-1.c: New.
* gcc.dg/vect/vect-licm-hoist-2.c: Likewise.

Signed-off-by: Kugan Vivekanandarajah <kvivekananda@nvidia.com>
2 weeks agoOpenMP: Fix "begin declare variant" test failure with -m32
Sandra Loosemore [Sun, 23 Nov 2025 03:29:34 +0000 (03:29 +0000)] 
OpenMP: Fix "begin declare variant" test failure with -m32

As reported by Haochen Jiang, this recently-added test case was
failing on x86_64 with -m32; the target hook for matching the "arch"
selector won't match "x86_64" in that case, even if gcc was configured
for that target.  It does match plain "x86" for both 64 and 32 bit targets,
so I've switched the testcase to use that instead.

Committed as obvious (at least in retrospect).

gcc/testsuite/ChangeLog
* c-c++-common/gomp/delim-declare-variant-6.c (f3): Use "x86"
instead of "x86_64" in the arch selector, to match both 64- and
32-bit targets.

2 weeks agoDaily bump.
GCC Administrator [Sun, 23 Nov 2025 00:19:38 +0000 (00:19 +0000)] 
Daily bump.

2 weeks agoc++/modules: Fix -Wexpose-global-module-tu-local [PR122636]
Nathaniel Shead [Sat, 22 Nov 2025 13:06:06 +0000 (00:06 +1100)] 
c++/modules: Fix -Wexpose-global-module-tu-local [PR122636]

I had mistakenly been checking the importedness of the originating
module decl, but this is wrong: really we want to check if the specific
decl we're currently instantating came from another module, so just
check DECL_MODULE_IMPORT_P on this directly.

Also updated slightly since there are cases where we do emit TU-local
function or variable templates, albeit unlikely to come up frequently.

PR c++/122636

gcc/cp/ChangeLog:

* module.cc (instantiating_tu_local_entity): Don't check
importingness of originating module decl; also check templates.

gcc/testsuite/ChangeLog:

* g++.dg/modules/internal-19_a.C: New test.
* g++.dg/modules/internal-19_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2 weeks agoc++: Add detailed diagnostics for __is_pointer_interconvertible_base_of
Nathaniel Shead [Sat, 25 Oct 2025 11:40:06 +0000 (22:40 +1100)] 
c++: Add detailed diagnostics for __is_pointer_interconvertible_base_of

gcc/cp/ChangeLog:

* constraint.cc (diagnose_trait_expr):
<case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF>: Explain failure
with more detail.
* cp-tree.h (pointer_interconvertible_base_of_p): Add explain
parameter.
* semantics.cc (pointer_interconvertible_base_of_p): Explain why
not.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/is-pointer-interconvertible-base-of2.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2 weeks agoc++: Add detailed diagnostics for __is_layout_compatible
Nathaniel Shead [Thu, 23 Oct 2025 02:57:37 +0000 (13:57 +1100)] 
c++: Add detailed diagnostics for __is_layout_compatible

gcc/cp/ChangeLog:

* constraint.cc (diagnose_trait_expr)
<case CPTK_IS_LAYOUT_COMPATIBLE>: Explain why not.
* cp-tree.h (layout_compatible_type_p): Add explain parameter.
* typeck.cc (layout_compatible_type_p): Add explanations when
returning false.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/is-layout-compatible4.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2 weeks agoc++: Add detailed diagnostics for __builtin_has_unique_object_representations
Nathaniel Shead [Thu, 23 Oct 2025 02:51:57 +0000 (13:51 +1100)] 
c++: Add detailed diagnostics for __builtin_has_unique_object_representations

gcc/cp/ChangeLog:

* constraint.cc (diagnose_trait_expr)
<case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS>: Explain failure with
more detail.
* cp-tree.h (type_has_unique_obj_representations): Add explain
parameter.
* tree.cc (record_has_unique_obj_representations): Explain when
returning false.
(type_has_unique_obj_representations): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/has-unique-obj-representations5.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2 weeks agoc++: Fix diagnostics for __is_destructable
Nathaniel Shead [Thu, 23 Oct 2025 06:10:04 +0000 (17:10 +1100)] 
c++: Fix diagnostics for __is_destructable

We'd missed providing a diagnostic when checking a non-scalar non-class
type, such as a function type.

gcc/cp/ChangeLog:

* method.cc (destructible_expr): Add explanation when type is
neither class nor scalar.

gcc/testsuite/ChangeLog:

* g++.dg/ext/is_destructible3.C: Add test for function type.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2 weeks agoc++: Adjust location of is_*_base_of diagnostics
Nathaniel Shead [Sat, 25 Oct 2025 13:01:30 +0000 (00:01 +1100)] 
c++: Adjust location of is_*_base_of diagnostics

It makes more sense to point at the derived type (that didn't specify
the base class).

gcc/cp/ChangeLog:

* constraint.cc (diagnose_trait_expr): Use t2's location for
is_base_of, is_pointer_interconvertible_base_of, and
is_virtual_base_of.

gcc/testsuite/ChangeLog:

* g++.dg/ext/is_virtual_base_of_diagnostic2.C: Adjust
diagnostic.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>