]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
8 weeks agocselim: change how to detect no load/stores after store in single_trailing_store_in_bb
Andrew Pinski [Fri, 6 Jun 2025 18:07:57 +0000 (11:07 -0700)] 
cselim: change how to detect no load/stores after store in single_trailing_store_in_bb

So the current code iterates through the uses of the vdef of the store to see if there
is an use of the vdef inside the bb. Except in this case we know the only usage will
be a phi node, so change the loop into calling single_imm_use and then checking if the
usage statement was the PHI node.

Bootstrapped and tested on x86_64-linux-gnu.

Also did a quick test by adding a return false after the checks of single_trailing_store_in_bb
in cond_if_else_store_replacement to make sure this code still does the correct thing.

gcc/ChangeLog:

* tree-ssa-phiopt.cc (single_trailing_store_in_bb): Add vphi argument.
Check for single use of the vdef of the store instead of a loop
and check vdef's single use statement is the same as vphi.
(cond_if_else_store_replacement): Update call to single_trailing_store_in_bb.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 weeks agocselim: Use get_virtual_phi instead of a loop in cond_if_else_store_replacement
Andrew Pinski [Sun, 8 Jun 2025 18:12:46 +0000 (11:12 -0700)] 
cselim: Use get_virtual_phi instead of a loop in cond_if_else_store_replacement

