]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
11 months agophiopt: Ignore some nop statements in heursics [PR116098]
Andrew Pinski [Fri, 30 Aug 2024 17:36:24 +0000 (10:36 -0700)] 
phiopt: Ignore some nop statements in heursics [PR116098]

The heurstics that was added for PR71016, try to search to see
if the conversion was being moved away from its definition. The problem
is the heurstics would stop if there was a non GIMPLE_ASSIGN (and already ignores
debug statements) and in this case we would have a GIMPLE_LABEL that was not
being ignored. So we should need to ignore GIMPLE_NOP, GIMPLE_LABEL and GIMPLE_PREDICT.
Note this is now similar to how gimple_empty_block_p behaves.

Note this fixes the wrong code that was reported by moving the VCE (conversion) out before
the phiopt/match could convert it into an bit_ior and move the VCE out with the VCE being
conditionally valid.

Bootstrapped and tested on x86_64-linux-gnu.
Also built and tested for aarch64-linux-gnu.

PR tree-optimization/116098

gcc/ChangeLog:

* tree-ssa-phiopt.cc (factor_out_conditional_operation): Ignore
nops, labels and predicts for heuristic for conversion with a constant.

gcc/testsuite/ChangeLog:

* c-c++-common/torture/pr116098-1.c: New test.
* gcc.target/aarch64/csel-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
11 months agotestsuite: Change what is being tested for pr66726-2.c
Andrew Pinski [Fri, 30 Aug 2024 16:53:01 +0000 (09:53 -0700)] 
testsuite: Change what is being tested for pr66726-2.c

r14-575-g6d6c17e45f62cf changed the debug dump message but the testcase
pr66726-2.c was not updated for the change. The testcase was searching to
make sure we didn't factor out a conversion but the testcase was no longer
testing that so we needed to update what was being searched for.

Tested on x86_64-linux.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr66726-2.c: Update scan dump message.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
11 months agoFortran: downgrade use associated namelist group name to legacy extension
Harald Anlauf [Fri, 30 Aug 2024 19:15:43 +0000 (21:15 +0200)] 
Fortran: downgrade use associated namelist group name to legacy extension

The Fortran standard disallows use associated names as namelist group name
(e.g. F2003:C581, but also later standards).  This feature is a gfortran
legacy extension, and we should give a warning even for -std=gnu.

gcc/fortran/ChangeLog:

* match.cc (gfc_match_namelist): Downgrade feature from GNU to
legacy extension.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr88169_3.f90: Adjust pattern.

11 months agoc++: Add unsequenced C++ testcase
Jakub Jelinek [Sat, 31 Aug 2024 14:03:20 +0000 (16:03 +0200)] 
c++: Add unsequenced C++ testcase

This is the testcase I wrote originally and which on top of the
https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659154.html
patch didn't behave the way I wanted (no warning and no optimizations of
[[unsequenced]] function templates which don't have pointer/reference
arguments.
Posting this separately, because it depends on the above mentioned
patch as well as the PR116175
https://gcc.gnu.org/pipermail/gcc-patches/2024-August/659157.html
patch.

2024-08-31  Jakub Jelinek  <jakub@redhat.com>

* g++.dg/ext/attr-unsequenced-1.C: New test.

11 months agoc: Add support for unsequenced and reproducible attributes
Jakub Jelinek [Sat, 31 Aug 2024 13:58:23 +0000 (15:58 +0200)] 
c: Add support for unsequenced and reproducible attributes

C23 added in N2956 ( https://open-std.org/JTC1/SC22/WG14/www/docs/n2956.htm )
two new attributes, which are described as similar to GCC const and pure
attributes, but they aren't really same and it seems that even the paper
is missing some of the differences.
The paper says unsequenced is the same as const on functions without pointer
arguments and reproducible is the same as pure on such functions (except
that they are function type attributes rather than function
declaration ones), but it seems the paper doesn't consider the finiteness GCC
relies on (aka non-DECL_LOOPING_CONST_OR_PURE_P) - the paper only talks
about using the attributes for CSE etc., not for DCE.

The following patch introduces (for now limited) support for those
attributes, both as standard C23 attributes and as GNU extensions (the
difference is that the patch is then less strict on where it allows them,
like other function type attributes they can be specified on function
declarations as well and apply to the type, while C23 standard ones must
go on the function declarators (i.e. after closing paren after function
parameters) or in type specifiers of function type.

If function doesn't have any pointer/reference arguments, the patch
adds additional internal attribute with " noptr" suffix which then is used
by flags_from_decl_or_type to handle those easy cases as
ECF_CONST|ECF_LOOPING_CONST_OR_PURE or
ECF_PURE|ECF_LOOPING_CONST_OR_PURE
The harder cases aren't handled right now, I'd hope they can be handled
incrementally.

I wonder whether we shouldn't emit a warning for the
gcc.dg/c23-attr-{reproducible,unsequenced}-5.c cases, while the standard
clearly specifies that composite types should union the attributes and it
is what GCC implements for decades, for ?: that feels dangerous for the
new attributes, it would be much better to be conservative on say
(cond ? unsequenced_function : normal_function) (args)

There is no diagnostics on incorrect [[unsequenced]] or [[reproducible]]
function definitions, while I think diagnosing non-const static/TLS
declarations in the former could be easy, the rest feels hard.  E.g. the
const/pure discovery can just punt on everything it doesn't understand,
but complete diagnostics would need to understand it.

2024-08-31  Jakub Jelinek  <jakub@redhat.com>

PR c/116130
gcc/
* doc/extend.texi (unsequenced, reproducible): Document new function
type attributes.
* calls.cc (flags_from_decl_or_type): Handle "unsequenced noptr" and
"reproducible noptr" attributes.
gcc/c-family/
* c-attribs.cc (c_common_gnu_attributes): Add entries for
"unsequenced", "reproducible", "unsequenced noptr" and
"reproducible noptr" attributes.
(handle_unsequenced_attribute): New function.
(handle_reproducible_attribute): Likewise.
* c-common.h (handle_unsequenced_attribute): Declare.
(handle_reproducible_attribute): Likewise.
* c-lex.cc (c_common_has_attribute): Return 202311 for standard
unsequenced and reproducible attributes.
gcc/c/
* c-decl.cc (handle_std_unsequenced_attribute): New function.
(handle_std_reproducible_attribute): Likewise.
(std_attributes): Add entries for "unsequenced" and "reproducible"
attributes.
(c_warn_type_attributes): Add TYPE argument.  Allow unsequenced
or reproducible attributes if it is FUNCTION_TYPE.
(groktypename): Adjust c_warn_type_attributes caller.
(grokdeclarator): Likewise.
(finish_declspecs): Likewise.
* c-parser.cc (c_parser_declaration_or_fndef): Likewise.
* c-tree.h (c_warn_type_attributes): Add TYPE argument.
gcc/testsuite/
* c-c++-common/attr-reproducible-1.c: New test.
* c-c++-common/attr-reproducible-2.c: New test.
* c-c++-common/attr-unsequenced-1.c: New test.
* c-c++-common/attr-unsequenced-2.c: New test.
* gcc.dg/c23-attr-reproducible-1.c: New test.
* gcc.dg/c23-attr-reproducible-2.c: New test.
* gcc.dg/c23-attr-reproducible-3.c: New test.
* gcc.dg/c23-attr-reproducible-4.c: New test.
* gcc.dg/c23-attr-reproducible-5.c: New test.
* gcc.dg/c23-attr-reproducible-5-aux.c: New file.
* gcc.dg/c23-attr-unsequenced-1.c: New test.
* gcc.dg/c23-attr-unsequenced-2.c: New test.
* gcc.dg/c23-attr-unsequenced-3.c: New test.
* gcc.dg/c23-attr-unsequenced-4.c: New test.
* gcc.dg/c23-attr-unsequenced-5.c: New test.
* gcc.dg/c23-attr-unsequenced-5-aux.c: New file.
* gcc.dg/c23-has-c-attribute-2.c: Add tests for unsequenced
and reproducible attributes.

11 months agoAVR: Don't print a space after , when printing instructions.
Georg-Johann Lay [Sat, 31 Aug 2024 08:58:12 +0000 (10:58 +0200)] 
AVR: Don't print a space after , when printing instructions.

gcc/
* config/avr/avr.cc: Follow the convention to not add a space
after comma when printing instructions.

11 months agoOptimize initialization of small padded objects
Alexandre Oliva [Sat, 31 Aug 2024 09:03:12 +0000 (06:03 -0300)] 
Optimize initialization of small padded objects

When small objects containing padding bits (or bytes) are fully
initialized, we will often store them in registers, and setting
bitfields and other small fields will attempt to preserve the
uninitialized padding bits, which tends to be expensive.
Zero-initializing registers, OTOH, tends to be cheap.

So, if we're optimizing, zero-initialize such small padded objects
even if that's not needed for correctness.  We can't zero-initialize
all such padding objects, though: if there's no padding whatsoever,
and all fields are initialized with nonzero, the zero initialization
would be flagged as dead.  That's why we introduce machinery to detect
whether objects have padding bits.  I considered distinguishing
between bitfields, units and larger padding elements, but I didn't
pursue that distinction.

Since the object's zero-initialization subsumes fields'
zero-initialization, the empty string test in builtin-snprintf-6.c's
test_assign_aggregate would regress without the addition of
native_encode_constructor.

for  gcc/ChangeLog

* expr.cc (categorize_ctor_elements_1): Change p_complete to
int, to distinguish complete initialization in presence or
absence of uninitialized padding bits.
(categorize_ctor_elements): Likewise.  Adjust all callers...
* expr.h (categorize_ctor_elements): ... and declaration.
(type_has_padding_at_level_p): New.
* gimple-fold.cc (type_has_padding_at_level_p): New.
* fold-const.cc (native_encode_constructor): New.
(native_encode_expr): Call it.
* gimplify.cc (gimplify_init_constructor): Clear small
non-addressable non-volatile objects with padding or
other uninitialized fields as an optimization.

for  gcc/testsuite/ChangeLog

* gcc.dg/init-pad-1.c: New.

11 months agoDaily bump.
GCC Administrator [Sat, 31 Aug 2024 00:18:22 +0000 (00:18 +0000)] 
Daily bump.

11 months agoc++: add fixed test [PR101099]
Marek Polacek [Fri, 30 Aug 2024 21:09:19 +0000 (17:09 -0400)] 
c++: add fixed test [PR101099]

-fconcepts-ts is no longer supported so this can't be made to ICE
anymore.

PR c++/101099

gcc/testsuite/ChangeLog:

* g++.dg/concepts/pr101099.C: New test.

11 months agoc++: add fixed test [PR115616]
Marek Polacek [Fri, 30 Aug 2024 20:34:11 +0000 (16:34 -0400)] 
c++: add fixed test [PR115616]

This got fixed by r15-2120.

PR c++/115616

gcc/testsuite/ChangeLog:

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

11 months agoc++: fix used but not defined warning for friend
Jason Merrill [Thu, 29 Aug 2024 17:27:13 +0000 (13:27 -0400)] 
c++: fix used but not defined warning for friend

Here limit_bad_template_recursion avoids instantiating foo, and then we
wrongly warn that it isn't defined, because as a non-template (but
templated) friend DECL_TEMPLATE_INSTANTIATION is false.

gcc/cp/ChangeLog:

* decl2.cc (c_parse_final_cleanups): Also check
DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/used-inline1.C: New test.

11 months agoFortran: default-initialization of derived-type function results [PR98454]
Harald Anlauf [Thu, 29 Aug 2024 20:17:07 +0000 (22:17 +0200)] 
Fortran: default-initialization of derived-type function results [PR98454]

gcc/fortran/ChangeLog:

PR fortran/98454
* resolve.cc (resolve_symbol): Add default-initialization of
non-allocatable, non-pointer derived-type function results.

gcc/testsuite/ChangeLog:

PR fortran/98454
* gfortran.dg/alloc_comp_class_4.f03: Remove bogus pattern.
* gfortran.dg/pdt_26.f03: Adjust expected count.
* gfortran.dg/derived_result_3.f90: New test.

11 months agogdbhooks: Fix printing of vec with vl_ptr layout
Alex Coplan [Fri, 30 Aug 2024 14:29:34 +0000 (15:29 +0100)] 
gdbhooks: Fix printing of vec with vl_ptr layout

As it stands, the pretty printing of GCC's vecs by gdbhooks.py only
handles vectors with vl_embed layout.  As such, when encountering a vec
with vl_ptr layout, GDB would print a diagnostic like:

  gdb.error: There is no member or method named m_vecpfx.

when (e.g.) any such vec occurred in a backtrace.  This patch extends
VecPrinter.children to also handle vl_ptr vectors.

gcc/ChangeLog:

* gdbhooks.py (VEC_KIND_EMBED): New.
(VEC_KIND_PTR): New.
(get_vec_kind): New.
(VecPrinter.children): Also handle vectors with vl_ptr layout.

11 months agoDon't remove /usr/lib and /lib from when passing to the linker [PR97304/104707]
Andrew Pinski [Tue, 16 Apr 2024 19:06:51 +0000 (12:06 -0700)] 
Don't remove /usr/lib and /lib from when passing to the linker [PR97304/104707]

With newer ld, the default search library path does not include /usr/lib nor /lib
but the driver decides to not pass -L down to the link for these and then in some/most
cases libc is not found.
This code dates from at least 1992 and it is done in a way which is not safe and
does not make sense. So let's remove it.

Bootstrapped and tested on x86_64-linux-gnu (which defaults to being a multilib).

gcc/ChangeLog:

PR driver/104707
PR driver/97304

* gcc.cc (is_directory): Don't not include /usr/lib and /lib
for library directory pathes. Remove library argument.
(add_to_obstack): Update call to is_directory.
(driver_handle_option): Likewise.
(spec_path): Likewise.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
11 months agomiddle-end: Remove integer_three_node [PR116537]
Andrew Pinski [Thu, 29 Aug 2024 18:01:56 +0000 (11:01 -0700)] 
middle-end: Remove integer_three_node [PR116537]

After the small expansion patch for __builtin_prefetch, the
only use of integer_three_node is inside tree-ssa-loop-prefetch.cc so let's
remove it as the loop prefetch pass is not enabled these days by default and
having a tree node around just for that pass is a little wasteful. Integer
constants are also shared these days so calling build_int_cst will use the cached
node anyways.

Bootstrapped and tested on x86_64-linux.

PR middle-end/116537

gcc/ChangeLog:

* tree-core.h (enum tree_index): Remove TI_INTEGER_THREE
* tree-ssa-loop-prefetch.cc (issue_prefetch_ref): Call build_int_cst
instead of using integer_three_node.
* tree.cc (build_common_tree_nodes): Remove initialization
of integer_three_node.
* tree.h (integer_three_node): Delete.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
11 months agoexpand: Small speed up expansion of __builtin_prefetch
Andrew Pinski [Thu, 29 Aug 2024 17:58:41 +0000 (10:58 -0700)] 
expand: Small speed up expansion of __builtin_prefetch

This is a small speed up of the expansion of __builtin_prefetch.
Basically for the optional arguments, no reason to call expand_normal
on a constant integer that we know the value, just replace it with
GEN_INT/const0_rtx instead.

Bootstrapped and tested on x86_64-linux.

gcc/ChangeLog:

* builtins.cc (expand_builtin_prefetch): Rewrite expansion of the optional
arguments to not expand known constants.

11 months agoPR modula2/116181: m2rts fix -Wodr warning
Gaius Mulley [Fri, 30 Aug 2024 13:22:01 +0000 (14:22 +0100)] 
PR modula2/116181: m2rts fix -Wodr warning

This patch fixes the -Wodr warning seen in pge-boot/m2rts.h
when building pge.

gcc/m2/ChangeLog:

PR modula2/116181
* pge-boot/GM2RTS.h: Regenerate.
* pge-boot/m2rts.h: Ditto.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
11 months agoAvoid division by zero via constant_multiple_p
Richard Biener [Fri, 30 Aug 2024 07:50:32 +0000 (09:50 +0200)] 
Avoid division by zero via constant_multiple_p

With recent SLP vectorization patches I see RISC-V divison by zero
for gfortran.dg/matmul_10.f90 and others in get_group_load_store_type
which does

              && can_div_trunc_p (group_size
                                  * LOOP_VINFO_VECT_FACTOR (loop_vinfo) - gap,
                                  nunits, &tem, &remain)
              && (known_eq (remain, 0u)
                  || (constant_multiple_p (nunits, remain, &num)
                      && (vector_vector_composition_type (vectype, num,
                                                          &half_vtype)
                          != NULL_TREE))))
            overrun_p = false;

