Commit Graph

226714 Commits

Author SHA1 Message Date
Johannes Altmanninger
b0db0df2b2 c++: -Wunused-value on ternary indexed by non-constant
On this expression:

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

"g++ -Wunused-value" incorrectly produces

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

From the -fdump-tree-original output:

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

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

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

gcc/cp/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

Signed-off-by: Johannes Altmanninger <aclopte@gmail.com>
Co-authored-by: Jason Merrill <jason@redhat.com>
2026-01-28 10:30:20 +08:00
Nina Ranns
9a8c08aaad c++, contracts: Add caller-side contract checks, and controls.
This a (currently GCC-only) extension that implements caller-side
checking of pre and post conditions.  It is completely in scope
with the C++26 CDIS wording, but is not mandated.

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

gcc/c-family/ChangeLog:

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

gcc/cp/ChangeLog:

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2026-01-28 01:26:26 +00:00
Nina Ranns
64674a295b c++, contracts: Allow contract checks as outlined functions.
In this variant of the contracts handling, we emit the contract
checks for pre and post conditions into small TU-local functions
that are then called in the relevant positions at the start of
the function and on each return edge (as a try-finally).

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

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

gcc/c-family/ChangeLog:

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

gcc/cp/ChangeLog:

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2026-01-28 01:26:10 +00:00
Iain Sandoe
7f914294fe c++, contracts: Add tests for C++26 contracts.
This adds in a set of tests for the C++26 contracts, and also ensures that
cases that previously failed with attribute syntax continue to work as
expected with the revised C++26 syntax.

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

gcc/testsuite/ChangeLog:

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

Co-Authored-by: Nina Ranns <dinka.ranns@gmail.com>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2026-01-28 01:25:47 +00:00
Nina Ranns
fbde291af6 libstdc++, contracts: Add base P2900R14 contracts support.
What we need to do here (and, of course, in the code synthesis
that produces the objects) needs to be interoperable with other
platforms that share ABI.  For the present, this means Itanium
and to interoperate with clang and libc++.

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

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

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

libstdc++-v3/ChangeLog:

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

Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Nina Ranns <dinka.ranns@gmail.com>
2026-01-28 01:25:12 +00:00
Nina Ranns
080b1cb5e4 c++, contracts: Apply P200R14 constification.
Split from the main patch as it was potentially contentious and might
have been altered by WG21 NB comment resolution. However, it most likely
makes sense to review in isolation (although we would expect to apply it
squashed into the base patch).

gcc/cp/ChangeLog:

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

gcc/ChangeLog:

	* tree.h (CONST_WRAPPER_P): New.

gcc/ChangeLog:

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

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
Co-authored-by: Iain Sandoe <iain@sandoe.co.uk>
2026-01-28 01:24:51 +00:00
Nina Ranns
cac79586e1 c++, contracts: Work around GCC IPA bug, PR121936 by wrapping terminate.
This implements a no-ipa wrapper around the calls made from terminating
contract assertions so that callers can no longer make assuptions about
the no-return behaviour.  This is sufficient to work around the reported
bug while a suitable general fix is evaluated.

gcc/c-family/ChangeLog:

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

gcc/cp/ChangeLog:

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

gcc/ChangeLog:

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

Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2026-01-28 01:24:17 +00:00
Iain Sandoe
c928dc5196 c++, contracts: C++26 base implementation as per P2900R14.
This implementation performs the contracts application in three
phases:
    1. Parsing and semantic checks.
       Most of the code for this is in the parser, with helpers provided here.
    2. Emitting contract assertion AST nodes into function bodies.
       This is initiated from "finish_function ()"
    3. Lowering the contract assertion AST nodes to control flow, constant
       data and calls to the violation handler.
       This is initiated from "cp_genericize ()".

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

gcc/c-family/ChangeLog:

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

gcc/ChangeLog:

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

gcc/cp/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

Co-Authored-by: Nina Ranns <dinka.ranns@gmail.com>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2026-01-28 01:23:34 +00:00
Iain Sandoe
918aa3fe87 c++, contracts: Add a contract scope per basic.scope.contract.
This adds a scope for contract assertions as per the standard section
referenced.  Split out here because it is the only part of the implementation
that touches the name lookup files.

gcc/cp/ChangeLog:

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

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2026-01-28 01:23:18 +00:00
Iain Sandoe
4e1f6865ac c++, contracts: Remove the abandoned C++2a implementation.
The C++26 contracts design bears little relationship with the abandoned C++2a one.
While we have, where possible, attempted to re-use code, the underlying syntax and
implementation are divergent.

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

gcc/c-family/ChangeLog:

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

gcc/cp/ChangeLog:

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

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

