]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
3 hours agooptabs: Fix expansion of abs and neg for Float16 [PR123869] master trunk
Andrew Pinski [Thu, 29 Jan 2026 00:50:52 +0000 (16:50 -0800)] 
optabs: Fix expansion of abs and neg for Float16 [PR123869]

The problem here is we try to use the widening type before
doing the bitwise expansion of neg/and for floating point types.
This moves the code around to try the bitwise expansion first.

Note this mostly matters for NaNs where you widening (promotion)
would cause a NaN to be slightly different when doing the rounding
back.

Bootstrapped and tested on x86_64-linux-gnu.

PR middle-end/123869

gcc/ChangeLog:

* optabs.cc (expand_unop): Move the NEG optab
handling before the widening code.
Move the ABS bitwise expansion from expand_abs_nojump
to before the widening code.
(expand_abs_nojump): Remove the bitwise expansion trial
since expand_unop is called right above.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
4 hours agolibstdc++: Make std::expected trivially copy/move assignable (LWG 4026)
Jonathan Wakely [Wed, 28 Jan 2026 12:33:46 +0000 (12:33 +0000)] 
libstdc++: Make std::expected trivially copy/move assignable (LWG 4026)

This is the subject of two NB comments on C++26 which seem likely to be
approved. We're allowed to make this change as QoI anyway, even if it
isn't approved for the standard, and it should apply to C++23 as well to
avoid ABI changes between C++23 and C++26.

As shown in the updates to the test, defaulted special members can have
noexcept(false) even if they would be noexcept(true) by default. The new
defaulted operator= overloads added by this commit have conditional
noexcept-specifiers that match the conditions of the non-trivial
assignments, propagating any noexcept(false) on trivial special members
of the T and E types. We could strengthen the noexcept for the trivial
operators, but propagating the conditions from the underlying types is
probably what users expect, if they've bothered to put noexcept(false)
on their defaulted special members.

libstdc++-v3/ChangeLog:

* include/std/expected (__expected::__trivially_replaceable)
(__expected::__usable_for_assign)
(__expected::__usable_for_trivial_assign)
(__expected::__can_reassign_type): New concepts.
(expected::operator=): Adjust constraints
on existing overloads and add defaulted overload.
(expected<cv void, E>::operator=): Likewise.
* testsuite/20_util/expected/requirements.cc: Check for trivial
and nothrow properties of assignments.

5 hours agotestsuite: Move pr116353.c from being x86 specific to being generic
Andrew Pinski [Wed, 28 Jan 2026 20:16:43 +0000 (12:16 -0800)] 
testsuite: Move pr116353.c from being x86 specific to being generic

While working on ifcvt's noce_can_force_operand, I noticed that
the testcase pr116353.c was added as x86 specific testcase but
it has nothing in it that is x86 specific. It is currently
compiled at -O2 but there is no reason why it can't be compiled
at any other optimization level.
So this moves the testcase to be a torture testcase.

The original issue showed up on x86 with respect to ifcvt
where there was a vec_select which does not have an optab for it
but it might show up on other targets too.

Tested on x86_64-linux-gnu.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr116353.c: Move to...
* gcc.dg/torture/pr116353.c: ...here.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
6 hours agoAllow CONCATs in emit_group_load_1.
Roger Sayle [Thu, 29 Jan 2026 18:48:14 +0000 (18:48 +0000)] 
Allow CONCATs in emit_group_load_1.

This one line patch is a pre-requisite to a solution to PR target/123506;
an effort to improve middle-end code for returning structures.  Currently,
emit_group_load_1 contains code to handle a CONCAT returned by force_reg.
This tweak avoids the call for force_reg if the source is already a CONCAT,
which allows this subroutine to be re-used by target-specific implementations
of emit_group_load.  Many thanks to Jeff Law for cross-platform testing.

2026-01-29  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* expr.cc (emit_group_load_1): Don't call force_reg if orig_src
is already a CONCAT.

7 hours agoAda: Fix internal error on equality test with empty container
Eric Botcazou [Thu, 29 Jan 2026 15:16:08 +0000 (16:16 +0100)] 
Ada: Fix internal error on equality test with empty container

This is a regression present on the mainline and 15 branch, although the
root cause has been present for years: the Sem_Type.Covers predicate
returns true for the type of an aggregate (Any_Composite) and any type
declared with the Aggregate aspect (when invoked in Ada 2022 or later),
but its companion function Sem_Type.Specific_Type punts when it is called
on the same combination.

gcc/ada/
PR ada/123861
* sem_type.adb (Covers): Fix couple of typos in comment.
(Specific_Type): Adjust to Covers' handling of types declared
with the Aggregate aspect in Ada 2022.

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

7 hours agotestsuite: arm: rework some target-supports checks to use -mfpu=auto
Richard Earnshaw [Thu, 29 Jan 2026 10:25:41 +0000 (10:25 +0000)] 
testsuite: arm: rework some target-supports checks to use -mfpu=auto

Several target-supports checks for Arm are still using the antiquated
-mfpu=... setting rather than picking up FPU extensions via the
architecture specification.  This causes problems when tests are
layered because they do not consistently override each other.

Arguably, that is incorrect anyway: you can't test two sets of flag
combinations independently and then expect to be able to apply both
of them, but this change at least makes this behave in a reasonable
way provided the second set of flags fully overrides the first.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp:
(check_effective_target_arm_v8_3a_complex_neon_ok_nocache):
Split and fill in arm and aarch64 compile options.  Remove the
cpu_unset variable.
(check_effective_target_arm_v8_2a_fp16_neon_ok_nocache): Likewise.
(check_effective_target_arm_v8_3a_fp16_complex_neon_ok_nocache):
Likewise.
(check_effective_target_arm_neon_ok_nocache): Rework to use
-mfpu=auto.
(check_effective_target_arm_neon_fp16_ok_nocache): Likewise.

Co-authored-by: Artemiy Volkov <artemiy.volkov@arm.com>
7 hours agotestsuite: require arm_v8_3a_fp16_complex_neon for complex fp16 tests
Artemiy Volkov [Thu, 8 Jan 2026 11:51:06 +0000 (11:51 +0000)] 
testsuite: require arm_v8_3a_fp16_complex_neon for complex fp16 tests

Changes to target-supports.exp from r16-6519-g56dd47c073cabf introduced
some new failures for complex fp16 tests with some arm-eabi targets
configured with -mfpu=auto.  This patch fixes those by (a) requiring the
full arm_v8_3a_fp16_complex_neon_ok target instead of just float16 in
vect/complex fp16 tests, and (b) simplifying down to one
dg-require-effective-target and one dg-add-options and removing the
explicit -march in advsimd-intrinsics/vector-complex_f16.c.

Regtested on aarch64, and the Linaro CI also delivers a positive verdict
for the relevant cortex-m33/-m3/-m55/-m7 configurations (after the
accompanying patch to target-supports.exp that follows).  Huge thanks to
Christophe for testing this on arm.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/complex/fast-math-bb-slp-complex-add-half-float.c:
Adjust testcase.
* gcc.dg/vect/complex/fast-math-bb-slp-complex-add-pattern-half-float.c:
Likewise.
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mla-half-float.c:
Likewise.
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mls-half-float.c:
Likewise.
* gcc.dg/vect/complex/fast-math-bb-slp-complex-mul-half-float.c:
Likewise.
* gcc.dg/vect/complex/fast-math-complex-add-half-float.c: Likewise.
* gcc.dg/vect/complex/fast-math-complex-add-pattern-half-float.c:
Likewise.
* gcc.dg/vect/complex/fast-math-complex-mla-half-float.c:
Likewise.
* gcc.dg/vect/complex/fast-math-complex-mls-half-float.c:
Likewise.
* gcc.dg/vect/complex/fast-math-complex-mul-half-float.c:
Likewise.
* gcc.target/aarch64/advsimd-intrinsics/vector-complex_f16.c:
Likewise.

7 hours agolibstdc++: Fix use of feature test macro in <source_location>
Jonathan Wakely [Thu, 29 Jan 2026 17:02:43 +0000 (17:02 +0000)] 
libstdc++: Fix use of feature test macro in <source_location>

libstdc++-v3/ChangeLog:

* include/std/source_location: Check __glibcxx_contracts instead
of __cpp_lib_contracts.
* testsuite/18_support/contracts/includes.cc: New test.

7 hours agolibstdc++: fix a wrong export of a contracts facility in std module
vspefs [Thu, 29 Jan 2026 16:58:19 +0000 (16:58 +0000)] 
libstdc++: fix a wrong export of a contracts facility in std module

This patch fixes a wrong export name in std module. std module currently
exports std::contracts::invoke_default_violation_handler, which is wrong.
The correct name is std::contracts::invoke_default_contract_violation_handler.

libstdc++-v3/ChangeLog:

* src/c++23/std.cc.in (invoke_default_violation_handler): Change
to invoke_default_contract_violation_handler.

Signed-off-by: Xie Han <vspefs@protonmail.com>
8 hours agoarm: testsuite: Use test framework to set arch in stack-protector-7
Christopher Bazley [Thu, 29 Jan 2026 15:55:15 +0000 (15:55 +0000)] 
arm: testsuite: Use test framework to set arch in stack-protector-7

This test was trying to set the architecture directly instead of
using the framework. The queried options were previously ignored.

gcc/testsuite/ChangeLog:
* gcc.target/arm/stack-protector-7.c: Fix dgdirectives.

8 hours agodoc: Add "user experience" documentation for options
Sandra Loosemore [Thu, 29 Jan 2026 16:41:07 +0000 (16:41 +0000)] 
doc: Add "user experience" documentation for options

After working through PR122243, it seems appropriate to write down
some guidelines for adding/maintaining options and options
documentation so that we can at least point to procedures to keep
things from getting out of sync again.

Thanks to jemarch@gnu.org and dmalcolm@redhat.com for their suggestions
to improve this patch.

gcc/ChangeLog
* doc/options.texi (Options): Point to the "user experience"
documentation.
* doc/ux.texi (Guidelines for Options): Add some.

8 hours agoRISC-V: Handle VL-setting FoF loads. [PR123806]
Robin Dapp [Mon, 26 Jan 2026 14:24:10 +0000 (15:24 +0100)] 
RISC-V: Handle VL-setting FoF loads. [PR123806]

For PR122869 I thought I fixed the issue of VL-spills clobbering
explicit VL reads after fault-only-first (FoF) loads but it turns
out the fix is insufficient.  Even though it avoided the original
issue, we can still have spills that clobber VL before the read_vl
RTL pattern.  That's mostly due to us hiding the VL data flow from
the optimizers so a regular spill to memory can and will introduce
a VL clobber.  In vsetvl we catch all the regular cases but not the
FoF-load case of PR123806 and PR122869.

This patch adds specific FoF patterns that emit the same instruction but
have a register-setting VL pattern inside the insn's PARALLEL.
It serves as a marker for the vsetvl pass that can recognize that we
clobber VL before reading its value.  In that case we now emit an
explicit csrr ..,vl.

After vsetvl it's safe to emit the read_vls because at that point the
VL dataflow has been established and we can be sure to not clobber VL
anymore.

Thus, the main changes are:
 - Unify read_vl si and di and make it an UNSPEC.  We don't optimize
   it anyway so a unified one is easier to include in the new FoF
   VL-setter variants.
 - Introduce VL-setting variants of FoF loads and handle them like
   read_vl()s in the vsetvl pass.
 - Emit read_vl()s after vsetvl insertion is done.

What this doesn't get rid of is the XFAIL in ff-load-3.c that I
introduced for PR122869.  The code is still "good" at -O1 and
"bad" at -O2 upwards.

PR target/123806

gcc/ChangeLog:

* config/riscv/riscv-string.cc (expand_rawmemchr): Use unified
vl_read.
(expand_strcmp): Ditto.
* config/riscv/riscv-vector-builtins-bases.cc:
* config/riscv/riscv-vector-builtins.cc (function_expander::use_fof_load_insn):
Only emit the store and not the VL read.
* config/riscv/riscv-vsetvl.cc (get_fof_set_vl_reg): New
function.
(init_rtl_ssa): New wrapper.
(finish_rtl_ssa): Ditto.
(emit_fof_read_vls): Emit read_vl after each fault-only-first
load.
(pass_vsetvl::simple_vsetvl): Call emit_fof_read_vls ().
(pass_vsetvl::lazy_vsetvl): Ditto.
* config/riscv/vector-iterators.md: Add read_vl unspec.
* config/riscv/vector.md (read_vlsi): Unify.
(@read_vl<mode>): Ditto.
(read_vldi_zero_extend): Ditto.
(@pred_fault_load_set_vl<V_VLS:mode><P:mode>): New FoF variant
that saves VL in a register.
(@pred_fault_load_set_vl<VT:mode><P:mode>): Ditto.

gcc/testsuite/ChangeLog:

* g++.target/riscv/rvv/base/pr123806.C: New test.
* g++.target/riscv/rvv/base/pr123808.C: New test.
* g++.target/riscv/rvv/base/pr123808-2.C: New test.

8 hours agoRISC-V: testsuite: Add zvl requirement to PR123626.
Robin Dapp [Wed, 28 Jan 2026 16:54:42 +0000 (17:54 +0100)] 
RISC-V: testsuite: Add zvl requirement to PR123626.

This adds a new require-effective-target check to pr123626.c.
As the test is a run test compiled with _zvl256b we need
to ensure the target actually supports 256b vectors.

We can only check for exactly 256b right now
(rvv_zvl256b_ok), i.e. "VLS".  Therefore, the patch also adds
a new target check rvv_zvl_ge_256b_ok where ge means greater
or equal.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp: Add rvv_zvl_ge_256b_ok.
* gcc.target/riscv/rvv/base/pr123626.c: Use new target check.

8 hours agod: Fix Segmentation fault with redeclared symbols [PR123407]
Iain Buclaw [Thu, 29 Jan 2026 15:26:21 +0000 (16:26 +0100)] 
d: Fix Segmentation fault with redeclared symbols [PR123407]

Issue an error if two symbols with the same assembler name have a
mismatched TREE_CODE.

PR d/123407

gcc/d/ChangeLog:

* decl.cc (get_symbol_decl): Handle declarations with matching
assembler names, but different TREE_CODE.

gcc/testsuite/ChangeLog:

* gdc.dg/pr123407a.d: New test.
* gdc.dg/pr123407b.d: New test.

10 hours agopta: Fix comment of intra_create_variable_infos
Filip Kastl [Thu, 29 Jan 2026 15:01:33 +0000 (16:01 +0100)] 
pta: Fix comment of intra_create_variable_infos

The comment says that this function creates varinfos for *all*
variables in a function.  Meanwhile, it only creates varinfos for
parameters, the return value and the static chain.

Commiting as obvious.

gcc/ChangeLog:

* gimple-ssa-pta-constraints.cc (make_param_constraints): Adjust
comment: The function only creates varinfos for the parameters,
the return value and the static chain.

Signed-off-by: Filip Kastl <fkastl@suse.cz>
10 hours agoc++/reflection: add fixed test [PR123871]
Marek Polacek [Thu, 29 Jan 2026 14:39:12 +0000 (09:39 -0500)] 
c++/reflection: add fixed test [PR123871]

Incredibly, a patch that I just pushed (r16-7140-g101f2970adc0a7) fixed
this ICE.

I notice that we don't emit the diag_array_subscript diagnostic because
slice calls fold_non_dependent_expr which calls _eval_outermost with
allow_non_constant=true.  I wonder if we want to change this.

PR c++/123871

gcc/testsuite/ChangeLog:

* g++.dg/reflect/error11.C: New test.

10 hours agod: Fix ICE in gimplify_expr with const ref noreturn parameters [PR123046]
Iain Buclaw [Thu, 29 Jan 2026 13:06:14 +0000 (14:06 +0100)] 
d: Fix ICE in gimplify_expr with const ref noreturn parameters [PR123046]

The ICE was caused by references to const/immutable qualified `noreturn'
declarations that were being leaked to the code generation when they
should have been omitted or replaced with `assert(0)'.

PR d/123046

gcc/d/ChangeLog:

* d-codegen.cc (build_address): Return `null' when generating the
address of a `noreturn' declaration.
(d_build_call): Compare TYPE_MAIN_VARIANT of type with `noreturn'.
* decl.cc (get_fndecl_arguments): Likewise.
* types.cc (finish_aggregate_mode): Likewise.
(TypeVisitor::visit (TypeFunction *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/pr123046.d: New test.

10 hours agotree-optimization/122537 - do not elide maybe_zero condition for wrapping IV
Richard Biener [Thu, 29 Jan 2026 12:56:11 +0000 (13:56 +0100)] 
tree-optimization/122537 - do not elide maybe_zero condition for wrapping IV

The following removes the optimization eliding the maybe_zero condition
from number_of_iterations_lt_to_ne when the IV can overflow since the
IV delta input is not accurately reflecting this.

PR tree-optimization/122537
* tree-ssa-loop-niter.cc (number_of_iterations_lt_to_ne): Register
may_be_zero condition when the IV may overflow.

* gcc.dg/torture/pr122537.c: New testcase.

11 hours agoc++/reflection: tweak for eval_has_template_arguments
Marek Polacek [Wed, 28 Jan 2026 20:43:35 +0000 (15:43 -0500)] 
c++/reflection: tweak for eval_has_template_arguments

As discussed in
<https://gcc.gnu.org/pipermail/gcc-patches/2026-January/705756.html>:

> For reflection it's probably best to go with
>
> if (TYPE_P (r) && typedef_variant_p (r))
>   return alias_template_specialization_p (r, nt_opaque);
>
> and not get into primary_template_specialization_p at all.

Here in a patch form.

gcc/cp/ChangeLog:

* reflect.cc (eval_has_template_arguments): Return immediately after
checking alias_template_specialization_p.

Reviewed-by: Jason Merrill <jason@redhat.com>
11 hours agoc++/reflection: add assert to eval_type_trait
Marek Polacek [Wed, 28 Jan 2026 21:26:35 +0000 (16:26 -0500)] 
c++/reflection: add assert to eval_type_trait

As discussed in
<https://gcc.gnu.org/pipermail/gcc-patches/2026-January/705756.html>.

Since we check eval_is_type in process_metafunction:

  if (eval_is_type (ht) != boolean_true_node)
     return throw_exception_nontype (loc, ctx, fun, non_constant_p,
     jump_target);

finish_trait_expr should never return error_mark_node.  We can ensure
that it's so by adding an assert.

gcc/cp/ChangeLog:

* reflect.cc (eval_type_trait): Assert that finish_trait_expr didn't
return error_mark_node.

Reviewed-by: Jason Merrill <jason@redhat.com>
11 hours agoc++/reflection: enhance splice error checking
Marek Polacek [Wed, 28 Jan 2026 22:30:06 +0000 (17:30 -0500)] 
c++/reflection: enhance splice error checking

As discussed in
<https://gcc.gnu.org/pipermail/gcc-patches/2026-January/705756.html>:

> Absolutely, I mean anything other than REFLECT_EXPR or error_mark_node
> should be an error.

I'm not giving another error for error_mark_node since we've already
complained (but make sure we have).

gcc/cp/ChangeLog:

* reflect.cc (class_members_of): Adjust comment.
(splice): Give an error if the expression doesn't evaluate to
a REFLECT_EXPR_P.

Reviewed-by: Jason Merrill <jason@redhat.com>
11 hours agoFix AIX build break in gcc/diagnostics/sarif-sink.cc.
Sangamesh Mallayya [Thu, 29 Jan 2026 13:04:40 +0000 (07:04 -0600)] 
Fix AIX build break in gcc/diagnostics/sarif-sink.cc.

In AIX, build fails while trying to compile gcc/diagnostics/sarif-sink.cc.
Here is the snapshot of the error we are getting.

In file included from /opt/freeware/src/packages/BUILD/gcc/gcc/system.h:46,
                 from /opt/freeware/src/packages/BUILD/gcc/gcc/diagnostics/sarif-sink.cc:34:
/opt/freeware/lib/gcc/powerpc-ibm-aix7.3.0.0/13/include-fixed/stdio.h:593:12: error: conflicting declaration of C function 'int fgetpos64(FILE*, fpos64_t*)'
  593 | extern int fgetpos64(FILE *, fpos64_t *);
      |            ^~~~~~~~~

This happens when we include sys/types.h before defining _LARGE_FILES.
We can see similar errors with this sample program.

#include <sys/types.h>
#define _LARGE_FILES 1
#include <stdio.h>
int main()
{
   return 0;
}

In gcc/diagnostics/sarif-sink.cc we are including config.h after #include <sys/un.h> which intern
 including sys/types.h and causing the conflicting errors.
Including config.h before including sys/un.h should solve this error.

The patch is to fix the build break on AIX.

gcc/ChangeLog:
* diagnostics/sarif-sink.cc: Move config.h at the begining.

12 hours agod: Fix buffer overflow detected with -defaultlib= and -debuglib= [PR123349]
Iain Buclaw [Thu, 29 Jan 2026 09:11:43 +0000 (10:11 +0100)] 
d: Fix buffer overflow detected with -defaultlib= and -debuglib= [PR123349]

PR d/123349

gcc/d/ChangeLog:

* d-spec.cc (lang_specific_driver): Use xstrdup to copy -defaultlib
and -debuglib argument, and unconditionally free the old value.

gcc/testsuite/ChangeLog:

* gdc.dg/driver_debuglib.d: New test.
* gdc.dg/driver_defaultlib.d: New test.

12 hours agolibstdc++: Fix non-ASCII characters in <contracts> header
Jonathan Wakely [Thu, 29 Jan 2026 12:12:45 +0000 (12:12 +0000)] 
libstdc++: Fix non-ASCII characters in <contracts> header

This fixes:
FAIL: 17_intro/headers/c++1998/charset.cc  -std=gnu++26 (test for excess errors)

libstdc++-v3/ChangeLog:

* include/std/contracts: Replace non-ASCII characters.

13 hours agotree-optimization/123596 - fix partial virtual SSA update in eh_cleanup
Richard Biener [Thu, 29 Jan 2026 09:41:16 +0000 (10:41 +0100)] 
tree-optimization/123596 - fix partial virtual SSA update in eh_cleanup

The following replaces the not quite correct use of
mark_virtual_operand_for_renaming by an appropriate way of dealing
with a possibly partially up-to-date virtual SSA form.  Namely
when we just move stmts and not remove a VDEF we should arrange
for missing virtual PHIs to be created and just queue its arguments
for possible renaming.  For the testcase at hand there's no renaming
necessary in the end when done this way.

PR tree-optimization/123596
* tree-eh.cc (sink_clobbers): Create a virtual PHI when
one is required but not present, queuing arguments
for renaming.

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

13 hours agotree-optimization/116747 - ICE in cselim due to duplicate sinking
Richard Biener [Thu, 29 Jan 2026 07:47:44 +0000 (08:47 +0100)] 
tree-optimization/116747 - ICE in cselim due to duplicate sinking

The following avoids queueing duplicate stmts in the set of sinkings
to consider as well as pick candidates in an order that ensures
we don't unnecessarily re-order stores.  While we currently only can
trigger the ICE with out-of-bound accesses future enhancements
to how we deal with dependence analysis in this pass could expose
the issue to a wider range of testcases, so this makes it future-proof.

PR tree-optimization/116747
* tree-ssa-phiopt.cc (cond_if_else_store_replacement): Avoid
duplicate stmts in the set of store pairs to process.

* gcc.dg/tree-ssa/cselim-4.c: New testcase.

13 hours agoc++: Fix ICE in eval_annotations_of [PR123866]
Jakub Jelinek [Thu, 29 Jan 2026 11:34:59 +0000 (12:34 +0100)] 
c++: Fix ICE in eval_annotations_of [PR123866]

eval_annotations_of throws if the passed in reflection handle is not
eval_is_function (and various others).  Now, eval_is_function uses
maybe_get_first_fn to look through BASELINK/OVERLOAD etc., but
eval_annotations_of wasn't doing that and ICEd on
  else if (TYPE_P (r))
    r = TYPE_ATTRIBUTES (r);
  else if (DECL_P (r))
    r = DECL_ATTRIBUTES (r);
  else
    gcc_unreachable ();
because r isn't a decl nor type (nor REFLECT_BASE earlier).

2026-01-29  Jakub Jelinek  <jakub@redhat.com>

PR c++/123866
* reflect.cc (eval_annotations_of): Use maybe_get_first_fn.

* g++.dg/reflect/annotations10.C: New test.

14 hours agoa68: implement GNU68-2026-001-short-of-symbol
Jose E. Marchesi [Thu, 29 Jan 2026 02:33:17 +0000 (03:33 +0100)] 
a68: implement GNU68-2026-001-short-of-symbol

This patch implements the GNU extension:

  GNU68-2026-001-brief-selection - Brief style for selection

which adds the preferred brief style for selection recommended by
Hansen in "ALGOL 68 Hardware Represenatation Recommendations"
published in the Algol Bulletin issue 42.

This extension is already listed in https://algol68-lang.org.

Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>
gcc/algol68/ChangeLog

* ga68.vw: Update formal grammar to express the GNU extension.
* a68-parser.cc (a68_dont_mark_here): Likewise.
* a68-parser-scanner.cc (SINGLE_QUOTE_CHAR): Define.
(get_next_token): Recognize ' as QUOTE_SYMBOL.
(tokenise_source): Acknowledge QUOTE_SYMBOL.
* a68-parser-keywords.cc (a68_set_up_tables): Likewise.
* a68-parser-bottom-up.cc (reduce_primary_parts): Adjust parser to
brief form of selection.
* a68-parser-attrs.def (QUOTE_SYMBOL): New attribute.
* ga68.texi (Brief selection): New section.

gcc/testsuite/ChangeLog

* algol68/compile/error-selector-1.a68: New test.
* algol68/execute/selection-2.a68: Update test.
* algol68/execute/selection-5.a68: Likewise.

16 hours agoc++: Implement CWG3131 - Value categories and types for the range in iterable expansi...
Jakub Jelinek [Thu, 29 Jan 2026 08:49:51 +0000 (09:49 +0100)] 
c++: Implement CWG3131 - Value categories and types for the range in iterable expansion statements

For the https://gcc.gnu.org/pipermail/gcc/2025-November/246977.html
issues I've filed https://github.com/cplusplus/CWG/issues/805
which resulted in two CWG issues,
https://cplusplus.github.io/CWG/issues/3131.html
and
https://cplusplus.github.io/CWG/issues/3140.html
This patch implements the former, changing
the iterating expansion statement http://eel.is/c++draft/stmt.expand#5.2
line from
constexpr auto&& range = expansion-initializer;
to
constexpr decltype(auto) range = (expansion-initializer);
(for our partly pre-CWG3044 implementation with static before it).

2026-01-29  Jakub Jelinek  <jakub@redhat.com>

* cp-tree.h (build_range_temp): Implement CWG3131 - Value
categories and types for the range in iterable expansion statements.
Add bool argument defaulted to false.
* parser.cc (build_range_temp): Add expansion_stmt_p argument,
if true build const decltype(auto) __for_range = range_expr instead of
auto &&__for_range = range_expr.
(cp_build_range_for_decls): For expansion stmts build __for_range as
static constexpr decltype(auto) __for_range = (range_expr);
rather than static constexpr auto &&__for_range = range_expr;.

* g++.dg/cpp26/expansion-stmt1.C (N::begin, N::end, O::begin,
O::end): Change argument type from B & to const B & or from
D & to const D &.
* g++.dg/cpp26/expansion-stmt2.C (N::begin, N::end, O::begin,
O::end): Likewise.
* g++.dg/cpp26/expansion-stmt3.C (N::begin, N::end, O::begin,
O::end): Likewise.
* g++.dg/cpp26/expansion-stmt16.C: Expect different diagnostics
for C++11.
* g++.dg/cpp26/expansion-stmt18.C (N::begin, N::end): Change
argument type from B & to const B &.
* g++.dg/cpp26/expansion-stmt25.C (N::begin, N::end): Likewise.
* g++.dg/cpp26/expansion-stmt26.C: New test.
* g++.dg/reflect/p3491-2.C (baz): Move workaround to a new
function garply, use the previously #if 0 guarded implementation.
(garply): New function.

23 hours agolibffi: Remove more unneeded files when merging
Pietro Monteiro [Thu, 29 Jan 2026 01:16:04 +0000 (20:16 -0500)] 
libffi: Remove more unneeded files when merging

Delete .allow-ai-service and .gail-labels which are present in newer
versions of libffi.

libffi/ChangeLog:
PR libffi/117635
* merge.sh: Delete .allow-ai-service and .gail-labels when
merging new upstream versions.

Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
23 hours agolibffi: Add missing GCC patches to LOCAL_PATCHES
Pietro Monteiro [Thu, 29 Jan 2026 01:16:04 +0000 (20:16 -0500)] 
libffi: Add missing GCC patches to LOCAL_PATCHES

Add all the patches to GCC's copy of libffi to LOCAL_PATCHES.  I
skipped patches that only regenerate the configure script because it
doesn't come from upstream.

libffi/ChangeLog:
PR libffi/117635
* LOCAL_PATCHES: Add missing patches.

Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
24 hours agoa68: support FFI with C via formal holes
Jose E. Marchesi [Sat, 24 Jan 2026 19:10:10 +0000 (20:10 +0100)] 
a68: support FFI with C via formal holes

This commit adds FFI support to access C variables and call C
functions from Algol 68, using the construct specified by the Modules
and Separated compilation facilities intended to that effect: formal
holes (`nest' constructs).

Briefly put, an `int foo' C variable can be accessed from Algol 68
like:

  int foo = nest C "foo";
  if foo > 10 then ... fi;

A ref to a C variable `int counter', that allows to modify it as well
as read it:

  ref int counter = nest C "&counter";
  counter +:= 1;

The address stored in an `int *ptr' variable, as an Algol 68
reference:

  ref int ptr = nest C "ptr";
  ptr := 100; { Changes the integer pointed by the C ptr }

Calling the standard C `random' function:

  proc long int random = nest C "random";
  if random < 100 then ... fi;

Some tests and an sketchy section in the manual are also included.

Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>
gcc/algol68/ChangeLog

* ga68.vw: Fix grammar for formal holes.
* ga68.texi (Particular programs): New section.
(Comments): Likewise.
* a68.h: Prototypes for a68_is_c_mode, a68_make_fomal_hole_decl,
a68_lower_formal_hole.
* a68-parser-attrs.def (FORMAL_HOLE): New attribute.
(LANGUAGE_INDICANT): Likewise.
* a68-parser-extract.cc (a68_elaborate_bold_tags): Elaborate
language indicants.
* a68-parser-moids-check.cc (mode_check_unit): Check mode in
formal holes.
* a68-low-units.cc (a68_lower_formal_hole): New function.
* a68-low.cc (a68_make_formal_hole_decl): Likewise.
* a68-moids-misc.cc (a68_is_c_mode): Likewise.
* a68-parser-bottom-up.cc (reduce_formal_holes): Likewise.

gcc/testsuite/ChangeLog

* algol68/compile/error-nest-1.a68: New test.
* algol68/compile/nest-c-1.a68: Likewise.
* algol68/compile/error-nest-5.a68: Likewise.
* algol68/compile/error-nest-4.a68: Likewise.
* algol68/compile/error-nest-3.a68: Likewise.
* algol68/compile/error-nest-2.a68: Likewise.

24 hours agoDaily bump.
GCC Administrator [Thu, 29 Jan 2026 00:16:45 +0000 (00:16 +0000)] 
Daily bump.

26 hours agoAda: Fix crash on Unchecked_Union parameter with -gnateV -gnata
Eric Botcazou [Wed, 28 Jan 2026 22:52:41 +0000 (23:52 +0100)] 
Ada: Fix crash on Unchecked_Union parameter with -gnateV -gnata

The problem is that the compiler generates 'Valid_Scalars for a formal
parameter of an Unchecked_Union type, which cannot work because it is not
possible to find out where the scalars are in it, given that the parameter
does not contain the discriminants of its Unchecked_Union type.  This also
changes -gnateV to work without the need for -gnata, as there is no mention
of this dependence in the documentation.

gcc/ada/
PR ada/123857
* checks.adb (Apply_Parameter_Validity_Checks.Add_Validity_Check):
Set Is_Checked on the generated {Pre,Post}_Condition pragma and
bail out if the parameter is of an Unchecked_Union type.

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