Don't inline finding of the virtual op phi node, instead use get_virtual_phi.
This is based on the review of a different patch (https://gcc.gnu.org/pipermail/gcc-patches/2025-June/686076.html).

Pushed as obvious after a bootstrap/test on x86_64-linux-gnu.

gcc/ChangeLog:

* tree-ssa-phiopt.cc (cond_if_else_store_replacement): Use get_virtual_phi
instead of inlining it.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 weeks agolibstdc++-v3: Update baseline symbols for hppa-linux
John David Anglin [Sun, 8 Jun 2025 15:48:14 +0000 (11:48 -0400)] 
libstdc++-v3: Update baseline symbols for hppa-linux

Duplicate symbol names with no version are removed.

2025-06-08  John David Anglin  <danglin@gcc.gnu.org>

libstdc++-v3/ChangeLog:
* config/abi/post/hppa-linux-gnu/baseline_symbols.txt: Update.

8 weeks ago[RISC-V] Handle 32bit operands in condition for conditional moves
Shreya Munnangi [Sun, 8 Jun 2025 14:42:53 +0000 (08:42 -0600)] 
[RISC-V] Handle 32bit operands in condition for conditional moves

So here's the next chunk of conditional move work from Shreya.

It's been a long standing wart that the conditional move expander does not
support sub-word operands in the comparison.  Particularly since we have
support routines to handle the necessary extensions for that case.

This patch adjusts the expander to use riscv_extend_comparands rather than fail
for that case.  I've built spec2017 before/after this and we definitely get
more conditional moves and they look sensible from a performance standpoint.
None are likely hitting terribly hot code, so I wouldn't expect any performance
jumps.

Waiting on pre-commit testing to do its thing.

gcc/
* config/riscv/riscv.cc (riscv_expand_conditional_move): Use
riscv_extend_comparands to extend sub-word comparison arguments.

Co-authored-by: Jeff Law <jlaw@ventanamicro.com>
8 weeks agoxtensa: Implement l(ceil|floor)sfsi2 insn patterns and their scaled variants
Takayuki 'January June' Suwa [Sun, 8 Jun 2025 05:05:05 +0000 (14:05 +0900)] 
xtensa: Implement l(ceil|floor)sfsi2 insn patterns and their scaled variants

By using the previously unused CEIL|FLOOR.S floating-point coprocessor
instructions.  In addition, two instruction operand format codes are added
to output the scale value as assembler source.

     /* example */
     int test0(float a) {
       return __builtin_lceilf(a);
     }
     int test1(float a) {
       return __builtin_lceilf(a * 2);
     }
     int test2(float a) {
       return __builtin_lfloorf(a);
     }
     int test3(float a) {
       return __builtin_lfloorf(a * 32768);
     }

     ;; result
     test0:
      entry sp, 32
      wfr f0, a2
      ceil.s a2, f0, 0
      retw.n
     test1:
      entry sp, 32
      wfr f0, a2
      ceil.s a2, f0, 1
      retw.n
     test2:
      entry sp, 32
      wfr f0, a2
      floor.s a2, f0, 0
      retw.n
     test3:
      entry sp, 32
      wfr f0, a2
      floor.s a2, f0, 15
      retw.n

However, because the rounding-half behavior (e.g., the rule that determines
whether 1.5 should be rounded to 1 or 2) of the two is inconsistent;
the lroundsfsi2 pattern is explicitly specified that rounding to nearest
integer and away from zero, but the other hand, the ROUND.S instruction is
not specified that by the ISA and is implementation-dependent.

Therefore lroundsfsi2 cannot be implemented by ROUND.S.

gcc/ChangeLog:

* config/xtensa/xtensa.cc (printx, print_operand):
Add two instruction operand format codes 'U' and 'V',
whose represent scale factors of 0 to 15th positive/negative
power of two.
* config/xtensa/xtensa.md (c_enum "unspec"):
Add UNSPEC_CEIL and UNSPEC_FLOOR.
(int_iterator ANY_ROUND, int_attr m_round):
New integer iterator and its attribute.
(fix<s_fix>_truncsfsi2, *fix<s_fix>_truncsfsi2_2x,
*fix<s_fix>_truncsfsi2_scaled, float<s_float>sisf2,
*float<s_float>sisf2_scaled):
Use output templates with the operand formats added above,
instead of individual output statements.
(l<m_round>sfsi2, *l<m_round>sfsi2_2x, *l<m_round>sfsi2_scaled):
New insn patterns.

8 weeks agoDaily bump.
GCC Administrator [Sun, 8 Jun 2025 00:16:33 +0000 (00:16 +0000)] 
Daily bump.

8 weeks agolibfortran: Regenerate files
Francois-Xavier Coudert [Fri, 6 Jun 2025 12:21:49 +0000 (14:21 +0200)] 
libfortran: Regenerate files

In commit 5e918a4db9e4a5bdbeafec6881fa8b22a55d3789, regenerated files
were not included in the commit as they should have been. Therefore, a
whitespace fix was not propagated. Sync generated files now, as obtained
from a run with --enable-maintainer-mode.

2025-06-06  François-Xavier Coudert  <fxcoudert@gcc.gnu.org>

libgfortran/ChangeLog:

PR libfortran/116400
* generated/iall_i1.c: Regenerate.
* generated/iall_i16.c: Regenerate.
* generated/iall_i2.c: Regenerate.
* generated/iall_i4.c: Regenerate.
* generated/iall_i8.c: Regenerate.
* generated/iany_i1.c: Regenerate.
* generated/iany_i16.c: Regenerate.
* generated/iany_i2.c: Regenerate.
* generated/iany_i4.c: Regenerate.
* generated/iany_i8.c: Regenerate.
* generated/iparity_i1.c: Regenerate.
* generated/iparity_i16.c: Regenerate.
* generated/iparity_i2.c: Regenerate.
* generated/iparity_i4.c: Regenerate.
* generated/iparity_i8.c: Regenerate.
* generated/matmulavx128_c10.c: Regenerate.
* generated/matmulavx128_c16.c: Regenerate.
* generated/matmulavx128_c17.c: Regenerate.
* generated/matmulavx128_c4.c: Regenerate.
* generated/matmulavx128_c8.c: Regenerate.
* generated/matmulavx128_i1.c: Regenerate.
* generated/matmulavx128_i16.c: Regenerate.
* generated/matmulavx128_i2.c: Regenerate.
* generated/matmulavx128_i4.c: Regenerate.
* generated/matmulavx128_i8.c: Regenerate.
* generated/matmulavx128_r10.c: Regenerate.
* generated/matmulavx128_r16.c: Regenerate.
* generated/matmulavx128_r17.c: Regenerate.
* generated/matmulavx128_r4.c: Regenerate.
* generated/matmulavx128_r8.c: Regenerate.
* generated/maxloc1_16_i1.c: Regenerate.
* generated/maxloc1_16_i16.c: Regenerate.
* generated/maxloc1_16_i2.c: Regenerate.
* generated/maxloc1_16_i4.c: Regenerate.
* generated/maxloc1_16_i8.c: Regenerate.
* generated/maxloc1_16_r10.c: Regenerate.
* generated/maxloc1_16_r16.c: Regenerate.
* generated/maxloc1_16_r17.c: Regenerate.
* generated/maxloc1_16_r4.c: Regenerate.
* generated/maxloc1_16_r8.c: Regenerate.
* generated/maxloc1_4_i1.c: Regenerate.
* generated/maxloc1_4_i16.c: Regenerate.
* generated/maxloc1_4_i2.c: Regenerate.
* generated/maxloc1_4_i4.c: Regenerate.
* generated/maxloc1_4_i8.c: Regenerate.
* generated/maxloc1_4_r10.c: Regenerate.
* generated/maxloc1_4_r16.c: Regenerate.
* generated/maxloc1_4_r17.c: Regenerate.
* generated/maxloc1_4_r4.c: Regenerate.
* generated/maxloc1_4_r8.c: Regenerate.
* generated/maxloc1_8_i1.c: Regenerate.
* generated/maxloc1_8_i16.c: Regenerate.
* generated/maxloc1_8_i2.c: Regenerate.
* generated/maxloc1_8_i4.c: Regenerate.
* generated/maxloc1_8_i8.c: Regenerate.
* generated/maxloc1_8_r10.c: Regenerate.
* generated/maxloc1_8_r16.c: Regenerate.
* generated/maxloc1_8_r17.c: Regenerate.
* generated/maxloc1_8_r4.c: Regenerate.
* generated/maxloc1_8_r8.c: Regenerate.
* generated/maxval_i1.c: Regenerate.
* generated/maxval_i16.c: Regenerate.
* generated/maxval_i2.c: Regenerate.
* generated/maxval_i4.c: Regenerate.
* generated/maxval_i8.c: Regenerate.
* generated/maxval_r10.c: Regenerate.
* generated/maxval_r16.c: Regenerate.
* generated/maxval_r17.c: Regenerate.
* generated/maxval_r4.c: Regenerate.
* generated/maxval_r8.c: Regenerate.
* generated/minloc1_16_i1.c: Regenerate.
* generated/minloc1_16_i16.c: Regenerate.
* generated/minloc1_16_i2.c: Regenerate.
* generated/minloc1_16_i4.c: Regenerate.
* generated/minloc1_16_i8.c: Regenerate.
* generated/minloc1_16_r10.c: Regenerate.
* generated/minloc1_16_r16.c: Regenerate.
* generated/minloc1_16_r17.c: Regenerate.
* generated/minloc1_16_r4.c: Regenerate.
* generated/minloc1_16_r8.c: Regenerate.
* generated/minloc1_4_i1.c: Regenerate.
* generated/minloc1_4_i16.c: Regenerate.
* generated/minloc1_4_i2.c: Regenerate.
* generated/minloc1_4_i4.c: Regenerate.
* generated/minloc1_4_i8.c: Regenerate.
* generated/minloc1_4_r10.c: Regenerate.
* generated/minloc1_4_r16.c: Regenerate.
* generated/minloc1_4_r17.c: Regenerate.
* generated/minloc1_4_r4.c: Regenerate.
* generated/minloc1_4_r8.c: Regenerate.
* generated/minloc1_8_i1.c: Regenerate.
* generated/minloc1_8_i16.c: Regenerate.
* generated/minloc1_8_i2.c: Regenerate.
* generated/minloc1_8_i4.c: Regenerate.
* generated/minloc1_8_i8.c: Regenerate.
* generated/minloc1_8_r10.c: Regenerate.
* generated/minloc1_8_r16.c: Regenerate.
* generated/minloc1_8_r17.c: Regenerate.
* generated/minloc1_8_r4.c: Regenerate.
* generated/minloc1_8_r8.c: Regenerate.
* generated/minval_i1.c: Regenerate.
* generated/minval_i16.c: Regenerate.
* generated/minval_i2.c: Regenerate.
* generated/minval_i4.c: Regenerate.
* generated/minval_i8.c: Regenerate.
* generated/minval_r10.c: Regenerate.
* generated/minval_r16.c: Regenerate.
* generated/minval_r17.c: Regenerate.
* generated/minval_r4.c: Regenerate.
* generated/minval_r8.c: Regenerate.
* generated/norm2_r10.c: Regenerate.
* generated/norm2_r16.c: Regenerate.
* generated/norm2_r17.c: Regenerate.
* generated/norm2_r4.c: Regenerate.
* generated/norm2_r8.c: Regenerate.
* generated/parity_l1.c: Regenerate.
* generated/parity_l16.c: Regenerate.
* generated/parity_l2.c: Regenerate.
* generated/parity_l4.c: Regenerate.
* generated/parity_l8.c: Regenerate.

8 weeks ago[PR modula2/119650, PR modula2/117203]: WriteString and Delete are missing from base...
Gaius Mulley [Sat, 7 Jun 2025 15:25:19 +0000 (16:25 +0100)] 
[PR modula2/119650, PR modula2/117203]: WriteString and Delete are missing from base libraries

This patch introduces a Write procedure for an array of char,
the string and char datatype.  It uses the m2r10 style of
naming the module on the datatype.  This uncovered a bug
in the import handling inside Quadident.  It also includes
an Unlink procedure from a new module FileSysOp and a String
interface to this module.

gcc/m2/ChangeLog:

PR modula2/119650
PR modula2/117203
* gm2-compiler/P2Build.bnf (CheckModuleQualident): New
procedure.
(Qualident): Rewrite.
* gm2-compiler/P3Build.bnf (PushTFQualident): New procedure.
(CheckModuleQualident): Ditto.
(Qualident): Rewrite.
* gm2-compiler/PCBuild.bnf (PushTFQualident): New procedure.
(CheckModuleQualident): Ditto.
(Qualident): Rewrite.
* gm2-compiler/PHBuild.bnf (PushTFQualident): New procedure.
(CheckModuleQualident): Ditto.
(Qualident): Rewrite.
* gm2-libs/ARRAYOFCHAR.def: New file.
* gm2-libs/ARRAYOFCHAR.mod: New file.
* gm2-libs/CFileSysOp.def: New file.
* gm2-libs/CHAR.def: New file.
* gm2-libs/CHAR.mod: New file.
* gm2-libs/FileSysOp.def: New file.
* gm2-libs/FileSysOp.mod: New file.
* gm2-libs/String.def: New file.
* gm2-libs/String.mod: New file.
* gm2-libs/StringFileSysOp.def: New file.
* gm2-libs/StringFileSysOp.mod: New file.

libgm2/ChangeLog:

PR modula2/119650
PR modula2/117203
* libm2pim/Makefile.am (M2MODS): Add ARRAYOFCHAR,
CHAR.mod, StringFileSysOp.mod and String.mod.
(M2DEFS): Add ARRAYOFCHAR, CHAR.mod,
StringFileSysOp.mod and String.mod.
(libm2pim_la_SOURCES): Add CFileSysOp.c.
* libm2pim/Makefile.in: Regenerate.
* libm2pim/CFileSysOp.cc: New file.

gcc/testsuite/ChangeLog:

PR modula2/119650
* gm2/iso/fail/CHAR.mod: New test.
* gm2/iso/run/pass/CHAR.mod: New test.
* gm2/iso/run/pass/importself.mod: New test.
* gm2/pimlib/run/pass/testwrite.mod: New test.
* gm2/pimlib/run/pass/testwritechar.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
8 weeks ago[to-be-committed][RISC-V] Handle 32bit operands in condition for conditional moves
Jeff Law [Sat, 7 Jun 2025 13:48:46 +0000 (07:48 -0600)] 
[to-be-committed][RISC-V] Handle 32bit operands in condition for conditional moves

So here's the next chunk of conditional move work from Shreya.

It's been a long standing wart that the conditional move expander does not
support sub-word operands in the comparison.  Particularly since we have
support routines to handle the necessary extensions for that case.

This patch adjusts the expander to use riscv_extend_comparands rather than fail
for that case.  I've built spec2017 before/after this and we definitely get
more conditional moves and they look sensible from a performance standpoint.
None are likely hitting terribly hot code, so I wouldn't expect any performance
jumps.

Waiting on pre-commit testing to do its thing.

* config/riscv/riscv.cc (riscv_expand_conditional_move): Use
riscv_extend_comparands to extend sub-word comparison arguments.

Co-authored-by: Jeff Law <jlaw@ventanamicro.com>
8 weeks agoFix index of some warnings [PR120572]
Andrew Pinski [Sat, 7 Jun 2025 04:50:27 +0000 (21:50 -0700)] 
Fix index of some warnings [PR120572]

The problem here is opindex should not include the `-` part of the option.
But Wmusttail-local-addr and Wno-maybe-musttail-local-addr currently do.
This deletes them.

Pushed as obvious after building the html.

PR tree-optimization/120572
gcc/ChangeLog:

* doc/invoke.texi (Wmusttail-local-addr,
Wno-maybe-musttail-local-addr): Fix opindex.
* common.opt.urls: Regenerate.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 weeks agoDaily bump.
GCC Administrator [Sat, 7 Jun 2025 00:19:12 +0000 (00:19 +0000)] 
Daily bump.

8 weeks agocobol: Diagnostic messages, Flex build, and some cppcheck reports. [PR120328, PR119695]
Robert Dubner [Fri, 6 Jun 2025 20:32:22 +0000 (16:32 -0400)] 
cobol: Diagnostic messages, Flex build, and some cppcheck reports. [PR120328, PR119695]

Remove %0x and similar from diagnostic framework messages.  Remove %zu
from printf messages because it is not supported on some
platforms. Corrections in response to cppcheck.  Sundry small fixes.

gcc/cobol/ChangeLog:

PR cobol/120328
* Make-lang.in: Success with non-English locale.
PR cobol/119695
* cbldiag.h (cbl_unimplemented_at): Comment:
* cdf-copy.cc (copybook_elem_t::open_file): Indentation.
* cdf.y: YYABORT on certain errors.
* cdfval.h (cdf_value): Const parameter.
* copybook.h (class copybook_elem_t): Initialization.
(class uppername_t): Explicit constructor.
* except.cc (ec_type_descr): Remove %04s.
(cbl_enabled_exceptions_t::dump): Remove %zu.
* exceptg.h (class exception_turn_t): Explicit constructor.
* genapi.cc (parser_perform_conditional): Remove %zu.
(set_exception_environment): Formatting.
(parser_statement_begin): Exception overhead.
(parser_perform_conditional): Formatting:
(parser_perform_conditional_end): Eliminate size_t.
(parser_check_fatal_exception): Exception overhead.
(parser_perform_conditional_end): Remove %zu.
* inspect.h (struct cbx_inspect_match_t): Const reference.
(struct cbx_inspect_t): Const parameter.
* lexio.cc (cdftext::process_file): Remove %zu.
* lexio.h (struct YYLTYPE): Remove unneeded struct.
(YYLTYPE_IS_DECLARED): Likewise.
(YYLTYPE_IS_TRIVIAL): Likewise.
* parse.y: Comment; change DOT.
* scan.l: Scan function names without swallowing whitespace.
* scan_ante.h (scanner_parsing): Remove %zu.
(scanner_parsing_pop): Remove %zu.
(binary_integer_usage): Remove %zu.
* scan_post.h (prelex): Correct post-CDF resumption.
(yylex): Clearer message.
* symbols.cc (symbol_table_extend): Explicit constructor.
(elementize): Const parameter.
(is_variable_length): Correct always-false.
(symbols_update): Remove unnecessary shadow variable.
(struct symbol_elem_t): Const parameter.
(symbol_alphabet_add): Const parameter.
(new_literal_add): Initialization.
* symbols.h (class cbl_domain_elem_t): Correct assignment.
(struct cbl_span_t): Improve constructor.
(struct cbl_refer_t): Initialization.
(struct cbl_alphabet_t): Rename shadow variable.
(struct cbl_file_key_t): Remove unused constructor.
(struct symbol_elem_t): Initialization.
(struct cbl_until_addresses_t): Use unsigned int, for messages.
(struct cbl_prog_hier_t): Initialization.
(struct cbl_perform_tgt_t): Repair constructor.
(struct cbl_label_t): Const parameter.
(symbol_typedef_add): Const parameter.
(symbol_field_add): Explicit constructor.
(symbol_label_add): Explicit constructor.
(symbol_program_add): Remove C-style "struct" use.
(symbol_special_add): Remove C-style "struct" use.
(symbol_alphabet_add): Const parameter.
(symbol_file_add): Remove C-style "struct" use.
(symbol_section_add): Remove C-style "struct" use.
* symfind.cc: Const parameter.
* util.cc (gb4): New function.
* util.h (gb4): New function.
* TODO: New file.

libgcobol/ChangeLog:

* common-defs.h (enum cbl_file_mode_t): Whitespace.
(enum file_stmt_t): Likewise.
(ec_cmp): Likewise.
(struct cbl_declarative_t): Add "explicit" keyword.
(class cbl_enabled_exceptions_t): Whitespace.
* gfileio.cc: Remove cppcheck comment.
* libgcobol.cc (class ec_status_t): Add "explicit" keyword.
(match_declarative): Remove %zu.
(default_exception_handler): Likwise.
(__gg__check_fatal_exception): Exception overhead.
(__gg__exception_push): Remove %zu.
(__gg__exception_pop): Likewise.
(cbl_enabled_exception_t::dump): Likewise.
(__gg__match_exception): Exception overhead; remove %zu.
(cbl_enabled_exceptions_t::dump): Remove %zu.
(__gg__set_exception_environment): Likewise.

Co-authored-by: James K. Lowden <jklowden@cobolworx.com>
Co-authored-by: Robert Dubner <rdubner@symas.com>
8 weeks agoc++: recursive template with deduced return [PR120555]
Jason Merrill [Fri, 6 Jun 2025 14:26:28 +0000 (10:26 -0400)] 
c++: recursive template with deduced return [PR120555]

Here since r15-4120 we were prematurely complaining about the use of func
within its own definiton, which is fine at instantiation time.  So don't
require this for function templates that are currently being defined.

But keep the error for instantiations of templates that are not currently
being defined, which we similarly did not diagnose before r15-4120 but other
implementations do.

Both of these follow the general principle from [temp.res.general]/6 that we
only error in a template body if no instatiation could be well-formed.

Also remove a redundant call to require_deduced_type.

PR c++/120555

gcc/cp/ChangeLog:

* decl2.cc (fn_being_defined, fn_template_being_defined): New.
(mark_used): Check fn_template_being_defined.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/constexpr-if39.C: New test.

8 weeks agolibstdc++: Add more tests for semaphores
Jonathan Wakely [Fri, 6 Jun 2025 16:18:40 +0000 (17:18 +0100)] 
libstdc++: Add more tests for semaphores

libstdc++-v3/ChangeLog:

* testsuite/30_threads/semaphore/1.cc: Check type properties and
max() values.
* testsuite/30_threads/semaphore/3.cc: New test.
* testsuite/30_threads/semaphore/cons_neg.cc: New test.

8 weeks agolibstdc++: Use std::conditional_t instead of lambda to select semaphore implementation
Jonathan Wakely [Fri, 6 Jun 2025 13:16:15 +0000 (14:16 +0100)] 
libstdc++: Use std::conditional_t instead of lambda to select semaphore implementation

The lambda expression causes testsuite failures such as:
FAIL g++.dg/modules/xtreme-header-2_b.C -std=c++26 (test for excess errors)

libstdc++-v3/ChangeLog:

* include/bits/semaphore_base.h (_Select_semaphore_impl): Rename
to _Semaphore_impl and use std::conditional_t instead of an
immediately invoked lambda expression.
* include/std/semaphore (counting_semaphore): Adjust to use new
name.

8 weeks agodiagnostics: introduce xml::doctypedecl to avoid hardcoding html
David Malcolm [Fri, 6 Jun 2025 17:41:28 +0000 (13:41 -0400)] 
diagnostics: introduce xml::doctypedecl to avoid hardcoding html

As further generalization of XML support during prototyping of new
features, don't hardcode the HTML DTD.

gcc/ChangeLog:
* diagnostic-format-html.cc (struct html_doctypedecl): New.
(html_builder::html_builder): Use it to populate the document's
m_doctypedecl.
* xml.cc (xml::document::write_as_xml): Replace hardcoded HTML DTD
with use of m_doctypedecl field.
(selftest::test_no_dtd): New.
(selftest::xml_cc_tests): New.
* xml.h (struct doctypedecl): New decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 weeks agodiagnostics: move xml defs to a new xml.cc
David Malcolm [Fri, 6 Jun 2025 17:41:27 +0000 (13:41 -0400)] 
diagnostics: move xml defs to a new xml.cc

While prototyping new features I'm finding it helpful to use XML
beyond the "experimental-html" diagnostics sink.  Move the
implementation of the xml classes to their own file.

No functional change intended.

gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add xml.o.
* diagnostic-format-html.cc (namespace xml): Move implementation
to xml.cc
(selftest::test_printer): Likewise.
(selftest::test_attribute_ordering): Likewise.
(selftest::diagnostic_format_html_cc_tests): Don't call the moved
tests here; they will be called from xml_cc_tests in xml.cc.
* selftest-run-tests.cc (selftest::run_tests): Call xml_cc_tests.
* selftest.h (selftest::xml_cc_tests): New decl.
* xml.cc: New file, based on material from
diagnostic-format-html.cc.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 weeks agoselftest.h: fix sort order of decls
David Malcolm [Fri, 6 Jun 2025 17:41:27 +0000 (13:41 -0400)] 
selftest.h: fix sort order of decls

No functional change intended.

gcc/ChangeLog:
* selftest.h: Fix the sorting of the various *_cc_tests decls.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 weeks agotext-art: allow wrapper_widget to have no child
David Malcolm [Fri, 6 Jun 2025 17:41:27 +0000 (13:41 -0400)] 
text-art: allow wrapper_widget to have no child

During prototyping a feature I found it useful for
text_art::wrapper_widget to be able to not have a child.

gcc/ChangeLog:
* text-art/widget.cc (selftest::test_empty_wrapper_widget): New.
(selftest::text_art_widget_cc_tests): Call it.
* text-art/widget.h (text_art::wrapper_widget::calc_req_size):
Gracefully handle m_child being null.
(text_art::wrapper_widget::update_child_alloc_rects): Likewise.
(text_art::wrapper_widget::paint_to_canvas): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 weeks agocselim: Update the vop manually for cond_if_else_store replacement
Andrew Pinski [Thu, 5 Jun 2025 22:03:27 +0000 (15:03 -0700)] 
cselim: Update the vop manually for cond_if_else_store replacement

To speed up things slightly, we can do the update of the vop for the
newly inserted store manually.
This will also allow a simplified part of cselim to be used inside
phi-opt to move the store out earlier and independent of the full cselim.

gcc/ChangeLog:

* tree-ssa-phiopt.cc (cond_if_else_store_replacement_1): Add vphi argument.
Manually update the vphi and new_stmt vdef/lhs.
(cond_if_else_store_replacement): Update call to cond_if_else_store_replacement_1.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agolibstdc++: Adjust effective-target requirements for <barrier> and <semaphore>
Jonathan Wakely [Wed, 4 Jun 2025 19:09:21 +0000 (20:09 +0100)] 
libstdc++: Adjust effective-target requirements for <barrier> and <semaphore>

These features depend on __cpp_lib_atomic_wait which is not available
for freestanding, and is available when either gthreads is supported, or
the target is linux (for futex support).

libstdc++-v3/ChangeLog:

* testsuite/30_threads/barrier/1.cc: Require hosted. Only
require gthreads for non-linux targets.
* testsuite/30_threads/barrier/2.cc: Likewise.
* testsuite/30_threads/semaphore/1.cc: Likewise.
* testsuite/30_threads/semaphore/2.cc: Likewise.
* testsuite/30_threads/semaphore/cons.cc: Likewise.
* testsuite/30_threads/semaphore/least_max_value_neg.cc:
Likewise.
* testsuite/30_threads/semaphore/try_acquire.cc: Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months ago[committed] Fix compromised ARC test
Jeff Law [Fri, 6 Jun 2025 14:45:53 +0000 (08:45 -0600)] 
[committed] Fix compromised ARC test

Jakub's recent changes for pr120231 compromised this arc port specific test.
Essentially we collapse the entire FMA sequence down to a constant and thus
never emit the FMA instruction the test wants to see.

If we make "a" an extern so that we don't know its value the optimizers can't
collapse the calculation away completely and we can verify that we get an FMA
operation.

Pushing to the trunk.

gcc/testsuite
* gcc.target/arc/fma-1.c: Make "a" extern so the optimizers can
see any value and optimize away the key computation.

2 months agoOpenMP: Add omp_get_initial_device/omp_get_num_devices builtins
Tobias Burnus [Fri, 6 Jun 2025 14:22:06 +0000 (16:22 +0200)] 
OpenMP: Add omp_get_initial_device/omp_get_num_devices builtins

By adding omp_get_initial_device and omp_get_num_devices builtins for
C, C++, and Fortran, the following can be achieved:
* By making them pure, multiple calls can be avoiding in some cases.
* Some comparisons can be optimized at compile time.

omp_get_initial_device will be converted to omp_get_num_devices for
consistency; note that OpenMP 6 also permits omp_initial_device (== -1)
as value.

If GCC has not been configure for offloading, either intrinsic will
leads to 0 - and on the offload side, -1 (= omp_initial_device) is
returned for omp_initial_device.

gcc/fortran/ChangeLog:

* f95-lang.cc (ATTR_PURE_NOTHROW_LIST): Define.
* trans-expr.cc (get_builtin_fn): Handle omp_get_num_devices
and omp_get_intrinsic_device.
* gfortran.h (gfc_option_t): Add disable_omp_... for them.
* options.cc (gfc_handle_option): Handle them with
-fno-builtin-.

gcc/ChangeLog:

* gimple-fold.cc (gimple_fold_builtin_omp_get_initial_device,
gimple_fold_builtin_omp_get_num_devices): New.
(gimple_fold_builtin): Call them.
* omp-builtins.def (BUILT_IN_OMP_GET_INITIAL_DEVICE): Add
(BUILT_IN_OMP_GET_NUM_DEVICES): Make uservisible + pure.

libgomp/ChangeLog:

* libgomp.texi (omp_get_num_devices, omp_get_intrinsic_device):
Document builtin handling.

gcc/testsuite/ChangeLog:

* c-c++-common/gomp/omp_get_num_devices_initial_device-2.c: New test.
* c-c++-common/gomp/omp_get_num_devices_initial_device.c: New test.
* gfortran.dg/gomp/omp_get_num_devices_initial_device-2.f90: New test.
* gfortran.dg/gomp/omp_get_num_devices_initial_device.f90: New test.

Co-authored-by: Sandra Loosemore <sloosemore@baylibre.com>
2 months agobuiltins.def: Enable OpenMP/OpenACC builtins also with -fno-nonansi-builtins
Tobias Burnus [Fri, 6 Jun 2025 13:57:50 +0000 (15:57 +0200)] 
builtins.def: Enable OpenMP/OpenACC builtins also with -fno-nonansi-builtins

The flags -std=c.. and -std=c++.. imply -fno-nonansi-builtins, which disabled
the OpenMP/OpenACC intrinsics - but -fopenmp/-fopenacc builtin use should be
rather othogonal to the user's choice between -std=c... and -std=gnuc...

gcc/ChangeLog:

* builtins.def (DEF_GOACC_BUILTIN_COMPILER, DEF_GOMP_BUILTIN_COMPILER):
Set NONANSI_P = false to enable those also with -fno-nonansi-builtins.

2 months agoRemove non-SLP path from get_[group_]load_store_type
Richard Biener [Fri, 6 Jun 2025 11:32:49 +0000 (13:32 +0200)] 
Remove non-SLP path from get_[group_]load_store_type

The following removes the non-SLP path from get_group_load_store_type
and get_load_store_type.

* tree-vect-stmts.cc (get_group_load_store_type): Remove
non-SLP path.
(get_load_store_type): Likewise.

2 months agolibstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]
Patrick Palka [Fri, 6 Jun 2025 13:34:17 +0000 (09:34 -0400)] 
libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]

