197024 Commits

Author SHA1 Message Date
Philipp Tomsich
30c2d8df17 RISC-V: split to allow formation of sh[123]add before 32bit divw
When using strength-reduction, we will reduce a multiplication to a
sequence of shifts and adds.  If this is performed with 32-bit types
and followed by a division, the lack of w-form sh[123]add will make
combination impossible and lead to a slli + addw being generated.

Split the sequence with the knowledge that a w-form div will perform
implicit sign-extensions.

gcc/ChangeLog:

	* config/riscv/bitmanip.md: Add a define_split to optimize
	  slliw + addiw + divw into sh[123]add + divw.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/zba-shNadd-05.c: New test.
2022-11-18 21:15:24 +01:00
Philipp Tomsich
acbb5ef06e RISC-V: Optimize branches testing a bit-range or a shifted immediate
gcc/ChangeLog:

	* config/riscv/predicates.md (shifted_const_arith_operand): New predicate.
	(uimm_extra_bit_operand): New predicate.
	* config/riscv/riscv.md (*branch<ANYI:mode>_shiftedarith_equals_zero):
	New pattern.
	(*branch<ANYI:mode>_shiftedmask_equals_zero): New pattern.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/branch-1.c: New test.
2022-11-18 21:15:24 +01:00
Philipp Tomsich
23d9f62c50 RISC-V: allow bseti on SImode without sign-extension
As long as the SImode operand is not a partial subreg, we can use a
bseti without postprocessing to or in a bit, as the middle end is
smart enough to stay away from the signbit.

gcc/ChangeLog:

	* config/riscv/bitmanip.md (*bsetidisi): New pattern.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/zbs-bseti-02.c: New test.
2022-11-18 21:15:24 +01:00
Richard Purdie
11543b27fe libcpp: Avoid remapping filenames within directives
Code such as:

 #include __FILE__

can interact poorly with the *-prefix-map options when cross compiling. In
general you're after to remap filenames for use in target context but the
local paths should be used to find include files at compile time. Ingoring
filename remapping for directives allows avoiding such failures.

Fix this to improve such usage and then document this against file-prefix-map
(referenced by the other *-prefix-map options) to make the behaviour clear
and defined.

libcpp/ChangeLog:

	* macro.cc (_cpp_builtin_macro_text): Don't remap filenames within
	directives.

gcc/ChangeLog:

	* doc/invoke.texi: Document prefix-maps don't affect directives.
2022-11-18 13:13:50 -07:00
Jakub Jelinek
59cc4da605 Manually add entries for r13-4128.
Aldo, replace some invalid tab + 2 spaces with just tab.
2022-11-18 19:22:18 +01:00
Harald Anlauf
820c25c835 Fortran: reject NULL actual argument without explicit interface [PR107576]
gcc/fortran/ChangeLog:

	PR fortran/107576
	* interface.cc (gfc_procedure_use): Reject NULL as actual argument
	when there is no explicit procedure interface.

gcc/testsuite/ChangeLog:

	PR fortran/107576
	* gfortran.dg/null_actual_3.f90: New test.
2022-11-18 19:15:09 +01:00
GCC Administrator
add8984069 Daily bump. 2022-11-18 18:09:19 +00:00
Jakub Jelinek
f003fdff96 Add another commit to ignore
We can't handle r13-4128-g1957bedf29a1b2cc231972aba680fe80199d5498

	* gcc-changelog/git_update_version.py: Add
	1957bedf29a1b2cc231972aba680fe80199d5498 to ignored commits.
2022-11-18 19:05:46 +01:00
Andrew Pinski
ceba66ee23 Fix PR middle-end/107705: ICE after reclaration error
The problem here is after we created a call expression
in the C front-end, we replace the decl type with
an error mark node. We then end up calling
aggregate_value_p with the call expression
with the decl with the error mark as the type
and we ICE.

The fix is to check the function type
after we process the call expression inside
aggregate_value_p to get it.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

gcc/ChangeLog:

	PR middle-end/107705
	* function.cc (aggregate_value_p): Return 0 if
	the function type was an error operand.

gcc/testsuite/ChangeLog:

	* gcc.dg/redecl-22.c: New test.
2022-11-18 17:02:06 +00:00
Andrew Pinski
bd0c9d9e70 Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration
The problem here is the gimplifier returns GS_ERROR but
in some cases we don't check that soon enough and try
to do other work which could crash.
So the fix in these two cases is to return GS_ERROR
early if the gimplify_* functions had return GS_ERROR.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

gcc/ChangeLog:

	PR c/106764
	PR c/106765
	PR c/107307
	* gimplify.cc (gimplify_compound_lval): Return GS_ERROR
	if gimplify_expr had return GS_ERROR.
	(gimplify_call_expr): Likewise.

gcc/testsuite/ChangeLog:

	PR c/106764
	PR c/106765
	PR c/107307
	* gcc.dg/redecl-19.c: New test.
	* gcc.dg/redecl-20.c: New test.
	* gcc.dg/redecl-21.c: New test.
2022-11-18 17:02:06 +00:00
Yixuan Chen
acc205eff4 Fix testcase for architectures that use .srodata
gcc/testsuite:

	* gcc.dg/pr25521.c: Fix testcase for architectures that use .srodata.
