]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
6 months agolibfortran: G formatting for UNSIGNED [PR118536]
Harald Anlauf [Fri, 17 Jan 2025 20:20:31 +0000 (21:20 +0100)] 
libfortran: G formatting for UNSIGNED [PR118536]

PR libfortran/118536

libgfortran/ChangeLog:

* io/transfer.c (formatted_transfer_scalar_write): Handle UNSIGNED
in G formatting.

gcc/testsuite/ChangeLog:

* gfortran.dg/unsigned_write_2.f90: New test.

6 months ago[PR118067][LRA]: Check secondary memory mode for the reg class
Vladimir N. Makarov [Fri, 17 Jan 2025 20:56:29 +0000 (15:56 -0500)] 
[PR118067][LRA]: Check secondary memory mode for the reg class

  This is the second patch for the PR for the new test.  The patch
solves problem in the case when secondary memory mode (SImode in the
PR test) returned by hook secondary_memory_needed_mode can not be used
for reg class (ALL_MASK_REGS) involved in secondary memory moves.  The
patch uses reg mode instead of one returned by
secondary_memory_needed_mode in this case.

gcc/ChangeLog:

PR rtl-optimization/118067
* lra-constraints.cc (invalid_mode_reg_p): New function.
(curr_insn_transform): Use it to check mode returned by target
secondary_memory_needed_mode.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr118067-2.c: New.

6 months agotestsuite: Make embed-10.c test more robust
Jakub Jelinek [Fri, 17 Jan 2025 20:00:50 +0000 (21:00 +0100)] 
testsuite: Make embed-10.c test more robust

With the https://gcc.gnu.org/pipermail/gcc-patches/2025-January/673945.html
hack we get slightly different error wording in one of the errors, given that
the test actually does use #embed, I think both wordings are just fine and
we should accept them.

2025-01-17  Jakub Jelinek  <jakub@redhat.com>

* c-c++-common/cpp/embed-10.c: Allow a different error wording for
C++.

6 months agod: Add testcase for fixed PR117115
Iain Buclaw [Fri, 17 Jan 2025 19:10:39 +0000 (20:10 +0100)] 
d: Add testcase for fixed PR117115

This was fixed in upstream dmd, and merged in r15-6824.

PR d/117115

gcc/testsuite/ChangeLog:

* gdc.dg/pr117115.d: New test.

6 months agos390: Replace some checking assertions with output_operand_lossage [PR118511]
Jakub Jelinek [Fri, 17 Jan 2025 18:27:59 +0000 (19:27 +0100)] 
s390: Replace some checking assertions with output_operand_lossage [PR118511]

r15-2002 s390: Fully exploit vgm, vgbm, vrepi change added
some code to print_operand and added gcc_checking_asserts in there.
But print_operand ideally should have no assertions in it, as most
of the assumptions can be easily violated by people using it in
inline asm.
This issue in particular was seen by failure to compile s390-tools,
which had in its extended inline asm uses of %r1 and %r2.
I really don't know if they meant %%r1 and %%r2 or %1 and %2 and
will leave that decision to the maintainers, but the thing is that
%r1 and %r2 used to expand like %1 and %2 in GCC 14 and earlier,
now in checking build it ICEs and in --enable-checking=release build
fails to assemble (the checking assert is ignored and the compiler just uses
some uninitialized variables to emit something arbitrary).

With the following patch it is diagnosed as error consistently
regardless if it is release checking or no checking or checking compiler.

Note, I see also
      else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSLDM)
        {
          fprintf (file, "%s", ":tls_ldcall:");
          const char *name = get_some_local_dynamic_name ();
          gcc_assert (name);
          assemble_name (file, name);
        }
in print_operand, maybe that isn't a big deal because it might be
impossible to construct inline asm argument which is UNSPEC_TLSLDM.
And then there is
        case 'e': case 'f':
        case 's': case 't':
          {
            int start, end;
            int len;
            bool ok;

            len = (code == 's' || code == 'e' ? 64 : 32);
            ok = s390_contiguous_bitmask_p (ival, true, len, &start, &end);
            gcc_assert (ok);
            if (code == 's' || code == 't')
              ival = start;
            else
              ival = end;
          }
          break;
which likely should be also output_operand_lossage but I haven't tried
to reproduce that.

2025-01-17  Jakub Jelinek  <jakub@redhat.com>

PR target/118511
* config/s390/s390.cc (print_operand) <case 'p'>: Use
output_operand_lossage instead of gcc_checking_assert.
(print_operand) <case 'q'>: Likewise.
(print_operand) <case 'r'>: Likewise.

* gcc.target/s390/pr118511.c: New test.

6 months agoAArch64: Use standard names for SVE saturating arithmetic
Tamar Christina [Fri, 17 Jan 2025 17:44:23 +0000 (17:44 +0000)] 
AArch64: Use standard names for SVE saturating arithmetic

Rename the existing SVE unpredicated saturating arithmetic instructions
to use standard names which are used by IFN_SAT_ADD and IFN_SAT_SUB.

gcc/ChangeLog:

* config/aarch64/aarch64-sve.md: Rename insns

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve/saturating_arithmetic.inc:
Template file for auto-vectorizer tests.
* gcc.target/aarch64/sve/saturating_arithmetic_1.c:
Instantiate 8-bit vector tests.
* gcc.target/aarch64/sve/saturating_arithmetic_2.c:
Instantiate 16-bit vector tests.
* gcc.target/aarch64/sve/saturating_arithmetic_3.c:
Instantiate 32-bit vector tests.
* gcc.target/aarch64/sve/saturating_arithmetic_4.c:
Instantiate 64-bit vector tests.

6 months agoAArch64: Use standard names for saturating arithmetic
Tamar Christina [Fri, 17 Jan 2025 17:43:49 +0000 (17:43 +0000)] 
AArch64: Use standard names for saturating arithmetic

This renames the existing {s,u}q{add,sub} instructions to use the
standard names {s,u}s{add,sub}3 which are used by IFN_SAT_ADD and
IFN_SAT_SUB.

The NEON intrinsics for saturating arithmetic and their corresponding
builtins are changed to use these standard names too.

Using the standard names for the instructions causes 32 and 64-bit
unsigned scalar saturating arithmetic to use the NEON instructions,
resulting in an additional (and inefficient) FMOV to be generated when
the original operands are in GP registers. This patch therefore also
restores the original behaviour of using the adds/subs instructions
in this circumstance.

Additional tests are written for the scalar and Adv. SIMD cases to
ensure that the correct instructions are used. The NEON intrinsics are
already tested elsewhere.

gcc/ChangeLog:

* config/aarch64/aarch64-builtins.cc: Expand iterators.
* config/aarch64/aarch64-simd-builtins.def: Use standard names
* config/aarch64/aarch64-simd.md: Use standard names, split insn
definitions on signedness of operator and type of operands.
* config/aarch64/arm_neon.h: Use standard builtin names.
* config/aarch64/iterators.md: Add VSDQ_I_QI_HI iterator to
simplify splitting of insn for unsigned scalar arithmetic.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/scalar_intrinsics.c: Update testcases.
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect.inc:
Template file for unsigned vector saturating arithmetic tests.
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_1.c:
8-bit vector type tests.
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_2.c:
16-bit vector type tests.
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_3.c:
32-bit vector type tests.
* gcc.target/aarch64/advsimd-intrinsics/saturating_arithmetic_autovect_4.c:
64-bit vector type tests.
* gcc.target/aarch64/saturating_arithmetic.inc: Template file
for scalar saturating arithmetic tests.
* gcc.target/aarch64/saturating_arithmetic_1.c: 8-bit tests.
* gcc.target/aarch64/saturating_arithmetic_2.c: 16-bit tests.
* gcc.target/aarch64/saturating_arithmetic_3.c: 32-bit tests.
* gcc.target/aarch64/saturating_arithmetic_4.c: 64-bit tests.

Co-authored-by: Tamar Christina <tamar.christina@arm.com>
6 months agors6000, Remove redundant built-in __builtin_vsx_xvcvuxwdp
Carl Love [Thu, 1 Aug 2024 22:33:42 +0000 (18:33 -0400)] 
rs6000, Remove redundant built-in __builtin_vsx_xvcvuxwdp

The built-in __builtin_vsx_xvcvuxwdp can be covered with PVIPR
function vec_doubleo on LE and vec_doublee on BE.  There are no test
cases or documentation for __builtin_vsx_xvcvuxwdp.  This patch
removes the redundant built-in.

gcc/ChangeLog:
* config/rs6000/rs6000-builtins.def (__builtin_vsx_xvcvuxwdp):
Remove built-in definition.

6 months agors6000, remove built-ins __builtin_vsx_vperm_8hi and __builtin_vsx_vperm_8hi_uns
Carl Love [Wed, 31 Jul 2024 20:40:34 +0000 (16:40 -0400)] 
rs6000, remove built-ins __builtin_vsx_vperm_8hi and __builtin_vsx_vperm_8hi_uns

The two built-ins __builtin_vsx_vperm_8hi and __builtin_vsx_vperm_8hi_uns
are redundant. The are covered by the overloaded vec_perm built-in.  The
built-ins are not documented and do not have test cases.

The removal of these built-ins was missed in commit gcc r15-1923 on
7/9/2024.

This patch removes the redundant built-ins.

gcc/ChangeLog:
* config/rs6000/rs6000-builtins.def (__builtin_vsx_vperm_8hi,
__builtin_vsx_vperm_8hi_uns): Remove built-in definitions.

6 months agors6000, add testcases to the overloaded vec_perm built-in
Carl Love [Wed, 31 Jul 2024 20:31:34 +0000 (16:31 -0400)] 
rs6000, add testcases to the overloaded vec_perm built-in

The overloaded vec_perm built-in supports permuting signed and unsigned
vectors of char, bool char, short int, short bool, int, bool, long long
int, long long bool, int128, float and double.  However, not all of the
supported arguments are included in the test cases.  This patch adds
the missing test cases.

Additionally, in the 128-bit debug print statements the expected result and
the result need to be cast to unsigned long long to print correctly.  The
patch makes this additional change to the print statements.

gcc/ChangeLog:
* doc/extend.texi: Fix spelling mistake in description of the
vec_sel built-in.  Add documentation of the 128-bit vec_perm
instance.

gcc/testsuite/ChangeLog:
* gcc.target/powerpc/vsx-builtin-3.c: Add vec_perm test cases for
arguments of type vector signed long long int, long long bool,
bool, bool short, bool char and pixel, vector unsigned long long
int, unsigned int, unsigned short int, unsigned char.  Cast
arguments for debug prints to unsigned long long.
* gcc.target/powerpc/builtins-4-int128-runnable.c: Add vec_perm
test cases for signed and unsigned int128 arguments.

6 months agors6000, fix test builtins-1-p10-runnable.c
Carl Love [Thu, 3 Oct 2024 01:05:08 +0000 (21:05 -0400)] 
rs6000, fix test builtins-1-p10-runnable.c

The test has two issues:

1) The test should generate execute abort() if an error is found.
However, the test contains a #define 0 which actually enables the
error prints not exectuting void() because the debug code is protected
by an #ifdef not #if.  The #define DEBUG needs to be removed to so the
test will abort on an error.

2) The vec_i_expected output was tweeked to test that it would fail.
The test value was not removed.

By removing the #define DEBUG, the test fails and reports 1 failure.
Removing the intentionally wrong expected value results in the test
passing with no errors as expected.

gcc/testsuite/ChangeLog:
* gcc.target/powerpc/builtins-1-p10-runnable.c: Remove #define
DEBUG. Replace vec_i_expected value with correct value.

6 months agoAVR: Add "const" attribute to avr built-in functions if possible.
Georg-Johann Lay [Fri, 17 Jan 2025 12:14:51 +0000 (13:14 +0100)] 
AVR: Add "const" attribute to avr built-in functions if possible.

gcc/
* config/avr/avr-c.cc (DEF_BUILTIN): Add ATTRS argument to macro
definition.
* config/avr/avr.cc: Same.
(avr_init_builtins) <attr_const>: New variable that can be used
as ATTRS argument in DEF_BUILTIN.
* config/avr/builtins.def (DEF_BUILTIN): Add ATTRS parameter
to all definitions.

6 months agoc++/modules: Propagate FNDECL_USED_AUTO when propagating deduced return types [PR118049]
Nathaniel Shead [Fri, 17 Jan 2025 10:29:08 +0000 (21:29 +1100)] 
c++/modules: Propagate FNDECL_USED_AUTO when propagating deduced return types [PR118049]

In the linked testcase, we're erroring because the declared return types
of the functions do not appear to match.  This is because when merging
the deduced return types for 'foo' in 'auto-5_b.C', we overwrote the
return type for the declaration with the deduced return type from
'auto-5_a.C' but neglected to track that we were originally declared
with 'auto'.

As a drive-by improvement to QOI, also add checks for if the deduced
return types do not match; this is currently useful because we do not
check the equivalence of the bodies of functions yet.

PR c++/118049

gcc/cp/ChangeLog:

* module.cc (trees_in::is_matching_decl): Propagate
FNDECL_USED_AUTO as well.

gcc/testsuite/ChangeLog:

* g++.dg/modules/auto-5_a.C: New test.
* g++.dg/modules/auto-5_b.C: New test.
* g++.dg/modules/auto-5_c.C: New test.
* g++.dg/modules/auto-6_a.H: New test.
* g++.dg/modules/auto-6_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
6 months agoOpenMP/C++: Fix declare_variant's 'adjust_args' if there is a 'this' pointer [PR118321]
Tobias Burnus [Fri, 17 Jan 2025 13:25:18 +0000 (14:25 +0100)] 
OpenMP/C++: Fix declare_variant's 'adjust_args' if there is a 'this' pointer [PR118321]

The adjust_args clause is internally store as the i-th argument to the function,
which fails if hidden arguments come before. This commit handles the C++ 'this'
pointer by shifting the internal arg index by one.

PR fortran/118321

gcc/cp/ChangeLog:

* decl.cc (omp_declare_variant_finalize_one): Shift adjust_args index
by one for non-static class function's 'this' pointer.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/adjust-args-4.C: New test.

6 months agoc++: Allow pragmas in NSDMIs [PR118147]
Nathaniel Shead [Fri, 20 Dec 2024 11:09:39 +0000 (22:09 +1100)] 
c++: Allow pragmas in NSDMIs [PR118147]

This patch removes the (unnecessary) CPP_PRAGMA_EOL case from
cp_parser_cache_defarg, which currently has the result that any pragmas
in the NSDMI cause an error.

PR c++/118147

gcc/cp/ChangeLog:

* parser.cc (cp_parser_cache_defarg): Don't error when
CPP_PRAGMA_EOL.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/nsdmi-defer7.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
6 months agotestsuite/117958 - ifcombine differences on aarch64 vs rest
Richard Biener [Fri, 17 Jan 2025 12:18:11 +0000 (13:18 +0100)] 
testsuite/117958 - ifcombine differences on aarch64 vs rest

ifcombine depends on BRANCH_COST and the testcase relies on ifcombine
to fully optimize the function.  But the important parts are optimized
everywhere, so the following delectively XFAILs the less important part.

PR testsuite/117958
* g++.dg/tree-ssa/pr117123.C: XFAIL parts on aarch64-*-*.

6 months agoAVR: Use INT_N to built-in define __int24.
Georg-Johann Lay [Thu, 16 Jan 2025 18:43:27 +0000 (19:43 +0100)] 
AVR: Use INT_N to built-in define __int24.

This patch uses the INT_N interface to define __int24 in avr-modes.def.

Since the testsuite uses -Wpedantic and __int24 is a C/C++ extension,
uses of __int24 and __uint24 is now marked as __extension__.

PR target/118329
gcc/
* config/avr/avr-modes.def: Add INT_N (PSI, 24).
* config/avr/avr.cc (avr_init_builtin_int24)
<__int24>: Remove definition.
<__uint24>: Adjust definition to INT_N interface.
gcc/testsuite/
* gcc.target/avr/pr115830-add.c (__int24, __uint24): Add __extension__
to respective typedefs.
* gcc.target/avr/pr115830-sub-ext.c: Same.
* gcc.target/avr/pr115830-sub.c: Same.
* gcc.target/avr/torture/get-mem.c: Same.
* gcc.target/avr/torture/set-mem.c: Same.
* gcc.target/avr/torture/ifelse-c.h: Same.
* gcc.target/avr/torture/ifelse-d.h: Same.
* gcc.target/avr/torture/ifelse-q.h: Same.
* gcc.target/avr/torture/ifelse-r.h: Same.
* gcc.target/avr/torture/int24-mul.c: Same.
* gcc.target/avr/torture/pr109907-2.c: Same.
* gcc.target/avr/torture/pr61443.c: Same.
* gcc.target/avr/torture/pr63633-ice-mult.c: Same.
* gcc.target/avr/torture/shift-l-u24.c: Same.
* gcc.target/avr/torture/shift-r-i24.c: Same.
* gcc.target/avr/torture/shift-r-u24.c: Same.
* gcc.target/avr/torture/add-extend.c: Same.
* gcc.target/avr/torture/sub-extend.c: Same.
* gcc.target/avr/torture/sub-zerox.c: Same.
* gcc.target/avr/torture/test-gprs.h: Same.

6 months agomatch.pd: Fix (FTYPE) N CMP (FTYPE) M optimization for GENERIC [PR118522]
Jakub Jelinek [Fri, 17 Jan 2025 10:30:07 +0000 (11:30 +0100)] 
match.pd: Fix (FTYPE) N CMP (FTYPE) M optimization for GENERIC [PR118522]

The last case of this optimization assumes that if 2 integral types
have same precision and TYPE_UNSIGNED, then they are uselessly convertible.
While that is very likely the case for GIMPLE, it is not the case for
GENERIC, so the following patch adds there a convert so that the
optimization produces also valid GENERIC.  Without it we got
(int) p == b where b had _BitInt(32) type, so incompatible types.

2025-01-17  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/118522
* match.pd ((FTYPE) N CMP (FTYPE) M): Add convert, as in GENERIC
integral types with the same precision and sign might actually not
be compatible types.

* gcc.dg/bitint-120.c: New test.

6 months agoc++: Friend classes don't shadow enclosing template class paramater [PR118255]
Simon Martin [Sun, 5 Jan 2025 09:36:47 +0000 (10:36 +0100)] 
c++: Friend classes don't shadow enclosing template class paramater [PR118255]

We currently reject the following code

=== code here ===
template <int non_template> struct S { friend class non_template; };
class non_template {};
S<0> s;
=== code here ===

While EDG agrees with the current behaviour, clang and MSVC don't (see
https://godbolt.org/z/69TGaabhd), and I believe that this code is valid,
since the friend clause does not actually declare a type, so it cannot
shadow anything. The fact that we didn't error out if the non_template
class was declared before S backs this up as well.

This patch fixes this by skipping the call to check_template_shadow for
hidden bindings.

PR c++/118255

gcc/cp/ChangeLog:

* name-lookup.cc (pushdecl): Don't call check_template_shadow
for hidden bindings.

gcc/testsuite/ChangeLog:

* g++.dg/lookup/pr99116-1.C: Adjust test expectation.
* g++.dg/template/friend84.C: New test.

6 months agotree-optimization/92539 - missed optimization leads to bogus -Warray-bounds
Richard Biener [Mon, 13 Jan 2025 12:24:06 +0000 (13:24 +0100)] 
tree-optimization/92539 - missed optimization leads to bogus -Warray-bounds

The following makes niter analysis recognize a loop with an exit
condition scanning over a STRING_CST.  This is done via enhancing
the force evaluation code rather than recognizing for example
strlen (s) as number of iterations because it allows to handle
some more cases.

STRING_CSTs are easy to handle since nothing can write to them, also
processing those should be cheap.  I've refrained from handling
anything besides char8_t.

Note to avoid the -Warray-bound dianostic we have to either early unroll
the loop (there's no final value replacement done, there's a PR
for doing this as part of CD-DCE when possibly eliding a loop),
or create a canonical IV so we can DCE the loads.  The latter is what
the patch does, also avoiding to repeatedly force-evaluate niters.
This also makes final value replacement work again since now ivcanon
is after it.

There are some testsuite adjustments needed, in particular we now
unroll some loops early, causing messages to appear in different
passes but also vectorization to now no longer happening on
outer loops.  The changes mitigate that.

PR tree-optimization/92539
* tree-ssa-loop-ivcanon.cc (tree_unroll_loops_completely_1):
Also try force-evaluation if ivcanon did not yet run.
(canonicalize_loop_induction_variables):
When niter was computed constant by force evaluation add a
canonical IV if we didn't unroll.
* tree-ssa-loop-niter.cc (loop_niter_by_eval): When we
don't find a proper PHI try if the exit condition scans
over a STRING_CST and simulate that.

* g++.dg/warn/Warray-bounds-pr92539.C: New testcase.
* gcc.dg/tree-ssa/sccp-16.c: New testcase.
* g++.dg/vect/pr87621.cc: Use larger power to avoid
inner loop unrolling.
* gcc.dg/vect/pr89440.c: Use larger loop bound to avoid
inner loop unrolling.
* gcc.dg/pr77975.c: Scan cunrolli dump and adjust.

6 months agoOpenMP: Fix metadirective test failures on x86_64 with -m32
Sandra Loosemore [Fri, 17 Jan 2025 03:59:01 +0000 (03:59 +0000)] 
OpenMP: Fix metadirective test failures on x86_64 with -m32

gcc/testsuite/ChangeLog
* c-c++-common/gomp/metadirective-device.c: Don't add extra options
for target ia32.
* c-c++-common/gomp/metadirective-target-device-1.c: Likewise.

6 months agoRISC-V: Add -fcf-protection=[full|branch|return] to enable zicfiss, zicfilp.
Monk Chiang [Fri, 15 Nov 2024 10:18:36 +0000 (18:18 +0800)] 
RISC-V: Add -fcf-protection=[full|branch|return] to enable zicfiss, zicfilp.

gcc/ChangeLog:
* config/riscv/riscv.cc
(is_zicfilp_p): New function.
(is_zicfiss_p): New function.
* config/riscv/riscv-zicfilp.cc: Update.
* config/riscv/riscv.h: Update.
* config/riscv/riscv.md: Update.
* config/riscv/riscv-c.cc: Add CFI predefine marco.

gcc/testsuite/ChangeLog:
* c-c++-common/fcf-protection-1.c: Update.
* c-c++-common/fcf-protection-2.c: Update.
* c-c++-common/fcf-protection-3.c: Update.
* c-c++-common/fcf-protection-4.c: Update.
* c-c++-common/fcf-protection-5.c: Update.
* c-c++-common/fcf-protection-6.c: Update.
* c-c++-common/fcf-protection-7.c: Update.
* gcc.target/riscv/ssp-1.c: Update.
* gcc.target/riscv/ssp-2.c: Update.
* gcc.target/riscv/zicfilp-call.c: Update.
* gcc.target/riscv/interrupt-no-lpad.c: Update.

6 months agoRISC-V: Add .note.gnu.property for ZICFILP and ZICFISS ISA extension
Monk Chiang [Fri, 22 Mar 2024 13:10:07 +0000 (21:10 +0800)] 
RISC-V: Add .note.gnu.property for ZICFILP and ZICFISS ISA extension

gcc/ChangeLog:
* config/riscv/riscv.cc
(riscv_file_end): Add .note.gnu.property.

libgcc/ChangeLog:
* config/riscv/crti.S: Add lpad instructions.
* config/riscv/crtn.S: Likewise.
* config/riscv/save-restore.S: Likewise.
* config/riscv/riscv-asm.h: Add GNU_PROPERTY for ZICFILP,
ZICFISS.

Co-Developed-by: Jesse Huang <jesse.huang@sifive.com>
6 months agoRISC-V: Add Zicfilp ISA extension.
Monk Chiang [Fri, 22 Mar 2024 13:00:24 +0000 (21:00 +0800)] 
RISC-V: Add Zicfilp ISA extension.

This patch only support landing pad value is 0.
The next version will implement function signature based labeling
scheme.

RISC-V CFI SPEC: https://github.com/riscv/riscv-cfi

gcc/ChangeLog:
* common/config/riscv/riscv-common.cc: Add ZICFILP ISA
string.
* config.gcc: Add riscv-zicfilp.o
* config/riscv/riscv-passes.def (INSERT_PASS_BEFORE):
Insert landing pad instructions.
* config/riscv/riscv-protos.h (make_pass_insert_landing_pad):
Declare.
* config/riscv/riscv-zicfilp.cc: New file.
* config/riscv/riscv.cc
(riscv_trampoline_init): Add landing pad instructions.
(riscv_legitimize_call_address): Likewise.
(riscv_output_mi_thunk): Likewise.
* config/riscv/riscv.h: Update.
* config/riscv/riscv.md: Add landing pad patterns.
* config/riscv/riscv.opt (TARGET_ZICFILP): Define.
* config/riscv/t-riscv: Add build rule for
riscv-zicfilp.o

gcc/testsuite/ChangeLog:
* gcc.target/riscv/interrupt-no-lpad.c: New test.
* gcc.target/riscv/zicfilp-call.c: New test.

Co-Developed-by: Greg McGary <gkm@rivosinc.com>,
Kito Cheng <kito.cheng@gmail.com>

6 months agoRISC-V: Add Zicfiss ISA extension.
Monk Chiang [Fri, 15 Nov 2024 05:38:48 +0000 (13:38 +0800)] 
RISC-V: Add Zicfiss ISA extension.

This patch is implemented according to the RISC-V CFI specification.
It supports the generation of shadow stack instructions in the prologue,
epilogue, non-local gotos, and unwinding.

RISC-V CFI SPEC: https://github.com/riscv/riscv-cfi

gcc/ChangeLog:
* common/config/riscv/riscv-common.cc: Add ZICFISS ISA string.
* config/riscv/predicates.md: New predicate x1x5_operand.
* config/riscv/riscv.cc
(riscv_expand_prologue): Insert shadow stack instructions.
(riscv_expand_epilogue): Likewise.
(riscv_for_each_saved_reg): Assign t0 or ra register for
sspopchk instruction.
(need_shadow_stack_push_pop_p): New function. Omit shadow
stack operation on leaf function.
* config/riscv/riscv.h
(need_shadow_stack_push_pop_p): Define.
* config/riscv/riscv.md: Add shadow stack patterns.
(save_stack_nonlocal): Add shadow stack instructions for setjump.
(restore_stack_nonlocal): Add shadow stack instructions for longjump.
* config/riscv/riscv.opt (TARGET_ZICFISS): Define.

