195928 Commits

Author SHA1 Message Date
Nathan Sidwell
c7cb239f51 c++: Lambda context mangling
VAR and FIELD decls can become part of a lambda context, when the
lambda is 'attached' to that entity (It's a C++20 ODR thing that was
discovered with modules, but is actually separate.)  We were not
marking those decls as substitution candidates, leading to demangling
failures and variance from other compilers.

This patch bumps the ABI, and adds the contexts them to the
substitution table.  This is the intent of the ABI.

	gcc/
	* common.opt (-fabi-version=): Document 18.
	* doc/invoke.texi (-fabi-version): Document 18.
	gcc/c-family/
	* c-opts.cc (c_common_post_options): Bump abi to 18.
	gcc/cp/
	* mangle.cc (write_prefix): Add VAR_DECL & FIELD_DECL to
	substitution table under abi=18.  Note possible mismatch.
	gcc/testsuite/
	* g++.dg/abi/lambda-ctx1-17.C: New.
	* g++.dg/abi/lambda-ctx1-18.C: New.
	* g++.dg/abi/lambda-ctx1-18vs17.C: New.
	* g++.dg/abi/lambda-ctx1.h: New.
	* g++.dg/abi/lambda-vis.C: Adjust expected mangles.
	* g++.dg/abi/macro0.C: Adjust.
2022-10-10 18:13:47 -04:00
Ian Lance Taylor
29b0fe3938 compiler: treat S("") as a string constant
The compiler neglected to notice that a conversion from a string
constant to a string type was a valid string constant.

No test case because this only caused a compiler failure when compiling
without optimization, which is not the normal case, and is not a case
that we test.

Fixes golang/go#56113

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/441555
2022-10-10 14:45:57 -07:00
Ian Lance Taylor
0f6efd34c2 compiler: only build thunk struct type when it is needed
Instead of building the thunk struct type in the determine_types pass,
build it when we need it.  That ensures that we are consistent in
determining whether an argument is constant.

We no longer need to add a field for a call to recover, as the
simplify_thunk_statements pass runs after the build_recover_thunks pass,
so the additional argument will already have been added to the call.

The test case is https://go.dev/cl/440297.

Fixes golang/go#56109

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/440298
2022-10-10 14:27:17 -07:00
Jonathan Wakely
1d2f07ed4c libstdc++: Revert addition of constraints to make_signed/make_unsigned
Constraining the primary template makes it unusable in uninstantiated
contexts.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (make_signed, make_unsigned): Remove
	constraints on primary template.
	* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
	Undo changes to expected error in C++20 mode.
	* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
	Likewise.
	* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
	Likewise.
	* testsuite/20_util/make_signed/requirements/uninstantiated.cc:
	New test.
	* testsuite/20_util/make_unsigned/requirements/uninstantiated.cc:
	New test.
2022-10-10 21:37:03 +01:00
Marek Polacek
67efffec94 c-family: ICE with [[gnu::nocf_check]] [PR106937]
When getting the name of an attribute, we ought to use
get_attribute_name, which handles both [[]] and __attribute__(())
forms.  Failure to do so may result in an ICE, like here.

pp_c_attributes_display wasn't able to print the [[]] form of
attributes, so this patch teaches it to.

When printing a pointer to function with a standard attribute, the attribute
should be printed after the parameter-list.  With this patch we print:

  aka 'void (*)(int) [[gnu::nocf_check]]'

or, in C++ with noexcept:

  aka 'void (*)(int) noexcept [[gnu::nocf_check]]'

pp_c_attributes has been unused since its introduction in r56273 so
this patch removes it.

	PR c++/106937

gcc/c-family/ChangeLog:

	* c-pretty-print.cc (pp_c_specifier_qualifier_list): Print only GNU
	attributes here.
	(c_pretty_printer::direct_abstract_declarator): Print the standard [[]]
	attributes here.
	(pp_c_attributes): Remove.
	(pp_c_attributes_display): Print the [[]] form if appropriate.  Use
	get_attribute_name.  Don't print a trailing space when printing the
	[[]] form.
	* c-pretty-print.h (pp_c_attributes): Remove.

gcc/cp/ChangeLog:

	* error.cc: Include "attribs.h".
	(dump_type_prefix): Print only GNU attributes here.
	(dump_type_suffix): Print standard attributes here.

gcc/testsuite/ChangeLog:

	* c-c++-common/pointer-to-fn1.c: New test.
2022-10-10 14:16:44 -04:00
Andrea Corallo
248c8aeebc Don't ICE running selftests if errors were raised [PR99723]
Hi all

this is to address PR 99723.

In the PR GCC crashes as the initialization of common trees is not
performed as no compilation is happening, this is because we raise an
error earlier while processing the arch flags.

This patch changes the code to execute selftests only if no errors
where raised before.

Bootstrapped on aarch64, okay for trunk?

Best Regards

  Andrea

2022-09-27  Andrea Corallo  <andrea.corallo@arm.com>

	PR other/99723
	* toplev.cc (toplev::main): Don't run self tests in case of
	previous error.