26 hours agoAda: Fix stack corruption with concatenation and 'Image of composite type
Eric Botcazou [Wed, 28 Jan 2026 22:31:49 +0000 (23:31 +0100)] 
Ada: Fix stack corruption with concatenation and 'Image of composite type

The issue is that the expansion of 'Image for composite types is heavyweight
and involves a mix of Expression_With_Actions and controlled object that
does not work properly when it is the argument of a call to a subprogram,
so this replaces it by the canonical scheme used for controlled temporaries.

gcc/ada/
PR ada/123832
* exp_imgv.adb: Add with and use clauses for Exp_Ch7.
(Expand_Image_Attribute): Establish a transient scope before
rewriting the attribute as a call to Put_Image.
(Expand_Wide_Image_Attribute): Likewise.
(Expand_Wide_Wide_Image_Attribute): Likewise.
* exp_put_image.ads (Build_Image_Call): Add note about the
need for a transient scope when the function is invoked.
* exp_put_image.adb (Build_Image_Call): Call Insert_Actions
to immediately insert the actions instead of wrapping them
in an Expression_With_Actions node.

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

26 hours agod: Fix ICE in ExprVisitor::visit, at d/expr.cc:2224 [PR123419]
Iain Buclaw [Wed, 28 Jan 2026 22:06:23 +0000 (23:06 +0100)] 
d: Fix ICE in ExprVisitor::visit, at d/expr.cc:2224 [PR123419]

