Andrew Pinski [Wed, 28 Jan 2026 20:32:12 +0000 (12:32 -0800)]
ifcvt: Improve noce_can_force_operand in ifcvt [PR122170]
Currently if the rtl is either an arithmetic or an unary
rtl, noce_can_force_operand checks to see if there is an
optab for that rtl code. This works for more things except
on some targets they have a ss_minus instruction but don't
implement the optab for it. In the case of arm you can
generate a ss_minus with a builtin and then when it comes
to trying to do ifcvt, force_operand fails over.
In this case the optab, sssub was only supported for
fixed-point modes before and it was working as code_to_optab
would return there was not optabs. But after r15-1030-gabe6d39365476e,
the optab will be return. What the backend is doing is correct and will
most likely happen with other rtl codes/optabs later on.
To fix this instead of just returning true if the optab exists, we need
to check if the optab entry for the mode exists.
PR rtl-optimization/122170
gcc/ChangeLog:
* ifcvt.cc (noce_can_force_operand): Don't only check if
there is an optab for the code check the entry for the
mode is non-null. Handle non integral div by checking
optab like force_operand does.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Lulu Cheng [Tue, 27 Jan 2026 02:31:36 +0000 (10:31 +0800)]
LoongArch: Fix bug123766.
The pointer parameter type for the original store class builtin
functions is CVPOINTER (const volatile void *).
Taking the following test as an example:
```
v4i64 v = {0, 0, 0, 0};
void try_store() {
long r[4];
__lasx_xvst(v, r, 0);
}
```
At this point, the type of r is CVPOINTER, which means data in memory
can only be read through r. Therefore, if the array r is not
initialized, an uninitialized warning will be issued.
This patch changes the pointer type of store-class builtin functions
from CVPOINTER to VPOINTER (volatile void *).
PR target/123766
gcc/ChangeLog:
* config/loongarch/loongarch-builtins.cc
(loongarch_build_vpointer_type): New function. Return a type
for 'volatile void *'.
(LARCH_ATYPE_VPOINTER): New macro.
* config/loongarch/loongarch-ftypes.def: Change the pointer
type of the store class function from CVPOINTER to VPOINTER.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/vector/lasx/pr123766.c: New test.
* gcc.target/loongarch/vector/lsx/pr123766.c: New test.
Lulu Cheng [Mon, 26 Jan 2026 03:38:59 +0000 (11:38 +0800)]
LoongArch: Fix bug123807.
In the function loongarch_expand_vector_init_same, if same is MEM and
the mode of same does not match imode, it will cause an ICE
in force_reg (imode, same).
PR target/123807
gcc/ChangeLog:
* config/loongarch/loongarch.cc
(loongarch_expand_vector_init_same): When same is MEM and
GET_MODE(same) != imode, first load the data from memory
and then process it further.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/vector/lsx/pr123807.c: New test.
mengqinggang [Fri, 23 Jan 2026 07:00:58 +0000 (15:00 +0800)]
LoongArch: Fix movsf in lp64s abi
When adding LoongArch32 ilp32s abi support, add TARGET_HARD_FLOAT condition for
movsf to prevent matching in target without FPU.
But movsf also needs to be used in lp64s abi, it can expand to some
non float instructions.
Delete TARGET_HARD_FLOAT condition.
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>
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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)[]'.
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.
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.
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.
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.
[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.
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.
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.
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.
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.
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.
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.
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.
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>
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>
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.
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.
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.
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.
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>
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.
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.
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.
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>
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>
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.
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>
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.
* 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.
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.
* 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.
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.
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.
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).
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.
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.
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.
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.
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.
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>
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>
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.
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.
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.
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.
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.
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
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.