2022-10-10 15:22:26 +02:00
Kito Cheng
d0bbecb1c4 RISC-V: Add riscv_vector.h wrapper in testsuite to prevent pull in stdint.h from C library
For RISC-V linux/glibc toolchain will got header file not found when including
stdint.h if multilib is not enabled, it because some header file will
try to include gnu/stubs-<ABI-NAME>.h from the system, however it only
generated when multilib enabled.

In order to prevent that, we introduce a wrapper for riscv_vector.h,
include stdint-gcc.h rather than the default stdint.h.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/base/riscv_vector.h: New.

Reported-by: Christoph Müllner <christoph.muellner@vrull.eu>
Tested-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
2022-10-10 21:10:34 +08:00
Kito Cheng
99e9796ca1 RISC-V: Adjust testcase for rvv/base/user-1.c
The -march option check isn't precise enough, -march=rv*v* also mach any
zve extensions.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/base/user-1.c: Add dg-options and drop
	dg-skip-if.

Reported-by: Christoph Müllner <christoph.muellner@vrull.eu>
Tested-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
2022-10-10 21:10:26 +08:00
Kito Cheng
684d238b8c RISC-V: Add newline to the end of file [NFC]
gcc/ChangeLog:

	* config/riscv/riscv-c.cc: Add newline to the end of file.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/base/pragma-1.c: Add newline to the end of file.
	* gcc.target/riscv/rvv/base/pragma-2.c: Ditto.
	* gcc.target/riscv/rvv/base/pragma-3.c: Ditto.
	* gcc.target/riscv/rvv/base/user-1.c: Ditto.
	* gcc.target/riscv/rvv/base/user-2.c: Ditto.
	* gcc.target/riscv/rvv/base/user-3.c: Ditto.
	* gcc.target/riscv/rvv/base/user-4.c: Ditto.
	* gcc.target/riscv/rvv/base/user-5.c: Ditto.
	* gcc.target/riscv/rvv/base/user-6.c: Ditto.
	* gcc.target/riscv/rvv/base/vread_csr.c: Ditto.
	* gcc.target/riscv/rvv/base/vwrite_csr.c: Ditto.
2022-10-10 21:08:02 +08:00
Aldy Hernandez
80cb09d4f7 Make range-op-float entries public.
gcc/ChangeLog:

	* range-op-float.cc (class foperator_identity): Make members public.
	(class foperator_equal): Same.
	(class foperator_not_equal): Same.
	(class foperator_lt): Same.
	(class foperator_le): Same.
	(class foperator_gt): Same.
	(class foperator_ge): Same.
	(class foperator_unordered): Same.
	(class foperator_ordered): Same.
2022-10-10 14:50:17 +02:00
Aldy Hernandez
e23f7dabe6 Add frange::maybe_isnan (bool sign).
It is useful to know if there's the possiblity of a NAN with a given
sign.  This is to complement maybe_isnan(void) which returns TRUE for a
NAN of any sign.

A follow-up patch implementing ABS will make use of this.

gcc/ChangeLog:

	* value-range.h (frange::maybe_isnan): New.
2022-10-10 14:50:17 +02:00
Aldy Hernandez
69988cd58b The true side of x != x should set NAN.
gcc/ChangeLog:

	* range-op-float.cc (foperator_not_equal::op1_range): Set NAN on
	TRUE side for x != x.
2022-10-10 14:50:17 +02:00
Aldy Hernandez
58fa21622b x UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side).
gcc/ChangeLog:

	* range-op-float.cc (foperator_unordered::op1_range): Set NAN when
	operands are equal and result is TRUE.
2022-10-10 14:50:16 +02:00
Aldy Hernandez
8b6bcedc88 Return non-legacy ranges in range.h.
int_range<1> is a legacy range (think anti ranges, legacy VRP, etc).
There is a penalty for converting anything built with <1> to
non-legacy.  Since most of the uses of these functions are now ranger,
we can save a miniscule amount of time by converting them to
non-legacy.

gcc/ChangeLog:

	* range.h (range_true): Return int_range<2>.
	(range_false): Same.
	(range_true_and_false): Same.
2022-10-10 14:50:16 +02:00
Jonathan Wakely
2bd112dee7 libstdc++: std::make_signed_t<cv bool> should be ill-formed
Currently we only reject std::make_signed_t<bool> but not cv bool.
Similarly for std::make_unsigned_t<cv bool>.

As well as making those ill-formed, this adds a requires-clause to the
make_signed and make_unsigned primary templates. This makes
non-integral, non-enum cases fail immediately with a clear error, rather
than giving an error about __make_signed_selector<T, false, false> being
incomplete.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (make_signed, make_unsigned): Add
	specializations for cv bool. Add requires-clause for C++20 to
	improve diagnostics for non-integral, non-enum cases.
	* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
	Check cv bool.
	* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
	Likewise.
	* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
	Adjust expected errors for C++20 and later.
	* testsuite/lib/prune.exp: Prune "in requirements  [with ...]"
	lines from diagnostics.
