diff options
148 files changed, 6106 insertions, 991 deletions
@@ -1,3 +1,11 @@ +2025-08-08 Andrew Pinski <andrew.pinski@oss.qualcomm.com> + + * MAINTAINERS (Andrew Pinski): Update email address. + +2025-08-07 Pengfei Li <Pengfei.Li2@arm.com> + + * MAINTAINERS: Add myself. + 2025-08-05 Thomas Schwinge <tschwinge@baylibre.com> * .gitignore: Remove 'libgrust/*/target/'. diff --git a/MAINTAINERS b/MAINTAINERS index 6148ce0..dd31eed 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -276,7 +276,7 @@ check in changes outside of the parts of the compiler they maintain. Reviewers aarch64 port Alex Coplan <alex.coplan@arm.com> -aarch64 port Andrew Pinski <pinskia@gmail.com> +aarch64 port Andrew Pinski <andrew.pinski@oss.qualcomm.com> arm port (MVE) Christophe Lyon <christophe.lyon@arm.com> callgraph Martin Jambor <mjambor@suse.cz> C front end Marek Polacek <polacek@redhat.com> @@ -628,6 +628,7 @@ James Lemke jwlemke <jim@lemke.org> Ilya Leoshkevich iii <iii@linux.ibm.com> Kriang Lerdsuwanakij lerdsuwa <lerdsuwa@users.sourceforge.net> Pan Li - <pan2.li@intel.com> +Pengfei Li pfustc <pengfei.li2@arm.com> Renlin Li renlin <renlin.li@arm.com> Xinliang David Li davidxl <davidxl@google.com> Kewen Lin linkw <linkw@gcc.gnu.org> @@ -733,7 +734,7 @@ Sebastian Peryt speryt <sebastian.peryt@intel.com> Johannes Pfau jpfau <johannespfau@gmail.com> Gerald Pfeifer gerald <gerald@pfeifer.com> Kaushik Phatak kaushikp <kaushik.phatak@kpitcummins.com> -Andrew Pinski pinskia <pinskia@gmail.com> +Andrew Pinski pinskia <andrew.pinski@qualcomm.com> Nicolas Pitre nico <nico@cam.org> Michael Ploujnikov plouj <michael.ploujnikov@oracle.com> Paul Pluzhnikov ppluzhnikov <ppluzhnikov@google.com> @@ -958,6 +959,7 @@ Immad Mir <mir@sourceware.org> Gaius Mulley <gaiusmod2@gmail.com> Szabolcs Nagy <nsz@gcc.gnu.org> Andrew Pinski <quic_apinski@quicinc.com> +Andrew Pinski <andrew.pinski@oss.qualcomm.com> Siddhesh Poyarekar <siddhesh@gotplt.org> Ramana Radhakrishnan <ramanara@nvidia.com> Navid Rahimi <navidr@gcc.gnu.org> diff --git a/contrib/ChangeLog b/contrib/ChangeLog index f4f48e5..5370de6 100644 --- a/contrib/ChangeLog +++ b/contrib/ChangeLog @@ -1,3 +1,11 @@ +2025-08-07 Tobias Burnus <tburnus@baylibre.com> + + PR other/120237 + * download_prerequisites: Update to download GMP 6.3.0 (before 6.2.1), + MPFR 4.2.2 (before 4.1.0), and MPC 1.3.1 (before 1.2.1). + * prerequisites.md5: Update hash. + * prerequisites.sha512: Likewise. + 2025-07-28 David Malcolm <dmalcolm@redhat.com> * gcc-changelog/git_commit.py: Add "diagnostics" to bug diff --git a/contrib/download_prerequisites b/contrib/download_prerequisites index b83fcc9..a6d756c 100755 --- a/contrib/download_prerequisites +++ b/contrib/download_prerequisites @@ -27,9 +27,9 @@ version='(unversioned)' # remember to also update the files `contrib/prerequisites.sha512` and # `contrib/prerequisites.md5` with the new checksums. -gmp='gmp-6.2.1.tar.bz2' -mpfr='mpfr-4.1.0.tar.bz2' -mpc='mpc-1.2.1.tar.gz' +gmp='gmp-6.3.0.tar.bz2' +mpfr='mpfr-4.2.2.tar.bz2' +mpc='mpc-1.3.1.tar.gz' isl='isl-0.24.tar.bz2' gettext='gettext-0.22.tar.gz' diff --git a/contrib/prerequisites.md5 b/contrib/prerequisites.md5 index 716a9ff..96b9802 100644 --- a/contrib/prerequisites.md5 +++ b/contrib/prerequisites.md5 @@ -1,5 +1,5 @@ -28971fc21cf028042d4897f02fd355ea gmp-6.2.1.tar.bz2 -44b892bc5a45bafb4294d134e13aad1d mpfr-4.1.0.tar.bz2 -9f16c976c25bb0f76b50be749cd7a3a8 mpc-1.2.1.tar.gz +c1cd6ef33085e9cb818b9b08371f9000 gmp-6.3.0.tar.bz2 +afe8268360bc8702fbc8297d351c8b5e mpfr-4.2.2.tar.bz2 +5c9bc658c9fd0f940e8e3e0f09530c62 mpc-1.3.1.tar.gz dd2f7b78e118c25bd96134a52aae7f4d isl-0.24.tar.bz2 c092102240f8f66134d22718421d5115 gettext-0.22.tar.gz diff --git a/contrib/prerequisites.sha512 b/contrib/prerequisites.sha512 index f71398b..7a3e9c2 100644 --- a/contrib/prerequisites.sha512 +++ b/contrib/prerequisites.sha512 @@ -1,5 +1,5 @@ -8904334a3bcc5c896ececabc75cda9dec642e401fb5397c4992c4fabea5e962c9ce8bd44e8e4233c34e55c8010cc28db0545f5f750cbdbb5f00af538dc763be9 gmp-6.2.1.tar.bz2 -410208ee0d48474c1c10d3d4a59decd2dfa187064183b09358ec4c4666e34d74383128436b404123b831e585d81a9176b24c7ced9d913967c5fce35d4040a0b4 mpfr-4.1.0.tar.bz2 -3279f813ab37f47fdcc800e4ac5f306417d07f539593ca715876e43e04896e1d5bceccfb288ef2908a3f24b760747d0dbd0392a24b9b341bc3e12082e5c836ee mpc-1.2.1.tar.gz +3b684c9bcb9ede2b7e54d0ba4c9764bfa17c20d4f3000017c553b6f1e135b536949580ff37341680c25dc236cfe0ba1db8cfdfe619ce013656189ef0871b89f8 gmp-6.3.0.tar.bz2 +0176e50808dcc07afbf5bc3e38bf9b7b21918e5f194aa0bfd860d99b00c470630aef149776c4be814a61c44269c3a5b9a4b0b1c0fcd4c9feb1459d8466452da8 mpfr-4.2.2.tar.bz2 +4bab4ef6076f8c5dfdc99d810b51108ced61ea2942ba0c1c932d624360a5473df20d32b300fc76f2ba4aa2a97e1f275c9fd494a1ba9f07c4cb2ad7ceaeb1ae97 mpc-1.3.1.tar.gz aab3bddbda96b801d0f56d2869f943157aad52a6f6e6a61745edd740234c635c38231af20bc3f1a08d416a5e973a90e18249078ed8e4ae2f1d5de57658738e95 isl-0.24.tar.bz2 e2a58dde1cae3e6b79c03e7ef3d888f7577c1f4cba283b3b0f31123ceea8c33d7c9700e83de57104644de23e5f5c374868caa0e091f9c45edbbe87b98ee51c04 gettext-0.22.tar.gz diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b600551..535eb24 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,382 @@ +2025-08-09 Iain Sandoe <iain@sandoe.co.uk> + + * config/darwin.cc (darwin_encode_section_info): Do not + make anchored symbols linker-visible. + (darwin_use_anchors_for_symbol_p): Disallow anchoring on + symbols that must be linker-visible (or external), even + if the definitions are in this TU. + +2025-08-09 Iain Sandoe <iain@sandoe.co.uk> + + * config/darwin.h (ASM_GENERATE_INTERNAL_LABEL): New + entry for LANCHOR. + +2025-08-09 David Malcolm <dmalcolm@redhat.com> + + * diagnostics/context.cc (context::dump): Bulletproof against + m_reference_printer being null. + * diagnostics/dumping.cc (emit_field<const char *>): Replace + with... + (emit_string_field): ...this. + (emit_field<char *>): Eliminate. + (emit_field<bool>): Replace with... + (emit_bool_field): ...this. + (emit_field<size_t>): Replace with... + (emit_size_t_field): ...this, and use HOST_SIZE_T_PRINT_DEC rather + than %zi in fprintf call. + (emit_field<int>): Replace with... + (emit_int_field): ...this. + (emit_field<unsigned>): Replace with... + (emit_unsigned_field): ...this. + * diagnostics/dumping.h (emit_field): Replace this template decl + with... + (emit_string_field): ...this, + (emit_bool_field): ...this, + (emit_size_t_field): ...this, + (emit_int_field): ...this, + (emit_unsigned_field): ... and this. + (DIAGNOSTICS_DUMPING_EMIT_FIELD): Rename to... + (DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD): ...this and update for + above change. + * diagnostics/file-cache.cc (file_cache_slot::dump): Replace + emit_field calls with calls that explicitly state the type. Fix + type of dump of m_missing_trailing_newline to use bool. + (file_cache_slot::dump): Use HOST_SIZE_T_PRINT_DEC rather than + %zi in fprintf call. + * diagnostics/html-sink.cc (html_generation_options::dump): Update + for macro renaming. + * diagnostics/sarif-sink.cc + (sarif_serialization_format_json::dump): Likewise. + (sarif_generation_options::dump): Likewise, and for function + renaming. + * diagnostics/text-sink.cc (text_sink::dump): Update for macro + renaming. + * libgdiagnostics.cc (diagnostic_manager_debug_dump_file): Use + HOST_SIZE_T_PRINT_DEC rather than %zi in fprintf call. + * pretty-print.cc: Include "diagnostics/dumping.h". + (pp_formatted_chunks::dump): Use it. + (get_url_format_as_string): New. + (pretty_printer::dump): Use diagnostics::dumping. Bulletproof + against m_buffer being null. + +2025-08-09 Takayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp> + + * config/xtensa/constraints.md (T): + Change define_memory_constraint to define_special_memory_constraint. + +2025-08-08 Andrew Pinski <quic_apinski@quicinc.com> + + PR tree-optimization/120599 + * tree-ssa-forwprop.cc (optimize_agr_copyprop): Don't try to copy + from statements that throw. + +2025-08-08 Andrew Pinski <quic_apinski@quicinc.com> + + PR tree-optimization/118946 + PR tree-optimization/121422 + * tree-ssa-forwprop.cc (optimize_memcpy_to_memset): Remove. + (optimize_aggr_zeroprop_1): New function. + (optimize_aggr_zeroprop): New function. + (simplify_builtin_call): Don't call optimize_memcpy_to_memset + for memcpy but call optimize_aggr_zeroprop for memset. + (pass_forwprop::execute): Don't call optimize_memcpy_to_memset + for aggregate copies but rather call optimize_aggr_zeroprop + for aggregate stores. + +2025-08-08 Andrew Pinski <quic_apinski@quicinc.com> + + * tree-ssa-forwprop.cc (optimize_agr_copyprop): Change into a + forward looking (looking at vdef's uses) instead of a back + looking (vuse's def). + +2025-08-08 David Malcolm <dmalcolm@redhat.com> + + PR diagnostics/116253 + * common.opt (fdiagnostics-show-nesting): New option. + (fdiagnostics-show-nesting-locations): New option. + (fdiagnostics-show-nesting-levels): New option. + * common.opt.urls: Regenerate. + * diagnostics/context.cc (context::set_show_nesting): New. + (context::set_show_nesting_locations): New. + (context::set_show_nesting_levels): New. + * diagnostics/context.h (context::set_show_nesting): New decl. + (context::set_show_nesting_locations): New decl. + (context::set_show_nesting_levels): New decl. + * diagnostics/html-sink.cc: Tweak comment. + * diagnostics/output-spec.cc (text_scheme_handler::make_sink): + Rename "experimental-nesting" to "show-nesting" and enable by + default. Rename "experimental-nesting-show-locations" to + "show-nesting-locations". Rename + "experimental-nesting-show-levels" to "show-nesting-levels". + * diagnostics/sink.h (sink::dyn_cast_text_sink): New. + * diagnostics/text-sink.h (text_sink::dyn_cast_text_sink): New. + * doc/invoke.texi: Add -fdiagnostics-show-nesting, + -fdiagnostics-show-nesting-locations, and + -fdiagnostics-show-nesting-levels. Update for changes to + output-spec.cc above. + * lto-wrapper.cc (merge_and_complain): Ignore + OPT_fdiagnostics_show_nesting, + OPT_fdiagnostics_show_nesting_locations, and + OPT_fdiagnostics_show_nesting_levels. + (append_compiler_options): Likewise. + (append_diag_options): Likewise. + * opts-common.cc (decode_cmdline_options_to_array): Add + "-fno-diagnostics-show-nesting" to -fdiagnostics-plain-output. + * opts.cc (common_handle_option): Handle the new options. + (gen_command_line_string): Ignore the new options. + * toplev.cc (general_init): Call set_show_nesting, + set_show_nesting_locations, and set_show_nesting_levels on + global_dc. + +2025-08-08 David Malcolm <dmalcolm@redhat.com> + + * Makefile.in (OBJS-libcommon): Add diagnostics/dumping.o. + * diagnostics/buffering.cc: Include "diagnostics/dumping.h". + (buffer::dump): Reimplement using diagnostics::dumping. + * diagnostics/context.cc: Include "diagnostics/dumping.h". + (context::dump): Reimplement using diagnostics::dumping. + Use sink::dump_kind when listing the sinks. + (sink::dump): Reimplement using diagnostics::dumping. + (counters::dump): Likewise. + * diagnostics/dumping.cc: New file. + * diagnostics/dumping.h: New file. + * diagnostics/file-cache.cc: Include "diagnostics/dumping.h". + (file_cache::dump): Reimplement using diagnostics::dumping. + (file_cache_slot::dump): Likewise. + * diagnostics/html-sink.cc: Include "diagnostics/dumping.h". + (html_generation_options::dump): New. + (html_sink_buffer::dump): Reimplement using diagnostics::dumping. + (html_builder::dump): New. + (html_sink::dump): Reimplement using diagnostics::dumping. + Add dump of the html_builder. + (html_file_sink::dump): Replace with... + (html_file_sink::dump_kind): ...this. + (html_buffered_sink::dump_kind): New. + * diagnostics/html-sink.h (html_generation_options::dump): New + decl. + * diagnostics/sarif-sink.cc: Include "diagnostics/dumping.h". + (sarif_serialization_format_json::dump): New. + (sarif_builder::dump): New. + (sarif_sink_buffer::dump): Reimplement using diagnostics::dumping. + (sarif_sink::dump): Likewise. Add dump of the sarif_builder. + (sarif_stream_sink::dump_kind): New. + (sarif_file_sink::dump): Replace with... + (sarif_file_sink::dump_kind): ...this. + (get_dump_string_for_sarif_version): New. + (sarif_generation_options::dump): New. + (class buffered_sink): Rename to... + (class sarif_buffered_sink): ...this. + (sarif_buffered_sink::dump_kind): New. + * diagnostics/sarif-sink.h (sarif_serialization_format::dump): + New. + (sarif_serialization_format_json::dump): New decl. + (sarif_generation_options::dump): New decl. + * diagnostics/sink.h (sink::dump_kind): New. + * diagnostics/text-sink.cc: Include "diagnostics/dumping.h". + (text_sink_buffer::dump): Reimplement using diagnostics::dumping. + (text_sink::dump): Likewise. Emit fields m_show_nesting, + m_show_locations_in_nesting, and m_show_nesting_levels. + * diagnostics/text-sink.h (text_sink::dump_kind): New. + +2025-08-08 David Malcolm <dmalcolm@redhat.com> + + * diagnostic.h (diagnostics::get_cwe_url): Move decl to + diagnostics/metadata.h. + (diagnostics::maybe_line_and_column): Move into + diagnostics::text_sink. + * diagnostics/context.cc: Update for maybe_line_and_column + becoming a static member of text_sink. + * diagnostics/metadata.h (diagnostics::get_cwe_url): Move decl + here from diagnostic.h. + * diagnostics/text-sink.cc (maybe_line_and_column): Convert to... + (text_sink::maybe_line_and_column): ...this. + * diagnostics/text-sink.h (text_sink::maybe_line_and_column): Move + here from diagnostic.h. + +2025-08-08 David Malcolm <dmalcolm@redhat.com> + + * diagnostics/context.cc (context::get_any_inlining_info): Convert + "context" arg of m_set_locations_cb from ptr to const &. + (context::report_diagnostic): Convert "context" arg of + m_adjust_diagnostic_info from ptr to const &. + * diagnostics/context.h (context::set_locations_callback_t): + Likewise. + (context::set_adjust_diagnostic_info_callback): Likewise. + (context::m_adjust_diagnostic_info): Likewise. + * tree-diagnostic.cc (set_inlining_locations): Likewise. + +2025-08-08 David Malcolm <dmalcolm@redhat.com> + + * diagnostics/column-options.h: New file, adding struct + diagnostics::column_options, taken from fields in + diagnostics::context and diagnostics::column_policy. + * diagnostics/context.cc (context::initialize): Update for moving + fields of diagnostics::context into diagnostics::column_options. + (column_policy::column_policy): Likewise. + (column_policy::converted_column): Move implementation to... + (column_options::convert_column): ...this new function. + (context::report_diagnostic): Update for moving fields of + diagnostics::context into diagnostics::column_options. + (assert_location_text): Likewise. + * diagnostics/context.h: Include "diagnostics/column-options.h". + (class column_policy): Replace fields m_column_unit, + m_column_origin, and m_tabstop with m_column_options. + (context::get_column_options): New accessors. + (context::m_column_unit): Move to struct column_options and + replace with m_column_options. + (context::m_column_origin): Likewise. + (context::m_tabstop): Likewise. + * diagnostics/sarif-sink.cc (sarif_builder::sarif_builder): Update + for moving fields of diagnostics::context into + diagnostics::column_options. + * diagnostics/source-printing.cc: Likewise. + * opts.cc (common_handle_option): Likewise. + +2025-08-08 Christophe Lyon <christophe.lyon@linaro.org> + + PR target/120977 + * config/arm/arm.md (call): Move unspec parameter to parallel. + (nonsecure_call_internal): Likewise. + (call_value): Likewise. + (nonsecure_call_value_internal): Likewise. + * config/arm/thumb1.md (nonsecure_call_reg_thumb1_v5): Likewise. + (nonsecure_call_value_reg_thumb1_v5): Likewise. + * config/arm/thumb2.md (nonsecure_call_reg_thumb2_fpcxt): + Likewise. + (nonsecure_call_reg_thumb2): Likewise. + (nonsecure_call_value_reg_thumb2_fpcxt): Likewise. + (nonsecure_call_value_reg_thumb2): Likewise. + * config/arm/arm.cc (cmse_nonsecure_call_inline_register_clear): + Likewise. + +2025-08-08 Pengfei Li <Pengfei.Li2@arm.com> + + PR target/121449 + * config/aarch64/aarch64-sve.md + (mask_gather_load<mode><v_int_container>): Use vg<Vesize> + constraints for alternatives with immediate offset. + (mask_scatter_store<mode><v_int_container>): Likewise. + +2025-08-08 Richard Biener <rguenther@suse.de> + + * doc/tm.texi.in: Add Vectorization and OpenMP and OpenACC + sub-sections to the list of target macros and functions. + * doc/tm.texi: Re-generate. + +2025-08-08 Richard Biener <rguenther@suse.de> + + * tree-vect-loop.cc (vect_determine_vectype_for_stmt_1): Remove. + (vect_determine_vectype_for_stmt): Likewise. + (vect_set_stmts_vectype): Likewise. + (vect_analyze_loop_2): Do not call vect_set_stmts_vectype. + * tree-vect-stmts.cc (vect_mark_stmts_to_be_vectorized): Detect + irregular stmts early here. + +2025-08-08 Alex Coplan <alex.coplan@arm.com> + + PR target/120986 + * config/aarch64/aarch64-sve-builtins.cc + (function_expander::expand): Relax fpm_t assert to allow + modeless const_ints. + +2025-08-08 Alex Coplan <alex.coplan@arm.com> + + PR target/120986 + * config/aarch64/aarch64-sve2.md (@aarch64_sve_dot<mode>): + Switch mode iterator from SVE_FULL_HSF to new iterator; + remove insn predicate as this is now taken care of by conditions + in the mode iterator. + (@aarch64_sve_dot_lane<mode>): Likewise. + * config/aarch64/iterators.md (SVE_FULL_HSF_FP8_FDOT): New. + +2025-08-08 Richard Biener <rguenther@suse.de> + + PR tree-optimization/121454 + * tree-ssa-sccvn.cc (visit_nary_op): Avoid unexpected + BIT_FIELD_REFs. + +2025-08-08 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/121389 + * tree-tailcall.cc (find_tail_calls): For finally_tmp.N + handle not just GIMPLE_CONDs with EQ_EXPR/NE_EXPR and only + values 0 and 1, but arbitrary non-negative values, arbitrary + comparisons in conditions and also GIMPLE_SWITCH next to + GIMPLE_CONDs. + +2025-08-08 Richard Biener <rguenther@suse.de> + + * tree-vect-loop.cc (vect_is_emulated_mixed_dot_prod): Get + the SLP node rather than the stmt_info. + (vectorizable_lane_reducing): Adjust, pass SLP node to costing. + (vect_transform_reduction): Adjust. + +2025-08-08 Richard Biener <rguenther@suse.de> + + * tree-vect-stmts.cc (vect_model_promotion_demotion_cost): Pass + in SLP node and drop unused dr argument. Use SLP node for + costing, drop costing of constant/external operands. + (vectorizable_conversion): Adjust. + +2025-08-08 Richard Biener <rguenther@suse.de> + + * tree-vect-stmts.cc (vectorizable_store): Apply SLP_TREE_VECTYPE + to slp_node rather than stmt_info. + +2025-08-07 Richard Sandiford <richard.sandiford@arm.com> + + PR target/121414 + * config/aarch64/aarch64.cc (aarch64_is_variant_pcs): New function, + split out from... + (aarch64_asm_output_variant_pcs): ...here. Handle various types + of SME function type. + +2025-08-07 Richard Sandiford <richard.sandiford@arm.com> + + PR rtl-optimization/120718 + * simplify-rtx.cc (simplify_context::simplify_gen_subreg): + Remove MODE_COMPOSITE_P condition. + +2025-08-07 Richard Biener <rguenther@suse.de> + + PR tree-optimization/121405 + * tree-ssa-sccvn.cc (visit_nary_op): Handle BIT_FIELD_REF + with reference def by looking up a combination of both. + +2025-08-07 Pengfei Li <Pengfei.Li2@arm.com> + + * tree-vect-data-refs.cc (vect_compute_data_ref_alignment): + Allow DR target alignment to be a poly_int. + (vect_enhance_data_refs_alignment): Support peeling and + versioning for VLA modes. + * tree-vect-loop-manip.cc (get_misalign_in_elems): Remove + power-of-two rounding in peeling. + (vect_create_cond_for_align_checks): Update alignment check + logic for poly_int mask. + (vect_create_cond_for_vla_spec_read): New runtime checks. + (vect_loop_versioning): Support new runtime checks. + * tree-vect-loop.cc (_loop_vec_info::_loop_vec_info): Add a new + loop_vinfo field. + (vectorizable_induction): Fix wrong IV offset issue. + * tree-vect-stmts.cc (get_load_store_type): Refactor + vectorizable checks for speculative loads. + * tree-vectorizer.h (LOOP_VINFO_MAX_SPEC_READ_AMOUNT): New + macro for new runtime checks. + (LOOP_REQUIRES_VERSIONING_FOR_SPEC_READ): Likewise + (LOOP_REQUIRES_VERSIONING): Update macro for new runtime checks. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * doc/invoke.texi (Wkeyword-macro): Document. + +2025-08-07 Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org> + + * config/s390/s390.cc (print_operand): Allow arbitrary wide_int + constants for _BitInt. + (s390_bitint_type_info): Implement target hook + TARGET_C_BITINT_TYPE_INFO. + 2025-08-06 Uros Bizjak <ubizjak@gmail.com> PR target/96226 diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP index d4024d7..c740198 100644 --- a/gcc/DATESTAMP +++ b/gcc/DATESTAMP @@ -1 +1 @@ -20250807 +20250810 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index cc79595..f21d692 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1856,6 +1856,7 @@ OBJS-libcommon = \ diagnostics/color.o \ diagnostics/context.o \ diagnostics/digraphs.o \ + diagnostics/dumping.o \ diagnostics/file-cache.o \ diagnostics/output-spec.o \ diagnostics/html-sink.o \ diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 2abe6df..d766c28 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,25 @@ +2025-08-08 David Malcolm <dmalcolm@redhat.com> + + * c-indentation.cc (should_warn_for_misleading_indentation): + Update for moving diagnostics::context::m_tabstop into + diagnostics::column_options. + * c-opts.cc (c_common_post_options): Likewise. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR c++/117783 + * c-cppbuiltin.cc (c_cpp_builtins): Change __cpp_structured_bindings + predefined value for C++26 from 202403L to 202411L. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * c.opt (Wkeyword-macro): New option. + * c.opt.urls: Regenerate. + * c-common.h (cxx_dialect): Comment formatting fix. + * c-opts.cc (c_common_post_options): Default to + -Wkeyword-macro for C++26 if pedantic. + 2025-08-06 Alexandre Oliva <oliva@adacore.com> * c-attribs.cc (handle_hardbool_attribute): Create distinct diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc index 4aea902..5476d10 100644 --- a/gcc/c-family/c-cppbuiltin.cc +++ b/gcc/c-family/c-cppbuiltin.cc @@ -1090,7 +1090,7 @@ c_cpp_builtins (cpp_reader *pfile) cpp_define (pfile, "__cpp_constexpr_exceptions=202411L"); cpp_define (pfile, "__cpp_static_assert=202306L"); cpp_define (pfile, "__cpp_placeholder_variables=202306L"); - cpp_define (pfile, "__cpp_structured_bindings=202403L"); + cpp_define (pfile, "__cpp_structured_bindings=202411L"); cpp_define (pfile, "__cpp_deleted_function=202403L"); cpp_define (pfile, "__cpp_variadic_friend=202403L"); cpp_define (pfile, "__cpp_pack_indexing=202311L"); diff --git a/gcc/c-family/c-indentation.cc b/gcc/c-family/c-indentation.cc index bb214fc..d378464 100644 --- a/gcc/c-family/c-indentation.cc +++ b/gcc/c-family/c-indentation.cc @@ -330,7 +330,7 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, if (guard_loc == body_loc || body_loc == next_stmt_loc) return false; - const unsigned int tab_width = global_dc->m_tabstop; + const unsigned int tab_width = global_dc->get_column_options ().m_tabstop; /* They must be in the same file. */ if (next_stmt_exploc.file != body_exploc.file) diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 3fb12b9..0ec30e8 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -1200,7 +1200,7 @@ c_common_post_options (const char **pfilename) flag_char8_t = (cxx_dialect >= cxx20) || flag_isoc23; cpp_opts->unsigned_utf8char = flag_char8_t ? 1 : cpp_opts->unsigned_char; - cpp_opts->cpp_tabstop = global_dc->m_tabstop; + cpp_opts->cpp_tabstop = global_dc->get_column_options ().m_tabstop; if (flag_extern_tls_init) { diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 2e5c896..87a18c9 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * c-decl.cc (c_init_decl_processing): Mark cpp nodes corresponding + to keywords as NODE_WARN if warn_keyword_macro. + 2025-08-06 Alexandre Oliva <oliva@adacore.com> * c-tree.h (C_BOOLEAN_TYPE_P): Cover hardbools as well. diff --git a/gcc/cobol/ChangeLog b/gcc/cobol/ChangeLog index 35d645c..8c47213 100644 --- a/gcc/cobol/ChangeLog +++ b/gcc/cobol/ChangeLog @@ -1,3 +1,13 @@ +2025-08-07 Robert Dubner <rdubner@symas.com> + + * cbldiag.h (location_dump): Source code formatting. + * parse.y: error_msg formatting. + * scan.l: Remove UTF-8 character from regex pattern. + * scan_ante.h (numstr_of): error_msg formatting. + * show_parse.h (class ANALYZE): Suppress cppcheck error. + * util.cc (cbl_field_t::report_invalid_initial_value): + error_msg formatting. + 2025-08-02 Jakub Jelinek <jakub@redhat.com> * parse.y (intrinsic): Use %td format specifier with no cast on diff --git a/gcc/cobol/cbldiag.h b/gcc/cobol/cbldiag.h index dd16190..2554deb 100644 --- a/gcc/cobol/cbldiag.h +++ b/gcc/cobol/cbldiag.h @@ -122,8 +122,8 @@ static void location_dump( const char func[], int line, const char tag[], const LOC& loc) { extern int yy_flex_debug; // cppcheck-suppress shadowVariable if( yy_flex_debug ) { - const char *detail = gcobol_getenv("update_location"); // cppcheck-suppress knownConditionTrueFalse - if( detail ) { + const char *detail = gcobol_getenv("update_location"); + if( detail ) { // cppcheck-suppress knownConditionTrueFalse fprintf(stderr, "%s:%d: %s location (%d,%d) to (%d,%d)\n", func, line, tag, loc.first_line, loc.first_column, loc.last_line, loc.last_column); diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index fae96ed..59cc64d 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -10336,8 +10336,8 @@ intrinsic: function_udf if( p != NULL ) { auto loc = symbol_field_location(field_index(p->field)); error_msg(loc, "FUNCTION %qs has " - "inconsistent parameter type %td (%qs)", - keyword_str($1), p - args.data(), name_of(p->field) ); + "inconsistent parameter type %ld (%qs)", + keyword_str($1), (long)(p - args.data()), name_of(p->field) ); YYERROR; } $$ = is_numeric(args[0].field)? diff --git a/gcc/cobol/scan.l b/gcc/cobol/scan.l index ba4c044..5773f09 100644 --- a/gcc/cobol/scan.l +++ b/gcc/cobol/scan.l @@ -123,7 +123,7 @@ NUMEDCHAR [BPVZ90/,]+{COUNT}? NUMEDCHARS {NUMEDCHAR}([.]?{NUMEDCHAR})* NUMED ([+-]{NUMEDCHARS}+)|({NUMEDCHARS}+[+-]) CURRENCY [A-Zfhijklmoqtuwy\x80-\xFF]{-}[ABCDEGNPRSVXZ] -NUMEDCUR (([.]?[-$0B/Z*+,P9()V+–]|{CURRENCY}+|{COUNT})+([.][$0B/Z*+P9()V+\–])*)+ +NUMEDCUR (([.]?[$0B/Z*+,P9()V+-]|{CURRENCY}+|{COUNT})+([.][$0B/Z*+P9()V+-])*)+ NUMEDITED {NUMED}|{NUMEDCUR} EDITED {ALPHED}|{NUMED}|{NUMEDCUR} diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h index 31093a6..c00826d 100644 --- a/gcc/cobol/scan_ante.h +++ b/gcc/cobol/scan_ante.h @@ -149,7 +149,7 @@ numstr_of( const char string[], radix_t radix = decimal_e ) { } auto nx = std::count_if(input, p, fisdigit); if( 36 < nx ) { - error_msg(yylloc, "significand of %s has more than 36 digits (%td)", input, nx); + error_msg(yylloc, "significand of %s has more than 36 digits (%ld)", input, (long)nx); return NO_CONDITION; } diff --git a/gcc/cobol/show_parse.h b/gcc/cobol/show_parse.h index bd0e16f..e1a8cb2 100644 --- a/gcc/cobol/show_parse.h +++ b/gcc/cobol/show_parse.h @@ -500,7 +500,7 @@ class ANALYZE int level; inline static int analyze_level=1; public: - ANALYZE(const char *func_) : func(func_) + ANALYZE(const char *func_) : func(func_) // cppcheck-suppress noExplicitConstructor { level = 0; if( getenv("Analyze") ) diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc index aed9483..2a7bf2b 100644 --- a/gcc/cobol/util.cc +++ b/gcc/cobol/util.cc @@ -1049,8 +1049,8 @@ cbl_field_t::report_invalid_initial_value(const YYLTYPE& loc) const { return TOUPPER(ch) == 'E'; } ); if( !has_exponent && data.precision() < pend - p ) { - error_msg(loc, "%s cannot represent VALUE %qs exactly (max %c%td)", - name, data.initial, '.', pend - p); + error_msg(loc, "%s cannot represent VALUE %qs exactly (max %c%ld)", + name, data.initial, '.', (long)(pend - p)); } } } diff --git a/gcc/common.opt b/gcc/common.opt index bf38f60..c58ac13 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1620,6 +1620,18 @@ fdiagnostics-minimum-margin-width= Common Joined UInteger Var(diagnostics_minimum_margin_width) Init(6) Set minimum width of left margin of source code when showing source. +fdiagnostics-show-nesting +Common Var(flag_diagnostics_show_nesting) Init(1) +Use indentation to show nesting of diagnostics in text output. + +fdiagnostics-show-nesting-locations +Common Var(flag_diagnostics_show_nesting_locations) Init(1) +Show location information when showing nested diagnostics. + +fdiagnostics-show-nesting-levels +Common Var(flag_diagnostics_show_nesting_levels) Init(0) +Show nesting levels as numbers when showing nested diagnostics. + fdisable- Common Joined RejectNegative Var(common_deferred_options) Defer -fdisable-[tree|rtl|ipa]-<pass>=range1+range2 Disable an optimization pass. diff --git a/gcc/common.opt.urls b/gcc/common.opt.urls index 38dd9d3..0bc36c4 100644 --- a/gcc/common.opt.urls +++ b/gcc/common.opt.urls @@ -640,6 +640,15 @@ UrlSuffix(gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-text fdiagnostics-minimum-margin-width= UrlSuffix(gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-minimum-margin-width) +fdiagnostics-show-nesting +UrlSuffix(gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-show-nesting) + +fdiagnostics-show-nesting-locations +UrlSuffix(gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-show-nesting-locations) + +fdiagnostics-show-nesting-levels +UrlSuffix(gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-show-nesting-levels) + fdisable- UrlSuffix(gcc/Developer-Options.html#index-fdisable-) diff --git a/gcc/config/aarch64/aarch64-sve-builtins.cc b/gcc/config/aarch64/aarch64-sve-builtins.cc index e394c9a..1764cf8 100644 --- a/gcc/config/aarch64/aarch64-sve-builtins.cc +++ b/gcc/config/aarch64/aarch64-sve-builtins.cc @@ -4590,8 +4590,9 @@ function_expander::expand () { /* The last element of these functions is always an fpm_t that must be written to FPMR before the call to the instruction itself. */ - gcc_assert (args.last ()->mode == DImode); - emit_move_insn (gen_rtx_REG (DImode, FPM_REGNUM), args.last ()); + rtx fpm = args.last (); + gcc_assert (CONST_INT_P (fpm) || GET_MODE (fpm) == DImode); + emit_move_insn (gen_rtx_REG (DImode, FPM_REGNUM), fpm); } rtx result = base->expand (*this); if (function_returns_void_p ()) diff --git a/gcc/config/aarch64/aarch64-sve.md b/gcc/config/aarch64/aarch64-sve.md index 88d323a..51e2d7d 100644 --- a/gcc/config/aarch64/aarch64-sve.md +++ b/gcc/config/aarch64/aarch64-sve.md @@ -1542,18 +1542,18 @@ UNSPEC_LD1_GATHER))] "TARGET_SVE && TARGET_NON_STREAMING" {@ [cons: =0, 1, 2, 3, 4, 5 ] - [&w, Z, w, Ui1, Ui1, Upl] ld1<Vesize>\t%0.s, %5/z, [%2.s] - [?w, Z, 0, Ui1, Ui1, Upl] ^ - [&w, vgw, w, Ui1, Ui1, Upl] ld1<Vesize>\t%0.s, %5/z, [%2.s, #%1] - [?w, vgw, 0, Ui1, Ui1, Upl] ^ - [&w, rk, w, Z, Ui1, Upl] ld1<Vesize>\t%0.s, %5/z, [%1, %2.s, sxtw] - [?w, rk, 0, Z, Ui1, Upl] ^ - [&w, rk, w, Ui1, Ui1, Upl] ld1<Vesize>\t%0.s, %5/z, [%1, %2.s, uxtw] - [?w, rk, 0, Ui1, Ui1, Upl] ^ - [&w, rk, w, Z, i, Upl] ld1<Vesize>\t%0.s, %5/z, [%1, %2.s, sxtw %p4] - [?w, rk, 0, Z, i, Upl] ^ - [&w, rk, w, Ui1, i, Upl] ld1<Vesize>\t%0.s, %5/z, [%1, %2.s, uxtw %p4] - [?w, rk, 0, Ui1, i, Upl] ^ + [&w, Z, w, Ui1, Ui1, Upl] ld1<Vesize>\t%0.s, %5/z, [%2.s] + [?w, Z, 0, Ui1, Ui1, Upl] ^ + [&w, vg<Vesize>, w, Ui1, Ui1, Upl] ld1<Vesize>\t%0.s, %5/z, [%2.s, #%1] + [?w, vg<Vesize>, 0, Ui1, Ui1, Upl] ^ + [&w, rk, w, Z, Ui1, Upl] ld1<Vesize>\t%0.s, %5/z, [%1, %2.s, sxtw] + [?w, rk, 0, Z, Ui1, Upl] ^ + [&w, rk, w, Ui1, Ui1, Upl] ld1<Vesize>\t%0.s, %5/z, [%1, %2.s, uxtw] + [?w, rk, 0, Ui1, Ui1, Upl] ^ + [&w, rk, w, Z, i, Upl] ld1<Vesize>\t%0.s, %5/z, [%1, %2.s, sxtw %p4] + [?w, rk, 0, Z, i, Upl] ^ + [&w, rk, w, Ui1, i, Upl] ld1<Vesize>\t%0.s, %5/z, [%1, %2.s, uxtw %p4] + [?w, rk, 0, Ui1, i, Upl] ^ } ) @@ -1572,14 +1572,14 @@ UNSPEC_LD1_GATHER))] "TARGET_SVE && TARGET_NON_STREAMING" {@ [cons: =0, 1, 2, 3, 4, 5] - [&w, Z, w, i, Ui1, Upl] ld1<Vesize>\t%0.d, %5/z, [%2.d] - [?w, Z, 0, i, Ui1, Upl] ^ - [&w, vgd, w, i, Ui1, Upl] ld1<Vesize>\t%0.d, %5/z, [%2.d, #%1] - [?w, vgd, 0, i, Ui1, Upl] ^ - [&w, rk, w, i, Ui1, Upl] ld1<Vesize>\t%0.d, %5/z, [%1, %2.d] - [?w, rk, 0, i, Ui1, Upl] ^ - [&w, rk, w, i, i, Upl] ld1<Vesize>\t%0.d, %5/z, [%1, %2.d, lsl %p4] - [?w, rk, 0, i, i, Upl] ^ + [&w, Z, w, i, Ui1, Upl] ld1<Vesize>\t%0.d, %5/z, [%2.d] + [?w, Z, 0, i, Ui1, Upl] ^ + [&w, vg<Vesize>, w, i, Ui1, Upl] ld1<Vesize>\t%0.d, %5/z, [%2.d, #%1] + [?w, vg<Vesize>, 0, i, Ui1, Upl] ^ + [&w, rk, w, i, Ui1, Upl] ld1<Vesize>\t%0.d, %5/z, [%1, %2.d] + [?w, rk, 0, i, Ui1, Upl] ^ + [&w, rk, w, i, i, Upl] ld1<Vesize>\t%0.d, %5/z, [%1, %2.d, lsl %p4] + [?w, rk, 0, i, i, Upl] ^ } ) @@ -2488,13 +2488,13 @@ (match_operand:SVE_4 4 "register_operand")] UNSPEC_ST1_SCATTER))] "TARGET_SVE && TARGET_NON_STREAMING" - {@ [ cons: 0 , 1 , 2 , 3 , 4 , 5 ] - [ Z , w , Ui1 , Ui1 , w , Upl ] st1<Vesize>\t%4.s, %5, [%1.s] - [ vgw , w , Ui1 , Ui1 , w , Upl ] st1<Vesize>\t%4.s, %5, [%1.s, #%0] - [ rk , w , Z , Ui1 , w , Upl ] st1<Vesize>\t%4.s, %5, [%0, %1.s, sxtw] - [ rk , w , Ui1 , Ui1 , w , Upl ] st1<Vesize>\t%4.s, %5, [%0, %1.s, uxtw] - [ rk , w , Z , i , w , Upl ] st1<Vesize>\t%4.s, %5, [%0, %1.s, sxtw %p3] - [ rk , w , Ui1 , i , w , Upl ] st1<Vesize>\t%4.s, %5, [%0, %1.s, uxtw %p3] + {@ [ cons: 0 , 1 , 2 , 3 , 4 , 5 ] + [ Z , w , Ui1 , Ui1 , w , Upl ] st1<Vesize>\t%4.s, %5, [%1.s] + [ vg<Vesize> , w , Ui1 , Ui1 , w , Upl ] st1<Vesize>\t%4.s, %5, [%1.s, #%0] + [ rk , w , Z , Ui1 , w , Upl ] st1<Vesize>\t%4.s, %5, [%0, %1.s, sxtw] + [ rk , w , Ui1 , Ui1 , w , Upl ] st1<Vesize>\t%4.s, %5, [%0, %1.s, uxtw] + [ rk , w , Z , i , w , Upl ] st1<Vesize>\t%4.s, %5, [%0, %1.s, sxtw %p3] + [ rk , w , Ui1 , i , w , Upl ] st1<Vesize>\t%4.s, %5, [%0, %1.s, uxtw %p3] } ) @@ -2511,11 +2511,11 @@ (match_operand:SVE_2 4 "register_operand")] UNSPEC_ST1_SCATTER))] "TARGET_SVE && TARGET_NON_STREAMING" - {@ [ cons: 0 , 1 , 3 , 4 , 5 ] - [ Z , w , Ui1 , w , Upl ] st1<Vesize>\t%4.d, %5, [%1.d] - [ vgd , w , Ui1 , w , Upl ] st1<Vesize>\t%4.d, %5, [%1.d, #%0] - [ rk , w , Ui1 , w , Upl ] st1<Vesize>\t%4.d, %5, [%0, %1.d] - [ rk , w , i , w , Upl ] st1<Vesize>\t%4.d, %5, [%0, %1.d, lsl %p3] + {@ [ cons: 0 , 1 , 3 , 4 , 5 ] + [ Z , w , Ui1 , w , Upl ] st1<Vesize>\t%4.d, %5, [%1.d] + [ vg<Vesize> , w , Ui1 , w , Upl ] st1<Vesize>\t%4.d, %5, [%1.d, #%0] + [ rk , w , Ui1 , w , Upl ] st1<Vesize>\t%4.d, %5, [%0, %1.d] + [ rk , w , i , w , Upl ] st1<Vesize>\t%4.d, %5, [%0, %1.d, lsl %p3] } ) diff --git a/gcc/config/aarch64/aarch64-sve2.md b/gcc/config/aarch64/aarch64-sve2.md index a4c3257..a3cbbce 100644 --- a/gcc/config/aarch64/aarch64-sve2.md +++ b/gcc/config/aarch64/aarch64-sve2.md @@ -2211,14 +2211,14 @@ ;; - FDOT (2-way, indexed) (FP8DOT2) ;; ------------------------------------------------------------------------- (define_insn "@aarch64_sve_dot<mode>" - [(set (match_operand:SVE_FULL_HSF 0 "register_operand") - (unspec:SVE_FULL_HSF - [(match_operand:SVE_FULL_HSF 1 "register_operand") + [(set (match_operand:SVE_FULL_HSF_FP8_FDOT 0 "register_operand") + (unspec:SVE_FULL_HSF_FP8_FDOT + [(match_operand:SVE_FULL_HSF_FP8_FDOT 1 "register_operand") (match_operand:VNx16QI 2 "register_operand") (match_operand:VNx16QI 3 "register_operand") (reg:DI FPM_REGNUM)] UNSPEC_DOT_FP8))] - "TARGET_SSVE_FP8DOT4 && !(<MODE>mode == VNx8HFmode && !TARGET_SSVE_FP8DOT2)" + "" {@ [ cons: =0 , 1 , 2 , 3 ; attrs: movprfx ] [ w , 0 , w , w ; * ] fdot\t%0.<Vetype>, %2.b, %3.b [ ?&w , w , w , w ; yes ] movprfx\t%0, %1\;fdot\t%0.<Vetype>, %2.b, %3.b @@ -2226,15 +2226,15 @@ ) (define_insn "@aarch64_sve_dot_lane<mode>" - [(set (match_operand:SVE_FULL_HSF 0 "register_operand") - (unspec:SVE_FULL_HSF - [(match_operand:SVE_FULL_HSF 1 "register_operand") + [(set (match_operand:SVE_FULL_HSF_FP8_FDOT 0 "register_operand") + (unspec:SVE_FULL_HSF_FP8_FDOT + [(match_operand:SVE_FULL_HSF_FP8_FDOT 1 "register_operand") (match_operand:VNx16QI 2 "register_operand") (match_operand:VNx16QI 3 "register_operand") (match_operand:SI 4 "const_int_operand") (reg:DI FPM_REGNUM)] UNSPEC_DOT_LANE_FP8))] - "TARGET_SSVE_FP8DOT4 && !(<MODE>mode == VNx8HFmode && !TARGET_SSVE_FP8DOT2)" + "" {@ [ cons: =0 , 1 , 2 , 3 ; attrs: movprfx ] [ w , 0 , w , y ; * ] fdot\t%0.<Vetype>, %2.b, %3.b[%4] [ ?&w , w , w , y ; yes ] movprfx\t%0, %1\;fdot\t%0.<Vetype>, %2.b, %3.b[%4] diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index d30c9c7..2dbaf4a 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -25435,20 +25435,41 @@ aarch64_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED, int global) return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type; } +/* Return true if function declaration FNDECL needs to be marked as + having a variant PCS. */ + +static bool +aarch64_is_variant_pcs (tree fndecl) +{ + /* Check for ABIs that preserve more registers than usual. */ + arm_pcs pcs = (arm_pcs) fndecl_abi (fndecl).id (); + if (pcs == ARM_PCS_SIMD || pcs == ARM_PCS_SVE) + return true; + + /* Check for ABIs that allow PSTATE.SM to be 1 on entry. */ + tree fntype = TREE_TYPE (fndecl); + if (aarch64_fntype_pstate_sm (fntype) != AARCH64_ISA_MODE_SM_OFF) + return true; + + /* Check for ABIs that require PSTATE.ZA to be 1 on entry, either because + of ZA or ZT0. */ + if (aarch64_fntype_pstate_za (fntype) != 0) + return true; + + return false; +} + /* Output .variant_pcs for aarch64_vector_pcs function symbols. */ static void aarch64_asm_output_variant_pcs (FILE *stream, const tree decl, const char* name) { - if (TREE_CODE (decl) == FUNCTION_DECL) + if (TREE_CODE (decl) == FUNCTION_DECL + && aarch64_is_variant_pcs (decl)) { - arm_pcs pcs = (arm_pcs) fndecl_abi (decl).id (); - if (pcs == ARM_PCS_SIMD || pcs == ARM_PCS_SVE) - { - fprintf (stream, "\t.variant_pcs\t"); - assemble_name (stream, name); - fprintf (stream, "\n"); - } + fprintf (stream, "\t.variant_pcs\t"); + assemble_name (stream, name); + fprintf (stream, "\n"); } } diff --git a/gcc/config/aarch64/iterators.md b/gcc/config/aarch64/iterators.md index 8f8237e..68b080d 100644 --- a/gcc/config/aarch64/iterators.md +++ b/gcc/config/aarch64/iterators.md @@ -543,6 +543,12 @@ ;; elements. (define_mode_iterator SVE_FULL_HSF [VNx8HF VNx4SF]) +;; Like SVE_FULL_HSF, but selectively enables those modes that are valid +;; for the variant of the SVE2 FP8 FDOT instruction associated with that +;; mode. +(define_mode_iterator SVE_FULL_HSF_FP8_FDOT [(VNx4SF "TARGET_SSVE_FP8DOT4") + (VNx8HF "TARGET_SSVE_FP8DOT2")]) + ;; Partial SVE floating-point vector modes that have 16-bit or 32-bit ;; elements. (define_mode_iterator SVE_PARTIAL_HSF [VNx2HF VNx4HF VNx2SF]) diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index 29b45ae..8b951f3 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -18983,7 +18983,8 @@ cmse_nonsecure_call_inline_register_clear (void) call = SET_SRC (call); /* Check if it is a cmse_nonsecure_call. */ - unspec = XEXP (call, 0); + unspec = XVECEXP (pat, 0, 2); + if (GET_CODE (unspec) != UNSPEC || XINT (unspec, 1) != UNSPEC_NONSECURE_MEM) continue; @@ -19010,7 +19011,7 @@ cmse_nonsecure_call_inline_register_clear (void) /* Make sure the register used to hold the function address is not cleared. */ - address = RTVEC_ELT (XVEC (unspec, 0), 0); + address = XEXP (call, 0); gcc_assert (MEM_P (address)); gcc_assert (REG_P (XEXP (address, 0))); address_regnum = REGNO (XEXP (address, 0)); diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index 5e5e112..537a3e2 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -8623,7 +8623,7 @@ if (detect_cmse_nonsecure_call (addr)) { pat = gen_nonsecure_call_internal (operands[0], operands[1], - operands[2]); + operands[2], const0_rtx); emit_call_insn (pat); } else @@ -8665,10 +8665,10 @@ (clobber (reg:SI LR_REGNUM))])]) (define_expand "nonsecure_call_internal" - [(parallel [(call (unspec:SI [(match_operand 0 "memory_operand")] - UNSPEC_NONSECURE_MEM) + [(parallel [(call (match_operand 0 "memory_operand") (match_operand 1 "general_operand")) (use (match_operand 2 "" "")) + (unspec:SI [(match_operand 3)] UNSPEC_NONSECURE_MEM) (clobber (reg:SI LR_REGNUM))])] "use_cmse" { @@ -8745,7 +8745,8 @@ if (detect_cmse_nonsecure_call (addr)) { pat = gen_nonsecure_call_value_internal (operands[0], operands[1], - operands[2], operands[3]); + operands[2], operands[3], + const0_rtx); emit_call_insn (pat); } else @@ -8779,10 +8780,10 @@ (define_expand "nonsecure_call_value_internal" [(parallel [(set (match_operand 0 "" "") - (call (unspec:SI [(match_operand 1 "memory_operand")] - UNSPEC_NONSECURE_MEM) + (call (match_operand 1 "memory_operand") (match_operand 2 "general_operand"))) (use (match_operand 3 "" "")) + (unspec:SI [(match_operand 4)] UNSPEC_NONSECURE_MEM) (clobber (reg:SI LR_REGNUM))])] "use_cmse" " diff --git a/gcc/config/arm/thumb1.md b/gcc/config/arm/thumb1.md index f9e89e9..4da0086 100644 --- a/gcc/config/arm/thumb1.md +++ b/gcc/config/arm/thumb1.md @@ -1874,10 +1874,10 @@ ) (define_insn "*nonsecure_call_reg_thumb1_v5" - [(call (unspec:SI [(mem:SI (reg:SI R4_REGNUM))] - UNSPEC_NONSECURE_MEM) + [(call (mem:SI (reg:SI R4_REGNUM)) (match_operand 0 "" "")) (use (match_operand 1 "" "")) + (unspec:SI [(match_operand 2)]UNSPEC_NONSECURE_MEM) (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB1 && use_cmse && !SIBLING_CALL_P (insn)" "bl\\t__gnu_cmse_nonsecure_call" @@ -1919,11 +1919,10 @@ (define_insn "*nonsecure_call_value_reg_thumb1_v5" [(set (match_operand 0 "" "") - (call (unspec:SI - [(mem:SI (reg:SI R4_REGNUM))] - UNSPEC_NONSECURE_MEM) + (call (mem:SI (reg:SI R4_REGNUM)) (match_operand 1 "" ""))) (use (match_operand 2 "" "")) + (unspec:SI [(match_operand 3)] UNSPEC_NONSECURE_MEM) (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB1 && use_cmse" "bl\\t__gnu_cmse_nonsecure_call" diff --git a/gcc/config/arm/thumb2.md b/gcc/config/arm/thumb2.md index 019f9d4..2c2026b 100644 --- a/gcc/config/arm/thumb2.md +++ b/gcc/config/arm/thumb2.md @@ -537,10 +537,10 @@ ) (define_insn "*nonsecure_call_reg_thumb2_fpcxt" - [(call (unspec:SI [(mem:SI (match_operand:SI 0 "s_register_operand" "l*r"))] - UNSPEC_NONSECURE_MEM) + [(call (mem:SI (match_operand:SI 0 "s_register_operand" "l*r")) (match_operand 1 "" "")) (use (match_operand 2 "" "")) + (unspec:SI [(match_operand 3)] UNSPEC_NONSECURE_MEM) (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB2 && use_cmse && TARGET_HAVE_FPCXT_CMSE" "blxns\\t%0" @@ -549,10 +549,10 @@ ) (define_insn "*nonsecure_call_reg_thumb2" - [(call (unspec:SI [(mem:SI (reg:SI R4_REGNUM))] - UNSPEC_NONSECURE_MEM) + [(call (mem:SI (reg:SI R4_REGNUM)) (match_operand 0 "" "")) (use (match_operand 1 "" "")) + (unspec:SI [(match_operand 2)] UNSPEC_NONSECURE_MEM) (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB2 && use_cmse && !TARGET_HAVE_FPCXT_CMSE" "bl\\t__gnu_cmse_nonsecure_call" @@ -573,11 +573,10 @@ (define_insn "*nonsecure_call_value_reg_thumb2_fpcxt" [(set (match_operand 0 "" "") - (call - (unspec:SI [(mem:SI (match_operand:SI 1 "register_operand" "l*r"))] - UNSPEC_NONSECURE_MEM) - (match_operand 2 "" ""))) + (call (mem:SI (match_operand:SI 1 "register_operand" "l*r")) + (match_operand 2 "" ""))) (use (match_operand 3 "" "")) + (unspec:SI [(match_operand 4)] UNSPEC_NONSECURE_MEM) (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB2 && use_cmse && TARGET_HAVE_FPCXT_CMSE" "blxns\\t%1" @@ -587,10 +586,10 @@ (define_insn "*nonsecure_call_value_reg_thumb2" [(set (match_operand 0 "" "") - (call - (unspec:SI [(mem:SI (reg:SI R4_REGNUM))] UNSPEC_NONSECURE_MEM) - (match_operand 1 "" ""))) + (call (mem:SI (reg:SI R4_REGNUM)) + (match_operand 1 "" ""))) (use (match_operand 2 "" "")) + (unspec:SI [(match_operand 3)] UNSPEC_NONSECURE_MEM) (clobber (reg:SI LR_REGNUM))] "TARGET_THUMB2 && use_cmse && !TARGET_HAVE_FPCXT_CMSE" "bl\\t__gnu_cmse_nonsecure_call" diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc index be2daed..1724084 100644 --- a/gcc/config/darwin.cc +++ b/gcc/config/darwin.cc @@ -1298,6 +1298,29 @@ darwin_encode_section_info (tree decl, rtx rtl, int first) SYMBOL_FLAG_EXTERNAL. */ default_encode_section_info (decl, rtl, first); + if (CONSTANT_CLASS_P (decl)) + { + bool is_str = TREE_CODE (decl) == STRING_CST; + rtx sym_ref = XEXP (rtl, 0); + + /* If this is a string cst or not anchored we have nothing to do. */ + if (is_str || !SYMBOL_REF_HAS_BLOCK_INFO_P (sym_ref)) + return; + + tree sym_decl = SYMBOL_REF_DECL (sym_ref); + const char *name = XSTR (sym_ref, 0); + gcc_checking_assert (strncmp ("*lC", name, 3) == 0); + + char *buf; + /* Lets identify anchored constants with a different prefix, for the + sake of inspection only. */ + buf = xasprintf ("*LaC%s", &name[3]); + if (sym_decl) + DECL_NAME (sym_decl) = get_identifier (buf); + XSTR (sym_ref, 0) = ggc_strdup (buf); + free (buf); + } + if (! VAR_OR_FUNCTION_DECL_P (decl)) return; @@ -3297,11 +3320,16 @@ darwin_use_anchors_for_symbol_p (const_rtx symbol) { if (DARWIN_SECTION_ANCHORS && flag_section_anchors) { - section *sect; - /* If the section contains a zero-sized object it's ineligible. */ - sect = SYMBOL_REF_BLOCK (symbol)->sect; - /* This should have the effect of disabling anchors for vars that follow - any zero-sized one, in a given section. */ + tree decl = SYMBOL_REF_DECL (symbol); + /* If the symbol would be linker-visible, then it can split at that + so we must disallow. This is more strict than the default impl. + TODO: add other cases. */ + if (decl && DECL_P (decl) + && (TREE_PUBLIC (decl) || !DECL_ARTIFICIAL (decl))) + return false; + + /* We mark sections containing unsuitable entries. */ + section *sect = SYMBOL_REF_BLOCK (symbol)->sect; if (sect->common.flags & SECTION_NO_ANCHOR) return false; diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 9b9a3fe..ccfe01e 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -1005,6 +1005,8 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS]; sprintf (LABEL, "*%s%ld", "lASAN", (long)(NUM));\ else if (strcmp ("LTRAMP", PREFIX) == 0) \ sprintf (LABEL, "*%s%ld", "lTRAMP", (long)(NUM));\ + else if (strncmp ("LANCHOR", PREFIX, 7) == 0) \ + sprintf (LABEL, "*%s%ld", "lANCHOR", (long)(NUM));\ else \ sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM)); \ } while (0) diff --git a/gcc/config/xtensa/constraints.md b/gcc/config/xtensa/constraints.md index 77c9571..727ec1e 100644 --- a/gcc/config/xtensa/constraints.md +++ b/gcc/config/xtensa/constraints.md @@ -130,7 +130,7 @@ (and (match_code "mem") (match_test "smalloffset_mem_p (op)"))) -(define_memory_constraint "T" +(define_special_memory_constraint "T" "Memory in a literal pool (addressable with an L32R instruction)." (and (match_code "mem") (match_test "!TARGET_CONST16 && constantpool_mem_p (op)"))) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8e9b8ea..b85f527 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,53 @@ +2025-08-08 David Malcolm <dmalcolm@redhat.com> + + * error.cc (cp_adjust_diagnostic_info): Convert "context" arg from + ptr to const &. + +2025-08-07 Patrick Palka <ppalka@redhat.com> + + * call.cc (extract_call_expr): Remove handling of C++20 + rewritten comparison operators. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR c++/117783 + * parser.cc: Implement C++26 P1061R10 - Structured Bindings can + introduce a Pack. + (cp_parser_range_for): Also handle TREE_VEC as DECL_VALUE_EXPR + instead of ARRAY_REF. + (cp_parser_decomposition_declaration): Use sb-identifier-list instead + of identifier-list in comments. Parse structured bindings with + structured binding pack. Don't emit pedwarn about structured + binding attributes in structured bindings inside of a condition. + (cp_convert_omp_range_for): Also handle TREE_VEC as DECL_VALUE_EXPR + instead of ARRAY_REF. + * decl.cc (get_tuple_element_type): Change i argument type from + unsigned to unsigned HOST_WIDE_INT. + (get_tuple_decomp_init): Likewise. + (set_sb_pack_name): New function. + (cp_finish_decomp): Handle structured binding packs. + * pt.cc (tsubst_pack_expansion): Handle structured binding packs + and capture proxies for them. Formatting fixes. + (tsubst_decl): For structured binding packs don't tsubst TREE_TYPE + first, instead recreate the type after r is created. + (tsubst_omp_for_iterator): Also handle TREE_VEC as DECL_VALUE_EXPR + instead of ARRAY_REF. + (tsubst_expr): Handle sizeof... on non-dependent structure binding + packs. + (value_dependent_expression_p): Return false for sizeof... on + non-dependent structure binding packs. + (instantiation_dependent_r): Don't recurse on sizeof... on + non-dependent structure binding packs. + * constexpr.cc (potential_constant_expression_1): Also handle + TREE_VEC on DECL_VALUE_EXPR of structure binding packs. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * lex.cc (cxx_init): Mark cpp nodes corresponding + to keywords, identifiers with special meaning and standard + attribute identifiers as NODE_WARN if warn_keyword_macro. + 2025-08-06 Patrick Palka <ppalka@redhat.com> PR c++/121231 diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 9283d97..63cad2a 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -7904,28 +7904,6 @@ extract_call_expr (tree call) call = TREE_OPERAND (call, 0); if (TREE_CODE (call) == TARGET_EXPR) call = TARGET_EXPR_INITIAL (call); - if (cxx_dialect >= cxx20) - switch (TREE_CODE (call)) - { - /* C++20 rewritten comparison operators. */ - case TRUTH_NOT_EXPR: - call = TREE_OPERAND (call, 0); - break; - case LT_EXPR: - case LE_EXPR: - case GT_EXPR: - case GE_EXPR: - case SPACESHIP_EXPR: - { - tree op0 = TREE_OPERAND (call, 0); - if (integer_zerop (op0)) - call = TREE_OPERAND (call, 1); - else - call = op0; - } - break; - default:; - } if (TREE_CODE (call) != CALL_EXPR && TREE_CODE (call) != AGGR_INIT_EXPR diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index b8ac454..eabf7f8 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -11615,12 +11615,14 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, } return false; } + tree ve = DECL_VALUE_EXPR (t); /* Treat __PRETTY_FUNCTION__ inside a template function as potentially-constant. */ - else if (DECL_PRETTY_FUNCTION_P (t) - && DECL_VALUE_EXPR (t) == error_mark_node) + if (DECL_PRETTY_FUNCTION_P (t) && ve == error_mark_node) return true; - return RECUR (DECL_VALUE_EXPR (t), rval); + if (DECL_DECOMPOSITION_P (t) && TREE_CODE (ve) == TREE_VEC) + return RECUR (TREE_VEC_ELT (ve, 0), rval); + return RECUR (ve, rval); } if (want_rval && (now || !var_in_maybe_constexpr_fn (t)) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 8122fca..ab5b0c9 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -9748,7 +9748,7 @@ get_tuple_size (tree type) /* Return std::tuple_element<I,TYPE>::type. */ static tree -get_tuple_element_type (tree type, unsigned i) +get_tuple_element_type (tree type, unsigned HOST_WIDE_INT i) { tree args = make_tree_vec (2); TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i); @@ -9764,7 +9764,7 @@ get_tuple_element_type (tree type, unsigned i) /* Return e.get<i>() or get<i>(e). */ static tree -get_tuple_decomp_init (tree decl, unsigned i) +get_tuple_decomp_init (tree decl, unsigned HOST_WIDE_INT i) { tree targs = make_tree_vec (1); TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i); @@ -9870,6 +9870,19 @@ cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp) } } +/* Append #i to DECL_NAME (decl). */ + +static void +set_sb_pack_name (tree decl, unsigned HOST_WIDE_INT i) +{ + tree name = DECL_NAME (decl); + size_t len = IDENTIFIER_LENGTH (name) + 22; + char *n = XALLOCAVEC (char, len); + snprintf (n, len, "%s#" HOST_WIDE_INT_PRINT_UNSIGNED, + IDENTIFIER_POINTER (name), i); + DECL_NAME (decl) = get_identifier (n); +} + /* Finish a decomposition declaration. DECL is the underlying declaration "e", FIRST is the head of a chain of decls for the individual identifiers chained through DECL_CHAIN in reverse order and COUNT is the number of @@ -9926,10 +9939,13 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) auto_vec<tree, 16> v; v.safe_grow (count, true); tree d = first; + int pack = -1; for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d)) { v[count - i - 1] = d; fit_decomposition_lang_decl (d, decl); + if (DECL_PACK_P (d)) + pack = count - i - 1; } tree type = TREE_TYPE (decl); @@ -9951,6 +9967,14 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) tree eltype = NULL_TREE; unsigned HOST_WIDE_INT eltscnt = 0; + /* Structured binding packs when initializer is non-dependent should + have their DECL_VALUE_EXPR set to a TREE_VEC. First two elements + of that TREE_VEC are the base and index, what is normally represented + as DECL_VALUE_EXPR ARRAY_REF <base, index> where index is the index + of the pack first element. The remaining elements of the TREE_VEC + are VAR_DECLs for the pack elements. */ + tree packv = NULL_TREE; + if (TREE_CODE (type) == ARRAY_TYPE) { tree nelts; @@ -9969,7 +9993,7 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) goto error_out; } eltscnt = tree_to_uhwi (nelts); - if (count != eltscnt) + if (pack != -1 ? count - 1 > eltscnt : count != eltscnt) { cnt_mismatch: auto_diagnostic_group d; @@ -9990,12 +10014,37 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) eltype = TREE_TYPE (type); for (unsigned int i = 0; i < count; i++) { + if ((unsigned) pack == i) + { + packv = make_tree_vec (eltscnt - count + 3); + for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j) + { + tree t; + TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]); + set_sb_pack_name (t, j); + maybe_push_decl (t); + TREE_TYPE (t) = eltype; + layout_decl (t, 0); + if (!processing_template_decl) + { + tree a = unshare_expr (dexp); + a = build4 (ARRAY_REF, eltype, a, size_int (j + pack), + NULL_TREE, NULL_TREE); + SET_DECL_VALUE_EXPR (t, a); + DECL_HAS_VALUE_EXPR_P (t) = 1; + } + } + continue; + } TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); if (processing_template_decl) continue; tree t = unshare_expr (dexp); - t = build4 (ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE); + unsigned HOST_WIDE_INT j = i; + if (pack != -1 && (unsigned) pack < i) + j = i + eltscnt - count; + t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE); SET_DECL_VALUE_EXPR (v[i], t); DECL_HAS_VALUE_EXPR_P (v[i]) = 1; } @@ -10004,17 +10053,41 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) else if (TREE_CODE (type) == COMPLEX_TYPE) { eltscnt = 2; - if (count != eltscnt) + if (pack != -1 ? count - 1 > eltscnt : count != eltscnt) goto cnt_mismatch; eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type)); for (unsigned int i = 0; i < count; i++) { + if ((unsigned) pack == i) + { + packv = make_tree_vec (eltscnt - count + 3); + for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j) + { + tree t; + TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]); + set_sb_pack_name (t, j); + maybe_push_decl (t); + TREE_TYPE (t) = eltype; + layout_decl (t, 0); + if (!processing_template_decl) + { + tree a = build1 (pack + j ? IMAGPART_EXPR : REALPART_EXPR, eltype, + unshare_expr (dexp)); + SET_DECL_VALUE_EXPR (t, a); + DECL_HAS_VALUE_EXPR_P (t) = 1; + } + } + continue; + } TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); if (processing_template_decl) continue; tree t = unshare_expr (dexp); - t = build1 (i ? IMAGPART_EXPR : REALPART_EXPR, eltype, t); + unsigned HOST_WIDE_INT j = i; + if (pack != -1 && (unsigned) pack < i) + j = i + eltscnt - count; + t = build1 (j ? IMAGPART_EXPR : REALPART_EXPR, eltype, t); SET_DECL_VALUE_EXPR (v[i], t); DECL_HAS_VALUE_EXPR_P (v[i]) = 1; } @@ -10026,19 +10099,47 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) error_at (loc, "cannot decompose variable length vector %qT", type); goto error_out; } - if (count != eltscnt) + if (pack != -1 ? count - 1 > eltscnt : count != eltscnt) goto cnt_mismatch; eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type)); for (unsigned int i = 0; i < count; i++) { + if ((unsigned) pack == i) + { + packv = make_tree_vec (eltscnt - count + 3); + for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j) + { + tree t; + TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]); + set_sb_pack_name (t, j); + maybe_push_decl (t); + TREE_TYPE (t) = eltype; + layout_decl (t, 0); + if (!processing_template_decl) + { + tree a = unshare_expr (dexp); + location_t loc = DECL_SOURCE_LOCATION (t); + tree s = size_int (j + pack); + convert_vector_to_array_for_subscript (loc, &a, s); + a = build4 (ARRAY_REF, eltype, a, s, + NULL_TREE, NULL_TREE); + SET_DECL_VALUE_EXPR (t, a); + DECL_HAS_VALUE_EXPR_P (t) = 1; + } + } + continue; + } TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); if (processing_template_decl) continue; tree t = unshare_expr (dexp); + unsigned HOST_WIDE_INT j = i; + if (pack != -1 && (unsigned) pack < i) + j = i + eltscnt - count; convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]), - &t, size_int (i)); - t = build4 (ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE); + &t, size_int (j)); + t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE); SET_DECL_VALUE_EXPR (v[i], t); DECL_HAS_VALUE_EXPR_P (v[i]) = 1; } @@ -10062,11 +10163,11 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) goto error_out; } eltscnt = tree_to_uhwi (tsize); - if (count != eltscnt) + if (pack != -1 ? count - 1 > eltscnt : count != eltscnt) goto cnt_mismatch; - if (test_p) + if (test_p && eltscnt) return true; - if (!processing_template_decl && DECL_DECOMP_BASE (decl)) + if (!processing_template_decl && DECL_DECOMP_BASE (decl) && eltscnt) { /* For structured bindings used in conditions we need to evaluate the conversion of decl (aka e in the standard) to bool or @@ -10096,16 +10197,70 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) location_t sloc = input_location; location_t dloc = DECL_SOURCE_LOCATION (v[i]); + if ((unsigned) pack == i) + { + packv = make_tree_vec (eltscnt - count + 3); + for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j) + { + tree t; + TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]); + set_sb_pack_name (t, j); + input_location = dloc; + tree init = get_tuple_decomp_init (decl, j + pack); + tree eltype = (init == error_mark_node ? error_mark_node + : get_tuple_element_type (type, j + pack)); + input_location = sloc; + + if (VOID_TYPE_P (eltype)) + { + error ("%<std::tuple_element<%wu, %T>::type%> is " + "%<void%>", j + pack, type); + eltype = error_mark_node; + } + if (init == error_mark_node || eltype == error_mark_node) + { + inform (dloc, "in initialization of structured binding " + "pack %qD", v[pack]); + goto error_out; + } + if (j == 0 + && !processing_template_decl + && TREE_STATIC (decl)) + { + sorry_at (dloc, "mangling of structured binding pack " + "elements not implemented yet"); + goto error_out; + } + maybe_push_decl (t); + /* Save the decltype away before reference collapse. */ + hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype); + eltype = cp_build_reference_type (eltype, !lvalue_p (init)); + TREE_TYPE (t) = eltype; + layout_decl (t, 0); + DECL_HAS_VALUE_EXPR_P (t) = 0; + if (!processing_template_decl) + { + copy_linkage (t, decl); + cp_finish_decl (t, init, /*constexpr*/false, + /*asm*/NULL_TREE, LOOKUP_NORMAL); + } + } + continue; + } + + unsigned HOST_WIDE_INT j = i; + if (pack != -1 && (unsigned) pack < i) + j = i + eltscnt - count; input_location = dloc; - tree init = get_tuple_decomp_init (decl, i); + tree init = get_tuple_decomp_init (decl, j); tree eltype = (init == error_mark_node ? error_mark_node - : get_tuple_element_type (type, i)); + : get_tuple_element_type (type, j)); input_location = sloc; if (VOID_TYPE_P (eltype)) { - error ("%<std::tuple_element<%u, %T>::type%> is %<void%>", - i, type); + error ("%<std::tuple_element<%wu, %T>::type%> is %<void%>", + j, type); eltype = error_mark_node; } if (init == error_mark_node || eltype == error_mark_node) @@ -10159,6 +10314,12 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) goto error_out; else if (btype == NULL_TREE) { + if (pack == 0 && count == 1) + { + eltscnt = 0; + packv = make_tree_vec (2); + goto done; + } error_at (loc, "cannot decompose class type %qT without non-static " "data members", type); goto error_out; @@ -10170,7 +10331,7 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) continue; else eltscnt++; - if (count != eltscnt) + if (pack != -1 ? count - 1 > eltscnt : count != eltscnt) goto cnt_mismatch; tree t = dexp; if (type != btype) @@ -10179,6 +10340,7 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) /*nonnull*/false, tf_warning_or_error); type = btype; } + unsigned HOST_WIDE_INT j = 0; unsigned int i = 0; for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field)) if (TREE_CODE (field) != FIELD_DECL @@ -10191,6 +10353,32 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) NULL_TREE); if (REFERENCE_REF_P (tt)) tt = TREE_OPERAND (tt, 0); + if (pack != -1 && j >= (unsigned) pack) + { + if (j == (unsigned) pack) + { + packv = make_tree_vec (eltscnt - count + 3); + i++; + } + if (j < (unsigned) pack + eltscnt - (count - 1)) + { + tree t; + TREE_VEC_ELT (packv, j + 3 - i) = t = copy_node (v[pack]); + set_sb_pack_name (t, j + 1 - i); + maybe_push_decl (t); + TREE_TYPE (t) = TREE_TYPE (tt); + layout_decl (t, 0); + if (!processing_template_decl) + { + SET_DECL_VALUE_EXPR (t, tt); + DECL_HAS_VALUE_EXPR_P (t) = 1; + } + else + DECL_HAS_VALUE_EXPR_P (t) = 0; + j++; + continue; + } + } TREE_TYPE (v[i]) = TREE_TYPE (tt); layout_decl (v[i], 0); if (!processing_template_decl) @@ -10199,7 +10387,26 @@ cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p) DECL_HAS_VALUE_EXPR_P (v[i]) = 1; } i++; + j++; } + if (pack != -1 && j == (unsigned) pack) + { + gcc_checking_assert (eltscnt == count - 1); + packv = make_tree_vec (2); + } + } + done: + if (packv) + { + gcc_checking_assert (pack != -1); + TREE_VEC_ELT (packv, 0) = decl; + TREE_VEC_ELT (packv, 1) = size_int (pack); + SET_DECL_VALUE_EXPR (v[pack], packv); + DECL_HAS_VALUE_EXPR_P (v[pack]) = 1; + DECL_IGNORED_P (v[pack]) = 1; + if (!processing_template_decl) + for (unsigned int i = 0; i < TREE_VEC_LENGTH (packv) - 2U; ++i) + pushdecl (TREE_VEC_ELT (packv, 2 + i)); } if (processing_template_decl) { diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index c427163..cd35c7a 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -250,7 +250,7 @@ erroneous_templates_t *erroneous_templates; issue an error if we later need to instantiate the template. */ static void -cp_adjust_diagnostic_info (diagnostics::context *context, +cp_adjust_diagnostic_info (const diagnostics::context &context, diagnostics::diagnostic_info *diagnostic) { if (diagnostic->m_kind == diagnostics::kind::error) @@ -258,7 +258,7 @@ cp_adjust_diagnostic_info (diagnostics::context *context, { diagnostic->m_option_id = OPT_Wtemplate_body; - if (context->m_permissive) + if (context.m_permissive) diagnostic->m_kind = diagnostics::kind::warning; bool existed; diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index a8c54c7..743fd74 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -14672,13 +14672,23 @@ cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl, tree v = DECL_VALUE_EXPR (range_decl); /* For decomposition declaration get all of the corresponding declarations out of the way. */ - if (TREE_CODE (v) == ARRAY_REF - && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) + if ((TREE_CODE (v) == ARRAY_REF + && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) + || (TREE_CODE (v) == TREE_VEC + && DECL_DECOMPOSITION_P (TREE_VEC_ELT (v, 0)))) { tree d = range_decl; - range_decl = TREE_OPERAND (v, 0); decomp = &decomp_d; - decomp->count = tree_to_uhwi (TREE_OPERAND (v, 1)) + 1; + if (TREE_CODE (v) == ARRAY_REF) + { + range_decl = TREE_OPERAND (v, 0); + decomp->count = tree_to_uhwi (TREE_OPERAND (v, 1)) + 1; + } + else + { + range_decl = TREE_VEC_ELT (v, 0); + decomp->count = tree_to_uhwi (TREE_VEC_ELT (v, 1)) + 1; + } decomp->decl = d; bool seen_name_independent_decl = false; for (unsigned int i = 0; i < decomp->count; @@ -16843,7 +16853,7 @@ cp_parser_simple_declaration (cp_parser* parser, } /* Helper of cp_parser_simple_declaration, parse a decomposition declaration. - decl-specifier-seq ref-qualifier [opt] [ identifier-list ] + decl-specifier-seq ref-qualifier [opt] [ sb-identifier-list ] initializer ; */ static tree @@ -16856,21 +16866,45 @@ cp_parser_decomposition_declaration (cp_parser *parser, location_t loc = cp_lexer_peek_token (parser->lexer)->location; cp_parser_require (parser, CPP_OPEN_SQUARE, RT_OPEN_SQUARE); - /* Parse the identifier-list. */ + /* Parse the sb-identifier-list. */ auto_vec<cp_expr, 10> v; bool attr_diagnosed = false; int first_attr = -1; + int pack = -1; unsigned int cnt = 0; if (!cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_SQUARE)) while (true) { + if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)) + { + location_t elloc = cp_lexer_peek_token (parser->lexer)->location; + if (!processing_template_decl) + error_at (elloc, "structured binding pack outside of template"); + else if (pack != -1) + error_at (elloc, + "multiple packs in structured binding declaration"); + else + { + if (keyword == RID_MAX + && cxx_dialect >= cxx17 + && cxx_dialect < cxx26) + pedwarn (elloc, OPT_Wc__26_extensions, + "structured binding packs only available with " + "%<-std=c++2c%> or %<-std=gnu++2c%>"); + pack = cnt; + } + cp_lexer_consume_token (parser->lexer); + } cp_expr e = cp_parser_identifier (parser); if (e.get_value () == error_mark_node) break; tree attr = NULL_TREE; if (cp_next_tokens_can_be_std_attribute_p (parser)) { - if (cxx_dialect >= cxx17 && cxx_dialect < cxx26 && !attr_diagnosed) + if (keyword == RID_MAX + && cxx_dialect >= cxx17 + && cxx_dialect < cxx26 + && !attr_diagnosed) { pedwarn (cp_lexer_peek_token (parser->lexer)->location, OPT_Wc__26_extensions, @@ -16931,7 +16965,7 @@ cp_parser_decomposition_declaration (cp_parser *parser, &pushed_scope); tree orig_decl = decl; - unsigned int i; + unsigned int i, j; cp_expr e; cp_decl_specifier_seq decl_specs; clear_decl_specs (&decl_specs); @@ -16939,6 +16973,7 @@ cp_parser_decomposition_declaration (cp_parser *parser, if (decl_specifiers->storage_class == sc_static) decl_specs.storage_class = sc_static; tree prev = decl; + j = 0; FOR_EACH_VEC_ELT (v, i, e) { if (i == 0) @@ -16969,9 +17004,22 @@ cp_parser_decomposition_declaration (cp_parser *parser, prev = decl2; DECL_DECLARED_CONSTEXPR_P (decl2) = DECL_DECLARED_CONSTEXPR_P (decl); DECL_DECLARED_CONSTINIT_P (decl2) = DECL_DECLARED_CONSTINIT_P (decl); + if (j == (unsigned) pack) + { + tree dtype = cxx_make_type (DECLTYPE_TYPE); + DECLTYPE_TYPE_EXPR (dtype) = decl2; + DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (dtype) = 1; + SET_TYPE_STRUCTURAL_EQUALITY (dtype); + tree type = cxx_make_type (TYPE_PACK_EXPANSION); + PACK_EXPANSION_PATTERN (type) = dtype; + SET_TYPE_STRUCTURAL_EQUALITY (type); + PACK_EXPANSION_PARAMETER_PACKS (type) = decl2; + TREE_TYPE (decl2) = type; + } } if (elt_pushed_scope) pop_scope (elt_pushed_scope); + ++j; } if (v.is_empty ()) @@ -46300,6 +46348,14 @@ cp_convert_omp_range_for (tree &this_pre_body, tree &sl, decomp->count = tree_to_uhwi (TREE_OPERAND (v, 1)) + 1; decomp->decl = decl; } + else if (TREE_CODE (v) == TREE_VEC + && DECL_DECOMPOSITION_P (TREE_VEC_ELT (v, 0))) + { + d = TREE_VEC_ELT (v, 0); + decomp = &decomp_d; + decomp->count = tree_to_uhwi (TREE_VEC_ELT (v, 1)) + 1; + decomp->decl = decl; + } } do_range_for_auto_deduction (d, init, decomp); } @@ -46423,6 +46479,15 @@ cp_convert_omp_range_for (tree &this_pre_body, tree &sl, decomp->count = tree_to_uhwi (TREE_OPERAND (v, 1)) + 1; decomp->decl = d; } + else if (TREE_CODE (v) == TREE_VEC + && DECL_DECOMPOSITION_P (TREE_VEC_ELT (v, 0))) + { + tree d = orig_decl; + orig_decl = TREE_VEC_ELT (v, 0); + decomp = &decomp_d; + decomp->count = tree_to_uhwi (TREE_VEC_ELT (v, 1)) + 1; + decomp->decl = d; + } } tree auto_node = type_uses_auto (TREE_TYPE (orig_decl)); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index acfeb81..b6b13ed 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -13981,9 +13981,30 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain, else if (is_capture_proxy (parm_pack)) { arg_pack = retrieve_local_specialization (parm_pack); + if (DECL_DECOMPOSITION_P (arg_pack)) + { + orig_arg = arg_pack; + goto expand_sb_pack; + } if (DECL_PACK_P (arg_pack)) arg_pack = NULL_TREE; } + else if (DECL_DECOMPOSITION_P (parm_pack)) + { + orig_arg = retrieve_local_specialization (parm_pack); + expand_sb_pack: + gcc_assert (DECL_DECOMPOSITION_P (orig_arg)); + if (TREE_TYPE (orig_arg) == error_mark_node) + return error_mark_node; + gcc_assert (DECL_HAS_VALUE_EXPR_P (orig_arg)); + arg_pack = DECL_VALUE_EXPR (orig_arg); + tree vec = make_tree_vec (TREE_VEC_LENGTH (arg_pack) - 2); + if (TREE_VEC_LENGTH (vec)) + memcpy (TREE_VEC_BEGIN (vec), &TREE_VEC_ELT (arg_pack, 2), + TREE_VEC_LENGTH (vec) * sizeof (tree)); + arg_pack = make_node (NONTYPE_ARGUMENT_PACK); + ARGUMENT_PACK_ARGS (arg_pack) = vec; + } else { int idx; @@ -13996,7 +14017,8 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain, arg_pack = NULL_TREE; } - orig_arg = arg_pack; + if (orig_arg == NULL_TREE) + orig_arg = arg_pack; if (arg_pack && TREE_CODE (arg_pack) == ARGUMENT_PACK_SELECT) arg_pack = ARGUMENT_PACK_SELECT_FROM_PACK (arg_pack); @@ -14011,8 +14033,8 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain, if (arg_pack) { - int my_len = - TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg_pack)); + int my_len + = TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg_pack)); /* Don't bother trying to do a partial substitution with incomplete packs; we'll try again after deduction. */ @@ -14176,8 +14198,8 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain, /* Update the corresponding argument. */ if (TMPL_ARGS_HAVE_MULTIPLE_LEVELS (args)) - TREE_VEC_ELT (TREE_VEC_ELT (args, level -1 ), idx) = - TREE_TYPE (pack); + TREE_VEC_ELT (TREE_VEC_ELT (args, level -1 ), idx) + = TREE_TYPE (pack); else TREE_VEC_ELT (args, idx) = TREE_TYPE (pack); } @@ -15921,7 +15943,10 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain, tsubst_flags_t tcomplain = complain; if (VAR_P (t)) tcomplain |= tf_tst_ok; - type = tsubst (type, args, tcomplain, in_decl); + if (DECL_DECOMPOSITION_P (t) && DECL_PACK_P (t)) + type = NULL_TREE; + else + type = tsubst (type, args, tcomplain, in_decl); /* Substituting the type might have recursively instantiated this same alias (c++/86171). */ if (use_spec_table && gen_tmpl && DECL_ALIAS_TEMPLATE_P (gen_tmpl) @@ -15938,6 +15963,17 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain, { DECL_INITIALIZED_P (r) = 0; DECL_TEMPLATE_INSTANTIATED (r) = 0; + if (DECL_DECOMPOSITION_P (t) && DECL_PACK_P (t)) + { + tree dtype = cxx_make_type (DECLTYPE_TYPE); + DECLTYPE_TYPE_EXPR (dtype) = r; + DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (dtype) = 1; + SET_TYPE_STRUCTURAL_EQUALITY (dtype); + type = cxx_make_type (TYPE_PACK_EXPANSION); + PACK_EXPANSION_PATTERN (type) = dtype; + SET_TYPE_STRUCTURAL_EQUALITY (type); + PACK_EXPANSION_PARAMETER_PACKS (type) = r; + } if (TREE_CODE (type) == FUNCTION_TYPE) { /* It may seem that this case cannot occur, since: @@ -18555,13 +18591,17 @@ tsubst_omp_for_iterator (tree t, int i, tree declv, tree &orig_declv, if (decl != error_mark_node && DECL_HAS_VALUE_EXPR_P (decl)) { tree v = DECL_VALUE_EXPR (decl); - if (TREE_CODE (v) == ARRAY_REF - && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) + if ((TREE_CODE (v) == ARRAY_REF + && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) + || (TREE_CODE (v) == TREE_VEC + && DECL_DECOMPOSITION_P (TREE_VEC_ELT (v, 0)))) { + v = (TREE_CODE (v) == ARRAY_REF + ? TREE_OPERAND (v, 0) : TREE_VEC_ELT (v, 0)); cp_decomp decomp_d = { NULL_TREE, 0 }; - tree d = tsubst_decl (TREE_OPERAND (v, 0), args, complain); + tree d = tsubst_decl (v, args, complain); maybe_push_decl (d); - d = tsubst_decomp_names (d, TREE_OPERAND (v, 0), args, complain, + d = tsubst_decomp_names (d, v, args, complain, in_decl, &decomp_d); decomp = true; if (d == error_mark_node) @@ -21220,7 +21260,28 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) ++c_inhibit_evaluation_warnings; /* We only want to compute the number of arguments. */ if (PACK_EXPANSION_P (op)) - expanded = tsubst_pack_expansion (op, args, complain, in_decl); + { + expanded = NULL_TREE; + if (DECL_DECOMPOSITION_P (PACK_EXPANSION_PATTERN (op))) + { + tree d = PACK_EXPANSION_PATTERN (op); + if (DECL_HAS_VALUE_EXPR_P (d)) + { + d = DECL_VALUE_EXPR (d); + if (TREE_CODE (d) == TREE_VEC) + { + tree b = TREE_VEC_ELT (d, 0); + if (!type_dependent_expression_p_push (b)) + { + expanded = void_node; + len = TREE_VEC_LENGTH (d) - 2; + } + } + } + } + if (!expanded) + expanded = tsubst_pack_expansion (op, args, complain, in_decl); + } else expanded = tsubst_template_args (ARGUMENT_PACK_ARGS (op), args, complain, in_decl); @@ -29050,6 +29111,24 @@ value_dependent_expression_p (tree expression) case SIZEOF_EXPR: if (SIZEOF_EXPR_TYPE_P (expression)) return dependent_type_p (TREE_TYPE (TREE_OPERAND (expression, 0))); + if (tree p = TREE_OPERAND (expression, 0)) + if (PACK_EXPANSION_P (p) + && DECL_DECOMPOSITION_P (PACK_EXPANSION_PATTERN (p))) + { + tree d = PACK_EXPANSION_PATTERN (p); + if (DECL_HAS_VALUE_EXPR_P (d)) + { + d = DECL_VALUE_EXPR (d); + /* [temp.dep.constexpr]/4: + Expressions of the following form are value-dependent: + sizeof ... ( identifier ) + unless the identifier is a structured binding pack whose + initializer is not dependent. */ + if (TREE_CODE (d) == TREE_VEC + && !type_dependent_expression_p (TREE_VEC_ELT (d, 0))) + return false; + } + } /* FALLTHRU */ case ALIGNOF_EXPR: case TYPEID_EXPR: @@ -29563,6 +29642,22 @@ instantiation_dependent_r (tree *tp, int *walk_subtrees, tree op = TREE_OPERAND (*tp, 0); if (code == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (*tp)) op = TREE_TYPE (op); + else if (code == SIZEOF_EXPR + && PACK_EXPANSION_P (op) + && DECL_DECOMPOSITION_P (PACK_EXPANSION_PATTERN (op))) + { + tree d = PACK_EXPANSION_PATTERN (op); + if (DECL_HAS_VALUE_EXPR_P (d)) + { + d = DECL_VALUE_EXPR (d); + if (TREE_CODE (d) == TREE_VEC + && !type_dependent_expression_p (TREE_VEC_ELT (d, 0))) + { + *walk_subtrees = 0; + return NULL_TREE; + } + } + } if (TYPE_P (op)) { if (dependent_type_p (op)) diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 7572e04..7d73046 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -277,9 +277,6 @@ namespace diagnostics { /* Compute the number of digits in the decimal representation of an integer. */ extern int num_digits (int); -extern char *get_cwe_url (int cwe); -extern const char *maybe_line_and_column (int line, int col); - } // namespace diagnostics #endif /* ! GCC_DIAGNOSTIC_H */ diff --git a/gcc/diagnostics/buffering.cc b/gcc/diagnostics/buffering.cc index 29f039f..a7747b5 100644 --- a/gcc/diagnostics/buffering.cc +++ b/gcc/diagnostics/buffering.cc @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "diagnostics/buffering.h" #include "diagnostics/sink.h" +#include "diagnostics/dumping.h" namespace diagnostics { @@ -122,12 +123,12 @@ void buffer::dump (FILE *out, int indent) const { m_diagnostic_counters.dump (out, indent + 2); - fprintf (out, "%*sm_per_sink_buffers:\n", indent, ""); + dumping::emit_heading (out, indent, "m_per_sink_buffers"); if (m_per_sink_buffers) for (auto per_sink_buffer_ : *m_per_sink_buffers) per_sink_buffer_->dump (out, indent + 2); else - fprintf (out, "%*s(none)\n", indent + 2, ""); + dumping::emit_none (out, indent + 2); } bool diff --git a/gcc/diagnostics/column-options.h b/gcc/diagnostics/column-options.h new file mode 100644 index 0000000..86296e9 --- /dev/null +++ b/gcc/diagnostics/column-options.h @@ -0,0 +1,44 @@ +/* Options relating to the meaning of column numbers. + Copyright (C) 2000-2025 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#ifndef GCC_DIAGNOSTICS_COLUMN_OPTIONS_H +#define GCC_DIAGNOSTICS_COLUMN_OPTIONS_H + +namespace diagnostics { + +/* A bundle of options relating to the meaning of column numbers. */ + +struct column_options +{ + int convert_column (file_cache &fc, + expanded_location s) const; + + /* What units to use when outputting the column number. */ + enum diagnostics_column_unit m_column_unit; + + /* The origin for the column number (1-based or 0-based typically). */ + int m_column_origin; + + /* The size of the tabstop for tab expansion. */ + int m_tabstop; +}; + +} // namespace diagnostics + +#endif /* ! GCC_DIAGNOSTICS_COLUMN_OPTIONS_H */ diff --git a/gcc/diagnostics/context.cc b/gcc/diagnostics/context.cc index a1441ca..3668958 100644 --- a/gcc/diagnostics/context.cc +++ b/gcc/diagnostics/context.cc @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/logical-locations.h" #include "diagnostics/buffering.h" #include "diagnostics/file-cache.h" +#include "diagnostics/dumping.h" #ifdef HAVE_TERMIOS_H # include <termios.h> @@ -176,12 +177,18 @@ context::initialize (int n_opts) m_client_aux_data = nullptr; m_lock = 0; m_inhibit_notes_p = false; + m_source_printing.colorize_source_p = false; m_source_printing.show_labels_p = false; m_source_printing.show_line_numbers_p = false; m_source_printing.min_margin_width = 0; m_source_printing.show_ruler_p = false; m_source_printing.show_event_links_p = false; + + m_column_options.m_column_unit = DIAGNOSTICS_COLUMN_UNIT_DISPLAY; + m_column_options.m_column_origin = 1; + m_column_options.m_tabstop = 8; + m_report_bug = false; m_extra_output_kind = EXTRA_DIAGNOSTIC_OUTPUT_none; if (const char *var = getenv ("GCC_EXTRA_DIAGNOSTIC_OUTPUT")) @@ -192,9 +199,6 @@ context::initialize (int n_opts) m_extra_output_kind = EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2; /* Silently ignore unrecognized values. */ } - m_column_unit = DIAGNOSTICS_COLUMN_UNIT_DISPLAY; - m_column_origin = 1; - m_tabstop = 8; m_escape_format = DIAGNOSTICS_ESCAPE_FORMAT_UNICODE; m_fixits_change_set = nullptr; m_diagnostic_groups.m_group_nesting_depth = 0; @@ -284,6 +288,33 @@ context::urls_init (int value) (m_reference_printer->get_url_format ()); } +void +context::set_show_nesting (bool val) +{ + for (auto sink_ : m_sinks) + if (sink_->follows_reference_printer_p ()) + if (auto text_sink_ = sink_->dyn_cast_text_sink ()) + text_sink_->set_show_nesting (val); +} + +void +context::set_show_nesting_locations (bool val) +{ + for (auto sink_ : m_sinks) + if (sink_->follows_reference_printer_p ()) + if (auto text_sink_ = sink_->dyn_cast_text_sink ()) + text_sink_->set_show_locations_in_nesting (val); +} + +void +context::set_show_nesting_levels (bool val) +{ + for (auto sink_ : m_sinks) + if (sink_->follows_reference_printer_p ()) + if (auto text_sink_ = sink_->dyn_cast_text_sink ()) + text_sink_->set_show_nesting_levels (val); +} + /* Create the file_cache, if not already created, and tell it how to translate files on input. */ void @@ -355,33 +386,40 @@ context::finish () /* Dump state of this diagnostics::context to OUT, for debugging. */ void -context::dump (FILE *out) const +context::dump (FILE *outfile) const { - fprintf (out, "diagnostics::context:\n"); - m_diagnostic_counters.dump (out, 2); - fprintf (out, " reference printer:\n"); - m_reference_printer->dump (out, 4); - fprintf (out, " output sinks:\n"); + dumping::emit_heading (outfile, 0, "diagnostics::context"); + m_diagnostic_counters.dump (outfile, 2); + dumping::emit_heading (outfile, 2, "reference printer"); + if (m_reference_printer) + m_reference_printer->dump (outfile, 4); + else + dumping::emit_none (outfile, 4); + dumping::emit_heading (outfile, 2, "output sinks"); if (m_sinks.length () > 0) { for (unsigned i = 0; i < m_sinks.length (); ++i) { - fprintf (out, " sink %i:\n", i); - m_sinks[i]->dump (out, 4); + dumping::emit_indent (outfile, 4); + const sink *s = m_sinks[i]; + fprintf (outfile, "sink %i (", i); + s->dump_kind (outfile); + fprintf (outfile, "):\n"); + s->dump (outfile, 6); } } else - fprintf (out, " (none):\n"); - fprintf (out, " diagnostic buffer:\n"); + dumping::emit_none (outfile, 4); + dumping::emit_heading (outfile, 2, "diagnostic buffer"); if (m_diagnostic_buffer) - m_diagnostic_buffer->dump (out, 4); + m_diagnostic_buffer->dump (outfile, 4); else - fprintf (out, " (none):\n"); - fprintf (out, " file cache:\n"); + dumping::emit_none (outfile, 4); + dumping::emit_heading (outfile, 2, "file cache"); if (m_file_cache) - m_file_cache->dump (out, 4); + m_file_cache->dump (outfile, 4); else - fprintf (out, " (none):\n"); + dumping::emit_none (outfile, 4); } /* Return true if sufficiently severe diagnostics have been seen that @@ -671,11 +709,22 @@ convert_column_unit (file_cache &fc, } } +/* Given an expanded_location, convert the column (which is in 1-based bytes) + to the requested units and origin. Return -1 if the column is + invalid (<= 0). */ +int +column_options::convert_column (file_cache &fc, + expanded_location s) const +{ + int one_based_col = convert_column_unit (fc, m_column_unit, m_tabstop, s); + if (one_based_col <= 0) + return -1; + return one_based_col + (m_column_origin - 1); +} + column_policy::column_policy (const context &dc) : m_file_cache (dc.get_file_cache ()), - m_column_unit (dc.m_column_unit), - m_column_origin (dc.m_column_origin), - m_tabstop (dc.m_tabstop) + m_column_options (dc.get_column_options ()) { } @@ -685,11 +734,7 @@ column_policy::column_policy (const context &dc) int column_policy::converted_column (expanded_location s) const { - int one_based_col = convert_column_unit (m_file_cache, - m_column_unit, m_tabstop, s); - if (one_based_col <= 0) - return -1; - return one_based_col + (m_column_origin - 1); + return m_column_options.convert_column (m_file_cache, s); } /* Return a string describing a location e.g. "foo.c:42:10". */ @@ -711,7 +756,7 @@ column_policy::get_location_text (const expanded_location &s, col = converted_column (s); } - const char *line_col = maybe_line_and_column (line, col); + const char *line_col = text_sink::maybe_line_and_column (line, col); return label_text::take (build_message_string ("%s%s%s:%s", locus_cs, file, line_col, locus_ce)); } @@ -1098,7 +1143,7 @@ context::get_any_inlining_info (diagnostic_info *diagnostic) /* Retrieve the locations into which the expression about to be diagnosed has been inlined, including those of all the callers all the way down the inlining stack. */ - m_set_locations_cb (this, diagnostic); + m_set_locations_cb (*this, diagnostic); else { /* When there's no callback use just the one location provided @@ -1249,7 +1294,7 @@ context::report_diagnostic (diagnostic_info *diagnostic) } if (m_adjust_diagnostic_info) - m_adjust_diagnostic_info (this, diagnostic); + m_adjust_diagnostic_info (*this, diagnostic); if (diagnostic->m_kind == kind::pedwarn) { @@ -1385,6 +1430,8 @@ context::report_diagnostic (diagnostic_info *diagnostic) sink_->on_report_diagnostic (*diagnostic, orig_diag_kind); } + const int tabstop = get_column_options ().m_tabstop; + switch (m_extra_output_kind) { default: @@ -1393,14 +1440,14 @@ context::report_diagnostic (diagnostic_info *diagnostic) print_parseable_fixits (get_file_cache (), m_reference_printer, diagnostic->m_richloc, DIAGNOSTICS_COLUMN_UNIT_BYTE, - m_tabstop); + tabstop); pp_flush (m_reference_printer); break; case EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2: print_parseable_fixits (get_file_cache (), m_reference_printer, diagnostic->m_richloc, DIAGNOSTICS_COLUMN_UNIT_DISPLAY, - m_tabstop); + tabstop); pp_flush (m_reference_printer); break; } @@ -1690,7 +1737,7 @@ context::set_nesting_level (int new_level) void sink::dump (FILE *out, int indent) const { - fprintf (out, "%*sprinter:\n", indent, ""); + dumping::emit_heading (out, indent, "printer"); m_printer->dump (out, indent + 2); } @@ -1777,19 +1824,19 @@ counters::counters () void counters::dump (FILE *out, int indent) const { - fprintf (out, "%*scounts:\n", indent, ""); + dumping::emit_heading (out, indent, "counts"); bool none = true; for (int i = 0; i < static_cast<int> (kind::last_diagnostic_kind); i++) if (m_count_for_kind[i] > 0) { - fprintf (out, "%*s%s%i\n", - indent + 2, "", + dumping::emit_indent (out, indent + 2); + fprintf (out, "%s%i\n", get_text_for_kind (static_cast<enum kind> (i)), m_count_for_kind[i]); none = false; } if (none) - fprintf (out, "%*s(none)\n", indent + 2, ""); + dumping::emit_none (out, indent + 2); } void @@ -2015,8 +2062,8 @@ assert_location_text (const char *expected_loc_text, = DIAGNOSTICS_COLUMN_UNIT_BYTE) { diagnostics::selftest::test_context dc; - dc.m_column_unit = column_unit; - dc.m_column_origin = origin; + dc.get_column_options ().m_column_unit = column_unit; + dc.get_column_options ().m_column_origin = origin; expanded_location xloc; xloc.file = filename; @@ -2052,8 +2099,8 @@ test_get_location_text () assert_location_text ("foo.c:42:", "foo.c", 42, 10, false); assert_location_text ("foo.c:", "foo.c", 0, 10, false); - diagnostics::maybe_line_and_column (INT_MAX, INT_MAX); - diagnostics::maybe_line_and_column (INT_MIN, INT_MIN); + diagnostics::text_sink::maybe_line_and_column (INT_MAX, INT_MAX); + diagnostics::text_sink::maybe_line_and_column (INT_MIN, INT_MIN); { /* In order to test display columns vs byte columns, we need to create a diff --git a/gcc/diagnostics/context.h b/gcc/diagnostics/context.h index b6ec85c..dea4588 100644 --- a/gcc/diagnostics/context.h +++ b/gcc/diagnostics/context.h @@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/option-id-manager.h" #include "diagnostics/context-options.h" #include "diagnostics/source-printing-options.h" +#include "diagnostics/column-options.h" #include "diagnostics/counters.h" namespace diagnostics { @@ -99,13 +100,11 @@ public: bool show_column, bool colorize) const; - int get_tabstop () const { return m_tabstop; } + int get_tabstop () const { return m_column_options.m_tabstop; } private: file_cache &m_file_cache; - enum diagnostics_column_unit m_column_unit; - int m_column_origin; - int m_tabstop; + column_options m_column_options; }; /* A bundle of state for printing locations within diagnostics @@ -265,7 +264,7 @@ public: friend class text_sink; friend class buffer; - typedef void (*set_locations_callback_t) (context *, + typedef void (*set_locations_callback_t) (const context &, diagnostic_info *); void initialize (int n_opts); @@ -393,6 +392,9 @@ public: } void set_show_path_depths (bool val) { m_show_path_depths = val; } void set_show_option_requested (bool val) { m_show_option_requested = val; } + void set_show_nesting (bool val); + void set_show_nesting_locations (bool val); + void set_show_nesting_levels (bool val); void set_max_errors (int val) { m_max_errors = val; } void set_escape_format (enum diagnostics_escape_format val) { @@ -572,7 +574,7 @@ public: } void - set_adjust_diagnostic_info_callback (void (*cb) (context *, + set_adjust_diagnostic_info_callback (void (*cb) (const context &, diagnostic_info *)) { m_adjust_diagnostic_info = cb; @@ -592,6 +594,9 @@ public: return m_source_printing; } + column_options &get_column_options () { return m_column_options; } + const column_options &get_column_options () const { return m_column_options; } + void set_caret_max_width (int value); private: @@ -708,7 +713,7 @@ private: /* Client hook to adjust properties of the given diagnostic that we're about to issue, such as its kind. */ - void (*m_adjust_diagnostic_info)(context *, diagnostic_info *); + void (*m_adjust_diagnostic_info)(const context &, diagnostic_info *); /* Owned by the context; this would be a std::unique_ptr if context had a proper ctor. */ @@ -739,6 +744,7 @@ private: bool m_inhibit_notes_p; source_printing_options m_source_printing; + column_options m_column_options; /* True if -freport-bug option is used. */ bool m_report_bug; @@ -748,17 +754,6 @@ private: -fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT. */ enum diagnostics_extra_output_kind m_extra_output_kind; -public: - /* What units to use when outputting the column number. */ - enum diagnostics_column_unit m_column_unit; - - /* The origin for the column number (1-based or 0-based typically). */ - int m_column_origin; - - /* The size of the tabstop for tab expansion. */ - int m_tabstop; - -private: /* How should non-ASCII/non-printable bytes be escaped when a diagnostic suggests escaping the source code on output. */ enum diagnostics_escape_format m_escape_format; diff --git a/gcc/diagnostics/dumping.cc b/gcc/diagnostics/dumping.cc new file mode 100644 index 0000000..1dbecf4 --- /dev/null +++ b/gcc/diagnostics/dumping.cc @@ -0,0 +1,102 @@ +/* Utilities for implementing "dump" functions for the diagnostics subsystem. + Copyright (C) 2025 Free Software Foundation, Inc. + Contributed by David Malcolm <dmalcolm@redhat.com>. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "diagnostics/dumping.h" + +namespace diagnostics { +namespace dumping { + +/* Emit indentation to OUTFILE for the start of a dump line. */ + +void +emit_indent (FILE *outfile, int indent) +{ + fprintf (outfile, "%*s", indent, ""); +} + +/* Emit an indented line to OUTFILE showing a heading. */ + +void +emit_heading (FILE *outfile, int indent, + const char *text) +{ + emit_indent (outfile, indent); + fprintf (outfile, "%s:\n", text); +} + +/* Various functions that emit an indented line to OUTFILE + showing "label: value". */ + +void +emit_string_field (FILE *outfile, int indent, + const char *label, const char *value) +{ + emit_indent (outfile, indent); + fprintf (outfile, "%s: %s\n", label, value); +} + +void +emit_bool_field (FILE *outfile, int indent, + const char *label, bool value) +{ + emit_string_field (outfile, indent, label, + value ? "true" : "false"); +} + +void +emit_size_t_field (FILE *outfile, int indent, + const char *label, size_t value) +{ + emit_indent (outfile, indent); + fprintf (outfile, "%s: " HOST_SIZE_T_PRINT_DEC "\n", label, value); +} + +void +emit_int_field (FILE *outfile, int indent, + const char *label, int value) +{ + emit_indent (outfile, indent); + fprintf (outfile, "%s: %i\n", label, value); +} + +void +emit_unsigned_field (FILE *outfile, int indent, + const char *label, unsigned value) +{ + emit_indent (outfile, indent); + fprintf (outfile, "%s: %u\n", label, value); +} + +/* Emit an indented line to OUTFILE reading "(none)". */ + +void +emit_none (FILE *outfile, int indent) +{ + emit_indent (outfile, indent); + fprintf (outfile, "(none)\n"); +} + + +} // namespace dumping { +} // namespace diagnostics diff --git a/gcc/diagnostics/dumping.h b/gcc/diagnostics/dumping.h new file mode 100644 index 0000000..02f6485 --- /dev/null +++ b/gcc/diagnostics/dumping.h @@ -0,0 +1,50 @@ +/* Utilities for implementing "dump" functions for the diagnostics subsystem. + Copyright (C) 2025 Free Software Foundation, Inc. + Contributed by David Malcolm <dmalcolm@redhat.com>. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#ifndef GCC_DIAGNOSTICS_DUMP_H +#define GCC_DIAGNOSTICS_DUMP_H + +namespace diagnostics { +namespace dumping { + +extern void emit_indent (FILE *outfile, int indent); +extern void emit_heading (FILE *outfile, int indent, + const char *text); + +extern void emit_string_field (FILE *outfile, int indent, + const char *label, const char *value); +extern void emit_bool_field (FILE *outfile, int indent, + const char *label, bool value); +extern void emit_size_t_field (FILE *outfile, int indent, + const char *label, size_t value); +extern void emit_int_field (FILE *outfile, int indent, + const char *label, int value); +extern void emit_unsigned_field (FILE *outfile, int indent, + const char *label, unsigned value); + +extern void emit_none (FILE *outfile, int indent); + +#define DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD(FLAG) \ + dumping::emit_bool_field (outfile, indent, #FLAG, FLAG) + +} // namespace dumping +} // namespace diagnostics + +#endif /* ! GCC_DIAGNOSTICS_DUMP_H */ diff --git a/gcc/diagnostics/file-cache.cc b/gcc/diagnostics/file-cache.cc index febeb03..0ec0679 100644 --- a/gcc/diagnostics/file-cache.cc +++ b/gcc/diagnostics/file-cache.cc @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "cpplib.h" #include "diagnostics/file-cache.h" +#include "diagnostics/dumping.h" #include "selftest.h" #ifndef HAVE_ICONV @@ -473,7 +474,8 @@ file_cache::dump (FILE *out, int indent) const { for (size_t i = 0; i < m_num_file_slots; ++i) { - fprintf (out, "%*sslot[%i]:\n", indent, "", (int)i); + dumping::emit_indent (out, indent); + fprintf (out, "slot[%i]:\n", (int)i); m_file_slots[i].dump (out, indent + 2); } } @@ -541,27 +543,38 @@ file_cache_slot::dump (FILE *out, int indent) const { if (!m_file_path) { - fprintf (out, "%*s(unused)\n", indent, ""); + dumping::emit_indent (out, indent); + fprintf (out, "(unused)\n"); return; } - fprintf (out, "%*sfile_path: %s\n", indent, "", m_file_path); - fprintf (out, "%*sfp: %p\n", indent, "", (void *)m_fp); - fprintf (out, "%*sneeds_read_p: %i\n", indent, "", (int)needs_read_p ()); - fprintf (out, "%*sneeds_grow_p: %i\n", indent, "", (int)needs_grow_p ()); - fprintf (out, "%*suse_count: %i\n", indent, "", m_use_count); - fprintf (out, "%*ssize: %zi\n", indent, "", m_size); - fprintf (out, "%*snb_read: %zi\n", indent, "", m_nb_read); - fprintf (out, "%*sstart_line_idx: %zi\n", indent, "", m_line_start_idx); - fprintf (out, "%*sline_num: %zi\n", indent, "", m_line_num); - fprintf (out, "%*smissing_trailing_newline: %i\n", - indent, "", (int)m_missing_trailing_newline); - fprintf (out, "%*sline records (%i):\n", - indent, "", m_line_record.length ()); + dumping::emit_string_field (out, indent, "file_path", m_file_path); + { + dumping::emit_indent (out, indent); + fprintf (out, "fp: %p\n", (void *)m_fp); + } + dumping::emit_bool_field (out, indent, "needs_read_p", needs_read_p ()); + dumping::emit_bool_field (out, indent, "needs_grow_p", needs_grow_p ()); + dumping::emit_unsigned_field (out, indent, "use_count", m_use_count); + dumping::emit_size_t_field (out, indent, "size", m_size); + dumping::emit_size_t_field (out, indent, "nb_read", m_nb_read); + dumping::emit_size_t_field (out, indent, "start_line_idx", m_line_start_idx); + dumping::emit_size_t_field (out, indent, "line_num", m_line_num); + dumping::emit_bool_field (out, indent, "missing_trailing_newline", + m_missing_trailing_newline); + { + dumping::emit_indent (out, indent); + fprintf (out, "line records (%i):\n", m_line_record.length ()); + } int idx = 0; for (auto &line : m_line_record) - fprintf (out, "%*s[%i]: line %zi: byte offsets: %zi-%zi\n", - indent + 2, "", - idx++, line.line_num, line.start_pos, line.end_pos); + { + dumping::emit_indent (out, indent); + fprintf (out, ("[%i]:" + " line " HOST_SIZE_T_PRINT_DEC ":" + " byte offsets: " HOST_SIZE_T_PRINT_DEC + "-" HOST_SIZE_T_PRINT_DEC "\n"), + idx++, line.line_num, line.start_pos, line.end_pos); + } } /* Returns TRUE iff the cache would need to be filled with data coming diff --git a/gcc/diagnostics/html-sink.cc b/gcc/diagnostics/html-sink.cc index 934d8e2..1fd317a 100644 --- a/gcc/diagnostics/html-sink.cc +++ b/gcc/diagnostics/html-sink.cc @@ -33,6 +33,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/output-file.h" #include "diagnostics/buffering.h" #include "diagnostics/paths.h" +#include "diagnostics/dumping.h" #include "diagnostics/client-data-hooks.h" #include "selftest.h" #include "diagnostics/selftest-context.h" @@ -61,6 +62,16 @@ html_generation_options::html_generation_options () { } +void +html_generation_options::dump (FILE *outfile, int indent) const +{ + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_css); + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_javascript); + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_state_diagrams); + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_state_diagrams_sarif); + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_state_diagrams_dot_src); +} + class html_builder; /* Concrete buffering implementation subclass for HTML output. */ @@ -116,6 +127,8 @@ public: const line_maps *line_maps, const html_generation_options &html_gen_opts); + void dump (FILE *out, int indent) const; + void set_main_input_filename (const char *name); @@ -223,11 +236,12 @@ make_span (std::string class_) void html_sink_buffer::dump (FILE *out, int indent) const { - fprintf (out, "%*shtml_sink_buffer:\n", indent, ""); + dumping::emit_heading (out, indent, "html_sink_buffer"); int idx = 0; for (auto &result : m_results) { - fprintf (out, "%*sresult[%i]:\n", indent + 2, "", idx); + dumping::emit_indent (out, indent + 2); + fprintf (out, "result[%i]:\n", idx); result->dump (out); fprintf (out, "\n"); ++idx; @@ -470,6 +484,13 @@ html_builder::html_builder (context &dc, } void +html_builder::dump (FILE *out, int indent) const +{ + dumping::emit_heading (out, indent, "HTML generation options"); + m_html_gen_opts.dump (out, indent + 2); +} + +void html_builder::set_main_input_filename (const char *name) { gcc_assert (m_title_element); @@ -539,7 +560,7 @@ html_builder::on_report_diagnostic (const diagnostic_info &diagnostic, } } -// For ease of comparison with experimental-nesting-show-levels=yes +// For ease of comparison with show-nesting-levels=yes static void add_nesting_level_attr (xml::element &element, @@ -1333,8 +1354,9 @@ public: void dump (FILE *out, int indent) const override { - fprintf (out, "%*shtml_sink\n", indent, ""); sink::dump (out, indent); + dumping::emit_heading (out, indent, "html_builder"); + m_builder.dump (out, indent + 2); } void @@ -1439,12 +1461,10 @@ public: { m_builder.flush_to_file (m_output_file.get_open_file ()); } - void dump (FILE *out, int indent) const override + void dump_kind (FILE *out) const override { - fprintf (out, "%*shtml_file_sink: %s\n", - indent, "", + fprintf (out, "html_file_sink: %s", m_output_file.get_filename ()); - sink::dump (out, indent); } bool machine_readable_stderr_p () const final override { @@ -1607,6 +1627,10 @@ private: : html_sink (dc, line_maps, html_gen_opts) { } + void dump_kind (FILE *out) const final override + { + fprintf (out, "html_buffered_sink"); + } bool machine_readable_stderr_p () const final override { return true; diff --git a/gcc/diagnostics/html-sink.h b/gcc/diagnostics/html-sink.h index d86bde8..d25ceea 100644 --- a/gcc/diagnostics/html-sink.h +++ b/gcc/diagnostics/html-sink.h @@ -30,6 +30,8 @@ struct html_generation_options { html_generation_options (); + void dump (FILE *out, int indent) const; + bool m_css; bool m_javascript; diff --git a/gcc/diagnostics/metadata.h b/gcc/diagnostics/metadata.h index c28f982..39291ec 100644 --- a/gcc/diagnostics/metadata.h +++ b/gcc/diagnostics/metadata.h @@ -119,6 +119,8 @@ class metadata const lazy_digraphs *m_lazy_digraphs; }; +extern char *get_cwe_url (int cwe); + } // namespace diagnostics #endif /* ! GCC_DIAGNOSTICS_METADATA_H */ diff --git a/gcc/diagnostics/output-spec.cc b/gcc/diagnostics/output-spec.cc index 83f128c..13565f9 100644 --- a/gcc/diagnostics/output-spec.cc +++ b/gcc/diagnostics/output-spec.cc @@ -368,7 +368,7 @@ text_scheme_handler::make_sink (const context &ctxt, const scheme_name_and_params &parsed_arg) const { bool show_color = pp_show_color (dc.get_reference_printer ()); - bool show_nesting = false; + bool show_nesting = true; bool show_locations_in_nesting = true; bool show_levels = false; for (auto& iter : parsed_arg.m_kvs) @@ -381,21 +381,21 @@ text_scheme_handler::make_sink (const context &ctxt, return nullptr; continue; } - if (key == "experimental-nesting") + if (key == "show-nesting") { if (!parse_bool_value (ctxt, unparsed_arg, key, value, show_nesting)) return nullptr; continue; } - if (key == "experimental-nesting-show-locations") + if (key == "show-nesting-locations") { if (!parse_bool_value (ctxt, unparsed_arg, key, value, show_locations_in_nesting)) return nullptr; continue; } - if (key == "experimental-nesting-show-levels") + if (key == "show-nesting-levels") { if (!parse_bool_value (ctxt, unparsed_arg, key, value, show_levels)) return nullptr; @@ -405,9 +405,9 @@ text_scheme_handler::make_sink (const context &ctxt, /* Key not found. */ auto_vec<const char *> known_keys; known_keys.safe_push ("color"); - known_keys.safe_push ("experimental-nesting"); - known_keys.safe_push ("experimental-nesting-show-locations"); - known_keys.safe_push ("experimental-nesting-show-levels"); + known_keys.safe_push ("show-nesting"); + known_keys.safe_push ("show-nesting-locations"); + known_keys.safe_push ("show-nesting-levels"); ctxt.report_unknown_key (unparsed_arg, key, get_scheme_name (), known_keys); return nullptr; diff --git a/gcc/diagnostics/sarif-sink.cc b/gcc/diagnostics/sarif-sink.cc index 4738ae9..7526c16 100644 --- a/gcc/diagnostics/sarif-sink.cc +++ b/gcc/diagnostics/sarif-sink.cc @@ -33,6 +33,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/paths.h" #include "diagnostics/sink.h" #include "diagnostics/buffering.h" +#include "diagnostics/dumping.h" #include "json.h" #include "cpplib.h" #include "diagnostics/logical-locations.h" @@ -704,6 +705,14 @@ sarif_serialization_format_json::write_to_file (FILE *outf, fprintf (outf, "\n"); } +void +sarif_serialization_format_json::dump (FILE *outfile, int indent) const +{ + dumping::emit_indent (outfile, indent); + fprintf (outfile, "json\n"); + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_formatted); +} + /* A class for managing SARIF output (for -fdiagnostics-format=sarif-stderr and -fdiagnostics-format=sarif-file). @@ -760,6 +769,8 @@ public: const sarif_generation_options &sarif_gen_opts); ~sarif_builder (); + void dump (FILE *out, int indent) const; + void set_printer (pretty_printer &printer) { m_printer = &printer; @@ -1674,7 +1685,7 @@ sarif_builder::sarif_builder (diagnostics::context &dc, (std::make_unique<sarif_array_of_unique<sarif_logical_location>> ()), m_run_graphs (std::make_unique<sarif_array_of_unique<sarif_graph>> ()), - m_tabstop (dc.m_tabstop), + m_tabstop (dc.get_column_options ().m_tabstop), m_serialization_format (std::move (serialization_format)), m_sarif_gen_opts (sarif_gen_opts), m_next_result_idx (0), @@ -1699,6 +1710,15 @@ sarif_builder::~sarif_builder () } } +void +sarif_builder::dump (FILE *out, int indent) const +{ + dumping::emit_heading (out, indent, "serialization format"); + m_serialization_format->dump (out, indent + 2); + dumping::emit_heading (out, indent, "SARIF generation options"); + m_sarif_gen_opts.dump (out, indent + 2); +} + /* Functions at which to stop the backtrace print. It's not particularly helpful to print the callers of these functions. */ @@ -3803,11 +3823,12 @@ sarif_builder::make_artifact_content_object (const char *text) const void sarif_sink_buffer::dump (FILE *out, int indent) const { - fprintf (out, "%*ssarif_sink_buffer:\n", indent, ""); + dumping::emit_heading (out, indent, "sarif_sink_buffer"); int idx = 0; for (auto &result : m_results) { - fprintf (out, "%*sresult[%i]:\n", indent + 2, "", idx); + dumping::emit_indent (out, indent + 2); + fprintf (out, "result[%i]:\n", idx); result->dump (out, true); fprintf (out, "\n"); ++idx; @@ -3862,8 +3883,9 @@ public: void dump (FILE *out, int indent) const override { - fprintf (out, "%*ssarif_sink\n", indent, ""); sink::dump (out, indent); + dumping::emit_heading (out, indent, "sarif_builder"); + m_builder.dump (out, indent + 2); } void @@ -3973,6 +3995,10 @@ public: { m_builder.flush_to_file (m_stream); } + void dump_kind (FILE *out) const override + { + fprintf (out, "sarif_stream_sink"); + } bool machine_readable_stderr_p () const final override { return m_stream == stderr; @@ -4001,12 +4027,10 @@ public: { m_builder.flush_to_file (m_output_file.get_open_file ()); } - void dump (FILE *out, int indent) const override + void dump_kind (FILE *out) const override { - fprintf (out, "%*ssarif_file_sink: %s\n", - indent, "", + fprintf (out, "sarif_file_sink: %s", m_output_file.get_filename ()); - sink::dump (out, indent); } bool machine_readable_stderr_p () const final override { @@ -4319,6 +4343,29 @@ sarif_generation_options::sarif_generation_options () { } +static const char * +get_dump_string_for_sarif_version (enum sarif_version version) +{ + switch (version) + { + default: + gcc_unreachable (); + case sarif_version::v2_1_0: + return "v2_1_0"; + case sarif_version::v2_2_prerelease_2024_08_08: + return "v2_2_prerelease_2024_08_08"; + } +} + +void +sarif_generation_options::dump (FILE *outfile, int indent) const +{ + dumping::emit_string_field (outfile, indent, + "m_version", + get_dump_string_for_sarif_version (m_version)); + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_state_graph); +} + #if CHECKING_P namespace selftest { @@ -4406,10 +4453,10 @@ public: test_sarif_diagnostic_context (const char *main_input_filename, const sarif_generation_options &sarif_gen_opts) { - auto sink_ = std::make_unique<buffered_sink> (*this, - line_table, - true, - sarif_gen_opts); + auto sink_ = std::make_unique<sarif_buffered_sink> (*this, + line_table, + true, + sarif_gen_opts); m_sink = sink_.get (); // borrowed init_sarif_sink (*this, std::move (sink_)); m_sink->set_main_input_filename (main_input_filename); @@ -4424,10 +4471,10 @@ public: sarif_result &get_result (size_t idx) { return m_sink->get_result (idx); } private: - class buffered_sink : public sarif_sink + class sarif_buffered_sink : public sarif_sink { public: - buffered_sink (context &dc, + sarif_buffered_sink (context &dc, const line_maps *line_maps, bool formatted, const sarif_generation_options &sarif_gen_opts) @@ -4436,6 +4483,10 @@ private: sarif_gen_opts) { } + void dump_kind (FILE *out) const final override + { + fprintf (out, "sarif_buffered_sink"); + } bool machine_readable_stderr_p () const final override { return false; @@ -4446,7 +4497,7 @@ private: } }; - buffered_sink *m_sink; // borrowed + sarif_buffered_sink *m_sink; // borrowed }; /* Test making a sarif_location for a complex rich_location diff --git a/gcc/diagnostics/sarif-sink.h b/gcc/diagnostics/sarif-sink.h index 9f8a73f..e6f897b 100644 --- a/gcc/diagnostics/sarif-sink.h +++ b/gcc/diagnostics/sarif-sink.h @@ -73,6 +73,7 @@ public: virtual ~sarif_serialization_format () {} virtual void write_to_file (FILE *outf, const json::value &top) = 0; + virtual void dump (FILE *out, int indent) const = 0; }; /* Concrete subclass for serializing SARIF as JSON. */ @@ -85,6 +86,7 @@ public: { } void write_to_file (FILE *outf, const json::value &top) final override; + void dump (FILE *out, int indent) const final override; private: bool m_formatted; @@ -108,6 +110,8 @@ struct sarif_generation_options { sarif_generation_options (); + void dump (FILE *out, int indent) const; + enum sarif_version m_version; bool m_state_graph; }; diff --git a/gcc/diagnostics/sink.h b/gcc/diagnostics/sink.h index ac4e0fb64..24eb707 100644 --- a/gcc/diagnostics/sink.h +++ b/gcc/diagnostics/sink.h @@ -36,6 +36,9 @@ class sink public: virtual ~sink () {} + virtual text_sink *dyn_cast_text_sink () { return nullptr; } + + virtual void dump_kind (FILE *out) const = 0; virtual void dump (FILE *out, int indent) const; /* Vfunc for notifying this format what the primary input file is, diff --git a/gcc/diagnostics/source-printing.cc b/gcc/diagnostics/source-printing.cc index 94b1c2d..aeda9ad 100644 --- a/gcc/diagnostics/source-printing.cc +++ b/gcc/diagnostics/source-printing.cc @@ -4412,7 +4412,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_) for (int tabstop = 1; tabstop != num_tabstops; ++tabstop) { test_context dc; - dc.m_tabstop = tabstop; + dc.get_column_options ().m_tabstop = tabstop; diagnostics::source_print_policy policy (dc); layout test_layout (policy, richloc, nullptr); colorizer col (*dc.get_reference_printer (), @@ -4436,7 +4436,7 @@ test_layout_x_offset_display_tab (const line_table_case &case_) for (int tabstop = 1; tabstop != num_tabstops; ++tabstop) { test_context dc; - dc.m_tabstop = tabstop; + dc.get_column_options ().m_tabstop = tabstop; static const int small_width = 24; auto &source_printing_opts = dc.get_source_printing_options (); source_printing_opts.max_width = small_width - 4; @@ -6833,7 +6833,7 @@ test_tab_expansion (const line_table_case &case_) everything too. */ { test_context dc; - dc.m_tabstop = tabstop; + dc.get_column_options ().m_tabstop = tabstop; rich_location richloc (line_table, linemap_position_for_column (line_table, first_non_ws_byte_col)); @@ -6846,7 +6846,7 @@ test_tab_expansion (const line_table_case &case_) as well. */ { test_context dc; - dc.m_tabstop = tabstop; + dc.get_column_options ().m_tabstop = tabstop; rich_location richloc (line_table, linemap_position_for_column (line_table, right_quote_byte_col)); diff --git a/gcc/diagnostics/text-sink.cc b/gcc/diagnostics/text-sink.cc index bcf91cf..48b369c 100644 --- a/gcc/diagnostics/text-sink.cc +++ b/gcc/diagnostics/text-sink.cc @@ -33,6 +33,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostics/diagram.h" #include "diagnostics/text-sink.h" #include "diagnostics/buffering.h" +#include "diagnostics/dumping.h" #include "text-art/theme.h" /* Disable warnings about quoting issues in the pp_xxx calls below @@ -76,7 +77,7 @@ text_sink_buffer::text_sink_buffer (sink &sink_) void text_sink_buffer::dump (FILE *out, int indent) const { - fprintf (out, "%*stext_sink_buffer:\n", indent, ""); + dumping::emit_heading (out, indent, "text_sink_buffer"); m_output_buffer.dump (out, indent + 2); } @@ -156,18 +157,19 @@ text_sink::~text_sink () } void -text_sink::dump (FILE *out, int indent) const -{ - fprintf (out, "%*stext_sink\n", indent, ""); - fprintf (out, "%*sm_follows_reference_printer: %s\n", - indent, "", - m_follows_reference_printer ? "true" : "false"); - sink::dump (out, indent); - fprintf (out, "%*ssaved_output_buffer:\n", indent + 2, ""); +text_sink::dump (FILE *outfile, int indent) const +{ + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_follows_reference_printer); + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_nesting); + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_locations_in_nesting); + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_nesting_levels); + + sink::dump (outfile, indent); + dumping::emit_heading (outfile, indent, "saved_output_buffer"); if (m_saved_output_buffer) - m_saved_output_buffer->dump (out, indent + 4); + m_saved_output_buffer->dump (outfile, indent + 2); else - fprintf (out, "%*s(none):\n", indent + 4, ""); + dumping::emit_none (outfile, indent + 2); } void @@ -612,7 +614,7 @@ text_sink::get_location_text (const expanded_location &s) const The result is a statically allocated buffer. */ const char * -maybe_line_and_column (int line, int col) +text_sink::maybe_line_and_column (int line, int col) { static char result[32]; diff --git a/gcc/diagnostics/text-sink.h b/gcc/diagnostics/text-sink.h index 5c60976..f280e72 100644 --- a/gcc/diagnostics/text-sink.h +++ b/gcc/diagnostics/text-sink.h @@ -51,6 +51,12 @@ public: {} ~text_sink (); + text_sink *dyn_cast_text_sink () final override { return this; } + + void dump_kind (FILE *out) const override + { + fprintf (out, "text_sink"); + } void dump (FILE *out, int indent) const override; std::unique_ptr<per_sink_buffer> @@ -127,6 +133,8 @@ public: return m_source_printing; } + static const char *maybe_line_and_column (int line, int col); + protected: void print_any_cwe (const diagnostic_info &diagnostic); void print_any_rules (const diagnostic_info &diagnostic); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 33ae98c..28466c4 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -322,6 +322,9 @@ Objective-C and Objective-C++ Dialects}. -fno-diagnostics-show-cwe -fno-diagnostics-show-rules -fno-diagnostics-show-highlight-colors +-fno-diagnostics-show-nesting +-fno-diagnostics-show-nesting-locations +-fdiagnostics-show-nesting-levels -fdiagnostics-minimum-margin-width=@var{width} -fdiagnostics-parseable-fixits -fdiagnostics-generate-patch -fdiagnostics-show-template-tree -fno-elide-type @@ -5429,7 +5432,8 @@ options: -fdiagnostics-urls=never -fdiagnostics-path-format=separate-events -fdiagnostics-text-art-charset=none --fno-diagnostics-show-event-links} +-fno-diagnostics-show-event-links +-fno-diagnostics-show-nesting} In the future, if GCC changes the default appearance of its diagnostics, the corresponding option to disable the new behavior will be added to this list. @@ -6051,6 +6055,40 @@ emoji variant of the character). The default is @samp{emoji}, except when the environment variable @env{LANG} is set to @samp{C}, in which case the default is @samp{ascii}. +@opindex fno-diagnostics-show-nesting +@opindex fdiagnostics-show-nesting +@item -fno-diagnostics-show-nesting +Some GCC diagnostics have an internal tree-like structure of nested +sub-diagnostics, such as for problems when instantiating C++ templates. + +By default GCC uses indentation and bullet points in its text output to +show the nesting structure of these diagnostics, moves location +information to separate lines to make the structure clearer, and +eliminates redundant repeated information. + +Selecting @option{-fno-diagnostics-show-nesting} suppresses this +indentation, reformatting, and elision, restoring an older `look'' for the +diagnostics. + +@opindex fno-diagnostics-show-nesting-locations +@opindex fdiagnostics-show-nesting-locations +@item -fno-diagnostics-show-nesting-locations + +When @option{fdiagnostics-show-nesting} is enabled, file names and +line- and column- numbers are displayed on separate lines from the +messages. This location information can be disabled altogether with +@option{-fno-diagnostics-show-nesting-locations}. +This option exists for use by GCC developers, for writing DejaGnu test cases. + +@opindex fdiagnostics-show-nesting-levels +@opindex fno-diagnostics-show-nesting-levels +@item -fdiagnostics-show-nesting-levels +When @option{fdiagnostics-show-nesting} is enabled, use +@option{fdiagnostics-show-nesting-levels} to also display numbers +showing the depth of the nesting. +This option exists for use by GCC developers for debugging nested +diagnostics, but may be of use to plugin authors. + @opindex fdiagnostics-format @item -fdiagnostics-format=@var{FORMAT} Select a different format for printing diagnostics. @@ -6099,18 +6137,18 @@ Supported keys are: Override colorization settings from @option{-fdiagnostics-color} for this text output. -@item experimental-nesting=@r{[}yes@r{|}no@r{]} -Enable an experimental mode that emphasizes hierarchical relationships -within diagnostics messages, displaying location information on separate -lines. +@item show-nesting=@r{[}yes@r{|}no@r{]} +Enable a mode that emphasizes hierarchical relationships +within diagnostics messages, as per @option{-fdiagnostics-show-nesting}. +Defaults to @code{yes}. -@item experimental-nesting-show-locations=@r{[}yes@r{|}no@r{]} -If @code{experimental-nesting=yes}, then by default locations are +@item show-nesting-locations=@r{[}yes@r{|}no@r{]} +If @code{show-nesting=yes}, then by default locations are shown; set this key to @code{no} to disable printing such locations. This exists for use by GCC developers, for writing DejaGnu test cases. -@item experimental-nesting-show-levels=@r{[}yes@r{|}no@r{]} -This is a debugging option for use with @code{experimental-nesting=yes}. +@item show-nesting-levels=@r{[}yes@r{|}no@r{]} +This is a debugging option for use with @code{show-nesting=yes}. Set this key to @code{yes} to print explicit nesting levels in the output. This exists for use by GCC developers. diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 4d4e676..4c338c3 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -37,6 +37,8 @@ through the macros defined in the @file{.h} file. * Trampolines:: Code set up at run time to enter a nested function. * Library Calls:: Controlling how library routines are implicitly called. * Addressing Modes:: Defining addressing modes valid for memory operands. +* Vectorization:: Controlling how the vectorizer operates. +* OpenMP and OpenACC:: Defining how OpenMP and OpenACC features should work. * Anchored Addresses:: Defining how @option{-fsection-anchors} should work. * Condition Code:: Defining how insns update the condition code. * Costs:: Defining relative costs of different operations. @@ -6282,6 +6284,10 @@ reciprocal of the machine-specific builtin function @var{fndecl}, or @code{NULL_TREE} if such a function is not available. @end deftypefn +@node Vectorization +@section Vectorization +@cindex Vectorization + @deftypefn {Target Hook} tree TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD (void) This hook should return the DECL of a function @var{f} that given an address @var{addr} as an argument returns a mask @var{m} that can be @@ -6522,6 +6528,10 @@ number of scalar elements in each scalar loop iteration that are to be combined into the vector. @end deftypefn +@node OpenMP and OpenACC +@section OpenMP and OpenACC +@cindex OpenMP and OpenACC + @deftypefn {Target Hook} int TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN (struct cgraph_node *@var{}, struct cgraph_simd_clone *@var{}, @var{tree}, @var{int}, @var{bool}) This hook should set @var{vecsize_mangle}, @var{vecsize_int}, @var{vecsize_float} fields in @var{simd_clone} structure pointed by @var{clone_info} argument and also diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 1a51ad5..12b8ed6 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -37,6 +37,8 @@ through the macros defined in the @file{.h} file. * Trampolines:: Code set up at run time to enter a nested function. * Library Calls:: Controlling how library routines are implicitly called. * Addressing Modes:: Defining addressing modes valid for memory operands. +* Vectorization:: Controlling how the vectorizer operates. +* OpenMP and OpenACC:: Defining how OpenMP and OpenACC features should work. * Anchored Addresses:: Defining how @option{-fsection-anchors} should work. * Condition Code:: Defining how insns update the condition code. * Costs:: Defining relative costs of different operations. @@ -4273,6 +4275,10 @@ address; but often a machine-dependent strategy can generate better code. @hook TARGET_BUILTIN_RECIPROCAL +@node Vectorization +@section Vectorization +@cindex Vectorization + @hook TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD @hook TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST @@ -4313,6 +4319,10 @@ address; but often a machine-dependent strategy can generate better code. @hook TARGET_VECTORIZE_PREFER_GATHER_SCATTER +@node OpenMP and OpenACC +@section OpenMP and OpenACC +@cindex OpenMP and OpenACC + @hook TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN @hook TARGET_SIMD_CLONE_ADJUST diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 20e4a76..c203356 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,18 @@ +2025-08-09 Paul Thomas <pault@gcc.gnu.org> + + PR fortran/121182 + * decl.cc (match_generic_stmt): New function based on original + gfc_match_generic but feeding namespace rather than typebound + generics. + (match_typebound_generic): Renamed original gfc_match_generic. + (gfc_match_generic): New function that selects between type + bound generic and other generic statements and calls one of the + above two functions as appropriate. + * parse.cc (decode_specification_statement): Allow generic + statements. + (parse_spec): Accept a generic statement in a specification + block. + 2025-08-05 Mikael Morin <morin-mikael@orange.fr> * trans-stmt.cc (trans_associate_var): Remove overwrite of @@ -285,7 +300,7 @@ 2025-07-11 Paul Thomas <pault@gcc.gnu.org> - PR fortran/106135 + PR fortran/106035 * decl.cc (build_sym): Emit an error if a symbol associated by an IMPORT, ONLY or IMPORT, all statement is being redeclared. (gfc_match_import): Parse and check the F2018 versions of the diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index af42575..5146731 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -11710,10 +11710,308 @@ syntax: } +/* Match a GENERIC statement. +F2018 15.4.3.3 GENERIC statement + +A GENERIC statement specifies a generic identifier for one or more specific +procedures, in the same way as a generic interface block that does not contain +interface bodies. + +R1510 generic-stmt is: +GENERIC [ , access-spec ] :: generic-spec => specific-procedure-list + +C1510 (R1510) A specific-procedure in a GENERIC statement shall not specify a +procedure that was specified previously in any accessible interface with the +same generic identifier. + +If access-spec appears, it specifies the accessibility (8.5.2) of generic-spec. + +For GENERIC statements outside of a derived type, use is made of the existing, +typebound matching functions to obtain access-spec and generic-spec. After +this the standard INTERFACE machinery is used. */ + +static match +match_generic_stmt (void) +{ + char name[GFC_MAX_SYMBOL_LEN + 1]; + /* Allow space for OPERATOR(...). */ + char generic_spec_name[GFC_MAX_SYMBOL_LEN + 16]; + /* Generics other than uops */ + gfc_symbol* generic_spec = NULL; + /* Generic uops */ + gfc_user_op *generic_uop = NULL; + /* For the matching calls */ + gfc_typebound_proc tbattr; + gfc_namespace* ns = gfc_current_ns; + interface_type op_type; + gfc_intrinsic_op op; + match m; + gfc_symtree* st; + /* The specific-procedure-list */ + gfc_interface *generic = NULL; + /* The head of the specific-procedure-list */ + gfc_interface **generic_tail = NULL; + + memset (&tbattr, 0, sizeof (tbattr)); + tbattr.where = gfc_current_locus; + + /* See if we get an access-specifier. */ + m = match_binding_attributes (&tbattr, true, false); + tbattr.where = gfc_current_locus; + if (m == MATCH_ERROR) + goto error; + + /* Now the colons, those are required. */ + if (gfc_match (" ::") != MATCH_YES) + { + gfc_error ("Expected %<::%> at %C"); + goto error; + } + + /* Match the generic-spec name; depending on type (operator / generic) format + it for future error messages in 'generic_spec_name'. */ + m = gfc_match_generic_spec (&op_type, name, &op); + if (m == MATCH_ERROR) + return MATCH_ERROR; + if (m == MATCH_NO) + { + gfc_error ("Expected generic name or operator descriptor at %C"); + goto error; + } + + switch (op_type) + { + case INTERFACE_GENERIC: + case INTERFACE_DTIO: + snprintf (generic_spec_name, sizeof (generic_spec_name), "%s", name); + break; + + case INTERFACE_USER_OP: + snprintf (generic_spec_name, sizeof (generic_spec_name), "OPERATOR(.%s.)", name); + break; + + case INTERFACE_INTRINSIC_OP: + snprintf (generic_spec_name, sizeof (generic_spec_name), "OPERATOR(%s)", + gfc_op2string (op)); + break; + + case INTERFACE_NAMELESS: + gfc_error ("Malformed GENERIC statement at %C"); + goto error; + break; + + default: + gcc_unreachable (); + } + + /* Match the required =>. */ + if (gfc_match (" =>") != MATCH_YES) + { + gfc_error ("Expected %<=>%> at %C"); + goto error; + } + + + if (gfc_current_state () != COMP_MODULE && tbattr.access != ACCESS_UNKNOWN) + { + gfc_error ("The access specification at %L not in a module", + &tbattr.where); + goto error; + } + + /* Try to find existing generic-spec with this name for this operator; + if there is something, check that it is another generic-spec and then + extend it rather than building a new symbol. Otherwise, create a new + one with the right attributes. */ + + switch (op_type) + { + case INTERFACE_DTIO: + case INTERFACE_GENERIC: + st = gfc_find_symtree (ns->sym_root, name); + generic_spec = st ? st->n.sym : NULL; + if (generic_spec) + { + if (generic_spec->attr.flavor != FL_PROCEDURE + && generic_spec->attr.flavor != FL_UNKNOWN) + { + gfc_error ("The generic-spec name %qs at %C clashes with the " + "name of an entity declared at %L that is not a " + "procedure", name, &generic_spec->declared_at); + goto error; + } + + if (op_type == INTERFACE_GENERIC && !generic_spec->attr.generic + && generic_spec->attr.flavor != FL_UNKNOWN) + { + gfc_error ("There's already a non-generic procedure with " + "name %qs at %C", generic_spec->name); + goto error; + } + + if (tbattr.access != ACCESS_UNKNOWN) + { + if (generic_spec->attr.access != tbattr.access) + { + gfc_error ("The access specification at %L conflicts with " + "that already given to %qs", &tbattr.where, + generic_spec->name); + goto error; + } + else + { + gfc_error ("The access specification at %L repeats that " + "already given to %qs", &tbattr.where, + generic_spec->name); + goto error; + } + } + + if (generic_spec->ts.type != BT_UNKNOWN) + { + gfc_error ("The generic-spec in the generic statement at %C " + "has a type from the declaration at %L", + &generic_spec->declared_at); + goto error; + } + } + + /* Now create the generic_spec if it doesn't already exist and provide + is with the appropriate attributes. */ + if (!generic_spec || generic_spec->attr.flavor != FL_PROCEDURE) + { + if (!generic_spec) + { + gfc_get_symbol (name, ns, &generic_spec, &gfc_current_locus); + gfc_set_sym_referenced (generic_spec); + generic_spec->attr.access = tbattr.access; + } + else if (generic_spec->attr.access == ACCESS_UNKNOWN) + generic_spec->attr.access = tbattr.access; + generic_spec->refs++; + generic_spec->attr.generic = 1; + generic_spec->attr.flavor = FL_PROCEDURE; + + generic_spec->declared_at = gfc_current_locus; + } + + /* Prepare to add the specific procedures. */ + generic = generic_spec->generic; + generic_tail = &generic_spec->generic; + break; + + case INTERFACE_USER_OP: + st = gfc_find_symtree (ns->uop_root, name); + generic_uop = st ? st->n.uop : NULL; + if (generic_uop) + { + if (generic_uop->access != ACCESS_UNKNOWN + && tbattr.access != ACCESS_UNKNOWN) + { + if (generic_uop->access != tbattr.access) + { + gfc_error ("The user operator at %L must have the same " + "access specification as already defined user " + "operator %qs", &tbattr.where, generic_spec_name); + goto error; + } + else + { + gfc_error ("The user operator at %L repeats the access " + "specification of already defined user operator " "%qs", &tbattr.where, generic_spec_name); + goto error; + } + } + else if (generic_uop->access == ACCESS_UNKNOWN) + generic_uop->access = tbattr.access; + } + else + { + generic_uop = gfc_get_uop (name); + generic_uop->access = tbattr.access; + } + + /* Prepare to add the specific procedures. */ + generic = generic_uop->op; + generic_tail = &generic_uop->op; + break; + + case INTERFACE_INTRINSIC_OP: + generic = ns->op[op]; + generic_tail = &ns->op[op]; + break; + + default: + gcc_unreachable (); + } + + /* Now, match all following names in the specific-procedure-list. */ + do + { + m = gfc_match_name (name); + if (m == MATCH_ERROR) + goto error; + if (m == MATCH_NO) + { + gfc_error ("Expected specific procedure name at %C"); + goto error; + } + + if (op_type == INTERFACE_GENERIC + && !strcmp (generic_spec->name, name)) + { + gfc_error ("The name %qs of the specific procedure at %C conflicts " + "with that of the generic-spec", name); + goto error; + } + + generic = *generic_tail; + for (; generic; generic = generic->next) + { + if (!strcmp (generic->sym->name, name)) + { + gfc_error ("%qs already defined as a specific procedure for the" + " generic %qs at %C", name, generic_spec->name); + goto error; + } + } + + gfc_find_sym_tree (name, ns, 1, &st); + if (!st) + { + /* This might be a procedure that has not yet been parsed. If + so gfc_fixup_sibling_symbols will replace this symbol with + that of the procedure. */ + gfc_get_sym_tree (name, ns, &st, false); + st->n.sym->refs++; + } + + generic = gfc_get_interface(); + generic->next = *generic_tail; + *generic_tail = generic; + generic->where = gfc_current_locus; + generic->sym = st->n.sym; + } + while (gfc_match (" ,") == MATCH_YES); + + if (gfc_match_eos () != MATCH_YES) + { + gfc_error ("Junk after GENERIC statement at %C"); + goto error; + } + + gfc_commit_symbols (); + return MATCH_YES; + +error: + return MATCH_ERROR; +} + + /* Match a GENERIC procedure binding inside a derived type. */ -match -gfc_match_generic (void) +static match +match_typebound_generic (void) { char name[GFC_MAX_SYMBOL_LEN + 1]; char bind_name[GFC_MAX_SYMBOL_LEN + 16]; /* Allow space for OPERATOR(...). */ @@ -11923,6 +12221,17 @@ error: } +match +gfc_match_generic () +{ + if (gfc_option.allow_std & ~GFC_STD_OPT_F08 + && gfc_current_state () != COMP_DERIVED_CONTAINS) + return match_generic_stmt (); + else + return match_typebound_generic (); +} + + /* Match a FINAL declaration inside a derived type. */ match diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index 847ff37..300a7a3 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -242,6 +242,7 @@ decode_specification_statement (void) break; case 'g': + match ("generic", gfc_match_generic, ST_GENERIC); break; case 'i': @@ -4534,6 +4535,11 @@ declSt: st = next_statement (); goto loop; + case ST_GENERIC: + accept_statement (st); + st = next_statement (); + goto loop; + case ST_ENUM: accept_statement (st); parse_enum(); diff --git a/gcc/libgdiagnostics.cc b/gcc/libgdiagnostics.cc index 784e281..d87dd46 100644 --- a/gcc/libgdiagnostics.cc +++ b/gcc/libgdiagnostics.cc @@ -1939,7 +1939,8 @@ diagnostic_manager_debug_dump_file (diagnostic_manager *, fprintf (out, ", sarif_source_language=\"%s\"", file->get_sarif_source_language ()); if (const content_buffer *buf = file->get_content ()) - fprintf (out, ", content=(size=%zi)", buf->m_sz); + fprintf (out, ", content=(size=" HOST_SIZE_T_PRINT_DEC ")", + buf->m_sz); fprintf (out, ")"); } else diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc index 03fca97..dbe3ad0 100644 --- a/gcc/lto-wrapper.cc +++ b/gcc/lto-wrapper.cc @@ -320,6 +320,9 @@ merge_and_complain (vec<cl_decoded_option> &decoded_options, case OPT_fdiagnostics_show_line_numbers: case OPT_fdiagnostics_show_option: case OPT_fdiagnostics_show_location_: + case OPT_fdiagnostics_show_nesting: + case OPT_fdiagnostics_show_nesting_locations: + case OPT_fdiagnostics_show_nesting_levels: case OPT_fshow_column: case OPT_fcommon: case OPT_fgnu_tm: @@ -739,6 +742,9 @@ append_compiler_options (obstack *argv_obstack, vec<cl_decoded_option> opts) case OPT_fdiagnostics_show_line_numbers: case OPT_fdiagnostics_show_option: case OPT_fdiagnostics_show_location_: + case OPT_fdiagnostics_show_nesting: + case OPT_fdiagnostics_show_nesting_locations: + case OPT_fdiagnostics_show_nesting_levels: case OPT_fshow_column: case OPT_fPIC: case OPT_fpic: @@ -801,6 +807,9 @@ append_diag_options (obstack *argv_obstack, vec<cl_decoded_option> opts) case OPT_fdiagnostics_show_line_numbers: case OPT_fdiagnostics_show_option: case OPT_fdiagnostics_show_location_: + case OPT_fdiagnostics_show_nesting: + case OPT_fdiagnostics_show_nesting_locations: + case OPT_fdiagnostics_show_nesting_levels: case OPT_fshow_column: break; default: diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc index e6d7f4d..379402e 100644 --- a/gcc/opts-common.cc +++ b/gcc/opts-common.cc @@ -1096,7 +1096,8 @@ decode_cmdline_options_to_array (unsigned int argc, const char **argv, "-fdiagnostics-urls=never", "-fdiagnostics-path-format=separate-events", "-fdiagnostics-text-art-charset=none", - "-fno-diagnostics-show-event-links" + "-fno-diagnostics-show-event-links", + "-fno-diagnostics-show-nesting" /* We don't put "-fno-diagnostics-show-highlight-colors" here as -fdiagnostics-color=never makes it redundant. */ }; diff --git a/gcc/opts.cc b/gcc/opts.cc index b6d25bf..a02d017 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -3016,11 +3016,12 @@ common_handle_option (struct gcc_options *opts, break; case OPT_fdiagnostics_column_unit_: - dc->m_column_unit = (enum diagnostics_column_unit)value; + dc->get_column_options ().m_column_unit + = (enum diagnostics_column_unit)value; break; case OPT_fdiagnostics_column_origin_: - dc->m_column_origin = value; + dc->get_column_options ().m_column_origin = value; break; case OPT_fdiagnostics_escape_format_: @@ -3051,6 +3052,18 @@ common_handle_option (struct gcc_options *opts, dc->set_show_option_requested (value); break; + case OPT_fdiagnostics_show_nesting: + dc->set_show_nesting (value); + break; + + case OPT_fdiagnostics_show_nesting_locations: + dc->set_show_nesting_locations (value); + break; + + case OPT_fdiagnostics_show_nesting_levels: + dc->set_show_nesting_levels (value); + break; + case OPT_fdiagnostics_minimum_margin_width_: dc->get_source_printing_options ().min_margin_width = value; break; @@ -3408,7 +3421,7 @@ common_handle_option (struct gcc_options *opts, case OPT_ftabstop_: /* It is documented that we silently ignore silly values. */ if (value >= 1 && value <= 100) - dc->m_tabstop = value; + dc->get_column_options ().m_tabstop = value; break; case OPT_freport_bug: @@ -3879,6 +3892,9 @@ gen_command_line_string (cl_decoded_option *options, case OPT_fdiagnostics_show_line_numbers: case OPT_fdiagnostics_color_: case OPT_fdiagnostics_format_: + case OPT_fdiagnostics_show_nesting: + case OPT_fdiagnostics_show_nesting_locations: + case OPT_fdiagnostics_show_nesting_levels: case OPT_fverbose_asm: case OPT____: case OPT__sysroot_: diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc index 77d40ec..d79a828 100644 --- a/gcc/pretty-print.cc +++ b/gcc/pretty-print.cc @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "pretty-print-urlifier.h" #include "diagnostics/color.h" #include "diagnostics/event-id.h" +#include "diagnostics/dumping.h" #include "diagnostic-highlight-colors.h" #include "auto-obstack.h" #include "selftest.h" @@ -1600,9 +1601,8 @@ pp_formatted_chunks::dump (FILE *out, int indent) const { for (size_t idx = 0; m_args[idx]; ++idx) { - fprintf (out, "%*s%i: ", - indent, "", - (int)idx); + diagnostics::dumping::emit_indent (out, indent); + fprintf (out, "%i: ", (int)idx); m_args[idx]->dump (out); } } @@ -3100,34 +3100,39 @@ pretty_printer::end_url () pp_string (this, get_end_url_string (this)); } -/* Dump state of this pretty_printer to OUT, for debugging. */ - -void -pretty_printer::dump (FILE *out, int indent) const +static const char * +get_url_format_as_string (diagnostic_url_format url_format) { - fprintf (out, "%*sm_show_color: %s\n", - indent, "", - m_show_color ? "true" : "false"); - - fprintf (out, "%*sm_url_format: ", indent, ""); - switch (m_url_format) + switch (url_format) { case URL_FORMAT_NONE: - fprintf (out, "none"); - break; + return "none"; case URL_FORMAT_ST: - fprintf (out, "st"); - break; + return "st"; case URL_FORMAT_BEL: - fprintf (out, "bel"); - break; + return "bel"; default: gcc_unreachable (); } - fprintf (out, "\n"); +} + +/* Dump state of this pretty_printer to OUT, for debugging. */ - fprintf (out, "%*sm_buffer:\n", indent, ""); - m_buffer->dump (out, indent + 2); +void +pretty_printer::dump (FILE *outfile, int indent) const +{ + namespace dumping = diagnostics::dumping; + + DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_color); + dumping::emit_string_field + (outfile, indent, + "m_url_format", + get_url_format_as_string (m_url_format)); + dumping::emit_heading (outfile, indent, "m_buffer"); + if (m_buffer) + m_buffer->dump (outfile, indent + 2); + else + dumping::emit_none (outfile, indent + 2); } /* class pp_markup::context. */ diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc index c723a07..ee9c048 100644 --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -8460,14 +8460,10 @@ simplify_context::simplify_gen_subreg (machine_mode outermode, rtx op, if (GET_CODE (op) == SUBREG || GET_CODE (op) == CONCAT - || GET_MODE (op) == VOIDmode) - return NULL_RTX; - - if (MODE_COMPOSITE_P (outermode) - && (CONST_SCALAR_INT_P (op) - || CONST_DOUBLE_AS_FLOAT_P (op) - || CONST_FIXED_P (op) - || GET_CODE (op) == CONST_VECTOR)) + || CONST_SCALAR_INT_P (op) + || CONST_DOUBLE_AS_FLOAT_P (op) + || CONST_FIXED_P (op) + || GET_CODE (op) == CONST_VECTOR) return NULL_RTX; if (validate_subreg (outermode, innermode, op, byte)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index df2c843..b3ddaf1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,185 @@ +2025-08-09 H.J. Lu <hjl.tools@gmail.com> + + PR testsuite/121205 + * gcc.target/i386/asm-hard-reg-2.c (z): Use long long for -m32 + to trigger RA error. + +2025-08-09 Dimitar Dimitrov <dimitar@dinux.eu> + + * g++.dg/modules/class-11_a.H: Skip test for effective + default_packed targets. + * g++.dg/modules/class-11_b.C: Ditto. + +2025-08-09 Paul Thomas <pault@gcc.gnu.org> + + PR fortran/121182 + * gfortran.dg/generic_stmt_1.f90: New test. + * gfortran.dg/generic_stmt_2.f90: New test. + * gfortran.dg/generic_stmt_3.f90: New test. + * gfortran.dg/generic_stmt_4.f90: New test. + +2025-08-09 Dimitar Dimitrov <dimitar@dinux.eu> + + * gcc.dg/torture/hardbool-ai.c: Require target that supports + atomic operations on int types. + +2025-08-08 Andrew Pinski <quic_apinski@quicinc.com> + + PR tree-optimization/120599 + * g++.dg/torture/noncall-eh-1.C: New test. + +2025-08-08 Andrew Pinski <quic_apinski@quicinc.com> + + PR tree-optimization/118946 + PR tree-optimization/121422 + * gcc.dg/pr118946-1.c: New test. + * gcc.dg/torture/pr121422-1.c: New test. + * gcc.dg/torture/pr121422-2.c: New test. + +2025-08-08 David Malcolm <dmalcolm@redhat.com> + + PR diagnostics/116253 + * g++.dg/concepts/nested-diagnostics-1-truncated.C: Update for + renamed keys to -fdiagnostics-set-output=text + * g++.dg/concepts/nested-diagnostics-1.C: Likewise. + * g++.dg/concepts/nested-diagnostics-2.C: Likewise. + * gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c: New + test. + * gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c: New test. + * gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c: + Update for renamed keys to -fdiagnostics-set-output=text. + * gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c: + Likewise. + * gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: Likewise. + * gcc.dg/plugin/plugin.exp: Add the new tests. + +2025-08-08 Christophe Lyon <christophe.lyon@linaro.org> + + PR target/120977 + * gcc.target/arm/cmse/cmse-18.c: Check only the case when FPCXT is + not enabled. + * gcc.target/arm/cmse/cmse-19.c: New test. + +2025-08-08 Pengfei Li <Pengfei.Li2@arm.com> + + PR target/121449 + * g++.target/aarch64/sve/pr121449.C: New test. + +2025-08-08 Alex Coplan <alex.coplan@arm.com> + + PR target/120986 + * gcc.target/aarch64/torture/pr120986-2.c: New test. + +2025-08-08 Alex Coplan <alex.coplan@arm.com> + + PR target/120986 + * gcc.target/aarch64/pr120986-1.c: New test. + +2025-08-08 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/121389 + * c-c++-common/asan/pr121389-1.c: New test. + * c-c++-common/asan/pr121389-2.c: New test. + * c-c++-common/asan/pr121389-3.c: New test. + * c-c++-common/asan/pr121389-4.c: New test. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR c++/117783 + * g++.dg/cpp26/decomp13.C: New test. + * g++.dg/cpp26/decomp14.C: New test. + * g++.dg/cpp26/decomp15.C: New test. + * g++.dg/cpp26/decomp16.C: New test. + * g++.dg/cpp26/decomp17.C: New test. + * g++.dg/cpp26/decomp18.C: New test. + * g++.dg/cpp26/decomp19.C: New test. + * g++.dg/cpp26/decomp20.C: New test. + * g++.dg/cpp26/decomp21.C: New test. + * g++.dg/cpp26/feat-cxx26.C (__cpp_structured_bindings): Expect + 202411 rather than 202403. + +2025-08-07 Richard Sandiford <richard.sandiford@arm.com> + + PR target/121414 + * gcc.target/aarch64/sme/pr121414_1.c: New test. + +2025-08-07 Richard Sandiford <richard.sandiford@arm.com> + + PR rtl-optimization/120718 + * gcc.target/aarch64/sve/acle/general/pr120718.c: New test. + +2025-08-07 Richard Biener <rguenther@suse.de> + + PR tree-optimization/121405 + * gcc.dg/tree-ssa/ssa-fre-107.c: New testcase. + * gcc.target/i386/pr90579.c: Adjust. + +2025-08-07 Pengfei Li <Pengfei.Li2@arm.com> + + * gcc.target/aarch64/sve/peel_ind_11.c: New test. + * gcc.target/aarch64/sve/peel_ind_11_run.c: New test. + * gcc.target/aarch64/sve/peel_ind_12.c: New test. + * gcc.target/aarch64/sve/peel_ind_12_run.c: New test. + * gcc.target/aarch64/sve/peel_ind_13.c: New test. + * gcc.target/aarch64/sve/peel_ind_13_run.c: New test. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * g++.dg/DRs/dr2577-1.C: New test. + * g++.dg/DRs/dr2577-2.C: New test. + * g++.dg/DRs/dr2577-2.h: New file. + * g++.dg/DRs/dr2577-3.C: New test. + * g++.dg/DRs/dr2577-3.h: New file. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * g++.dg/DRs/dr2575.C: New test. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * g++.dg/DRs/dr2576.C: New test. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * gcc.dg/Wkeyword-macro-1.c: New test. + * gcc.dg/Wkeyword-macro-2.c: New test. + * gcc.dg/Wkeyword-macro-3.c: New test. + * gcc.dg/Wkeyword-macro-4.c: New test. + * gcc.dg/Wkeyword-macro-5.c: New test. + * gcc.dg/Wkeyword-macro-6.c: New test. + * gcc.dg/Wkeyword-macro-7.c: New test. + * gcc.dg/Wkeyword-macro-8.c: New test. + * gcc.dg/Wkeyword-macro-9.c: New test. + * g++.dg/warn/Wkeyword-macro-1.C: New test. + * g++.dg/warn/Wkeyword-macro-2.C: New test. + * g++.dg/warn/Wkeyword-macro-3.C: New test. + * g++.dg/warn/Wkeyword-macro-4.C: New test. + * g++.dg/warn/Wkeyword-macro-5.C: New test. + * g++.dg/warn/Wkeyword-macro-6.C: New test. + * g++.dg/warn/Wkeyword-macro-7.C: New test. + * g++.dg/warn/Wkeyword-macro-8.C: New test. + * g++.dg/warn/Wkeyword-macro-9.C: New test. + * g++.dg/warn/Wkeyword-macro-10.C: New test. + * g++.dg/opt/pr82577.C: Don't #define register to nothing for + C++17 and later. Instead define reg macro to nothing for C++17 + and later or to register and use it instead of register. + * g++.dg/modules/atom-preamble-3.C: Add -Wno-keyword-macro to + dg-additional-options. + * g++.dg/template/sfinae17.C (static_assert): Rename macro to ... + (my_static_assert): ... this. + (main): Use my_static_assert instead of static_assert. + +2025-08-07 Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org> + + * gcc.target/s390/bitint-1.c: New test. + * gcc.target/s390/bitint-2.c: New test. + * gcc.target/s390/bitint-3.c: New test. + * gcc.target/s390/bitint-4.c: New test. + 2025-08-06 Sam James <sam@gentoo.org> * g++.dg/cpp26/constexpr-new3.C: Escape '[' and ']'. @@ -2820,7 +3002,7 @@ 2025-07-11 Paul Thomas <pault@gcc.gnu.org> - PR fortran/106135 + PR fortran/106035 * gfortran.dg/import3.f90: Use -std=f2008 and comment on change in error message texts with f2018. * gfortran.dg/import12.f90: New test. diff --git a/gcc/testsuite/c-c++-common/asan/pr121389-1.c b/gcc/testsuite/c-c++-common/asan/pr121389-1.c new file mode 100644 index 0000000..0116d7a --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr121389-1.c @@ -0,0 +1,23 @@ +// PR middle-end/121389 +// { dg-do compile { target musttail } } +// { dg-options "-fsanitize=address" } + +int foo (void); +int bar (void); +int baz (unsigned *); + +int +bar (void) +{ + do + { + unsigned t; + int u = baz (&t); + if (u == 42) + [[gnu::musttail]] return foo (); + if (u == -42) + break; + } + while (1); + return 42; +} diff --git a/gcc/testsuite/c-c++-common/asan/pr121389-2.c b/gcc/testsuite/c-c++-common/asan/pr121389-2.c new file mode 100644 index 0000000..02914f8 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr121389-2.c @@ -0,0 +1,37 @@ +// PR middle-end/121389 +// { dg-do compile { target musttail } } +// { dg-options "-fsanitize=address" } + +int foo (void); +int bar (void); +int baz (unsigned *); + +int +bar (void) +{ + for (int a = 0; a < 420; ++a) + { + for (int b = 0; b < 420; ++b) + { + for (int c = 0; c < 420; ++c) + { + unsigned t; + int u = baz (&t); + if (u == 42) + [[gnu::musttail]] return foo (); + if (u == -42) + break; + if (u == 16) + goto l1; + if (u == 18) + goto l2; + if (u == 20) + goto l3; + } + l3:; + } + l2:; + } + l1:; + return 42; +} diff --git a/gcc/testsuite/c-c++-common/asan/pr121389-3.c b/gcc/testsuite/c-c++-common/asan/pr121389-3.c new file mode 100644 index 0000000..5f71e06 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr121389-3.c @@ -0,0 +1,130 @@ +// PR middle-end/121389 +// { dg-do compile { target musttail } } +// { dg-options "-fsanitize=address" } + +int foo (void); +int bar (void); +int baz (unsigned *); + +int +bar (void) +{ + for (int a = 0; a < 420; ++a) + { + for (int b = 0; b < 420; ++b) + { + for (int c = 0; c < 420; ++c) + { + unsigned t; + int u = baz (&t); + if (u == 42) + [[gnu::musttail]] return foo (); + if (u == -42) + break; + if (u == 16) + goto l1; + if (u == 18) + goto l2; + if (u == 20) + goto l3; + switch (u) + { + case 100: goto l100; + case 101: goto l101; + case 102: goto l102; + case 103: goto l103; + case 104: goto l104; + case 105: goto l105; + case 106: goto l106; + case 107: goto l107; + case 108: goto l108; + case 109: goto l109; + case 110: goto l110; + case 111: goto l111; + case 112: goto l112; + case 113: goto l113; + case 114: goto l114; + case 115: goto l115; + case 116: goto l116; + case 117: goto l117; + case 118: goto l118; + case 119: goto l119; + case 120: goto l120; + case 121: goto l121; + case 122: goto l122; + case 123: goto l123; + case 124: goto l124; + case 125: goto l125; + case 126: goto l126; + case 127: goto l127; + case 128: goto l128; + case 129: goto l129; + } + } + l3:; + foo (); + l100: + foo (); + l101: + foo (); + l102: + foo (); + l103: + foo (); + l104: + foo (); + l105: + foo (); + l106: + foo (); + l107: + foo (); + l108: + foo (); + l109:; + } + l2:; + foo (); + l110: + foo (); + l111: + foo (); + l112: + foo (); + l113: + foo (); + l114: + foo (); + l115: + foo (); + l116: + foo (); + l117: + foo (); + l118: + foo (); + l119:; + } + l1:; + foo (); + l120: + foo (); + l121: + foo (); + l122: + foo (); + l123: + foo (); + l124: + foo (); + l125: + foo (); + l126: + foo (); + l127: + foo (); + l128: + foo (); + l129:; + return 42; +} diff --git a/gcc/testsuite/c-c++-common/asan/pr121389-4.c b/gcc/testsuite/c-c++-common/asan/pr121389-4.c new file mode 100644 index 0000000..2f7b410 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr121389-4.c @@ -0,0 +1,6 @@ +// PR middle-end/121389 +// { dg-do compile { target musttail } } +// { dg-options "-fsanitize=address -fdisable-tree-switchlower_O0" } +// { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } + +#include "pr121389-3.c" diff --git a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C index 0cb1610..5b5e3fe 100644 --- a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C +++ b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C @@ -1,6 +1,6 @@ // { dg-do compile { target c++17 } } // { dg-options "-fconcepts" } -// { dg-additional-options "-fdiagnostics-set-output=text:experimental-nesting=yes,experimental-nesting-show-locations=no" } +// { dg-additional-options "-fdiagnostics-set-output=text:show-nesting=yes,show-nesting-locations=no" } struct dog {}; struct cat {}; diff --git a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C index e642676..a071b55 100644 --- a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C +++ b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C @@ -1,6 +1,6 @@ // { dg-do compile { target c++17 } } // { dg-options "-fconcepts" } -// { dg-additional-options "-fdiagnostics-set-output=text:experimental-nesting=yes,experimental-nesting-show-locations=no" } +// { dg-additional-options "-fdiagnostics-set-output=text:show-nesting=yes,show-nesting-locations=no" } // { dg-additional-options "-fconcepts-diagnostics-depth=3" } struct dog {}; diff --git a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C index cc15f11..9530bc1 100644 --- a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C +++ b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C @@ -1,6 +1,6 @@ // { dg-do compile { target c++17 } } // { dg-options "-fconcepts" } -// { dg-additional-options "-fdiagnostics-set-output=text:experimental-nesting=yes,experimental-nesting-show-locations=no" } +// { dg-additional-options "-fdiagnostics-set-output=text:show-nesting=yes,show-nesting-locations=no" } struct dog{}; struct cat{}; diff --git a/gcc/testsuite/g++.dg/cpp26/decomp13.C b/gcc/testsuite/g++.dg/cpp26/decomp13.C new file mode 100644 index 0000000..d01590f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp13.C @@ -0,0 +1,52 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do compile { target c++11 } } +// { dg-options "" } + +namespace std { + template<typename T> struct tuple_size; + template<int, typename> struct tuple_element; +} + +struct S { int a, b, c, d; }; +struct T { + int a[5]; + template <int I> int &get () { return a[I]; } +}; + +template<> struct std::tuple_size<T> { static const int value = 5; }; +template<int I> struct std::tuple_element<I,T> { using type = int; }; + +template <int N> +void +foo () +{ + auto [a, ...b, c] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + auto [...d] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + auto [...e, f, ...g, h] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "multiple packs in structured binding declaration" "" { target *-*-* } .-2 } + auto [i, j, k, l, ...m, n] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "6 names provided for structured binding" "" { target *-*-* } .-2 } + // { dg-message "while 'S' decomposes into 4 elements" "" { target *-*-* } .-3 } + auto [o, ...p, q, r, s] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + auto [t, u, v, w, x, ...y, z] = T (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "7 names provided for structured binding" "" { target *-*-* } .-2 } + // { dg-message "while 'T' decomposes into 5 elements" "" { target *-*-* } .-3 } + int aa[] = { 1, 2, 3 }; + const auto & [ab, ...ac, ad, ae, af] = aa; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "5 names provided for structured binding" "" { target *-*-* } .-2 } + // { dg-message "while 'const int \\\[3\\\]' decomposes into 3 elements" "" { target *-*-* } .-3 } +} + +void +bar () +{ + auto [a, ...b, c, d] = S (); // { dg-error "structured binding pack outside of template" } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp14.C b/gcc/testsuite/g++.dg/cpp26/decomp14.C new file mode 100644 index 0000000..f626ec9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp14.C @@ -0,0 +1,474 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +struct S { + int a; long long b; short c; + explicit operator bool () const noexcept { return true; } +}; +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +struct T { + short c; int a; long long b; + template <int I> + typename std::tuple_element<I, T>::type &get (); + template <int I> + typename std::tuple_element<I, const T>::type &get () const; + explicit operator bool () const noexcept { return false; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 3; }; +template <> +struct std::tuple_element<0, T> { typedef int type; }; +template <> +struct std::tuple_element<1, T> { typedef long long type; }; +template <> +struct std::tuple_element<2, T> { typedef short type; }; +template <> +std::tuple_element<0, T>::type &T::get <0> () { return a; } +template <> +std::tuple_element<1, T>::type &T::get <1> () { return b; } +template <> +std::tuple_element<2, T>::type &T::get <2> () { return c; } +template <> +struct std::tuple_size<const T> { static constexpr int value = 3; }; +template <> +struct std::tuple_element<0, const T> { typedef const int type; }; +template <> +struct std::tuple_element<1, const T> { typedef const long long type; }; +template <> +struct std::tuple_element<2, const T> { typedef const short type; }; +template <> +std::tuple_element<0, const T>::type &T::get <0> () const { return a; } +template <> +std::tuple_element<1, const T>::type &T::get <1> () const { return b; } +template <> +std::tuple_element<2, const T>::type &T::get <2> () const { return c; } +template <typename T, typename U> +struct same_type { static const bool value = false; }; +template <typename T> +struct same_type<T, T> { static const bool value = true; }; + +int +sum () +{ + return 0; +} + +template <typename T, typename ...A> +T +sum (T x, A... y) +{ + return x + sum (y...); +} + +template <typename T> +T +square (T x) +{ + return x * x; +} + +template <typename T> +T & +ref (T &x) +{ + return x; +} + +using size_t = decltype (sizeof 0); + +template <int N> +size_t +foo () +{ + S s = S { 1, 2, 3 }; + auto [sa, sb, sc] = S { 1, 2, 3 }; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (sa), int>::value, ""); + static_assert (same_type <decltype (sb), long long>::value, ""); + static_assert (same_type <decltype (sc), short>::value, ""); + auto [sd, ...se] = S { 1, 2, 3 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + constexpr size_t ses = sizeof... (se); + static_assert (sizeof... (se) == 2, ""); + static_assert (same_type <decltype (sd), int>::value, ""); + static_assert (same_type <decltype (se...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (se...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + const auto & [...sf [[]], sg] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sf) == 2, ""); + static_assert (same_type <decltype (sf...[0]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sf...[1]), const long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sg), const short>::value, ""); + auto [sh, si, sj [[]], ...sk] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sk) == 0, ""); + static_assert (same_type <decltype (sh), int>::value, ""); + static_assert (same_type <decltype (si), long long>::value, ""); + static_assert (same_type <decltype (sj), short>::value, ""); + auto && [sl, ...sm [[maybe_unused]], sn] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sm) == 1, ""); + static_assert (same_type <decltype (sl), int>::value, ""); + static_assert (same_type <decltype (sm...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sn), short>::value, ""); + auto [...so] = S { 1, 2, 3 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (so) == 3, ""); + static_assert (same_type <decltype (so...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (so...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (so...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...sp, sq, sr, ss [[maybe_unused]]] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sp) == 0, ""); + static_assert (same_type <decltype (sq), int>::value, ""); + static_assert (same_type <decltype (sr), long long>::value, ""); + static_assert (same_type <decltype (ss), short>::value, ""); + auto [st, ...su, sv, sw] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (su) == 0, ""); + static_assert (same_type <decltype (st), int>::value, ""); + static_assert (same_type <decltype (sv), long long>::value, ""); + static_assert (same_type <decltype (sw), short>::value, ""); + if (sa != 1 || sb != 2 || sc != 3 + || sd != 1 || se...[0] != 2 || se...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sf...[0] != 1 || sf...[1] != 2 || sg != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sh != 1 || si != 2 || sj != 3 + || sl != 1 || sm...[0] != 2 || sn != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || so...[0] != 1 || so...[1] != 2 || so...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sq != 1 || sr != 2 || ss != 3 + || st != 1 || sv != 2 || sw != 3 + || sum (se...) != 5 + || sum <decltype (se)...> (se...) != 5 + || sum (square (square (se))...) != 97 + || sum (sf...) != 3 + || sum (sk...) != 0 + || sum (sm...) != 2 + || sum (so...) != 6 + || sum <decltype (so)...> (so...) != 6 + || sum (square (so)...) != 14 + || sum (sp...) != 0 + || sum (su...) != 0 + || (se + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + sf) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + sk) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (sm + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (so + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (sp + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + su) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + S s2[] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; + int i = 0; + for (auto [sx, ...sy [[]]] : s2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sy) == 2, ""); + static_assert (same_type <decltype (sx), int>::value, ""); + static_assert (same_type <decltype (sy...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sy...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sx != i * 3 + 1 || sum (sy...) != i * 6 + 5) + __builtin_abort (); + auto fn1 = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn1 (); + auto fn2 = [&sy..., &i] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn2 (); + auto fn3 = [&...sy2 = sy, &i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn3 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn4 = [&...sy3 = ref (sy), &i] () { if (sum (sy3...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn4 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn5 = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn5 (); + auto fn6 = [sy..., i] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn6 (); + auto fn7 = [...sy2 = sy, i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn7 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn8 = [...sy3 = square (sy), i] () { if (sum (sy3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn8 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn9 = [&] () { auto fn = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn9 (); + auto fn10 = [&sy..., &i] () { auto fn = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn10 (); + auto fn11 = [&] () { auto fn = [&...sy2 = sy, &i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn11 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn12 = [&sy..., &i] () { auto fn = [&...sy3 = ref (sy), &i] () { if (sum (sy3...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn12 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn13 = [=] () { auto fn = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn13 (); + auto fn14 = [sy..., i] () { auto fn = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn14 (); + auto fn15 = [=] () { auto fn = [...sy2 = sy, i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn15 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn16 = [&sy..., &i] () { auto fn = [...sy3 = square (sy), i] () { if (sum (sy3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn16 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + ++i; + } + i = 0; + for (auto [...sz] : s2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (sz) == 3, ""); + static_assert (same_type <decltype (sz...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sz...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sz...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (sz...) != i * 9 + 6) + __builtin_abort (); + auto fn = [=] () { if (sum (sz...) != i * 9 + 6) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn (); + ++i; + } + if (auto [...sx, sy] = s) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + { + static_assert (sizeof... (sx) == 2, ""); + static_assert (same_type <decltype (sx...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sx...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sy), short>::value, ""); + if (sum (sx...) != 3 || sy != 3) + __builtin_abort (); + } + else + __builtin_abort (); + T t = T { 3, 1, 2 }; + auto [ta, tb, tc] = T { 3, 1, 2 }; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (ta), int>::value, ""); + static_assert (same_type <decltype (tb), long long>::value, ""); + static_assert (same_type <decltype (tc), short>::value, ""); + auto [td [[maybe_unused]], ...te] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (te) == 2, ""); + static_assert (same_type <decltype (td), int>::value, ""); + static_assert (same_type <decltype (te...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (te...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...tf [[maybe_unused]], tg] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tf) == 2, ""); + static_assert (same_type <decltype (tf...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tf...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tg), short>::value, ""); + const auto & [th, ti, tj, ...tk] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (tk) == 0, ""); + static_assert (same_type <decltype (th), const int>::value, ""); + static_assert (same_type <decltype (ti), const long long>::value, ""); + static_assert (same_type <decltype (tj), const short>::value, ""); + auto [tl [[]], ...tm [[]], tn [[]]] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tm) == 1, ""); + static_assert (same_type <decltype (tl), int>::value, ""); + static_assert (same_type <decltype (tm...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tn), short>::value, ""); + auto && [...to] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (to) == 3, ""); + static_assert (same_type <decltype (to...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (to...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (to...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...tp, tq [[]], tr, ts] = T { 3, 1, 2 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tp) == 0, ""); + static_assert (same_type <decltype (tq), int>::value, ""); + static_assert (same_type <decltype (tr), long long>::value, ""); + static_assert (same_type <decltype (ts), short>::value, ""); + auto [tt, ...tu [[]], tv, tw] = T { 3, 1, 2 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tu) == 0, ""); + static_assert (same_type <decltype (tt), int>::value, ""); + static_assert (same_type <decltype (tv), long long>::value, ""); + static_assert (same_type <decltype (tw), short>::value, ""); + if (ta != 1 || tb != 2 || tc != 3 + || td != 1 || te...[0] != 2 || te...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || tf...[0] != 1 || tf...[1] != 2 || tg != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || th != 1 || ti != 2 || tj != 3 + || tl != 1 || tm...[0] != 2 || tn != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || to...[0] != 1 || to...[1] != 2 || to...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || tq != 1 || tr != 2 || ts != 3 + || tt != 1 || tv != 2 || tw != 3 + || sum (te...) != 5 + || sum <decltype (te)...> (te...) != 5 + || sum (square (square (te))...) != 97 + || sum (tf...) != 3 + || sum (tk...) != 0 + || sum (tm...) != 2 + || sum (to...) != 6 + || sum <decltype (to)...> (to...) != 6 + || sum (square (to)...) != 14 + || sum (tp...) != 0 + || sum (tu...) != 0 + || (te + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + tf) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + tk) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (tm + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (to + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (tp + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + tu) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + T t2[] = { { 3, 1, 2 }, { 6, 4, 5 }, { 9, 7, 8 } }; + i = 0; + for (auto [tx, ...ty] : t2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ty) == 2, ""); + static_assert (same_type <decltype (tx), int>::value, ""); + static_assert (same_type <decltype (ty...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ty...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (tx != i * 3 + 1 || sum (ty...) != i * 6 + 5) + __builtin_abort (); + auto fn1 = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; + fn1 (); + auto fn2 = [&ty..., &i] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn2 (); + auto fn3 = [&...ty2 = ty, &i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn3 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn4 = [&...ty3 = ref (ty), &i] () { if (sum (ty3...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn4 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn5 = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; + fn5 (); + auto fn6 = [ty..., i] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn6 (); + auto fn7 = [...ty2 = ty, i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn7 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn8 = [...ty3 = square (ty), i] () { if (sum (ty3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn8 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn9 = [&] () { auto fn = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; + fn9 (); + auto fn10 = [&ty..., &i] () { auto fn = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn10 (); + auto fn11 = [&] () { auto fn = [&...ty2 = ty, &i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn11 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn12 = [&ty..., &i] () { auto fn = [&...ty3 = ref (ty), &i] () { if (sum (ty3...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn12 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn13 = [=] () { auto fn = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; + fn13 (); + auto fn14 = [ty..., i] () { auto fn = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn14 (); + auto fn15 = [=] () { auto fn = [...ty2 = ty, i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn15 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn16 = [&ty..., &i] () { auto fn = [...ty3 = square (ty), i] () { if (sum (ty3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn16 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + ++i; + } + i = 0; + for (auto [...tz] : t2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (tz) == 3, ""); + static_assert (same_type <decltype (tz...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tz...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tz...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (tz...) != i * 9 + 6) + __builtin_abort (); + auto fn = [=] () { if (sum (tz...) != i * 9 + 6) __builtin_abort (); }; + fn (); + ++i; + } + if (auto [...tx [[maybe_unused]], ty] = t) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + __builtin_abort (); + else + { + static_assert (sizeof... (tx) == 2, ""); + static_assert (same_type <decltype (tx...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tx...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ty), short>::value, ""); + if (sum (tx...) != 3 || ty != 3) + __builtin_abort (); + } + int a[3] = { 1, 2, 3 }; + auto [aa, ab, ac] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (aa), int>::value, ""); + static_assert (same_type <decltype (ab), int>::value, ""); + static_assert (same_type <decltype (ac), int>::value, ""); + auto [ad [[maybe_unused]], ...ae [[maybe_unused]]] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ae) == 2, ""); + static_assert (same_type <decltype (ad), int>::value, ""); + static_assert (same_type <decltype (ae...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ae...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...af, ag] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (af) == 2, ""); + static_assert (same_type <decltype (af...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (af...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ag), int>::value, ""); + auto [ah, ai [[]], aj, ...ak [[]]] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ak) == 0, ""); + static_assert (same_type <decltype (ah), int>::value, ""); + static_assert (same_type <decltype (ai), int>::value, ""); + static_assert (same_type <decltype (aj), int>::value, ""); + auto [al, ...am [[]], an] = a;// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (am) == 1, ""); + static_assert (same_type <decltype (al), int>::value, ""); + static_assert (same_type <decltype (am...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (an), int>::value, ""); + const auto &[...ao] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ao) == 3, ""); + static_assert (same_type <decltype (ao...[0]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ao...[1]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ao...[2]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto &&[...ap, aq, ar [[]], as] = a;// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ap) == 0, ""); + static_assert (same_type <decltype (aq), int>::value, ""); + static_assert (same_type <decltype (ar), int>::value, ""); + static_assert (same_type <decltype (as), int>::value, ""); + auto [at, ...au, av, aw] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (au) == 0, ""); + static_assert (same_type <decltype (at), int>::value, ""); + static_assert (same_type <decltype (av), int>::value, ""); + static_assert (same_type <decltype (aw), int>::value, ""); + if (aa != 1 || ab != 2 || ac != 3 + || ad != 1 || ae...[0] != 2 || ae...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || af...[0] != 1 || af...[1] != 2 || ag != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || ah != 1 || ai != 2 || aj != 3 + || al != 1 || am...[0] != 2 || an != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || ao...[0] != 1 || ao...[1] != 2 || ao...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || aq != 1 || ar != 2 || as != 3 + || at != 1 || av != 2 || aw != 3 + || sum (ae...) != 5 + || sum <decltype (ae)...> (ae...) != 5 + || sum (square (square (ae))...) != 97 + || sum (af...) != 3 + || sum (ak...) != 0 + || sum (am...) != 2 + || sum (ao...) != 6 + || sum <decltype (ao)...> (ao...) != 6 + || sum (square (ao)...) != 14 + || sum (ap...) != 0 + || sum (au...) != 0 + || (ae + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + af) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + ak) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (am + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (ao + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (ap + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + au) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + return ses; +} + +int +main () +{ + if (foo <0> () != 2) + __builtin_abort (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp15.C b/gcc/testsuite/g++.dg/cpp26/decomp15.C new file mode 100644 index 0000000..9bb55b3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp15.C @@ -0,0 +1,474 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +struct S { + int a; long long b; short c; + explicit operator bool () const noexcept { return true; } +}; +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +struct T { + short c; int a; long long b; + template <int I> + typename std::tuple_element<I, T>::type &get (); + template <int I> + typename std::tuple_element<I, const T>::type &get () const; + explicit operator bool () const noexcept { return false; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 3; }; +template <> +struct std::tuple_element<0, T> { typedef int type; }; +template <> +struct std::tuple_element<1, T> { typedef long long type; }; +template <> +struct std::tuple_element<2, T> { typedef short type; }; +template <> +std::tuple_element<0, T>::type &T::get <0> () { return a; } +template <> +std::tuple_element<1, T>::type &T::get <1> () { return b; } +template <> +std::tuple_element<2, T>::type &T::get <2> () { return c; } +template <> +struct std::tuple_size<const T> { static constexpr int value = 3; }; +template <> +struct std::tuple_element<0, const T> { typedef const int type; }; +template <> +struct std::tuple_element<1, const T> { typedef const long long type; }; +template <> +struct std::tuple_element<2, const T> { typedef const short type; }; +template <> +std::tuple_element<0, const T>::type &T::get <0> () const { return a; } +template <> +std::tuple_element<1, const T>::type &T::get <1> () const { return b; } +template <> +std::tuple_element<2, const T>::type &T::get <2> () const { return c; } +template <typename T, typename U> +struct same_type { static const bool value = false; }; +template <typename T> +struct same_type<T, T> { static const bool value = true; }; + +int +sum () +{ + return 0; +} + +template <typename T, typename ...A> +T +sum (T x, A... y) +{ + return x + sum (y...); +} + +template <typename T> +T +square (T x) +{ + return x * x; +} + +template <typename T> +T & +ref (T &x) +{ + return x; +} + +using size_t = decltype (sizeof 0); + +template <typename S, typename T, typename U> +size_t +foo () +{ + S s = S { 1, 2, 3 }; + auto [sa, sb, sc] = S { 1, 2, 3 }; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (sa), int>::value, ""); + static_assert (same_type <decltype (sb), long long>::value, ""); + static_assert (same_type <decltype (sc), short>::value, ""); + auto [sd, ...se] = S { 1, 2, 3 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (se) == 2, ""); + static_assert (same_type <decltype (sd), int>::value, ""); + static_assert (same_type <decltype (se...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (se...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + const auto & [...sf [[]], sg] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sf) == 2, ""); + static_assert (same_type <decltype (sf...[0]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sf...[1]), const long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sg), const short>::value, ""); + auto [sh, si, sj [[]], ...sk] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sk) == 0, ""); + static_assert (same_type <decltype (sh), int>::value, ""); + static_assert (same_type <decltype (si), long long>::value, ""); + static_assert (same_type <decltype (sj), short>::value, ""); + auto && [sl, ...sm [[maybe_unused]], sn] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sm) == 1, ""); + static_assert (same_type <decltype (sl), int>::value, ""); + static_assert (same_type <decltype (sm...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sn), short>::value, ""); + auto [...so] = S { 1, 2, 3 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (so) == 3, ""); + static_assert (same_type <decltype (so...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (so...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (so...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...sp, sq, sr, ss [[maybe_unused]]] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sp) == 0, ""); + static_assert (same_type <decltype (sq), int>::value, ""); + static_assert (same_type <decltype (sr), long long>::value, ""); + static_assert (same_type <decltype (ss), short>::value, ""); + auto [st, ...su, sv, sw] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (su) == 0, ""); + static_assert (same_type <decltype (st), int>::value, ""); + static_assert (same_type <decltype (sv), long long>::value, ""); + static_assert (same_type <decltype (sw), short>::value, ""); + if (sa != 1 || sb != 2 || sc != 3 + || sd != 1 || se...[0] != 2 || se...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sf...[0] != 1 || sf...[1] != 2 || sg != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sh != 1 || si != 2 || sj != 3 + || sl != 1 || sm...[0] != 2 || sn != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || so...[0] != 1 || so...[1] != 2 || so...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sq != 1 || sr != 2 || ss != 3 + || st != 1 || sv != 2 || sw != 3 + || sum (se...) != 5 + || sum <decltype (se)...> (se...) != 5 + || sum (square (square (se))...) != 97 + || sum (sf...) != 3 + || sum (sk...) != 0 + || sum (sm...) != 2 + || sum (so...) != 6 + || sum <decltype (so)...> (so...) != 6 + || sum (square (so)...) != 14 + || sum (sp...) != 0 + || sum (su...) != 0 + || (se + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + sf) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + sk) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (sm + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (so + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (sp + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + su) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + S s2[] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; + int i = 0; + for (auto [sx, ...sy [[]]] : s2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sy) == 2, ""); + static_assert (same_type <decltype (sx), int>::value, ""); + static_assert (same_type <decltype (sy...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sy...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sx != i * 3 + 1 || sum (sy...) != i * 6 + 5) + __builtin_abort (); + auto fn1 = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn1 (); + auto fn2 = [&sy..., &i] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn2 (); + auto fn3 = [&...sy2 = sy, &i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn3 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn4 = [&...sy3 = ref (sy), &i] () { if (sum (sy3...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn4 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn5 = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn5 (); + auto fn6 = [sy..., i] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn6 (); + auto fn7 = [...sy2 = sy, i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn7 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn8 = [...sy3 = square (sy), i] () { if (sum (sy3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn8 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn9 = [&] () { auto fn = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn9 (); + auto fn10 = [&sy..., &i] () { auto fn = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn10 (); + auto fn11 = [&] () { auto fn = [&...sy2 = sy, &i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn11 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn12 = [&sy..., &i] () { auto fn = [&...sy3 = ref (sy), &i] () { if (sum (sy3...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn12 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn13 = [=] () { auto fn = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn13 (); + auto fn14 = [sy..., i] () { auto fn = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn14 (); + auto fn15 = [=] () { auto fn = [...sy2 = sy, i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn15 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn16 = [&sy..., &i] () { auto fn = [...sy3 = square (sy), i] () { if (sum (sy3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn16 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + ++i; + } + i = 0; + for (auto [...sz] : s2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (sz) == 3, ""); + static_assert (same_type <decltype (sz...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sz...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sz...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (sz...) != i * 9 + 6) + __builtin_abort (); + auto fn = [=] () { if (sum (sz...) != i * 9 + 6) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn (); + ++i; + } + if (auto [...sx, sy] = s) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + { + static_assert (sizeof... (sx) == 2, ""); + static_assert (same_type <decltype (sx...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sx...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sy), short>::value, ""); + if (sum (sx...) != 3 || sy != 3) + __builtin_abort (); + } + else + __builtin_abort (); + T t = T { 3, 1, 2 }; + auto [ta, tb, tc] = T { 3, 1, 2 }; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (ta), int>::value, ""); + static_assert (same_type <decltype (tb), long long>::value, ""); + static_assert (same_type <decltype (tc), short>::value, ""); + auto [td [[maybe_unused]], ...te] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (te) == 2, ""); + static_assert (same_type <decltype (td), int>::value, ""); + static_assert (same_type <decltype (te...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (te...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...tf [[maybe_unused]], tg] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tf) == 2, ""); + static_assert (same_type <decltype (tf...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tf...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tg), short>::value, ""); + const auto & [th, ti, tj, ...tk] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (tk) == 0, ""); + static_assert (same_type <decltype (th), const int>::value, ""); + static_assert (same_type <decltype (ti), const long long>::value, ""); + static_assert (same_type <decltype (tj), const short>::value, ""); + auto [tl [[]], ...tm [[]], tn [[]]] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tm) == 1, ""); + static_assert (same_type <decltype (tl), int>::value, ""); + static_assert (same_type <decltype (tm...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tn), short>::value, ""); + auto && [...to] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (to) == 3, ""); + constexpr size_t tos = sizeof... (to); + static_assert (same_type <decltype (to...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (to...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (to...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...tp, tq [[]], tr, ts] = T { 3, 1, 2 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tp) == 0, ""); + static_assert (same_type <decltype (tq), int>::value, ""); + static_assert (same_type <decltype (tr), long long>::value, ""); + static_assert (same_type <decltype (ts), short>::value, ""); + auto [tt, ...tu [[]], tv, tw] = T { 3, 1, 2 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tu) == 0, ""); + static_assert (same_type <decltype (tt), int>::value, ""); + static_assert (same_type <decltype (tv), long long>::value, ""); + static_assert (same_type <decltype (tw), short>::value, ""); + if (ta != 1 || tb != 2 || tc != 3 + || td != 1 || te...[0] != 2 || te...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || tf...[0] != 1 || tf...[1] != 2 || tg != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || th != 1 || ti != 2 || tj != 3 + || tl != 1 || tm...[0] != 2 || tn != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || to...[0] != 1 || to...[1] != 2 || to...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || tq != 1 || tr != 2 || ts != 3 + || tt != 1 || tv != 2 || tw != 3 + || sum (te...) != 5 + || sum <decltype (te)...> (te...) != 5 + || sum (square (square (te))...) != 97 + || sum (tf...) != 3 + || sum (tk...) != 0 + || sum (tm...) != 2 + || sum (to...) != 6 + || sum <decltype (to)...> (to...) != 6 + || sum (square (to)...) != 14 + || sum (tp...) != 0 + || sum (tu...) != 0 + || (te + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + tf) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + tk) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (tm + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (to + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (tp + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + tu) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + T t2[] = { { 3, 1, 2 }, { 6, 4, 5 }, { 9, 7, 8 } }; + i = 0; + for (auto [tx, ...ty] : t2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ty) == 2, ""); + static_assert (same_type <decltype (tx), int>::value, ""); + static_assert (same_type <decltype (ty...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ty...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (tx != i * 3 + 1 || sum (ty...) != i * 6 + 5) + __builtin_abort (); + auto fn1 = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; + fn1 (); + auto fn2 = [&ty..., &i] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn2 (); + auto fn3 = [&...ty2 = ty, &i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn3 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn4 = [&...ty3 = ref (ty), &i] () { if (sum (ty3...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn4 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn5 = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; + fn5 (); + auto fn6 = [ty..., i] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn6 (); + auto fn7 = [...ty2 = ty, i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn7 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn8 = [...ty3 = square (ty), i] () { if (sum (ty3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn8 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn9 = [&] () { auto fn = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; + fn9 (); + auto fn10 = [&ty..., &i] () { auto fn = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn10 (); + auto fn11 = [&] () { auto fn = [&...ty2 = ty, &i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn11 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn12 = [&ty..., &i] () { auto fn = [&...ty3 = ref (ty), &i] () { if (sum (ty3...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn12 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn13 = [=] () { auto fn = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; + fn13 (); + auto fn14 = [ty..., i] () { auto fn = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn14 (); + auto fn15 = [=] () { auto fn = [...ty2 = ty, i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn15 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn16 = [&ty..., &i] () { auto fn = [...ty3 = square (ty), i] () { if (sum (ty3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn16 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + ++i; + } + i = 0; + for (auto [...tz] : t2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (tz) == 3, ""); + static_assert (same_type <decltype (tz...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tz...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tz...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (tz...) != i * 9 + 6) + __builtin_abort (); + auto fn = [=] () { if (sum (tz...) != i * 9 + 6) __builtin_abort (); }; + fn (); + ++i; + } + if (auto [...tx [[maybe_unused]], ty] = t) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + __builtin_abort (); + else + { + static_assert (sizeof... (tx) == 2, ""); + static_assert (same_type <decltype (tx...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tx...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ty), short>::value, ""); + if (sum (tx...) != 3 || ty != 3) + __builtin_abort (); + } + U a[3] = { 1, 2, 3 }; + auto [aa, ab, ac] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (aa), int>::value, ""); + static_assert (same_type <decltype (ab), int>::value, ""); + static_assert (same_type <decltype (ac), int>::value, ""); + auto [ad [[maybe_unused]], ...ae [[maybe_unused]]] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ae) == 2, ""); + static_assert (same_type <decltype (ad), int>::value, ""); + static_assert (same_type <decltype (ae...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ae...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...af, ag] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (af) == 2, ""); + static_assert (same_type <decltype (af...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (af...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ag), int>::value, ""); + auto [ah, ai [[]], aj, ...ak [[]]] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ak) == 0, ""); + static_assert (same_type <decltype (ah), int>::value, ""); + static_assert (same_type <decltype (ai), int>::value, ""); + static_assert (same_type <decltype (aj), int>::value, ""); + auto [al, ...am [[]], an] = a;// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (am) == 1, ""); + static_assert (same_type <decltype (al), int>::value, ""); + static_assert (same_type <decltype (am...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (an), int>::value, ""); + const auto &[...ao] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ao) == 3, ""); + static_assert (same_type <decltype (ao...[0]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ao...[1]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ao...[2]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto &&[...ap, aq, ar [[]], as] = a;// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ap) == 0, ""); + static_assert (same_type <decltype (aq), int>::value, ""); + static_assert (same_type <decltype (ar), int>::value, ""); + static_assert (same_type <decltype (as), int>::value, ""); + auto [at, ...au, av, aw] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (au) == 0, ""); + static_assert (same_type <decltype (at), int>::value, ""); + static_assert (same_type <decltype (av), int>::value, ""); + static_assert (same_type <decltype (aw), int>::value, ""); + if (aa != 1 || ab != 2 || ac != 3 + || ad != 1 || ae...[0] != 2 || ae...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || af...[0] != 1 || af...[1] != 2 || ag != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || ah != 1 || ai != 2 || aj != 3 + || al != 1 || am...[0] != 2 || an != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || ao...[0] != 1 || ao...[1] != 2 || ao...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || aq != 1 || ar != 2 || as != 3 + || at != 1 || av != 2 || aw != 3 + || sum (ae...) != 5 + || sum <decltype (ae)...> (ae...) != 5 + || sum (square (square (ae))...) != 97 + || sum (af...) != 3 + || sum (ak...) != 0 + || sum (am...) != 2 + || sum (ao...) != 6 + || sum <decltype (ao)...> (ao...) != 6 + || sum (square (ao)...) != 14 + || sum (ap...) != 0 + || sum (au...) != 0 + || (ae + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + af) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + ak) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (am + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (ao + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (ap + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + au) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + return tos; +} + +int +main () +{ + if (foo <S, T, int> () != 3) + __builtin_abort (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp16.C b/gcc/testsuite/g++.dg/cpp26/decomp16.C new file mode 100644 index 0000000..548f9af --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp16.C @@ -0,0 +1,240 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +int +sum () +{ + return 0; +} + +template <typename T, typename ...A> +T +sum (T x, A... y) +{ + return x + sum (y...); +} + +template <typename T> +T +square (T x) +{ + return x * x; +} + +template <typename T, typename U> +struct same_type { static const bool value = false; }; + +template <typename T> +struct same_type<T, T> { static const bool value = true; }; + +typedef int V __attribute__((vector_size (16 * sizeof (int)))); + +template <int N> +void +foo () +{ + V v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + auto [...va] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (va) == 16, ""); + static_assert (same_type <decltype (va...[5]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (va...[13]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [vb, ...vc, vd, ve] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vc) == 13, ""); + static_assert (same_type <decltype (vb), int>::value, ""); + static_assert (same_type <decltype (vc...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vc...[12]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vd), int>::value, ""); + static_assert (same_type <decltype (ve), int>::value, ""); + auto [vf, vg, vh, vi, ...vj] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vj) == 12, ""); + static_assert (same_type <decltype (vf), int>::value, ""); + static_assert (same_type <decltype (vg), int>::value, ""); + static_assert (same_type <decltype (vh), int>::value, ""); + static_assert (same_type <decltype (vi), int>::value, ""); + static_assert (same_type <decltype (vj...[2]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vj...[10]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (va...[13] != 14 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (va...) != 8 * 17 + || sum (square (va)...) != 1496 + || vb != 1 + || vc...[10] != 12 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (vc...) != 15 * 7 - 1 + || sum <decltype (vc)...> (vc...) != 15 * 7 - 1 + || vd != 15 || ve != 16 + || vf != 1 || vg != 2 || vh != 3 || vi != 4 + || sum (vj...) != 8 * 17 - 10 + || (va + ...) != 8 * 17 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + vc) != 15 * 7 - 1 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + vj) != 8 * 17 - 10) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + V v2[3] = { v, v + 1, v + 2 }; + int i = 0; + for (auto [vk, ...vl, vm] : v2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vl) == 14, ""); + static_assert (same_type <decltype (vk), int>::value, ""); + static_assert (same_type <decltype (vl...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vl...[9]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vm), int>::value, ""); + if (vk != i + 1 || sum (vl...) != i * 14 + 15 * 8 - 1 || vm != i + 16) + __builtin_abort (); + ++i; + } + _Complex double c = 1.0 + 2.0i; + auto [...ca] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ca) == 2, ""); + static_assert (same_type <decltype (ca...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ca...[1]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [cb, ...cc, cd] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cc) == 0, ""); + static_assert (same_type <decltype (cb), double>::value, ""); + static_assert (same_type <decltype (cd), double>::value, ""); + auto [ce, ...cf] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cf) == 1, ""); + static_assert (same_type <decltype (ce), double>::value, ""); + static_assert (same_type <decltype (cf...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...cg, ch] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cg) == 1, ""); + static_assert (same_type <decltype (cg...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ch), double>::value, ""); + if (ca...[0] != 1.0 || ca...[1] != 2.0// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (ca...) != 3.0 + || sum <decltype (ca)...> (ca...) != 3.0 + || sum (square (square (square (ca)))...) != 257.0 + || cb != 1.0 || cd != 2.0 + || ce != 1.0 || cf...[0] != 2.0 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (cf...) != 2.0 + || cg...[0] != 1.0 || ch != 2.0 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (cg...) != 1.0 + || (ca + ...) != 3.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0.0 + ... + cc) != 0.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + cf) != 2.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (cg + ... + 0.0) != 1.0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + _Complex float c2[3] = { 1.0f + 2.0fi, 2.0f + 3.0fi, 3.0f + 4.0fi }; + i = 0; + for (auto [...ci] : c2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ci) == 2, ""); + static_assert (same_type <decltype (ci...[0]), float>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ci...[1]), float>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (ci...) != i * 2 + 3.0f) + __builtin_abort (); + ++i; + } +} + +template <typename V, typename C, typename D> +void +bar () +{ + V v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + auto [...va] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (va) == 16, ""); + static_assert (same_type <decltype (va...[5]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (va...[13]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [vb, ...vc, vd, ve] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vc) == 13, ""); + static_assert (same_type <decltype (vb), int>::value, ""); + static_assert (same_type <decltype (vc...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vc...[12]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vd), int>::value, ""); + static_assert (same_type <decltype (ve), int>::value, ""); + auto [vf, vg, vh, vi, ...vj] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vj) == 12, ""); + static_assert (same_type <decltype (vf), int>::value, ""); + static_assert (same_type <decltype (vg), int>::value, ""); + static_assert (same_type <decltype (vh), int>::value, ""); + static_assert (same_type <decltype (vi), int>::value, ""); + static_assert (same_type <decltype (vj...[2]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vj...[10]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (va...[13] != 14 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (va...) != 8 * 17 + || vb != 1 + || vc...[10] != 12 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (vc...) != 15 * 7 - 1 + || sum <decltype (vc)...> (vc...) != 15 * 7 - 1 + || vd != 15 || ve != 16 + || vf != 1 || vg != 2 || vh != 3 || vi != 4 + || sum (vj...) != 8 * 17 - 10 + || (va + ...) != 8 * 17 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + vc) != 15 * 7 - 1 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + vj) != 8 * 17 - 10) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + V v2[3] = { v, v + 1, v + 2 }; + int i = 0; + for (auto [vk, ...vl, vm] : v2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vl) == 14, ""); + static_assert (same_type <decltype (vk), int>::value, ""); + static_assert (same_type <decltype (vl...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vl...[9]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vm), int>::value, ""); + if (vk != i + 1 || sum (vl...) != i * 14 + 15 * 8 - 1 || vm != i + 16) + __builtin_abort (); + ++i; + } + C c = 1.0 + 2.0i; + auto [...ca] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ca) == 2, ""); + static_assert (same_type <decltype (ca...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ca...[1]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [cb, ...cc, cd] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cc) == 0, ""); + static_assert (same_type <decltype (cb), double>::value, ""); + static_assert (same_type <decltype (cd), double>::value, ""); + auto [ce, ...cf] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cf) == 1, ""); + static_assert (same_type <decltype (ce), double>::value, ""); + static_assert (same_type <decltype (cf...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...cg, ch] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cg) == 1, ""); + static_assert (same_type <decltype (cg...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ch), double>::value, ""); + if (ca...[0] != 1.0 || ca...[1] != 2.0// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (ca...) != 3.0 + || sum <decltype (ca)...> (ca...) != 3.0 + || cb != 1.0 || cd != 2.0 + || ce != 1.0 || cf...[0] != 2.0 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (cf...) != 2.0 + || cg...[0] != 1.0 || ch != 2.0 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (cg...) != 1.0 + || (ca + ...) != 3.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0.0 + ... + cc) != 0.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + cf) != 2.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (cg + ... + 0.0) != 1.0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + D c2[3] = { 1.0f + 2.0fi, 2.0f + 3.0fi, 3.0f + 4.0fi }; + i = 0; + for (auto [...ci] : c2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ci) == 2, ""); + static_assert (same_type <decltype (ci...[0]), float>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ci...[1]), float>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (ci...) != i * 2 + 3.0f) + __builtin_abort (); + ++i; + } +} + +int +main () +{ + foo <0> (); + bar <V, _Complex double, _Complex float> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp17.C b/gcc/testsuite/g++.dg/cpp26/decomp17.C new file mode 100644 index 0000000..49ad0e2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp17.C @@ -0,0 +1,28 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do compile { target c++11 } } +// { dg-options "" } + +typedef int V __attribute__((vector_size (16 * sizeof (int)))); + +template <int N> +void +foo () +{ + V v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + auto [va, vb, vc, vd, ...ve, vf, vg, vh, vi, vj, vk, vl, vm, vn, vo, vp, vq, vr] = v; + // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } .-1 } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-2 } + // { dg-error "18 names provided for structured binding" "" { target *-*-* } .-3 } + // { dg-message "while '__vector\\\(16\\\) int' decomposes into 16 elements" "" { target *-*-* } .-4 } + _Complex double c = 1.0 + 2.0i; + auto [...ca, cb, cc, cd] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "4 names provided for structured binding" "" { target *-*-* } .-2 } + // { dg-message "while '__complex__ double' decomposes into 2 elements" "" { target *-*-* } .-3 } +} + +int +main () +{ + foo <0> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp18.C b/gcc/testsuite/g++.dg/cpp26/decomp18.C new file mode 100644 index 0000000..86b9bf4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp18.C @@ -0,0 +1,109 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +struct S { int a, b, c; }; +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +struct T { + int a[3]; + template <int I> + int &get () { return a[2 - I]; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 3; }; +template <int N> +struct std::tuple_element<N, T> { typedef int type; }; + +template <int N> +inline int +foo () +{ + static int a[4] = { N, N + 1, N + 2, N + 3 }; + static auto [...aa] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } .-2 } + aa...[1]++; // { dg-warning "pack indexing only available with" "" { target c++23_down } } + return (... + aa); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +bar () +{ + static S s = { N, N + 1, N + 2 }; + static auto [...sa] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } .-2 } + sa...[1]++; // { dg-warning "pack indexing only available with" "" { target c++23_down } } + return (sa + ...); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +baz () +{ + static T t = { { N, N + 1, N + 2 } }; + static auto [ta, ...tb, tc, td] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } .-2 } + tc++; + return ((ta + tc + td) + ... + tb); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +qux () +{ + thread_local int a[4] = { N, N + 1, N + 2, N + 3 }; + thread_local auto [...aa] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'thread_local' only in" "" { target c++17_down } .-2 } + aa...[1]++; // { dg-warning "pack indexing only available with" "" { target c++23_down } } + return (... + aa); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +freddy () +{ + thread_local S s = { N, N + 1, N + 2 }; + thread_local auto [...sa] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'thread_local' only in" "" { target c++17_down } .-2 } + sa...[1]++; // { dg-warning "pack indexing only available with" "" { target c++23_down } } + return (sa + ...); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +corge () +{ + thread_local T t = { { N, N + 1, N + 2 } }; + thread_local auto [ta, ...tb, tc, td] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'thread_local' only in" "" { target c++17_down } .-2 } + tc++; + return ((ta + tc + td) + ... + tb); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +int +main () +{ + if (foo <2> () != 15 || foo <2> () != 16 || foo <2> () != 17 + || foo <42> () != 175 || foo <42> () != 176 + || bar <5> () != 19 || bar <5> () != 20 || bar <5> () != 21 + || bar <18> () != 58 || bar <18> () != 59 + || baz <3> () != 13 || baz <3> () != 14 || baz <3> () != 15 + || baz <22> () != 70 || baz <22> () != 71) + __builtin_abort (); + if (qux <2> () != 15 || qux <2> () != 16 || qux <2> () != 17 + || qux <42> () != 175 || qux <42> () != 176 + || freddy <5> () != 19 || freddy <5> () != 20 || freddy <5> () != 21 + || freddy <18> () != 58 || freddy <18> () != 59 + || corge <3> () != 13 || corge <3> () != 14 || corge <3> () != 15 + || corge <22> () != 70 || corge <22> () != 71) + __builtin_abort (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp19.C b/gcc/testsuite/g++.dg/cpp26/decomp19.C new file mode 100644 index 0000000..b4d97a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp19.C @@ -0,0 +1,46 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do compile { target c++11 } } +// { dg-options "" } + +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +struct T { + int a[3]; + template <int I> + int &get () { return a[2 - I]; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 3; }; +template <int N> +struct std::tuple_element<N, T> { typedef int type; }; + +template <int N> +inline void +foo () +{ + static T t = { { N, N + 1, N + 2 } }; + static auto [ta, ...tb, tc] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } .-2 } + // { dg-message "mangling of structured binding pack elements not implemented yet" "" { target *-*-* } .-3 } +} + +template <int N> +inline void +bar () +{ + thread_local T t = { { N, N + 1, N + 2 } }; + thread_local auto [...ta] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'thread_local' only in" "" { target c++17_down } .-2 } + // { dg-message "mangling of structured binding pack elements not implemented yet" "" { target *-*-* } .-3 } +} + +int +main () +{ + foo <0> (); + bar <0> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp20.C b/gcc/testsuite/g++.dg/cpp26/decomp20.C new file mode 100644 index 0000000..5091e13 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp20.C @@ -0,0 +1,53 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do compile { target c++11 } } +// { dg-options "" } + +struct S { + explicit operator bool () const noexcept { return true; } +}; +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +int x; +struct T { + template <int I> + int &get () { return x; } + explicit operator bool () const noexcept { return false; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 0; }; +template <int N> +struct std::tuple_element<N, T> { typedef int type; }; + +template <int N> +void +foo () +{ + int a[0] = {}; + auto [...aa] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (aa) == 0, ""); + S s = {}; + auto [...sa] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (sa) == 0, ""); + T t = {}; + auto [...ta] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ta) == 0, ""); + if (auto [...sb] = s) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + static_assert (sizeof... (sb) == 0, ""); + else + __builtin_abort (); + if (auto [...tb] = t) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + __builtin_abort (); + else + static_assert (sizeof... (tb) == 0, ""); +} + +int +main () +{ + foo <0> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp21.C b/gcc/testsuite/g++.dg/cpp26/decomp21.C new file mode 100644 index 0000000..6baa8aa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp21.C @@ -0,0 +1,103 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +using size_t = decltype (sizeof 0); + +auto g () -> int (&)[4] +{ + static int a[4] = { 1, 2, 3, 4 }; + return a; +} + +template <size_t N> +void +h (int (&arr)[N]) +{ + auto [a, ...b, c] = arr; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (b) == 2, ""); + auto &[f, ...g, h] = arr; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (g) == 2, ""); + if (&f != &arr[0] || &h != &arr[3] + || &g...[0] != &arr[1] || &g...[1] != &arr[2]) // { dg-warning "pack indexing only available with" "" { target c++23_down } } + __builtin_abort (); + auto &[...e] = arr; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof ... (e) == 4, ""); + if (&e...[0] != &arr[0] || &e...[3] != &arr[3]) // { dg-warning "pack indexing only available with" "" { target c++23_down } } + __builtin_abort (); +} + +struct C { int x, y, z; }; + +template <class T> +void +now_i_know_my () +{ + auto [a, b, c] = C (); // { dg-warning "structured bindings only available with" "" { target c++14_down } } + auto [d, ...e] = C (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (e) == 2, ""); + auto [...f, g] = C (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (f) == 2, ""); + auto [h, i, j, ...k] = C (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (k) == 0, ""); +// auto [l, m, n, o, ...p] = C (); +} + +auto foo () -> int (&)[2] +{ + static int a[2] = { 1, 2 }; + return a; +} + +template <class T> +void +bar () +{ + auto [...a] = foo (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (a) == 2, ""); + auto [b, c, ...d] = foo (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (d) == 0, ""); +} + +struct D { }; + +void +baz (...) +{ + __builtin_abort (); +} + +template <typename T> +void +qux () +{ + D arr[1] = {}; + auto [...e] = arr; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + baz (e...); +} + +int d; + +void +baz (D) +{ + d = 1; +} + +int +main () +{ + h (g ()); + now_i_know_my <int> (); + bar <int> (); + qux <int> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C b/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C index cfc5f61..9284bc2 100644 --- a/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C +++ b/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C @@ -395,8 +395,8 @@ #ifndef __cpp_structured_bindings # error "__cpp_structured_bindings" -#elif __cpp_structured_bindings != 202403 -# error "__cpp_structured_bindings != 202403" +#elif __cpp_structured_bindings != 202411 +# error "__cpp_structured_bindings != 202411" #endif #ifndef __cpp_template_template_args diff --git a/gcc/testsuite/g++.dg/modules/class-11_a.H b/gcc/testsuite/g++.dg/modules/class-11_a.H index 799dbdd..43fddb6 100644 --- a/gcc/testsuite/g++.dg/modules/class-11_a.H +++ b/gcc/testsuite/g++.dg/modules/class-11_a.H @@ -1,6 +1,7 @@ // Check for some additional lang_type flags that we'd missed. // { dg-additional-options "-fmodule-header -fabi-version=21 -Wabi=15" } // { dg-module-cmi {} } +// { dg-skip-if "test assumes that structs have padding" { default_packed } } #if __cpp_trivial_relocatability < 202502L #define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible diff --git a/gcc/testsuite/g++.dg/modules/class-11_b.C b/gcc/testsuite/g++.dg/modules/class-11_b.C index 2450a45..87be71a 100644 --- a/gcc/testsuite/g++.dg/modules/class-11_b.C +++ b/gcc/testsuite/g++.dg/modules/class-11_b.C @@ -1,4 +1,5 @@ // { dg-additional-options "-fmodules -fabi-version=21 -Wabi=15" } +// { dg-skip-if "test assumes that structs have padding" { default_packed } } import "class-11_a.H"; diff --git a/gcc/testsuite/g++.dg/torture/noncall-eh-1.C b/gcc/testsuite/g++.dg/torture/noncall-eh-1.C new file mode 100644 index 0000000..ea8fd79 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/noncall-eh-1.C @@ -0,0 +1,26 @@ +// { dg-do compile } +// For slim LTO there's no optimized dump +// { dg-skip-if "" { *-*-* } { "-flto" } { "" } } +// { dg-additional-options "-fnon-call-exceptions -fexceptions -fdump-tree-optimized-eh" } + +// PR tree-optimization/120599 +// Copying prop for aggregates should not touch `a = *__val` since that statement +// can throw (internally) so we need to be able to keep the landing pad. + +struct RefitOption { + char subtype; + int string; +} n; +void h(RefitOption) __attribute__((nothrow)); +void k(RefitOption *__val, RefitOption a) +{ + try { + a = *__val; + RefitOption __trans_tmp_2 = a; + h(__trans_tmp_2); + } + catch(...){} +} + +// Make sure There is a landing pad for the non-call exception from the aggregate load. +// { dg-final { scan-tree-dump "LP " "optimized" } } diff --git a/gcc/testsuite/g++.target/aarch64/sve/pr121449.C b/gcc/testsuite/g++.target/aarch64/sve/pr121449.C new file mode 100644 index 0000000..b2e1376 --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/sve/pr121449.C @@ -0,0 +1,44 @@ +/* PR target/121449 */ +/* { dg-do assemble { target aarch64_asm_sve_ok } } */ +/* { dg-options "-O3 -save-temps" } */ + +struct example; + +struct array { + unsigned length(); + example *operator[](unsigned i) { + example **data = reinterpret_cast<example **>(this); + return data[i]; + } +}; + +struct example { + int a[16]; + bool is_even; + int version; + int count() { return is_even ? 2 : 1; } + void fun1(int, long); + void fun2(unsigned, unsigned); + void process(array &, array &); +}; + +bool found; + +void example::process(array &a, array &b) { + for (unsigned i = 1; a.length(); i++) { + long total = 0; + for (unsigned k = 0; k <= i; k++) { + total += a[k]->count(); + } + for (unsigned j = 0; j < i; j++) { + int major = b[j]->version; + if (found) + major += i; + fun1(i + 1, total); + fun2(j, major); + } + } +} + +/* { dg-final { scan-assembler-not {\tld1b\t(z[0-9]+)\.d, p[0-7]/z, \[(z[0-9]+)\.d, #64\]} } } */ + diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c new file mode 100644 index 0000000..3492899 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-fno-diagnostics-show-nesting" } */ + +extern void foo (void); + +void test_nesting (void) +{ + foo (); /* { dg-error "top-level error" } */ +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c new file mode 100644 index 0000000..8fc2edb --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-fdiagnostics-show-nesting" } */ + +extern void foo (void); + +void test_nesting (void) +{ + foo (); /* { dg-error "top-level error" } */ +} + +/* { dg-begin-multiline-output "" } + * child 0 + * grandchild 0 0 + * grandchild 0 1 + * grandchild 0 2 + * child 1 + * grandchild 1 0 + * grandchild 1 1 + * grandchild 1 2 + * child 2 + * grandchild 2 0 + * grandchild 2 1 + * grandchild 2 2 + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c index f44c8eb..4be52fe 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-set-output=text:experimental-nesting=yes,experimental-nesting-show-levels=yes" } */ +/* { dg-options "-fdiagnostics-set-output=text:show-nesting=yes,show-nesting-levels=yes" } */ extern void foo (void); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c index 39e29f7..c069c3f 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-set-output=text:experimental-nesting=yes -fdiagnostics-text-art-charset=unicode" } */ +/* { dg-options "-fdiagnostics-set-output=text:show-nesting=yes -fdiagnostics-text-art-charset=unicode" } */ extern void foo (void); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c index e103429..a35254d 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-set-output=text:experimental-nesting=yes" } */ +/* { dg-options "-fdiagnostics-set-output=text:show-nesting=yes" } */ extern void foo (void); diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index 3bb6063..c7cc36c 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -112,6 +112,8 @@ set plugin_test_list [list \ diagnostic-test-graphs-html.c \ diagnostic-test-graphs-sarif.c } \ { diagnostic_plugin_test_nesting.cc \ + diagnostic-test-nesting-show-nesting.c \ + diagnostic-test-nesting-no-show-nesting.c \ diagnostic-test-nesting-text-plain.c \ diagnostic-test-nesting-text-indented.c \ diagnostic-test-nesting-text-indented-show-levels.c \ diff --git a/gcc/testsuite/gcc.dg/pr118946-1.c b/gcc/testsuite/gcc.dg/pr118946-1.c new file mode 100644 index 0000000..6cf2661 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr118946-1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-forwprop1-details" } */ + +/* PR tree-optimization/118946 */ + +void f(char *a) +{ + char t[1024] = {}; + __builtin_memcpy(a, t, 10); +} + +/* We should be able to optimize the memcpy into a memset here. */ +/* { dg-final { scan-tree-dump-times "after previous" 1 "forwprop1"} } */ +/* { dg-final { scan-tree-dump-times "memset " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "memcpy " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/hardbool-ai.c b/gcc/testsuite/gcc.dg/torture/hardbool-ai.c index 97569a6..af4e0e1 100644 --- a/gcc/testsuite/gcc.dg/torture/hardbool-ai.c +++ b/gcc/testsuite/gcc.dg/torture/hardbool-ai.c @@ -1,4 +1,5 @@ /* { dg-do run } */ +/* { dg-require-effective-target sync_int_long } */ #define basetype _Atomic int diff --git a/gcc/testsuite/gcc.dg/torture/pr121422-1.c b/gcc/testsuite/gcc.dg/torture/pr121422-1.c new file mode 100644 index 0000000..136f80d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr121422-1.c @@ -0,0 +1,35 @@ +/* { dg-do run } */ +/* PR tree-optimization/121422 */ + +struct s1 +{ + char a[4]; +}; +struct s1 b; +char t[4]; + +/* if both t and b startout zero initialized before this function, + t should end up being: + {0, 0, 1, 0} + while b.a should end up being: + {0, 0, 0, 1} +*/ +__attribute__((noipa,noinline)) +void f(void) +{ + b = (struct s1){}; + b.a[3] = 1; + /* This memcpy should stay a memcpy and not become memset. */ + __builtin_memcpy(&t[0], &b.a[1], 3*sizeof(t[0])); +} + + +int main() +{ + f(); + for(int i = 0; i < 4; i++) + { + if (t[i] != (i == 2 ? 1 : 0)) + __builtin_abort(); + } +} diff --git a/gcc/testsuite/gcc.dg/torture/pr121422-2.c b/gcc/testsuite/gcc.dg/torture/pr121422-2.c new file mode 100644 index 0000000..570559c --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr121422-2.c @@ -0,0 +1,36 @@ +/* { dg-do run } */ +/* PR tree-optimization/121422 */ + +struct s1 +{ + char a[4]; +}; +struct s1 b; +char t[4]; + +/* if both t and b startout zero initialized before this function, + t should end up being: + {0, 0, 1, 0} + while b.a should end up being: + {0, 0, 0, 1} +*/ +__attribute__((noipa,noinline)) +void f(void) +{ + __builtin_memset(&b.a[1], 0, 2); + b.a[3] = 1; + /* This memcpy should stay a memcpy and not become memset. */ + __builtin_memcpy(&t[0], &b.a[1], 3); +} + + +int main() +{ + f(); + for(int i = 0; i < 4; i++) + { + if (t[i] != (i == 2 ? 1 : 0)) + __builtin_abort(); + } +} + diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-107.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-107.c new file mode 100644 index 0000000..f80baf3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-107.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +struct vec_char_16 +{ + unsigned char raw[2]; +}; + +static inline struct vec_char_16 +Dup128VecFromValues(unsigned char t0, unsigned char t1) +{ + struct vec_char_16 result; + result.raw[0] = t0; + result.raw[1] = t1; + return result; +} + +int f(unsigned char t0, unsigned char t1) +{ + struct vec_char_16 a = Dup128VecFromValues(t0, t1); + struct vec_char_16 b; + __builtin_memcpy(&b, &a, sizeof(a)); + return b.raw[0] + b.raw[1]; +} + +/* Ideally we'd optimize this at FRE1 time but we only replace + the loads from b.raw[] with BIT_FIELD_REFs which get optimized + only later in the next FRE. */ +/* { dg-final { scan-tree-dump-not "MEM" "optimized" } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/pr120986-1.c b/gcc/testsuite/gcc.target/aarch64/pr120986-1.c new file mode 100644 index 0000000..e3bc56c --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr120986-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=armv8.2-a+sve2+fp8dot2" } */ +#include <arm_sve.h> + +/* This triggered an ICE with an unrecognizable insn due to incorrect gating of + the insn in the backend. */ +svfloat16_t foo(svfloat16_t a, svmfloat8_t b, svmfloat8_t c, unsigned long fpm) +{ + return svdot_lane_fpm (a, b, c, 0, fpm); +} diff --git a/gcc/testsuite/gcc.target/aarch64/sme/pr121414_1.c b/gcc/testsuite/gcc.target/aarch64/sme/pr121414_1.c new file mode 100644 index 0000000..ad8600f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/pr121414_1.c @@ -0,0 +1,27 @@ +#pragma GCC target "+sme2" + +void f1() __arm_streaming_compatible {} +void f2() __arm_streaming {} +void f3() __arm_in("za") {} +void f4() __arm_out("za") {} +void f5() __arm_inout("za") {} +void f6() __arm_in("zt0") {} +void f7() __arm_out("zt0") {} +void f8() __arm_inout("zt0") {} + +__arm_locally_streaming void g1() {} +__arm_new("za") void g2() {} +__arm_new("zt0") void g3() {} + +/* { dg-final { scan-assembler {\t\.variant_pcs\tf1\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf2\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf3\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf4\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf5\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf6\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf7\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf8\n} } } */ + +/* { dg-final { scan-assembler-not {\t\.variant_pcs\tg1\n} } } */ +/* { dg-final { scan-assembler-not {\t\.variant_pcs\tg2\n} } } */ +/* { dg-final { scan-assembler-not {\t\.variant_pcs\tg3\n} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr120718.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr120718.c new file mode 100644 index 0000000..9ca0938 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr120718.c @@ -0,0 +1,12 @@ +/* { dg-options "-O2" } */ + +#include <arm_sve.h> +typedef int __attribute__((vector_size(8))) v2si; +typedef struct { int x; int y; } A; +void bar(A a); +void foo() +{ + A a; + *(v2si *)&a = (v2si){0, (int)svcntd_pat(SV_ALL)}; + bar(a); +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_11.c b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_11.c new file mode 100644 index 0000000..feb7ee7 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_11.c @@ -0,0 +1,20 @@ +/* Peeling for alignment with masking in VLA modes. */ +/* { dg-do compile } */ +/* { dg-options "-Ofast -msve-vector-bits=scalable --param aarch64-autovec-preference=sve-only -fdump-tree-vect-details" } */ + +#define START 3 +#define END 510 + +int __attribute__((noipa)) +foo (int *a) { + for (signed int i = START; i < END; ++i) { + if (a[i] != 0) + return i; + } + return -1; +} + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ +/* { dg-final { scan-tree-dump "pfa_iv_offset" "vect" } } */ +/* { dg-final { scan-tree-dump "Alignment of access forced using peeling" "vect" } } */ +/* { dg-final { scan-assembler {\tnot\tp[0-7]\.b, p[0-7]/z, p.*\n} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_11_run.c b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_11_run.c new file mode 100644 index 0000000..b4c267f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_11_run.c @@ -0,0 +1,27 @@ +/* Peeling for alignment with masking in VLA modes. */ +/* { dg-do run { target aarch64_sve_hw } } */ +/* { dg-options "-Ofast -msve-vector-bits=scalable --param aarch64-autovec-preference=sve-only" } */ + +#include "peel_ind_11.c" +#include <stdio.h> +#include <stdlib.h> + +#define N 512 + +int __attribute__ ((optimize (1))) +main (void) +{ + for (int k = 5; k < 30; k++) { + int *a = (int *) malloc (sizeof(int) * N); + + /* Set only one non-zero element for test. */ + for (int i = 5; i < 30; i++) + a[i] = (i == k ? 1 : 0); + + int res = foo (a); + asm volatile (""); + if (res != k) { + __builtin_abort (); + } + } +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_12.c b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_12.c new file mode 100644 index 0000000..260482a --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_12.c @@ -0,0 +1,21 @@ +/* Peeling for alignment with masking together with versioning in VLA modes. */ +/* { dg-do compile } */ +/* { dg-options "-Ofast -msve-vector-bits=scalable --param aarch64-autovec-preference=sve-only -fdump-tree-vect-details" } */ + +#define START 5 +#define END 509 + +int __attribute__((noipa)) +foo (int *restrict a, int * restrict b) { + for (signed int i = START; i < END; ++i) { + if (a[i] != b[i]) + return i; + } + return -1; +} + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ +/* { dg-final { scan-tree-dump "pfa_iv_offset" "vect" } } */ +/* { dg-final { scan-tree-dump "Both peeling and versioning will be applied" "vect" } } */ +/* { dg-final { scan-assembler {\tnot\tp[0-7]\.b, p[0-7]/z, p.*\n} } } */ +/* { dg-final { scan-assembler {\teor\t.*\n} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_12_run.c b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_12_run.c new file mode 100644 index 0000000..ba978fe --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_12_run.c @@ -0,0 +1,29 @@ +/* Peeling for alignment with masking together with versioning in VLA modes. */ +/* { dg-do run { target aarch64_sve_hw } } */ +/* { dg-options "-Ofast -msve-vector-bits=scalable --param aarch64-autovec-preference=sve-only" } */ + +#include "peel_ind_12.c" +#include <stdio.h> +#include <stdlib.h> + +#define N 512 + +int __attribute__ ((optimize (1))) +main (void) { + for (int k = 5; k < 50; k++) { + int *a = (int *) malloc (sizeof(int) * N); + int *b = (int *) malloc (sizeof(int) * N); + + /* Set only one place of different values for test. */ + for (int i = 5; i < 50; i++) { + a[i] = (i == k ? 1 : 0); + b[i] = 0; + } + + int res = foo (a, b); + asm volatile (""); + if (res != k) { + __builtin_abort (); + } + } +} diff --git a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_13.c b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_13.c new file mode 100644 index 0000000..730e33e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_13.c @@ -0,0 +1,24 @@ +/* Known inbounds DR in VLA modes. */ +/* { dg-do compile } */ +/* { dg-options "-Ofast -msve-vector-bits=scalable --param aarch64-autovec-preference=sve-only -fdump-tree-vect-details" } */ + +#define N 512 +#define START 5 +#define END 509 + +int x[N] __attribute__((aligned(32))); + +int __attribute__((noipa)) +foo (void) +{ + for (signed int i = START; i < END; ++i) + { + if (x[i] == 0) + return i; + } + return -1; +} + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ +/* { dg-final { scan-tree-dump-not "pfa_iv_offset" "vect" } } */ +/* { dg-final { scan-tree-dump-not "Alignment of access forced using peeling" "vect" } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_13_run.c b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_13_run.c new file mode 100644 index 0000000..83352a8 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/peel_ind_13_run.c @@ -0,0 +1,15 @@ +/* Known inbounds DR in VLA modes. */ +/* { dg-do run { target aarch64_sve_hw } } */ +/* { dg-options "-Ofast -msve-vector-bits=scalable --param aarch64-autovec-preference=sve-only" } */ + +#include "peel_ind_13.c" + +int __attribute__ ((optimize (1))) +main (void) +{ + int res = foo (); + asm volatile (""); + if (res != START) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.target/aarch64/torture/pr120986-2.c b/gcc/testsuite/gcc.target/aarch64/torture/pr120986-2.c new file mode 100644 index 0000000..1218dea --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/torture/pr120986-2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-march=armv8.2-a+sve2+fp8dot2" } */ +#include <arm_sve.h> +svfloat16_t foo(svfloat16_t a, svmfloat8_t b, svmfloat8_t c) +{ + return svdot_lane_fpm (a, b, c, 0, 0); +} diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-18.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-18.c index db7d975..eb8a358 100644 --- a/gcc/testsuite/gcc.target/arm/cmse/cmse-18.c +++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-18.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-mcmse -fdump-rtl-final-slim" } */ +/* Make sure FPCXT is not enabled. */ +/* { dg-options "-mcmse -fdump-rtl-final -march=armv8-m.main+fp" } */ typedef void (*f)(int) __attribute__((cmse_nonsecure_call)); @@ -8,5 +9,5 @@ void bar(f func, int a) func(a); } -/* { dg-final { scan-rtl-dump "call unspec\\\[\\\[r4:SI\\\]\\\]" "final" { target { ! arm_v8_1m_mve_ok } } } } */ -/* { dg-final { scan-rtl-dump "call unspec\\\[\\\[r\[0-7\]:SI\\\]\\\]" "final" { target { arm_v8_1m_mve_ok } } } } */ +/* { dg-final { scan-rtl-dump "call \\\(mem:SI \\\(reg:SI 4 r4" "final" } } */ +/* { dg-final { scan-rtl-dump "UNSPEC_NONSECURE_MEM" "final" } } */ diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-19.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-19.c new file mode 100644 index 0000000..ae075c3 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-19.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* This is a duplicate of cmse-18.c, targetting arm_v8_1m_mve, to make sure + FPCXT is enabled. */ +/* { dg-options "-mcmse -fdump-rtl-final -march=armv8.1-m.main+mve" } */ + +typedef void (*f)(int) __attribute__((cmse_nonsecure_call)); + +void bar(f func, int a) +{ + func(a); +} + +/* { dg-final { scan-rtl-dump "call \\\(mem:SI \\\(reg/f:SI \[0-7] r\[0-7\]" "final" } } */ +/* { dg-final { scan-rtl-dump "UNSPEC_NONSECURE_MEM" "final" } } */ diff --git a/gcc/testsuite/gcc.target/i386/asm-hard-reg-2.c b/gcc/testsuite/gcc.target/i386/asm-hard-reg-2.c index b35cf53..756f6f8 100644 --- a/gcc/testsuite/gcc.target/i386/asm-hard-reg-2.c +++ b/gcc/testsuite/gcc.target/i386/asm-hard-reg-2.c @@ -8,7 +8,7 @@ test (void) #ifdef __x86_64__ int z __attribute__ ((mode (TI))); #else - long z; + long long z; #endif __asm__ __volatile__ ("" : "=A" (z), "={rbx}" (y)); diff --git a/gcc/testsuite/gcc.target/i386/pr90579.c b/gcc/testsuite/gcc.target/i386/pr90579.c index ab48a44..bd2fd33 100644 --- a/gcc/testsuite/gcc.target/i386/pr90579.c +++ b/gcc/testsuite/gcc.target/i386/pr90579.c @@ -16,8 +16,5 @@ loop (int k, double x) return t; } -/* Verify we end up with scalar loads from r for the final sum. */ -/* { dg-final { scan-assembler "vaddsd\tr\\\+40" } } */ -/* { dg-final { scan-assembler "vaddsd\tr\\\+32" } } */ -/* { dg-final { scan-assembler "vaddsd\tr\\\+24" } } */ -/* { dg-final { scan-assembler "vaddsd\tr\\\+16" } } */ +/* Verify we end up with no loads from r. */ +/* { dg-final { scan-assembler-not "v\[ma\]\[^\t \]+\tr" } } */ diff --git a/gcc/testsuite/gfortran.dg/generic_stmt_1.f90 b/gcc/testsuite/gfortran.dg/generic_stmt_1.f90 new file mode 100644 index 0000000..57d0aba --- /dev/null +++ b/gcc/testsuite/gfortran.dg/generic_stmt_1.f90 @@ -0,0 +1,194 @@ +! { dg-do run } +! +! Test the F2018 generic statement +! +function cg (arg1, arg2) + complex :: cg + complex, intent(in) :: arg1, arg2 + cg = arg1 + arg2 +end + +module m + implicit none + + type :: t + integer :: i + end type + integer :: tsum = 0 + + public g + interface g ! Check generic statement + generic interface works + module procedure tg + end interface g + + generic :: g => ig, rg + generic :: operator(.plus.) => ig, rg + generic, private :: h => ig, rg + generic :: WRITE(FORMATTED) => wtarray + + interface g ! Check generic statement + generic interface works + function cg (arg1, arg2) + complex :: cg + complex, intent(in) :: arg1, arg2 + end + end interface g + +! Subroutines + generic, public :: sg => sig, srg + +! Check that we can mix with submodule procedures + interface + real module function realg (arg1, arg2) + real, intent(in) :: arg1, arg2 + end function + end interface + generic, public :: subg => ig, realg + +contains + + function rg (arg1, arg2) + real :: rg + real, intent(in) :: arg1, arg2 + rg = arg1 + arg2 + end + function ig (arg1, arg2) + integer :: ig + integer, intent(in) :: arg1, arg2 + ig = arg1 + arg2 + end + function tg (arg1, arg2) result(res) + type(t) :: res + type(t), intent(in) :: arg1, arg2 + res%i = arg1%i + arg2%i + end + subroutine srg (arg1, arg2, arg3) + real :: arg3 + real, intent(in) :: arg1, arg2 + arg3 = arg1 + arg2 + end + subroutine sig (arg1, arg2, arg3) + integer :: arg3 + integer, intent(in) :: arg1, arg2 + arg3 = arg1 + arg2 + end + + SUBROUTINE wtarray (dtv, unit, iotype, v_list, iostat, iomsg) + CLASS(t), INTENT(IN) :: dtv + INTEGER, INTENT(IN) :: unit + CHARACTER(*), INTENT(IN) :: iotype + INTEGER, INTENT(IN) :: v_list (:) + INTEGER, INTENT(OUT) :: iostat + CHARACTER(*), INTENT(INOUT) :: iomsg + WRITE (unit, FMT=*, iostat=iostat, iomsg=iomsg) dtv%i + END SUBROUTINE wtarray + + subroutine foo + real :: a = 1.0, b = 2.0, r + integer :: c = 3, d = 4 + type(t) :: tres + generic :: operator(+) => tg +! private in foo + r = h(a,b) + if (r /= rg(a,b)) stop 1 + if (h(c,d) /= ig(c,d)) stop 2 +! operator in foo + r = a.plus.b + if (r /= rg(a,b)) stop 3 + if ((c.plus.(2*d)) /= ig(c,2*d)) stop 4 +! check intrinsic operator + tres = t(21) + t(21) + if (tres%i /= 42) stop 5 + end +end module m + +submodule (m) subm +contains + real module function realg (arg1, arg2) + real, intent(in) :: arg1, arg2 + realg = arg1 + arg2 + end +end + +program p + use m + implicit none + integer :: i, rv + + generic :: operator(.minus.) => pig, prg + generic :: operator(*) => times + generic :: j => ig, rg + generic :: j => mg + + real :: a = 1.0, b = 2.0, s3 + integer :: c = 3, d = 4, si + type(t) :: t1 = t(2), t2 = t(3), tres + type(t) :: tarray(5) = [t(5), t(4), t(3), t(2), t(1)] + +! module generic in p + if (g(2.0*a,2.0*b) /= rg(2.0*a,2.0*b)) stop 6 + if (g(c,d) /= ig(c,d)) stop 7 +! local generic in p + if (j(a,b) /= rg(a,b)) stop 8 + if (j(c,d) /= ig (c,d)) stop 9 +! local generic in p with different number of arguments + if (j(c,d,-1) /= mg(c,d,-1)) stop 10 +! module operator in p + if (7*int(a.plus.b) /= 3*(c.plus.d)) stop 11 +! local operator in p + if ((a.minus.b) /= prg(a,b)) stop 12 + if ((c.minus.d) /= pig(c,d)) stop 13 +! local operator in block + block + generic :: operator(.bminus.) => pig, prg + if ((a.bminus.b) /= prg(a,b)) stop 14 + if ((c.bminus.d) /= pig(c,d)) stop 15 + end block +! intrinsic operator in p + tres = t1 * t2 + if (tres%i /= 6) stop 16 +! test private interface in module + call foo +! test mixture of GENERIC statement and generic INTERFACE + if (g((1.0,1.0),(2.0,2.0)) /= cg((1.0,1.0),(2.0,2.0))) stop 17 + tres = g(t1,t2) + if (tres%i /= 5) stop 18 +! subroutines + call sg(10.0*a, b, s3) + if (int(s3) /= 12) stop 19 + call sg(5*c, d, si) + if (si /= 19) stop 20 +! submodule procedures + if (subg(20.0*a,2.0*b) /= realg(20.0*a,2.0*b)) stop 21 +! check DTIO + open (10,status='scratch') + WRITE(10, '(DT)') tarray + rewind(10) + do i = 1,5 + read(10, *) rv + tsum = tsum + rv + end do + close(10) + if (tsum /= 15) stop 22 +contains + + function pig (arg1, arg2) + integer :: pig + integer, intent(in) :: arg1, arg2 + pig = arg1 - arg2 + end + function prg (arg1, arg2) + real :: prg + real, intent(in) :: arg1, arg2 + prg = arg1 - arg2 + end + function times (arg1, arg2) result(res) + type(t) :: res + type(t), intent(in) :: arg1, arg2 + res%i = arg1%i * arg2%i + end + function mg (arg1, arg2, arg3) + integer :: mg + integer, intent(in) :: arg1, arg2, arg3 + mg = arg1 - arg2 * arg3 + end +end diff --git a/gcc/testsuite/gfortran.dg/generic_stmt_2.f90 b/gcc/testsuite/gfortran.dg/generic_stmt_2.f90 new file mode 100644 index 0000000..f698012 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/generic_stmt_2.f90 @@ -0,0 +1,87 @@ +! { dg-do compile } +! +! Test the F2018 generic statement error reporting using the module from +! generic_stmt_1.f90 +! +function cg (arg1, arg2) + complex :: cg + complex, intent(in) :: arg1, arg2 + cg = arg1 + arg2 +end + +module m1 + implicit none + + type :: t + integer :: i + end type + + public g + interface g ! Check generic statement + generic interface works + module procedure tg + end interface g + + generic, public :: g => ig ! { dg-error "repeats that already given" } + generic, private :: g => rg ! { dg-error "conflicts with that already" } + generic :: operator(.plus.) => ig, rg, gg ! { dg-error "did you mean|must be a FUNCTION" } + generic, private :: h => ig, rg + generic :: => ig, rg ! { dg-error "Malformed GENERIC statement" } + generic :: wron ng => ig, rg ! { dg-error "Expected .=>." } + generic :: #!& => ig, rg ! { dg-error "Malformed GENERIC statement" } + generic, private :: operator(.plusplus.) => ig + generic, private :: operator(.plusplus.) => rg ! { dg-error "repeats the access specification" } + generic, PUBLIC :: operator(.plusplus.) => tg ! { dg-error "must have the same access" } + + interface g ! Check generic statement + generic interface works + function cg (arg1, arg2) + complex :: cg + complex, intent(in) :: arg1, arg2 + end + end interface g + + generic, public :: sg => sig, srg + generic, public :: sg2 => sig, srg, rg ! Error appears at 'srg' declaration + + +contains + + function rg (arg1, arg2) + real :: rg + real, intent(in) :: arg1, arg2 + rg = arg1 + arg2 + end + function ig (arg1, arg2) + integer :: ig + integer, intent(in) :: arg1, arg2 + ig = arg1 + arg2 + end + function tg (arg1, arg2) result(res) + type(t) :: res + type(t), intent(in) :: arg1, arg2 + res%i = arg1%i + arg2%i + end + subroutine srg (arg1, arg2, arg3) ! { dg-error "procedures must be either all SUBROUTINEs" } + real :: arg3 + real, intent(in) :: arg1, arg2 + arg3 = arg1 + arg2 + end + subroutine sig (arg1, arg2, arg3) + integer :: arg3 + integer, intent(in) :: arg1, arg2 + arg3 = arg1 + arg2 + end + subroutine foo + real :: a = 1.0, b = 2.0, r + integer :: c = 3, d = 4 + generic, public :: sg => sig, srg ! { dg-error "not in a module" } + generic :: operator(+) => rg ! { dg-error "conflicts with intrinsic interface" } + r = h(a,d) ! { dg-error "There is no specific function" } + if (r /= rg(a,b)) stop 1 + if (h(c,d) /= ig(c,d)) stop 2 + generic :: wrong => ig, rg ! { dg-error "Unexpected GENERIC statement" } +! operator in foo + r = c.plus.b ! { dg-error "Unknown operator" } + if (r /= rg(a,b)) stop 3 + if ((c.plus.(2*d)) /= ig(c,2*d)) stop 4 + end +end module m1 diff --git a/gcc/testsuite/gfortran.dg/generic_stmt_3.f90 b/gcc/testsuite/gfortran.dg/generic_stmt_3.f90 new file mode 100644 index 0000000..543c63f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/generic_stmt_3.f90 @@ -0,0 +1,96 @@ +! { dg-do compile } +! +! Test the F2018 generic statement error reporting of access and name conflicts. +! +! Contributed by Steven Kargl <kargls@comcast.net> +! + module foo1 + + implicit none + private + + public bah + generic :: bah => bah, bak ! { dg-error "conflicts with that" } + + public bar + generic :: bar => bah, bak ! OK - checked that 'bar' is not a procedure + + contains + integer function bah(i) + integer, intent(in) :: i + bah = i + end function bah + real function bak(x) + real, intent(in) :: x + bak = 42.5 + end function bak + end module foo1 + + module foo2 + + implicit none + private + + generic :: bah => bah, bak ! { dg-error "conflicts with that" } + public bah + + generic :: bar => bah, bak ! OK - checked that 'bar' is not a procedure + public bar + + contains + integer function bah(i) + integer, intent(in) :: i + bah = i + end function bah + real function bak(x) + real, intent(in) :: x + bak = 42.5 + end function bak + end module foo2 + + module foo3 ! { dg-error "clashes with the name of an entity" } + + implicit none + private + + integer :: bar = 10 ! { dg-error "has a type" } + generic :: bar => bah, bak ! { dg-error "has a type" } + + generic :: foo3 => bah, bak ! { dg-error "clashes with the name of an entity" } + + contains + integer function bah(i) + integer, intent(in) :: i + bah = i + end function bah + real function bak(x) + real, intent(in) :: x + bak = 42.5 + end function bak + end module foo3 + + module foo4 + implicit none + private + public bak + + generic :: bak => bar, bah + + contains + function bar(i) + real bar + integer, intent(in) :: i + bar = i + end function bar + function bah(x) + real bah + real, intent(in) :: x + bah = x + end function bah + end module foo4 + + program snooze + use foo4 + print *, bak(42) ! Public statement for 'bak' exposes the + print *, bak(43.5) ! specific procedures 'bar' and 'bah' here. + end program snooze diff --git a/gcc/testsuite/gfortran.dg/generic_stmt_4.f90 b/gcc/testsuite/gfortran.dg/generic_stmt_4.f90 new file mode 100644 index 0000000..24e814a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/generic_stmt_4.f90 @@ -0,0 +1,43 @@ +! { dg-do run } +! +! Test the correct processing of public generic statements and verify that they +! behave in the same way as public interfaces. +! +! Contributed by Steven Kargl <kargls@comcast.net> +! +module foo + + implicit none + + private + public bak1, bak2 + + + generic :: bak1 => bar, bah + + ! Should be equivalent to above. + + interface bak2 + module procedure bar + module procedure bah + end interface bak2 + + + contains + function bar(i) + real bar + integer, intent(in) :: i + bar = i + end function bar + function bah(x) + real bah + real, intent(in) :: x + bah = x + end function bah +end module foo + +program snooze + use foo + if (bak1(42) /= bak2(42)) stop 1 + if (bak1(43.5) /= bak2(43.5)) stop 2 +end program snooze diff --git a/gcc/toplev.cc b/gcc/toplev.cc index d349d83..d264674 100644 --- a/gcc/toplev.cc +++ b/gcc/toplev.cc @@ -1094,6 +1094,12 @@ general_init (const char *argv0, bool init_signals, unique_argv original_argv) = global_options_init.x_flag_show_column; global_dc->set_show_highlight_colors (global_options_init.x_flag_diagnostics_show_highlight_colors); + global_dc->set_show_nesting + (global_options_init.x_flag_diagnostics_show_nesting); + global_dc->set_show_nesting_locations + (global_options_init.x_flag_diagnostics_show_nesting_locations); + global_dc->set_show_nesting_levels + (global_options_init.x_flag_diagnostics_show_nesting_levels); global_dc->set_internal_error_callback (internal_error_function); const unsigned lang_mask = lang_hooks.option_lang_mask (); global_dc->set_option_id_manager diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc index 3761fc0..20183c8 100644 --- a/gcc/tree-diagnostic.cc +++ b/gcc/tree-diagnostic.cc @@ -110,7 +110,7 @@ default_tree_printer (pretty_printer *pp, text_info *text, const char *spec, to the DIAGNOSTIC location. */ static void -set_inlining_locations (diagnostics::context *, +set_inlining_locations (const diagnostics::context &, diagnostics::diagnostic_info *diagnostic) { location_t loc = diagnostic_location (diagnostic); diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index 43b1c9d..3d38d88 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -1190,117 +1190,55 @@ constant_pointer_difference (tree p1, tree p2) return NULL_TREE; } - -/* Optimize - a = {}; - b = a; - into - a = {}; - b = {}; - Similarly for memset (&a, ..., sizeof (a)); instead of a = {}; - and/or memcpy (&b, &a, sizeof (a)); instead of b = a; */ - +/* Helper function for optimize_aggr_zeroprop. + Props the zeroing (memset, VAL) that was done in DEST+OFFSET:LEN + (DEFSTMT) into the STMT. Returns true if the STMT was updated. */ static bool -optimize_memcpy_to_memset (gimple_stmt_iterator *gsip, tree dest, tree src, tree len) +optimize_aggr_zeroprop_1 (gimple *defstmt, gimple *stmt, + tree dest, poly_int64 offset, tree val, + poly_offset_int len) { - ao_ref read; - gimple *stmt = gsi_stmt (*gsip); - if (gimple_has_volatile_ops (stmt)) - return false; - - tree src2 = NULL_TREE, len2 = NULL_TREE; - poly_int64 offset, offset2; - tree val = integer_zero_node; - bool len_was_null = len == NULL_TREE; - if (len == NULL_TREE) - len = (TREE_CODE (src) == COMPONENT_REF - ? DECL_SIZE_UNIT (TREE_OPERAND (src, 1)) - : TYPE_SIZE_UNIT (TREE_TYPE (src))); - if (len == NULL_TREE - || !poly_int_tree_p (len)) - return false; + tree src2; + tree len2 = NULL_TREE; + poly_int64 offset2; - ao_ref_init (&read, src); - tree vuse = gimple_vuse (stmt); - gimple *defstmt; - unsigned limit = param_sccvn_max_alias_queries_per_access; - do { - /* If the vuse is the default definition, then there is no stores beforhand. */ - if (SSA_NAME_IS_DEFAULT_DEF (vuse)) - return false; - defstmt = SSA_NAME_DEF_STMT (vuse); - if (is_a <gphi*>(defstmt)) - return false; - if (limit-- == 0) - return false; - /* If the len was null, then we can use TBBA. */ - if (stmt_may_clobber_ref_p_1 (defstmt, &read, - /* tbaa_p = */ len_was_null)) - break; - vuse = gimple_vuse (defstmt); - } while (true); - - if (gimple_store_p (defstmt) - && gimple_assign_single_p (defstmt) - && TREE_CODE (gimple_assign_rhs1 (defstmt)) == STRING_CST - && !gimple_clobber_p (defstmt)) + if (gimple_call_builtin_p (stmt, BUILT_IN_MEMCPY) + && TREE_CODE (gimple_call_arg (stmt, 1)) == ADDR_EXPR + && poly_int_tree_p (gimple_call_arg (stmt, 2))) { - tree str = gimple_assign_rhs1 (defstmt); - src2 = gimple_assign_lhs (defstmt); - /* The string must contain all null char's for now. */ - for (int i = 0; i < TREE_STRING_LENGTH (str); i++) - { - if (TREE_STRING_POINTER (str)[i] != 0) - { - src2 = NULL_TREE; - break; - } - } - } - else if (gimple_store_p (defstmt) - && gimple_assign_single_p (defstmt) - && TREE_CODE (gimple_assign_rhs1 (defstmt)) == CONSTRUCTOR - && !gimple_clobber_p (defstmt)) - src2 = gimple_assign_lhs (defstmt); - else if (gimple_call_builtin_p (defstmt, BUILT_IN_MEMSET) - && TREE_CODE (gimple_call_arg (defstmt, 0)) == ADDR_EXPR - && TREE_CODE (gimple_call_arg (defstmt, 1)) == INTEGER_CST) - { - src2 = TREE_OPERAND (gimple_call_arg (defstmt, 0), 0); - len2 = gimple_call_arg (defstmt, 2); - val = gimple_call_arg (defstmt, 1); - /* For non-0 val, we'd have to transform stmt from assignment - into memset (only if dest is addressable). */ - if (!integer_zerop (val) && is_gimple_assign (stmt)) - src2 = NULL_TREE; + src2 = TREE_OPERAND (gimple_call_arg (stmt, 1), 0); + len2 = gimple_call_arg (stmt, 2); } + else if (gimple_assign_load_p (stmt) && gimple_store_p (stmt)) + { + src2 = gimple_assign_rhs1 (stmt); + len2 = (TREE_CODE (src2) == COMPONENT_REF + ? DECL_SIZE_UNIT (TREE_OPERAND (src2, 1)) + : TYPE_SIZE_UNIT (TREE_TYPE (src2))); + /* Can only handle zero memsets. */ + if (!integer_zerop (val)) + return false; + } + else + return false; - if (src2 == NULL_TREE) - return false; - - if (len2 == NULL_TREE) - len2 = (TREE_CODE (src2) == COMPONENT_REF - ? DECL_SIZE_UNIT (TREE_OPERAND (src2, 1)) - : TYPE_SIZE_UNIT (TREE_TYPE (src2))); if (len2 == NULL_TREE || !poly_int_tree_p (len2)) return false; - src = get_addr_base_and_unit_offset (src, &offset); src2 = get_addr_base_and_unit_offset (src2, &offset2); - if (src == NULL_TREE - || src2 == NULL_TREE - || maybe_lt (offset, offset2)) + if (src2 == NULL_TREE + || maybe_lt (offset2, offset)) return false; - if (!operand_equal_p (src, src2, 0)) + if (!operand_equal_p (dest, src2, 0)) return false; - /* [ src + offset2, src + offset2 + len2 - 1 ] is set to val. + /* [ dest + offset, dest + offset + len - 1 ] is set to val. Make sure that - [ src + offset, src + offset + len - 1 ] is a subset of that. */ - if (maybe_gt (wi::to_poly_offset (len) + (offset - offset2), - wi::to_poly_offset (len2))) + [ dest + offset2, dest + offset2 + len2 - 1 ] is a subset of that. */ + if (maybe_gt (wi::to_poly_offset (len2) + (offset2 - offset), + len)) return false; if (dump_file && (dump_flags & TDF_DETAILS)) @@ -1310,7 +1248,7 @@ optimize_memcpy_to_memset (gimple_stmt_iterator *gsip, tree dest, tree src, tree fprintf (dump_file, "after previous\n "); print_gimple_stmt (dump_file, defstmt, 0, dump_flags); } - + gimple *orig_stmt = stmt; /* For simplicity, don't change the kind of the stmt, turn dest = src; into dest = {}; and memcpy (&dest, &src, len); into memset (&dest, val, len); @@ -1320,8 +1258,10 @@ optimize_memcpy_to_memset (gimple_stmt_iterator *gsip, tree dest, tree src, tree of dest, dest isn't volatile. */ if (is_gimple_assign (stmt)) { - tree ctor = build_constructor (TREE_TYPE (dest), NULL); - gimple_assign_set_rhs_from_tree (gsip, ctor); + tree ctor_type = TREE_TYPE (gimple_assign_lhs (stmt)); + tree ctor = build_constructor (ctor_type, NULL); + gimple_stmt_iterator gsi = gsi_for_stmt (stmt); + gimple_assign_set_rhs_from_tree (&gsi, ctor); update_stmt (stmt); statistics_counter_event (cfun, "copy zeroing propagation of aggregate", 1); } @@ -1341,89 +1281,210 @@ optimize_memcpy_to_memset (gimple_stmt_iterator *gsip, tree dest, tree src, tree fprintf (dump_file, "into\n "); print_gimple_stmt (dump_file, stmt, 0, dump_flags); } + + /* Mark the bb for eh cleanup if needed. */ + if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt)) + bitmap_set_bit (to_purge, gimple_bb (stmt)->index); + return true; } -/* Optimizes - a = c; + +/* Optimize + a = {}; // DEST = value ;; LEN(nullptr) b = a; into - a = c; - b = c; - GSIP is the second statement and SRC is the common - between the statements. -*/ + a = {}; + b = {}; + Similarly for memset (&a, ..., sizeof (a)); instead of a = {}; + and/or memcpy (&b, &a, sizeof (a)); instead of b = a; */ + static bool -optimize_agr_copyprop (gimple_stmt_iterator *gsip) +optimize_aggr_zeroprop (gimple_stmt_iterator *gsip) { + ao_ref read; gimple *stmt = gsi_stmt (*gsip); if (gimple_has_volatile_ops (stmt)) return false; - tree dest = gimple_assign_lhs (stmt); - tree src = gimple_assign_rhs1 (stmt); - /* If the statement is `src = src;` then ignore it. */ - if (operand_equal_p (dest, src, 0)) - return false; + tree dest = NULL_TREE; + tree val = integer_zero_node; + tree len = NULL_TREE; + bool can_use_tbba = true; + bool changed = false; + + if (gimple_call_builtin_p (stmt, BUILT_IN_MEMSET) + && TREE_CODE (gimple_call_arg (stmt, 0)) == ADDR_EXPR + && TREE_CODE (gimple_call_arg (stmt, 1)) == INTEGER_CST + && poly_int_tree_p (gimple_call_arg (stmt, 2))) + { + dest = TREE_OPERAND (gimple_call_arg (stmt, 0), 0); + len = gimple_call_arg (stmt, 2); + val = gimple_call_arg (stmt, 1); + ao_ref_init_from_ptr_and_size (&read, gimple_call_arg (stmt, 0), len); + can_use_tbba = false; + } + else if (gimple_store_p (stmt) + && gimple_assign_single_p (stmt) + && TREE_CODE (gimple_assign_rhs1 (stmt)) == STRING_CST) + { + tree str = gimple_assign_rhs1 (stmt); + dest = gimple_assign_lhs (stmt); + ao_ref_init (&read, dest); + /* The string must contain all null char's for now. */ + for (int i = 0; i < TREE_STRING_LENGTH (str); i++) + { + if (TREE_STRING_POINTER (str)[i] != 0) + { + dest = NULL_TREE; + break; + } + } + } + else if (gimple_store_p (stmt) + && gimple_assign_single_p (stmt) + && TREE_CODE (gimple_assign_rhs1 (stmt)) == CONSTRUCTOR + && !gimple_clobber_p (stmt)) + { + dest = gimple_assign_lhs (stmt); + ao_ref_init (&read, dest); + } - tree vuse = gimple_vuse (stmt); - /* If the vuse is the default definition, then there is no store beforehand. */ - if (SSA_NAME_IS_DEFAULT_DEF (vuse)) + if (dest == NULL_TREE) return false; - gimple *defstmt = SSA_NAME_DEF_STMT (vuse); - if (!gimple_assign_load_p (defstmt) - || !gimple_store_p (defstmt)) + + if (len == NULL_TREE) + len = (TREE_CODE (dest) == COMPONENT_REF + ? DECL_SIZE_UNIT (TREE_OPERAND (dest, 1)) + : TYPE_SIZE_UNIT (TREE_TYPE (dest))); + if (len == NULL_TREE + || !poly_int_tree_p (len)) return false; - if (gimple_has_volatile_ops (defstmt)) + + /* This store needs to be on the byte boundary and pointing to an object. */ + poly_int64 offset; + tree dest_base = get_addr_base_and_unit_offset (dest, &offset); + if (dest_base == NULL_TREE) return false; - tree dest2 = gimple_assign_lhs (defstmt); - tree src2 = gimple_assign_rhs1 (defstmt); + /* Setup the worklist. */ + auto_vec<std::pair<tree, unsigned>> worklist; + unsigned limit = param_sccvn_max_alias_queries_per_access; + worklist.safe_push (std::make_pair (gimple_vdef (stmt), limit)); - /* If the original store is `src2 = src2;` skip over it. */ - if (operand_equal_p (src2, dest2, 0)) - return false; - if (!operand_equal_p (src, dest2, 0)) + while (!worklist.is_empty ()) + { + std::pair<tree, unsigned> top = worklist.pop (); + tree vdef = top.first; + limit = top.second; + gimple *use_stmt; + imm_use_iterator iter; + FOR_EACH_IMM_USE_STMT (use_stmt, iter, vdef) + { + /* Handling PHI nodes might not be worth it so don't. */ + if (is_a <gphi*> (use_stmt)) + continue; + + /* If this statement does not clobber add the vdef stmt to the + worklist. */ + if (gimple_vdef (use_stmt) + && !stmt_may_clobber_ref_p_1 (use_stmt, &read, + /* tbaa_p = */ can_use_tbba) + && limit != 0) + worklist.safe_push (std::make_pair (gimple_vdef (use_stmt), + limit - 1)); + + if (optimize_aggr_zeroprop_1 (stmt, use_stmt, dest_base, offset, + val, wi::to_poly_offset (len))) + changed = true; + } + } + + return changed; +} +/* Optimizes + DEST = SRC; + DEST2 = DEST; # DEST2 = SRC2; + into + DEST = SRC; + DEST2 = SRC; + GSIP is the first statement and SRC is the common + between the statements. +*/ +static bool +optimize_agr_copyprop (gimple_stmt_iterator *gsip) +{ + gimple *stmt = gsi_stmt (*gsip); + if (gimple_has_volatile_ops (stmt)) return false; + /* Can't prop if the statement could throw. */ + if (stmt_could_throw_p (cfun, stmt)) + return false; - /* For 2 memory refences and using a temporary to do the copy, - don't remove the temporary as the 2 memory references might overlap. - Note t does not need to be decl as it could be field. - See PR 22237 for full details. - E.g. - t = *a; - *b = t; - Cannot be convert into - t = *a; - *b = *a; - Though the following is allowed to be done: - t = *a; - *a = t; - And convert it into: - t = *a; - *a = *a; - */ - if (!operand_equal_p (src2, dest, 0) - && !DECL_P (dest) && !DECL_P (src2)) + tree dest = gimple_assign_lhs (stmt); + tree src = gimple_assign_rhs1 (stmt); + /* If the statement is `src = src;` then ignore it. */ + if (operand_equal_p (dest, src, 0)) return false; - if (dump_file && (dump_flags & TDF_DETAILS)) + tree vdef = gimple_vdef (stmt); + imm_use_iterator iter; + gimple *use_stmt; + bool changed = false; + FOR_EACH_IMM_USE_STMT (use_stmt, iter, vdef) { - fprintf (dump_file, "Simplified\n "); - print_gimple_stmt (dump_file, stmt, 0, dump_flags); - fprintf (dump_file, "after previous\n "); - print_gimple_stmt (dump_file, defstmt, 0, dump_flags); - } - gimple_assign_set_rhs_from_tree (gsip, unshare_expr (src2)); - update_stmt (stmt); + if (!gimple_assign_load_p (use_stmt) + || !gimple_store_p (use_stmt)) + continue; + if (gimple_has_volatile_ops (use_stmt)) + continue; + tree dest2 = gimple_assign_lhs (use_stmt); + tree src2 = gimple_assign_rhs1 (use_stmt); + /* If the new store is `src2 = src2;` skip over it. */ + if (operand_equal_p (src2, dest2, 0)) + continue; + if (!operand_equal_p (dest, src2, 0)) + continue; + /* For 2 memory refences and using a temporary to do the copy, + don't remove the temporary as the 2 memory references might overlap. + Note t does not need to be decl as it could be field. + See PR 22237 for full details. + E.g. + t = *a; #DEST = SRC; + *b = t; #DEST2 = SRC2; + Cannot be convert into + t = *a; + *b = *a; + Though the following is allowed to be done: + t = *a; + *a = t; + And convert it into: + t = *a; + *a = *a; + */ + if (!operand_equal_p (dest2, src, 0) + && !DECL_P (dest2) && !DECL_P (src)) + continue; + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Simplified\n "); + print_gimple_stmt (dump_file, use_stmt, 0, dump_flags); + fprintf (dump_file, "after previous\n "); + print_gimple_stmt (dump_file, stmt, 0, dump_flags); + } + gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt); + gimple_assign_set_rhs_from_tree (&gsi, unshare_expr (src)); + update_stmt (use_stmt); - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "into\n "); - print_gimple_stmt (dump_file, stmt, 0, dump_flags); + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "into\n "); + print_gimple_stmt (dump_file, use_stmt, 0, dump_flags); + } + statistics_counter_event (cfun, "copy prop for aggregate", 1); + changed = true; } - statistics_counter_event (cfun, "copy prop for aggregate", 1); - return true; + return changed; } /* *GSI_P is a GIMPLE_CALL to a builtin function. @@ -1463,22 +1524,6 @@ simplify_builtin_call (gimple_stmt_iterator *gsi_p, tree callee2) switch (DECL_FUNCTION_CODE (callee2)) { - case BUILT_IN_MEMCPY: - if (gimple_call_num_args (stmt2) == 3) - { - tree dest = gimple_call_arg (stmt2, 0); - tree src = gimple_call_arg (stmt2, 1); - tree len = gimple_call_arg (stmt2, 2); - /* Try to optimize the memcpy to memset if src - and dest are addresses. */ - if (TREE_CODE (dest) == ADDR_EXPR - && TREE_CODE (src) == ADDR_EXPR - && TREE_CODE (len) == INTEGER_CST - && optimize_memcpy_to_memset (gsi_p, TREE_OPERAND (dest, 0), - TREE_OPERAND (src, 0), len)) - return true; - } - break; case BUILT_IN_MEMCHR: if (gimple_call_num_args (stmt2) == 3 && (res = gimple_call_lhs (stmt2)) != nullptr @@ -1540,6 +1585,13 @@ simplify_builtin_call (gimple_stmt_iterator *gsi_p, tree callee2) break; case BUILT_IN_MEMSET: + if (gimple_call_num_args (stmt2) == 3) + { + /* Try to prop the zeroing/value of the memset to memcpy + if the dest is an address and the value is a constant. */ + if (optimize_aggr_zeroprop (gsi_p)) + return true; + } if (gimple_call_num_args (stmt2) != 3 || gimple_call_lhs (stmt2) || CHAR_BIT != 8 @@ -4858,21 +4910,16 @@ pass_forwprop::execute (function *fun) { tree rhs1 = gimple_assign_rhs1 (stmt); enum tree_code code = gimple_assign_rhs_code (stmt); - if (gimple_assign_load_p (stmt) && gimple_store_p (stmt)) + if (gimple_store_p (stmt) && optimize_aggr_zeroprop (&gsi)) { - if (optimize_memcpy_to_memset (&gsi, - gimple_assign_lhs (stmt), - gimple_assign_rhs1 (stmt), - /* len = */NULL_TREE)) - { - changed = true; - break; - } - if (optimize_agr_copyprop (&gsi)) - { - changed = true; - break; - } + changed = true; + break; + } + if (gimple_assign_load_p (stmt) && gimple_store_p (stmt) + && optimize_agr_copyprop (&gsi)) + { + changed = true; + break; } if (TREE_CODE_CLASS (code) == tcc_comparison) diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 00315d1..ccd8080 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -5633,6 +5633,37 @@ visit_nary_op (tree lhs, gassign *stmt) } } break; + case BIT_FIELD_REF: + if (TREE_CODE (TREE_OPERAND (rhs1, 0)) == SSA_NAME) + { + tree op0 = TREE_OPERAND (rhs1, 0); + gassign *ass = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (op0)); + if (ass + && !gimple_has_volatile_ops (ass) + && vn_get_stmt_kind (ass) == VN_REFERENCE) + { + tree last_vuse = gimple_vuse (ass); + tree op = gimple_assign_rhs1 (ass); + /* Avoid building invalid and unexpected refs. */ + if (TREE_CODE (op) != TARGET_MEM_REF + && TREE_CODE (op) != BIT_FIELD_REF + && TREE_CODE (op) != REALPART_EXPR + && TREE_CODE (op) != IMAGPART_EXPR) + { + tree op = build3 (BIT_FIELD_REF, TREE_TYPE (rhs1), + gimple_assign_rhs1 (ass), + TREE_OPERAND (rhs1, 1), + TREE_OPERAND (rhs1, 2)); + tree result = vn_reference_lookup (op, gimple_vuse (ass), + default_vn_walk_kind, + NULL, true, &last_vuse); + if (result + && useless_type_conversion_p (type, TREE_TYPE (result))) + return set_ssa_val_to (lhs, result); + } + } + } + break; case TRUNC_DIV_EXPR: if (TYPE_UNSIGNED (type)) break; diff --git a/gcc/tree-tailcall.cc b/gcc/tree-tailcall.cc index c80145d..d04394f 100644 --- a/gcc/tree-tailcall.cc +++ b/gcc/tree-tailcall.cc @@ -605,6 +605,12 @@ find_tail_calls (basic_block bb, edge esucc, struct tailcall **ret, && (stmt = last_nondebug_stmt (bb)) && gimple_code (stmt) == GIMPLE_COND) ; + else if (esucc + && cfun->has_musttail + && diag_musttail + && (stmt = last_nondebug_stmt (bb)) + && gimple_code (stmt) == GIMPLE_SWITCH) + ; /* If there is an abnormal edge assume it's the only extra one. Tolerate that case so that we can give better error messages for musttail later. */ @@ -668,7 +674,7 @@ find_tail_calls (basic_block bb, edge esucc, struct tailcall **ret, else goto <bb 6>; [INV] When walking backwards, ESUCC is the edge we are coming from, - depending on its EDGE_TRUE_FLAG, == vs. != for the comparison + depending on its EDGE_TRUE_FLAG, comparison code and value compared against try to find out through which edge we need to go and which edge should be ignored. The code handles both INTEGER_CST PHI arguments and SSA_NAMEs set to constants @@ -677,19 +683,16 @@ find_tail_calls (basic_block bb, edge esucc, struct tailcall **ret, && diag_musttail && esucc && gimple_code (stmt) == GIMPLE_COND - && (gimple_cond_code (stmt) == EQ_EXPR - || gimple_cond_code (stmt) == NE_EXPR) && TREE_CODE (gimple_cond_lhs (stmt)) == SSA_NAME && TREE_CODE (gimple_cond_rhs (stmt)) == INTEGER_CST && INTEGRAL_TYPE_P (TREE_TYPE (gimple_cond_lhs (stmt))) - && (integer_zerop (gimple_cond_rhs (stmt)) - || integer_onep (gimple_cond_rhs (stmt)))) + && tree_int_cst_sgn (gimple_cond_rhs (stmt)) >= 0) { tree lhs = gimple_cond_lhs (stmt); - bool rhsv = integer_onep (gimple_cond_rhs (stmt)); - if (((esucc->flags & EDGE_TRUE_VALUE) != 0) - ^ (gimple_cond_code (stmt) == EQ_EXPR)) - rhsv = !rhsv; + tree_code ccode = gimple_cond_code (stmt); + tree rhsv = gimple_cond_rhs (stmt); + if ((esucc->flags & EDGE_FALSE_VALUE) != 0) + ccode = invert_tree_comparison (ccode, false); if (!ignored_edges) { ignored_edges = new hash_set<edge>; @@ -700,8 +703,10 @@ find_tail_calls (basic_block bb, edge esucc, struct tailcall **ret, && (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (lhs)) == INTEGER_CST)) { - tree rhs = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (lhs)); - if (rhsv ? integer_onep (rhs) : integer_zerop (rhs)) + tree lhsv = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (lhs)); + + if (const_binop (ccode, boolean_type_node, lhsv, rhsv) + == boolean_true_node) continue; } else if (gimple_code (SSA_NAME_DEF_STMT (lhs)) == GIMPLE_PHI) @@ -712,15 +717,62 @@ find_tail_calls (basic_block bb, edge esucc, struct tailcall **ret, edge_iterator ei; FOR_EACH_EDGE (e, ei, pbb->preds) { - tree rhs = gimple_phi_arg_def_from_edge (phi, e); - if (TREE_CODE (rhs) == SSA_NAME - && is_gimple_assign (SSA_NAME_DEF_STMT (rhs)) - && (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (rhs)) + tree lhsv = gimple_phi_arg_def_from_edge (phi, e); + if (TREE_CODE (lhsv) == SSA_NAME + && is_gimple_assign (SSA_NAME_DEF_STMT (lhsv)) + && (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (lhsv)) == INTEGER_CST)) - rhs = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (rhs)); - if (!(rhsv ? integer_onep (rhs) : integer_zerop (rhs))) + lhsv = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (lhsv)); + if (TREE_CODE (lhsv) != INTEGER_CST + || const_binop (ccode, boolean_type_node, + lhsv, rhsv) != boolean_true_node) ignored_edges->add (e); } + continue; + } + } + if (cfun->has_musttail + && diag_musttail + && esucc + && gimple_code (stmt) == GIMPLE_SWITCH + && (TREE_CODE (gimple_switch_index (as_a <gswitch *> (stmt))) + == SSA_NAME)) + { + gswitch *swtch = as_a <gswitch *> (stmt); + tree idx = gimple_switch_index (swtch); + if (!ignored_edges) + { + ignored_edges = new hash_set<edge>; + must_see_bbs = new hash_set<basic_block>; + delete_ignored_edges = true; + } + if (is_gimple_assign (SSA_NAME_DEF_STMT (idx)) + && (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (idx)) + == INTEGER_CST)) + { + tree val = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (idx)); + if (find_taken_edge_switch_expr (swtch, val) == esucc) + continue; + } + else if (gimple_code (SSA_NAME_DEF_STMT (idx)) == GIMPLE_PHI) + { + gimple *phi = SSA_NAME_DEF_STMT (idx); + basic_block pbb = gimple_bb (phi); + must_see_bbs->add (pbb); + edge_iterator ei; + FOR_EACH_EDGE (e, ei, pbb->preds) + { + tree val = gimple_phi_arg_def_from_edge (phi, e); + if (TREE_CODE (val) == SSA_NAME + && is_gimple_assign (SSA_NAME_DEF_STMT (val)) + && (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (val)) + == INTEGER_CST)) + val = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (val)); + if (TREE_CODE (val) != INTEGER_CST + || find_taken_edge_switch_expr (swtch, val) != esucc) + ignored_edges->add (e); + } + continue; } } @@ -1138,47 +1190,67 @@ find_tail_calls (basic_block bb, edge esucc, struct tailcall **ret, if (ignored_edges) { if (is_gimple_assign (stmt) - && gimple_assign_rhs_code (stmt) == INTEGER_CST) + && gimple_assign_rhs_code (stmt) == INTEGER_CST + && tree_int_cst_sgn (gimple_assign_rhs1 (stmt)) >= 0) { use_operand_p use_p; - gimple *use_stmt; - if ((integer_zerop (gimple_assign_rhs1 (stmt)) - || integer_onep (gimple_assign_rhs1 (stmt))) - && single_imm_use (gimple_assign_lhs (stmt), &use_p, - &use_stmt)) + imm_use_iterator imm_iter; + bool bad_p = false; + FOR_EACH_IMM_USE_FAST (use_p, imm_iter, + gimple_assign_lhs (stmt)) { - if (gimple_code (use_stmt) == GIMPLE_COND) - continue; - if (gimple_code (use_stmt) == GIMPLE_PHI - && single_imm_use (gimple_phi_result (use_stmt), - &use_p, &use_stmt) - && gimple_code (use_stmt) == GIMPLE_COND) + gimple *use_stmt = USE_STMT (use_p); + if (is_gimple_debug (use_stmt) + || gimple_code (use_stmt) == GIMPLE_COND + || gimple_code (use_stmt) == GIMPLE_SWITCH) continue; + if (gimple_code (use_stmt) == GIMPLE_PHI) + { + use_operand_p use_p2; + imm_use_iterator imm_iter2; + FOR_EACH_IMM_USE_FAST (use_p2, imm_iter2, + gimple_phi_result (use_stmt)) + { + gimple *use_stmt2 = USE_STMT (use_p2); + if (is_gimple_debug (use_stmt2) + || gimple_code (use_stmt2) == GIMPLE_COND + || gimple_code (use_stmt2) == GIMPLE_SWITCH) + continue; + bad_p = true; + break; + } + if (bad_p) + break; + } + else + { + bad_p = true; + break; + } } + if (!bad_p) + continue; } if (gimple_code (stmt) == GIMPLE_COND - && (gimple_cond_code (stmt) == EQ_EXPR - || gimple_cond_code (stmt) == NE_EXPR) && TREE_CODE (gimple_cond_lhs (stmt)) == SSA_NAME && TREE_CODE (gimple_cond_rhs (stmt)) == INTEGER_CST && INTEGRAL_TYPE_P (TREE_TYPE (gimple_cond_lhs (stmt))) - && (integer_zerop (gimple_cond_rhs (stmt)) - || integer_onep (gimple_cond_rhs (stmt)))) + && tree_int_cst_sgn (gimple_cond_rhs (stmt)) >= 0) { edge e = NULL, et, ef; + enum tree_code ccode = gimple_cond_code (stmt); tree lhs = gimple_cond_lhs (stmt); - bool rhsv = integer_onep (gimple_cond_rhs (stmt)); - if (gimple_cond_code (stmt) == NE_EXPR) - rhsv = !rhsv; + tree rhsv = gimple_cond_rhs (stmt); extract_true_false_edges_from_block (gimple_bb (stmt), &et, &ef); if (is_gimple_assign (SSA_NAME_DEF_STMT (lhs)) && (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (lhs)) == INTEGER_CST)) { - tree rhs = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (lhs)); - if (rhsv ? integer_onep (rhs) : integer_zerop (rhs)) + tree lhsv = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (lhs)); + tree r = const_binop (ccode, boolean_type_node, lhsv, rhsv); + if (r == boolean_true_node) e = et; - else if (rhsv ? integer_zerop (rhs) : integer_onep (rhs)) + else if (r == boolean_false_node) e = ef; } else if (gimple_code (SSA_NAME_DEF_STMT (lhs)) == GIMPLE_PHI) @@ -1188,16 +1260,17 @@ find_tail_calls (basic_block bb, edge esucc, struct tailcall **ret, for (edge e2 : edges) if (e2->dest == pbb) { - tree rhs = gimple_phi_arg_def_from_edge (phi, e2); - if (TREE_CODE (rhs) == SSA_NAME) - if (gimple *g = SSA_NAME_DEF_STMT (rhs)) + tree lhsv = gimple_phi_arg_def_from_edge (phi, e2); + if (TREE_CODE (lhsv) == SSA_NAME) + if (gimple *g = SSA_NAME_DEF_STMT (lhsv)) if (is_gimple_assign (g) && gimple_assign_rhs_code (g) == INTEGER_CST) - rhs = gimple_assign_rhs1 (g); - if (rhsv ? integer_onep (rhs) : integer_zerop (rhs)) + lhsv = gimple_assign_rhs1 (g); + tree r = const_binop (ccode, boolean_type_node, + lhsv, rhsv); + if (r == boolean_true_node) e = et; - else if (rhsv ? integer_zerop (rhs) - : integer_onep (rhs)) + else if (r == boolean_false_node) e = ef; break; } @@ -1212,6 +1285,48 @@ find_tail_calls (basic_block bb, edge esucc, struct tailcall **ret, goto new_bb; } } + if (gimple_code (stmt) == GIMPLE_SWITCH + && (TREE_CODE (gimple_switch_index (as_a <gswitch *> (stmt))) + == SSA_NAME)) + { + edge e = NULL; + gswitch *swtch = as_a <gswitch *> (stmt); + tree idx = gimple_switch_index (swtch); + if (is_gimple_assign (SSA_NAME_DEF_STMT (idx)) + && (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (idx)) + == INTEGER_CST)) + { + tree val = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (idx)); + e = find_taken_edge_switch_expr (swtch, val); + } + else if (gimple_code (SSA_NAME_DEF_STMT (idx)) == GIMPLE_PHI) + { + gimple *phi = SSA_NAME_DEF_STMT (idx); + basic_block pbb = gimple_bb (phi); + for (edge e2 : edges) + if (e2->dest == pbb) + { + tree val = gimple_phi_arg_def_from_edge (phi, e2); + if (TREE_CODE (val) == SSA_NAME) + if (gimple *g = SSA_NAME_DEF_STMT (val)) + if (is_gimple_assign (g) + && gimple_assign_rhs_code (g) == INTEGER_CST) + val = gimple_assign_rhs1 (g); + if (TREE_CODE (val) == INTEGER_CST) + e = find_taken_edge_switch_expr (swtch, val); + break; + } + } + if (e) + { + ass_var = propagate_through_phis (ass_var, e); + if (!ass_var || ignored_edges) + edges.safe_push (e); + abb = e->dest; + agsi = gsi_start_bb (abb); + goto new_bb; + } + } } if (gimple_code (stmt) != GIMPLE_ASSIGN) diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index a9d4aae..a3d3b3e 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -1448,17 +1448,20 @@ vect_compute_data_ref_alignment (vec_info *vinfo, dr_vec_info *dr_info, if (loop_vinfo && dr_safe_speculative_read_required (stmt_info)) { - poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo); - auto vectype_size + /* The required target alignment must be a power-of-2 value and is + computed as the product of vector element size, VF and group size. + We compute the constant part first as VF may be a variable. For + variable VF, the power-of-2 check of VF is deferred to runtime. */ + auto align_factor_c = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))); - poly_uint64 new_alignment = vf * vectype_size; - /* If we have a grouped access we require that the alignment be N * elem. */ if (STMT_VINFO_GROUPED_ACCESS (stmt_info)) - new_alignment *= DR_GROUP_SIZE (DR_GROUP_FIRST_ELEMENT (stmt_info)); + align_factor_c *= DR_GROUP_SIZE (DR_GROUP_FIRST_ELEMENT (stmt_info)); + + poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo); + poly_uint64 new_alignment = vf * align_factor_c; - unsigned HOST_WIDE_INT target_alignment; - if (new_alignment.is_constant (&target_alignment) - && pow2p_hwi (target_alignment)) + if ((vf.is_constant () && pow2p_hwi (new_alignment.to_constant ())) + || (!vf.is_constant () && pow2p_hwi (align_factor_c))) { if (dump_enabled_p ()) { @@ -1467,7 +1470,7 @@ vect_compute_data_ref_alignment (vec_info *vinfo, dr_vec_info *dr_info, dump_dec (MSG_NOTE, new_alignment); dump_printf (MSG_NOTE, " bytes.\n"); } - vector_alignment = target_alignment; + vector_alignment = new_alignment; } } @@ -2438,6 +2441,7 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) - The cost of peeling (the extra runtime checks, the increase in code size). */ + poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo); FOR_EACH_VEC_ELT (datarefs, i, dr) { dr_vec_info *dr_info = loop_vinfo->lookup_dr (dr); @@ -2446,9 +2450,18 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) stmt_vec_info stmt_info = dr_info->stmt; tree vectype = STMT_VINFO_VECTYPE (stmt_info); - do_peeling - = vector_alignment_reachable_p (dr_info, - LOOP_VINFO_VECT_FACTOR (loop_vinfo)); + + /* With variable VF, unsafe speculative read can be avoided for known + inbounds DRs as long as partial vectors are used. */ + if (!vf.is_constant () + && dr_safe_speculative_read_required (stmt_info) + && DR_SCALAR_KNOWN_BOUNDS (dr_info)) + { + dr_set_safe_speculative_read_required (stmt_info, false); + LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true; + } + + do_peeling = vector_alignment_reachable_p (dr_info, vf); if (do_peeling) { if (known_alignment_for_access_p (dr_info, vectype)) @@ -2488,7 +2501,6 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) poly_uint64 nscalars = npeel_tmp; if (unlimited_cost_model (LOOP_VINFO_LOOP (loop_vinfo))) { - poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo); unsigned group_size = 1; if (STMT_SLP_TYPE (stmt_info) && STMT_VINFO_GROUPED_ACCESS (stmt_info)) @@ -2911,14 +2923,12 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) 2) there is at least one unsupported misaligned data ref with an unknown misalignment, and 3) all misaligned data refs with a known misalignment are supported, and - 4) the number of runtime alignment checks is within reason. - 5) the vectorization factor is a constant. */ + 4) the number of runtime alignment checks is within reason. */ do_versioning = (optimize_loop_nest_for_speed_p (loop) && !loop->inner /* FORNOW */ - && loop_cost_model (loop) > VECT_COST_MODEL_CHEAP) - && LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant (); + && loop_cost_model (loop) > VECT_COST_MODEL_CHEAP); if (do_versioning) { @@ -2965,25 +2975,22 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) ?? We could actually unroll the loop to achieve the required overall step alignment, and forcing the alignment could be done by doing some iterations of the non-vectorized loop. */ - if (!multiple_p (LOOP_VINFO_VECT_FACTOR (loop_vinfo) - * DR_STEP_ALIGNMENT (dr), + if (!multiple_p (vf * DR_STEP_ALIGNMENT (dr), DR_TARGET_ALIGNMENT (dr_info))) { do_versioning = false; break; } - /* The rightmost bits of an aligned address must be zeros. - Construct the mask needed for this test. For example, - GET_MODE_SIZE for the vector mode V4SI is 16 bytes so the - mask must be 15 = 0xf. */ - gcc_assert (DR_TARGET_ALIGNMENT (dr_info).is_constant ()); - int mask = DR_TARGET_ALIGNMENT (dr_info).to_constant () - 1; + /* Use "mask = DR_TARGET_ALIGNMENT - 1" to test rightmost address + bits for runtime alignment check. For example, for 16 bytes + target alignment the mask is 15 = 0xf. */ + poly_uint64 mask = DR_TARGET_ALIGNMENT (dr_info) - 1; /* FORNOW: use the same mask to test all potentially unaligned references in the loop. */ - if (LOOP_VINFO_PTR_MASK (loop_vinfo) - && LOOP_VINFO_PTR_MASK (loop_vinfo) != mask) + if (maybe_ne (LOOP_VINFO_PTR_MASK (loop_vinfo), 0U) + && maybe_ne (LOOP_VINFO_PTR_MASK (loop_vinfo), mask)) { do_versioning = false; break; diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 6c1b26a..566308f 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -2454,10 +2454,7 @@ get_misalign_in_elems (gimple **seq, loop_vec_info loop_vinfo) else { tree vla = build_int_cst (type, target_align); - tree vla_align = fold_build2 (BIT_AND_EXPR, type, vla, - fold_build2 (MINUS_EXPR, type, - build_int_cst (type, 0), vla)); - target_align_minus_1 = fold_build2 (MINUS_EXPR, type, vla_align, + target_align_minus_1 = fold_build2 (MINUS_EXPR, type, vla, build_int_cst (type, 1)); } @@ -3840,7 +3837,7 @@ vect_create_cond_for_align_checks (loop_vec_info loop_vinfo, const vec<stmt_vec_info> &may_misalign_stmts = LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo); stmt_vec_info stmt_info; - int mask = LOOP_VINFO_PTR_MASK (loop_vinfo); + poly_uint64 mask = LOOP_VINFO_PTR_MASK (loop_vinfo); tree mask_cst; unsigned int i; tree int_ptrsize_type; @@ -3852,9 +3849,7 @@ vect_create_cond_for_align_checks (loop_vec_info loop_vinfo, tree ptrsize_zero; tree part_cond_expr; - /* Check that mask is one less than a power of 2, i.e., mask is - all zeros followed by all ones. */ - gcc_assert ((mask != 0) && ((mask & (mask+1)) == 0)); + gcc_assert (known_ne (mask, 0U)); int_ptrsize_type = signed_type_for (ptr_type_node); @@ -3962,6 +3957,62 @@ vect_create_cond_for_align_checks (loop_vec_info loop_vinfo, chain_cond_expr (cond_expr, part_cond_expr); } +/* Function vect_create_cond_for_vla_spec_read. + + Create a conditional expression that represents the run-time checks with + max speculative read amount in VLA modes. We check two things: + 1) if the max speculative read amount exceeds the min page size + 2) if the VF is power-of-2 - done by checking the max read amount instead + + Input: + COND_EXPR - input conditional expression. New conditions will be chained + with logical AND operation. + LOOP_VINFO - field LOOP_VINFO_MAX_SPEC_READ_AMOUNT contains the max + possible speculative read amount in VLA modes. + + Output: + COND_EXPR - conditional expression. + + The returned COND_EXPR is the conditional expression to be used in the + if statement that controls which version of the loop gets executed at + runtime. */ + +static void +vect_create_cond_for_vla_spec_read (loop_vec_info loop_vinfo, tree *cond_expr) +{ + poly_uint64 read_amount_poly = LOOP_VINFO_MAX_SPEC_READ_AMOUNT (loop_vinfo); + tree amount = build_int_cst (long_unsigned_type_node, read_amount_poly); + + /* Both the read amount and the VF must be variants, and the read amount must + be a constant power-of-2 multiple of the VF. */ + unsigned HOST_WIDE_INT multiple; + gcc_assert (!read_amount_poly.is_constant () + && !LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant () + && constant_multiple_p (read_amount_poly, + LOOP_VINFO_VECT_FACTOR (loop_vinfo), + &multiple) + && pow2p_hwi (multiple)); + + tree cst_ul_zero = build_int_cstu (long_unsigned_type_node, 0U); + tree cst_ul_one = build_int_cstu (long_unsigned_type_node, 1U); + tree cst_ul_pagesize = build_int_cstu (long_unsigned_type_node, + (unsigned long) param_min_pagesize); + + /* Create an expression of "amount & (amount - 1) == 0". */ + tree amount_m1 = fold_build2 (MINUS_EXPR, long_unsigned_type_node, + amount, cst_ul_one); + tree amount_and_expr = fold_build2 (BIT_AND_EXPR, long_unsigned_type_node, + amount, amount_m1); + tree powof2_cond_expr = fold_build2 (EQ_EXPR, boolean_type_node, + amount_and_expr, cst_ul_zero); + chain_cond_expr (cond_expr, powof2_cond_expr); + + /* Create an expression of "amount <= cst_ul_pagesize". */ + tree pagesize_cond_expr = fold_build2 (LE_EXPR, boolean_type_node, + amount, cst_ul_pagesize); + chain_cond_expr (cond_expr, pagesize_cond_expr); +} + /* If LOOP_VINFO_CHECK_UNEQUAL_ADDRS contains <A1, B1>, ..., <An, Bn>, create a tree representation of: (&A1 != &B1) && ... && (&An != &Bn). Set *COND_EXPR to a tree that is true when both the original *COND_EXPR @@ -4087,6 +4138,7 @@ vect_loop_versioning (loop_vec_info loop_vinfo, gimple_seq gimplify_stmt_list = NULL; tree scalar_loop_iters = LOOP_VINFO_NITERSM1 (loop_vinfo); bool version_align = LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (loop_vinfo); + bool version_spec_read = LOOP_REQUIRES_VERSIONING_FOR_SPEC_READ (loop_vinfo); bool version_alias = LOOP_REQUIRES_VERSIONING_FOR_ALIAS (loop_vinfo); bool version_niter = LOOP_REQUIRES_VERSIONING_FOR_NITERS (loop_vinfo); poly_uint64 versioning_threshold @@ -4145,6 +4197,9 @@ vect_loop_versioning (loop_vec_info loop_vinfo, vect_create_cond_for_align_checks (loop_vinfo, &cond_expr, &cond_expr_stmt_list); + if (version_spec_read) + vect_create_cond_for_vla_spec_read (loop_vinfo, &cond_expr); + if (version_alias) { vect_create_cond_for_unequal_addrs (loop_vinfo, &cond_expr); diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 85f3e90..5fc24dc 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -163,169 +163,6 @@ static void vect_estimate_min_profitable_iters (loop_vec_info, int *, int *, static stmt_vec_info vect_is_simple_reduction (loop_vec_info, stmt_vec_info, bool *, bool *, bool); -/* Subroutine of vect_determine_vf_for_stmt that handles only one - statement. VECTYPE_MAYBE_SET_P is true if STMT_VINFO_VECTYPE - may already be set for general statements (not just data refs). */ - -static opt_result -vect_determine_vectype_for_stmt_1 (vec_info *vinfo, stmt_vec_info stmt_info, - bool vectype_maybe_set_p) -{ - gimple *stmt = stmt_info->stmt; - - if ((!STMT_VINFO_RELEVANT_P (stmt_info) - && !STMT_VINFO_LIVE_P (stmt_info)) - || gimple_clobber_p (stmt)) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, "skip.\n"); - return opt_result::success (); - } - - tree stmt_vectype, nunits_vectype; - opt_result res = vect_get_vector_types_for_stmt (vinfo, stmt_info, - &stmt_vectype, - &nunits_vectype); - if (!res) - return res; - - if (stmt_vectype) - { - if (STMT_VINFO_VECTYPE (stmt_info)) - /* The only case when a vectype had been already set is for stmts - that contain a data ref, or for "pattern-stmts" (stmts generated - by the vectorizer to represent/replace a certain idiom). */ - gcc_assert ((STMT_VINFO_DATA_REF (stmt_info) - || vectype_maybe_set_p) - && STMT_VINFO_VECTYPE (stmt_info) == stmt_vectype); - else - STMT_VINFO_VECTYPE (stmt_info) = stmt_vectype; - } - - return opt_result::success (); -} - -/* Subroutine of vect_determine_vectorization_factor. Set the vector - types of STMT_INFO and all attached pattern statements and update - the vectorization factor VF accordingly. Return true on success - or false if something prevented vectorization. */ - -static opt_result -vect_determine_vectype_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info) -{ - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, "==> examining statement: %G", - stmt_info->stmt); - opt_result res = vect_determine_vectype_for_stmt_1 (vinfo, stmt_info, false); - if (!res) - return res; - - if (STMT_VINFO_IN_PATTERN_P (stmt_info) - && STMT_VINFO_RELATED_STMT (stmt_info)) - { - gimple *pattern_def_seq = STMT_VINFO_PATTERN_DEF_SEQ (stmt_info); - stmt_info = STMT_VINFO_RELATED_STMT (stmt_info); - - /* If a pattern statement has def stmts, analyze them too. */ - for (gimple_stmt_iterator si = gsi_start (pattern_def_seq); - !gsi_end_p (si); gsi_next (&si)) - { - stmt_vec_info def_stmt_info = vinfo->lookup_stmt (gsi_stmt (si)); - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, - "==> examining pattern def stmt: %G", - def_stmt_info->stmt); - res = vect_determine_vectype_for_stmt_1 (vinfo, def_stmt_info, true); - if (!res) - return res; - } - - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, - "==> examining pattern statement: %G", - stmt_info->stmt); - res = vect_determine_vectype_for_stmt_1 (vinfo, stmt_info, true); - if (!res) - return res; - } - - return opt_result::success (); -} - -/* Function vect_set_stmts_vectype - - Set STMT_VINFO_VECTYPE of all stmts. */ - -static opt_result -vect_set_stmts_vectype (loop_vec_info loop_vinfo) -{ - class loop *loop = LOOP_VINFO_LOOP (loop_vinfo); - basic_block *bbs = LOOP_VINFO_BBS (loop_vinfo); - unsigned nbbs = loop->num_nodes; - tree scalar_type = NULL_TREE; - gphi *phi; - tree vectype; - stmt_vec_info stmt_info; - unsigned i; - - DUMP_VECT_SCOPE ("vect_set_stmts_vectype"); - - for (i = 0; i < nbbs; i++) - { - basic_block bb = bbs[i]; - - for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si); - gsi_next (&si)) - { - phi = si.phi (); - stmt_info = loop_vinfo->lookup_stmt (phi); - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, "==> examining phi: %G", - (gimple *) phi); - - gcc_assert (stmt_info); - - if (STMT_VINFO_RELEVANT_P (stmt_info) - || STMT_VINFO_LIVE_P (stmt_info)) - { - gcc_assert (!STMT_VINFO_VECTYPE (stmt_info)); - scalar_type = TREE_TYPE (PHI_RESULT (phi)); - - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, - "get vectype for scalar type: %T\n", - scalar_type); - - vectype = get_vectype_for_scalar_type (loop_vinfo, scalar_type); - if (!vectype) - return opt_result::failure_at (phi, - "not vectorized: unsupported " - "data-type %T\n", - scalar_type); - STMT_VINFO_VECTYPE (stmt_info) = vectype; - - if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, "vectype: %T\n", - vectype); - } - } - - for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si); - gsi_next (&si)) - { - if (is_gimple_debug (gsi_stmt (si))) - continue; - stmt_info = loop_vinfo->lookup_stmt (gsi_stmt (si)); - opt_result res - = vect_determine_vectype_for_stmt (loop_vinfo, stmt_info); - if (!res) - return res; - } - } - - return opt_result::success (); -} - /* Function vect_is_simple_iv_evolution. @@ -1009,6 +846,7 @@ _loop_vec_info::_loop_vec_info (class loop *loop_in, vec_info_shared *shared) unaligned_dr (NULL), peeling_for_alignment (0), ptr_mask (0), + max_spec_read_amount (0), nonlinear_iv (false), ivexpr_map (NULL), scan_map (NULL), @@ -2482,15 +2320,6 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo, bool &fatal, } LOOP_VINFO_MAX_VECT_FACTOR (loop_vinfo) = max_vf; - ok = vect_set_stmts_vectype (loop_vinfo); - if (!ok) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "cannot determine vector types.\n"); - return ok; - } - /* Compute the scalar iteration cost. */ vect_compute_single_scalar_iteration_cost (loop_vinfo); @@ -4956,8 +4785,9 @@ have_whole_vector_shift (machine_mode mode) See vect_emulate_mixed_dot_prod for the actual sequence used. */ static bool -vect_is_emulated_mixed_dot_prod (stmt_vec_info stmt_info) +vect_is_emulated_mixed_dot_prod (slp_tree slp_node) { + stmt_vec_info stmt_info = SLP_TREE_REPRESENTATIVE (slp_node); gassign *assign = dyn_cast<gassign *> (stmt_info->stmt); if (!assign || gimple_assign_rhs_code (assign) != DOT_PROD_EXPR) return false; @@ -4969,7 +4799,7 @@ vect_is_emulated_mixed_dot_prod (stmt_vec_info stmt_info) gcc_assert (STMT_VINFO_REDUC_VECTYPE_IN (stmt_info)); return !directly_supported_p (DOT_PROD_EXPR, - STMT_VINFO_VECTYPE (stmt_info), + SLP_TREE_VECTYPE (slp_node), STMT_VINFO_REDUC_VECTYPE_IN (stmt_info), optab_vector_mixed_sign); } @@ -7118,13 +6948,13 @@ vectorizable_lane_reducing (loop_vec_info loop_vinfo, stmt_vec_info stmt_info, vectype_in); gcc_assert (ncopies_for_cost >= 1); - if (vect_is_emulated_mixed_dot_prod (stmt_info)) + if (vect_is_emulated_mixed_dot_prod (slp_node)) { /* We need extra two invariants: one that contains the minimum signed value and one that contains half of its negative. */ int prologue_stmts = 2; unsigned cost = record_stmt_cost (cost_vec, prologue_stmts, - scalar_to_vec, stmt_info, 0, + scalar_to_vec, slp_node, 0, vect_prologue); if (dump_enabled_p ()) dump_printf (MSG_NOTE, "vectorizable_lane_reducing: " @@ -7134,7 +6964,7 @@ vectorizable_lane_reducing (loop_vec_info loop_vinfo, stmt_vec_info stmt_info, ncopies_for_cost *= 4; } - record_stmt_cost (cost_vec, (int) ncopies_for_cost, vector_stmt, stmt_info, + record_stmt_cost (cost_vec, (int) ncopies_for_cost, vector_stmt, slp_node, 0, vect_body); if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)) @@ -8420,7 +8250,7 @@ vect_transform_reduction (loop_vec_info loop_vinfo, } } - bool emulated_mixed_dot_prod = vect_is_emulated_mixed_dot_prod (stmt_info); + bool emulated_mixed_dot_prod = vect_is_emulated_mixed_dot_prod (slp_node); unsigned num = vec_oprnds[reduc_index == 0 ? 1 : 0].length (); unsigned mask_index = 0; @@ -10141,7 +9971,12 @@ vectorizable_induction (loop_vec_info loop_vinfo, if (peel_mul) { if (!step_mul) - step_mul = peel_mul; + { + gcc_assert (!nunits.is_constant ()); + step_mul = gimple_build (&init_stmts, + MINUS_EXPR, step_vectype, + build_zero_cst (step_vectype), peel_mul); + } else step_mul = gimple_build (&init_stmts, MINUS_EXPR, step_vectype, diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index a6f4db4..26d5be5 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -724,14 +724,21 @@ vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal) if (vect_stmt_relevant_p (phi_info, loop_vinfo, &relevant, &live_p)) vect_mark_relevant (&worklist, phi_info, relevant, live_p); } - for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si)) + for (si = gsi_after_labels (bb); !gsi_end_p (si); gsi_next (&si)) { - if (is_gimple_debug (gsi_stmt (si))) + gimple *stmt = gsi_stmt (si); + if (is_gimple_debug (stmt)) continue; - stmt_vec_info stmt_info = loop_vinfo->lookup_stmt (gsi_stmt (si)); + stmt_vec_info stmt_info = loop_vinfo->lookup_stmt (stmt); if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, - "init: stmt relevant? %G", stmt_info->stmt); + "init: stmt relevant? %G", stmt); + + if (gimple_get_lhs (stmt) == NULL_TREE + && !is_a <gcond *> (stmt) + && !is_a <gcall *> (stmt)) + return opt_result::failure_at + (stmt, "not vectorized: irregular stmt: %G", stmt); if (vect_stmt_relevant_p (stmt_info, loop_vinfo, &relevant, &live_p)) vect_mark_relevant (&worklist, stmt_info, relevant, live_p); @@ -929,8 +936,7 @@ vect_model_simple_cost (vec_info *, int n, slp_tree node, is true the stmt is doing widening arithmetic. */ static void -vect_model_promotion_demotion_cost (stmt_vec_info stmt_info, - enum vect_def_type *dt, +vect_model_promotion_demotion_cost (slp_tree slp_node, unsigned int ncopies, int pwr, stmt_vector_for_cost *cost_vec, bool widen_arith) @@ -943,16 +949,10 @@ vect_model_promotion_demotion_cost (stmt_vec_info stmt_info, inside_cost += record_stmt_cost (cost_vec, ncopies, widen_arith ? vector_stmt : vec_promote_demote, - stmt_info, 0, vect_body); + slp_node, 0, vect_body); ncopies *= 2; } - /* FORNOW: Assuming maximum 2 args per stmts. */ - for (i = 0; i < 2; i++) - if (dt[i] == vect_constant_def || dt[i] == vect_external_def) - prologue_cost += record_stmt_cost (cost_vec, 1, vector_stmt, - stmt_info, 0, vect_prologue); - if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, "vect_model_promotion_demotion_cost: inside_cost = %d, " @@ -2400,70 +2400,26 @@ get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info, /* We can only peel for loops, of course. */ gcc_checking_assert (loop_vinfo); + poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo); + poly_uint64 read_amount + = vf * TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))); + if (STMT_VINFO_GROUPED_ACCESS (stmt_info)) + read_amount *= DR_GROUP_SIZE (DR_GROUP_FIRST_ELEMENT (stmt_info)); + auto target_alignment = DR_TARGET_ALIGNMENT (STMT_VINFO_DR_INFO (stmt_info)); - unsigned HOST_WIDE_INT target_align; - - bool group_aligned = false; - if (target_alignment.is_constant (&target_align) - && nunits.is_constant ()) - { - poly_uint64 vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo); - auto vectype_size - = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))); - poly_uint64 required_alignment = vf * vectype_size; - /* If we have a grouped access we require that the alignment be N * elem. */ - if (STMT_VINFO_GROUPED_ACCESS (stmt_info)) - required_alignment *= - DR_GROUP_SIZE (DR_GROUP_FIRST_ELEMENT (stmt_info)); - if (!multiple_p (target_alignment, required_alignment)) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "desired alignment %wu not met. Instead got %wu " - "for DR alignment at %G", - required_alignment.to_constant (), - target_align, STMT_VINFO_STMT (stmt_info)); - return false; - } - - if (!pow2p_hwi (target_align)) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "non-power-of-two vector alignment %wd " - "for DR alignment at %G", - target_align, STMT_VINFO_STMT (stmt_info)); - return false; - } - - /* For VLA we have to insert a runtime check that the vector loads - per iterations don't exceed a page size. For now we can use - POLY_VALUE_MAX as a proxy as we can't peel for VLA. */ - if (known_gt (required_alignment, (unsigned)param_min_pagesize)) + if (!multiple_p (target_alignment, read_amount)) + { + if (dump_enabled_p ()) { - if (dump_enabled_p ()) - { - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "alignment required for correctness ("); - dump_dec (MSG_MISSED_OPTIMIZATION, required_alignment); - dump_printf (MSG_NOTE, ") may exceed page size\n"); - } - return false; + dump_printf_loc (MSG_NOTE, vect_location, + "desired alignment not met, target was "); + dump_dec (MSG_NOTE, target_alignment); + dump_printf (MSG_NOTE, " previously, but read amount is "); + dump_dec (MSG_NOTE, read_amount); + dump_printf (MSG_NOTE, " at %G.\n", STMT_VINFO_STMT (stmt_info)); } - - group_aligned = true; - } - - /* There are multiple loads that have a misalignment that we couldn't - align. We would need LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P to - vectorize. */ - if (!group_aligned) - { - if (inbounds) - LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true; - else - return false; + return false; } /* When using a group access the first element may be aligned but the @@ -2485,6 +2441,33 @@ get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info, STMT_VINFO_STMT (stmt_info)); return false; } + + /* Reject vectorization if we know the read mount per vector iteration + exceeds the min page size. */ + if (known_gt (read_amount, (unsigned) param_min_pagesize)) + { + if (dump_enabled_p ()) + { + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "alignment required for correctness ("); + dump_dec (MSG_MISSED_OPTIMIZATION, read_amount); + dump_printf (MSG_NOTE, ") may exceed page size.\n"); + } + return false; + } + + if (!vf.is_constant ()) + { + /* For VLA modes, we need a runtime check to ensure any speculative + read amount does not exceed the page size. Here we record the max + possible read amount for the check. */ + if (maybe_gt (read_amount, + LOOP_VINFO_MAX_SPEC_READ_AMOUNT (loop_vinfo))) + LOOP_VINFO_MAX_SPEC_READ_AMOUNT (loop_vinfo) = read_amount; + + /* For VLA modes, we must use partial vectors. */ + LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P (loop_vinfo) = true; + } } if (*alignment_support_scheme == dr_unaligned_unsupported) @@ -5403,7 +5386,7 @@ vectorizable_conversion (vec_info *vinfo, SLP_TREE_TYPE (slp_node) = type_demotion_vec_info_type; /* The final packing step produces one vector result per copy. */ unsigned int nvectors = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node); - vect_model_promotion_demotion_cost (stmt_info, dt, nvectors, + vect_model_promotion_demotion_cost (slp_node, nvectors, multi_step_cvt, cost_vec, widen_arith); } @@ -5415,7 +5398,7 @@ vectorizable_conversion (vec_info *vinfo, so >> MULTI_STEP_CVT divides by 2^(number of steps - 1). */ unsigned int nvectors = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node) >> multi_step_cvt; - vect_model_promotion_demotion_cost (stmt_info, dt, nvectors, + vect_model_promotion_demotion_cost (slp_node, nvectors, multi_step_cvt, cost_vec, widen_arith); } @@ -7794,7 +7777,7 @@ vectorizable_store (vec_info *vinfo, return false; } - tree vectype = SLP_TREE_VECTYPE (stmt_info), rhs_vectype = NULL_TREE; + tree vectype = SLP_TREE_VECTYPE (slp_node), rhs_vectype = NULL_TREE; poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype); if (loop_vinfo) diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index 9653496..041cff8 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -919,7 +919,10 @@ public: int peeling_for_alignment; /* The mask used to check the alignment of pointers or arrays. */ - int ptr_mask; + poly_uint64 ptr_mask; + + /* The maximum speculative read amount in VLA modes for runtime check. */ + poly_uint64 max_spec_read_amount; /* Indicates whether the loop has any non-linear IV. */ bool nonlinear_iv; @@ -1155,6 +1158,7 @@ public: #define LOOP_VINFO_RGROUP_IV_TYPE(L) (L)->rgroup_iv_type #define LOOP_VINFO_PARTIAL_VECTORS_STYLE(L) (L)->partial_vector_style #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask +#define LOOP_VINFO_MAX_SPEC_READ_AMOUNT(L) (L)->max_spec_read_amount #define LOOP_VINFO_LOOP_NEST(L) (L)->shared->loop_nest #define LOOP_VINFO_DATAREFS(L) (L)->shared->datarefs #define LOOP_VINFO_DDRS(L) (L)->shared->ddrs @@ -1209,6 +1213,8 @@ public: #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \ ((L)->may_misalign_stmts.length () > 0) +#define LOOP_REQUIRES_VERSIONING_FOR_SPEC_READ(L) \ + (maybe_gt ((L)->max_spec_read_amount, 0U)) #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \ ((L)->comp_alias_ddrs.length () > 0 \ || (L)->check_unequal_addrs.length () > 0 \ @@ -1219,6 +1225,7 @@ public: (LOOP_VINFO_SIMD_IF_COND (L)) #define LOOP_REQUIRES_VERSIONING(L) \ (LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (L) \ + || LOOP_REQUIRES_VERSIONING_FOR_SPEC_READ (L) \ || LOOP_REQUIRES_VERSIONING_FOR_ALIAS (L) \ || LOOP_REQUIRES_VERSIONING_FOR_NITERS (L) \ || LOOP_REQUIRES_VERSIONING_FOR_SIMD_IF_COND (L)) diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 7deda4b..874a08a 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,15 @@ +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * include/cpplib.h (struct cpp_options): Add cpp_warn_keyword_macro. + (enum cpp_warning_reason): Add CPP_W_KEYWORD_MACRO enumerator. + (cpp_keyword_p): New inline function. + * directives.cc (do_undef): Support -Wkeyword-macro diagnostics. + * macro.cc (warn_of_redefinition): Ignore NODE_WARN flag on nodes + registered for -Wkeyword-macro. + (_cpp_create_definition): Support -Wkeyword-macro diagnostics. + Formatting fixes. + 2025-08-05 Jakub Jelinek <jakub@redhat.com> PR preprocessor/120778 diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index 882117d..830685f 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,25 @@ +2025-08-08 Christophe Lyon <christophe.lyon@linaro.org> + + PR libgcc/117600 + * Makefile.in (WERROR): New. + * config/aarch64/t-aarch64: Handle WERROR. + * configure: Regenerate. + * configure.ac: Add support for --enable-werror. + +2025-08-07 Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org> + + * config/s390/libgcc-glibc.ver: Export _BitInt support + functions. + * config/s390/t-softfp (softfp_extras): Add fixtfbitint + floatbitinttf. + +2025-08-07 Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org> + + * config.host: Include makefiles t-softfp for -m64. + * config/s390/sfp-exceptions.c: New file. + * config/s390/sfp-machine.h: New file. + * config/s390/t-softfp: New file. + 2025-08-06 Jakub Jelinek <jakub@redhat.com> PR libgcc/121397 diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index f7b48dc..e258f94 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -87,6 +87,7 @@ CC = @CC@ CFLAGS = @CFLAGS@ RANLIB = @RANLIB@ LN_S = @LN_S@ +WERROR = @WERROR@ PWD_COMMAND = $${PWDCMD-pwd} diff --git a/libgcc/config/aarch64/t-aarch64 b/libgcc/config/aarch64/t-aarch64 index d4c5922..c7d83c7 100644 --- a/libgcc/config/aarch64/t-aarch64 +++ b/libgcc/config/aarch64/t-aarch64 @@ -30,4 +30,4 @@ LIB2ADDEH += \ $(srcdir)/config/aarch64/__arm_za_disable.S SHLIB_MAPFILES += $(srcdir)/config/aarch64/libgcc-sme.ver -LIBGCC2_CFLAGS += -Werror -Wno-prio-ctor-dtor +LIBGCC2_CFLAGS += $(WERROR) -Wno-prio-ctor-dtor diff --git a/libgcc/configure b/libgcc/configure index 1841833..d5e80d2 100755 --- a/libgcc/configure +++ b/libgcc/configure @@ -586,6 +586,7 @@ ac_unique_file="static-object.mk" ac_includes_default='/* none */' ac_subst_vars='LTLIBOBJS LIBOBJS +WERROR md_unwind_header md_unwind_def_header unwind_header @@ -720,6 +721,7 @@ enable_tm_clone_registry with_glibc_version enable_tls with_gcc_major_version_only +enable_werror ' ac_precious_vars='build_alias host_alias @@ -1362,6 +1364,7 @@ Optional Features: installations without PT_GNU_EH_FRAME support --disable-tm-clone-registry disable TM clone registry --enable-tls Use thread-local storage [default=yes] + --enable-werror build with -Werror for selected targets Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -5789,6 +5792,22 @@ fi +# Check whether --enable-werror was given. +if test "${enable_werror+set}" = set; then : + enableval=$enable_werror; +case ${enable_werror} in + no) WERROR="" ;; + *) WERROR="-Werror" ;; +esac + +else + +WERROR="-Werror" + +fi + + + # We need multilib support. ac_config_files="$ac_config_files Makefile" diff --git a/libgcc/configure.ac b/libgcc/configure.ac index 85e4f1b..65cd3c6 100644 --- a/libgcc/configure.ac +++ b/libgcc/configure.ac @@ -733,6 +733,20 @@ AC_SUBST(md_unwind_header) AC_SUBST(sfp_machine_header) AC_SUBST(thread_header) +AC_ARG_ENABLE(werror, +[AS_HELP_STRING([--enable-werror], + [build with -Werror for selected targets])], +[ +case ${enable_werror} in + no) WERROR="" ;; + *) WERROR="-Werror" ;; +esac +], +[ +WERROR="-Werror" +]) +AC_SUBST(WERROR) + # We need multilib support. AC_CONFIG_FILES([Makefile]) AC_CONFIG_COMMANDS([default], diff --git a/libgcobol/ChangeLog b/libgcobol/ChangeLog index 91a3b86..38b6dbc 100644 --- a/libgcobol/ChangeLog +++ b/libgcobol/ChangeLog @@ -1,3 +1,22 @@ +2025-08-08 Robert Dubner <rdubner@symas.com> + + * libgcobol.cc (int128_to_field): Switch to the new routine. + * stringbin.cc (packed_from_combined): Implement the new routine. + (__gg__binary_to_packed): Likewise. + * stringbin.h (__gg__binary_to_packed): Likewise. + +2025-08-07 Robert Dubner <rdubner@symas.com> + + * Makefile.am: Include new stringbin.cc file. + * Makefile.in: Regenerated. + * libgcobol.cc (__gg__power_of_ten): Improve error message. + (__gg__binary_to_string): Deleted. + (__gg__binary_to_string_internal): Deleted. + (int128_to_field): Use new conversion routine. + (__gg__move): Use new conversion routine. + * stringbin.cc: New file. Implements new conversion routine. + * stringbin.h: New file. Likewise. + 2025-07-13 Robert Dubner <rdubner@symas.com> * common-defs.h (PTRCAST): Moved here from libgcobol.h. diff --git a/libgcobol/Makefile.am b/libgcobol/Makefile.am index 0a17d20..1e3d3432 100644 --- a/libgcobol/Makefile.am +++ b/libgcobol/Makefile.am @@ -42,6 +42,7 @@ libgcobol_la_SOURCES = \ intrinsic.cc \ io.cc \ libgcobol.cc \ + stringbin.cc \ valconv.cc WARN_CFLAGS = -W -Wall -Wwrite-strings diff --git a/libgcobol/Makefile.in b/libgcobol/Makefile.in index 5fdc42c..42dc823 100644 --- a/libgcobol/Makefile.in +++ b/libgcobol/Makefile.in @@ -178,7 +178,7 @@ libgcobol_la_LIBADD = @BUILD_LIBGCOBOL_TRUE@am_libgcobol_la_OBJECTS = charmaps.lo \ @BUILD_LIBGCOBOL_TRUE@ constants.lo gfileio.lo gmath.lo \ @BUILD_LIBGCOBOL_TRUE@ intrinsic.lo io.lo libgcobol.lo \ -@BUILD_LIBGCOBOL_TRUE@ valconv.lo +@BUILD_LIBGCOBOL_TRUE@ stringbin.lo valconv.lo libgcobol_la_OBJECTS = $(am_libgcobol_la_OBJECTS) @BUILD_LIBGCOBOL_TRUE@am_libgcobol_la_rpath = -rpath $(toolexeclibdir) AM_V_P = $(am__v_P_@AM_V@) @@ -404,6 +404,7 @@ gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER) @BUILD_LIBGCOBOL_TRUE@ intrinsic.cc \ @BUILD_LIBGCOBOL_TRUE@ io.cc \ @BUILD_LIBGCOBOL_TRUE@ libgcobol.cc \ +@BUILD_LIBGCOBOL_TRUE@ stringbin.cc \ @BUILD_LIBGCOBOL_TRUE@ valconv.cc @BUILD_LIBGCOBOL_TRUE@WARN_CFLAGS = -W -Wall -Wwrite-strings @@ -526,6 +527,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intrinsic.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgcobol.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stringbin.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/valconv.Plo@am__quote@ .cc.o: diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc index c3d78d4..eac6e31 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -72,6 +72,8 @@ #include <sys/time.h> #include <execinfo.h> #include "exceptl.h" +#include "stringbin.h" + /* BSD extension. */ #if !defined(LOG_PERROR) @@ -798,7 +800,7 @@ __gg__power_of_ten(int n) fprintf(stderr, "Trying to raise 10 to %d as an int128, which we can't do.\n", n); - fprintf(stderr, "The problem is in %s.\n", __func__); + fprintf(stderr, "The problem is in %s %s:%d.\n", __func__, __FILE__, __LINE__); abort(); } if( n <= MAX_POWER ) @@ -875,56 +877,6 @@ __gg__scale_by_power_of_ten_2(__int128 value, int N) return value; } -extern "C" -bool -__gg__binary_to_string(char *result, int digits, __int128 value) - { - // The result is not terminated, because this routine is used - // to put information directly into cblc_field_t::data - // Our caller has to keep track of whether value was negative. - - // Note that this routine operates in the source code-set space; that is - // the result comes back with zero as an ASCII 0x30, not an EBCDIC 0xF0 - - if( value < 0 ) - { - value = -value; - } - result += digits-1 ; - while( digits-- ) - { - *result-- = value%10 + ascii_zero; - value /= 10; - } - // Should value be non-zero, it means we potentially have a size error - return value != 0; - } - -extern "C" -bool -__gg__binary_to_string_internal(char *result, int digits, __int128 value) - { - // The result is not terminated, because this routine is used - // to put information directly into cblc_field_t::data - // Our caller has to keep track of whether value was negative. - - // Note that this routine operates in the source code-set space; that is - // the result comes back with zero as an ASCII 0x30, not an EBCDIC 0xF0 - - if( value < 0 ) - { - value = -value; - } - result += digits-1 ; - while( digits-- ) - { - *result-- = (value%10) + internal_zero; - value /= 10; - } - // Should value be non-zero, it means we potentially have a size error - return value != 0; - } - static bool value_is_too_big(const cblc_field_t *var, __int128 value, @@ -1617,9 +1569,13 @@ int128_to_field(cblc_field_t *var, // Note that sending a signed value to an alphanumeric strips off // any plus or minus signs. + memset(location, 0, length); size_error = __gg__binary_to_string_internal( - PTRCAST(char, location), - length, value); + PTRCAST(char, location), + length > MAX_FIXED_POINT_DIGITS + ? MAX_FIXED_POINT_DIGITS + : length, + value); break; case FldNumericDisplay: @@ -1708,7 +1664,7 @@ int128_to_field(cblc_field_t *var, // At this point, value is scaled to the target's rdigits - size_error = __gg__binary_to_string(ach, var->digits, value); + size_error = __gg__binary_to_string_ascii(ach, var->digits, value); ach[var->digits] = NULLCH; // Convert that string according to the PICTURE clause @@ -1749,7 +1705,7 @@ int128_to_field(cblc_field_t *var, case FldAlphaEdited: { char ach[128]; - size_error = __gg__binary_to_string(ach, length, value); + size_error = __gg__binary_to_string_ascii(ach, length, value); ach[length] = NULLCH; // Convert that string according to the PICTURE clause @@ -1763,34 +1719,27 @@ int128_to_field(cblc_field_t *var, case FldPacked: { - static const unsigned char bin2pd[100] = - { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, - } ; - // Convert the binary value to packed decimal. + int digits = var->digits; - // Set the destination bytes to zero - memset(location, 0, length); + // Assume for the moment that the res unsigned char sign_nybble = 0; - if( !(var->attr & packed_no_sign_e) ) + if( var->attr & packed_no_sign_e ) + { + // This is COMP-6 packed decimal, with no sign nybble + sign_nybble = 0; + } + else { // This is COMP-3 packed decimal, so we need to make room to the // right of the final decimal digit for the sign nybble: value *= 10; + digits += 1; // Figure out what the sign nybble is going to be, and make the // the value positive: if(var->attr & signable_e) { + // It is signable, so 0xD for negative, and 0xC for positive if(value < 0) { sign_nybble = 0x0D; @@ -1803,6 +1752,7 @@ int128_to_field(cblc_field_t *var, } else { + // The value is not signable, so the sign nybble is 0xF sign_nybble = 0x0F; if(value < 0) { @@ -1810,43 +1760,25 @@ int128_to_field(cblc_field_t *var, } } } - // ploc points to the current rightmost byte of the location: - unsigned char *ploc = location + length -1 ; - // Build the target from right to left, so that the result is - // big-endian: - while( value && ploc >= location ) - { - *ploc-- = bin2pd[value%100]; - value /= 100; - } + /* We need to check if the value is too big, in case our caller + wants to check for the error condition. In any event, we need + to make sure the value actually fits, because otherwise the + result might have a bad high-place digit for a value with an + odd number of places. */ + + __int128 mask = __gg__power_of_ten(digits); + size_error = !!(value / mask); + value %= mask; + // We are now set up to do the conversion: + __gg__binary_to_packed(location, digits, value); + // We can put the sign nybble into place at this point. Note that // for COMP-6 numbers the sign_nybble value is zero, so the next // operation is harmless. location[length -1] |= sign_nybble; - // If we still have value left, we have a size error - if( value ) - { - size_error = true; - } - else - { - if( ( sign_nybble && !(var->digits&1) ) - || ( !sign_nybble && (var->digits&1) ) ) - { - // This is either - // comp-3 with an even number of digits, or - // comp-6 with an odd number of digits. - // Either way, the first byte of the target has to have a high - // nybble of zero. If it's non-zero, then we have a size error: - if( location[0] & 0xF0 ) - { - size_error = true; - } - } - } // And we're done. break; } @@ -6126,7 +6058,7 @@ __gg__move( cblc_field_t *fdest, // Convert it to the full complement of digits available // from the source...but no more - __gg__binary_to_string(ach, source_digits, value); + __gg__binary_to_string_ascii(ach, source_digits, value); // Binary to string returns ASCII characters: for(int i=0; i<source_digits; i++) diff --git a/libgcobol/stringbin.cc b/libgcobol/stringbin.cc new file mode 100644 index 0000000..2cc229e --- /dev/null +++ b/libgcobol/stringbin.cc @@ -0,0 +1,477 @@ +/* + * Copyright (c) 2021-2025 Symas Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the Symas Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <algorithm> +#include <cctype> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <ctime> +#include <set> +#include <stack> +#include <string> +#include <unordered_map> +#include <vector> + +#include <dirent.h> +#include <dlfcn.h> +#include <err.h> +#include <fcntl.h> +#include <fenv.h> +#include <math.h> // required for fpclassify(3), not in cmath +#include <setjmp.h> +#include <signal.h> +#include <syslog.h> +#include <unistd.h> +#include <stdarg.h> +#if __has_include(<errno.h>) +# include <errno.h> // for program_invocation_short_name +#endif + +#include "config.h" +#include "libgcobol-fp.h" + +#include "ec.h" +#include "common-defs.h" +#include "io.h" +#include "gcobolio.h" +#include "libgcobol.h" +#include "gfileio.h" +#include "charmaps.h" +#include "valconv.h" +#include <sys/mman.h> +#include <sys/resource.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/time.h> +#include <execinfo.h> +#include "exceptl.h" +#include "stringbin.h" + +/* This routine evolved from a primitive binary-to-string routine that simply + peeled digits off the bottom of an __int128 by using + + value % 10 + '0'; + value /= 10; + + That turns out to be unnecessarily slow. + + The routine implemented here uses a divide-and-conquer approach to + minimimizing the number of operations, and when you get down to two + digits it does a divide-by-100 and uses the remainder in a table lookup + to get the digits. */ + +/* These static tables are born of a pathologic desire to avoid calculations. + Whether that paranoia is justified (perhaps "digit%10 + '0';" ) would + actually be faster) is currently untested. But I figured this would be + pretty darn fast. + + Use them when you know the index is between zero and one hundred. */ + +static const char digit_low[100] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + }; + +static const char digit_high[100] = + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + }; + +static char combined_string[128]; +static char zero_char; + +typedef struct + { + int start; + int run; + union + { + unsigned __int128 val128; + uint64_t val64; + uint32_t val32; + uint16_t val16; + uint8_t val8; + }; + } COMBINED; + +static +void +string_from_combined(const COMBINED &combined) + { + COMBINED left; + COMBINED right; + + uint16_t v16; + + switch(combined.run) + { + case 1: + // We know that val8 is a single digit + combined_string[combined.start] = combined.val8 + zero_char;; + break; + + case 2: + // We know that val8 has two digits + combined_string[combined.start] = digit_high[combined.val8] + zero_char; + combined_string[combined.start+1] = digit_low [combined.val8] + zero_char; + break; + + case 3: + // We know that val16 has three digits. + v16 = combined.val16; + combined_string[combined.start] = v16 / 100 + zero_char; + v16 %= 100; + combined_string[combined.start+1] = v16 / 10 + zero_char; + combined_string[combined.start+2] = v16 % 10 + zero_char; + break; + + case 4: + // We know that val16 has four digits: + v16 = combined.val16; + combined_string[combined.start] = v16 / 1000 + zero_char; + v16 %= 1000; + combined_string[combined.start+1] = v16 / 100 + zero_char; + v16 %= 100; + combined_string[combined.start+2] = v16 / 10 + zero_char; + combined_string[combined.start+3] = v16 % 10 + zero_char; + break; + + case 5: + case 6: + case 7: + case 8: + // We know that val32 can be treated as two 4-digit pieces + left.start = combined.start; + left.run = combined.run - 4; + left.val16 = combined.val32 / 10000; + + right.start = combined.start+left.run; + right.run = 4; + right.val16 = combined.val32 % 10000; + + string_from_combined(left); + string_from_combined(right); + break; + + case 9: + // We break val32 into a 1-digit piece, and an 8-digit piece: + left.start = combined.start; + left.run = combined.run - 8; + left.val32 = combined.val32 / 100000000; + + right.start = combined.start+left.run; + right.run = 8; + right.val32 = combined.val32 % 100000000; + + string_from_combined(left); + string_from_combined(right); + break; + + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + // We know we can treat val64 as two 9-digit pieces: + left.start = combined.start; + left.run = combined.run - 9; + left.val32 = combined.val64 / 1000000000; + + right.start = combined.start+left.run; + right.run = 9; + right.val32 = combined.val64 % 1000000000; + + string_from_combined(left); + string_from_combined(right); + break; + + case 19: + // We split off the bottom nine digits + left.start = combined.start; + left.run = combined.run - 9; + left.val64 = combined.val64 / 1000000000; + + right.start = combined.start+left.run; + right.run = 9; + right.val32 = combined.val64 % 1000000000; + + string_from_combined(left); + string_from_combined(right); + break; + + default: + // For twenty or more digits we peel eighteen digits at a time off the + // right side: + left.start = combined.start; + left.run = combined.run - 18; + left.val128 = combined.val128 / 1000000000000000000ULL; + + right.start = combined.start+left.run; + right.run = 18; + right.val64 = combined.val128 % 1000000000000000000ULL; + + string_from_combined(left); + string_from_combined(right); + break; + } + } + +bool +__gg__binary_to_string_ascii(char *result, int digits, __int128 value) + { + zero_char = ascii_zero; + + // Note that this routine does not terminate the generated string with a + // NUL. This routine is sometimes used to generate a NumericDisplay string + // of digits in place, with no terminator. + __int128 mask = __gg__power_of_ten(digits); + + COMBINED combined; + if( value < 0 ) + { + value = -value; + } + + // A non-zero retval means the number was too big to fit into the desired + // number of digits: + bool retval = !!(value / mask); + + // mask off the bottom digits to avoid garbage when value is too large + value %= mask; + + combined.start = 0; + combined.run = digits; + combined.val128 = value; + string_from_combined(combined); + memcpy(result, combined_string, digits); + return retval; + } + +bool +__gg__binary_to_string_internal(char *result, int digits, __int128 value) + { + zero_char = internal_zero; + + // Note that this routine does not terminate the generated string with a + // NUL. This routine is sometimes used to generate a NumericDisplay string + // of digits in place, with no terminator. + __int128 mask = __gg__power_of_ten(digits); + + COMBINED combined; + if( value < 0 ) + { + value = -value; + } + + // A non-zero retval means the number was too big to fit into the desired + // number of digits: + bool retval = !!(value / mask); + + // mask off the bottom digits to avoid garbage when value is too large + value %= mask; + + combined.start = 0; + combined.run = digits; + combined.val128 = value; + string_from_combined(combined); + memcpy(result, combined_string, digits); + return retval; + } + + +static +void +packed_from_combined(COMBINED &combined) + { + /* The combined.value must be positive at this point. + + The combined.run value has to be the number of places needed to hold + combined.value. The proper calculation is (digits+1)/2. + + For a signable value, the caller had to multiple the original value by + ten to create room on the right for the sign nybble. */ + + static const unsigned char bin2pd[100] = + { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + } ; + + COMBINED left; + COMBINED right; + + switch(combined.run) + { + case 1: + // We know that val8 has two digits. + combined_string[combined.start] = bin2pd[combined.val8]; + break; + + case 2: + // We know that val16 has four digits. + combined_string[combined.start ] = bin2pd[combined.val16/100]; + combined_string[combined.start+1] = bin2pd[combined.val16%100]; + break; + + case 3: + case 4: + // We know that val32 can hold up to eight digits. Break it in half. + left.start = combined.start; + left.run = combined.run - 2; + left.val16 = combined.val32 / 10000; + + right.start = combined.start+left.run; + right.run = 2; + right.val16 = combined.val32 % 10000; + + packed_from_combined(left); + packed_from_combined(right); + break; + + case 5: + case 6: + case 7: + case 8: + // We know that val64 is holding up to 18 digits. Break it into two + // eight-digit places that can each go into a val23 + left.start = combined.start; + left.run = combined.run - 4; + left.val32 = combined.val64 / 100000000; + + right.start = combined.start+left.run; + right.run = 4; + right.val32 = combined.val64 % 100000000; + + packed_from_combined(left); + packed_from_combined(right); + break; + + case 9: + // We know that val64 is holding 17 or 18 digits. Break off the + // bottom eight. + left.start = combined.start; + left.run = combined.run - 4; + left.val64 = combined.val64 / 100000000; + + right.start = combined.start+left.run; + right.run = 4; + right.val32 = combined.val64 % 100000000; + + packed_from_combined(left); + packed_from_combined(right); + break; + + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + // We know that val64 is holding between 18 and 36 digits. Break it + // two val64: + + left.start = combined.start; + left.run = combined.run - 9; + left.val64 = combined.val128 / 1000000000000000000ULL; + + right.start = combined.start+left.run; + right.run = 9; + right.val64 = combined.val128 % 1000000000000000000ULL; + + packed_from_combined(left); + packed_from_combined(right); + break; + + default: + // For twenty or more digits we peel eighteen digits at a time off the + // right side: + left.start = combined.start; + left.run = combined.run - 9; + left.val128 = combined.val128 / 1000000000000000000ULL; + + right.start = combined.start+left.run; + right.run = 9; + right.val64 = combined.val128 % 1000000000000000000ULL; + + packed_from_combined(left); + packed_from_combined(right); + break; + } + } + +extern "C" +void +__gg__binary_to_packed( unsigned char *result, + int digits, + __int128 value) + { + size_t length = (digits+1)/2; + + COMBINED combined; + combined.start = 0; + combined.run = length; + combined.val128 = value; + packed_from_combined(combined); + memcpy(result, combined_string, length); + } diff --git a/libgcobol/stringbin.h b/libgcobol/stringbin.h new file mode 100644 index 0000000..5ddb441 --- /dev/null +++ b/libgcobol/stringbin.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021-2025 Symas Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of the Symas Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef STRINGBIN_H_ +#define STRINGBIN_H_ + +extern "C" +bool __gg__binary_to_string_ascii(char *result, + int digits, + __int128 value); +extern "C" +bool __gg__binary_to_string_internal( char *result, + int digits, + __int128 value); + +extern "C" +void __gg__binary_to_packed( unsigned char *result, + int digits, + __int128 value); + +#endif diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 09ee090..72a8610 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2025-08-07 Gerald Pfeifer <gerald@pfeifer.com> + + * doc/xml/manual/build_hacking.xml: Switch gcc.gnu.org installation + docs to https. + * doc/html/manual/appendix_porting.html: Regenerate. + 2025-08-05 Jakub Jelinek <jakub@redhat.com> PR libstdc++/121373 diff --git a/libstdc++-v3/doc/html/manual/appendix_porting.html b/libstdc++-v3/doc/html/manual/appendix_porting.html index 887fa50..7b63613 100644 --- a/libstdc++-v3/doc/html/manual/appendix_porting.html +++ b/libstdc++-v3/doc/html/manual/appendix_porting.html @@ -26,7 +26,7 @@ Support for C++11 dialect. </a></span></dt><dt><span class="section"><a href="backwards.html#backwards.third.iterator_type"> <code class="code">Container::iterator_type</code> is not necessarily <code class="code">Container::value_type*</code> </a></span></dt></dl></dd></dl></dd></dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="appendix.porting.build_hacking"></a>Configure and Build Hacking</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="build_hacking.prereq"></a>Prerequisites</h3></div></div></div><p> - As noted <a class="link" href="http://gcc.gnu.org/install/prerequisites.html" target="_top">previously</a>, + As noted <a class="link" href="https://gcc.gnu.org/install/prerequisites.html" target="_top">previously</a>, certain other tools are necessary for hacking on files that control configure (<code class="code">configure.ac</code>, <code class="code">acinclude.m4</code>) and make diff --git a/libstdc++-v3/doc/xml/manual/build_hacking.xml b/libstdc++-v3/doc/xml/manual/build_hacking.xml index 20de49f..4c044d9 100644 --- a/libstdc++-v3/doc/xml/manual/build_hacking.xml +++ b/libstdc++-v3/doc/xml/manual/build_hacking.xml @@ -17,7 +17,7 @@ <section xml:id="build_hacking.prereq"><info><title>Prerequisites</title></info> <para> - As noted <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/prerequisites.html">previously</link>, + As noted <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/install/prerequisites.html">previously</link>, certain other tools are necessary for hacking on files that control configure (<code>configure.ac</code>, <code>acinclude.m4</code>) and make |