Co-Authored-by: Nina Ranns <dinka.ranns@gmail.com>

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2026-01-28 01:22:20 +00:00
GCC Administrator
a6201597c4 Daily bump. 2026-01-28 00:16:36 +00:00
Iain Buclaw
8e869a0d0e d: Side effects not evaluated for array literals on stack [PR120096]
PR d/120096

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

	* gdc.dg/torture/pr120096.d: New test.
2026-01-27 23:35:24 +01:00
Rainer Orth
20bc4561ec 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.
2026-01-27 23:25:12 +01:00
David Malcolm
f1318516f0 analyzer: add option -fanalyzer-assume-nothrow [PR122623]
As of r16-264-g7a39e0ca0652ff, -fanalyzer assumes that a call to an
external function not marked with attribute "nothrow" could throw an
exception, if -fexceptions is enabled.

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

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

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

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

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

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

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2026-01-27 16:36:29 -05:00
Andrew Pinski
9438c98dca 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>
2026-01-27 13:21:23 -08:00
Joseph Myers
869a5a70f7 Update gcc sv.po
* sv.po: Update.
2026-01-27 21:15:03 +00:00
Qing Zhao
078b0a2be2 C: Do not warn for calls to .ACCESS_WITH_SIZE when -Wbad-function-cast is specified [PR123500]
For the following source code:

(uintptr_t)b->ptr;

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

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

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

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

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

	PR c/123500

gcc/c/ChangeLog:

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

gcc/testsuite/ChangeLog:

	* gcc.dg/pointer-counted-by-pr123500.c: New test.
2026-01-27 20:46:04 +00:00
Iain Buclaw
a321508c1b d: Fix root modules have no file location set [PR122817]
PR d/122817

gcc/d/ChangeLog:

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

gcc/testsuite/ChangeLog:

	* gdc.dg/pr122817.d: New test.
2026-01-27 21:35:25 +01:00
Jan Hubicka
fe050fa9d1 Remove impossible speculation in ipa_polymorphic_call_context::possible_dynamic_type_change
This patch makes ipa-cp dataflow monotone by making sure we do not use speculation that
was proved to be impossible earlier.

gcc/ChangeLog:

	PR ipa/123619
	* ipa-polymorphic-call.cc
	(ipa_polymorphic_call_context::possible_dynamic_type_change): Remove impossible
	speuculation.
2026-01-27 19:20:34 +01:00
Rainer Orth
0e240e22ce build: Unifiy 32 and 64-bit linker options
Similarly to assembler option handling in gcc/configure.ac, selecting
linker options to control 32 or 64-bit output is handled in various
different ways all over the place.

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

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

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

	gcc:
	* configure.ac (ld_32_opt, ld_64_opt): Set.
	(ld_ix86_gld_32_opt): Replace by ld_32_opt.
	(ld_ix86_gld_64_opt): Replace by ld_64_opt.
	Replace -melf_x86_64 by ld_64_opt.
	* configure: Regenerate.
2026-01-27 19:16:53 +01:00
Rainer Orth
5fc4e333b4 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.
2026-01-27 19:15:36 +01:00
Rainer Orth
f75fe68437 build: Only use --fatal-warnings if assembler supports it
On Solaris/x86 with the native as, two tests currently FAIL:

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

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

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

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

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

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

	gcc:
	* configure.ac (fw_as_opt): Set.
	Replace --fatal-warnings by $fw_as_opt.
	(tls_as_opt): Remove --fatal-warnings.
	(gcc_cv_as_tls): Use $fw_as_opt.
	* configure: Regenerate.
2026-01-27 19:11:11 +01:00
Richard Biener
ef652d7bd4 ipa/116296 - avoid overflow in modref_access_node::contains
The following aovids overflow when scaling the param offset
difference by BITS_PER_UNIT by using poly_offset_int instead of
poly_int64 for the computations.

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

	* gcc.dg/torture/pr116296.c: New testcase.
2026-01-27 15:59:55 +01:00
Richard Biener
b227c79c43 debug/123376 - mangle decls referenced in initializers early
The following makes sure to mangle decls referenced in initializers,
even when of aggregate type, during the early debug phase since
later we eventually leave stray supposedly unused CV qualified
types as their own main variant which confuses C++ mangling.  The
comment that refers to rtl_for_decl_init punting might be
accurate, but loc_list_from_tree_1 will happily see to
cst_pool_loc_descr where constant pool lookup will eventually
create DECL_RTL of referenced symbols, triggering mangling.

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

	* g++.dg/lto/pr123376_0.C: New testcase.
