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.
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:
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.
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.
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>
Jakub Jelinek [Tue, 27 Jan 2026 09:23:43 +0000 (10:23 +0100)]
c++: Don't error on non-consteval defaulted special members in consteval-only classes [PR123404]
As discussed earlier, the following testcase is incorrectly rejected.
While check_consteval_only_fn -> immediate_escalating_function_p
knows that defaulted special members are immediate-scalating:
/* -- a defaulted special member function that is not declared with the
consteval specifier */
special_function_kind sfk = special_memfn_p (fn);
if (sfk != sfk_none && DECL_DEFAULTED_FN (fn))
return true;
it returns false anyway, because the call is too early and DECL_DEFAULTED_FN
is not set yet (unlike DECL_DELETED_FN).
For DECL_DEFAULTED_FN there is quite more code, involving diagnostics for
invalid uses of = delete etc. later in grokfield:
else if (init == ridpointers[(int)RID_DEFAULT])
{
if (defaultable_fn_check (value))
{
DECL_DEFAULTED_FN (value) = 1;
DECL_INITIALIZED_IN_CLASS_P (value) = 1;
DECL_DECLARED_INLINE_P (value) = 1;
/* grokfndecl set this to error_mark_node, but we want to
leave it unset until synthesize_method. */
DECL_INITIAL (value) = NULL_TREE;
}
}
but that is after the
else if (init == ridpointers[(int)RID_DEFAULT])
initialized = SD_DEFAULTED;
...
value = grokdeclarator (declarator, declspecs, FIELD, initialized, &attrlist);
call in the same function where grokdeclarator calls grokfndecl.
As for defaulted special member functions there is nothing to diagnose,
those are always immediate-escalating or explicitly consteval and neither
of those is diagnosed, the following patch just passes not just whether
a fn is deleted, but whole initialized, so both whether it is deleted or
defaulted, and just doesn't call check_consteval_only_fn in that case.
During pt.cc check_consteval_only_fn call DECL_DEFAULTED_FN is already set
before we test it.
2026-01-27 Jakub Jelinek <jakub@redhat.com>
PR c++/123404
* decl.cc (grokfndecl): Replace bool deletedp argument with
int initialized. Test initialized == SD_DELETED instead of deletedp.
Don't call check_consteval_only_fn for defaulted special member fns.
(grokdeclarator): Pass initialized rather than
initialized == SD_DELETED to grokfndecl.
Jakub Jelinek [Tue, 27 Jan 2026 09:19:39 +0000 (10:19 +0100)]
c++: Fix ICE in cxx_printable_name_internal [PR123578]
On the following testcase, we end up with cxx_printable_name_internal
recursion, in particular
+../../gcc/cp/pt.cc:20736
+../../gcc/cp/error.cc:625
+template_args=<tree_vec 0x7fffe94b59b0>, flags=4) at ../../gcc/cp/error.cc:1876
The ICE is due to double free, that function is doing caching of up to 4
printed names, but if such a recursion happens, the inner call can change
ring_counter etc. and the caller will then store the result in a different
ring element from what was freed and so the freed one can be left
unmodified.
The patch fixes it by moving the lang_decl_name call earlier, after the:
/* See if this print name is lying around. */
for (i = 0; i < PRINT_RING_SIZE; i++)
if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i])
/* yes, so return it. */
return print_ring[i];
loop and repeating the loop again just for the theoretical case
that some recursion would add the same entry.
The ring_counter adjustment and decision which cache entry to reuse
for the cache is then done without the possibility of ring_counter
or the cache being changed in the middle.
2026-01-27 Jakub Jelinek <jakub@redhat.com>
PR c++/123578
* tree.cc (cxx_printable_name_internal): Call lang_decl_name before
finding the slot to cache it in and repeat search in the cache
after the call.
Frank Scheiner [Mon, 12 Jan 2026 09:48:58 +0000 (10:48 +0100)]
testsuite: only test with LTO if LTO support is actually configured
Bootstrapping GCC (c, c++) on ia64 w/o support for LTO ([1]) showed that
the testsuite (specifically c-c++-common/guality) executes tests with
`-flto` although there was no support for LTO configured.
This is because [...]/guality.exp adds test permutations w/`-flto`
unconditionally. Fix that by checking for LTO support and drop
permutations w/`-flto` if unsupported.
mul z2.s, z2.s, z1.s
mul z4.s, z4.s, z26.s
mul z1.s, z24.s, z1.s
mul z3.s, z23.s, z3.s
add z29.s, z2.s, z29.s
add z30.s, z1.s, z30.s
add z28.s, z3.s, z28.s
add z0.s, z4.s, z0.s
This is since the fix for r16-3328-g3182e95eda4 we now insert casts around the
reduction addend. This causes convert_mult_to_fma to miss the mul + add
sequence.
This patch teaches it to look around the casts for the operands and only accept
the conversions if it's essentially only a sign changing operations.
PR tree-optimization/122749
* tree-ssa-math-opts.cc (convert_mult_to_fma_1, convert_mult_to_fma):
Unwrap converts around addend.
gcc/testsuite/ChangeLog:
PR tree-optimization/122749
* gcc.target/aarch64/pr122749_1.c: New test.
* gcc.target/aarch64/pr122749_2.c: New test.
* gcc.target/aarch64/pr122749_3.c: New test.
* gcc.target/aarch64/pr122749_4.c: New test.
* gcc.target/aarch64/pr122749_5.c: New test.
* gcc.target/aarch64/pr122749_6.c: New test.
* gcc.target/aarch64/pr122749_8.c: New test.
* gcc.target/aarch64/pr122749_9.c: New test.
* gcc.target/aarch64/sve/pr122749_1.c: New test.
* gcc.target/aarch64/sve/pr122749_11.c: New test.
* gcc.target/aarch64/sve/pr122749_12.c: New test.
* gcc.target/aarch64/sve/pr122749_13.c: New test.
* gcc.target/aarch64/sve/pr122749_14.c: New test.
* gcc.target/aarch64/sve/pr122749_2.c: New test.
* gcc.target/aarch64/sve/pr122749_3.c: New test.
* gcc.target/aarch64/sve/pr122749_4.c: New test.
* gcc.target/aarch64/sve/pr122749_5.c: New test.
* gcc.target/aarch64/sve/pr122749_6.c: New test.
* gcc.target/aarch64/sve/pr122749_8.c: New test.
* gcc.target/aarch64/sve/pr122749_9.c: New test.
Patrick Palka [Tue, 27 Jan 2026 03:00:16 +0000 (22:00 -0500)]
c++: non-dep decltype folding of concept-id C<Ts...> [PR123676]
Here since the expression within the decltype C<Ts...> is not instantiation
dependent (we know its type is bool, and don't care about its value)
finish_decltype_type instantiates it immediately via the usual tsubst_expr
with NULL_TREE args. During which however tsubst_pack_expansion isn't
prepared to handle such a substitution due to an overly strict assert.
This patch relaxes the assert accordingly.
PR c++/123676
gcc/cp/ChangeLog:
* pt.cc (tsubst_pack_expansion): Relax unsubsituted_packs
assert to allow !processing_template_decl when args is
NULL_TREE.
In the PR122494 testcase we constant evaluate 'B<int>::v == 0' first
during warning-dependent folding, which is restricted to avoid unnecessary
template instantiation. During this restricted evaluation we do
decl_constant_value on v which in turn manifestly constant evaluates v's
initializer. But this nested evaluation is incorrectly still restricted
since the restriction mechanism is controlled by a global flag. This
causes constraint checking for A<int> to spuriously fail.
We could narrowly fix this by guarding the decl_constant_value code path
with uid_sensitive_constexpr_evaluation_p but that would overly
pessimize warning-dependent folding of constexpr variables with simple
initializers. The problem is ultimately that the restriction mechanism
is misdesigned, and it shouldn't be a global toggle, instead it should
be local to the constexpr evaluation context and propagated accordingly.
The PR123814 testcase is similar except that the nested manifestly
constant evaluation happens through __fold_builtin_source_location
(which performs arbitrary tsubst).
Until we remove or reimplement the mechanism, this patch disables the
mechanism during nested manifestly constant evaluation. We don't ever
want such evaluation to be restricted since it has semantic consequences.
PR c++/122494
PR c++/123814
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_outermost_constant_expr): Clear
uid_sensitive_constexpr_evaluation_value when mce_true.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-pr122494.C: New test.
* g++.dg/cpp2a/concepts-pr123814.C: New test.
PR analyzer/123145 tracks a large slowdown seen in -fanalyzer on
a particular test case in qemu.
Profiling showed a large amount of time being spent iterating through
binding maps with binding_map::const_iterator::operator*, due to the
work spent converting from bit_range to concrete_key via
store_manager::get_concrete_binding.
Many of the iterations where this done are merely looking at the bound
svalues, not the keys, so this work is wasted.
This patch updates these iterations to avoid needing to do work on the
keys.
Crude benchmarking (on a debug, not release build) showed a speedup on
the test case, from 3 hours to 2.2 hours.
No functional change intended.
gcc/analyzer/ChangeLog:
PR analyzer/123145
* program-state.cc (sm_state_map::impl_set_state): Update
iteration to avoid looking up binding_key values.
* region-model-reachability.cc (reachable_regions::handle_sval):
Use iter.get_svalue.
(reachable_regions::handle_parm): Likewise.
* region-model.cc (iterable_cluster::iterable_cluster): Update
iteration to avoid looking up binding_key values.
(iterable_cluster::dump_to_pp): Likewise.
(exposure_through_uninit_copy::calc_num_uninit_bits): Likewise.
(exposure_through_uninit_copy::complain_about_uninit_ranges):
Likewise.
(contains_uninit_p): Likewise.
* store.cc (binding_map::hash): Likewise.
* store.h (bit_range::hash): New, based on...
(concrete_binding::hash): ...this. Reimplement using the above.
(binding_map::const_iterator::get_svalue): New decl.
(binding_map::get_symbolic_bindings): New accessor.
(binding_map::for_each_value): Update iteration to avoid looking
up binding_key values.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Andrew Pinski [Mon, 26 Jan 2026 06:23:51 +0000 (22:23 -0800)]
slsr: Use the correct type to try to convert to for inserting on edge case [PR123820]
I had noticed there was code that will convert the stride
to the correct type
What I didn't realize was the type which it was trying to
use was stride_type but for this case it should have been using
the type of the lhs. This fixes that oversight. Note for pointers
we still want to use stride_type like what is done right above.
I don't have a testcase that does not use LTO though. I didn't figure
out why this testcase needed LTO though.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/123820
gcc/ChangeLog:
* gimple-ssa-strength-reduction.cc (create_add_on_incoming_edge): Use
the correct type for the stride (lhs if non-pointer).
gcc/testsuite/ChangeLog:
* g++.dg/torture/pr123820-1.C: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Andrew Pinski [Sun, 25 Jan 2026 23:08:31 +0000 (15:08 -0800)]
final: Fix out of bounds access for invalid asm operands [PR123709]
output_asm_insn has an out of bounds array access if the supplied
operand number in the inline-asm is "big" (>=MAX_RECOG_OPERANDS).
This makes it so that there is no longer an out of bounds access
by increasing the two arrays by one and using the last element as
the fake location for all out of range operands.
This could be a regression because r0-38026-g4f9b4029463bc0 seems like
introduce the out of bounds access but
Bootstrapped and tested on x86_64-linux-gnu.
PR middle-end/123709
gcc/ChangeLog:
* final.cc (output_asm_operand_names): Skip over
opnum which is MAX_RECOG_OPERANDS (invalid).
(output_asm_insn): Increase opoutput and oporder size
by 1. For out of range operands, set the opnum to
MAX_RECOG_OPERANDS.
gcc/testsuite/ChangeLog:
* c-c++-common/asm-invalid-operand-1.c: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Joseph Myers [Mon, 26 Jan 2026 16:49:29 +0000 (16:49 +0000)]
testsuite: Make profopt-execute also copy profile data for dg-additional-sources
Most gcc.dg/tree-prof tests work correctly in environments where .gcda
files from the first run need to be copied from the target, because
there is existing code in profopt-execute to do so. A few tests using
dg-additional-sources fail because that code only copies the .gcda
file for the main test source file. Add similar code to copy it for
any sources listed in dg-additional-sources as well.
The use of additional_sources_used is consistent with what
profopt-target-cleanup does. It turns out to require the added call
to cleanup-after-saved-dg-test to avoid additional_sources_used
leaking from one test into the next.
Tested for x86_64-pc-linux-gnu to make sure native testing isn't
broken, and with cross to aarch64-linux.
* lib/profopt.exp (profopt-execute): Also copy profile data from
target for additional sources. Call cleanup-after-saved-dg-test
before normal return.
Karl Meakin [Thu, 11 Dec 2025 16:49:14 +0000 (16:49 +0000)]
aarch64: fix `asm.c` tests
The assembly functions declared in `asm_1.c` and `asm_3` were not marked
global, so they could not be found by the linker, and would cause the
`asm_2.c` and `asm_4.c` test to fail. Fix by marking the functions with
`.globl`.
Karl Meakin [Thu, 11 Dec 2025 16:24:51 +0000 (16:24 +0000)]
aarch64: fix `mangle_5.C` test
The `volatile` type qualifier is deprecated on function parameters and
return types since C++ 20. This caused extra warning to be emmitted, so
the test failed. Fix it by suppressing the warning.
Marek Polacek [Thu, 22 Jan 2026 20:52:45 +0000 (15:52 -0500)]
c++/reflection: detect more invalid splices in lambda
The comment for check_splice_expr in
<https://gcc.gnu.org/pipermail/gcc-patches/2025-December/704168.html>
points out that I wasn't giving an error for this testcase. (clang++
rejects the testcase.)
Fixed by checking if process_outer_var_ref returned a capture.
gcc/cp/ChangeLog:
* reflect.cc (check_splice_expr): Check if process_outer_var_ref
returned a capture, and give an error if so.
Marek Polacek [Thu, 22 Jan 2026 19:49:08 +0000 (14:49 -0500)]
c++: tweak for cp_parser_type_id_1
This addresses the cp_parser_type_id_1 comment in
<https://gcc.gnu.org/pipermail/gcc-patches/2025-December/704168.html>
asking for simplifying the type_alias_p handling.
gcc/cp/ChangeLog:
* parser.cc (cp_parser_type_specifier): Adjust comment.
(cp_parser_type_id_1): Simplify setting of type_alias_p.
Use nullptr instead of NULL.
Marek Polacek [Thu, 22 Jan 2026 16:31:35 +0000 (11:31 -0500)]
c++/reflection: fix fnptr extraction [PR123620]
When extracting a function pointer, removing noexcept should be
allowed (but not the other way round):
int fn (int) noexcept;
constexpr auto a = extract<int (*)(int)>(^^fn);
but currently we reject this code -- I didn't realize that fnptr_conv_p
allows things that same_type_p doesn't allow, and in can_extract_* we
should check both. And then we need to perform the actual conversion.
PR c++/123620
gcc/cp/ChangeLog:
* reflect.cc (can_extract_member_or_function_p): Also check
fnptr_conv_p.
(extract_member_or_function): Call perform_implicit_conversion.
gcc/testsuite/ChangeLog:
* g++.dg/reflect/extract1.C: Test removing noexcept.
* g++.dg/reflect/extract2.C: Adjust static_assert.
Richard Biener [Fri, 23 Jan 2026 14:24:53 +0000 (15:24 +0100)]
tree-optimization/122474 - adjust check for .VEC_SHL_INSERT
The r16-4558-g1b387bd8978577 change added a check that does not
match what the commit message says. The following fixes this,
trying to more closely match up what we later do during transform
and what we check here. As cleanup this also makes sure that
we compute the neutral value for the scalar type and consistently
when it depends on the initial value, recording it in a new
VECT_REDUC_INFO_NEUTRAL_OP. This avoids issues with comparing
the neutral and initial value when it is bool. This also
refactors vect_transform_cycle_phi a bit to remove dead code
and make the flow easier to follow.
PR tree-optimization/122474
* tree-vectorizer.h (vect_reduc_info_s::neutral_op): New.
(VECT_REDUC_INFO_NEUTRAL_OP): New.
* tree-vect-loop.cc (vectorizable_reduction): Adjust condition
guarding the check for .VEC_SHL_INSERT.
* gcc.target/aarch64/sve2/pr123053.c: New testcase.
* gcc.target/riscv/rvv/pr122474.c: Likewise.
Richard Biener [Mon, 26 Jan 2026 07:57:45 +0000 (08:57 +0100)]
tree-optimization/123755 - fix LEN-masking of trapping calls
There's multiple issues with properly handling len-masking of calls
that might trap. Similar to get_conditional_internal_fn,
get_len_internal_fn expects a COND_* argument only. When the
original call is not already masked computation and code-gen fails
to add mask and else arguments.
This fixes gcc.target/riscv/rvv/autovec/reduc/reduc_call-5.c
PR tree-optimization/123755
* tree-vect-stmts.cc (vectorizable_call): Fixup LEN masking
of unconditional but possibly trapping calls.
vect: Fix outer loop vectorization for nested uncounted loops [PR123657]
Given the inability of `expr_invariant_in_loop_p (loop, expr)' to
handle the `scev_not_known' node as the expression, an unknown loop
bound in the inner loop in a nested set of loops led to
`vect_analyze_loop_form' to erroneously consider the outer loop as
suitable for vectorization. This introduces the necessary unknown
loop iteration count check to ensure correct handling of counted loops
with an embedded uncounted loop.
Tamar Christina [Mon, 26 Jan 2026 08:06:34 +0000 (08:06 +0000)]
vect: distinguish between MASK_CALL and non-trapping calls [PR123628]
In the Fix for PR122103 an ambiguity was introduced when it comes to fortran
due to an inconsistency in libmvec headers.
A reproducer is
!GCC$ builtin (expf) attributes simd (notinbranch)
SUBROUTINE a(b)
REAL, DIMENSION(:) :: b
c: DO i = 1, d
IF (e <= f) THEN
g = EXP(h)
r = g
IF (r > s) THEN
b(i) = t
END IF
END IF
END DO c
END
compiled with -O2 -march=armv8-a+sve, note that fortran, unlike C provides the
libmvec header math-vector-fortran.h unconditionally, which is a separate bug
PR118955 which causes the functions to become available outside of -Ofast.
This means the cases for MASK_CALL and trapping math overlap for fortran at -O2.
The new masking code shouldn't handle SIMD clones.
gcc/ChangeLog:
PR tree-optimization/122103
PR tree-optimization/123628
* tree-if-conv.cc (if_convertible_simdclone_stmt_p): New.
(if_convertible_stmt_p, predicate_statements): Use it.
gcc/testsuite/ChangeLog:
PR tree-optimization/122103
PR tree-optimization/123628
* gfortran.target/aarch64/pr123628.f90: New test.
Nathaniel Shead [Fri, 23 Jan 2026 23:11:35 +0000 (10:11 +1100)]
c++: Fix behaviour of nested maybe_push_to_top_level [PR123663]
What happens in the linked PR is that when evaluating the concept we
call 'push_to_top_level', we see cfun is non-null, and so call
'push_function_context' which sets cfun to NULL and sets a flag so that
we remember to pop it later.
Then, when instantiating Foo's default constructor as part of the
concept, we call 'maybe_push_to_top_level'. Here we see that 'Foo' is
function-local, so '!push_to_top', and we call 'push_function_context'.
This allocates a new cfun for some reason, and pushes that empty cfun.
Eventually we 'maybe_pop_from_top_level', and restore that newly
allocated cfun (instead of a NULL cfun), which means that when we start
trying to build the new-expression (which requires building a statement
list) we try accessing the (uninitialized) cfun's x_stmt_tree rather
than the scope_chain's x_stmt_tree, and so crash.
This fixes the issue by also remembering whether we had a cfun when
doing maybe_push_to_top_level so that we only do push_function_context
if needed.
This also seems to fix PR123354.
PR c++/123663
PR c++/123354
gcc/cp/ChangeLog:
* name-lookup.cc (struct local_state_t): New flag has_cfun.
(local_state_t::save_and_clear): Set has_cfun, call
push_function_context iff there's a cfun to save.
(local_state_t::restore): call pop_function_context if
has_cfun is set.
(maybe_push_to_top_level): Delegte push_function_context to
local_state_t::save_and_clear.
(maybe_pop_from_top_level): Delegate pop_function_context to
local_state_t::restore.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-pr123663.C: New test.
* g++.dg/template/pr123354.C
Reviewed-by: Jason Merrill <jason@redhat.com> Reviewed-by: Patrick Palka <ppalka@redhat.com> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Sandra Loosemore [Sun, 25 Jan 2026 22:43:58 +0000 (22:43 +0000)]
Fix gcc-urlifier selftest failure
My recent commits for PR122243 added index entries for -fno-* options
as well as their normal positive forms. Apparently the "urlifier"
used to insert option URLS into diagnostic messages can find the
anchor for either form, but its self-tests are hard-wired to match
only the positive form for the two specific options it's looking up.
This patch robustifies it to allow it to match the anchor for either
the positive or negative forms.
gcc/ChangeLog
* gcc-urlifier.cc (test_gcc_urlifier): Match either positive
or negative option URLS.
Iain Sandoe [Sat, 24 Jan 2026 14:22:43 +0000 (14:22 +0000)]
c++: Do not mark STATEMENT_LISTs as visited in genericization.
This addresses a latent issue in C++ genericization (only seen
in development code, so far).
In the following code snippet using facilities from the proposed
C++26 contracts implementation:
while (!SWAPPER::isFinished()) {
uc = SWAPPER::swapBytes();
if (0 != uc) {
}
}
contract_assert( translator.d_capacity >= 1 );
During genericization, a statement list from the while loop is freed.
The expansion of the contract_assert then requires a 'new' statement list.
Since the statment list in the while has been visited, it was marked as
such.
A specific property of statement lists is that they are cached using a
LIFO stack. So that the statement list picked for the contract_assert
is the one freed from the while loop. However since that list entry
has already been marked as visited, the newly created contract expansion
is not visited (leading to an ICE).
The solution here is to forgo marking STATEMENT_LISTs as visited in this
code (which is provision for potential future cases, as well as resolving
the specific instance seen).
gcc/cp/ChangeLog:
* cp-gimplify.cc (cp_genericize_r): Do not mark STATEMENT_LISTs
as visited.
Roger Sayle [Sun, 25 Jan 2026 21:06:39 +0000 (21:06 +0000)]
PR middle-end/122348: ICE in store_constructor from flexible array member
This patch resolves PR middle-end/122348, an ICE caused by passing a
initialized structure containing a flexible array member by value.
The semantics in C99 (and since gcc 4.4) are that the zero sized array
at the end of the structure is ignored when passing by value. Hence
for the structure in the PR:
struct S {
int a;
int b[];
} s = { 0, { 42 } };
when passed by value, sizeof(s) is considered to be 4 bytes, and on
x86_64 passed in the 32-bit %edi register. Unfortunately, the code
in store_constructor isn't expecting initialized fields where the
type's DECL_SIZE is NULL, which leads to the ICE. Fixed by explicitly
ignoring fields where DECL_SIZE is NULL_TREE. On x86_64, passing "s"
now compiles to just:
f: xorl %edi, %edi
jmp foo
2026-01-25 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
PR middle-end/122348
* expr.cc (store_constructor): Ignore fields where DECL_SIZE
is NULL_TREE, i.e. flexible array members.
gcc/testsuite/ChangeLog
PR middle-end/122348
* g++.dg/pr122348.C: New C++ testcase.
* gcc.dg/pr122348.c: New C testcase.
Sandra Loosemore [Sat, 24 Jan 2026 21:37:40 +0000 (21:37 +0000)]
doc: whitespace fixes in option summary
We should be consistently using two spaces between options on the same
line in @gccoptlist environments, in order to visually distinguish
options that take a separate argument (with only one space).
e.g.
-foo @var{arg} -bar
Most places in the Option Summary section follow this convention already
but people have not always been consistent about it when adding
new options.
gcc/ChangeLog
* doc/invoke.texi (Option Summary): Fix whitespace in @gccoptlist
tables.
Sandra Loosemore [Sat, 10 Jan 2026 01:04:56 +0000 (01:04 +0000)]
doc: Fix various option documentation problems [PR122243]
This patch fixes a number of minor problems I found after my initial
pass through the options documentation; a few options still missing
documentation, options documented but missing entries in the index or
option summary, options whose names were misspelled in either the main
entry, option summary, or index, etc.
gcc/ChangeLog
PR other/122243
* doc/cppdiropts.texi: Document -imultiarch.
* doc/invoke.texi (Option Summary) <Optimization Options>: Add
-flto-toplevel-asm-heuristics.
<Program Instrumentation Options>: Remove -fbounds-check.
<Directory Options>: Add -imultiarch.
<ARC Options>: Add -mbitops, -mcmem, -munaligned-access.
<ARM Options>: Add -mvectorize-with-neon-quad and
-mvectorize-with-neon-double.
<AVR Options>: Add -mrmw and -mstrict-X.
<CRIS Options>: Fix typo in -mmax-stackframe.
<Cygwin and MinGW Options>: Add -muse-libstdc-wrappers.
<M680x0 Options>: Add several missing CPU options, plus -mxtls.
<MIPS Options>: Add -mno-data-in-code and -mcode-xonly.
<MMIX Options>: Add mset-data-start, -mset-program-start, and
-mno-set-program-start.
<Nvidia PTX Options>: Add -msoft-stack-reserve-local.
<RS/6000 and PowerPC Options>: Add -mprofile-kernel, -mbit-word,
-mno-splat-word-constant, -mno-splat-float-constant,
-mno-ieee128-constant, and -mno-warn-altivec-long.
(Optimization Options): Document -flto-toplevel-asm-heuristics.
(ARC Options): Document -mbitops and -mcmem.
(ARM Options): Add index entries for mbe32,
m[no-]fix-cortex-a57-aes-1742098, m[no-]fix-cortex-a72-aes-1655431.
Document -mvectorize-with-neon-quad and -mvectorize-with-neon-double.
(AVR Options): Document -mpmem-wrap-around.
(CRIS Options): Fix typo in -mmax-stackframe.
(Cygwin and MinGW Options): Document -muse-libstdc-wrappers.
(DEC Alpha Options): Fix typo in -mfp-regs.
(eBPF Options): Add @opindex for -mframe-limit.
(HPPA Options): Fix typos in -mno-disable-fpregs and -mno-gas
index entries.
(m680x0 Options): Document -m68302, -m68332, -m68851, and -mfidoa.
Document -mnoshort and -mnortd aliases. Document -mxtls.
(MCore Options): Fix typos in -m[no-]relax-immediates.
(MIPS Options): Document -mno-data-in-code and -mcode-xonly.
(MMIX Options): Document -mset-data-start, -mset-program-start, and
-mno-set-program-start.
(Nvidia PTX Options): Document -msoft-stack-reserve-local.
(RS/6000 and PowerPC Options): Document -mprofile-kernel,
-mbit-word, -msplat-word-constant, -msplat-float-constant,
-mieee128-constant, and -mwarn-altivec-long.
(SH Options): Add index entry for -m2e. Document -m4-400.
Sandra Loosemore [Sun, 25 Jan 2026 00:40:51 +0000 (00:40 +0000)]
doc: Mark more options as Undocumented/RejectNegative [PR122243]
In reviewing the autogenerated list of remaining undocumented options
after my first pass through the whole chapter, I found several more
options I'd previously overlooked that should either be marked
Undocumented, or that were missing a RejectNegative attribute where
one was plainly appropriate.
gcc/c-family/ChangeLog
PR other/122243
* c.opt (-output-pch): Mark as Undocumented, as it seems to be
an internal option that has never been documented anyway.
(Werror-implicit-function-declaration): Mark deprecated option
that is not currently documented as Undocumented.
(fconstant-string-class=): Add RejectNegative property.
gcc/ChangeLog
PR other/122243
* common.opt (fbounds-check): Mark as Undocumented, expand comments
to explain why.
* config/frv/frv.opt (msched-lookahead=): Mark unused option as
Undocumented.
* config/m68k/m68k.opt (m68851): Add RejectNegative.
* config/nvptx/nvptx.opt (minit-regs=): Mark as Undocumented. It's
not currently documented and seems to have been introduced as a
stopgap to experiment with different implementation strategies.
* config/rs6000/476.opt (mpreserve-link-stack): Mark as Undocumented.
It seems to be an internal option that is enabled by default on the
cpu that can benefit from it.
This patch corrects the option summary for debug options, adds missing
@opindex entries, and copy-edits the option descriptions in this section
of the manual.
I also marked -gtoggle as RejectNegative; given its documented special
handling, it does not seem possible to use the negative form to override
an earlier positive option.
gcc/ChangeLog
PR other/122243
* common.opt (gtoggle): Mark RejectNegative.
* doc/invoke.texi (Option Summary) <Debugging Options>: Remove
redundant -gno- forms from the list.
(Debugging Options): Add @opindex for -gno- option forms.
Copy-edit option descriptions to avoid future tense and use of
implementor jargon.
Xin Wang [Sat, 24 Jan 2026 23:54:46 +0000 (23:54 +0000)]
libgcc: Use UTItype with mode(TI) for 16-byte atomics
The use of UOItype with mode(OI) for 16-byte atomic operations is
non-standard. The OI mode is not defined in machmode.def and exists
only as an ad-hoc construct in libgcc/sync.c.
This patch replaces it with UTItype using mode(TI), which is the
standard GCC machine mode for 16-byte integers (Tetra Integer).
The size argument is also corrected from 8 to 16 to match the actual
operand width.
libgcc/ChangeLog:
* sync.c: Replace UOItype with UTItype and use mode(TI) pass 16, not
8, to DEFINE macro.
Andrew Pinski [Sat, 24 Jan 2026 07:13:25 +0000 (23:13 -0800)]
SLSR: Wrong type sometimes for rhs2 with pointers [PR123803]
I messed up one of the new gimple_convert when there is
still a pointer type (with -fwrapv-pointer or -fno-strict-overflow).
The newrhs2 should be converted into sizetype instead of the type
of the lhs. Other places were already done correctly, it was
just in replace_rhs_if_not_dup which was broken this way.
Pushed as obvious after bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/123803
gcc/ChangeLog:
* gimple-ssa-strength-reduction.cc (replace_rhs_if_not_dup): For
pointer lhs use sizetype.
gcc/testsuite/ChangeLog:
* gcc.dg/pr123803-1.c: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Jerry DeLisle [Sat, 24 Jan 2026 02:52:34 +0000 (18:52 -0800)]
Fortran: Fix missed finalization
PR fortran/123772
gcc/fortran/ChangeLog:
* trans.cc: Add global variable is_assign_call.
(gfc_finalize_tree_expr): Derived type function results
with components that have defined assignements are
handled in resolve.cc(generate_component_assignments), unless
the assignment was replaced by a subroutine call to the
subroutine associated with the assignment operator.
(trans_code): In the case of EXEC_ASSIGN_CALL, set the
is_asign_call before calling gfc_trans_call, then clear it
after.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr123772.f03: New test.
Signed off by: Andrew Benson <abensonca@gcc.gnu.org>
Jose E. Marchesi [Sat, 24 Jan 2026 15:58:51 +0000 (16:58 +0100)]
a68: build a68 type nodes before targetm.init_builtins [PR algol68/123785]
The alpha target calls type_for_mode in init_builtins. The algol68
implementation of type_for_mode uses modes created by
a68_build_a68_type_nodes. This patch makes sure that the later is
called before the init_builtins target hook.
Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>
gcc/algol68/ChangeLog
Jakub Jelinek [Sat, 24 Jan 2026 09:38:17 +0000 (10:38 +0100)]
c++: Fix wrong-code with overloaded comma and CPP_EMBED [PR123737]
In cp_parser_expression for comma operator I've used a short path
where instead of calling build_x_compound_expr #embed number times
it is called just 3 times, for the CPP_NUMBER added by the preprocessor
at the start, last byte from CPP_EMBED and then CPP_NUMBER added by
libcpp at the end, enough to make sure -Wunused-value reports something,
but not bothering users with millions of -Wunused-value warnings
and spending too much compile time on it when they use a very large #embed.
As the following testcases show, that is ok for C or for C++ if the
expression before it is known not to have OVERLOAD_TYPE_P (common case
is INTEGER_TYPE I guess), but doesn't work well in case one uses overloaded
comma operator. In that case we just have to call build_x_compound_expr
the right number of times, even if it is a lot.
I think I don't need to test for !expression, because the preprocessor
should guarantee that CPP_EMBED is preceded by CPP_NUMBER CPP_COMMA
tokens.
2026-01-24 Jakub Jelinek <jakub@redhat.com>
PR c++/123737
* parser.cc (cp_parser_expression): Don't handle CPP_EMBED just
as the last byte in it if expression has or might have overloaded
type. In that case call build_x_compound_expr for each byte
in CPP_EMBED separately.
* g++.dg/cpp/embed-28.C: New test.
* g++.dg/parse/comma3.C: New test.
Jakub Jelinek [Sat, 24 Jan 2026 09:36:45 +0000 (10:36 +0100)]
c++: Fix ICE on decltype on non-local structured binding inside of a template [PR123667]
The following testcases ICE when decltype (x) appears in a template
where x is a tuple based structured binding from outside of that template
(one testcase shows the sb in a function and template is a lambda within
that function, the other shows namespace scope sb referenced from a
template).
What I wrote in the comment there is true only for structured bindings
within the current template function, in that case that structured binding
indeed has to have DECL_VALUE_EXPR and lookup_decomp_type might return
NULL or might not and depending on that we should choose if it is
a tuple based structured binding and return its type or if we should
return unlowered type of expr.
But if decltype in a template refers to a structured binding elsewhere,
it could have been finalized already and determined to be tuple based
structured binding, so DECL_HAVE_VALUE_EXPR_P can be false in that case.
In that case, if ptds.saved would be false, we'd just always
return lookup_decomp_type. So, for this case the patch allows
that case in the assert and asserts lookup_decomp_type returned non-NULL.
2026-01-24 Jakub Jelinek <jakub@redhat.com>
PR c++/123667
* semantics.cc (finish_decltype_type): Allow a structured binding
for ptds.saved to have DECL_HAS_VALUE_EXPR_P cleared, if it is
not within current_function_decl, but in that case assert that
lookup_decomp_type succeeded.
* g++.dg/cpp1z/decomp66.C: New test.
* g++.dg/cpp1z/decomp67.C: New test.
Jakub Jelinek [Sat, 24 Jan 2026 08:56:23 +0000 (09:56 +0100)]
c++: Fix ICE on namespace attributes [PR123684]
The following testcase ICEs sionce my r14-650 PR109756 change to
set TREE_VALUE (attr) to error_mark_node for unsupported attributes
for which we've just skipped over balanced tokens for arguments in order
to differentiate that from no arguments.
The problem is that handle_namespace_attrs doesn't go through the normal
attribute handling and just checked attributes by name.
So, if user uses [[visibility (whatever)]] or
[[whatever::visibility (whatever)]] or similarly abi_tag or for deprecated
(which is valid as both [[deprecated ("foo")]] and
[[gnu::deprecated ("foo")]] ) [[whatever::deprecated (whatever)]] on
a namespace, we handle it as if it was a gnu or gnu or standard attribute
even when it is not and can ICE on error_mark_node attributes.
The following patch makes sure we handle it only in the right namespaces
and emit a warning on anything else.
Not sure about backports, the patch changes behavior for say
inline namespace [[foo::abi_tag]] N or
inline namespace [[abi_tag]] N where previously it would use the name
of the namespace as abi tag and now it will ignore it and emit a warning.
One possibility is to just deal with args == error_mark_node and warn
on that attribute only in that case (that is where it would previously ICE).
But perhaps I'm worrying too much and no code in the wild is relying on
non-gnu attributes on namespaces with the same names as the gnu ones
behaving like the gnu ones.
2026-01-24 Jakub Jelinek <jakub@redhat.com>
PR c++/123684
* name-lookup.cc (handle_namespace_attrs): Only handle visibility and
abi_tag attributes in the gnu namespace and deprecated attribute in
the standard or gnu namespaces.
Joseph Myers [Fri, 23 Jan 2026 21:14:31 +0000 (21:14 +0000)]
testsuite: Enable cross testing for gcov tests
Tests of gcov are generally restricted to { target native }. The
issue for these tests is the need to transfer .gcda files from the
target to the host before running gcov. Implement that support and
remove the { target native } restrictions for these tests.
Note that by default code built to generate coverage data expects to
be able to write .gcda files to the same directory name in which the
compiler generated its output, so if that path cannot be created by
the tests on the target then they may still not work in a cross setup.
Other options involving -fprofile-dir are possible but involve their
own complications such as mangling of the .gcda file name (the
mangling logic would then need replicating in gcov.exp). Copying
files from the target using such absolute directory paths is what
already happens with gcc.dg/tree-prof tests using profopt.exp (and
those already work in a cross configuration except for a few using
dg-additional-sources), so this change is effectively making the gcov
tests work more like the tree-prof ones.
Note also that [remote_file host absolute ...] may require appropriate
support in your host board file for the case of a remote host (this
isn't an operation DejaGnu knows about doing remotely by default).
The logic for determining .gcda paths does mean it's the absolute path
on host, not on build, that is relevant.
Tested for x86_64-pc-linux-gnu to make sure native testing isn't
broken, and with cross to aarch64-linux.
Andrew Pinski [Fri, 23 Jan 2026 20:29:17 +0000 (12:29 -0800)]
aarch64/testsuite: Fix test_frame_*.c
The problem here is the test function is now being
inlined into main but that was not expected.
So mark the test functions with noinline and noclone
fixes the issue.
Pushed as obvious after testing to make sure the
test_frame_*.c testcases now work.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/test_frame_common.h (t_frame_pattern):
Add noclone and noinline to the defining test function.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>