libgcc/ChangeLog:
* config/riscv/linux-unwind.h: Include shadow-stack-unwind.h.
* config/riscv/shadow-stack-unwind.h
(_Unwind_Frames_Extra): Define.
(_Unwind_Frames_Increment): Define.

gcc/testsuite/ChangeLog:
* gcc.target/riscv/ssp-1.c: New test.
* gcc.target/riscv/ssp-2.c: New test.

Co-Developed-by: Greg McGary <gkm@rivosinc.com>,
Kito Cheng <kito.cheng@gmail.com>

6 months agoDaily bump.
GCC Administrator [Fri, 17 Jan 2025 00:20:08 +0000 (00:20 +0000)] 
Daily bump.

6 months agod: Fix record layout of compiler-generated TypeInfo_Class [PR115249]
Iain Buclaw [Thu, 16 Jan 2025 23:23:45 +0000 (00:23 +0100)] 
d: Fix record layout of compiler-generated TypeInfo_Class [PR115249]

In r14-8766, the layout of TypeInfo_Class changed in the runtime
library, but didn't get reflected in the compiler-generated data,
causing a corruption of runtime type introspection on BigEndian targets.

This adjusts the size of the `ClassFlags' field from uint to ushort, and
adds a new ushort `depth' field in the space where ClassFlags used to
occupy.

PR d/115249

gcc/d/ChangeLog:

* typeinfo.cc (create_tinfo_types): Update internal Typenfo
representation.
(TypeInfoVisitor::visit (TypeInfoClassDeclaration *)): Likewise.

6 months agoc++: RESULT_DECL replacement w/ non-reduced ctx->object [PR105440]
Patrick Palka [Thu, 16 Jan 2025 23:28:17 +0000 (18:28 -0500)] 
c++: RESULT_DECL replacement w/ non-reduced ctx->object [PR105440]

After surgically replacing RESULT_DECL within a constexpr call result
(for sake of RVO), we can in some cases simplify the call result
further.

In the below testcase the result of get() during evaluation of a's
initializer is the self-referential CONSTRUCTOR:

  {._M_p=(char *) &<retval>._M_local_buf}

which after replacing RESULT_DECL with ctx->object (aka *D.2603, where
the D.2603 temporary points to the current element of _M_elems under
construction) becomes:

  {._M_p=(char *) &D.2603->_M_local_buf}

but what we really want is:

  {._M_p=(char *) &a._M_elems[0]._M_local_buf}.

so that the value of _M_p is independent of the value of the mutable
D.2603 temporary.

So to that end, it seems we should constexpr evaluate the result again
after RESULT_DECL replacement, which is what this patch implements.

PR c++/105440

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_call_expression): If any RESULT_DECLs get
replaced in the call result, try further evaluating the result.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constexpr-dtor17.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
6 months ago[testsuite] [arm] adjust wmul expectations [PR113560]
Alexandre Oliva [Thu, 16 Jan 2025 23:19:50 +0000 (20:19 -0300)] 
[testsuite] [arm] adjust wmul expectations [PR113560]

Since the machine-independent widening multiply logic was improved
PR113560, ARM's wmul-[567].c fail.  AFAICT the logic takes advantage
of the fact that, after zero-extending a narrow integral type to a
wider type, further zero- or sign-extending is equivalent, which
enables different instructions to be used for equivalent effect.

Adjust the tests to accept all the equivalent instructions that can be
used.

for  gcc/testsuite/ChangeLog

PR target/113560
* gcc.target/arm/wmul-5.c: Accept other mla instructions.
* gcc.target/arm/wmul-6.c: Likewise.
* gcc.target/arm/wmul-7.c: Likewise.

6 months ago[testsuite] [arm] multilibs.exp: adjust float abi opt matching
Alexandre Oliva [Thu, 16 Jan 2025 23:19:41 +0000 (20:19 -0300)] 
[testsuite] [arm] multilibs.exp: adjust float abi opt matching

The regexp that matches options that mess with multilibs matches
-mfloat=abi=, but that's probably a typo for -mfloat-abi=.  Fix that,
and add -msoft-float and -mhard-float.

for  gcc/testsuite/ChangeLog

* gcc.target/arm/multilib.exp: Skip if -mfloat-abi=* or any of
its aliases are used.

6 months ago[testsuite] skip test on non-hosted libstdc++ [PR113994]
Alexandre Oliva [Thu, 16 Jan 2025 23:19:38 +0000 (20:19 -0300)] 
[testsuite] skip test on non-hosted libstdc++ [PR113994]

Tests that include <string> need to be skipped when libstdc++ is built
in freestanding mode.

for  gcc/testsuite/ChangeLog

PR rtl-optimization/113994
* g++.dg/torture/pr113994.C: Require hosted libstdc++.

6 months ago[testsuite] drop explicit run overrider in more dfp tests
Alexandre Oliva [Thu, 16 Jan 2025 23:19:32 +0000 (20:19 -0300)] 
[testsuite] drop explicit run overrider in more dfp tests

A few more dfp tests that recently got backported to gcc-14 override
dfp.exp's selection of default action depending on dfprt.  Let the
default stand.

for  gcc/testsuite/ChangeLog

* gcc.dg/dfp/pr102674.c: Use the default dg-do.
* gcc.dg/dfp/pr43374.c: Likewise.

6 months ago[testsuite] rearrange requirements for dfp bitint run tests
Alexandre Oliva [Thu, 16 Jan 2025 23:19:28 +0000 (20:19 -0300)] 
[testsuite] rearrange requirements for dfp bitint run tests

dfp.exp sets the default to compile when dfprt is not available, but
some dfp bitint tests override the default without that requirement,
and try to run even when dfprt is not available.

Instead of overriding the default, rewrite the requirements so that
they apply even when compiling, since the absence of bitint or of
int128 would presumably cause compile failures.

for  gcc/testsuite/ChangeLog

* gcc.dg/dfp/bitint-1.c: Rewrite requirements to retain dfprt.
* gcc.dg/dfp/bitint-2.c: Likewise.
* gcc.dg/dfp/bitint-3.c: Likewise.
* gcc.dg/dfp/bitint-4.c: Likewise.
* gcc.dg/dfp/bitint-5.c: Likewise.
* gcc.dg/dfp/bitint-6.c: Likewise.
* gcc.dg/dfp/bitint-7.c: Likewise.
* gcc.dg/dfp/bitint-8.c: Likewise.
* gcc.dg/dfp/int128-1.c: Likewise.
* gcc.dg/dfp/int128-2.c: Likewise.
* gcc.dg/dfp/int128-3.c: Likewise.
* gcc.dg/dfp/int128-4.c: Likewise.

6 months agoFortran/OpenMP: Fix declare_variant's 'adjust_args' mishandling with return by refere...
Tobias Burnus [Thu, 16 Jan 2025 21:39:03 +0000 (22:39 +0100)] 
Fortran/OpenMP: Fix declare_variant's 'adjust_args' mishandling with return by reference [PR118321]

declare_variant's 'adjust_args' clause references the arguments in the
middle end by the argument position; this has to account for hidden
arguments that are inserted before due to return by reference,
as done in this commit.

PR fortran/118321

gcc/fortran/ChangeLog:

* trans-openmp.cc (gfc_trans_omp_declare_variant): Honor hidden
arguments for append_arg's need_device_ptr.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/adjust-args-12.f90: New test.

6 months agoc++: explicit spec of constrained member tmpl [PR107522]
Patrick Palka [Thu, 16 Jan 2025 21:40:08 +0000 (16:40 -0500)] 
c++: explicit spec of constrained member tmpl [PR107522]

When defining a explicit specialization of a constrained member template
(of a class template) such as f and g in the below testcase, the
DECL_TEMPLATE_PARMS of the corresponding TEMPLATE_DECL are partially
instantiated, whereas its associated constraints are carried over
from the original template and thus are in terms of the original
DECL_TEMPLATE_PARMS.  So during normalization for such an explicit
specialization we need to consider the (parameters of) the most general
template, since that's what the constraints are in terms of and since we
always use the full set of template arguments during satisfaction.

PR c++/107522

gcc/cp/ChangeLog:

* constraint.cc (get_normalized_constraints_from_decl): Use the
most general template for an explicit specialization of a
member template.

gcc/testsuite/ChangeLog:

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

Reviewed-by: Jason Merrill <jason@redhat.com>
6 months agoc++: pack expansion arg vs non-pack parm checking ICE [PR118454]
Patrick Palka [Thu, 16 Jan 2025 21:08:25 +0000 (16:08 -0500)] 
c++: pack expansion arg vs non-pack parm checking ICE [PR118454]

During ahead of time template argument coercion, we handle the case of
passing a pack expansion to a non-pack parameter by breaking out early
and using the original unconverted arguments, deferring coercion until
instantiation time where we have concrete arguments.

This PR illustrates we still need to strip typedefs from the original
arguments in this case as in the ordinary case, for sake of our template
argument hashing/equivalence routines which assume template arguments
went through strip_typedefs.