The original assert expected the type of `__traits(initSymbol)' to be
exactly `const(void[])', but because D strips const from arrays to allow
passing slices as mutable ranges to template functions, so it got turned
into `const(void)[]'.

PR d/123419

gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (VarExp *)): Adjust assertion.

gcc/testsuite/ChangeLog:

* gdc.dg/pr123419.d: New test.

27 hours agod: Fix ICE: in output_constructor_regular_field, at varasm.cc:5500 [PR123798]
Iain Buclaw [Wed, 28 Jan 2026 21:09:37 +0000 (22:09 +0100)] 
d: Fix ICE: in output_constructor_regular_field, at varasm.cc:5500 [PR123798]

PR d/123798

gcc/d/ChangeLog:

* types.cc (insert_aggregate_bitfield): Set DECL_NONADDRESSABLE_P and
DECL_PADDING_P on bit-field decls.
(finish_aggregate_type): Pass the aligned bit offset to layout_decl.

gcc/testsuite/ChangeLog:

* gdc.dg/pr123798.d: New test.

28 hours agoi386: Use x >> ~y for x >> 31-y [PR36503]
Uros Bizjak [Wed, 28 Jan 2026 20:57:47 +0000 (21:57 +0100)] 
i386: Use x >> ~y for x >> 31-y [PR36503]

x86 targets mask 32-bit shifts with a 5-bit mask (and 64-bit with 6-bit mask),
so they can use x >> ~y instead of x >> 31-y.

The optimization converts:

movl    $31, %ecx
        subl    %esi, %ecx
        sall    %cl, %eax

to:
        notl    %ecx
        sall    %cl, %eax

PR target/36503

gcc/ChangeLog:

* config/i386/i386.md (*<insn:any_shift><mode:SWI48>3_sub):
Also allow operands[3] & (<mode_bitsize>-1) == (<mode_bitsize>-1)
in insn condition. Emit NOT RTX instead of NEG RTX in this case.
(*<insn:any_shift><mode:SWI48>3_sub_1): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr36503-5.c: New test.
* gcc.target/i386/pr36503-6.c: New test.

30 hours agoRISC-V: Fix ABI vector passing on stack and GPR [PR123824].
Robin Dapp [Mon, 26 Jan 2026 16:59:58 +0000 (17:59 +0100)] 
RISC-V: Fix ABI vector passing on stack and GPR [PR123824].

Krister reported that we violate the psABI when one vector argument
halfway fits into a register:

"Aggregates whose total size is no more than 2×XLEN bits are passed in a
pair of registers; if only one register is available, the first XLEN
bits are passed in a register and the remaining bits are passed on the
stack. If no registers are available, the aggregate is passed on the
stack."

This patch fixes this oversight and adds a few tests.

Regtested on rv64gcv_zvl512b.

PR target/123824

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_vls_mode_fits_in_gprs_p): New
helper.
(riscv_pass_vls_aggregate_in_gpr): Use helper and distribute
half-fitting vector to GPR and stack.
(riscv_pass_aggregate_in_vr): Reformat comment.
(riscv_get_arg_info): Use helper.
(riscv_pass_by_reference): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/abi/vls-gpr-1.c: New test.
* gcc.target/riscv/abi/vls-gpr-10.c: New test.
* gcc.target/riscv/abi/vls-gpr-11.c: New test.
* gcc.target/riscv/abi/vls-gpr-12.c: New test.
* gcc.target/riscv/abi/vls-gpr-13.c: New test.
* gcc.target/riscv/abi/vls-gpr-14.c: New test.
* gcc.target/riscv/abi/vls-gpr-2.c: New test.
* gcc.target/riscv/abi/vls-gpr-3.c: New test.
* gcc.target/riscv/abi/vls-gpr-4.c: New test.
* gcc.target/riscv/abi/vls-gpr-5.c: New test.
* gcc.target/riscv/abi/vls-gpr-6.c: New test.
* gcc.target/riscv/abi/vls-gpr-7.c: New test.
* gcc.target/riscv/abi/vls-gpr-8.c: New test.
* gcc.target/riscv/abi/vls-gpr-9.c: New test.

30 hours agoC/C++: Better notification if misused a function like macro [PR102846]
Andrew Pinski [Wed, 15 Oct 2025 00:50:13 +0000 (17:50 -0700)] 
C/C++: Better notification if misused a function like macro [PR102846]

Currently if assert is misused, e.g. like passing to a function like a
function pointer, GCC suggests to include assert.h/cassert. But since
it is already included that is just a bogus suggestion. Instead we should
see if a function-like macro is that same name (in the case of assert it will be),
and inform the user that it is being mis-used.

PR c++/102846
PR c/102846

gcc/c-family/ChangeLog:

* known-headers.cc (macro_like_function_used::macro_like_function_used): New.
(macro_like_function_used::~macro_like_function_used): New.
* known-headers.h (class macro_like_function_used): New class.

gcc/c/ChangeLog:

* c-decl.cc (lookup_name_fuzzy): Lookup function-like macro and
notify of misuse there.

gcc/cp/ChangeLog:

* name-lookup.cc (lookup_name_fuzzy): Lookup function-like macro and
notify of misuse there.

gcc/testsuite/ChangeLog:

* c-c++-common/function-like-macro-1.c: New test.
* c-c++-common/function-like-macro-2.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
31 hours agod: Fix ICE: in expand_asm_stmt, at cfgexpand.cc:3445 [PR121477]
Iain Buclaw [Wed, 28 Jan 2026 17:34:21 +0000 (18:34 +0100)] 
d: Fix ICE: in expand_asm_stmt, at cfgexpand.cc:3445 [PR121477]

The d_mark_addressable routine that sets TREE_ADDRESSABLE in the D
front-end did not handle DECL_BIT_FIELD.

PR d/121477

gcc/d/ChangeLog:

* d-codegen.cc (d_mark_addressable): Give an error if taking the
address of a DECL_BIT_FIELD.

gcc/testsuite/ChangeLog:

* gdc.dg/pr121477.d: New test.

33 hours ago[PR121571, LRA]: Reprocess asm insn with different preferences when there are no...
Vladimir N. Makarov [Wed, 28 Jan 2026 15:52:21 +0000 (10:52 -0500)] 
[PR121571, LRA]: Reprocess asm insn with different preferences when there are no enough regs for the asm-insn

The test for the PR contains asm insn requiring 7 general regs but
three operands can be in memory too ('g' constraint).  There are only
6 available general regs.  IRA in the test case assigns a mask reg to
one pseudo.  When LRA reloads the pseudo assigned to mask reg, it
frees general reg assigned to another pseudo in the asm and assigns
mask reg to another pseudo.  After a few iterations, we have asm all
operands of which are reload pseudos assigned to general regs and one
pseudo assigned to mask reg.  After that LRA can do nothing and
reports "not enough regs".  The patch recognizes situation when there
are not enough regs for an asm insn and makes 2nd attempt to find
reloads when memory for operands with 'g' or 'rm' constraint is
preferred.

gcc/ChangeLog:

PR target/121571
* lra-constraints.cc (process_alt_operands): Reprocess asm insn
when there are no enough regs for the asm-insn.

gcc/testsuite/ChangeLog:

PR target/121571
* gcc.target/i386/pr121571.c: New.

34 hours agod: RVO/NRVO not done when returning a copy constructor
Iain Buclaw [Wed, 28 Jan 2026 11:45:26 +0000 (12:45 +0100)] 
d: RVO/NRVO not done when returning a copy constructor

RVO was already being done when returning a constructor call via a
temporary, which in the front-end AST looks like:

    return S.this((__tmp = {}, &__tmp), args...);

But this was not being done for copy construction calls, which instead
looks like:

    return __copytmp = {}, S.this(&__copytmp, V(1).s), __copytmp;

This pattern is now matched and the temporary gets set up as a
DECL_VALUE_EXPR of the RESULT_DECL.

PR d/123422

gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (ArrayLiteralExp *)): Don't add
TARGET_EXPR around constructor.
* toir.cc (IRVisitor::visit (ReturnStatement *)): Recognize more
patterns for return value optimization.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr123422.d: New test.

35 hours agoc: Fix parser error on address space names [PR 123583]
Senthil Kumar Selvaraj [Wed, 28 Jan 2026 08:29:55 +0000 (13:59 +0530)] 
c: Fix parser error on address space names [PR 123583]

This patch fixes a regression introduced by PR 67784
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67784) - it broke
recognition of named address space qualifiers (such as __memx on
AVR or __seg_gs on x86) after certain statements.

The fix for PR 67784 attempts to reclassify tokens whose
token->id_kind could have been set incorrectly (because of possibly
wrong scope when peeking ahead). c_parser_maybe_reclassify_token
only skips reclassification for C_ID_CLASSNAME though - a token with
id_kind = C_ID_ADDRSPACE ends up getting reclassified as C_ID_ID,
eventually causing a ": error: '<address space name>' undeclared"
error later down the line.

Rather than explicitly excluding C_ID_ADDRSPACE, the patch modifies
the check to reclassify only tokens kinds that could potentially get
incorrectly classified - C_ID_ID and C_ID_TYPENAME.

Bootstrapped and regtested on x86_64-linux.

PR c/123583

gcc/c/ChangeLog:

* c-parser.cc (c_parser_maybe_reclassify_token): Reclassify only
C_ID_ID and C_ID_TYPENAME tokens.

gcc/testsuite/ChangeLog:

* gcc.target/avr/pr123583.c: New test.
* gcc.target/i386/pr123583.c: New test.

35 hours agomiddle-end/123575 - fix ABS_EXPR folding for vectors
Richard Biener [Wed, 28 Jan 2026 12:39:14 +0000 (13:39 +0100)] 
middle-end/123575 - fix ABS_EXPR folding for vectors

Folding away a conversion requires an optab check for vectors.

PR middle-end/123575
* match.pd (abs ((T)x) -> absu (x)): For vector type
arguments require the resulting operation is supported.

* g++.dg/pr123575.C: New testcase.

36 hours agolibstdc++: Default to C++20 in src/experimental/Makefile.am
Jonathan Wakely [Wed, 28 Jan 2026 10:27:07 +0000 (10:27 +0000)] 
libstdc++: Default to C++20 in src/experimental/Makefile.am

r16-7089-gfbde291af66e02 had a stray change to the Makefile.in but
actually we probably should change that directory to use C++20, now that
it's the default. So this updates the Makefile.am, and the Makefile.in
doesn't need to be regenerated now.

libstdc++-v3/ChangeLog:

* src/experimental/Makefile.am: Change AM_CXXFLAGS to use C++20
by default.

36 hours agolibstdc++: Do not allow contract26.cc to build without -fcontracts
Jonathan Wakely [Wed, 28 Jan 2026 12:17:14 +0000 (12:17 +0000)] 
libstdc++: Do not allow contract26.cc to build without -fcontracts

It seems prefereable to get a hard error if this file is built
incorrectly, rather than failing to define any symbols.

libstdc++-v3/ChangeLog:

* src/experimental/contract26.cc: Use #error if built without
contracts support enabled.
* include/std/source_location: Remove stray whitespace.

37 hours agoipa/111036 - strip nop conversions around __builtin_constant_p arguments
Richard Biener [Wed, 28 Jan 2026 09:55:56 +0000 (10:55 +0100)] 
ipa/111036 - strip nop conversions around __builtin_constant_p arguments

The PR is about inconsistent behavior wrt inline predicate analysis
and later folding of __builtin_constant_p which ultimatively results
from fold_builtin_constant_p stripping nops off its argument but
this not being done on GIMPLE.  The following adds a match.pd pattern
for this.

PR ipa/111036
* match.pd (__builtin_constant_p ((T)x)): Strip nop-conversions
from __builtin_constant_p arguments.

* gcc.dg/torture/pr111036.c: New testcase.

37 hours agortl-optimization/106859 - fix location dumping from var-tracking
Richard Biener [Wed, 28 Jan 2026 09:16:29 +0000 (10:16 +0100)] 
rtl-optimization/106859 - fix location dumping from var-tracking

We currently ICE when the locations include one without a setting insn.
Looking at cselib this seems to be a supported state so the following
arranges for this and dumps -1 as UID.

PR rtl-optimization/106859
* var-tracking.cc (val_store): Dump -1 as UID if setting_insn
is NULL.

37 hours agotree-optimization/123537 - fix too permissive .REDUC_* folding
Richard Biener [Wed, 28 Jan 2026 09:04:45 +0000 (10:04 +0100)] 
tree-optimization/123537 - fix too permissive .REDUC_* folding

The following restricts the allowed conversions to those maintaining
the element type size.

PR tree-optimization/123537
* match.pd (REDUC (@0 & @1) -> @0[I] & @1[I]): Restrict
allowed conversions.

* gcc.dg/pr123537.c: New testcase.

37 hours agoaarch64: FEAT_SVE_BFSCALE support
Karl Meakin [Thu, 6 Nov 2025 16:34:06 +0000 (16:34 +0000)] 
aarch64: FEAT_SVE_BFSCALE support

Add support for the `SVE_BFSCALE` architecture extension.

gcc/ChangeLog:

* doc/invoke.texi: Document `+sve-bfscale` flag.
* config/aarch64/aarch64.h (TARGET_SVE_BFSCALE): New macro.
* config/aarch64/aarch64-c.cc (aarch64_update_cpp_builtins):
Define `__AARCH64_FEATURE_SVE_BFSCALE`.
* config/aarch64/aarch64-sve-builtins-base.cc: Skip constant
folding for floating-point or unpredicated multiplications.
* config/aarch64/aarch64-sve-builtins-sve2.def: New `SVE_FUNCTION`s.
* config/aarch64/aarch64-sve.md: Modify insns for
`SVE_COND_FP_BINARY_INT` to handle BF16 modes.
* config/aarch64/aarch64-sve2.md
(@aarch64_sve_<optab><mode>, @aarch64_sve_<optab><mode>_single): New insn for `BFSCALE`.
Modify insns for `UNSPEC_FSCALE` to handle BF16 modes.
* config/aarch64/iterators.md (SVE_FULL_F_SCALAR): Add `VNx8BF` to iterator.
(SVE_FULL_F_BFSCALE): New iterator.
(SVE_Fx24_BFSCALE): New iterator.
(SVE_BFx24): New iterator.
(UNSPEC_FMUL): New unspec.
(V_INT_EQUIV): Add entries for BF16 modes.
(b): Add entries for scalar float modes.
(is_bf16): Add entries for BF16 modes and reformat.
(SVSCALE_SINGLE_INTARG): Likewise.
(SVSCALE_INTARG): Likewise.
(SVE_FP_MULL): New iterator.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp: Add `sve-bfscale` to `sve_exts`.
* gcc.target/aarch64/pragma_cpp_predefs_4.c: Add test for `__ARM_SVE_FEATURE_BFSCALE`.
* gcc.target/aarch64/sme2/acle-asm/mul_bf16_x2.c: New test.
* gcc.target/aarch64/sme2/acle-asm/mul_bf16_x4.c: New test.
* gcc.target/aarch64/sme2/acle-asm/scale_bf16_x2.c: New test.
* gcc.target/aarch64/sme2/acle-asm/scale_bf16_x4.c: New test.
* gcc.target/aarch64/sve/acle/asm/scale_bf16.c: New test.
* gcc.target/aarch64/sve/acle/general-c/bfscale.c: New test.

37 hours agoexpand: Increase stack slot alignment for STRICT_ALIGNMENT targets [PR123447]
Pengfei Li [Mon, 26 Jan 2026 16:09:42 +0000 (16:09 +0000)] 
expand: Increase stack slot alignment for STRICT_ALIGNMENT targets [PR123447]

PR123447 reports an ICE on AArch64 with "-O2 -mstrict-align" in subreg
lowering while decomposing the following multiword store RTL:

(insn 12 11 13 2 (set (mem/c:XI (plus:DI (reg/f:DI 64 sfp)
                (const_int -96 [0xffffffffffffffa0])) [0  S64 A8])
        (reg:XI 103)) "a.c":14:6 4861 {*aarch64_movxi}

This RTL originates from expanding the following GIMPLE statement:

_1 = BIT_FIELD_REF <{ 9, -64497, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 256, 0>;

The operand is a constant _Decimal64 vector with BLKmode, so expand has
to materialize it in memory. Current get_object_alignment() returns a
1-byte guaranteed alignment for this VECTOR_CST, as indicated by A8 in
the RTL dump above. However, with "-mstrict-align" enabled, later subreg
lowering pass expects at least 64-bit alignment when it constructs a new
RTX to decompose the store into pieces. Because the original alignment
is too small, simplify_gen_subreg() returns NULL_RTX and an assertion is
hit.

This patch increases the stack slot alignment for STRICT_ALIGNMENT
targets, when the operand is forced into memory. The increased alignment
is capped by MAX_SUPPORTED_STACK_ALIGNMENT so it won't be too large.

Bootstrapped and tested on aarch64-linux-gnu and x86_64-linux-gnu.

gcc/ChangeLog:

PR middle-end/123447
* expr.cc (expand_expr_real_1): Increase stack slot alignment
for STRICT_ALIGNMENT targets.

gcc/testsuite/ChangeLog:

PR middle-end/123447
* gcc.dg/pr123447.c: New test.

37 hours agooptions: Fix a missing period on and option message.
Iain Sandoe [Wed, 28 Jan 2026 11:13:56 +0000 (11:13 +0000)] 
options: Fix a missing period on and option message.

As per subject.

gcc/c-family/ChangeLog:

* c.opt: Append a period to the message for
-fcontracts-client-check=.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
37 hours agovect: reconstruct vectype for non scalar masks
Andre Vieira [Wed, 28 Jan 2026 11:11:14 +0000 (11:11 +0000)] 
vect: reconstruct vectype for non scalar masks

This reconstructs the masks vectype based on the the type set by the backend
for any non scalar masks, which resolves the ICE caused by the sve type
attribute in SVE types used for simdclones.

gcc/ChangeLog:

PR target/123016
* tree-vect-stmts.cc (vectorizable_simd_clone_call): use
'build_truth_vector_type_for_mode' to reconstruct mask's vectype for
non-scalar masks.

gcc/testsuite/ChangeLog:

* gfortran.dg/vect/pr123016.f90: New test.

38 hours agolibstdc++: Disable false positive middle end warnings in std::shared_ptr [PR122197]
Jonathan Wakely [Fri, 23 Jan 2026 14:25:03 +0000 (14:25 +0000)] 
libstdc++: Disable false positive middle end warnings in std::shared_ptr [PR122197]

Speculative devirtualization in GCC 16 causes some false positive
warnings for unreachable paths. Use diagnostic pragmas to suppress
those warnings until the regression is fixed.

libstdc++-v3/ChangeLog:

PR tree-optimization/122197
* include/bits/shared_ptr_base.h (~_Sp_counted_deleter): Use
diagnostic pragam to disable -Wfree-nonheap-object false
positive.
(~_Sp_counted_ptr_inplace): Likewise for -Warray-bounds false
positive.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
38 hours agolibstdc++: Avoid -Wtype-limits warnings in locale/gnu/ctype_members.cc
Jonathan Wakely [Fri, 23 Jan 2026 14:04:26 +0000 (14:04 +0000)] 
libstdc++: Avoid -Wtype-limits warnings in locale/gnu/ctype_members.cc

On targets where wchar_t is unsigned we get warnings during the
libstdc++ build:

ctype_members.cc: In member function â€˜virtual char std::ctype<wchar_t>::do_narrow(wchar_t, char) const’:
ctype_members.cc:224:14: warning: comparison of unsigned expression in â€˜>= 0’ is always true [-Wtype-limits]
  224 |     if (__wc >= 0 && __wc < 128 && _M_narrow_ok)
      |         ~~~~~^~~~
ctype_members.cc: In member function â€˜virtual const wchar_t* std::ctype<wchar_t>::do_narrow(const wchar_t*, const wchar_t*, char, char*) const’:
ctype_members.cc:247:21: warning: comparison of unsigned expression in â€˜>= 0’ is always true [-Wtype-limits]
  247 |           if (*__lo >= 0 && *__lo < 128)
      |               ~~~~~~^~~~

This introduces a helper function that converts the wchar_t to an
unsigned type and then does the comparison. This means the comparison is
not target-dependent, and there's no more warning.

libstdc++-v3/ChangeLog:

* config/locale/gnu/ctype_members.cc (use_table): New function.
(ctype<wchar_t>::do_narrow): Use use_table.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
39 hours agoc++: Implement C++23 P2246R1 - Character encoding of diagnostic text
Jakub Jelinek [Wed, 28 Jan 2026 09:23:20 +0000 (10:23 +0100)] 
c++: Implement C++23 P2246R1 - Character encoding of diagnostic text

The following patch attempts to implement the C++23 P2246R1
Character encoding of diagnostic text paper.
Initially I thought there is nothing to do, but this patch shows
that there is (and I wonder if we shouldn't backport it to release
branches).  Though the patch is on top of the cpp_translate_string
libcpp addition from the reflection patchset (though, that is
quite small change that could be backported too).

We have various different encodings in play in GCC.
There is -finput-charset= defaulting to SOURCE_CHARSET, which is
almost always UTF-8 (but in theory could be UTF-EBCDIC if that really
works).  libcpp converts source from the input charset to SOURCE_CHARSET
initially.  And then we have -fexec-charset=, again defaulting to
SOURCE_CHARSET, -fwide-exec-charset=, then UTF-8, UTF-16 and UTF-32
for u8, u and U string literals and constants and finally user uses
some character set in the terminal in which gcc is running.

Now, I think we mostly just emit diagnostics in SOURCE_CHARSET,
there is identifier_to_locale function which uses UCNs if LC_CTYPE
CODESET is not UTF-8-ish, but I think we don't use it all the time.
Even then, there is really no support for outputing from SOURCE_CHARSET
UTF-8 to non-ASCII compatible terminal charsets.
So for now let's pretend that we are emitting diagnostics to UTF-8
capable terminal.

When reporting errors about identifiers in the source (which are in
SOURCE_CHARSET), we just emit those.  The paper talks about
deprecated & nodiscard attribute msgs, static_assert, #error (and for
C++26 it would talk about #warning, delete (reason) and static_assert
with constexpr user messages).  #error/#warning works fine on UTF-8
terminals, delete (reason) too (we don't translate the string literal
from SOURCE_CHARSET to exec-charset in that case), static_assert
with a string literal too (again, notranslate), __attribute__ form
of deprecated attribute too (again, !parser->translate_strings_p).
What doesn't work properly are C++11 attributes (standard or gnu::),
we do translate those to exec charset, except for C++26
standard deprecated/nodiscard (which aren't translated).  And static_assert
with user messages doesn't work, those really have to be in exec-charset
because we have no control on how user constructs the messages during
constexpr evaluation.

So, this patch for C++11 attributes if they have the first argument
of a CPP_STRING temporarily disables translation of that string, which
fixes [[gnu::deprecated ("foo")]], [[gnu::unavailable ("foo")]]
and for C++ < 26 also [[deprecated ("foo")]] and [[nodiscard ("foo")]].
And another change is convert back from exec-charset to SOURCE_CHARSET
the custom user static_assert messages (and also inline asm strings).
For diagnostics without this patch worst case we show garbage, but
for inline asm we actually then fail to assemble stuff when users
use the constexpr created string views with non-ASCII exec charsets.

2026-01-28  Jakub Jelinek  <jakub@redhat.com>

PR c++/102613
* parser.cc: Implement C++23 P2246R1 - Character encoding of
diagnostic text.
(cp_parser_parenthesized_expression_list): For std attribute
argument where the first argument is CPP_STRING, ensure the
string is not translated.
* semantics.cc: Include c-family/c-pragma.h.
(cexpr_str::extract): Use cpp_translate_string to translate
string from ordinary literal encoding to SOURCE_CHARSET.

* g++.dg/cpp1z/constexpr-asm-6.C: New test.
* g++.dg/cpp23/charset2.C: New test.
* g++.dg/cpp23/charset3.C: New test.
* g++.dg/cpp23/charset4.C: New test.
* g++.dg/cpp23/charset5.C: New test.

39 hours agoc++: Implement part of CWG3044
Jakub Jelinek [Wed, 28 Jan 2026 09:08:14 +0000 (10:08 +0100)] 
c++: Implement part of CWG3044

The following patch implements part of CWG3044 resolution.
Small part of it has been implemented already earlier (using ptrdiff_t
as the type of i rather than leaving that unspecified), part of it
can't be implemented until constexpr references are supported
(removal of static keywords), but the final CWG3044 resolution
wording states that it is begin + decltype(begin - begin){i}
rather than just begin + i.

The following patch implements that.

It broke a bunch of tests because I haven't implemented operator -
for those. fixed that too (plus added a testcase expected to fail
now with operator - not implemented).

2026-01-28  Jakub Jelinek  <jakub@redhat.com>

* pt.cc (finish_expansion_stmt): Implement part of CWG3044.
Add to begin decltype(begin - begin){i} with std::ptrdiff_t
i instead of just i.

* g++.dg/cpp26/expansion-stmt1.C (A::operator -, C::operator -): New.
* g++.dg/cpp26/expansion-stmt2.C (A::operator -, C::operator -): New.
* g++.dg/cpp26/expansion-stmt3.C (A::operator -, C::operator -): New.
* g++.dg/cpp26/expansion-stmt18.C  (A::operator -): New.
* g++.dg/cpp26/expansion-stmt25.C: New test.

40 hours agoc, c++: Use c*_build_qualified_type instead of build_qualified_type from within build...
Jakub Jelinek [Wed, 28 Jan 2026 08:50:26 +0000 (09:50 +0100)] 
c, c++: Use c*_build_qualified_type instead of build_qualified_type from within build_type_attribute_qual_variant [PR101312]

The following testcases ICE in various ways because of the interaction
between attributes and C/C++ c*_build_qualified_type behavior on array
types and how they affect TYPE_CANONICAL.
For array types, C/C++ moves qualifiers to the element type, but
when a cv qualified array build that way has an attribute applied to it,
we call build_type_attribute_qual_variant and that doesn't have that
handling and builds non-qualified version of the array type with qualified
element type and puts it as TYPE_CANONICAL of the type with attribute
which is a distinct type copy.

The following patch adds a langhook, so that even
build_type_attribute_qual_variant uses for C/C++ for array types
c*_build_qualified_type.
There has been already a related langhook
lang_hooks.types.copy_lang_qualifiers used solely for C++, so instead
of adding another langhook this adds a combined langhook for those two,
where C can handle array types specially and otherwise build_qualified_type,
while C++ ditto + do the function/method type modifiers propagation as
well.

Unfortunately there is a terrible array_as_string hack used by some
of the middle-end warnings which creates some array type with sometimes
an artificial attribute and then has hacks in the c-family type printing
to tweak the printed form, and this hack relies on the previous behavior
of build_type_attribute_qual_variant where it even for C/C++ kept
element type quals unmodified and added normally invalid quals on the
array type itself.  The patch stops using build_type_attribute_qual_variant
for that and instead uses copy_node on the type and adjusts the quals and
adds the attribute to the copy and then ggc_frees it.  Also it renames the
attribute from "array" to "array " to make it clear it is internal
attribute users can't specify even in vendor attributes.

2026-01-28  Jakub Jelinek  <jakub@redhat.com>

PR c/101312
gcc/
* langhooks.h (struct lang_hooks_for_types): Remove
copy_lang_qualifiers.  Add build_lang_qualified_type.
* langhooks.cc (lhd_build_lang_qualified_type): New function.
* langhooks-def.h (lhd_build_lang_qualified_type): Declare.
(LANG_HOOKS_COPY_LANG_QUALIFIERS): Remove.
(LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE): Add.
(LANG_HOOKS_FOR_TYPES_INITIALIZER): Use
LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE instead of
LANG_HOOKS_COPY_LANG_QUALIFIERS.
* attribs.cc (build_type_attribute_qual_variant): Use
lang_hooks.types.build_lang_qualified_type instead of
build_qualified_type and/or build_qualified_type with
optional lang_hooks.types.copy_lang_qualifiers call.
(attr_access::array_as_string): Use "array " attribute instead of
"array".  If attribute has been created or intended quals differ
from quals of build_array_type, use copy_node and adjust quals and
attributes on the copy, print and then ggc_free.
gcc/c-family/
* c-pretty-print.cc (c_pretty_printer::direct_abstract_declarator):
Look up "array " attribute instead of "array".
gcc/c/
* c-tree.h (c_build_lang_qualified_type): Declare.
* c-objc-common.h (LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE): Define.
* c-objc-common.cc (c_build_lang_qualified_type): New function.
gcc/cp/
* cp-tree.h (cxx_build_lang_qualified_type): Declare.
* cp-objcp-common.h (LANG_HOOKS_COPY_LANG_QUALIFIERS): Remove.
(LANG_HOOKS_BUILD_LANG_QUALIFIED_TYPE): Define.
* tree.cc (cxx_build_lang_qualified_type): New function.
gcc/testsuite/
* c-c++-common/pr101312-1.c: New test.
* c-c++-common/pr101312-2.c: New test.

40 hours agofree-lang-data: Remove C++ annotations [PR123837]
Jakub Jelinek [Wed, 28 Jan 2026 08:48:10 +0000 (09:48 +0100)] 
free-lang-data: Remove C++ annotations [PR123837]

As mentioned in the PR and reproduced on the testcase, we ICE during
LTO streaming because C++ annotation arguments can contain trees LTO
streaming doesn't handle.
We don't really need annotations when the FE is done with the whole
TU, annotations are always TU local and not exposed to the rest and
used in consteval only stuff, so the following patch just removes
all annotations at free-lang-data time.

2026-01-28  Jakub Jelinek  <jakub@redhat.com>

PR c++/123837
* ipa-free-lang-data.cc (find_decls_types_r): Remove C++ annotations
from {DECL,TYPE}_ATRIBUTES.

* g++.dg/reflect/annotations9.C: New test.

40 hours agowaccess: Fix handling of extended builtin types [PR123849]
Andrew Pinski [Wed, 28 Jan 2026 00:55:45 +0000 (16:55 -0800)] 
waccess: Fix handling of extended builtin types [PR123849]

So DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE is not being handled
from the demangler in new_delete_mismatch_p. This adds the handling,
just like DEMANGLE_COMPONENT_BUILTIN_TYPE as there is no simple way
to compare the type you have to call into the demanager to do it
instead.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/123849

gcc/ChangeLog:

* gimple-ssa-warn-access.cc (new_delete_mismatch_p): Handle
DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE like DEMANGLE_COMPONENT_BUILTIN_TYPE.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wmismatched-new-delete-11.C: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
40 hours agotree-optimization/110043 - avoid overflow in pointer-query
Richard Biener [Tue, 27 Jan 2026 14:43:53 +0000 (15:43 +0100)] 
tree-optimization/110043 - avoid overflow in pointer-query

pointer-query is built around using offset_int to avoid needing
to deal with overflow.  This falls apart when trying to analyze
array accesses indexed by __int128.  So don't.

PR tree-optimization/110043
* pointer-query.cc (get_offset_range): Fail for integer
types with precision larger than ptrdiff_type_node.

* gcc.dg/torture/pr110043.c: New testcase.

43 hours agoi386: Drop mask subst for define_insn_and_split of extend [PR123779]
Hongyu Wang [Tue, 27 Jan 2026 07:38:12 +0000 (15:38 +0800)] 
i386: Drop mask subst for define_insn_and_split of extend [PR123779]

For define_insn_and_split, the subst applied only for the define_insn
part, not the define_split part. So several define_insn_and_split with
mask_name is actually producing non-splitable insns, resulting ICE in
lra. Separate them to define_insn_and_split for mask/nonmask variants
to generate corresponding splitters.

PR target/123779

gcc/ChangeLog:

* config/i386/sse.md (*sse4_1_<code>v8qiv8hi2<mask_name>_2):
Rename to ...
(*sse4_1_<code>v8qiv8hi2_2): ... this, and drop mask conditions.
(*avx2_<code>v8qiv8si2<mask_name>_2): Rename to ...
(*avx2_<code>v8qiv8si2_2): ... this, and likewise.
(*sse4_1_<code>v4qiv4si2<mask_name>_2): Rename to ...
(*sse4_1_<code>v4qiv4si2_2): ... this, and likewise.
(*sse4_1_<code>v4hiv4si2<mask_name>_2): Rename to ...
(*sse4_1_<code>v4hiv4si2_2): ... this, and likewise.
(*avx2_<code>v4qiv4di2<mask_name>_2): Rename to ...
(*avx2_<code>v4qiv4di2_2): ... this, and likewise.
(*avx2_<code>v4hiv4di2<mask_name>_2): Rename to ...
(*avx2_<code>v4hiv4di2_2): ... this, and likewise.
(*sse4_1_<code>v2hiv2di2<mask_name>_2): Rename to ...
(*sse4_1_<code>v2hiv2di2_2): ... this, and likewise.
(*sse4_1_<code>v2siv2di2<mask_name>_2): Rename to ...
(*sse4_1_<code>v2siv2di2_2): ... this, and likewise.
(*avx512f_<code>v8qiv8di2<mask_name>_2): Rename to ...
(*avx512f_<code>v8qiv8di2_2): ... this.
(*avx512vl_<code>v8qiv8hi2_mask_2): New define_insn_and_split.
(*avx512vl_<code>v8qiv8si2_mask_2): Likewise.
(*avx512vl_<code>v4qiv4si2_mask_2): Likewise.
(*avx512vl_<code>v4hiv4si2_mask_2): Likewise.
(*avx512f_<code>v8qiv8di2_mask_2): Likewise.
(*avx512vl_<code>v4qiv4di2_mask_2): Likewise.
(*avx512vl_<code>v4hiv4di2_mask_2): Likewise.
(*avx512vl_<code>v2hiv2di2_mask_2): Likewise.
(*avx512vl_<code>v2siv2di2_mask_2): Likewise.

gcc/testsuite/ChangeLog:

* g++.target/i386/pr123779.C: New test.

43 hours agolibstdc++: Implement std::atomic::fetch_min/max
Soumya AR [Fri, 16 Jan 2026 05:20:50 +0000 (05:20 +0000)] 
libstdc++: Implement std::atomic::fetch_min/max

This patch extends libstdc++ to implement C++26's atomic fetch min/max
operations.

The __atomic_fetch_minmaxable concept checks if __atomic_fetch_min and
__atomic_fetch_max builtins are implemented by the compiler. If not, fall back
to a CAS loop.

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

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

* include/bits/atomic_base.h:
Add fetch_min and fetch_max memberfunctions.
* include/bits/version.def:
Add __cpp_lib_atomic_min_max feature test macro.
* include/bits/version.h (defined): Regenerate.
* include/std/atomic: Extend for fetch_min/max non-member functions.
* src/c++23/std.cc.in: Export atomic_fetch_min, atomic_fetch_max,
atomic_fetch_min_explicit, atomic_fetch_max_explicit.
* testsuite/29_atomics/atomic_integral/nonmembers_fetch_minmax.cc:
New test.
* testsuite/29_atomics/atomic_ref/integral_fetch_minmax.cc: New test.

46 hours agoc++: Error diagnostics for pointer-to-member type [PR38612]
Alex Yesmanchyk [Wed, 28 Jan 2026 02:07:07 +0000 (21:07 -0500)] 
c++: Error diagnostics for pointer-to-member type [PR38612]

Consider the following ptrtomem4.C file.

Now for test1 and test3 it produces the following errors:

ptrtomem4.C: In function 'int test1(int Base::*, X*)':
ptrtomem4.C:8:21: error: pointer to member type 'int Base::*' incompatible with incomplete object type 'X'
ptrtomem4.C: In function 'int test3(int Base::*, Y*)':
ptrtomem4.C:22:21: error: pointer to member type 'int Base::*' incompatible with object type 'Y' because 'Y' is not derived from 'Base'

PR c++/38612

gcc/cp/ChangeLog:

* typeck2.cc (build_m_component_ref): Improve class mismatch
diagnostic.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/ptrtomem4.C: New test.

Signed-off-by: Alex Yesmanchyk <aliaksandr.yesmanchyk@gmail.com>
Co-authored-by: Jason Merrill <jason@redhat.com>
46 hours agoc++/modules: Handle reflection SPLICE_SCOPE tree node
vspefs [Mon, 26 Jan 2026 20:56:52 +0000 (20:56 +0000)] 
c++/modules: Handle reflection SPLICE_SCOPE tree node

This patch adds support for serializing and deserializing SPLICE_SCOPE trees
in C++20 modules implementation. SPLICE_SCOPE is introduced by C++26
reflection, notably used for dependent splice types, thus needing to be
exported/imported as part of the module interface. Not handling SPLICE_SCOPE
leads to ICE.

This patch also includes 2 simple test cases: one for exporting splice scope
types and another for importing them.

gcc/cp/

* module.cc (trees_out::type_node): Add case for SPLICE_SCOPE.
(trees_in::tree_node): Add case for SPLICE_SCOPE.

gcc/testsuite/

* g++.dg/modules/splice-scope-tree_a.C: New test.
* g++.dg/modules/splice-scope-tree_b.C: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
46 hours agoc++: Fix false positive with -Wunused [PR114450]
Lucas Chollet [Mon, 26 Jan 2026 10:16:53 +0000 (18:16 +0800)] 
c++: Fix false positive with -Wunused [PR114450]

The patch fixes a bug in the detection of the usage of static variables
inside generic lambdas.  The comment in finish_id_expression_1 already
mentions this case, but the code didn't actually handle it.

PR c++/114450

gcc/cp/ChangeLog:

* lambda.cc (generic_lambda_fn_p): Handle null argument.
* semantics.cc (finish_id_expression_1): Check for generic lambda.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wunused-var-42.C: New test.

Co-authored-by: Jason Merrill <jason@redhat.com>
46 hours agoc++: -Wunused-value on ternary indexed by non-constant
Johannes Altmanninger [Mon, 26 Jan 2026 10:16:53 +0000 (18:16 +0800)] 
c++: -Wunused-value on ternary indexed by non-constant

On this expression:

(true ? "a" : "b")[index()]

"g++ -Wunused-value" incorrectly produces

warning: left operand of comma operator has no effect [-Wunused-value]

From the -fdump-tree-original output:

if ((void) SAVE_EXPR <index ()>, 1)
  {
    (void) "a"[SAVE_EXPR <index ()>];
  }
else
  {
    (void) "b"[SAVE_EXPR <index ()>];
  }

Observe that we evaluate index() (and save it) before evaluating the
ternary expression.  Since "(void) SAVE_EXPR <index ()>" is ostensibly
side-effect free, we get this warning.  Since SAVE_EXPR is not useless,
this is a false positive. Also the comma operator compiler-generated,
so warning about it is wrong.

Suppress this warning for this implicit expression. Test that the
warning is gone for "$ternary[index()]" but we still warn on cases like
"$ternary[(1, 0)]".

gcc/cp/ChangeLog:

* typeck.cc (cp_build_array_ref): Suppress unused-value
warning for implicit comma expression.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wunused-value-2.C: New test.

Signed-off-by: Johannes Altmanninger <aclopte@gmail.com>
Co-authored-by: Jason Merrill <jason@redhat.com>
47 hours agoc++, contracts: Add caller-side contract checks, and controls.
Nina Ranns [Thu, 28 Aug 2025 16:56:56 +0000 (17:56 +0100)] 
c++, contracts: Add caller-side contract checks, and controls.

This a (currently GCC-only) extension that implements caller-side
checking of pre and post conditions.  It is completely in scope
with the C++26 CDIS wording, but is not mandated.

The implementation here allows applying caller or callee-side
checking independently.

gcc/c-family/ChangeLog:

* c.opt (fcontracts-definition-check=,
fcontracts-client-check=): New.
* c.opt.urls: Regenerate.

gcc/cp/ChangeLog:

* call.cc (build_cxx_call): Where enabled, wrap calls to
functions with contract specifiers.
* contracts.cc (enum contract_match_kind): Move to contracts
header.
(build_contract_condition_function): Copy caller-side wrapper
state.
(set_contract_wrapper_function, get_contract_wrapper_function,
get_orig_func_for_wrapper, contracts_fixup_cdtorname,
build_contract_wrapper_function,
get_or_create_contract_wrapper_function): New.
(start_function_contracts): Handle caller-side wrappers.
(maybe_apply_function_contracts): Likewise.
(copy_and_remap_contracts): Likewise.
(should_contract_wrap_call, maybe_contract_wrap_call,
define_contract_wrapper_func, emit_contract_wrapper_func): New.
(finish_function_contracts): Handle caller-side wrappers.
(get_src_loc_impl_ptr): Likewise.
* contracts.h (DECL_IS_WRAPPER_FN_P): New.
(enum contract_match_kind): Moved from contracts.cc.
(copy_and_remap_contracts): Allow selection on the specific
contract kind.
(maybe_contract_wrap_call, emit_contract_wrapper_func): New.
(set_decl_contracts): Delete dead code.
* cp-tree.h (struct lang_decl_fn): Add wrapper function bit.
(DECL_CONTRACT_WRAPPER): New.
* decl2.cc (c_parse_final_cleanups): Emit wrappers.

gcc/ChangeLog:

* doc/invoke.texi: Document -fcontracts-client-check= and
-fcontracts-definition-check=.

gcc/testsuite/ChangeLog:

* g++.dg/contracts/cpp26/callerside-checks/callerside-checks-all.C: New test.
* g++.dg/contracts/cpp26/callerside-checks/callerside-checks-non-trivial.C: New test.
* g++.dg/contracts/cpp26/callerside-checks/callerside-checks-none.C: New test.
* g++.dg/contracts/cpp26/callerside-checks/callerside-checks-pre.C: New test.
* g++.dg/contracts/cpp26/callerside-checks/ctor.C: New test.
* g++.dg/contracts/cpp26/callerside-checks/freefunc-noexcept-post.C: New test.
* g++.dg/contracts/cpp26/callerside-checks/freefunc-noexcept-pre.C: New test.
* g++.dg/contracts/cpp26/definition-checks/contract-assert-no-def-check.C: New test.
* g++.dg/contracts/cpp26/non-trivial-ice.C: New test.

Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
47 hours agoc++, contracts: Allow contract checks as outlined functions.
Nina Ranns [Fri, 31 Oct 2025 00:20:43 +0000 (00:20 +0000)] 
c++, contracts: Allow contract checks as outlined functions.

In this variant of the contracts handling, we emit the contract
checks for pre and post conditions into small TU-local functions
that are then called in the relevant positions at the start of
the function and on each return edge (as a try-finally).

The rationale for adding this is that it is possible to treat
these outlined functions specially (for example, with different
(potentially fixed) optimisation settings from the code body.
Doing this can be a mechanism to work around cases where
optimisation of the contract conditions (or some function that
they might call) can lead to the elision of checks.

In order to pass parameters through to these small outlined
functions, we need similar functionality to that used for thunk
calls with respect copies of non-trivial values.  We are calling
this a "thunk-like" call, since none of the adjustments are
relevant here.

gcc/c-family/ChangeLog:

* c.opt (fcontract-checks-outlined,
fcontract-disable-optimized-checks): New.
* c.opt.urls: Regenerate.

gcc/cp/ChangeLog:

* contracts.cc (handle_contracts_p): Check that we are
handling an original function, not an outlined check.
(set_precondition_function, set_postcondition_function,
get_orig_for_outlined, contracts_fixup_name,
build_contract_condition_function,
build_precondition_function, build_postcondition_function,
build_contract_function_decls): New.
(start_function_contracts): Update for the case that we
outline the contract checks.
(build_arg_list, build_thunk_like_call,
add_pre_condition_fn_call,
get_postcondition_result_parameter,
add_post_condition_fn_call): New.
(apply_preconditions): Allow outlined checks.
(apply_postconditions): Likewise.
(get_precondition_function, get_postcondition_function,
set_contract_functions, remap_and_emit_conditions,
finish_function_contracts): New.
(get_src_loc_impl_ptr): Handle outlined checks.
(build_contract_check): Likewise.
* contracts.h (DECL_PRE_FN, DECL_POST_FN,
DECL_IS_PRE_FN_P, DECL_IS_POST_FN_P,
get_precondition_function, get_postcondition_function,
get_orig_for_outlined, finish_function_contracts,
set_contract_functions): New.
* cp-tree.h (enum lang_contract_helper): New.
(struct lang_decl_fn): Add contract helper enum.
(CONTRACT_HELPER): New.
(mangle_decl_string): New.
* decl.cc (finish_function): Emit outlined checks when
in use.
* module.cc (trees_out::fn_parms_init): Stream pre and post
outlined checks.
(trees_in::fn_parms_init): Reload pre and post outlined checks.
(check_mergeable_decl): Handle pre and post outlined functions.
(module_state_config::get_dialect): Add contracts dialect.

gcc/ChangeLog:

* doc/invoke.texi: Document -fcontract-checks-outlined and
-fcontract-disable-optimized-checks.

gcc/testsuite/ChangeLog:

* g++.dg/contracts/cpp26/outline-checks/freefunc-noexcept-post.C: New test.
* g++.dg/contracts/cpp26/outline-checks/freefunc-noexcept-pre.C: New test.
* g++.dg/contracts/cpp26/outline-checks/func-noexcept-assert.C: New test.
* g++.dg/contracts/cpp26/outline-checks/memberfunc-noexcept-post.C: New test.
* g++.dg/contracts/cpp26/outline-checks/memberfunc-noexcept-pre.C: New test.
* g++.dg/contracts/cpp26/empty-nt-param.C: Test with outlined checks.

Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
47 hours agoc++, contracts: Add tests for C++26 contracts.
Iain Sandoe [Sun, 19 Oct 2025 14:49:31 +0000 (15:49 +0100)] 
c++, contracts: Add tests for C++26 contracts.

This adds in a set of tests for the C++26 contracts, and also ensures that
cases that previously failed with attribute syntax continue to work as
expected with the revised C++26 syntax.

PR c++/113968
PR c++/110871
PR c++/110872

gcc/testsuite/ChangeLog:

* g++.dg/contracts/cpp26/BZ121936-workaround-noipa.C: New test.
* g++.dg/contracts/cpp26/assertion-statement-errors.C: New test.
* g++.dg/contracts/cpp26/assertion-statement.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p11-observe.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p14.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17-2.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17-3.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17-4.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17-5.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17-SMF-post.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17-SMF-pre.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17-SMF2.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17-SMF3.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17-SMF4.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p17.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p4-error.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p4.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p6.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p6.observe.C: New test.
* g++.dg/contracts/cpp26/basic.scope.contract.p1.C: New test.
* g++.dg/contracts/cpp26/basic.scope.contract.p2.1.C: New test.
* g++.dg/contracts/cpp26/contract-assert-run.C: New test.
* g++.dg/contracts/cpp26/contract-assert-warn-attributes.C: New test.
* g++.dg/contracts/cpp26/contract-violation-noexcept.C: New test.
* g++.dg/contracts/cpp26/contract-violation-noexcept2.C: New test.
* g++.dg/contracts/cpp26/contract_genericize.C: New test.
* g++.dg/contracts/cpp26/contracts-friend1.C: New test.
* g++.dg/contracts/cpp26/contracts-nested-class1.C: New test.
* g++.dg/contracts/cpp26/contracts-nested-class2.C: New test.
* g++.dg/contracts/cpp26/contracts-tmpl-spec2.C: New test.
* g++.dg/contracts/cpp26/dcl.contract.func.p4.C: New test.
* g++.dg/contracts/cpp26/dcl.contract.func.p6.C: New test.
* g++.dg/contracts/cpp26/dcl.contract.res.p1-NT.C: New test.
* g++.dg/contracts/cpp26/dcl.contract.res.p1.C: New test.
* g++.dg/contracts/cpp26/dcl.contract.res.p2.C: New test.
* g++.dg/contracts/cpp26/debug-and-opt.C: New test.
* g++.dg/contracts/cpp26/deferred1.C: New test.
* g++.dg/contracts/cpp26/dependent_contract.C: New test.
* g++.dg/contracts/cpp26/empty-nt-param.C: New test.
* g++.dg/contracts/cpp26/function-contract-specifier-seq-error.C: New test.
* g++.dg/contracts/cpp26/function-contract-specifier-seq.C: New test.
* g++.dg/contracts/cpp26/lambda.C: New test.
* g++.dg/contracts/cpp26/name_mangling.C: New test.
* g++.dg/contracts/cpp26/over.call.func.p3.1.C: New test.
* g++.dg/contracts/cpp26/pr113968.C: New test.
* g++.dg/contracts/cpp26/src-loc-0.C: New test.
* g++.dg/contracts/cpp26/src-loc-1.C: New test.
* g++.dg/contracts/cpp26/src-loc-2.C: New test.
* g++.dg/contracts/cpp26/throwing-violation-handler.cc: New test.
* g++.dg/contracts/cpp26/unused_warning.C: New test.
* g++.dg/contracts/cpp26/vaargs.C: New test.
* g++.dg/contracts/cpp2a/check-err.C: New test.
* g++.dg/coroutines/pr110871.C: New test.
* g++.dg/coroutines/pr110872.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p8.C: New test.
* g++.dg/contracts/cpp26/dcl.contract.func.p7.C: New test.
* g++.dg/contracts/cpp26/dcl.contract.res.p1-2.C: New test.
* g++.dg/contracts/cpp26/expr.prim.id.unqual.p7-2.C: New test.
* g++.dg/contracts/cpp26/expr.prim.id.unqual.p7.C: New test.
* g++.dg/contracts/cpp26/basic.contract.eval.p7.3.C: New test.
* g++.dg/contracts/cpp26/intro.compliance.general.p2.3.4.C: New test.

Co-Authored-by: Nina Ranns <dinka.ranns@gmail.com>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
47 hours agolibstdc++, contracts: Add base P2900R14 contracts support.
Nina Ranns [Sun, 19 Oct 2025 14:55:52 +0000 (15:55 +0100)] 
libstdc++, contracts: Add base P2900R14 contracts support.

What we need to do here (and, of course, in the code synthesis
that produces the objects) needs to be interoperable with other
platforms that share ABI.  For the present, this means Itanium
and to interoperate with clang and libc++.

The model we have followed in the development is essentially the
same as the model used for the C++2a edition.  However there is some
concern that the read-only data footprint of this is potentially
high and alternate schemes are in discussion with the clang folks.

Since the layout of the violation object is ABI let's leave this
in experimental until an agreed solution is fixed.

Remove the cxx2a support at the same time, GCC no longer supports
this mode.

libstdc++-v3/ChangeLog:

* include/Makefile.am: Add contract include.
* include/Makefile.in: Regenerate.
* include/bits/version.def: Add ftm for contracts.
* include/bits/version.h: Regenerate.
* include/precompiled/stdc++.h: Add contracts header.
* include/std/source_location: Befriend the contract_violation
class so that we can initialise a source_location from an
existing __impl *.
* src/c++23/std.cc.in: Add contracts support.
* src/experimental/Makefile.am: Add new contract violation
implementation, remove the old one.
* src/experimental/Makefile.in: Regenerate.
* include/experimental/contract: Removed.
* src/experimental/contract.cc: Removed.
* include/std/contracts: New file.
* src/experimental/contract26.cc: New file.
* testsuite/18_support/contracts/invoke_default_cvh.cc: New test.
* testsuite/18_support/contracts/invoke_default_cvh2.cc: New test.

Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Nina Ranns <dinka.ranns@gmail.com>
47 hours agoc++, contracts: Apply P200R14 constification.
Nina Ranns [Tue, 14 Oct 2025 11:37:48 +0000 (12:37 +0100)] 
c++, contracts: Apply P200R14 constification.

Split from the main patch as it was potentially contentious and might
have been altered by WG21 NB comment resolution. However, it most likely
makes sense to review in isolation (although we would expect to apply it
squashed into the base patch).

gcc/cp/ChangeLog:

* contracts.cc (view_as_const, constify_contract_access,
set_parm_used_in_post, check_param_in_postcondition,
parm_used_in_post_p, check_postconditions_in_redecl): New.
(check_redecl_contract): Handle constification.
* contracts.h (constify_contract_access, view_as_const,
contract_const_wrapper_p, strip_contract_const_wrapper): New.
* cp-tree.h: Update tree flag usage comment.
* lambda.cc (build_capture_proxy): Handle constification.
* parser.cc (cp_parser_late_contract_condition, cp_parser_contract_assert,
cp_parser_function_contract_specifier): Likewise.
* pt.cc (tsubst_function_decl, tsubst_expr): Likewise.
* semantics.cc (finish_id_expression_1, finish_decltype_type): Likewise.

gcc/ChangeLog:

* tree.h (CONST_WRAPPER_P): New.

gcc/ChangeLog:

* tree-core.h (struct tree_base): Update tree flag usage comment.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
Co-authored-by: Iain Sandoe <iain@sandoe.co.uk>
47 hours agoc++, contracts: Work around GCC IPA bug, PR121936 by wrapping terminate.
Nina Ranns [Fri, 31 Oct 2025 16:08:15 +0000 (16:08 +0000)] 
c++, contracts: Work around GCC IPA bug, PR121936 by wrapping terminate.

This implements a no-ipa wrapper around the calls made from terminating
contract assertions so that callers can no longer make assuptions about
the no-return behaviour.  This is sufficient to work around the reported
bug while a suitable general fix is evaluated.

gcc/c-family/ChangeLog:

* c.opt (fcontracts-conservative-ipa): New.

gcc/cp/ChangeLog:

* contracts.cc (__tu_terminate_wrapper): New.
(build_terminate_wrapper): New.
(declare_terminate_wrapper): New.
(maybe_emit_violation_handler_wrappers): Build a no-ipa wrapper
for terminating contract violations if required.

gcc/ChangeLog:

* doc/invoke.texi: Document -fcontracts-conservative-ipa.

Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
47 hours agoc++, contracts: C++26 base implementation as per P2900R14.
Iain Sandoe [Mon, 30 Oct 2023 11:12:56 +0000 (13:12 +0200)] 
c++, contracts: C++26 base implementation as per P2900R14.

This implementation performs the contracts application in three
phases:
    1. Parsing and semantic checks.
       Most of the code for this is in the parser, with helpers provided here.
    2. Emitting contract assertion AST nodes into function bodies.
       This is initiated from "finish_function ()"
    3. Lowering the contract assertion AST nodes to control flow, constant
       data and calls to the violation handler.
       This is initiated from "cp_genericize ()".

  Contract Assertion State
  ========================

  contract_assert () does not require any special handling and can be
  represented directly by AST inserted in the function body.

  'pre' and 'post' function contract specifiers require most of the special
  handling, since they must be tracked across re-declarations of functions and
  there are contraints on how such specifiers may change in these cases.

  The contracts specification identifies a "first declaration" of any given
  function - which is the first encountered when parsing a given TU.
  Subsequent re-declarations may not add or change the function contract
  specifiers from any introduced on this first declaration.  It is, however,
  permitted to omit specifiers on re-declarations.

  Since the implementation of GCC's (re-)declarations is a destructive merge
  we need to keep some state on the side to determine whether the re-declaration
  rules are met.  In this current design we have chosen not to add another tree
  to each function decl but, instead, keep a map from function decl to contract
  specifier state.  In this state we record the 'first declaration' specifiers
  which are used to validate re-declaration(s) and to report the initial state
  in diagnostics.

  We need (for example) to compare
    pre ( x > 2 ) equal to
    pre ( z > 2 ) when x and z refer to the same function parameter in a
    re-declaration.

  The mechanism used to determine if two contracts are the same is to compare
  the folded trees.  This makes use of current compiler machinery, rather than
  constructing some new AST comparison scheme.  However, it does introduce an
  additional complexity in that we need to defer such comparison until parsing
  is complete - and function contract specifiers in class declarations must be
  deferred parses, since it is also permitted for specifiers to refer to class
  members.

  When we encounter a definition, the parameter names in a function decl are
  re-written to match those of the definition (thus the expected names will
  appear in debug information etc).  At this point, we also need to re-map
  any function parameter names that appear in function contract specifiers
  to agree with those of the definition - although we intend to keep the
  'first declaration' record consistent for diagnostics.

  Since we shared some code from the C++2a contracts implementation, pre and
  post specifiers are represented by chains of attributes, where the payload
  of the attribute is an AST node.  However during the parse, these are not
  inserted into the function bodies, but kept in the decl-keyed state described
  above.  A future improvement planned here is to store the specifiers using a
  tree vec instead of the attribute list.

  Emitting contract AST
  =====================

  When we reach `finish_function ()` and therefore are committed to potentially
  emitting code for an instance, we build a new variant of the function body
  with the pre-condition AST inserted before the user's function body, and the
  post condition AST (if any) linked into the function return.

  Lowering the contract assertion AST
  ===================================

  In all cases (pre, post, contract_assert) the AST node is lowered to control
  flow and (potentially) calls to the violation handler and/or termination.
  This is done during `cp_genericize ()`.  In the current implementation, the
  decision on the control flow is made on the basis of the setting of a command-
  line flag that determines a TU-wide contract evaluation semantic, which has
  the following initial set of behaviours:

    'ignore'     : contract assertion AST is lowered to 'nothing',
      i.e. omitted.
    'enforce'     : contract assertion AST is lowered to a check, if this
      fails a violation handler is called, followed by
      std::terminate().
    'quick_enforce' : contract assertion AST is lowered to a check, if this
      fails, std::terminate () is called.
    'observe'     : contract assertion AST is lowered to a check, if this
      fails, a violation handler is called, the code then
      continues.

  In each case, the "check" might be a simple 'if' (when it is determined that
  the assertion condition does not throw) or the condition evaluation will be
  wrapped in a try-catch block that treats any exception thrown when evaluating
  the check as equivalent to a failed check.  It is noted in the violation data
  object whether a check failed because of an exception raised in evaluation.

  At present, a simple (but potentially space-inefficient) scheme is used to
  store constant data objects that represent the read-only data for the
  violation.  The exact form of this is subject to revision as it represents
  ABI that must be agreed between implementations (as of this point, that
  discussion is not yet concluded).

gcc/c-family/ChangeLog:

* c-common.cc: Add contract_assert keyword.
* c-common.h (enum rid): Likewise.
* c-cppbuiltin.cc (c_cpp_builtins): Add C++26 contracts feature test
macro.
* c.opt: Add a flag to control the TU-wide evaluation semantic. Add
a flag to control whether P1494 observable_checkpoints are inserted
to separate contract checks.
* c.opt.urls: Regenerate.

gcc/ChangeLog:

* config/darwin.h (ASM_GENERATE_INTERNAL_LABEL): Add cases for contract
constant data that need to be in independent link-time 'atoms'.
* doc/invoke.texi: Document -fcontracts and
-fcontract-evaluation-semantic=.

gcc/cp/ChangeLog:

* class.cc (check_for_override): Diagnose attemtps to add contracts to
virtual functions.
* constexpr.cc (cxx_eval_builtin_function_call): Handle
observable_checkpoints emitted for contracts.
(cxx_eval_constant_expression): Check we do not see contract assertions
here...
(potential_constant_expression_1): ... but that we do here.
* contracts.cc: Implement base C++26 P2600R14 contracts.
* contracts.h: Likewise.
* cp-gimplify.cc (cp_genericize_r): Lower contract assertions to control
flow and calls (where required) to the violation handler.
(fold_builtin_source_location): Use revised source_location impl.
constructor.
(build_source_location_impl): Split out the core of the constructor of
source_location so that it can be re-used from the contracts code.
* cp-tree.def (ASSERTION_STMT, PRECONDITION_STMT,
POSTCONDITION_STMT): Revise to allow space for specifying a semantic,
an assertion kind, and (where required) a source location.
* cp-tree.h (enum cp_tree_index, builtin_contract_violation_type): Add
the contract violation object type.
(struct saved_scope): Add a contracts class pointer.
(processing_postcondition, contract_class_ptr): New.
(struct cp_declarator): Add contract_specifiers.
(build_call_a_1): New.
(build_source_location_impl): New.
* decl.cc (duplicate_decls): Check function contract specifiers on
redeclarations.  Handle contract specifiers on instantiations.
(cxx_init_decl_processing): Initialise the terminate function since
this can be called from contracts even when exception processing is
disabled.  Build the contract violation object layout.
(start_decl): Handle checking contract postcondition identifiers.
(grokfndecl): Handle function contract specifiers.
(grokdeclarator): Likewise.
(start_preparsed_function): Start function contracts where needed.
(finish_function): Emit contract specifier AST corresponding to the
checked contracts.
* decl2.cc (c_parse_final_cleanups): Emit helpers for contract
violation handler calls.
* lex.cc (cxx_init): Add keyword warning for contract_assert.
* parser.cc (make_call_declarator): Add contract specifiers.
(unparsed_contracts): New.
(cp_parser_lambda_introducer): Allow contract specifier lambdas to have
a capture default.
(cp_parser_lambda_declarator_opt): Parse function contract specifiers.
(make_dummy_lambda_op): Account for contract specifiers in declarator.
(cp_parser_lambda_body): We have to ensure that deferred contracts are
parsed before we finish the lambda.
(cp_parser_statement): Handle contract_assert and diagnostics for
misplaced pre and post conditions.
(attr_chainon): Make this defensive against being passed a missing
attribute list.
(cp_parser_using_directive): Use attr_chainon instead of chainon.
(contract_attribute_p): New.
(cp_parser_init_declarator): Handle contract specifier names in
attributes.
(cp_parser_direct_declarator): Rename attrs to std_attrs for these.
(cp_parser_type_specifier_seq): Allow for function contract specifiers.
(cp_parser_class_specifier): Handle deferred parsing for function
contract specifiers
(cp_next_tokens_can_be_contract_attribute_p): True if this can be
a function contract specifier (which appear in the same position
as the attribute variant).
(cp_next_tokens_can_be_std_attribute_p): Allow for contracts.
(cp_nth_tokens_can_be_std_attribute_p): Likewise.
(cp_next_tokens_can_be_attribute_p): Likewise.
(cp_parser_late_contract_condition, cp_parser_late_contracts,
cp_parser_contract_assert, cp_parser_function_contract_specifier,
cp_parser_function_contract_specifier_seq): New.
(cp_parser_skip_std_attribute_spec_seq): Handle contracts case.
(cp_parser_skip_attributes_opt): Likewise.
(cp_parser_save_default_args): Handle unparsed contract specs.
* pt.cc (check_explicit_specialization): Handle removing contract
specifiers from instances.
(tsubst_contract, tsubst_contract_attribute,
tsubst_contract_attributes): New.
(tsubst_function_decl): Set contract specs. on substituted func.
(tsubst_stmt): Handle contract_assert.
(tsubst_expr): Allow for uses of postcondition uses of parm names.
(regenerate_decl_from_template): Handle function contract specs.
* semantics.cc (set_one_cleanup_loc): Add a location to
postcondition specifiers.
(finish_non_static_data_member): Diagnose bad uses of members
in contract specifiers.
(finish_this_expr): Diagnose invalid use of this in contract
specifiers.
(process_outer_var_ref): Allow use of params in contract specs.
(finish_id_expression_1): Likewise.
(apply_deduced_return_type): Maybe update postconditions when
the return type is changed.
* tree.cc (cp_tree_equal): Handle special cases when comparing
contracts.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wkeyword-macro-1.C: Update for contract_assert.
* g++.dg/warn/Wkeyword-macro-2.C: Likewise.
* g++.dg/warn/Wkeyword-macro-4.C: Likewise.
* g++.dg/warn/Wkeyword-macro-5.C: Likewise.
* g++.dg/warn/Wkeyword-macro-7.C: Likewise.
* g++.dg/warn/Wkeyword-macro-8.C: Likewise.

Co-Authored-by: Nina Ranns <dinka.ranns@gmail.com>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
47 hours agoc++, contracts: Add a contract scope per basic.scope.contract.
Iain Sandoe [Fri, 31 Oct 2025 11:02:13 +0000 (11:02 +0000)] 
c++, contracts: Add a contract scope per basic.scope.contract.

This adds a scope for contract assertions as per the standard section
referenced.  Split out here because it is the only part of the implementation
that touches the name lookup files.

gcc/cp/ChangeLog:

* cp-tree.h (processing_contract_condition): New.
* name-lookup.cc (cp_binding_level_descriptor): Add contract scope.
(begin_scope): Likewise.
* name-lookup.h (enum scope_kind): Add sk_contract.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
47 hours agoc++, contracts: Remove the abandoned C++2a implementation.
Iain Sandoe [Tue, 14 Oct 2025 10:49:28 +0000 (11:49 +0100)] 
c++, contracts: Remove the abandoned C++2a implementation.

The C++26 contracts design bears little relationship with the abandoned C++2a one.
While we have, where possible, attempted to re-use code, the underlying syntax and
implementation are divergent.

We have thus decided to represent this as a new implementation, after first removing
the old one.  Trying to review the patches as changes between two different designs
would be quite confusing.

gcc/c-family/ChangeLog:

* c-cppbuiltin.cc (c_cpp_builtins): Remove C++2a-specific
feature macros.
* c.opt: Remove C++2a-specific flags.

gcc/cp/ChangeLog:

* contracts.cc: Remove all C++2a contracts code.
* contracts.h: Likewise.
* coroutines.cc (coro_build_actor_or_destroy_function): Remove
unused contracts references.
* cp-gimplify.cc (cp_genericize_r): Remove C++2a contracts
implementation.
* cp-objcp-common.cc (cp_handle_option): Likewise.
* cp-tree.h: Remove C++2a contracts code.
* decl.cc: Likewise.
* decl2.cc: Likewise.
* mangle.cc: Likewise.
* module.cc: Likewise.
* parser.cc: Likewise.
* pt.cc: Likewise.
* search.cc: Likewise.
* semantics.cc: Likewise.
* tree.cc: Likewise.
* constexpr.cc: Likewise.

gcc/ChangeLog:

* doc/invoke.texi: Remove documentation of contracts options.

gcc/testsuite/ChangeLog:

* g++.dg/contracts/contracts-access1.C: Removed.
* g++.dg/contracts/contracts-assume1.C: Removed.
* g++.dg/contracts/contracts-assume2.C: Removed.
* g++.dg/contracts/contracts-assume3.C: Removed.
* g++.dg/contracts/contracts-assume4.C: Removed.
* g++.dg/contracts/contracts-assume5.C: Removed.
* g++.dg/contracts/contracts-assume6.C: Removed.
* g++.dg/contracts/contracts-comdat1.C: Removed.
* g++.dg/contracts/contracts-config1.C: Removed.
* g++.dg/contracts/contracts-constexpr1.C: Removed.
* g++.dg/contracts/contracts-constexpr2.C: Removed.
* g++.dg/contracts/contracts-constexpr3.C: Removed.
* g++.dg/contracts/contracts-conversion1.C: Removed.
* g++.dg/contracts/contracts-ctor-dtor1.C: Removed.
* g++.dg/contracts/contracts-ctor-dtor2.C: Removed.
* g++.dg/contracts/contracts-cv1.C: Removed.
* g++.dg/contracts/contracts-deduced1.C: Removed.
* g++.dg/contracts/contracts-deduced2.C: Removed.
* g++.dg/contracts/contracts-err1.C: Removed.
* g++.dg/contracts/contracts-externC.C: Removed.
* g++.dg/contracts/contracts-friend1.C: Removed.
* g++.dg/contracts/contracts-ft1.C: Removed.
* g++.dg/contracts/contracts-ignore1.C: Removed.
* g++.dg/contracts/contracts-ignore2.C: Removed.
* g++.dg/contracts/contracts-large-return.C: Removed.
* g++.dg/contracts/contracts-multiline1.C: Removed.
* g++.dg/contracts/contracts-multiple-inheritance1.C: Removed.
* g++.dg/contracts/contracts-multiple-inheritance2.C: Removed.
* g++.dg/contracts/contracts-nested-class1.C: Removed.
* g++.dg/contracts/contracts-nested-class2.C: Removed.
* g++.dg/contracts/contracts-nocopy1.C: Removed.
* g++.dg/contracts/contracts-override.C: Removed.
* g++.dg/contracts/contracts-post1.C: Removed.
* g++.dg/contracts/contracts-post2.C: Removed.
* g++.dg/contracts/contracts-post3.C: Removed.
* g++.dg/contracts/contracts-post4.C: Removed.
* g++.dg/contracts/contracts-post5.C: Removed.
* g++.dg/contracts/contracts-post6.C: Removed.
* g++.dg/contracts/contracts-post7.C: Removed.
* g++.dg/contracts/contracts-pre1.C: Removed.
* g++.dg/contracts/contracts-pre10.C: Removed.
* g++.dg/contracts/contracts-pre2.C: Removed.
* g++.dg/contracts/contracts-pre2a1.C: Removed.
* g++.dg/contracts/contracts-pre2a2.C: Removed.
* g++.dg/contracts/contracts-pre3.C: Removed.
* g++.dg/contracts/contracts-pre4.C: Removed.
* g++.dg/contracts/contracts-pre5.C: Removed.
* g++.dg/contracts/contracts-pre6.C: Removed.
* g++.dg/contracts/contracts-pre7.C: Removed.
* g++.dg/contracts/contracts-pre9.C: Removed.
* g++.dg/contracts/contracts-redecl1.C: Removed.
* g++.dg/contracts/contracts-redecl2.C: Removed.
* g++.dg/contracts/contracts-redecl3.C: Removed.
* g++.dg/contracts/contracts-redecl4.C: Removed.
* g++.dg/contracts/contracts-redecl5.C: Removed.
* g++.dg/contracts/contracts-redecl6.C: Removed.
* g++.dg/contracts/contracts-redecl7.C: Removed.
* g++.dg/contracts/contracts-redecl8.C: Removed.
* g++.dg/contracts/contracts-tmpl-attr1.C: Removed.
* g++.dg/contracts/contracts-tmpl-spec1.C: Removed.
* g++.dg/contracts/contracts-tmpl-spec2.C: Removed.
* g++.dg/contracts/contracts-tmpl-spec3.C: Removed.
* g++.dg/contracts/contracts1.C: Removed.
* g++.dg/contracts/contracts10.C: Removed.
* g++.dg/contracts/contracts11.C: Removed.
* g++.dg/contracts/contracts12.C: Removed.
* g++.dg/contracts/contracts13.C: Removed.
* g++.dg/contracts/contracts14.C: Removed.
* g++.dg/contracts/contracts15.C: Removed.
* g++.dg/contracts/contracts16.C: Removed.
* g++.dg/contracts/contracts17.C: Removed.
* g++.dg/contracts/contracts18.C: Removed.
* g++.dg/contracts/contracts19.C: Removed.
* g++.dg/contracts/contracts2.C: Removed.
* g++.dg/contracts/contracts20.C: Removed.
* g++.dg/contracts/contracts22.C: Removed.
* g++.dg/contracts/contracts24.C: Removed.
* g++.dg/contracts/contracts25.C: Removed.
* g++.dg/contracts/contracts3.C: Removed.
* g++.dg/contracts/contracts35.C: Removed.
* g++.dg/contracts/contracts4.C: Removed.
* g++.dg/contracts/contracts5.C: Removed.
* g++.dg/contracts/contracts6.C: Removed.
* g++.dg/contracts/contracts7.C: Removed.
* g++.dg/contracts/pr110159.C: Removed.
* g++.dg/contracts/pr113968.C: Removed.
* g++.dg/contracts/pr115434.C: Removed.
* g++.dg/contracts/pr116490.C: Removed.
* g++.dg/contracts/pr116607.C: Removed.
* g++.dg/contracts/pr117579.C: Removed.
* g++.dg/contracts/noexcept_preload_handler/Makefile: Removed.
* g++.dg/contracts/noexcept_preload_handler/README: Removed.
* g++.dg/contracts/noexcept_preload_handler/assert_fail.cpp: Removed.
* g++.dg/contracts/noexcept_preload_handler/handle_contract_violation.cpp: Removed.
* g++.dg/contracts/preload_handler/Makefile: Removed.
* g++.dg/contracts/preload_handler/README: Removed.
* g++.dg/contracts/preload_handler/assert_fail.cpp: Removed.
* g++.dg/contracts/preload_handler/handle_contract_violation.cpp: Removed.
* g++.dg/contracts/preload_nocontinue_handler/Makefile: Removed.
* g++.dg/contracts/preload_nocontinue_handler/README: Removed.
* g++.dg/contracts/preload_nocontinue_handler/assert_fail.cpp: Removed.
* g++.dg/contracts/preload_nocontinue_handler/handle_contract_violation.cpp: Removed.
* g++.dg/contracts/preload_nocontinue_handler/nocontinue.cpp: Removed.
* g++.dg/contracts/backtrace_handler/Makefile: Removed.
* g++.dg/contracts/backtrace_handler/README: Removed.
* g++.dg/contracts/backtrace_handler/assert_fail.cpp: Removed.
* g++.dg/contracts/backtrace_handler/example_out.txt: Removed.
* g++.dg/contracts/backtrace_handler/example_pretty.txt: Removed.
* g++.dg/contracts/backtrace_handler/handle_contract_violation.cpp: Removed.
* g++.dg/contracts/backtrace_handler/prettytrace.sh: Removed.
* g++.dg/coroutines/pr110871.C: Removed.
* g++.dg/coroutines/pr110872.C: Removed.
* g++.dg/modules/contracts-1_a.C: Removed.
* g++.dg/modules/contracts-1_b.C: Removed.
* g++.dg/modules/contracts-2_a.C: Removed.
* g++.dg/modules/contracts-2_b.C: Removed.
* g++.dg/modules/contracts-2_c.C: Removed.
* g++.dg/modules/contracts-3_a.C: Removed.
* g++.dg/modules/contracts-3_b.C: Removed.
* g++.dg/modules/contracts-4_a.C: Removed.
* g++.dg/modules/contracts-4_b.C: Removed.
* g++.dg/modules/contracts-4_c.C: Removed.
* g++.dg/modules/contracts-4_d.C: Removed.
* g++.dg/modules/contracts-5_a.C: Removed.
* g++.dg/modules/contracts-5_b.C: Removed.
* g++.dg/modules/contracts-tpl-friend-1_a.C: Removed.
* g++.dg/modules/contracts-tpl-friend-1_b.C: Removed.
* g++.dg/contracts/contracts8.C: Removed.
* g++.dg/contracts/contracts9.C: Removed.
* g++.dg/contracts/except_preload_handler/Makefile: Removed.
* g++.dg/contracts/except_preload_handler/README: Removed.
* g++.dg/contracts/except_preload_handler/assert_fail.cpp: Removed.
* g++.dg/contracts/except_preload_handler/handle_contract_violation.cpp: Removed.

Co-Authored-by: Nina Ranns <dinka.ranns@gmail.com>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2 days agoDaily bump.
GCC Administrator [Wed, 28 Jan 2026 00:16:36 +0000 (00:16 +0000)] 
Daily bump.

2 days agod: Side effects not evaluated for array literals on stack [PR120096]
Iain Buclaw [Tue, 27 Jan 2026 20:51:40 +0000 (21:51 +0100)] 
d: Side effects not evaluated for array literals on stack [PR120096]

PR d/120096

gcc/d/ChangeLog:

* expr.cc (ExprVisitor::visit (ArrayLiteralExp *)): Include saved side
effects in expression result.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr120096.d: New test.

2 days agobuild: Fix Linux/x86 bootstrap without --with-gnu-as/--with-as [PR123841]
Rainer Orth [Tue, 27 Jan 2026 22:25:12 +0000 (23:25 +0100)] 
build: Fix Linux/x86 bootstrap  without --with-gnu-as/--with-as [PR123841]

My recent patch r16-7073 broke Linux/x86 bootstrap without
--with-gnu-as/with-as by only setting gcc_cv_as_flags in acinclude.m4
with gas_flag=yes.  Instead it should allow for any value.

Bootstrapped without regressions on x86_64-pc-linux-gnu,
i386-pc-solaris2.11 --with-gnu-as --with-as, and and
x86_64-apple-darwin21.6.0 (both in state 2 now with gcc/auto-host.h
unchanged).

2026-01-27  Jakub Jelinek  <jakub@redhat.com>

gcc:
PR other/123841
* acinclude.m4 (gcc_GAS_FLAGS) <i?86-*-* | x86_64-*-*>: Set
gcc_cv_as_flags irrespective of $gas_flag.
* configure: Regenerate.

2 days agoanalyzer: add option -fanalyzer-assume-nothrow [PR122623]
David Malcolm [Tue, 27 Jan 2026 21:36:29 +0000 (16:36 -0500)] 
analyzer: add option -fanalyzer-assume-nothrow [PR122623]

As of r16-264-g7a39e0ca0652ff, -fanalyzer assumes that a call to an
external function not marked with attribute "nothrow" could throw an
exception, if -fexceptions is enabled.

PR analyzer/122623 notes that testing -fanalyzer with GCC 16 on Fedora
packages turned up some new leak warnings due to -fexceptions being
passed to all C code (for interoperability with C++), due to C headers
typically not having their entrypoints being marked with "nothrow".
Some of these are false positives.  Others are arguably true positives,
such as the case in the above report, but highly surprising to
end-users, and of dubious value.

I don't have data on the scale of the problem, but I am worried that
the C++ exception support added in GCC 16 could cause a big regression
in analyzer signal:noise when compiling C code with distro build flags.

To provide a workaround for distro mass analysis runs, this patch adds a
new option: -fanalyzer-assume-nothrow, which when enabled assumes that
external functions do not throw exceptions.  This may be something of a
blunt hammer, but may be useful to distros to add to build flags for C.

gcc/analyzer/ChangeLog:
PR analyzer/122623
* analyzer.opt (fanalyzer-assume-nothrow): New.
* analyzer.opt.urls: Regenerate.
* region-model.cc (can_throw_p): Bail out if the user specified
-fanalyzer-assume-nothrow.

gcc/ChangeLog:
PR analyzer/122623
* doc/invoke.texi (-fanalyzer-assume-nothrow): New option.

gcc/testsuite/ChangeLog:
PR analyzer/122623
* gcc.dg/analyzer/fexceptions-1.c: New test.
* gcc.dg/analyzer/fexceptions-2.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2 days agoopenmp: Fix omp for static schedule loop with pointers [PR97898]
Andrew Pinski [Sat, 24 Jan 2026 01:06:14 +0000 (17:06 -0800)] 
openmp: Fix omp for static schedule loop with pointers [PR97898]

When r0-122699-gea3a0fdefa353d was done to fix up handling of
gimple statements in openmp expand, there was one spot which did:
```
if (DECL_P (vback) && TREE_ADDRESSABLE (vback))
  t = force_gimple_operand_gsi (&gsi t, true
```
While other locations did:
```
t = force_gimple_operand_gsi (&gsi t, DECL_P (vback) && TREE_ADDRESSABLE (vback) ...
```

This fixes that one location which fixes up openmp for static scheduling with
a pointer as the induction variable.
Basically with a pointer type, we need to convert the rhs of the POINTER_PLUS
to be the same as size_type and with that conversion, the POINTER_PLUS becomes
an invalid gimple.

I don't think this is a regression but this is a small fix up which has now
shown up twice.

Bootstrapped and tested on x86_64-linux-gnu.

PR middle-end/97898

gcc/ChangeLog:

* omp-expand.cc (expand_omp_for_static_chunk): Don't
conditionalize the call to force_gimple_operand_gsi on DECL_P/TREE_ADDRESSABLE
but rather pass that as the 3rd argument.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/pr97898-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2 days agoUpdate gcc sv.po
Joseph Myers [Tue, 27 Jan 2026 21:15:03 +0000 (21:15 +0000)] 
Update gcc sv.po

* sv.po: Update.

2 days agoC: Do not warn for calls to .ACCESS_WITH_SIZE when -Wbad-function-cast is specified...
Qing Zhao [Mon, 26 Jan 2026 20:22:43 +0000 (20:22 +0000)] 
C: Do not warn for calls to .ACCESS_WITH_SIZE when -Wbad-function-cast is specified [PR123500]

For the following source code:

(uintptr_t)b->ptr;

when b->ptr has an counted_by annotation, the IR for this pointer reference
is changed to a call to .ACCESS_WITH_SIZE as:

(uintptr_t).ACCESS_WITH_SIZE (b->ptr, &b->len, 0B, 1);

As a result, the following code in the routine "build_c_cast" is invoked:

 7455       if (TREE_CODE (value) == CALL_EXPR
 7456           && TREE_CODE (type) != TREE_CODE (otype))
 7457         warning_at (loc, OPT_Wbad_function_cast,
 7458                     "cast from function call of type %qT "
 7459                     "to non-matching type %qT", otype, type);
 7460

It's obviously that C FE should exclude the call to .ACCESS_WITH_SIZE from
issuing such warning.

PR c/123500

gcc/c/ChangeLog:

* c-typeck.cc (build_c_cast): Exclude call to .ACCESS_WITH_SIZE from
-Wbad-function-cast warnings.

gcc/testsuite/ChangeLog:

* gcc.dg/pointer-counted-by-pr123500.c: New test.

2 days agod: Fix root modules have no file location set [PR122817]
Iain Buclaw [Tue, 27 Jan 2026 13:10:52 +0000 (14:10 +0100)] 
d: Fix root modules have no file location set [PR122817]

PR d/122817

gcc/d/ChangeLog:

* d-lang.cc (d_parse_file): Set module filename location after
creation.

gcc/testsuite/ChangeLog:

* gdc.dg/pr122817.d: New test.

2 days agoRemove impossible speculation in ipa_polymorphic_call_context::possible_dynamic_type_...
Jan Hubicka [Tue, 27 Jan 2026 18:18:13 +0000 (19:18 +0100)] 
Remove impossible speculation in ipa_polymorphic_call_context::possible_dynamic_type_change

This patch makes ipa-cp dataflow monotone by making sure we do not use speculation that
was proved to be impossible earlier.

gcc/ChangeLog:

PR ipa/123619
* ipa-polymorphic-call.cc
(ipa_polymorphic_call_context::possible_dynamic_type_change): Remove impossible
speuculation.

2 days agobuild: Unifiy 32 and 64-bit linker options
Rainer Orth [Tue, 27 Jan 2026 18:16:53 +0000 (19:16 +0100)] 
build: Unifiy 32 and 64-bit linker options

Similarly to assembler option handling in gcc/configure.ac, selecting
linker options to control 32 or 64-bit output is handled in various
different ways all over the place.

This patch uses the same approach as its assembler equivalent, setting
ld_32_opt and ld_64_opt once and using the result everywhere.

Bootstrapped without regressions on i386-pc-solaris2.11,
amd64-pc-solaris2.11, sparc-sun-solaris2.11, sparcv9-sun-solaris2.11
(as/ld and gas/gld), x86_64-pc-linux-gnu, i686-pc-linux-gnu,
x86_64-unknown-freebsd14.3, sparc64-unknown-linux-gnu, and
x86_64-apple-darwin21.6.0.

2026-01-10  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc:
* configure.ac (ld_32_opt, ld_64_opt): Set.
(ld_ix86_gld_32_opt): Replace by ld_32_opt.
(ld_ix86_gld_64_opt): Replace by ld_64_opt.
Replace -melf_x86_64 by ld_64_opt.
* configure: Regenerate.

2 days agobuild: Unify 32 and 64-bit assembler handling
Rainer Orth [Tue, 27 Jan 2026 18:15:36 +0000 (19:15 +0100)] 
build: Unify 32 and 64-bit assembler handling

gcc/configure.ac uses various ways to handle differences between GNU as
and Solaris as assembler options and syntax.

This patch unifies all those, setting gcc_cv_as_flags, as_32_opt, and
as_64_opt once in acinclude.m4 (gcc_GAS_FLAGS) and using the result
everywhere.  Besides, handling Solaris as syntax differences from GNU as
is done in a more readable way.

Bootstrapped without regressions on i386-pc-solaris2.11,
x86_64-pc-solaris2.11, x86_64-pc-linux-gnu, x86_64-unknown-freebsd14.3,
and x86_64-apple-darwin21.6.0.

gcc:
* acinclude.m4 (gcc_cv_as_flags) Provide Solaris settings.
Apply Linux/x86 gas settings on all x86 gas targets, too.
(as_32_opt, as_64_opt): Set on all x86 gas targets.
* configure.ac: Consistenly use as_32_opt, as_64_opt instead of
as_ix86_gas_{32,64}_opt or hardcoded --64.
<sparc*-*-*>: Simplify setting TLS test code.
* configure: Regenerate.

2 days agobuild: Only use --fatal-warnings if assembler supports it
Rainer Orth [Tue, 27 Jan 2026 18:11:11 +0000 (19:11 +0100)] 
build: Only use --fatal-warnings if assembler supports it

On Solaris/x86 with the native as, two tests currently FAIL:

FAIL: gcc.dg/tree-ssa/cswtch-6.c scan-assembler .rodata.cst16
FAIL: gcc.dg/tree-ssa/cswtch-7.c scan-assembler .rodata.cst32

These tests depend on SHF_MERGE/SHF_STRINGS support and we have no
effective-target keyword for this.

However, Solaris as supports the ELF section 'e' flag just fine.  The
gcc/configure.ac doesn't detect this because it unconditionally invokes
as with --fatal-warnings, which as doesn't support.

Rather than liberally sprinkling configure.ac with --fatal-warnings as
is done now, this patch just checks for the option once, using the
result everywhere.

Bootstrapped without regressions on i386-pc-solaris2.11,
sparc-sun-solaris2.11 (as and gas), x86_64-pc-linux-gnu, and
x86_64-apple-darwin21.6.0.  auto-host.h is unchanged everywhere except
Solaris/x86 with as and macOS 12.  On the latter, the section exclude
flag is now detected for the same reason.

2026-01-07  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc:
* configure.ac (fw_as_opt): Set.
Replace --fatal-warnings by $fw_as_opt.
(tls_as_opt): Remove --fatal-warnings.
(gcc_cv_as_tls): Use $fw_as_opt.
* configure: Regenerate.

2 days agoipa/116296 - avoid overflow in modref_access_node::contains
Richard Biener [Tue, 27 Jan 2026 12:01:19 +0000 (13:01 +0100)] 
ipa/116296 - avoid overflow in modref_access_node::contains

The following aovids overflow when scaling the param offset
difference by BITS_PER_UNIT by using poly_offset_int instead of
poly_int64 for the computations.

PR ipa/116296
* ipa-modref-tree.cc (modref_access_node::contains): Use
poly_offset_int for the param offset difference and the
overlap computation.

* gcc.dg/torture/pr116296.c: New testcase.

2 days agodebug/123376 - mangle decls referenced in initializers early
Richard Biener [Tue, 27 Jan 2026 10:29:27 +0000 (11:29 +0100)] 
debug/123376 - mangle decls referenced in initializers early

The following makes sure to mangle decls referenced in initializers,
even when of aggregate type, during the early debug phase since
later we eventually leave stray supposedly unused CV qualified
types as their own main variant which confuses C++ mangling.  The
comment that refers to rtl_for_decl_init punting might be
accurate, but loc_list_from_tree_1 will happily see to
cst_pool_loc_descr where constant pool lookup will eventually
create DECL_RTL of referenced symbols, triggering mangling.

PR debug/123376
* dwarf2out.cc (tree_add_const_value_attribute): Walk all
initializers for early mangling of referenced decls.
(mangle_referenced_decls): Also walk subtrees of CONSTRUCTORS.

* g++.dg/lto/pr123376_0.C: New testcase.

2 days agotestsuite: arm: Add another expected output in vdupq_n_f32.c
Christophe Lyon [Mon, 26 Jan 2026 14:25:04 +0000 (14:25 +0000)] 
testsuite: arm: Add another expected output in vdupq_n_f32.c

Depending on how GCC was configured, default -mtune parameter can load
the floating-point constant using either:
    movw    r3, #52429
    movt    r3, 16268
    or
    ldr     r3, .L4

Update the expected code to accept both versions.

Tested on:
- arm-linux-gnueabihf --with-tune=cortex-a9 --with-arch=armv7-a
- arm-none-eabi --with-cpu=cortex-m0
- arm-none-eabi --with-cpu=cortex-m55

2026-01-26  Christophe Lyon  <christophe.lyon@arm.com>

gcc/testsuite/
* gcc.target/arm/mve/intrinsics/vdupq_n_f32.c: Update expected
code.

2 days agoforwprop: Pun with integer type if needed [PR123799].
Robin Dapp [Sat, 24 Jan 2026 21:07:07 +0000 (22:07 +0100)] 
forwprop: Pun with integer type if needed [PR123799].

We cannot directly build vectors from BitInts, which this patch
circumvents by punning  the conversion element type with an integer
type.  This results in two separate conversions at the gimple level.
Those don't appear to cause worse final code, though.  It is possible to
merge those two conversions at the construction site but from what I can
tell would involve more changes than necessary now, so I refrained from
it.

Before this patch we would check tree_nop_conversion_p for e.g.
BitInt _12 = BIT_FIELD_REF (vector unsigned int).  This is a
"nop conversion" but the implicit assumption is that we can build
a vector type from the lhs type that can be nop-converted back to
the original type.  This is not true for BitInt.

Bootstrapped and regtested on x86, power10, and aarch64.
Regtested on riscv64.

PR tree-optimization/123799

gcc/ChangeLog:

* tree-ssa-forwprop.cc (simplify_vector_constructor): Pun
conversion element type with integer type.

gcc/testsuite/ChangeLog:

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

2 days agoFortran/OpenMP: Reject device-local var in MAP clause
Tobias Burnus [Tue, 27 Jan 2026 12:05:27 +0000 (13:05 +0100)] 
Fortran/OpenMP: Reject device-local var in MAP clause

gcc/fortran/ChangeLog:

* openmp.cc (resolve_omp_clauses): Reject groupprivate/device-local
variables in MAP clauses.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/groupprivate-7.f90: New test.

2 days agofortran: Allow vector math functions only with fast-math [PR 118955]
Wilco Dijkstra [Wed, 17 Sep 2025 15:50:04 +0000 (15:50 +0000)] 
fortran: Allow vector math functions only with fast-math [PR 118955]

Vector math functions are currently always enabled in Fortran.  This is
incorrect since vector math functions are designed to be Ofast only.
Add a new 'fastmath' option which only accepts vector functions if fast-math
is enabled:

!GCC$ builtin (sin) attributes simd (notinbranch) if('fastmath')

gcc/fortran:
PR fortran/118955
* decl.cc (gfc_match_gcc_builtin): Add 'fastmath' option which
checks for fast-math before accepting a vector function.
* gfortran.texi (!GCC$ builtin): Update documentation.

gcc/testsuite:
PR fortran/118955
* gfortran.dg/simd-builtins-9.f90: Add new test.
* gfortran.dg/simd-builtins-9.h: Likewise.

2 days agoAArch64: Block symbols in literal pools [PR 123791]
Wilco Dijkstra [Mon, 26 Jan 2026 14:11:17 +0000 (14:11 +0000)] 
AArch64: Block symbols in literal pools [PR 123791]

Symbols with a large offset may be emitted into a literal pool.
aarch64_select_rtx_section() may then select .text or .rodata even if
the symbol has a dynamic relocation.  Checking for CONST_INT or
CONST_DOUBLE avoids this.  Ensure aarch64_cannot_force_const_mem()
returns true for symbols and labels so that they cannot be placed in
literal pools.  Only the large code model emits symbols in the literal
pool (no support for PIC/PIE).

gcc:
PR target/123791
* config/aarch64/aarch64.cc (aarch64_cannot_force_const_mem):
Always return true for symbols and labels except for large model.
(aarch64_select_rtx_section): Force .rodata for constants only.

gcc/testsuite:
PR target/123791
* gcc.target/aarch64/pr123791.c: New test.

2 days agoAArch64: Allow invert for shift counts [PR 123792]
Wilco Dijkstra [Fri, 23 Jan 2026 17:48:00 +0000 (17:48 +0000)] 
AArch64: Allow invert for shift counts [PR 123792]

Optimize 1 << (31 - x) into 1 << ~x. This fixes part of PR 123792.

gcc:
PR target/123792
* config/aarch64/aarch64.md (aarch64_<optab>_reg_minus<mode>3):
Add support for invert in shift count.

gcc/testsuite:
PR target/123792
* gcc.target/aarch64/pr123792.c: New test.

2 days agoinstall.texi: Update GCN's newlib requirements
Tobias Burnus [Tue, 27 Jan 2026 10:50:26 +0000 (11:50 +0100)] 
install.texi: Update GCN's newlib requirements

GCN requires 4.3.0 or newer, but improvements and bug fixes were added
in later versions; before 4.3.0 was listed as required and several versions
up to post-4.5.0 commits were mentioned. Now that 4.6.0 has been released,
just referring to 4.6.0 is sufficient. As fixes are important and there is no
real reason to use an older Newlib: Only list 4.6.0+ as to be used,
instead of also mentioning 4.3.0+ (and other older releases).

gcc/ChangeLog:

* doc/install.texi (gcn): Require Newlib 4.6.0+, replacing 4.3.0+
requirement with long list of recommended fixes up to post-4.5.0.

2 days agoc++/modules: Include instantiation origination for all name lookup [PR122609]
Nathaniel Shead [Fri, 9 Jan 2026 06:21:08 +0000 (17:21 +1100)] 
c++/modules: Include instantiation origination for all name lookup [PR122609]

Many expressions rely on standard library names being visible when used,
such as for structured bindings, typeid, coroutine traits, and so forth.
When these expressions occur in templates, and the instantiations occur
in a TU where those names are not visible, we currently error, even if
the name was visible in the TU the template was defined.

This is a poor user experience (made worse by fixit suggestions to add
an include in the module the template was defined, which wouldn't fix
the error anyway).  It seems reasonable to also include declarations that
were visible at the point the instantiation originated.

When using 'import std' this should fix most such errors.  If using
traditional #includes to provide the standard library this may or may
not fix the error; in many cases we may still incorrectly discard the
relevant names (e.g. typeid in a template does not currently cause us to
consider std::type_info to be decl-reachable).

This also fixes the XFAIL in adl-12_b.C as we add_candidates now
properly considers names visible in the instantiation context of the
comparison.

PR c++/122609
PR c++/101140

gcc/cp/ChangeLog:

* cp-tree.h (visible_from_instantiation_origination): Declare.
* module.cc: (orig_decl_for_instantiation): New function.
(path_of_instantiation): Use it.
(visible_from_instantiation_origination): New function.
* name-lookup.cc (name_lookup::search_namespace_only): Also find
names visible at the point the instantiation originated.

gcc/testsuite/ChangeLog:

* g++.dg/modules/adl-12_b.C: Remove XFAIL.
* g++.dg/modules/inst-8_a.C: New test.
* g++.dg/modules/inst-8_b.C: New test.
* g++.dg/modules/inst-8_c.C: New test.
* g++.dg/modules/inst-9_a.C: New test.
* g++.dg/modules/inst-9_b.C: New test.
* g++.dg/modules/inst-10_a.C: New test.
* g++.dg/modules/inst-10_b.C: New test.
* g++.dg/modules/inst-10_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2 days agoc++: Implement CWG3153 - Immediate-escalating defaulted comparison
Jakub Jelinek [Tue, 27 Jan 2026 09:24:49 +0000 (10:24 +0100)] 
c++: Implement CWG3153 - Immediate-escalating defaulted comparison

The following patch implements the
https://cplusplus.github.io/CWG/issues/3153.html
core issue proposal.

2026-01-27  Jakub Jelinek  <jakub@redhat.com>

* cp-gimplify.cc (immediate_escalating_function_p): Implement
CWG3153 - Immediate-escalating defaulted comparison.  Don't check
special_memfn_p for sfk_none for DECL_DEFAULTED_FNs.
* decl.cc (grokfndecl): Similarly for initialized == SD_DEFAULTED
fns.

* g++.dg/reflect/cwg3153.C: New test.