]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
97 min agoDaily bump. master trunk
GCC Administrator [Mon, 18 Aug 2025 00:18:52 +0000 (00:18 +0000)] 
Daily bump.

10 hours ago[PR target/121213] Avoid unnecessary constant load in amoswap
Austin Law [Sun, 17 Aug 2025 15:03:51 +0000 (09:03 -0600)] 
[PR target/121213] Avoid unnecessary constant load in amoswap

PR 121213 shows an unnecessary "li target,0" in an atomic exchange loop
on RISC-V.

The source operand for an amoswap instruction should allow (const_int 0)
in addition to GPRs.  So the operand's predicate is changed to
"reg_or_0_operand".   The corresponding constraint is also changed to
allow a reg or the constant 0.

With the source operand no longer tied to the destination operand we do
not need the earlyclobber for the destination, so the destination
operand's constraint is adjusted accordingly.

This patch does not address the unnecessary sign extension reported in
the PR.

Tested with no regressions on riscv32-elf and riscv64-elf.

PR target/121213
gcc/
* config/riscv/sync.md (amo_atomic_exchange<mode>): Allow
(const_int 0) as input operand. Do not tie input to output.
No longer earlyclobber the output.

gcc/testsuite
* gcc.target/riscv/amo/pr121213.c: New test.

11 hours agoAdd test for spill failure
dragan.mladjenovic [Sun, 17 Aug 2025 14:51:25 +0000 (08:51 -0600)] 
Add test for spill failure

Adding the float-agnostic reproducer as test-case.

gcc/testsuite/

* gcc.target/mips/tls-1.c: New file.

11 hours agoTestsuite: Use HAS_LDC instead of a specific ISA
Matthew Fortune [Sun, 17 Aug 2025 14:47:02 +0000 (08:47 -0600)] 
Testsuite: Use HAS_LDC instead of a specific ISA

The call-clobbered-1.c test has both reasons to be above a certain
ISA and below a certain ISA level.  The option based ISA min/max
code only triggers if there is no isa level request.

gcc/testsuite/
* gcc.target/mips/call-clobbered-1.c: Use HAS_LDC ghost
option instead of isa>=2.

11 hours agoTestsuite: Fix tests properly for compact-branches
Andrew Bennett [Sun, 17 Aug 2025 14:41:13 +0000 (08:41 -0600)] 
Testsuite: Fix tests properly for compact-branches

Compact-branches use the balc opcode, this patch adjusts the testsuite
to handle that correctly.

gcc/testsuite
* gcc.target/mips/near-far-1.c: Fix tests properly for
compact-branches (jals and balc).
* gcc.target/mips/near-far-2.c: Likewise.
* gcc.target/mips/near-far-3.c: Likewise.
* gcc.target/mips/near-far-4.c: Likewise.

11 hours agoTestsuite: Adjust tests to cope with -mips16
Jeff Law [Sun, 17 Aug 2025 14:34:22 +0000 (08:34 -0600)] 
Testsuite: Adjust tests to cope with -mips16

Various tests are missing NOMIPS16 markers or can be safely
skipped via -mno-mips16.  Adjust them appropriately.

gcc/testsuite/

* gcc.target/mips/call-clobbered-2.c: Add a NOMIPS16 attribute.
* gcc.target/mips/call-clobbered-3.c: Likewise.
* gcc.target/mips/call-clobbered-5.c: Likewise.
* gcc.target/mips/ds-schedule-2.c: Add an -mno-mips16 option.
* gcc.target/mips/interrupt_handler-bug-1.c: Same as
call-clobbered-*.c tests.
* gcc.target/mips/movdf-1.c: Likewise.
* gcc.target/mips/movdf-2.c: Likewise.
* gcc.target/mips/movdf-3.c: Likewise.
* gcc.target/mips/msa-builtins.c: Same as ds-schedule-2.c.
Remove a NOMIPS16 attribute from builtins.
* gcc.target/mips/msa.c: Likewise.

11 hours agoTestsuite: Fix insn-*.c tests from trunk
Matthew Fortune [Sun, 17 Aug 2025 14:26:12 +0000 (08:26 -0600)] 
Testsuite: Fix insn-*.c tests from trunk

Ensure micromips test does not get confused about library support.
Ensure insn-casesi.c and insn-tablejump.c can be executed.

Move the micromips/mips16 selection into the file as per function
attributes so that there is no requirement on having a full
micromips or mips16 runtime to execute the test.

gcc/testsuite/

* gcc.target/mips/insn-casesi.c: Require mips16 support but
not the command line option.
* gcc.target/mips/insn-tablejump.c: Force o32 ABI as
we do not really support n32/n64 microMIPS.  Require micromips
support but not the command line option.

11 hours agoregrename: treat writes as reads for fused instruction pairs
Artemiy Volkov [Sun, 17 Aug 2025 14:08:29 +0000 (08:08 -0600)] 
regrename: treat writes as reads for fused instruction pairs

Consider the following (RISC-V) instruction pair:

mul s6,a1,a2
add s6,a4,s6

Without this patch, while handling the second instruction, (a) the
existing chain for s6 will first be closed (upon the terminate_write
action for the input operand), then (b) a new one will be opened (upon
the mark_write action for the output operand).  This will likely lead to
the two output operands being different physical registers, breaking the
single-output property required for some macro-op fusion pairs.

This patch, using the single_output_fused_pair_p () predicate introduced
earlier, changes the regrename behavior for such pairs to append the
input and the output operands to the existing chain (as if both actions
were mark_read), instead of breaking the current renaming chain and
starting a new one.  This ensures that the output operands of both fused
instructions are kept in the same hard register, and that the
single-output property of the insn pair is preserved.

gcc/ChangeLog:

* regrename.cc (scan_rtx_reg): Handle fused insn pairs.

11 hours ago[PR target/109324] H8/300: Fix genrecog warnings about operands missing modes.
Jan Dubiec [Sun, 17 Aug 2025 14:03:33 +0000 (08:03 -0600)] 
[PR target/109324] H8/300: Fix genrecog warnings about operands missing modes.

This patch fixes genrecog warnings about operands missing modes. This is
done by explicitly specifying modes of operations.

PR target/109324

gcc/ChangeLog:

* config/h8300/addsub.md: Explicitly specify mode for plus operation.
* config/h8300/jumpcall.md: Explicitly specify modes for eq and
match_operand operations.
* config/h8300/testcompare.md: Explicitly specify modes for eq, ltu
and compare operations.

15 hours agoMAINTAINERS, contrib: Appease check-MAINTAINERS.py (email order)
Filip Kastl [Sun, 17 Aug 2025 10:56:03 +0000 (12:56 +0200)] 
MAINTAINERS, contrib: Appease check-MAINTAINERS.py (email order)

The contrib/check-MAINTAINERS.py script sorts by surname, name, bugzilla
handle and email (in this order).  Document this.  Switch around Andrew
Pinski's entries in Contributing under DCO.

Pushing as obvious.

ChangeLog:

* MAINTAINERS: Switch around Andrew Pinski's entries in
Contributing under DCO.

contrib/ChangeLog:

* check-MAINTAINERS.py: Document the way the script sorts
entries.

Signed-off-by: Filip Kastl <fkastl@suse.cz>
23 hours agoira: tie output allocnos for fused instruction pairs
Artemiy Volkov [Sun, 17 Aug 2025 02:40:28 +0000 (20:40 -0600)] 
ira: tie output allocnos for fused instruction pairs

Some of the instruction pairs recognized as fusible by a preceding
invocation of the dep_fusion pass require that both components of a pair
have the same hard register output for the fusion to work in hardware.
(An example of this would be a multiply-add operation, or a zero-extract
operation composed of two shifts.)

For all such pairs, the following conditions will hold:
  (a) Both insns are single_sets
  (b) Both insns have a register destination
  (c) The pair has been marked as fusible by setting the second insn's
SCHED_GROUP flag
  (d) Additionally, post-RA, both instructions' destination regnos are
equal

(All of these conditions are encapsulated in the newly created
single_output_fused_pair_p () predicate.)

During IRA, if conditions (a)-(c) above hold, we need to tie the two
instructions' destination allocnos together so that they are allocated
to the same hard register.  We do this in add_insn_allocno_copies () by
adding a constraint conflict to the output operands of the two
instructions.

gcc/ChangeLog:

* ira-conflicts.cc (add_insn_allocno_copies): Handle fused insn pairs.
* rtl.h (single_output_fused_pair_p): Declare new function.
* rtlanal.cc (single_output_fused_pair_p): Define it.

23 hours ago[PATCH] RISC-V: Fix block matching in arch-canonicalize [PR121538]
Dimitar Dimitrov [Sun, 17 Aug 2025 02:30:14 +0000 (20:30 -0600)] 
[PATCH] RISC-V: Fix block matching in arch-canonicalize [PR121538]

Commit r16-3028-g0c517ddf9b136c introduced parsing of conditional blocks
in riscv-ext*.def.  For simplicity, it used a simple regular expression
to match the C++ lambda function for each condition.  But the regular
expression is too simple - it matches only the first scoped code block,
without any trailing closing braces.