where for [2, 2] / [0, 2] the condition doesn't reflect what we
are trying to test - that, when remain is zero or, when non-zero,
nunits is a multiple of remain, we can avoid touching a gap via
loading smaller pieces and vector composition.

It isn't safe to change the known_eq to maybe_eq so instead
require known_ne (remain, 0u) before doing constant_multiple_p.
There's the corresponding code in vectorizable_load that's known
to have a latent similar issue, so sync that up as well.

* tree-vect-stmts.cc (get_group_load_store_type): Check
known_ne (remain, 0u) before doing constant_multiple_p.
(vectorizable_load): Likewise.

11 months agoDo not bother with reassociation in SLP discovery for single-lane
Richard Biener [Fri, 30 Aug 2024 09:39:53 +0000 (11:39 +0200)] 
Do not bother with reassociation in SLP discovery for single-lane

It just clutters the dump files and takes up compile-time.

* tree-vect-slp.cc (vect_build_slp_tree_2): Disable SLP
reassociation for single-lane.

11 months agoc++: Allow standard attributes after closing square bracket in new-type-id [PR110345]
Jakub Jelinek [Fri, 30 Aug 2024 07:40:34 +0000 (09:40 +0200)] 
c++: Allow standard attributes after closing square bracket in new-type-id [PR110345]

For C++ 26 P2552R3 I went through all the spots (except modules) where
attribute-specifier-seq appears in the grammar and tried to construct
a testcase in all those spots, for now for [[deprecated]] attribute.

The first thing I found is that we aren't parsing standard attributes in
noptr-new-declarator - https://eel.is/c++draft/expr.new#1

The following patch parses it there, for the non-outermost arrays
applies normally the attributes to the array type, for the outermost
where we just set *nelts and don't really build an array type just
warns that we ignore those attributes (or, do you think we should
just build an array type in that case and just take its element type?).

2024-08-30  Jakub Jelinek  <jakub@redhat.com>

PR c++/110345
* parser.cc (make_array_declarator): Add STD_ATTRS argument, set
declarator->std_attributes to it.
(cp_parser_new_type_id): Warn on non-ignored std_attributes on the
array declarator which is being omitted.
(cp_parser_direct_new_declarator): Parse standard attributes after
closing square bracket, pass it to make_array_declarator.
(cp_parser_direct_declarator): Pass std_attrs to make_array_declarator
instead of setting declarator->std_attributes manually.

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

11 months agoCheck avx upper register for parallel.
liuhongt [Thu, 29 Aug 2024 03:39:20 +0000 (11:39 +0800)] 
Check avx upper register for parallel.

For function arguments/return, when it's BLK mode, it's put in a
parallel with an expr_list, and the expr_list contains the real mode
and registers.
Current ix86_check_avx_upper_register only checked for SSE_REG_P, and
failed to handle that. The patch extend the handle to each subrtx.

gcc/ChangeLog:

PR target/116512
* config/i386/i386.cc (ix86_check_avx_upper_register): Iterate
subrtx to scan for avx upper register.
(ix86_check_avx_upper_stores): Inline old
ix86_check_avx_upper_register.
(ix86_avx_u128_mode_needed): Ditto, and replace
FOR_EACH_SUBRTX with call to new
ix86_check_avx_upper_register.

gcc/testsuite/ChangeLog:

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

11 months agoDaily bump.
GCC Administrator [Fri, 30 Aug 2024 00:19:54 +0000 (00:19 +0000)] 
Daily bump.

11 months agoSARIF output: implement embedded URLs in messages (§3.11.6; PR other/116419)
David Malcolm [Thu, 29 Aug 2024 22:48:32 +0000 (18:48 -0400)] 
SARIF output: implement embedded URLs in messages (§3.11.6; PR other/116419)

GCC diagnostic messages can contain URLs, such as to our documentation
when we suggest an option name to correct a misspelling.

SARIF message strings can contain embedded URLs in the plain text
messages (see SARIF v2.1.0 §3.11.6), but previously we were
simply dropping any URLs from the diagnostic messages.

This patch adds support for encoding URLs into messages in our SARIF
output, using the pp_token machinery added in the previous patch.

As well as supporting URLs, the patch also adjusts how we report
event IDs in SARIF message, so that rather than e.g.
  "text": "second 'free' here; first 'free' was at (1)"
we now report:
  "text": "second 'free' here; first 'free' was at [(1)](sarif:/runs/0/results/0/codeFlows/0/threadFlows/0/locations/0)"

i.e. the text "(1)" now has a embedded link referring within the sarif
log to the threadFlowLocation object for the other event, via JSON
pointer (see §3.10.3 "URIs that use the sarif scheme").  Doing so
requires the arious objects to know their index within their containing
array, requiring some reworking of how they are constructed.

gcc/ChangeLog:
PR other/116419
* diagnostic-event-id.h (diagnostic_event_id_t::zero_based): New.
* diagnostic-format-sarif.cc: Include "pretty-print-format-impl.h"
and "pretty-print-urlifier.h".
(sarif_result::sarif_result): Add param "idx_within_parent".
(sarif_result::get_index_within_parent): New accessor.
(sarif_result::m_idx_within_parent): New field.
(sarif_code_flow::sarif_code_flow): New ctor.
(sarif_code_flow::get_parent): New accessor.
(sarif_code_flow::get_index_within_parent): New accessor.
(sarif_code_flow::m_parent): New field.
(sarif_code_flow::m_thread_id_map): New field.
(sarif_code_flow::m_thread_flows_arr): New field.
(sarif_code_flow::m_all_tfl_objs): New field.
(sarif_thread_flow::sarif_thread_flow): Add "parent" and
"idx_within_parent" params.
(sarif_thread_flow::get_parent): New accessor.
(sarif_thread_flow::get_index_within_parent): New accessor.
(sarif_thread_flow::m_parent): New field.
(sarif_thread_flow::m_idx_within_parent): New field.
(sarif_thread_flow_location::sarif_thread_flow_location): New
ctor.
(sarif_thread_flow_location::get_parent): New accessor.
(sarif_thread_flow_location::get_index_within_parent): New
accessor.
(sarif_thread_flow_location::m_parent): New field.
(sarif_thread_flow_location::m_idx_within_parent): New field.
(sarif_builder::get_code_flow_for_event_ids): New accessor.
(class sarif_builder::sarif_token_printer): New.
(sarif_builder::m_token_printer): New member.
(sarif_builder::m_next_result_idx): New field.
(sarif_builder::m_current_code_flow): New field.
(sarif_code_flow::get_or_append_thread_flow): New.
(sarif_code_flow::get_thread_flow): New.
(sarif_code_flow::add_location): New.
(sarif_code_flow::get_thread_flow_loc_obj): New.
(sarif_thread_flow::add_location): Create the new
sarif_thread_flow_location internally, rather than passing
it in as a parm so that we can keep track of its index in
the array.  Return a reference to it.
(sarif_builder::sarif_builder): Initialize m_token_printer,
m_next_result_idx, and m_current_code_flow.
(sarif_builder::on_report_diagnostic): Pass index to
make_result_object.
(sarif_builder::make_result_object): Add "idx_within_parent" param
and pass to sarif_result ctor.  Pass code flow index to call to
make_code_flow_object.
(make_sarif_url_for_event): New.
(sarif_builder::make_code_flow_object): Add "idx_within_parent"
param and pass it to sarif_code_flow ctor.  Reimplement walking
of events so that we first create threadFlow objects for each
thread, then populate them with threadFlowLocation objects, so
that the IDs work.  Set m_current_code_flow whilst creating the
latter, so that we can create correct URIs for "%@".
(sarif_builder::make_thread_flow_location_object): Replace with...
(sarif_builder::populate_thread_flow_location_object): ...this.
(sarif_output_format::get_builder): New accessor.
(sarif_begin_embedded_link): New.
(sarif_end_embedded_link): New.
(sarif_builder::sarif_token_printer::print_tokens): New.
(diagnostic_output_format_init_sarif): Add "fmt" param; use it to
set the token printer and output format for the context.
(diagnostic_output_format_init_sarif_stderr): Move responsibility
for setting the context's output format to within
diagnostic_output_format_init_sarif.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
(test_sarif_diagnostic_context::test_sarif_diagnostic_context):
Likewise.
(selftest::test_make_location_object): Provide an idx for the
result.
(selftest::get_result_from_log): New.
(selftest::get_message_from_log): New.
(selftest::test_message_with_embedded_link): New test.
(selftest::diagnostic_format_sarif_cc_tests): Call it.
* pretty-print-format-impl.h: Include "diagnostic-event-id.h".
(pp_token::kind): Add "event_id".
(struct pp_token_event_id): New.
(is_a_helper <pp_token_event_id *>::test): New.
(is_a_helper <const pp_token_event_id *>::test): New.
* pretty-print.cc (pp_token::dump): Handle kind::event_id.
(pretty_printer::format): Update handling of "%@" in phase 2
so that we add a pp_token_event_id, rather that the text "(N)".
(default_token_printer): Handle pp_token::kind::event_id by
printing the text "(N)".

gcc/testsuite/ChangeLog:
PR other/116419
* gcc.dg/sarif-output/bad-pragma.c: New test.
* gcc.dg/sarif-output/test-bad-pragma.py: New test.
* gcc.dg/sarif-output/test-include-chain-2.py
(test_location_relationships): Update expected text of event to
include an intra-sarif URI to the other event.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
11 months agopretty-print: reimplement pp_format with a new struct pp_token
David Malcolm [Thu, 29 Aug 2024 22:48:27 +0000 (18:48 -0400)] 
pretty-print: reimplement pp_format with a new struct pp_token

The following patch rewrites the internals of pp_format.

A pretty_printer's output_buffer maintains a stack of chunk_info
instances, each one responsible for handling a call to pp_format, where
having a stack allows us to support re-entrant calls to pp_format on the
same pretty_printer.

Previously a chunk_info merely stored buffers of accumulated text
per unformatted run and per formatted argument.

This led to various special-casing for handling:

- urlifiers, needing class quoting_info to handle awkard cases where
  the run of quoted text could be split between stages 1 and 2
  of formatting

- dumpfiles, where the optinfo machinery could lead to objects being
  stashed during formatting for later replay to JSON optimization
  records

- in the C++ frontend, the format codes %H and %I can't be processed
  until we've seen both, leading to awkward code to manipulate the
  text buffers

Further, supporting URLs in messages in SARIF output (PR other/116419)
would add additional manipulations of text buffers, since our internal
pp_begin_url API gives the URL at the beginning of the wrapped text,
whereas SARIF's format for embedded URLs has the URL *after* the wrapped
text.  Also when handling "%@" we wouldn't necessarily know the URL of
an event ID until later, requiring further nasty special-case
manipulation of text buffers.

This patch rewrites pretty-print formatting by introducing a new
intermediate representation during formatting: pp_token and
pp_token_list.  Rather than simply accumulating a buffer of "char" in
the chunk_obstack during formatting, we now also accumulate a
pp_token_list, a doubly-linked list of pp_token, which can be:
- text buffers
- begin/end colorization
- begin/end quote
- begin/end URL
- "custom data" tokens

Working at the level of tokens rather than just text buffers allows the
various awkward special cases above to be replaced with uniform logic.
For example, all "urlification" is now done in phase 3 of formatting,
in one place, by looking for [..., BEGIN_QUOTE, TEXT, END_QUOTE, ...]
and injecting BEGIN_URL and END_URL wrapper tokens when the urlifier
has a URL for TEXT.  Doing so greatly simplifies the urlifier code,
allowing the removal of class quoting_info.

The tokens and token lists are allocated on the chunk_obstack, and so
there's no additional heap activity required, with the memory reclaimed
when the chunk_obstack is freed after phase 3 of formatting.

New kinds of pp_token can be added as needed to support output formats.
For example, the followup patch adds a token for "%@" for events IDs, to
better support SARIF output.

No functional change intended.

gcc/c/ChangeLog:
* c-objc-common.cc (c_tree_printer): Convert final param from
const char ** to pp_token_list &.