2022-10-10 12:19:11 +01:00
Jakub Jelinek
a99f511c57 Require fgraphite effective target for pr107153.c test [PR107153]
The test uses -floop-parallelize-all which emits a sorry when graphite
isn't configured in.

2022-10-10  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/107153
	* gcc.dg/autopar/pr107153.c: Require fgraphite effective target.
2022-10-10 12:04:56 +02:00
Aldy Hernandez
98ad452728 Add op1_range for __builtin_signbit.
This is the op1_range range-op entry for __builtin_signbit.  It allows
us to wind back through a call to signbit.

For example, on the true side of if (__builtin_signbit(x_5) != 0) we
can crop down the range of x_5 to:

	[frange] float [-Inf, -0.0 (-0x0.0p+0)] -NAN

Similarly on the false side, we can crop to:

	[frange] float [0.0 (0x0.0p+0), +Inf] +NAN

Tested on x86-64 Linux.

gcc/ChangeLog:

	* gimple-range-op.cc: Add op1_range entry for __builtin_signbit.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/vrp-float-signbit-3.c: New test.
2022-10-10 11:39:42 +02:00
liuhongt
9b8520fa9d Fix unrecognizable insn of cvtss2si.
Adjust lrintmn2 operand preidcates according to real instructions.

gcc/ChangeLog:

	PR target/107185
	* config/i386/i386.md (lrint<MODEF:mode><SWI48:mode>2): Swap
	predicate of operands[0] and operands[1].

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr107185.c: New test.
2022-10-10 15:58:04 +08:00
Jakub Jelinek
70f66a47fd openmp, fortran: Fix up IFN_ASSUME call
Like in other spots in trans-openmp.cc that create a TARGET_EXPR, the
slot has to be created with create_tmp_var_raw, because gfc_create_var
adds the var to BLOCK_VARS and that ICEs during expansion because
gimple_add_tmp_var_fn has:
  gcc_assert (!DECL_CHAIN (tmp) && !DECL_SEEN_IN_BIND_EXPR_P (tmp));
assertion.  Also, both C/C++ ensure the argument to IFN_ASSUME has
boolean_type_node, it is easier if Fortran does that too.

2022-10-10  Jakub Jelinek  <jakub@redhat.com>

	* trans-openmp.cc (gfc_trans_omp_assume): Use create_tmp_var_raw
	instead of gfc_create_var for TARGET_EXPR slot creation.  Create it
	with boolean_type_node and convert.
2022-10-10 09:38:05 +02:00
Claudiu Zissulescu
59d27853f1 arc: Remove obsolete mRcq and mRcw options.
gcc/

	* common/config/arc/arc-common.cc (arc_option_optimization_table):
	Remove Rcq and Rcw options.
	* config/arc/arc.opt (mRcq): Ignore option, preserve it for
	backwards compatibility.
	(mRcw): Likewise.
	* doc/invoke.texi (mRcw, mRcq): Update document.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2022-10-10 10:32:49 +03:00
Claudiu Zissulescu
e8f5074f48 arc: Remove Rcq constraint.
gcc/
	* config/arc/arc.cc (arc_check_short_reg_p): New function.
	(arc_address_cost): Replace satisfies_constraint_Rcq with the
	above new function.
	(arc_output_addsi): Likewise.
	(split_addsi): Likewise.
	(split_subsi): Likewise.
	* config/arc/arc.md (movqi_insn): Remove Rcq constraint.
	(movhi_insn): Likewise.
	(movsi_insn): Likewise.
	(tst_movb): Likewise.
	(tst): Likewise.
	(tst_bitfield): Likewise.
	(abssi2): Likewise.
	(addsi3_mixed): Likewise.
	(mulhisi3_reg): Likewise.
	(umulhisi3_reg): Likewise.
	(mulsi_600): Likewise.
	(mul64): Likewise.
	(subsi3_insn): Likewise.
	(bicsi3_insn): Likewise.
	(xorsi3): Likewise.
	(negsi2): Likewise.
	(one_cmplsi2): Likewise.
	(lshrsi3_insn): Likewise.
	(cmpsi_cc_insn_mixed): Likewise.
	(cmpsi_cc_zn_insn): Likewise.
	(btst): Likewise.
	(cmpsi_cc_z_insn): Likewise.
	(cmpsi_cc_c_insn): Likewise.
	(indirect_jump): Likewise.
	(casesi_jump): Likewise.
	(call_i): Likewise.
	(call_value_i): Likewise.
	(bbit): Likewise.
	(abssf2): Likewise.
	(ashlsi2_cnt1): Likewise.
	(lshrsi3_cnt1): Likewise.
	(ashrsi3_cnt1): Likewise.
	* config/arc/constraints.md (Rcq): Remove.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2022-10-10 10:32:47 +03:00