The "c" dependency for the "zca" extension has two code blocks inside
its conditional.  One for RV32 and one for RV64.  The script matches
only the RV32 block, and leaves the RV64 one.  Any strings left, in turn,
are considered a list of non-conditional extensions.  Thus the quoted
strings "d" and "zcd" from that block are taken as "simple" (non-conditional)
dependencies:

  if (subset_list->xlen () == 64)
    {
      if (subset_list->lookup ("d"))
        return subset_list->lookup ("zcd");

As a result, arch-canonicalize erroneously adds "d" extension:
  $ ./config/riscv/arch-canonicalize rv32ec
  rv32efdc_zicsr_zca_zcd_zcf

  Before r16-3028-g0c517ddf9b136c the command returned:
  $ ./config/riscv/arch-canonicalize rv32ec
  rv32ec

Fix by extending the conditional block match until the number of opening
and closing braces is equal.  This change might seem crude, but it does
save us from introducing a full C++ parser into the simple
arch-canonicalize python script.  With this patch the script now
returns:

  $ ./config/riscv/arch-canonicalize rv32ec
  rv32ec_zca

Ok for trunk?

PR target/121538

gcc/ChangeLog:

* config/riscv/arch-canonicalize (parse_dep_exts):
Match condition block up to closing brace.
(test_parse_long_condition_block): New test.

24 hours agox86: Add target("80387") function attribute
H.J. Lu [Fri, 15 Aug 2025 02:04:33 +0000 (19:04 -0700)] 
x86: Add target("80387") function attribute

Add target("80387") attribute to enable and disable x87 instructions in a
function.

gcc/

PR target/121541
* config/i386/i386-options.cc
(ix86_valid_target_attribute_inner_p): Add target("80387")
attribute.  Set the mask bit in opts_set->x_target_flags if the
mask bit in opts->x_target_flags is updated.
* doc/extend.texi: Document target("80387") function attribute.

gcc/testsuite/

PR target/121541
* gcc.target/i386/pr121541-1a.c: New test.
* gcc.target/i386/pr121541-1b.c: Likewise.
* gcc.target/i386/pr121541-2.c: Likewise.
* gcc.target/i386/pr121541-3.c: Likewise.
* gcc.target/i386/pr121541-4.c: Likewise.
* gcc.target/i386/pr121541-5a.c: Likewise.
* gcc.target/i386/pr121541-5b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
25 hours agoDaily bump.
GCC Administrator [Sun, 17 Aug 2025 00:19:17 +0000 (00:19 +0000)] 
Daily bump.

25 hours agoc++: Implement P2115R0 linkage changes for unnamed unscoped enums [PR120503]
Nathaniel Shead [Fri, 8 Aug 2025 13:23:18 +0000 (23:23 +1000)] 
c++: Implement P2115R0 linkage changes for unnamed unscoped enums [PR120503]

We currently list P2115R0 as implemented, but only the modules changes
had been done.  This patch implements the linkage changes so that
unnamed unscoped enums will use the name of the first enumerator for
linkage purposes.

This is (strictly speaking) a breaking change, as code that previously
relied on unnamed enumerations being internal linkage may have overloads
using those types become exposed and clash with other functions in a
different TU that have been similarly exposed.  As such this feature is
only implemented for C++20.

No ABI flag warning is provided, partly because C++20 is still an
experimental standard, but also because any affected functions could not
have been part of an ABI until this change anyway.

A number of testcases that are testing for behaviour of no-linkage types
are adjusted to use an enumeration with no values, so that the pre-C++20
and post-C++20 behaviour is equivalently tested.

In terms of implementation, I had originally considered adjusting the
DECL_NAME of the enum, as with 'name_unnamed_type', but this ended up
being more complicated as it had unwanted interactions with the existing
modules streaming and with name lookup and diagnostic messages.  This
patch instead uses a new function to derive this case.

The standard says that ([dcl.enum] p11) such an enum "...is denoted, for
linkage purposes, by its underlying type and its first enumerator", so
we need to add a new mangling production as well to handle this.

PR c++/120503
PR c++/120824

gcc/cp/ChangeLog:

* cp-tree.h (TYPE_UNNAMED_P): Adjust for enums with enumerators
for linkage purposes.
(enum_with_enumerator_for_linkage_p): Declare.
* decl.cc (name_unnamed_type): Adjust assertions to handle enums
with enumerators for linkage purposes.
(grokdeclarator): Use a typedef name for enums with enumerators
for linkage purposes.
(enum_with_enumerator_for_linkage_p): New function.
(finish_enum_value_list): Reset type linkage for enums with
enumerators for linkage purposes.
* mangle.cc (write_unnamed_enum_name): New function.
(write_unqualified_name): Handle enums with enumerators for
linkage purposes.
* tree.cc (decl_linkage): Fixup unnamed enums.

gcc/testsuite/ChangeLog:

* g++.dg/abi/mangle32.C: Remove enumerator list.
* g++.dg/cpp0x/linkage2.C: Likewise.
* g++.dg/ext/vector26.C: Likewise.
* g++.dg/other/anon3.C: Likewise.
* g++.dg/abi/mangle83.C: New test.
* g++.dg/modules/enum-15_a.C: New test.
* g++.dg/modules/enum-15_b.C: New test.

include/ChangeLog:

* demangle.h (enum demangle_component_type): Add enumeration
DEMANGLE_COMPONENT_UNNAMED_ENUM.

libiberty/ChangeLog:

* cp-demangle.c (d_unnamed_enum): New function.
(d_unqualified_name): Call it.
(cplus_demangle_type): Handle unscoped unnamed types
(Ue, Ul, etc.)
(d_count_templates_scopes): Handle unnamed enums.
(d_find_pack): Likewise.
(d_print_comp_inner): Print unnamed enums.
* testsuite/demangle-expected: Add tests.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
25 hours agoRISC-V: Update the comments of vx combine [NFC]
Pan Li [Sat, 16 Aug 2025 08:08:23 +0000 (16:08 +0800)] 
RISC-V: Update the comments of vx combine [NFC]

The supported insn of vx combine is out of date, update all
insn supported for now.

gcc/ChangeLog:

* config/riscv/autovec-opt.md: Add supported insn
of vx combine.

Signed-off-by: Pan Li <pan2.li@intel.com>
25 hours agoRISC-V: Add missed DONE for vx combine pattern [NFC]
Pan Li [Sat, 16 Aug 2025 08:01:40 +0000 (16:01 +0800)] 
RISC-V: Add missed DONE for vx combine pattern [NFC]

The previous patch missed the DONE indicator of the vx
combine pattern.  Thus add it back.

gcc/ChangeLog:

* config/riscv/autovec-opt.md: Add missed DONE
for vx combine pattern.

Signed-off-by: Pan Li <pan2.li@intel.com>
28 hours agofortran: Set DECL_TLS_MODEL after processing a variable
H.J. Lu [Fri, 1 Aug 2025 12:00:51 +0000 (05:00 -0700)] 
fortran: Set DECL_TLS_MODEL after processing a variable

Call set_decl_tls_model only after a variable has been fully processed,
not in the middle of processing it.

gcc/fortran/

PR fortran/107421
* trans-common.cc (build_common_decl): Call set_decl_tls_model
after processing a variable.
* trans-decl.cc (gfc_finish_var_decl): Likewise.
(get_proc_pointer_decl): Likewise.

gcc/testsuite/

PR fortran/107421
* gfortran.dg/gomp/pr107421.f90: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
40 hours agoMAINTAINERS: Add myself to write after approval
Mikael Pettersson [Sat, 16 Aug 2025 09:08:58 +0000 (11:08 +0200)] 
MAINTAINERS: Add myself to write after approval

ChangeLog:

* MAINTAINERS: Add myself to write after approval.

2 days agoDaily bump.
GCC Administrator [Sat, 16 Aug 2025 00:19:12 +0000 (00:19 +0000)] 
Daily bump.

2 days agoc++: Implement __builtin_structured_binding_size trait
Jakub Jelinek [Fri, 15 Aug 2025 20:38:41 +0000 (22:38 +0200)] 
c++: Implement __builtin_structured_binding_size trait

clang++ apparently added a SFINAE-friendly __builtin_structured_binding_size
trait to return the structured binding size (or error if not in SFINAE
contexts if a type doesn't have a structured binding size).

The expansion statement patch already anticipated this through adding
complain argument to cp_finish_decomp.

The following patch implements it.

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

gcc/
* doc/extend.texi (Type Traits): Document
__builtin_structured_binding_size.
gcc/cp/
* cp-trait.def (STRUCTURED_BINDING_SIZE): New unary trait.
* cp-tree.h (finish_structured_binding_size): Declare.
* semantics.cc (trait_expr_value): Handle
CPTK_STRUCTURED_BINDING_SIZE.
(finish_structured_binding_size): New function.
(finish_trait_expr): Handle CPTK_RANK and CPTK_TYPE_ORDER
in the switch instead of just doing break; for those and
ifs at the end to handle them.  Handle CPTK_STRUCTURED_BINDING_SIZE.
* pt.cc (tsubst_expr): Likewise.
* constraint.cc (diagnose_trait_expr): Likewise.
* decl.cc (get_tuple_size): Use mce_true for maybe_const_value.
(cp_decomp_size): Diagnose incomplete types not just if
processing_template_decl, and use error_at instead of pedwarn.
If btype is NULL, just return 0 instead of diagnosing an error.
gcc/testsuite/
* g++.dg/cpp26/expansion-stmt15.C: Expect different diagnostics
for zero size destructuring expansion statement.
* g++.dg/ext/builtin-structured-binding-size1.C: New test.
* g++.dg/ext/builtin-structured-binding-size2.C: New test.
* g++.dg/ext/builtin-structured-binding-size3.C: New test.
* g++.dg/ext/builtin-structured-binding-size4.C: New test.

2 days agoc++: Add testcases for the defarg part of P1766R1 [PR121552]
Jakub Jelinek [Fri, 15 Aug 2025 20:37:42 +0000 (22:37 +0200)] 
c++: Add testcases for the defarg part of P1766R1 [PR121552]

The following patch adds some testcases for the default argument (function
and template) part of the paper, making sure we diagnose multiple defargs
in the same TU and when visible in modules and DTRT when some aren't visible
and some are visible and they are equal.  Not testing when they are
different since that is IFNDR.

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

PR c++/121552
* g++.dg/parse/defarg21.C: New test.
* g++.dg/template/defarg24.C: New test.
* g++.dg/modules/default-arg-4_a.C: New test.
* g++.dg/modules/default-arg-4_b.C: New test.
* g++.dg/modules/default-arg-5_a.C: New test.
* g++.dg/modules/default-arg-5_b.C: New test.

2 days agoc++: Implement C++20 P1766R1 - Mitigating minor modules maladies [PR121552]
Jakub Jelinek [Fri, 15 Aug 2025 20:36:18 +0000 (22:36 +0200)] 
c++: Implement C++20 P1766R1 - Mitigating minor modules maladies [PR121552]

The following patch attempts to implement the
C++20 P1766R1 - Mitigating minor modules maladies
paper.
clang++ a few years ago introduced for the diagnostics required in
the paper -Wnon-c-typedef-for-linkage pedwarn and the following patch
does that too.
The paper was accepted as a DR, the patch enables the warning
also for C++98, dunno whether it might not be better to do it only
for C++11 onwards.

The paper is also about differences in default arguments of functions
in different TUs and in modules, I think within the same TU we diagnose
it correctly (maybe I should add some testcase) and perhaps try
something with modules as well.  But in different TUs it is IFNDR.

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

PR c++/121552
gcc/
* doc/invoke.texi (-Wno-non-c-typedef-for-linkage): Document.
gcc/c-family/
* c.opt (Wnon-c-typedef-for-linkage): New option.
* c.opt.urls: Regenerate.
gcc/cp/
* decl.cc: Implement C++20 P1766R1 - Mitigating minor modules maladies.
(diagnose_non_c_class_typedef_for_linkage,
maybe_diagnose_non_c_class_typedef_for_linkage): New functions.
(name_unnamed_type): Call
maybe_diagnose_non_c_class_typedef_for_linkage.
gcc/testsuite/
* g++.dg/cpp2a/typedef1.C: New test.
* g++.dg/debug/dwarf2/typedef5.C: Add -Wno-non-c-typedef-for-linkage
to dg-options.
* g++.dg/inherit/typeinfo1.C: Add -Wno-non-c-typedef-for-linkage
to dg-additional-options.
* g++.dg/parse/ctor2.C: Likewise.
* g++.dg/ext/anon-struct9.C: Add -Wno-non-c-typedef-for-linkage to
dg-options.
* g++.dg/ext/visibility/anon11.C: Add -Wno-non-c-typedef-for-linkage
to dg-additional-options.
* g++.dg/lto/pr69137_0.C: Add -Wno-non-c-typedef-for-linkage
to dg-lto-options.
* g++.dg/other/anon8.C: Add -Wno-non-c-typedef-for-linkage
to dg-additional-options.
* g++.dg/template/pr84973.C: Likewise.
* g++.dg/template/pr84973-2.C: Likewise.
* g++.dg/template/pr84973-3.C: Likewise.
* g++.dg/abi/anon2.C: Likewise.
* g++.dg/abi/anon3.C: Likewise.
* g++.old-deja/g++.oliva/linkage1.C: Likewise.

2 days agoc++: Fix default argument parsing in non-comma variadic methods [PR121539]
Jakub Jelinek [Fri, 15 Aug 2025 20:34:59 +0000 (22:34 +0200)] 
c++: Fix default argument parsing in non-comma variadic methods [PR121539]

While the non-comma variadic functions/methods were deprecated in C++26,
they are still valid and they are valid without deprecation in C++98 to
C++23.
We parse default arguments followed by ...) outside of classes or
for out of class definitions of methods, but I think since C++11 support
in GCC 4.9 or so we consider ... to be a part of a default argument and
error on it.
I think a default argument can't validly contain a pack expansion
that ends the expression with ..., so I think we can simply handle
...) if at depth 0 as not part of the default argument.

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

PR c++/121539
* parser.cc (cp_parser_cache_defarg): Set done to true for
CPP_ELLIPSIS followed by CPP_CLOSE_PAREN in !nsdmi at depth 0.

* g++.dg/parse/defarg20.C: New test.

2 days agoc++: Warn on #undef/#define of remaining cpp.predefined macros [PR120778]
Jakub Jelinek [Fri, 15 Aug 2025 20:31:27 +0000 (22:31 +0200)] 
c++: Warn on #undef/#define of remaining cpp.predefined macros [PR120778]

We already warn on #undef or pedwarn on #define (but not on #define
after #undef) of some builtin macros mentioned in cpp.predefined.