gcc/cp/ChangeLog:
* error.cc: Include "make-unique.h".
(deferred_printed_type::m_buffer_ptr): Replace with...
(deferred_printed_type::m_printed_text): ...this and...
(deferred_printed_type::m_token_list): ...this.
(deferred_printed_type::deferred_printed_type): Update ctors for
above changes.
(deferred_printed_type::set_text_for_token_list): New.
(append_formatted_chunk): Pass chunk_obstack to
append_formatted_chunk.
(add_quotes): Delete.
(cxx_format_postprocessor::handle): Reimplement to call
deferred_printed_type::set_text_for_token_list, rather than store
buffer pointers.
(defer_phase_2_of_type_diff): Replace param "buffer_ptr"
with "formatted_token_list".  Reimplement by storing
a pointer to formatted_token_list so that the postprocessor can
put its text there.
(cp_printer): Convert param "buffer_ptr" to
"formatted_token_list".  Update calls to
defer_phase_2_of_type_diff accordingly.

gcc/ChangeLog:
* diagnostic.cc (diagnostic_context::report_diagnostic): Don't
pass m_urlifier to pp_format, as urlification now happens in
phase 3.
* dump-context.h (class dump_pretty_printer): Update leading
comment.
(dump_pretty_printer::emit_items): Drop decl.
(dump_pretty_printer::set_optinfo): New.
(class dump_pretty_printer::stashed_item): Delete class.
(class dump_pretty_printer::custom_token_printer): New class.
(dump_pretty_printer::format_decoder_cb): Convert param from
const char ** to pp_token_list &.
(dump_pretty_printer::decode_format): Likewise.
(dump_pretty_printer::stash_item): Likewise.
(dump_pretty_printer::emit_any_pending_textual_chunks): Drop decl.
(dump_pretty_printer::m_stashed_items): Delete field.
(dump_pretty_printer::m_token_printer): New member data.
* dumpfile.cc (struct wrapped_optinfo_item): New.
(dump_pretty_printer::dump_pretty_printer): Update for dropping
of field m_stashed_items and new field m_token_printer.
(dump_pretty_printer::emit_items): Delete; we now use
pp_output_formatted_text..
(dump_pretty_printer::emit_any_pending_textual_chunks): Delete.
(dump_pretty_printer::stash_item): Convert param from
const char ** to pp_token_list &.
(dump_pretty_printer::format_decoder_cb): Likewise.
(dump_pretty_printer::decode_format): Likewise.
(dump_pretty_printer::custom_token_printer::print_tokens): New.
(dump_pretty_printer::custom_token_printer::emit_any_pending_textual_chunks):
New.
(dump_context::dump_printf_va): Call set_optinfo on the
dump_pretty_printer.  Replace call to emit_items with a call to
pp_output_formatted_text.
* opt-problem.cc (opt_problem::opt_problem): Replace call to
emit_items with call to set_optinfo and call to
pp_output_formatted_text.
* pretty-print-format-impl.h (struct pp_token): New.
(struct pp_token_text): New.
(is_a_helper <pp_token_text *>::test): New.
(is_a_helper <const pp_token_text *>::test): New.
(struct pp_token_begin_color): New.
(is_a_helper <pp_token_begin_color *>::test): New.
(is_a_helper <const pp_token_begin_color *>::test): New.
(struct pp_token_end_color): New.
(struct pp_token_begin_quote): New.
(struct pp_token_end_quote): New.
(struct pp_token_begin_url): New.
(is_a_helper <pp_token_begin_url*>::test): New.
(is_a_helper <const pp_token_begin_url*>::test): New.
(struct pp_token_end_url): New.
(struct pp_token_custom_data): New.
(is_a_helper <pp_token_custom_data *>::test): New.
(is_a_helper <const pp_token_custom_data *>::test): New.
(class pp_token_list): New.
(chunk_info::get_args): Drop.
(chunk_info::get_quoting_info): Drop.
(chunk_info::get_token_lists): New accessor.
(chunk_info::append_formatted_chunk): Add obstack & param.
(chunk_info::dump): New decls.
(chunk_info::m_args): Convert element type from const char * to
pp_token_list *.  Rewrite/update comment.
(chunk_info::m_quotes): Drop field.
* pretty-print-markup.h (class pp_token_list): New forward decl.
(pp_markup::context::context): Drop urlifier param; add
formatted_token_list param.
(pp_markup::context::push_back_any_text): New decl.
(pp_markup::context::m_urlifier): Drop field.
(pp_markup::context::m_formatted_token_list): New field.
* pretty-print-urlifier.h: Update comment.
* pretty-print.cc: Define INCLUDE_MEMORY.  Include
"make-unique.h".
(default_token_printer): New forward decl.
(obstack_append_string): Delete.
(urlify_quoted_string): Delete.
(pp_token::pp_token): New.
(pp_token::dump): New.
(allocate_object): New.
(class quoting_info): Delete.
(pp_token::operator new): New.
(pp_token::operator delete): New.
(pp_token_list::operator new): New.
(pp_token_list::operator delete): New.
(pp_token_list::pp_token_list): New.
(pp_token_list::~pp_token_list): New.
(pp_token_list::push_back_text): New.
(pp_token_list::push_back): New.
(pp_token_list::push_back_list): New.
(pp_token_list::pop_front): New.
(pp_token_list::remove_token): New.
(pp_token_list::insert_after): New.
(pp_token_list::replace_custom_tokens): New.
(pp_token_list::merge_consecutive_text_tokens): New.
(pp_token_list::apply_urlifier): New.
(pp_token_list::dump): New.
(chunk_info::append_formatted_chunk): Add obstack & param and use
it to reimplement in terms of token lists.
(chunk_info::pop_from_output_buffer): Drop m_quotes.
(chunk_info::on_begin_quote): Delete.
(chunk_info::dump): New.
(chunk_info::on_end_quote): Delete.
(push_back_any_text): New.
(pretty_printer::format): Drop "urlifier" param and quoting_info
logic.  Convert "formatters" and "args" from const ** to
pp_token_list **.  Reimplement so that rather than just
accumulating a text buffer in the chunk_obstack for each arg,
instead also accumulate a pp_token_list and pp_tokens for each
arg.
(auto_obstack::operator obstack &): New.
(quoting_info::handle_phase_3): Delete.
(pp_output_formatted_text): Reimplement in terms of manipulations
of pp_token_lists, rather than char buffers.  Call
default_token_printer, or m_token_printer's print_tokens vfunc.
(default_token_printer): New.
(pretty_printer::pretty_printer): Initialize m_token_printer in
both ctors.
(pp_markup::context::begin_quote): Reimplement to use token list.
(pp_markup::context::end_quote): Likewise.
(pp_markup::context::begin_highlight_color): Likewise.
(pp_markup::context::end_highlight_color): Likewise.
(pp_markup::context::push_back_any_text): New.
(selftest::test_merge_consecutive_text_tokens): New.
(selftest::test_custom_tokens_1): New.
(selftest::test_custom_tokens_2): New.
(selftest::pp_printf_with_urlifier): Drop "urlifier" param from
call to pp_format.
(selftest::test_urlification): Add test of the example from
pretty-print-format-impl.h.
(selftest::pretty_print_cc_tests): Call the new selftest
functions.
* pretty-print.h (class quoting_info): Drop forward decl.
(class pp_token_list): New forward decl.
(printer_fn): Convert final param from const char ** to
pp_token_list &.
(class token_printer): New.
(class pretty_printer): Add pp_output_formatted_text as friend.
(pretty_printer::set_token_printer): New.
(pretty_printer::format): Drop urlifier param as this now happens
in phase 3.
(pretty_printer::m_format_decoder): Update comment.
(pretty_printer::m_token_printer): New field.
(pp_format): Drop urlifier param.
* tree-diagnostic.cc (default_tree_printer): Convert final param
from const char ** to pp_token_list &.
* tree-diagnostic.h: Likewise for decl.

gcc/fortran/ChangeLog:
* error.cc (gfc_format_decoder): Convert final param from
const char **buffer_ptr to pp_token_list &formatted_token_list,
and update call to default_tree_printer accordingly.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
11 months agopretty-print: move class chunk_info into its own header
David Malcolm [Thu, 29 Aug 2024 22:48:20 +0000 (18:48 -0400)] 
pretty-print: move class chunk_info into its own header

No functional change intended.

gcc/cp/ChangeLog:
* error.cc: Include "pretty-print-format-impl.h".

gcc/ChangeLog:
* dumpfile.cc: Include "pretty-print-format-impl.h".
* pretty-print-format-impl.h: New file, based on material from
pretty-print.h.
* pretty-print.cc: Include "pretty-print-format-impl.h".
* pretty-print.h (chunk_info): Replace full declaration with
a forward decl, moving full decl to pretty-print-format-impl.h.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
11 months agoUse std::unique_ptr for optinfo_item
David Malcolm [Thu, 29 Aug 2024 22:48:16 +0000 (18:48 -0400)] 
Use std::unique_ptr for optinfo_item

As preliminary work towards an overhaul of how optinfo_items
interact with dump_pretty_printer, replace uses of optinfo_item * with
std::unique_ptr<optinfo_item> to make ownership clearer.

No functional change intended.

gcc/ChangeLog:
* config/aarch64/aarch64.cc: Define INCLUDE_MEMORY.
* config/arm/arm.cc: Likewise.
* config/i386/i386.cc: Likewise.
* config/loongarch/loongarch.cc: Likewise.
* config/riscv/riscv-vector-costs.cc: Likewise.
* config/riscv/riscv.cc: Likewise.
* config/rs6000/rs6000.cc: Likewise.
* dump-context.h (dump_context::emit_item): Convert "item" param
from * to const &.
(dump_pretty_printer::stash_item): Convert "item" param from
optinfo_ * to std::unique_ptr<optinfo_item>.
(dump_pretty_printer::emit_item): Likewise.
* dumpfile.cc: Include "make-unique.h".
(make_item_for_dump_gimple_stmt): Replace uses of optinfo_item *
with std::unique_ptr<optinfo_item>.
(dump_context::dump_gimple_stmt): Likewise.
(make_item_for_dump_gimple_expr): Likewise.
(dump_context::dump_gimple_expr): Likewise.
(make_item_for_dump_generic_expr): Likewise.
(dump_context::dump_generic_expr): Likewise.
(make_item_for_dump_symtab_node): Likewise.
(dump_pretty_printer::emit_items): Likewise.
(dump_pretty_printer::emit_any_pending_textual_chunks): Likewise.
(dump_pretty_printer::emit_item): Likewise.
(dump_pretty_printer::stash_item): Likewise.
(dump_pretty_printer::decode_format): Likewise.
(dump_context::dump_printf_va): Fix overlong line.
(make_item_for_dump_dec): Replace uses of optinfo_item * with
std::unique_ptr<optinfo_item>.
(dump_context::dump_dec): Likewise.
(dump_context::dump_symtab_node): Likewise.
(dump_context::begin_scope): Likewise.
(dump_context::emit_item): Likewise.
* gimple-loop-interchange.cc: Define INCLUDE_MEMORY.
* gimple-loop-jam.cc: Likewise.
* gimple-loop-versioning.cc: Likewise.
* graphite-dependences.cc: Likewise.
* graphite-isl-ast-to-gimple.cc: Likewise.
* graphite-optimize-isl.cc: Likewise.
* graphite-poly.cc: Likewise.
* graphite-scop-detection.cc: Likewise.
* graphite-sese-to-poly.cc: Likewise.
* graphite.cc: Likewise.
* opt-problem.cc: Likewise.
* optinfo.cc (optinfo::add_item): Convert "item" param from
optinfo_ * to std::unique_ptr<optinfo_item>.
(optinfo::emit_for_opt_problem): Update for change to
dump_context::emit_item.
* optinfo.h: Add #error to fail immediately if INCLUDE_MEMORY
wasn't defined, rather than fail to find std::unique_ptr.
(optinfo::add_item): Convert "item" param from optinfo_ * to
std::unique_ptr<optinfo_item>.
* sese.cc: Define INCLUDE_MEMORY.
* targhooks.cc: Likewise.
* tree-data-ref.cc: Likewise.
* tree-if-conv.cc: Likewise.
* tree-loop-distribution.cc: Likewise.
* tree-parloops.cc: Likewise.
* tree-predcom.cc: Likewise.
* tree-ssa-live.cc: Likewise.
* tree-ssa-loop-ivcanon.cc: Likewise.
* tree-ssa-loop-ivopts.cc: Likewise.
* tree-ssa-loop-prefetch.cc: Likewise.
* tree-ssa-loop-unswitch.cc: Likewise.
* tree-ssa-phiopt.cc: Likewise.
* tree-ssa-threadbackward.cc: Likewise.
* tree-ssa-threadupdate.cc: Likewise.
* tree-vect-data-refs.cc: Likewise.
* tree-vect-generic.cc: Likewise.
* tree-vect-loop-manip.cc: Likewise.
* tree-vect-loop.cc: Likewise.
* tree-vect-patterns.cc: Likewise.
* tree-vect-slp-patterns.cc: Likewise.
* tree-vect-slp.cc: Likewise.
* tree-vect-stmts.cc: Likewise.
* tree-vectorizer.cc: Likewise.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/dump_plugin.c: Define INCLUDE_MEMORY.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
11 months agoFortran: fix ICE with use with rename of namelist member [PR116530]
Harald Anlauf [Thu, 29 Aug 2024 19:21:39 +0000 (21:21 +0200)] 
Fortran: fix ICE with use with rename of namelist member [PR116530]

gcc/fortran/ChangeLog:

PR fortran/116530
* trans-io.cc (transfer_namelist_element): Prevent NULL pointer
dereference.

gcc/testsuite/ChangeLog:

PR fortran/116530
* gfortran.dg/use_rename_12.f90: New test.

11 months agohppa: Fix handling of unscaled index addresses on HP-UX
John David Anglin [Thu, 29 Aug 2024 15:53:45 +0000 (11:53 -0400)] 
hppa: Fix handling of unscaled index addresses on HP-UX

The PA-RISC architecture uses the top two bits of memory pointers
to select space registers.  The space register ID is ored with the
pointer offset to compute the global virtual address for an access.

The new late combine passes broke gcc on HP-UX.  One of these passes
runs after reload.  The existing code assumed no unscaled index
instructions would be created after reload as the REG_POINTER flag
is not reliable after reload.  The new pass sometimes interchanged
the base and index registers, causing these instructions to fault
when the wrong space register was selected.