2026-01-27 15:59:55 +01:00
Christophe Lyon
858392b691 testsuite: arm: Add another expected output in vdupq_n_f32.c
Depending on how GCC was configured, default -mtune parameter can load
the floating-point constant using either:
    movw    r3, #52429
    movt    r3, 16268
    or
    ldr     r3, .L4

Update the expected code to accept both versions.

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

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

	gcc/testsuite/
	* gcc.target/arm/mve/intrinsics/vdupq_n_f32.c: Update expected
	code.
2026-01-27 14:43:04 +00:00
Robin Dapp
0accf2b4df forwprop: Pun with integer type if needed [PR123799].
We cannot directly build vectors from BitInts, which this patch
circumvents by punning  the conversion element type with an integer
type.  This results in two separate conversions at the gimple level.
Those don't appear to cause worse final code, though.  It is possible to
merge those two conversions at the construction site but from what I can
tell would involve more changes than necessary now, so I refrained from
it.

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

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

	PR tree-optimization/123799

gcc/ChangeLog:

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

gcc/testsuite/ChangeLog:

	* gcc.dg/torture/pr123799.c: New test.
2026-01-27 13:26:20 +01:00
Tobias Burnus
1284cefa89 Fortran/OpenMP: Reject device-local var in MAP clause
gcc/fortran/ChangeLog:

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

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/groupprivate-7.f90: New test.
2026-01-27 13:05:27 +01:00
Wilco Dijkstra
66a2e71370 fortran: Allow vector math functions only with fast-math [PR 118955]
Vector math functions are currently always enabled in Fortran.  This is
incorrect since vector math functions are designed to be Ofast only.
Add a new 'fastmath' option which only accepts vector functions if fast-math
is enabled:

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

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

gcc/testsuite:
	PR fortran/118955
	* gfortran.dg/simd-builtins-9.f90: Add new test.
	* gfortran.dg/simd-builtins-9.h: Likewise.
2026-01-27 11:45:16 +00:00
Wilco Dijkstra
4fb8b2a1fc 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.
2026-01-27 11:34:16 +00:00
Wilco Dijkstra
3cb7c85eeb AArch64: Allow invert for shift counts [PR 123792]
Optimize 1 << (31 - x) into 1 << ~x. This fixes part of PR 123792.

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

gcc/testsuite:
	PR target/123792
	* gcc.target/aarch64/pr123792.c: New test.
2026-01-27 11:33:10 +00:00
Tobias Burnus
5e7ccdb6d4 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.
2026-01-27 11:52:00 +01:00
Nathaniel Shead
aaa06bae53 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>
2026-01-27 21:50:42 +11:00
Jakub Jelinek
9b7b6a4075 c++: Implement CWG3153 - Immediate-escalating defaulted comparison
The following patch implements the
https://cplusplus.github.io/CWG/issues/3153.html
core issue proposal.

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

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

	* g++.dg/reflect/cwg3153.C: New test.
2026-01-27 10:24:49 +01:00
Jakub Jelinek
de19477814 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.

	* g++.dg/reflect/pr123404.C: New test.
2026-01-27 10:23:43 +01:00
Jakub Jelinek
d341b0d57f 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.

	* g++.dg/cpp2a/pr123578.C: New test.
2026-01-27 10:19:39 +01:00
Frank Scheiner
c86745f4f6 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.

[1]: https://gcc.gnu.org/pipermail/gcc-testresults/2025-December/865397.html

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.

Fixes r10-2142-gec8ac265ff21fb as per [2].

[2]: https://gcc.gnu.org/pipermail/gcc-patches/2026-January/705638.html

gcc/testsuite/ChangeLog:
	* gcc.dg/guality/guality.exp: Only test with LTO if supported.
	* g++.dg/guality/guality.exp: Likewise.

Signed-off-by: Frank Scheiner <frank.scheiner@web.de>
2026-01-27 09:17:39 +00:00
Tamar Christina
cb40e813b8 middle-end: teach convert_mult_to_fma handle casts between addend and multiplicant [PR122749]
The following example

int foo2 (char *buf, int len) {
    int x;
    for (int i =0; i < len; i++) {
        x += (int) i * buf[i];
    }
    return x;
}

compiled with -O3 -mcpu=neoverse-v2 used to generate a 4x unrolled MLA sequence

        mla     z29.s, p7/m, z2.s, z0.s
        mla     z27.s, p7/m, z4.s, z26.s
        mla     z30.s, p7/m, z1.s, z0.s
        mla     z28.s, p7/m, z23.s, z3.s

but now generates MUL + ADD

        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.