2022-11-18 08:47:11 -07:00
Kyrylo Tkachov
92905f614e aarch64: Fix LDAPURS assembly output
... And another follow-up once I realised that the sign-extending load, of course,
needs to have strictly an X-reg as a destination for DImode extensions and a W-reg
for SImode ones.

Tested on aarch64-none-linux.

gcc/ChangeLog:

	* config/aarch64/atomics.md (*aarch64_atomic_load<ALLX:mode>_rcpc_sext):
	Use <GPI:w>  for destination format.
	* config/aarch64/iterators.md (w_sz): Delete.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/ldapr-sext.c: Adjust expected output.
2022-11-18 14:29:36 +00:00
Torbjörn SVENSSON
20d2a8c24f testsuite: Verify that module-mapper is available
For some test cases, it's required that the optional module mapper
"g++-mapper-server" is built. As the server is not required, the
test cases will fail if it can't be found.

gcc/testsuite/ChangeLog:

	* lib/target-supports.exp (check_is_prog_name_available):
	New.
	* lib/target-supports-dg.exp
	(dg-require-prog-name-available): New.
	* g++.dg/modules/modules.exp: Verify avilability of module
	mapper.

Signed-off-by: Torbjörn SVENSSON  <torbjorn.svensson@foss.st.com>
2022-11-18 11:30:35 +01:00
Kyrylo Tkachov
33de7b3746 aarch64: Fix up LDAPR codegen
Upon some further inspection I realised I had misunderstood some intricacies of the extending loads of the RCPC feature.
This patch fixes up the recent GCC support accordingly. In particular:
* The sign-extending forms are a form of LDAPURS* and are actually part of FEAT_RCPC2
that is enabled with Armv8.4-a rather than the base Armv8.3-a FEAT_RCPC.
The patch introduces a TARGET_RCPC2 macro and gates this combine pattern accordingly.
* The assembly output for the zero-extending LDAPR instruction should always use %w formatting for its destination register.

The testcase is split into zero-extending and sign-extending parts since they require different architecture pragmas.
It's also straightforward to add the rest of the FEAT_RCPC2 codegen
(with immediate offset addressing modes) but that can be done as a separate patch.
Apologies for not catching this sooner, but it hasn't been in trunk long, so no harm done.

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

gcc/ChangeLog:

	* config/aarch64/aarch64.h (TARGET_RCPC2): Define.
	* config/aarch64/atomics.md (*aarch64_atomic_load<ALLX:mode>_rcpc_zext):
	Adjust output template.
	(*aarch64_atomic_load<ALLX:mode>_rcpc_sex): Guard on TARGET_RCPC2.
	Adjust output template.
	* config/aarch64/iterators.md (w_sz): New mode attr.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/ldapr-ext.c: Rename to...
	* gcc.target/aarch64/ldapr-zext.c: ... This.  Fix expected assembly.
	* gcc.target/aarch64/ldapr-sext.c: New test.
2022-11-18 09:06:38 +00:00
Jakub Jelinek
e5049dfbe2 c++: Implement CWG2635 - Constrained structured bindings
The following patch implements CWG2635.

2022-11-18  Jakub Jelinek  <jakub@redhat.com>

	* decl.cc (grokdeclarator): Implement
	CWG2635 - Constrained structured bindings.  Emit a pedwarn on
	constrained auto type.  Add auto_diagnostic_group for error_at
	and inform for non-auto type on structured bindings declaration.

	* g++.dg/cpp2a/decomp5.C: New test.
	* g++.dg/cpp2a/decomp6.C: New test.
	* g++.dg/cpp2a/decomp7.C: New test.
	* g++.dg/cpp2a/concepts-placeholder7.C: Adjust expected diagnostics.
	* g++.dg/cpp2a/concepts-placeholder8.C: Likewise.
	* g++.dg/cpp2a/concepts-placeholder9.C: New test.
	* g++.dg/cpp2a/concepts-placeholder10.C: New test.
2022-11-18 09:04:16 +01:00
Richard Biener
c5df8392c5 tree-optimization/107647 - avoid FMA from SLP with -ffp-contract=off
Only with -ffp-contract=fast we can synthesize FMA operations like
vfmaddsub231ps, so properly guard the transform in SLP pattern
detection.

	PR tree-optimization/107647
	* tree-vect-slp-patterns.cc (addsub_pattern::recognize): Only
	allow FMA generation with -ffp-contract=fast for FP types.
	(complex_mul_pattern::matches): Likewise.

	* gcc.target/i386/pr107647.c: New testcase.
2022-11-18 08:37:23 +01:00
Jinyang He
f0024bfb22 LoongArch: Fix atomic_exchange expanding [PR107713]
We used to expand atomic_exchange_n(ptr, new, mem_order) for subword types
into something like:

    {
      __typeof__(*ptr) t = atomic_load_n(ptr, mem_order);
      atomic_compare_exchange_n(ptr, &t, new, true, mem_order, mem_order);
      return t;
    }

It's incorrect because another thread may store a different value into *ptr
after atomic_load_n.  Then atomic_compare_exchange_n will not store into
*ptr, but atomic_exchange_n should always perform the store.

gcc/ChangeLog:

	PR target/107713
	* config/loongarch/sync.md
	(atomic_cas_value_exchange_7_<mode>): New define_insn.
	(atomic_exchange): Use atomic_cas_value_exchange_7_si instead of
	atomic_cas_value_cmp_and_7_si.