I investigated various alternatives to try to retain generation
of unscaled index instructions on HP-UX.  It's not possible to
simply treat unscaled index addresses as not legitimate after
reload as sometimes instructions need to be rerecognized after
reload.  So, we needed to allow unscaled index addresses after
reload and to disable the late combine passes.

I had noticed that reversing the current order of base and index
register canonicalization resulted in more accesses using unscaled
index addresses.  However, this exposed issues with the REG_POINTER
flag.

The flag is not propagated when a constant is added to a pointer.
Tree opimization sometimes adds two pointers.  I found that I had
to treat the result as a pointer but the addition generally corrupts
the space register bits.  These get fixed when a negative pointer
is added.  Finally, the REG_POINTER flag isn't set when a pointer
is passed in a function call.  I couldn't get this approach to work.

Thus, I came to the conclusion that the best approach was to
disable use of unscaled index addresses on HP-UX.  I don't think
this impacts performance significantly.  Code size might get
slightly larger but we get some or more back from having the late
combine passes.

2024-08-29  John David Anglin  <danglin@gcc.gnu.org>

gcc/ChangeLog:

* config/pa/pa.cc (load_reg): Don't generate load with
unscaled index address when !TARGET_NO_SPACE_REGS.
(pa_legitimate_address_p): Only allow unscaled index
addresses when TARGET_NO_SPACE_REGS.

11 months agoexpand: Allow widdening optab when expanding popcount==1 [PR116508]
Andrew Pinski [Wed, 28 Aug 2024 22:03:53 +0000 (15:03 -0700)] 
expand: Allow widdening optab when expanding popcount==1 [PR116508]

After adding popcount{qi,hi}2 to the aarch64 backend, I noticed that
the expansion for popcount==1 was no longer trying to do the trick
of handling popcount==1 as `(arg ^ (arg - 1)) > arg - 1`. The problem
is the expansion was using OPTAB_DIRECT, when using OPTAB_WIDEN
will allow modes which are smaller than SImode (in the aarch64 case).

Note QImode's cost still needs some improvements so part of popcnt-eq-1.c
is xfailed. Though there is a check to make sure the costs are compared now.

Built and tested on aarch64-linux-gnu.

PR middle-end/116508

gcc/ChangeLog:

* internal-fn.cc (expand_POPCOUNT): Use OPTAB_WIDEN for PLUS and
XOR/AND expansion.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
11 months agoada: Fix assertion failure on private limited with clause
Eric Botcazou [Fri, 16 Aug 2024 23:18:43 +0000 (01:18 +0200)] 
ada: Fix assertion failure on private limited with clause

This checks that the name is of an entity before accessing its Entity field.

gcc/ada/

* sem_ch8.adb (Has_Private_With): Add test on Is_Entity_Name.

11 months agoada: Fix internal error on concatenation of discriminant-dependent component
Eric Botcazou [Fri, 16 Aug 2024 14:03:30 +0000 (16:03 +0200)] 
ada: Fix internal error on concatenation of discriminant-dependent component

This only occurs with optimization enabled, but the expanded code is always
wrong because it reuses the formal parameter of an initialization procedure
associated with a discriminant (a discriminal in GNAT parlance) outside of
the initialization procedure.

gcc/ada/

* checks.adb (Selected_Length_Checks.Get_E_Length): For a
component of a record with discriminants and if the expression is
a selected component, try to build an actual subtype from its
prefix instead of from the discriminal.

11 months agoada: Missing legality check when type completed
Steve Baird [Mon, 5 Aug 2024 22:53:12 +0000 (15:53 -0700)] 
ada: Missing legality check when type completed

Refine previous fix to better handle tagged cases.

gcc/ada/

* sem_ch6.adb (Check_Discriminant_Conformance): Immediately after
calling Is_Immutably_Limited_Type, perform an additional test that
one might reasonably imagine would instead have been part of
Is_Immutably_Limited_Type. The new test is a call to a new
function Has_Tagged_Limited_Partial_View whose implementation
includes a call to Incomplete_Or_Partial_View, which cannot be
easily be called from Is_Immutably_Limited_Type (because sem_aux,
which is in the closure of the binder, cannot easily "with"
sem_util).
* sem_aux.adb (Is_Immutably_Limited): Include
N_Derived_Type_Definition case when testing Limited_Present flag.

11 months agoada: Fix missing finalization for call to function returning limited view
Eric Botcazou [Fri, 16 Aug 2024 09:28:37 +0000 (11:28 +0200)] 
ada: Fix missing finalization for call to function returning limited view

The call is legal because it is made from the body, which has visibility on
the nonlimited view, so this changes the code in Expand_Call_Helper to look
at the Etype of the call node instead of the Etype of the function.

gcc/ada/

* exp_ch6.adb (Expand_Call_Helper): In the case of a function
call, look at the Etype of the call node to determine whether
finalization actions need to be performed.

11 months agoada: Print Insertion_Sloc in dmsg
Viljar Indus [Mon, 22 Jul 2024 06:45:03 +0000 (09:45 +0300)] 
ada: Print Insertion_Sloc in dmsg

gcc/ada/

* erroutc.adb (dmsg): Print Insertion_Sloc.

11 months agoada: Use the same warning character in continuation messages
Viljar Indus [Fri, 19 Jul 2024 07:34:03 +0000 (10:34 +0300)] 
ada: Use the same warning character in continuation messages

For consitency sake the main and continuation messages should
use the same warning characters.

gcc/ada/

* exp_aggr.adb (Expand_Range_Component): Remove extra warning
character. Use same conditional warning char.
* freeze.adb (Warn_Overlay): Use named warning character.
* restrict.adb (Id_Case): Use named warning character.
* sem_prag.adb (Rewrite_Assertion_Kind): Use default warning
character.

11 months agoada: Restructure continuation message for pretty printing
Viljar Indus [Wed, 17 Jul 2024 10:08:23 +0000 (13:08 +0300)] 
ada: Restructure continuation message for pretty printing

Continuation messages should have the same location
as the main message. If the goal is to point to a different
location then Error_Msg_Sloc should be used to change
the location of the continuation message.

gcc/ada/

* par-ch4.adb (P_Name): Use Error_Msg_Sloc for the location of the
continuation message.

11 months agoada: Improve Inspection_Point warning
Viljar Indus [Tue, 16 Jul 2024 11:17:41 +0000 (14:17 +0300)] 
ada: Improve Inspection_Point warning

Ensure that the primary and sub message point
to the same location in order to assure that the
submessages get pretty printed in the correct order.

gcc/ada/

* exp_prag.adb (Expand_Pragma_Inspection_Point): Improve sub
diagnostic generation.

11 months agoada: Avoid creating continuation messages without an intended parent
Viljar Indus [Wed, 14 Aug 2024 12:24:10 +0000 (15:24 +0300)] 
ada: Avoid creating continuation messages without an intended parent

The messages modified in this patch do not have a clear intended
parent. This causes a lot of issues when grouping continuation
messages together with their parent. This can be confusing as it
is not obvious what was the parent message that caused this
problem or in worst case scenarios the message not being printed
alltogether.

These modified messages do not seem to be related to any concrete
error message and thus should be treated as independent messages.

gcc/ada/

* sem_ch12.adb (Abandon_Instantiation): Remove continuation
characters from the error message.
* sem_ch13.adb (Check_False_Aspect_For_Derived_Type): Remove
continuation characters from the error message.
* sem_ch6.adb (Assert_False): Avoid creating a continuation
message without a parent. If no primary message is created then
the message is considered as primary.

gcc/testsuite/ChangeLog:

* gnat.dg/interface6.adb: Adjust test.

11 months agoada: Parse the attributes of continuation messages correctly
Viljar Indus [Fri, 21 Jun 2024 10:28:40 +0000 (13:28 +0300)] 
ada: Parse the attributes of continuation messages correctly

Currently unless pretty printing is enabled we avoid parsing
the message strings for continuation messages. This leads
to inconsistent state for the Error_Msg_Object-s that are
being created.

gcc/ada/

* erroutc.adb (Prescan_Message): Avoid not parsing all of the
message attributes.
* erroutc.ads: Update the documentation.

11 months agoada: Use consistent type continuations messages
Viljar Indus [Fri, 21 Jun 2024 10:19:10 +0000 (13:19 +0300)] 
ada: Use consistent type continuations messages

Avoid cases where the main message is an error and the
continuation is a warning.

gcc/ada/

* freeze.adb: Remove warning insertion characters from a
continuation message.
* sem_util.adb: Remove warning insertion characters from a
continuation message.
* sem_warn.adb: Use same warning character as the main message.

11 months agoada: Extract line fitting algorithm
Viljar Indus [Mon, 1 Apr 2024 08:50:10 +0000 (11:50 +0300)] 
ada: Extract line fitting algorithm

Separate the line fitting algorithm from the general line
printing algorithm.

gcc/ada/

* erroutc.ads: Add new method Output_Text_Within
* erroutc.adb: Move the line fitting code to a new method called
Output_Text_Within

11 months agoada: Ensure validity checks for private scalar types
Piotr Trojanek [Fri, 9 Aug 2024 15:52:51 +0000 (17:52 +0200)] 
ada: Ensure validity checks for private scalar types

To check validity of data values, we must strip privacy from their
types.

gcc/ada/

* checks.adb (Expr_Known_Valid): Use Validated_View, which strips
type derivation and privacy.
* exp_ch3.adb (Simple_Init_Private_Type): Kill checks inside
unchecked conversions, just like in Simple_Init_Scalar_Type.

11 months agoada: Display actual line length in line length check
Viljar Indus [Tue, 13 Aug 2024 08:37:31 +0000 (11:37 +0300)] 
ada: Display actual line length in line length check

gcc/ada/

* styleg.adb (Check_Line_Max_Length): Add the actual line length
to the diagnostic message.

11 months agoada: Proper handling for iterator associations in array aggregates
Gary Dismukes [Mon, 12 Aug 2024 22:50:57 +0000 (22:50 +0000)] 
ada: Proper handling for iterator associations in array aggregates

The compiler was flagging type-mismatch errors on iterated component
associations in array aggregates of form "for C in <iterator_name>",
improperly requiring the type of the iterator to be the array index
type. The parser can't distinguish whether the association is one
involving an actual discrete choice vs. an iterator specification,
and creates an N_Iterated_Component_Association with a Defining_Identifer
and Discrete_Choices, and the analysis phase has to disambiguate this,
determining whether to create an N_Iterator_Specification node for
the association. A related change is to revise the similar code for
iterated associations of container aggregates, to allow forms of
iterator objects other than just function calls.

gcc/ada/

* sem_aggr.adb (Resolve_Array_Aggregate): Add loop over associations to locate
N_Iterated_Component_Associations that do not have an Iterator_Specification,
and if their Discrete_Choices list consists of a single choice, analyze it and
if it's the name of an iterator object, then create an Iterator_Specification
and associate it with the iterated component association.
(Resolve_Iterated_Association): Replace test for function call with test of
Is_Object_Reference, to handle other forms of iterator objects in container
aggregates.

11 months agoada: First controlling parameter aspect
Javier Miranda [Mon, 12 Aug 2024 18:50:09 +0000 (18:50 +0000)] 
ada: First controlling parameter aspect

gcc/ada/

* usage.adb (Usage): Document switch -gnatw_j
* doc/gnat_rm/gnat_language_extensions.rst: Add documentation.
* gnat_rm.texi: Regenerate.

11 months agoada: Update documentation for conditional when constructs
Justin Squirek [Mon, 12 Aug 2024 18:31:39 +0000 (18:31 +0000)] 
ada: Update documentation for conditional when constructs

This patch moves the documentation for conditional when constructs out of the
curated set (e.g. into -gnatX0).

gcc/ada/

* doc/gnat_rm/gnat_language_extensions.rst: Move conditional when
constructs out of the curated set.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.

11 months agoAllow subregs around constant displacements [PR116516]
Richard Sandiford [Thu, 29 Aug 2024 13:00:23 +0000 (14:00 +0100)] 
Allow subregs around constant displacements [PR116516]

This patch fixes a regression introduced by g:708ee71808ea61758e73.
x86_64 allows addresses of the form:

  (zero_extend:DI (subreg:SI (symbol_ref:DI "foo") 0))

Before the previous patch, a lax SUBREG check meant that we would
treat the subreg as a base and reload it into a base register.
But that wasn't what the target was expecting.  Instead we should
treat "foo" as a constant displacement, to match:

leal foo, <dest>

After the patch, we recognised that "foo" isn't a base register,
but ICEd on it rather than handling it as a displacement.

With or without the recent patches, if the address had instead been:

  (zero_extend:DI
    (subreg:SI (plus:DI (reg:DI R) (symbol_ref:DI "foo") 0)))

then we would have treated "foo" as the displacement and R as the base
or index, as expected.  The problem was that the code that does this was
rejecting all subregs of objects, rather than just subregs of variable
objects.

gcc/
PR middle-end/116516
* rtlanal.cc (strip_address_mutations): Allow subregs around
constant displacements.

gcc/testsuite/
PR middle-end/116516
* gcc.c-torture/compile/pr116516.c: New test.

11 months agoMake some smallest_int_mode_for_size calls cope with failure
Richard Sandiford [Thu, 29 Aug 2024 13:00:23 +0000 (14:00 +0100)] 
Make some smallest_int_mode_for_size calls cope with failure

smallest_int_mode_for_size now returns an optional mode rather
than aborting on failure.  This patch adjusts a couple of callers
so that they fail gracefully when no mode exists.

There should be no behavioural change, since anything that triggers
the new return paths would previously have aborted.  I just think
this is how the code would have been written if the option had been
available earlier.

gcc/
* dse.cc (find_shift_sequence): Allow smallest_int_mode_for_size
to failure.
* optabs.cc (expand_twoval_binop_libfunc): Likewise.

11 months agoAVR: target/115830 - Make better use of SREG.N and SREG.Z.
Georg-Johann Lay [Sun, 4 Aug 2024 17:46:43 +0000 (19:46 +0200)] 
AVR: target/115830 - Make better use of SREG.N and SREG.Z.