The const lvalue operator[] overload wasn't properly forwarding the key
type to the generic overload, causing a hard error for const keys.

Rather than correcting the forwarded type this patch just makes the
non-template overloads call try_emplace directly instead.  That way we
can remove the non-standard same_as constraint on the generic overload
and match the spec more closely.

PR libstdc++/120432

libstdc++-v3/ChangeLog:

* include/std/flat_map (flat_map::operator[]): Make the
non-template overloads call try_emplace directly.  Remove
non-standard same_as constraint on the template overload.
* testsuite/23_containers/flat_map/1.cc (test08): New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2 months agoRISC-V: Reconcile the existing test for vdivu.vx combine
Pan Li [Fri, 6 Jun 2025 02:03:50 +0000 (10:03 +0800)] 
RISC-V: Reconcile the existing test for vdivu.vx combine

Some existing vdiv related test need some adjust for the
asm check due to cost model.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv-nofm.c: Adjust
the asm check for vdivu.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv32gcv.c: Ditto.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv-nofm.c: Ditto.
* gcc.target/riscv/rvv/autovec/binop/vdiv-rv64gcv.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Add test for vec_duplicate + vdivu.vv combine case 1 with GR2VR cost 0, 1...
Pan Li [Fri, 6 Jun 2025 01:51:10 +0000 (09:51 +0800)] 
RISC-V: Add test for vec_duplicate + vdivu.vv combine case 1 with GR2VR cost 0, 1 and 2

Add asm dump check test for vec_duplicate + vdivu.vv combine to vdivu.vx,
with the GR2VR cost is 0, 1 and 2.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u16.c: Add asm check
for vdivu.vx combine.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-4-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-5-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-6-u8.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Add test for vec_duplicate + vdivu.vv combine case 0 with GR2VR cost 0, 2...
Pan Li [Fri, 6 Jun 2025 01:49:56 +0000 (09:49 +0800)] 
RISC-V: Add test for vec_duplicate + vdivu.vv combine case 0 with GR2VR cost 0, 2 and 15

Add asm dump check test for vec_duplicate + vdivu.vv combine to vdivu.vx,
with the GR2VR cost is 0, 2 and 15.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u16.c: Add asm check
for vdivu.vx combine.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-1-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-2-u8.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u16.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u32.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u64.c: Ditto.
* gcc.target/riscv/rvv/autovec/vx_vf/vx-3-u8.c: Ditto.
* 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_vdiv-run-1-u16.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u32.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u64.c: New test.
* gcc.target/riscv/rvv/autovec/vx_vf/vx_vdiv-run-1-u8.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agoRISC-V: Combine vec_duplicate + vidvu.vv to vdivu.vx on GR2VR cost
Pan Li [Fri, 6 Jun 2025 01:33:21 +0000 (09:33 +0800)] 
RISC-V: Combine vec_duplicate + vidvu.vv to vdivu.vx on GR2VR cost

This patch would like to combine the vec_duplicate + vdivu.vv to the
vdivu.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_BINARY(T, OP)                                        \
  void                                                                \
  test_vx_binary (T * restrict out, T * restrict in, T x, unsigned n) \
  {                                                                   \
    for (unsigned i = 0; i < n; i++)                                  \
      out[i] = in[i] OP x;                                            \
  }

  DEF_VX_BINARY(int32_t, /)

Before this patch:
  10   │ test_vx_binary_or_int32_t_case_0:
  11   │     beq a3,zero,.L8
  12   │     vsetvli a5,zero,e32,m1,ta,ma
  13   │     vmv.v.x v2,a2
  14   │     slli    a3,a3,32
  15   │     srli    a3,a3,32
  16   │ .L3:
  17   │     vsetvli a5,a3,e32,m1,ta,ma
  18   │     vle32.v v1,0(a1)
  19   │     slli    a4,a5,2
  20   │     sub a3,a3,a5
  21   │     add a1,a1,a4
  22   │     vdivu.vv v1,v1,v2
  23   │     vse32.v v1,0(a0)
  24   │     add a0,a0,a4
  25   │     bne a3,zero,.L3

After this patch:
  10   │ test_vx_binary_or_int32_t_case_0:
  11   │     beq a3,zero,.L8
  12   │     slli    a3,a3,32
  13   │     srli    a3,a3,32
  14   │ .L3:
  15   │     vsetvli a5,a3,e32,m1,ta,ma
  16   │     vle32.v v1,0(a1)
  17   │     slli    a4,a5,2
  18   │     sub a3,a3,a5
  19   │     add a1,a1,a4
  20   │     vdivu.vx v1,v1,a2
  21   │     vse32.v v1,0(a0)
  22   │     add a0,a0,a4
  23   │     bne a3,zero,.L3

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_vx_binary_vec_vec_dup): Add new
case UDIV.
* config/riscv/riscv.cc (riscv_rtx_costs): Ditto.
* config/riscv/vector-iterators.md: Add new op divu.

Signed-off-by: Pan Li <pan2.li@intel.com>
2 months agolibgomp.c/target-map-zero-sized-3.c: Fix code for non-USM offload [PR120530]
Tobias Burnus [Fri, 6 Jun 2025 13:15:03 +0000 (15:15 +0200)] 
libgomp.c/target-map-zero-sized-3.c: Fix code for non-USM offload [PR120530]

A mapping clause was missing, causing the code to fail with offloading
when a host pointer was not device accessible.

libgomp/ChangeLog:

PR target/120530
* testsuite/libgomp.c/target-map-zero-sized-3.c (main): Add missing
map clause; remove unused variable.

2 months agoRemove non-SLP path from vectorizable_store
Richard Biener [Fri, 6 Jun 2025 10:22:36 +0000 (12:22 +0200)] 
Remove non-SLP path from vectorizable_store

This prunes now unreachable paths from vectorizable_store,
eliminates the toplevel ncopies and loops that become non-loops.
And eliminates the use of STMT_VINFO_VECTYPE.

* tree-vect-stmts.cc (vectorizable_store): Remove non-SLP
paths.

2 months agoRemove create_tmp_reg_or_ssa_name
Richard Biener [Fri, 6 Jun 2025 09:44:18 +0000 (11:44 +0200)] 
Remove create_tmp_reg_or_ssa_name

Now that create_tmp_reg_or_ssa_name just calls make_ssa_name replace
all of its uses.

* gimple-fold.h (create_tmp_reg_or_ssa_name): Remove.
* gimple-fold.cc (create_tmp_reg_or_ssa_name): Likewise.
(gimple_fold_builtin_memory_op): Use make_ssa_name.
(gimple_fold_builtin_strchr): Likewise.
(gimple_fold_builtin_strcat): Likewise.
(gimple_load_first_char): Likewise.
(gimple_fold_builtin_string_compare): Likewise.
(gimple_build): Likewise.
* tree-inline.cc (copy_bb): Likewise.
* config/rs6000/rs6000-builtin.cc (fold_build_vec_cmp): Likewise.
(rs6000_gimple_fold_mma_builtin): Likewise.
(rs6000_gimple_fold_builtin): Likewise.

2 months agoPR modula2/120542: Return statement in the main procedure crashes the compiler
Gaius Mulley [Fri, 6 Jun 2025 09:46:48 +0000 (10:46 +0100)] 
PR modula2/120542: Return statement in the main procedure crashes the compiler

The patch checks whether a return statement is allowed.  It also checks
to see that a return expression is allowed.

gcc/m2/ChangeLog:

PR modula2/120542
* gm2-compiler/M2Quads.mod (BuildReturnLower): New procedure.
(BuildReturn): Allow return without an expression from
module initialization blocks.  Generate an error if an
expression is provided.  Call BuildReturnLower if no error
was seen.

gcc/testsuite/ChangeLog:

PR modula2/120542
* gm2/iso/fail/badreturn.mod: New test.
* gm2/iso/fail/badreturn2.mod: New test.
* gm2/iso/pass/modulereturn.mod: New test.
* gm2/iso/pass/modulereturn2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2 months agoFix assertion failure on small array constructor
Eric Botcazou [Fri, 6 Jun 2025 09:32:51 +0000 (11:32 +0200)] 
Fix assertion failure on small array constructor

The Ada testcase triggers an assertion failure in size_binop_loc:

+===========================GNAT BUG DETECTED==============================+
| 16.0.0 20250605 (experimental) (x86_64-suse-linux) GCC error:            |
| in size_binop_loc, at fold-const.cc:2091                                 |
| Error detected around aggr7.ads:9:36

  gcc_assert (int_binop_types_match_p (code, TREE_TYPE (arg0),
                                       TREE_TYPE (arg1)));

because the very old code for ARRAY_TYPE in store_constructor is confused in
the case where it cannot perform static host-based arithmetics on offsets.

But the root cause is that it performs all the calculations in signed
sizetype while TYPE_DOMAIN is supposed to be a subtype of (unsigned)
sizetype, even for signed index types in Ada like in the testcase,
so the code takes the dynamic path instead of the static one for
negative indices.

gcc/
* expr.cc (store_constructor) <ARRAY_TYPE>: Perform the arithmetics
on offsets in (unsigned) sizetype.

gcc/testsuite/
* gnat.dg/specs/aggr7.ads: New test.

2 months agoAvoid useless reading of profile data in LTO
Jan Hubicka [Fri, 6 Jun 2025 08:56:51 +0000 (10:56 +0200)] 
Avoid useless reading of profile data in LTO

New auto-profile merging dumps made me notice that we read the afdo
data when we are in LTO.  This is not necessary since profile is read
at compile time and streamed to LTO bytecode.

gcc/ChangeLog:

* coverage.cc (coverage_init): Return early when in LTO

2 months agolibstdc++: Add assertions to atomic waiting functions that need platform wait
Jonathan Wakely [Wed, 4 Jun 2025 15:58:45 +0000 (16:58 +0100)] 
libstdc++: Add assertions to atomic waiting functions that need platform wait

These overloads should never be used for proxy waits, so add assertions
to ensure that they aren't used accidentally.

The reason they can't be used is that they don't call
__args._M_setup_wait to obtain a __wait_state pointer. Even if that was
changed, they would wait on a proxy wait which is potentially used by
many other threads waiting on other addresses, meaning spurious wake ups
are likely. In order to make the functions correct they would need to
perform additional loads and comparisons of the atomic variable before
calling __wait_impl or __wait_until_impl, which would make these
functions no faster than the general purpose overloads that take an
accessor function and predicate. That would be possible, and I think
they would then work for proxy waits, but doesn't seem necessary at this
time.

In order to preseve the property that these functions are more
lightweight and efficient than the general ones, they should not be used
for proxy waits.

libstdc++-v3/ChangeLog:

* include/bits/atomic_timed_wait.h (__atomic_wait_address_until_v):
Add assertion to prevent use with proxy waits.
(__atomic_wait_address_for_v): Likewise.
* include/bits/atomic_wait.h (__atomic_wait_address_v):
Likewise.

2 months agolibstdc++: Optimize std::counting_semaphore for futex path
Jonathan Wakely [Wed, 4 Jun 2025 14:53:20 +0000 (15:53 +0100)] 
libstdc++: Optimize std::counting_semaphore for futex path

Rename __semaphore_base to __semaphore_impl, because it's not used as a
base class. Replace the three identical lambda expressions with a named
class, __semaphore_impl::_Available, which stores the most recent
value of the counter as a data member, and provides call operators that
test whether the value is decrementable (i.e. whether the semaphore can
be acquired).

Add a new __platform_semaphore_impl class template to be used when
__platform_wait is available, which uses __platform_wait_t for the
counter and uses more efficient atomic waits for the acquire functions.
For a binary semaphore some members are further optimized because we
know the counter can only be zero or one.

Also add a bare wait flag to __atomic_wait_address_v, for consistency
with __atomic_wait_address_until_v and __atomic_wait_address_for_v and
to allow semaphores to use it without the redundant overhead of tracking
waiters.

libstdc++-v3/ChangeLog:

* include/bits/atomic_wait.h (__atomic_wait_address_v): Add bare
wait flag.
* include/bits/semaphore_base.h (__semaphore_base): Rename to
__semaphore_impl. Replace local variable and predicate lambdas
with _Available struct.
(__platform_semaphore_impl): New class template.
(__semaphore_impl): Remove alias template.
(_Select_semaphore_impl): New alias template.
* include/std/semaphore (counting_semaphore): Use
_Select_semaphore_impl.

2 months agoMore of autofdo 0 issues
Jan Hubicka [Fri, 6 Jun 2025 08:43:38 +0000 (10:43 +0200)] 
More of autofdo 0 issues

This patch fixes ICE seen when building spec2k17 with autofdo and enable
checking compiler.  Bause we special case 0 of autofdo to be kind of 1 in IPA
scalling, we can now end up with function heving global0 profile but producing
inline clone with nonzero profile.

I think correct way is to extend auto-profile generation to merge static profile
with afdo in places afdo profile is missing and drop the autofdo 0 hacks, but
I think we need to run benchmarks first before making broader changes here.

* profile-count.cc (profile_count::to_sreal_scale): Special case 0 of autofdo.
(profile_count::combine_with_ipa_count): If outer function has GLOBAL0 profile
but innter counter has non-zero profile, force it to be 0.

2 months agoada: Avoid repeated range checks when negating a rational number
Piotr Trojanek [Thu, 27 Feb 2025 10:44:54 +0000 (11:44 +0100)] 
ada: Avoid repeated range checks when negating a rational number

Use local constant to avoid repeated range checks (at least in the debug
builds), but also to make the code easier to read and consistent in style
with similar routines in the same package.

gcc/ada/ChangeLog:

* urealp.adb (UR_Negate): Capture array element in a local constant.

2 months agoada: Remove repeated call in exponentiation of rational numbers
Piotr Trojanek [Thu, 27 Feb 2025 10:32:05 +0000 (11:32 +0100)] 
ada: Remove repeated call in exponentiation of rational numbers

Code cleanup.

gcc/ada/ChangeLog:

* urealp.adb (UR_Exponentiate): Use local variable.

2 months agoada: Simplify tests for positive rational numbers
Piotr Trojanek [Mon, 24 Feb 2025 09:40:16 +0000 (10:40 +0100)] 
ada: Simplify tests for positive rational numbers

Checking a rational number for being positive takes a shorter code path than
a general comparison with zero. Code cleanup; semantics is unaffected.

gcc/ada/ChangeLog:

* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Tune code for
attribute Small.
* sem_prag.adb (Analyze_Attribute): Tune code for pragma Time_Slice.

2 months agoada: Tune style in code for floating-point numbers
Piotr Trojanek [Tue, 18 Feb 2025 13:36:53 +0000 (14:36 +0100)] 
ada: Tune style in code for floating-point numbers

Cleanup whitespace and comments.

gcc/ada/ChangeLog:

* ada_get_targ.adb, cstand.ads, cstand.adb, sem_eval.adb, sem_eval.ads,
urealp.adb, urealp.ads: Tune style.

2 months agoada: Add null exclusion to registration of floating-point types
Piotr Trojanek [Tue, 18 Feb 2025 13:38:24 +0000 (14:38 +0100)] 
ada: Add null exclusion to registration of floating-point types

Null exclusion both clarifies the intention of the code and allows GNAT to
eliminate runtime checks where possible (or make them fail where violated), at
least in developer builds. Code cleanup.

gcc/ada/ChangeLog:

* get_targ.ads (Register_Proc_Type): Add null exclusion.

2 months agoada: Refine subtypes in routines for building floating-point numbers
Piotr Trojanek [Tue, 18 Feb 2025 13:37:19 +0000 (14:37 +0100)] 
ada: Refine subtypes in routines for building floating-point numbers

Propagate strict subtypes from callees to the caller; code cleanup.

gcc/ada/ChangeLog:

* cstand.adb (Build_Float_Type, Register_Float_Type): Refine
parameter subtypes.
* set_targ.ads (FPT_Mode_Entry): Refine component subtype.

2 months agoada: Check references to subprogram outputs with Program_Exit expression
Piotr Trojanek [Wed, 26 Feb 2025 13:02:15 +0000 (14:02 +0100)] 
ada: Check references to subprogram outputs with Program_Exit expression

Add check for references to subprogram outputs occurring within the
Program_Exit expression. This check is necessarily partial, as it misses
objects referenced by subprograms called from the Program_Exit expression,
but this is consistent with other checks.

gcc/ada/ChangeLog:

* sem_prag.adb (Analyze_Pragma): Add dependency of Program_Exit on
Global and Depends contracts.
(Analyze_Program_Exit_In_Decl_Part): Check references to subprogram
outputs.

2 months agoada: Add case for Program_Exit in Exit_Cases
Claire Dross [Fri, 17 Jan 2025 13:29:47 +0000 (14:29 +0100)] 
ada: Add case for Program_Exit in Exit_Cases

Extend the syntax for Exit_Cases to support exiting the program.

gcc/ada/ChangeLog:

* doc/gnat_rm/implementation_defined_pragmas.rst
(Pragma Exit_Cases): Update the documentation for Exit_Cases.
* sem_prag.adb
(Anlayze_Pragma): Accept Program_Exit as an exit kind.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

2 months agoada: Support aspect Program_Exit with no expression
Piotr Trojanek [Thu, 13 Feb 2025 15:39:43 +0000 (16:39 +0100)] 
ada: Support aspect Program_Exit with no expression

New aspect Program_Exit for SPARK was originally designed to require an
expression, but now we want this expression to be optional.

gcc/ada/ChangeLog:

* aspects.ads (Aspect_Argument): Argument for Program_Exit is now
optional.
* doc/gnat_rm/implementation_defined_pragmas.rst
(Pragma Program_Exit): Change documentation for pragma syntax.
* sem_prag.adb (Analyze_Pragma): Argument for Program_Exit is now
optional.
(Analyze_Program_Exit_In_Decl_Part): Likewise.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

2 months agoada: Add new aspect Program_Exit for SPARK
Piotr Trojanek [Thu, 13 Feb 2025 15:26:33 +0000 (16:26 +0100)] 
ada: Add new aspect Program_Exit for SPARK

A new aspect Program_Exit is added for SPARK to specify that a subprogram
can exit the entire program, e.g. GNAT.System.OS_Exit. The implementation
is based on the existing machinery for similar aspects, in particular, for
aspects Subprogram_Variant and Always_Terminates.

gcc/ada/ChangeLog:

* aspects.ads (Aspect_Id): Add new aspect identifier.
(Aspect_Argument): Specify argument for the new aspect.
(Is_Representation_Aspect): New aspect is not a representation aspect.
(Aspect_Names): Map new aspect to name.
(Aspect_Delay): New aspect is always delayed.
* contracts.adb (Expand_Subprogram_Contract)
(Add_Pre_Post_Condition, Add_Contract_Item)
(Analyze_Entry_Or_Subprogram_Contract)
(Analyze_Entry_Or_Subprogram_Body_Contract)
(Analyze_Subprogram_Body_Stub_Contract): Support new aspect.
* contracts.ads (Add_Contract_Item,
Analyze_Entry_Or_Subprogram_Contract,
Analyze_Entry_Or_Subprogram_Body_Contract,
Analyze_Subprogram_Body_Stub_Contract): Mention new contract in
comment.
* doc/gnat_rm/implementation_defined_aspects.rst
(Aspect Program_Exit): Document new aspect.
* doc/gnat_rm/implementation_defined_pragmas.rst
(Pragma Program_Exit): Document new pragma.
* einfo-utils.adb (Get_Pragma): Support new pragma.
* einfo-utils.ads (Get_Pragma): Mention new pragma in comment.
* exp_prag.adb (Expand_Pragma_Program_Exit): Expand new pragma;
body.
* exp_prag.ads (Expand_Pragma_Program_Exit): Expand new pragma;
spec.
* inline.adb (Remove_Aspects_And_Pragmas): Support new pragma.
* par-prag.adb (Prag): Support new pragma.
* sem_attr.adb (Analyze_Attribute_Old_Result): Accept attribute
Old in new pragma.
* sem_ch12.adb (Implementation of Generic Contracts): Mention new
aspect in comment.
* sem_ch13.adb (Insert_Pragma, Analyze_Aspect_Specifications):
Convert new new aspect to pragma.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Renumber
subsequent rule in comment.
* sem_prag.adb (Check_Postcondition_Use_In_Inlined_Subprogram)
(Contract_Freeze_Error): Mention new pragma in comment.
(Analyze_Pragma): Support new pragma; renumber subsequent rule in
comment.
(Analyze_Program_Exit_In_Decl_Part): Analyze new pragma; body.
(Sig_Flags): References in new pragma are significant when
detecting unreferenced objects.
* sem_prag.ads (Aspect_Specifying_Pragma)
(Assertion_Expression_Pragma, Pragma_Significant_To_Subprograms):
Support new aspect and pragma.
(Analyze_Program_Exit_In_Decl_Part): Analyze new pragma; spec.
(Find_Related_Package_Or_Body): Mention new pragma in comment.
* sem_util.adb (Is_Subprogram_Contract_Annotation): Support new
pragma.
* sem_util.ads (Is_Subprogram_Contract_Annotation): Mention new
pragma in comment.
* sinfo.ads (Is_Generic_Contract_Pragma): Mention new pragma in
comment.
* snames.ads-tmpl (Preset Names, Pragma_Id): Add name and pragma
identifiers.
* gnat_rm.texi: Regenerate.