The C++26 P2843R3 paper changes it from (compile time) undefined behavior
to ill-formed.  The following patch arranges for warning (for #undef)
and pedwarn (on #define) for the remaining cpp.predefined macros.
__cpp_* feature test macros only for C++20 which added some of them
to cpp.predefined, in earlier C++ versions it was just an extension and
for pedantic diagnostic I think we don't need to diagnose anything,
__STDCPP_* and __cplusplus macros for all C++ versions where they appeared.

Like the earlier posted -Wkeyword-macro diagnostics (which is done
regardless whether the identifier is defined as a macro or not, obviously
most likely none of the keywords are defined as macros initially), this
one also warns on #undef when a macro isn't defined or later #define
after #undef.

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

PR preprocessor/120778
PR target/121520
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Implement C++26 DR 2581.  Add
cpp_define_warn lambda and use it as well as cpp_warn where needed.
In the if (c_dialect_cxx ()) block with __cpp_* predefinitions add
cpp_define lambda.  Formatting fixes.
gcc/c/
* c-decl.cc (c_init_decl_processing): Use cpp_warn instead of
cpp_lookup and NODE_WARN bit setting.
gcc/cp/
* lex.cc (cxx_init): Remove warn_on lambda.  Use cpp_warn instead of
cpp_lookup and NODE_WARN bit setting or warn_on.
gcc/testsuite/
* g++.dg/DRs/dr2581-1.C: New test.
* g++.dg/DRs/dr2581-2.C: New test.
* c-c++-common/cpp/pr92296-2.c: Expect warnings also on defining
special macros after undefining them.
libcpp/
* include/cpplib.h (struct cpp_options): Add
suppress_builtin_macro_warnings member.
(cpp_warn): New inline functions.
* init.cc (cpp_create_reader): Clear suppress_builtin_macro_warnings.
(cpp_init_builtins): Call cpp_warn on __cplusplus, __STDC__,
__STDC_VERSION__, __STDC_MB_MIGHT_NEQ_WC__ and
__STDCPP_STRICT_POINTER_SAFETY__ when appropriate.
* directives.cc (do_undef): Warn on undefining NODE_WARN macros if
not cpp_keyword_p.  Don't emit any NODE_WARN related diagnostics
if CPP_OPTION (pfile, suppress_builtin_macro_warnings).
(cpp_define, _cpp_define_builtin, cpp_undef): Temporarily set
CPP_OPTION (pfile, suppress_builtin_macro_warnings) around
run_directive calls.
* macro.cc (_cpp_create_definition): Warn on defining NODE_WARN
macros if they weren't previously defined and not cpp_keyword_p.
Ignore NODE_WARN for diagnostics if
CPP_OPTION (pfile, suppress_builtin_macro_warnings).

2 days agocobol: Eliminate a run-time structure type that is no longer used.
Robert Dubner [Thu, 14 Aug 2025 13:49:46 +0000 (09:49 -0400)] 
cobol: Eliminate a run-time structure type that is no longer used.

gcc/cobol/ChangeLog:

* genapi.h (parser_call_exception_end): Remove obsolete comment.
* structs.cc (create_cbl_enabled_exception_t):
Remove cbl_enabled_exception_type_node;
remove create_cbl_enabled_exception_t().
(create_our_type_nodes): Likewise.
* structs.h (GTY): Likewise.

2 days agoreal: Eliminate access to uninitialized memory.
Robert Dubner [Thu, 31 Jul 2025 11:45:26 +0000 (07:45 -0400)] 
real: Eliminate access to uninitialized memory.

When compiling this program with gcobol:

        identification division.
        program-id. prog.
        data division.
        working-storage section.
        01 val pic v9(5) value .001.
        procedure division.
            display val
            goback.

the rounding up of .99999...9999 to 1.000...0000 causes a read of the
first byte of the output buffer.  Although harmless, it generates a
valgrind warning.  The following change clears that warning.

gcc/ChangeLog:

* real.cc (real_to_decimal_for_mode): Set str[0] to known value.

2 days agoRISC-V: fix __builtin_round clobbering FP exceptions flags [PR121534]
Vineet Gupta [Thu, 14 Aug 2025 03:20:34 +0000 (20:20 -0700)] 
RISC-V: fix __builtin_round clobbering FP exceptions flags [PR121534]

__builtin_round() fails to save/restore FP exception flags around the FP
compare insn which can potentially clobber the same.

Worth noting that the fflags restore bracketing is slightly different
than the glibc implementation. Both FLT and FCVT can potentially clobber
fflags. gcc generates below where even if branch is not taken and FCVT
is not executed, FLT still executed. Thus FSFLAGS is placed AFTER the
label 'L3'. glibc implementation FLT can't clobber due to early NaN check,
so FSFLAGS can be moved under the branch, before the label.

| convert_float_to_float_round
| ...
|   frflags a5
|   fabs.s fa5,fa0
|   flt.s a4,fa5,fa4    <--- can clobber fflags
|   beq a4,zero,.L3
|     fcvt.w.s a4,fa0,rmm     <--- also
|     fcvt.s.w fa5,a4
|     fsgnj.s fa0,fa5,fa0
| .L3:
|    fsflags a5            <-- both code paths

Fixes: f652a35877e3 ("This is almost exclusively Jivan's work....")
PR target/121534

gcc/ChangeLog:

* config/riscv/riscv.md (round_pattern): save/restore fflags.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vls/math-nearbyint-1.c: Adjust
scan pattern for additional instances of frflags/fsrflags.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
2 days agofixincludes: skip stdio_va_list on modern darwin
Francois-Xavier Coudert [Fri, 15 Aug 2025 15:31:07 +0000 (17:31 +0200)] 
fixincludes: skip stdio_va_list on modern darwin

Complement to the previous commit in fixincludes
(b1f9ab40cbcc6ecd53a2be3e01052cee096e1a00), for the MacOSX12.3 SDK, it
is necessary to also bypass the stdio_va_list fix. The same bypass is
used, namely, the inclusion of <_stdio.h>.

fixincludes/ChangeLog:

* fixincl.x: Regenerate.
* inclhack.def (stdio_va_list): Skip on recent darwin.

2 days agoGenerate a call to a .ACCESS_WITH_SIZE for a FAM with counted_by attribute only when...
Qing Zhao [Thu, 14 Aug 2025 20:27:20 +0000 (20:27 +0000)] 
Generate a call to a .ACCESS_WITH_SIZE for a FAM with counted_by attribute only when it's read from.

Currently, we generate a call to a .ACCESS_WITH_SIZE for a FAM with counted_by
attribute for every component_ref that corresponds to such an object.
Actually, such .ACCESS_WITH_SIZE calls are useless when they are generated
for a written site or an address taken site.

In this patch, we only generate a call to .ACCESS_WITH_SIZE for a FAM with
counted_by attribute when it's a read.

gcc/c/ChangeLog:

* c-tree.h (handle_counted_by_for_component_ref): New prototype of
build_component_ref and handle_counted_by_for_component_ref.
* c-parser.cc (c_parser_postfix_expression): Call the new prototypes
of build_component_ref and handle_counted_by_for_component_ref,
update comments.
* c-typeck.cc (default_function_array_read_conversion): Likewise.
(convert_lvalue_to_rvalue): Likewise.
(default_conversion): Likewise.
(handle_counted_by_p): Update comments.
(handle_counted_by_for_component_ref): Delete one argument.
(build_component_ref): Delete one argument. Delete the call to
handle_counted_by_for_component_ref completely.
(build_array_ref): Generate call to .ACCESS_WITH_SIZE for array.

gcc/testsuite/ChangeLog:

* gcc.dg/flex-array-counted-by-2.c: Adjust testing case.

2 days agoUse the counted_by attribute of pointers in array bound checker.
Qing Zhao [Thu, 14 Aug 2025 20:25:55 +0000 (20:25 +0000)] 
Use the counted_by attribute of pointers in array bound checker.

Current array bound checker only instruments ARRAY_REF, and the INDEX
information is the 2nd operand of the ARRAY_REF.

When extending the array bound checker to pointer references with
counted_by attributes, the hardest part is to get the INDEX of the
corresponding array ref from the offset computation expression of
the pointer ref.  I.e.

Given an OFFSET expression, and the ELEMENT_SIZE,
get the index expression from the OFFSET.
For example:
  OFFSET:
   ((long unsigned int) m * (long unsigned int) SAVE_EXPR <n>) * 4
  ELEMENT_SIZE:
   (sizetype) SAVE_EXPR <n> * 4
get the index as (long unsigned int) m.

gcc/c-family/ChangeLog:

* c-gimplify.cc (is_address_with_access_with_size): New function.
(ubsan_walk_array_refs_r): Instrument an INDIRECT_REF whose base
address is .ACCESS_WITH_SIZE or an address computation whose base
address is .ACCESS_WITH_SIZE.
* c-ubsan.cc (ubsan_instrument_bounds_pointer_address): New function.
(struct factor_t): New structure.
(get_factors_from_mul_expr): New function.
(get_index_from_offset): New function.
(get_index_from_pointer_addr_expr): New function.
(is_instrumentable_pointer_array_address): New function.
(ubsan_array_ref_instrumented_p): Change prototype.
Handle MEM_REF in addtional to ARRAY_REF.
(ubsan_maybe_instrument_array_ref): Handle MEM_REF in addtional
to ARRAY_REF.

gcc/testsuite/ChangeLog:

* gcc.dg/ubsan/pointer-counted-by-bounds-2.c: New test.
* gcc.dg/ubsan/pointer-counted-by-bounds-3.c: New test.
* gcc.dg/ubsan/pointer-counted-by-bounds-4.c: New test.
* gcc.dg/ubsan/pointer-counted-by-bounds-5.c: New test.
* gcc.dg/ubsan/pointer-counted-by-bounds.c: New test.

2 days agoUse the counted_by attribute of pointers in builtinin-object-size. No need to change...
Qing Zhao [Thu, 14 Aug 2025 20:24:18 +0000 (20:24 +0000)] 
Use the counted_by attribute of pointers in builtinin-object-size. No need to change anything in middle-end. Add the testing case for PR120929.

gcc/testsuite/ChangeLog:

* gcc.dg/pointer-counted-by-4-char.c: New test.
* gcc.dg/pointer-counted-by-4-float.c: New test.
* gcc.dg/pointer-counted-by-4-struct.c: New test.
* gcc.dg/pointer-counted-by-4-union.c: New test.
* gcc.dg/pointer-counted-by-4.c: New test.
* gcc.dg/pointer-counted-by-5.c: New test.
* gcc.dg/pointer-counted-by-6.c: New test.
* gcc.dg/pointer-counted-by-7.c: New test.
* gcc.dg/pr120929.c: New test.

2 days agoExtend "counted_by" attribute to pointer fields of structures. Convert a pointer...
Qing Zhao [Thu, 14 Aug 2025 20:22:20 +0000 (20:22 +0000)] 
Extend "counted_by" attribute to pointer fields of structures. Convert a pointer reference with counted_by attribute to .ACCESS_WITH_SIZE. Fix PR120929.

For example:

struct PP {
  size_t count2;
  char other1;
  char *array2 __attribute__ ((counted_by (count2)));
  int other2;
} *pp;

specifies that the "array2" is an array that is pointed by the
pointer field, and its number of elements is given by the field
"count2" in the same structure.

In order to fix PR120929, we agreed on the following solution:

for a pointer field with counted_by attribute:

struct S {
  int n;
  int *p __attribute__((counted_by(n)));
} *f;

when generating call to .ACCESS_WITH_SIZE for f->p, instead of generating
 *.ACCESS_WITH_SIZE (&f->p, &f->n,...)

We should generate
 .ACCESS_WITH_SIZE (f->p, &f->n,...)

i.e.,
the return type and the type of the first argument of the call is the
   original pointer type in this version.

However, this code generation might bring undefined behavior into the
applicaiton if the call to .ACCESS_WITH_SIZE is generated for a pointer
field reference when this refernece is written to.

For example:

f->p = malloc (size);

***** the IL for the above is:

  tmp1 = f->p;
  tmp2 = &f->n;
  tmp3 = .ACCESS_WITH_SIZE (tmp1, tmp2, ...);
  tmp4 = malloc (size);
  tmp3 = tmp4;

In the above, in order to generate a call to .ACCESS_WITH_SIZE for the pointer
reference f->p,  the new GIMPLE tmp1 = f->p is necessary to pass the value of
the pointer f->p to the call to .ACCESS_WITH_SIZE. However, this new GIMPLE is
the one that brings UB into the application since the value of f->p is not
initialized yet when it is assigned to "tmp1".

the above IL will be expanded to the following when .ACCESS_WITH_SIZE is
expanded to its first argument:

  tmp1 = f->p;
  tmp2 = &f->n;
  tmp3 = tmp1;
  tmp4 = malloc (size);
  tmp3 = tmp4;

the final optimized IL will be:

  tmp3 = f->p;
  tmp3 = malloc (size);;

As a result, the f->p will NOT be set correctly to the pointer
returned by malloc (size).

Due to this potential issue, We will need to selectively generate the call to
.ACCESS_WITH_SIZE for f->p according to whether it's a read or a write.

We will only generate call to .ACCESS_WITH_SIZE for f->p when it's a read in
C FE.

gcc/c-family/ChangeLog:

* c-attribs.cc (handle_counted_by_attribute): Accept counted_by
attribute for pointer fields.

gcc/c/ChangeLog:

* c-decl.cc (verify_counted_by_attribute): Change the 2nd argument
to a vector of fields with counted_by attribute. Verify all fields
in this vector.
(finish_struct): Collect all the fields with counted_by attribute
to a vector and pass this vector to verify_counted_by_attribute.
* c-tree.h (handle_counted_by_for_component_ref): New prototype of
handle_counted_by_form_component_ref.
* c-parser.cc (c_parser_postfix_expression): Call the new prototype
of handle_counted_by_for_component_ref.
* c-typeck.cc (default_function_array_read_conversion): Only generate
call to .ACCESS_WITH_SIZE for a pointer field when it's a read.
(convert_lvalue_to_rvalue): Likewise.
(default_conversion): Likewise.
(handle_counted_by_p): New routine.
(check_counted_by_attribute): New routine.
(build_counted_by_ref): Handle pointers with counted_by.
(build_access_with_size_for_counted_by): Handle pointers with counted_by.
(handle_counted_by_for_component_ref): Add one more argument.
(build_component_ref): Call the new prototype of
handle_counted_by_for_component_ref.

gcc/ChangeLog:

* doc/extend.texi: Extend counted_by attribute to pointer fields in
structures. Add one more requirement to pointers with counted_by
attribute.

gcc/testsuite/ChangeLog:

* gcc.dg/flex-array-counted-by.c: Update test.
* gcc.dg/pointer-counted-by-1.c: New test.
* gcc.dg/pointer-counted-by-2.c: New test.
* gcc.dg/pointer-counted-by-3.c: New test.
* gcc.dg/pointer-counted-by-8.c: New test.
* gcc.dg/pointer-counted-by-9.c: New test.
* gcc.dg/pointer-counted-by.c: New test.

2 days agoRISC-V: MIPS prefetch extensions for MIPS RV64 P8700 and can be enabled with xmipscbop.
Umesh Kalappa [Fri, 15 Aug 2025 13:35:40 +0000 (07:35 -0600)] 
RISC-V: MIPS prefetch extensions for MIPS RV64 P8700 and can be enabled with xmipscbop.

Addressed the comments and tested "runtest --tool gcc --target_board='riscv-sim/-march=rv64gc_zba_zbb_zbc_zbs/-mabi=lp64/-mcmodel=medlow' riscv.exp" and 32 bit too

lint warnings can be ignored for riscv-ext.opt.

gcc/ChangeLog:

* config/riscv/riscv-ext-mips.def (DEFINE_RISCV_EXT):
Added mips prefetch extension.
* config/riscv/riscv-ext.opt: Generated file.
* config/riscv/riscv.md (prefetch):
Added mips prefetch address operand constraint.
* config/riscv/constraints.md: Added mips specific constraint.
* config/riscv/predicates.md (prefetch_operand):
Updated for mips nine bits offset.
* config/riscv/riscv.cc (riscv_prefetch_offset_address_p):
Legitimate address with offset for prefetch check.
* config/riscv/riscv-protos.h: Likewise.
* config/riscv/riscv.h:
Macros to support for mips cached type.
* doc/riscv-ext.texi: Updated for mips prefetch.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/mipsprefetch.c: Test file for mips.pref.

2 days agotestsuite: Add a test for [PR119156]
Richard Sandiford [Fri, 15 Aug 2025 13:22:23 +0000 (14:22 +0100)] 
testsuite: Add a test for [PR119156]

PR119156 was fixed by g:f702b593e7268ab161053bafd097f1b09933b783.
This patch adds a test for it.

gcc/testsuite/
PR target/119156
* gcc.target/aarch64/sve/pr119156_1.c: New test.

2 days agoRISC-V: Allow errors to be suppressed when parsing architectures
Richard Sandiford [Fri, 15 Aug 2025 13:15:35 +0000 (14:15 +0100)] 
RISC-V: Allow errors to be suppressed when parsing architectures

One of Alfie's FMV patches adds a hook that, in some cases,
is used to silently query a target_version (with no diagnostics
expected).  In the review, I'd suggested handling this using
a location_t *, with null meaning "suppress diagnostics":

   https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692113.html

This patch tries to propagate that through the RISC-V parsing code.
I realise this isn't very elegant, sorry.

I think riscv_compare_version_priority should also logically suppress
diagnostics, since it's supposed to be a pure query function.  (From
that point of view, advocating for this change for Alfie's patch might
have been a bit unfair.)

gcc/
* config/riscv/riscv-protos.h
(riscv_process_target_version_attr): Change location_t argument
to location_t *.
* config/riscv/riscv-subset.h
(riscv_subset_list::riscv_subset_list): Change location_t argument
to location_t *.
(riscv_subset_list::parse): Likwise.
(riscv_subset_list::set_loc): Likewise.
(riscv_minimal_hwprobe_feature_bits): Likewise.
(riscv_subset_list::m_loc): Change type to location_t.
* common/config/riscv/riscv-common.cc
(riscv_subset_list::riscv_subset_list): Change location_t argument
to location_t *.
(riscv_subset_list::add): Suppress diagnostics when m_loc is null.
(riscv_subset_list::parsing_subset_version): Likewise.
(riscv_subset_list::parse_profiles): Likewise.
(riscv_subset_list::parse_base_ext): Likewise.
(riscv_subset_list::parse_single_std_ext): Likewise.
(riscv_subset_list::check_conflict_ext): Likewise.
(riscv_subset_list::parse_single_multiletter_ext): Likewise.
(riscv_subset_list::parse): Change location_t argument to location_t *.
(riscv_subset_list::set_loc): Likewise.
(riscv_minimal_hwprobe_feature_bits): Likewise.
(riscv_parse_arch_string): Update call accordingly.
* config/riscv/riscv-target-attr.cc
(riscv_target_attr_parser::m_loc): Change type to location_t *.
(riscv_target_attr_parser::riscv_target_attr_parser): Change
location_t argument to location_t *.
(riscv_process_one_target_attr): Likewise.
(riscv_process_target_attr): Likewise.
(riscv_process_target_version_attr): Likewise.
(riscv_target_attr_parser::parse_arch): Suppress diagnostics when
m_loc is null.
(riscv_target_attr_parser::handle_arch): Likewise.
(riscv_target_attr_parser::handle_cpu): Likewise.
(riscv_target_attr_parser::handle_tune): Likewise.
(riscv_target_attr_parser::handle_priority): Likewise.
(riscv_option_valid_attribute_p): Update call accordingly.
(riscv_option_valid_version_attribute_p): Likewise.
* config/riscv/riscv.cc (parse_features_for_version): Add a
location_t * argument.
(dispatch_function_versions): Update call accordingly.
(riscv_compare_version_priority): Likewise, suppressing diagnostics.

2 days agofixincludes: skip stdio_stdarg_h on modern darwin
Francois-Xavier Coudert [Fri, 13 Jun 2025 15:24:10 +0000 (17:24 +0200)] 
fixincludes: skip stdio_stdarg_h on modern darwin

All macOS SDK since at least macOS 10.9, and until macOS 10.12
(included), feature these lines in <stdio.h>:

/* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:
 * __gnuc_va_list and include <stdarg.h> */

The clear intent (and effect) was to bypass gcc’s stdio_stdarg_h
fixinclude.

However, since macOS 10.13, these lines have been moved to <_stdio.h>,
which is itself included at the top of <stdio.h>. The unintended
consequence is that the stdio_stdarg_h fixinclude is now applied to
macOS <stdio.h>, where it is not needed. This useless fixinclude makes
the compiler more fragile and less portable.

A previous attempt to skip the stdio_stdarg_h fix entirely had to be
reverted, since it broken some very old macOS versions. The new fix is
to bypass the fix based on the detection of <_stdio.h> inclusion, which
is more robust.

fixincludes/ChangeLog:

* fixincl.x: Regenerate.
* inclhack.def (stdio_stdarg_h): Skip on darwin.

2 days agoUse gimple_call_fntype rather than gimple_call_fndecl in pass_return_slot::execute
Kito Cheng [Thu, 14 Aug 2025 09:30:17 +0000 (17:30 +0800)] 
Use gimple_call_fntype rather than gimple_call_fndecl in pass_return_slot::execute

Call with funciton pointer might not able to get the fndecl, but fntype
so use gimple_call_fntype instead of gimple_call_fndecl.

aggregate_value_p can handle fndecl and fntype right (and even CALL_EXPR), so I
think this change is safe.

gcc/ChangeLog:

* tree-nrv.cc (pass_return_slot::execute): Use
gimple_call_fntype instead of gimple_call_fndecl.

3 days agoLoongArch: Fix ICE caused by function add_stmt_cost[PR121542].
Lulu Cheng [Thu, 14 Aug 2025 03:59:53 +0000 (11:59 +0800)] 
LoongArch: Fix ICE caused by function add_stmt_cost[PR121542].

PR target/121542

gcc/ChangeLog:

* config/loongarch/loongarch.cc
(loongarch_vector_costs::add_stmt_cost): When using vectype,
first determine whether it is NULL.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/pr121542.c: New test.

3 days agoDaily bump.
GCC Administrator [Fri, 15 Aug 2025 00:17:03 +0000 (00:17 +0000)] 
Daily bump.

3 days agoc++: Fix up build_cplus_array_type [PR121524]
Jakub Jelinek [Thu, 14 Aug 2025 20:30:45 +0000 (22:30 +0200)] 
c++: Fix up build_cplus_array_type [PR121524]

The following testcase is miscompiled since my r15-3046 change
to properly apply std attributes after closing ] for arrays to the
array type.
Array type is not a class type, so when cplus_decl_attribute is
called on the ARRAY_TYPE, it doesn't do ATTR_FLAG_TYPE_IN_PLACE.
Though, for alignas/gnu::aligned/deprecated/gnu::unavailable/gnu::unused
attributes the handlers of those attributes for non-ATTR_FLAG_TYPE_IN_PLACE
on types call build_variant_type_copy and modify some flags on the new
variant type.  They also usually don't clear *no_add_attrs, so the caller
then checks if the attributes are present on the new type and if not, calls
build_type_attribute_variant.
On the following testcase, it results in the B::foo type to be properly
32 byte aligned.
The problem happens later when we build_cplus_array_type for C::a.
elt_type is T (typedef, or using works likewise), we get as m
main variant type with unsigned int element type but because elt_type
is different, build_cplus_array_type searches the TYPE_NEXT_VARIANT chain
to find if there isn't already a useful ARRAY_TYPE to reuse.
It checks for NULL TYPE_NAME, NULL TYPE_ATTRIBUTES and the right TREE_TYPE.
Unfortunately this is not good enough, build_variant_type_copy above created
a variant type on which it modified TYPE_USER_ALIGN and TYPE_ALIGN, but
TYPE_ATTRIBUTES is still NULL, only the build_type_attribute_variant call
later adds attributes.
The problem is that the intermediate type is found in the TYPE_NEXT_VARIANT
chain and reused.