Claudiu Zissulescu
5ebbdf9c4e arc: Remove Rcw constraint
gcc/Changelog:

	* config/arc/arc.md (smaxsi3): Remove Rcw.
	(sminsi3): Likewise.
	(addsi3_mixed): Likewise.
	(add_f_2): Likewise.
	(subsi3_insn): Likewise.
	(sub_f): Likewise.
	(sub_n): Likewise.
	(bset): Likewise.
	(bxor): Likewise.
	(bclr): Likewise.
	(bset_insn): Likewise.
	(bxor_insn): Likewise.
	(bclr_insn): Likewise.
	(bmsk_insn): Likewise.
	(bicsi3_insn): Likewise.
	(xorsi3): Likewise.
	(negsi2): Likewise.
	(lshrsi3_insn): Likewise.
	(abssf2): Likewise.
	(negsf2): Likewise.
	* config/arc/constraints.md(Rcw): Remove it.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2022-10-10 10:32:44 +03:00
Claudiu Zissulescu
af681e948f arc: Remove Rcr constraint
gcc/ChangeLog:

	* config/arc/arc.md(mulsi3_700): Remove Rcr.
	(mulsi3_highpart): Likewise.
	(umulsi3_highpart_i): Likewise.
	(umulsi3_highpart_int): Likewise.
	(macd): Likewise.
	(macdu): Likewise.
	* config/arc/constraints.md (Rcr): Remove it.

gcc/testsuite/ChangeLog:
	* gcc.target/arc/tmac-2.c: Update test.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2022-10-10 10:32:36 +03:00
Claudiu Zissulescu
5e81df88ca arc: Use negative enter pattern instruction's offsets
The enter pattern instruction contains the necessary information for
the dwarf machinery to generate the appropriate dwarf code.  This
patch is fixing the register offsets related to CFA, and adds a test.

gcc/
	* config/arc/arc.cc (arc_save_callee_enter): Use negative offsets.

gcc/testsuite
	* gcc.target/arc/enter-dw2-1.c: New file.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2022-10-10 10:32:32 +03:00
LIU Hao
decbb5bf7c libgfortran: Use __gthread_t instead of pthread_t
It used to cause errors if a thread model other than `posix` was selected,
which looks like a leftover from a79878585a1c5e32bafbc6d1e73f91fd6e4293bf.

libgfortran/
	* io/async.h (struct async_unit): Use `__gthread_t` instead
	of `pthread_t`.

Signed-off-by: LIU Hao <lh_mouse@126.com>
Signed-off-by: Jonathan Yong <10walls@gmail.com>
2022-10-10 07:16:03 +00:00
GCC Administrator
570eb458c6 Daily bump. 2022-10-10 00:16:29 +00:00
Dimitar Dimitrov
e95e91eccd pru: Add cbranchdi4 pattern
Manually expanding into 32-bit comparisons is much more efficient than
the default expansion into word-size comparisons.  Note that word for PRU
is 8-bit.

	PR target/106562

gcc/ChangeLog:

	* config/pru/pru-protos.h (pru_noteq_condition): New
	function declaration.
	* config/pru/pru.cc (pru_noteq_condition): New function.
	* config/pru/pru.md (cbranchdi4): Define new pattern.

gcc/testsuite/ChangeLog:

	* gcc.target/pru/pr106562-1.c: New test.
	* gcc.target/pru/pr106562-2.c: New test.
	* gcc.target/pru/pr106562-3.c: New test.
	* gcc.target/pru/pr106562-4.c: New test.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2022-10-09 14:38:34 +03:00
Dimitar Dimitrov
73137f365a pru: Optimize DI shifts
If the number of shift positions is a constant, then the DI shift
operation is expanded to a sequence of 2 to 4 machine instructions.
That is more efficient than the default action to call libgcc.

gcc/ChangeLog:

	* config/pru/pru.md (lshrdi3): New expand pattern.
	(ashldi3): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/pru/ashiftdi-1.c: New test.
	* gcc.target/pru/lshiftrtdi-1.c: New test.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2022-10-09 14:38:34 +03:00
YunQiang Su
66c48be23e MIPS: improve -march=native arch detection
If we cannot get info from options and cpuinfo, we try to get from:
  1. getauxval(AT_BASE_PLATFORM), introduced since Linux 5.7
  2. _MIPS_ARCH from host compiler.

mnan=2008 option is also used if __mips_nan2008__ is used.
This can fix the wrong loader usage on r5/r6 platform with
 -march=native.

gcc/ChangeLog:
	* config.gcc: set with_arch to default_mips_arch if no defined.
	* config/mips/driver-native.cc (host_detect_local_cpu):
	  try getauxval(AT_BASE_PLATFORM) and _MIPS_ARCH, too.
	  pass -mnan=2008 if __mips_nan2008__ is defined.
	* config.in: define HAVE_SYS_AUXV_H and HAVE_GETAUXVAL.
	* configure.ac: detect sys/auxv.h and getauxval.
	* configure: regenerated.