2 months agoada: Deconstruct C header for the SCOs unit
Piotr Trojanek [Wed, 26 Feb 2025 17:00:57 +0000 (18:00 +0100)] 
ada: Deconstruct C header for the SCOs unit

The C version of SCOs unit provided a gigi interface to source code obligations
that at some point were generated by the frontend. This functionality has been
deconstructed long ago.

gcc/ada/ChangeLog:

* libgnat/g-dyntab.ads (Instance): Update and extend comment.
* scos.ads: Remove comment about the corresponding C header.
* scos.h: Remove.

2 months agoada: Child unit subprograms are not primitive subprograms
Steve Baird [Tue, 25 Feb 2025 21:51:40 +0000 (13:51 -0800)] 
ada: Child unit subprograms are not primitive subprograms

If a package declares a type and a child unit of that package is a subprogram
with a parameter (or function result) of that type, then that subprogram is
not a primitive subprogram of that type. Previously this was handled
incorrectly in some cases, leading to incorrect analysis of overriding
indicators.

gcc/ada/ChangeLog:

* sem_util.adb (Collect_Primitive_Operations): When collecting
primitive operations, do not include child unit subprograms.

2 months agoada: Constant_Indexing used when context requires a variable
Javier Miranda [Fri, 31 Jan 2025 20:21:09 +0000 (20:21 +0000)] 
ada: Constant_Indexing used when context requires a variable

In the case of an assignment where the type of its left hand side
is an indexable container that has indexable container components
(for example a container vector of container vectors), and both
indexable containers have Constant_Indexing and Variable_Indexing
aspects, the left hand side of the assignment is erroneously
interpreted as constant indexing. The error results in spurious
compile-time error messages saying that the left hand side of
the assignment must be a variable.

gcc/ada/ChangeLog:

* sem_ch4.adb (Constant_Indexing_OK): Add missing support for
RM 4.1.6(13/3), and improve performance to avoid climbing more
than needed. Add documentation.
(Try_Indexing_Function): New subprogram.
(Expr_Matches_In_Formal): Added new formals.
(Handle_Selected_Component): New subprogram.
(Has_IN_Mode): New subprogram.
(Try_Container_Indexing): Add documentation, code reorganization
and extend its functionality to improve its support for prefixed
notation calls.

2 months agoada: Refactor the implementation of gnat diagnostics
Viljar Indus [Tue, 17 Sep 2024 12:37:13 +0000 (15:37 +0300)] 
ada: Refactor the implementation of gnat diagnostics

The goal of this patch is to remove the implementation from the
Diagnostic objects and port the new features over to the
Error_Msg_Objects.

gcc/ada/ChangeLog:

* debug.adb: Mark -gnatd_D as unused.
* diagnostics-repository.adb: Move to...
* errid.adb: ...here.
* diagnostics-repository.ads: Move to...
* errid.ads: ...here.
* errout.adb (Error_Msg_Internal): Add new arguments for the new
attributes of Error_Msg_Objects.
(Error_Msg): Likewise.
(Error_Msg_N): Likewise.
(Labeled_Span): New method for creating Labeled_Span-s
(Primary_Label_Span): New method for creating primary Labeled_Spans.
(Secondary_Labeled_Span): New method for creating secondary
Labeled_Spans.
(Edit): New method for creating Edit elements.
(Fix): New method for creating Fix elements.
(Error_Msg_F): Simplify code for evaluating the span.
(Error_Msg_FE): Likewise.
(Error_Msg_NE): Likewise.
(Error_Msg_NEL): Likewise.
(Error_Msg_N_Gigi): New method that is used as a wrapper for the
Error_Msg_xxx methods that have the new arguments. This function
is later mapped to the Error_Msg method used inside gigi.
(Error_Msg_NE_Gigi): Likewise.
(Write_JSON_Span): Ensure that the Style prefix is included that is
removed when parsing the message is reinserted to the JSON report.
(Output_Messages): Use the new Pretty_Printer and Sarif_Printer
packages to print the messages and remove the old implementation
for the pretty printer.
(Set_Msg_Text): Remove message kind insertion characters from the
final message text to avoid some message kinds being duplicated.
(To_Full_Span_First): New method for creating a span for a node.
(To_Full_Span): Likewise.
* errout.ads: Add the specs for all of the newly added functions.
* diagnostics-pretty_emitter.adb: Move to...
* erroutc-pretty_emitter.adb: ...here.
* diagnostics-pretty_emitter.ads: Move to...
* erroutc-pretty_emitter.ads: ...here.
* diagnostics-sarif_emitter.adb: Move to...
* erroutc-sarif_emitter.adb: ...here.
* diagnostics-sarif_emitter.ads: Move to...
* erroutc-sarif_emitter.ads: ...here.
* erroutc.adb (Next_Error_Msg): New method for iterating to the
next error message.
(Next_Continuation_Msg): New method for iterating to the next
continuation message.
(Primary_Location): New method for returning the first primary
location for the error message.
(Get_Human_Id): New method for returning the human readable
name for the switch associated with this error message.
(Get_Doc_Switch): New method for creating the tag for the switch
used in the error message.
(Output_Text_Within): Change the method to operating on Strings
instead of String pointers.
(Output_Msg_Text): Simplify implementation for generating the
error message.
(Prescan_Message): Make the String handling more error proof.
* erroutc.ads (Error_Msg_Object): Add new attributes that were
added to Diagnostic objects to Error_Msg_Objects.
Add new methods for handling the new error objects.
* diagnostics-switch_repository.adb: Move to...
* errsw.adb: ...here.
* errutil.adb (Error_Msg): Initialize all of the new attributes
added to Error_Msg_Object-s.
* fe.h (Error_Msg_N): Update the binding.
(Error_Msg_NE): Update the binding.
For now the error_msg methods in gigi will use the old
simplified interface for those methods.
* diagnostics-json_utils.adb: Move to...
* json_utils.adb: ...here.
* diagnostics-json_utils.ads: Move to...
* json_utils.ads: ...here.
* par-endh.adb: Replace the old error_msg
calls with the updated interface.
* sem_aggr.adb: Likewise.
* sem_ch13.adb: Likewise.
* sem_ch4.adb: Likewise.
* sem_ch9.adb: Likewise.
* diagnostics-brief_emitter.adb: Removed.
* diagnostics-brief_emitter.ads: Removed.
* diagnostics-constructors.adb: Removed.
* diagnostics-constructors.ads: Removed.
* diagnostics-converter.adb: Removed.
* diagnostics-converter.ads: Removed.
* diagnostics-switch_repository.ads: Removed.
* diagnostics-utils.adb: Removed.
* diagnostics-utils.ads: Removed.
* diagnostics.adb: Removed.
* diagnostics.ads: Removed.
* errsw.ads: New file. Based on diagnostics-switch_repository.ads.
It additionally contains all the switch enumerations.
* gcc-interface/Make-lang.in: Update compilation dependencies.
* gcc-interface/Makefile.in: Likewise.

2 months agoada: Set Ekind early for entities created in expansion
Ronan Desplanques [Wed, 26 Feb 2025 10:22:45 +0000 (11:22 +0100)] 
ada: Set Ekind early for entities created in expansion

This patch adds early Ekind assignments to entities created for the
expansion of a few constructs. The only effect is to enable more dynamic
checks for the uses of those entities that used to happen before the
Ekind had been set.

gcc/ada/ChangeLog:

* contracts.adb (Add_Invariant_And_Predicate_Checks): Assign Ekind.
* inline.adb (Expand_Inlined_Call): Likewise.
* exp_ch9.adb (Build_Simple_Entry_Call): Likewise.
* exp_dist.adb (Append_Array_Traversal): Likewise.
* exp_fixd.adb (Build_Double_Divide_Code, Build_Scaled_Divide_Code):
Likewise.

2 months agoada: Rework Android struct sigaction bindings
Olivier Hainque [Fri, 21 Feb 2025 08:18:38 +0000 (08:18 +0000)] 
ada: Rework Android struct sigaction bindings

A previous change arranged for the common definition of
struct_sigaction in s-osinte__android.ads to work both for
ARM and aarch64 by way of representation clauses with
field offsets taken from specialized versions of s-linux
(one for ARM, one for aarch64).

The aarch64 variant had the offsets wrong, placing the
sa_handler pointer at offset 4, following the sa_flags int
at offset 0. The pointer is 8 bytes wide so should be
placed at an offset multiple of 8. This caused a discrepancy
between the Ada runtime actions and the expectations of the
underlying libc functions called.

This change refactors the struct_sigaction definition
to instanciate an entire type provided by s-linux instead,
parametrized by sigset_t which needs to remain provided
by the common System.OS_Interface spec.

gcc/ada/ChangeLog:

* libgnarl/s-linux__android-aarch64.ads: Provide an
Android_Sigaction generic package to expose an aarch64
version of struct_sigation, using a provided sigset_t
for sa_flags.
* libgnarl/s-linux__android-arm.ads: Likewise, for ARM
rather than aarch64.
* libgnarl/s-osinte__android.ads: Move sigset_t definition
to the visible part and use it to instantiate the Android_Sigation
generic provided by System.Linux, which is specialized for ARM vs
aarch64. Define struct_sigaction out of the Android_Sigaction
instance, remove the local representation clauses.

2 months agoada: Adjust the Android RTS config to match linux
Olivier Hainque [Wed, 12 Feb 2025 17:15:00 +0000 (17:15 +0000)] 
ada: Adjust the Android RTS config to match linux

Android has many traits of Linux, reflected
by the gcc port triplets composition (<cpu>-android-linux).

The Android Ada RTS was so far configured as a mostly "posix"
port, which happens to be very little tested, if at all.

This change reworks the Android Ada RTS to map a lot more closely
to that of a regular Linux target, a natural fit and much more toroughly
exercized.

This expects support of pthread rwlocks in the bionic libc,
which is there in the not-so-old-but-not-so-recent versions we
tested (Android 11 at least).

gcc/ada/ChangeLog:

* Makefile.rtl: Rework the Android pairs to match those of a
regular Linux port rather than a generic posix one.
* libgnarl/s-osinte__android.ads: Import pcrtl and add bindings
for the pthread_rwlock entry points, used by the Linux units now
in the libgnat target pairs.
* sysdep.c (__gnat_has_cap_sys_nice): Define for Android,
conservative return 0.
* adaint.c (__gnat_cpu_alloc): Define for Android as for Linux.

2 months agoada: Document representation clauses previously required by ASIS
Piotr Trojanek [Tue, 25 Feb 2025 11:48:32 +0000 (12:48 +0100)] 
ada: Document representation clauses previously required by ASIS

A record type used for name identifiers had representation clause to make sure
that table with identifiers is written to an ASIS file without holes. Now ASIS
mode has been deconstructed, but we still want this representation clause to
ensure efficient implementation.

Comment update; behavior is unaffected.

gcc/ada/ChangeLog:

* namet.ads (Name_Entry): Update comments to explain the current needs.

2 months agoada: Deconstruct representation clauses required by ASIS
Piotr Trojanek [Mon, 24 Feb 2025 13:19:46 +0000 (14:19 +0100)] 
ada: Deconstruct representation clauses required by ASIS

When GNAT was operating in ASIS mode, it was writing internal tables to files,
so we annotated record types for elements stored in these tables with
representation clauses to avoid holes with potentially uninitialized data.

Since ASIS mode has been now deconstructed and we no longer write internal
tables to files, we can remove explicit representation clauses and rely on the
data layout chosen by the compiler.

Code cleanup; behavior is unaffected.

gcc/ada/ChangeLog:

* lib.ads (Unit_Record): Remove representation clauses and filler
components
* lib-load.adb, lib-writ.adb: Remove initialization of data fillers.
* nlists.adb (Allocate_List_Tables): Remove explicit initialization.
* repinfo.adb (Exp_Node): Remove representation clauses.
* sinput.ads (Source_File_Record): Likewise.
* urealp.adb (Ureal_Entry): Likewise.

2 months agoada: Fix typo in documentation about convention and representation
Piotr Trojanek [Tue, 25 Feb 2025 12:02:38 +0000 (13:02 +0100)] 
ada: Fix typo in documentation about convention and representation

Currently there are only three exceptions to the general rule; the fourth
exception applied to OpenVMS, whose support has been deconstructed.

gcc/ada/ChangeLog:

* doc/gnat_rm/representation_clauses_and_pragmas.rst
(Effect of Convention on Representation): Fix number of list items.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

2 months agoada: Fix libgpr2 build failure with compiler built with assertions
Eric Botcazou [Mon, 24 Feb 2025 21:27:21 +0000 (22:27 +0100)] 
ada: Fix libgpr2 build failure with compiler built with assertions