gcc/testsuite/ChangeLog:

	PR target/107713
	* gcc.target/loongarch/pr107713-1.c: New test.
	* gcc.target/loongarch/pr107713-2.c: New test.
2022-11-18 15:02:27 +08:00
Marek Polacek
7b3b2f5095 c++: constinit on pointer to function [PR104066]
[dcl.constinit]: "The constinit specifier shall be applied only to
a declaration of a variable with static or thread storage duration."

Thus, this ought to be OK:

  constinit void (*p)() = nullptr;

but the error message I introduced when implementing constinit was
not looking at funcdecl_p, so the code above was rejected.

Fixed thus.  I'm checking constinit_p first because I think that's
far more likely to be false than funcdecl_p.

	PR c++/104066

gcc/cp/ChangeLog:

	* decl.cc (grokdeclarator): Check funcdecl_p before complaining
	about constinit.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/constinit18.C: New test.
2022-11-17 19:15:57 -05:00
Bernhard Reutner-Fischer
3f467ea953 c: Set the locus of the function result decl
gcc/c/ChangeLog:

	* c-decl.cc (start_function): Set the result decl source
	location to the location of the typespec.
2022-11-17 20:40:47 +01:00
Bernhard Reutner-Fischer
19be89d79e Fortran: Remove double spaces in open() warning [PR99884]
gcc/fortran/ChangeLog:

	PR fortran/99884
	* io.cc (check_open_constraints): Remove double spaces.
2022-11-17 20:40:38 +01:00
Andrew Pinski
ee892832ea Fix PR 107734: valgrind errors with sbitmap in match.pd
sbitmap is a simple bitmap and the memory allocated is not cleared
on creation; you have to clear it or set it to all ones before using
it.  This is unlike bitmap which is a sparse bitmap and the entries are
cleared as created.
The code added in r13-4044-gdc95e1e9702f2f missed that.
This patch fixes that mistake.

Committed as obvious after a bootstrap and test on x86_64-linux-gnu.

gcc/ChangeLog:

	PR middle-end/107734
	* match.pd (perm + vector op pattern): Clear the sbitmap before
	use.
2022-11-17 17:56:55 +00:00
Aldy Hernandez
4e306222f4 [PR tree-optimization/107732] [range-ops] Handle attempt to abs() negatives.
The threader is creating a scenario where we are trying to solve:

	[NEGATIVES] = abs(x)

While solving this we have an intermediate value of UNDEFINED because
we have no positive numbers.  But then we try to union the negative
pair to the final result by querying the bounds.  Since neither
UNDEFINED nor NAN have bounds, they need to be specially handled.

	PR tree-optimization/107732

gcc/ChangeLog:

	* range-op-float.cc (foperator_abs::op1_range): Early exit when
	result is undefined.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/pr107732.c: New test.
2022-11-17 18:42:56 +01:00
David Malcolm
f9ed1d24ee c, analyzer: fix ICE with -fanalyzer and -Wunused-macros [PR107711]
PR analyzer/107711 reports an ICE since r13-4073-gd8aba860b34203 with
the combination of -fanalyzer and -Wunused-macros.

The issue is that in c_translation_unit::consider_macro's call to
cpp_create_reader I was passing "ident_hash" for use by the the new
reader, but that takes ownership of that hash_table, so that ident_hash
erroneously gets freed when c_translation_unit::consider_macro calls
cpp_destroy, leading to a use-after-free in -Wunused-macros, where:

(gdb) p pfile->hash_table->pfile == pfile
$23 = false

and it's instead pointing at the freed reader from consider_macro,
leading to a use-after-free ICE.

Fixed thusly.

gcc/c/ChangeLog:
	PR analyzer/107711
	* c-parser.cc (ana::c_translation_unit::consider_macro): Pass NULL
	to cpp_create_reader, rather than ident_hash, so that the new
	reader gets its own hash table.

gcc/testsuite/ChangeLog:
	PR analyzer/107711
	* gcc.dg/analyzer/named-constants-Wunused-macros.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2022-11-17 12:34:56 -05:00
Philipp Tomsich
0045d254c0 RISC-V: Optimize masking with two clear bits not a SMALL_OPERAND
Add a split for cases where we can use two bclri (or one bclri and an
andi) to clear two bits.

gcc/ChangeLog:

	* config/riscv/bitmanip.md (*bclri<mode>_nottwobits): New pattern.
	(*bclridisi_nottwobits): New pattern, handling the sign-bit.
	* config/riscv/predicates.md (const_nottwobits_operand):
	New predicate.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/zbs-bclri.c: New test.
2022-11-17 16:27:17 +01:00
Philipp Tomsich
1957bedf29 RISC-V: bitmanip: add splitter to use bexti for "(a & (1 << BIT_NO)) ? 0 : -1"
Consider creating a polarity-reversed mask from a set-bit (i.e., if
the bit is set, produce all-ones; otherwise: all-zeros).  Using Zbb,
this can be expressed as bexti, followed by an addi of minus-one.  To
enable the combiner to discover this opportunity, we need to split the
canonical expression for "(a & (1 << BIT_NO)) ? 0 : -1" into a form
combinable into bexti.

Consider the function:
    long f(long a)
    {
      return (a & (1 << BIT_NO)) ? 0 : -1;
    }