2022-10-09 06:39:04 +00:00
GCC Administrator
d7346a3bf6 Daily bump. 2022-10-09 00:17:55 +00:00
Harald Anlauf
705ed42a1a Fortran: error recovery for invalid types in array constructors [PR107000]
gcc/fortran/ChangeLog:

	PR fortran/107000
	* arith.cc (gfc_arith_error): Define error message for
	ARITH_INVALID_TYPE.
	(reduce_unary): Catch arithmetic expressions with invalid type.
	(reduce_binary_ac): Likewise.
	(reduce_binary_ca): Likewise.
	(reduce_binary_aa): Likewise.
	(eval_intrinsic): Likewise.
	(gfc_real2complex): Source expression must be of type REAL.
	* gfortran.h (enum arith): Add ARITH_INVALID_TYPE.

gcc/testsuite/ChangeLog:

	PR fortran/107000
	* gfortran.dg/pr107000.f90: New test.

Co-authored-by: Mikael Morin <mikael@gcc.gnu.org>
2022-10-08 21:19:26 +02:00
Jason Merrill
6ffbf87ca6 c++: track whether we expect a TARGET_EXPR to be elided
A discussion at Cauldron made me think that with the formalization of copy
elision in C++17, we should be able to determine before optimization which
TARGET_EXPRs will become temporaries and which are initializers.  This patch
implements that: we set TARGET_EXPR_ELIDING_P if it's used as an
initializer, and later check that we were right.

There's an exception in the cp_gimplify_expr check to allow extra
temporaries of non-addressable type: this is used by
gimplify_init_ctor_preeval to materialize subobjects of a CONSTRUCTOR on the
rhs of a MODIFY_EXPR rather than materializing the whole object.  If the
type isn't addressable, there's no way for a program to tell the difference,
so this is a valid optimization.

I considered changing replace_placeholders_for_class_temp_r to check
TARGET_EXPR_ELIDING_P instead of potential_prvalue_result_of, but decided
that would be wrong: if we have an eliding TARGET_EXPR inside a non-eliding
one, we would miss replacing its placeholders.

gcc/cp/ChangeLog:

	* cp-tree.h (TARGET_EXPR_ELIDING_P): New.
	(unsafe_copy_elision_p, set_target_expr_eliding)
	(cp_build_init_expr): Declare.
	* call.cc (unsafe_copy_elision_p): No longer static.
	(build_over_call, build_special_member_call)
	(build_new_method_call): Use cp_build_init_expr.
	* coroutines.cc (expand_one_await_expression)
	(build_actor_fn, flatten_await_stmt, handle_nested_conditionals)
	(await_statement_walker, morph_fn_to_coro): Use cp_build_init_expr.
	* cp-gimplify.cc (cp_gimplify_init_expr)
	(cp_gimplify_expr): Check TARGET_EXPR_ELIDING_P.
	(cp_fold_r): Propagate it.
	(cp_fold): Use cp_build_init_expr.
	* decl.cc (check_initializer): Use cp_build_init_expr.
	* except.cc (build_throw): Use cp_build_init_expr.
	* init.cc (get_nsdmi): Call set_target_expr_eliding.
	(perform_member_init, expand_default_init, expand_aggr_init_1)
	(build_new_1, build_vec_init): Use cp_build_init_expr.
	* method.cc (do_build_copy_constructor): Use cp_build_init_expr.
	* semantics.cc (simplify_aggr_init_expr, finalize_nrv_r)
	(finish_omp_reduction_clause): Use cp_build_init_expr.
	* tree.cc (build_target_expr): Call set_target_expr_eliding.
	(bot_manip): Copy TARGET_EXPR_ELIDING_P.
	* typeck.cc (cp_build_modify_expr): Call set_target_expr_eliding.
	(check_return_expr): Use cp_build_modify_expr.
	* typeck2.cc (split_nonconstant_init_1)
	(split_nonconstant_init): Use cp_build_init_expr.
	(massage_init_elt): Call set_target_expr_eliding.
	(process_init_constructor_record): Clear TARGET_EXPR_ELIDING_P on
	unsafe copy elision.
	(set_target_expr_eliding, cp_build_init_expr): New.
2022-10-07 20:25:51 -04:00
GCC Administrator
9ff6c33e2e Daily bump. 2022-10-08 00:17:29 +00:00
Marek Polacek
895dd027d5 c++: fixes for derived-to-base reference binding [PR107085]
This PR reports that

  struct Base {};
  struct Derived : Base {};
  static_assert(__reference_constructs_from_temporary(Base const&, Derived));

doesn't pass, which it should: it's just like

  const Base& b(Derived{});

where we bind 'b' to the Base subobject of a temporary object of type
Derived.  The ck_base conversion didn't have ->need_temporary_p set because
we didn't need to create a temporary object just for the base, but the whole
object is a temporary so we're still binding to a temporary.  Since the
Base subobject is an xvalue, a new function is introduced.

	PR c++/107085

gcc/cp/ChangeLog:

	* call.cc (conv_binds_ref_to_temporary): New.
	(ref_conv_binds_directly): Rename to...
	(ref_conv_binds_to_temporary): ...this.  Use
	conv_binds_ref_to_temporary.
	* cp-tree.h (ref_conv_binds_directly): Rename to...
	(ref_conv_binds_to_temporary): ...this.
	* method.cc (ref_xes_from_temporary): Use ref_conv_binds_to_temporary.
	* parser.cc (warn_for_range_copy): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/reference_constructs_from_temporary1.C: Adjust expected
	result.
	* g++.dg/ext/reference_converts_from_temporary1.C: Likewise.
	* g++.dg/cpp0x/elision4.C: New test.