This patch adds new CC modes CCN and CCZN for operations that
set SREG.N, resp. SREG.Z and SREG.N.  Add peephole2 patterns
to generate new compute + branch insns that make use
of the Z and N flags.  Most of these patterns need their own
asm output routines that don't do all the micro-optimizations
that the ordinary outputs may perform, as the latter have no
requirement to set CC in a usable way.

We don't use cmpelim because it cannot provide scratch regs
(which peephole2 can), and some of the patterns require a
scratch reg, whereas the same operations that don't set REG_CC
don't require a scratch.  See the comments in avr.md for details.

The existing add.for.cc* patterns are simplified as they no
more cover QImode, which is handled in a separate QImode case.
Apart from that, it adds 3 patterns for subtractions and one
pattern for shift left, all for multi-byte cases (HI, PSI, SI).

The add.for.cc* patterns now use CC[Z]Nmode, instead of the
formerly abuse of CCmode.

PR target/115830
gcc/
* config/avr/avr-modes.def (CCN, CCZN): New CC_MODEs.
* config/avr/avr-protos.h (avr_cond_branch): New from
ret_cond_branch.
(avr_out_plus_set_N, avr_op8_ZN_operator, avr_cmp0_code)
(avr_out_op8_set_ZN, avr_len_op8_set_ZN): New protos.
(ccn_reg_rtx, cczn_reg_rtx): New declarations.
* config/avr/avr.cc (avr_cond_branch): New from ret_cond_branch.
(avr_cond_string): Add bool cc_overflow_unusable argument.
(avr_print_operand) ['L']: Like 'j' but overflow unusable.
['K']: Like 'k' but overflow unusable.
(avr_out_plus_set_ZN): Remove handling of QImode.
(avr_out_plus_set_N, avr_op8_ZN_operator, avr_cmp0_code)
(avr_out_op8_set_ZN, avr_len_op8_set_ZN): New functions.
(avr_adjust_insn_length) [ADJUST_LEN_ADD_SET_N]: Hande case.
(avr_class_max_nregs): All MODE_CCs occupy one hard reg.
(avr_hard_regno_nregs): Same.
(avr_hard_regno_mode_ok) [REG_CC]: Allow all MODE_CC.
(pass_manager.h, context.h, tree-pass.h): Include them.
(ccn_reg_rtx, cczn_reg_rtx): New GTY variables.
(avr_init_expanders): Initialize them.
(avr_option_override): Run peephole2 a second time.
* config/avr/avr.md (adjust_len) [add_set_N]: New attr value.
(ALLCC, HI_SI): New mode iterators.
(CCname): New mode attribute.
(eqnegtle, cmp_signed, op8_ZN): New code iterators.
(swap, SWAP): New code attributes.
(branch): Handle CCNmode and CCZNmode.  Assimilate...
(difficult_branch): ...this insn.
(p1m1): Remove.
(gen_add_for_<code>_<mode>): Adjust to CCNmode and CCZNmode. Use
HISI as mode iterator.  Extend peephole2s that produce them.
(*add.for.eqne.<mode>): Extend to *add.for.cc[z]n.<mode>.
(*ashift.for.ccn.<mode>): New insn and peephole2 to make them.
(*sub.for.cczn.<mode>, *sub-extend<mode>.for.cczn.<mode>):
New insns and peephole2s to make them.
(*op8.for.cczn.<code>): New insn and peephole2 to make them.
* config/avr/predicates.md (const_1_to_3_operand)
(abs1_abs2_operand, signed_comparison_operator)
(op8_ZN_operator): New predicates.
gcc/testsuite/
* gcc.target/avr/pr115830-add.c: New test.
* gcc.target/avr/pr115830-add-c.c: New test.
* gcc.target/avr/pr115830-add-i.c: New test.
* gcc.target/avr/pr115830-and.c: New test.
* gcc.target/avr/pr115830-asl.c: New test.
* gcc.target/avr/pr115830-asr.c: New test.
* gcc.target/avr/pr115830-ior.c: New test.
* gcc.target/avr/pr115830-lsr.c: New test.
* gcc.target/avr/pr115830-asl32.c: New test.
* gcc.target/avr/pr115830-sub.c: New test.
* gcc.target/avr/pr115830-sub-ext.c: New test.

11 months agoc++: don't remove labels during coro-early-expand-ifns [PR105104]
Arsen Arsenović [Fri, 16 Aug 2024 17:07:01 +0000 (19:07 +0200)] 
c++: don't remove labels during coro-early-expand-ifns [PR105104]

In some scenarios, it is possible for the CFG cleanup to cause one of
the labels mentioned in CO_YIELD, which coro-early-expand-ifns intends
to remove, to become part of some statement.  As a result, when that
label is removed, the statement it became part of becomes invalid,
crashing the compiler.

There doesn't appear to be a reason to remove the labels (anymore, at
least), so let's not do that.

PR c++/105104

gcc/ChangeLog:

* coroutine-passes.cc (execute_early_expand_coro_ifns): Don't
remove any labels.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/torture/pr105104.C: New test.

11 months agoAVR: Outsource code for avr-specific passes to new avr-passes.cc.
Georg-Johann Lay [Wed, 28 Aug 2024 09:18:45 +0000 (11:18 +0200)] 
AVR: Outsource code for avr-specific passes to new avr-passes.cc.