The problem is that the Entity field is accessed for a node without one.

gcc/ada/ChangeLog:

* sem_ch10.adb (Install_Siblings.In_Context): Add missing guard.

2 months agoada: Tweak condition for name resolution failure
Ronan Desplanques [Fri, 21 Feb 2025 16:32:35 +0000 (17:32 +0100)] 
ada: Tweak condition for name resolution failure

It is sometimes used as a convention across GNAT's code to set the Etype
field of a node to Any_Type to signal a name resolution error. This has
the potential to be confusing, which is why this patch replaces one such
use of the convention by a less convoluted check.

This only affects error recovery paths, and possibly doesn't change the
behavior of the compiler at all.

gcc/ada/ChangeLog:

* sem_ch4.adb (Analyze_Selected_Component): Tweak condition.

2 months agoada: Fix wrong initialization of library-level object by conditional expression
Eric Botcazou [Fri, 21 Feb 2025 09:03:22 +0000 (10:03 +0100)] 
ada: Fix wrong initialization of library-level object by conditional expression

At library level the object must be allocated statically and with its bounds
when its nominal subtype is an unconstrained array type.

gcc/ada/ChangeLog:

* exp_ch4.adb (Insert_Conditional_Object_Declaration): Make sure the
object is allocated properly by the code generator at library level.

2 months agoada: Convert floating-point zero to machine representation
Piotr Trojanek [Thu, 20 Feb 2025 18:25:02 +0000 (19:25 +0100)] 
ada: Convert floating-point zero to machine representation

When statically evaluating floating-point expressions we convert the final
result to machine number. However, we skipped this conversion if the result was
zero.

This inconsistency was introduced when adding a warning for compile-time
evaluation that gives different result from a run-time evaluation, but left
when this warning was deconstructed. It causes a crash in GNATprove, which
expects all floating-point numbers in the GNAT AST to be in a machine
representation form.

gcc/ada/ChangeLog:

* sem_eval.adb (Check_Non_Static_Context): Remove special handling of
floating-point zero.

2 months agoada: Move Incomplete_View from node to entity field
Piotr Trojanek [Wed, 19 Feb 2025 15:32:43 +0000 (16:32 +0100)] 
ada: Move Incomplete_View from node to entity field

The Incomplete_View property of a type was attached to its full type
declaration as a semantic field, but retrieving it from there required
low-level tree navigation and caused code duplication. In one case we
relied on internal class-wide type being attached to the corresponding
full type declaration, which is an undocumented assumption.

It seems better to attach this field to entities, just like we do with
Full_View and many other type properties. Ideally, this field should be
present just in type entities, but currently we set it before setting
the proper entity kind.

Behavior is unaffected. This is rather a code cleanup, originating from the
need to use Incomplete_View in GNATprove.

gcc/ada/ChangeLog:

* einfo.ads (Incomplete_View): Move from Sinfo; adapt wording.
* exp_ch3.adb (Build_Record_Init_Proc): Adapt retrieval of
Incomplete_View.
* gen_il-fields.ads (Opt_Field_Enum): Move Incomplete_View from node
to entity field.
* gen_il-gen-gen_entities.adb (Gen_Entities): Add field.
* gen_il-gen-gen_nodes.adb (Gen_Nodes): Remove field.
* sem_ch3.adb (Analyze_Full_Type_Declaration,
Check_Anonymous_Access_Component): Adapt setting of Incomplete_View.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Adapt retrieval of
Incomplete_View for class-wide types; no longer rely on class-wide
type being attached to non-classwide type declaration.
* sem_util.adb (Collect_Primitive_Operations): Adapt retrieval of
Incomplete_View.
* sinfo.ads (Incomplete_View): Move to Einfo.

2 months agoada: Initial prototype of constructors
squirek [Thu, 20 Feb 2025 13:12:58 +0000 (13:12 +0000)] 
ada: Initial prototype of constructors

The patch implements the experimental constructors RFC. Currently a WIP.

gcc/ada/ChangeLog:

* aspects.ads: Add support for constructors.
* exp_aggr.adb: Likewise.
* exp_attr.adb: Likewise.
* exp_ch3.adb: Likewise.
* exp_ch4.adb: Likewise.
* exp_util.adb: Likewise.
* gen_il-fields.ads: Likewise.
* gen_il-gen-gen_entities.adb: Likewise.
* gen_il-gen-gen_nodes.adb: Likewise.
* par-ch4.adb: Likewise.
* sem_aggr.adb: Likewise.
* sem_attr.adb, sem_attr.ads: Likewise.
* sem_ch13.adb: Likewise.
* sem_ch3.adb: Likewise.
* sem_ch5.adb: Likewise.
* sem_ch6.adb: Likewise.
* sem_res.adb: Likewise.
* sem_util.adb, sem_util.ads: Likewise.
* snames.ads-tmpl: Likewise.

2 months agoada: Implement use implies with experimental extension
squirek [Tue, 18 Feb 2025 10:54:01 +0000 (10:54 +0000)] 
ada: Implement use implies with experimental extension

The patch implements the experimental feature to allow use package
clauses within the context area to imply with.

gcc/ada/ChangeLog:

* doc/gnat_rm/gnat_language_extensions.rst: Add documentation.
* gnat_rm.texi: Regenerate.

2 months agoada: Tweak definition of Modulus field of entities
Eric Botcazou [Tue, 18 Feb 2025 10:24:15 +0000 (11:24 +0100)] 
ada: Tweak definition of Modulus field of entities

The compiler may build modular integer subtypes whose base type is private
in the context of instantiations, but we want to be able to get the Modulus.

gcc/ada/ChangeLog:

* einfo.ads (Modulus): Change to implementation base type only.
* gen_il-gen-gen_entities.adb (Modular_Integer_Kind): Change type
of Modulus field to Impl_Base_Type_Only.

2 months agoada: Restore Original_Access_Type field in E_Access_Subprogram_Type entities
Eric Botcazou [Mon, 17 Feb 2025 09:29:48 +0000 (10:29 +0100)] 
ada: Restore Original_Access_Type field in E_Access_Subprogram_Type entities

It is used by CodePeer to recognize the special access pattern.

gcc/ada/ChangeLog:

* einfo.ads (Original_Access_Type): Restore.
* gen_il-fields.ads (Opt_Field_Enum): Restore Original_Access_Type.
* gen_il-gen-gen_entities.adb: Adjust accordingly.
* exp_ch9.adb (Expand_Access_Protected_Subprogram_Type): Restore the
call to Set_Original_Access_Type.

2 months agoada: Remove more unused fields from entities
Eric Botcazou [Fri, 14 Feb 2025 11:31:33 +0000 (12:31 +0100)] 
ada: Remove more unused fields from entities

This removes 5 more unused fields from entities, as well as 1 flag.

gcc/ada/ChangeLog:

* einfo.ads (Default_Expr_Function): Delete.
(Dependent_Instances): Likewise.
(Handler_Records): Likewise.
(Needs_Activation_Record): Likewise.
(Original_Access_Type): Likewise.
(Register_Exception_Call): Likewise.
* sinfo.ads (Accept_Handler_Records): Likewise.
* gen_il-fields.ads (Opt_Field_Enum): Remove Accept_Handler_Records,
Default_Expr_Function, Dependent_Instances, Handler_Records,
Needs_Activation_Record, Original_Access_Type and
Register_Exception_Call.
* gen_il-gen-gen_entities.adb: Adjust accordingly.
* gen_il-gen-gen_nodes.adb: Likewise.
* exp_ch9.adb (Expand_Access_Protected_Subprogram_Type): Remove call
to Set_Original_Access_Type.
(Expand_N_Selective_Accept): Remove call to Set_Handler_Records.
* exp_ch11.adb (Expand_N_Exception_Declaration): Remove call to
Set_Register_Exception_Call.
* sem_ch3.adb (Access_Subprogram_Declaration): Remove call to
Set_Needs_Activation_Record.
* sem_ch12.adb (Instantiate_Package_Body): Remove call to
Set_Handler_Records.

2 months agoada: Incorrect unresolved operator name in an instantiation
Steve Baird [Fri, 7 Feb 2025 20:29:46 +0000 (12:29 -0800)] 
ada: Incorrect unresolved operator name in an instantiation

In some cases, a generic containing a use of a unary operator successfully
compiles but the compiler incorrectly rejects the corresponding use in
an instantiation.

gcc/ada/ChangeLog:

* sem_ch4.adb
(Find_Unary_Types): Because we reanalyze names in an instance,
we sometimes have to take steps to filter out extraneous name
resolution candidates that happen to be visible at the point of the
instance declaration. Remove some code that appears to have been
written with this in mind. This is done for two reasons. First, the
code sometimes doesn't work (possibly because the In_Instance test
is not specific enough - it probably should be testing to see whether
we are in an instance of the particular generic in which the result
of calling Corresponding_Generic_Type was declared) and causes correct
code to be rejected. Second, the code seems to no longer be necessary
(possibly because of subsequent fixes in this area which are not
specific to unary operators).

2 months agoada: Remove dead code
Ronan Desplanques [Thu, 13 Feb 2025 13:19:58 +0000 (14:19 +0100)] 
ada: Remove dead code

The code this patch removes is never executed on any of the available
test suites. The patch that introduced it mentions that it fixes a test
in particular, but that test passes anyway today.

gcc/ada/ChangeLog:

* sem_ch8.adb (Premature_Usage): Remove dead code.

2 months agoada: Remove Size_Check_Code field from entities
Eric Botcazou [Thu, 13 Feb 2025 11:07:37 +0000 (12:07 +0100)] 
ada: Remove Size_Check_Code field from entities

It has been unused for a very long time.

gcc/ada/ChangeLog:

* einfo.ads (Size_Check_Code): Delete.
* gen_il-fields.ads (Opt_Field_Enum): Remove Size_Check_Code.
* gen_il-gen-gen_entities.adb (Constant_Or_Variable_Kind): Likewise.
* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Remove call
to Kill_Size_Check_Code.
* sem_prag.adb (Analyze_Pragma): Likewise.
* sem_util.ads (Kill_Size_Check_Code): Delete.
* sem_util.adb (Kill_Size_Check_Code): Likewise.

2 months agoada: Allow IN OUT parameters for first parameter of traversal functions
Claire Dross [Wed, 12 Feb 2025 11:10:20 +0000 (12:10 +0100)] 
ada: Allow IN OUT parameters for first parameter of traversal functions

In general, functions in SPARK cannot have parameters of mode IN OUT
unless they are annotated with the Side_Effects aspect. Borrowing
traversal functions are special functions which can return a part
of their first parameter as an access-to-variable type. This might not
be allowed in Ada if the parameter is a constant. Allow the first
parameter of borrowing traversal functions to have mode IN OUT.

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_SPARK_Subprogram_Specification):
Allow the first parameter of functions whose return type is
an anonymous access-to-variable type to have mode IN OUT.

2 months agoada: Improve large unconstrained-but-definite warning
Ronan Desplanques [Wed, 12 Feb 2025 18:09:18 +0000 (19:09 +0100)] 
ada: Improve large unconstrained-but-definite warning

Before this patch, Check_Discriminant_Use called Is_Limited type on
entities before they were fully analyzed. That caused Is_Limited_Type
to incorrectly return False for records that are limited because they
have a limited component.

This patch pushes back the emissions of the Check_Discriminant_Use
warning after analysis of record declarations. A new field to
E_Record_Type entity is added to take relevant discriminant uses into
account.

gcc/ada/ChangeLog:

* gen_il-fields.ads: New field.
* gen_il-gen-gen_entities.adb: New field.
* einfo.ads: Document new field.
* sem_res.adb (Check_Discriminant_Use): Record relevant uses in new
field. Move warning emission to...
* sem_ch3.adb (Analyze_Full_Type_Declaration): ... Here.

2 months agoada: Do not generate warning about missing overriding indicator
Steve Baird [Thu, 6 Feb 2025 01:35:16 +0000 (17:35 -0800)] 
ada: Do not generate warning about missing overriding indicator

We were previously generating a warning about a missing overriding
indicator in some cases when a dispatching subprogram is declared.
In at least some (and perhaps all) cases where this warning was generated,
it was incorrect. It was also generated very infrequently. The simple
solution is to stop generating the warning.

gcc/ada/ChangeLog:

* sem_disp.adb
(Check_Dispatching_Operation): Delete code to generate
"missing overriding indicator" warning. Update comments.

2 months agoada: Move standard subtype declarations generation
Ronan Desplanques [Wed, 12 Feb 2025 09:37:30 +0000 (10:37 +0100)] 
ada: Move standard subtype declarations generation

Before this patch, the subtype declarations for Standard.Natural and
Standard.Positive were created before the entity for Standard.Integer
was complete. In preparation of a future change that will make it
impossible to call Etype on an incomplete node, this patch delays the
creation of these subtype declarations. It doesn't affect the behavior
of the compiler.

gcc/ada/ChangeLog:

* cstand.adb (Create_Standard): Delay declaration generation for
Natural and Positive.

2 months agoada: Remove useless calls
Ronan Desplanques [Wed, 12 Feb 2025 09:34:06 +0000 (10:34 +0100)] 
ada: Remove useless calls

The subprogram calls this patch removes were useless because they were
already made in New_Standard_Entity.

gcc/ada/ChangeLog:

* cstand.adb (Create_Standard): Remove useless calls.