2022-10-07 17:18:16 -04:00
Eugene Rozenfeld
f30e9fd33e Set discriminators for call stmts on the same line within the same basic block.
Call statements are possible split points of a basic block so they may end up
in different basic blocks by the time pass_ipa_auto_profile executes.

This change will also simplify call site lookups since now location with discriminator
will uniquely identify the call site (no callee function name is needed).

This change is based on commit 1e6c4a7a8fb8e20545bb9f9032d3854f3f794c18
by Dehao Chen in vendors/google/heads/gcc-4_8.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
	* tree-cfg.cc (assign_discriminators): Set discriminators for call stmts
	on the same line within the same basic block.
2022-10-07 13:04:36 -07:00
Qing Zhao
b9ad850e86 Use array_at_struct_end_p in __builtin_object_size [PR101836]
Use array_at_struct_end_p to determine whether the trailing array
of a structure is flexible array member in __builtin_object_size.

gcc/ChangeLog:

	PR tree-optimization/101836
	* tree-object-size.cc (addr_object_size): Use array_at_struct_end_p
	to determine a flexible array member reference.

gcc/testsuite/ChangeLog:

	PR tree-optimization/101836
	* gcc.dg/pr101836.c: New test.
	* gcc.dg/pr101836_1.c: New test.
	* gcc.dg/pr101836_2.c: New test.
	* gcc.dg/pr101836_3.c: New test.
	* gcc.dg/pr101836_4.c: New test.
	* gcc.dg/pr101836_5.c: New test.
	* gcc.dg/strict-flex-array-2.c: New test.
	* gcc.dg/strict-flex-array-3.c: New test.
2022-10-07 17:44:14 +00:00
Qing Zhao
1879e48f3d Add a new option -fstrict-flex-arrays[=n] and new attribute strict_flex_array
Add the following new option -fstrict-flex-arrays[=n] and a corresponding
attribute strict_flex_array to GCC:

'-fstrict-flex-arrays'
     Control when to treat the trailing array of a structure as a flexible array
     member for the purpose of accessing the elements of such an array.
     The positive form is equivalent to '-fstrict-flex-arrays=3', which is the
     strictest.  A trailing array is treated as a flexible array member only when
     it declared as a flexible array member per C99 standard onwards.
     The negative form is equivalent to '-fstrict-flex-arrays=0', which is the
     least strict.  All trailing arrays of structures are treated as flexible
     array members.

'-fstrict-flex-arrays=LEVEL'
     Control when to treat the trailing array of a structure as a flexible array
     member for the purpose of accessing the elements of such an array.  The value
     of LEVEL controls the level of strictness

     The possible values of LEVEL are the same as for the
     'strict_flex_array' attribute (*note Variable Attributes::).

     You can control this behavior for a specific trailing array field
     of a structure by using the variable attribute 'strict_flex_array'
     attribute (*note Variable Attributes::).

'strict_flex_array (LEVEL)'
     The 'strict_flex_array' attribute should be attached to the trailing
     array field of a structure. It controls when to treat the trailing array
     field of a structure as a flexible array member for the purposes of accessing
     the elements of such an array. LEVEL must be an integer betwen 0 to 3.

     LEVEL=0 is the least strict level, all trailing arrays of
     structures are treated as flexible array members.  LEVEL=3 is the
     strictest level, only when the trailing array is declared as a
     flexible array member per C99 standard onwards ('[]'), it is
     treated as a flexible array member.

     There are two more levels in between 0 and 3, which are provided to
     support older codes that use GCC zero-length array extension
     ('[0]') or one-element array as flexible array members('[1]'): When
     LEVEL is 1, the trailing array is treated as a flexible array member
     when it is declared as either '[]', '[0]', or '[1]'; When
     LEVEL is 2, the trailing array is treated as a flexible array member
     when it is declared as either '[]', or '[0]'.

     This attribute can be used with or without the
     '-fstrict-flex-arrays'.  When both the attribute and the option
     present at the same time, the level of the strictness for the
     specific trailing array field is determined by the attribute.

gcc/c-family/ChangeLog:

	* c-attribs.cc (handle_strict_flex_array_attribute): New function.
	(c_common_attribute_table): New item for strict_flex_array.
	* c.opt: (fstrict-flex-arrays): New option.
	(fstrict-flex-arrays=): New option.

gcc/c/ChangeLog:

	* c-decl.cc (flexible_array_member_type_p): New function.
	(one_element_array_type_p): Likewise.
	(zero_length_array_type_p): Likewise.
	(add_flexible_array_elts_to_size): Call new utility
	routine flexible_array_member_type_p.
	(is_flexible_array_member_p): New function.
	(finish_struct): Set the new DECL_NOT_FLEXARRAY flag.