gcc/
* config.gcc (extra_objs) [target=avr]: Add avr-passes.o.
* config/avr/t-avr (avr-passes.o): New rule to make it.
* config/avr/avr.cc (#define INCLUDE_VECTOR): Remove.
(cfganal.h, cfgrtl.h, context.h, tree-pass.h, print-rtl.h): Don't
include them.
(avr_strict_signed_p, avr_strict_unsigned_p, avr_2comparisons_rhs)
(make_avr_pass_recompute_notes, make_avr_pass_casesi)
(make_avr_pass_ifelse, make_avr_pass_pre_proep, avr_split_tiny_move)
(emit_move_ccc, emit_move_ccc_after, reg_seen_between_p)
(avr_maybe_adjust_cfa, avr_redundant_compare_regs)
(avr_parallel_insn_from_insns, avr_is_casesi_sequence)
(avr_optimize_casesi, avr_redundant_compare, make_avr_pass_fuse_add)
(avr_optimize_2ifelse, avr_rest_of_handle_ifelse)
(avr_casei_sequence_check_operands)
Move functions...
(avr_pass_data_fuse_add, avr_pass_data_ifelse)
(avr_pass_data_casesi, avr_pass_data_recompute_notes)
(avr_pass_data_pre_proep): Move objects...
(avr_pass_fuse_add, avr_pass_pre_proep, avr_pass_recompute_notes)
(avr_pass_ifelse, avr_pass_casesi, AVR_LdSt_Props): Move classes...
* config/avr/avr-passes.cc: ... to this new C++ module.
(struct Ranges): Move to...
* config/avr/ranges.h: ...this new file.
* config/avr/avr-protos.h: Adjust comments.

11 months agotestsuite: Fix up refactored scanltranstree.exp functions [PR116522]
Alex Coplan [Thu, 29 Aug 2024 10:31:40 +0000 (11:31 +0100)] 
testsuite: Fix up refactored scanltranstree.exp functions [PR116522]

When adding RTL variants of the scan-ltrans-tree* functions in:
r15-3254-g3f51f0dc88ec21c1ec79df694200f10ef85915f4
I messed up the name of the underlying scan function to invoke.  The
code currently attempts to invoke functions named
scan{,-not,-dem,-dem-not} but should instead be invoking
scan-dump{,-not,-dem,-dem-not}.  This patch fixes that.

gcc/testsuite/ChangeLog:

PR testsuite/116522
* lib/scanltranstree.exp: Fix name of underlying scan function
used for scan-ltrans-{tree,rtl}-dump{,-not,-dem,-dem-not}.

11 months agoRISC-V: Fix subreg of VLS modes larger than a vector [PR116086].
Robin Dapp [Tue, 27 Aug 2024 08:25:34 +0000 (10:25 +0200)] 
RISC-V: Fix subreg of VLS modes larger than a vector [PR116086].

When the source mode is potentially larger than one vector (e.g. an
LMUL2 mode for VLEN=128) we don't know which vector the subreg actually
refers to.  For zvl128b and LMUL=2 the subreg in (subreg:V2DI (reg:V4DI))
could actually be the a full (high) vector register of a two-register
group (at VLEN=128) or the higher part of a single register (at VLEN>128).

As the subreg is statically ambiguous we prevent such situations in
can_change_mode_class.

The culprit in PR116086 is

 _12 = BIT_FIELD_REF <vect_cst__42, 128, 128>;

which can be expanded with a vector-vector extract (from V4DI to V2DI).
This patch adds a VLS-mode vector-vector extract that handles "halving"
cases like this one by sliding down the source vector, thus making sure
the correct part is used.

PR target/116086

gcc/ChangeLog:

* config/riscv/autovec.md (vec_extract<mode><v_half>): Add
vector-vector extract for VLS modes.
* config/riscv/riscv.cc (riscv_can_change_mode_class): Forbid
VLS modes larger than one vector.
* config/riscv/vector-iterators.md: Add vector-vector extract
iterators.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp: Add effective target checks for
zvl256b and zvl512b.
* gcc.target/riscv/rvv/autovec/pr116086-2-run.c: New test.
* gcc.target/riscv/rvv/autovec/pr116086-2.c: New test.
* gcc.target/riscv/rvv/autovec/pr116086.c: New test.

11 months agoi386: Support wide immediate constants in STV.
Roger Sayle [Thu, 29 Aug 2024 03:19:28 +0000 (21:19 -0600)] 
i386: Support wide immediate constants in STV.

This patch provides more accurate costs/gains for (wide) immediate
constants in STV, suitably adjusting the costs/gains when the highpart
and lowpart words are the same.

2024-08-28  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/i386/i386-features.cc (timode_immed_const_gain): New
function to determine the gain/cost on a CONST_WIDE_INT.
(timode_scalar_chain::compute_convert_gain): Fix whitespace.
<case CONST_WIDE_INT>: Provide more accurate estimates using
timode_immed_const_gain.
<case AND>: Handle CONSTANT_SCALAR_INT_P (src).

11 months agoWrite LF_MFUNC_ID types for CodeView struct member functions
Mark Harmstone [Mon, 26 Aug 2024 21:16:11 +0000 (22:16 +0100)] 
Write LF_MFUNC_ID types for CodeView struct member functions

If recording the definition of a struct member function, write an
LF_MFUNC_ID type rather than an LF_FUNC_ID. This links directly to the
struct type, rather than to an LF_STRING_ID with its name.

gcc/
* dwarf2codeview.cc (enum cv_leaf_type): Add LF_MFUNC_ID.
(write_lf_mfunc_id): New function.
(add_lf_func_id): New function.
(add_lf_mfunc_id): New function.
(add_function): Call add_lf_func_id or add_lf_mfunc_id.

11 months agoRecord member functions in CodeView struct definitions
Mark Harmstone [Mon, 26 Aug 2024 21:40:56 +0000 (22:40 +0100)] 
Record member functions in CodeView struct definitions

CodeView has two ways of recording struct member functions.
Non-overloaded functions have an LF_ONEMETHOD sub-type in the field
list, which records the name and the function type (LF_MFUNCTION).
Overloaded functions have an LF_METHOD instead, which points to an
LF_METHODLIST, which is an array of links to various LF_MFUNCTION types.

gcc/
* dwarf2codeview.cc (enum cv_leaf_type): Add LF_MFUNCTION,
LF_METHODLIST, LF_METHOD, and LF_ONEMETHOD.
(struct codeview_subtype): Add lf_onemethod and lf_method to union.
(struct lf_methodlist_entry): New type.
(struct codeview_custom_type): Add lf_mfunc_id, lf_mfunction, and
lf_methodlist to union.
(struct codeview_method): New type.
(struct method_hasher): New type.
(get_type_num_subroutine_type): Add forward declaration.
(write_lf_fieldlist): Handle LF_ONEMETHOD and LF_METHOD.
(write_lf_mfunction): New function.
(write_lf_methodlist): New function.
(write_custom_types): Handle LF_MFUNCTION and LF_METHODLIST.
(add_struct_function): New function.
(get_mfunction_type): New function.
(is_templated_func): New function.
(get_type_num_struct): Handle DW_TAG_subprogram child DIEs.
(get_type_num_subroutine_type): Add containing_class_type, this_type,
and this_adjustment params, and handle creating LF_MFUNCTION types as
well as LF_PROCEDURE.
(get_type_num): New params for get_type_num_subroutine_type.
(add_function): New params for get_type_num_subroutine_type.
* dwarf2codeview.h (CV_METHOD_VANILLA, CV_METHOD_VIRTUAL): Define.
(CV_METHOD_STATIC, CV_METHOD_FRIEND, CV_METHOD_INTRO): Likewise.
(CV_METHOD_PUREVIRT, CV_METHOD_PUREINTRO): Likewise.

11 months agoRecord static data members in CodeView structs
Mark Harmstone [Mon, 26 Aug 2024 20:34:46 +0000 (21:34 +0100)] 
Record static data members in CodeView structs

Record LF_STMEMBER field list subtypes to represent static data members
in structs.

gcc/
* dwarf2codeview.cc (enum cv_leaf_type): Add LF_STMEMBER.
(struct codeview_subtype): Add lf_static_member to union.
(write_lf_fieldlist): Handle LF_STMEMBER.
(add_struct_member): New function.
(add_struct_static_member): New function.
(get_accessibility): New function.
(get_type_num_struct): Split out into add_struct_member and
get_accessibility, and handle static members.

11 months agoHandle scoping in CodeView LF_FUNC_ID types
Mark Harmstone [Mon, 26 Aug 2024 20:19:51 +0000 (21:19 +0100)] 
Handle scoping in CodeView LF_FUNC_ID types

If a function is in a namespace, create an LF_STRING_ID type for the
name of its parent, and record this in the LF_FUNC_ID type we create
for the function.

gcc/
* dwarf2codeview.cc (enum cf_leaf_type): Add LF_STRING_ID.
(struct codeview_custom_type): Add lf_string_id to union.
(struct string_id_hasher): New type.
(string_id_htab): New global variable.
(write_lf_string_id): New function.
(write_custom_types): Call write_lf_string_id.
(codeview_debug_finish): Free string_id_htab.
(add_string_id): New function.
(get_scope_string_id): New function.
(add_function): Call get_scope_string_id and set scope.

11 months agoHandle namespaced names for CodeView
Mark Harmstone [Mon, 26 Aug 2024 20:03:58 +0000 (21:03 +0100)] 
Handle namespaced names for CodeView

Run all CodeView names through a new function get_name, which chains
together a DIE's DW_AT_name with that of its parent to create a
C++-style name.

gcc/
* dwarf2codeview.cc (get_name): New function.
(add_enum_forward_def): Call get_name.
(get_type_num_enumeration_type): Call get_name.
(add_struct_forward_def): Call get_name.
(get_type_num_struct): Call get_name.
(add_variable): Call get_name.
(add function): Call get_name.
* dwarf2out.cc (get_die_parent): Rename to dw_get_die_parent and make
non-static.
(generate_type_signature): Handle renamed get_die_parent.
* dwarf2out.h (dw_get_die_parent): Add declaration.

11 months agoDaily bump.
GCC Administrator [Thu, 29 Aug 2024 00:19:25 +0000 (00:19 +0000)] 
Daily bump.

11 months agoc++: wrong error due to std::initializer_list opt [PR116476]
Marek Polacek [Wed, 28 Aug 2024 19:45:49 +0000 (15:45 -0400)] 
c++: wrong error due to std::initializer_list opt [PR116476]

Here maybe_init_list_as_array gets elttype=field, init={NON_LVALUE_EXPR <2>}
and it tries to convert the init's element type (int) to field
using implicit_conversion, which works, so overall maybe_init_list_as_array
is successful.

But it constifies init_elttype so we end up with "const int".  Later,
when we actually perform the conversion and invoke field::field(T&&),
we end up with this error:

  error: binding reference of type 'int&&' to 'const int' discards qualifiers

So I think maybe_init_list_as_array should try to perform the conversion,
like it does below with fc.

PR c++/116476

gcc/cp/ChangeLog:

* call.cc (maybe_init_list_as_array): Try convert_like and see if it
worked.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/initlist-opt2.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
11 months agoPR modula2/116181 remove ODR warnings from library interface files
Gaius Mulley [Wed, 28 Aug 2024 21:51:11 +0000 (22:51 +0100)] 
PR modula2/116181 remove ODR warnings from library interface files

This patch removes the warnings generated by -Wodr from the library
interface between modula-2 and C.

gcc/m2/ChangeLog:

PR modula2/116181
* Make-lang.in (MC_SRC_FLAGS): New macro.
(m2/mc-boot/$(SRC_PREFIX)%.o): Use MC_SRC_FLAGS.
(m2/mc-boot-ch/$(SRC_PREFIX)%.o): Ditto.
(m2/gm2-libs-boot/M2RTS.o): Ditto.
(m2/gm2-libs-boot/%.o): Ditto.
(GM2-LIBS-BOOT-H): New macro.
(m2/gm2-libs-boot/RTcodummy.o): Use MC_SRC_FLAGS.
Remove gm2-libs-host.h from the dependancy.
(m2/gm2-libs-boot/wrapc.o): Use MC_SRC_FLAGS.
Add dependancy GM2-LIBS-BOOT-H.
(m2/gm2-libs-boot/UnixArgs.o): Ditto.
(m2/gm2-libs-boot/choosetemp.o): Ditto.
(m2/gm2-libs-boot/errno.o): Ditto.
(m2/gm2-libs-boot/dtoa.o): Ditto.
(m2/gm2-libs-boot/ldtoa.o): Ditto.
(m2/gm2-libs-boot/termios.o): Ditto.
(m2/gm2-libs-boot/SysExceptions.o): Ditto.
(m2/gm2-compiler-boot/M2GCCDeclare.o): Add gm2-libs-ch to the
search path.
(m2/gm2-compiler-boot/M2Error.o): Ditto.
(m2/gm2-compiler-boot/%.o): Ditto.
(m2/pge-boot/%.o): Ditto.
* gm2-gcc/m2color.cc (m2color_colorize_start): Replace parameter
type char to void and recast to char * when calling colorize_start.
* gm2-gcc/m2color.h (m2color_colorize_start): Replace parameter
type char to void.
* gm2-gcc/m2type.h: Remove #if 0 block.
* gm2-libs-ch/SysExceptions.c (DECL_PROC_T): Provide alternative
defines for MC an gm2.
(PROC_FUNC): Ditto.
(EXTERN): Force undefine and redefine.
(SysExceptions_InitExceptionHandlers): Rewrite function
declaration using defined macros.
(_M2_SysExceptions_init): Use EXTERN.
(_M2_SysExceptions_finish): Replace with ...
(_M2_SysExceptions_fini): ... this and add parameters.
* gm2-libs-ch/UnixArgs.cc (gm2-libs-host.h): Include.
(GUnixArgs.h): Include.
(GM2RTS.h): Include.
(UnixArgs_GetArgV): Change return type to void *.
(UnixArgs_GetEnvV): Ditto.
* gm2-libs-ch/m2rts.h (M2RTS_RegisterModule_Cstr): Add new
conditional macro.
(M2RTS_RequestDependant): Remove.
(M2RTS_RegisterModule): Ditto.
(M2RTS_Terminate): Ditto.
(M2RTS_DeconstructModules): Ditto.
(M2RTS_Halt): Ditto.
(_M2_M2RTS_init): Ditto.
(M2RTS_ConstructModules): Ditto.
* gm2-libs-ch/termios.c (_termios_C): Define.
(EXTERN): Add conditional definition.
(doSetUnset): New function.
(_M2_termios_init): Add correct parameters.
(_M2_termios_finish): Ditto.
(_M2_termios_fini): Ditto.
* mc-boot-ch/GSysExceptions.c (DECL_PROC_T): New define.
(PROC_FUNC): Ditto.
(EXTERN): Force undef.
(SysExceptions_InitExceptionHandlers): Rewrite.
* mc-boot-ch/Glibc.c (libc_open): Rename parameter
oflag to flags.
* mc-boot-ch/Gtermios.cc (_termios_C): New define.
(KillTermios): Change parameter type from
struct termios * to termios_TERMIOS.
(tcsnow): Rewrite.
(tcsnow): Rewrite.
(tcsdrain): Rewrite.
(tcsflush): Rewrite.
(cfgetospeed): Rewrite.
(cfgetispeed): Rewrite.
(cfsetospeed): Rewrite.
(cfsetispeed): Rewrite.
(cfsetspeed): Rewrite.
(cfsetspeed): Rewrite.
(tcgetattr): Rewrite.
(tcsetattr): Rewrite.
(cfmakeraw): Rewrite.
(tcsendbreak): Rewrite.
(tcdrain): Rewrite.
(tcflushi): Rewrite.
(tcflusho): Rewrite.
(tcflushio): Rewrite.
(tcflowoni): Rewrite.
(tcflowoffi): Rewrite.
(tcflowono): Rewrite.
(tcflowoffo): Rewrite.
(GetFlag): Rewrite.
(SetFlag): Rewrite.
(GetChar): Rewrite.
(SetChar): Rewrite.
(InitTermios): Rewrite.
* pge-boot/GM2RTS.cc: Regenerate.
* pge-boot/GSysExceptions.cc: Ditto.
* pge-boot/Gtermios.cc: Ditto.
* pge-boot/m2rts.h: Rewrite.
* mc-boot-ch/GSYSTEM.h: New file.
* mc-boot-ch/GSysExceptions.h: New file.
* mc-boot-ch/Gtermios.h: New file.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
11 months agoexpand: Add debug dump on the cost for `popcount==1` expand
Andrew Pinski [Mon, 26 Aug 2024 22:14:24 +0000 (15:14 -0700)] 
expand: Add debug dump on the cost for `popcount==1` expand

While working on PR 114224, I found it would be useful to dump the
different costs of the expansion to make easier to understand why one
was chosen over the other.

Changes since v1:
* v2: make the dump a single line

Bootstrapped and tested on x86_64-linux-gnu.
Build and tested for aarch64-linux-gnu.

gcc/ChangeLog:

* internal-fn.cc (expand_POPCOUNT): Dump the costs for
the two choices.

11 months agolibstdc++: Fix autoconf check for O_NONBLOCK in <fcntl.h>
Jonathan Wakely [Wed, 28 Aug 2024 11:38:18 +0000 (12:38 +0100)] 
libstdc++: Fix autoconf check for O_NONBLOCK in <fcntl.h>

I misused the AC_CHECK_DECL macro, assuming that it behaved like
AC_CHECK_DECLS and always defined a HAVE_xxx macro if the decl was
found. Instead, the [action-if-found] shell commands are needed to
defined HAVE_O_NONBLOCK explicitly.

libstdc++-v3/ChangeLog:

* configure.ac: Fix check for O_NONBLOCK.
* config.h.in: Regenerate.
* configure: Regenerate.

11 months agolibstdc++: Fix -Wunused-parameter warnings in Networking TS headers
Jonathan Wakely [Wed, 28 Aug 2024 11:21:56 +0000 (12:21 +0100)] 
libstdc++: Fix -Wunused-parameter warnings in Networking TS headers

libstdc++-v3/ChangeLog:

* include/experimental/io_context: Remove name of unused
parameter.
* include/experimental/socket: Add [[maybe_unused]] attribute.

11 months agolibstdc++: Fix -Wunused-variable warning in <format>
Jonathan Wakely [Wed, 28 Aug 2024 11:09:58 +0000 (12:09 +0100)] 
libstdc++: Fix -Wunused-variable warning in <format>

libstdc++-v3/ChangeLog:

* include/std/format (format_parse_context::check_dynamic_spec):
Add [[maybe_unused]] attribute and comment.

11 months agolibstdc++: Remove unused typedef in <ranges>
Jonathan Wakely [Wed, 28 Aug 2024 10:49:08 +0000 (11:49 +0100)] 
libstdc++: Remove unused typedef in <ranges>

This local typedef should have been removed in r14-6199-g45630fbcf7875b.

libstdc++-v3/ChangeLog:

* include/std/ranges (to): Remove unused typedef.

11 months agodoc: Add Dhruv Matani to Contributors
Jonathan Wakely [Wed, 28 Aug 2024 10:49:46 +0000 (11:49 +0100)] 
doc: Add Dhruv Matani to Contributors

gcc/ChangeLog:

* doc/contrib.texi (Contributors): Add Dhruv Matani.

11 months agolibstdc++: Fix @file for target-specific opt_random.h
Kim Gräsman [Tue, 27 Aug 2024 16:11:29 +0000 (17:11 +0100)] 
libstdc++: Fix @file for target-specific opt_random.h

A few of these files self-identified as ext/random.tcc, update to use
the actual basename.

libstdc++-v3/ChangeLog:

* config/cpu/aarch64/opt/ext/opt_random.h: Improve doxygen file
docs.
* config/cpu/i486/opt/ext/opt_random.h: Likewise.

11 months agolibstdc++: Fix @headername for bits/cpp_type_traits.h
Kim Gräsman [Tue, 27 Aug 2024 16:08:47 +0000 (17:08 +0100)] 
libstdc++: Fix @headername for bits/cpp_type_traits.h

There is no file ext/type_traits, point it to ext/type_traits.h instead.

libstdc++-v3/ChangeLog:

* include/bits/cpp_type_traits.h: Improve doxygen file docs.

11 months agoAVR: Overhaul the avr-ifelse RTL optimization pass.
Georg-Johann Lay [Fri, 23 Aug 2024 09:34:43 +0000 (11:34 +0200)] 
AVR: Overhaul the avr-ifelse RTL optimization pass.

Mini-pass avr-ifelse realizes optimizations that replace two cbranch
insns with one comparison and two branches.  This patch adds the
following improvements:

- The right operand of the comparisons may also be REGs.
  Formerly only CONST_INT was handled.

- The RTX code of the first comparison in no more restricted
  to (effectively) EQ.

- When the second cbranch is located in the fallthrough path
  of the first cbranch, then difficult (expensive) comparisons
  can always be avoided.  This may require to swap the branch
  targets.  (When the second cbranch is located after the target
  label of the first one, then getting rid of difficult branches
  would require to reorder blocks.)

- The code has been cleaned up:  avr_rest_of_handle_ifelse() now
  just scans the insn stream for optimization candidates.  The code
  that actually performs the transformation has been outsourced to
  the new function avr_optimize_2ifelse().

- The code to find a better representation for reg-const_int comparisons
  has been split into two parts:  First try to find codes such that the
  right-hand sides of the comparisons are the same (avr_2comparisons_rhs).
  When this succeeds then one comparison can serve two branches, and
  that function tries to get rid of difficult branches.  This is always
  possible when the second cbranch is located in the fallthrough path
  of the first one.

Some final notes on why we don't use compare-elim:  1) The two cbranch
insns may come with different scratch operands depending on the chosen
constraint alternatives.  There are cases where the outgoing comparison
requires a scratch but only one incoming cbranch has one.  2) Avoiding
difficult branches can be achieved by rewiring basic blocks.
compare-elim doesn't do that; it doesn't even know the costs of the
branch codes.  3)  avr_2comparisons_rhs() may de-canonicalize a
comparison to achieve its goal.  compare-elim doesn't know how to do
that.  4) There are more reasons, see for example the commit message
and discussion for PR115830.

avr_2comparisons_rhs tries to decompose the interval as given by some
[u]intN_t into three intervals using the new Ranges struct that
implemens set operations on finite unions of intervals.
Sadly, value-range.h is not well suited for that, and writing a
wrapper around it that avoids all corner case ICEs would be more
laborious than struct Ranges.

gcc/
* config/avr/avr.cc (INCLUDE_VECTOR): Define it.
(cfganal.h): Include it.
(Ranges): New struct.
(avr_2comparisons_rhs, avr_redundant_compare_regs)
(avr_strict_signed_p, avr_strict_unsigned_p): New static functions.
(avr_redundant_compare): Overhaul: Allow more cases.
(avr_optimize_2ifelse): New static function, outsourced from...
(avr_rest_of_handle_ifelse): ...this method.
gcc/testsuite/
* gcc.target/avr/torture/ifelse-c.h: New file.
* gcc.target/avr/torture/ifelse-d.h: New file.
* gcc.target/avr/torture/ifelse-q.h: New file.
* gcc.target/avr/torture/ifelse-r.h: New file.
* gcc.target/avr/torture/ifelse-c-i8.c: New test.
* gcc.target/avr/torture/ifelse-d-i8.c: New test.
* gcc.target/avr/torture/ifelse-q-i8.c: New test.
* gcc.target/avr/torture/ifelse-r-i8.c: New test.
* gcc.target/avr/torture/ifelse-c-i16.c: New test.
* gcc.target/avr/torture/ifelse-d-i16.c: New test.
* gcc.target/avr/torture/ifelse-q-i16.c: New test.
* gcc.target/avr/torture/ifelse-r-i16.c: New test.
* gcc.target/avr/torture/ifelse-c-u16.c: New test.
* gcc.target/avr/torture/ifelse-d-u16.c: New test.
* gcc.target/avr/torture/ifelse-q-u16.c: New test.
* gcc.target/avr/torture/ifelse-r-u16.c: New test.