Concretely, it converts:

  # vect_vec_iv_.13_49 = PHI <_50(5), { 0, 1, 2, ... }(4)>
  vect__3.8_38 = MEM <vector([4,4]) char> [(char *)_16];
  vect__4.12_45 = (vector([4,4]) int) vect__3.8_38;
  vect__5.14_54 = vect__4.12_45 * vect_vec_iv_.13_49;
  vect_x_12.17_62 = VIEW_CONVERT_EXPR<vector([4,4]) unsigned int>(vect__5.14_54);
  vect_x_12.17_63 = VIEW_CONVERT_EXPR<vector([4,4]) unsigned int>(vect_x_16.15_58);
  vect_x_12.17_64 = vect_x_12.17_62 + vect_x_12.17_63;
  vect_x_12.16_65 = VIEW_CONVERT_EXPR<vector([4,4]) int>(vect_x_12.17_64);

into:

  # vect_vec_iv_.13_49 = PHI <_50(5), { 0, 1, 2, ... }(4)>
  vect__3.8_38 = MEM <vector([4,4]) charD.8> [(charD.8 *)_16];
  vect__4.12_45 = (vector([4,4]) intD.7) vect__3.8_38;
  vect_x_12.17_63 = VIEW_CONVERT_EXPR<vector([4,4]) unsigned int>(vect_x_16.15_58);
  _2 = (vector([4,4]) unsigned int) vect_vec_iv_.13_49;
  _1 = (vector([4,4]) unsigned int) vect__4.12_45;
  vect_x_12.17_64 = .FMA (_1, _2, vect_x_12.17_63);
  vect_x_12.16_65 = VIEW_CONVERT_EXPR<vector([4,4]) intD.7>(vect_x_12.17_64);

thus restoring FMAs on reductions.

gcc/ChangeLog:

	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.
2026-01-27 09:12:16 +00:00
Patrick Palka
22f51c0f5e 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.

gcc/testsuite/ChangeLog:

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

Reviewed-by: Jason Merrill <jason@redhat.com>
2026-01-26 22:00:16 -05:00
Patrick Palka
9cb5c879e7 c++: leaky uid-sensitive constexpr evaluation [PR122494, PR123814]
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.

Reviewed-by: Jason Merrill <jason@redhat.com>
2026-01-26 21:59:48 -05:00
GCC Administrator
e8b4d34ed1 Daily bump. 2026-01-27 00:16:29 +00:00
David Malcolm
c28dd8467b analyzer: avoid calling binding_map::const_iterator::operator* [PR123145]
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>
2026-01-26 18:57:51 -05:00
Iain Buclaw
4626921de2 libphobos: Bump soname to version 7 [PR122800]
Each major release is not binary compatible with the previous.

	PR d/122800

libphobos/ChangeLog:

	* configure: Regenerate.
	* configure.ac (libtool_VERSION): Update to 7:0:0.
2026-01-26 20:15:20 +01:00
Andrew Pinski
d1b30abe52 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>
2026-01-26 11:10:57 -08:00
Andrew Pinski
3ec1d59c17 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>
2026-01-26 11:10:57 -08:00
Joseph Myers
e373a57b07 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.
2026-01-26 16:49:29 +00:00
Karl Meakin
a33091a696 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`.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/sve/pcs/asm_1.c
	* gcc.target/aarch64/sve/pcs/asm_3.c: Fix tests.
2026-01-26 15:57:21 +00:00
Karl Meakin
939cebe693 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.

gcc/testsuite/ChangeLog:

	* g++.target/aarch64/sve/acle/general-c++/mangle_5.C: Fix test.
2026-01-26 15:24:00 +00:00
Karl Meakin
2591468a54 aarch64: fix XAR tests
Some tests were failing because the pattern was not accounting for the
`#` before the immediate argument.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/rotate_xar_1.c
	* gcc.target/aarch64/sha3_1.c
	* gcc.target/aarch64/sha3_2.c
	* gcc.target/aarch64/sha3_3.c
	* gcc.target/aarch64/xar_v2di_nonsve.c: Fix tests.
2026-01-26 15:24:00 +00:00
Pietro Monteiro
59d70a96c8 Generate Algol 68 front end Coding Guidelines
maintainer-scripts/ChangeLog:

	* update_web_docs_git (MANUALS): Add ga68-coding-guidelines.

Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
2026-01-26 10:05:16 -05:00
Filip Kastl
1a93153dac doc: Document --param auto-profile-reorder-only
This patch adds --param auto-profile-reorder-only into invoke.texi and
fixes spelling in its description.

gcc/ChangeLog:

	* doc/invoke.texi: Document --param auto-profile-reorder-only.
	* params.opt: Fix spelling.

Signed-off-by: Filip Kastl <fkastl@suse.cz>
2026-01-26 15:32:19 +01:00