This produces the following sequence prior to this change:
	andi	a0,a0,16
	seqz	a0,a0
	neg	a0,a0
	ret
Following this change, it results in:
	bexti	a0,a0,4
	addi	a0,a0,-1
	ret

gcc/ChangeLog:

	* config/riscv/bitmanip.md: Add a splitter to generate
	  polarity-reversed masks from a set bit using bexti + addi.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/zbs-bexti.c: New test.
2022-11-17 16:20:56 +01:00
mtsamis
705bae2351 Enable shrink wrapping for the RISC-V target.
This commit implements the target macros (TARGET_SHRINK_WRAP_*) that
enable separate shrink wrapping for function prologues/epilogues in
RISC-V.

Tested against SPEC CPU 2017, this change always has a net-positive
effect on the dynamic instruction count.  See the following table for
the breakdown on how this reduces the number of dynamic instructions
per workload on a like-for-like (i.e., same config file; suppressing
shrink-wrapping with -fno-shrink-wrap):

                             # dynamic instructions
                w/o shrink-wrap   w/ shrink-wrap      reduction
500.perlbench_r   1265716786593    1262156218578     3560568015   0.28%
500.perlbench_r    779224795689     765337009025    13887786664   1.78%
500.perlbench_r    724087331471     711307152522    12780178949   1.77%
502.gcc_r          204259864844     194517006339     9742858505   4.77%
502.gcc_r          244047794302     231555834722    12491959580   5.12%
502.gcc_r          230896069400     221877703011     9018366389   3.91%
502.gcc_r          192130616624     183856450605     8274166019   4.31%
502.gcc_r          258875074079     247756203226    11118870853   4.30%
505.mcf_r          662653430325     660678680547     1974749778   0.30%
520.omnetpp_r      985114167068     934191310154    50922856914   5.17%
523.xalancbmk_r    927037633578     921688937650     5348695928   0.58%
525.x264_r         490953958454     490565583447      388375007   0.08%
525.x264_r        1994662294421    1993171932425     1490361996   0.07%
525.x264_r        1897617120450    1896062750609     1554369841   0.08%
531.deepsjeng_r   1695189878907    1669304130411    25885748496   1.53%
541.leela_r       1925941222222    1897900861198    28040361024   1.46%
548.exchange2_r   2073816227944    2073816226729           1215   0.00%
557.xz_r           379572090003     379057409041      514680962   0.14%
557.xz_r           953117469352     952680431430      437037922   0.05%
557.xz_r           536859579650     536456690164      402889486   0.08%
                 18421773405376   18223938521833   197834883543   1.07%  totals

Signed-off-by: Manolis Tsamis <manolis.tsamis@vrull.eu>

gcc/ChangeLog:

	* config/riscv/riscv.cc (struct machine_function): Add array to store
	register wrapping information.
	(riscv_for_each_saved_reg): Skip registers that are wrapped separetely.
	(riscv_get_separate_components): New function.
	(riscv_components_for_bb): Likewise.
	(riscv_disqualify_components): Likewise.
	(riscv_process_components): Likewise.
	(riscv_emit_prologue_components): Likewise.
	(riscv_emit_epilogue_components): Likewise.
	(riscv_set_handled_components): Likewise.
	(TARGET_SHRINK_WRAP_GET_SEPARATE_COMPONENTS): Define.
	(TARGET_SHRINK_WRAP_COMPONENTS_FOR_BB): Likewise.
	(TARGET_SHRINK_WRAP_DISQUALIFY_COMPONENTS): Likewise.
	(TARGET_SHRINK_WRAP_EMIT_PROLOGUE_COMPONENTS): Likewise.
	(TARGET_SHRINK_WRAP_EMIT_EPILOGUE_COMPONENTS): Likewise.
	(TARGET_SHRINK_WRAP_SET_HANDLED_COMPONENTS): Likewise.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/shrink-wrap-1.c: New test.
2022-11-17 12:59:06 +01:00
Kyrylo Tkachov
06c8f2ebf0 aarch64: Add mode size check on LDAPR-extend patterns
Add an extra safety check as suggested by Richard.
Tested on aarch64-none-linux-gnu.

gcc/ChangeLog:

	* config/aarch64/atomics.md (*aarch64_atomic_load<ALLX:mode>_rcpc_zext):
	Add mode size check to condition.
	(*aarch64_atomic_load<ALLX:mode>_rcpc_sext): Likewise.
2022-11-17 11:30:08 +00:00
Aldy Hernandez
822a0823c0 [PR68097] Try to avoid recursing for floats in gimple_stmt_nonnegative_warnv_p.
It irks me that a PR named "we should track ranges for floating-point
hasn't been closed in this release.  This is an attempt to do just
that.

As mentioned in the PR, even though we track ranges for floats, it has
been suggested that avoiding recursing through SSA defs in
gimple_assign_nonnegative_warnv_p is also a goal.  This patch uses a
global range query (no on-demand lookups, just global ranges and
minimal folding) to determine if the range of a statement is known to
be non-negative.

	PR tree-optimization/68097

gcc/ChangeLog:

	* gimple-fold.cc (gimple_stmt_nonnegative_warnv_p): Call
	range_of_stmt for floats.