11 months agoAdd gcc ka.po
Joseph Myers [Wed, 28 Aug 2024 16:31:13 +0000 (16:31 +0000)] 
Add gcc ka.po

* ka.po: New file.

11 months agoc++: ICE with ()-init and TARGET_EXPR eliding [PR116424]
Marek Polacek [Tue, 27 Aug 2024 22:25:17 +0000 (18:25 -0400)] 
c++: ICE with ()-init and TARGET_EXPR eliding [PR116424]

Here we crash on a cp_gimplify_expr/TARGET_EXPR assert:

      gcc_checking_assert (!TARGET_EXPR_ELIDING_P (*expr_p)
                           || !TREE_ADDRESSABLE (TREE_TYPE (*expr_p)));

We cannot elide the TARGET_EXPR because we're taking its address.

It is set as eliding in massage_init_elt.  I've tried to not set
TARGET_EXPR_ELIDING_P when the context is not direct-initialization.
That didn't work: even when it's not direct-initialization now, it
can become one later, for instance, after split_nonconstant_init.
One problem is that replace_placeholders_for_class_temp_r will replace
placeholders in non-eliding TARGET_EXPRs with the slot, but if we then
elide the TARGET_EXPR, we end up with a "stray" VAR_DECL and crash.
(Only some TARGET_EXPRs are handled by replace_decl.)

I thought I'd have to go back to
<https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651163.html> but
then I realized that this problem occurrs only with ()-init but not
{}-init.  With {}-init, there is no problem, because we are clearing
TARGET_EXPR_ELIDING_P in process_init_constructor_record:

       /* We can't actually elide the temporary when initializing a
          potentially-overlapping field from a function that returns by
          value.  */
       if (ce->index
           && TREE_CODE (next) == TARGET_EXPR
           && unsafe_copy_elision_p (ce->index, next))
         TARGET_EXPR_ELIDING_P (next) = false;

But that does not happen for ()-init because we have no ce->index.
()-init doesn't allow brace elision so we don't really reshape them.

But I can just move the clearing a few lines down and then it handles
both ()-init and {}-init.

PR c++/116424

gcc/cp/ChangeLog:

* typeck2.cc (process_init_constructor_record): Move the clearing of
TARGET_EXPR_ELIDING_P down.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/paren-init38.C: New test.

11 months agoaarch64: Assume zero gather/scatter set-up cost for -mtune=generic
Richard Sandiford [Wed, 28 Aug 2024 15:41:09 +0000 (16:41 +0100)] 
aarch64: Assume zero gather/scatter set-up cost for -mtune=generic

generic_vector_cost is not currently used by any SVE target
by default; it has to be specifically selected by -mtune=generic.
Its SVE costing has historically been somewhat idealised, since
it predated any actual SVE cores.  This seems like a useful
tradition to continue, at least for testing purposes.

The ideal case is that gathers and scatters do not induce a specific
one-off overhead.  This patch therefore sets the gather/scatter init
costs to zero.

This patch is necessary to switch -mtune=generic over to the
"new" vector costs.

gcc/
* config/aarch64/tuning_models/generic.h (generic_sve_vector_cost):
Set gather_load_x32_init_cost and gather_load_x64_init_cost to 0.

11 months agoaarch64: Fix gather x32/x64 selection
Richard Sandiford [Wed, 28 Aug 2024 15:41:08 +0000 (16:41 +0100)] 
aarch64: Fix gather x32/x64 selection

The SVE gather and scatter costs are classified based on whether
they do 4 loads per 128 bits (x32) or 2 loads per 128 bits (x64).
The number after the "x" refers to the number of bits in each
"container".

However, the test for which to use was based on the element size
rather than the container size.  This meant that we'd use the
overly conservative x32 costs for VNx2SI gathers.  VNx2SI gathers
are really .D gathers in which the upper half of each extension
result is ignored.

This patch is necessary to switch -mtune=generic over to the
"new" vector costs.

gcc/
* config/aarch64/aarch64.cc (aarch64_detect_vector_stmt_subtype)
(aarch64_vector_costs::add_stmt_cost): Use the x64 cost rather
than x32 cost for all VNx2 modes.

11 months agoaarch64: Add a test for zeroing <64bits>x2_t structures
Richard Sandiford [Wed, 28 Aug 2024 15:41:08 +0000 (16:41 +0100)] 
aarch64: Add a test for zeroing <64bits>x2_t structures

g:8d6c6fbc5271dde433998c09407b30e2cf195420 improved the code
generated for functions like:

  void test_s8 (int8x8x2_t *ptr) { *ptr = (int8x8x2_t) {}; }

Previously we would load zero from the constant pool, whereas
now we just use "stp xzr, xzr".  This patch adds a test for
this improvement.

gcc/testsuite/
* gcc.target/aarch64/struct_zero.c: New test.

11 months agoTweak documentation of ASM_INPUT_P
Richard Sandiford [Wed, 28 Aug 2024 15:37:53 +0000 (16:37 +0100)] 
Tweak documentation of ASM_INPUT_P

The documentation of ASM_INPUT_P implied that the flag has no
effect on ASM_EXPRs that have operands (and which therefore must be
extended asms).  In fact we require ASM_INPUT_P to be false for all
extended asms.

gcc/
* tree.h (ASM_INPUT_P): Fix documentation.

11 months agoLibquadmath: update doc for some constants
Francois-Xavier Coudert [Tue, 20 Aug 2024 16:42:31 +0000 (18:42 +0200)] 
Libquadmath: update doc for some constants

libquadmath/ChangeLog:

* libquadmath.texi (M_LOG2Eq, M_LOG10Eq, M_1_PIq,
M_2_PIq, M_2_SQRTPIq, M_SQRT1_2q): Adjust descriptioni
of these constants.

11 months agogimple ssa: switchconv: Use __builtin_popcount and support more types in exp transfor...
Filip Kastl [Wed, 28 Aug 2024 13:47:44 +0000 (15:47 +0200)] 
gimple ssa: switchconv: Use __builtin_popcount and support more types in exp transform [PR116355]

The gen_pow2p function generates (a & -a) == a as a fallback for
POPCOUNT (a) == 1.  Not only is the bitmagic not equivalent to
POPCOUNT (a) == 1 but it also introduces UB (consider signed
a = INT_MIN).

This patch rewrites gen_pow2p to always use __builtin_popcount instead.
This means that what the end result GIMPLE code is gets decided by an
already existing machinery in a later pass.  That is a cleaner solution
I think.  This existing machinery also uses a ^ (a - 1) > a - 1 which is
the correct bitmagic.

While rewriting gen_pow2p I had to add logic for converting the
operand's type to a type that __builtin_popcount accepts.  I naturally
also added this logic to gen_log2.  Thanks to this, exponential index
transform gains the capability to handle all operand types with
precision at most that of long long int.

gcc/ChangeLog:

PR tree-optimization/116355
* tree-switch-conversion.cc (can_log2): Add capability to
suggest converting the operand to a different type.
(gen_log2): Add capability to generate a conversion in case the
operand is of a type incompatible with the logarithm operation.
(can_pow2p): New function.
(gen_pow2p): Rewrite to use __builtin_popcount instead of
manually inserting an internal fn call or bitmagic.  Also add
capability to generate a conversion.
(switch_conversion::is_exp_index_transform_viable): Call
can_pow2p.  Store types suggested by can_log2 and gen_log2.
(switch_conversion::exp_index_transform): Params of gen_pow2p
and gen_log2 changed so update their calls.
* tree-switch-conversion.h: Add m_exp_index_transform_log2_type
and m_exp_index_transform_pow2p_type to switch_conversion class
to track type conversions needed to generate the "is power of 2"
and logarithm operations.

gcc/testsuite/ChangeLog:

PR tree-optimization/116355
* gcc.target/i386/switch-exp-transform-1.c: Don't test for
presence of POPCOUNT internal fn after switch conversion.  Test
for it after __builtin_popcount has had a chance to get
expanded.
* gcc.target/i386/switch-exp-transform-3.c: Also test char and
short.

Signed-off-by: Filip Kastl <fkastl@suse.cz>
11 months agolibstdc++: avoid -Wsign-compare
Jason Merrill [Tue, 27 Aug 2024 17:17:20 +0000 (13:17 -0400)] 
libstdc++: avoid -Wsign-compare

-Wsign-compare complained about these comparisons between (unsigned) size_t
and (signed) streamsize, or between (unsigned) native_handle_type
and (signed) -1.  Fixed by adding casts to unify the types.

libstdc++-v3/ChangeLog:

* include/std/istream: Add cast to avoid -Wsign-compare.
* include/std/stacktrace: Likewise.

11 months agotestsuite: Add scan-ltrans-rtl* for use in dg-final [PR116140]
Alex Coplan [Tue, 27 Aug 2024 16:51:12 +0000 (16:51 +0000)] 
testsuite: Add scan-ltrans-rtl* for use in dg-final [PR116140]

This extends the scan-ltrans-tree* helpers to create RTL variants.  This
is needed to check the behaviour of an RTL pass under LTO.

gcc/ChangeLog:

PR libstdc++/116140
* doc/sourcebuild.texi: Document ltrans-rtl value of kind for
scan-<kind>-dump*.

gcc/testsuite/ChangeLog:

PR libstdc++/116140
* lib/scanltranstree.exp (scan-ltrans-rtl-dump): New.
(scan-ltrans-rtl-dump-not): New.
(scan-ltrans-rtl-dump-dem): New.
(scan-ltrans-rtl-dump-dem-not): New.
(scan-ltrans-rtl-dump-times): New.

11 months agoAdd debug overload for slp_instance
Richard Biener [Wed, 28 Aug 2024 09:06:00 +0000 (11:06 +0200)] 
Add debug overload for slp_instance

I found it helpful to be able to print a whole SLP instance from gdb.

* tree-vect-slp.cc (debug): Add overload for slp_instance.

11 months agoFix leak of SLP nodes when building store interleaving
Richard Biener [Wed, 28 Aug 2024 09:04:07 +0000 (11:04 +0200)] 
Fix leak of SLP nodes when building store interleaving

The following fixes a leak of the discovered single-lane store
SLP nodes from which we only use their children.  This uncovers
a latent reference counting issue in the interleaving build where
we fail to increment their reference count.

* tree-vect-slp.cc (vect_build_slp_store_interleaving):
Fix reference counting.
(vect_build_slp_instance): Release rhs_nodes.

11 months agoSplit out vect_build_slp_store_interleaving
Richard Biener [Tue, 27 Aug 2024 12:19:38 +0000 (14:19 +0200)] 
Split out vect_build_slp_store_interleaving

This splits out SLP store interleaving into a separate function.

* tree-vect-slp.cc (vect_build_slp_store_interleaving): Split
out from ...
(vect_build_slp_instance): Here.

11 months agoc++: add missing -Wc++??-extensions checks
Jason Merrill [Tue, 27 Aug 2024 17:14:45 +0000 (13:14 -0400)] 
c++: add missing -Wc++??-extensions checks

The pedwarns for each of these features should be silenced by
the appropriate -Wno-c++??-extensions.

The handle_pragma_diagnostic_impl change is necessary so that we handle
-Wc++23-extensions early so it's available to interpret_float while lexing.

gcc/c-family/ChangeLog:

* c-pragma.cc (handle_pragma_diagnostic_impl): Also handle
-Wc++23-extensions early.
* c-lex.cc (interpret_float): Use -Wc++23-extensions for extended
floating point literal pedwarn.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_simple_type_specifier): Use
-Wc++20-extensions for auto parameter pedwarn.
* pt.cc (do_decl_instantiation, do_type_instantiation): Use
-Wc++11-extensions for 'extern template'.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/extern_template-7.C: New test.
* g++.dg/cpp23/ext-floating19.C: New test.
* g++.dg/cpp2a/abbrev-fn1.C: New test.

11 months agolibgomp: Add interop types and routines to OpenMP's headers and module
Tobias Burnus [Wed, 28 Aug 2024 09:50:43 +0000 (11:50 +0200)] 
libgomp: Add interop types and routines to OpenMP's headers and module

This commit adds OpenMP 5.1+'s interop enumeration, type and routine
declarations to the C/C++ header file and, new in OpenMP TR13, also to
the Fortran module and omp_lib.h header file.

While a stub implementation is provided, only with foreign runtime
support by the libgomp GPU plugins and with the 'interop' directive,
this becomes really useful.

libgomp/ChangeLog:

* fortran.c (omp_get_interop_str_, omp_get_interop_name_,
omp_get_interop_type_desc_, omp_get_interop_rc_desc_): Add.
* libgomp.map (GOMP_5.1.3): New; add interop routines.
* omp.h.in: Add interop typedefs, enum and prototypes.
(__GOMP_DEFAULT_NULL): Define.
(omp_target_memcpy_async, omp_target_memcpy_rect_async):
Use it for the optional depend argument.
* omp_lib.f90.in: Add paramters and interfaces for interop.
* omp_lib.h.in: Likewise; move F90 '&' to column 81 for
-ffree-length-80.
* target.c (omp_get_num_interop_properties, omp_get_interop_int,
omp_get_interop_ptr, omp_get_interop_str, omp_get_interop_name,
omp_get_interop_type_desc, omp_get_interop_rc_desc): Add.
* config/gcn/target.c (omp_get_num_interop_properties,
omp_get_interop_int, omp_get_interop_ptr, omp_get_interop_str,
omp_get_interop_name, omp_get_interop_type_desc,
omp_get_interop_rc_desc): Add.
* config/nvptx/target.c (omp_get_num_interop_properties,
omp_get_interop_int, omp_get_interop_ptr, omp_get_interop_str,
omp_get_interop_name, omp_get_interop_type_desc,
omp_get_interop_rc_desc): Add.
* testsuite/libgomp.c-c++-common/interop-routines-1.c: New test.
* testsuite/libgomp.c-c++-common/interop-routines-2.c: New test.
* testsuite/libgomp.fortran/interop-routines-1.F90: New test.
* testsuite/libgomp.fortran/interop-routines-2.F90: New test.
* testsuite/libgomp.fortran/interop-routines-3.F: New test.
* testsuite/libgomp.fortran/interop-routines-4.F: New test.
* testsuite/libgomp.fortran/interop-routines-5.F: New test.
* testsuite/libgomp.fortran/interop-routines-6.F: New test.
* testsuite/libgomp.fortran/interop-routines-7.F90: New test.