gcc/cp/ChangeLog:

	* module.cc (trees_out::core_bools): Stream out new bit
	decl_not_flexarray.
	(trees_in::core_bools): Stream in new bit decl_not_flexarray.

gcc/ChangeLog:

	* doc/extend.texi: Document strict_flex_array attribute.
	* doc/invoke.texi: Document -fstrict-flex-arrays[=n] option.
	* print-tree.cc (print_node): Print new bit decl_not_flexarray.
	* tree-core.h (struct tree_decl_common): New bit field
	decl_not_flexarray.
	* tree-streamer-in.cc (unpack_ts_decl_common_value_fields): Stream
	in new bit decl_not_flexarray.
	* tree-streamer-out.cc (pack_ts_decl_common_value_fields): Stream
	out new bit decl_not_flexarray.
	* tree.cc (array_at_struct_end_p): Update it with the new bit field
	decl_not_flexarray.
	* tree.h (DECL_NOT_FLEXARRAY): New flag.

gcc/testsuite/ChangeLog:

	* g++.dg/strict-flex-array-1.C: New test.
	* gcc.dg/strict-flex-array-1.c: New test.
2022-10-07 17:44:08 +00:00
Olivier Hainque
21e51a55e9 Specialize paths to version.h in _vxworks-versions.h
The _vxworks-versions.h runtime file helps us control
the compilation of some library components depending on
the OS version extracted out of a system header.

The system header name is "version.h", and gcc has a
"version.h" file of its own.

gcc's version.h is now generated and the current
instance instead of the OS one, resulting in build failures
from

  #if !defined(_WRS_VXWORKS_MAJOR)
  #error "_WRS_VXWORKS_MAJOR undefined"
  #endif

This change introduces a twist in the way
_vxworks-versions.h #includes version.h, using a relative
path with components that will match in the OS include
dirs only.

The actual relative path is conditioned on _VSB_CONFIG_FILE
to accommodate a change in the include dirs organisation between
VxWorks 6 and 7.

2022-10-07  Olivier Hainque  <hainque@adacore.com>

gcc/
	* config/vxworks/_vxworks-versions.h: Use OS specific
	paths in #include of version.h.
2022-10-07 16:58:43 +00:00
David Malcolm
f09b99550a analyzer: extract bits from integer constants [PR105783]
Fix a false positive from -Wanalyzer-null-dereference due to -fanalyzer
failing to grok the value of a particular boolean field initialized to a
constant.

gcc/analyzer/ChangeLog:
	PR analyzer/105783
	* region-model.cc (selftest::get_bit): New function.
	(selftest::test_bits_within_svalue_folding): New.
	(selfftest::analyzer_region_model_cc_tests): Call it.
	* svalue.cc (constant_svalue::maybe_fold_bits_within): Handle the
	case of extracting a single bit.

gcc/testsuite/ChangeLog:
	PR analyzer/105783
	* gcc.dg/analyzer/pr105783.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2022-10-07 12:41:59 -04:00
Nathan Sidwell
eb491ea5c1 libiberty: Demangle variadic template lambdas
Now we have templated lambdas, we can have variadic template lambdas,
and this leads to lambda signatures containing parameter packs.  But
just like 'auto' inside such a signature, we don't have a containing
template, and thus fail.  The fix is to check is_lambda_arg, just as
for a template parameter.  This allows us to demangle g++'s manglings
of such lambdas.