2 months agoada: Fix internal error on allocator involving interface type
Eric Botcazou [Tue, 11 Feb 2025 11:47:36 +0000 (12:47 +0100)] 
ada: Fix internal error on allocator involving interface type

The problem is that an itype duplicated through Duplicate_Subexpr_No_Checks
ends up in a different scope than its source.  It is fixed by adding a new
formal parameter New_Scope to the function and forwarding it in the call to
the New_Copy_Tree function.

gcc/ada/ChangeLog:

* exp_aggr.adb (Expand_Record_Aggregate): Use the named form for the
second actual parameter in the call to Duplicate_Subexpr.
* exp_attr.adb (Expand_Size_Attribute): Likewise.
* exp_ch5.adb (Expand_Assign_Array): Likewise.
(Expand_Assign_Array_Bitfield): Likewise.
(Expand_Assign_Array_Bitfield_Fast): Likewise.
* exp_util.ads (Duplicate_Subexpr): Add New_Scope formal parameter.
(Duplicate_Subexpr_No_Checks): Likewise.
(Duplicate_Subexpr_Move_Checks): Likewise.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Pass Proc_Id as the
actual for New_Scope in the calls to Duplicate_Subexpr_No_Checks.
(Duplicate_Subexpr): Add New_Scope formal parameter and forward it
in the call to New_Copy_Tree.
(Duplicate_Subexpr_No_Checks): Likewise.
(Duplicate_Subexpr_Move_Checks): Likewise.

2 months agoada: Fix for validity checking of limited scalar types
Piotr Trojanek [Tue, 28 Jan 2025 11:12:23 +0000 (12:12 +0100)] 
ada: Fix for validity checking of limited scalar types

With a recent change we are now validity checking objects of private scalar
types, but need to handle private scalar types whose public view is limited.

gcc/ada/ChangeLog:

* checks.adb (Insert_Valid_Check): Set flag Assignment_OK in the object
declaration inserted for the validity checks.

2 months agolibstdc++: Support wide characters output for sys_info and local_info [PR120565]
Tomasz Kamiński [Fri, 6 Jun 2025 07:07:49 +0000 (09:07 +0200)] 
libstdc++: Support wide characters output for sys_info and local_info [PR120565]

Formatting sys_info as wchar_t require widening of the abbrev (zone) member.
To support that we reuse the existing code in support for '%Z' specifier, for
local_time_format, and produce output using singe format call with
"[{0:%F %T},{1:%F %T},{2:%T},{3:%Q%q},{0:%Z}]" format string. As noted in the
comment, produced output is locale independed, as it does not contain decimal
separtors.

For sys_info, the outputed literals are widended using _GLIBCXX_WIDEN, except
opening and closing brackets, that are fetched from __format::_Separators.

PR libstdc++/120565

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h
(operator<<(basic_ostream<_CharT, _Traits>&, const sys_info&))
(operator<<(basic_ostream<_CharT, _Traits>&, const local_info&)):
Support wchar_t as _CharT.
* testsuite/std/time/format/empty_spec.cc: Instantiated test_infos for
wchar_t and increase timeout.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agolibstdc++: Test for formatting with empty spec for local_info and sys_info.
Tomasz Kamiński [Thu, 5 Jun 2025 14:27:41 +0000 (16:27 +0200)] 
libstdc++: Test for formatting with empty spec for local_info and sys_info.

We do not test with wchar_t currently, as operator<< (and format) are
ill-formed in such case, because we do not widen abbrev member of local_info.

Adding a tests for behavior of the ostream operator and the formatting
with empty chrono-spec for the chrono types. The coverage is now
complete:
 * sys_info, local_info in this commit,
 * time point, zoned_time and local_time_format in r16-1107-g3cfa53aa95a19c,
 * duration and hh_mm_ss in r16-1099-gac0a04b7a254fb,
 * calendar types in r16-1016-g28a17985dd34b7.

Finally, the timeout for the test was increased again and preprocessor checks
for zoned_time where changed to _GLIBCXX_USE_CXX11_ABI || !_GLIBCXX_USE_DUAL_ABI
to match ones from bits/chrono_io.h file.

libstdc++-v3/ChangeLog:

* testsuite/std/time/format/empty_spec.cc: New tests and increased
timeout.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 months agoRISC-V: Support -mcpu for XiangShan Kunminghu cpu.
Jiawei [Wed, 4 Jun 2025 09:56:49 +0000 (17:56 +0800)] 
RISC-V: Support -mcpu for XiangShan Kunminghu cpu.

This patch adds support for the XiangShan Kunminghu CPU in GCC, allowing
the use of the `-mcpu=xiangshan-kunminghu` option.

XiangShan-KunMingHu is the third-generation open-source high-performance
RISC-V processor.[1] You can find the corresponding ISA extension from the
XiangShan Github repository.[2] The latest news of KunMingHu can be found
in the XiangShan Biweekly.[3]

[1] https://github.com/OpenXiangShan/XiangShan-User-Guide/releases.
[2] https://github.com/OpenXiangShan/XiangShan/blob/master/src/main/scala/xiangshan/Parameters.scala
[3] https://docs.xiangshan.cc/zh-cn/latest/blog

A dedicated scheduling model for KunMingHu's hybrid pipeline will be
proposed in a subsequent PR.

gcc/ChangeLog:

* config/riscv/riscv-cores.def (RISCV_TUNE): New cpu tune.
(RISCV_CORE): New cpu.
* doc/invoke.texi: Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/mcpu-xiangshan-kunminghu.c: New test.

Co-Authored-By: Jiawei Chen <jiawei@iscas.ac.cn>
Co-Authored-By: Yangyu Chen <cyy@cyyself.name>
Co-Authored-By: Tang Haojin <tanghaojin@outlook.com>
2 months agotree-optimization/120032 - CLZ matching, fallback for missing range-info
Richard Biener [Thu, 5 Jun 2025 12:23:06 +0000 (14:23 +0200)] 
tree-optimization/120032 - CLZ matching, fallback for missing range-info

The following allows us to emit a conditional move when the value
of the table based CLZ/CLZ implementation at zero differs from what
the target implementation guarantees or we cannot easily fixup
otherwise.  In that case emit a val == 0 ? table-based-zero-result : ...

PR tree-optimization/120032
* tree-ssa-forwprop.cc (simplify_count_zeroes): When we cannot use
the IFN to determine the result at zero use a conditional move
to reproduce the correct result from the table-based
algorithm.

* gcc.target/i386/pr120032-3.c: New testcase.

2 months agotree-optimization/120032 - matching of table based CLZ
Richard Biener [Wed, 28 May 2025 13:09:19 +0000 (15:09 +0200)] 
tree-optimization/120032 - matching of table based CLZ

The following adds the ability to match a table based CLZ implementation
similar as to how we can do for CTZ.  I'm re-using the workers for
matching up array and string tables by using a lambda and templates
and kept the transform step for CLZ/CTZ inter-mangled.

PR tree-optimization/120032
* match.pd (clz_table_index): New match.
* tree-ssa-forwprop.cc (check_table_array): Rename from
check_ctz_array.  Split out actual verification to a functor.
(check_table_string): Rename from check_ctz_string and likewise.
(check_table): Rename from check_ctz_table and adjust.
(gimple_clz_table_index): Declare.
(simplify_count_zeroes): Rename from simplify_count_trailing_zeroes.
Extend to cover CLZ.
(pass_forwprop::execute): Adjust.

* gcc.target/i386/pr120032-1.c: New testcase.
* gcc.target/i386/pr120032-2.c: Likewise.

2 months agoUse ranger for table based CTZ detection
Richard Biener [Wed, 28 May 2025 13:26:48 +0000 (15:26 +0200)] 
Use ranger for table based CTZ detection

The following uses context sensitive ranger for determining whether
the input to the table based CTZ is ever zero.

* tree-ssa-forwprop.cc (simplify_count_trailing_zeroes):
Use ranger instead of tree_expr_nonzero_p.

2 months agoRefactor CTZ detection in forwprop
Richard Biener [Wed, 28 May 2025 12:13:00 +0000 (14:13 +0200)] 
Refactor CTZ detection in forwprop

The following refactors the CTZ detection code to be more easily
extensible to also handle CLZ.

* tree-ssa-forwprop.cc (optimize_count_trailing_zeroes):
Inline into ...
(simplify_count_trailing_zeroes): ... this function.
Split out ...
(check_ctz_table): ... a wrapper for CONSTRUCTOR vs. STRING_CST
handling.

2 months agoDaily bump.
GCC Administrator [Fri, 6 Jun 2025 00:18:30 +0000 (00:18 +0000)] 
Daily bump.

2 months ago[RISC-V] Improve signed division by 2^n
Jeff Law [Thu, 5 Jun 2025 22:58:45 +0000 (16:58 -0600)] 
[RISC-V] Improve signed division by 2^n

So another class of cases where we can do better than a zicond sequence.  Like
the prior patch this came up evaluating some code from Shreya to detect more
conditional move cases.

This patch allows us to use the "splat the sign bit" idiom to efficiently
select between 0 and 2^n-1.  That's particularly important for signed division
by a power of two.

For signed division by a power of 2, you conditionally add 2^n-1 to the
numerator, then right shift that result.  Using zicond somewhat naively you get
something like this (for n / 4096):

>         li      a5,4096
>         addi    a5,a5,-1
>         slti    a4,a0,0
>         add     a5,a0,a5
>         czero.eqz       a5,a5,a4
>         czero.nez       a0,a0,a4
>         add     a0,a0,a5
>         srai    a0,a0,12

After this patch you get this instead:

>         srai    a5,a0,63
>         srli    a5,a5,52
>         add     a0,a5,a0
>         srai    a0,a0,12

It's not *that* much faster, but it's certainly shorter.

So the trick here is that after splatting the sign bit we have 0, -1. So a
subsequent logical shift right would generate 0 or 2^n-1.

Yes, there a nice variety of other constant pairs we can select between. Some
notes have been added to the PR I opened yesterday.

The first thing we need to do is throttle back zicond generation. Unfortunately
we don't see the constants from the division-by-2^n algorithm, so we have to
disable for all lt/ge 0 cases.  This can have small negative impacts.  I looked
at this across spec and didn't see anything I was particularly worried about
and numerous small improvements from that alone.

With that in place we need to recognize the form seen by combine. Essentially
it sees the splat of the sign bit feeding a logical AND. We split that into two
right shifts.

This has survived in my tester.  Waiting on upstream pre-commit before moving
forward.

gcc/
* config/riscv/riscv.cc (riscv_expand_conditional_move): Avoid
zicond in some cases involving sign bit tests.
* config/riscv/riscv.md: Split a splat of the sign bit feeding a
masking off high bits into a pair of right shifts.

gcc/testsuite
* gcc.target/riscv/nozicond-3.c: New test.

2 months ago[i386] Improve "mov<mode>cc" expander for DImode immediates [PR120553]
Uros Bizjak [Thu, 5 Jun 2025 20:53:35 +0000 (22:53 +0200)] 
[i386] Improve "mov<mode>cc" expander for DImode immediates [PR120553]

"mov<mode>cc" expander uses x86_64_general_operand predicate that limits the
range of immediate operands to 32-bit size.  The usage of this predicate
causes ifcvt to force out-of-range immediates to registers when converting
through noce_try_cmove.  The testcase:

long long foo (long long c) { return c >= 0 ? 0x400000000ll : -1ll; }

compiles (-O2) to:

foo:
testq %rdi, %rdi
movq $-1, %rax
movabsq $0x400000000, %rdx
cmovns %rdx, %rax
ret

The above testcase can be compiled to a more optimized code without
problematic CMOV instruction if 64-bit immediates are allowed in
"mov<mode>cc" expander:

foo:
movq %rdi, %rax
sarq $63, %rax
btsq $34, %rax
ret

The expander calls the ix86_expand_int_movcc function which internally
sanitizes arguments of emitted logical insns using expand_simple_binop.
The out-of-range immediates are forced to a temporary register just
before the instruction, so the instruction combiner is then able to
synthesize 64-bit BTS instruction.

The code improves even for non-exact-log2 64-bit immediates, e.g.

long long foo (long long c) { return c >= 0 ? 0x400001234ll : -1ll; }

that now compiles to:

foo:
        movabsq $0x400001234, %rdx
        movq    %rdi, %rax
        sarq    $63, %rax
        orq     %rdx, %rax
        ret

again avoiding problematic CMOV instruction.

PR target/120553

gcc/ChangeLog:

* config/i386/i386.md (mov<mode>cc): Use "general_operand"
predicate for operands 2 and 3 for all modes.

gcc/testsuite/ChangeLog:

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

2 months agodoc: update links to c99status.html
Marek Polacek [Thu, 5 Jun 2025 19:50:45 +0000 (15:50 -0400)] 
doc: update links to c99status.html

gcc/ChangeLog:

* doc/invoke.texi: Update a link to c99status.html.
* doc/standards.texi: Likewise.

2 months agoCCP: Manually rename the virtual mem op when inserting clobbers
Andrew Pinski [Sat, 31 May 2025 05:30:01 +0000 (22:30 -0700)] 
CCP: Manually rename the virtual mem op when inserting clobbers

Right now the only place where CCP needs to have the virtual op renamed is
after inserting clobbers which come right before __builtin_stack_restore.
So let's manually do the correct thing so we can remove the TODO_update_ssa todo.