11 months agolibstdc++: fix testcase regexp
Jason Merrill [Tue, 27 Aug 2024 17:16:47 +0000 (13:16 -0400)] 
libstdc++: fix testcase regexp

The unescaped * broke the match.

libstdc++-v3/ChangeLog:

* testsuite/20_util/default_delete/void_neg.cc: Fix regexp quoting.

11 months agolibstdc++: avoid -Wzero-as-null-pointer-constant
Jason Merrill [Tue, 27 Aug 2024 17:15:52 +0000 (13:15 -0400)] 
libstdc++: avoid -Wzero-as-null-pointer-constant

libstdc++-v3/ChangeLog:

* include/std/coroutine (coroutine_handle): Use nullptr instead of
0 as initializer for _M_fr_ptr.

11 months agolibstdc++: add missing return
Jason Merrill [Tue, 27 Aug 2024 17:14:05 +0000 (13:14 -0400)] 
libstdc++: add missing return

The return seems to have been lost in the r15-1858 RAII overhaul.

libstdc++-v3/ChangeLog:

* include/bits/stl_uninitialized.h (__uninitialized_move_copy): Add
missing return.

11 months agolibstdc++: remove extra semicolons
Jason Merrill [Tue, 27 Aug 2024 17:13:40 +0000 (13:13 -0400)] 
libstdc++: remove extra semicolons

The semicolons after each macro invocation here end up following the closing
brace of a function, leading to -Wextra-semi pedwarns.

libstdc++-v3/ChangeLog:

* include/decimal/decimal.h (_DEFINE_DECIMAL_BINARY_OP_WITH_INT):
Remove redundant semicolons.

11 months agoTest: Move pr116278 run test to dg/torture [NFC]
Pan Li [Mon, 19 Aug 2024 02:02:46 +0000 (10:02 +0800)] 
Test: Move pr116278 run test to dg/torture [NFC]

Move the run test of pr116278 to dg/torture and leave the risc-v the
asm check under risc-v part.

PR target/116278

gcc/testsuite/ChangeLog:

* gcc.target/riscv/pr116278-run-1.c: Take compile instead of run.
* gcc.target/riscv/pr116278-run-2.c: Ditto.
* gcc.dg/torture/pr116278-run-1.c: New test.
* gcc.dg/torture/pr116278-run-2.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
11 months agoVect: Reconcile the const_int operand type of unsigned .SAT_ADD
Pan Li [Tue, 27 Aug 2024 07:01:02 +0000 (15:01 +0800)] 
Vect: Reconcile the const_int operand type of unsigned .SAT_ADD

The .SAT_ADD has 2 operand, when one of the operand may be INTEGER_CST.
For example _1 = .SAT_ADD (_2, 9) comes from below sample code.

Form 3:
  #define DEF_VEC_SAT_U_ADD_IMM_FMT_3(T, IMM)                          \
  T __attribute__((noinline))                                          \
  vec_sat_u_add_imm##IMM##_##T##_fmt_3 (T *out, T *in, unsigned limit) \
  {                                                                    \
    unsigned i;                                                        \
    T ret;                                                             \
    for (i = 0; i < limit; i++)                                        \
      {                                                                \
        out[i] = __builtin_add_overflow (in[i], IMM, &ret) ? -1 : ret; \
      }                                                                \
  }

DEF_VEC_SAT_U_ADD_IMM_FMT_3(uint64_t, 9)

It will fail to vectorize as the vectorizable_call will check the
operands is type_compatiable but the imm will be (const_int 9) with
the SImode, which is different from _2 (DImode).  Aka:

uint64_t _1;
uint64_t _2;
_1 = .SAT_ADD (_2, 9);

This patch would like to reconcile the imm operand to the operand type
mode of _2 by fold_convert to make the vectorizable_call happy.

The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. The x86 bootstrap tests.
3. The x86 fully regression tests.

gcc/ChangeLog:

* tree-vect-patterns.cc (vect_recog_sat_add_pattern): Add fold
convert for const_int to the type of operand 0.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/vec_sat_arith.h: Add test helper macros.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-1.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-10.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-11.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-12.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-13.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-14.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-15.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-2.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-3.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-4.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-5.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-6.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-7.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-8.c: New test.
* gcc.target/riscv/rvv/autovec/binop/vec_sat_u_add_imm_reconcile-9.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
11 months agoRISC-V: Add missing mode_idx for vrol and vror
Kito Cheng [Tue, 27 Aug 2024 13:27:02 +0000 (21:27 +0800)] 
RISC-V: Add missing mode_idx for vrol and vror

We add pattern for vector rotate, but seems like we forgot adding
mode_idx which used in AVL propgation (riscv-avlprop.cc).

gcc/ChangeLog:

* config/riscv/vector.md (mode_idx): Add vrol and vror.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/rotr.c: New.

11 months agoMatch: Support form 1 for scalar signed integer .SAT_ADD
Pan Li [Mon, 26 Aug 2024 02:11:38 +0000 (10:11 +0800)] 
Match: Support form 1 for scalar signed integer .SAT_ADD

This patch would like to support the form 1 of the scalar signed
integer .SAT_ADD.  Aka below example:

Form 1:
  #define DEF_SAT_S_ADD_FMT_1(T, UT, MIN, MAX) \
  T __attribute__((noinline))                  \
  sat_s_add_##T##_fmt_1 (T x, T y)             \
  {                                            \
    T sum = (UT)x + (UT)y;                     \
    return (x ^ y) < 0                         \
      ? sum                                    \
      : (sum ^ x) >= 0                         \
        ? sum                                  \
        : x < 0 ? MIN : MAX;                   \
  }

DEF_SAT_S_ADD_FMT_1(int64_t, uint64_t, INT64_MIN, INT64_MAX)

We can tell the difference before and after this patch if backend
implemented the ssadd<m>3 pattern similar as below.

Before this patch:
   4   │ __attribute__((noinline))
   5   │ int64_t sat_s_add_int64_t_fmt_1 (int64_t x, int64_t y)
   6   │ {
   7   │   int64_t sum;
   8   │   long unsigned int x.0_1;
   9   │   long unsigned int y.1_2;
  10   │   long unsigned int _3;
  11   │   long int _4;
  12   │   long int _5;
  13   │   int64_t _6;
  14   │   _Bool _11;
  15   │   long int _12;
  16   │   long int _13;
  17   │   long int _14;
  18   │   long int _16;
  19   │   long int _17;
  20   │
  21   │ ;;   basic block 2, loop depth 0
  22   │ ;;    pred:       ENTRY
  23   │   x.0_1 = (long unsigned int) x_7(D);
  24   │   y.1_2 = (long unsigned int) y_8(D);
  25   │   _3 = x.0_1 + y.1_2;
  26   │   sum_9 = (int64_t) _3;
  27   │   _4 = x_7(D) ^ y_8(D);
  28   │   _5 = x_7(D) ^ sum_9;
  29   │   _17 = ~_4;
  30   │   _16 = _5 & _17;
  31   │   if (_16 < 0)
  32   │     goto <bb 3>; [41.00%]
  33   │   else
  34   │     goto <bb 4>; [59.00%]
  35   │ ;;    succ:       3
  36   │ ;;                4
  37   │
  38   │ ;;   basic block 3, loop depth 0
  39   │ ;;    pred:       2
  40   │   _11 = x_7(D) < 0;
  41   │   _12 = (long int) _11;
  42   │   _13 = -_12;
  43   │   _14 = _13 ^ 9223372036854775807;
  44   │ ;;    succ:       4
  45   │
  46   │ ;;   basic block 4, loop depth 0
  47   │ ;;    pred:       2
  48   │ ;;                3
  49   │   # _6 = PHI <sum_9(2), _14(3)>
  50   │   return _6;
  51   │ ;;    succ:       EXIT
  52   │
  53   │ }

After this patch:
   4   │ __attribute__((noinline))
   5   │ int64_t sat_s_add_int64_t_fmt_1 (int64_t x, int64_t y)
   6   │ {
   7   │   int64_t _4;
   8   │
   9   │ ;;   basic block 2, loop depth 0
  10   │ ;;    pred:       ENTRY
  11   │   _4 = .SAT_ADD (x_5(D), y_6(D)); [tail call]
  12   │   return _4;
  13   │ ;;    succ:       EXIT
  14   │
  15   │ }

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

gcc/ChangeLog:

* match.pd: Add the matching for signed .SAT_ADD.
* tree-ssa-math-opts.cc (gimple_signed_integer_sat_add): Add new
matching func decl.
(match_unsigned_saturation_add): Try signed .SAT_ADD and rename
to ...
(match_saturation_add): ... here.
(math_opts_dom_walker::after_dom_children): Update the above renamed
func from caller.

Signed-off-by: Pan Li <pan2.li@intel.com>
11 months agoFix PR testsuite/116271, gcc.dg/vect/tsvc/vect-tsvc-s176.c fails
Joern Rennecke [Wed, 28 Aug 2024 00:46:25 +0000 (01:46 +0100)] 
Fix PR testsuite/116271, gcc.dg/vect/tsvc/vect-tsvc-s176.c fails

gcc/testsuite:
PR testsuite/116271
* gcc.dg/vect/tsvc/vect-tsvc-s176.c [TRUNCATE_TEST]: Make sure
that m stays the same as the loop bound of the middle loop.
* gcc.dg/vect/tsvc/tsvc.h (get_expected_result) <s176> [TRUNCATE_TEST]:
Adjust expected value.

11 months agoRISC-V: Add testcases for unsigned scalar .SAT_SUB IMM form 4
Pan Li [Tue, 27 Aug 2024 07:14:40 +0000 (15:14 +0800)] 
RISC-V: Add testcases for unsigned scalar .SAT_SUB IMM form 4

This patch would like to add test cases for the unsigned scalar
.SAT_SUB IMM form 4.  Aka:

Form 4:
  #define DEF_SAT_U_SUB_IMM_FMT_4(T, IMM) \
  T __attribute__((noinline))             \
  sat_u_sub_imm##IMM##_##T##_fmt_4 (T x)  \
  {                                       \
    return x > (T)IMM ? x - (T)IMM : 0;   \
  }

DEF_SAT_U_SUB_IMM_FMT_4(uint64_t, 23)

The below test is passed for this patch.
* The rv64gcv regression test.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add test helper macros.
* gcc.target/riscv/sat_u_sub_imm-13.c: New test.
* gcc.target/riscv/sat_u_sub_imm-13_1.c: New test.
* gcc.target/riscv/sat_u_sub_imm-13_2.c: New test.
* gcc.target/riscv/sat_u_sub_imm-14.c: New test.
* gcc.target/riscv/sat_u_sub_imm-14_1.c: New test.
* gcc.target/riscv/sat_u_sub_imm-14_2.c: New test.
* gcc.target/riscv/sat_u_sub_imm-15.c: New test.
* gcc.target/riscv/sat_u_sub_imm-15_1.c: New test.
* gcc.target/riscv/sat_u_sub_imm-15_2.c: New test.
* gcc.target/riscv/sat_u_sub_imm-16.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-13.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-14.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-15.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-16.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
11 months agoRISC-V: Add testcases for unsigned scalar .SAT_SUB IMM form 3
Pan Li [Tue, 27 Aug 2024 06:37:01 +0000 (14:37 +0800)] 
RISC-V: Add testcases for unsigned scalar .SAT_SUB IMM form 3

This patch would like to add test cases for the unsigned scalar
.SAT_SUB IMM form 3.  Aka:

Form 3:
  #define DEF_SAT_U_SUB_IMM_FMT_3(T, IMM) \
  T __attribute__((noinline))             \
  sat_u_sub_imm##IMM##_##T##_fmt_3 (T y)  \
  {                                       \
    return (T)IMM > y ? (T)IMM - y : 0;   \
  }

DEF_SAT_U_SUB_IMM_FMT_3(uint64_t, 23)

The below test is passed for this patch.
* The rv64gcv regression test.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/sat_arith.h: Add test helper macros.
* gcc.target/riscv/sat_u_sub_imm-10.c: New test.
* gcc.target/riscv/sat_u_sub_imm-10_1.c: New test.
* gcc.target/riscv/sat_u_sub_imm-10_2.c: New test.
* gcc.target/riscv/sat_u_sub_imm-11.c: New test.
* gcc.target/riscv/sat_u_sub_imm-11_1.c: New test.
* gcc.target/riscv/sat_u_sub_imm-11_2.c: New test.
* gcc.target/riscv/sat_u_sub_imm-12.c: New test.
* gcc.target/riscv/sat_u_sub_imm-9.c: New test.
* gcc.target/riscv/sat_u_sub_imm-9_1.c: New test.
* gcc.target/riscv/sat_u_sub_imm-9_2.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-10.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-11.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-12.c: New test.
* gcc.target/riscv/sat_u_sub_imm-run-9.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
11 months agoDaily bump.
GCC Administrator [Wed, 28 Aug 2024 00:19:45 +0000 (00:19 +0000)] 
Daily bump.

11 months agoFix test failing on sparc
Andi Kleen [Tue, 27 Aug 2024 23:45:26 +0000 (16:45 -0700)] 
Fix test failing on sparc

SPARC does not support vectorizing conditions, which this test relies
on. Use vect_condition as effective target.

Committed as obvious.

PR testsuite/116500

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-switch-ifcvt-1.c: Use vect_condition to
check if vectorizing conditions is supported for target.

11 months agoUpdate gcc zh_CN.po
Joseph Myers [Tue, 27 Aug 2024 21:20:43 +0000 (21:20 +0000)] 
Update gcc zh_CN.po

* zh_CN.po: Update.