2022-11-17 09:53:49 +01:00
Lili Cui
156f523f95 x86: Enable 256 move by pieces for ALDERLAKE machine.
gcc/ChangeLog:

	* config/i386/x86-tune.def
	(X86_TUNE_AVX256_MOVE_BY_PIECES): Add alderlake.
	(X86_TUNE_AVX256_STORE_BY_PIECES): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pieces-memset-50.c: New test.
2022-11-17 16:27:34 +08:00
Tamar Christina
cbe313060c middle-end: ensure that VEC_PERM operands get lowered to the same SSA_NAME. [PR107717]
At the moment when the VEC_PERMs generated by this match.pd rule is generated
it creates two different SSA_NAMEs for the folded operand.  Because of this it
the permute switches from a single operand permute to a two operand permute and
the target may no longer support a permute for this.

This fixes it by ensuring we generate the same SSA_NAME for both operands.

gcc/ChangeLog:

	PR tree-optimization/107717
	* match.pd: Ensure same SSA_NAME.

gcc/testsuite/ChangeLog:

	PR tree-optimization/107717
	* gcc.target/aarch64/sve2/pr107717.c: New test.
2022-11-17 08:20:59 +00:00
Tamar Christina
1bc7efa948 middle-end: replace GET_MODE_WIDER_MODE with GET_MODE_NEXT_MODE
After the fix to the addsub patch yesterday for bootstrap I had only regtested on x86.
While looking today it seemed the new tests were failing, this was caused
by a change in the behavior of the GET_MODE_WIDER_MODE macro on trunk.

gcc/ChangeLog:

	* match.pd: Replace GET_MODE_WIDER_MODE with
	custom code.
2022-11-17 08:14:44 +00:00
Aldy Hernandez
2b2f2ee49a [range-ops] Minor readability fix.
gcc/ChangeLog:

	* range-op-float.cc (range_operator_float::fold_range): Make check
	for maybe_isnan more readable.