Since we're using the unconverted arguments we need to preserve
injected-class-name typedefs because we use them to distinguish passing
an injected-class-name vs the corresponding specialization as the
argument to a template template parameter (the former is valid, the
latter isn't).

PR c++/118454

gcc/cp/ChangeLog:

* cp-tree.h (STF_KEEP_INJ_CLASS_NAME): Define.
* pt.cc (iterative_hash_template_argument) <case tcc_type>:
Clarify comment for when we'd see an alias template
specialization here.
(coerce_template_parms): Strip typedefs (except for
injected-class-names) in the pack expansion early break cases
that defer coercion.
* tree.cc (strip_typedefs): Don't strip an injected-class-name
if STF_KEEP_INJ_CLASS_NAME is set.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/variadic187.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
6 months agoc++: make finish_pseudo_destructor_expr SFINAE-aware [PR116417]
Patrick Palka [Thu, 16 Jan 2025 21:05:46 +0000 (16:05 -0500)] 
c++: make finish_pseudo_destructor_expr SFINAE-aware [PR116417]

PR c++/116417

gcc/cp/ChangeLog:

* cp-tree.h (finish_pseudo_destructor_expr): Add complain
parameter.
* parser.cc (cp_parser_postfix_dot_deref_expression): Pass
complain=tf_warning_or_error to finish_pseudo_destructor_expr.
* pt.cc (tsubst_expr): Pass complain to
finish_pseudo_destructor_expr.
* semantics.cc (finish_pseudo_destructor_expr): Check complain
before emitting a diagnostic.

gcc/testsuite/ChangeLog:

* g++.dg/template/pseudodtor7.C: New test.

Reviewed-by: Marek Polacek <polacek@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
6 months agoc++: Make sure fold_sizeof_expr returns the correct type [PR117775]
Simon Martin [Thu, 16 Jan 2025 15:27:06 +0000 (16:27 +0100)] 
c++: Make sure fold_sizeof_expr returns the correct type [PR117775]

We currently ICE upon the following code, that is valid under
-Wno-pointer-arith:

=== cut here ===
int main() {
  decltype( [](auto) { return sizeof(void); } ) x;
  return x.operator()(0);
}
=== cut here ===

The problem is that "fold_sizeof_expr (sizeof(void))" returns
size_one_node, that has a different TREE_TYPE from that of the sizeof
expression, which later triggers an assert in cxx_eval_store_expression.

This patch makes sure that fold_sizeof_expr always returns a tree with
the size_type_node type.

PR c++/117775

gcc/cp/ChangeLog:

* decl.cc (fold_sizeof_expr): Make sure the folded result has
type size_type_node.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/constexpr-117775.C: New test.

6 months agolibfortran: fix conversion of UNSIGNED(kind=16) to decimal in output [PR118406]
Harald Anlauf [Thu, 16 Jan 2025 19:23:06 +0000 (20:23 +0100)] 
libfortran: fix conversion of UNSIGNED(kind=16) to decimal in output [PR118406]

PR libfortran/118406

libgfortran/ChangeLog:

* runtime/string.c (gfc_itoa): Handle unsigned integers larger than
(10^19 * 2^64).

gcc/testsuite/ChangeLog:

* gfortran.dg/unsigned_write.f90: New test.

6 months agoAArch64: have -mcpu=native detect architecture extensions for unknown non-homogenous...
Tamar Christina [Thu, 16 Jan 2025 19:25:26 +0000 (19:25 +0000)] 
AArch64: have -mcpu=native detect architecture extensions for unknown non-homogenous systems [PR113257]

in g:e91a17fe39c39e98cebe6e1cbc8064ee6846a3a7 we added the ability for
-mcpu=native on unknown CPUs to still enable architecture extensions.

This has worked great but was only added for homogenous systems.

However the same thing works for big.LITTLE as in such system the cores must
have the same extensions otherwise it doesn't fundamentally work.

i.e. task migration from one core to the other wouldn't work.

This extends the same handling to non-homogenous systems.

gcc/ChangeLog:

PR target/113257
* config/aarch64/driver-aarch64.cc (get_cpu_from_id, DEFAULT_CPU): New.
(host_detect_local_cpu): Use it.

gcc/testsuite/ChangeLog:

PR target/113257
* gcc.target/aarch64/cpunative/info_34: New test.
* gcc.target/aarch64/cpunative/native_cpu_34.c: New test.
* gcc.target/aarch64/cpunative/info_35: New test.
* gcc.target/aarch64/cpunative/native_cpu_35.c: New test.

Co-authored-by: Richard Sandiford <richard.sandiford@arm.com>
6 months agoAArch64: don't override march to assembler with mcpu if march is specified [PR110901]
Tamar Christina [Thu, 16 Jan 2025 19:23:50 +0000 (19:23 +0000)] 
AArch64: don't override march to assembler with mcpu if march is specified [PR110901]

When both -mcpu and -march are specified, the value of -march wins out.

This is done correctly for the calls to cc1 and for the assembler directives we
put out in assembly files.

However in the call to as we don't do this and instead use the arch from the
cpu.  This leads to a situation that GCC cannot reliably be used to compile
assembly files which don't have a .arch directive.

This is quite common with .S files which use macros to selectively enable
codepath based on what the preprocessor sees.

The fix is to change MCPU_TO_MARCH_SPEC to not override the march if an march
is already specified.

gcc/ChangeLog:

PR target/110901
* config/aarch64/aarch64.h (MCPU_TO_MARCH_SPEC): Don't override if
march is set.

gcc/testsuite/ChangeLog:

PR target/110901
* gcc.target/aarch64/options_set_29.c: New test.

6 months ago[PR118067][LRA]: Use the right mode to evaluate secondary memory reload
Vladimir N. Makarov [Thu, 16 Jan 2025 17:17:31 +0000 (12:17 -0500)] 
[PR118067][LRA]: Use the right mode to evaluate secondary memory reload

  In the PR case, LRA made insn alternative costly.  It happened
because LRA incorrectly found that the alternative needs 2nd memory
reload as the wrong mode for targetm.secondary_memory_needed was used.
This resulted in LRA cycling as an alternative with mask regs was
chosen.  The patch fixes the PR and add more debug printing which
could be useful in the future for debugging function
process_alt_operands.

gcc/ChangeLog:

PR rtl-optimization/1180167
* lra-constraints.cc (process_alt_operands): Use operand mode not
subreg reg mode.  Add and improve debugging prints for updating
losers.

gcc/testsuite/ChangeLog:

PR rtl-optimization/118067
* gcc.target/i386/pr118067.c: New.

6 months agoAllow CFI_cdesc_t in argument lists with -fc-prototypes.
Thomas Koenig [Wed, 8 Jan 2025 16:06:31 +0000 (17:06 +0100)] 
Allow CFI_cdesc_t in argument lists with -fc-prototypes.

This patch fixes and reorganizes dumping C prototypes.  It makes the following
changes:

- BIND(C) types are now always output before any global symbols
- CFI_cdesc_t is issued for assumed shape and assumed rank arguments.
- BIND(C,NAME="...") entities were not always issued.

gcc/fortran/ChangeLog:

PR fortran/118359
* dump-parse-tree.cc (show_external_symbol): New function.
(write_type): Add prototype, put in restrictions on what not to dump.
(has_cfi_cdesc): New function.
(need_iso_fortran_binding): New function.
(gfc_dump_c_prototypes): Adjust to take only a file output.  Add
"#include <ISO_Fortran_binding.h" if CFI_cdesc_t is found.
Traverse global namespaces to dump types and the globalsymol list
to dump external symbols.
(gfc_dump_external_c_prototypes): Traverse global namespaces.
(get_c_type_name): Handle CFI_cdesc_t.
(write_proc): Also pass array spec to get_c_type_name.
* gfortran.h (gfc_dump_c_prototypes): Adjust prototype.
* parse.cc (gfc_parse_file): Adjust call to gfc_dump_c_prototypes.

6 months agoOpenMP: Improve error message for invalid directive in "assumes".
Sandra Loosemore [Wed, 15 Jan 2025 17:22:53 +0000 (17:22 +0000)] 
OpenMP: Improve error message for invalid directive in "assumes".

gcc/c/ChangeLog
* c-parser.cc (c_parser_omp_assumption_clauses): Give a more specific
error message for invalid directives vs unknown names.

gcc/cp/ChangeLog
* parser.cc (cp_parser_omp_assumption_clauses): Give a more specific
error message for invalid directives vs unknown names.

gcc/fortran/ChangeLog
* openmp.cc (gfc_omp_absent_contains_clause): Use an Oxford comma
in the message.

gcc/testsuite/ChangeLog
* c-c++-common/gomp/assume-2.c: Adjust expected diagnostics.
* c-c++-common/gomp/assumes-2.c: Likewise.
* c-c++-common/gomp/begin-assumes-2.c: Likewise.
* gfortran.dg/gomp/allocate-6.f90: Likewise.
* gfortran.dg/gomp/assumes-2.f90: Likewise.

6 months agod: Add testcase for fixed PR116373
Iain Buclaw [Thu, 16 Jan 2025 16:20:06 +0000 (17:20 +0100)] 
d: Add testcase for fixed PR116373

This was fixed in upstream, and merged in r15-6559-g332cf038fda109.

PR d/116373

gcc/testsuite/ChangeLog:

* gdc.dg/pr116373.d: New test.

6 months agoOpenMP: Update "declare target"/OpenMP context interaction
Sandra Loosemore [Thu, 26 Dec 2024 18:16:00 +0000 (18:16 +0000)] 
OpenMP: Update "declare target"/OpenMP context interaction

The code and test case previously implemented the OpenMP 5.0 spec,
which said in section 2.3.1:

"For functions within a declare target block, the target trait is added
to the beginning of the set..."

In OpenMP 5.1, this was changed to
"For device routines, the target trait is added to the beginning of
the set..."

In OpenMP 5.2 and TR12, it says:
"For procedures that are determined to be target function variants
by a declare target directive..."

The definition of "device routine" in OpenMP 5.1 is confusing, but
certainly the intent of the later versions of the spec is clear that
it doesn't just apply to functions within a begin declare target/end
declare target block.

The only use of the "omp declare target block" function attribute was
to support the 5.0 language, so it can be removed.  This patch changes
the context augmentation to use the "omp declare target" attribute
instead.

gcc/c-family/ChangeLog
* c-attribs.cc (c_common_gnu_attributes): Delete "omp declare
target block".

gcc/c/ChangeLog
* c-decl.cc (c_decl_attributes): Don't add "omp declare target
block".

gcc/cp/ChangeLog
* decl2.cc (cplus_decl_attributes): Don't add "omp declare target
block".

gcc/ChangeLog
* omp-general.cc (omp_complete_construct_context): Check
"omp declare target" attribute, not "omp declare target block".

gcc/testsuite/ChangeLog
* c-c++-common/gomp/declare-target-indirect-2.c : Adjust
expected output for removal of "omp declare target block".
* c-c++-common/gomp/declare-variant-8.c: Likewise, the variant
call to f20 is now resolved differently.
* c-c++-common/gomp/reverse-offload-1.c: Adjust expected output.
* gfortran.dg/gomp/declare-variant-8.f90: Likewise, both f18
and f20 now resolve to the variant.  Delete obsolete comments.

6 months agoOpenMP: Shared metadirective/dynamic selector tests for C and C++
Sandra Loosemore [Wed, 8 Jan 2025 01:55:47 +0000 (01:55 +0000)] 
OpenMP: Shared metadirective/dynamic selector tests for C and C++

gcc/testsuite/ChangeLog
* c-c++-common/gomp/adjust-args-6.c: New.
* c-c++-common/gomp/attrs-metadirective-1.c: New.
* c-c++-common/gomp/attrs-metadirective-2.c: New.
* c-c++-common/gomp/attrs-metadirective-3.c: New.
* c-c++-common/gomp/attrs-metadirective-4.c: New.
* c-c++-common/gomp/attrs-metadirective-5.c: New.
* c-c++-common/gomp/attrs-metadirective-6.c: New.
* c-c++-common/gomp/attrs-metadirective-7.c: New.
* c-c++-common/gomp/attrs-metadirective-8.c: New.
* c-c++-common/gomp/declare-variant-arg-exprs.c: New.
* c-c++-common/gomp/declare-variant-dynamic-1.c: New.
* c-c++-common/gomp/declare-variant-dynamic-2.c: New.
* c-c++-common/gomp/metadirective-1.c: New.
* c-c++-common/gomp/metadirective-2.c: New.
* c-c++-common/gomp/metadirective-3.c: New.
* c-c++-common/gomp/metadirective-4.c: New.
* c-c++-common/gomp/metadirective-5.c: New.
* c-c++-common/gomp/metadirective-6.c: New.
* c-c++-common/gomp/metadirective-7.c: New.
* c-c++-common/gomp/metadirective-8.c: New.
* c-c++-common/gomp/metadirective-construct.c: New.
* c-c++-common/gomp/metadirective-device.c: New.
* c-c++-common/gomp/metadirective-no-score.c: New.
* c-c++-common/gomp/metadirective-target-device-1.c: New.
* c-c++-common/gomp/metadirective-target-device-2.c: New.

libgomp/ChangeLog
* testsuite/libgomp.c-c++-common/metadirective-1.c: New.
* testsuite/libgomp.c-c++-common/metadirective-2.c: New.
* testsuite/libgomp.c-c++-common/metadirective-3.c: New.
* testsuite/libgomp.c-c++-common/metadirective-4.c: New.
* testsuite/libgomp.c-c++-common/metadirective-5.c: New.
* testsuite/libgomp.c-c++-common/metadirective-late-1.c: New.
* testsuite/libgomp.c-c++-common/metadirective-late-2.c: New.
* testsuite/libgomp.c-c++-common/metadirective-target-device.c: New.

Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com>
Co-Authored-By: Sandra Loosemore <sandra@codesourcery.com>
6 months agoOpenMP: C++ support for metadirectives and dynamic selectors.
Sandra Loosemore [Tue, 14 Jan 2025 23:28:02 +0000 (23:28 +0000)] 
OpenMP: C++ support for metadirectives and dynamic selectors.

Additional shared C/C++ testcases are included in a subsequent patch in this
series.

gcc/cp/ChangeLog
PR middle-end/112779
PR middle-end/113904
* cp-tree.h (struct saved_scope): Add new field
x_processing_omp_trait_property_expr.
(processing_omp_trait_property_expr): New.
* parser.cc (cp_parser_skip_to_end_of_block_or_statement): Add
metadirective_p parameter and handle skipping over the parentheses
in a "for" statement.
(struct omp_metadirective_parse_data): New.
(mangle_metadirective_region_label): New.
(cp_parser_label_for_labeled_statement): Mangle label names in a
metadirective body.
(cp_parser_jump_statement): Likewise.
(cp_parser_omp_context_selector): Allow arbitrary expressions in
device_num and condition properties.
(cp_parser_omp_assumption_clauses): Handle C_OMP_DIR_META.
(analyze_metadirective_body): New.
(cp_parser_omp_metadirective): New.
(cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE.
* parser.h (struct cp_parser): Add omp_metadirective_state field.
* pt.cc (tsubst_omp_context_selector): New.
(tsubst_stmt): Handle OMP_METADIRECTIVE.
* semantics.cc (finish_id_expression_1): Don't diagnose use of
parameter outside function body in dynamic selector expressions here.

gcc/testsuite/
PR middle-end/112779
PR middle-end/113904
* c-c++-common/gomp/declare-variant-2.c: Adjust output for C++.
* g++.dg/gomp/declare-variant-class-1.C: New.
* g++.dg/gomp/declare-variant-class-2.C: New.
* g++.dg/gomp/metadirective-template-1.C: New.

libgomp/
PR middle-end/112779
PR middle-end/113904
* testsuite/libgomp.c++/metadirective-template-1.C: New.
* testsuite/libgomp.c++/metadirective-template-2.C: New.
* testsuite/libgomp.c++/metadirective-template-3.C: New.

Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com>
Co-Authored-By: Sandra Loosemore <sandra@codesourcery.com>
6 months agoOpenMP: Add C support for metadirectives and dynamic selectors.
Sandra Loosemore [Tue, 14 Jan 2025 23:27:53 +0000 (23:27 +0000)] 
OpenMP: Add C support for metadirectives and dynamic selectors.

Additional shared C/C++ testcases are included in a subsequent patch in this
series.

gcc/c-family/ChangeLog
PR middle-end/112779
PR middle-end/113904
* c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META.
(c_omp_expand_variant_construct): Declare.
* c-gimplify.cc: Include omp-general.h.
(genericize_omp_metadirective_stmt): New.
(c_genericize_control_stmt): Add case for OMP_METADIRECTIVE.
* c-omp.cc (c_omp_directives): Fix entries for metadirective.
(c_omp_expand_variant_construct_r): New.
(c_omp_expand_variant_construct): New.
* c-pragma.cc (omp_pragmas): Add metadirective.
* c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE.

gcc/c/ChangeLog
PR middle-end/112779
PR middle-end/113904
* c-parser.cc (struct c_parser): Add omp_metadirective_state field.
(c_parser_skip_to_end_of_block_or_statement): Add metadirective_p
parameter and handle skipping over the parentheses in a "for"
statement.
(struct omp_metadirective_parse_data): New.
(mangle_metadirective_region_label): New.
(c_parser_label): Mangle label names in a metadirective body.
(c_parser_statement_after_labels): Likewise.
(c_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE.
(c_parser_omp_context_selector): Allow arbitrary expressions in
device_num and condition properties.
(c_parser_omp_assumption_clauses): Handle C_OMP_DIR_META.
(analyze_metadirective_body): New.
(c_parser_omp_metadirective): New.

gcc/testsuite/
PR middle-end/112779
* c-c++-common/gomp/declare-variant-2.c: Adjust expected output for C.
* gcc.dg/gomp/metadirective-1.c: New.

Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com>
Co-Authored-By: Sandra Loosemore <sandra@codesourcery.com>
6 months agors6000: Fix ICE for invalid constants in built-in functions
Peter Bergner [Thu, 16 Jan 2025 16:53:27 +0000 (10:53 -0600)] 
rs6000: Fix ICE for invalid constants in built-in functions

For invalid constant operand values used in built-in functions, return
const0_rtx to signify an error occurred during expansion.

2025-01-16  Peter Bergner  <bergner@linux.ibm.com>

gcc/
* config/rs6000/rs6000-builtin.cc (rs6000_expand_builtin): Return
const0_rtx when there is an error.

gcc/testsuite/
* gcc.target/powerpc/mma-builtin-error.c: New test.

6 months agors6000: Fix loop limit for built-in constant checking
Peter Bergner [Thu, 16 Jan 2025 16:49:45 +0000 (10:49 -0600)] 
rs6000: Fix loop limit for built-in constant checking

The loop checking for built-in constant operand restrictions was missing
some operands due to the loop limit being too small.  Fixing that exposed
a testsuite failure which is caused by a typo in the pmxvi4ger8pp definition
where we had made the PMASK field too small.

2025-01-16  Peter Bergner  <bergner@linux.ibm.com>

gcc/
* config/rs6000/rs6000-builtin.cc (rs6000_expand_builtin): Use correct
array size for the loop limit.
* config/rs6000/rs6000-builtins.def: Fix field size for PMASK operand.

6 months agoc++: Fix up reshape_* RAW_DATA_CST handling [PR118214]
Jakub Jelinek [Thu, 16 Jan 2025 16:25:24 +0000 (17:25 +0100)] 
c++: Fix up reshape_* RAW_DATA_CST handling [PR118214]

The embed-17.C testcase is miscompiled and pr118214.C testcase used to be
miscompiled on the trunk before I've temporarily reverted the
r15-6339 C++ large initializer speed-up commit in r15-6448.
The problem is that reshape_* is only sometimes allowed to modify the given
CONSTRUCTOR in place (when reuse is true, so
                first_initializer_p
                && (complain & tf_error)
                && !CP_AGGREGATE_TYPE_P (elt_type)
                && !TREE_SIDE_EFFECTS (first_initializer_p)
) and at other times is not allowed to change it.  But the RAW_DATA_CST
handling was modifying those in place always, by peeling off whatever
was needed for the processing of the current element or set of elements
and leaving the rest in the original CONSTRUCTOR_ELTS, either as
RAW_DATA_CST with adjusted RAW_DATA_POINTER/RAW_DATA_LENGTH, or turning
it into INTEGER_CST if it would be a RAW_DATA_LENGTH == 1 RAW_DATA_CST.

The following patch fixes that by adding raw_idx member into
struct reshape_iter where we for the RAW_DATA_CST current elements track
offset into the current RAW_DATA_CST (how many elements were processed
from it already) and modifying the original CONSTRUCTOR_ELTS only if reuse
is true and we used the whole RAW_DATA_CST (with zero raw_idx); which means
just modifying its type in place.

2025-01-16  Jakub Jelinek  <jakub@redhat.com>

PR c++/118214
* decl.cc (struct reshape_iter): Add raw_idx member.
(cp_maybe_split_raw_data): Add inc_cur parameter, set *inc_cur,
don't modify original CONSTRUCTOR, use d->raw_idx to track index
into a RAW_DATA_CST d->cur->value.
(consume_init): Adjust cp_maybe_split_raw_data caller, increment
d->cur when cur_inc is true.
(reshape_init_array_1): Don't modify original CONSTRUCTOR when
handling RAW_DATA_CST d->cur->value and !reuse, instead use
d->raw_idx to track index into RAW_DATA_CST.
(reshape_single_init): Initialize iter.raw_idx.
(reshape_init_class): Adjust for introduction of d->raw_idx,
adjust cp_maybe_split_raw_data caller, do d->cur++ if inc_cur
rather than when it returns non-NULL.
(reshape_init_r): Check for has_designator_problem for second
half of _Complex earlier, also check for
error_operand_p (d->cur->value).  Use consume_init instead of
cp_maybe_split_raw_data with later conditional d->cur++.
(reshape_init): Initialize d.raw_idx.

* g++.dg/cpp/embed-17.C: New test.
* g++.dg/cpp0x/pr118214.C: New test.

6 months agoc++: Change c++2b and gnu++2b to c++23 and gnu++23 in C++ diagnostics
Jakub Jelinek [Thu, 16 Jan 2025 16:23:02 +0000 (17:23 +0100)] 
c++: Change c++2b and gnu++2b to c++23 and gnu++23 in C++ diagnostics

This is something we should have done when -std=c++23 was made the
primary option and -std=c++2b turned into undocumented alias.

2025-01-16  Jakub Jelinek  <jakub@redhat.com>

gcc/cp/
* parser.cc (cp_parser_lambda_declarator_opt,
cp_parser_statement, cp_parser_selection_statement,
cp_parser_jump_statement): Use -std=c++23 and -std=gnu++23
in diagnostics rather than -std=c++2b and -std=gnu++2b.
* semantics.cc (finish_compound_literal): Likewise.
* typeck2.cc (build_functional_cast_1): Likewise.
* decl.cc (start_decl): Likewise.
* constexpr.cc (ensure_literal_type_for_constexpr_object,
potential_constant_expression_1): Likewise.
gcc/c-family/
* c-lex.cc (interpret_float): Use -std=c++23 and -std=gnu++23
in diagnostics rather than -std=c++2b and -std=gnu++2b.

6 months agomiddle-end: Add early break conditions to vect-switch-search-line-fast.c [PR118451]
Tamar Christina [Thu, 16 Jan 2025 12:54:44 +0000 (12:54 +0000)] 
middle-end: Add early break conditions to vect-switch-search-line-fast.c [PR118451]

When this test was added initially it didn't add the early break effective
target tests.

This means that the test was "passing" (as in, it was failing to vectorize)
because many targets don't support early break.

But the test should not have been run for these targets.  When the vectorizer
learned PFA the test started passing for 32-bit targets. I had adjusted the
testcase but fail to notice the requirements were wrong.

Thus this adds the extra guards, and on targets that don't support early break
this test will move to UNSUPPORTED, which is what it should have been all
along...

gcc/testsuite/ChangeLog:

PR testsuite/118451
* gcc.dg/vect/vect-switch-search-line-fast.c: Add early_break guards.

6 months agoExtend OpenACC 'serial' testing, compiler-side
Thomas Schwinge [Sun, 10 Nov 2019 21:43:44 +0000 (22:43 +0100)] 
Extend OpenACC 'serial' testing, compiler-side

In 2019 commit 62aee289e4791fd68aace01accf433fb26b3eeae
"Add OpenACC 2.6 `serial' construct support", we didn't quite excel in test
suite coverage.  Add some more, similar to OpenACC 'parallel' construct
testing.

gcc/testsuite/
* c-c++-common/goacc-gomp/nesting-1.c: Extend OpenACC 'serial'
testing.
* c-c++-common/goacc-gomp/nesting-fail-1.c: Likewise.
* c-c++-common/goacc/Wparentheses-1.c: Likewise.
* c-c++-common/goacc/builtin-goacc-parlevel-id-size.c: Likewise.
* c-c++-common/goacc/combined-directives-2.c: Likewise.
* c-c++-common/goacc/combined-directives-3.c: Likewise.
* c-c++-common/goacc/combined-directives.c: Likewise.
* c-c++-common/goacc/combined-reduction.c: Likewise.
* c-c++-common/goacc/data-clause-duplicate-1.c: Likewise.
* c-c++-common/goacc/default-1.c: Likewise.
* c-c++-common/goacc/default-2.c: Likewise.
* c-c++-common/goacc/default-3.c: Likewise.
* c-c++-common/goacc/default-4.c: Likewise.
* c-c++-common/goacc/default-5.c: Likewise.
* c-c++-common/goacc/if-clause-2.c: Likewise.
* c-c++-common/goacc/kernels-1.c: Likewise.
* c-c++-common/goacc/loop-1.c: Likewise.
* c-c++-common/goacc/loop-clauses.c: Likewise.
* c-c++-common/goacc/nesting-1.c: Likewise.
* c-c++-common/goacc/nesting-data-1.c: Likewise.
* c-c++-common/goacc/nesting-fail-1.c: Likewise.
* c-c++-common/goacc/parallel-1.c: Likewise.
* c-c++-common/goacc/private-reduction-1.c: Likewise.
* c-c++-common/goacc/reduction-promotions.c: Likewise.
* c-c++-common/goacc/routine-1.c: Likewise.
* c-c++-common/goacc/sb-1.c: Likewise.
* c-c++-common/goacc/sb-2.c: Likewise.
* c-c++-common/goacc/uninit-firstprivate-clause.c: Likewise.
* c-c++-common/goacc/uninit-if-clause.c: Likewise.
* c-c++-common/goacc/update-if_present-2.c: Likewise.
* g++.dg/goacc/template.C: Likewise.
* gfortran.dg/goacc/array-reduction.f90: Likewise.
* gfortran.dg/goacc/assumed.f95: Likewise.
* gfortran.dg/goacc/branch.f95: Likewise.
* gfortran.dg/goacc/coarray.f95: Likewise.
* gfortran.dg/goacc/coarray_2.f90: Likewise.
* gfortran.dg/goacc/combined-directives-3.f90: Likewise.
* gfortran.dg/goacc/combined-directives.f90: Likewise.
* gfortran.dg/goacc/common-block-1.f90: Likewise.
* gfortran.dg/goacc/common-block-2.f90: Likewise.
* gfortran.dg/goacc/common-block-3.f90: Likewise.
* gfortran.dg/goacc/cray-2.f95: Likewise.
* gfortran.dg/goacc/cray.f95: Likewise.
* gfortran.dg/goacc/critical.f95: Likewise.
* gfortran.dg/goacc/data-clauses.f95: Likewise.
* gfortran.dg/goacc/default-1.f95: Likewise.
* gfortran.dg/goacc/default-2.f: Likewise.
* gfortran.dg/goacc/default-3.f95: Likewise.
* gfortran.dg/goacc/default-4.f: Likewise.
* gfortran.dg/goacc/default-5.f: Likewise.
* gfortran.dg/goacc/default_none.f95: Likewise.
* gfortran.dg/goacc/derived-types.f90: Likewise.
* gfortran.dg/goacc/firstprivate-1.f95: Likewise.
* gfortran.dg/goacc/gang-static.f95: Likewise.
* gfortran.dg/goacc/if.f95: Likewise.
* gfortran.dg/goacc/list.f95: Likewise.
* gfortran.dg/goacc/literal.f95: Likewise.
* gfortran.dg/goacc/loop-1-2.f95: Likewise.
* gfortran.dg/goacc/loop-1.f95: Likewise.
* gfortran.dg/goacc/loop-2-parallel-3.f95: Likewise.
* gfortran.dg/goacc/loop-3-2.f95: Likewise.
* gfortran.dg/goacc/loop-3.f95: Likewise.
* gfortran.dg/goacc/multi-clause.f90: Likewise.
* gfortran.dg/goacc/nested-parallelism.f90: Likewise.
* gfortran.dg/goacc/parameter.f95: Likewise.
* gfortran.dg/goacc/pr71704.f90: Likewise.
* gfortran.dg/goacc/private-3.f95: Likewise.
* gfortran.dg/goacc/pure-elemental-procedures.f95: Likewise.
* gfortran.dg/goacc/reduction-2.f95: Likewise.
* gfortran.dg/goacc/reduction-3.f95: Likewise.
* gfortran.dg/goacc/reduction-promotions.f90: Likewise.
* gfortran.dg/goacc/reduction.f95: Likewise.
* gfortran.dg/goacc/routine-3.f90: Likewise.
* gfortran.dg/goacc/routine-module-1.f90: Likewise.
* gfortran.dg/goacc/routine-module-2.f90: Likewise.
* gfortran.dg/goacc/routine-module-mod-1.f90: Likewise.
* gfortran.dg/goacc/sie.f95: Likewise.
* gfortran.dg/goacc/subarrays.f95: Likewise.
* gfortran.dg/goacc/uninit-firstprivate-clause.f95: Likewise.
* gfortran.dg/goacc/uninit-if-clause.f95: Likewise.
* gfortran.dg/goacc/update-if_present-2.f90: Likewise.
* c-c++-common/goacc/loop-3.c: Rename to...
* c-c++-common/goacc/loop-3-parallel.c: ... this.
* gfortran.dg/goacc/parallel-kernels-clauses.f95: Rename to...
* gfortran.dg/goacc/compute_construct-clauses.f95: ... this.
Extend OpenACC 'serial' testing.
* gfortran.dg/goacc/parallel-kernels-regions.f95: Rename to...
* gfortran.dg/goacc/nesting-fail-1.f95: ... this.  Extend OpenACC
'serial' testing.
* gfortran.dg/goacc/routine-external-level-of-parallelism-1.f:
Rename to...
* gfortran.dg/goacc/routine-external-level-of-parallelism-1-parallel.f:
... this.
* gfortran.dg/goacc/routine-external-level-of-parallelism-2.f:
Rename to...
* gfortran.dg/goacc/routine-external-level-of-parallelism-2-parallel.f:
... this.
* c-c++-common/goacc/loop-2-serial.c: New.
* c-c++-common/goacc/loop-3-serial.c: Likewise.
* c-c++-common/goacc/nested-reductions-1-serial.c: Likewise.
* c-c++-common/goacc/nested-reductions-2-serial.c: Likewise.
* c-c++-common/goacc/serial-1.c: Likewise.
* gfortran.dg/goacc/loop-2-serial-3.f95: Likewise.
* gfortran.dg/goacc/loop-2-serial-nested.f95: Likewise.
* gfortran.dg/goacc/loop-2-serial-tile.f95: Likewise.
* gfortran.dg/goacc/loop-2-serial.f95: Likewise.
* gfortran.dg/goacc/nested-reductions-1-serial.f90: Likewise.
* gfortran.dg/goacc/nested-reductions-2-serial.f90: Likewise.
* gfortran.dg/goacc/private-explicit-serial-1.f95: Likewise.
* gfortran.dg/goacc/private-predetermined-serial-1.f95: Likewise.
* gfortran.dg/goacc/routine-external-level-of-parallelism-1-serial.f:
Likewise.
* gfortran.dg/goacc/routine-external-level-of-parallelism-2-serial.f:
Likewise.
* gfortran.dg/goacc/serial-tree.f95: Likewise.

6 months ago[OpenACC/Fortran testsuite] Use relative line numbers for a few DejaGnu directives
Thomas Schwinge [Fri, 8 Nov 2019 13:03:06 +0000 (14:03 +0100)] 
[OpenACC/Fortran testsuite] Use relative line numbers for a few DejaGnu directives

For easier maintenance.

gcc/testsuite/
* gfortran.dg/goacc/assumed.f95: Use relative line numbers for a
few DejaGnu directives.
* gfortran.dg/goacc/list.f95: Likewise.
* gfortran.dg/goacc/loop-1-2.f95: Likewise.
* gfortran.dg/goacc/loop-1.f95: Likewise.
* gfortran.dg/goacc/reduction.f95: Likewise.

6 months agoFortran: Create fresh ts.u.cl for result in gfc_get_symbol_for_expr [PR118441]
Tobias Burnus [Thu, 16 Jan 2025 10:50:26 +0000 (11:50 +0100)] 
Fortran: Create fresh ts.u.cl for result in gfc_get_symbol_for_expr [PR118441]

For intrinsic routines, called in libraries, the prototype is created from
the call via gfc_get_symbol_for_expr. For the actual arguments, it calls
gfc_copy_formal_args_intr which already ensures that the ts.u.cl is freshly
allocated.

This commit now ensures the same for character-returning functions.

PR fortran/118441

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (gfc_get_symbol_for_expr): Use
gfc_new_charlen for character-returning functions.

gcc/testsuite/ChangeLog:

* gfortran.dg/gomp/intrinsic_pack_7.f90: New test.

6 months agolibstdc++: Move std::basic_ostream to new internal header [PR99995]
Jonathan Wakely [Wed, 11 Dec 2024 17:32:39 +0000 (17:32 +0000)] 
libstdc++: Move std::basic_ostream to new internal header [PR99995]

This adds <bits/ostream.h> so that other headers don't need to include
all of <ostream>, which pulls in all of <format> since C++23 (for the
std::print and std::println overloads in <ostream>). This new header
allows the constrained operator<< in <bits/unique_ptr.h> to be defined
without all of std::format being compiled.

We could also replace <ostream> with <bits/ostream.h> in all of
<istream>, <fstream>, <sstream>, and <spanstream>. That seems more
likely to cause problems for users who might be expecting <sstream> to
define std::endl, for example. Although the standard doesn't guarantee
that, it is more reasonable than expecting <memory> to define it! We can
look into making those changes for GCC 16.

libstdc++-v3/ChangeLog:

PR libstdc++/99995
* include/Makefile.am: Add new header.
* include/Makefile.in: Regenerate.
* include/bits/unique_ptr.h: Include bits/ostream.h instead of
ostream.
* include/std/ostream: Include new header.
* include/bits/ostream.h: New file.

6 months agolibstdc++: Implement LWG 2937 for std::filesystem::equivalent [PR118158]
Jonathan Wakely [Mon, 30 Dec 2024 13:08:41 +0000 (13:08 +0000)] 
libstdc++: Implement LWG 2937 for std::filesystem::equivalent [PR118158]

Do not report an error for (is_other(s1) && is_other(s2)) as the
standard originally said, nor for (is_other(s1) || is_other(s2)) as
libstdc++ was doing. We can compare inode numbers for special files and
so give sensible answers.

libstdc++-v3/ChangeLog:

PR libstdc++/118158
* src/c++17/fs_ops.cc (fs::equivalent): Remove error reporting
for is_other(s1) && is_other(s2) case, as per LWG 2937.
* testsuite/27_io/filesystem/operations/pr118158.cc: New test.

6 months agolibstdc++: Check feature test macro for associative container node extraction
Jonathan Wakely [Fri, 1 Nov 2024 10:50:02 +0000 (10:50 +0000)] 
libstdc++: Check feature test macro for associative container node extraction

Replace some `__cplusplus > 201402L` preprocessor checks with more
expressive checks for the appropriate feature test macro.

libstdc++-v3/ChangeLog:

* include/bits/stl_map.h: Check __glibcxx_node_extract instead
of __cplusplus.
* include/bits/stl_multimap.h: Likewise.
* include/bits/stl_multiset.h: Likewise.
* include/bits/stl_set.h: Likewise.
* include/bits/stl_tree.h: Likewise.

6 months agoRISC-V: Update Xsfvqmacc and Xsfvfnrclip's testcases
Liao Shihua [Fri, 13 Dec 2024 12:38:29 +0000 (20:38 +0800)] 
RISC-V: Update Xsfvqmacc and Xsfvfnrclip's testcases

Update Sifive Xsfvqmacc and Xsfvfnrclip extension's testcases.

version log:
Update synchronize LMUL settings with return type.

gcc/ChangeLog:

* config/riscv/vector.md: New attr set.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/xsfvector/sf_vfnrclip_x_f_qf.c: Add vsetivli checking.
* gcc.target/riscv/rvv/xsfvector/sf_vfnrclip_xu_f_qf.c: Ditto.
* gcc.target/riscv/rvv/xsfvector/sf_vqmacc_2x8x2.c: Ditto.
* gcc.target/riscv/rvv/xsfvector/sf_vqmacc_4x8x4.c: Ditto.
* gcc.target/riscv/rvv/xsfvector/sf_vqmaccsu_2x8x2.c: Ditto.
* gcc.target/riscv/rvv/xsfvector/sf_vqmaccsu_4x8x4.c: Ditto.
* gcc.target/riscv/rvv/xsfvector/sf_vqmaccu_2x8x2.c: Ditto.
* gcc.target/riscv/rvv/xsfvector/sf_vqmaccu_4x8x4.c: Ditto.
* gcc.target/riscv/rvv/xsfvector/sf_vqmaccus_2x8x2.c: Ditto.
* gcc.target/riscv/rvv/xsfvector/sf_vqmaccus_4x8x4.c: Ditto.

6 months agoRISC-V: Update Xsfvfnrclip implementation.
Jiawei [Fri, 13 Dec 2024 12:38:28 +0000 (20:38 +0800)] 
RISC-V: Update Xsfvfnrclip implementation.

Update implementation of Xsfvfnrclip, using return type as iterator.

gcc/ChangeLog:

* config/riscv/genrvv-type-indexer.cc (expand_floattype): New func.
(main): New type.
* config/riscv/riscv-vector-builtins-types.def (DEF_RVV_XFQF_OPS): New def.
(vint8mf8_t): Ditto.
(vint8mf4_t): Ditto.
(vint8mf2_t): Ditto.
(vint8m1_t): Ditto.
(vint8m2_t): Ditto.
* config/riscv/riscv-vector-builtins.cc (DEF_RVV_XFQF_OPS): Ditto.
(rvv_arg_type_info::get_xfqf_float_type): Ditto.
* config/riscv/riscv-vector-builtins.def (xfqf_vector): Ditto.
(xfqf_float): Ditto.
* config/riscv/riscv-vector-builtins.h
(struct rvv_arg_type_info): New function prototype.
* config/riscv/sifive-vector.md: Update iterator.
* config/riscv/vector-iterators.md: Ditto.

6 months agoforwprop: Ensure that shuffle masks are VECTOR_CSTs
Christoph Müllner [Wed, 15 Jan 2025 16:53:47 +0000 (17:53 +0100)] 
forwprop: Ensure that shuffle masks are VECTOR_CSTs

As reported in PR118487, it is possible that the mask parameter
of a __builtin_shuffle() is not a VECTOR_CST.
If this is the case and checking is enabled then an ICE is triggered.
Let's add a check to fix this issue.

PR tree-optimization/118487

gcc/ChangeLog:

* tree-ssa-forwprop.cc (recognise_vec_perm_simplify_seq):
Ensure that shuffle masks are VECTOR_CSTs.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr118487.c: New test.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
6 months agoforwprop: Eliminate redundant calls to to_constant()
Christoph Müllner [Wed, 15 Jan 2025 13:53:27 +0000 (14:53 +0100)] 
forwprop: Eliminate redundant calls to to_constant()

When extracting the amount of vector elements, we currently
first check if the value is a contant with is_constant(),
followed by obtaining the value with to_constant(),
which internally calls is_constant() again.
We can address this by using is_constant (T*), which also
provides the constant value.

gcc/ChangeLog:

* tree-ssa-forwprop.cc (recognise_vec_perm_simplify_seq):
Eliminate redundant calls to to_constant().

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
6 months agotree-optimization/115494 - PRE PHI translation and ranges
Richard Biener [Wed, 15 Jan 2025 13:31:57 +0000 (14:31 +0100)] 
tree-optimization/115494 - PRE PHI translation and ranges

When we PHI translate dependent expressions we keep SSA defs in
place of the translated expression in case the expression itself
did not change even though it's context did and thus the validity
of ranges associated with it.  That eventually leads to simplification
errors given we violate the precondition that used SSA defs fed to
vn_valueize are valid to use (including their associated ranges).
The following makes sure to replace those with new representatives
always, not only when the dependent expression translation changed it.

The fix was originally discovered by Michael Morin.

PR tree-optimization/115494
* tree-ssa-pre.cc (phi_translate_1): Always generate a
representative for translated dependent expressions.

* gcc.dg/torture/pr115494.c: New testcase.

Co-Authored-By: Mikael Morin <mikael@gcc.gnu.org>
6 months agotree-ssa-propagate: Special case lhs of musttail calls in may_propagate_copy [PR118430]
Jakub Jelinek [Thu, 16 Jan 2025 08:25:16 +0000 (09:25 +0100)] 
tree-ssa-propagate: Special case lhs of musttail calls in may_propagate_copy [PR118430]

This patch ensures that VRP or similar passes don't replace the uses of lhs of
[[gnu::musttail]] calls with some constant (e.g. if the call is known is known
to return a singleton value range) etc. to make it more likely that it is actually
tail callable.

2025-01-16  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/118430
* tree-ssa-propagate.cc (may_propagate_copy): Return false if dest
is lhs of an [[gnu::musttail]] call.
(substitute_and_fold_dom_walker::before_dom_children): Formatting fix.

* c-c++-common/musttail14.c: Expect lhs on the must tail call calls.

6 months agotailc: Virtually undo IPA-VRP return value optimization for tail calls [PR118430]
Jakub Jelinek [Thu, 16 Jan 2025 08:20:15 +0000 (09:20 +0100)] 
tailc: Virtually undo IPA-VRP return value optimization for tail calls [PR118430]

When we have return somefn (whatever); where somefn is normally tail
callable and IPA-VRP determines somefn returns a singleton range, VRP
just changes the IL to
  somefn (whatever);
  return 42;
(or whatever the value in that range is).  The introduction of IPA-VRP
return value tracking then effectively regresses the tail call optimization.
This is even more important if the call is [[gnu::musttail]].

So, the following patch queries IPA-VRP whether a function returns singleton
range and if so and the value returned is identical to that, marks the
call as [tail call] anyway.  If expansion decides it can't use the tail
call, we'll still expand the return 42; or similar statement, and if it
decides it can use the tail call, that part will be ignored and we'll emit
normal tail call.

The reason it works is that the expand pass relies on the tailc pass to
do its job properly.
E.g. when we have
  <bb 2> [local count: 1073741824]:
  foo (x_2(D));
  baz (&v);
  v ={v} {CLOBBER(eos)};
  bar (x_2(D)); [tail call]
  return 1;
when expand_gimple_basic_block handles the bar (x_2(D)); call, it uses
          if (call_stmt && gimple_call_tail_p (call_stmt))
            {
              bool can_fallthru;
              new_bb = expand_gimple_tailcall (bb, call_stmt, &can_fallthru);
              if (new_bb)
                {
                  if (can_fallthru)
                    bb = new_bb;
                  else
                    {
                      currently_expanding_gimple_stmt = NULL;
                      return new_bb;
                    }
                }
            }
As it is actually tail callable during expansion of the bar (x_2(D)); call
stmt, expand_gimple_tailbb returns non-NULL and sets can_fallthru to false,
plus emits
;; bar (x_2(D)); [tail call]

(insn 11 10 12 2 (set (reg:SI 5 di)
        (reg/v:SI 99 [ x ])) "pr118430.c":35:10 -1
     (nil))

(call_insn/j 12 11 13 2 (set (reg:SI 0 ax)
        (call (mem:QI (symbol_ref:DI ("bar") [flags 0x3]  <function_decl 0x7fb39020bd00 bar>) [0 bar S1 A8])
            (const_int 0 [0]))) "pr118430.c":35:10 -1
     (expr_list:REG_CALL_DECL (symbol_ref:DI ("bar") [flags 0x3]  <function_decl 0x7fb39020bd00 bar>)
        (expr_list:REG_EH_REGION (const_int 0 [0])
            (nil)))
    (expr_list:SI (use (reg:SI 5 di))
        (nil)))

(barrier 13 12 0)
Because it doesn't fallthru, no further statements in the same bb are
expanded.  Now, if the bb with return happened to be in some other basic
block from the [tail call], it could be expanded but because the bb with
tail call ends with a barrier, it doesn't fall thru there and if nothing
else could reach it, we'd remove the unreachable bb RSN.

2025-01-16  Jakub Jelinek  <jakub@redhat.com>
    Andrew Pinski  <quic_apinski@quicinc.com>

PR tree-optimization/118430
* tree-tailcall.cc: Include gimple-range.h, alloc-pool.h, sreal.h,
symbol-summary.h, ipa-cp.h and ipa-prop.h.
(find_tail_calls): If ass_var is NULL and ret_var is not, check if
IPA-VRP has not found singleton return range for it.  In that case,
don't punt if ret_var is the only value in that range.  Adjust the
maybe_error_musttail message otherwise to diagnose different value
being returned from the caller and callee rather than using return
slot.  Formatting fixes.

* c-c++-common/musttail14.c: New test.
* c-c++-common/pr118430.c: New test.

6 months agodocs: Fix up inline asm documentation
Jakub Jelinek [Thu, 16 Jan 2025 08:18:59 +0000 (09:18 +0100)] 
docs: Fix up inline asm documentation

When writing the gcc-15/changes.html patch posted earlier, I've been
wondering where significant part of the Basic asm chapter went and the
problem was the insertion of a new @node in the middle of the Basic Asm
@node, plus not mentioning the new @node in the @menu.  So the asm constexpr
node was not normally visible and the Remarks for the section neither.

The following patch moves it before Asm Labels, removes the spots where it
described what hasn't been actually committed (constant expression can only
be a container with data/size member functions) and fixes up the toplevel
extended asm documentation (it was in the Basic Asm remarks and Extended Asm
section's remark still said it is not valid).

2025-01-16  Jakub Jelinek  <jakub@redhat.com>

* doc/extend.texi (Using Assembly Language with C): Add Asm constexprs
to @menu.
(Basic Asm): Move @node asm constexprs before Asm Labels, rename to
Asm constexprs, change wording so that it is clearer that the constant
expression actually must not return a string literal, just some specific
container and other wording tweaks.  Only talk about top-level for basic
asms in this @node, move restrictions on top-level extended asms to ...
(Extended Asm): ... here.

6 months agovec.h: Properly destruct elements in auto_vec auto storage [PR118400]
Jakub Jelinek [Thu, 16 Jan 2025 08:17:50 +0000 (09:17 +0100)] 
vec.h: Properly destruct elements in auto_vec auto storage [PR118400]

For T with non-trivial destructors, we were destructing objects in the
vector on release only when not using auto storage of auto_vec.

The following patch calls truncate (0) instead of m_vecpfx.m_num clearing,
and truncate takes care of that destruction:
  unsigned l = length ();
  gcc_checking_assert (l >= size);
  if (!std::is_trivially_destructible <T>::value)
    vec_destruct (address () + size, l - size);
  m_vecpfx.m_num = size;

2025-01-16  Jakub Jelinek  <jakub@redhat.com>

PR ipa/118400
* vec.h (vec<T, va_heap, vl_ptr>::release): Call m_vec->truncate (0)
instead of clearing m_vec->m_vecpfx.m_num.

6 months agoFix typo to avoid ICE.
liuhongt [Thu, 16 Jan 2025 03:09:24 +0000 (19:09 -0800)] 
Fix typo to avoid ICE.

gcc/ChangeLog:

PR target/118489
* config/i386/sse.md (VF1_AVX512BW): Fix typo.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr118489.c: New test.

6 months agotree-optimization/115895 - overrun with masked loop
Richard Biener [Tue, 14 Jan 2025 14:26:21 +0000 (15:26 +0100)] 
tree-optimization/115895 - overrun with masked loop

The following addresses the fact that with loop masking (or regular
mask loads) we do not implement load shortening but we override
the case where we need that for correctness.  Likewise when we
attempt to use loop masking to handle large trailing gaps we cannot
do so when there's this overrun case.

PR tree-optimization/115895
* tree-vect-stmts.cc (get_group_load_store_type): When we
might overrun because the group size is not a multiple of the
vector size we cannot use loop masking since that does not
implement the required load shortening.

* gcc.target/i386/vect-pr115895.c: New testcase.

6 months agolm32: In va_arg, skip to stack args with too few remaining reg args
Keith Packard [Thu, 16 Jan 2025 05:11:01 +0000 (22:11 -0700)] 
lm32: In va_arg, skip to stack args with too few remaining reg args

lm32 has 8 register parameter slots, so many vararg functions end up
with several anonymous parameters passed in registers. If we run out
of registers in the middle of a parameter, the entire parameter will
be placed on the stack, skipping any remaining available registers.

The receiving varargs function doesn't know this, and will save all of
the possible parameter register values just below the stack parameters.

When processing a va_arg call with a type size larger than a single
register, we must check to see if it spans the boundary between
register and stack parameters. If so, we need to skip to the stack
parameters.

This is done by making va_list a structure containing the arg pointer
and the address of the start of the stack parameters. Boundary checks
are inserted in va_arg calls to detect this case and the address of
the parameter is set to the stack parameter start when the parameter
crosses over.

gcc/
* config/lm32/lm32.cc: Add several #includes.
(va_list_type): New.
(lm32_build_va_list): New function.
(lm32_builtin_va_start): Likewise.
(lm32_sd_gimplify_va_arg_expr): Likewise.
(lm32_gimplify_va_arg_expr): Likewise.

6 months agolm32: Compute pretend_size in setup_incoming_varargs even if no_rtl
Keith Packard [Thu, 16 Jan 2025 05:08:59 +0000 (22:08 -0700)] 
lm32: Compute pretend_size in setup_incoming_varargs even if no_rtl

gcc/
* config/lm32/lm32.cc (setup_incoming_varargs): Adjust the
conditionals so that pretend_size is always computed, even
if no_rtl is set.

6 months agolm32: Skip last named param when computing save varargs regs
Keith Packard [Thu, 16 Jan 2025 05:05:46 +0000 (22:05 -0700)] 
lm32: Skip last named param when computing save varargs regs

The cumulative args value in setup_incoming_varargs points at
the last named parameter. We need to skip over that (if present) to
get to the first anonymous argument as we only want to include
those anonymous args in the saved register block.

gcc/
* config/lm32/lm32.cc (lm32_setup_incoming_varargs): Skip last
named parameter when preparing to flush registers with unnamed
arguments to th stack.

6 months agolm32: Args with arg.named false still get passed in regs
Keith Packard [Thu, 16 Jan 2025 05:02:36 +0000 (22:02 -0700)] 
lm32: Args with arg.named false still get passed in regs

* config/lm32/lm32.cc (lm32_function_arg): Pass unnamed
arguments in registers too, just like named arguments.

6 months agoFix an incorrect file header comment for the core2 scheduling model
Andi Kleen [Thu, 16 Jan 2025 03:07:44 +0000 (19:07 -0800)] 
Fix an incorrect file header comment for the core2 scheduling model

Committed as obvious.

gcc/ChangeLog:

* config/i386/x86-tune-sched-core.cc: Fix incorrect comment.

6 months agoFix setting of call graph node AutoFDO count
Eugene Rozenfeld [Sat, 11 Jan 2025 03:48:52 +0000 (19:48 -0800)] 
Fix setting of call graph node AutoFDO count

We are initializing both the call graph node count and
the entry block count of the function with the head_count value
from the profile.

Count propagation algorithm may refine the entry block count
and we may end up with a case where the call graph node count
is set to zero but the entry block count is non-zero. That becomes
a problem because we have this code in execute_fixup_cfg:

 profile_count num = node->count;
 profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
 bool scale = num.initialized_p () && !(num == den);

Here if num is 0 but den is not 0, scale becomes true and we
lose the counts in

if (scale)
  bb->count = bb->count.apply_scale (num, den);

This is what happened in the issue reported in PR116743
(a 10% regression in MySQL HAMMERDB tests).
3d9e6767939e9658260e2506e81ec32b37cba041 made an improvement in
AutoFDO count propagation, which caused a mismatch between
the call graph node count (zero) and the entry block count (non-zero)
and subsequent loss of counts as described above.

The fix is to update the call graph node count once we've done count propagation.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
PR gcov-profile/116743
* auto-profile.cc (afdo_annotate_cfg): Fix mismatch between the call graph node count
and the entry block count.

6 months agoDaily bump.
GCC Administrator [Thu, 16 Jan 2025 00:18:58 +0000 (00:18 +0000)] 
Daily bump.

6 months agolibstdc++: Fix use of internal feature test macro in test
Jonathan Wakely [Wed, 15 Jan 2025 23:37:14 +0000 (23:37 +0000)] 
libstdc++: Fix use of internal feature test macro in test

This test should use __cpp_lib_ios_noreplace rather than the internal
__glibcxx_ios_noreplace macro.

libstdc++-v3/ChangeLog:

* testsuite/27_io/ios_base/types/openmode/case_label.cc: Use
standard feature test macro not internal one.

6 months agolibstdc++: Fix fancy pointer test for std::set
Jonathan Wakely [Wed, 15 Jan 2025 21:24:15 +0000 (21:24 +0000)] 
libstdc++: Fix fancy pointer test for std::set

The alloc_ptr.cc test for std::set tries to use C++17 features
unconditionally, and tries to use the C++23 range members which haven't
been implemented for std::set yet.

Some of the range checks are left in place but commented out, so they
can be added after the ranges members are implemented. Others (such as
prepend_range) are not valid for std::set at all.

Also fix uses of internal feature test macros in two other tests, which
should use the standard __cpp_lib_xxx macros.

libstdc++-v3/ChangeLog:

* testsuite/23_containers/set/requirements/explicit_instantiation/alloc_ptr.cc:
Guard node extraction checks with feature test macro. Remove
calls to non-existent range members.
* testsuite/23_containers/forward_list/requirements/explicit_instantiation/alloc_ptr.cc:
Use standard macro not internal one.
* testsuite/23_containers/list/requirements/explicit_instantiation/alloc_ptr.cc:
Likewise.

6 months agomatch: Simplify `1 >> x` into `x == 0` [PR102705]
Andrew Pinski [Wed, 15 Jan 2025 03:38:47 +0000 (19:38 -0800)] 
match: Simplify `1 >> x` into `x == 0` [PR102705]

This in this PR we have missed optimization where we miss that,
`1 >> x` and `(1 >> x) ^ 1` can't be equal. There are a few ways of
optimizing this, the easiest and simpliest is to simplify `1 >> x` into
just `x == 0` as those are equivalant (if we ignore out of range values for x).
we already have an optimization for `(1 >> X) !=/== 0` so the only difference
here is we don't need the `!=/== 0` part to do the transformation.

So this removes the `(1 >> X) !=/== 0` transformation and just adds a simplfied
`1 >> x` -> `x == 0` one.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/102705

gcc/ChangeLog:

* match.pd (`(1 >> X) != 0`): Remove pattern.
(`1 >> x`): New pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr105832-2.c: Update testcase.
* gcc.dg/tree-ssa/pr96669-1.c: Likewise.
* gcc.dg/tree-ssa/pr102705-1.c: New test.
* gcc.dg/tree-ssa/pr102705-2.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
6 months agodoc: cleanup trailing whitespace
Sam James [Wed, 15 Jan 2025 22:51:31 +0000 (22:51 +0000)] 
doc: cleanup trailing whitespace

gcc/ChangeLog:

* doc/extend.texi: Cleanup trailing whitespace.

6 months agodoc: trivial grammar fix
Sam James [Wed, 15 Jan 2025 22:50:28 +0000 (22:50 +0000)] 
doc: trivial grammar fix

We say 'a constant .. expression' elsewhere. Fix the grammar.

gcc/ChangeLog:

* doc/extend.texi: Add 'a' for grammar fix.

6 months agolibstdc++: Fix reversed args in unreachable assumption [PR109849]
Jonathan Wakely [Wed, 15 Jan 2025 09:33:55 +0000 (09:33 +0000)] 
libstdc++: Fix reversed args in unreachable assumption [PR109849]

libstdc++-v3/ChangeLog:

PR libstdc++/109849
* include/bits/vector.tcc (vector::_M_range_insert): Fix
reversed args in length calculation.

6 months agoFortran: reject NULL as source-expr in ALLOCATE with SOURCE= or MOLD= [PR71884]
Harald Anlauf [Wed, 15 Jan 2025 18:42:52 +0000 (19:42 +0100)] 
Fortran: reject NULL as source-expr in ALLOCATE with SOURCE= or MOLD= [PR71884]

PR fortran/71884

gcc/fortran/ChangeLog:

* resolve.cc (resolve_allocate_expr): Reject intrinsic NULL as
source-expr.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr71884.f90: New test.

6 months agoc++: Handle RAW_DATA_CST in unify [PR118390]
Jakub Jelinek [Wed, 15 Jan 2025 17:27:07 +0000 (18:27 +0100)] 
c++: Handle RAW_DATA_CST in unify [PR118390]

This patch uses the count_ctor_elements function to fix up
unify deduction of array sizes.

2025-01-15  Jakub Jelinek  <jakub@redhat.com>

PR c++/118390
* cp-tree.h (count_ctor_elements): Declare.
* call.cc (count_ctor_elements): No longer static.
* pt.cc (unify): Use count_ctor_elements instead of
CONSTRUCTOR_NELTS.

* g++.dg/cpp/embed-20.C: New test.
* g++.dg/cpp0x/pr118390.C: New test.

6 months agoAArch64: Update neoverse512tvb tuning
Wilco Dijkstra [Fri, 10 Jan 2025 19:48:02 +0000 (19:48 +0000)] 
AArch64: Update neoverse512tvb tuning

Fix the neoverse512tvb tuning to be like Neoverse V1/V2 and add the
missing AARCH64_EXTRA_TUNE_BASE and AARCH64_EXTRA_TUNE_AVOID_PRED_RMW.

gcc:
* config/aarch64/tuning_models/neoverse512tvb.h (tune_flags): Update.

6 months agoAArch64: Add FULLY_PIPELINED_FMA to tune baseline
Wilco Dijkstra [Thu, 14 Nov 2024 14:34:17 +0000 (14:34 +0000)] 
AArch64: Add FULLY_PIPELINED_FMA to tune baseline

Add FULLY_PIPELINED_FMA to tune baseline - this is a generic feature that is
already enabled for some cores, but benchmarking it shows it is faster on all
modern cores (SPECFP improves ~0.17% on Neoverse V1 and 0.04% on Neoverse N1).

gcc:
* config/aarch64/aarch64-tuning-flags.def (AARCH64_EXTRA_TUNE_BASE):
Add AARCH64_EXTRA_TUNE_FULLY_PIPELINED_FMA.
* config/aarch64/tuning_models/ampere1b.h: Remove redundant
AARCH64_EXTRA_TUNE_FULLY_PIPELINED_FMA.
* config/aarch64/tuning_models/neoversev2.h: Likewise.

6 months agoAArch64: Deprecate -mabi=ilp32
Wilco Dijkstra [Thu, 9 Jan 2025 19:41:14 +0000 (19:41 +0000)] 
AArch64: Deprecate -mabi=ilp32

ILP32 was originally intended to make porting to AArch64 easier.  Support was
never merged in the Linux kernel or GLIBC, so it has been unsupported for many
years.  There isn't a benefit in keeping unsupported features forever, so
deprecate it now (and it could be removed in a future release).

gcc:
* config/aarch64/aarch64.cc (aarch64_override_options): Add warning.
* doc/invoke.texi: Document -mabi=ilp32 as deprecated.

gcc/testsuite:
* gcc.target/aarch64/inline-mem-set-pr112804.c: Add -Wno-deprecated.
* gcc.target/aarch64/pr100518.c: Likewise.
* gcc.target/aarch64/pr113114.c: Likewise.
* gcc.target/aarch64/pr80295.c: Likewise.
* gcc.target/aarch64/pr94201.c: Likewise.
* gcc.target/aarch64/pr94577.c: Likewise.
* gcc.target/aarch64/sve/pr108603.c: Likewise.

6 months agobpf: set index entry for a VAR_DECL in CO-RE relocs
Cupertino Miranda [Wed, 15 Jan 2025 14:38:32 +0000 (14:38 +0000)] 
bpf: set index entry for a VAR_DECL in CO-RE relocs

CO-RE accesses with non pointer struct variables will also generate a
"0" string access within the CO-RE relocation.
The first index within the access string, has sort of a different
meaning then the remaining of the indexes.
For i0:i1:...:in being an access index for "struct A a" declaration, its
semantics are represented by:
  (&a + (sizeof(struct A) * i0) + offsetof(i1:...:in)

gcc/ChangeLog:
* config/bpf/core-builtins.cc (compute_field_expr): Change
VAR_DECL outcome in switch case.

gcc/testsuite/ChangeLog:
* gcc.target/bpf/core-builtin-1.c: Correct test.
* gcc.target/bpf/core-builtin-2.c: Correct test.
* gcc.target/bpf/core-builtin-exprlist-1.c: Correct test.

6 months agobpf: calls do not promote attr access_index on lhs
Cupertino Miranda [Wed, 15 Jan 2025 14:28:59 +0000 (14:28 +0000)] 
bpf: calls do not promote attr access_index on lhs

When traversing gimple to introduce CO-RE relocation entries to
expressions that are accesses to attributed perserve_access_index types,
the access is likely to be split in multiple gimple statments.
In order to keep doing the proper CO-RE convertion we will need to mark
the LHS tree nodes of gimple expressions as explicit CO-RE accesses,
such that the gimple traverser will further convert the sub-expressions.

This patch makes sure that this LHS marking will not happen in case the
gimple statement is a function call, which case it is no longer
expecting to keep generating CO-RE accesses with the remaining of the
expression.

gcc/ChangeLog:

* config/bpf/core-builtins.cc
(make_gimple_core_safe_access_index): Fix in condition.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/core-attr-calls.c: New test.

6 months agobpf: make sure CO-RE relocs are typed with struct BTF_KIND_STRUCT
Cupertino Miranda [Wed, 15 Jan 2025 14:25:44 +0000 (14:25 +0000)] 
bpf: make sure CO-RE relocs are typed with struct BTF_KIND_STRUCT

Based on observation within bpf-next selftests and comparisson of GCC
and clang compiled code, the BPF loader expects all CO-RE relocations to
point to BTF non const and non volatile type nodes.

gcc/ChangeLog:

* btfout.cc (get_btf_kind): Remove static from function definition.
* config/bpf/btfext-out.cc (bpf_code_reloc_add): Check if CO-RE type
is not a const or volatile.
* ctfc.h (btf_dtd_kind): Add prototype for function.

gcc/testsuite/ChangeLog:

* gcc.target/bpf/core-attr-const.c: New test.

6 months agoc++: Implement mangling of RAW_DATA_CST [PR118278]
Jakub Jelinek [Wed, 15 Jan 2025 16:04:31 +0000 (17:04 +0100)] 
c++: Implement mangling of RAW_DATA_CST [PR118278]

As the following testcases show (mangle80.C only after reversion of the
temporary reversion of C++ large array speedup commit), RAW_DATA_CST can
be seen during mangling of some templates and we ICE because
the mangler doesn't handle it.

The following patch handles it and mangles it the same as a sequence of
INTEGER_CSTs that were used previously instead.
The only slight complication is that if ce->value is the last nonzero
element, we need to skip the zeros at the end of RAW_DATA_CST.

2025-01-03  Jakub Jelinek  <jakub@redhat.com>

PR c++/118278
* mangle.cc (write_expression): Handle RAW_DATA_CST.

* g++.dg/abi/mangle80.C: New test.
* g++.dg/cpp/embed-19.C: New test.

6 months agoc++: handle decltype in nested-name-spec printing [PR118139]
Marek Polacek [Thu, 19 Dec 2024 22:47:03 +0000 (17:47 -0500)] 
c++: handle decltype in nested-name-spec printing [PR118139]

Compiling this test, we emit:

  error: 'static void CW<T>::operator=(int) requires requires(typename'decltype_type' not supported by pp_cxx_unqualified_id::type x) {x;}' must be a non-static member function

where the DECLTYPE_TYPE isn't printed properly.  This patch fixes that
to print:

error: 'static void CW<T>::operator=(int) requires requires(typename decltype(T())::type x) {x;}' must be a non-static member function

PR c++/118139

gcc/cp/ChangeLog:

* cxx-pretty-print.cc (pp_cxx_nested_name_specifier): Handle
a computed-type-specifier.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/decltype1.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
6 months agolibstdc++: Fix comments in test that reference wrong subclause of C++11
Jonathan Wakely [Wed, 18 Dec 2024 17:48:59 +0000 (17:48 +0000)] 
libstdc++: Fix comments in test that reference wrong subclause of C++11

libstdc++-v3/ChangeLog:

* testsuite/28_regex/traits/char/transform_primary.cc: Fix
subclause numbering in references to the standard.

6 months agomiddle-end: Fix incorrect type replacement in operands_equals [PR118472]
Tamar Christina [Wed, 15 Jan 2025 13:58:00 +0000 (13:58 +0000)] 
middle-end: Fix incorrect type replacement in operands_equals [PR118472]

In g:3c32575e5b6370270d38a80a7fa8eaa144e083d0 I made a mistake and incorrectly
replaced the type of the arguments of an expression with the type of the
expression.  This is of course wrong.

This reverts that change and I have also double checked the other replacements
and they are fine.

gcc/ChangeLog:

PR middle-end/118472
* fold-const.cc (operand_compare::operand_equal_p): Fix incorrect
replacement.

gcc/testsuite/ChangeLog:

PR middle-end/118472
* gcc.dg/pr118472.c: New test.

6 months agoAnnotate dbg_line_numbers table
Richard Biener [Wed, 15 Jan 2025 10:25:25 +0000 (11:25 +0100)] 
Annotate dbg_line_numbers table

The following adds /* <num> */ to dbg_line_numbers so there's the chance
to more easily lookup the ID of the match.pd line number used for
dumping when you want to debug a speicific replacement.  It also cuts
the lines down to 10 entries.

  static int dbg_line_numbers[1267] = {
        /* 0 */ 161, 164, 173, 175, 178, 181, 183, 189, 197, 195,
        /* 10 */ 199, 201, 205, 923, 921, 2060, 2071, 2052, 2058, 2063,
...

* genmatch.cc (define_dump_logs): Make reverse lookup in
dbg_line_numbers easier by adding comments with start index
and cutting number of elements per line to 10.

6 months agotestsuite: i386: Fix expected vectoriziation in pr105493.c
Christoph Müllner [Tue, 14 Jan 2025 12:20:50 +0000 (13:20 +0100)] 
testsuite: i386: Fix expected vectoriziation in pr105493.c

As reported in PR117079, commit ab18785840d7b8 broke the test pr105493.c.
The test code contains two loops, where the first one is exected to be
vectorized.  The commit that broke that vectorization was the first of
several that enabled vectorization of both loops.
Now, that GCC can vectorize the whole function, let's adjust this test
to expect vectorization of both loops by ensuring that we don't write
to the helper-array 'tmp'.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
PR target/117079

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr105493.c: Fix expected vectorization

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
6 months agoOpenMP/C++: Fix 'declare variant' for struct-returning functions [PR118486]
Tobias Burnus [Wed, 15 Jan 2025 09:47:29 +0000 (10:47 +0100)] 
OpenMP/C++: Fix 'declare variant' for struct-returning functions [PR118486]

To find the variant declaration, a call is constructed in
omp_declare_variant_finalize_one, which gives here:
  TARGET_EXPR <D.3010, variant_fn ()>

Extracting now the function declaration failed and gave the bogus
  error: could not find variant declaration

Solution: Use the 2nd argument of the TARGET_EXPR and continue.

PR c++/118486

gcc/cp/ChangeLog:

* decl.cc (omp_declare_variant_finalize_one): When resolving
the variant to use, handle variant calls with TARGET_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/gomp/declare-variant-11.C: New test.

6 months agoipa: Initialize/release global obstack in process_new_functions [PR116068]
Jakub Jelinek [Wed, 15 Jan 2025 08:43:32 +0000 (09:43 +0100)] 
ipa: Initialize/release global obstack in process_new_functions [PR116068]

Other spots in cgraphunit.cc already call bitmap_obstack_initialize (NULL);
before running a pass list and bitmap_obstack_release (NULL); after that,
while process_new_functions wasn't doing that and with the new r15-130
bitmap_alloc checking that results in ICE.

2025-01-15  Jakub Jelinek  <jakub@redhat.com>

PR ipa/116068
* cgraphunit.cc (symbol_table::process_new_functions): Call
bitmap_obstack_initialize (NULL); and bitmap_obstack_release (NULL)
around processing the functions.

* gcc.dg/graphite/pr116068.c: New test.