It's not a totally accurate demangling, because we don't mangle the
template head (that's a separate issue), but it is better than failing
to demangle.

Due to the way we print subexprs, we add an unnecessary parens around
the argument of the pack.  That's an orthogonal problem, for which the
solution is to have better knowledge of operator precedence.

	libiberty/
	* cp-demangle.c (d_print_comp_inner): Allow parameter packs
	in a lambda signature.
	* testsuite/demangle-expected: Add tests.
2022-10-07 09:12:01 -07:00
Patrick Palka
f7f4628054 c++ modules: ICE with bitfield in class template
According to grokbitfield, DECL_BIT_FIELD_REPRESENTATIVE contains the
width of the bitfield until we layout the class type (after which it'll
contain a decl).  Thus for a bitfield in a class template it'll always
be the width, and this patch makes us avoid ICEing from mark_class_def
in this case.

gcc/cp/ChangeLog:

	* module.cc (trees_out::mark_class_def): Guard against
	DECL_BIT_FIELD_REPRESENTATIVE not being a decl.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/bfield-3.H: New test.
2022-10-07 12:01:58 -04:00
Jason Merrill
f8ba88b6a8 c++: catch parm initialization tweak
We want to push the INIT_EXPR inside the CLEANUP_POINT_EXPR for the same
reason we want to push it into the MUST_NOT_THROW_EXPR: any cleanups follow
the initialization.

gcc/cp/ChangeLog:

	* init.cc (expand_default_init): Also push the INIT_EXPR inside a
	CLEANUP_POINT_EXPR.
2022-10-07 09:52:52 -04:00
Martin Liska
1a308905c1 IPA: support -flto + -flive-patching=inline-clone
There's no fundamental reason why -flive-patching=inline-clone can't
coexist with -flto. Yes, one can theoretically have many more clone
function that includes a live patch. It is pretty much the same
as in-module inlining.

gcc/ChangeLog:

	* opts.cc (finish_options): Print sorry message only
	for -flive-patching=inline-only-static.

gcc/testsuite/ChangeLog:

	* gcc.dg/live-patching-2.c: Update scanned pattern.
	* gcc.dg/live-patching-5.c: New test.
2022-10-07 15:46:30 +02:00
Patrick Palka
edbb2551d1 c++ modules: static var in inline function [PR104433]
The below testcase fails to link with the error

  undefined reference to `f()::y'

ultimately because during stream out for the static VAR_DECL y we
override DECL_EXTERNAL to true, which later during IPA confuses
symbol_table::remove_unreachable_nodes into thinking it's safe
to not emit the symbol.

The streaming code here already avoids overriding DECL_EXTERNAL for
inline vars and functions, so it seems natural to extend this to
static vars from an inline function.

	PR c++/104433

gcc/cp/ChangeLog:

	* module.cc (trees_out::core_bools): Don't override
	DECL_EXTERNAL to true for static variables from an inline
	function.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/static-2_a.H: New test.
	* g++.dg/modules/static-2_b.C: New test.
2022-10-07 09:32:45 -04:00
Jason Merrill
d3e5465757 gimplify: prevent some C++ temporary elision
In this testcase, we were optimizing away the temporary for f(), but
C++17 and above are clear that there is a temporary, and because its
destructor has visible side-effects we can't optimize it away under the
as-if rule.  So disable this optimization for TREE_ADDRESSABLE type.

I moved the declaration of volatile_p after the call to
gimple_fold_indirect_ref_rhs to minimize indentation changes; I don't see
any way the value of that flag could be affected by the call.

gcc/ChangeLog:

	* gimplify.cc (gimplify_modify_expr_rhs): Don't optimize
	x = *(A*)&<expr> to x = <expr> for a TREE_ADDRESSABLE type.

gcc/testsuite/ChangeLog:

	* g++.dg/init/elide9.C: New test.
2022-10-07 09:22:32 -04:00
Richard Biener
89228e3985 tree-optimization/107153 - autopar SSA update issue
autopar performs insertion of stores, eventually requiring a
virtual loop PHI and assorted LC PHI adjustments which we intend
to do once after the pass finishes.  But we also perform intermediate
update_ssa after loop duplication which can lose this fact.  The
following forces renaming of the virtual operand before the final
SSA update to fix that.  It also removes the explicit update_ssa
call from the gimple_duplicate_sese_tail utility as has been done
for all other such utilities and instead performs the SSA update
from autopar.

	PR tree-optimization/107153
	* tree-cfg.cc (gimple_duplicate_sese_tail): Do not update
	SSA form here.
	* tree-parloops.cc (gen_parallel_loop): Update SSA form
	after to-exit-first transform, no PHI insertion is necessary.
	(pass_parallelize_loops::execute): Force re-write of the
	virtual operand SSA web.

	* gcc.dg/autopar/pr107153.c: New testcase.
2022-10-07 14:27:37 +02:00
Jonathan Wakely
6bd2c1231a libstdc++: Add --disable-libstdcxx-hosted as an alias for hosted-libstdcxx
Most libstdc++ configure args are of the form --enable-libstdcxx-xxx but
the option to build freestanding is --disable-hosted-libstdcxx. If you
accidentally type --disable-libstdcxx-hosted then it will be ignored.

This adds --disable-libstdcxx-hosted as an alias for the existing arg,
so it works whichever way you say it. If both args are used explicitly
and their values do not agree, configure fails with an error.

libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_ENABLE_HOSTED): Add libstdcxx-hosted
	enable arg as an alias for hosted-libstdcxx enable arg.
	* configure: Regenerate.
2022-10-07 12:55:52 +01:00
Jonathan Wakely
93b3ab6c0c libstdc++: Shuffle header dependencies of <functional>
The <new> header is needed by std::function to use placement new, so
include it in <bits/std_function.h> instead of in <functional>.

libstdc++-v3/ChangeLog:

	* include/bits/std_function.h: Include <new> but do not include
	<bits/stl_function.h>.
	* include/std/functional: Do not include <new>.
2022-10-07 12:55:33 +01:00
Jonathan Wakely
df78e15233 gcc: Fix comment typo
gcc/ChangeLog:

	* value-range.cc (irange::irange_contains_p): Fix comment typo.
2022-10-07 12:22:32 +01:00
Jonathan Wakely
8e2f453de3 libstdc++: Use bold style for DR titles in the manual
This matches how the issues are styled in the LWG issues list, and also
allows us to use italics for "cv" (e.g. in issue 2487).

libstdc++-v3/ChangeLog:

	* doc/xml/manual/intro.xml: Add role="bold" attribute to
	emphasis elements for issue titles.
	* doc/html/manual/bugs.html: Regenerate.
2022-10-07 12:20:24 +01:00