2022-11-17 07:39:46 +01:00
Kewen Lin
928bc5b863 Fix typo in gimple_fold_partial_load_store_mem_ref
As Robin spotted, my recent commit r13-3716 caused an ICE
on s390 if vector access with length is enabled there (his
patch for the enablement hasn't been committed yet).  The
failure is caused by one stupid typo, the bias on s390 is
-1, so the assertion should use tree_fits_shwi_p rather
than tree_fits_uhwi_p.  Thanks for Robin's catching.

I just reproduced the ICE and verified the fix worked fine
with a cross build, the optimized dump against the test case
gcc.target/powerpc/pr107412.c looked expected.

gcc/ChangeLog:

	* gimple-fold.cc (gimple_fold_partial_load_store_mem_ref): Use
	tree_fits_shwi_p rather than tree_fits_uhwi_p as bias is signed.
2022-11-16 23:08:23 -06:00
Jia-Wei Chen
a62d957342 RISC-V: Optimize RVV epilogue logic.
Sometimes "step1 -= scalable_frame" will cause adjust equal to
zero. And it will generate additional redundant instruction
"addi sp,sp,0". Add checking segement to skip that case.

This testcase mix exist spill-1.c and adding new fun to check if
there have redundant addi intructions. Idea provided by Jeff Law.

gcc/ChangeLog:

	* config/riscv/riscv.cc (riscv_expand_epilogue):
	Do not emit useless add sp, sp, 0 instrutions.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/base/spill-sp-adjust.c: New test.
2022-11-16 23:00:52 -05:00
Jeff Law
e214cab68c Fix multiple recent sh3/sh3eb regressions
So my tester started showing even more regressions on the sh3/sh4 runs
recently (beyond the one recently reported in BZ triggered by some DCE
related changes).  Bisection kept showing inconsistent results.  I was
starting to think memory management error, but valgrind didn't flag anything.

After a bit of head-banging I was able to track it down to predicate
tests called from the SH specific combiner passes.  And once I started
getting inside the actual code for the predicate function it became
pretty obvious.  The predicate routines are supposed to return a bool,
fine and they dutifully set the low bit in %eax properly.

The *caller* was looking at the full register.  Uh-oh.  Naturally we
became dependent on what happened to be in the upper 31 bits of a register.
That's why the bug would come and go so willy-nilly.  This was ultimately
chased down to an incorrect prototype in sh_treg_combine.cc for predicate
functions defined via define_predicate.

Removing the bogus prototypes and instead including the generated
tm-preds.h fixes this problem.  I also checked the other ports for
similar problems (specifically looking for a extern int.*_operand, then
for each of the hits looking to see if the predicate was defined via
define_predicate).  No other ports had similar braindamage.

This fixes the most recent regressions in my tester for sh3/sh3eb
and I strongly suspect sh4.  It does not fix 107704, but I think
Richi and I both agree that's a visitation order issue and we were
just getting lucky before.

gcc/

	* config/sh/sh_treg_combine.cc: Include tm-preds.h.
	(t_reg_operand): Remove bogus prototype.
	(negt_reg_operand): Likewise.
2022-11-16 18:47:59 -07:00
Jonathan Wakely
f69a8299c1 libstdc++: Ensure std::to_chars overloads all declared in <format> [PR107720]
For powerpc64le we need to be able to format both of __ieee128 and
__ibm128, so we need the std::to_chars overloads for both types to be
visible at once. The __ieee128 overloads are always visible in C++23
mode, because they're used to implement the _Float128 overloads. The
__ibm128 overloads are only visible when long double is __ibm128.

libstdc++-v3/ChangeLog:

	PR libstdc++/107720
	* include/std/format [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT]:
	Declare overloads of std::to_chars for the alternative long
	double type.
2022-11-17 00:34:42 +00:00
GCC Administrator
80909529c9 Daily bump. 2022-11-17 00:16:52 +00:00
David Malcolm
ff199a859b analyzer: more test coverage for named constants
gcc/testsuite/ChangeLog:
	* gcc.dg/analyzer/named-constants-via-command-line.c: New test.
	* gcc.dg/analyzer/named-constants-via-macros-3.c: New test.
	* gcc.dg/analyzer/named-constants-via-macros-4.c: New test.
	* gcc.dg/analyzer/named-constants-via-macros-empty.c: New test.
	* gcc.dg/analyzer/named-constants-via-macros-gc.c: New test.
	* gcc.dg/analyzer/named-constants-via-macros-traditional.c: New test.
	* gcc.dg/analyzer/named-constants-via-macros-undef.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2022-11-16 17:38:28 -05:00
David Malcolm
6e4962810f analyzer: log the stashing of named constants [PR107711]
PR analyzer/107711 seems to be a bug in how named constants are looked up
by the analyzer in the C frontend.

To help debug this, this patch extends -fdump-analyzer and
-fdump-analyzer-stderr so that they dump this part of the analyzer's
startup.

gcc/analyzer/ChangeLog:
	PR analyzer/107711
	* analyzer-language.cc: Include "diagnostic.h".
	(maybe_stash_named_constant): Add logger param and use it to log
	the name being looked up, and the result.
	(stash_named_constants): New, splitting out from...
	(on_finish_translation_unit): ...this function.  Call
	get_or_create_logfile and use the result to create a logger
	instance, passing it to stash_named_constants.
	* analyzer.h (get_or_create_any_logfile): New decl.
	* engine.cc (dump_fout, owns_dump_fout): New globals, split out
	from run_checkers.
	(get_or_create_any_logfile): New function, split out from...
	(run_checkers): ...here, so that the logfile can be opened by
	on_finish_translation_unit.  Clear the globals when closing the
	dump file.

gcc/testsuite/ChangeLog:
	PR analyzer/107711
	* gcc.dg/analyzer/fdump-analyzer-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2022-11-16 17:38:24 -05:00
Steve Kargl
bdd784fc48 Fortran: ICE on procedure arguments with non-integer length [PR107707]
gcc/fortran/ChangeLog:

	PR fortran/107707
	* interface.cc (gfc_compare_actual_formal): Check that we actually
	have integer values before asking gmp_* to use them.

gcc/testsuite/ChangeLog:

	PR fortran/107707
	* gfortran.dg/pr107707.f90: New test.
2022-11-16 22:50:51 +01:00
Marek Polacek
c85f8dbb17 c++: P2448 - Relaxing some constexpr restrictions [PR106649]
This patch implements C++23 P2448, which lifts more restrictions on the
constexpr keyword.  It's effectively going the way of being just a hint
(hello, inline!).

This gist is relatively simple: in C++23, a constexpr function's return
type/parameter type doesn't have to be a literal type; and you can have
a constexpr function for which no invocation satisfies the requirements
of a core constant expression.  For example,

  void f(int& i); // not constexpr

  constexpr void g(int& i) {
    f(i); // unconditionally calls a non-constexpr function
  }

is now OK, even though there isn't an invocation of 'g' that would be
a constant expression.  Maybe 'f' will be made constexpr soon, or maybe
this depends on the version of C++ used, and similar.  The patch is
unfortunately not that trivial.  The important bit is to use the new
require_potential_rvalue_constant_expression_fncheck in
maybe_save_constexpr_fundef (and where appropriate).  It has a new flag
that says that we're checking the body of a constexpr function, and in
that case it's OK to find constructs that aren't a constant expression.

Since it's useful to be able to check for problematic constructs even
in C++23, this patch implements a new warning, -Winvalid-constexpr,
which is a pedwarn turned on by default in C++20 and earlier, and which
can be turned on in C++23 as well, in which case it's an ordinary warning.
This I implemented by using the new function constexpr_error, used in
p_c_e_1 and friends.  (In some cases I believe fundef_p will be always
false (= hard error), but it made sense to me to be consistent and use
constexpr_error throughout p_c_e_1.)

While working on this I think I found a bug, see constexpr-nonlit15.C
and <https://gcc.gnu.org/PR107598>.  This patch doesn't address that.

This patch includes changes to diagnose the problem if the user doesn't
use -Winvalid-constexpr and calls a constexpr function that in fact isn't
constexpr-ready yet: maybe_save_constexpr_fundef registers the function
if warn_invalid_constexpr is 0 and explain_invalid_constexpr_fn then
gives the diagnostic.

	PR c++/106649

gcc/c-family/ChangeLog:

	* c-cppbuiltin.cc (c_cpp_builtins): Update value of __cpp_constexpr for
	C++23.
	* c-opts.cc (c_common_post_options): Set warn_invalid_constexpr
	depending on cxx_dialect.
	* c.opt (Winvalid-constexpr): New option.

gcc/cp/ChangeLog:

	* constexpr.cc (constexpr_error): New function.
	(is_valid_constexpr_fn): Use constexpr_error.
	(maybe_save_constexpr_fundef): Call
	require_potential_rvalue_constant_expression_fncheck rather than
	require_potential_rvalue_constant_expression.  Register the
	function if -Wno-invalid-constexpr was specified.
	(explain_invalid_constexpr_fn): Don't return early if a function marked
	'constexpr' that isn't actually a constant expression was called.
	(non_const_var_error): Add a bool parameter.  Use constexpr_error.
	(inline_asm_in_constexpr_error): Likewise.
	(cxx_eval_constant_expression): Adjust calls to non_const_var_error
	and inline_asm_in_constexpr_error.
	(potential_constant_expression_1): Add a bool parameter.  Use
	constexpr_error.
	(require_potential_rvalue_constant_expression_fncheck): New function.
	* cp-tree.h (require_potential_rvalue_constant_expression_fncheck):
	Declare.
	* method.cc (struct comp_info): Call
	require_potential_rvalue_constant_expression_fncheck rather than
	require_potential_rvalue_constant_expression.

gcc/ChangeLog:

	* doc/invoke.texi: Document -Winvalid-constexpr.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-ctor2.C: Expect an error in c++20_down only.
	* g++.dg/cpp0x/constexpr-default-ctor.C: Likewise.
	* g++.dg/cpp0x/constexpr-diag3.C: Likewise.
	* g++.dg/cpp0x/constexpr-ex1.C: Likewise.
	* g++.dg/cpp0x/constexpr-friend.C: Likewise.
	* g++.dg/cpp0x/constexpr-generated1.C: Likewise.
	* g++.dg/cpp0x/constexpr-ice5.C: Likewise.
	* g++.dg/cpp0x/constexpr-ice6.C: Likewise.
	* g++.dg/cpp0x/constexpr-memfn1.C: Likewise.
	* g++.dg/cpp0x/constexpr-neg2.C: Likewise.
	* g++.dg/cpp0x/constexpr-non-const-arg.C: Likewise.
	* g++.dg/cpp0x/constexpr-reinterpret1.C: Likewise.
	* g++.dg/cpp0x/pr65327.C: Likewise.
	* g++.dg/cpp1y/constexpr-105050.C: Likewise.
	* g++.dg/cpp1y/constexpr-89285-2.C: Likewise.
	* g++.dg/cpp1y/constexpr-89285.C: Likewise.
	* g++.dg/cpp1y/constexpr-89785-2.C: Likewise.
	* g++.dg/cpp1y/constexpr-neg1.C: Likewise.
	* g++.dg/cpp1y/constexpr-nsdmi7b.C: Likewise.
	* g++.dg/cpp1y/constexpr-throw.C: Likewise.
	* g++.dg/cpp23/constexpr-nonlit3.C: Remove dg-error.
	* g++.dg/cpp23/constexpr-nonlit6.C: Call the test functions.
	* g++.dg/cpp23/feat-cxx2b.C: Adjust the expected value of
	__cpp_constexpr.
	* g++.dg/cpp2a/consteval3.C: Remove dg-error.
	* g++.dg/cpp2a/constexpr-new7.C: Expect an error in c++20_down only.
	* g++.dg/cpp2a/constexpr-try5.C: Remove dg-error.
	* g++.dg/cpp2a/spaceship-constexpr1.C: Expect an error in c++20_down
	only.
	* g++.dg/cpp2a/spaceship-eq3.C: Likewise.
	* g++.dg/diagnostic/constexpr1.C: Remove dg-error.
	* g++.dg/gomp/pr79664.C: Use -Winvalid-constexpr -pedantic-errors.
	* g++.dg/ubsan/vptr-4.C: Likewise.
	* g++.dg/cpp23/constexpr-nonlit10.C: New test.
	* g++.dg/cpp23/constexpr-nonlit11.C: New test.
	* g++.dg/cpp23/constexpr-nonlit12.C: New test.
	* g++.dg/cpp23/constexpr-nonlit13.C: New test.
	* g++.dg/cpp23/constexpr-nonlit14.C: New test.
	* g++.dg/cpp23/constexpr-nonlit15.C: New test.
	* g++.dg/cpp23/constexpr-nonlit16.C: New test.
	* g++.dg/cpp23/constexpr-nonlit8.C: New test.
	* g++.dg/cpp23/constexpr-nonlit9.C: New test.
2022-11-16 16:29:09 -05:00
Jonathan Wakely
dbdce6adb7 libstdc++: Fix dumb typos in ALT128 support in <format> [PR107720]
This is only a partial fix for the PR.

libstdc++-v3/ChangeLog:

	PR libstdc++/107720
	* include/std/format (__format::_Arg_t): Fix typo in enumerator
	name.
	(_Arg_value::_S_get): Fix missing semi-colons.
2022-11-16 20:52:53 +00:00
Jonathan Wakely
629897ed80 libstdc++: Improve performance of chrono::utc_clock::now()
We can use an array instead of a std::vector, and we can avoid the
binary search for the common case of a time point after the most recent
leap second. On one system where I tested this, utc_clock::now() now
takes about 16ns instead of 31ns.

libstdc++-v3/ChangeLog:

	* include/std/chrono (get_leap_second_info): Optimize.
2022-11-16 20:52:53 +00:00
Jonathan Wakely
2f5c071860 libstdc++: Adjust <format> for Clang compatibility [PR107712]
Clang doesn't define __builtin_toupper, so use std::toupper.

Also add some (not actually required since C++20) typename keywords to
help Clang versions up to and including 15.

libstdc++-v3/ChangeLog:

	PR libstdc++/107712
	* include/std/format (__format::__formatter_int::format): Use
	std::toupper when __builtin_toupper isn't available.
	(basic_format_arg::handle): Add 'typename'.
	* include/std/complex (complex<T>): Add 'typename'.
2022-11-16 20:52:37 +00:00
Jonathan Wakely
22cb0fea71 libstdc++: Disable std::format of _Float128 if std::to_chars is innaccurate
This restricts std::format support for _Float128 (and __float128) to
targets where glibc provides __strfromf128 and so can give correct
output.

libstdc++-v3/ChangeLog:

	* include/std/format [__FLT128_DIG__] (_GLIBCXX_FORMAT_F128):
	Only support formatting _Float128 when glibc provides the
	functionality needed for accurate std::to_chars.
2022-11-16 20:52:03 +00:00
Harald Anlauf
96e4244ef3 Fortran: error recovery after reference to bad CLASS variable [PR107681]
gcc/fortran/ChangeLog:

	PR fortran/107681
	* resolve.cc (resolve_fl_var_and_proc): Prevent NULL pointer
	dereference with reference to bad CLASS variable.

gcc/testsuite/ChangeLog:

	PR fortran/107681
	* gfortran.dg/pr107681.f90: New test.
2022-11-16 21:41:19 +01:00
Harald Anlauf
713dcfc85e Fortran: ICE in simplification of array expression involving power [PR107680]
gcc/fortran/ChangeLog:

	PR fortran/107680
	* arith.cc (arith_power): Check that operands are properly converted
	before attempting to simplify.

gcc/testsuite/ChangeLog:

	PR fortran/107680
	* gfortran.dg/pr107680.f90: New test.
2022-11-16 21:13:16 +01:00
Philipp Tomsich
ac74b3f82b RISC-V: Split "(a & (1UL << bitno)) ? 0 : 1" to bext + xori
We avoid reassociating "(~(a >> BIT_NO)) & 1" into "((~a) >> BIT_NO) & 1"
by splitting it into a zero-extraction (bext) and an xori.  This both
avoids burning a register on a temporary and generates a sequence that
clearly captures 'extract bit, then invert bit'.

This change improves the previously generated
    srl   a0,a0,a1
    not	  a0,a0
    andi  a0,a0,1
into
    bext  a0,a0,a1
    xori  a0,a0,1

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>

gcc/ChangeLog:

	* config/riscv/bitmanip.md: Add split covering
	"(a & (1 << BIT_NO)) ? 0 : 1".

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/zbs-bext.c: Add testcases.
	* gcc.target/riscv/zbs-bexti.c: Add testcases.
2022-11-16 20:33:59 +01:00
Philipp Tomsich
32462550f2 RISC-V: Split "(a & (1UL << bitno)) ? 0 : -1" to bext + addi
For a straightforward application of bext for the following function
  long bext64(long a, char bitno)
  {
    return (a & (1UL << bitno)) ? 0 : -1;
  }
we generate
	srl	a0,a0,a1	# 7	[c=4 l=4]  lshrdi3
	andi	a0,a0,1	# 8	[c=4 l=4]  anddi3/1
	addi	a0,a0,-1	# 14	[c=4 l=4]  adddi3/1
due to the following failed match at combine time:
  (set (reg:DI 82)
       (zero_extract:DI (reg:DI 83)
            (const_int 1 [0x1])
            (reg:DI 84)))

The existing pattern for bext requires the 3rd argument to
zero_extract to be a QImode register wrapped in a zero_extension.
This adds an additional pattern that allows an Xmode argument.

With this change, the testcase compiles to
	bext	a0,a0,a1	# 8	[c=4 l=4]  *bextdi
	addi	a0,a0,-1	# 14	[c=4 l=4]  adddi3/1

gcc/ChangeLog:

	* config/riscv/bitmanip.md (*bext<mode>): Add an additional
	pattern that allows the 3rd argument to zero_extract to be
	an Xmode register operand.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/zbs-bext.c: Add testcases.
	* gcc.target/riscv/zbs-bexti.c: Add testcases.
2022-11-16 20:31:17 +01:00
Hans-Peter Nilsson
e91d514575 testsuite: Fix mistransformed gcov
In commit r13-2619-g34b9a03353d3fd, [transform] was applied to all
invocations of gcov, for both out-of-tree and in-tree testing.
For in-tree cross builds, this means gcov was called as
"/path/to/gccobj/gcc/target-tuple-gcov" gcov-pr94029.c which is
incorrect, as it's there "/path/to/gccobj/gcc/gcov" until it's
installed.  This caused a testsuite failure, like:

Running /x/gcc/gcc/testsuite/gcc.misc-tests/gcov.exp ...
FAIL: gcc.misc-tests/gcov-pr94029.c gcov failed: spawn failed

To avoid cumbersome conditionals, use a dedicated new helper function.

gcc/testsuite:
	* lib/gcc-dg.exp (gcc-transform-out-of-tree): New proc.
	* g++.dg/gcov/gcov.exp, gcc.misc-tests/gcov.exp: Call
	gcc-transform-out-of-tree instead of transform.
2022-11-16 18:19:17 +01:00