The following patch adds conditions to prevent problems with the affected
attributes (except gnu::unused, I think whether TREE_USED is set or not
shouldn't prevent sharing).  In particular, if TYPE_USER_ALIGN is not
set on the variant, it wasn't user realigned, if it is set, it verifies
it has it set because the elt_type has been user aligned and TYPE_ALIGN
is the expected one.  For deprecated it punts on the flag being set and
for gnu::unavailable as well.

2025-08-14  Jakub Jelinek  <jakub@redhat.com>

PR c++/121524
* tree.cc (build_cplus_array_type): Don't reuse variant type
if it has TREE_DEPRECATED or TREE_UNAVAILABLE flags set or,
unless elt_type has TYPE_USER_ALIGN set and TYPE_ALIGN is
TYPE_ALIGN of elt_type, TYPE_USER_ALIGN is not set.

* g++.dg/cpp0x/gen-attrs-89.C: New test.

3 days ago[PR target/119275][RISC-V] Avoid calling gen_lowpart in cases where it would ICE
Jeff Law [Thu, 14 Aug 2025 20:15:40 +0000 (14:15 -0600)] 
[PR target/119275][RISC-V] Avoid calling gen_lowpart in cases where it would ICE

So this is a minor bug in the riscv move expanders.  It has a special cases for
extraction from vector objects which makes assumptions that it can use
gen_lowpart unconditionally.  That's not always the case.

We can just bypass that special code for cases where we can't use gen_lowpart
and let the more generic code run. If gen_lowpart_common indicates we've got a
case that can't be handled we just bypass the special extraction code.

Tested on riscv64-elf and riscv32-elf.  Waiting for pre-commit CI to do its
thing.

PR target/119275
gcc/
* config/riscv/riscv.cc (riscv_legitimize_move): Avoid calling
gen_lowpart for cases where it'll fail.  Just use standard expander
paths for those cases.

gcc/testsuite/
* gcc.target/riscv/pr119275.c: New test.

3 days agofix cris-elf build with binutils-2.45
Mikael Pettersson [Thu, 31 Jul 2025 15:00:40 +0000 (17:00 +0200)] 
fix cris-elf build with binutils-2.45

Since the cris port was added to gcc it has passed --em=criself
to gas, as an abbreviation for --emulation=criself.  Starting with
binutils-2.45 that causes a hard error in gas due to ambiguity with
another option.

Fixed by replacing the abbreviation with the complete option.

Tested by building a cross to cris-elf with binutils-2.45, which
failed before but now succeeds.

gcc/
PR target/121336
* config/cris/cris.h: Do not abbreviate --emulation.

Signed-off-by: Mikael Pettersson <mikpelinux@gmail.com>
3 days agopowerpc: Add missing modes to P9 if_then_elses [PR121501]
Richard Sandiford [Thu, 14 Aug 2025 12:36:40 +0000 (13:36 +0100)] 
powerpc: Add missing modes to P9 if_then_elses [PR121501]

These patterns had one (if_then_else ...) nested within another.
The outer if_then_else had SImode, which means that the "then"
and "else" should also be SImode (unless they're const_ints).
However, the inner if_then_else was modeless, which led to an
assertion failure when trying to take a subreg of it.

gcc/
PR target/121501
* config/rs6000/rs6000.md (cmprb, setb_signed, setb_unsigned)
(cmprb2, cmpeqb): Add missing modes to nested if_then_elses.

3 days agoMAINTAINERS: Add myself to write after approval
Avinash Jayakar [Thu, 14 Aug 2025 10:58:40 +0000 (16:28 +0530)] 
MAINTAINERS: Add myself to write after approval

2025-08-12  Avinash Jayakar  <avinashd@linux.ibm.com>

* MAINTAINERS: Add myself to write after approval.

3 days agoforwprop: Limit alias walk in some cases [PR121474]
Andrew Pinski [Wed, 13 Aug 2025 06:31:15 +0000 (23:31 -0700)] 
forwprop: Limit alias walk in some cases [PR121474]

https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692091.html
pointed out:
'''
Oh, as we now do alias walks in forwprop maybe we should make this
conditional and do
this not for all pass instances, since it makes forwprop possibly a lot slower?
'''

This does patch limits the walk in a few different ways.
First only allow for a full walk in the first 2 forwprop (the one before inlining
and the one after inlining).  The other 2 forwprop are less likely to find any extra
zero prop so limit them so there is no walk.

There is an exception to the rule though, allowing to skip over clobbers still since those
will not take a long time for the walk and from when looking at benchmarks the only place
where forwprop3/4 would cause a zero prop.

The other thing is limit a full walk only if flag_expensive_optimizations is true.
This limits the walk for -O1 since flag_expensive_optimizations is turned on at -O2+.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/121474
gcc/ChangeLog:

* passes.def: Update forwprop1/2 to have full_walk to be true.
* tree-ssa-forwprop.cc (optimize_aggr_zeroprop): Add new argument
full_walk. Take into account the full_walk and clobbers at the end
of the limit can be done always.
(simplify_builtin_call): Add new argument, full_walk.
Update call to optimize_aggr_zeroprop.
(pass_forwprop): Add m_full_walk field.
(pass_forwprop::set_pass_param): Update for m_full_walk.
(pass_forwprop::execute): Update call to simplify_builtin_call
and optimize_aggr_zeroprop.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
3 days agoforwprop: Copy prop aggregates into args
Andrew Pinski [Tue, 10 Jun 2025 07:11:58 +0000 (00:11 -0700)] 
forwprop: Copy prop aggregates into args

This implements the simple copy prop of aggregates into
arguments of function calls. This can reduce the number of copies
done. Just like removing of an extra copy in general, this can and
will help out SRA; since we might not need to do a full scalarization
of the aggregate now.

This is the simpliest form of this copy prop of aggregates into function arguments.

Changes since v1:
* v2: Merge in the changes of r16-3160-g2fe432175ef135.
      Move the checks for assignment and call statement into optimize_agr_copyprop
      rather than having it in optimize_agr_copyprop_1 and optimize_agr_copyprop_arg.

gcc/ChangeLog:

* tree-ssa-forwprop.cc (optimize_agr_copyprop_1): New function split out of ...
(optimize_agr_copyprop): Here. Also try calling optimize_agr_copyprop_arg.
(optimize_agr_copyprop_arg): New function.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/copy-prop-aggregate-arg-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 days agos390: Fix zero extend patterns using vlgv
Stefan Schulze Frielinghaus [Thu, 14 Aug 2025 06:18:27 +0000 (08:18 +0200)] 
s390: Fix zero extend patterns using vlgv

In commit r16-2316-gc6676092318 mistakenly patterns were introduced
which actually should have been merged as alternatives to existing zero
extend patterns.

While on it, generalize the vec_extract patterns and also allow
registers for the index.  A subsequent patch will add
register+immediate support.

gcc/ChangeLog:

* config/s390/s390.md: Merge movdi<mode>_zero_extend_A and
movsi<mode>_zero_extend_A into zero_extendsidi2 and
zero_extendhi<mode>2_z10 and
zero_extend<HQI:mode><GPR:mode>2_extimm.
* config/s390/vector.md (*movdi<mode>_zero_extend_A): Remove.
(*movsi<mode>_zero_extend_A): Remove.
(*movdi<mode>_zero_extend_B): Move to vec_extract patterns and
rename to *vec_extract<mode>_zero_extend.
(*movsi<mode>_zero_extend_B): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/s390/vector/vlgv-zero-extend-1.c: Require target
s390_mvx.
* gcc.target/s390/vector/vlgv-zero-extend-2.c: New test.

3 days agotestsuite: Fix asm-hard-reg-error-3.c for arm [PR121511]
Stefan Schulze Frielinghaus [Thu, 14 Aug 2025 06:07:15 +0000 (08:07 +0200)] 
testsuite: Fix asm-hard-reg-error-3.c for arm [PR121511]

This test is about register pairs.  On arm a long long is accepted in
thumb mode in any register 0-6 whereas in arm mode this is restricted to
even register pairs.  Thus, in order to trigger the error even if gcc is
configured with --with-mode=thumb, add option -marm.

gcc/testsuite/ChangeLog:

PR target/121511
* gcc.dg/asm-hard-reg-error-3.c: Add additional option -marm for
target arm.

3 days agox86: Disallow MMX and 80387 in no_caller_saved_registers function
H.J. Lu [Wed, 13 Aug 2025 21:18:26 +0000 (14:18 -0700)] 
x86: Disallow MMX and 80387 in no_caller_saved_registers function

commit 9804b23198b39f85a7258be556c5e8aed44b9efc
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Apr 13 11:38:24 2025 -0700

    x86: Add preserve_none and update no_caller_saved_registers attributes

allowed MMX/80387 instructions in functions with no_caller_saved_registers
attribute by accident.  Update ix86_set_current_function to properly
check if MMX and 80387 are enabled.

gcc/

PR target/121540
* config/i386/i386-options.cc (ix86_set_current_function):
Properly check if MMX and 80387 are enabled.

gcc/testsuite/

PR target/121540
* gcc.target/i386/no-callee-saved-19a.c (dg-options): Add
"-mno-avx -mno-mmx -mno-80387"
* gcc.target/i386/no-callee-saved-19b.c: Likewise.
* gcc.target/i386/no-callee-saved-19c.c: Likewise.
* gcc.target/i386/no-callee-saved-19d.c: Likewise.
* gcc.target/i386/no-callee-saved-19e.c: Likewise.
* gcc.target/i386/pr121208-1a.c: Likewise.
* gcc.target/i386/pr121208-1b.c: Likewise.
* gcc.target/i386/pr121540-1.c: New test.
* gcc.target/i386/pr121540-2.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 days agoDaily bump.
GCC Administrator [Thu, 14 Aug 2025 00:20:55 +0000 (00:20 +0000)] 
Daily bump.

4 days ago[RISC-V][PR target/121531] Cover missing insn types in p400 and p600 scheduler models
Jeff Law [Wed, 13 Aug 2025 23:16:41 +0000 (17:16 -0600)] 
[RISC-V][PR target/121531] Cover missing insn types in p400 and p600 scheduler models

So the usual problems, DFAs without full coverage.  I took the output of Kito's
checker and use that to construct a dummy reservation for the p400 and p600
sifive models.

Tested on riscv32-elf and riscv64-elf with no regressions.

Pushing to the trunk once pre-commit CI gives the green light.

PR target/121531
gcc/
* config/riscv/sifive-p400.md (sifive_p400_unknown): New reservation.
* config/riscv/sifive-p600.md (sifive_p600_unkonwn): Likewise.

gcc/testsuite/
* gcc.target/riscv/pr121531.c: New test.

4 days agoc++: P2036R3 - Change scope of lambda trailing-return-type [PR102610]
Marek Polacek [Wed, 13 Nov 2024 21:56:40 +0000 (16:56 -0500)] 
c++: P2036R3 - Change scope of lambda trailing-return-type [PR102610]

This patch is an attempt to implement P2036R3 along with P2579R0, fixing
build breakages caused by P2036R3.

The simplest example is:

  auto counter1 = [j=0]() mutable -> decltype(j) {
      return j++;
  };

which currently doesn't compile because the 'j' in the capture isn't
visible in the trailing return type.  With these proposals, the 'j'
will be in a lambda scope which spans the trailing return type, so
this test will compile.

This oughtn't be difficult but decltype and other issues made this patch
much more challenging.

We have to push the explicit captures before going into
_lambda_declarator_opt because that is what parses the trailing return
type.  Yet we can't build any captures until after _lambda_body ->
start_lambda_function which creates the lambda's operator(), without
which we can't build a proxy, but _lambda_body happens only after
parsing the declarator.  This patch works around it by creating a fake
operator() and adding it to the capture and then removing it when we
have the real operator().

Another thing is that in "-> decltype(j)" we don't have the right
current_function_decl yet.  If current_lambda_expr gives us a lambda,
we know this decltype appertains to a lambda.  But we have to know if we
are in a parameter-declaration-clause: as per [expr.prim.id.unqual]/4.4,
if we are, we shouldn't be adding "const".  The new LAMBDA_EXPR_CONST_QUAL_P
flag tracks this.  But it doesn't handle nested lambdas yet, specifically,
[expr.prim.id.unqual]/14.

I don't think this patch changes behavior for the tests in
"capture-default with [=]" as the paper promises; clang++ behaves the
same as gcc with this patch.

PR c++/102610

gcc/cp/ChangeLog:

* cp-tree.h (LAMBDA_EXPR_CONST_QUAL_P): Define.
(maybe_add_dummy_lambda_op): Declare.
(remove_dummy_lambda_op): Declare.
(push_capture_proxies): Adjust.
* lambda.cc (build_capture_proxy): No longer static.  New early_p
parameter.  Use it.
(add_capture): Adjust the call to build_capture_proxy.
(resolvable_dummy_lambda): Check DECL_LAMBDA_FUNCTION_P.
(push_capture_proxies): New.
(start_lambda_function): Use it.
* name-lookup.cc (check_local_shadow): Give an error for
is_capture_proxy.
(cp_binding_level_descriptor): Add lambda-scope.
(begin_scope) <case sk_lambda>: New case.
* name-lookup.h (enum scope_kind): Add sk_lambda.
(struct cp_binding_level): Widen kind.
* parser.cc (cp_parser_lambda_expression): Create a new (lambda) scope
after the lambda-introducer.
(cp_parser_lambda_declarator_opt): Set LAMBDA_EXPR_CONST_QUAL_P.
Create a dummy operator() if needed.  Inject the captures into the
lambda scope.  Remove the dummy operator().
(make_dummy_lambda_op): New.
(maybe_add_dummy_lambda_op): New.
(remove_dummy_lambda_op): New.
* pt.cc (tsubst_lambda_expr): Begin/end a lambda scope.  Push the
capture proxies.  Build/remove a dummy operator() if needed.  Set
LAMBDA_EXPR_CONST_QUAL_P.
* semantics.cc (parsing_lambda_declarator): New.
(outer_var_p): Also consider captures as outer variables if in a lambda
declarator.
(process_outer_var_ref): Reset containing_function when
parsing_lambda_declarator.
(finish_decltype_type): Process decls in the lambda-declarator as well.
Look at LAMBDA_EXPR_CONST_QUAL_P unless we have an xobj function.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-decltype3.C: Remove xfail.
* g++.dg/warn/Wshadow-19.C: Add -Wpedantic.  Adjust a dg-warning.
* g++.dg/warn/Wshadow-6.C: Adjust expected diagnostics.
* g++.dg/cpp23/lambda-scope1.C: New test.
* g++.dg/cpp23/lambda-scope2.C: New test.
* g++.dg/cpp23/lambda-scope3.C: New test.
* g++.dg/cpp23/lambda-scope4.C: New test.
* g++.dg/cpp23/lambda-scope4b.C: New test.
* g++.dg/cpp23/lambda-scope5.C: New test.
* g++.dg/cpp23/lambda-scope6.C: New test.
* g++.dg/cpp23/lambda-scope7.C: New test.
* g++.dg/cpp23/lambda-scope8.C: New test.
* g++.dg/cpp23/lambda-scope9.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
4 days agodiagnostics/output-spec.cc: simplify implementation
David Malcolm [Wed, 13 Aug 2025 21:29:22 +0000 (17:29 -0400)] 
diagnostics/output-spec.cc: simplify implementation

No functional change intended.

gcc/ChangeLog:
* diagnostics/output-spec.cc (sarif_scheme_handler::make_sink):
Populate sarif_generation_options instance directly, rather than
through local variables.
(sarif_scheme_handler::make_sarif_gen_opts): Drop.
(html_scheme_handler::make_sink): Populate html_generation_options
instance directly, rather than through local variables.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
4 days agolibiberty: Fix comment typo
Jakub Jelinek [Wed, 13 Aug 2025 20:26:54 +0000 (22:26 +0200)] 
libiberty: Fix comment typo

This patch fixes a comment typo, whaever -> whatever, prompted by the
recent hae -> has typo fix.

2025-08-13  Jakub Jelinek  <jakub@redhat.com>

* cp-demangle.c (d_encoding): Fix a comment typo, whaever -> whatever.

4 days agoc++: Implement C++26 P1306R5 - Expansion statements [PR120776]
Jakub Jelinek [Wed, 13 Aug 2025 20:07:27 +0000 (22:07 +0200)] 
c++: Implement C++26 P1306R5 - Expansion statements [PR120776]

The following patch implements the C++26 P1306R5 - Expansion statements
paper.
When expansion statements are used outside of templates, the lowering
of the statement uses push_tinst_level_loc and instantiates the body
multiple times, otherwise when the new TEMPLATE_FOR_STMT statement is
being instantiated and !processing_template_decl, it instantiates the
body several times with just local_specialization_stack around each
iteration but with the original args.
Because the lowering of these statements is mostly about instantiation,
I've put the lowering code into pt.cc rather than semantics.cc.
Only destructuring expansion statements currently use in the patch
temporary lifetime extension which matches the proposed resolution of
https://cplusplus.github.io/CWG/issues/3043.html
I'm not sure what will CWG decide about that if there will be some
temporary lifetime extension for enumerating expansion statements and if
yes, under what exact rules (e.g. whether it extends all the temporaries
across one iteration of the body, or only if a reference is initialized
or nothing at all).  And for iterating expansion statements, I think I
don't understand the P2686R4 rules well yet, I think if the
expansion-initializer is used in static constexpr rvalue reference, then
it isn't needed, but not sure if it won't be needed if static would be
dropped (whether
struct S { constexpr S () : s (0) {} constexpr ~S () {} int s; };
struct T { const S &t, &u; };
void foo () { constexpr T t = { S {}, S {} }; use (t.t, t.u); }
is ok under P2686R4; though without constexpr before T I see S::~S () being
called after use, not at the end of the t declaration, so maybe it is
fine also without static).
As per
https://cplusplus.github.io/CWG/issues/3044.html
the patch uses build_int_cst (ptrdiff_type_node, i) to create second
operand of begin + i and doesn't lookup overloaded comma operator (note, I'm
actually not even creating a lambda there, just using TARGET_EXPRs).
I guess my preference would be dropping those 4 static keywords from
[stmt.expand] but the patch does use those for now and it won't be possible
to change that until the rest of P2686R4 is implemented.
As per
https://cplusplus.github.io/CWG/issues/3045.html
it treats sk_template_for like sk_for for the purpose of redeclaration of
vars in the body but doesn't yet reject [[fallthrough]]; in the expansion
stmt body (when not nested in another switch).
I'm not sure if cp_perform_range_for_lookup used in the patch is exactly
what we want for the https://eel.is/c++draft/stmt.expand#3.2
- it does finish_call_expr on the perform_koenig_lookup as well, shouldn't
for the decision whether it is iterating or destructing (i.e. tf_none)
just call perform_koenig_lookup and check if it found some
FUNCTION_DECL/OVERLOAD/TEMPLATE_DECL?
cp_decomp_size in the patch has tsubst_flags_t argument and attempts to be
SFINAE friendly, even when it isn't needed strictly for this patch.
This is with PR96185 __builtin_structured_binding_size implementation in
mind (to follow clang).
The new TEMPLATE_FOR_STMT statement is expected to be lowered to something
that doesn't use the statement at all, I've implemented break/continue
discovery in the body, so all I needed was to punt on TEMPLATE_FOR_STMT
in potential_constant_expression_1 so that we don't try to constant evaluate
it when it is still dependent (and cxx_eval_constant_expression rejects
it without any extra code).
I think only enumerating and iterating expansion statements can have zero
iteration, because for destructuring ones it doesn't use a structured
binding pack and so valid structured binding has to have at least one
iteration.  Though
https://cplusplus.github.io/CWG/issues/3048.html
could change that, this patch currently rejects it though.

2025-08-13  Jakub Jelinek  <jakub@redhat.com>

PR c++/120776
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Predefine
__cpp_expansion_statements=202506L for C++26.
gcc/cp/
* cp-tree.def: Implement C++26 P1306R5 - Expansion statements.
(TEMPLATE_FOR_STMT): New tree code.
* cp-tree.h (struct saved_scope): Add expansion_stmt.
(in_expansion_stmt): Define.
(TEMPLATE_FOR_DECL, TEMPLATE_FOR_EXPR, TEMPLATE_FOR_BODY,
TEMPLATE_FOR_SCOPE, TEMPLATE_FOR_INIT_STMT): Define.
(struct tinst_level): Adjust comment.
(cp_decomp_size, finish_expansion_stmt, do_pushlevel,
cp_build_range_for_decls, build_range_temp,
cp_perform_range_for_lookup, begin_template_for_scope): Declare.
(finish_range_for_stmt): Remove declaration.
* cp-objcp-common.cc (cp_common_init_ts): Handle TEMPLATE_FOR_STMT.
* name-lookup.h (enum scope_kind): Add sk_template_for enumerator.
(struct cp_binding_level): Enlarge kind bitfield from 4 to 5 bits.
Adjust comment with remaining space bits.
* name-lookup.cc (check_local_shadow): Handle sk_template_for like
sk_for.
(cp_binding_level_descriptor): Add entry for sk_template_for.
(begin_scope): Handle sk_template_for.
* parser.h (IN_EXPANSION_STMT): Define.
* parser.cc (cp_debug_parser): Print IN_EXPANSION_STMT bit.
(cp_parser_lambda_expression): Temporarily clear in_expansion_stmt.
(cp_parser_statement): Handle RID_TEMPLATE followed by RID_FOR for
C++11.
(cp_parser_label_for_labeled_statement): Complain about named labels
inside of expansion stmt body.
(cp_hide_range_decl): New function.
(cp_parser_range_for): Use it.  Adjust do_range_for_auto_deduction
caller.  Remove second template argument from auto_vecs bindings and
names.
(build_range_temp): No longer static.
(do_range_for_auto_deduction): Add expansion_stmt argument.
(cp_build_range_for_decls): New function.
(cp_convert_range_for): Use it.  Call cp_perform_range_for_lookup
rather than cp_parser_perform_range_for_lookup.
(cp_parser_perform_range_for_lookup): Rename to ...
(cp_perform_range_for_lookup): ... this.  No longer static.  Add
complain argument and handle it.
(cp_parser_range_for_member_function): Rename to ...
(cp_range_for_member_function): ... this.
(cp_parser_expansion_statement): New function.
(cp_parser_jump_statement): Handle IN_EXPANSION_STMT.
(cp_convert_omp_range_for): Adjust do_range_for_auto_deduction caller.
Call cp_perform_range_for_lookup rather than
cp_parser_perform_range_for_lookup.
* error.cc (print_instantiation_full_context): Handle tldcl being
TEMPLATE_FOR_STMT.
(print_instantiation_partial_context_line): Likewise.
* constexpr.cc (potential_constant_expression_1): Handle
TEMPLATE_FOR_STMT.
* decl.cc (poplevel_named_label_1): Use obl instead of bl->level_chain.
(finish_case_label): Diagnose case labels inside of template for.
(find_decomp_class_base): Add complain argument, don't diagnose
anything and just return error_mark_node if tf_none, adjust recursive
call.
(cp_decomp_size): New function.
(cp_finish_decomp): Adjust find_decomp_class_base caller.
* semantics.cc (do_pushlevel): No longer static.
(begin_template_for_scope): New function.
* pt.cc (push_tinst_level_loc): Handle TEMPLATE_FOR_STMT.
(reopen_tinst_level): Likewise.
(tsubst_stmt): Handle TEMPLATE_FOR_STMT.
(struct expansion_stmt_bc): New type.
(expansion_stmt_find_bc_r, finish_expansion_stmt): New functions.
* decl2.cc (decl_dependent_p): Return true for current function's decl
if in_expansion_stmt.
* call.cc (extend_ref_init_temps): Don't extend_all_temps if
TREE_STATIC (decl).
* cxx-pretty-print.cc (cxx_pretty_printer::statement): Handle
TEMPLATE_FOR_STMT.
gcc/testsuite/
* g++.dg/cpp1z/decomp64.C: New test.
* g++.dg/cpp26/expansion-stmt1.C: New test.
* g++.dg/cpp26/expansion-stmt2.C: New test.
* g++.dg/cpp26/expansion-stmt3.C: New test.
* g++.dg/cpp26/expansion-stmt4.C: New test.
* g++.dg/cpp26/expansion-stmt5.C: New test.
* g++.dg/cpp26/expansion-stmt6.C: New test.
* g++.dg/cpp26/expansion-stmt7.C: New test.
* g++.dg/cpp26/expansion-stmt8.C: New test.
* g++.dg/cpp26/expansion-stmt9.C: New test.
* g++.dg/cpp26/expansion-stmt10.C: New test.
* g++.dg/cpp26/expansion-stmt11.C: New test.
* g++.dg/cpp26/expansion-stmt12.C: New test.
* g++.dg/cpp26/expansion-stmt13.C: New test.
* g++.dg/cpp26/expansion-stmt14.C: New test.
* g++.dg/cpp26/expansion-stmt15.C: New test.
* g++.dg/cpp26/expansion-stmt16.C: New test.
* g++.dg/cpp26/expansion-stmt17.C: New test.
* g++.dg/cpp26/expansion-stmt18.C: New test.
* g++.dg/cpp26/expansion-stmt19.C: New test.
* g++.dg/cpp26/feat-cxx26.C: Add __cpp_expansion_statements
tests.

4 days agoMark epiphany and rl78 as obsolete targets
Andrew Pinski [Wed, 13 Aug 2025 17:48:15 +0000 (17:48 +0000)] 
Mark epiphany and rl78 as obsolete targets

rl78 still uses reload rather than LRA.
epiphany still uses reload and causes ICEs during reload.

Both don't have a maintainer. epiphany has been without one since
2024 (2023 email) while rl78 has been without one since 2018.

gcc/ChangeLog:

* config.gcc: Mark epiphany*-*-* and rl78*-*-* as
obsolete targets.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
4 days agox86-64: Remove redundant TLS calls
H.J. Lu [Fri, 19 Aug 2022 18:50:41 +0000 (11:50 -0700)] 
x86-64: Remove redundant TLS calls

For TLS calls:

1. UNSPEC_TLS_GD:

  (parallel [
    (set (reg:DI 0 ax)
     (call:DI (mem:QI (symbol_ref:DI ("__tls_get_addr")))
  (const_int 0 [0])))
    (unspec:DI [(symbol_ref:DI ("e") [flags 0x50])
                (reg/f:DI 7 sp)] UNSPEC_TLS_GD)
    (clobber (reg:DI 5 di))])

2. UNSPEC_TLS_LD_BASE:

  (parallel [
    (set (reg:DI 0 ax)
 (call:DI (mem:QI (symbol_ref:DI ("__tls_get_addr")))
  (const_int 0 [0])))
    (unspec:DI [(reg/f:DI 7 sp)] UNSPEC_TLS_LD_BASE)])

3. UNSPEC_TLSDESC:

  (parallel [
     (set (reg/f:DI 104)
   (plus:DI (unspec:DI [
       (symbol_ref:DI ("_TLS_MODULE_BASE_") [flags 0x10])
                       (reg:DI 114)
                       (reg/f:DI 7 sp)] UNSPEC_TLSDESC)
                    (const:DI (unspec:DI [
 (symbol_ref:DI ("e") [flags 0x1a])
      ] UNSPEC_DTPOFF))))
     (clobber (reg:CC 17 flags))])

  (parallel [
    (set (reg:DI 101)
 (unspec:DI [(symbol_ref:DI ("e") [flags 0x50])
                     (reg:DI 112)
                     (reg/f:DI 7 sp)] UNSPEC_TLSDESC))
    (clobber (reg:CC 17 flags))])

they return the same value for the same input value.  But multiple calls
with the same input value may be generated for simple programs like:

void a(long *);
int b(void);
void c(void);
static __thread long e;
long
d(void)
{
  a(&e);
  if (b())
    c();
  return e;
}

When compiled with -O2 -fPIC -mtls-dialect=gnu2, the following codes are
generated:

.type d, @function
d:
.LFB0:
.cfi_startproc
pushq %rbx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
leaq e@TLSDESC(%rip), %rbx
movq %rbx, %rax
call *e@TLSCALL(%rax)
addq %fs:0, %rax
movq %rax, %rdi
call a@PLT
call b@PLT
testl %eax, %eax
jne .L8
movq %rbx, %rax
call *e@TLSCALL(%rax)
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 8
movq %fs:(%rax), %rax
ret
.p2align 4,,10
.p2align 3
.L8:
.cfi_restore_state
call c@PLT
movq %rbx, %rax
call *e@TLSCALL(%rax)
popq %rbx
.cfi_def_cfa_offset 8
movq %fs:(%rax), %rax
ret
.cfi_endproc

There are 3 "call *e@TLSCALL(%rax)".  They all return the same value.
Rename the remove_redundant_vector pass to the x86_cse pass, for 64bit,
extend it to also remove redundant TLS calls to generate:

d:
.LFB0:
.cfi_startproc
pushq %rbx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
leaq e@TLSDESC(%rip), %rax
movq %fs:0, %rdi
call *e@TLSCALL(%rax)
addq %rax, %rdi
movq %rax, %rbx
call a@PLT
call b@PLT
testl %eax, %eax
jne .L8
movq %fs:(%rbx), %rax
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L8:
.cfi_restore_state
call c@PLT
movq %fs:(%rbx), %rax
popq %rbx
.cfi_def_cfa_offset 8
ret
.cfi_endproc

with only one "call *e@TLSCALL(%rax)".  This reduces the number of
__tls_get_addr calls in libgcc.a by 72%:

__tls_get_addr calls     before         after
libgcc.a                 868            243

gcc/

PR target/81501
* config/i386/i386-features.cc (x86_cse_kind): Add X86_CSE_TLS_GD,
X86_CSE_TLS_LD_BASE and X86_CSE_TLSDESC.
(redundant_load): Renamed to ...
(redundant_pattern): This.
(ix86_place_single_vector_set): Replace redundant_load with
redundant_pattern.
(replace_tls_call): New.
(ix86_place_single_tls_call): Likewise.
(pass_remove_redundant_vector_load): Renamed to ...
(pass_x86_cse): This.  Add val, def_insn, mode, scalar_mode, kind,
x86_cse, candidate_gnu_tls_p, candidate_gnu2_tls_p and
candidate_vector_p.
(pass_x86_cse::candidate_gnu_tls_p): New.
(pass_x86_cse::candidate_gnu2_tls_p): Likewise.
(pass_x86_cse::candidate_vector_p): Likewise.
(remove_redundant_vector_load): Renamed to ...
(pass_x86_cse::x86_cse): This.  Extend to remove redundant TLS
calls.
(make_pass_remove_redundant_vector_load): Renamed to ...
(make_pass_x86_cse): This.
* config/i386/i386-passes.def: Replace
pass_remove_redundant_vector_load with pass_x86_cse.
* config/i386/i386-protos.h (ix86_tls_get_addr): New.
(make_pass_remove_redundant_vector_load): Renamed to ...
(make_pass_x86_cse): This.
* config/i386/i386.cc (ix86_tls_get_addr): Remove static.
* config/i386/i386.h (machine_function): Add
tls_descriptor_call_multiple_p.
* config/i386/i386.md (tls64): New attribute.
(@tls_global_dynamic_64_<mode>): Set tls_descriptor_call_multiple_p.
(@tls_local_dynamic_base_64_<mode>): Likewise.
(@tls_dynamic_gnu2_64_<mode>): Likewise.
(*tls_global_dynamic_64_<mode>): Set tls64 attribute to gd.
(*tls_local_dynamic_base_64_<mode>): Set tls64 attribute to ld_base.
(*tls_dynamic_gnu2_lea_64_<mode>): Set tls64 attribute to lea.
(*tls_dynamic_gnu2_call_64_<mode>): Set tls64 attribute to call.
(*tls_dynamic_gnu2_combine_64_<mode>): Set tls64 attribute to
combine.

gcc/testsuite/

PR target/81501
* g++.target/i386/pr81501-1.C: New test.
* gcc.target/i386/pr81501-1a.c: Likewise.
* gcc.target/i386/pr81501-1b.c: Likewise.
* gcc.target/i386/pr81501-2a.c: Likewise.
* gcc.target/i386/pr81501-2b.c: Likewise.
* gcc.target/i386/pr81501-3.c: Likewise.
* gcc.target/i386/pr81501-4a.c: Likewise.
* gcc.target/i386/pr81501-4b.c: Likewise.
* gcc.target/i386/pr81501-5.c: Likewise.
* gcc.target/i386/pr81501-6a.c: Likewise.
* gcc.target/i386/pr81501-6b.c: Likewise.
* gcc.target/i386/pr81501-7.c: Likewise.
* gcc.target/i386/pr81501-8a.c: Likewise.
* gcc.target/i386/pr81501-8b.c: Likewise.
* gcc.target/i386/pr81501-9a.c: Likewise.
* gcc.target/i386/pr81501-9b.c: Likewise.
* gcc.target/i386/pr81501-10a.c: Likewise.
* gcc.target/i386/pr81501-10b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
4 days agoDarwin: Handle linker '-no_deduplicate' option.
Iain Sandoe [Fri, 21 Jul 2023 18:32:28 +0000 (19:32 +0100)] 
Darwin: Handle linker '-no_deduplicate' option.

Newer linker support an option to disable deduplication of entities.
This speeds up linking and can improve debug experience.  Adopting the
same criteria as clang in adding the option.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/ChangeLog:

* config.in: Regenerate.
* config/darwin.h (DARWIN_LD_NO_DEDUPLICATE): New.
(LINK_SPEC): Handle -no_deduplicate.
* configure: Regenerate.
* configure.ac: Detect linker support for -no_deduplicate.

4 days agoDarwin: Handle string constants specially when asan is enabled.
Iain Sandoe [Sat, 9 Aug 2025 07:19:08 +0000 (08:19 +0100)] 
Darwin: Handle string constants specially when asan is enabled.

The Darwin ABI uses a different section for string constants when
address sanitizing is enabled.  This adds defintions of the asan-
specific sections and switches string constants to the correct
section.

It also makes the string constant symbols linker-visible when
asan is enabled, but not otherwise.

gcc/ChangeLog:

* config/darwin-sections.def (asan_string_section,
asan_globals_section, asan_liveness_section): New.
* config/darwin.cc (objc_method_decl): Use asan sections
when asan is enabled.
(darwin_encode_section_info): Alter string constant
linker visibility depending on asan.
(machopic_select_section): Use the asan sections when
asan is enabled.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/darwin-cfstring-3.c: Adjust for amended
string labels.
* g++.dg/torture/darwin-cfstring-3.C: Likewise.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 days ago[RISC-V][PR target/121160] Avoid bogus force_reg call
Jeff Law [Wed, 13 Aug 2025 17:17:02 +0000 (11:17 -0600)] 
[RISC-V][PR target/121160] Avoid bogus force_reg call

When we canonicalize the comparison for a czero sequence we need to handle both
integer and fp comparisons.  Furthermore, within the integer space we want to
make sure we promote any sub-word objects to a full word.

All that is working fine.  After promotion we then force the value into a
register if it is not a register or constant already.   The idea is not to have
to special case subregs in subsequent code.  This works fine except when we're
presented with a floating point object that would be a subword.  (subreg:SF
(reg:SI)) on rv64 for example.

So this tightens up that force_reg step.   Bootstapped and regression tested on
riscv64-linux-gnu and tested on  riscv32-elf and riscv64-elf.

Pushing to the trunk after pre-commit verifies no regressions.

Jeff

PR target/121160
gcc/
* config/riscv/riscv.cc (canonicalize_comparands); Tighten check for
forcing value into a GPR.

gcc/testsuite/
* gcc.target/riscv/pr121160.c: New test.

4 days agoforwprop: Move check of limit first [PR121474]
Andrew Pinski [Wed, 13 Aug 2025 16:19:42 +0000 (09:19 -0700)] 
forwprop: Move check of limit first [PR121474]

This is the first step in handling the review part of:
https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692091.html
'''
Oh, as we now do alias walks in forwprop maybe we should make this
conditional and do
this not for all pass instances, since it makes forwprop possibly a lot slower?
'''

The check of the limit was after the alias check which could slow down things.
This moves the check of the limit to begining of the if.

Bootstrapped and tested on x86_64-linux-gnu.

Pushed as obvious.

PR tree-optimization/121474
gcc/ChangeLog:

* tree-ssa-forwprop.cc (optimize_aggr_zeroprop): Move the check
for limit before the alias check.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
4 days agoRegenerate libgcobol/configure
Mark Wielaard [Wed, 13 Aug 2025 15:53:10 +0000 (17:53 +0200)] 
Regenerate libgcobol/configure

Use autoconf 2.69 to regenerate libgcobol/configure

Fixes: 9992c0a0e1b4 ("cobol: Bring EBCDIC NumericDisplay variables into IBM compliance.")
libgcobol/ChangeLog:

* configure: Regenerate.

4 days agocobol: Implement and use faster __gg__packed_to_binary() routine.
Robert Dubner [Wed, 13 Aug 2025 15:17:05 +0000 (11:17 -0400)] 
cobol: Implement and use faster __gg__packed_to_binary() routine.

The new routine uses table lookups more effectively, and avoids __int128
arithmetic until necessary.

gcc/cobol/ChangeLog:

* genutil.cc (get_binary_value): Use the new routine.

libgcobol/ChangeLog:

* libgcobol.cc (get_binary_value_local): Use the new routine.
* stringbin.cc (int_from_string): Removed.
(__gg__packed_to_binary): Implement new routine.
* stringbin.h (__gg__packed_to_binary): Likewise.

4 days agoc++: fix typo in comment
Benjamin Wu [Wed, 13 Aug 2025 14:48:34 +0000 (10:48 -0400)] 
c++: fix typo in comment

gcc/cp/ChangeLog:

* lex.cc (init_operators): Fix typo.

4 days agoIntroduce SLP_TREE_PERMUTE_P
Richard Biener [Wed, 13 Aug 2025 11:53:41 +0000 (13:53 +0200)] 
Introduce SLP_TREE_PERMUTE_P

The following wraps SLP_TREE_CODE checks against VEC_PERM_EXPR
(the only relevant code) in a new SLP_TREE_PERMUTE_P predicate.
Most places guard against SLP_TREE_REPRESENTATIVE being NULL.

* tree-vectorizer.h (SLP_TREE_PERMUTE_P): New.
* tree-vect-slp-patterns.cc (linear_loads_p): Adjust.
(vect_detect_pair_op): Likewise.
(addsub_pattern::recognize): Likewise.
* tree-vect-slp.cc (vect_print_slp_tree): Likewise.
(vect_gather_slp_loads): Likewise.
(vect_is_slp_load_node): Likewise.
(optimize_load_redistribution_1): Likewise.
(vect_optimize_slp_pass::is_cfg_latch_edge): Likewise.
(vect_optimize_slp_pass::internal_node_cost): Likewise.
(vect_optimize_slp_pass::start_choosing_layouts): Likewise.
(vect_optimize_slp_pass::backward_cost): Likewise.
(vect_optimize_slp_pass::forward_pass): Likewise.
(vect_optimize_slp_pass::get_result_with_layout): Likewise.
(vect_optimize_slp_pass::materialize): Likewise.
(vect_optimize_slp_pass::dump): Likewise.
(vect_optimize_slp_pass::decide_masked_load_lanes): Likewise.
(vect_update_slp_vf_for_node): Likewise.
(vect_slp_analyze_node_operations_1): Likewise.
(vect_schedule_slp_node): Likewise.
(vect_schedule_scc): Likewise.
* tree-vect-stmts.cc (vect_analyze_stmt): Likewise.
(vect_transform_stmt): Likewise.
(vect_is_simple_use): Likewise.

4 days agoRemove use of STMT_VINFO_DEF_TYPE in vect_analyze_stmt
Richard Biener [Wed, 13 Aug 2025 12:43:28 +0000 (14:43 +0200)] 
Remove use of STMT_VINFO_DEF_TYPE in vect_analyze_stmt

This removes a use of STMT_VINFO_DEF_TYPE.

* tree-vect-stmts.cc (vect_analyze_stmt): Use
SLP_TREE_DEF_TYPE instead of STMT_VINFO_DEF_TYPE.

4 days agoFold GATHER_SCATTER_*_P into vect_memory_access_type
Richard Biener [Tue, 12 Aug 2025 11:34:30 +0000 (13:34 +0200)] 
Fold GATHER_SCATTER_*_P into vect_memory_access_type

The following splits up VMAT_GATHER_SCATTER into
VMAT_GATHER_SCATTER_LEGACY, VMAT_GATHER_SCATTER_IFN and
VMAT_GATHER_SCATTER_EMULATED.  The main motivation is to reduce
the uses of (full) gs_info, but it also makes the kind representable
by a single entry rather than the ifn and decl tristate.

The strided load with gather case gets to use VMAT_GATHER_SCATTER_IFN,
since that's what we end up checking.

* tree-vectorizer.h (vect_memory_access_type): Replace
VMAT_GATHER_SCATTER with three separate access types,
VMAT_GATHER_SCATTER_LEGACY, VMAT_GATHER_SCATTER_IFN and
VMAT_GATHER_SCATTER_EMULATED.
(mat_gather_scatter_p): New predicate.
(GATHER_SCATTER_LEGACY_P): Remove.
(GATHER_SCATTER_IFN_P): Likewise.
(GATHER_SCATTER_EMULATED_P): Likewise.
* tree-vect-stmts.cc (check_load_store_for_partial_vectors):
Adjust.
(get_load_store_type): Likewise.
(vect_get_loop_variant_data_ptr_increment): Likewise.
(vectorizable_store): Likewise.
(vectorizable_load): Likewise.
* config/i386/i386.cc (ix86_vector_costs::add_stmt_cost):
Likewise.
* config/riscv/riscv-vector-costs.cc
(costs::need_additional_vector_vars_p): Likewise.
* config/aarch64/aarch64.cc (aarch64_detect_vector_stmt_subtype):
Likewise.
(aarch64_vector_costs::count_ops): Likewise.
(aarch64_vector_costs::add_stmt_cost): Likewise.

4 days agoSimplify vect_supportable_dr_alignment API
Richard Biener [Tue, 12 Aug 2025 13:47:06 +0000 (15:47 +0200)] 
Simplify vect_supportable_dr_alignment API

The gather_scatter_info pointer is only used as flag, so pass down
a flag.

* tree-vectorizer.h (vect_supportable_dr_alignment): Pass
a bool instead of a pointer to gather_scatter_info.
* tree-vect-data-refs.cc (vect_supportable_dr_alignment):
Likewise.
* tree-vect-stmts.cc (get_load_store_type): Adjust.

4 days agoFortran: Use associated TBP subroutine not found [PR89092]
Paul Thomas [Wed, 13 Aug 2025 06:16:31 +0000 (07:16 +0100)] 
Fortran: Use associated TBP subroutine not found [PR89092]

2025-08-13  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/89092
* resolve.cc (was_declared): Add subroutine attribute.

gcc/testsuite/
PR fortran/89092
* gfortran.dg/pr89092.f90: New test.

4 days agoLoongArch: Define hook TARGET_COMPUTE_PRESSURE_CLASSES[PR120476].
Lulu Cheng [Wed, 13 Aug 2025 03:04:35 +0000 (11:04 +0800)] 
LoongArch: Define hook TARGET_COMPUTE_PRESSURE_CLASSES[PR120476].

The rtx cost value defined by the target backend affects the
calculation of register pressure classes in the IRA, thus affecting
scheduling.  This may cause program performance degradation.
For example, OpenSSL 3.5.1 SHA512 and SPEC CPU 2017 exchange_r.

This problem can be avoided by defining a set of register pressure
classes in the target backend instead of using the default IRA to
automatically calculate them.

gcc/ChangeLog:

PR target/120476
* config/loongarch/loongarch.cc
(loongarch_compute_pressure_classes): New function.
(TARGET_COMPUTE_PRESSURE_CLASSES): Define.

4 days agoLoongArch: Add support for _BitInt [PR117599]
Yang Yujie [Sat, 2 Aug 2025 09:16:23 +0000 (17:16 +0800)] 
LoongArch: Add support for _BitInt [PR117599]

This patch adds support for C23's _BitInt for LoongArch.

From the LoongArch psABI[1]:

> _BitInt(N) objects are stored in little-endian order in memory
> and are signed by default.
>
> For N ≤ 64, a _BitInt(N) object have the same size and alignment
> of the smallest fundamental integral type that can contain it.
> The unused high-order bits within this containing type are filled
> with sign or zero extension of the N-bit value, depending on whether
> the _BitInt(N) object is signed or unsigned. The _BitInt(N) object
> propagates its signedness to the containing type and is laid out
> in a register or memory as an object of this type.
>
> For N > 64, _BitInt(N) objects are implemented as structs of 64-bit
> integer chunks. The number of chunks is the smallest even integer M
> so that M * 64 ≥ N. These objects are of the same size of the struct
> containing the chunks, but always have 16-byte alignment. If there
> are unused bits in the highest-ordered chunk that contains used
> bits, they are defined as the sign- or zero- extension of the used
> bits depending on whether the _BitInt(N) object is signed or
> unsigned. If an entire chunk is unused, its bits are undefined.

[1] https://github.com/loongson/la-abi-specs

PR target/117599

gcc/ChangeLog:

* config/loongarch/loongarch.h: Define a PROMOTE_MODE case for
small _BitInts.
* config/loongarch/loongarch.cc (loongarch_promote_function_mode):
Same.
(loongarch_bitint_type_info): New function.
(TARGET_C_BITINT_TYPE_INFO): Declare.

libgcc/ChangeLog:

* config/loongarch/t-softfp-tf: Enable _BitInt helper functions.
* config/loongarch/t-loongarch: Same.
* config/loongarch/libgcc-loongarch.ver: New file.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/bitint-alignments.c: New test.
* gcc.target/loongarch/bitint-args.c: New test.
* gcc.target/loongarch/bitint-sizes.c: New test.

4 days agoLoongArch: Prioritize target-specific makefile fragments
Yang Yujie [Sat, 2 Aug 2025 09:14:25 +0000 (17:14 +0800)] 
LoongArch: Prioritize target-specific makefile fragments

libgcc/ChangeLog:

* config.host: Remove unused code. Include LoongArch-specific
tmake_files after the OS-specific ones.

4 days ago[RISC-V][PR target/121113] Handle HFmode in various insn reservations
Jeff Law [Wed, 13 Aug 2025 02:29:50 +0000 (20:29 -0600)] 
[RISC-V][PR target/121113] Handle HFmode in various insn reservations

So this is a minor bug in a few DFA descriptions such as the Xiangshan and a
couple of the SiFive descriptions.

While Xiangshan covers every insn type, some of the reservations check the mode
of the operation.   Concretely the fdiv/fsqrt unit reservations vary based on
the mode.  They handled DF/SF, but not HF (the relevant iterators don't include
BF).

This patch just adds HF support with the same characteristics as SF. Those who
know these designs better could perhaps improve the reservation, but this at
least keeps us from aborting.

I did check the other published DFAs for mode dependent reservations. That's
show I found the p400/p600 issue.

Tested in my tester, waiting for CI to render its verdict before pushing.

PR target/121113
gcc/
* config/riscv/sifive-p400.md: Handle HFmode for fdiv/fsqrt.
* config/riscv/sifive-p600.md: Likewise.
* config/riscv/xiangshan.md: Likewise.

gcc/testsuite/
* gcc.target/riscv/pr121113.c: New test.

4 days agocobol: Implement faster zoned decimal to binary conversion.
Robert Dubner [Wed, 13 Aug 2025 02:13:59 +0000 (22:13 -0400)] 
cobol: Implement faster zoned decimal to binary conversion.

Replace " value *= 10; value += digit" routines with a new one that does two
digits at a time and avoids __int128 calculations until they are necessary.

These changes also clean up the conversion behavior when a digit is not valid.

gcc/cobol/ChangeLog:

* genutil.cc (get_binary_value): Use the new routine.

libgcobol/ChangeLog:

* libgcobol.cc (int128_to_field): Use the new routine.
(get_binary_value_local): Use the new routine.
(format_for_display_internal): Formatting.
(__gg__get_file_descriptor): Likewise.
* stringbin.cc (string_from_combined): Formatting.
(packed_from_combined): Likewise.
(int_from_string): New routine.
(__gg__numeric_display_to_binary): Likewise.
* stringbin.h (__gg__numeric_display_to_binary): Likewise.

5 days agotestsuite: fix jit.dg/test-error-impossible-must-tail-call.c [PR119783]
David Malcolm [Wed, 13 Aug 2025 01:46:41 +0000 (21:46 -0400)] 
testsuite: fix jit.dg/test-error-impossible-must-tail-call.c [PR119783]

I added this test back in r7-934-g15c671a79ca66d, but it looks like
r15-2125-g81824596361cf4 changed the error message.

gcc/testsuite/ChangeLog:
PR testsuite/119783
jit.dg/test-error-impossible-must-tail-call.c
* jit.dg/test-error-impossible-must-tail-call.c (verify_code):
Check that we get a suitable-looking error message, but don't
try to specify exactly what the message is.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
5 days agojit: don't use &vect[0] in libgccjit++.h [PR121516]
David Malcolm [Wed, 13 Aug 2025 01:46:41 +0000 (21:46 -0400)] 
jit: don't use &vect[0] in libgccjit++.h [PR121516]

gcc/jit/ChangeLog:
PR jit/121516
* libgccjit++.h (context::new_struct_type): Replace use of
&fields[0] with fields.data ().
(context::new_function): Likewise for params.
(context::new_rvalue): Likewise for elements.
(context::new_call): Likewise for args.
(block::end_with_switch): Likewise for cases.
(block::end_with_extended_asm_goto): Likewise for goto_blocks.
(context::new_struct_ctor): Likewise for fields and values.
(context::new_array_ctor): Likewise for values.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
5 days agox86: Convert integer constant to mode of move
H.J. Lu [Tue, 12 Aug 2025 12:19:24 +0000 (05:19 -0700)] 
x86: Convert integer constant to mode of move

For

(set (reg/v:DI 106 [ k ])
     (const_int 3000000000 [0xb2d05e00]))
...
(set (reg:V4SI 115 [ _13 ])
     (vec_duplicate:V4SI (subreg:SI (reg/v:DI 106 [ k ]) 0)))
...
(set (reg:V2SI 118 [ _9 ])
     (vec_duplicate:V2SI (subreg:SI (reg/v:DI 106 [ k ]) 0)))

we should generate

(set (reg:SI 125)
     (const_int -1294967296 [0xffffffffb2d05e00]))
(set (reg:V4SI 124)
     (vec_duplicate:V4SI (reg:VSI 125))
...
(set (reg:V4SI 115 [ _13 ])
     (reg:V4SI 124)
...
(set (reg:V2SI 118 [ _9 ])
     (subreg:V2SI (reg:V4SI 124))

by converting integer constant to mode of move.

gcc/

PR target/121497
* config/i386/i386-features.cc (ix86_broadcast_inner): Convert
integer constant to mode of move

gcc/testsuite/

PR target/121497
* gcc.target/i386/pr121497.c: New test.

Co-authored-by: Liu, Hongtao <hongtao.liu@intel.com>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
5 days agoDaily bump.
GCC Administrator [Wed, 13 Aug 2025 00:19:57 +0000 (00:19 +0000)] 
Daily bump.

5 days agoRISC-V: RISC-V: Add test for vec_duplicate + vmerge.vvm combine with GR2VR cost 0...
Pan Li [Mon, 4 Aug 2025 01:54:34 +0000 (09:54 +0800)] 
RISC-V: RISC-V: Add test for vec_duplicate + vmerge.vvm combine with GR2VR cost 0, 1 and 15

Add asm dump check and run test for vec_duplicate + vmerge.vvm
combine to vmerge.vxm, with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary.h: Add test
helper macros.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_binary_data.h: Add test
data for run test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-1-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-1-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-1-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-1-i8.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-2-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-2-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-2-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-2-i8.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-3-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-3-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-3-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-merge-3-i8.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmerge-run-1-i16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmerge-run-1-i32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmerge-run-1-i64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vmerge-run-1-i8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
5 days agoRISC-V: Combine vec_duplicate + vmerge.vv to vmerge.vx on GR2VR cost
Pan Li [Mon, 11 Aug 2025 13:22:08 +0000 (21:22 +0800)] 
RISC-V: Combine vec_duplicate + vmerge.vv to vmerge.vx on GR2VR cost

This patch would like to combine the vec_duplicate + vaadd.vv to the
vaadd.vx.  From example as below code.  The related pattern will depend
on the cost of vec_duplicate from GR2VR.  Then the late-combine will
take action if the cost of GR2VR is zero, and reject the combination
if the GR2VR cost is greater than zero.

Assume we have example code like below, GR2VR cost is 0.

  #define DEF_VX_MERGE_0(T)                                      \
  void                                                           \
  test_vx_merge_##T##_case_0 (T * restrict out, T * restrict in, \
                              T x,  unsigned n)                  \
  {                                                              \
    for (unsigned i = 0; i < n; i++)                             \
      {                                                          \
        if (i % 2 == 0)                                          \
          out[i] = x;                                            \
        else                                                     \
          out[i] = in[i];                                        \
      }                                                          \
  }

  DEF_VX_MERGE_0(int32_t)

Before this patch:
  11   │     beq a3,zero,.L8
  12   │     vsetvli a5,zero,e32,m1,ta,ma
  13   │     vmv.v.x v2,a2
  ...
  16   │ .L3:
  17   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  22   │     vmerge.vvm v1,v1,v2,v0
  ...
  25   │     bne a3,zero,.L3

After this patch:
  11   │     beq a3,zero,.L8
  ...
  14   │ .L3:
  15   │     vsetvli a5,a3,e32,m1,ta,ma
  ...
  20   │     vmerge.vxm v1,v1,a2,v0
  ...
  23   │     bne a3,zero,.L3

gcc/ChangeLog:

* config/riscv/autovec-opt.md (*merge_vx_<mode>): Add new
pattern to combine the vmerge.vxm.

Signed-off-by: Pan Li <pan2.li@intel.com>
5 days agoRISC-V: Expand const_vector with 2 elts per pattern.
Robin Dapp [Mon, 4 Aug 2025 09:09:50 +0000 (11:09 +0200)] 
RISC-V: Expand const_vector with 2 elts per pattern.

Hi,

In PR121334 we are asked to expand a const_vector of size 4 with
poly_int elements.  It has 2 elts per pattern so is neither a
const_vector_duplicate nor a const_vector_stepped.

We don't allow this kind of constant in legitimate_constant_p but expr
apparently still wants us to expand it under certain conditions.

This patch implements a basic expander for such kinds of patterns.
As slide1up is used to build the individual vectors it also adds
a helper function expand_slide1up.

I regtested on rv64gcv_zvl512b but unfortunately the newly created pattern is
not even executed.  I tried some variations of the original code but didn't
manage to trigger it.

Regards
 Robin

PR target/121334

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_slide1up): New function.
(expand_vector_init_trailing_same_elem): Use new function.
(expand_const_vector_onestep): New function.
(expand_const_vector): Uew expand_slide1up.
(expand_vector_init_merge_repeating_sequence): Ditto.
(shuffle_off_by_one_patterns): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr121334.c: New test.

5 days agoLoongArch: macro instead enum for base abi type
mengqinggang [Fri, 8 Aug 2025 08:22:59 +0000 (16:22 +0800)] 
LoongArch: macro instead enum for base abi type

enum can't be used in #if.
For #if expression, identifiers that are not macros,
which are all considered to be the number zero.

This patch may fix https://sourceware.org/bugzilla/show_bug.cgi?id=32776.

gcc/ChangeLog:

* config/loongarch/loongarch-def.h (ABI_BASE_LP64D): New macro.
(ABI_BASE_LP64F): New macro.
(ABI_BASE_LP64S): New macro.
(N_ABI_BASE_TYPES): New macro.

5 days agoCleanup SLP decision during loop analysis
Richard Biener [Tue, 12 Aug 2025 09:00:54 +0000 (11:00 +0200)] 
Cleanup SLP decision during loop analysis

The following refactors the now misleading slp_done_for_suggested_uf
and slp states kept during vectorizer loop analysis.

* tree-vect-loop.cc (vect_analyze_loop_2): Change
slp_done_for_suggested_uf to a boolean
single_lane_slp_done_for_suggested_uf.  Change slp
to force_single_lane boolean.
(vect_analyze_loop_1): Adjust similarly.

5 days agofwprop: Don't propagate asms [PR121253]
Richard Sandiford [Tue, 12 Aug 2025 09:21:47 +0000 (10:21 +0100)] 
fwprop: Don't propagate asms [PR121253]

For the reasons explained in the comment, fwprop shouldn't even
try to propagate an asm definition.

gcc/
PR rtl-optimization/121253
* fwprop.cc (forward_propagate_into): Don't propagate asm defs.

gcc/testsuite/
PR rtl-optimization/121253
* gcc.target/aarch64/pr121253.c: New test.

5 days agotree-optimization/121509 - failure to detect unvectorizable loop
Richard Biener [Tue, 12 Aug 2025 07:51:54 +0000 (09:51 +0200)] 
tree-optimization/121509 - failure to detect unvectorizable loop

With the hybrid stmt detection no longer working as a gate-keeper
to detect unhandled stmts we have to, and can, detect those earlier.
The appropriate place is vect_mark_stmts_to_be_vectorized where
for trivially relevant PHIs we can stop analyzing when the PHI
wasn't classified as a known def during vect_analyze_scalar_cycles.

PR tree-optimization/121509
* tree-vect-stmts.cc (vect_mark_stmts_to_be_vectorized):
Fail early when we detect a relevant but not handled PHI.

* gcc.dg/vect/pr121509.c: New testcase.

5 days agotree-optimization/121514 - ICE with recent VN improvement
Richard Biener [Tue, 12 Aug 2025 07:00:48 +0000 (09:00 +0200)] 
tree-optimization/121514 - ICE with recent VN improvement

When inserting a compensation stmt during VN we are making sure to
register the result for the original stmt into the hashtable so
VN iteration has the chance to converge and we avoid inserting
another copy each time.  But the implementation doesn't work for
non-SSA name values, and is also not necessary for constants since
we did not insert anything for them.  The following appropriately
guards the calls to vn_nary_op_insert_stmt as was already done
in one place.

PR tree-optimization/121514
* tree-ssa-sccvn.cc (visit_nary_op): Only call
vn_nary_op_insert_stmt for SSA name result.

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

5 days agoforwprop: Fix non-call exceptions some more with copy prop for aggregates [PR121494]
Andrew Pinski [Mon, 11 Aug 2025 20:47:30 +0000 (20:47 +0000)] 
forwprop: Fix non-call exceptions some more with copy prop for aggregates [PR121494]

Note this conflicts with my not yet approved patch for copy prop for aggregates into
function arguments (I will get back to that soon).

So the problem here is that I assumed if:
*a = decl1;
would not cause an exception that:
decl2 = *a;
would cause not cause one too.

I was wrong, in some cases where the Ada front-end marks `*a` in the store
as TREE_THIS_NOTRAP (due to knowing never be null or some other cases).
So that means when we prop decl1 into the statement storing decl2, we need to
mark that statement as possible to cleanup for eh.

Bootstraped and tested on x86_64-linux-gnu.
Also tested on x86_64-linux-gnu with a hack to force generate LC constant decls in the gimplifier.

PR tree-optimization/121494
gcc/ChangeLog:

* tree-ssa-forwprop.cc (optimize_agr_copyprop): Mark the bb of the use
stmt if needed for eh cleanup.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
5 days agoDo not set STMT_VINFO_VECTYPE for non-dataref stmts
Richard Biener [Mon, 11 Aug 2025 09:22:47 +0000 (11:22 +0200)] 
Do not set STMT_VINFO_VECTYPE for non-dataref stmts

Now that all STMT_VINFO_VECTYPE uses from vectorizable_* have been
pruged there's no longer a need to have STMT_VINFO_VECTYPE set.
We still rely on it being present on data-ref stmts and there it
can differ between different SLP instances when doing BB vectorization.
The following removes the setting from vect_analyze_stmt and
vect_transform_stmt.

Note the following clears STMT_VINFO_VECTYPE from pattern stmts (the
vector type should have moved to the SLP tree by this time).

* tree-vect-stmts.cc (vect_analyze_stmt): Only set
STMT_VINFO_VECTYPE for dataref SLP representatives.
Clear it for others and do not restore the original value.
(vect_transform_stmt): Likewise.

5 days agoPass down vector type to avoid STMT_VINFO_VECTYPE on reduc-info
Richard Biener [Mon, 11 Aug 2025 13:38:41 +0000 (15:38 +0200)] 
Pass down vector type to avoid STMT_VINFO_VECTYPE on reduc-info

The following passes down the vector type to functions instead of
querying it from the reduc-info stmt-info.

* tree-vect-loop.cc (get_initial_defs_for_reduction):
Get vector type as argument.
(vect_find_reusable_accumulator): Likewise.
(vect_transform_cycle_phi): Adjust.

5 days agoDo not use STMT_VINFO_VECTYPE in vectorizable_reduction
Richard Biener [Mon, 11 Aug 2025 09:20:41 +0000 (11:20 +0200)] 
Do not use STMT_VINFO_VECTYPE in vectorizable_reduction

There's one use of STMT_VINFO_VECTYPE in vectorizable_reduction
where I'm only 99% sure which SLP_TREE_VECTYPE to replace it with
(vectorizable_reduction needs a lot of post-only-SLP TLC).  The
following replaces it with the hopefully appropriate one.

* tree-vect-loop.cc (vectorizable_reduction): Replace
STMT_VINFO_VECTYPE use with SLP_TREE_VECTYPE.

5 days agotree-optimization/121493 - another missed VN with aggregate copy
Richard Biener [Mon, 11 Aug 2025 08:42:47 +0000 (10:42 +0200)] 
tree-optimization/121493 - another missed VN with aggregate copy

This is another case where opportunistically handling a first
aggregate copy where we failed to match up the refs exactly
(as we don't insert missing handling components) yields to a
failure in the second aggregate copy that we visit.  Add another
fixup to deal with such situations, in-line with that present
opportunistic handling.

PR tree-optimization/121493
* tree-ssa-sccvn.cc (vn_reference_lookup_3): Opportunistically
strip components with known offset.

* gcc.dg/tree-ssa/ssa-fre-109.c: New testcase.

5 days agoRestrict aggregate copy VN generalization
Richard Biener [Mon, 11 Aug 2025 12:43:58 +0000 (14:43 +0200)] 
Restrict aggregate copy VN generalization

The following avoids ending up with a MEM_REF as component to apply.

* tree-ssa-sccvn.cc (vn_reference_lookup_3): When we fail to
match up the two base MEM_REFs, fail.

5 days agofortran: add optional lower arg to c_f_pointer
Yuao Ma [Thu, 7 Aug 2025 14:35:17 +0000 (22:35 +0800)] 
fortran: add optional lower arg to c_f_pointer

This patch adds support for the optional lower argument in intrinsic
c_f_pointer specified in Fortran 2023. Test cases and documentation have also
been updated.

gcc/fortran/ChangeLog:

* check.cc (gfc_check_c_f_pointer): Check lower arg legitimacy.
* intrinsic.cc (add_subroutines): Teach c_f_pointer about lower arg.
* intrinsic.h (gfc_check_c_f_pointer): Add lower arg.
* intrinsic.texi: Update lower arg for c_f_pointer.
* trans-intrinsic.cc (conv_isocbinding_subroutine): Add logic handle lower.

gcc/testsuite/ChangeLog:

* gfortran.dg/c_f_pointer_shape_tests_7.f90: New test.
* gfortran.dg/c_f_pointer_shape_tests_8.f90: New test.
* gfortran.dg/c_f_pointer_shape_tests_9.f90: New test.

Signed-off-by: Yuao Ma <c8ef@outlook.com>
5 days agoImprove initial code generation for addsi/adddi
Shreya Munnangi [Tue, 12 Aug 2025 03:42:50 +0000 (21:42 -0600)] 
Improve initial code generation for addsi/adddi

This is a patch primarily from Shreya, though I think she cribbed some
code from Philipp that we had internally within Ventana and I made some
minor adjustments as well.

So the basic idea here is similar to her work on logical ops --
specifically when we can generate more efficient code at expansion time,
then do so.  In some cases the net is better code; in other cases we
lessen reliance on mvconst_internal and finally it provides
infrastructure that I think will help address an issue Paul Antoine
reported a little while back.

The most obvious case is using paired addis from initial code generation
for some constants.  It will also use a shNadd insn when the cost to
synthesize the original value is higher than the right-shifted value.
Finally it will negate the constant and use "sub"  if the negated
constant is cheaper than the original constant.

There's more work to do in here, particularly WRT 32 bit objects for
rv64.  Shreya is looking at that right now.  There may also be cases
where another shNadd or addi would be profitable.  We haven't really
explored those cases in any detail, while there may be cases to handle,
it's unclear how often they occur in practice.

I don't want to remove the define_insn_and_split for the paired addi
cases yet.  I think that likely happens as a side effect of fixing Paul
Antoine's issue.

Bootstrapped and regression tested on a BPI & Pioneer box.  Will
obviously wait for the pre-commit tester before moving forward.

Jeff
PR target/120603
gcc/
* config/riscv/riscv-protos.h (synthesize_add): Add prototype.
* config/riscv/riscv.cc (synthesize_add): New function.
* config/riscv/riscv.md (addsi3): Allow any constant as operands[2]
in the expander.  Force the constant into a register as needed for
TARGET_64BIT.  Use synthesize_add for !TARGET_64BIT.
(*adddi3): Renamed from adddi3.
(adddi3): New expander.  Use synthesize_add.

gcc/testsuite
* gcc.target/riscv/add-synthesis-1.c: New test.

Co-authored-by: Jeff Law <jlaw@ventanamicro.com>
Co-authored-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
6 days agocobol: Bring EBCDIC NumericDisplay variables into IBM compliance.
Robert Dubner [Tue, 12 Aug 2025 00:56:38 +0000 (20:56 -0400)] 
cobol: Bring EBCDIC NumericDisplay variables into IBM compliance.

The internal representation of Numeric Display (ND) zoned decimal variables
when operating in EBCDIC mode has been brought into compliance with IBM
conventions.  This requires changes to data input, data output, internal
conversion of zoned decimal to binary, and variable assignment.

gcc/cobol/ChangeLog:

* genapi.cc (compare_binary_binary): Formatting.
(cobol_compare): Formatting.
(mh_numeric_display): Rewrite "move ND to ND" algorithm.
(initial_from_initial): Proper initialization of EBCDIC ND variables.
* genmath.cc (fast_add): Delete comment.
* genutil.cc (get_binary_value): Modify for updated EBCDIC.

libgcobol/ChangeLog:

* common-defs.h (NUMERIC_DISPLAY_SIGN_BIT): New comment; new constant.
(EBCDIC_MINUS): New constant.
(EBCDIC_PLUS): Likewise.
(EBCDIC_ZERO): Likewise.
(EBCDIC_NINE): Likewise.
(PACKED_NYBBLE_PLUS): Likewise.
(PACKED_NYBBLE_MINUS): Likewise.
(PACKED_NYBBLE_UNSIGNED): Likewise.
(NUMERIC_DISPLAY_SIGN_BIT_ASCII): Likewise.
(NUMERIC_DISPLAY_SIGN_BIT_EBCDIC): Likewise.
(SEPARATE_PLUS): Likewise.
(SEPARATE_MINUS): Likewise.
(ZONED_ZERO): Likewise.
(ZONE_SIGNED_EBCDIC): Likewise.
* configure: Regenerate.
* libgcobol.cc (turn_sign_bit_on): Handle new EBCDIC sign convention.
(turn_sign_bit_off): Likewise.
(is_sign_bit_on): Likewise.
(int128_to_field): EBCDIC NumericDisplay conversion.
(get_binary_value_local): Likewise.
(format_for_display_internal): Likewise.
(normalize_id): Likewise.
(__gg__inspect_format_1): Convert EBCDIC negative numbers to positive.
* stringbin.cc (packed_from_combined): Quell cppcheck warning.

gcc/testsuite/ChangeLog:

* cobol.dg/group2/ALLOCATE_Rule_8_OPTION_INITIALIZE_with_figconst.out:
Change test for updated handling of Numeric Display variables.

6 days agoDaily bump.
GCC Administrator [Tue, 12 Aug 2025 00:20:17 +0000 (00:20 +0000)] 
Daily bump.

6 days agoaarch64: Fix condition accepted by mov<ALLI>cc
Richard Henderson [Fri, 8 Aug 2025 01:01:26 +0000 (01:01 +0000)] 
aarch64: Fix condition accepted by mov<ALLI>cc

Reject QI/HImode conditions, which would require extension in
order to compare.  Fixes

z.c:10:1: error: unrecognizable insn:
   10 | }
      | ^
(insn 23 22 24 2 (set (reg:CC 66 cc)
        (compare:CC (reg:HI 128)
            (reg:HI 127))) "z.c":6:6 -1
     (nil))
during RTL pass: vregs

gcc:
* config/aarch64/aarch64.md (mov<ALLI>cc): Accept MODE_CC
conditions directly; reject QI/HImode conditions.

gcc/testsuite:
* gcc.target/aarch64/cmpbr-3.c: New.
* gcc.target/aarch64/ifcvt_multiple_sets_rewire.c: Simplify
test for csel by ignoring the actual registers used.

6 days agoaarch64: CMPBR branches must be invertable
Richard Henderson [Thu, 7 Aug 2025 22:48:52 +0000 (22:48 +0000)] 
aarch64: CMPBR branches must be invertable

Restrict the immediate range to the intersection of LT/GE and GT/LE
so that cfglayout can invert the condition to redirect any branch.

gcc:
PR target/121388
* config/aarch64/aarch64.cc (aarch64_cb_rhs): Restrict the
range of LT/GE and GT/LE to their intersections.
* config/aarch64/aarch64.md (*aarch64_cb<INT_CMP><GPI>): Unexport.
Use cmpbr_imm_predicate instead of aarch64_cb_rhs.
* config/aarch64/constraints.md (Uc1): Accept 0..62.
(Uc2): Remove.
* config/aarch64/iterators.md (cmpbr_imm_predicate): New.
(cmpbr_imm_constraint): Update to match aarch64_cb_rhs.
* config/aarch64/predicates.md (aarch64_cb_reg_i63_operand): New.
(aarch64_cb_reg_i62_operand): New.

gcc/testsuite:
PR target/121388
* gcc.target/aarch64/cmpbr.c (u32_x0_ult_64): XFAIL.
(i32_x0_slt_64, u64_x0_ult_64, i64_x0_slt_64): XFAIL.
* gcc.target/aarch64/cmpbr-2.c: New.

6 days agoaarch64: Consider TARGET_CMPBR in rtx costs
Richard Henderson [Mon, 4 Aug 2025 12:47:05 +0000 (22:47 +1000)] 
aarch64: Consider TARGET_CMPBR in rtx costs

gcc:
* config/aarch64/aarch64.cc (aarch64_if_then_else_costs):
Use aarch64_cb_rhs to match CB insns.