gcc/ChangeLog:

* tree-ssa-ccp.cc (insert_clobber_before_stack_restore): Update the virtual
op on the inserted clobber and the stack restore function.
(do_ssa_ccp): Don't add TODO_update_ssa to the todo.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agocobol: Guard clock_gettime(). [PR119975]
Robert Dubner [Thu, 5 Jun 2025 14:53:02 +0000 (10:53 -0400)] 
cobol: Guard clock_gettime(). [PR119975]

This attempts to eliminate "'clock_gettime' not declared..." when
building on x86_64-apple-darwin15.6.0.  Calls to clock_gettime have been
reduced to two locations.  Both have been guarded with

gcc/cobol/ChangeLog:

PR cobol/119975
* genapi.cc (parser_intrinsic_call_0): Use get_time_nanoseconds().
* genutil.cc (get_time_64): Rename to get_time_nanoseconds().
(get_time_nanoseconds): Likewise.
* genutil.h (get_time_64): Likewise.
(get_time_nanoseconds): Likewise.
* util.cc (class cbl_timespec): Timing routine uses
get_time_nanoseconds().
(operator-): Likewise.
(parse_file): Likewise.

libgcobol/ChangeLog:

PR cobol/119975
* configure.ac: AC_CHECK_LIB(rt, clock_gettime).
* config.h.in: Likewise.
* configure: Likewise.
* gfileio.cc: Remove in-line cppcheck-suppress.
* intrinsic.cc (timespec_to_string): Use guarded clock_gettime().
(__gg__current_date): Likewise.
(__gg__seconds_past_midnight): Likewise.
(__gg__formatted_current_date): Likewise.
(__gg__random): Likewise.
(__gg__random_next): Likewise.
(__gg__when_compiled): Likewise.
* libgcobol.cc (cobol_time): Likewise.
(get_time_nanoseconds): Likewise.
(__gg__clock_gettime): Likewise.
(__gg__get_date_hhmmssff): Likewise.
* libgcobol.h (__gg__clock_gettime): Likewise.
(struct cbl_timespec): Likewise.

2 months agoaarch64:sve: Use make_ssa_name instead of create_tmp_var in the folder
Andrew Pinski [Sat, 31 May 2025 17:22:34 +0000 (10:22 -0700)] 
aarch64:sve: Use make_ssa_name instead of create_tmp_var in the folder

Currently gimple_folder::convert_and_fold calls create_tmp_var; that
means while in ssa form, the pass which calls fold_stmt will always
have to update the ssa (via TODO_update_ssa or otherwise).  This seems
not very useful since we know that this will always be a ssa name, using
make_ssa_name instead is better and don't need to depend on the ssa updater.
Plus this should have a small compile time performance and memory usage
improvement too since this uses an anonymous ssa name rather than creating a
full decl for this.

Changes since v1:
* Use make_ssa_name instead of create_tmp_reg_or_ssa_name, anonymous ssa
  names are allowed early on in gimple too.

Built and tested on aarch64-linux-gnu.

gcc/ChangeLog:

* config/aarch64/aarch64-sve-builtins.cc: Include value-range.h and tree-ssanames.h
(gimple_folder::convert_and_fold): Use make_ssa_name
instead of create_tmp_var for the temporary. Add comment about callback argument.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agoranger: Add support for float <-> int casts [PR120231]
Jakub Jelinek [Thu, 5 Jun 2025 16:10:22 +0000 (18:10 +0200)] 
ranger: Add support for float <-> int casts [PR120231]

The following patch adds support for float <-> integer conversions in
ranger.
The patch reverts part of the r16-571 changes, those changes were right
for fold_range, but not for op1_range, where RO_IFI and RO_FIF are actually
called rather than RO_IFF and RO_FII that the patch expected.
Also, the float -> int operation actually uses FIX_TRUNC_EXPR tree code
rather than NOP_EXPR or CONVERT_EXPR and int -> float uses FLOAT_EXPR,
but I think we can just handle all of them using operator_cast, at least
as long as we don't try to use VIEW_CONVERT_EXPR using that too; not really
sure handling VCE at least for floating to integral or vice versa would
be actually useful though.

The patch "regressed" two tests, gfortran.dg/inline_matmul_16.f90 and
g++.dg/tree-ssa/loop-split-1.C.  In the first case, there is a loop doing
matmul on various sizes of matrices, up to 10x10 matrices, and Fortran
FE given the options emits two implementations of the matmul, one inline
for the case where the matmul has less than 1000 elements and one for
larger matmuls.  The check for whatever reason uses floating point
calculations and before this patch we weren't able to prove that all the
matrices will be smaller than the cutoff and the test was checking for
presence of the fallback call; with the patch we are able to figure it
out and only keep the inline copy.  I've duplicated the test, once
unmodified source which doesn't expect _gfortran_matmul string in optimized
dump anymore, and another copy which uses volatile ten instead of 10 in
loop upper bounds so that it has to keep the fallback and scans for it.
The other test is g++.dg/tree-ssa/loop-split-1.C, which does
constexpr unsigned s = 100000000;
...
    for(unsigned i = 0; i < s; ++i)
    {
        if(i == 0)
            a[i] = b[i] * c[i];
        else
            a[i] = (b[i] + c[i]) * c[i-1] * std::log(i);
    }
and for some reason the successful loop splitting for which the test
searches in a dump file is dependent on the errno fallback of std::log,
where we do t = std::log((double)i); if ((double)i) u> 0); else log ((double)i);
But i goes only from 1 to 100000000, so (double)i has the range
[1.0, 100000000.0] with the patch and so we see it will never need errno
nor raise exception.  I've tested adding + d for it where d is 0.0 but
modifiable in some other TU, and tested it also with r14-2851 and r14-2852,
where the former FAILed the test both unmodified and modified, while
the latter PASSed both versions.

2025-06-05  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/120231
* range-op.cc (range_op_table::range_op_table): Register op_cast
also for FLOAT_EXPR and FIX_TRUNC_EXPR.
(RO_III): Adjust comment.
(range_op_handler::op1_range): Handle RO_IFI rather than RO_IFF.
Don't handle RO_FII.
(range_operator::op1_range): Remove overload with
irange &, tree, const frange &, const frange &, relation_trio
and frange &, tree, const irange &, const irange &, relation_trio
arguments.  Add overload with
irange &, tree, const frange &, const irange &, relation_trio
arguments.
* range-op-mixed.h (operator_cast::op1_range): Remove overload with
irange &, tree, const frange &, const frange &, relation_trio
and frange &, tree, const irange &, const irange &, relation_trio
arguments.  Add overload with
irange &, tree, const frange &, const irange &, relation_trio and
frange &, tree, const irange &, const frange &, relation_trio
arguments.
* range-op.h (range_operator::op1_cast): Remove overload with
irange &, tree, const frange &, const frange &, relation_trio
and frange &, tree, const irange &, const irange &, relation_trio
arguments.  Add overload with
irange &, tree, const frange &, const irange &, relation_trio
arguments.
* range-op-float.cc (operator_cast::fold_range): Implement
float to int and int to float casts.
(operator_cast::op1_range): Remove overload with
irange &, tree, const frange &, const frange &, relation_trio
and frange &, tree, const irange &, const irange &, relation_trio
arguments.  Add overload with
irange &, tree, const frange &, const irange &, relation_trio and
frange &, tree, const irange &, const frange &, relation_trio
arguments and implement reverse op of float to int and int to float
cast there.

* gcc.dg/tree-ssa/pr120231-2.c: New test.
* gcc.dg/tree-ssa/pr120231-3.c: New test.
* gfortran.dg/inline_matmul_16.f90: Don't expect any _gfortran_matmul
strings in optimized dump.
* gfortran.dg/inline_matmul_26.f90: New test.
* g++.dg/tree-ssa/loop-split-1.C (d): New variable.
(main): Use std::log (i + d) instead of std::log (i).

2 months agoFix typo in afdo_calculate_branch_prob
Jan Hubicka [Thu, 5 Jun 2025 16:10:16 +0000 (18:10 +0200)] 
Fix typo in afdo_calculate_branch_prob

gcc/ChangeLog:

* auto-profile.cc (afdo_calculate_branch_prob): Fix typo
in previous patch.

2 months agoaarch64: Add testcase for vld2 which was fixed by r16-1113 [PR89606]
Andrew Pinski [Wed, 4 Jun 2025 21:32:33 +0000 (14:32 -0700)] 
aarch64: Add testcase for vld2 which was fixed by r16-1113 [PR89606]

This aarch64 specific vld2 intrinsics testcase was fixed by r16-1113-g069caa5cea91f
(simple copy propagation for aggregates). I didn't include it in the original
patch as I was testing on x86_64 but I got around to testing this
and now we don't have any more extra movs so let's add a testcase.

Tested for aarch64-linux-gnu.

PR tree-optimization/89606

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/vld2-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2 months agoc++: substituting fn parm redeclared with dep alias tmpl [PR120224]
Patrick Palka [Thu, 5 Jun 2025 15:07:25 +0000 (11:07 -0400)] 
c++: substituting fn parm redeclared with dep alias tmpl [PR120224]

Here we declare f twice, the second time around using a dependent
alias template.  Due to alias template transparency these are logically
the same overload.  But now the function type of f (produced from the
first declaration) diverges from the type of its formal parameter
(produced from the subsequent redefinition) in that substituting T=int
succeeds for the function type but not for the formal parameter type.
This eventually causes us to produce an undiagnosed error_mark_node in
the AST of the function call, leading to failure of the sanity check
check added in r14-6343-g0c018a74eb1aff.

Before r14-6343 we would still go on to reject the testcase later at
instantiation time, from regenerate_decl_from_template, making this a
regression.

To fix this, it seems we just need to propagate error_mark_node upon
substitution failure into the type of a PARM_DECL.

PR c++/120224

gcc/cp/ChangeLog:

* pt.cc (tsubst_function_decl): Return error_mark_node if
substituting into the formal parameter list failed.
(tsubst_decl) <case PARM_DECL>: Return error_mark_node
upon TREE_TYPE substitution failure, when in a SFINAE
context.  Return error_mark_node upon DECL_CHAIN substitution
failure.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/alias-decl-80.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoc++: quadratic constexpr folding of arith expr [PR118340]
Patrick Palka [Thu, 5 Jun 2025 15:06:04 +0000 (11:06 -0400)] 
c++: quadratic constexpr folding of arith expr [PR118340]

Here the PR's testcase demonstrates that the cp_fully_fold calls in
cp_build_binary_op (for diagnosing arithmetic overflow) lead to
quadratic behavior when building up a large arithmetic constant
expression.  The problem is ultimately that maybe_constant_value's
caching doesn't reuse intermediate values, unlike cp_fold.  (And
unfortunately we can't leverage the cp_fold cache in this call site
because here we want to evaluate constexpr calls even in -O0, which
cp_fold avoids.)

This patch fixes this by making maybe_constant_value look up each
operand of the given expression to see if we've previously reduced it,
and if so, rebuild the expression using the (presumably) reduced
operands and evaluate that.  After this patch each version of the
testcase from the PR compiles in ~0.1s on my machine.

PR c++/118340

gcc/cp/ChangeLog:

* constexpr.cc (maybe_constant_value): First try looking up each
operand in the cv_cache and reusing the result.

Reviewed-by: Jason Merrill <jason@redhat.com>
2 months agoRISC-V: Don't use structured binding in riscv-common.cc
Kito Cheng [Thu, 5 Jun 2025 07:23:59 +0000 (15:23 +0800)] 
RISC-V: Don't use structured binding in riscv-common.cc

It's new C++ language feature introduced in C++17, which is higher than
the build environment required by the GCC (C++14).

gcc/ChangeLog:

* common/config/riscv/riscv-common.cc: Remove structured binding
from the code.

2 months agoreal: Fix up real_from_integer [PR120547]
Jakub Jelinek [Thu, 5 Jun 2025 13:47:19 +0000 (15:47 +0200)] 
real: Fix up real_from_integer [PR120547]

The function has 2 problems, one is _BitInt specific and the other is
most likely also reproduceable only with it.

The first issue is that I've missed updating the function for _BitInt,
maxbitlen as MAX_BITSIZE_MODE_ANY_INT + HOST_BITS_PER_WIDE_INT
obviously isn't guaranteed to be larger than any integral type we might
want to convert at compile time from wide_int to REAL_VALUE_FORMAT.
Just using len instead of it works fine, at least when used after
HOST_BITS_PER_WIDE_INT is added to it and it is truncated to multiples
of HOST_BITS_PER_WIDE_INT.

The other bug is that if the value has too many significant bits (formerly
maxbitlen - cnt_l_z, now len - cnt_l_z), the code just shifts it right and
adds the shift count to the future exponent.  That isn't correct for
rounding as the testcase attempts to show, the internal real format has more
bits than any precision in supported format, but we still need to
distinguish bewtween values exactly half way between representable floating
point values (those should be rounded to even) and the case when we've
shifted away some non-zero bits, so the value was tiny bit larger than half
way and then we should round up.

The patch uses something like e.g. soft-fp uses in these cases, right shift
with sticky bit in the least significant bit.

2025-06-05  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/120547
* real.cc (real_from_integer): Remove maxbitlen variable, use
len instead of that.  When shifting right, or in 1 if any of the
shifted away bits are non-zero.  Formatting fix.

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