diff options
307 files changed, 18256 insertions, 3415 deletions
diff --git a/contrib/ChangeLog b/contrib/ChangeLog index a4f8bb3..d883133 100644 --- a/contrib/ChangeLog +++ b/contrib/ChangeLog @@ -1,3 +1,8 @@ +2025-07-11 Richard Biener <rguenther@suse.de> + + * gcc-changelog/git_update_version.py: Stop updating gcc-12 + branch. + 2025-07-08 Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> * prepare-commit-msg: Force default git prefixes. diff --git a/contrib/gcc-changelog/git_update_version.py b/contrib/gcc-changelog/git_update_version.py index aa9adee..b3ea33b 100755 --- a/contrib/gcc-changelog/git_update_version.py +++ b/contrib/gcc-changelog/git_update_version.py @@ -85,7 +85,7 @@ def prepend_to_changelog_files(repo, folder, git_commit, add_to_git): repo.git.add(full_path) -active_refs = ['master', 'releases/gcc-12', +active_refs = ['master', 'releases/gcc-13', 'releases/gcc-14', 'releases/gcc-15'] parser = argparse.ArgumentParser(description='Update DATESTAMP and generate ' diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0ac20fd..76fd227 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,548 @@ +2025-07-11 David Malcolm <dmalcolm@redhat.com> + + * diagnostic-format-html.cc: Include "diagnostic-format-sarif.h", + Replace include of "diagnostic-state.h" with includes of + "diagnostic-digraphs.h" and "diagnostic-state-graphs.h". + (html_generation_options::html_generation_options): Update for + field renaming. + (html_builder::m_body_element): New field. + (html_builder::html_builder): Initialize m_body_element. + (html_builder::maybe_make_state_diagram): Port from XML + implementation to state graph implementation. + (html_builder::make_element_for_diagnostic): Add any + per-diagnostic graphs. + (html_builder::add_graph): New. + (html_builder::emit_global_graph): New. + (html_output_format::report_global_digraph): New. + * diagnostic-format-html.h + (html_generation_options::m_show_state_diagram_xml): Replace + with... + (html_generation_options::m_show_state_diagrams_sarif): ...this. + (html_generation_options::m_show_state_diagram_dot_src): Rename + to... + (html_generation_options::m_show_state_diagrams_dot_src): ...this. + * diagnostic-format-sarif.cc: Include "diagnostic-digraphs.h" and + "diagnostic-state-graphs.h". + (sarif_builder::m_run_graphs): New field. + (sarif_result::on_nested_diagnostic): Update call to + make_location_object to pass arg by pointer. + (sarif_builder::sarif_builder): Initialize m_run_graphs. + (sarif_builder::report_global_digraph): New. + (sarif_builder::make_result_object): Add any graphs to + the result object. + (sarif_builder::make_locations_arr): Update call to + make_location_object to pass arg by pointer. + (sarif_builder::make_location_object): Pass param "loc_mgr" by + pointer rather than by reference so that it can be null, and + handle this case. + (copy_any_property_bag): New. + (make_sarif_graph): New. + (make_sarif_node): New. + (make_sarif_edge): New. + (sarif_property_bag::set_graph): New. + (populate_thread_flow_location_object): Port from XML + implementation to state graph implementation. + (make_run_object): Store any graphs. + (sarif_output_format::report_global_digraph): New. + (sarif_generation_options::sarif_generation_options): Rename + m_xml_state to m_state_graph. + (selftest::test_make_location_object): Update for change to + make_location_object. + * diagnostic-format-sarif.h: + (sarif_generation_options::m_xml_state): Replace with... + (sarif_generation_options::m_state_graph): ...this. + (class sarif_location_manager): Add forward decl. + (diagnostics::digraphs::digraph): New forward decl. + (diagnostics::digraphs::node): New forward decl. + (diagnostics::digraphs::edge): New forward decl. + (sarif_property_bag::set_graph): New decl. + (class sarif_graph): New. + (class sarif_node): New. + (class sarif_edge): New. + (make_sarif_graph): New decl. + (make_sarif_node): New decl. + (make_sarif_edge): New decl. + * diagnostic-format-text.h + (diagnostic_text_output_format::report_global_digraph): New. + * diagnostic-format.h + (diagnostic_output_format::report_global_digraph): New vfunc. + * diagnostic-digraphs.cc: New file. + * diagnostic-digraphs.h: New file. + * diagnostic-metadata.h (diagnostics::digraphs::lazy_digraphs): + New forward decl. + (diagnostic_metadata::diagnostic_metadata): Initialize + m_lazy_digraphs. + (diagnostic_metadata::set_lazy_digraphs): New. + (diagnostic_metadata::get_lazy_digraphs): New. + (diagnostic_metadata::m_lazy_digraphs): New field. + * diagnostic-output-spec.cc (sarif_scheme_handler::make_sink): + Update for XML to state graph changes. + (sarif_scheme_handler::make_sarif_gen_opts): Likewise. + (html_scheme_handler::make_sink): Rename "show-state-diagram-xml" + to "show-state-diagrams-sarif" and use pluralization consistently. + * diagnostic-path.cc: Replace include of "xml.h" with + "diagnostic-state-graphs.h". + (diagnostic_event::maybe_make_xml_state): Replace with... + (diagnostic_event::maybe_make_diagnostic_state_graph): ...this. + * diagnostic-path.h (diagnostics::digraphs::digraph): New forward + decl. + (diagnostic_event::maybe_make_xml_state): Replace with... + (diagnostic_event::maybe_make_diagnostic_state_graph): ...this. + * diagnostic-state-graphs.cc: New file. + * diagnostic-state-graphs.h: New file. + * diagnostic-state-to-dot.cc: Port implementation from XML to + state graphs. + * diagnostic-state.h: Deleted file. + * diagnostic.cc (diagnostic_context::report_global_digraph): New. + * diagnostic.h (diagnostics::digraphs::lazy_digraph): New forward + decl. + (diagnostic_context::report_global_digraph): New decl. + * doc/analyzer.texi (Debugging the Analyzer): Update to reflect + change from XML to state graphs. + * doc/invoke.texi ("sarif" diagnostics sink): Replace "xml-state" + with "state-graphs". + ("experimental-html" diagnostics sink): Replace + "show-state-diagrams-xml" with "show-state-diagrams-sarif" + * doc/libgdiagnostics/topics/compatibility.rst + (LIBGDIAGNOSTICS_ABI_3): New. + * doc/libgdiagnostics/topics/graphs.rst: New file. + * doc/libgdiagnostics/topics/index.rst: Add graphs.rst. + * graphviz.h (node_id::operator=): New. + * json.h (json::value::dyn_cast_string): New. + (json::object::get_num_keys): New accessor. + (json::object::get_key): New accessor. + (json::string::dyn_cast_string): New. + * libgdiagnostics++.h (class libgdiagnostics::graph): New. + (class libgdiagnostics::node): New. + (class libgdiagnostics::edge): New. + (class libgdiagnostics::diagnostic::take_graph): New. + (class libgdiagnostics::manager::take_global_graph): New. + (class libgdiagnostics::graph::set_description): New. + (class libgdiagnostics::graph::get_node_by_id): New. + (class libgdiagnostics::graph::get_edge_by_id): New. + (class libgdiagnostics::graph::add_edge): New. + (class libgdiagnostics::node::set_label): New. + (class libgdiagnostics::node::set_location): New. + (class libgdiagnostics::node::set_logical_location): New. + * libgdiagnostics-private.h: New file. + * libgdiagnostics.cc: Define INCLUDE_STRING. Include + "diagnostic-digraphs.h", "diagnostic-state-graphs.h", and + "libgdiagnostics-private.h". + (struct diagnostic_graph): New. + (struct diagnostic_node): New. + (struct diagnostic_edge): New. + (libgdiagnostics_path_event::libgdiagnostics_path_event): Add + state_graph param. + (libgdiagnostics_path_event::maybe_make_diagnostic_state_graph): + New. + (libgdiagnostics_path_event::m_state_graph): New field. + (diagnostic_execution_path::add_event_va): Add state_graph param. + (class prebuilt_digraphs): New. + (diagnostic::diagnostic): Use m_graphs in m_metadata. + (diagnostic::take_graph): New. + (diagnostic::get_graphs): New accessor. + (diagnostic::m_graphs): New field. + (diagnostic_manager::take_global_graph): New. + (diagnostic_execution_path_add_event): Update for new param to + add_event_va. + (diagnostic_execution_path_add_event_va): Likewise. + (diagnostic_graph::add_node_with_id): New public entrypoint. + (diagnostic_graph::add_edge_with_label): New public entrypoint. + (diagnostic_manager_new_graph): New public entrypoint. + (diagnostic_manager_take_global_graph): New public entrypoint. + (diagnostic_take_graph): New public entrypoint. + (diagnostic_graph_release): New public entrypoint. + (diagnostic_graph_set_description): New public entrypoint. + (diagnostic_graph_add_node): New public entrypoint. + (diagnostic_graph_add_edge): New public entrypoint. + (diagnostic_graph_get_node_by_id): New public entrypoint. + (diagnostic_graph_get_edge_by_id): New public entrypoint. + (diagnostic_node_set_location): New public entrypoint. + (diagnostic_node_set_label): New public entrypoint. + (diagnostic_node_set_logical_location): New public entrypoint. + (private_diagnostic_execution_path_add_event_2): New private + entrypoint. + (private_diagnostic_graph_set_property_bag): New private + entrypoint. + (private_diagnostic_node_set_property_bag): New private + entrypoint. + (private_diagnostic_edge_set_property_bag): New private + entrypoint. + * libgdiagnostics.h (diagnostic_graph): New typedef. + (diagnostic_node): New typedef. + (diagnostic_edge): New typedef. + (diagnostic_manager_new_graph): New decl. + (diagnostic_manager_take_global_graph): New decl. + (diagnostic_take_graph): New decl. + (diagnostic_graph_release): New decl. + (diagnostic_graph_set_description): New decl. + (diagnostic_graph_add_node): New decl. + (diagnostic_graph_add_edge): New decl. + (diagnostic_graph_get_node_by_id): New decl. + (diagnostic_graph_get_edge_by_id): New decl. + (diagnostic_node_set_label): New decl. + (diagnostic_node_set_location): New decl. + (diagnostic_node_set_logical_location): New decl. + * libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_3): New. + * libsarifreplay.cc: Include "libgdiagnostics-private.h". + (id_map): New "using". + (sarif_replayer::report_invalid_sarif): Update for change to + report_problem params. + (sarif_replayer::report_unhandled_sarif): Likewise. + (sarif_replayer::report_note): New. + (sarif_replayer::report_problem): Pass param "ref" by + pointer rather than reference and handle it being null. + (sarif_replayer::maybe_get_property_bag): New. + (sarif_replayer::maybe_get_property_bag_value): New. + (sarif_replayer::handle_run_obj): Handle run-level "graphs" as per + §3.14.20. + (sarif_replayer::handle_result_obj): Handle result-level "graphs" + as per §3.27.19. + (handle_thread_flow_location_object): Optionally handle graphs + stored in property "gcc/diagnostic_event/state_graph" as state + graphs. + (sarif_replayer::handle_graph_object): New. + (sarif_replayer::handle_node_object): New. + (sarif_replayer::handle_edge_object): New. + (sarif_replayer::get_graph_node_by_id_property): New. + * selftest-run-tests.cc (selftest::run_tests): Call + selftest::diagnostic_graph_cc_tests and + selftest::diagnostic_state_graph_cc_tests. + * selftest.h (selftest::diagnostic_graph_cc_tests): New decl. + (selftest::diagnostic_state_graph_cc_tests): New decl. + +2025-07-11 David Malcolm <dmalcolm@redhat.com> + + * Makefile.in (OBJS-libcommon): Add diagnostic-digraphs.o and + diagnostic-state-graphs.o. + +2025-07-11 David Malcolm <dmalcolm@redhat.com> + + * json.cc (json::object::clone): New. + (json::object::clone_as_object): New. + (json::array::clone): New. + (json::float_number::clone): New. + (json::integer_number::clone): New. + (json::string::clone): New. + (json::literal::clone): New. + (selftest::test_cloning): New test. + (selftest::json_cc_tests): Call it. + * json.h (json::value::clone): New vfunc. + (json::object::clone): New decl. + (json::object::clone_as_object): New decl. + (json::array::clone): New decl. + (json::float_number::clone): New decl. + (json::integer_number::clone): New decl. + (json::string::clone): New decl. + (json::literal::clone): New decl. + +2025-07-11 David Malcolm <dmalcolm@redhat.com> + + * json.cc (string::string): When constructing from pointer and + length, ensure the new buffer is null-terminated. + (selftest::test_strcmp): New. + (selftest::json_cc_tests): Likewise. + +2025-07-11 David Malcolm <dmalcolm@redhat.com> + + * doc/libgdiagnostics/topics/compatibility.rst + (_LIBGDIAGNOSTICS_ABI_2): Add missing anchor. + * doc/libgdiagnostics/topics/diagnostic-manager.rst + (diagnostic_manager_add_sink_from_spec): Add links to GCC's + documentation of "-fdiagnostics-add-output=". Fix parameter + markup. + (diagnostic_manager_set_analysis_target): Fix parameter markup. + Add link to SARIF spec. + * doc/libgdiagnostics/topics/logical-locations.rst: Markup fix. + * doc/libgdiagnostics/tutorial/02-physical-locations.rst: Clarify + wording of what "the source file" means, and that a range can't + have multiple files. + +2025-07-11 Vladimir N. Makarov <vmakarov@redhat.com> + + * lra-constraints.cc (process_address_1): When changing base reg + on a reg of the base class, fall back to reload of whole inner address. + (process_address): Constrain the iteration number. + +2025-07-11 Jakub Jelinek <jakub@redhat.com> + + PR c++/119064 + * doc/invoke.texi (Wc++26-compat): Document. + +2025-07-11 Richard Sandiford <richard.sandiford@arm.com> + + PR target/121027 + * config/aarch64/aarch64.cc (aarch64_evpc_sve_tbl): Punt on 2-input + operations that can be handled by vec_perm. + +2025-07-11 Kyrylo Tkachov <ktkachov@nvidia.com> + + * config/aarch64/aarch64-simd.md (*eor3qdi4): New + define_insn_and_split. + +2025-07-11 Kyrylo Tkachov <ktkachov@nvidia.com> + + * config/aarch64/aarch64-simd.md (*bcaxqdi4): New + define_insn_and_split. + +2025-07-11 Kyrylo Tkachov <ktkachov@nvidia.com> + + * config/aarch64/aarch64-simd.md (eor3q<mode>4): Use VDQ_I mode + iterator. + +2025-07-11 Kyrylo Tkachov <ktkachov@nvidia.com> + + * config/aarch64/aarch64-simd.md (bcaxq<mode>4): Use VDQ_I mode + iterator. + +2025-07-11 Richard Biener <rguenther@suse.de> + + PR tree-optimization/121034 + * tree-vect-loop.cc (vectorizable_reduction): Cleanup + reduction chain following code. + +2025-07-11 Jan Hubicka <hubicka@ucw.cz> + + * opts.cc (finish_options): Enable debug_nonbind_markers_p for + auto-profile. + * tree-cfg.cc (struct locus_discrim_map): Remove. + (struct locus_discrim_hasher): Remove. + (locus_discrim_hasher::hash): Remove. + (locus_discrim_hasher::equal): Remove. + (first_non_label_nondebug_stmt): Remove. + (build_gimple_cfg): Do not allocate discriminator tables. + (next_discriminator_for_locus): Remove. + (same_line_p): Remove. + (struct discrim_entry): New structure. + (assign_discriminator): Rewrite. + (assign_discriminators): Rewrite. + +2025-07-11 Jan Hubicka <hubicka@ucw.cz> + + PR ipa/114790 + * cgraph.cc (cgraph_update_edges_for_call_stmt_node): Resolve devirtualization + if call statement was optimized out or turned to direct call. + +2025-07-11 Jakub Jelinek <jakub@redhat.com> + Martin Jambor <mjambor@suse.cz> + + PR ipa/121023 + * ipa-fnsummary.cc (compute_fn_summary): Disallow signature changes + on cfun->has_musttail functions. + +2025-07-11 Hu, Lin1 <lin1.hu@intel.com> + + PR target/91384 + * config/i386/i386.md: Add new peeophole2 for optimize *negsi_1 + followed by *cmpsi_ccno_1 with APX_F. + +2025-07-11 Richard Biener <rguenther@suse.de> + + * config/i386/i386.cc (ix86_vector_costs::add_stmt_cost): Use + the LHS of a scalar stmt to determine mode and whether it is FP. + +2025-07-10 Richard Sandiford <richard.sandiford@arm.com> + + * config/aarch64/aarch64.cc (aarch64_vector_costs::add_stmt_cost): + Guard VF-based costing with !m_costing_for_scalar. + +2025-07-10 Qing Zhao <qing.zhao@oracle.com> + + * internal-fn.cc (expand_ACCESS_WITH_SIZE): Update comments. + * internal-fn.def (ACCESS_WITH_SIZE): Update comments. + * tree-object-size.cc (access_with_size_object_size): Update comments. + Adjust the arguments per the new design. + +2025-07-10 Qing Zhao <qing.zhao@oracle.com> + + PR middle-end/121000 + * internal-fn.cc (expand_ACCESS_WITH_SIZE): Update comments. + * internal-fn.def (ACCESS_WITH_SIZE): Update comments. + * tree-object-size.cc (access_with_size_object_size): Update comments. + Get the element_size from the 6th argument directly. + +2025-07-10 Richard Sandiford <richard.sandiford@arm.com> + + * config/aarch64/aarch64-sve2.md (aarch64_gather_ld1q): Replace with... + (@aarch64_gather_ld1q<mode>): ...this, parameterizing based on mode. + * config/aarch64/aarch64-sve-builtins-sve2.cc + (svld1q_gather_impl::expand): Update accordingly. + (svst1q_scatter_impl::expand): Use aarch64_sve_reinterpret + instead of force_lowpart_subreg. + +2025-07-10 Jan Hubicka <hubicka@ucw.cz> + + * auto-profile.cc: Include output.h. + (function_instance::set_call_location): Also sanity check + that location is known. + (raw_symbol_name): Two new static functions. + (dump_inline_stack): Use it. + (string_table::get_index_by_decl): Likewise. + (function_instance::get_cgraph_node): Likewise. + (function_instance::get_function_instance_by_decl): Fix typo + in warning; use raw names; fix lineno decoding. + (match_with_target): Add containing funciton parameter; + correctly output function and call location in warning. + (function_instance::lookup_count): Fix warning locations. + (function_instance::match): Fix warning locations; avoid + crash with mismatched callee; do not warn about broken callsites + twice. + (autofdo_source_profile::offline_external_functions): Use + raw_assembler_name. + (walk_block): Use raw_assembler_name. + +2025-07-10 Robin Dapp <rdapp@ventanamicro.com> + + PR target/121014 + * cfgexpand.cc (expand_debug_expr): Assert FLOAT_MODE_P. + * optabs-tree.cc (optab_for_tree_code): Assert FLOAT_TYPE_P. + * tree-vect-loop.cc (vect_get_loop_len): Use EXACT_DIV_EXPR. + +2025-07-10 Robin Dapp <rdapp@ventanamicro.com> + + PR target/118734 + * config/riscv/constraints.md (Wdm): Use tunable for Wdm + constraint. + * config/riscv/riscv-protos.h (emit_avltype_insn): Declare. + (can_be_broadcasted_p): Rename to... + (can_be_broadcast_p): ...this. + * config/riscv/predicates.md: Use renamed function. + (strided_load_broadcast_p): Declare. + * config/riscv/riscv-selftests.cc (run_broadcast_selftests): + Only run broadcast selftest if strided broadcasts are OK. + * config/riscv/riscv-v.cc (emit_avltype_insn): New function. + (sew64_scalar_helper): Only emit a pred_broadcast if the new + tunable says so. + (can_be_broadcasted_p): Rename to... + (can_be_broadcast_p): ...this and use new tunable. + * config/riscv/riscv.cc (struct riscv_tune_param): Add strided + broad tunable. + (strided_load_broadcast_p): Implement. + * config/riscv/vector.md: Use strided_load_broadcast_p () and + work around 64-bit broadcast on rv32 targets. + +2025-07-10 Co-authored-by: Jeff Law <jlaw@ventanamicro.com> + + * config/riscv/riscv.cc (riscv_fusion_pairs): Add new cases. + (riscv_set_is_add): New function. + (riscv_set_is_addi, riscv_set_is_adduw, riscv_set_is_shNadd): Likewise. + (riscv_set_is_shNadduw): Likewise. + (riscv_macro_fusion_pair_p): Add new fusion cases. + +2025-07-10 Richard Biener <rguenther@suse.de> + + * tree-vect-slp.cc (vect_analyze_slp): Fail for non-canonical + gconds. + +2025-07-10 Richard Biener <rguenther@suse.de> + + * tree-vect-slp.cc (vect_build_slp_instance): Do not use + SLP_TREE_VECTYPE to determine the conversion back to the + reduction IV. + +2025-07-10 Richard Biener <rguenther@suse.de> + + * tree-vect-loop.cc (vectorizable_reduction): Avoid + vect_is_simple_use and record a vector type if we come + up with one. + +2025-07-10 Richard Biener <rguenther@suse.de> + + * tree-vect-stmts.cc (get_load_store_type): Do not use + vect_is_simple_use to fill gather/scatter offset operand + vectype and dt. + +2025-07-10 Richard Biener <rguenther@suse.de> + + * tree-vect-loop.cc (vect_model_reduction_cost): Get SLP + node instead of stmt_info and use that when recording costs. + +2025-07-10 Kyrylo Tkachov <ktkachov@nvidia.com> + + PR target/120999 + * config/aarch64/aarch64-sve2.md (*aarch64_sve2_nor<mode>): + Adjust movprfx alternative. + +2025-07-10 Richard Sandiford <richard.sandiford@arm.com> + + * doc/sourcebuild.texi (aarch64_sve2_hw, aarch64_sve2p1_hw): Document. + * config/aarch64/aarch64.cc (aarch64_evpc_hvla): Extend to + BYTES_BIG_ENDIAN. + +2025-07-10 Richard Biener <rguenther@suse.de> + + * tree-vectorizer.h (vect_analyze_stmt): Remove stmt-info + and need_to_vectorize arguments. + * tree-vect-slp.cc (vect_slp_analyze_node_operations_1): + Adjust. + * tree-vect-stmts.cc (can_vectorize_live_stmts): Remove + stmt_info argument and remove non-SLP path. + (vect_analyze_stmt): Remove stmt_info and need_to_vectorize + argument and prune paths no longer reachable. + (vect_transform_stmt): Adjust. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + * config/i386/x86-tune.def: Change "Tunning the" to "tuning" in + comment and use semicolon instead of dot in comment. + * loop-unroll.cc (decide_unroll_stupid): Comment spelling fix, + tunning -> tuning. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + * tree-vect-loop.cc (scale_profile_for_vect_loop): Comment + spelling fix: bellow -> below. + * ipa-polymorphic-call.cc (record_known_type): Likewise. + * config/i386/x86-tune.def: Likewise. + * config/riscv/vector.md (*vsetvldi_no_side_effects_si_extend): + Likewise. + * tree-scalar-evolution.cc (iv_can_overflow_p): Likewise. + * ipa-devirt.cc (add_type_duplicate): Likewise. + * tree-ssa-loop-niter.cc (maybe_lower_iteration_bound): Likewise. + * gimple-ssa-sccopy.cc: Likewise. + * cgraphunit.cc: Likewise. + * graphite.h (struct poly_dr): Likewise. + * ipa-reference.cc (ignore_edge_p): Likewise. + * tree-ssa-alias.cc (ao_compare::compare_ao_refs): Likewise. + * profile-count.h (profile_probability::probably_reliable_p): + Likewise. + * ipa-inline-transform.cc (inline_call): Likewise. + +2025-07-10 Richard Biener <rguenther@suse.de> + + * tree-vect-loop.cc (vect_dissolve_slp_only_groups): Remove. + (vect_analyze_loop_2): Do not call it. + +2025-07-10 Richard Biener <rguenther@suse.de> + + * tree-vect-loop.cc (vect_active_double_reduction_p): Remove. + (vect_analyze_loop_operations): Remove. + (vect_analyze_loop_2): Do not call it. + +2025-07-10 Richard Biener <rguenther@suse.de> + + * tree-vect-loop.cc (vect_determine_vf_for_stmt_1): Rename + to ... + (vect_determine_vectype_for_stmt_1): ... this and only set + STMT_VINFO_VECTYPE. Fail for single-element vector types. + (vect_determine_vf_for_stmt): Rename to ... + (vect_determine_vectype_for_stmt): ... this and only set + STMT_VINFO_VECTYPE. Fail for single-element vector types. + (vect_determine_vectorization_factor): Rename to ... + (vect_set_stmts_vectype): ... this and only set STMT_VINFO_VECTYPE. + (vect_update_vf_for_slp): Remove. + (vect_analyze_loop_operations): Remove walk over stmts. + (vect_analyze_loop_2): Call vect_set_stmts_vectype instead of + vect_determine_vectorization_factor. Set vectorization factor + from LOOP_VINFO_SLP_UNROLLING_FACTOR. Fail if vect_detect_hybrid_slp + detects hybrid stmts or when vect_make_slp_decision finds + nothing to SLP. + * tree-vect-slp.cc (vect_detect_hybrid_slp): Move check + whether we have any hybrid stmts here from vect_update_vf_for_slp + * tree-vect-stmts.cc (vect_analyze_stmt): Remove loop over + stmts. + * tree-vectorizer.h (vect_detect_hybrid_slp): Update. + 2025-07-09 Richard Sandiford <richard.sandiford@arm.com> * config/aarch64/aarch64.cc (aarch64_simd_valid_imm): Account diff --git a/gcc/DATESTAMP b/gcc/DATESTAMP index 12032ce..e177aad 100644 --- a/gcc/DATESTAMP +++ b/gcc/DATESTAMP @@ -1 +1 @@ -20250710 +20250712 diff --git a/gcc/Makefile.in b/gcc/Makefile.in index d5ceccc..bdb5292 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1856,11 +1856,13 @@ OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \ diagnostic-format-sarif.o \ diagnostic-format-text.o \ diagnostic-global-context.o \ + diagnostic-digraphs.o \ diagnostic-macro-unwinding.o \ diagnostic-output-spec.o \ diagnostic-path.o \ diagnostic-path-output.o \ diagnostic-show-locus.o \ + diagnostic-state-graphs.o \ diagnostic-state-to-dot.o \ edit-context.o \ graphviz.o pex.o \ diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index d88e73f..49b4b95 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + * par-load.adb: Comment spelling fix: bellow -> below. + * libgnarl/s-taskin.ads: Likewise. + 2025-07-04 Eric Botcazou <ebotcazou@adacore.com> * gcc-interface/Make-lang.in (ACATSDIR): Change to acats-4. diff --git a/gcc/analyzer/ChangeLog b/gcc/analyzer/ChangeLog index d31cbbc..a34fa13 100644 --- a/gcc/analyzer/ChangeLog +++ b/gcc/analyzer/ChangeLog @@ -1,3 +1,41 @@ +2025-07-11 David Malcolm <dmalcolm@redhat.com> + + * ana-state-to-diagnostic-state.cc: Reimplement, replacing + XML-based implementation with one based on state graphs. + * ana-state-to-diagnostic-state.h: Likewise. + * checker-event.cc: Replace include of "xml.h" with include of + "diagnostic-state-graphs.h". + (checker_event::maybe_make_xml_state): Replace with... + (checker_event::maybe_make_diagnostic_state_graph): ...this. + * checker-event.h: Add include of "diagnostic-digraphs.h". + (checker_event::maybe_make_xml_state): Replace decl with... + (checker_event::maybe_make_diagnostic_state_graph): ...this. + * engine.cc (exploded_node::on_stmt_pre): Replace + "_analyzer_dump_xml" with "__analyzer_dump_sarif". + * program-state.cc: Replace include of "diagnostic-state.h" with + "diagnostic-state-graphs.h". + (program_state::dump_dot): Port from XML to state graphs. + * program-state.h: Drop reduntant forward decl of xml::document. + (program_state::make_xml): Replace decl with... + (program_state::make_diagnostic_state_graph): ...this. + (program_state::dump_xml_to_pp): Drop decl. + (program_state::dump_xml_to_file): Drop decl. + (program_state::dump_xml): Drop decl. + (program_state::dump_dump_sarif): New decl. + * sm-malloc.cc (get_dynalloc_state_for_state): New. + (malloc_state_machine::add_state_to_xml): Replace with... + (malloc_state_machine::add_state_to_state_graph): ...this. + * sm.cc (state_machine::add_state_to_xml): Replace with... + (state_machine::add_state_to_state_graph): ...this. + (state_machine::add_global_state_to_xml): Replace with... + (state_machine::add_global_state_to_state_graph): ...this. + * sm.h (class xml_state): Drop forward decl. + (class analyzer_state_graph): New forward decl. + (state_machine::add_state_to_xml): Replace decl with... + (state_machine::add_state_to_state_graph): ...this. + (state_machine::add_global_state_to_xml): Replace decl with... + (state_machine::add_global_state_to_state_graph): ...this. + 2025-06-30 David Malcolm <dmalcolm@redhat.com> * access-diagram.cc: Use nullptr rather than NULL where diff --git a/gcc/analyzer/ana-state-to-diagnostic-state.cc b/gcc/analyzer/ana-state-to-diagnostic-state.cc index b85a2f1..2701259 100644 --- a/gcc/analyzer/ana-state-to-diagnostic-state.cc +++ b/gcc/analyzer/ana-state-to-diagnostic-state.cc @@ -1,4 +1,4 @@ -/* Converting ana::program_state to XML state documents. +/* Creating diagnostic state graphs from ana::program_state. Copyright (C) 2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.com>. @@ -23,8 +23,8 @@ along with GCC; see the file COPYING3. If not see #define INCLUDE_SET #include "analyzer/common.h" -#include "xml.h" -#include "xml-printer.h" +#include "diagnostic-state-graphs.h" +#include "diagnostic-format-sarif.h" #include "analyzer/region-model.h" #include "analyzer/program-state.h" @@ -39,57 +39,47 @@ along with GCC; see the file COPYING3. If not see namespace ana { +using namespace ::diagnostics::state_graphs; + static void -set_wi_attr (xml::element &e, +set_wi_attr (state_node_ref state_node, const char *attr_name, const wide_int_ref &w, signop sgn) { pretty_printer pp; pp_wide_int (&pp, w, sgn); - e.set_attr (attr_name, pp_formatted_text (&pp)); + state_node.set_attr (attr_name, pp_formatted_text (&pp)); } static void -set_type_attr (xml::element &e, const_tree type) +set_type_attr (state_node_ref state_node, const_tree type) { gcc_assert (type); pretty_printer pp; pp_format_decoder (&pp) = default_tree_printer; pp_printf (&pp, "%T", type); - e.set_attr ("type", pp_formatted_text (&pp)); + state_node.set_type (pp_formatted_text (&pp)); } static void -set_bits_attr (xml::element &e, +set_bits_attr (state_node_ref state_node, bit_range bits) { pretty_printer pp; bits.dump_to_pp (&pp); - e.set_attr ("bits", pp_formatted_text (&pp)); + state_node.set_attr ("bits", pp_formatted_text (&pp)); } -static void -set_region_id_attr (xml::element &e, - const region ®) -{ - e.set_attr ("region_id", std::to_string (reg.get_id ())); -} +// class analyzer_state_graph : public diagnostics::digraphs::digraph -// class xml_state : public xml::document - -xml_state::xml_state (const program_state &state, - const extrinsic_state &ext_state) -: xml::document (), - m_state (state), +analyzer_state_graph::analyzer_state_graph (const program_state &state, + const extrinsic_state &ext_state) +: m_state (state), m_ext_state (ext_state), m_mgr (*ext_state.get_engine ()->get_model_manager ()), - m_root (nullptr) + m_next_id (0) { - auto root = std::make_unique<xml::element> ("state-diagram", false); - m_root = root.get (); - add_child (std::move (root)); - /* Find pointers to heap-allocated regions, and record their types, so that we have a user-friendly way of showing the memory (by field, rather than by byte offset). */ @@ -117,14 +107,14 @@ xml_state::xml_state (const program_state &state, for (int i = state.m_region_model->get_stack_depth () - 1; i >= 0; --i) { const frame_region *reg = state.m_region_model->get_frame_at_index (i); - get_or_create_element (*reg); + get_or_create_state_node (*reg); } /* Create bound memory. */ for (auto iter : *state.m_region_model->get_store ()) { const bool create_all = false; // "true" for verbose, for debugging - create_elements_for_binding_cluster (*iter.second, create_all); + create_state_nodes_for_binding_cluster (*iter.second, create_all); } /* TODO: Constraints. */ @@ -137,52 +127,165 @@ xml_state::xml_state (const program_state &state, { auto &sm = ext_state.get_sm (i); for (const auto &iter : *smap) - sm.add_state_to_xml (*this, *iter.first, iter.second.m_state); + sm.add_state_to_state_graph (*this, *iter.first, iter.second.m_state); if (auto s = smap->get_global_state ()) - sm.add_global_state_to_xml (*this, s); + sm.add_global_state_to_state_graph (*this, s); } } + + /* Process pending edges. */ + while (m_pending_edges.size () > 0) + { + pending_edge item = m_pending_edges.back (); + m_pending_edges.pop_back (); + + /* Ensure we have a node for the dst region. This + could lead to additional pending edges. */ + auto dst_node = get_or_create_state_node (item.m_dst_reg); + add_edge (nullptr, item.m_src_node.m_node, dst_node.m_node); + } } -xml::element & -xml_state::get_or_create_element (const region ®) +state_node_ref +analyzer_state_graph::get_or_create_state_node (const region ®) { - auto existing = m_region_to_element_map.find (®); - if (existing != m_region_to_element_map.end ()) + auto existing = m_region_to_state_node_map.find (®); + if (existing != m_region_to_state_node_map.end ()) return *existing->second; - auto &e = create_and_add_element (reg); - m_region_to_element_map[®] = &e; - return e; + auto ref = create_and_add_state_node (reg); + m_region_to_state_node_map[®] = &ref.m_node; + return ref; } -xml::element& -xml_state::create_and_add_element (const region ®) +state_node_ref +analyzer_state_graph::create_and_add_state_node (const region ®) { - auto e = create_element (reg); - xml::element &result = *e; + auto node = create_state_node (reg); + + state_node_ref result = *node; if (auto parent_reg = reg.get_parent_region ()) + if (parent_reg->get_kind () != RK_ROOT) + { + auto parent_state_node = get_or_create_state_node (*parent_reg); + parent_state_node.m_node.add_child (std::move (node)); + return result; + } + add_node (std::move (node)); + return result; +} + +std::string +analyzer_state_graph::make_node_id (const char *prefix) +{ + return std::string (prefix) + "-" + std::to_string (m_next_id++); +} + +std::string +analyzer_state_graph::make_node_id (const region ®) +{ + const char *prefix = nullptr; + switch (reg.get_kind ()) { - auto parent_element = &get_or_create_element (*parent_reg); - parent_element->add_child (std::move (e)); + case RK_ROOT: + default: + gcc_unreachable (); + break; + + case RK_GLOBALS: + return "globals"; + case RK_CODE: + return "code"; + case RK_STACK: + return "stack"; + case RK_HEAP: + return "heap"; + + case RK_FRAME: + prefix = "frame-region"; + break; + case RK_FUNCTION: + prefix = "function-region"; + break; + case RK_LABEL: + prefix = "label-region"; + break; + case RK_THREAD_LOCAL: + prefix = "thread-local-region"; + break; + case RK_SYMBOLIC: + prefix = "symbolic-region"; + break; + case RK_DECL: + prefix = "decl-region"; + break; + case RK_FIELD: + prefix = "field-region"; + break; + case RK_ELEMENT: + prefix = "element-region"; + break; + case RK_OFFSET: + prefix = "offset-region"; + break; + case RK_SIZED: + prefix = "sized-region"; + break; + case RK_CAST: + prefix = "cast-region"; + break; + case RK_HEAP_ALLOCATED: + prefix = "heap-allocated-region"; + break; + case RK_ALLOCA: + prefix = "alloca-region"; + break; + case RK_STRING: + prefix = "string-region"; + break; + case RK_BIT_RANGE: + prefix = "bit-range-region"; + break; + case RK_VAR_ARG: + prefix = "var-arg-region"; + break; + case RK_ERRNO: + prefix = "errno-region"; + break; + case RK_PRIVATE: + prefix = "private-region"; + break; + case RK_UNKNOWN: + prefix = "unknown-region"; + break; } - else - m_root->add_child (std::move (e)); - return result; + return std::string (prefix) + "-" + std::to_string (reg.get_id ()); +} + +std::unique_ptr<diagnostics::digraphs::node> +analyzer_state_graph:: +make_state_node (diagnostics::state_graphs::node_kind kind, + std::string id) +{ + auto node = std::make_unique<diagnostics::digraphs::node> (*this, std::move (id)); + state_node_ref node_ref (*node); + node_ref.set_node_kind (kind); + return node; } -std::unique_ptr<xml::element> -xml_state::make_memory_space_element (const char *label) +std::unique_ptr<diagnostics::digraphs::node> +analyzer_state_graph:: +make_memspace_state_node (const region ®, + diagnostics::state_graphs::node_kind kind) { - auto e = std::make_unique<xml::element> ("memory-space", false); - e->set_attr ("label", label); - return e; + return make_state_node (kind, make_node_id (reg)); } -std::unique_ptr<xml::element> -xml_state::create_element (const region ®) +std::unique_ptr<diagnostics::digraphs::node> +analyzer_state_graph::create_state_node (const region ®) { - std::unique_ptr<xml::element> e; + std::unique_ptr<diagnostics::digraphs::node> node; + switch (reg.get_kind ()) { default: @@ -190,110 +293,102 @@ xml_state::create_element (const region ®) case RK_FRAME: { - e = std::make_unique<xml::element> ("stack-frame", false); const frame_region &frame_reg = static_cast<const frame_region &> (reg); + + node = make_state_node (diagnostics::state_graphs::node_kind::stack_frame, + make_node_id (reg)); + node->set_logical_loc + (m_logical_loc_mgr.key_from_tree (frame_reg.get_fndecl ())); { pretty_printer pp; pp_format_decoder (&pp) = default_tree_printer; pp_printf (&pp, "%E", frame_reg.get_fndecl ()); - e->set_attr ("function", pp_formatted_text (&pp)); + node->set_attr (STATE_NODE_PREFIX, "function", + pp_formatted_text (&pp)); } } break; + case RK_GLOBALS: - e = make_memory_space_element ("Globals"); + node = make_memspace_state_node (reg, + diagnostics::state_graphs::node_kind::globals); break; case RK_CODE: - e = make_memory_space_element ("Code"); + node = make_memspace_state_node (reg, + diagnostics::state_graphs::node_kind::code); break; case RK_FUNCTION: - e = std::make_unique<xml::element> ("function", false); - // TODO - break; - case RK_LABEL: - e = std::make_unique<xml::element> ("label", false); + node = make_memspace_state_node (reg, + diagnostics::state_graphs::node_kind::function); // TODO break; + case RK_STACK: - e = std::make_unique<xml::element> ("stack", false); + node = make_memspace_state_node (reg, + diagnostics::state_graphs::node_kind::stack); break; case RK_HEAP: - e = make_memory_space_element ("Heap"); + node = make_memspace_state_node (reg, + diagnostics::state_graphs::node_kind::heap_); break; case RK_THREAD_LOCAL: - e = make_memory_space_element ("Thread-local"); + node = make_memspace_state_node (reg, + diagnostics::state_graphs::node_kind::thread_local_); break; case RK_ROOT: - e = std::make_unique<xml::element> ("memory-regions", false); + gcc_unreachable (); break; case RK_SYMBOLIC: - e = std::make_unique<xml::element> ("symbolic-region", false); - // TODO + node = make_memspace_state_node (reg, + diagnostics::state_graphs::node_kind::other); break; + case RK_DECL: { - e = std::make_unique<xml::element> ("variable", false); + node = make_state_node (diagnostics::state_graphs::node_kind::variable, + make_node_id (reg)); const decl_region &decl_reg = static_cast<const decl_region &> (reg); + state_node_ref node_ref (*node); { pretty_printer pp; pp_format_decoder (&pp) = default_tree_printer; pp_printf (&pp, "%E", decl_reg.get_decl ()); - e->set_attr ("name", pp_formatted_text (&pp)); + node_ref.set_name (pp_formatted_text (&pp)); } - set_type_attr (*e, TREE_TYPE (decl_reg.get_decl ())); + set_type_attr (*node, TREE_TYPE (decl_reg.get_decl ())); } break; + case RK_FIELD: - e = std::make_unique<xml::element> ("field", false); - break; case RK_ELEMENT: - e = std::make_unique<xml::element> ("element", false); + /* These should be handled in populate_state_node_for_typed_region. */ + gcc_unreachable (); break; + + case RK_LABEL: case RK_OFFSET: - e = std::make_unique<xml::element> ("offset-region", false); - // TODO - break; case RK_SIZED: - e = std::make_unique<xml::element> ("sized-region", false); - // TODO - break; case RK_CAST: - e = std::make_unique<xml::element> ("cast-region", false); - // TODO - break; - case RK_HEAP_ALLOCATED: - e = std::make_unique<xml::element> ("heap-buffer", false); - set_attr_for_dynamic_extents (reg, *e); - break; - case RK_ALLOCA: - e = std::make_unique<xml::element> ("alloca-buffer", false); - set_attr_for_dynamic_extents (reg, *e); - break; case RK_STRING: - e = std::make_unique<xml::element> ("string-region", false); - // TODO - break; case RK_BIT_RANGE: - e = std::make_unique<xml::element> ("RK_BIT_RANGE", false); // TODO - break; case RK_VAR_ARG: - e = std::make_unique<xml::element> ("RK_VAR_ARG", false); // TODO - break; case RK_ERRNO: - e = std::make_unique<xml::element> ("errno", false); - break; case RK_PRIVATE: - e = std::make_unique<xml::element> ("RK_PRIVATE", false); // TODO - break; case RK_UNKNOWN: - e = std::make_unique<xml::element> ("RK_UNKNOWN", false); // TODO + node = make_state_node (diagnostics::state_graphs::node_kind::other, + make_node_id (reg)); break; - } - gcc_assert (e); - set_region_id_attr (*e, reg); + case RK_HEAP_ALLOCATED: + case RK_ALLOCA: + node = make_memspace_state_node (reg, + diagnostics::state_graphs::node_kind::dynalloc_buffer); + set_attr_for_dynamic_extents (reg, *node); + break; + } + gcc_assert (node); if (reg.get_base_region () == ®) if (!reg.get_type ()) @@ -303,16 +398,17 @@ xml_state::create_element (const region ®) if (search != m_types_for_untyped_regions.end ()) { tree type_to_use = search->second; - set_type_attr (*e, type_to_use); + set_type_attr (*node, type_to_use); } } - return e; + return node; } void -xml_state::create_elements_for_binding_cluster (const binding_cluster &cluster, - bool create_all) +analyzer_state_graph:: +create_state_nodes_for_binding_cluster (const binding_cluster &cluster, + bool create_all) { /* TODO: - symbolic bindings @@ -326,12 +422,12 @@ xml_state::create_elements_for_binding_cluster (const binding_cluster &cluster, if (auto conc_key = key->dyn_cast_concrete_binding ()) conc_bindings[conc_key->get_bit_range ()] = svalue; if (const region *reg = svalue->maybe_get_region ()) - get_or_create_element (*reg); + get_or_create_state_node (*reg); } - auto &e = get_or_create_element (*cluster.get_base_region ()); + auto ref = get_or_create_state_node (*cluster.get_base_region ()); - e.add_child (create_element_for_conc_bindings (conc_bindings)); + ref.m_node.add_child (create_state_node_for_conc_bindings (conc_bindings)); const region *typed_reg = cluster.get_base_region (); if (!typed_reg->get_type ()) @@ -346,44 +442,45 @@ xml_state::create_elements_for_binding_cluster (const binding_cluster &cluster, } if (typed_reg->get_type ()) - populate_element_for_typed_region (e, - *typed_reg, - conc_bindings, - create_all); + populate_state_node_for_typed_region (ref, + *typed_reg, + conc_bindings, + create_all); else { // TODO } } -std::unique_ptr<xml::element> -xml_state::create_element_for_conc_bindings (const concrete_bindings_t &conc_bindings) +std::unique_ptr<diagnostics::digraphs::node> +analyzer_state_graph::create_state_node_for_conc_bindings (const concrete_bindings_t &conc_bindings) { - auto e = std::make_unique<xml::element> ("concrete-bindings", false); + auto node = make_state_node (diagnostics::state_graphs::node_kind::other, + make_node_id ("concrete-bindings")); for (auto iter : conc_bindings) { const bit_range bits = iter.first; const svalue *sval = iter.second; - auto binding_element - = std::make_unique<xml::element> ("binding", false); - set_bits_attr (*binding_element, bits); + auto binding_state_node + = make_state_node (diagnostics::state_graphs::node_kind::other, + make_node_id ("binding")); + set_bits_attr (*binding_state_node, bits); { pretty_printer pp; pp_format_decoder (&pp) = default_tree_printer; sval->dump_to_pp (&pp, true); - binding_element->set_attr ("value", pp_formatted_text (&pp)); - if (auto svalue_element = create_element_for_svalue (sval)) - binding_element->add_child (std::move (svalue_element)); + binding_state_node->set_attr (STATE_NODE_PREFIX, "value", + pp_formatted_text (&pp)); } - e->add_child (std::move (binding_element)); + node->add_child (std::move (binding_state_node)); } - return e; + return node; } // Try to get the bit_range of REG within its base region bool -xml_state::get_bit_range_within_base_region (const region ®, - bit_range &out) +analyzer_state_graph::get_bit_range_within_base_region (const region ®, + bit_range &out) { region_offset start_offset = reg.get_offset (&m_mgr); if (!start_offset.concrete_p ()) @@ -398,30 +495,28 @@ xml_state::get_bit_range_within_base_region (const region ®, } void -xml_state::populate_element_for_typed_region (xml::element &e, - const region ®, - const concrete_bindings_t &conc_bindings, - bool create_all) +analyzer_state_graph:: +populate_state_node_for_typed_region (state_node_ref node, + const region ®, + const concrete_bindings_t &conc_bindings, + bool create_all) { const_tree reg_type = reg.get_type (); gcc_assert (reg_type); - set_type_attr (e, reg_type); + set_type_attr (node, reg_type); bit_range bits (0, 0); if (get_bit_range_within_base_region (reg, bits)) { - set_bits_attr (e, bits); + set_bits_attr (node, bits); auto search = conc_bindings.find (bits); if (search != conc_bindings.end ()) { const svalue *bound_sval = search->second; - if (auto svalue_element = create_element_for_svalue (bound_sval)) - { - xml::printer xp (e); - xp.push_tag ("value-of-region"); - xp.append (std::move (svalue_element)); - } + node.set_json_attr ("value", bound_sval->to_json ()); + if (const region *dst_reg = bound_sval->maybe_get_region ()) + m_pending_edges.push_back ({node, *dst_reg}); } } @@ -454,22 +549,23 @@ xml_state::populate_element_for_typed_region (xml::element &e, = m_mgr.get_element_region (®, const_cast<tree> (element_type), sval_index); - if (show_child_element_for_child_region_p (*child_reg, + if (show_child_state_node_for_child_region_p (*child_reg, conc_bindings, create_all)) { - // Here "element" is in the xml sense - auto child_element - = std::make_unique<xml::element> ("element", false); - set_wi_attr (*child_element, "index", idx, UNSIGNED); - set_region_id_attr (*child_element, *child_reg); + auto child_state_node + = make_state_node + (diagnostics::state_graphs::node_kind::element, + make_node_id (*child_reg)); + set_wi_attr (*child_state_node, "index", idx, UNSIGNED); + // Recurse: gcc_assert (element_type); - populate_element_for_typed_region (*child_element, - *child_reg, - conc_bindings, - create_all); - e.add_child (std::move (child_element)); + populate_state_node_for_typed_region (*child_state_node, + *child_reg, + conc_bindings, + create_all); + node.m_node.add_child (std::move (child_state_node)); } } } @@ -485,15 +581,17 @@ xml_state::populate_element_for_typed_region (xml::element &e, const bit_range bits (0, item.m_bit_range.m_size_in_bits); const region *child_reg = m_mgr.get_bit_range (®, NULL_TREE, bits); - if (show_child_element_for_child_region_p (*child_reg, - conc_bindings, - create_all)) + if (show_child_state_node_for_child_region_p (*child_reg, + conc_bindings, + create_all)) { - auto child_element - = std::make_unique<xml::element> ("padding", false); - set_wi_attr (*child_element, "num_bits", + auto child_state_node + = make_state_node + (diagnostics::state_graphs::node_kind::padding, + make_node_id (*child_reg)); + set_wi_attr (*child_state_node, "num_bits", item.m_bit_range.m_size_in_bits, SIGNED); - e.add_child (std::move (child_element)); + node.m_node.add_child (std::move (child_state_node)); } } else @@ -501,26 +599,28 @@ xml_state::populate_element_for_typed_region (xml::element &e, const region *child_reg = m_mgr.get_field_region (®, const_cast<tree> (item.m_field)); - if (show_child_element_for_child_region_p (*child_reg, + if (show_child_state_node_for_child_region_p (*child_reg, conc_bindings, create_all)) { - auto child_element - = std::make_unique<xml::element> ("field", false); + auto child_state_node + = make_state_node + (diagnostics::state_graphs::node_kind::field, + make_node_id (*child_reg)); { pretty_printer pp; pp_format_decoder (&pp) = default_tree_printer; pp_printf (&pp, "%D", item.m_field); - child_element->set_attr ("name", - pp_formatted_text (&pp)); + child_state_node->set_attr (STATE_NODE_PREFIX, "name", + pp_formatted_text (&pp)); } - set_region_id_attr (*child_element, *child_reg); + // Recurse: - populate_element_for_typed_region (*child_element, + populate_state_node_for_typed_region (*child_state_node, *child_reg, conc_bindings, create_all); - e.add_child (std::move (child_element)); + node.m_node.add_child (std::move (child_state_node)); } } } @@ -530,7 +630,8 @@ xml_state::populate_element_for_typed_region (xml::element &e, } void -xml_state::set_attr_for_dynamic_extents (const region ®, xml::element &e) +analyzer_state_graph::set_attr_for_dynamic_extents (const region ®, + state_node_ref node_ref) { const svalue *sval = m_state.m_region_model->get_dynamic_extents (®); if (sval) @@ -541,13 +642,13 @@ xml_state::set_attr_for_dynamic_extents (const region ®, xml::element &e) pp_wide_int (&pp, wi::to_wide (cst), UNSIGNED); else sval->dump_to_pp (&pp, true); - e.set_attr ("dynamic-extents", pp_formatted_text (&pp)); + node_ref.set_attr ("dynamic-extents", pp_formatted_text (&pp)); } } bool -xml_state:: -show_child_element_for_child_region_p (const region ®, +analyzer_state_graph:: +show_child_state_node_for_child_region_p (const region ®, const concrete_bindings_t &conc_bindings, bool create_all) { @@ -569,216 +670,18 @@ show_child_element_for_child_region_p (const region ®, return false; } -std::unique_ptr<xml::element> -xml_state::create_element_for_svalue (const svalue *sval) +std::unique_ptr<diagnostics::digraphs::digraph> +program_state:: +make_diagnostic_state_graph (const extrinsic_state &ext_state) const { - if (!sval) - return nullptr; - - std::unique_ptr<xml::element> result; - switch (sval->get_kind ()) - { - default: - gcc_unreachable (); - case SK_REGION: - { - const region_svalue *region_sval = (const region_svalue *)sval; - result - = std::make_unique<xml::element> ("pointer-to-region", false); - set_region_id_attr (*result, *region_sval->get_pointee ()); - } - break; - case SK_CONSTANT: - { - const constant_svalue *constant_sval = (const constant_svalue *)sval; - result = std::make_unique<xml::element> ("constant", false); - pretty_printer pp; - pp_format_decoder (&pp) = default_tree_printer; - pp_printf (&pp, "%E", constant_sval->get_constant ()); - result->set_attr ("value", pp_formatted_text (&pp)); - } - break; - case SK_UNKNOWN: - result = std::make_unique<xml::element> ("unknown", false); - break; - case SK_POISONED: - { - const poisoned_svalue *poisoned_sval = (const poisoned_svalue *)sval; - switch (poisoned_sval->get_poison_kind ()) - { - default: - gcc_unreachable (); - case poison_kind::uninit: - result = std::make_unique<xml::element> ("uninitialized", false); - break; - case poison_kind::freed: - result = std::make_unique<xml::element> ("freed", false); - break; - case poison_kind::deleted: - result = std::make_unique<xml::element> ("deleted", false); - break; - case poison_kind::popped_stack: - result = std::make_unique<xml::element> ("popped-stack", false); - break; - } - } - break; - case SK_SETJMP: - { - //const setjmp_svalue *setjmp_sval = (const setjmp_svalue *)sval; - result = std::make_unique<xml::element> ("setjmp-buffer", false); - // TODO - } - break; - case SK_INITIAL: - { - const initial_svalue *initial_sval = (const initial_svalue *)sval; - result = std::make_unique<xml::element> ("initial-value-of", false); - set_region_id_attr (*result, *initial_sval->get_region ()); - } - break; - case SK_UNARYOP: - { - const unaryop_svalue *unaryop_sval = (const unaryop_svalue *)sval; - result = std::make_unique<xml::element> ("unary-op", false); - result->set_attr ("op", get_tree_code_name (unaryop_sval->get_op ())); - result->add_child - (create_element_for_svalue (unaryop_sval->get_arg ())); - } - break; - case SK_BINOP: - { - const binop_svalue *binop_sval = (const binop_svalue *)sval; - result = std::make_unique<xml::element> ("binary-op", false); - result->set_attr ("op", get_tree_code_name (binop_sval->get_op ())); - result->add_child (create_element_for_svalue (binop_sval->get_arg0 ())); - result->add_child (create_element_for_svalue (binop_sval->get_arg1 ())); - } - break; - case SK_SUB: - { - //const sub_svalue *sub_sval = (const sub_svalue *)sval; - result = std::make_unique<xml::element> ("subregion-value", false); - // TODO - } - break; - case SK_REPEATED: - { - const repeated_svalue *repeated_sval = (const repeated_svalue *)sval; - result = std::make_unique<xml::element> ("repeated-value", false); - result->add_child - (create_element_for_svalue (repeated_sval->get_outer_size ())); - result->add_child - (create_element_for_svalue (repeated_sval->get_inner_svalue ())); - } - break; - case SK_BITS_WITHIN: - { - const bits_within_svalue *bits_within_sval - = (const bits_within_svalue *)sval; - result = std::make_unique<xml::element> ("bits-within", false); - set_bits_attr (*result, bits_within_sval->get_bits ()); - result->add_child - (create_element_for_svalue (bits_within_sval->get_inner_svalue ())); - } - break; - case SK_UNMERGEABLE: - { - const unmergeable_svalue *unmergeable_sval - = (const unmergeable_svalue *)sval; - result = std::make_unique<xml::element> ("unmergeable", false); - result->add_child - (create_element_for_svalue (unmergeable_sval->get_arg ())); - } - break; - case SK_PLACEHOLDER: - { - const placeholder_svalue *placeholder_sval - = (const placeholder_svalue *)sval; - result = std::make_unique<xml::element> ("placeholder", false); - result->set_attr ("name", placeholder_sval->get_name ()); - } - break; - case SK_WIDENING: - { - //const widening_svalue *widening_sval = (const widening_svalue *)sval; - result = std::make_unique<xml::element> ("iterating-value", false); - // TODO - } - break; - case SK_COMPOUND: - { - //const compound_svalue *compound_sval = (const compound_svalue *)sval; - result = std::make_unique<xml::element> ("compound-value", false); - // TODO - } - break; - case SK_CONJURED: - { - //const conjured_svalue *conjured_sval = (const conjured_svalue *)sval; - result = std::make_unique<xml::element> ("conjured-value", false); - // TODO - } - break; - case SK_ASM_OUTPUT: - { - /* const asm_output_svalue *asm_output_sval - = (const asm_output_svalue *)sval; */ - result = std::make_unique<xml::element> ("asm-output", false); - // TODO - } - break; - case SK_CONST_FN_RESULT: - { - /* const const_fn_result_svalue *const_fn_result_sval - = (const const_fn_result_svalue *)sval; */ - result = std::make_unique<xml::element> ("const-fn-result", false); - // TODO - } - } - - if (result) - { - if (sval->get_type ()) - set_type_attr (*result, sval->get_type ()); - - pretty_printer pp; - pp_format_decoder (&pp) = default_tree_printer; - sval->dump_to_pp (&pp, true); - result->set_attr ("dump-text", pp_formatted_text (&pp)); - } - - return result; -} - -std::unique_ptr<xml::document> -program_state::make_xml (const extrinsic_state &ext_state) const -{ - return std::make_unique<xml_state> (*this, ext_state); -} - -void -program_state::dump_xml_to_pp (const extrinsic_state &ext_state, - pretty_printer *pp) const -{ - auto doc = make_xml (ext_state); - doc->write_as_xml (pp, 0, true); -} - -void -program_state::dump_xml_to_file (const extrinsic_state &ext_state, - FILE *outf) const -{ - pretty_printer pp; - pp.set_output_stream (outf); - dump_xml_to_pp (ext_state, &pp); - pp_flush (&pp); + return std::make_unique<analyzer_state_graph> (*this, ext_state); } void -program_state::dump_xml (const extrinsic_state &ext_state) const +program_state::dump_sarif (const extrinsic_state &ext_state) const { - dump_xml_to_file (ext_state, stderr); + auto g = make_diagnostic_state_graph (ext_state); + g->dump (); } } // namespace ana diff --git a/gcc/analyzer/ana-state-to-diagnostic-state.h b/gcc/analyzer/ana-state-to-diagnostic-state.h index bd6aa46..186e19d 100644 --- a/gcc/analyzer/ana-state-to-diagnostic-state.h +++ b/gcc/analyzer/ana-state-to-diagnostic-state.h @@ -1,4 +1,4 @@ -/* XML documents for dumping state in an easier-to-read form. +/* Creating diagnostic state graphs from ana::program_state. Copyright (C) 2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.com>. @@ -18,41 +18,52 @@ 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_ANALYZER_ANA_STATE_TO_XML_STATE_H -#define GCC_ANALYZER_ANA_STATE_TO_XML_STATE_H +#ifndef GCC_ANALYZER_ANA_STATE_TO_DIAGNOSTIC_STATE_H +#define GCC_ANALYZER_ANA_STATE_TO_DIAGNOSTIC_STATE_H -#include "xml.h" +#include "diagnostic-state-graphs.h" +#include "tree-logical-location.h" namespace ana { -class xml_state : public xml::document +class analyzer_state_graph : public diagnostics::digraphs::digraph { public: - xml_state (const program_state &state, - const extrinsic_state &ext_state); - - xml::element & - get_or_create_element (const region ®); + analyzer_state_graph (const program_state &state, + const extrinsic_state &ext_state); + diagnostics::state_graphs::state_node_ref + get_or_create_state_node (const region ®); private: - xml::element& - create_and_add_element (const region ®); - - static std::unique_ptr<xml::element> - make_memory_space_element (const char *label); - - std::unique_ptr<xml::element> - create_element (const region ®); + struct pending_edge + { + diagnostics::state_graphs::state_node_ref m_src_node; + const region &m_dst_reg; + }; + + diagnostics::state_graphs::state_node_ref + create_and_add_state_node (const region ®); + + std::unique_ptr<diagnostics::digraphs::node> + make_state_node (diagnostics::state_graphs::node_kind kind, + std::string id); + + std::unique_ptr<diagnostics::digraphs::node> + make_memspace_state_node (const region ®, + enum diagnostics::state_graphs::node_kind kind); + + std::unique_ptr<diagnostics::digraphs::node> + create_state_node (const region ®); /* Spatially sorted concrete bindings. */ typedef std::map<bit_range, const svalue *> concrete_bindings_t; void - create_elements_for_binding_cluster (const binding_cluster &cluster, - bool create_all); + create_state_nodes_for_binding_cluster (const binding_cluster &cluster, + bool create_all); - std::unique_ptr<xml::element> - create_element_for_conc_bindings (const concrete_bindings_t &conc_bindings); + std::unique_ptr<diagnostics::digraphs::node> + create_state_node_for_conc_bindings (const concrete_bindings_t &conc_bindings); // Try to get the bit_range of REG within its base region bool @@ -60,30 +71,36 @@ private: bit_range &out); void - populate_element_for_typed_region (xml::element &e, - const region ®, - const concrete_bindings_t &conc_bindings, - bool create_all); + populate_state_node_for_typed_region (diagnostics::state_graphs::state_node_ref, + const region ®, + const concrete_bindings_t &conc_bindings, + bool create_all); void - set_attr_for_dynamic_extents (const region ®, xml::element &e); + set_attr_for_dynamic_extents (const region ®, + diagnostics::state_graphs::state_node_ref); bool - show_child_element_for_child_region_p (const region ®, - const concrete_bindings_t &conc_bindings, - bool create_all); + show_child_state_node_for_child_region_p (const region ®, + const concrete_bindings_t &conc_bindings, + bool create_all); + + std::unique_ptr<diagnostics::digraphs::node> + create_state_node_for_svalue (const svalue *sval); - std::unique_ptr<xml::element> - create_element_for_svalue (const svalue *sval); + std::string make_node_id (const region ®); + std::string make_node_id (const char *prefix); + tree_logical_location_manager m_logical_loc_mgr; const program_state &m_state; const extrinsic_state &m_ext_state; region_model_manager &m_mgr; - xml::element *m_root; - std::map<const region *, xml::element *> m_region_to_element_map; + std::map<const region *, diagnostics::digraphs::node *> m_region_to_state_node_map; std::map<const region *, tree> m_types_for_untyped_regions; + unsigned m_next_id; + std::vector<pending_edge> m_pending_edges; }; } // namespace ana -#endif /* GCC_ANALYZER_ANA_STATE_TO_XML_STATE_H */ +#endif /* GCC_ANALYZER_ANA_STATE_TO_DIAGNOSTIC_STATE_H */ diff --git a/gcc/analyzer/checker-event.cc b/gcc/analyzer/checker-event.cc index af336df..8cc5ac2 100644 --- a/gcc/analyzer/checker-event.cc +++ b/gcc/analyzer/checker-event.cc @@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see #include "inlining-iterator.h" #include "tree-logical-location.h" #include "diagnostic-format-sarif.h" -#include "xml.h" +#include "diagnostic-state-graphs.h" #include "analyzer/analyzer-logging.h" #include "analyzer/sm.h" @@ -225,8 +225,8 @@ checker_event::prepare_for_emission (checker_path *path, print_desc (*pp.get ()); } -std::unique_ptr<xml::document> -checker_event::maybe_make_xml_state (bool debug) const +std::unique_ptr<diagnostics::digraphs::digraph> +checker_event::maybe_make_diagnostic_state_graph (bool debug) const { const program_state *state = get_program_state (); if (!state) @@ -235,14 +235,16 @@ checker_event::maybe_make_xml_state (bool debug) const gcc_assert (m_path); const extrinsic_state &ext_state = m_path->get_ext_state (); - auto result = state->make_xml (ext_state); + auto result = state->make_diagnostic_state_graph (ext_state); if (debug) { pretty_printer pp; text_art::theme *theme = global_dc->get_diagram_theme (); text_art::dump_to_pp (*state, theme, &pp); - result->add_comment (pp_formatted_text (&pp)); + result->set_attr (STATE_GRAPH_PREFIX, + "analyzer/program_state/", + pp_formatted_text (&pp)); } return result; diff --git a/gcc/analyzer/checker-event.h b/gcc/analyzer/checker-event.h index 7c44f1e..cf24e77 100644 --- a/gcc/analyzer/checker-event.h +++ b/gcc/analyzer/checker-event.h @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-logical-location.h" #include "analyzer/program-state.h" #include "analyzer/event-loc-info.h" +#include "diagnostic-digraphs.h" namespace ana { @@ -128,12 +129,12 @@ public: virtual bool is_function_entry_p () const { return false; } virtual bool is_return_p () const { return false; } + std::unique_ptr<diagnostics::digraphs::digraph> + maybe_make_diagnostic_state_graph (bool debug) const final override; + virtual const program_state * get_program_state () const { return nullptr; } - std::unique_ptr<xml::document> - maybe_make_xml_state (bool debug) const final override; - /* For use with %@. */ const diagnostic_event_id_t *get_id_ptr () const { diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 67024e9..745ef7e 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -1580,9 +1580,9 @@ exploded_node::on_stmt_pre (exploded_graph &eg, state->dump (eg.get_ext_state (), true); return; } - else if (is_special_named_call_p (call, "__analyzer_dump_xml", 0)) + else if (is_special_named_call_p (call, "__analyzer_dump_sarif", 0)) { - state->dump_xml (eg.get_ext_state ()); + state->dump_sarif (eg.get_ext_state ()); return; } else if (is_special_named_call_p (call, "__analyzer_dump_dot", 0)) diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc index c0befac..85cbe75 100644 --- a/gcc/analyzer/program-state.cc +++ b/gcc/analyzer/program-state.cc @@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "digraph.h" #include "diagnostic-event-id.h" -#include "diagnostic-state.h" +#include "diagnostic-state-graphs.h" #include "graphviz.h" #include "text-art/tree-widget.h" @@ -1230,8 +1230,14 @@ program_state::make_dump_widget (const text_art::dump_widget_info &dwi) const void program_state::dump_dot (const extrinsic_state &ext_state) const { - auto doc = make_xml (ext_state); - auto graph = make_dot_graph_from_xml_state (*doc); + auto state_graph = make_diagnostic_state_graph (ext_state); + + gcc_assert (global_dc); + auto logical_loc_mgr = global_dc->get_logical_location_manager (); + gcc_assert (logical_loc_mgr); + + auto graph = diagnostics::state_graphs::make_dot_graph (*state_graph, + *logical_loc_mgr); pretty_printer pp; dot::writer w (pp); diff --git a/gcc/analyzer/program-state.h b/gcc/analyzer/program-state.h index e2076c1..4278237 100644 --- a/gcc/analyzer/program-state.h +++ b/gcc/analyzer/program-state.h @@ -26,8 +26,6 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/store.h" -namespace xml { class document; } - namespace ana { /* Data shared by all program_state instances. */ @@ -248,11 +246,14 @@ public: void dump (const extrinsic_state &ext_state, bool simple) const; void dump () const; - std::unique_ptr<xml::document> make_xml (const extrinsic_state &ext_state) const; - void dump_xml_to_pp (const extrinsic_state &ext_state, pretty_printer *pp) const; - void dump_xml_to_file (const extrinsic_state &ext_state, FILE *outf) const; - void dump_xml (const extrinsic_state &ext_state) const; - void dump_dot (const extrinsic_state &ext_state) const; + std::unique_ptr<diagnostics::digraphs::digraph> + make_diagnostic_state_graph (const extrinsic_state &ext_state) const; + + void + dump_sarif (const extrinsic_state &ext_state) const; + + void + dump_dot (const extrinsic_state &ext_state) const; std::unique_ptr<json::object> to_json (const extrinsic_state &ext_state) const; diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index 3581dbb..2a218d0 100644 --- a/gcc/analyzer/sm-malloc.cc +++ b/gcc/analyzer/sm-malloc.cc @@ -436,9 +436,9 @@ public: const extrinsic_state &ext_state) const; void - add_state_to_xml (xml_state &out_xml, - const svalue &sval, - state_machine::state_t state) const final override; + add_state_to_state_graph (analyzer_state_graph &out_state_graph, + const svalue &sval, + state_machine::state_t state) const final override; standard_deallocator_set m_free; standard_deallocator_set m_scalar_delete; @@ -2735,27 +2735,57 @@ malloc_state_machine::transition_ptr_sval_non_null (region_model *model, smap->set_state (model, new_ptr_sval, m_free.m_nonnull, nullptr, ext_state); } +static enum diagnostics::state_graphs::node_dynalloc_state +get_dynalloc_state_for_state (enum resource_state rs) +{ + switch (rs) + { + default: + gcc_unreachable (); + case RS_START: + case RS_NULL: + case RS_NON_HEAP: + case RS_STOP: + return diagnostics::state_graphs::node_dynalloc_state::unknown; + + case RS_ASSUMED_NON_NULL: + return diagnostics::state_graphs::node_dynalloc_state::nonnull; + + case RS_UNCHECKED: + return diagnostics::state_graphs::node_dynalloc_state::unchecked; + case RS_NONNULL: + return diagnostics::state_graphs::node_dynalloc_state::nonnull; + case RS_FREED: + return diagnostics::state_graphs::node_dynalloc_state::freed; + } +} + void -malloc_state_machine::add_state_to_xml (xml_state &out_xml, - const svalue &sval, - state_machine::state_t state) const +malloc_state_machine:: +add_state_to_state_graph (analyzer_state_graph &out_state_graph, + const svalue &sval, + state_machine::state_t state) const { if (const region *reg = sval.maybe_get_region ()) { - auto ®_element = out_xml.get_or_create_element (*reg); + auto reg_node = out_state_graph.get_or_create_state_node (*reg); auto alloc_state = as_a_allocation_state (state); gcc_assert (alloc_state); - reg_element.set_attr ("dynamic-alloc-state", state->get_name ()); + reg_node.set_dynalloc_state + (get_dynalloc_state_for_state (alloc_state->m_rs)); if (alloc_state->m_deallocators) { pretty_printer pp; alloc_state->m_deallocators->dump_to_pp (&pp); - reg_element.set_attr ("expected-deallocators", pp_formatted_text (&pp)); + reg_node.m_node.set_attr (STATE_NODE_PREFIX, + "expected-deallocators", + pp_formatted_text (&pp)); } if (alloc_state->m_deallocator) - reg_element.set_attr ("deallocator", - alloc_state->m_deallocator->m_name); + reg_node.m_node.set_attr (STATE_NODE_PREFIX, + "deallocator", + alloc_state->m_deallocator->m_name); } } diff --git a/gcc/analyzer/sm.cc b/gcc/analyzer/sm.cc index 840806a..c93e9c2 100644 --- a/gcc/analyzer/sm.cc +++ b/gcc/analyzer/sm.cc @@ -161,16 +161,16 @@ state_machine::to_json () const } void -state_machine::add_state_to_xml (xml_state &out_xml, - const svalue &sval, - state_machine::state_t state) const +state_machine::add_state_to_state_graph (analyzer_state_graph &out_state_graph, + const svalue &sval, + state_machine::state_t state) const { // no-op } void -state_machine::add_global_state_to_xml (xml_state &out_xml, - state_machine::state_t state) const +state_machine::add_global_state_to_state_graph (analyzer_state_graph &out_state_graph, + state_machine::state_t state) const { // no-op } diff --git a/gcc/analyzer/sm.h b/gcc/analyzer/sm.h index 6298fb6..4633fac 100644 --- a/gcc/analyzer/sm.h +++ b/gcc/analyzer/sm.h @@ -28,7 +28,7 @@ namespace ana { class state_machine; class sm_context; class pending_diagnostic; -class xml_state; +class analyzer_state_graph; extern bool any_pointer_p (tree expr); extern bool any_pointer_p (const svalue *sval); @@ -188,13 +188,13 @@ public: state_t get_start_state () const { return m_start; } virtual void - add_state_to_xml (xml_state &out_xml, - const svalue &sval, - state_machine::state_t state) const; + add_state_to_state_graph (analyzer_state_graph &out_state_graph, + const svalue &sval, + state_machine::state_t state) const; virtual void - add_global_state_to_xml (xml_state &out_xml, - state_machine::state_t state) const; + add_global_state_to_state_graph (analyzer_state_graph &out_state_graph, + state_machine::state_t state) const; protected: state_t add_state (const char *name); diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc index 2196760..5226e455 100644 --- a/gcc/auto-profile.cc +++ b/gcc/auto-profile.cc @@ -53,6 +53,7 @@ along with GCC; see the file COPYING3. If not see #include "auto-profile.h" #include "tree-pretty-print.h" #include "gimple-pretty-print.h" +#include "output.h" /* The following routines implements AutoFDO optimization. @@ -430,7 +431,8 @@ public: void set_call_location (location_t l) { - gcc_checking_assert (call_location_ == UNKNOWN_LOCATION); + gcc_checking_assert (call_location_ == UNKNOWN_LOCATION + && l != UNKNOWN_LOCATION); call_location_= l; } @@ -685,6 +687,26 @@ dump_afdo_loc (FILE *f, unsigned loc) fprintf (f, "%i", loc >> 16); } +/* Return assembler name as in symbol table and DW_AT_linkage_name. */ + +static const char * +raw_symbol_name (const char *asmname) +{ + /* If we start supporting user_label_prefixes, add_linkage_attr will also + need to be fixed. */ + if (strlen (user_label_prefix)) + sorry ("auto-profile is not supported for targets with user label prefix"); + return asmname + (asmname[0] == '*'); +} + +/* Convenience wrapper that looks up assembler name. */ + +static const char * +raw_symbol_name (tree decl) +{ + return raw_symbol_name (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); +} + /* Dump STACK to F. */ static void @@ -695,7 +717,7 @@ dump_inline_stack (FILE *f, inline_stack *stack) { fprintf (f, "%s%s:", first ? "" : "; ", - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (p.decl))); + raw_symbol_name (p.decl)); dump_afdo_loc (f, p.afdo_loc); first = false; } @@ -817,7 +839,7 @@ string_table::get_index (const char *name) const int string_table::get_index_by_decl (tree decl) const { - const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); + const char *name = raw_symbol_name (decl); int ret = get_index (name); if (ret != -1) return ret; @@ -880,10 +902,9 @@ function_instance::~function_instance () cgraph_node * function_instance::get_cgraph_node () { - for (symtab_node *n = cgraph_node::get_for_asmname - (get_identifier - (afdo_string_table->get_name (name ()))); - n; n = n->next_sharing_asm_name) + const char *sname = afdo_string_table->get_name (name ()); + symtab_node *n = cgraph_node::get_for_asmname (get_identifier (sname)); + for (;n; n = n->next_sharing_asm_name) if (cgraph_node *cn = dyn_cast <cgraph_node *> (n)) if (cn->definition && cn->has_gimple_body_p ()) return cn; @@ -921,10 +942,10 @@ function_instance::get_function_instance_by_decl (unsigned lineno, dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS, dump_user_location_t::from_location_t (location), "auto-profile has mismatched function name %s" - " instaed of %s at loc %i:%i", + " insteed of %s at loc %i:%i", afdo_string_table->get_name (iter.first.second), - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), - lineno << 16, + raw_symbol_name (decl), + lineno >> 16, lineno & 65535); } @@ -1127,10 +1148,13 @@ function_instance::offline_if_in_set (name_index_set &seen, Return non-zero if it correspons and 2 if renaming was done. */ static int -match_with_target (gimple *stmt, function_instance *inlined_fn, cgraph_node *n) +match_with_target (cgraph_node *n, + gimple *stmt, + function_instance *inlined_fn, + cgraph_node *orig_callee) { - const char *symbol_name = IDENTIFIER_POINTER - (DECL_ASSEMBLER_NAME (n->decl)); + cgraph_node *callee = orig_callee->ultimate_alias_target (); + const char *symbol_name = raw_symbol_name (callee->decl); const char *name = afdo_string_table->get_name (inlined_fn->name ()); if (strcmp (name, symbol_name)) { @@ -1144,8 +1168,8 @@ match_with_target (gimple *stmt, function_instance *inlined_fn, cgraph_node *n) in_suffix = true; } /* Accept dwarf names and stripped suffixes. */ - if (!strcmp (lang_hooks.dwarf_name (n->decl, 0), - afdo_string_table->get_name (inlined_fn->name ())) + if (!strcmp (lang_hooks.dwarf_name (callee->decl, 0), + afdo_string_table->get_name (inlined_fn->name ())) || (!name[i] && symbol_name[i] == '.') || in_suffix) { @@ -1159,10 +1183,14 @@ match_with_target (gimple *stmt, function_instance *inlined_fn, cgraph_node *n) inlined_fn->set_name (index); return 2; } - warning_at (gimple_location (stmt), OPT_Wauto_profile, - "auto-profile contains inlined " - "function with symbol name %s instead of symbol name %s", - name, symbol_name); + /* Only warn about declarations. It is possible that the function is + declared as alias in other module and we inlined cross-module. */ + if (callee->definition + && warning (OPT_Wauto_profile, + "auto-profile of %q+F contains inlined " + "function with symbol name %s instead of symbol name %s", + n->decl, name, symbol_name)) + inform (gimple_location (stmt), "corresponding call"); return 0; } return 1; @@ -1205,13 +1233,14 @@ function_instance::lookup_count (location_t loc, inline_stack &stack, if (stack.length ()) { int c = pos_counts.count (stack[0].afdo_loc); - if (c > 1) - warning_at (loc, OPT_Wauto_profile, - "duplicated count information" - " in auto-profile of %q+F" - " with relative location %i discriminator %i", - node->decl, stack[0].afdo_loc >> 16, - stack[0].afdo_loc & 65535); + if (c > 1 + && warning (OPT_Wauto_profile, + "duplicated count information" + " in auto-profile of %q+F" + " with relative location %i discriminator %i", + node->decl, stack[0].afdo_loc >> 16, + stack[0].afdo_loc & 65535)) + inform (loc, "corresponding source location"); if (c) return &pos_counts[stack[0].afdo_loc]; } @@ -1273,6 +1302,7 @@ function_instance::match (cgraph_node *node, hash_set<const count_info *> counts; hash_set<const count_info *> targets; hash_set<const function_instance *> functions; + hash_set<const function_instance *> functions_to_offline; /* We try to fill in lost disciminator if there is unique call with given line number. This map is used to record them. */ @@ -1376,20 +1406,23 @@ function_instance::match (cgraph_node *node, inlined_fn_nodisc = iter.second; cnodis++; } - if (c > 1 || cnodis > 1) - warning_at (gimple_location (stmt), OPT_Wauto_profile, - "duplicated callsite in auto-profile of %q+F" - " with relative location %i, discriminator %i", - node->decl, stack[0].afdo_loc >> 16, - stack[0].afdo_loc & 65535); - if (inlined_fn && info && info->targets.size ()) - warning_at (gimple_location (stmt), OPT_Wauto_profile, - "both call targets and inline callsite" - " information is present in auto-profile" - " of function %q+F with relative location" - " %i, discriminator %i", - node->decl, stack[0].afdo_loc >> 16, - stack[0].afdo_loc & 65535); + if ((c > 1 || (!c && cnodis > 1)) + && warning (OPT_Wauto_profile, + "duplicated callsite in auto-profile of %q+F" + " with relative location %i," + " discriminator %i", + node->decl, stack[0].afdo_loc >> 16, + stack[0].afdo_loc & 65535)) + inform (gimple_location (stmt), "corresponding call"); + if (inlined_fn && info && info->targets.size () + && warning (OPT_Wauto_profile, + "both call targets and inline callsite" + " information is present in auto-profile" + " of function %q+F with relative location" + " %i, discriminator %i", + node->decl, stack[0].afdo_loc >> 16, + stack[0].afdo_loc & 65535)) + inform (gimple_location (stmt), "corresponding call"); tree callee = gimple_call_fndecl (stmt); cgraph_node *callee_node; unsigned int loc = stack[0].afdo_loc; @@ -1422,11 +1455,17 @@ function_instance::match (cgraph_node *node, if (lineno_to_call.get (stack[0].afdo_loc >> 16)->length () == 1) { - warning_at (gimple_location (stmt), OPT_Wauto_profile, - "auto-profile of %q+F seem to contain" - " lost discriminator %i for call at" - " relative location %i", - node->decl, loc & 65535, loc >> 16); + if (warning (OPT_Wauto_profile, + "auto-profile of %q+F seem to contain" + " lost discriminator %i for" + " call of %s at relative location %i", + node->decl, + loc & 65535, + afdo_string_table->get_name + (inlined_fn_nodisc->name ()), + loc >> 16)) + inform (gimple_location (stmt), + "corresponding call"); inlined_fn = inlined_fn_nodisc; if (dump_file) fprintf (dump_file, " Lost discriminator %i\n", @@ -1437,11 +1476,10 @@ function_instance::match (cgraph_node *node, } if (callee && (callee_node = cgraph_node::get (callee))) { - callee_node = callee_node->ultimate_alias_target (); if (inlined_fn) { int old_name = inlined_fn->name (); - int r = match_with_target (stmt, inlined_fn, + int r = match_with_target (node, stmt, inlined_fn, callee_node); if (r == 2) { @@ -1458,6 +1496,8 @@ function_instance::match (cgraph_node *node, } if (r) functions.add (inlined_fn); + else + functions_to_offline.add (inlined_fn); } if (info && info->targets.size () > 1) @@ -1475,19 +1515,24 @@ function_instance::match (cgraph_node *node, { if (inlined_fn && inlined_fn->get_call_location () - != UNKNOWN_LOCATION - && warning_at (gimple_location (stmt), - OPT_Wauto_profile, - "%q+F contains two calls of the same" - " relative location +%i," - " discrimnator %i," - " that leads to lost auto-profile", - node->decl, - loc << 16, - loc & 65535)) + != UNKNOWN_LOCATION) { - inform (inlined_fn->get_call_location (), - "location of the earlier call"); + if (warning (OPT_Wauto_profile, + "function contains two calls of the same" + " relative location +%i," + " discrimnator %i," + " that leads to lost auto-profile", + loc >> 16, + loc & 65535)) + { + inform (gimple_location (stmt), + "location of the first call"); + inform (inlined_fn->get_call_location (), + "location of the second call"); + } + if (dump_file) + fprintf (dump_file, + " Duplicated call location\n"); inlined_fn = NULL; } if (inlined_fn) @@ -1561,11 +1606,18 @@ function_instance::match (cgraph_node *node, (DECL_STRUCT_FUNCTION (node->decl)->function_end_locus, node->decl); unsigned int start_location = get_combined_location (DECL_STRUCT_FUNCTION (node->decl)->function_start_locus, node->decl); + /* When outputting code to builtins location we use line number 0. + craeate_gcov is stupid and hapilly computes offsets across files. + Silently ignore it. */ + unsigned int zero_location + = ((unsigned)(1-DECL_SOURCE_LINE (node->decl))) << 16; for (position_count_map::const_iterator iter = pos_counts.begin (); iter != pos_counts.end ();) if (!counts.contains (&iter->second)) { - if (iter->first != end_location && iter->first != start_location + if (iter->first != end_location + && iter->first != start_location + && (iter->first & 65535) != zero_location && iter->first) { if (!warned) @@ -1603,28 +1655,42 @@ function_instance::match (cgraph_node *node, iter != callsites.end ();) if (!functions.contains (iter->second)) { - if (!warned) - warned = warning_at (DECL_SOURCE_LOCATION (node->decl), - OPT_Wauto_profile, - "auto-profile of %q+F contains extra callsites", - node->decl); - if (warned) - inform (DECL_SOURCE_LOCATION (node->decl), - "call of %s with relative location +%i, discriminator %i", - afdo_string_table->get_name (iter->first.second), - iter->first.first >> 16, iter->first.first & 65535); - if ((iter->first.first >> 16) > (end_location >> 16) && warned) - inform (DECL_SOURCE_LOCATION (node->decl), - "location is after end of function"); - warned = true; function_instance *f = iter->second; - if (dump_file) + /* If we did not see the corresponding statement, warn. */ + if (!functions_to_offline.contains (iter->second)) + { + if (!warned) + warned = warning_at (DECL_SOURCE_LOCATION (node->decl), + OPT_Wauto_profile, + "auto-profile of %q+F contains" + " extra callsites", + node->decl); + if (warned) + inform (DECL_SOURCE_LOCATION (node->decl), + "call of %s with total count %" PRId64 + ", relative location +%i, discriminator %i", + afdo_string_table->get_name (iter->first.second), + iter->second->total_count (), + iter->first.first >> 16, iter->first.first & 65535); + if ((iter->first.first >> 16) > (end_location >> 16) && warned) + inform (DECL_SOURCE_LOCATION (node->decl), + "location is after end of function"); + if (dump_file) + { + fprintf (dump_file, + "Offlining inline with no corresponding gimple stmt "); + f->dump_inline_stack (dump_file); + fprintf (dump_file, "\n"); + } + } + else if (dump_file) { fprintf (dump_file, - "Offlining inline with no corresponding gimple stmt "); + "Offlining mismatched inline "); f->dump_inline_stack (dump_file); fprintf (dump_file, "\n"); } + warned = true; callsites.erase (iter); offline (f, new_functions); iter = callsites.begin (); @@ -1923,7 +1989,7 @@ autofdo_source_profile::offline_external_functions () FOR_EACH_DEFINED_FUNCTION (node) { const char *name - = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)); + = raw_symbol_name (node->decl); const char *dwarf_name = lang_hooks.dwarf_name (node->decl, 0); int index = afdo_string_table->get_index (name); @@ -2105,8 +2171,7 @@ walk_block (tree fn, function_instance *s, tree block) fprintf (dump_file, ":"); dump_afdo_loc (dump_file, loc); fprintf (dump_file, " %s\n", - IDENTIFIER_POINTER - (DECL_ASSEMBLER_NAME (BLOCK_ABSTRACT_ORIGIN (block)))); + raw_symbol_name (BLOCK_ABSTRACT_ORIGIN (block))); } return; } @@ -2464,7 +2529,7 @@ autofdo_source_profile::get_callsite_total_count ( { if (dump_file) fprintf (dump_file, "Mismatched name of callee %s and profile %s\n", - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (edge->callee->decl)), + raw_symbol_name (edge->callee->decl), afdo_string_table->get_name (s->name ())); return 0; } @@ -2558,8 +2623,7 @@ autofdo_source_profile::get_function_instance_by_inline_stack ( { if (dump_file) fprintf (dump_file, "No offline instance for %s\n", - IDENTIFIER_POINTER - (DECL_ASSEMBLER_NAME (stack[stack.length () - 1].decl))); + raw_symbol_name (stack[stack.length () - 1].decl)); return NULL; } function_instance *s = iter->second; @@ -2581,8 +2645,7 @@ autofdo_source_profile::get_function_instance_by_inline_stack ( "auto-profile has no inlined function instance " "for inlined call of %s at relative " " locaction +%i, discriminator %i\n", - IDENTIFIER_POINTER - (DECL_ASSEMBLER_NAME (stack[i - 1].decl)), + raw_symbol_name (stack[i - 1].decl), stack[i].afdo_loc >> 16, stack[i].afdo_loc & 65535); return NULL; diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 54dcb52..ed79d36 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,24 @@ +2025-07-11 Jakub Jelinek <jakub@redhat.com> + + PR c++/119064 + * c.opt (Wc++26-compat): New option. + * c.opt.urls: Regenerate. + * c-opts.cc (c_common_post_options): Clear warn_cxx26_compat for + C++26 or later. + * c-cppbuiltin.cc (c_cpp_builtins): For C++26 predefine + __cpp_trivial_relocatability=202502L. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + PR c++/117785 + * c-cppbuiltin.cc (c_cpp_builtins): Predefine + __cpp_constexpr_exceptions=202411L for C++26. + +2025-07-10 Qing Zhao <qing.zhao@oracle.com> + + * c-ubsan.cc (get_bound_from_access_with_size): Adjust the position + of the arguments per the new design. + 2025-07-07 Qing Zhao <qing.zhao@oracle.com> Revert: diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc index 459fd86..2f86b1f 100644 --- a/gcc/c-family/c-cppbuiltin.cc +++ b/gcc/c-family/c-cppbuiltin.cc @@ -1087,6 +1087,7 @@ c_cpp_builtins (cpp_reader *pfile) { /* Set feature test macros for C++26. */ cpp_define (pfile, "__cpp_constexpr=202406L"); + 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"); @@ -1095,6 +1096,7 @@ c_cpp_builtins (cpp_reader *pfile) cpp_define (pfile, "__cpp_pack_indexing=202311L"); cpp_define (pfile, "__cpp_pp_embed=202502L"); cpp_define (pfile, "__cpp_constexpr_virtual_inheritance=202506L"); + cpp_define (pfile, "__cpp_trivial_relocatability=202502L"); } if (flag_concepts && cxx_dialect > cxx14) cpp_define (pfile, "__cpp_concepts=202002L"); diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 3ee9444..872bdf4 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -1165,6 +1165,9 @@ c_common_post_options (const char **pfilename) warn_cxx20_compat = 0; cpp_opts->cpp_warn_cxx20_compat = 0; } + if (cxx_dialect >= cxx26) + /* Don't warn about C++26 compatibility changes in C++26 or later. */ + warn_cxx26_compat = 0; /* C++17 has stricter evaluation order requirements; let's use some of them for earlier C++ as well, so chaining works as expected. */ diff --git a/gcc/c-family/c-ubsan.cc b/gcc/c-family/c-ubsan.cc index 78b7868..a4dc310 100644 --- a/gcc/c-family/c-ubsan.cc +++ b/gcc/c-family/c-ubsan.cc @@ -397,8 +397,7 @@ get_bound_from_access_with_size (tree call) return NULL_TREE; tree ref_to_size = CALL_EXPR_ARG (call, 1); - unsigned int class_of_size = TREE_INT_CST_LOW (CALL_EXPR_ARG (call, 2)); - tree type = TREE_TYPE (CALL_EXPR_ARG (call, 3)); + tree type = TREE_TYPE (TREE_TYPE (CALL_EXPR_ARG (call, 2))); tree size = fold_build2 (MEM_REF, type, unshare_expr (ref_to_size), build_int_cst (ptr_type_node, 0)); /* If size is negative value, treat it as zero. */ @@ -410,12 +409,7 @@ get_bound_from_access_with_size (tree call) build_zero_cst (type), size); } - /* Only when class_of_size is 1, i.e, the number of the elements of - the object type, return the size. */ - if (class_of_size != 1) - return NULL_TREE; - else - size = fold_convert (sizetype, size); + size = fold_convert (sizetype, size); return size; } diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 6a55e71..12877eb 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -497,6 +497,10 @@ Wc++20-compat C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall) Init(0) CPP(cpp_warn_cxx20_compat) CppReason(CPP_W_CXX20_COMPAT) Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020. +Wc++26-compat +C++ ObjC++ Var(warn_cxx26_compat) Warning LangEnabledBy(C++ ObjC++,Wall) Init(0) +Warn about C++ constructs whose meaning differs between ISO C++ 2023 and ISO C++ 2026. + Wc++11-extensions C++ ObjC++ Var(warn_cxx11_extensions) Warning Init(1) Warn about C++11 constructs in code compiled with an older standard. diff --git a/gcc/c-family/c.opt.urls b/gcc/c-family/c.opt.urls index 401e6e7..5c97593 100644 --- a/gcc/c-family/c.opt.urls +++ b/gcc/c-family/c.opt.urls @@ -190,6 +190,9 @@ UrlSuffix(gcc/Warning-Options.html#index-Wc_002b_002b17-compat) Wc++20-compat UrlSuffix(gcc/Warning-Options.html#index-Wc_002b_002b20-compat) +Wc++26-compat +UrlSuffix(gcc/Warning-Options.html#index-Wc_002b_002b26-compat) + Wc++11-extensions UrlSuffix(gcc/Warning-Options.html#index-Wc_002b_002b11-extensions) diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index dcef284..bd139a7 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,14 @@ +2025-07-10 Qing Zhao <qing.zhao@oracle.com> + + * c-typeck.cc (build_access_with_size_for_counted_by): Update comments. + Adjust the arguments per the new design. + +2025-07-10 Qing Zhao <qing.zhao@oracle.com> + + PR middle-end/121000 + * c-typeck.cc (build_access_with_size_for_counted_by): Update comments. + Pass TYPE_SIZE_UNIT of the element as the 6th argument. + 2025-07-07 Qing Zhao <qing.zhao@oracle.com> Revert: diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index e24629b..9a5eb0d 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -2982,8 +2982,8 @@ build_counted_by_ref (tree datum, tree subdatum, tree *counted_by_type) to: - (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, 1, (TYPE_OF_SIZE)0, -1, - (TYPE_OF_ARRAY *)0)) + (*.ACCESS_WITH_SIZE (REF, COUNTED_BY_REF, (* TYPE_OF_SIZE)0, + TYPE_SIZE_UNIT for element) NOTE: The return type of this function is the POINTER type pointing to the original flexible array type. @@ -2992,11 +2992,11 @@ build_counted_by_ref (tree datum, tree subdatum, tree *counted_by_type) The type of the first argument of this function is a POINTER type to the original flexible array type. - The 4th argument of the call is a constant 0 with the TYPE of the - object pointed by COUNTED_BY_REF. + The 3rd argument of the call is a constant 0 with the pointer TYPE whose + pointee type is the TYPE of the object pointed by COUNTED_BY_REF. - The 6th argument of the call is a constant 0 with the pointer TYPE - to the original flexible array type. + The 4th argument of the call is the TYPE_SIZE_UNIT of the element TYPE + of the array. */ static tree @@ -3007,20 +3007,22 @@ build_access_with_size_for_counted_by (location_t loc, tree ref, gcc_assert (c_flexible_array_member_type_p (TREE_TYPE (ref))); /* The result type of the call is a pointer to the flexible array type. */ tree result_type = c_build_pointer_type (TREE_TYPE (ref)); + tree element_size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ref))); + tree first_param = c_fully_fold (array_to_pointer_conversion (loc, ref), false, NULL); tree second_param = c_fully_fold (counted_by_ref, false, NULL); + tree third_param = build_int_cst (build_pointer_type (counted_by_type), 0); tree call = build_call_expr_internal_loc (loc, IFN_ACCESS_WITH_SIZE, - result_type, 6, + result_type, 4, first_param, second_param, - build_int_cst (integer_type_node, 1), - build_int_cst (counted_by_type, 0), - build_int_cst (integer_type_node, -1), - build_int_cst (result_type, 0)); + third_param, + element_size); + /* Wrap the call with an INDIRECT_REF with the flexible array type. */ call = build1 (INDIRECT_REF, TREE_TYPE (ref), call); SET_EXPR_LOCATION (call, loc); diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc index 33649d4..a656cce 100644 --- a/gcc/cfgexpand.cc +++ b/gcc/cfgexpand.cc @@ -5358,6 +5358,8 @@ expand_debug_expr (tree exp) return simplify_gen_binary (MULT, mode, op0, op1); case RDIV_EXPR: + gcc_assert (FLOAT_MODE_P (mode)); + /* Fall through. */ case TRUNC_DIV_EXPR: case EXACT_DIV_EXPR: if (unsignedp) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 94a2e6e..32071a8 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -1790,6 +1790,19 @@ cgraph_update_edges_for_call_stmt_node (cgraph_node *node, if (e) { + /* If call was devirtualized during cloning, mark edge + as resolved. */ + if (e->speculative) + { + if (new_stmt && is_gimple_call (new_stmt)) + { + tree decl = gimple_call_fndecl (new_stmt); + if (decl) + e = cgraph_edge::resolve_speculation (e, decl); + } + else + e = cgraph_edge::resolve_speculation (e, NULL); + } /* Keep calls marked as dead dead. */ if (new_stmt && is_gimple_call (new_stmt) && e->callee && fndecl_built_in_p (e->callee->decl, BUILT_IN_UNREACHABLE, diff --git a/gcc/cobol/ChangeLog b/gcc/cobol/ChangeLog index 6c3e1bd..5555b8e 100644 --- a/gcc/cobol/ChangeLog +++ b/gcc/cobol/ChangeLog @@ -1,3 +1,71 @@ +2025-07-11 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> + + PR cobol/120621 + * lexio.cc (parse_replace_pairs): Cast mfile.lineno() to fmt_size_t. + * parse.y (intrinsic): Print ptrdiff_t using %ld, cast arg to long. + * scan_ante.h (numstr_of): Print nx using %ld, cast arg to long. + * util.cc (cbl_field_t::report_invalid_initial_value): Print + ptrdiff_t using %ld, cast arg to long. + +2025-07-10 James K. Lowden <jklowden@cobolworx.com> + + PR cobol/120765 + * cdf.y: Extend grammar for new CDF syntax, relocate dictionary. + * cdfval.h (cdf_dictionary): Use new CDF dictionary. + * dts.h: Remove useless assignment, note incorrect behavior. + * except.cc: Remove obsolete EC state. + * gcobol.1: Document CDF in its own section. + * genapi.cc (parser_statement_begin): Use new EC state function. + (parser_file_merge): Same. + (parser_check_fatal_exception): Same. + * genutil.cc (get_and_check_refstart_and_reflen): Same. + (get_depending_on_value_from_odo): Same. + (get_data_offset): Same. + (process_this_exception): Same. + * lexio.cc (check_push_pop_directive): New function. + (check_source_format_directive): Restrict regex search to 1 line. + (cdftext::free_form_reference_format): Use new function. + * parse.y: Define new CDF tokens, use new CDF state. + * parse_ante.h (cdf_tokens): Use new CDF state. + (redefined_token): Same. + (class prog_descr_t): Remove obsolete CDF state. + (class program_stack_t): Same. + (current_call_convention): Same. + * scan.l: Recognize new CDF tokens. + * scan_post.h (is_cdf_token): Same. + * symbols.h (cdf_current_tokens): Change current_call_convention to return void. + * token_names.h: Regenerate. + * udf/stored-char-length.cbl: Use new PUSH/POP CDF functionality. + * util.cc (class cdf_directives_t): Define cdf_directives_t. + (current_call_convention): Same. + (cdf_current_tokens): Same. + (cdf_dictionary): Same. + (cdf_enabled_exceptions): Same. + (cdf_push): Same. + (cdf_push_call_convention): Same. + (cdf_push_current_tokens): Same. + (cdf_push_dictionary): Same. + (cdf_push_enabled_exceptions): Same. + (cdf_push_source_format): Same. + (cdf_pop): Same. + (cdf_pop_call_convention): Same. + (cdf_pop_current_tokens): Same. + (cdf_pop_dictionary): Same. + (cdf_pop_enabled_exceptions): Same. + (cdf_pop_source_format): Same. + * util.h (cdf_push): Declare cdf_directives_t. + (cdf_push_call_convention): Same. + (cdf_push_current_tokens): Same. + (cdf_push_dictionary): Same. + (cdf_push_enabled_exceptions): Same. + (cdf_push_source_format): Same. + (cdf_pop): Same. + (cdf_pop_call_convention): Same. + (cdf_pop_current_tokens): Same. + (cdf_pop_dictionary): Same. + (cdf_pop_source_format): Same. + (cdf_pop_enabled_exceptions): Same. + 2025-07-09 Robert Dubner <rdubner@symas.com> James K. Lowden <jklowden@cobolworx.com> diff --git a/gcc/cobol/cdf.y b/gcc/cobol/cdf.y index f1a7912..840eb50 100644 --- a/gcc/cobol/cdf.y +++ b/gcc/cobol/cdf.y @@ -105,14 +105,14 @@ void input_file_status_notify(); using std::map; - static map<std::string, cdfval_t> dictionary; - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" static bool cdfval_add( const char name[], const cdfval_t& value, bool override = false ) { + cdf_values_t& dictionary( cdf_dictionary() ); + if( scanner_parsing() ) { if( ! override ) { if( dictionary.find(name) != dictionary.end() ) return false; @@ -123,6 +123,8 @@ void input_file_status_notify(); } static void cdfval_off( const char name[] ) { + cdf_values_t& dictionary( cdf_dictionary() ); + if( scanner_parsing() ) { auto p = dictionary.find(name); if( p == dictionary.end() ) { @@ -159,6 +161,8 @@ exception_turn_t exception_turn; bool apply_cdf_turn( const exception_turn_t& turn ) { + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); + for( auto elem : turn.exception_files() ) { std::set<size_t> files(elem.second.begin(), elem.second.end()); enabled_exceptions.turn_on_off(turn.enabled, @@ -204,15 +208,17 @@ apply_cdf_turn( const exception_turn_t& turn ) { %type <file> filename %type <files> filenames -%token BY 482 +%type <number> cdf_stackable + +%token BY 486 %token COPY 362 %token CDF_DISPLAY 384 ">>DISPLAY" -%token IN 601 +%token IN 605 %token NAME 286 %token NUMSTR 305 "numeric literal" -%token OF 682 -%token PSEUDOTEXT 717 -%token REPLACING 739 +%token OF 686 +%token PSEUDOTEXT 721 +%token REPLACING 743 %token LITERAL 298 %token SUPPRESS 376 @@ -227,25 +233,32 @@ apply_cdf_turn( const exception_turn_t& turn ) { %token CDF_WHEN 389 ">>WHEN" %token CDF_END_EVALUATE 390 ">>END-EVALUATE" -%token AS 464 CONSTANT 361 DEFINED 363 +%token ALL 450 +%token CALL_CONVENTION 391 ">>CALL-CONVENTION" +%token COBOL_WORDS 380 ">>COBOL-WORDS" +%token CDF_PUSH 394 ">>PUSH" +%token CDF_POP 395 ">>POP" +%token SOURCE_FORMAT 396 ">>SOURCE FORMAT" + +%token AS 468 CONSTANT 361 DEFINED 363 %type <boolean> DEFINED -%token OTHER 694 PARAMETER_kw 368 "PARAMETER" -%token OFF 683 OVERRIDE 369 -%token THRU 935 -%token TRUE_kw 809 "True" +%token OTHER 698 PARAMETER_kw 368 "PARAMETER" +%token OFF 687 OVERRIDE 369 +%token THRU 939 +%token TRUE_kw 813 "True" -%token CALL_COBOL 391 "CALL" -%token CALL_VERBATIM 392 "CALL (as C)" +%token CALL_COBOL 392 "CALL" +%token CALL_VERBATIM 393 "CALL (as C)" -%token TURN 811 CHECKING 492 LOCATION 645 ON 685 WITH 837 +%token TURN 815 CHECKING 496 LOCATION 649 ON 689 WITH 841 -%left OR 936 -%left AND 937 -%right NOT 938 -%left '<' '>' '=' NE 939 LE 940 GE 941 +%left OR 940 +%left AND 941 +%right NOT 942 +%left '<' '>' '=' NE 943 LE 944 GE 945 %left '-' '+' %left '*' '/' -%right NEG 943 +%right NEG 947 %define api.prefix {ydf} %define api.token.prefix{YDF_} @@ -277,6 +290,8 @@ complete: cdf_define | cdf_display | cdf_turn | cdf_call_convention + | cdf_push + | cdf_pop ; /* @@ -328,6 +343,7 @@ cdf_define: CDF_DEFINE cdf_constant NAME as cdf_expr[value] override } if( !cdfval_add( $NAME, cdfval_t($value), $override) ) { error_msg(@NAME, "name already in dictionary: %s", $NAME); + cdf_values_t& dictionary( cdf_dictionary() ); const cdfval_t& entry = dictionary[$NAME]; if( entry.filename ) { error_msg(@NAME, "%s previously defined in %s:%d", @@ -357,7 +373,7 @@ cdf_define: CDF_DEFINE cdf_constant NAME as cdf_expr[value] override * available regardless. */ { - if( 0 == dictionary.count($NAME) ) { + if( 0 == cdf_dictionary().count($NAME) ) { yywarn("CDF: '%s' is defined AS PARAMETER " "but was not defined", $NAME); } @@ -400,6 +416,35 @@ cdf_call_convention: } ; +cdf_push: CDF_PUSH cdf_stackable { + switch( $cdf_stackable ) { + case YDF_ALL: cdf_push(); break; + case YDF_CALL_CONVENTION: cdf_push_call_convention(); break; + case YDF_CDF_DEFINE: cdf_push_dictionary(); break; + case YDF_COBOL_WORDS: cdf_push_current_tokens(); break; + case YDF_SOURCE_FORMAT: cdf_push_source_format(); break; + default: gcc_unreachable(); + } + } + ; +cdf_pop: CDF_POP cdf_stackable { + switch( $cdf_stackable ) { + case YDF_ALL: cdf_pop(); break; + case YDF_CALL_CONVENTION: cdf_pop_call_convention(); break; + case YDF_CDF_DEFINE: cdf_pop_dictionary(); break; + case YDF_COBOL_WORDS: cdf_pop_current_tokens(); break; + case YDF_SOURCE_FORMAT: cdf_pop_source_format(); break; + default: gcc_unreachable(); + } + } + ; + +cdf_stackable: ALL { $$ = YDF_ALL; } + | CALL_CONVENTION { $$ = YDF_CALL_CONVENTION; } + | COBOL_WORDS { $$ = YDF_COBOL_WORDS; } + | CDF_DEFINE { $$ = YDF_CDF_DEFINE; } + | SOURCE_FORMAT { $$ = YDF_SOURCE_FORMAT; } + ; except_names: except_name | except_names except_name @@ -471,6 +516,7 @@ cdf_eval_obj: cdf_cond_expr cdf_cond_expr: BOOL | NAME DEFINED { + cdf_values_t& dictionary( cdf_dictionary() ); auto p = dictionary.find($1); bool found = p != dictionary.end(); if( !$DEFINED ) found = ! found; @@ -552,6 +598,7 @@ cdf_expr: cdf_expr '+' cdf_expr { $$ = $1(@1) + $3(@3); } ; cdf_factor: NAME { + cdf_values_t& dictionary( cdf_dictionary() ); auto that = dictionary.find($1); if( that != dictionary.end() ) { $$ = that->second; @@ -651,6 +698,7 @@ name_any: namelit name_one: NAME { + cdf_values_t& dictionary( cdf_dictionary() ); cdf_arg_t arg = { YDF_NAME, $1 }; auto p = dictionary.find($1); @@ -665,6 +713,7 @@ name_one: NAME namelit: name { + cdf_values_t& dictionary( cdf_dictionary() ); cdf_arg_t arg = { YDF_NAME, $1 }; auto p = dictionary.find($1); @@ -745,6 +794,7 @@ location_set( const YYLTYPE& loc ) { bool // used by cobol1.cc defined_cmd( const char arg[] ) { + cdf_values_t& dictionary( cdf_dictionary() ); cdfval_t value(1); char *name = xstrdup(arg); @@ -868,6 +918,7 @@ static int ydflex(void) { bool cdf_value( const char name[], const cdfval_t& value ) { + cdf_values_t& dictionary( cdf_dictionary() ); auto p = dictionary.find(name); if( p != dictionary.end() ) return false; @@ -878,6 +929,7 @@ cdf_value( const char name[], const cdfval_t& value ) { const cdfval_t * cdf_value( const char name[] ) { + cdf_values_t& dictionary( cdf_dictionary() ); auto p = dictionary.find(name); if( p == dictionary.end() ) return NULL; diff --git a/gcc/cobol/cdfval.h b/gcc/cobol/cdfval.h index 465bdbb..cc474a2 100644 --- a/gcc/cobol/cdfval.h +++ b/gcc/cobol/cdfval.h @@ -126,4 +126,8 @@ cdf_value( const char name[] ); bool cdf_value( const char name[], const cdfval_t& value ); +typedef std::map<std::string, cdfval_t> cdf_values_t; + +cdf_values_t& cdf_dictionary(); + #endif diff --git a/gcc/cobol/dts.h b/gcc/cobol/dts.h index aa3fa58..e12b979 100644 --- a/gcc/cobol/dts.h +++ b/gcc/cobol/dts.h @@ -86,18 +86,24 @@ namespace dts { #if __cpp_exceptions static const char msg[] = "input not NUL-terminated"; throw std::domain_error( msg ); -#else - // eoinput terminates input - eoinput = strchr(input, '\0'); // cppcheck-suppress uselessAssignmentPtrArg #endif } auto ncm = re.size(); cm.resize(ncm); std::vector <regmatch_t> cms(ncm); - int erc = regexec( &re, input, ncm, cms.data(), 0 ); if( erc != 0 ) return false; +#if __cpp_exceptions + // This is not correct at all, but current use depends on current behavior. + // The following line is excluded from the GCC build, which is compiled + // without __cpp_exceptions. parse_copy_directive (for one) depends on + // regex_search returning true even if the match is beyond eoinput. + if( eoinput < cm[0].second ) return false; + // Correct behavior would return match only between input and eoinput. + // Because regex(3) uses a NUL terminator, it may match text between + // eoinput and the NUL. +#endif std::transform( cms.begin(), cms.end(), cm.begin(), [input]( const regmatch_t& m ) { return csub_match( input, m ); diff --git a/gcc/cobol/except.cc b/gcc/cobol/except.cc index 60b8416..e42aea2 100644 --- a/gcc/cobol/except.cc +++ b/gcc/cobol/except.cc @@ -84,8 +84,6 @@ cbl_enabled_exception_t::dump( int i ) const { file ); } -cbl_enabled_exceptions_t enabled_exceptions; - void cbl_enabled_exceptions_t::dump() const { extern int yydebug; diff --git a/gcc/cobol/gcobol.1 b/gcc/cobol/gcobol.1 index 6db5400..ebb833c 100644 --- a/gcc/cobol/gcobol.1 +++ b/gcc/cobol/gcobol.1 @@ -587,6 +587,21 @@ statement, regardless of compile-time constants. .. . .Ss Implemented Exception Conditions +By default, per ISO, no EC is enabled. Implemented ECs may be enabled +on the command line or via the +.Sy TURN +directive. Any attempt to enable an EC that is not implemented is +treated as an error. +.Pp +An enabled EC not handled by a +.Sy DECLARATIVE +is written to the system log and to standard error. (The authors +intend to make that an option.) A fatal EC not handled with +.Sy RESUME +ends with a call to +.Xr abort 3 +and process termination. +.Pp Not all Exception Conditions are implemented. Any attempt to enable an EC that that is not implemented produces a warning message. The following are implemented: @@ -913,11 +928,90 @@ or has no effect; the two are interchangeable. .. . -.Ss Compiler-Directing Facility (CDF) +.Sh COMPILER-DIRECTING FACILITY The CDF should be used with caution because no comprehensive test -suite has been identified. +suite has been identified. . -.Ss Conditional Compilation +.Ss CDF Text Manipulation +.Bl -tag -width >>DEFINE +.It Sy COPY Ar copybook Li Oo OF|BY Ar library Oc Oo Sy REPLACING ... Oc +If +.Ar copybook +is a literal, it treated a literal filename, which either does or does not exist. If +.Ar copybook +is a \*[lang] word, +.Nm +looks first for an environment variable named +.Va copybook +and, if found, uses the contents of that variable as the name of the +copybook file. If that file does not exist, it continues looking for +a file named one of: +.sp +.Bl -bullet -compact -offset 5n +.It +.Pa copybook +(literally) +.It +.Pa copybook.cpy +.It +.Pa copybook.CPY +.It +.Pa copybook.cbl +.It +.Pa copybook.CBL +.It +.Pa copybook.cob +.It +.Pa copybook.COB +.El +.sp +in that order. It looks first in the same directory as the source +code file, and then in any +.Ar copybook-path +named with the +.Fl I +option. +. +.\" FIXME: need escape mechanism for directories with ':' in the name. +.Ar copybook-path +may (like the shell's +.Ev PATH +variable) be a colon-separated list. +The +.Fl I +option may occur multiple times on the command line. Each successive +.Ar copybook-path +is concatenated to previous ones. +Relative paths (having no leading +.Ql / Ns +\&) +are searched relative to the compiler's current working directory. +.Pp +For example, +.D1 \& +.D1 Fl I Li /usr/local/include:include +.D1 \& +searches first the directory where the \*[lang] program is found, next in +.Pa /usr/local/include , +and finally in an +.Pa include +subdirectory of the directory from which +.Nm +was invoked. +.Pp +For the +.Sy REPLACING +phrase, both the modern pseudo-text and the \*[lang]/85 forms are +recognized. (The older forms are used in the NIST CCVS/85 test suite.) +.It Sy REPLACE ... +.Nm +supports the full ISO +.Sy REPLACE +syntax. +.El +. +.Ss CDF Directives +.\"Bl -tag -width >>PROPAGATE .Bl -tag -width >>DEFINE .It >> Ns Sy DEFINE Ar name Sy AS Bro Ar expression Li | Sy PARAMETER Brc Op Sy OVERRIDE Define @@ -959,10 +1053,6 @@ is supported. Boolean literals are not supported. . .It >> Ns Sy EVALUATE Not implemented. -.El -. -.Ss Other CDF Directives -.Bl -tag -width >>PROPAGATE .It >> Ns Sy CALL-CONVENTION Ar convention .Ar convention may be one of: @@ -1036,6 +1126,24 @@ Not implemented. Not implemented. .It >> Ns Sy PROPAGATE Not implemented. +.It >> Ns Sy PUSH Ar directive +.It >> Ns Sy POP Ar directive +With +.Sy PUSH , +push CDF state onto a stack. +With +.Sy POP , +return to the prior pushed state. +.Ar directive +may be one of +.Bl -tag -compact +.It Sy CALL-CONVENTION +.It Sy COBOL-WORDS +.It Sy DEFINE +.It Sy SOURCE FORMAT +.It Sy TURN +.El +. .It >> Ns Sy TURN Oo .Ar ec Oo Ar file Li ... Oc ... .Oc Sy CHECKING Bro Oo Sy ON Oc Oo Oo Sy WITH Oc Sy LOCATION Oc | Sy OFF Brc @@ -1087,76 +1195,6 @@ the directive must appear before To test a feature-set variable, use .Dl >>IF Ar feature Li DEFINED . -.Ss Copybooks -.Nm -supports the CDF -.Sy COPY -statement, with or without its -.Sy REPLACING -component. For any statement -.sp -.D1 COPY Ar copybook -.sp -.Nm -looks first for an environment variable named -.Va copybook -and, if found, uses the contents of that variable as the name of the -copybook file. If that file does not exist, it continues looking for -a file named one of: -.sp -.Bl -bullet -compact -offset 5n -.It -.Pa copybook -(literally) -.It -.Pa copybook.cpy -.It -.Pa copybook.CPY -.It -.Pa copybook.cbl -.It -.Pa copybook.CBL -.It -.Pa copybook.cob -.It -.Pa copybook.COB -.El -.sp -in that order. It looks first in the same directory as the source -code file, and then in any -.Ar copybook-path -named with the -.Fl I -option. -. -.\" FIXME: need escape mechanism for directories with ':' in the name. -.Ar copybook-path -may (like the shell's -.Ev PATH -variable) be a colon-separated list. -. -The -.Fl I -option may occur multiple times on the command line. Each successive -.Ar copybook-path -is concatenated to previous ones. -Relative paths (having no leading -.Ql / Ns -\&) -are searched relative to the compiler's current working directory. -.Pp -For example, -.D1 \& -.D1 Fl I Li /usr/local/include:include -.D1 \& -searches first the directory where the \*[lang] program is found, next in -.Pa /usr/local/include , -and finally in an -.Pa include -subdirectory of the directory from which -.Nm -was invoked. -. .Ss Intrinsic functions .Nm implements all intrinsic functions defined by \*[isostd], plus a few diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index 55db870..3c4e9a9 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -1166,7 +1166,7 @@ parser_statement_begin( const cbl_name_t statement_name, // the execution time of a program doing two-billion simple adds in an inner // loop dropped from 3.8 seconds to 0.175 seconds. - bool exception_processing = enabled_exceptions.size() ; + bool exception_processing = cdf_enabled_exceptions().size() ; if( !exception_processing ) { @@ -12236,6 +12236,8 @@ parser_file_merge( cbl_file_t *workfile, ELSE ENDIF + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); + for(size_t i=0; i<ninputs; i++) { if( process_this_exception(ec_sort_merge_file_open_e) ) @@ -13905,7 +13907,7 @@ parser_check_fatal_exception() // in its innermost loop had an execution time of 19.5 seconds. By putting in // the if() statement, that was reduced to 3.8 seconds. - if( enabled_exceptions.size() || sv_is_i_o ) + if( cdf_enabled_exceptions().size() || sv_is_i_o ) { gg_call(VOID, "__gg__check_fatal_exception", diff --git a/gcc/cobol/genutil.cc b/gcc/cobol/genutil.cc index 1d921a3..e09b1bf 100644 --- a/gcc/cobol/genutil.cc +++ b/gcc/cobol/genutil.cc @@ -307,6 +307,8 @@ get_and_check_refstart_and_reflen( tree refstart,// LONG returned value tree reflen, // LONG returned value cbl_refer_t &refer) { + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); + if( !enabled_exceptions.match(ec_bound_ref_mod_e) ) { // This is normal operation -- no exception checking. Thus, we won't @@ -458,6 +460,7 @@ get_depending_on_value_from_odo(tree retval, cbl_field_t *odo) declarative with a RESUME NEXT STATEMENT, or before the default_condition processing can do a controlled exit. */ + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); cbl_field_t *depending_on; depending_on = cbl_field_of(symbol_at(odo->occurs.depending_on)); @@ -601,6 +604,7 @@ get_data_offset(cbl_refer_t &refer, } else { + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); if( !enabled_exceptions.match(ec_bound_subscript_e) ) { // With no exception testing, just pick up the value @@ -657,6 +661,8 @@ get_data_offset(cbl_refer_t &refer, // Although we strictly don't need to look at the ODO value at this point, // we do want it checked for the purposes of ec-bound-odo + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); + if( enabled_exceptions.match(ec_bound_odo_e) ) { if( parent->occurs.depending_on ) @@ -1669,6 +1675,7 @@ set_exception_code_func(ec_type_t ec, int /*line*/, int from_raise_statement) bool process_this_exception(ec_type_t ec) { + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); bool retval; if( enabled_exceptions.match(ec) || !skip_exception_processing ) { diff --git a/gcc/cobol/lexio.cc b/gcc/cobol/lexio.cc index 4a50441..dc632c2 100644 --- a/gcc/cobol/lexio.cc +++ b/gcc/cobol/lexio.cc @@ -321,7 +321,69 @@ recognize_replacements( filespan_t mfile, std::list<replace_t>& pending_replacem } static void +check_push_pop_directive( filespan_t& mfile ) { + char eol = '\0'; + const char *p = std::find(mfile.cur, mfile.eol, '>'); + if( ! (p < mfile.eol && p[1] == *p ) ) return; + + const char pattern[] = + ">>[[:blank:]]*(push|pop)[[:blank:]]+" + "(" + "all|" + "call-convention|" + "cobol-words|" + "define|" + "source[[:blank:]]+format|" + "turn" + ")"; + static regex re(pattern, extended_icase); + + // show contents of marked subexpressions within each match + cmatch cm; + + std::swap(*mfile.eol, eol); // see implementation for excuses + bool ok = regex_search(p, const_cast<const char *>(mfile.eol), cm, re); + std::swap(*mfile.eol, eol); + + if( ok ) { + gcc_assert(cm.size() > 1); + bool push = TOUPPER(cm[1].first[1]) == 'U'; + switch( TOUPPER(cm[2].first[0]) ) { + case 'A': // ALL + push? cdf_push() : cdf_pop(); + break; + case 'C': + switch( TOUPPER(cm[2].first[1]) ) { + case 'A': // CALL-CONVENTION + push? cdf_push_call_convention() : cdf_pop_call_convention(); + break; + case 'O': // COBOL-WORDS + push? cdf_push_current_tokens() : cdf_pop_current_tokens(); + break; + default: + gcc_unreachable(); + } + break; + case 'D': // DEFINE + push? cdf_push_dictionary() : cdf_pop_dictionary(); + break; + case 'S': // SOURCE FORMAT + push? cdf_push_source_format() : cdf_pop_source_format(); + break; + case 'T': // TURN + push? cdf_push_enabled_exceptions() : cdf_pop_enabled_exceptions(); + break; + default: + gcc_unreachable(); + } + erase_line(const_cast<char*>(cm[0].first), + const_cast<char*>(cm[0].second)); + } +} + +static void check_source_format_directive( filespan_t& mfile ) { + char eol = '\0'; const char *p = std::find(mfile.cur, mfile.eol, '>'); if( ! (p < mfile.eol && p[1] == *p ) ) return; @@ -334,7 +396,12 @@ check_source_format_directive( filespan_t& mfile ) { // show contents of marked subexpressions within each match cmatch cm; - if( regex_search(p, const_cast<const char *>(mfile.eol), cm, re) ) { + + std::swap(*mfile.eol, eol); // see implementation for excuses + bool ok = regex_search(p, const_cast<const char *>(mfile.eol), cm, re); + std::swap(*mfile.eol, eol); + + if( ok ) { gcc_assert(cm.size() > 1); switch( cm[3].length() ) { case 4: @@ -353,8 +420,8 @@ check_source_format_directive( filespan_t& mfile ) { cdf_source_format().description(), (fmt_size_t)mfile.lineno() ); char *bol = cdf_source_format().is_fixed()? mfile.cur : const_cast<char*>(cm[0].first); + gcc_assert(cm[0].second <= mfile.eol); erase_line(bol, const_cast<char*>(cm[0].second)); - mfile.cur = const_cast<char*>(cm[0].second); } } @@ -1688,6 +1755,7 @@ cdftext::free_form_reference_format( int input ) { } while( mfile.next_line() ) { + check_push_pop_directive(mfile); check_source_format_directive(mfile); remove_inline_comment(mfile.cur, mfile.eol); @@ -1836,7 +1904,7 @@ cdftext::process_file( filespan_t mfile, int output, bool second_pass ) { []( char ch ) { return ch == '\n'; } ); struct { int in, out; filespan_t mfile; } copy; dbgmsg("%s:%d: line " HOST_SIZE_T_PRINT_UNSIGNED ", opening %s on fd %d", - __func__, __LINE__,mfile.lineno(), + __func__, __LINE__, (fmt_size_t)mfile.lineno(), copybook.source(), copybook.current()->fd); copy.in = copybook.current()->fd; copy.mfile = free_form_reference_format( copy.in ); diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 2212acc..7bcbf74 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -386,7 +386,10 @@ CDF_EVALUATE ">>EVALUATE" CDF_WHEN ">>WHEN" CDF_END_EVALUATE ">>END-EVALUATE" + CALL_CONVENTION ">>CALL-CONVENTION" CALL_COBOL "CALL" CALL_VERBATIM "CALL (as C)" + CDF_PUSH ">>PUSH" CDF_POP ">>POP" + SOURCE_FORMAT ">>SOURCE FORMAT" IF THEN ELSE SENTENCE @@ -1469,16 +1472,16 @@ cobol_words: cobol_words1 | cobol_words cobol_words1 ; cobol_words1: COBOL_WORDS EQUATE NAME[keyword] WITH NAME[name] { - if( ! tokens.equate(@keyword, $keyword, $name) ) { YYERROR; } + if( ! cdf_tokens.equate(@keyword, $keyword, $name) ) { YYERROR; } } | COBOL_WORDS UNDEFINE NAME[keyword] { - if( ! tokens.undefine(@keyword, $keyword) ) { YYERROR; } + if( ! cdf_tokens.undefine(@keyword, $keyword) ) { YYERROR; } } | COBOL_WORDS SUBSTITUTE NAME[keyword] BY NAME[name] { - if( ! tokens.substitute(@keyword, $keyword, $name) ) { YYERROR; } + if( ! cdf_tokens.substitute(@keyword, $keyword, $name) ) { YYERROR; } } | COBOL_WORDS RESERVE NAME[name] { - if( ! tokens.reserve(@name, $name) ) { YYERROR; } + if( ! cdf_tokens.reserve(@name, $name) ) { YYERROR; } } ; @@ -4915,6 +4918,7 @@ by_value_arg: scalar declaratives: %empty | DECLARATIVES '.' <label>{ + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); current.enabled_exception_cache = enabled_exceptions; enabled_exceptions.clear(); current.doing_declaratives(true); @@ -4933,6 +4937,7 @@ declaratives: %empty * forward reference, because we haven't yet begun to parse * nondeclarative procedures. */ + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); parser_label_label($label); enabled_exceptions = current.enabled_exception_cache; current.enabled_exception_cache.clear(); @@ -10311,8 +10316,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 %zu (%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)? @@ -11433,6 +11438,7 @@ void ast_call( const YYLTYPE& loc, cbl_refer_t name, const cbl_refer_t& returnin */ static bool possible_ec() { + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); bool format_1 = current.declaratives.has_format_1(); bool enabled = 0xFF < (current.declaratives.status() @@ -11455,6 +11461,7 @@ possible_ec() { */ static void statement_epilog( int token ) { + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); if( possible_ec() && token != CONTINUE ) { if( enabled_exceptions.size() ) { current.declaratives_evaluate(); @@ -11517,7 +11524,7 @@ keyword_str( int token ) { return ascii; } - return tokens.name_of(token); + return cdf_tokens.name_of(token); } bool iso_cobol_word( const std::string& name, bool include_context ); @@ -11589,7 +11596,7 @@ current_tokens_t::tokenset_t::find( const cbl_name_t name, bool include_intrinsi int keyword_tok( const char * text, bool include_intrinsics ) { - return tokens.find(text, include_intrinsics); + return cdf_tokens.find(text, include_intrinsics); } static inline size_t @@ -13131,7 +13138,7 @@ cobol_dialect_set( cbl_dialect_t dialect ) { break; case dialect_gnu_e: if( 0 == (cbl_dialects & dialect) ) { // first time - tokens.equate(YYLTYPE(), "BINARY-DOUBLE", "BINARY-C-LONG"); + cdf_tokens.equate(YYLTYPE(), "BINARY-DOUBLE", "BINARY-C-LONG"); } break; } diff --git a/gcc/cobol/parse_ante.h b/gcc/cobol/parse_ante.h index 3543a00..fa06e6c 100644 --- a/gcc/cobol/parse_ante.h +++ b/gcc/cobol/parse_ante.h @@ -935,11 +935,11 @@ teed_up_names() { return name_queue_t::namelist_of( name_queue.peek() ); } -current_tokens_t tokens; +#define cdf_tokens cdf_current_tokens() int redefined_token( const cbl_name_t name ) { - return tokens.redefined_as(name); + return cdf_tokens.redefined_as(name); } struct file_list_t { @@ -1321,7 +1321,6 @@ class prog_descr_t { } } } locale; - cbl_call_convention_t call_convention; cbl_options_t options; explicit prog_descr_t( size_t isymbol ) @@ -1330,9 +1329,7 @@ class prog_descr_t { , paragraph(NULL) , section(NULL) , collating_sequence(NULL) - { - call_convention = current_call_convention(); - } + {} std::set<std::string> external_targets() { std::set<std::string> externals; @@ -1421,24 +1418,13 @@ static cbl_label_t * implicit_section(); class program_stack_t : protected std::stack<prog_descr_t> { struct pending_t { - cbl_call_convention_t call_convention; bool initial; - pending_t() - : call_convention(cbl_call_convention_t(0)) - , initial(false) - {} + pending_t() : initial(false) {} } pending; public: - cbl_call_convention_t - pending_call_convention( cbl_call_convention_t convention ) { - return pending.call_convention = convention; - } bool pending_initial() { return pending.initial = true; } void push( prog_descr_t descr ) { - cbl_call_convention_t call_convention = cbl_call_cobol_e; - if( !empty() ) call_convention = top().call_convention; - descr.call_convention = call_convention; std::stack<prog_descr_t>& me(*this); me.push(descr); } @@ -1464,9 +1450,6 @@ class program_stack_t : protected std::stack<prog_descr_t> { } void apply_pending() { - if( size() == 1 && 0 != pending.call_convention ) { - top().call_convention = pending.call_convention; - } if( pending.initial ) { auto e = symbol_at(top().program_index); auto prog(cbl_label_of(e)); @@ -1873,19 +1856,6 @@ static class current_t { return programs.top().options.default_round = mode; } - cbl_call_convention_t - call_convention() { - return programs.empty()? cbl_call_cobol_e : programs.top().call_convention; - } - cbl_call_convention_t - call_convention( cbl_call_convention_t convention) { - if( programs.empty() ) { - return programs.pending_call_convention(convention); - } - auto& prog( programs.top() ); - return prog.call_convention = convention; - } - const char * locale() { return programs.empty()? NULL : programs.top().locale.os_name; @@ -1983,6 +1953,7 @@ static class current_t { * ISO, in new_program. */ std::set<std::string> end_program() { + cbl_enabled_exceptions_t& enabled_exceptions( cdf_enabled_exceptions() ); if( enabled_exceptions.size() ) { declaratives_evaluate(); } @@ -2273,15 +2244,6 @@ current_rounded_mode( cbl_round_t rounded) { #endif static cbl_round_t current_rounded_mode( int token ); -cbl_call_convention_t -current_call_convention() { - return current.call_convention(); -} -cbl_call_convention_t -current_call_convention( cbl_call_convention_t convention) { - return current.call_convention(convention); -} - size_t program_level() { return current.program_level(); } static size_t constant_index( int token ); diff --git a/gcc/cobol/scan.l b/gcc/cobol/scan.l index 3c12eda..8b5dc25 100644 --- a/gcc/cobol/scan.l +++ b/gcc/cobol/scan.l @@ -2095,15 +2095,28 @@ BASIS { yy_push_state(basis); return BASIS; } ^[ ]*>>{OBLANK}TURN { yy_push_state(exception); return TURN; } ^[ ]*>>{OBLANK}COBOL-WORDS { yy_push_state(cobol_words); return COBOL_WORDS; } + ^[ ]*>>{OBLANK}SOURCE{BLANK}FORMAT { return SOURCE_FORMAT; } + + ^[ ]*>>{OBLANK}PUSH { return CDF_PUSH; } + ^[ ]*>>{OBLANK}POP { return CDF_POP; } + ^[ ]*>>{OBLANK}{NAME} { error_msg(yylloc, "unknown CDF token: %s", yytext); } + OTHER { return OTHER; } OVERRIDE { return OVERRIDE; } PARAMETER { return PARAMETER_kw; } THRU { return THRU; } TRUE { return TRUE_kw; } + + ALL { return ALL; } + CALL-CONVENTION { return CALL_CONVENTION; } + COBOL-WORDS { return COBOL_WORDS; } + DEFINE { return CDF_DEFINE; } + SOURCE{BLANK}FORMAT { return SOURCE_FORMAT; } + } <cobol_words>{ diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h index 6960739..88a8e8c 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 (%zu)", 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/scan_post.h b/gcc/cobol/scan_post.h index fd70ea9..7cf2b98 100644 --- a/gcc/cobol/scan_post.h +++ b/gcc/cobol/scan_post.h @@ -158,6 +158,8 @@ is_cdf_token( int token ) { case CDF_DISPLAY: case CDF_IF: case CDF_ELSE: case CDF_END_IF: case CDF_EVALUATE: case CDF_WHEN: case CDF_END_EVALUATE: + case CDF_PUSH: + case CDF_POP: return true; case CALL_COBOL: case CALL_VERBATIM: diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h index f96f1ec..c3de0aa 100644 --- a/gcc/cobol/symbols.h +++ b/gcc/cobol/symbols.h @@ -2551,8 +2551,9 @@ class current_tokens_t { }; cbl_call_convention_t current_call_convention(); +current_tokens_t& cdf_current_tokens(); -cbl_call_convention_t +void current_call_convention( cbl_call_convention_t convention); class procref_base_t { diff --git a/gcc/cobol/token_names.h b/gcc/cobol/token_names.h index d35b706..ca51510 100644 --- a/gcc/cobol/token_names.h +++ b/gcc/cobol/token_names.h @@ -1,5 +1,5 @@ // generated by ./token_names.h.gen ../../build/gcc/cobol/parse.h -// Fri Jul 4 12:35:01 EDT 2025 +// Tue Jul 8 19:21:28 EDT 2025 tokens = { { "identification", IDENTIFICATION_DIV }, // 258 { "environment", ENVIRONMENT_DIV }, // 259 @@ -137,562 +137,566 @@ tokens = { { "cdf-evaluate", CDF_EVALUATE }, // 388 { "cdf-when", CDF_WHEN }, // 389 { "cdf-end-evaluate", CDF_END_EVALUATE }, // 390 - { "call-cobol", CALL_COBOL }, // 391 - { "call-verbatim", CALL_VERBATIM }, // 392 - { "if", IF }, // 393 - { "then", THEN }, // 394 - { "else", ELSE }, // 395 - { "sentence", SENTENCE }, // 396 - { "accept", ACCEPT }, // 397 - { "add", ADD }, // 398 - { "alter", ALTER }, // 399 - { "call", CALL }, // 400 - { "cancel", CANCEL }, // 401 - { "close", CLOSE }, // 402 - { "compute", COMPUTE }, // 403 - { "continue", CONTINUE }, // 404 - { "delete", DELETE }, // 405 - { "display", DISPLAY }, // 406 - { "divide", DIVIDE }, // 407 - { "evaluate", EVALUATE }, // 408 - { "exit", EXIT }, // 409 - { "filler", FILLER_kw }, // 410 - { "goback", GOBACK }, // 411 - { "goto", GOTO }, // 412 - { "initialize", INITIALIZE }, // 413 - { "inspect", INSPECT }, // 414 - { "merge", MERGE }, // 415 - { "move", MOVE }, // 416 - { "multiply", MULTIPLY }, // 417 - { "open", OPEN }, // 418 - { "paragraph", PARAGRAPH }, // 419 - { "read", READ }, // 420 - { "release", RELEASE }, // 421 - { "return", RETURN }, // 422 - { "rewrite", REWRITE }, // 423 - { "search", SEARCH }, // 424 - { "set", SET }, // 425 - { "select", SELECT }, // 426 - { "sort", SORT }, // 427 - { "sort-merge", SORT_MERGE }, // 428 - { "string", STRING_kw }, // 429 - { "stop", STOP }, // 430 - { "subtract", SUBTRACT }, // 431 - { "start", START }, // 432 - { "unstring", UNSTRING }, // 433 - { "write", WRITE }, // 434 - { "when", WHEN }, // 435 - { "argument-number", ARGUMENT_NUMBER }, // 436 - { "argument-value", ARGUMENT_VALUE }, // 437 - { "environment-name", ENVIRONMENT_NAME }, // 438 - { "environment-value", ENVIRONMENT_VALUE }, // 439 - { "abs", ABS }, // 440 - { "access", ACCESS }, // 441 - { "acos", ACOS }, // 442 - { "actual", ACTUAL }, // 443 - { "advancing", ADVANCING }, // 444 - { "after", AFTER }, // 445 - { "all", ALL }, // 446 - { "allocate", ALLOCATE }, // 447 - { "alphabet", ALPHABET }, // 448 - { "alphabetic", ALPHABETIC }, // 449 - { "alphabetic-lower", ALPHABETIC_LOWER }, // 450 - { "alphabetic-upper", ALPHABETIC_UPPER }, // 451 - { "alphanumeric", ALPHANUMERIC }, // 452 - { "alphanumeric-edited", ALPHANUMERIC_EDITED }, // 453 - { "also", ALSO }, // 454 - { "alternate", ALTERNATE }, // 455 - { "annuity", ANNUITY }, // 456 - { "anum", ANUM }, // 457 - { "any", ANY }, // 458 - { "anycase", ANYCASE }, // 459 - { "apply", APPLY }, // 460 - { "are", ARE }, // 461 - { "area", AREA }, // 462 - { "areas", AREAS }, // 463 - { "as", AS }, // 464 - { "ascending", ASCENDING }, // 465 - { "activating", ACTIVATING }, // 466 - { "asin", ASIN }, // 467 - { "assign", ASSIGN }, // 468 - { "at", AT }, // 469 - { "atan", ATAN }, // 470 - { "based", BASED }, // 471 - { "baseconvert", BASECONVERT }, // 472 - { "before", BEFORE }, // 473 - { "binary", BINARY }, // 474 - { "bit", BIT }, // 475 - { "bit-of", BIT_OF }, // 476 - { "bit-to-char", BIT_TO_CHAR }, // 477 - { "blank", BLANK }, // 478 - { "block", BLOCK_kw }, // 479 - { "boolean-of-integer", BOOLEAN_OF_INTEGER }, // 480 - { "bottom", BOTTOM }, // 481 - { "by", BY }, // 482 - { "byte", BYTE }, // 483 - { "byte-length", BYTE_LENGTH }, // 484 - { "cf", CF }, // 485 - { "ch", CH }, // 486 - { "changed", CHANGED }, // 487 - { "char", CHAR }, // 488 - { "char-national", CHAR_NATIONAL }, // 489 - { "character", CHARACTER }, // 490 - { "characters", CHARACTERS }, // 491 - { "checking", CHECKING }, // 492 - { "class", CLASS }, // 493 - { "cobol", COBOL }, // 494 - { "code", CODE }, // 495 - { "code-set", CODESET }, // 496 - { "collating", COLLATING }, // 497 - { "column", COLUMN }, // 498 - { "combined-datetime", COMBINED_DATETIME }, // 499 - { "comma", COMMA }, // 500 - { "command-line", COMMAND_LINE }, // 501 - { "command-line-count", COMMAND_LINE_COUNT }, // 502 - { "commit", COMMIT }, // 503 - { "common", COMMON }, // 504 - { "concat", CONCAT }, // 505 - { "condition", CONDITION }, // 506 - { "configuration", CONFIGURATION_SECT }, // 507 - { "contains", CONTAINS }, // 508 - { "content", CONTENT }, // 509 - { "control", CONTROL }, // 510 - { "controls", CONTROLS }, // 511 - { "convert", CONVERT }, // 512 - { "converting", CONVERTING }, // 513 - { "corresponding", CORRESPONDING }, // 514 - { "cos", COS }, // 515 - { "count", COUNT }, // 516 - { "currency", CURRENCY }, // 517 - { "current", CURRENT }, // 518 - { "current-date", CURRENT_DATE }, // 519 - { "data", DATA }, // 520 - { "date", DATE }, // 521 - { "date-compiled", DATE_COMPILED }, // 522 - { "date-of-integer", DATE_OF_INTEGER }, // 523 - { "date-to-yyyymmdd", DATE_TO_YYYYMMDD }, // 524 - { "date-written", DATE_WRITTEN }, // 525 - { "day", DAY }, // 526 - { "day-of-integer", DAY_OF_INTEGER }, // 527 - { "day-of-week", DAY_OF_WEEK }, // 528 - { "day-to-yyyyddd", DAY_TO_YYYYDDD }, // 529 - { "dbcs", DBCS }, // 530 - { "de", DE }, // 531 - { "debugging", DEBUGGING }, // 532 - { "decimal-point", DECIMAL_POINT }, // 533 - { "declaratives", DECLARATIVES }, // 534 - { "default", DEFAULT }, // 535 - { "delimited", DELIMITED }, // 536 - { "delimiter", DELIMITER }, // 537 - { "depending", DEPENDING }, // 538 - { "descending", DESCENDING }, // 539 - { "detail", DETAIL }, // 540 - { "direct", DIRECT }, // 541 - { "direct-access", DIRECT_ACCESS }, // 542 - { "down", DOWN }, // 543 - { "duplicates", DUPLICATES }, // 544 - { "dynamic", DYNAMIC }, // 545 - { "e", E }, // 546 - { "ebcdic", EBCDIC }, // 547 - { "ec", EC }, // 548 - { "egcs", EGCS }, // 549 - { "entry", ENTRY }, // 550 - { "environment", ENVIRONMENT }, // 551 - { "equal", EQUAL }, // 552 - { "every", EVERY }, // 553 - { "examine", EXAMINE }, // 554 - { "exhibit", EXHIBIT }, // 555 - { "exp", EXP }, // 556 - { "exp10", EXP10 }, // 557 - { "extend", EXTEND }, // 558 - { "external", EXTERNAL }, // 559 - { "exception-file", EXCEPTION_FILE }, // 560 - { "exception-file-n", EXCEPTION_FILE_N }, // 561 - { "exception-location", EXCEPTION_LOCATION }, // 562 - { "exception-location-n", EXCEPTION_LOCATION_N }, // 563 - { "exception-statement", EXCEPTION_STATEMENT }, // 564 - { "exception-status", EXCEPTION_STATUS }, // 565 - { "factorial", FACTORIAL }, // 566 - { "false", FALSE_kw }, // 567 - { "fd", FD }, // 568 - { "file-control", FILE_CONTROL }, // 569 - { "file", FILE_KW }, // 570 - { "file-limit", FILE_LIMIT }, // 571 - { "final", FINAL }, // 572 - { "finally", FINALLY }, // 573 - { "find-string", FIND_STRING }, // 574 - { "first", FIRST }, // 575 - { "fixed", FIXED }, // 576 - { "footing", FOOTING }, // 577 - { "for", FOR }, // 578 - { "formatted-current-date", FORMATTED_CURRENT_DATE }, // 579 - { "formatted-date", FORMATTED_DATE }, // 580 - { "formatted-datetime", FORMATTED_DATETIME }, // 581 - { "formatted-time", FORMATTED_TIME }, // 582 - { "form-overflow", FORM_OVERFLOW }, // 583 - { "free", FREE }, // 584 - { "fraction-part", FRACTION_PART }, // 585 - { "from", FROM }, // 586 - { "function", FUNCTION }, // 587 - { "generate", GENERATE }, // 588 - { "giving", GIVING }, // 589 - { "global", GLOBAL }, // 590 - { "go", GO }, // 591 - { "group", GROUP }, // 592 - { "heading", HEADING }, // 593 - { "hex", HEX }, // 594 - { "hex-of", HEX_OF }, // 595 - { "hex-to-char", HEX_TO_CHAR }, // 596 - { "high-values", HIGH_VALUES }, // 597 - { "highest-algebraic", HIGHEST_ALGEBRAIC }, // 598 - { "hold", HOLD }, // 599 - { "ibm-360", IBM_360 }, // 600 - { "in", IN }, // 601 - { "include", INCLUDE }, // 602 - { "index", INDEX }, // 603 - { "indexed", INDEXED }, // 604 - { "indicate", INDICATE }, // 605 - { "initial", INITIAL_kw }, // 606 - { "initiate", INITIATE }, // 607 - { "input", INPUT }, // 608 - { "installation", INSTALLATION }, // 609 - { "interface", INTERFACE }, // 610 - { "integer", INTEGER }, // 611 - { "integer-of-boolean", INTEGER_OF_BOOLEAN }, // 612 - { "integer-of-date", INTEGER_OF_DATE }, // 613 - { "integer-of-day", INTEGER_OF_DAY }, // 614 - { "integer-of-formatted-date", INTEGER_OF_FORMATTED_DATE }, // 615 - { "integer-part", INTEGER_PART }, // 616 - { "into", INTO }, // 617 - { "intrinsic", INTRINSIC }, // 618 - { "invoke", INVOKE }, // 619 - { "i-o", IO }, // 620 - { "i-o-control", IO_CONTROL }, // 621 - { "is", IS }, // 622 - { "isnt", ISNT }, // 623 - { "kanji", KANJI }, // 624 - { "key", KEY }, // 625 - { "label", LABEL }, // 626 - { "last", LAST }, // 627 - { "leading", LEADING }, // 628 - { "left", LEFT }, // 629 - { "length", LENGTH }, // 630 - { "length-of", LENGTH_OF }, // 631 - { "limit", LIMIT }, // 632 - { "limits", LIMITS }, // 633 - { "line", LINE }, // 634 - { "lines", LINES }, // 635 - { "line-counter", LINE_COUNTER }, // 636 - { "linage", LINAGE }, // 637 - { "linkage", LINKAGE }, // 638 - { "locale", LOCALE }, // 639 - { "locale-compare", LOCALE_COMPARE }, // 640 - { "locale-date", LOCALE_DATE }, // 641 - { "locale-time", LOCALE_TIME }, // 642 - { "locale-time-from-seconds", LOCALE_TIME_FROM_SECONDS }, // 643 - { "local-storage", LOCAL_STORAGE }, // 644 - { "location", LOCATION }, // 645 - { "lock", LOCK }, // 646 - { "lock-on", LOCK_ON }, // 647 - { "log", LOG }, // 648 - { "log10", LOG10 }, // 649 - { "lower-case", LOWER_CASE }, // 650 - { "low-values", LOW_VALUES }, // 651 - { "lowest-algebraic", LOWEST_ALGEBRAIC }, // 652 - { "lparen", LPAREN }, // 653 - { "manual", MANUAL }, // 654 - { "maxx", MAXX }, // 655 - { "mean", MEAN }, // 656 - { "median", MEDIAN }, // 657 - { "midrange", MIDRANGE }, // 658 - { "minn", MINN }, // 659 - { "multiple", MULTIPLE }, // 660 - { "mod", MOD }, // 661 - { "mode", MODE }, // 662 - { "module-name", MODULE_NAME }, // 663 - { "named", NAMED }, // 664 - { "nat", NAT }, // 665 - { "national", NATIONAL }, // 666 - { "national-edited", NATIONAL_EDITED }, // 667 - { "national-of", NATIONAL_OF }, // 668 - { "native", NATIVE }, // 669 - { "nested", NESTED }, // 670 - { "next", NEXT }, // 671 - { "no", NO }, // 672 - { "note", NOTE }, // 673 - { "nulls", NULLS }, // 674 - { "null", NULLS }, // 674 - { "nullptr", NULLPTR }, // 675 - { "numeric", NUMERIC }, // 676 - { "numeric-edited", NUMERIC_EDITED }, // 677 - { "numval", NUMVAL }, // 678 - { "numval-c", NUMVAL_C }, // 679 - { "numval-f", NUMVAL_F }, // 680 - { "occurs", OCCURS }, // 681 - { "of", OF }, // 682 - { "off", OFF }, // 683 - { "omitted", OMITTED }, // 684 - { "on", ON }, // 685 - { "only", ONLY }, // 686 - { "optional", OPTIONAL }, // 687 - { "options", OPTIONS }, // 688 - { "ord", ORD }, // 689 - { "order", ORDER }, // 690 - { "ord-max", ORD_MAX }, // 691 - { "ord-min", ORD_MIN }, // 692 - { "organization", ORGANIZATION }, // 693 - { "other", OTHER }, // 694 - { "otherwise", OTHERWISE }, // 695 - { "output", OUTPUT }, // 696 - { "packed-decimal", PACKED_DECIMAL }, // 697 - { "padding", PADDING }, // 698 - { "page", PAGE }, // 699 - { "page-counter", PAGE_COUNTER }, // 700 - { "pf", PF }, // 701 - { "ph", PH }, // 702 - { "pi", PI }, // 703 - { "pic", PIC }, // 704 - { "picture", PICTURE }, // 705 - { "plus", PLUS }, // 706 - { "present-value", PRESENT_VALUE }, // 707 - { "print-switch", PRINT_SWITCH }, // 708 - { "procedure", PROCEDURE }, // 709 - { "procedures", PROCEDURES }, // 710 - { "proceed", PROCEED }, // 711 - { "process", PROCESS }, // 712 - { "program-id", PROGRAM_ID }, // 713 - { "program", PROGRAM_kw }, // 714 - { "property", PROPERTY }, // 715 - { "prototype", PROTOTYPE }, // 716 - { "pseudotext", PSEUDOTEXT }, // 717 - { "quotes", QUOTES }, // 718 - { "quote", QUOTES }, // 718 - { "random", RANDOM }, // 719 - { "random-seed", RANDOM_SEED }, // 720 - { "range", RANGE }, // 721 - { "raise", RAISE }, // 722 - { "raising", RAISING }, // 723 - { "rd", RD }, // 724 - { "record", RECORD }, // 725 - { "recording", RECORDING }, // 726 - { "records", RECORDS }, // 727 - { "recursive", RECURSIVE }, // 728 - { "redefines", REDEFINES }, // 729 - { "reel", REEL }, // 730 - { "reference", REFERENCE }, // 731 - { "relative", RELATIVE }, // 732 - { "rem", REM }, // 733 - { "remainder", REMAINDER }, // 734 - { "remarks", REMARKS }, // 735 - { "removal", REMOVAL }, // 736 - { "renames", RENAMES }, // 737 - { "replace", REPLACE }, // 738 - { "replacing", REPLACING }, // 739 - { "report", REPORT }, // 740 - { "reporting", REPORTING }, // 741 - { "reports", REPORTS }, // 742 - { "repository", REPOSITORY }, // 743 - { "rerun", RERUN }, // 744 - { "reserve", RESERVE }, // 745 - { "restricted", RESTRICTED }, // 746 - { "resume", RESUME }, // 747 - { "reverse", REVERSE }, // 748 - { "reversed", REVERSED }, // 749 - { "rewind", REWIND }, // 750 - { "rf", RF }, // 751 - { "rh", RH }, // 752 - { "right", RIGHT }, // 753 - { "rounded", ROUNDED }, // 754 - { "run", RUN }, // 755 - { "same", SAME }, // 756 - { "screen", SCREEN }, // 757 - { "sd", SD }, // 758 - { "seconds-from-formatted-time", SECONDS_FROM_FORMATTED_TIME }, // 759 - { "seconds-past-midnight", SECONDS_PAST_MIDNIGHT }, // 760 - { "security", SECURITY }, // 761 - { "separate", SEPARATE }, // 762 - { "sequence", SEQUENCE }, // 763 - { "sequential", SEQUENTIAL }, // 764 - { "sharing", SHARING }, // 765 - { "simple-exit", SIMPLE_EXIT }, // 766 - { "sign", SIGN }, // 767 - { "sin", SIN }, // 768 - { "size", SIZE }, // 769 - { "smallest-algebraic", SMALLEST_ALGEBRAIC }, // 770 - { "source", SOURCE }, // 771 - { "source-computer", SOURCE_COMPUTER }, // 772 - { "special-names", SPECIAL_NAMES }, // 773 - { "sqrt", SQRT }, // 774 - { "stack", STACK }, // 775 - { "standard", STANDARD }, // 776 - { "standard-1", STANDARD_1 }, // 777 - { "standard-deviation", STANDARD_DEVIATION }, // 778 - { "standard-compare", STANDARD_COMPARE }, // 779 - { "status", STATUS }, // 780 - { "strong", STRONG }, // 781 - { "substitute", SUBSTITUTE }, // 782 - { "sum", SUM }, // 783 - { "symbol", SYMBOL }, // 784 - { "symbolic", SYMBOLIC }, // 785 - { "synchronized", SYNCHRONIZED }, // 786 - { "tally", TALLY }, // 787 - { "tallying", TALLYING }, // 788 - { "tan", TAN }, // 789 - { "terminate", TERMINATE }, // 790 - { "test", TEST }, // 791 - { "test-date-yyyymmdd", TEST_DATE_YYYYMMDD }, // 792 - { "test-day-yyyyddd", TEST_DAY_YYYYDDD }, // 793 - { "test-formatted-datetime", TEST_FORMATTED_DATETIME }, // 794 - { "test-numval", TEST_NUMVAL }, // 795 - { "test-numval-c", TEST_NUMVAL_C }, // 796 - { "test-numval-f", TEST_NUMVAL_F }, // 797 - { "than", THAN }, // 798 - { "time", TIME }, // 799 - { "times", TIMES }, // 800 - { "to", TO }, // 801 - { "top", TOP }, // 802 - { "top-level", TOP_LEVEL }, // 803 - { "tracks", TRACKS }, // 804 - { "track-area", TRACK_AREA }, // 805 - { "trailing", TRAILING }, // 806 - { "transform", TRANSFORM }, // 807 - { "trim", TRIM }, // 808 - { "true", TRUE_kw }, // 809 - { "try", TRY }, // 810 - { "turn", TURN }, // 811 - { "type", TYPE }, // 812 - { "typedef", TYPEDEF }, // 813 - { "ulength", ULENGTH }, // 814 - { "unbounded", UNBOUNDED }, // 815 - { "unit", UNIT }, // 816 - { "units", UNITS }, // 817 - { "unit-record", UNIT_RECORD }, // 818 - { "until", UNTIL }, // 819 - { "up", UP }, // 820 - { "upon", UPON }, // 821 - { "upos", UPOS }, // 822 - { "upper-case", UPPER_CASE }, // 823 - { "usage", USAGE }, // 824 - { "using", USING }, // 825 - { "usubstr", USUBSTR }, // 826 - { "usupplementary", USUPPLEMENTARY }, // 827 - { "utility", UTILITY }, // 828 - { "uuid4", UUID4 }, // 829 - { "uvalid", UVALID }, // 830 - { "uwidth", UWIDTH }, // 831 - { "value", VALUE }, // 832 - { "variance", VARIANCE }, // 833 - { "varying", VARYING }, // 834 - { "volatile", VOLATILE }, // 835 - { "when-compiled", WHEN_COMPILED }, // 836 - { "with", WITH }, // 837 - { "working-storage", WORKING_STORAGE }, // 838 - { "xml", XML }, // 839 - { "xmlgenerate", XMLGENERATE }, // 840 - { "xmlparse", XMLPARSE }, // 841 - { "year-to-yyyy", YEAR_TO_YYYY }, // 842 - { "yyyyddd", YYYYDDD }, // 843 - { "yyyymmdd", YYYYMMDD }, // 844 - { "arithmetic", ARITHMETIC }, // 845 - { "attribute", ATTRIBUTE }, // 846 - { "auto", AUTO }, // 847 - { "automatic", AUTOMATIC }, // 848 - { "away-from-zero", AWAY_FROM_ZERO }, // 849 - { "background-color", BACKGROUND_COLOR }, // 850 - { "bell", BELL }, // 851 - { "binary-encoding", BINARY_ENCODING }, // 852 - { "blink", BLINK }, // 853 - { "capacity", CAPACITY }, // 854 - { "center", CENTER }, // 855 - { "classification", CLASSIFICATION }, // 856 - { "cycle", CYCLE }, // 857 - { "decimal-encoding", DECIMAL_ENCODING }, // 858 - { "entry-convention", ENTRY_CONVENTION }, // 859 - { "eol", EOL }, // 860 - { "eos", EOS }, // 861 - { "erase", ERASE }, // 862 - { "expands", EXPANDS }, // 863 - { "float-binary", FLOAT_BINARY }, // 864 - { "float-decimal", FLOAT_DECIMAL }, // 865 - { "foreground-color", FOREGROUND_COLOR }, // 866 - { "forever", FOREVER }, // 867 - { "full", FULL }, // 868 - { "highlight", HIGHLIGHT }, // 869 - { "high-order-left", HIGH_ORDER_LEFT }, // 870 - { "high-order-right", HIGH_ORDER_RIGHT }, // 871 - { "ignoring", IGNORING }, // 872 - { "implements", IMPLEMENTS }, // 873 - { "initialized", INITIALIZED }, // 874 - { "intermediate", INTERMEDIATE }, // 875 - { "lc-all", LC_ALL_kw }, // 876 - { "lc-collate", LC_COLLATE_kw }, // 877 - { "lc-ctype", LC_CTYPE_kw }, // 878 - { "lc-messages", LC_MESSAGES_kw }, // 879 - { "lc-monetary", LC_MONETARY_kw }, // 880 - { "lc-numeric", LC_NUMERIC_kw }, // 881 - { "lc-time", LC_TIME_kw }, // 882 - { "lowlight", LOWLIGHT }, // 883 - { "nearest-away-from-zero", NEAREST_AWAY_FROM_ZERO }, // 884 - { "nearest-even", NEAREST_EVEN }, // 885 - { "nearest-toward-zero", NEAREST_TOWARD_ZERO }, // 886 - { "none", NONE }, // 887 - { "normal", NORMAL }, // 888 - { "numbers", NUMBERS }, // 889 - { "prefixed", PREFIXED }, // 890 - { "previous", PREVIOUS }, // 891 - { "prohibited", PROHIBITED }, // 892 - { "relation", RELATION }, // 893 - { "required", REQUIRED }, // 894 - { "reverse-video", REVERSE_VIDEO }, // 895 - { "rounding", ROUNDING }, // 896 - { "seconds", SECONDS }, // 897 - { "secure", SECURE }, // 898 - { "short", SHORT }, // 899 - { "signed", SIGNED_kw }, // 900 - { "standard-binary", STANDARD_BINARY }, // 901 - { "standard-decimal", STANDARD_DECIMAL }, // 902 - { "statement", STATEMENT }, // 903 - { "step", STEP }, // 904 - { "structure", STRUCTURE }, // 905 - { "toward-greater", TOWARD_GREATER }, // 906 - { "toward-lesser", TOWARD_LESSER }, // 907 - { "truncation", TRUNCATION }, // 908 - { "ucs-4", UCS_4 }, // 909 - { "underline", UNDERLINE }, // 910 - { "unsigned", UNSIGNED_kw }, // 911 - { "utf-16", UTF_16 }, // 912 - { "utf-8", UTF_8 }, // 913 - { "address", ADDRESS }, // 914 - { "end-accept", END_ACCEPT }, // 915 - { "end-add", END_ADD }, // 916 - { "end-call", END_CALL }, // 917 - { "end-compute", END_COMPUTE }, // 918 - { "end-delete", END_DELETE }, // 919 - { "end-display", END_DISPLAY }, // 920 - { "end-divide", END_DIVIDE }, // 921 - { "end-evaluate", END_EVALUATE }, // 922 - { "end-multiply", END_MULTIPLY }, // 923 - { "end-perform", END_PERFORM }, // 924 - { "end-read", END_READ }, // 925 - { "end-return", END_RETURN }, // 926 - { "end-rewrite", END_REWRITE }, // 927 - { "end-search", END_SEARCH }, // 928 - { "end-start", END_START }, // 929 - { "end-string", END_STRING }, // 930 - { "end-subtract", END_SUBTRACT }, // 931 - { "end-unstring", END_UNSTRING }, // 932 - { "end-write", END_WRITE }, // 933 - { "end-if", END_IF }, // 934 - { "thru", THRU }, // 935 - { "through", THRU }, // 935 - { "or", OR }, // 936 - { "and", AND }, // 937 - { "not", NOT }, // 938 - { "ne", NE }, // 939 - { "le", LE }, // 940 - { "ge", GE }, // 941 - { "pow", POW }, // 942 - { "neg", NEG }, // 943 + { "call-convention", CALL_CONVENTION }, // 391 + { "call-cobol", CALL_COBOL }, // 392 + { "call-verbatim", CALL_VERBATIM }, // 393 + { "cdf-push", CDF_PUSH }, // 394 + { "cdf-pop", CDF_POP }, // 395 + { "source-format", SOURCE_FORMAT }, // 396 + { "if", IF }, // 397 + { "then", THEN }, // 398 + { "else", ELSE }, // 399 + { "sentence", SENTENCE }, // 400 + { "accept", ACCEPT }, // 401 + { "add", ADD }, // 402 + { "alter", ALTER }, // 403 + { "call", CALL }, // 404 + { "cancel", CANCEL }, // 405 + { "close", CLOSE }, // 406 + { "compute", COMPUTE }, // 407 + { "continue", CONTINUE }, // 408 + { "delete", DELETE }, // 409 + { "display", DISPLAY }, // 410 + { "divide", DIVIDE }, // 411 + { "evaluate", EVALUATE }, // 412 + { "exit", EXIT }, // 413 + { "filler", FILLER_kw }, // 414 + { "goback", GOBACK }, // 415 + { "goto", GOTO }, // 416 + { "initialize", INITIALIZE }, // 417 + { "inspect", INSPECT }, // 418 + { "merge", MERGE }, // 419 + { "move", MOVE }, // 420 + { "multiply", MULTIPLY }, // 421 + { "open", OPEN }, // 422 + { "paragraph", PARAGRAPH }, // 423 + { "read", READ }, // 424 + { "release", RELEASE }, // 425 + { "return", RETURN }, // 426 + { "rewrite", REWRITE }, // 427 + { "search", SEARCH }, // 428 + { "set", SET }, // 429 + { "select", SELECT }, // 430 + { "sort", SORT }, // 431 + { "sort-merge", SORT_MERGE }, // 432 + { "string", STRING_kw }, // 433 + { "stop", STOP }, // 434 + { "subtract", SUBTRACT }, // 435 + { "start", START }, // 436 + { "unstring", UNSTRING }, // 437 + { "write", WRITE }, // 438 + { "when", WHEN }, // 439 + { "argument-number", ARGUMENT_NUMBER }, // 440 + { "argument-value", ARGUMENT_VALUE }, // 441 + { "environment-name", ENVIRONMENT_NAME }, // 442 + { "environment-value", ENVIRONMENT_VALUE }, // 443 + { "abs", ABS }, // 444 + { "access", ACCESS }, // 445 + { "acos", ACOS }, // 446 + { "actual", ACTUAL }, // 447 + { "advancing", ADVANCING }, // 448 + { "after", AFTER }, // 449 + { "all", ALL }, // 450 + { "allocate", ALLOCATE }, // 451 + { "alphabet", ALPHABET }, // 452 + { "alphabetic", ALPHABETIC }, // 453 + { "alphabetic-lower", ALPHABETIC_LOWER }, // 454 + { "alphabetic-upper", ALPHABETIC_UPPER }, // 455 + { "alphanumeric", ALPHANUMERIC }, // 456 + { "alphanumeric-edited", ALPHANUMERIC_EDITED }, // 457 + { "also", ALSO }, // 458 + { "alternate", ALTERNATE }, // 459 + { "annuity", ANNUITY }, // 460 + { "anum", ANUM }, // 461 + { "any", ANY }, // 462 + { "anycase", ANYCASE }, // 463 + { "apply", APPLY }, // 464 + { "are", ARE }, // 465 + { "area", AREA }, // 466 + { "areas", AREAS }, // 467 + { "as", AS }, // 468 + { "ascending", ASCENDING }, // 469 + { "activating", ACTIVATING }, // 470 + { "asin", ASIN }, // 471 + { "assign", ASSIGN }, // 472 + { "at", AT }, // 473 + { "atan", ATAN }, // 474 + { "based", BASED }, // 475 + { "baseconvert", BASECONVERT }, // 476 + { "before", BEFORE }, // 477 + { "binary", BINARY }, // 478 + { "bit", BIT }, // 479 + { "bit-of", BIT_OF }, // 480 + { "bit-to-char", BIT_TO_CHAR }, // 481 + { "blank", BLANK }, // 482 + { "block", BLOCK_kw }, // 483 + { "boolean-of-integer", BOOLEAN_OF_INTEGER }, // 484 + { "bottom", BOTTOM }, // 485 + { "by", BY }, // 486 + { "byte", BYTE }, // 487 + { "byte-length", BYTE_LENGTH }, // 488 + { "cf", CF }, // 489 + { "ch", CH }, // 490 + { "changed", CHANGED }, // 491 + { "char", CHAR }, // 492 + { "char-national", CHAR_NATIONAL }, // 493 + { "character", CHARACTER }, // 494 + { "characters", CHARACTERS }, // 495 + { "checking", CHECKING }, // 496 + { "class", CLASS }, // 497 + { "cobol", COBOL }, // 498 + { "code", CODE }, // 499 + { "code-set", CODESET }, // 500 + { "collating", COLLATING }, // 501 + { "column", COLUMN }, // 502 + { "combined-datetime", COMBINED_DATETIME }, // 503 + { "comma", COMMA }, // 504 + { "command-line", COMMAND_LINE }, // 505 + { "command-line-count", COMMAND_LINE_COUNT }, // 506 + { "commit", COMMIT }, // 507 + { "common", COMMON }, // 508 + { "concat", CONCAT }, // 509 + { "condition", CONDITION }, // 510 + { "configuration", CONFIGURATION_SECT }, // 511 + { "contains", CONTAINS }, // 512 + { "content", CONTENT }, // 513 + { "control", CONTROL }, // 514 + { "controls", CONTROLS }, // 515 + { "convert", CONVERT }, // 516 + { "converting", CONVERTING }, // 517 + { "corresponding", CORRESPONDING }, // 518 + { "cos", COS }, // 519 + { "count", COUNT }, // 520 + { "currency", CURRENCY }, // 521 + { "current", CURRENT }, // 522 + { "current-date", CURRENT_DATE }, // 523 + { "data", DATA }, // 524 + { "date", DATE }, // 525 + { "date-compiled", DATE_COMPILED }, // 526 + { "date-of-integer", DATE_OF_INTEGER }, // 527 + { "date-to-yyyymmdd", DATE_TO_YYYYMMDD }, // 528 + { "date-written", DATE_WRITTEN }, // 529 + { "day", DAY }, // 530 + { "day-of-integer", DAY_OF_INTEGER }, // 531 + { "day-of-week", DAY_OF_WEEK }, // 532 + { "day-to-yyyyddd", DAY_TO_YYYYDDD }, // 533 + { "dbcs", DBCS }, // 534 + { "de", DE }, // 535 + { "debugging", DEBUGGING }, // 536 + { "decimal-point", DECIMAL_POINT }, // 537 + { "declaratives", DECLARATIVES }, // 538 + { "default", DEFAULT }, // 539 + { "delimited", DELIMITED }, // 540 + { "delimiter", DELIMITER }, // 541 + { "depending", DEPENDING }, // 542 + { "descending", DESCENDING }, // 543 + { "detail", DETAIL }, // 544 + { "direct", DIRECT }, // 545 + { "direct-access", DIRECT_ACCESS }, // 546 + { "down", DOWN }, // 547 + { "duplicates", DUPLICATES }, // 548 + { "dynamic", DYNAMIC }, // 549 + { "e", E }, // 550 + { "ebcdic", EBCDIC }, // 551 + { "ec", EC }, // 552 + { "egcs", EGCS }, // 553 + { "entry", ENTRY }, // 554 + { "environment", ENVIRONMENT }, // 555 + { "equal", EQUAL }, // 556 + { "every", EVERY }, // 557 + { "examine", EXAMINE }, // 558 + { "exhibit", EXHIBIT }, // 559 + { "exp", EXP }, // 560 + { "exp10", EXP10 }, // 561 + { "extend", EXTEND }, // 562 + { "external", EXTERNAL }, // 563 + { "exception-file", EXCEPTION_FILE }, // 564 + { "exception-file-n", EXCEPTION_FILE_N }, // 565 + { "exception-location", EXCEPTION_LOCATION }, // 566 + { "exception-location-n", EXCEPTION_LOCATION_N }, // 567 + { "exception-statement", EXCEPTION_STATEMENT }, // 568 + { "exception-status", EXCEPTION_STATUS }, // 569 + { "factorial", FACTORIAL }, // 570 + { "false", FALSE_kw }, // 571 + { "fd", FD }, // 572 + { "file-control", FILE_CONTROL }, // 573 + { "file", FILE_KW }, // 574 + { "file-limit", FILE_LIMIT }, // 575 + { "final", FINAL }, // 576 + { "finally", FINALLY }, // 577 + { "find-string", FIND_STRING }, // 578 + { "first", FIRST }, // 579 + { "fixed", FIXED }, // 580 + { "footing", FOOTING }, // 581 + { "for", FOR }, // 582 + { "formatted-current-date", FORMATTED_CURRENT_DATE }, // 583 + { "formatted-date", FORMATTED_DATE }, // 584 + { "formatted-datetime", FORMATTED_DATETIME }, // 585 + { "formatted-time", FORMATTED_TIME }, // 586 + { "form-overflow", FORM_OVERFLOW }, // 587 + { "free", FREE }, // 588 + { "fraction-part", FRACTION_PART }, // 589 + { "from", FROM }, // 590 + { "function", FUNCTION }, // 591 + { "generate", GENERATE }, // 592 + { "giving", GIVING }, // 593 + { "global", GLOBAL }, // 594 + { "go", GO }, // 595 + { "group", GROUP }, // 596 + { "heading", HEADING }, // 597 + { "hex", HEX }, // 598 + { "hex-of", HEX_OF }, // 599 + { "hex-to-char", HEX_TO_CHAR }, // 600 + { "high-values", HIGH_VALUES }, // 601 + { "highest-algebraic", HIGHEST_ALGEBRAIC }, // 602 + { "hold", HOLD }, // 603 + { "ibm-360", IBM_360 }, // 604 + { "in", IN }, // 605 + { "include", INCLUDE }, // 606 + { "index", INDEX }, // 607 + { "indexed", INDEXED }, // 608 + { "indicate", INDICATE }, // 609 + { "initial", INITIAL_kw }, // 610 + { "initiate", INITIATE }, // 611 + { "input", INPUT }, // 612 + { "installation", INSTALLATION }, // 613 + { "interface", INTERFACE }, // 614 + { "integer", INTEGER }, // 615 + { "integer-of-boolean", INTEGER_OF_BOOLEAN }, // 616 + { "integer-of-date", INTEGER_OF_DATE }, // 617 + { "integer-of-day", INTEGER_OF_DAY }, // 618 + { "integer-of-formatted-date", INTEGER_OF_FORMATTED_DATE }, // 619 + { "integer-part", INTEGER_PART }, // 620 + { "into", INTO }, // 621 + { "intrinsic", INTRINSIC }, // 622 + { "invoke", INVOKE }, // 623 + { "i-o", IO }, // 624 + { "i-o-control", IO_CONTROL }, // 625 + { "is", IS }, // 626 + { "isnt", ISNT }, // 627 + { "kanji", KANJI }, // 628 + { "key", KEY }, // 629 + { "label", LABEL }, // 630 + { "last", LAST }, // 631 + { "leading", LEADING }, // 632 + { "left", LEFT }, // 633 + { "length", LENGTH }, // 634 + { "length-of", LENGTH_OF }, // 635 + { "limit", LIMIT }, // 636 + { "limits", LIMITS }, // 637 + { "line", LINE }, // 638 + { "lines", LINES }, // 639 + { "line-counter", LINE_COUNTER }, // 640 + { "linage", LINAGE }, // 641 + { "linkage", LINKAGE }, // 642 + { "locale", LOCALE }, // 643 + { "locale-compare", LOCALE_COMPARE }, // 644 + { "locale-date", LOCALE_DATE }, // 645 + { "locale-time", LOCALE_TIME }, // 646 + { "locale-time-from-seconds", LOCALE_TIME_FROM_SECONDS }, // 647 + { "local-storage", LOCAL_STORAGE }, // 648 + { "location", LOCATION }, // 649 + { "lock", LOCK }, // 650 + { "lock-on", LOCK_ON }, // 651 + { "log", LOG }, // 652 + { "log10", LOG10 }, // 653 + { "lower-case", LOWER_CASE }, // 654 + { "low-values", LOW_VALUES }, // 655 + { "lowest-algebraic", LOWEST_ALGEBRAIC }, // 656 + { "lparen", LPAREN }, // 657 + { "manual", MANUAL }, // 658 + { "maxx", MAXX }, // 659 + { "mean", MEAN }, // 660 + { "median", MEDIAN }, // 661 + { "midrange", MIDRANGE }, // 662 + { "minn", MINN }, // 663 + { "multiple", MULTIPLE }, // 664 + { "mod", MOD }, // 665 + { "mode", MODE }, // 666 + { "module-name", MODULE_NAME }, // 667 + { "named", NAMED }, // 668 + { "nat", NAT }, // 669 + { "national", NATIONAL }, // 670 + { "national-edited", NATIONAL_EDITED }, // 671 + { "national-of", NATIONAL_OF }, // 672 + { "native", NATIVE }, // 673 + { "nested", NESTED }, // 674 + { "next", NEXT }, // 675 + { "no", NO }, // 676 + { "note", NOTE }, // 677 + { "nulls", NULLS }, // 678 + { "null", NULLS }, // 678 + { "nullptr", NULLPTR }, // 679 + { "numeric", NUMERIC }, // 680 + { "numeric-edited", NUMERIC_EDITED }, // 681 + { "numval", NUMVAL }, // 682 + { "numval-c", NUMVAL_C }, // 683 + { "numval-f", NUMVAL_F }, // 684 + { "occurs", OCCURS }, // 685 + { "of", OF }, // 686 + { "off", OFF }, // 687 + { "omitted", OMITTED }, // 688 + { "on", ON }, // 689 + { "only", ONLY }, // 690 + { "optional", OPTIONAL }, // 691 + { "options", OPTIONS }, // 692 + { "ord", ORD }, // 693 + { "order", ORDER }, // 694 + { "ord-max", ORD_MAX }, // 695 + { "ord-min", ORD_MIN }, // 696 + { "organization", ORGANIZATION }, // 697 + { "other", OTHER }, // 698 + { "otherwise", OTHERWISE }, // 699 + { "output", OUTPUT }, // 700 + { "packed-decimal", PACKED_DECIMAL }, // 701 + { "padding", PADDING }, // 702 + { "page", PAGE }, // 703 + { "page-counter", PAGE_COUNTER }, // 704 + { "pf", PF }, // 705 + { "ph", PH }, // 706 + { "pi", PI }, // 707 + { "pic", PIC }, // 708 + { "picture", PICTURE }, // 709 + { "plus", PLUS }, // 710 + { "present-value", PRESENT_VALUE }, // 711 + { "print-switch", PRINT_SWITCH }, // 712 + { "procedure", PROCEDURE }, // 713 + { "procedures", PROCEDURES }, // 714 + { "proceed", PROCEED }, // 715 + { "process", PROCESS }, // 716 + { "program-id", PROGRAM_ID }, // 717 + { "program", PROGRAM_kw }, // 718 + { "property", PROPERTY }, // 719 + { "prototype", PROTOTYPE }, // 720 + { "pseudotext", PSEUDOTEXT }, // 721 + { "quotes", QUOTES }, // 722 + { "quote", QUOTES }, // 722 + { "random", RANDOM }, // 723 + { "random-seed", RANDOM_SEED }, // 724 + { "range", RANGE }, // 725 + { "raise", RAISE }, // 726 + { "raising", RAISING }, // 727 + { "rd", RD }, // 728 + { "record", RECORD }, // 729 + { "recording", RECORDING }, // 730 + { "records", RECORDS }, // 731 + { "recursive", RECURSIVE }, // 732 + { "redefines", REDEFINES }, // 733 + { "reel", REEL }, // 734 + { "reference", REFERENCE }, // 735 + { "relative", RELATIVE }, // 736 + { "rem", REM }, // 737 + { "remainder", REMAINDER }, // 738 + { "remarks", REMARKS }, // 739 + { "removal", REMOVAL }, // 740 + { "renames", RENAMES }, // 741 + { "replace", REPLACE }, // 742 + { "replacing", REPLACING }, // 743 + { "report", REPORT }, // 744 + { "reporting", REPORTING }, // 745 + { "reports", REPORTS }, // 746 + { "repository", REPOSITORY }, // 747 + { "rerun", RERUN }, // 748 + { "reserve", RESERVE }, // 749 + { "restricted", RESTRICTED }, // 750 + { "resume", RESUME }, // 751 + { "reverse", REVERSE }, // 752 + { "reversed", REVERSED }, // 753 + { "rewind", REWIND }, // 754 + { "rf", RF }, // 755 + { "rh", RH }, // 756 + { "right", RIGHT }, // 757 + { "rounded", ROUNDED }, // 758 + { "run", RUN }, // 759 + { "same", SAME }, // 760 + { "screen", SCREEN }, // 761 + { "sd", SD }, // 762 + { "seconds-from-formatted-time", SECONDS_FROM_FORMATTED_TIME }, // 763 + { "seconds-past-midnight", SECONDS_PAST_MIDNIGHT }, // 764 + { "security", SECURITY }, // 765 + { "separate", SEPARATE }, // 766 + { "sequence", SEQUENCE }, // 767 + { "sequential", SEQUENTIAL }, // 768 + { "sharing", SHARING }, // 769 + { "simple-exit", SIMPLE_EXIT }, // 770 + { "sign", SIGN }, // 771 + { "sin", SIN }, // 772 + { "size", SIZE }, // 773 + { "smallest-algebraic", SMALLEST_ALGEBRAIC }, // 774 + { "source", SOURCE }, // 775 + { "source-computer", SOURCE_COMPUTER }, // 776 + { "special-names", SPECIAL_NAMES }, // 777 + { "sqrt", SQRT }, // 778 + { "stack", STACK }, // 779 + { "standard", STANDARD }, // 780 + { "standard-1", STANDARD_1 }, // 781 + { "standard-deviation", STANDARD_DEVIATION }, // 782 + { "standard-compare", STANDARD_COMPARE }, // 783 + { "status", STATUS }, // 784 + { "strong", STRONG }, // 785 + { "substitute", SUBSTITUTE }, // 786 + { "sum", SUM }, // 787 + { "symbol", SYMBOL }, // 788 + { "symbolic", SYMBOLIC }, // 789 + { "synchronized", SYNCHRONIZED }, // 790 + { "tally", TALLY }, // 791 + { "tallying", TALLYING }, // 792 + { "tan", TAN }, // 793 + { "terminate", TERMINATE }, // 794 + { "test", TEST }, // 795 + { "test-date-yyyymmdd", TEST_DATE_YYYYMMDD }, // 796 + { "test-day-yyyyddd", TEST_DAY_YYYYDDD }, // 797 + { "test-formatted-datetime", TEST_FORMATTED_DATETIME }, // 798 + { "test-numval", TEST_NUMVAL }, // 799 + { "test-numval-c", TEST_NUMVAL_C }, // 800 + { "test-numval-f", TEST_NUMVAL_F }, // 801 + { "than", THAN }, // 802 + { "time", TIME }, // 803 + { "times", TIMES }, // 804 + { "to", TO }, // 805 + { "top", TOP }, // 806 + { "top-level", TOP_LEVEL }, // 807 + { "tracks", TRACKS }, // 808 + { "track-area", TRACK_AREA }, // 809 + { "trailing", TRAILING }, // 810 + { "transform", TRANSFORM }, // 811 + { "trim", TRIM }, // 812 + { "true", TRUE_kw }, // 813 + { "try", TRY }, // 814 + { "turn", TURN }, // 815 + { "type", TYPE }, // 816 + { "typedef", TYPEDEF }, // 817 + { "ulength", ULENGTH }, // 818 + { "unbounded", UNBOUNDED }, // 819 + { "unit", UNIT }, // 820 + { "units", UNITS }, // 821 + { "unit-record", UNIT_RECORD }, // 822 + { "until", UNTIL }, // 823 + { "up", UP }, // 824 + { "upon", UPON }, // 825 + { "upos", UPOS }, // 826 + { "upper-case", UPPER_CASE }, // 827 + { "usage", USAGE }, // 828 + { "using", USING }, // 829 + { "usubstr", USUBSTR }, // 830 + { "usupplementary", USUPPLEMENTARY }, // 831 + { "utility", UTILITY }, // 832 + { "uuid4", UUID4 }, // 833 + { "uvalid", UVALID }, // 834 + { "uwidth", UWIDTH }, // 835 + { "value", VALUE }, // 836 + { "variance", VARIANCE }, // 837 + { "varying", VARYING }, // 838 + { "volatile", VOLATILE }, // 839 + { "when-compiled", WHEN_COMPILED }, // 840 + { "with", WITH }, // 841 + { "working-storage", WORKING_STORAGE }, // 842 + { "xml", XML }, // 843 + { "xmlgenerate", XMLGENERATE }, // 844 + { "xmlparse", XMLPARSE }, // 845 + { "year-to-yyyy", YEAR_TO_YYYY }, // 846 + { "yyyyddd", YYYYDDD }, // 847 + { "yyyymmdd", YYYYMMDD }, // 848 + { "arithmetic", ARITHMETIC }, // 849 + { "attribute", ATTRIBUTE }, // 850 + { "auto", AUTO }, // 851 + { "automatic", AUTOMATIC }, // 852 + { "away-from-zero", AWAY_FROM_ZERO }, // 853 + { "background-color", BACKGROUND_COLOR }, // 854 + { "bell", BELL }, // 855 + { "binary-encoding", BINARY_ENCODING }, // 856 + { "blink", BLINK }, // 857 + { "capacity", CAPACITY }, // 858 + { "center", CENTER }, // 859 + { "classification", CLASSIFICATION }, // 860 + { "cycle", CYCLE }, // 861 + { "decimal-encoding", DECIMAL_ENCODING }, // 862 + { "entry-convention", ENTRY_CONVENTION }, // 863 + { "eol", EOL }, // 864 + { "eos", EOS }, // 865 + { "erase", ERASE }, // 866 + { "expands", EXPANDS }, // 867 + { "float-binary", FLOAT_BINARY }, // 868 + { "float-decimal", FLOAT_DECIMAL }, // 869 + { "foreground-color", FOREGROUND_COLOR }, // 870 + { "forever", FOREVER }, // 871 + { "full", FULL }, // 872 + { "highlight", HIGHLIGHT }, // 873 + { "high-order-left", HIGH_ORDER_LEFT }, // 874 + { "high-order-right", HIGH_ORDER_RIGHT }, // 875 + { "ignoring", IGNORING }, // 876 + { "implements", IMPLEMENTS }, // 877 + { "initialized", INITIALIZED }, // 878 + { "intermediate", INTERMEDIATE }, // 879 + { "lc-all", LC_ALL_kw }, // 880 + { "lc-collate", LC_COLLATE_kw }, // 881 + { "lc-ctype", LC_CTYPE_kw }, // 882 + { "lc-messages", LC_MESSAGES_kw }, // 883 + { "lc-monetary", LC_MONETARY_kw }, // 884 + { "lc-numeric", LC_NUMERIC_kw }, // 885 + { "lc-time", LC_TIME_kw }, // 886 + { "lowlight", LOWLIGHT }, // 887 + { "nearest-away-from-zero", NEAREST_AWAY_FROM_ZERO }, // 888 + { "nearest-even", NEAREST_EVEN }, // 889 + { "nearest-toward-zero", NEAREST_TOWARD_ZERO }, // 890 + { "none", NONE }, // 891 + { "normal", NORMAL }, // 892 + { "numbers", NUMBERS }, // 893 + { "prefixed", PREFIXED }, // 894 + { "previous", PREVIOUS }, // 895 + { "prohibited", PROHIBITED }, // 896 + { "relation", RELATION }, // 897 + { "required", REQUIRED }, // 898 + { "reverse-video", REVERSE_VIDEO }, // 899 + { "rounding", ROUNDING }, // 900 + { "seconds", SECONDS }, // 901 + { "secure", SECURE }, // 902 + { "short", SHORT }, // 903 + { "signed", SIGNED_kw }, // 904 + { "standard-binary", STANDARD_BINARY }, // 905 + { "standard-decimal", STANDARD_DECIMAL }, // 906 + { "statement", STATEMENT }, // 907 + { "step", STEP }, // 908 + { "structure", STRUCTURE }, // 909 + { "toward-greater", TOWARD_GREATER }, // 910 + { "toward-lesser", TOWARD_LESSER }, // 911 + { "truncation", TRUNCATION }, // 912 + { "ucs-4", UCS_4 }, // 913 + { "underline", UNDERLINE }, // 914 + { "unsigned", UNSIGNED_kw }, // 915 + { "utf-16", UTF_16 }, // 916 + { "utf-8", UTF_8 }, // 917 + { "address", ADDRESS }, // 918 + { "end-accept", END_ACCEPT }, // 919 + { "end-add", END_ADD }, // 920 + { "end-call", END_CALL }, // 921 + { "end-compute", END_COMPUTE }, // 922 + { "end-delete", END_DELETE }, // 923 + { "end-display", END_DISPLAY }, // 924 + { "end-divide", END_DIVIDE }, // 925 + { "end-evaluate", END_EVALUATE }, // 926 + { "end-multiply", END_MULTIPLY }, // 927 + { "end-perform", END_PERFORM }, // 928 + { "end-read", END_READ }, // 929 + { "end-return", END_RETURN }, // 930 + { "end-rewrite", END_REWRITE }, // 931 + { "end-search", END_SEARCH }, // 932 + { "end-start", END_START }, // 933 + { "end-string", END_STRING }, // 934 + { "end-subtract", END_SUBTRACT }, // 935 + { "end-unstring", END_UNSTRING }, // 936 + { "end-write", END_WRITE }, // 937 + { "end-if", END_IF }, // 938 + { "thru", THRU }, // 939 + { "through", THRU }, // 939 + { "or", OR }, // 940 + { "and", AND }, // 941 + { "not", NOT }, // 942 + { "ne", NE }, // 943 + { "le", LE }, // 944 + { "ge", GE }, // 945 + { "pow", POW }, // 946 + { "neg", NEG }, // 947 }; // cppcheck-suppress useInitializationList @@ -830,557 +834,561 @@ token_names = { "CDF-EVALUATE", // 130 (388) "CDF-WHEN", // 131 (389) "CDF-END-EVALUATE", // 132 (390) - "CALL-COBOL", // 133 (391) - "CALL-VERBATIM", // 134 (392) - "IF", // 135 (393) - "THEN", // 136 (394) - "ELSE", // 137 (395) - "SENTENCE", // 138 (396) - "ACCEPT", // 139 (397) - "ADD", // 140 (398) - "ALTER", // 141 (399) - "CALL", // 142 (400) - "CANCEL", // 143 (401) - "CLOSE", // 144 (402) - "COMPUTE", // 145 (403) - "CONTINUE", // 146 (404) - "DELETE", // 147 (405) - "DISPLAY", // 148 (406) - "DIVIDE", // 149 (407) - "EVALUATE", // 150 (408) - "EXIT", // 151 (409) - "FILLER", // 152 (410) - "GOBACK", // 153 (411) - "GOTO", // 154 (412) - "INITIALIZE", // 155 (413) - "INSPECT", // 156 (414) - "MERGE", // 157 (415) - "MOVE", // 158 (416) - "MULTIPLY", // 159 (417) - "OPEN", // 160 (418) - "PARAGRAPH", // 161 (419) - "READ", // 162 (420) - "RELEASE", // 163 (421) - "RETURN", // 164 (422) - "REWRITE", // 165 (423) - "SEARCH", // 166 (424) - "SET", // 167 (425) - "SELECT", // 168 (426) - "SORT", // 169 (427) - "SORT-MERGE", // 170 (428) - "STRING", // 171 (429) - "STOP", // 172 (430) - "SUBTRACT", // 173 (431) - "START", // 174 (432) - "UNSTRING", // 175 (433) - "WRITE", // 176 (434) - "WHEN", // 177 (435) - "ARGUMENT-NUMBER", // 178 (436) - "ARGUMENT-VALUE", // 179 (437) - "ENVIRONMENT-NAME", // 180 (438) - "ENVIRONMENT-VALUE", // 181 (439) - "ABS", // 182 (440) - "ACCESS", // 183 (441) - "ACOS", // 184 (442) - "ACTUAL", // 185 (443) - "ADVANCING", // 186 (444) - "AFTER", // 187 (445) - "ALL", // 188 (446) - "ALLOCATE", // 189 (447) - "ALPHABET", // 190 (448) - "ALPHABETIC", // 191 (449) - "ALPHABETIC-LOWER", // 192 (450) - "ALPHABETIC-UPPER", // 193 (451) - "ALPHANUMERIC", // 194 (452) - "ALPHANUMERIC-EDITED", // 195 (453) - "ALSO", // 196 (454) - "ALTERNATE", // 197 (455) - "ANNUITY", // 198 (456) - "ANUM", // 199 (457) - "ANY", // 200 (458) - "ANYCASE", // 201 (459) - "APPLY", // 202 (460) - "ARE", // 203 (461) - "AREA", // 204 (462) - "AREAS", // 205 (463) - "AS", // 206 (464) - "ASCENDING", // 207 (465) - "ACTIVATING", // 208 (466) - "ASIN", // 209 (467) - "ASSIGN", // 210 (468) - "AT", // 211 (469) - "ATAN", // 212 (470) - "BASED", // 213 (471) - "BASECONVERT", // 214 (472) - "BEFORE", // 215 (473) - "BINARY", // 216 (474) - "BIT", // 217 (475) - "BIT-OF", // 218 (476) - "BIT-TO-CHAR", // 219 (477) - "BLANK", // 220 (478) - "BLOCK", // 221 (479) - "BOOLEAN-OF-INTEGER", // 222 (480) - "BOTTOM", // 223 (481) - "BY", // 224 (482) - "BYTE", // 225 (483) - "BYTE-LENGTH", // 226 (484) - "CF", // 227 (485) - "CH", // 228 (486) - "CHANGED", // 229 (487) - "CHAR", // 230 (488) - "CHAR-NATIONAL", // 231 (489) - "CHARACTER", // 232 (490) - "CHARACTERS", // 233 (491) - "CHECKING", // 234 (492) - "CLASS", // 235 (493) - "COBOL", // 236 (494) - "CODE", // 237 (495) - "CODE-SET", // 238 (496) - "COLLATING", // 239 (497) - "COLUMN", // 240 (498) - "COMBINED-DATETIME", // 241 (499) - "COMMA", // 242 (500) - "COMMAND-LINE", // 243 (501) - "COMMAND-LINE-COUNT", // 244 (502) - "COMMIT", // 245 (503) - "COMMON", // 246 (504) - "CONCAT", // 247 (505) - "CONDITION", // 248 (506) - "CONFIGURATION", // 249 (507) - "CONTAINS", // 250 (508) - "CONTENT", // 251 (509) - "CONTROL", // 252 (510) - "CONTROLS", // 253 (511) - "CONVERT", // 254 (512) - "CONVERTING", // 255 (513) - "CORRESPONDING", // 256 (514) - "COS", // 257 (515) - "COUNT", // 258 (516) - "CURRENCY", // 259 (517) - "CURRENT", // 260 (518) - "CURRENT-DATE", // 261 (519) - "DATA", // 262 (520) - "DATE", // 263 (521) - "DATE-COMPILED", // 264 (522) - "DATE-OF-INTEGER", // 265 (523) - "DATE-TO-YYYYMMDD", // 266 (524) - "DATE-WRITTEN", // 267 (525) - "DAY", // 268 (526) - "DAY-OF-INTEGER", // 269 (527) - "DAY-OF-WEEK", // 270 (528) - "DAY-TO-YYYYDDD", // 271 (529) - "DBCS", // 272 (530) - "DE", // 273 (531) - "DEBUGGING", // 274 (532) - "DECIMAL-POINT", // 275 (533) - "DECLARATIVES", // 276 (534) - "DEFAULT", // 277 (535) - "DELIMITED", // 278 (536) - "DELIMITER", // 279 (537) - "DEPENDING", // 280 (538) - "DESCENDING", // 281 (539) - "DETAIL", // 282 (540) - "DIRECT", // 283 (541) - "DIRECT-ACCESS", // 284 (542) - "DOWN", // 285 (543) - "DUPLICATES", // 286 (544) - "DYNAMIC", // 287 (545) - "E", // 288 (546) - "EBCDIC", // 289 (547) - "EC", // 290 (548) - "EGCS", // 291 (549) - "ENTRY", // 292 (550) - "ENVIRONMENT", // 293 (551) - "EQUAL", // 294 (552) - "EVERY", // 295 (553) - "EXAMINE", // 296 (554) - "EXHIBIT", // 297 (555) - "EXP", // 298 (556) - "EXP10", // 299 (557) - "EXTEND", // 300 (558) - "EXTERNAL", // 301 (559) - "EXCEPTION-FILE", // 302 (560) - "EXCEPTION-FILE-N", // 303 (561) - "EXCEPTION-LOCATION", // 304 (562) - "EXCEPTION-LOCATION-N", // 305 (563) - "EXCEPTION-STATEMENT", // 306 (564) - "EXCEPTION-STATUS", // 307 (565) - "FACTORIAL", // 308 (566) - "FALSE", // 309 (567) - "FD", // 310 (568) - "FILE-CONTROL", // 311 (569) - "FILE", // 312 (570) - "FILE-LIMIT", // 313 (571) - "FINAL", // 314 (572) - "FINALLY", // 315 (573) - "FIND-STRING", // 316 (574) - "FIRST", // 317 (575) - "FIXED", // 318 (576) - "FOOTING", // 319 (577) - "FOR", // 320 (578) - "FORMATTED-CURRENT-DATE", // 321 (579) - "FORMATTED-DATE", // 322 (580) - "FORMATTED-DATETIME", // 323 (581) - "FORMATTED-TIME", // 324 (582) - "FORM-OVERFLOW", // 325 (583) - "FREE", // 326 (584) - "FRACTION-PART", // 327 (585) - "FROM", // 328 (586) - "FUNCTION", // 329 (587) - "GENERATE", // 330 (588) - "GIVING", // 331 (589) - "GLOBAL", // 332 (590) - "GO", // 333 (591) - "GROUP", // 334 (592) - "HEADING", // 335 (593) - "HEX", // 336 (594) - "HEX-OF", // 337 (595) - "HEX-TO-CHAR", // 338 (596) - "HIGH-VALUES", // 339 (597) - "HIGHEST-ALGEBRAIC", // 340 (598) - "HOLD", // 341 (599) - "IBM-360", // 342 (600) - "IN", // 343 (601) - "INCLUDE", // 344 (602) - "INDEX", // 345 (603) - "INDEXED", // 346 (604) - "INDICATE", // 347 (605) - "INITIAL", // 348 (606) - "INITIATE", // 349 (607) - "INPUT", // 350 (608) - "INSTALLATION", // 351 (609) - "INTERFACE", // 352 (610) - "INTEGER", // 353 (611) - "INTEGER-OF-BOOLEAN", // 354 (612) - "INTEGER-OF-DATE", // 355 (613) - "INTEGER-OF-DAY", // 356 (614) - "INTEGER-OF-FORMATTED-DATE", // 357 (615) - "INTEGER-PART", // 358 (616) - "INTO", // 359 (617) - "INTRINSIC", // 360 (618) - "INVOKE", // 361 (619) - "I-O", // 362 (620) - "I-O-CONTROL", // 363 (621) - "IS", // 364 (622) - "ISNT", // 365 (623) - "KANJI", // 366 (624) - "KEY", // 367 (625) - "LABEL", // 368 (626) - "LAST", // 369 (627) - "LEADING", // 370 (628) - "LEFT", // 371 (629) - "LENGTH", // 372 (630) - "LENGTH-OF", // 373 (631) - "LIMIT", // 374 (632) - "LIMITS", // 375 (633) - "LINE", // 376 (634) - "LINES", // 377 (635) - "LINE-COUNTER", // 378 (636) - "LINAGE", // 379 (637) - "LINKAGE", // 380 (638) - "LOCALE", // 381 (639) - "LOCALE-COMPARE", // 382 (640) - "LOCALE-DATE", // 383 (641) - "LOCALE-TIME", // 384 (642) - "LOCALE-TIME-FROM-SECONDS", // 385 (643) - "LOCAL-STORAGE", // 386 (644) - "LOCATION", // 387 (645) - "LOCK", // 388 (646) - "LOCK-ON", // 389 (647) - "LOG", // 390 (648) - "LOG10", // 391 (649) - "LOWER-CASE", // 392 (650) - "LOW-VALUES", // 393 (651) - "LOWEST-ALGEBRAIC", // 394 (652) - "LPAREN", // 395 (653) - "MANUAL", // 396 (654) - "MAXX", // 397 (655) - "MEAN", // 398 (656) - "MEDIAN", // 399 (657) - "MIDRANGE", // 400 (658) - "MINN", // 401 (659) - "MULTIPLE", // 402 (660) - "MOD", // 403 (661) - "MODE", // 404 (662) - "MODULE-NAME", // 405 (663) - "NAMED", // 406 (664) - "NAT", // 407 (665) - "NATIONAL", // 408 (666) - "NATIONAL-EDITED", // 409 (667) - "NATIONAL-OF", // 410 (668) - "NATIVE", // 411 (669) - "NESTED", // 412 (670) - "NEXT", // 413 (671) - "NO", // 414 (672) - "NOTE", // 415 (673) - "NULLS", // 416 (674) - "NULLPTR", // 417 (675) - "NUMERIC", // 418 (676) - "NUMERIC-EDITED", // 419 (677) - "NUMVAL", // 420 (678) - "NUMVAL-C", // 421 (679) - "NUMVAL-F", // 422 (680) - "OCCURS", // 423 (681) - "OF", // 424 (682) - "OFF", // 425 (683) - "OMITTED", // 426 (684) - "ON", // 427 (685) - "ONLY", // 428 (686) - "OPTIONAL", // 429 (687) - "OPTIONS", // 430 (688) - "ORD", // 431 (689) - "ORDER", // 432 (690) - "ORD-MAX", // 433 (691) - "ORD-MIN", // 434 (692) - "ORGANIZATION", // 435 (693) - "OTHER", // 436 (694) - "OTHERWISE", // 437 (695) - "OUTPUT", // 438 (696) - "PACKED-DECIMAL", // 439 (697) - "PADDING", // 440 (698) - "PAGE", // 441 (699) - "PAGE-COUNTER", // 442 (700) - "PF", // 443 (701) - "PH", // 444 (702) - "PI", // 445 (703) - "PIC", // 446 (704) - "PICTURE", // 447 (705) - "PLUS", // 448 (706) - "PRESENT-VALUE", // 449 (707) - "PRINT-SWITCH", // 450 (708) - "PROCEDURE", // 451 (709) - "PROCEDURES", // 452 (710) - "PROCEED", // 453 (711) - "PROCESS", // 454 (712) - "PROGRAM-ID", // 455 (713) - "PROGRAM", // 456 (714) - "PROPERTY", // 457 (715) - "PROTOTYPE", // 458 (716) - "PSEUDOTEXT", // 459 (717) - "QUOTES", // 460 (718) - "RANDOM", // 461 (719) - "RANDOM-SEED", // 462 (720) - "RANGE", // 463 (721) - "RAISE", // 464 (722) - "RAISING", // 465 (723) - "RD", // 466 (724) - "RECORD", // 467 (725) - "RECORDING", // 468 (726) - "RECORDS", // 469 (727) - "RECURSIVE", // 470 (728) - "REDEFINES", // 471 (729) - "REEL", // 472 (730) - "REFERENCE", // 473 (731) - "RELATIVE", // 474 (732) - "REM", // 475 (733) - "REMAINDER", // 476 (734) - "REMARKS", // 477 (735) - "REMOVAL", // 478 (736) - "RENAMES", // 479 (737) - "REPLACE", // 480 (738) - "REPLACING", // 481 (739) - "REPORT", // 482 (740) - "REPORTING", // 483 (741) - "REPORTS", // 484 (742) - "REPOSITORY", // 485 (743) - "RERUN", // 486 (744) - "RESERVE", // 487 (745) - "RESTRICTED", // 488 (746) - "RESUME", // 489 (747) - "REVERSE", // 490 (748) - "REVERSED", // 491 (749) - "REWIND", // 492 (750) - "RF", // 493 (751) - "RH", // 494 (752) - "RIGHT", // 495 (753) - "ROUNDED", // 496 (754) - "RUN", // 497 (755) - "SAME", // 498 (756) - "SCREEN", // 499 (757) - "SD", // 500 (758) - "SECONDS-FROM-FORMATTED-TIME", // 501 (759) - "SECONDS-PAST-MIDNIGHT", // 502 (760) - "SECURITY", // 503 (761) - "SEPARATE", // 504 (762) - "SEQUENCE", // 505 (763) - "SEQUENTIAL", // 506 (764) - "SHARING", // 507 (765) - "SIMPLE-EXIT", // 508 (766) - "SIGN", // 509 (767) - "SIN", // 510 (768) - "SIZE", // 511 (769) - "SMALLEST-ALGEBRAIC", // 512 (770) - "SOURCE", // 513 (771) - "SOURCE-COMPUTER", // 514 (772) - "SPECIAL-NAMES", // 515 (773) - "SQRT", // 516 (774) - "STACK", // 517 (775) - "STANDARD", // 518 (776) - "STANDARD-1", // 519 (777) - "STANDARD-DEVIATION", // 520 (778) - "STANDARD-COMPARE", // 521 (779) - "STATUS", // 522 (780) - "STRONG", // 523 (781) - "SUBSTITUTE", // 524 (782) - "SUM", // 525 (783) - "SYMBOL", // 526 (784) - "SYMBOLIC", // 527 (785) - "SYNCHRONIZED", // 528 (786) - "TALLY", // 529 (787) - "TALLYING", // 530 (788) - "TAN", // 531 (789) - "TERMINATE", // 532 (790) - "TEST", // 533 (791) - "TEST-DATE-YYYYMMDD", // 534 (792) - "TEST-DAY-YYYYDDD", // 535 (793) - "TEST-FORMATTED-DATETIME", // 536 (794) - "TEST-NUMVAL", // 537 (795) - "TEST-NUMVAL-C", // 538 (796) - "TEST-NUMVAL-F", // 539 (797) - "THAN", // 540 (798) - "TIME", // 541 (799) - "TIMES", // 542 (800) - "TO", // 543 (801) - "TOP", // 544 (802) - "TOP-LEVEL", // 545 (803) - "TRACKS", // 546 (804) - "TRACK-AREA", // 547 (805) - "TRAILING", // 548 (806) - "TRANSFORM", // 549 (807) - "TRIM", // 550 (808) - "TRUE", // 551 (809) - "TRY", // 552 (810) - "TURN", // 553 (811) - "TYPE", // 554 (812) - "TYPEDEF", // 555 (813) - "ULENGTH", // 556 (814) - "UNBOUNDED", // 557 (815) - "UNIT", // 558 (816) - "UNITS", // 559 (817) - "UNIT-RECORD", // 560 (818) - "UNTIL", // 561 (819) - "UP", // 562 (820) - "UPON", // 563 (821) - "UPOS", // 564 (822) - "UPPER-CASE", // 565 (823) - "USAGE", // 566 (824) - "USING", // 567 (825) - "USUBSTR", // 568 (826) - "USUPPLEMENTARY", // 569 (827) - "UTILITY", // 570 (828) - "UUID4", // 571 (829) - "UVALID", // 572 (830) - "UWIDTH", // 573 (831) - "VALUE", // 574 (832) - "VARIANCE", // 575 (833) - "VARYING", // 576 (834) - "VOLATILE", // 577 (835) - "WHEN-COMPILED", // 578 (836) - "WITH", // 579 (837) - "WORKING-STORAGE", // 580 (838) - "XML", // 581 (839) - "XMLGENERATE", // 582 (840) - "XMLPARSE", // 583 (841) - "YEAR-TO-YYYY", // 584 (842) - "YYYYDDD", // 585 (843) - "YYYYMMDD", // 586 (844) - "ARITHMETIC", // 587 (845) - "ATTRIBUTE", // 588 (846) - "AUTO", // 589 (847) - "AUTOMATIC", // 590 (848) - "AWAY-FROM-ZERO", // 591 (849) - "BACKGROUND-COLOR", // 592 (850) - "BELL", // 593 (851) - "BINARY-ENCODING", // 594 (852) - "BLINK", // 595 (853) - "CAPACITY", // 596 (854) - "CENTER", // 597 (855) - "CLASSIFICATION", // 598 (856) - "CYCLE", // 599 (857) - "DECIMAL-ENCODING", // 600 (858) - "ENTRY-CONVENTION", // 601 (859) - "EOL", // 602 (860) - "EOS", // 603 (861) - "ERASE", // 604 (862) - "EXPANDS", // 605 (863) - "FLOAT-BINARY", // 606 (864) - "FLOAT-DECIMAL", // 607 (865) - "FOREGROUND-COLOR", // 608 (866) - "FOREVER", // 609 (867) - "FULL", // 610 (868) - "HIGHLIGHT", // 611 (869) - "HIGH-ORDER-LEFT", // 612 (870) - "HIGH-ORDER-RIGHT", // 613 (871) - "IGNORING", // 614 (872) - "IMPLEMENTS", // 615 (873) - "INITIALIZED", // 616 (874) - "INTERMEDIATE", // 617 (875) - "LC-ALL", // 618 (876) - "LC-COLLATE", // 619 (877) - "LC-CTYPE", // 620 (878) - "LC-MESSAGES", // 621 (879) - "LC-MONETARY", // 622 (880) - "LC-NUMERIC", // 623 (881) - "LC-TIME", // 624 (882) - "LOWLIGHT", // 625 (883) - "NEAREST-AWAY-FROM-ZERO", // 626 (884) - "NEAREST-EVEN", // 627 (885) - "NEAREST-TOWARD-ZERO", // 628 (886) - "NONE", // 629 (887) - "NORMAL", // 630 (888) - "NUMBERS", // 631 (889) - "PREFIXED", // 632 (890) - "PREVIOUS", // 633 (891) - "PROHIBITED", // 634 (892) - "RELATION", // 635 (893) - "REQUIRED", // 636 (894) - "REVERSE-VIDEO", // 637 (895) - "ROUNDING", // 638 (896) - "SECONDS", // 639 (897) - "SECURE", // 640 (898) - "SHORT", // 641 (899) - "SIGNED", // 642 (900) - "STANDARD-BINARY", // 643 (901) - "STANDARD-DECIMAL", // 644 (902) - "STATEMENT", // 645 (903) - "STEP", // 646 (904) - "STRUCTURE", // 647 (905) - "TOWARD-GREATER", // 648 (906) - "TOWARD-LESSER", // 649 (907) - "TRUNCATION", // 650 (908) - "UCS-4", // 651 (909) - "UNDERLINE", // 652 (910) - "UNSIGNED", // 653 (911) - "UTF-16", // 654 (912) - "UTF-8", // 655 (913) - "ADDRESS", // 656 (914) - "END-ACCEPT", // 657 (915) - "END-ADD", // 658 (916) - "END-CALL", // 659 (917) - "END-COMPUTE", // 660 (918) - "END-DELETE", // 661 (919) - "END-DISPLAY", // 662 (920) - "END-DIVIDE", // 663 (921) - "END-EVALUATE", // 664 (922) - "END-MULTIPLY", // 665 (923) - "END-PERFORM", // 666 (924) - "END-READ", // 667 (925) - "END-RETURN", // 668 (926) - "END-REWRITE", // 669 (927) - "END-SEARCH", // 670 (928) - "END-START", // 671 (929) - "END-STRING", // 672 (930) - "END-SUBTRACT", // 673 (931) - "END-UNSTRING", // 674 (932) - "END-WRITE", // 675 (933) - "END-IF", // 676 (934) - "THRU", // 677 (935) - "OR", // 678 (936) - "AND", // 679 (937) - "NOT", // 680 (938) - "NE", // 681 (939) - "LE", // 682 (940) - "GE", // 683 (941) - "POW", // 684 (942) - "NEG", // 685 (943) + "CALL-CONVENTION", // 133 (391) + "CALL-COBOL", // 134 (392) + "CALL-VERBATIM", // 135 (393) + "CDF-PUSH", // 136 (394) + "CDF-POP", // 137 (395) + "SOURCE-FORMAT", // 138 (396) + "IF", // 139 (397) + "THEN", // 140 (398) + "ELSE", // 141 (399) + "SENTENCE", // 142 (400) + "ACCEPT", // 143 (401) + "ADD", // 144 (402) + "ALTER", // 145 (403) + "CALL", // 146 (404) + "CANCEL", // 147 (405) + "CLOSE", // 148 (406) + "COMPUTE", // 149 (407) + "CONTINUE", // 150 (408) + "DELETE", // 151 (409) + "DISPLAY", // 152 (410) + "DIVIDE", // 153 (411) + "EVALUATE", // 154 (412) + "EXIT", // 155 (413) + "FILLER", // 156 (414) + "GOBACK", // 157 (415) + "GOTO", // 158 (416) + "INITIALIZE", // 159 (417) + "INSPECT", // 160 (418) + "MERGE", // 161 (419) + "MOVE", // 162 (420) + "MULTIPLY", // 163 (421) + "OPEN", // 164 (422) + "PARAGRAPH", // 165 (423) + "READ", // 166 (424) + "RELEASE", // 167 (425) + "RETURN", // 168 (426) + "REWRITE", // 169 (427) + "SEARCH", // 170 (428) + "SET", // 171 (429) + "SELECT", // 172 (430) + "SORT", // 173 (431) + "SORT-MERGE", // 174 (432) + "STRING", // 175 (433) + "STOP", // 176 (434) + "SUBTRACT", // 177 (435) + "START", // 178 (436) + "UNSTRING", // 179 (437) + "WRITE", // 180 (438) + "WHEN", // 181 (439) + "ARGUMENT-NUMBER", // 182 (440) + "ARGUMENT-VALUE", // 183 (441) + "ENVIRONMENT-NAME", // 184 (442) + "ENVIRONMENT-VALUE", // 185 (443) + "ABS", // 186 (444) + "ACCESS", // 187 (445) + "ACOS", // 188 (446) + "ACTUAL", // 189 (447) + "ADVANCING", // 190 (448) + "AFTER", // 191 (449) + "ALL", // 192 (450) + "ALLOCATE", // 193 (451) + "ALPHABET", // 194 (452) + "ALPHABETIC", // 195 (453) + "ALPHABETIC-LOWER", // 196 (454) + "ALPHABETIC-UPPER", // 197 (455) + "ALPHANUMERIC", // 198 (456) + "ALPHANUMERIC-EDITED", // 199 (457) + "ALSO", // 200 (458) + "ALTERNATE", // 201 (459) + "ANNUITY", // 202 (460) + "ANUM", // 203 (461) + "ANY", // 204 (462) + "ANYCASE", // 205 (463) + "APPLY", // 206 (464) + "ARE", // 207 (465) + "AREA", // 208 (466) + "AREAS", // 209 (467) + "AS", // 210 (468) + "ASCENDING", // 211 (469) + "ACTIVATING", // 212 (470) + "ASIN", // 213 (471) + "ASSIGN", // 214 (472) + "AT", // 215 (473) + "ATAN", // 216 (474) + "BASED", // 217 (475) + "BASECONVERT", // 218 (476) + "BEFORE", // 219 (477) + "BINARY", // 220 (478) + "BIT", // 221 (479) + "BIT-OF", // 222 (480) + "BIT-TO-CHAR", // 223 (481) + "BLANK", // 224 (482) + "BLOCK", // 225 (483) + "BOOLEAN-OF-INTEGER", // 226 (484) + "BOTTOM", // 227 (485) + "BY", // 228 (486) + "BYTE", // 229 (487) + "BYTE-LENGTH", // 230 (488) + "CF", // 231 (489) + "CH", // 232 (490) + "CHANGED", // 233 (491) + "CHAR", // 234 (492) + "CHAR-NATIONAL", // 235 (493) + "CHARACTER", // 236 (494) + "CHARACTERS", // 237 (495) + "CHECKING", // 238 (496) + "CLASS", // 239 (497) + "COBOL", // 240 (498) + "CODE", // 241 (499) + "CODE-SET", // 242 (500) + "COLLATING", // 243 (501) + "COLUMN", // 244 (502) + "COMBINED-DATETIME", // 245 (503) + "COMMA", // 246 (504) + "COMMAND-LINE", // 247 (505) + "COMMAND-LINE-COUNT", // 248 (506) + "COMMIT", // 249 (507) + "COMMON", // 250 (508) + "CONCAT", // 251 (509) + "CONDITION", // 252 (510) + "CONFIGURATION", // 253 (511) + "CONTAINS", // 254 (512) + "CONTENT", // 255 (513) + "CONTROL", // 256 (514) + "CONTROLS", // 257 (515) + "CONVERT", // 258 (516) + "CONVERTING", // 259 (517) + "CORRESPONDING", // 260 (518) + "COS", // 261 (519) + "COUNT", // 262 (520) + "CURRENCY", // 263 (521) + "CURRENT", // 264 (522) + "CURRENT-DATE", // 265 (523) + "DATA", // 266 (524) + "DATE", // 267 (525) + "DATE-COMPILED", // 268 (526) + "DATE-OF-INTEGER", // 269 (527) + "DATE-TO-YYYYMMDD", // 270 (528) + "DATE-WRITTEN", // 271 (529) + "DAY", // 272 (530) + "DAY-OF-INTEGER", // 273 (531) + "DAY-OF-WEEK", // 274 (532) + "DAY-TO-YYYYDDD", // 275 (533) + "DBCS", // 276 (534) + "DE", // 277 (535) + "DEBUGGING", // 278 (536) + "DECIMAL-POINT", // 279 (537) + "DECLARATIVES", // 280 (538) + "DEFAULT", // 281 (539) + "DELIMITED", // 282 (540) + "DELIMITER", // 283 (541) + "DEPENDING", // 284 (542) + "DESCENDING", // 285 (543) + "DETAIL", // 286 (544) + "DIRECT", // 287 (545) + "DIRECT-ACCESS", // 288 (546) + "DOWN", // 289 (547) + "DUPLICATES", // 290 (548) + "DYNAMIC", // 291 (549) + "E", // 292 (550) + "EBCDIC", // 293 (551) + "EC", // 294 (552) + "EGCS", // 295 (553) + "ENTRY", // 296 (554) + "ENVIRONMENT", // 297 (555) + "EQUAL", // 298 (556) + "EVERY", // 299 (557) + "EXAMINE", // 300 (558) + "EXHIBIT", // 301 (559) + "EXP", // 302 (560) + "EXP10", // 303 (561) + "EXTEND", // 304 (562) + "EXTERNAL", // 305 (563) + "EXCEPTION-FILE", // 306 (564) + "EXCEPTION-FILE-N", // 307 (565) + "EXCEPTION-LOCATION", // 308 (566) + "EXCEPTION-LOCATION-N", // 309 (567) + "EXCEPTION-STATEMENT", // 310 (568) + "EXCEPTION-STATUS", // 311 (569) + "FACTORIAL", // 312 (570) + "FALSE", // 313 (571) + "FD", // 314 (572) + "FILE-CONTROL", // 315 (573) + "FILE", // 316 (574) + "FILE-LIMIT", // 317 (575) + "FINAL", // 318 (576) + "FINALLY", // 319 (577) + "FIND-STRING", // 320 (578) + "FIRST", // 321 (579) + "FIXED", // 322 (580) + "FOOTING", // 323 (581) + "FOR", // 324 (582) + "FORMATTED-CURRENT-DATE", // 325 (583) + "FORMATTED-DATE", // 326 (584) + "FORMATTED-DATETIME", // 327 (585) + "FORMATTED-TIME", // 328 (586) + "FORM-OVERFLOW", // 329 (587) + "FREE", // 330 (588) + "FRACTION-PART", // 331 (589) + "FROM", // 332 (590) + "FUNCTION", // 333 (591) + "GENERATE", // 334 (592) + "GIVING", // 335 (593) + "GLOBAL", // 336 (594) + "GO", // 337 (595) + "GROUP", // 338 (596) + "HEADING", // 339 (597) + "HEX", // 340 (598) + "HEX-OF", // 341 (599) + "HEX-TO-CHAR", // 342 (600) + "HIGH-VALUES", // 343 (601) + "HIGHEST-ALGEBRAIC", // 344 (602) + "HOLD", // 345 (603) + "IBM-360", // 346 (604) + "IN", // 347 (605) + "INCLUDE", // 348 (606) + "INDEX", // 349 (607) + "INDEXED", // 350 (608) + "INDICATE", // 351 (609) + "INITIAL", // 352 (610) + "INITIATE", // 353 (611) + "INPUT", // 354 (612) + "INSTALLATION", // 355 (613) + "INTERFACE", // 356 (614) + "INTEGER", // 357 (615) + "INTEGER-OF-BOOLEAN", // 358 (616) + "INTEGER-OF-DATE", // 359 (617) + "INTEGER-OF-DAY", // 360 (618) + "INTEGER-OF-FORMATTED-DATE", // 361 (619) + "INTEGER-PART", // 362 (620) + "INTO", // 363 (621) + "INTRINSIC", // 364 (622) + "INVOKE", // 365 (623) + "I-O", // 366 (624) + "I-O-CONTROL", // 367 (625) + "IS", // 368 (626) + "ISNT", // 369 (627) + "KANJI", // 370 (628) + "KEY", // 371 (629) + "LABEL", // 372 (630) + "LAST", // 373 (631) + "LEADING", // 374 (632) + "LEFT", // 375 (633) + "LENGTH", // 376 (634) + "LENGTH-OF", // 377 (635) + "LIMIT", // 378 (636) + "LIMITS", // 379 (637) + "LINE", // 380 (638) + "LINES", // 381 (639) + "LINE-COUNTER", // 382 (640) + "LINAGE", // 383 (641) + "LINKAGE", // 384 (642) + "LOCALE", // 385 (643) + "LOCALE-COMPARE", // 386 (644) + "LOCALE-DATE", // 387 (645) + "LOCALE-TIME", // 388 (646) + "LOCALE-TIME-FROM-SECONDS", // 389 (647) + "LOCAL-STORAGE", // 390 (648) + "LOCATION", // 391 (649) + "LOCK", // 392 (650) + "LOCK-ON", // 393 (651) + "LOG", // 394 (652) + "LOG10", // 395 (653) + "LOWER-CASE", // 396 (654) + "LOW-VALUES", // 397 (655) + "LOWEST-ALGEBRAIC", // 398 (656) + "LPAREN", // 399 (657) + "MANUAL", // 400 (658) + "MAXX", // 401 (659) + "MEAN", // 402 (660) + "MEDIAN", // 403 (661) + "MIDRANGE", // 404 (662) + "MINN", // 405 (663) + "MULTIPLE", // 406 (664) + "MOD", // 407 (665) + "MODE", // 408 (666) + "MODULE-NAME", // 409 (667) + "NAMED", // 410 (668) + "NAT", // 411 (669) + "NATIONAL", // 412 (670) + "NATIONAL-EDITED", // 413 (671) + "NATIONAL-OF", // 414 (672) + "NATIVE", // 415 (673) + "NESTED", // 416 (674) + "NEXT", // 417 (675) + "NO", // 418 (676) + "NOTE", // 419 (677) + "NULLS", // 420 (678) + "NULLPTR", // 421 (679) + "NUMERIC", // 422 (680) + "NUMERIC-EDITED", // 423 (681) + "NUMVAL", // 424 (682) + "NUMVAL-C", // 425 (683) + "NUMVAL-F", // 426 (684) + "OCCURS", // 427 (685) + "OF", // 428 (686) + "OFF", // 429 (687) + "OMITTED", // 430 (688) + "ON", // 431 (689) + "ONLY", // 432 (690) + "OPTIONAL", // 433 (691) + "OPTIONS", // 434 (692) + "ORD", // 435 (693) + "ORDER", // 436 (694) + "ORD-MAX", // 437 (695) + "ORD-MIN", // 438 (696) + "ORGANIZATION", // 439 (697) + "OTHER", // 440 (698) + "OTHERWISE", // 441 (699) + "OUTPUT", // 442 (700) + "PACKED-DECIMAL", // 443 (701) + "PADDING", // 444 (702) + "PAGE", // 445 (703) + "PAGE-COUNTER", // 446 (704) + "PF", // 447 (705) + "PH", // 448 (706) + "PI", // 449 (707) + "PIC", // 450 (708) + "PICTURE", // 451 (709) + "PLUS", // 452 (710) + "PRESENT-VALUE", // 453 (711) + "PRINT-SWITCH", // 454 (712) + "PROCEDURE", // 455 (713) + "PROCEDURES", // 456 (714) + "PROCEED", // 457 (715) + "PROCESS", // 458 (716) + "PROGRAM-ID", // 459 (717) + "PROGRAM", // 460 (718) + "PROPERTY", // 461 (719) + "PROTOTYPE", // 462 (720) + "PSEUDOTEXT", // 463 (721) + "QUOTES", // 464 (722) + "RANDOM", // 465 (723) + "RANDOM-SEED", // 466 (724) + "RANGE", // 467 (725) + "RAISE", // 468 (726) + "RAISING", // 469 (727) + "RD", // 470 (728) + "RECORD", // 471 (729) + "RECORDING", // 472 (730) + "RECORDS", // 473 (731) + "RECURSIVE", // 474 (732) + "REDEFINES", // 475 (733) + "REEL", // 476 (734) + "REFERENCE", // 477 (735) + "RELATIVE", // 478 (736) + "REM", // 479 (737) + "REMAINDER", // 480 (738) + "REMARKS", // 481 (739) + "REMOVAL", // 482 (740) + "RENAMES", // 483 (741) + "REPLACE", // 484 (742) + "REPLACING", // 485 (743) + "REPORT", // 486 (744) + "REPORTING", // 487 (745) + "REPORTS", // 488 (746) + "REPOSITORY", // 489 (747) + "RERUN", // 490 (748) + "RESERVE", // 491 (749) + "RESTRICTED", // 492 (750) + "RESUME", // 493 (751) + "REVERSE", // 494 (752) + "REVERSED", // 495 (753) + "REWIND", // 496 (754) + "RF", // 497 (755) + "RH", // 498 (756) + "RIGHT", // 499 (757) + "ROUNDED", // 500 (758) + "RUN", // 501 (759) + "SAME", // 502 (760) + "SCREEN", // 503 (761) + "SD", // 504 (762) + "SECONDS-FROM-FORMATTED-TIME", // 505 (763) + "SECONDS-PAST-MIDNIGHT", // 506 (764) + "SECURITY", // 507 (765) + "SEPARATE", // 508 (766) + "SEQUENCE", // 509 (767) + "SEQUENTIAL", // 510 (768) + "SHARING", // 511 (769) + "SIMPLE-EXIT", // 512 (770) + "SIGN", // 513 (771) + "SIN", // 514 (772) + "SIZE", // 515 (773) + "SMALLEST-ALGEBRAIC", // 516 (774) + "SOURCE", // 517 (775) + "SOURCE-COMPUTER", // 518 (776) + "SPECIAL-NAMES", // 519 (777) + "SQRT", // 520 (778) + "STACK", // 521 (779) + "STANDARD", // 522 (780) + "STANDARD-1", // 523 (781) + "STANDARD-DEVIATION", // 524 (782) + "STANDARD-COMPARE", // 525 (783) + "STATUS", // 526 (784) + "STRONG", // 527 (785) + "SUBSTITUTE", // 528 (786) + "SUM", // 529 (787) + "SYMBOL", // 530 (788) + "SYMBOLIC", // 531 (789) + "SYNCHRONIZED", // 532 (790) + "TALLY", // 533 (791) + "TALLYING", // 534 (792) + "TAN", // 535 (793) + "TERMINATE", // 536 (794) + "TEST", // 537 (795) + "TEST-DATE-YYYYMMDD", // 538 (796) + "TEST-DAY-YYYYDDD", // 539 (797) + "TEST-FORMATTED-DATETIME", // 540 (798) + "TEST-NUMVAL", // 541 (799) + "TEST-NUMVAL-C", // 542 (800) + "TEST-NUMVAL-F", // 543 (801) + "THAN", // 544 (802) + "TIME", // 545 (803) + "TIMES", // 546 (804) + "TO", // 547 (805) + "TOP", // 548 (806) + "TOP-LEVEL", // 549 (807) + "TRACKS", // 550 (808) + "TRACK-AREA", // 551 (809) + "TRAILING", // 552 (810) + "TRANSFORM", // 553 (811) + "TRIM", // 554 (812) + "TRUE", // 555 (813) + "TRY", // 556 (814) + "TURN", // 557 (815) + "TYPE", // 558 (816) + "TYPEDEF", // 559 (817) + "ULENGTH", // 560 (818) + "UNBOUNDED", // 561 (819) + "UNIT", // 562 (820) + "UNITS", // 563 (821) + "UNIT-RECORD", // 564 (822) + "UNTIL", // 565 (823) + "UP", // 566 (824) + "UPON", // 567 (825) + "UPOS", // 568 (826) + "UPPER-CASE", // 569 (827) + "USAGE", // 570 (828) + "USING", // 571 (829) + "USUBSTR", // 572 (830) + "USUPPLEMENTARY", // 573 (831) + "UTILITY", // 574 (832) + "UUID4", // 575 (833) + "UVALID", // 576 (834) + "UWIDTH", // 577 (835) + "VALUE", // 578 (836) + "VARIANCE", // 579 (837) + "VARYING", // 580 (838) + "VOLATILE", // 581 (839) + "WHEN-COMPILED", // 582 (840) + "WITH", // 583 (841) + "WORKING-STORAGE", // 584 (842) + "XML", // 585 (843) + "XMLGENERATE", // 586 (844) + "XMLPARSE", // 587 (845) + "YEAR-TO-YYYY", // 588 (846) + "YYYYDDD", // 589 (847) + "YYYYMMDD", // 590 (848) + "ARITHMETIC", // 591 (849) + "ATTRIBUTE", // 592 (850) + "AUTO", // 593 (851) + "AUTOMATIC", // 594 (852) + "AWAY-FROM-ZERO", // 595 (853) + "BACKGROUND-COLOR", // 596 (854) + "BELL", // 597 (855) + "BINARY-ENCODING", // 598 (856) + "BLINK", // 599 (857) + "CAPACITY", // 600 (858) + "CENTER", // 601 (859) + "CLASSIFICATION", // 602 (860) + "CYCLE", // 603 (861) + "DECIMAL-ENCODING", // 604 (862) + "ENTRY-CONVENTION", // 605 (863) + "EOL", // 606 (864) + "EOS", // 607 (865) + "ERASE", // 608 (866) + "EXPANDS", // 609 (867) + "FLOAT-BINARY", // 610 (868) + "FLOAT-DECIMAL", // 611 (869) + "FOREGROUND-COLOR", // 612 (870) + "FOREVER", // 613 (871) + "FULL", // 614 (872) + "HIGHLIGHT", // 615 (873) + "HIGH-ORDER-LEFT", // 616 (874) + "HIGH-ORDER-RIGHT", // 617 (875) + "IGNORING", // 618 (876) + "IMPLEMENTS", // 619 (877) + "INITIALIZED", // 620 (878) + "INTERMEDIATE", // 621 (879) + "LC-ALL", // 622 (880) + "LC-COLLATE", // 623 (881) + "LC-CTYPE", // 624 (882) + "LC-MESSAGES", // 625 (883) + "LC-MONETARY", // 626 (884) + "LC-NUMERIC", // 627 (885) + "LC-TIME", // 628 (886) + "LOWLIGHT", // 629 (887) + "NEAREST-AWAY-FROM-ZERO", // 630 (888) + "NEAREST-EVEN", // 631 (889) + "NEAREST-TOWARD-ZERO", // 632 (890) + "NONE", // 633 (891) + "NORMAL", // 634 (892) + "NUMBERS", // 635 (893) + "PREFIXED", // 636 (894) + "PREVIOUS", // 637 (895) + "PROHIBITED", // 638 (896) + "RELATION", // 639 (897) + "REQUIRED", // 640 (898) + "REVERSE-VIDEO", // 641 (899) + "ROUNDING", // 642 (900) + "SECONDS", // 643 (901) + "SECURE", // 644 (902) + "SHORT", // 645 (903) + "SIGNED", // 646 (904) + "STANDARD-BINARY", // 647 (905) + "STANDARD-DECIMAL", // 648 (906) + "STATEMENT", // 649 (907) + "STEP", // 650 (908) + "STRUCTURE", // 651 (909) + "TOWARD-GREATER", // 652 (910) + "TOWARD-LESSER", // 653 (911) + "TRUNCATION", // 654 (912) + "UCS-4", // 655 (913) + "UNDERLINE", // 656 (914) + "UNSIGNED", // 657 (915) + "UTF-16", // 658 (916) + "UTF-8", // 659 (917) + "ADDRESS", // 660 (918) + "END-ACCEPT", // 661 (919) + "END-ADD", // 662 (920) + "END-CALL", // 663 (921) + "END-COMPUTE", // 664 (922) + "END-DELETE", // 665 (923) + "END-DISPLAY", // 666 (924) + "END-DIVIDE", // 667 (925) + "END-EVALUATE", // 668 (926) + "END-MULTIPLY", // 669 (927) + "END-PERFORM", // 670 (928) + "END-READ", // 671 (929) + "END-RETURN", // 672 (930) + "END-REWRITE", // 673 (931) + "END-SEARCH", // 674 (932) + "END-START", // 675 (933) + "END-STRING", // 676 (934) + "END-SUBTRACT", // 677 (935) + "END-UNSTRING", // 678 (936) + "END-WRITE", // 679 (937) + "END-IF", // 680 (938) + "THRU", // 681 (939) + "OR", // 682 (940) + "AND", // 683 (941) + "NOT", // 684 (942) + "NE", // 685 (943) + "LE", // 686 (944) + "GE", // 687 (945) + "POW", // 688 (946) + "NEG", // 689 (947) }; diff --git a/gcc/cobol/udf/stored-char-length.cbl b/gcc/cobol/udf/stored-char-length.cbl index 9ab3b14..66889d0 100644 --- a/gcc/cobol/udf/stored-char-length.cbl +++ b/gcc/cobol/udf/stored-char-length.cbl @@ -1,3 +1,6 @@ + >> PUSH source format + >>SOURCE format is fixed + * This function is in public domain. * Contributed by James K. Lowden of Cobolworx in August 2024 @@ -13,3 +16,4 @@ to Output-Value. End Function STORED-CHAR-LENGTH. + >> pop source format
\ No newline at end of file diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc index 0076fc4..854bd7f 100644 --- a/gcc/cobol/util.cc +++ b/gcc/cobol/util.cc @@ -121,35 +121,76 @@ gb4( size_t input ) { * command-line option. A push to a stack pushes the default value onto it; a * pop copies the top of the stack to the default value. * + * Supported: + * CALL-CONVENTION + * COBOL-WORDS + * DEFINE + * DISPLAY + * IF + * POP + * PUSH + * SOURCE FORMAT + * TURN + * not supported + * EVALUATE + * FLAG-02 + * FLAG-14 + * LEAP-SECOND + * LISTING + * PAGE + * PROPAGATE + * REF-MOD-ZERO-LENGTH + * * >>PUSH ALL calls the class's push() method. * >>POP ALL calls the class's pop() method. */ class cdf_directives_t { - typedef std::map<std::string, cdfval_t> cdf_values_t; - template <typename T> class cdf_stack_t : private std::stack<T> { T default_value; + const T& top() const { return std::stack<T>::top(); } + bool empty() const { return std::stack<T>::empty(); } public: void value( const T& value ) { - T& output( std::stack<T>::empty()? default_value : std::stack<T>::top() ); + T& output( empty()? default_value : std::stack<T>::top() ); output = value; + dbgmsg("cdf_directives_t::%s: %s", __func__, str(output).c_str()); } T& value() { - return std::stack<T>::empty()? default_value : std::stack<T>::top(); + return empty()? default_value : std::stack<T>::top(); } void push() { std::stack<T>::push(value()); + dbgmsg("cdf_directives_t::%s: %s", __func__, str(top()).c_str()); } void pop() { - if( std::stack<T>::empty() ) { + if( empty() ) { error_msg(YYLTYPE(), "CDF stack empty"); return; } - default_value = std::stack<T>::top(); + default_value = top(); std::stack<T>::pop(); + dbgmsg("cdf_directives_t::%s: %s", __func__, str(default_value).c_str()); + } + protected: + static std::string str(cbl_call_convention_t arg) { + char output[2] = { static_cast<char>(arg) }; + return std::string("call-convention ") + output; + } + static std::string str(current_tokens_t) { + return "<cobol-words>"; + } + static std::string str(cdf_values_t) { + return "<dictionary>"; + } + static std::string str(source_format_t arg) { + return arg.description(); } + static std::string str(cbl_enabled_exceptions_t) { + return "<enabled_exceptions>"; + } + }; public: @@ -181,6 +222,25 @@ class cdf_directives_t static cdf_directives_t cdf_directives; void +current_call_convention( cbl_call_convention_t convention) { + cdf_directives.call_convention.value(convention); +} +cbl_call_convention_t +current_call_convention() { + return cdf_directives.call_convention.value(); +} + +current_tokens_t& +cdf_current_tokens() { + return cdf_directives.cobol_words.value(); +} + +cdf_values_t& +cdf_dictionary() { + return cdf_directives.dictionary.value(); +} + +void cobol_set_indicator_column( int column ) { cdf_directives.source_format.value().indicator_column_set(column); } @@ -188,6 +248,24 @@ source_format_t& cdf_source_format() { return cdf_directives.source_format.value(); } +cbl_enabled_exceptions_t& +cdf_enabled_exceptions() { + return cdf_directives.enabled_exceptions.value(); +} + +void cdf_push() { cdf_directives.push(); } +void cdf_push_call_convention() { cdf_directives.call_convention.push(); } +void cdf_push_current_tokens() { cdf_directives.cobol_words.push(); } +void cdf_push_dictionary() { cdf_directives.dictionary.push(); } +void cdf_push_enabled_exceptions() { cdf_directives.enabled_exceptions.push(); } +void cdf_push_source_format() { cdf_directives.source_format.push(); } + +void cdf_pop() { cdf_directives.pop(); } +void cdf_pop_call_convention() { cdf_directives.call_convention.pop(); } +void cdf_pop_current_tokens() { cdf_directives.cobol_words.pop(); } +void cdf_pop_dictionary() { cdf_directives.dictionary.pop(); } +void cdf_pop_enabled_exceptions() { cdf_directives.enabled_exceptions.pop(); } +void cdf_pop_source_format() { cdf_directives.source_format.pop(); } const char * symbol_type_str( enum symbol_type_t type ) @@ -980,8 +1058,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%zu)", - 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/cobol/util.h b/gcc/cobol/util.h index 2881809..d07b669 100644 --- a/gcc/cobol/util.h +++ b/gcc/cobol/util.h @@ -110,4 +110,19 @@ public: } }; + +void cdf_push(); +void cdf_push_call_convention(); +void cdf_push_current_tokens(); +void cdf_push_dictionary(); +void cdf_push_enabled_exceptions(); +void cdf_push_source_format(); + +void cdf_pop(); +void cdf_pop_call_convention(); +void cdf_pop_current_tokens(); +void cdf_pop_dictionary(); +void cdf_pop_source_format(); +void cdf_pop_enabled_exceptions(); + #endif diff --git a/gcc/config/aarch64/aarch64-simd.md b/gcc/config/aarch64/aarch64-simd.md index 8de79ca..75192dd 100644 --- a/gcc/config/aarch64/aarch64-simd.md +++ b/gcc/config/aarch64/aarch64-simd.md @@ -9180,17 +9180,42 @@ ;; sha3 (define_insn "eor3q<mode>4" - [(set (match_operand:VQ_I 0 "register_operand" "=w") - (xor:VQ_I - (xor:VQ_I - (match_operand:VQ_I 2 "register_operand" "w") - (match_operand:VQ_I 3 "register_operand" "w")) - (match_operand:VQ_I 1 "register_operand" "w")))] + [(set (match_operand:VDQ_I 0 "register_operand" "=w") + (xor:VDQ_I + (xor:VDQ_I + (match_operand:VDQ_I 2 "register_operand" "w") + (match_operand:VDQ_I 3 "register_operand" "w")) + (match_operand:VDQ_I 1 "register_operand" "w")))] "TARGET_SHA3" "eor3\\t%0.16b, %1.16b, %2.16b, %3.16b" [(set_attr "type" "crypto_sha3")] ) +(define_insn_and_split "*eor3qdi4" + [(set (match_operand:DI 0 "register_operand") + (xor:DI + (xor:DI + (match_operand:DI 2 "register_operand") + (match_operand:DI 3 "register_operand")) + (match_operand:DI 1 "register_operand")))] + "TARGET_SHA3" + {@ [ cons: =0, 1, 2 , 3 ; attrs: type ] + [ w , w, w , w ; crypto_sha3 ] eor3\t%0.16b, %1.16b, %2.16b, %3.16b + [ &r , r, r0, r0 ; multiple ] # + } + "&& REG_P (operands[0]) && GP_REGNUM_P (REGNO (operands[0]))" + [(set (match_dup 4) (xor:DI (match_dup 2) (match_dup 3))) + (set (match_dup 0) (xor:DI (match_dup 4) (match_dup 1)))] + { + if (reload_completed) + operands[4] = operands[0]; + else if (can_create_pseudo_p ()) + operands[4] = gen_reg_rtx (DImode); + else + FAIL; + } +) + (define_insn "aarch64_rax1qv2di" [(set (match_operand:V2DI 0 "register_operand" "=w") (xor:V2DI @@ -9241,17 +9266,46 @@ ) (define_insn "bcaxq<mode>4" - [(set (match_operand:VQ_I 0 "register_operand" "=w") - (xor:VQ_I - (and:VQ_I - (not:VQ_I (match_operand:VQ_I 3 "register_operand" "w")) - (match_operand:VQ_I 2 "register_operand" "w")) - (match_operand:VQ_I 1 "register_operand" "w")))] + [(set (match_operand:VDQ_I 0 "register_operand" "=w") + (xor:VDQ_I + (and:VDQ_I + (not:VDQ_I (match_operand:VDQ_I 3 "register_operand" "w")) + (match_operand:VDQ_I 2 "register_operand" "w")) + (match_operand:VDQ_I 1 "register_operand" "w")))] "TARGET_SHA3" "bcax\\t%0.16b, %1.16b, %2.16b, %3.16b" [(set_attr "type" "crypto_sha3")] ) +(define_insn_and_split "*bcaxqdi4" + [(set (match_operand:DI 0 "register_operand") + (xor:DI + (and:DI + (not:DI (match_operand:DI 3 "register_operand")) + (match_operand:DI 2 "register_operand")) + (match_operand:DI 1 "register_operand")))] + "TARGET_SHA3" + {@ [ cons: =0, 1, 2 , 3 ; attrs: type ] + [ w , w, w , w ; crypto_sha3 ] bcax\t%0.16b, %1.16b, %2.16b, %3.16b + [ &r , r, r0, r0 ; multiple ] # + } + "&& REG_P (operands[0]) && GP_REGNUM_P (REGNO (operands[0]))" + [(set (match_dup 4) + (and:DI (not:DI (match_dup 3)) + (match_dup 2))) + (set (match_dup 0) + (xor:DI (match_dup 4) + (match_dup 1)))] + { + if (reload_completed) + operands[4] = operands[0]; + else if (can_create_pseudo_p ()) + operands[4] = gen_reg_rtx (DImode); + else + FAIL; + } +) + ;; SM3 (define_insn "aarch64_sm3ss1qv4si" diff --git a/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc b/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc index d9922de..abe21a8 100644 --- a/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc +++ b/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc @@ -316,7 +316,8 @@ public: expand (function_expander &e) const override { e.prepare_gather_address_operands (1, false); - return e.use_exact_insn (CODE_FOR_aarch64_gather_ld1q); + auto icode = code_for_aarch64_gather_ld1q (e.tuple_mode (0)); + return e.use_exact_insn (icode); } }; @@ -722,7 +723,7 @@ public: expand (function_expander &e) const override { rtx data = e.args.last (); - e.args.last () = force_lowpart_subreg (VNx2DImode, data, GET_MODE (data)); + e.args.last () = aarch64_sve_reinterpret (VNx2DImode, data); e.prepare_gather_address_operands (1, false); return e.use_exact_insn (CODE_FOR_aarch64_scatter_st1q); } diff --git a/gcc/config/aarch64/aarch64-sve2.md b/gcc/config/aarch64/aarch64-sve2.md index 789ec0d..660901d 100644 --- a/gcc/config/aarch64/aarch64-sve2.md +++ b/gcc/config/aarch64/aarch64-sve2.md @@ -334,12 +334,21 @@ ;; - LD1Q (SVE2p1) ;; ------------------------------------------------------------------------- -;; Model this as operating on the largest valid element size, which is DI. -;; This avoids having to define move patterns & more for VNx1TI, which would -;; be difficult without a non-gather form of LD1Q. -(define_insn "aarch64_gather_ld1q" - [(set (match_operand:VNx2DI 0 "register_operand") - (unspec:VNx2DI +;; For little-endian targets, it would be enough to use a single pattern, +;; with a subreg to bitcast the result to whatever mode is needed. +;; However, on big-endian targets, the bitcast would need to be an +;; aarch64_sve_reinterpret instruction. That would interact badly +;; with the "&" and "?" constraints in this pattern: if the result +;; of the reinterpret needs to be in the same register as the index, +;; the RA would tend to prefer to allocate a separate register for the +;; intermediate (uncast) result, even if the reinterpret prefers tying. +;; +;; The index is logically VNx1DI rather than VNx2DI, but introducing +;; and using VNx1DI would just create more bitcasting. The ACLE intrinsic +;; uses svuint64_t, which corresponds to VNx2DI. +(define_insn "@aarch64_gather_ld1q<mode>" + [(set (match_operand:SVE_FULL 0 "register_operand") + (unspec:SVE_FULL [(match_operand:VNx2BI 1 "register_operand") (match_operand:DI 2 "aarch64_reg_or_zero") (match_operand:VNx2DI 3 "register_operand") diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 27c315f..6e16763 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -17932,7 +17932,7 @@ aarch64_vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind, /* Do one-time initialization based on the vinfo. */ loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (m_vinfo); - if (!m_analyzed_vinfo) + if (!m_analyzed_vinfo && !m_costing_for_scalar) { if (loop_vinfo) analyze_loop_vinfo (loop_vinfo); @@ -26960,12 +26960,23 @@ aarch64_evpc_tbl (struct expand_vec_perm_d *d) static bool aarch64_evpc_sve_tbl (struct expand_vec_perm_d *d) { - unsigned HOST_WIDE_INT nelt; + if (!d->one_vector_p) + { + /* aarch64_expand_sve_vec_perm does not yet handle variable-length + vectors. */ + if (!d->perm.length ().is_constant ()) + return false; - /* Permuting two variable-length vectors could overflow the - index range. */ - if (!d->one_vector_p && !d->perm.length ().is_constant (&nelt)) - return false; + /* This permutation reduces to the vec_perm optab if the elements are + large enough to hold all selector indices. Do not handle that case + here, since the general TBL+SUB+TBL+ORR sequence is too expensive to + be considered a "native" constant permutation. + + Not doing this would undermine code that queries can_vec_perm_const_p + with allow_variable_p set to false. See PR121027. */ + if (selector_fits_mode_p (d->vmode, d->perm)) + return false; + } if (d->testing_p) return true; diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index ad7360e..313522b 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -25798,6 +25798,14 @@ ix86_vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind, if (scalar_p) mode = TYPE_MODE (TREE_TYPE (vectype)); } + /* When we are costing a scalar stmt use the scalar stmt to get at the + type of the operation. */ + else if (scalar_p && stmt_info) + if (tree lhs = gimple_get_lhs (stmt_info->stmt)) + { + fp = FLOAT_TYPE_P (TREE_TYPE (lhs)); + mode = TYPE_MODE (TREE_TYPE (lhs)); + } if ((kind == vector_stmt || kind == scalar_stmt) && stmt_info diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 5825aca..83c438b 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -14769,6 +14769,17 @@ (compare:CCZ (neg:SWI (match_dup 0)) (const_int 0))) (set (match_dup 0) (neg:SWI (match_dup 0)))])]) +;; Optimize *negsi_1 followed by *cmpsi_ccno_1 (PR target/91384) with APX_F +(define_peephole2 + [(parallel [(set (match_operand:SWI 0 "general_reg_operand") + (neg:SWI (match_operand:SWI 1 "general_reg_operand"))) + (clobber (reg:CC FLAGS_REG))]) + (set (reg:CCZ FLAGS_REG) (compare:CCZ (match_dup 1) (const_int 0)))] + "TARGET_APX_NDD" + [(parallel [(set (reg:CCZ FLAGS_REG) + (compare:CCZ (neg:SWI (match_dup 1)) (const_int 0))) + (set (match_dup 0) (neg:SWI (match_dup 1)))])]) + ;; Special expand pattern to handle integer mode abs (define_expand "abs<mode>2" diff --git a/gcc/config/riscv/constraints.md b/gcc/config/riscv/constraints.md index ccab1a2..5ecaa19 100644 --- a/gcc/config/riscv/constraints.md +++ b/gcc/config/riscv/constraints.md @@ -237,10 +237,11 @@ (and (match_code "const_vector") (match_test "rtx_equal_p (op, riscv_vector::gen_scalar_move_mask (GET_MODE (op)))"))) -(define_memory_constraint "Wdm" +(define_constraint "Wdm" "Vector duplicate memory operand" - (and (match_code "mem") - (match_code "reg" "0"))) + (and (match_test "strided_load_broadcast_p ()") + (and (match_code "mem") + (match_code "reg" "0")))) ;; Vendor ISA extension constraints. diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md index 8baad2f..1f9a6b5 100644 --- a/gcc/config/riscv/predicates.md +++ b/gcc/config/riscv/predicates.md @@ -617,7 +617,7 @@ ;; The scalar operand can be directly broadcast by RVV instructions. (define_predicate "direct_broadcast_operand" - (match_test "riscv_vector::can_be_broadcasted_p (op)")) + (match_test "riscv_vector::can_be_broadcast_p (op)")) ;; A CONST_INT operand that has exactly two bits cleared. (define_predicate "const_nottwobits_operand" diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 38f63ea..a41c4c2 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -604,6 +604,7 @@ void emit_vlmax_vsetvl (machine_mode, rtx); void emit_hard_vlmax_vsetvl (machine_mode, rtx); void emit_vlmax_insn (unsigned, unsigned, rtx *); void emit_nonvlmax_insn (unsigned, unsigned, rtx *, rtx); +void emit_avltype_insn (unsigned, unsigned, rtx *, avl_type, rtx = nullptr); void emit_vlmax_insn_lra (unsigned, unsigned, rtx *, rtx); enum vlmul_type get_vlmul (machine_mode); rtx get_vlmax_rtx (machine_mode); @@ -760,7 +761,7 @@ uint8_t get_sew (rtx_insn *); enum vlmul_type get_vlmul (rtx_insn *); int count_regno_occurrences (rtx_insn *, unsigned int); bool imm_avl_p (machine_mode); -bool can_be_broadcasted_p (rtx); +bool can_be_broadcast_p (rtx); bool gather_scatter_valid_offset_p (machine_mode); HOST_WIDE_INT estimated_poly_value (poly_int64, unsigned int); bool whole_reg_to_reg_move_p (rtx *, machine_mode, int); @@ -813,6 +814,7 @@ extern const char *th_output_move (rtx, rtx); extern bool th_print_operand_address (FILE *, machine_mode, rtx); #endif +extern bool strided_load_broadcast_p (void); extern bool riscv_use_divmod_expander (void); void riscv_init_cumulative_args (CUMULATIVE_ARGS *, tree, rtx, tree, int); extern bool diff --git a/gcc/config/riscv/riscv-selftests.cc b/gcc/config/riscv/riscv-selftests.cc index 34d01ac..9ca1ffe 100644 --- a/gcc/config/riscv/riscv-selftests.cc +++ b/gcc/config/riscv/riscv-selftests.cc @@ -342,9 +342,13 @@ run_broadcast_selftests (void) expand_vector_broadcast (mode, mem); \ insn = get_last_insn (); \ src = SET_SRC (PATTERN (insn)); \ - ASSERT_TRUE (MEM_P (XEXP (src, 0))); \ - ASSERT_TRUE ( \ - rtx_equal_p (src, gen_rtx_VEC_DUPLICATE (mode, XEXP (src, 0)))); \ + if (strided_load_broadcast_p ()) \ + { \ + ASSERT_TRUE (MEM_P (XEXP (src, 0))); \ + ASSERT_TRUE ( \ + rtx_equal_p (src, \ + gen_rtx_VEC_DUPLICATE (mode, XEXP (src, 0)))); \ + } \ end_sequence (); \ /* Test vmv.v.x or vfmv.v.f. */ \ start_sequence (); \ diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc index 2efe56a..242ac08 100644 --- a/gcc/config/riscv/riscv-v.cc +++ b/gcc/config/riscv/riscv-v.cc @@ -437,6 +437,26 @@ emit_nonvlmax_insn (unsigned icode, unsigned insn_flags, rtx *ops, rtx vl) e.emit_insn ((enum insn_code) icode, ops); } +/* Emit either a VLMAX insn or a non-VLMAX insn depending on TYPE. For a + non-VLMAX insn, the length must be specified in VL. */ + +void +emit_avltype_insn (unsigned icode, unsigned insn_flags, rtx *ops, + avl_type type, rtx vl) +{ + if (type != avl_type::VLMAX && vl != NULL_RTX) + { + insn_expander<RVV_INSN_OPERANDS_MAX> e (insn_flags, false); + e.set_vl (vl); + e.emit_insn ((enum insn_code) icode, ops); + } + else + { + insn_expander<RVV_INSN_OPERANDS_MAX> e (insn_flags, true); + e.emit_insn ((enum insn_code) icode, ops); + } +} + /* Return true if the vector duplicated by a super element which is the fusion of consecutive elements. @@ -2144,21 +2164,40 @@ sew64_scalar_helper (rtx *operands, rtx *scalar_op, rtx vl, return false; } + bool avoid_strided_broadcast = false; if (CONST_INT_P (*scalar_op)) { if (maybe_gt (GET_MODE_SIZE (scalar_mode), GET_MODE_SIZE (Pmode))) - *scalar_op = force_const_mem (scalar_mode, *scalar_op); + { + if (strided_load_broadcast_p ()) + *scalar_op = force_const_mem (scalar_mode, *scalar_op); + else + avoid_strided_broadcast = true; + } else *scalar_op = force_reg (scalar_mode, *scalar_op); } rtx tmp = gen_reg_rtx (vector_mode); - rtx ops[] = {tmp, *scalar_op}; - if (type == VLMAX) - emit_vlmax_insn (code_for_pred_broadcast (vector_mode), UNARY_OP, ops); + if (!avoid_strided_broadcast) + { + rtx ops[] = {tmp, *scalar_op}; + emit_avltype_insn (code_for_pred_broadcast (vector_mode), UNARY_OP, ops, + type, vl); + } else - emit_nonvlmax_insn (code_for_pred_broadcast (vector_mode), UNARY_OP, ops, - vl); + { + /* Load scalar as V1DI and broadcast via vrgather.vi. */ + rtx tmp1 = gen_reg_rtx (V1DImode); + emit_move_insn (tmp1, lowpart_subreg (V1DImode, *scalar_op, + scalar_mode)); + tmp1 = lowpart_subreg (vector_mode, tmp1, V1DImode); + + rtx ops[] = {tmp, tmp1, CONST0_RTX (Pmode)}; + emit_vlmax_insn (code_for_pred_gather_scalar (vector_mode), + BINARY_OP, ops); + } + emit_vector_func (operands, tmp); return true; @@ -5769,9 +5808,9 @@ count_regno_occurrences (rtx_insn *rinsn, unsigned int regno) return count; } -/* Return true if the OP can be directly broadcasted. */ +/* Return true if the OP can be directly broadcast. */ bool -can_be_broadcasted_p (rtx op) +can_be_broadcast_p (rtx op) { machine_mode mode = GET_MODE (op); /* We don't allow RA (register allocation) reload generate @@ -5783,7 +5822,8 @@ can_be_broadcasted_p (rtx op) return false; if (satisfies_constraint_K (op) || register_operand (op, mode) - || satisfies_constraint_Wdm (op) || rtx_equal_p (op, CONST0_RTX (mode))) + || (strided_load_broadcast_p () && satisfies_constraint_Wdm (op)) + || rtx_equal_p (op, CONST0_RTX (mode))) return true; return can_create_pseudo_p () && nonmemory_operand (op, mode); diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index b868a50..a4428f0 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -283,6 +283,10 @@ enum riscv_fusion_pairs RISCV_FUSE_AUIPC_LD = (1 << 7), RISCV_FUSE_LDPREINCREMENT = (1 << 8), RISCV_FUSE_ALIGNED_STD = (1 << 9), + RISCV_FUSE_CACHE_ALIGNED_STD = (1 << 10), + RISCV_FUSE_BFEXT = (1 << 11), + RISCV_FUSE_EXPANDED_LD = (1 << 12), + RISCV_FUSE_B_ALUI = (1 << 13), }; /* Costs of various operations on the different architectures. */ @@ -302,6 +306,7 @@ struct riscv_tune_param bool vector_unaligned_access; bool use_divmod_expansion; bool overlap_op_by_pieces; + bool use_zero_stride_load; bool speculative_sched_vsetvl; unsigned int fusible_ops; const struct cpu_vector_cost *vec_costs; @@ -465,6 +470,7 @@ static const struct riscv_tune_param generic_tune_info = { false, /* vector_unaligned_access */ false, /* use_divmod_expansion */ false, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_NOTHING, /* fusible_ops */ NULL, /* vector cost */ @@ -488,6 +494,7 @@ static const struct riscv_tune_param rocket_tune_info = { false, /* vector_unaligned_access */ false, /* use_divmod_expansion */ false, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_NOTHING, /* fusible_ops */ NULL, /* vector cost */ @@ -511,6 +518,7 @@ static const struct riscv_tune_param sifive_7_tune_info = { false, /* vector_unaligned_access */ false, /* use_divmod_expansion */ false, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_NOTHING, /* fusible_ops */ NULL, /* vector cost */ @@ -534,6 +542,7 @@ static const struct riscv_tune_param sifive_p400_tune_info = { false, /* vector_unaligned_access */ false, /* use_divmod_expansion */ false, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_LUI_ADDI | RISCV_FUSE_AUIPC_ADDI, /* fusible_ops */ &generic_vector_cost, /* vector cost */ @@ -557,6 +566,7 @@ static const struct riscv_tune_param sifive_p600_tune_info = { false, /* vector_unaligned_access */ false, /* use_divmod_expansion */ false, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_LUI_ADDI | RISCV_FUSE_AUIPC_ADDI, /* fusible_ops */ &generic_vector_cost, /* vector cost */ @@ -580,6 +590,7 @@ static const struct riscv_tune_param thead_c906_tune_info = { false, /* vector_unaligned_access */ false, /* use_divmod_expansion */ false, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_NOTHING, /* fusible_ops */ NULL, /* vector cost */ @@ -603,6 +614,7 @@ static const struct riscv_tune_param xiangshan_nanhu_tune_info = { false, /* vector_unaligned_access */ false, /* use_divmod_expansion */ false, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_ZEXTW | RISCV_FUSE_ZEXTH, /* fusible_ops */ NULL, /* vector cost */ @@ -626,6 +638,7 @@ static const struct riscv_tune_param generic_ooo_tune_info = { true, /* vector_unaligned_access */ false, /* use_divmod_expansion */ true, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_NOTHING, /* fusible_ops */ &generic_vector_cost, /* vector cost */ @@ -649,6 +662,7 @@ static const struct riscv_tune_param tt_ascalon_d8_tune_info = { true, /* vector_unaligned_access */ true, /* use_divmod_expansion */ true, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_NOTHING, /* fusible_ops */ &generic_vector_cost, /* vector cost */ @@ -672,6 +686,7 @@ static const struct riscv_tune_param optimize_size_tune_info = { false, /* vector_unaligned_access */ false, /* use_divmod_expansion */ false, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_NOTHING, /* fusible_ops */ NULL, /* vector cost */ @@ -695,6 +710,7 @@ static const struct riscv_tune_param mips_p8700_tune_info = { false, /* vector_unaligned_access */ true, /* use_divmod_expansion */ false, /* overlap_op_by_pieces */ + true, /* use_zero_stride_load */ false, /* speculative_sched_vsetvl */ RISCV_FUSE_NOTHING, /* fusible_ops */ NULL, /* vector cost */ @@ -10205,6 +10221,81 @@ riscv_fusion_enabled_p(enum riscv_fusion_pairs op) return tune_param->fusible_ops & op; } +/* Matches an add: + (set (reg:DI rd) (plus:SI (reg:SI rs1) (reg:SI rs2))) */ + +static bool +riscv_set_is_add (rtx set) +{ + return (GET_CODE (SET_SRC (set)) == PLUS + && REG_P (XEXP (SET_SRC (set), 0)) + && REG_P (XEXP (SET_SRC (set), 1)) + && REG_P (SET_DEST (set))); +} + +/* Matches an addi: + (set (reg:DI rd) (plus:SI (reg:SI rs1) (const_int imm))) */ + +static bool +riscv_set_is_addi (rtx set) +{ + return (GET_CODE (SET_SRC (set)) == PLUS + && REG_P (XEXP (SET_SRC (set), 0)) + && CONST_INT_P (XEXP (SET_SRC (set), 1)) + && REG_P (SET_DEST (set))); +} + +/* Matches an add.uw: + (set (reg:DI rd) + (plus:DI (zero_extend:DI (reg:SI rs1)) (reg:DI rs2))) */ + +static bool +riscv_set_is_adduw (rtx set) +{ + return (GET_CODE (SET_SRC (set)) == PLUS + && GET_CODE (XEXP (SET_SRC (set), 0)) == ZERO_EXTEND + && REG_P (XEXP (XEXP (SET_SRC (set), 0), 0)) + && REG_P (XEXP (SET_SRC (set), 1)) + && REG_P (SET_DEST (set))); +} + +/* Matches a shNadd: + (set (reg:DI rd) + (plus:DI (ashift:DI (reg:DI rs1) (const_int N)) (reg:DI rS2)) */ + +static bool +riscv_set_is_shNadd (rtx set) +{ + return (GET_CODE (SET_SRC (set)) == PLUS + && GET_CODE (XEXP (SET_SRC (set), 0)) == ASHIFT + && REG_P (XEXP (XEXP (SET_SRC (set), 0), 0)) + && CONST_INT_P (XEXP (XEXP (SET_SRC (set), 0), 1)) + && (INTVAL (XEXP (XEXP (SET_SRC (set), 0), 1)) == 1 + || INTVAL (XEXP (XEXP (SET_SRC (set), 0), 1)) == 2 + || INTVAL (XEXP (XEXP (SET_SRC (set), 0), 1)) == 3) + && REG_P (SET_DEST (set))); +} + +/* Matches a shNadd.uw: + (set (reg:DI rd) + (plus:DI (and:DI (ashift:DI (reg:DI rs1) (const_int N)) + (const_int N)) + (reg:DI rs2)) */ + +static bool +riscv_set_is_shNadduw (rtx set) +{ + return (GET_CODE (SET_SRC (set)) == PLUS + && GET_CODE (XEXP (SET_SRC (set), 0)) == AND + && GET_CODE (XEXP (XEXP (SET_SRC (set), 0), 0)) == ASHIFT + && REG_P (XEXP (XEXP (XEXP (SET_SRC (set), 0), 0), 0)) + && CONST_INT_P (XEXP (XEXP (XEXP (SET_SRC (set), 0), 0), 1)) + && (INTVAL (XEXP (XEXP (XEXP (SET_SRC (set), 0), 0), 1)) == 1 + || INTVAL (XEXP (XEXP (XEXP (SET_SRC (set), 0), 0), 1)) == 2 + || INTVAL (XEXP (XEXP (XEXP (SET_SRC (set), 0), 0), 1)) == 3) + && REG_P (SET_DEST (set))); +} + /* Implement TARGET_SCHED_MACRO_FUSION_PAIR_P. Return true if PREV and CURR should be kept together during scheduling. */ @@ -10334,6 +10425,139 @@ riscv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr) } } + if (simple_sets_p && riscv_fusion_enabled_p (RISCV_FUSE_EXPANDED_LD) + && (sched1 || prev_dest_regno == curr_dest_regno)) + { + /* For the "expanded add/load fusion" family we have 2 main + categories: memory loads with displacement (i.e. with imm offset) + and loads without displacement (i.e. with offset = x0). + + For loads without displacement we'll need: + - add + ld (done in RISCV_FUSE_LDINDEXED) + - addi + ld (done in RISCV_FUSE_LDPREINCREMENT) + - shNadd + ld + - add.uw + lw + - shNadd.uw + lw + + For loads with displacement/immediates: + with lw with immediate): + - add + ld with displacement + - addi + ld with displacement + - shNadd + ld with displacement + - add.uw + lw with displacement + - shNadd.uw + lw with displacement */ + + /* We're trying to match a curr_set ld with displacement: + prev (add|addi) = (set (reg:DI rd) (...)) + curr (ld) == (set (reg:DI rD) + (mem:DI (plus:DI (reg:DI rD) (const_int IMM12)))) */ + if (MEM_P (SET_SRC (curr_set)) + && SCALAR_INT_MODE_P (GET_MODE (SET_DEST (curr_set))) + && GET_CODE (XEXP (SET_SRC (curr_set), 0)) == PLUS + && REGNO (XEXP (XEXP (SET_SRC (curr_set), 0), 0)) == prev_dest_regno) + { + if (riscv_set_is_add (prev_set)) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_EXPANDED_LD\n"); + return true; + } + + if (riscv_set_is_addi (prev_set)) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_EXPANDED_LD\n"); + return true; + } + + if (riscv_set_is_shNadd (prev_set)) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_EXPANDED_LD\n"); + return true; + } + } + + /* We're trying to match a ld without displacement: + prev (addi|shNadd) = (reg:DI rD) (...)) + curr (ld) == (set (reg:DI rD) + (mem:DI (reg:DI rD))) */ + if (MEM_P (SET_SRC (curr_set)) + && SCALAR_INT_MODE_P (GET_MODE (SET_DEST (curr_set))) + && REG_P (XEXP (SET_SRC (curr_set), 0)) + && REGNO (XEXP (SET_SRC (curr_set), 0)) == prev_dest_regno) + { + if (riscv_set_is_addi (prev_set)) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_EXPANDED_LD\n"); + return true; + } + + if (riscv_set_is_shNadd (prev_set)) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_EXPANDED_LD\n"); + return true; + } + } + + /* We're trying to match a curr_set lw with displacement: + prev (add.uw|shNadd.uw) = (set (reg:DI rd) (...)) + curr (lw) == (set (reg:DI rd) + (any_extend:DI (mem:SUBX (plus:DI ((reg:DI rd) + (const_int IMM)))) */ + if ((GET_CODE (SET_SRC (curr_set)) == SIGN_EXTEND + || (GET_CODE (SET_SRC (curr_set)) == ZERO_EXTEND)) + && MEM_P (XEXP (SET_SRC (curr_set), 0)) + && SCALAR_INT_MODE_P (GET_MODE (SET_DEST (curr_set))) + && GET_CODE (XEXP (XEXP (SET_SRC (curr_set), 0), 0)) == PLUS + && REG_P (XEXP (XEXP (XEXP (SET_SRC (curr_set), 0), 0),0)) + && (REGNO (XEXP (XEXP (XEXP (SET_SRC (curr_set), 0), 0),0)) + == prev_dest_regno)) + { + if (riscv_set_is_adduw (prev_set)) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_EXPANDED_LD\n"); + return true; + } + + if (riscv_set_is_shNadduw (prev_set)) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_EXPANDED_LD\n"); + return true; + } + } + + /* We're trying to match a curr_set lw without displacement: + prev (add.uw|shNadd.uw) = (set (reg:DI rd) (...)) + curr (ld|lh|lw) == (set (reg:DI rd) + (any_extend:DI (mem:SUBX (reg:DI rsd)))) */ + if ((GET_CODE (SET_SRC (curr_set)) == SIGN_EXTEND + || (GET_CODE (SET_SRC (curr_set)) == ZERO_EXTEND)) + && MEM_P (XEXP (SET_SRC (curr_set), 0)) + && SCALAR_INT_MODE_P (GET_MODE (SET_DEST (curr_set))) + && REG_P (XEXP (XEXP (SET_SRC (curr_set), 0), 0)) + && REGNO (XEXP (XEXP (SET_SRC (curr_set), 0), 0)) == prev_dest_regno) + { + if (riscv_set_is_adduw (prev_set)) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_EXPANDED_LD\n"); + return true; + } + + if (riscv_set_is_shNadduw (prev_set)) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_EXPANDED_LD\n"); + return true; + } + } + } + if (simple_sets_p && riscv_fusion_enabled_p (RISCV_FUSE_LDPREINCREMENT) && (sched1 || prev_dest_regno == curr_dest_regno)) { @@ -10474,7 +10698,7 @@ riscv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr) } } - if (simple_sets_p && riscv_fusion_enabled_p (RISCV_FUSE_ALIGNED_STD)) + if (simple_sets_p && riscv_fusion_enabled_p (RISCV_FUSE_CACHE_ALIGNED_STD)) { /* We are trying to match the following: prev (sd) == (set (mem (plus (reg sp|fp) (const_int))) @@ -10528,6 +10752,175 @@ riscv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr) } } + /* More general form of the RISCV_FUSE_CACHE_ALIGNED_STD. The + major difference is the dependency on the stores being opposite + halves of a cache line is dropped. Instead the lowest address + needs 2X the alignment of the object and the higher address + immediately followed the first object. */ + if (simple_sets_p && riscv_fusion_enabled_p (RISCV_FUSE_ALIGNED_STD)) + { + /* We are trying to match the following: + prev (sd) == (set (mem (plus (reg rS1) (const_int))) + (reg rS2)) + curr (sd) == (set (mem (plus (reg rS1) (const_int))) + (reg rS3)) */ + + if (MEM_P (SET_DEST (prev_set)) + && SCALAR_INT_MODE_P (GET_MODE (SET_DEST (curr_set))) + && MEM_P (SET_DEST (curr_set)) + /* Stores must have the same width */ + && GET_MODE (SET_DEST (curr_set)) == GET_MODE (SET_DEST (prev_set))) + { + rtx base_prev, base_curr, offset_prev, offset_curr; + unsigned mode_size; + + extract_base_offset_in_addr (SET_DEST (prev_set), + &base_prev, &offset_prev); + extract_base_offset_in_addr (SET_DEST (curr_set), + &base_curr, &offset_curr); + + /* Proceed only if we find both bases, both bases + are registers and bases are the same register. */ + if (base_prev != NULL_RTX && base_curr != NULL_RTX + && REG_P (base_prev) && REG_P (base_curr) + && REGNO (base_prev) == REGNO (base_curr)) + { + machine_mode mode = GET_MODE (SET_DEST (curr_set)); + mode_size = estimated_poly_value (GET_MODE_SIZE (mode)); + + HOST_WIDE_INT offset_prev_int = INTVAL (offset_prev); + HOST_WIDE_INT offset_curr_int = INTVAL (offset_curr); + + /* Get the smaller offset into OFFSET_PREV_INT. */ + if (offset_prev_int > offset_curr_int) + std::swap (offset_prev_int, offset_curr_int); + + /* We've normalized, so we need to check that the lower + address is aligned to 2X the size of the object. The + higher address must be the lower address plus the + size of the object. */ + if (((offset_prev_int % (2 * mode_size)) == 0) + && offset_prev_int + mode_size == offset_curr_int) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_ALIGNED_STD\n"); + return true; + } + } + } + } + + if (simple_sets_p && riscv_fusion_enabled_p (RISCV_FUSE_BFEXT) + && (sched1 || prev_dest_regno == curr_dest_regno)) + { + /* We are trying to match the following: + prev (slli) == (set (reg:DI rD) + (ashift:DI (reg:DI rS) (const_int))) + curr (srli) == (set (reg:DI rD) + (lshiftrt:DI (reg:DI rD) (const_int))) */ + + if (GET_CODE (SET_SRC (prev_set)) == ASHIFT + && (GET_CODE (SET_SRC (curr_set)) == LSHIFTRT + || GET_CODE (SET_SRC (curr_set)) == ASHIFTRT) + && REG_P (SET_DEST (prev_set)) + && REG_P (SET_DEST (curr_set)) + && REGNO (XEXP (SET_SRC (curr_set), 0)) == prev_dest_regno + && CONST_INT_P (XEXP (SET_SRC (prev_set), 1)) + && CONST_INT_P (XEXP (SET_SRC (curr_set), 1))) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_BFEXT\n"); + return true; + } + } + + if (simple_sets_p && riscv_fusion_enabled_p (RISCV_FUSE_B_ALUI) + && (sched1 || prev_dest_regno == curr_dest_regno)) + { + /* We are trying to match the following: + prev (orc.b) == (set (reg rD) + (unspec (reg rS1))) + curr (not) == (set (reg rD2) (not (reg rD))) */ + + if (GET_CODE (SET_SRC (prev_set)) == UNSPEC + && GET_CODE (SET_SRC (curr_set)) == NOT + && XINT (SET_SRC (prev_set), 1) == UNSPEC_ORC_B + && REG_P (SET_DEST (prev_set)) + && REG_P (SET_DEST (curr_set)) + && REG_P (XEXP (SET_SRC (curr_set), 0)) + && REGNO (XEXP (SET_SRC (curr_set), 0)) == prev_dest_regno) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_B_ALUI\n"); + return true; + } + + /* We are trying to match the following: + prev (ctz) == (set (reg rD) (ctz (reg rS1))) + curr (andi) == (set (reg rD) + (and (reg rD) (const_int 63))) */ + + if (GET_CODE (SET_SRC (prev_set)) == CTZ + && GET_CODE (SET_SRC (curr_set)) == AND + && CONST_INT_P (XEXP (SET_SRC (curr_set), 1)) + && INTVAL (XEXP (SET_SRC (curr_set), 1)) == 63 + && REG_P (SET_DEST (prev_set)) + && REG_P (SET_DEST (curr_set)) + && REG_P (XEXP (SET_SRC (curr_set), 0)) + && REGNO (XEXP (SET_SRC (curr_set), 0)) == prev_dest_regno) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_B_ALUI\n"); + return true; + } + + /* We are trying to match the following: + prev (sub) == (set (reg rD) + (minus (const_int 0) (reg rS2)) + curr (max) == (set (reg rD) + (smax (reg rD) (reg rS2))) */ + + if (GET_CODE (SET_SRC (prev_set)) == MINUS + && (XEXP (SET_SRC (prev_set), 0) + == CONST0_RTX (GET_MODE (SET_SRC (prev_set)))) + && CONST_INT_P (XEXP (SET_SRC (prev_set), 0)) + && GET_CODE (SET_SRC (curr_set)) == SMAX + && REG_P (SET_DEST (prev_set)) + && REG_P (SET_DEST (curr_set)) + && REG_P (XEXP (SET_SRC (curr_set), 0)) + && REGNO (XEXP (SET_SRC (curr_set), 0)) == prev_dest_regno + && REG_P (XEXP (SET_SRC (prev_set), 1)) + && REG_P (XEXP (SET_SRC (curr_set), 1)) + && (REGNO (XEXP (SET_SRC (prev_set), 1)) + == REGNO (XEXP (SET_SRC (curr_set), 1)))) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_B_ALUI\n"); + return true; + } + + /* We are trying to match the following: + prev (neg) == (set (reg rD) (neg (reg rS1))) + curr (max) == (set (reg rD) + (smax (reg rD) (reg rS1))) */ + + if (GET_CODE (SET_SRC (prev_set)) == NEG + && GET_CODE (SET_SRC (curr_set)) == SMAX + && REG_P (SET_DEST (prev_set)) + && REG_P (SET_DEST (curr_set)) + && REG_P (XEXP (SET_SRC (curr_set), 0)) + && REGNO (XEXP (SET_SRC (curr_set), 0)) == prev_dest_regno + && REG_P (XEXP (SET_SRC (prev_set), 0)) + && REG_P (XEXP (SET_SRC (curr_set), 1)) + && (REGNO (XEXP (SET_SRC (prev_set), 0)) + == REGNO (XEXP (SET_SRC (curr_set), 1)))) + { + if (dump_file) + fprintf (dump_file, "RISCV_FUSE_B_ALUI\n"); + return true; + } + } + return false; } @@ -12384,6 +12777,14 @@ riscv_lshift_subword (machine_mode mode ATTRIBUTE_UNUSED, rtx value, rtx shift, gen_lowpart (QImode, shift))); } +/* Return TRUE if we should use the zero stride load, FALSE otherwise. */ + +bool +strided_load_broadcast_p () +{ + return tune_param->use_zero_stride_load; +} + /* Return TRUE if we should use the divmod expander, FALSE otherwise. This allows the behavior to be tuned for specific implementations as well as when optimizing for size. */ diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index 2046f04..c5b23b3 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -1580,8 +1580,22 @@ "&& 1" [(const_int 0)] { - riscv_vector::emit_vlmax_insn (code_for_pred_broadcast (<MODE>mode), - riscv_vector::UNARY_OP, operands); + if (!strided_load_broadcast_p () + && TARGET_ZVFHMIN && !TARGET_ZVFH && <VEL>mode == HFmode) + { + /* For Float16, reinterpret as HImode, broadcast and reinterpret + back. */ + poly_uint64 nunits = GET_MODE_NUNITS (<MODE>mode); + machine_mode vmodehi + = riscv_vector::get_vector_mode (HImode, nunits).require (); + rtx ops[] = {lowpart_subreg (vmodehi, operands[0], <MODE>mode), + lowpart_subreg (HImode, operands[1], HFmode)}; + riscv_vector::emit_vlmax_insn (code_for_pred_broadcast (vmodehi), + riscv_vector::UNARY_OP, ops); + } + else + riscv_vector::emit_vlmax_insn (code_for_pred_broadcast (<MODE>mode), + riscv_vector::UNARY_OP, operands); DONE; } [(set_attr "type" "vector")] @@ -2171,7 +2185,7 @@ } } else if (GET_MODE_BITSIZE (<VEL>mode) > GET_MODE_BITSIZE (Pmode) - && (immediate_operand (operands[3], Pmode) + && (immediate_operand (operands[3], Pmode) || (CONST_POLY_INT_P (operands[3]) && known_ge (rtx_to_poly_int64 (operands[3]), 0U) && known_le (rtx_to_poly_int64 (operands[3]), GET_MODE_SIZE (<MODE>mode))))) @@ -2224,12 +2238,7 @@ "(register_operand (operands[3], <VEL>mode) || CONST_POLY_INT_P (operands[3])) && GET_MODE_BITSIZE (<VEL>mode) > GET_MODE_BITSIZE (Pmode)" - [(set (match_dup 0) - (if_then_else:V_VLSI (unspec:<VM> [(match_dup 1) (match_dup 4) - (match_dup 5) (match_dup 6) (match_dup 7) - (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (vec_duplicate:V_VLSI (match_dup 3)) - (match_dup 2)))] + [(const_int 0)] { gcc_assert (can_create_pseudo_p ()); if (CONST_POLY_INT_P (operands[3])) @@ -2238,12 +2247,6 @@ emit_move_insn (tmp, operands[3]); operands[3] = tmp; } - rtx m = assign_stack_local (<VEL>mode, GET_MODE_SIZE (<VEL>mode), - GET_MODE_ALIGNMENT (<VEL>mode)); - m = validize_mem (m); - emit_move_insn (m, operands[3]); - m = gen_rtx_MEM (<VEL>mode, force_reg (Pmode, XEXP (m, 0))); - operands[3] = m; /* For SEW = 64 in RV32 system, we expand vmv.s.x: andi a2,a2,1 @@ -2254,6 +2257,35 @@ operands[4] = riscv_vector::gen_avl_for_scalar_move (operands[4]); operands[1] = CONSTM1_RTX (<VM>mode); } + + /* If the target doesn't want a strided-load broadcast we go with a regular + V1DImode load and a broadcast gather. */ + if (strided_load_broadcast_p ()) + { + rtx mem = assign_stack_local (<VEL>mode, GET_MODE_SIZE (<VEL>mode), + GET_MODE_ALIGNMENT (<VEL>mode)); + mem = validize_mem (mem); + emit_move_insn (mem, operands[3]); + mem = gen_rtx_MEM (<VEL>mode, force_reg (Pmode, XEXP (mem, 0))); + + emit_insn + (gen_pred_broadcast<mode> + (operands[0], operands[1], operands[2], mem, + operands[4], operands[5], operands[6], operands[7])); + } + else + { + rtx tmp = gen_reg_rtx (V1DImode); + emit_move_insn (tmp, lowpart_subreg (V1DImode, operands[3], + <VEL>mode)); + tmp = lowpart_subreg (<MODE>mode, tmp, V1DImode); + + emit_insn + (gen_pred_gather<mode>_scalar + (operands[0], operands[1], operands[2], tmp, CONST0_RTX (Pmode), + operands[4], operands[5], operands[6], operands[7])); + } + DONE; } [(set_attr "type" "vimov,vimov,vlds,vlds,vlds,vlds,vimovxv,vimovxv") (set_attr "mode" "<MODE>")]) @@ -2293,9 +2325,9 @@ (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (vec_duplicate:V_VLSF_ZVFHMIN - (match_operand:<VEL> 3 "direct_broadcast_operand" "Wdm, Wdm, Wdm, Wdm")) + (match_operand:<VEL> 3 "direct_broadcast_operand" " A, A, A, A")) (match_operand:V_VLSF_ZVFHMIN 2 "vector_merge_operand" " vu, 0, vu, 0")))] - "TARGET_VECTOR" + "TARGET_VECTOR && strided_load_broadcast_p ()" "@ vlse<sew>.v\t%0,%3,zero,%1.t vlse<sew>.v\t%0,%3,zero,%1.t diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 79873a2..b0928d0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,262 @@ +2025-07-11 Jakub Jelinek <jakub@redhat.com> + + PR c++/119064 + * cp-tree.h: Implement C++26 P2786R13 - Trivial Relocatability. + (struct lang_type): Add trivially_relocatable, + trivially_relocatable_computed, replaceable and replaceable_computed + bitfields. Change width of dummy from 2 to 30. + (CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT, + CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED, CLASSTYPE_REPLACEABLE_BIT, + CLASSTYPE_REPLACEABLE_COMPUTED): Define. + (enum virt_specifier): Add VIRT_SPEC_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE + and VIRT_SPEC_REPLACEABLE_IF_ELIGIBLE enumerators. + (trivially_relocatable_type_p, replaceable_type_p): Declare. + * cp-trait.def (IS_NOTHROW_RELOCATABLE, IS_REPLACEABLE, + IS_TRIVIALLY_RELOCATABLE): New traits. + * parser.cc (cp_parser_class_property_specifier_seq_opt): Handle + trivially_relocatable_if_eligible, + __trivially_relocatable_if_eligible, replaceable_if_eligible and + __replaceable_if_eligible. + (cp_parser_class_head): Set CLASSTYPE_REPLACEABLE_BIT + and/or CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT if corresponding + conditional keywords were parsed and assert corresponding *_COMPUTED + macro is false. + * pt.cc (instantiate_class_template): Copy over also + CLASSTYPE_TRIVIALLY_RELOCATABLE_{BIT,COMPUTED} and + CLASSTYPE_REPLACEABLE_{BIT,COMPUTED} bits. + * semantics.cc (referenceable_type_p): Move definition earlier. + (trait_expr_value): Handle CPTK_IS_NOTHROW_RELOCATABLE, + CPTK_IS_REPLACEABLE and CPTK_IS_TRIVIALLY_RELOCATABLE. + (finish_trait_expr): Likewise. + * tree.cc (default_movable_type_p): New function. + (union_with_no_declared_special_member_fns): Likewise. + (trivially_relocatable_type_p): Likewise. + (replaceable_type_p): Likewise. + * constraint.cc (diagnose_trait_expr): Handle + CPTK_IS_NOTHROW_RELOCATABLE, CPTK_IS_REPLACEABLE and + CPTK_IS_TRIVIALLY_RELOCATABLE. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + * cp-tree.h (struct lang_type): Add comment before key_method. + Remove lambda_expr. + (CLASSTYPE_KEY_METHOD): Give NULL_TREE if not TYPE_POLYMORPHIC_P. + (SET_CLASSTYPE_KEY_METHOD): Define. + (CLASSTYPE_LAMBDA_EXPR): Give NULL_TREE if TYPE_POLYMORPHIC_P. + Use key_method member instead of lambda_expr. + (SET_CLASSTYPE_LAMBDA_EXPR): Define. + * class.cc (determine_key_method): Use SET_CLASSTYPE_KEY_METHOD + macro. + * decl.cc (xref_tag): Use SET_CLASSTYPE_LAMBDA_EXPR macro. + * lambda.cc (begin_lambda_type): Likewise. + * module.cc (trees_in::read_class_def): Use SET_CLASSTYPE_LAMBDA_EXPR + and SET_CLASSTYPE_KEY_METHOD macros, assert lambda is NULL if + TYPE_POLYMORPHIC_P and otherwise assert key_method is NULL. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + PR c++/120628 + * parser.cc (cp_parser_elaborated_type_specifier): Use + cp_parser_nth_token_starts_class_definition_p with extra argument 1 + instead of cp_parser_next_token_starts_class_definition_p. + (cp_parser_class_property_specifier_seq_opt): For final conditional + keyword in C++98 check if the token after it isn't + cp_parser_nth_token_starts_class_definition_p nor CPP_NAME and in + that case break without consuming it nor warning. + (cp_parser_class_head): Use + cp_parser_nth_token_starts_class_definition_p with extra argument 1 + instead of cp_parser_next_token_starts_class_definition_p. + (cp_parser_next_token_starts_class_definition_p): Renamed to ... + (cp_parser_nth_token_starts_class_definition_p): ... this. Add N + argument. Use cp_lexer_peek_nth_token instead of cp_lexer_peek_token. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + PR c++/120569 + * parser.cc (cp_parser_class_property_specifier_seq_opt): New + function. + (cp_parser_class_head): Use it instead of + cp_parser_property_specifier_seq_opt. Don't diagnose + VIRT_SPEC_OVERRIDE here. Formatting fix. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + PR c++/117785 + * constexpr.cc: Implement C++26 P3068R5 - constexpr exceptions. + (class constexpr_global_ctx): Add caught_exceptions and + uncaught_exceptions members. + (constexpr_global_ctx::constexpr_global_ctx): Initialize + uncaught_exceptions. + (returns, breaks, continues, switches): Move earlier. + (throws): New function. + (exception_what_str, diagnose_std_terminate, + diagnose_uncaught_exception): New functions. + (enum cxa_builtin): New type. + (cxx_cxa_builtin_fn_p, cxx_eval_cxa_builtin_fn): New functions. + (cxx_eval_builtin_function_call): Add jump_target argument. Call + cxx_eval_cxa_builtin_fn for __builtin_eh_ptr_adjust_ref. Adjust + cxx_eval_constant_expression calls, if it results in jmp_target, + set *jump_target to it and return. + (cxx_bind_parameters_in_call): Add jump_target argument. Pass + it through to cxx_eval_constant_expression. If it sets *jump_target, + break. + (fold_operand): Adjust cxx_eval_constant_expression caller. + (cxx_eval_assert): Likewise. If it set jmp_target, return true. + (cxx_eval_internal_function): Add jump_target argument. Pass it + through to cxx_eval_constant_expression. Return early if *jump_target + after recursing on args. + (cxx_eval_dynamic_cast_fn): Likewise. Don't set reference_p for + C++26 with -fexceptions. + (cxx_eval_thunk_call): Add jump_target argument. Pass it through + to cxx_eval_constant_expression. + (cxx_set_object_constness): Likewise. Don't set TREE_READONLY if + throws (jump_target). + (cxx_eval_call_expression): Add jump_target argument. Pass it + through to cxx_eval_internal_function, cxx_eval_builtin_function_call, + cxx_eval_thunk_call, cxx_eval_dynamic_cast_fn and + cxx_set_object_constness. Pass it through also + cxx_eval_constant_expression on arguments, cxx_bind_parameters_in_call + and cxx_fold_indirect_ref and for those cases return early + if *jump_target. Call cxx_eval_cxa_builtin_fn for cxx_cxa_builtin_fn_p + functions. For cxx_eval_constant_expression on body, pass address of + cleared jmp_target automatic variable, if it throws propagate + to *jump_target and make it non-cacheable. For C++26 don't diagnose + calls to non-constexpr functions before cxx_bind_parameters_in_call + could report some argument throwing an exception. + (cxx_eval_unary_expression): Add jump_target argument. Pass it + through to cxx_eval_constant_expression and return early + if *jump_target after the call. + (cxx_fold_pointer_plus_expression): Likewise. + (cxx_eval_binary_expression): Likewise and similarly for + cxx_fold_pointer_plus_expression call. + (cxx_eval_conditional_expression): Pass jump_target to + cxx_eval_constant_expression on first operand and return early + if *jump_target after the call. + (cxx_eval_vector_conditional_expression): Add jump_target argument. + Pass it through to cxx_eval_constant_expression for all 3 arguments + and return early if *jump_target after any of those calls. + (get_array_or_vector_nelts): Add jump_target argument. Pass it + through to cxx_eval_constant_expression. + (eval_and_check_array_index): Add jump_target argument. Pass it + through to cxx_eval_constant_expression calls and return early after + each of them if *jump_target. + (cxx_eval_array_reference): Likewise. + (cxx_eval_component_reference): Likewise. + (cxx_eval_bit_field_ref): Likewise. + (cxx_eval_bit_cast): Likewise. Assert CHECKING_P call doesn't + throw or return. + (cxx_eval_logical_expression): Add jump_target argument. Pass it + through to cxx_eval_constant_expression calls and return early after + each of them if *jump_target. + (cxx_eval_bare_aggregate): Likewise. + (cxx_eval_vec_init_1): Add jump_target argument. Pass it through + to cxx_eval_bare_aggregate and recursive call. Pass it through + to get_array_or_vector_nelts and cxx_eval_constant_expression + and return early after it if *jump_target. + (cxx_eval_vec_init): Add jump_target argument. Pass it through + to cxx_eval_constant_expression and cxx_eval_vec_init_1. + (cxx_union_active_member): Add jump_target argument. Pass it + through to cxx_eval_constant_expression and return early after it + if *jump_target. + (cxx_fold_indirect_ref_1): Add jump_target argument. Pass it + through to cxx_union_active_member and recursive calls. + (cxx_eval_indirect_ref): Add jump_target argument. Pass it through + to cxx_fold_indirect_ref_1 calls and to recursive call, in which + case return early after it if *jump_target. + (cxx_fold_indirect_ref): Add jump_target argument. Pass it through + to cxx_fold_indirect_ref and cxx_eval_constant_expression calls and + return early after those if *jump_target. + (cxx_eval_trinary_expression): Add jump_target argument. Pass it + through to cxx_eval_constant_expression calls and return early after + those if *jump_target. + (cxx_eval_store_expression): Add jump_target argument. Pass it + through to cxx_eval_constant_expression and eval_and_check_array_index + calls and return early after those if *jump_target. + (cxx_eval_increment_expression): Add jump_target argument. Pass it + through to cxx_eval_constant_expression calls and return early after + those if *jump_target. + (label_matches): Handle VAR_DECL case. + (cxx_eval_statement_list): Remove local_target variable and + !jump_target handling. Handle throws (jump_target) like returns or + breaks. + (cxx_eval_loop_expr): Remove local_target variable and !jump_target + handling. Pass it through to cxx_eval_constant_expression. Handle + throws (jump_target) like returns. + (cxx_eval_switch_expr): Pass jump_target through to + cxx_eval_constant_expression on cond, return early after it + if *jump_target. + (build_new_constexpr_heap_type): Add jump_target argument. Pass it + through to cxx_eval_constant_expression calls, return early after + those if *jump_target. + (merge_jump_target): New function. + (cxx_eval_constant_expression): Make jump_target argument no longer + defaulted, don't test jump_target for NULL. Pass jump_target + through to recursive calls, cxx_eval_call_expression, + cxx_eval_store_expression, cxx_eval_indirect_ref, + cxx_eval_unary_expression, cxx_eval_binary_expression, + cxx_eval_logical_expression, cxx_eval_array_reference, + cxx_eval_component_reference, cxx_eval_bit_field_ref, + cxx_eval_vector_conditional_expression, cxx_eval_bare_aggregate, + cxx_eval_vec_init, cxx_eval_trinary_expression, cxx_fold_indirect_ref, + build_new_constexpr_heap_type, cxx_eval_increment_expression, + cxx_eval_bit_cast and return earlyu after some of those + if *jump_target as needed. + (cxx_eval_constant_expression) <case TARGET_EXPR>: For C++26 push + also CLEANUP_EH_ONLY cleanups, with NULL_TREE marker after them. + (cxx_eval_constant_expression) <case RETURN_EXPR>: Don't + override *jump_target if throws (jump_target). + (cxx_eval_constant_expression) <case TRY_CATCH_EXPR, case TRY_BLOCK, + case MUST_NOT_THROW_EXPR, case TRY_FINALLY_EXPR, case CLEANUP_STMT>: + Handle C++26 constant expressions. + (cxx_eval_constant_expression) <case CLEANUP_POINT_EXPR>: For C++26 + with throws (jump_target) evaluate the CLEANUP_EH_ONLY cleanups as + well, and if not throws (jump_target) skip those. Set *jump_target + if some of the cleanups threw. + (cxx_eval_constant_expression) <case THROW_EXPR>: Recurse on operand + for C++26. + (cxx_eval_outermost_constant_expr): Diagnose uncaught exceptions both + from main expression and cleanups, diagnose also + break/continue/returns from the main expression. Handle + CLEANUP_EH_ONLY cleanup markers. Don't diagnose mutable poison stuff + if non_constant_p. Use different diagnostics for non-deleted heap + allocations if they were allocated by __cxa_allocate_exception. + (callee_might_throw): New function. + (struct check_for_return_continue_data): Add could_throw field. + (check_for_return_continue): Handle AGGR_INIT_EXPR and CALL_EXPR and + set d->could_throw if they could throw. + (potential_constant_expression_1): For CALL_EXPR allow + cxx_dynamic_cast_fn_p calls. For C++26 set *jump_target to void_node + for calls that could throw. For C++26 if call to non-constexpr call + is seen, try to evaluate arguments first and if they could throw, + don't diagnose call to non-constexpr function nor return false. + Adjust check_for_return_continue_data initializers and + set *jump_target to void_node if data.could_throw_p. For C++26 + recurse on THROW_EXPR argument. Add comment explaining TRY_BLOCK + handling with C++26 exceptions. Handle throws like returns in some + cases. + * cp-tree.h (MUST_NOT_THROW_NOEXCEPT_P, MUST_NOT_THROW_THROW_P, + MUST_NOT_THROW_CATCH_P, DECL_EXCEPTION_REFCOUNT): Define. + (DECL_LOCAL_DECL_P): Fix comment typo, VARIABLE_DECL -> VAR_DECL. + (enum cp_built_in_function): Add CP_BUILT_IN_EH_PTR_ADJUST_REF, + (handler_match_for_exception_type): Declare. + * call.cc (handler_match_for_exception_type): New function. + * except.cc (initialize_handler_parm): Set MUST_NOT_THROW_CATCH_P + on newly created MUST_NOT_THROW_EXPR. + (begin_eh_spec_block): Set MUST_NOT_THROW_NOEXCEPT_P. + (wrap_cleanups_r): Set MUST_NOT_THROW_THROW_P. + (build_throw): Add another TARGET_EXPR whose scope spans + until after the __cxa_throw call and copy pointer value from ptr + to it and use it in __cxa_throw argument. + * tree.cc (builtin_valid_in_constant_expr_p): Handle + CP_BUILT_IN_EH_PTR_ADJUST_REF. + * decl.cc (cxx_init_decl_processing): Initialize + __builtin_eh_ptr_adjust_ref FE builtin. + * pt.cc (tsubst_stmt) <case MUST_NOT_THROW_EXPR>: Copy the + MUST_NOT_THROW_NOEXCEPT_P, MUST_NOT_THROW_THROW_P and + MUST_NOT_THROW_CATCH_P flags. + * cp-gimplify.cc (cp_gimplify_expr) <case CALL_EXPR>: Error on + non-folded CP_BUILT_IN_EH_PTR_ADJUST_REF calls. + 2025-07-09 Jason Merrill <jason@redhat.com> PR c++/121012 diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 2c3ef3d..2629625 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -1723,6 +1723,56 @@ involves_qualification_conversion_p (tree to, tree from) return false; } +/* Return true if HANDLER is a match for exception object with EXCEPT_TYPE as + per [except.handle]/3. */ + +bool +handler_match_for_exception_type (tree handler, tree except_type) +{ + tree handler_type = HANDLER_TYPE (handler); + if (handler_type == NULL_TREE) + return true; /* ... */ + if (same_type_ignoring_top_level_qualifiers_p (handler_type, except_type)) + return true; + if (CLASS_TYPE_P (except_type) && CLASS_TYPE_P (handler_type)) + { + base_kind b_kind; + tree binfo = lookup_base (except_type, handler_type, ba_check, &b_kind, + tf_none); + if (binfo && binfo != error_mark_node) + return true; + } + if (TYPE_PTR_P (handler_type) || TYPE_PTRDATAMEM_P (handler_type)) + { + if (TREE_CODE (except_type) == NULLPTR_TYPE) + return true; + if ((TYPE_PTR_P (handler_type) && TYPE_PTR_P (except_type)) + || (TYPE_PTRDATAMEM_P (handler_type) + && TYPE_PTRDATAMEM_P (except_type))) + { + conversion *conv + = standard_conversion (handler_type, except_type, NULL_TREE, + /*c_cast_p=*/false, 0, tf_none); + if (conv && !conv->bad_p) + { + for (conversion *t = conv; t; t = next_conversion (t)) + switch (t->kind) + { + case ck_ptr: + case ck_fnptr: + case ck_qual: + case ck_identity: + break; + default: + return false; + } + return true; + } + } + } + return false; +} + /* A reference of the indicated TYPE is being bound directly to the expression represented by the implicit conversion sequence CONV. Return a conversion sequence for this binding. */ diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index 9a41c00..151ee2b 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -7452,7 +7452,7 @@ determine_key_method (tree type) && ! DECL_DECLARED_INLINE_P (method) && ! DECL_PURE_VIRTUAL_P (method)) { - CLASSTYPE_KEY_METHOD (type) = method; + SET_CLASSTYPE_KEY_METHOD (type, method); break; } diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index f9066bc..eb19784 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -1184,6 +1184,10 @@ public: /* Heap VAR_DECLs created during the evaluation of the outermost constant expression. */ auto_vec<tree, 16> heap_vars; + /* Vector of caught exceptions, including exceptions still not active at + the start of a handler (those are immediately followed up by HANDLER_TYPE + until __cxa_begin_catch finishes). */ + auto_vec<tree, 2> caught_exceptions; /* Cleanups that need to be evaluated at the end of CLEANUP_POINT_EXPR. */ vec<tree> *cleanups; /* If non-null, only allow modification of existing values of the variables @@ -1191,10 +1195,13 @@ public: hash_set<tree> *modifiable; /* Number of heap VAR_DECL deallocations. */ unsigned heap_dealloc_count; + /* Number of uncaught exceptions. */ + unsigned uncaught_exceptions; + /* Constructor. */ constexpr_global_ctx () : constexpr_ops_count (0), cleanups (NULL), modifiable (nullptr), - heap_dealloc_count (0) {} + heap_dealloc_count (0), uncaught_exceptions (0) {} bool is_outside_lifetime (tree t) { @@ -1308,6 +1315,48 @@ struct constexpr_ctx { mce_value manifestly_const_eval; }; +/* Predicates for the meaning of *jump_target. */ + +static bool +returns (tree *jump_target) +{ + return *jump_target && TREE_CODE (*jump_target) == RETURN_EXPR; +} + +static bool +breaks (tree *jump_target) +{ + return (*jump_target + && ((TREE_CODE (*jump_target) == LABEL_DECL + && LABEL_DECL_BREAK (*jump_target)) + || TREE_CODE (*jump_target) == BREAK_STMT + || TREE_CODE (*jump_target) == EXIT_EXPR)); +} + +static bool +continues (tree *jump_target) +{ + return (*jump_target + && ((TREE_CODE (*jump_target) == LABEL_DECL + && LABEL_DECL_CONTINUE (*jump_target)) + || TREE_CODE (*jump_target) == CONTINUE_STMT)); +} + +static bool +switches (tree *jump_target) +{ + return *jump_target && TREE_CODE (*jump_target) == INTEGER_CST; +} + +static bool +throws (tree *jump_target) +{ + /* void_node is for use in potential_constant_expression_1, otherwise + it should an artificial VAR_DECL created by constant evaluation + of __cxa_allocate_exception (). */ + return (*jump_target && (VAR_P (*jump_target) || *jump_target == void_node)); +} + /* True if the constexpr relaxations afforded by P2280R4 for unknown references and objects are in effect. */ @@ -1543,13 +1592,672 @@ enum value_cat { }; static tree cxx_eval_constant_expression (const constexpr_ctx *, tree, - value_cat, bool *, bool *, tree * = NULL); + value_cat, bool *, bool *, tree *); static tree cxx_eval_bare_aggregate (const constexpr_ctx *, tree, - value_cat, bool *, bool *); + value_cat, bool *, bool *, tree *); static tree cxx_fold_indirect_ref (const constexpr_ctx *, location_t, tree, tree, - bool * = NULL); + bool *, tree *); static tree find_heap_var_refs (tree *, int *, void *); +/* For exception object EXC if it has class type and usable what () method + which returns cv char * return the xmalloced string literal which it returns + if possible, otherwise return NULL. */ + +static char * +exception_what_str (const constexpr_ctx *ctx, tree exc) +{ + tree type = strip_array_types (TREE_TYPE (exc)); + if (!CLASS_TYPE_P (type)) + return NULL; + tree std_exception = lookup_qualified_name (std_node, "exception", + LOOK_want::NORMAL, false); + if (TREE_CODE (std_exception) != TYPE_DECL) + return NULL; + if (!CLASS_TYPE_P (TREE_TYPE (std_exception))) + return NULL; + base_kind b_kind; + tree binfo = lookup_base (type, TREE_TYPE (std_exception), ba_check, &b_kind, + tf_none); + if (binfo == NULL_TREE || binfo == error_mark_node) + return NULL; + if (type != TREE_TYPE (exc)) + exc = build4 (ARRAY_REF, type, exc, size_zero_node, NULL, NULL); + tree call + = finish_class_member_access_expr (exc, get_identifier ("what"), false, + tf_none); + if (call == error_mark_node) + return NULL; + releasing_vec what_args; + call = finish_call_expr (call, &what_args, false, false, tf_none); + if (call == error_mark_node) + return NULL; + if (TREE_CODE (TREE_TYPE (call)) != POINTER_TYPE + || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (call))) + || !COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (call))) + || !tree_int_cst_equal (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (call))), + TYPE_SIZE_UNIT (char_type_node)) + || TYPE_PRECISION (TREE_TYPE (TREE_TYPE (call))) != BITS_PER_UNIT) + return NULL; + if (!potential_constant_expression (call)) + return NULL; + bool non_constant_p = false, overflow_p = false; + tree jmp_target = NULL; + tree ptr = cxx_eval_constant_expression (ctx, call, vc_prvalue, + &non_constant_p, &overflow_p, + &jmp_target); + if (throws (&jmp_target) || non_constant_p) + return NULL; + if (reduced_constant_expression_p (ptr)) + if (const char *msg = c_getstr (ptr)) + return xstrdup (msg); + auto_vec <char, 32> v; + for (unsigned i = 0; i < INT_MAX; ++i) + { + tree t = call; + if (i) + t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (ptr), ptr, size_int (i)); + t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t); + non_constant_p = false; + overflow_p = false; + jmp_target = NULL; + tree t2 = cxx_eval_constant_expression (ctx, t, vc_prvalue, + &non_constant_p, &overflow_p, + &jmp_target); + if (throws (&jmp_target) + || non_constant_p + || !tree_fits_shwi_p (t2)) + return NULL; + char c = tree_to_shwi (t2); + v.safe_push (c); + if (c == '\0') + break; + } + return xstrdup (v.address ()); +} + +/* Diagnose constant expression evaluation encountering call to + std::terminate due to exception EXC. */ + +static void +diagnose_std_terminate (location_t loc, const constexpr_ctx *ctx, tree exc) +{ + tree type = strip_array_types (TREE_TYPE (exc)); + if (char *str = exception_what_str (ctx, exc)) + { + error_at (loc, "%qs called after throwing an exception of type %qT; " + "%<what()%>: %qs", "std::terminate", type, str); + free (str); + } + else + { + if (type != TREE_TYPE (exc)) + exc = build4 (ARRAY_REF, type, exc, size_zero_node, NULL, NULL); + bool non_constant_p = false, overflow_p = false; + tree jmp_target = NULL; + tree val = cxx_eval_constant_expression (ctx, exc, vc_prvalue, + &non_constant_p, &overflow_p, + &jmp_target); + gcc_assert (!throws (&jmp_target) && !non_constant_p); + if (reduced_constant_expression_p (val)) + error_at (loc, "%qs called after throwing an exception %qE", + "std::terminate", val); + else + error_at (loc, "%qs called after throwing an exception of type %qT", + "std::terminate", type); + } +} + +/* Diagnose constant expression evaluation encountering call to + uncaught exception EXC. */ + +static void +diagnose_uncaught_exception (location_t loc, const constexpr_ctx *ctx, tree exc) +{ + tree type = strip_array_types (TREE_TYPE (exc)); + if (char *str = exception_what_str (ctx, exc)) + { + error_at (loc, "uncaught exception of type %qT; %<what()%>: %qs", type, str); + free (str); + } + else + { + if (type != TREE_TYPE (exc)) + exc = build4 (ARRAY_REF, type, exc, size_zero_node, NULL, NULL); + bool non_constant_p = false, overflow_p = false; + tree jmp_target = NULL; + tree val = cxx_eval_constant_expression (ctx, exc, vc_prvalue, + &non_constant_p, &overflow_p, + &jmp_target); + gcc_assert (!throws (&jmp_target) && !non_constant_p); + if (reduced_constant_expression_p (val)) + error_at (loc, "uncaught exception %qE", val); + else + error_at (loc, "uncaught exception of type %qT", type); + } +} + +/* Kinds of __cxa_* functions (and a few other EH related ones) we handle as + magic constexpr functions for C++26. */ + +enum cxa_builtin { + CXA_NONE = 0, + CXA_ALLOCATE_EXCEPTION = 1, + CXA_FREE_EXCEPTION = 2, + CXA_THROW = 3, + CXA_BEGIN_CATCH = 4, + CXA_END_CATCH = 5, + CXA_RETHROW = 6, + CXA_GET_EXCEPTION_PTR = 7, + CXA_BAD_CAST = 8, + CXA_BAD_TYPEID = 9, + CXA_THROW_BAD_ARRAY_NEW_LENGTH = 10, + STD_UNCAUGHT_EXCEPTIONS = 11, + STD_CURRENT_EXCEPTION = 12, + STD_RETHROW_EXCEPTION = 13, + BUILTIN_EH_PTR_ADJUST_REF = 14 +}; + +/* Return cxa_builtin if FNDECL is a __cxa_* function handled as + magic constexpr function for C++26. Return CXA_NONE otherwise. */ + +static enum cxa_builtin +cxx_cxa_builtin_fn_p (tree fndecl) +{ + if (cxx_dialect < cxx26) + return CXA_NONE; + if (DECL_LANGUAGE (fndecl) != lang_c) + { + if (!decl_in_std_namespace_p (fndecl)) + return CXA_NONE; + if (id_equal (DECL_NAME (fndecl), "uncaught_exceptions")) + return STD_UNCAUGHT_EXCEPTIONS; + if (id_equal (DECL_NAME (fndecl), "current_exception")) + return STD_CURRENT_EXCEPTION; + if (id_equal (DECL_NAME (fndecl), "rethrow_exception")) + return STD_RETHROW_EXCEPTION; + return CXA_NONE; + } + if (!startswith (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "__cxa_")) + return CXA_NONE; + if (id_equal (DECL_NAME (fndecl), "__cxa_allocate_exception")) + return CXA_ALLOCATE_EXCEPTION; + if (id_equal (DECL_NAME (fndecl), "__cxa_free_exception")) + return CXA_FREE_EXCEPTION; + if (id_equal (DECL_NAME (fndecl), "__cxa_throw")) + return CXA_THROW; + if (id_equal (DECL_NAME (fndecl), "__cxa_begin_catch")) + return CXA_BEGIN_CATCH; + if (id_equal (DECL_NAME (fndecl), "__cxa_end_catch")) + return CXA_END_CATCH; + if (id_equal (DECL_NAME (fndecl), "__cxa_rethrow")) + return CXA_RETHROW; + if (id_equal (DECL_NAME (fndecl), "__cxa_get_exception_ptr")) + return CXA_GET_EXCEPTION_PTR; + if (id_equal (DECL_NAME (fndecl), "__cxa_bad_cast")) + return CXA_BAD_CAST; + if (id_equal (DECL_NAME (fndecl), "__cxa_bad_typeid")) + return CXA_BAD_TYPEID; + if (id_equal (DECL_NAME (fndecl), "__cxa_throw_bad_array_new_length")) + return CXA_THROW_BAD_ARRAY_NEW_LENGTH; + return CXA_NONE; +} + +/* Helper function for cxx_eval_cxa_builtin_fn. + Check if ARG is a valid first argument of __cxa_throw or + __cxa_free_exception or __builtin_eh_ptr_adjust_ref. Return NULL_TREE if + not, otherwise return the artificial __cxa_allocate_exception allocated + VAR_DECL. FREE_EXC is true for __cxa_free_exception, false otherwise. */ + +static tree +cxa_check_throw_arg (tree arg, bool free_exc) +{ + STRIP_NOPS (arg); + if (TREE_CODE (arg) != ADDR_EXPR) + return NULL_TREE; + arg = TREE_OPERAND (arg, 0); + if (!VAR_P (arg) + || !DECL_ARTIFICIAL (arg) + || ((!free_exc || DECL_NAME (arg) != heap_uninit_identifier) + && DECL_NAME (arg) != heap_identifier) + || !DECL_LANG_SPECIFIC (arg)) + return NULL_TREE; + return arg; +} + +/* Helper function for cxx_eval_cxa_builtin_fn. + "Allocate" on the constexpr heap an exception object of TYPE + with REFCOUNT. */ + +static tree +cxa_allocate_exception (location_t loc, const constexpr_ctx *ctx, tree type, + tree refcount) +{ + tree var = build_decl (loc, VAR_DECL, heap_uninit_identifier, type); + DECL_ARTIFICIAL (var) = 1; + retrofit_lang_decl (var); + DECL_EXCEPTION_REFCOUNT (var) = refcount; + ctx->global->heap_vars.safe_push (var); + return var; +} + +/* Evaluate various __cxa_* calls as magic constexpr builtins for + C++26 constexpr exception support (P3068R5). */ + +static tree +cxx_eval_cxa_builtin_fn (const constexpr_ctx *ctx, tree call, + enum cxa_builtin kind, tree fndecl, + bool *non_constant_p, bool *overflow_p, + tree *jump_target) +{ + int nargs = call_expr_nargs (call); + location_t loc = cp_expr_loc_or_input_loc (call); + tree args[4], arg; + if (nargs > 4) + { + invalid_nargs: + if (!ctx->quiet) + error_at (loc, "call to %qD function with incorrect" + "number of arguments", fndecl); + *non_constant_p = true; + return call; + } + if ((kind == CXA_BEGIN_CATCH || kind == CXA_GET_EXCEPTION_PTR) + && nargs == 1 + && (arg = CALL_EXPR_ARG (call, 0)) + && TREE_CODE (arg) == CALL_EXPR + && call_expr_nargs (arg) == 1 + && integer_zerop (CALL_EXPR_ARG (arg, 0))) + if (tree fun = get_function_named_in_call (arg)) + if (fndecl_built_in_p (fun, BUILT_IN_EH_POINTER)) + { + if (ctx->global->caught_exceptions.length () < 2) + { + no_caught_exceptions: + if (!ctx->quiet) + error_at (loc, "%qD called with no caught exceptions pending", + fndecl); + *non_constant_p = true; + return call; + } + /* Both __cxa_get_exception_ptr (__builtin_eh_pointer (0)) + and __cxa_begin_catch (__builtin_eh_pointer (0)) calls expect + ctx->global->caught_exceptions vector to end with + __cxa_allocate_exception created artificial VAR_DECL (the + exception object) followed by handler type, pushed by TRY_BLOCK + evaluation. The only difference between the functions is that + __cxa_begin_catch pops the handler type from the vector and keeps + the VAR_DECL last and decreases uncaught_exceptions. The + VAR_DECL after __cxa_begin_catch serves as the current exception + and is then popped in __cxa_end_catch evaluation. */ + tree handler_type = ctx->global->caught_exceptions.last (); + if (handler_type && VAR_P (handler_type)) + goto no_caught_exceptions; + unsigned idx = ctx->global->caught_exceptions.length () - 2; + arg = ctx->global->caught_exceptions[idx]; + gcc_assert (VAR_P (arg)); + if (kind == CXA_BEGIN_CATCH) + { + ctx->global->caught_exceptions.pop (); + --ctx->global->uncaught_exceptions; + } + if (handler_type == NULL_TREE) + /* Used for catch (...). Just return void. */ + return void_node; + else if (POINTER_TYPE_P (handler_type)) + { + /* Used for catch of a pointer. */ + if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE) + arg = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (arg)), arg, + size_zero_node, NULL_TREE, NULL_TREE); + arg = cp_convert (handler_type, arg, + ctx->quiet ? tf_none : tf_warning_or_error); + if (arg == error_mark_node) + { + *non_constant_p = true; + return call; + } + } + else + { + /* Used for catch of a non-pointer type. */ + tree exc_type = strip_array_types (TREE_TYPE (arg)); + tree exc_ptr_type = build_pointer_type (exc_type); + arg = build_fold_addr_expr_with_type (arg, exc_ptr_type); + if (CLASS_TYPE_P (handler_type)) + { + tree ptr_type = build_pointer_type (handler_type); + arg = cp_convert (ptr_type, arg, + ctx->quiet ? tf_none + : tf_warning_or_error); + if (arg == error_mark_node) + { + *non_constant_p = true; + return call; + } + } + } + return cxx_eval_constant_expression (ctx, arg, vc_prvalue, + non_constant_p, overflow_p, + jump_target); + } + for (int i = 0; i < nargs; ++i) + { + args[i] = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (call, i), + vc_prvalue, non_constant_p, + overflow_p, jump_target); + if (*non_constant_p) + return call; + if (*jump_target) + return NULL_TREE; + } + switch (kind) + { + case CXA_ALLOCATE_EXCEPTION: + if (nargs != 1) + goto invalid_nargs; + if (!tree_fits_uhwi_p (args[0])) + { + if (!ctx->quiet) + error_at (loc, "cannot allocate exception: size not constant"); + *non_constant_p = true; + return call; + } + else + { + tree type = build_array_type_nelts (char_type_node, + tree_to_uhwi (args[0])); + tree var = cxa_allocate_exception (loc, ctx, type, size_zero_node); + ctx->global->put_value (var, NULL_TREE); + return fold_convert (ptr_type_node, build_address (var)); + } + case CXA_FREE_EXCEPTION: + if (nargs != 1) + goto invalid_nargs; + arg = cxa_check_throw_arg (args[0], true); + if (arg == NULL_TREE) + { + invalid_ptr: + if (!ctx->quiet) + error_at (loc, "first argument to %qD function not result of " + "%<__cxa_allocate_exception%>", fndecl); + *non_constant_p = true; + return call; + } + DECL_NAME (arg) = heap_deleted_identifier; + ctx->global->destroy_value (arg); + ctx->global->heap_dealloc_count++; + return void_node; + case CXA_THROW: + if (nargs != 3) + goto invalid_nargs; + arg = cxa_check_throw_arg (args[0], false); + if (arg == NULL_TREE) + goto invalid_ptr; + DECL_EXCEPTION_REFCOUNT (arg) + = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg), + size_one_node); + ++ctx->global->uncaught_exceptions; + *jump_target = arg; + return void_node; + case CXA_BEGIN_CATCH: + case CXA_GET_EXCEPTION_PTR: + goto invalid_nargs; + case CXA_END_CATCH: + if (nargs != 0) + goto invalid_nargs; + if (ctx->global->caught_exceptions.is_empty ()) + { + no_active_exc: + if (!ctx->quiet) + error_at (loc, "%qD called with no caught exceptions active", + fndecl); + *non_constant_p = true; + return call; + } + else + { + arg = ctx->global->caught_exceptions.pop (); + if (arg == NULL_TREE || !VAR_P (arg)) + goto no_active_exc; + free_except: + DECL_EXCEPTION_REFCOUNT (arg) + = size_binop (MINUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg), + size_one_node); + if (integer_zerop (DECL_EXCEPTION_REFCOUNT (arg))) + { + if (type_build_dtor_call (TREE_TYPE (arg))) + { + tree cleanup + = cxx_maybe_build_cleanup (arg, (ctx->quiet ? tf_none + : tf_warning_or_error)); + if (cleanup == error_mark_node) + *non_constant_p = true; + tree jmp_target = NULL_TREE; + cxx_eval_constant_expression (ctx, cleanup, vc_discard, + non_constant_p, overflow_p, + &jmp_target); + if (throws (&jmp_target)) + *jump_target = jmp_target; + } + DECL_NAME (arg) = heap_deleted_identifier; + ctx->global->destroy_value (arg); + ctx->global->heap_dealloc_count++; + } + } + return void_node; + case CXA_RETHROW: + if (nargs != 0) + goto invalid_nargs; + unsigned idx; + FOR_EACH_VEC_ELT_REVERSE (ctx->global->caught_exceptions, idx, arg) + if (arg == NULL_TREE || !VAR_P (arg)) + --idx; + else + break; + if (arg == NULL_TREE) + { + if (!ctx->quiet) + error_at (loc, "%qD called with no caught exceptions active", + fndecl); + *non_constant_p = true; + return call; + } + DECL_EXCEPTION_REFCOUNT (arg) + = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg), size_one_node); + ++ctx->global->uncaught_exceptions; + *jump_target = arg; + return void_node; + case CXA_BAD_CAST: + case CXA_BAD_TYPEID: + case CXA_THROW_BAD_ARRAY_NEW_LENGTH: + if (nargs != 0) + goto invalid_nargs; + else + { + tree name; + switch (kind) + { + case CXA_BAD_CAST: + name = get_identifier ("bad_cast"); + break; + case CXA_BAD_TYPEID: + name = get_identifier ("bad_typeid"); + break; + case CXA_THROW_BAD_ARRAY_NEW_LENGTH: + name = get_identifier ("bad_array_new_length"); + break; + default: + gcc_unreachable (); + } + tree decl = lookup_qualified_name (std_node, name); + if (TREE_CODE (decl) != TYPE_DECL + || !CLASS_TYPE_P (TREE_TYPE (decl)) + || !type_build_ctor_call (TREE_TYPE (decl))) + { + if (!ctx->quiet) + error_at (loc, "%qD called without %<std::%D%> being defined", + fndecl, name); + *non_constant_p = true; + return call; + } + tree type = TREE_TYPE (decl); + tree var = cxa_allocate_exception (loc, ctx, type, size_one_node); + tree ctor + = build_special_member_call (var, complete_ctor_identifier, + NULL, type, LOOKUP_NORMAL, + ctx->quiet ? tf_none + : tf_warning_or_error); + if (ctor == error_mark_node) + { + *non_constant_p = true; + return call; + } + if (TREE_CONSTANT (ctor)) + ctx->global->put_value (var, ctor); + else + { + ctx->global->put_value (var, NULL_TREE); + cxx_eval_constant_expression (ctx, ctor, vc_discard, + non_constant_p, overflow_p, + jump_target); + if (*non_constant_p) + return call; + if (throws (jump_target)) + return NULL_TREE; + } + ++ctx->global->uncaught_exceptions; + *jump_target = var; + } + return void_node; + case STD_UNCAUGHT_EXCEPTIONS: + if (nargs != 0) + goto invalid_nargs; + /* Similarly to __builtin_is_constant_evaluated (), we don't + want to give a definite answer during mce_unknown evaluation, + because that might prevent evaluation later on when some + exceptions might be uncaught. But unlike that, we don't + want to constant fold it even during cp_fold, because at runtime + std::uncaught_exceptions () might still be non-zero. */ + if (ctx->manifestly_const_eval != mce_true) + { + *non_constant_p = true; + return call; + } + return build_int_cst (integer_type_node, + ctx->global->uncaught_exceptions); + case STD_CURRENT_EXCEPTION: + if (nargs != 0) + goto invalid_nargs; + else + { + tree name = get_identifier ("exception_ptr"); + tree decl = lookup_qualified_name (std_node, name); + tree fld; + if (TREE_CODE (decl) != TYPE_DECL + || !CLASS_TYPE_P (TREE_TYPE (decl)) + || !COMPLETE_TYPE_P (TREE_TYPE (decl)) + || !(fld = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (decl)))) + || DECL_ARTIFICIAL (fld) + || TREE_CODE (TREE_TYPE (fld)) != POINTER_TYPE + || next_aggregate_field (DECL_CHAIN (fld)) + || !tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (decl)), + TYPE_SIZE (TREE_TYPE (fld)))) + { + if (!ctx->quiet) + error_at (loc, "%qD called without supportable %qs", + fndecl, "std::exception_ptr"); + *non_constant_p = true; + return call; + } + FOR_EACH_VEC_ELT_REVERSE (ctx->global->caught_exceptions, idx, arg) + if (arg == NULL_TREE || !VAR_P (arg)) + --idx; + else + break; + /* Similarly to __builtin_is_constant_evaluated (), we don't + want to give a definite answer during mce_unknown evaluation, + because that might prevent evaluation later on when some + exceptions might be current. But unlike that, we don't + want to constant fold it to null even during cp_fold, because + at runtime std::current_exception () might still be non-null. */ + if (ctx->manifestly_const_eval != mce_true && arg == NULL_TREE) + { + *non_constant_p = true; + return call; + } + if (arg == NULL_TREE) + arg = build_zero_cst (TREE_TYPE (fld)); + else + { + DECL_EXCEPTION_REFCOUNT (arg) + = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg), + size_one_node); + arg = fold_convert (ptr_type_node, build_address (arg)); + } + return build_constructor_single (TREE_TYPE (decl), fld, arg); + } + case STD_RETHROW_EXCEPTION: + if (nargs != 1) + goto invalid_nargs; + if (TYPE_REF_P (TREE_TYPE (args[0]))) + { + arg = args[0]; + STRIP_NOPS (arg); + if (TREE_CODE (arg) == ADDR_EXPR) + { + args[0] + = cxx_eval_constant_expression (ctx, TREE_OPERAND (arg, 0), + vc_prvalue, non_constant_p, + overflow_p, jump_target); + if (*non_constant_p) + return call; + if (*jump_target) + return NULL_TREE; + } + } + if (TREE_CODE (args[0]) != CONSTRUCTOR + || CONSTRUCTOR_NELTS (args[0]) != 1) + { + invalid_std_rethrow: + if (!ctx->quiet) + error_at (loc, "%qD called with unexpected %qs argument", + fndecl, "std::exception_ptr"); + *non_constant_p = true; + return void_node; + } + arg = cxa_check_throw_arg (CONSTRUCTOR_ELT (args[0], 0)->value, false); + if (arg == NULL_TREE) + goto invalid_std_rethrow; + DECL_EXCEPTION_REFCOUNT (arg) + = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg), size_one_node); + ++ctx->global->uncaught_exceptions; + *jump_target = arg; + return void_node; + case BUILTIN_EH_PTR_ADJUST_REF: + if (nargs != 2) + goto invalid_nargs; + arg = cxa_check_throw_arg (args[0], false); + if (arg == NULL_TREE) + goto invalid_ptr; + if (integer_onep (args[1])) + DECL_EXCEPTION_REFCOUNT (arg) + = size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg), + size_one_node); + else if (integer_minus_onep (args[1])) + goto free_except; + else + { + if (!ctx->quiet) + error_at (loc, "%qD called with second argument " + "other than 1 or -1", fndecl); + *non_constant_p = true; + } + return void_node; + default: + gcc_unreachable (); + } +} + /* Attempt to evaluate T which represents a call to a builtin function. We assume here that all builtin functions evaluate to scalar types represented by _CST nodes. */ @@ -1557,7 +2265,8 @@ static tree find_heap_var_refs (tree *, int *, void *); static tree cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { const int nargs = call_expr_nargs (t); tree *args = (tree *) alloca (nargs * sizeof (tree)); @@ -1603,6 +2312,12 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun, return fold_builtin_source_location (t); } + if (fndecl_built_in_p (fun, CP_BUILT_IN_EH_PTR_ADJUST_REF, + BUILT_IN_FRONTEND)) + return cxx_eval_cxa_builtin_fn (ctx, t, BUILTIN_EH_PTR_ADJUST_REF, + fun, non_constant_p, overflow_p, + jump_target); + int strops = 0; int strret = 0; if (fndecl_built_in_p (fun, BUILT_IN_NORMAL)) @@ -1677,8 +2392,14 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun, || potential_constant_expression (arg)) { bool dummy1 = false, dummy2 = false; + tree jmp_target = NULL_TREE; arg = cxx_eval_constant_expression (&new_ctx, arg, vc_prvalue, - &dummy1, &dummy2); + &dummy1, &dummy2, &jmp_target); + if (jmp_target) + { + *jump_target = jmp_target; + return NULL_TREE; + } } if (bi_const_p) @@ -1767,7 +2488,8 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun, } return cxx_eval_constant_expression (&new_ctx, new_call, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); } /* TEMP is the constant value of a temporary object of type TYPE. Adjust @@ -1882,7 +2604,8 @@ addr_of_non_const_var (tree *tp, int *walk_subtrees, void *data) static tree cxx_bind_parameters_in_call (const constexpr_ctx *ctx, tree t, tree fun, tree orig_fun, bool *non_constant_p, - bool *overflow_p, bool *non_constant_args) + bool *overflow_p, bool *non_constant_args, + tree *jump_target) { int nargs = call_expr_nargs (t); tree parms = DECL_ARGUMENTS (fun); @@ -1958,14 +2681,16 @@ cxx_bind_parameters_in_call (const constexpr_ctx *ctx, tree t, tree fun, /* Undo convert_for_arg_passing work here. */ x = convert_from_reference (x); arg = cxx_eval_constant_expression (ctx, x, vc_glvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); } else /* Normally we would strip a TARGET_EXPR in an initialization context such as this, but here we do the elision differently: we keep the TARGET_EXPR, and use its CONSTRUCTOR as the value of the parm. */ arg = cxx_eval_constant_expression (ctx, x, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); /* Check we aren't dereferencing a null pointer when calling a non-static member function, which is undefined behaviour. */ if (i == 0 && DECL_OBJECT_MEMBER_FUNCTION_P (fun) @@ -1983,6 +2708,8 @@ cxx_bind_parameters_in_call (const constexpr_ctx *ctx, tree t, tree fun, /* Don't VERIFY_CONSTANT here. */ if (*non_constant_p && ctx->quiet) break; + if (*jump_target) + break; /* Just discard ellipsis args after checking their constantitude. */ if (!parms) continue; @@ -2094,9 +2821,10 @@ fold_operand (tree e, const constexpr_ctx *ctx) if (ctx) { bool new_non_constant_p = false, new_overflow_p = false; + tree jmp_target = NULL_TREE; e = cxx_eval_constant_expression (ctx, e, vc_prvalue, &new_non_constant_p, - &new_overflow_p); + &new_overflow_p, &jmp_target); } else e = fold_non_dependent_expr (e, tf_none, /*manifestly_const_eval=*/true); @@ -2183,7 +2911,7 @@ cxx_eval_assert (const constexpr_ctx *ctx, tree arg, const char *msg, if (*non_constant_p) return true; - tree eval; + tree eval, jmp_target = NULL_TREE; if (!evaluated) { if (!potential_rvalue_constant_expression (arg)) @@ -2196,12 +2924,15 @@ cxx_eval_assert (const constexpr_ctx *ctx, tree arg, const char *msg, modifiable_tracker ms (new_ctx.global); eval = cxx_eval_constant_expression (&new_ctx, arg, vc_prvalue, &new_non_constant_p, - &new_overflow_p); + &new_overflow_p, &jmp_target); } else eval = cxx_eval_constant_expression (ctx, arg, vc_prvalue, non_constant_p, - overflow_p); + overflow_p, &jmp_target); + if (jmp_target) + return true; + if (!*non_constant_p && integer_zerop (eval)) { if (!ctx->quiet) @@ -2233,7 +2964,8 @@ cxx_eval_assert (const constexpr_ctx *ctx, tree arg, const char *msg, static tree cxx_eval_internal_function (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { enum tree_code opcode = ERROR_MARK; @@ -2266,13 +2998,15 @@ cxx_eval_internal_function (const constexpr_ctx *ctx, tree t, case IFN_LAUNDER: return cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 0), vc_prvalue, non_constant_p, - overflow_p); + overflow_p, jump_target); case IFN_VEC_CONVERT: { tree arg = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 0), vc_prvalue, non_constant_p, - overflow_p); + overflow_p, jump_target); + if (*jump_target) + return NULL_TREE; if (TREE_CODE (arg) == VECTOR_CST) if (tree r = fold_const_call (CFN_VEC_CONVERT, TREE_TYPE (t), arg)) return r; @@ -2290,10 +3024,13 @@ cxx_eval_internal_function (const constexpr_ctx *ctx, tree t, /* Evaluate constant arguments using OPCODE and return a complex number containing the result and the overflow bit. */ tree arg0 = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 0), lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); tree arg1 = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 1), lval, - non_constant_p, overflow_p); - + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST) { location_t loc = cp_expr_loc_or_input_loc (t); @@ -2566,7 +3303,8 @@ get_component_with_type (tree path, tree type, tree stop) static tree cxx_eval_dynamic_cast_fn (const constexpr_ctx *ctx, tree call, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { /* T will be something like __dynamic_cast ((B*) b, &_ZTI1B, &_ZTI1D, 8) @@ -2585,19 +3323,26 @@ cxx_eval_dynamic_cast_fn (const constexpr_ctx *ctx, tree call, /* TYPE can only be either T* or T&. We can't know which of these it is by looking at TYPE, but OBJ will be "(T*) x" in the first case, - and something like "(T*)(T&)(T*) x" in the second case. */ - bool reference_p = false; + and something like "(T*)(T&)(T*) x" in the second case. + This is true for the reference cases in C++ < 26 or when exceptions + aren't enabled, in that case we should diagnose errors. For C++26 + with exceptions we should silently evaluate to null pointer and + let the callers call __cxa_bad_cast () later to throw an exception. */ + bool fail_for_non_constant_p = false; while (CONVERT_EXPR_P (obj) || TREE_CODE (obj) == SAVE_EXPR) { - reference_p |= TYPE_REF_P (TREE_TYPE (obj)); + if (cxx_dialect < cxx26 || !flag_exceptions) + fail_for_non_constant_p |= TYPE_REF_P (TREE_TYPE (obj)); obj = TREE_OPERAND (obj, 0); } /* Evaluate the object so that we know its dynamic type. */ obj = cxx_eval_constant_expression (ctx, obj, vc_prvalue, non_constant_p, - overflow_p); + overflow_p, jump_target); if (*non_constant_p) return call; + if (*jump_target) + return NULL_TREE; /* For dynamic_cast from classes with virtual bases we can get something like (virt_base *)(&d + 16) as OBJ. Try to convert that into @@ -2609,7 +3354,7 @@ cxx_eval_dynamic_cast_fn (const constexpr_ctx *ctx, tree call, if (TREE_CODE (objo) == POINTER_PLUS_EXPR) { objo = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (TREE_TYPE (obj)), - obj); + obj, NULL, jump_target); if (objo) obj = build_fold_addr_expr (objo); } @@ -2625,7 +3370,7 @@ cxx_eval_dynamic_cast_fn (const constexpr_ctx *ctx, tree call, ? TREE_OPERAND (obj, 1) : obj)) if (TREE_CODE (t) != FIELD_DECL || !DECL_FIELD_IS_BASE (t)) { - if (reference_p) + if (fail_for_non_constant_p) { if (!ctx->quiet) { @@ -2647,9 +3392,12 @@ cxx_eval_dynamic_cast_fn (const constexpr_ctx *ctx, tree call, constructor or destructor's class. */ tree vtable = build_vfield_ref (obj, objtype); vtable = cxx_eval_constant_expression (ctx, vtable, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); if (*non_constant_p) return call; + if (*jump_target) + return NULL_TREE; /* With -fsanitize=vptr, we initialize all vtable pointers to null, so it's possible that we got a null pointer now. */ if (integer_zerop (vtable)) @@ -2681,7 +3429,7 @@ cxx_eval_dynamic_cast_fn (const constexpr_ctx *ctx, tree call, /* If not accessible, give an error. */ if (t == error_mark_node) { - if (reference_p) + if (fail_for_non_constant_p) { if (!ctx->quiet) { @@ -2714,7 +3462,7 @@ cxx_eval_dynamic_cast_fn (const constexpr_ctx *ctx, tree call, obj = get_component_with_type (obj, mdtype, NULL_TREE); if (obj == error_mark_node) { - if (reference_p) + if (fail_for_non_constant_p) { if (!ctx->quiet) { @@ -2736,7 +3484,7 @@ cxx_eval_dynamic_cast_fn (const constexpr_ctx *ctx, tree call, tree binfo = lookup_base (mdtype, type, ba_check, &b_kind, tf_none); if (!binfo || binfo == error_mark_node) { - if (reference_p) + if (fail_for_non_constant_p) { if (!ctx->quiet) { @@ -2832,7 +3580,7 @@ replace_decl (tree *tp, tree decl, tree replacement) static tree cxx_eval_thunk_call (const constexpr_ctx *ctx, tree t, tree thunk_fndecl, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, tree *jump_target) { tree function = THUNK_TARGET (thunk_fndecl); @@ -2875,7 +3623,8 @@ cxx_eval_thunk_call (const constexpr_ctx *ctx, tree t, tree thunk_fndecl, new_call, offset); return cxx_eval_constant_expression (ctx, new_call, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); } /* If OBJECT is of const class type, evaluate it to a CONSTRUCTOR and set @@ -2885,7 +3634,7 @@ cxx_eval_thunk_call (const constexpr_ctx *ctx, tree t, tree thunk_fndecl, static void cxx_set_object_constness (const constexpr_ctx *ctx, tree object, bool readonly_p, bool *non_constant_p, - bool *overflow_p) + bool *overflow_p, tree *jump_target) { if (CLASS_TYPE_P (TREE_TYPE (object)) && CP_TYPE_CONST_P (TREE_TYPE (object))) @@ -2893,8 +3642,11 @@ cxx_set_object_constness (const constexpr_ctx *ctx, tree object, /* Subobjects might not be stored in ctx->global->values but we can get its CONSTRUCTOR by evaluating *this. */ tree e = cxx_eval_constant_expression (ctx, object, vc_prvalue, - non_constant_p, overflow_p); - if (TREE_CODE (e) == CONSTRUCTOR && !*non_constant_p) + non_constant_p, overflow_p, + jump_target); + if (!*non_constant_p + && !throws (jump_target) + && TREE_CODE (e) == CONSTRUCTOR) TREE_READONLY (e) = readonly_p; } } @@ -2906,20 +3658,25 @@ cxx_set_object_constness (const constexpr_ctx *ctx, tree object, static tree cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { location_t loc = cp_expr_loc_or_input_loc (t); tree fun = get_function_named_in_call (t); if (fun == NULL_TREE) return cxx_eval_internal_function (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); if (TREE_CODE (fun) != FUNCTION_DECL) { /* Might be a constexpr function pointer. */ fun = cxx_eval_constant_expression (ctx, fun, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; STRIP_NOPS (fun); if (TREE_CODE (fun) == ADDR_EXPR) fun = TREE_OPERAND (fun, 0); @@ -2971,9 +3728,12 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, if (fndecl_built_in_p (fun)) return cxx_eval_builtin_function_call (ctx, t, fun, - lval, non_constant_p, overflow_p); + lval, non_constant_p, overflow_p, + jump_target); if (DECL_THUNK_P (fun)) - return cxx_eval_thunk_call (ctx, t, fun, lval, non_constant_p, overflow_p); + return cxx_eval_thunk_call (ctx, t, fun, lval, non_constant_p, overflow_p, + jump_target); + bool non_constexpr_call = false; if (!maybe_constexpr_fn (fun)) { if (TREE_CODE (t) == CALL_EXPR @@ -2988,7 +3748,10 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, { tree arg = CALL_EXPR_ARG (t, i); arg = cxx_eval_constant_expression (ctx, arg, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; /* Deleting a non-constant pointer has a better error message below. */ if (new_op_p || i != 0) @@ -3103,7 +3866,10 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, { tree arg = CALL_EXPR_ARG (t, i); arg = cxx_eval_constant_expression (ctx, arg, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; if (i == 1) arg1 = arg; else @@ -3113,16 +3879,31 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, return arg1; } else if (cxx_dynamic_cast_fn_p (fun)) - return cxx_eval_dynamic_cast_fn (ctx, t, non_constant_p, overflow_p); + return cxx_eval_dynamic_cast_fn (ctx, t, non_constant_p, overflow_p, + jump_target); + else if (enum cxa_builtin kind = cxx_cxa_builtin_fn_p (fun)) + return cxx_eval_cxa_builtin_fn (ctx, t, kind, fun, + non_constant_p, overflow_p, + jump_target); - if (!ctx->quiet) + /* Calls to non-constexpr functions can be diagnosed right away + before C++26, though in C++26 evaluation of the arguments might + throw and if caught it could be still constant expression. + So for C++26 this is diagnosed only after + cxx_bind_parameters_in_call. */ + if (cxx_dialect >= cxx26) + non_constexpr_call = true; + else { - if (!lambda_static_thunk_p (fun)) - error_at (loc, "call to non-%<constexpr%> function %qD", fun); - explain_invalid_constexpr_fn (fun); + if (!ctx->quiet) + { + if (!lambda_static_thunk_p (fun)) + error_at (loc, "call to non-%<constexpr%> function %qD", fun); + explain_invalid_constexpr_fn (fun); + } + *non_constant_p = true; + return t; } - *non_constant_p = true; - return t; } constexpr_ctx new_ctx = *ctx; @@ -3158,7 +3939,8 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, constexpr_call new_call; new_call.bindings = cxx_bind_parameters_in_call (ctx, t, fun, orig_fun, non_constant_p, - overflow_p, &non_constant_args); + overflow_p, &non_constant_args, + jump_target); /* We build up the bindings list before we know whether we already have this call cached. If we don't end up saving these bindings, ggc_free them when @@ -3172,8 +3954,21 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, void preserve () { bindings = NULL; } } fb (new_call.bindings); + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; + if (non_constexpr_call) + { + if (!ctx->quiet) + { + if (!lambda_static_thunk_p (fun)) + error_at (loc, "call to non-%<constexpr%> function %qD", fun); + explain_invalid_constexpr_fn (fun); + } + *non_constant_p = true; + return t; + } /* We can't defer instantiating the function any longer. */ if (!DECL_INITIAL (fun) @@ -3246,7 +4041,9 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, new_obj = TREE_VEC_ELT (new_call.bindings, 0); bool empty_base = false; new_obj = cxx_fold_indirect_ref (ctx, loc, DECL_CONTEXT (fun), new_obj, - &empty_base); + &empty_base, jump_target); + if (*jump_target) + return NULL_TREE; /* If we're initializing an empty class, don't set constness, because cxx_fold_indirect_ref will return the wrong object to set constness of. */ @@ -3395,7 +4192,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, semantics are no longer in effect; see [class.dtor]p5. */ if (new_obj && DECL_DESTRUCTOR_P (fun)) cxx_set_object_constness (ctx, new_obj, /*readonly_p=*/false, - non_constant_p, overflow_p); + non_constant_p, overflow_p, jump_target); /* If this is a constructor, we are beginning the lifetime of the object we are initializing. */ @@ -3409,16 +4206,25 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, build_constructor (TREE_TYPE (new_obj), NULL)); cxx_eval_constant_expression (ctx, activate, - lval, non_constant_p, overflow_p); + lval, non_constant_p, overflow_p, + jump_target); ggc_free (activate); + if (*jump_target) + return NULL_TREE; } - tree jump_target = NULL_TREE; + tree jmp_target = NULL_TREE; cxx_eval_constant_expression (&call_ctx, body, vc_discard, non_constant_p, overflow_p, - &jump_target); + &jmp_target); - if (DECL_CONSTRUCTOR_P (fun)) + if (!*non_constant_p && throws (&jmp_target)) + { + result = NULL_TREE; + cacheable = false; + *jump_target = jmp_target; + } + else if (DECL_CONSTRUCTOR_P (fun)) /* This can be null for a subobject constructor call, in which case what we care about is the initialization side-effects rather than the value. We could get at the @@ -3446,7 +4252,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, marking the CONSTRUCTOR TREE_READONLY. */ if (new_obj && DECL_CONSTRUCTOR_P (fun)) cxx_set_object_constness (ctx, new_obj, /*readonly_p=*/true, - non_constant_p, overflow_p); + non_constant_p, overflow_p, jump_target); /* Remove the parms/result from the values map. */ destroy_value_checked (ctx, res, non_constant_p); @@ -3506,7 +4312,13 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, cacheable = false; result = cxx_eval_constant_expression (ctx, result, lval, non_constant_p, - overflow_p); + overflow_p, + jump_target); + if (*jump_target) + { + cacheable = false; + result = NULL_TREE; + } } } @@ -3864,12 +4676,16 @@ cxx_eval_check_shift_p (location_t loc, const constexpr_ctx *ctx, static tree cxx_eval_unary_expression (const constexpr_ctx *ctx, tree t, bool /*lval*/, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { tree r; tree orig_arg = TREE_OPERAND (t, 0); tree arg = cxx_eval_constant_expression (ctx, orig_arg, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (arg); location_t loc = EXPR_LOCATION (t); enum tree_code code = TREE_CODE (t); @@ -3893,7 +4709,7 @@ cxx_eval_unary_expression (const constexpr_ctx *ctx, tree t, static tree cxx_fold_pointer_plus_expression (const constexpr_ctx *ctx, tree t, tree lhs, tree rhs, bool *non_constant_p, - bool *overflow_p) + bool *overflow_p, tree *jump_target) { STRIP_NOPS (lhs); if (TREE_CODE (lhs) != ADDR_EXPR) @@ -3915,9 +4731,12 @@ cxx_fold_pointer_plus_expression (const constexpr_ctx *ctx, tree t, t = fold_convert_loc (loc, ssizetype, TREE_OPERAND (lhs, 1)); tree nelts = array_type_nelts_top (TREE_TYPE (TREE_OPERAND (lhs, 0))); nelts = cxx_eval_constant_expression (ctx, nelts, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); if (*non_constant_p) return NULL_TREE; + if (*jump_target) + return NULL_TREE; /* Don't fold an out-of-bound access. */ if (!tree_int_cst_le (t, nelts)) return NULL_TREE; @@ -3937,7 +4756,8 @@ cxx_fold_pointer_plus_expression (const constexpr_ctx *ctx, tree t, t = cp_build_addr_expr (t, tf_warning_or_error); t = cp_fold_convert (orig_type, t); return cxx_eval_constant_expression (ctx, t, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); } return NULL_TREE; @@ -3981,22 +4801,29 @@ cxx_maybe_fold_addr_pointer_plus (tree t) static tree cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { tree r = NULL_TREE; tree orig_lhs = TREE_OPERAND (t, 0); tree orig_rhs = TREE_OPERAND (t, 1); tree lhs, rhs; lhs = cxx_eval_constant_expression (ctx, orig_lhs, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); /* Don't VERIFY_CONSTANT here, it's unnecessary and will break pointer subtraction. */ if (*non_constant_p) return t; + if (*jump_target) + return NULL_TREE; rhs = cxx_eval_constant_expression (ctx, orig_rhs, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); if (*non_constant_p) return t; + if (*jump_target) + return NULL_TREE; location_t loc = EXPR_LOCATION (t); enum tree_code code = TREE_CODE (t); @@ -4052,13 +4879,17 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t, return t; } else if (code == POINTER_PLUS_EXPR) - r = cxx_fold_pointer_plus_expression (ctx, t, lhs, rhs, non_constant_p, - overflow_p); + { + r = cxx_fold_pointer_plus_expression (ctx, t, lhs, rhs, non_constant_p, + overflow_p, jump_target); + if (*jump_target) + return NULL_TREE; + } else if (code == SPACESHIP_EXPR) { r = genericize_spaceship (loc, type, lhs, rhs); return cxx_eval_constant_expression (ctx, r, lval, non_constant_p, - overflow_p); + overflow_p, jump_target); } if (r == NULL_TREE) @@ -4117,7 +4948,10 @@ cxx_eval_conditional_expression (const constexpr_ctx *ctx, tree t, { tree val = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (val); if (TREE_CODE (t) == IF_STMT && IF_STMT_CONSTEVAL_P (t)) { @@ -4178,19 +5012,29 @@ cxx_eval_conditional_expression (const constexpr_ctx *ctx, tree t, static tree cxx_eval_vector_conditional_expression (const constexpr_ctx *ctx, tree t, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { tree arg1 = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (arg1); tree arg2 = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1), vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (arg2); tree arg3 = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 2), vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (arg3); location_t loc = EXPR_LOCATION (t); tree type = TREE_TYPE (t); @@ -4578,7 +5422,8 @@ diag_array_subscript (location_t loc, const constexpr_ctx *ctx, tree array, tree static tree get_array_or_vector_nelts (const constexpr_ctx *ctx, tree type, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { tree nelts; if (TREE_CODE (type) == ARRAY_TYPE) @@ -4595,7 +5440,8 @@ get_array_or_vector_nelts (const constexpr_ctx *ctx, tree type, /* For VLAs, the number of elements won't be an integer constant. */ nelts = cxx_eval_constant_expression (ctx, nelts, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); return nelts; } @@ -4626,13 +5472,17 @@ extract_string_elt (tree string, unsigned chars_per_elt, unsigned index) static tree eval_and_check_array_index (const constexpr_ctx *ctx, tree t, bool allow_one_past, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { location_t loc = cp_expr_loc_or_input_loc (t); tree ary = TREE_OPERAND (t, 0); t = TREE_OPERAND (t, 1); tree index = cxx_eval_constant_expression (ctx, t, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (index); if (!tree_fits_shwi_p (index) @@ -4644,7 +5494,9 @@ eval_and_check_array_index (const constexpr_ctx *ctx, } tree nelts = get_array_or_vector_nelts (ctx, TREE_TYPE (ary), non_constant_p, - overflow_p); + overflow_p, jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (nelts); if (allow_one_past ? !tree_int_cst_le (index, nelts) @@ -4664,14 +5516,18 @@ eval_and_check_array_index (const constexpr_ctx *ctx, static tree cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { tree oldary = TREE_OPERAND (t, 0); tree ary = cxx_eval_constant_expression (ctx, oldary, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); if (*non_constant_p) return t; + if (*jump_target) + return NULL_TREE; if (!lval && TREE_CODE (ary) == VIEW_CONVERT_EXPR && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (ary, 0))) @@ -4681,9 +5537,12 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, tree oldidx = TREE_OPERAND (t, 1); tree index = eval_and_check_array_index (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); if (*non_constant_p) return t; + if (*jump_target) + return NULL_TREE; if (lval && ary == oldary && index == oldidx) return t; @@ -4801,7 +5660,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, ctx = &new_ctx; } t = cxx_eval_constant_expression (ctx, val, lval, non_constant_p, - overflow_p); + overflow_p, jump_target); if (new_ctor && t != ctx->ctor) free_constructor (ctx->ctor); return t; @@ -4813,7 +5672,8 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, static tree cxx_eval_component_reference (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { unsigned HOST_WIDE_INT i; tree field; @@ -4822,9 +5682,12 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t, tree orig_whole = TREE_OPERAND (t, 0); tree whole = cxx_eval_constant_expression (ctx, orig_whole, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); if (*non_constant_p) return t; + if (*jump_target) + return NULL_TREE; if (INDIRECT_REF_P (whole) && integer_zerop (TREE_OPERAND (whole, 0))) { @@ -4933,7 +5796,8 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t, value = build_value_init (TREE_TYPE (t), tf_warning_or_error); return cxx_eval_constant_expression (ctx, value, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); } /* Subroutine of cxx_eval_constant_expression. @@ -4943,7 +5807,8 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t, static tree cxx_eval_bit_field_ref (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { tree orig_whole = TREE_OPERAND (t, 0); tree retval, fldval, utype, mask; @@ -4951,10 +5816,13 @@ cxx_eval_bit_field_ref (const constexpr_ctx *ctx, tree t, HOST_WIDE_INT istart, isize; tree whole = cxx_eval_constant_expression (ctx, orig_whole, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); tree start, field, value; unsigned HOST_WIDE_INT i; + if (*jump_target) + return NULL_TREE; if (whole == orig_whole) return t; /* Don't VERIFY_CONSTANT here; we only want to check that we got a @@ -5235,7 +6103,7 @@ clear_uchar_or_std_byte_in_mask (location_t loc, tree t, unsigned char *mask) static tree cxx_eval_bit_cast (const constexpr_ctx *ctx, tree t, bool *non_constant_p, - bool *overflow_p) + bool *overflow_p, tree *jump_target) { if (check_bit_cast_type (ctx, EXPR_LOCATION (t), TREE_TYPE (t), TREE_TYPE (t)) @@ -5249,9 +6117,12 @@ cxx_eval_bit_cast (const constexpr_ctx *ctx, tree t, bool *non_constant_p, } tree op = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); if (*non_constant_p) return t; + if (*jump_target) + return NULL_TREE; location_t loc = EXPR_LOCATION (t); if (BITS_PER_UNIT != 8 || CHAR_BIT != 8) @@ -5329,8 +6200,9 @@ cxx_eval_bit_cast (const constexpr_ctx *ctx, tree t, bool *non_constant_p, if (CHECKING_P) { tree e = cxx_eval_bare_aggregate (ctx, r, vc_prvalue, - non_constant_p, overflow_p); - gcc_checking_assert (e == r); + non_constant_p, overflow_p, + jump_target); + gcc_checking_assert (e == r && !*jump_target); r = e; } } @@ -5371,19 +6243,24 @@ cxx_eval_bit_cast (const constexpr_ctx *ctx, tree t, bool *non_constant_p, static tree cxx_eval_logical_expression (const constexpr_ctx *ctx, tree t, tree bailout_value, tree continue_value, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { tree r; tree lhs = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), vc_prvalue, non_constant_p, - overflow_p); + overflow_p, jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (lhs); if (tree_int_cst_equal (lhs, bailout_value)) return lhs; gcc_assert (tree_int_cst_equal (lhs, continue_value)); r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1), vc_prvalue, non_constant_p, - overflow_p); + overflow_p, jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (r); return r; } @@ -5540,7 +6417,8 @@ verify_ctor_sanity (const constexpr_ctx *ctx, tree type) static tree cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t); bool changed = false; @@ -5593,7 +6471,10 @@ cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, get_or_insert_ctor_field (ctx->ctor, index); tree elt = cxx_eval_constant_expression (&new_ctx, value, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; /* Don't VERIFY_CONSTANT here. */ if (ctx->quiet && *non_constant_p) break; @@ -5683,7 +6564,8 @@ cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, static tree cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, bool value_init, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { tree elttype = TREE_TYPE (atype); verify_ctor_sanity (ctx, atype); @@ -5694,7 +6576,7 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, if (init && TREE_CODE (init) == CONSTRUCTOR) return cxx_eval_bare_aggregate (ctx, init, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, jump_target); /* For the default constructor, build up a call to the default constructor of the element type. We only need to handle class types @@ -5731,7 +6613,9 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, } tree nelts = get_array_or_vector_nelts (ctx, atype, non_constant_p, - overflow_p); + overflow_p, jump_target); + if (*jump_target) + return NULL_TREE; unsigned HOST_WIDE_INT max = tree_to_uhwi (nelts); for (i = 0; i < max; ++i) { @@ -5757,9 +6641,9 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, } else eltinit = cp_build_array_ref (input_location, init, idx, complain); - eltinit = cxx_eval_vec_init_1 (&new_ctx, elttype, eltinit, value_init, - lval, - non_constant_p, overflow_p); + eltinit = cxx_eval_vec_init_1 (&new_ctx, elttype, eltinit, + value_init, lval, non_constant_p, + overflow_p, jump_target); } else if (pre_init) { @@ -5773,7 +6657,8 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, /* Clarify what object is being initialized (118285). */ eltinit = build2 (INIT_EXPR, elttype, new_ctx.object, eltinit); eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); reuse = i == 0; } else @@ -5789,8 +6674,11 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, /* Clarify what object is being initialized (118285). */ eltinit = build2 (INIT_EXPR, elttype, new_ctx.object, eltinit); eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); } + if (*jump_target) + return NULL_TREE; if (*non_constant_p) break; if (no_slot) @@ -5840,7 +6728,7 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, static tree cxx_eval_vec_init (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, tree *jump_target) { tree atype = TREE_TYPE (t); tree init = VEC_INIT_EXPR_INIT (t); @@ -5872,10 +6760,10 @@ cxx_eval_vec_init (const constexpr_ctx *ctx, tree t, } init = expand_vec_init_expr (ctx->object, t, complain); return cxx_eval_constant_expression (ctx, init, lval, non_constant_p, - overflow_p); + overflow_p, jump_target); } tree r = cxx_eval_vec_init_1 (ctx, atype, init, value_init, - lval, non_constant_p, overflow_p); + lval, non_constant_p, overflow_p, jump_target); if (*non_constant_p) return t; else @@ -5904,14 +6792,16 @@ same_type_ignoring_tlq_and_bounds_p (tree type1, tree type2) otherwise return NULL_TREE. */ static tree -cxx_union_active_member (const constexpr_ctx *ctx, tree t) +cxx_union_active_member (const constexpr_ctx *ctx, tree t, tree *jump_target) { constexpr_ctx new_ctx = *ctx; new_ctx.quiet = true; bool non_constant_p = false, overflow_p = false; tree ctor = cxx_eval_constant_expression (&new_ctx, t, vc_prvalue, &non_constant_p, - &overflow_p); + &overflow_p, jump_target); + if (*jump_target) + return NULL_TREE; if (TREE_CODE (ctor) == CONSTRUCTOR && CONSTRUCTOR_NELTS (ctor) == 1 && CONSTRUCTOR_ELT (ctor, 0)->index @@ -5924,7 +6814,8 @@ cxx_union_active_member (const constexpr_ctx *ctx, tree t) static tree cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, - tree op, unsigned HOST_WIDE_INT off, bool *empty_base) + tree op, unsigned HOST_WIDE_INT off, bool *empty_base, + tree *jump_target) { tree optype = TREE_TYPE (op); unsigned HOST_WIDE_INT const_nunits; @@ -5941,7 +6832,8 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, than pointer type. */ if (tree ret = cxx_fold_indirect_ref_1 (ctx, loc, strip_array_types (optype), - op, off, empty_base)) + op, off, empty_base, + jump_target)) return fold_convert (type, ret); } else if (TREE_CODE (optype) == COMPLEX_TYPE @@ -5987,7 +6879,7 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, op = build4_loc (loc, ARRAY_REF, TREE_TYPE (optype), op, index, NULL_TREE, NULL_TREE); return cxx_fold_indirect_ref_1 (ctx, loc, type, op, rem, - empty_base); + empty_base, jump_target); } } /* ((foo *)&struct_with_foo_field)[x] => COMPONENT_REF */ @@ -5996,7 +6888,7 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, { if (TREE_CODE (optype) == UNION_TYPE) /* For unions prefer the currently active member. */ - if (tree field = cxx_union_active_member (ctx, op)) + if (tree field = cxx_union_active_member (ctx, op, jump_target)) { unsigned HOST_WIDE_INT el_sz = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (field))); @@ -6005,7 +6897,8 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, tree cop = build3 (COMPONENT_REF, TREE_TYPE (field), op, field, NULL_TREE); if (tree ret = cxx_fold_indirect_ref_1 (ctx, loc, type, cop, - off, empty_base)) + off, empty_base, + jump_target)) return ret; } } @@ -6050,7 +6943,8 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, op, field, NULL_TREE); if (tree ret = cxx_fold_indirect_ref_1 (ctx, loc, type, cop, off - upos, - empty_base)) + empty_base, + jump_target)) return ret; } } @@ -6070,7 +6964,7 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, static tree cxx_fold_indirect_ref (const constexpr_ctx *ctx, location_t loc, tree type, - tree op0, bool *empty_base /* = NULL*/) + tree op0, bool *empty_base, tree *jump_target) { tree sub = op0; tree subtype; @@ -6152,7 +7046,8 @@ cxx_fold_indirect_ref (const constexpr_ctx *ctx, location_t loc, tree type, tree off = integer_zero_node; canonicalize_obj_off (op, off); return cxx_fold_indirect_ref_1 (ctx, loc, type, op, - tree_to_uhwi (off), empty_base); + tree_to_uhwi (off), empty_base, + jump_target); } } else if (TREE_CODE (sub) == POINTER_PLUS_EXPR @@ -6167,7 +7062,8 @@ cxx_fold_indirect_ref (const constexpr_ctx *ctx, location_t loc, tree type, tree obj = TREE_OPERAND (op00, 0); canonicalize_obj_off (obj, off); return cxx_fold_indirect_ref_1 (ctx, loc, type, obj, - tree_to_uhwi (off), empty_base); + tree_to_uhwi (off), empty_base, + jump_target); } } /* *(foo *)fooarrptr => (*fooarrptr)[0] */ @@ -6177,7 +7073,10 @@ cxx_fold_indirect_ref (const constexpr_ctx *ctx, location_t loc, tree type, tree type_domain; tree min_val = size_zero_node; tree newsub - = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (subtype), sub, NULL); + = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (subtype), sub, NULL, + jump_target); + if (*jump_target) + return NULL_TREE; if (newsub) sub = newsub; else @@ -6195,7 +7094,8 @@ cxx_fold_indirect_ref (const constexpr_ctx *ctx, location_t loc, tree type, static tree cxx_eval_indirect_ref (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { tree orig_op0 = TREE_OPERAND (t, 0); bool empty_base = false; @@ -6213,13 +7113,17 @@ cxx_eval_indirect_ref (const constexpr_ctx *ctx, tree t, /* First try to simplify it directly. */ tree r = cxx_fold_indirect_ref (ctx, EXPR_LOCATION (t), TREE_TYPE (t), - orig_op0, &empty_base); + orig_op0, &empty_base, jump_target); + if (*jump_target) + return NULL_TREE; if (!r) { /* If that didn't work, evaluate the operand first. */ tree op0 = cxx_eval_constant_expression (ctx, orig_op0, vc_prvalue, non_constant_p, - overflow_p); + overflow_p, jump_target); + if (*jump_target) + return NULL_TREE; /* Don't VERIFY_CONSTANT here. */ if (*non_constant_p) return t; @@ -6233,7 +7137,9 @@ cxx_eval_indirect_ref (const constexpr_ctx *ctx, tree t, } r = cxx_fold_indirect_ref (ctx, EXPR_LOCATION (t), TREE_TYPE (t), op0, - &empty_base); + &empty_base, jump_target); + if (*jump_target) + return NULL_TREE; if (r == NULL_TREE) { /* We couldn't fold to a constant value. Make sure it's not @@ -6263,7 +7169,10 @@ cxx_eval_indirect_ref (const constexpr_ctx *ctx, tree t, } r = cxx_eval_constant_expression (ctx, r, - lval, non_constant_p, overflow_p); + lval, non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; @@ -6373,7 +7282,8 @@ non_const_var_error (location_t loc, tree r, bool fundef_p) static tree cxx_eval_trinary_expression (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { int i; tree args[3]; @@ -6383,7 +7293,10 @@ cxx_eval_trinary_expression (const constexpr_ctx *ctx, tree t, { args[i] = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, i), lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (args[i]); } @@ -6505,7 +7418,8 @@ modifying_const_object_p (tree_code code, tree obj, bool mutable_p) static tree cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { constexpr_ctx new_ctx = *ctx; @@ -6531,7 +7445,10 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, if (!SCALAR_TYPE_P (type)) new_ctx.ctor = new_ctx.object = NULL_TREE; init = cxx_eval_constant_expression (&new_ctx, init, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; } @@ -6543,8 +7460,11 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, as a whole; otherwise, only evaluate the innermost piece to avoid building up unnecessary *_REFs. */ target = cxx_eval_constant_expression (ctx, target, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); evaluated = true; + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; } @@ -6570,7 +7490,10 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, if (TREE_CODE (probe) == ARRAY_REF) { elt = eval_and_check_array_index (ctx, probe, false, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; } @@ -6627,8 +7550,11 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, break; } probe = cxx_eval_constant_expression (ctx, probe, vc_glvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); evaluated = true; + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; } @@ -6972,7 +7898,10 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, if (tree tinit = TARGET_EXPR_INITIAL (init)) init = tinit; init = cxx_eval_constant_expression (&new_ctx, init, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; /* The hash table might have moved since the get earlier, and the initializer might have mutated the underlying CONSTRUCTORs, so we must recompute VALP. */ @@ -7098,7 +8027,8 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, static tree cxx_eval_increment_expression (const constexpr_ctx *ctx, tree t, value_cat lval, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { enum tree_code code = TREE_CODE (t); tree type = TREE_TYPE (t); @@ -7112,12 +8042,18 @@ cxx_eval_increment_expression (const constexpr_ctx *ctx, tree t, /* The operand as an lvalue. */ op = cxx_eval_constant_expression (ctx, op, vc_glvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; /* The operand as an rvalue. */ tree val = cxx_eval_constant_expression (ctx, op, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; /* Don't VERIFY_CONSTANT if this might be dealing with a pointer to a local array in a constexpr function. */ bool ptr = INDIRECT_TYPE_P (TREE_TYPE (val)); @@ -7156,8 +8092,11 @@ cxx_eval_increment_expression (const constexpr_ctx *ctx, tree t, tree store = build2_loc (cp_expr_loc_or_loc (t, input_location), MODIFY_EXPR, type, op, mod); mod = cxx_eval_constant_expression (ctx, store, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); ggc_free (store); + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; @@ -7171,42 +8110,6 @@ cxx_eval_increment_expression (const constexpr_ctx *ctx, tree t, return val; } -/* Predicates for the meaning of *jump_target. */ - -static bool -returns (tree *jump_target) -{ - return *jump_target - && TREE_CODE (*jump_target) == RETURN_EXPR; -} - -static bool -breaks (tree *jump_target) -{ - return *jump_target - && ((TREE_CODE (*jump_target) == LABEL_DECL - && LABEL_DECL_BREAK (*jump_target)) - || TREE_CODE (*jump_target) == BREAK_STMT - || TREE_CODE (*jump_target) == EXIT_EXPR); -} - -static bool -continues (tree *jump_target) -{ - return *jump_target - && ((TREE_CODE (*jump_target) == LABEL_DECL - && LABEL_DECL_CONTINUE (*jump_target)) - || TREE_CODE (*jump_target) == CONTINUE_STMT); - -} - -static bool -switches (tree *jump_target) -{ - return *jump_target - && TREE_CODE (*jump_target) == INTEGER_CST; -} - /* Subroutine of cxx_eval_statement_list. Determine whether the statement STMT matches *jump_target. If we're looking for a case label and we see the default label, note it in ctx->css_state. */ @@ -7254,6 +8157,11 @@ label_matches (const constexpr_ctx *ctx, tree *jump_target, tree stmt) breaks (jump_target) or continues (jump_target). */ break; + case VAR_DECL: + /* Uncaught exception. This is handled by TRY_BLOCK evaluation + and other places by testing throws (jump_target). */ + break; + default: gcc_unreachable (); } @@ -7268,15 +8176,9 @@ cxx_eval_statement_list (const constexpr_ctx *ctx, tree t, bool *non_constant_p, bool *overflow_p, tree *jump_target) { - tree local_target; /* In a statement-expression we want to return the last value. For empty statement expression return void_node. */ tree r = void_node; - if (!jump_target) - { - local_target = NULL_TREE; - jump_target = &local_target; - } for (tree_stmt_iterator i = tsi_start (t); !tsi_end_p (i); ++i) { tree stmt = *i; @@ -7304,18 +8206,11 @@ cxx_eval_statement_list (const constexpr_ctx *ctx, tree t, jump_target); if (*non_constant_p) break; - if (returns (jump_target) || breaks (jump_target)) + if (returns (jump_target) + || breaks (jump_target) + || throws (jump_target)) break; } - if (*jump_target && jump_target == &local_target) - { - /* We aren't communicating the jump to our caller, so give up. We don't - need to support evaluation of jumps out of statement-exprs. */ - if (!ctx->quiet) - error_at (cp_expr_loc_or_input_loc (r), - "statement is not a constant expression"); - *non_constant_p = true; - } return r; } @@ -7327,13 +8222,6 @@ cxx_eval_loop_expr (const constexpr_ctx *ctx, tree t, bool *non_constant_p, bool *overflow_p, tree *jump_target) { - tree local_target; - if (!jump_target) - { - local_target = NULL_TREE; - jump_target = &local_target; - } - tree body, cond = NULL_TREE, expr = NULL_TREE; tree cond_prep = NULL_TREE, cond_cleanup = NULL_TREE; unsigned cond_cleanup_depth = 0; @@ -7389,7 +8277,7 @@ cxx_eval_loop_expr (const constexpr_ctx *ctx, tree t, tree c; FOR_EACH_VEC_ELT_REVERSE (cleanups, i, c) cxx_eval_constant_expression (ctx, c, vc_discard, non_constant_p, - overflow_p); + overflow_p, jump_target); } if (cond_prep) for (tree decl = BIND_EXPR_VARS (cond_prep); @@ -7484,7 +8372,8 @@ cxx_eval_loop_expr (const constexpr_ctx *ctx, tree t, if (*non_constant_p || returns (jump_target) || breaks (jump_target) - || continues (jump_target)) + || continues (jump_target) + || throws (jump_target)) { depth = 1; break; @@ -7531,6 +8420,7 @@ cxx_eval_loop_expr (const constexpr_ctx *ctx, tree t, && !breaks (jump_target) && !continues (jump_target) && (!switches (jump_target) || count == 0) + && !throws (jump_target) && !*non_constant_p); cleanup_cond (); @@ -7549,7 +8439,10 @@ cxx_eval_switch_expr (const constexpr_ctx *ctx, tree t, tree cond = TREE_CODE (t) == SWITCH_STMT ? SWITCH_STMT_COND (t) : SWITCH_COND (t); cond = cxx_eval_constant_expression (ctx, cond, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (cond); if (TREE_CODE (cond) != INTEGER_CST) { @@ -7682,7 +8575,8 @@ maybe_warn_about_constant_value (location_t loc, tree decl) static tree build_new_constexpr_heap_type (const constexpr_ctx *ctx, tree elt_type, tree cookie_size, tree full_size, tree arg_size, - bool *non_constant_p, bool *overflow_p) + bool *non_constant_p, bool *overflow_p, + tree *jump_target) { gcc_assert (cookie_size == NULL_TREE || tree_fits_uhwi_p (cookie_size)); gcc_assert (tree_fits_uhwi_p (full_size)); @@ -7718,13 +8612,17 @@ build_new_constexpr_heap_type (const constexpr_ctx *ctx, tree elt_type, if (integer_zerop (op0)) arg_size = cxx_eval_constant_expression (ctx, op1, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); else if (integer_zerop (op1)) arg_size = cxx_eval_constant_expression (ctx, op0, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); else arg_size = NULL_TREE; + if (*jump_target) + return NULL_TREE; } else arg_size = NULL_TREE; @@ -7745,6 +8643,38 @@ build_new_constexpr_heap_type (const constexpr_ctx *ctx, tree elt_type, return build_new_constexpr_heap_type (elt_type, cookie_size, itype2); } +/* Handle the case when a cleanup of some expression throws. JMP_TARGET + indicates whether the cleanup threw or not, *JUMP_TARGET indicates whether + the expression which needed the cleanup threw. If both threw, diagnose + it and return NULL, otherwise return R. If only the cleanup threw, set + *JUMP_TARGET to the exception object from the cleanup. */ + +static tree +merge_jump_target (location_t loc, const constexpr_ctx *ctx, tree r, + bool *non_constant_p, tree *jump_target, tree jmp_target) +{ + if (!throws (&jmp_target)) + return r; + if (throws (jump_target)) + { + /* [except.throw]/9 - If the exception handling mechanism + handling an uncaught exception directly invokes a function + that exits via an exception, the function std::terminate is + invoked. */ + if (!ctx->quiet) + { + auto_diagnostic_group d; + diagnose_std_terminate (loc, ctx, *jump_target); + inform (loc, "destructor exited with an exception"); + } + *non_constant_p = true; + *jump_target = NULL_TREE; + return NULL_TREE; + } + *jump_target = jmp_target; + return r; +} + /* Attempt to reduce the expression T to a constant value. On failure, issue diagnostic and return error_mark_node. */ /* FIXME unify with c_fully_fold */ @@ -7754,9 +8684,9 @@ static tree cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, value_cat lval, bool *non_constant_p, bool *overflow_p, - tree *jump_target /* = NULL */) + tree *jump_target) { - if (jump_target && *jump_target) + if (*jump_target) { /* If we are jumping, ignore all statements/expressions except those that could have LABEL_EXPR or CASE_LABEL_EXPR in their bodies. */ @@ -7880,7 +8810,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, r = convert_from_reference (r); } return cxx_eval_constant_expression (ctx, r, lval, non_constant_p, - overflow_p); + overflow_p, jump_target); } /* fall through */ case CONST_DECL: @@ -7958,7 +8888,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, r = v; if (TREE_ADDRESSABLE (TREE_TYPE (t))) r = cxx_eval_constant_expression (ctx, r, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; } else if (lval) /* Defer in case this is only used for its type. */; @@ -7991,7 +8924,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, case CALL_EXPR: case AGGR_INIT_EXPR: r = cxx_eval_call_expression (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, jump_target); break; case DECL_EXPR: @@ -8055,7 +8988,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, if (tree init = DECL_INITIAL (r)) { init = cxx_eval_constant_expression (ctx, init, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; /* Don't share a CONSTRUCTOR that might be changed. */ init = unshare_constructor (init); /* Remember that a constant object's constructor has already @@ -8125,9 +9061,12 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, /* Pass vc_prvalue because this indicates initialization of a temporary. */ r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1), vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); if (*non_constant_p) break; + if (*jump_target) + return NULL_TREE; if (!is_complex) { r = unshare_constructor (r); @@ -8135,8 +9074,15 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, r = adjust_temp_type (type, r); ctx->global->put_value (slot, r); } - if (TARGET_EXPR_CLEANUP (t) && !CLEANUP_EH_ONLY (t)) - ctx->global->cleanups->safe_push (TARGET_EXPR_CLEANUP (t)); + if (TARGET_EXPR_CLEANUP (t) + && (!CLEANUP_EH_ONLY (t) || cxx_dialect >= cxx26)) + { + ctx->global->cleanups->safe_push (TARGET_EXPR_CLEANUP (t)); + /* Mark CLEANUP_EH_ONLY cleanups by pushing NULL_TREE after + them. */ + if (CLEANUP_EH_ONLY (t)) + ctx->global->cleanups->safe_push (NULL_TREE); + } if (ctx->save_exprs) ctx->save_exprs->safe_push (slot); if (lval) @@ -8150,33 +9096,28 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, case MODIFY_EXPR: gcc_assert (jump_target == NULL || *jump_target == NULL_TREE); r = cxx_eval_store_expression (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, jump_target); break; case SCOPE_REF: r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1), lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case RETURN_EXPR: if (TREE_OPERAND (t, 0) != NULL_TREE) r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, - non_constant_p, overflow_p); - /* FALLTHRU */ + non_constant_p, overflow_p, + jump_target); + if (!throws (jump_target)) + *jump_target = t; + break; case BREAK_STMT: case CONTINUE_STMT: - if (jump_target) - *jump_target = t; - else - { - /* Can happen with ({ return true; }) && false; passed to - maybe_constant_value. There is nothing to jump over in this - case, and the bug will be diagnosed later. */ - gcc_assert (ctx->quiet); - *non_constant_p = true; - } + *jump_target = t; break; case SAVE_EXPR: @@ -8185,9 +9126,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, r = v; else { - r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), vc_prvalue, - non_constant_p, overflow_p); - if (*non_constant_p) + r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), + vc_prvalue, non_constant_p, + overflow_p, jump_target); + if (*non_constant_p || *jump_target) break; ctx->global->put_value (t, r); if (ctx->save_exprs) @@ -8195,16 +9137,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, } break; - case TRY_CATCH_EXPR: - if (TREE_OPERAND (t, 0) == NULL_TREE) - { - r = void_node; - break; - } - /* FALLTHRU */ case NON_LVALUE_EXPR: - case TRY_BLOCK: - case MUST_NOT_THROW_EXPR: case EXPR_STMT: case EH_SPEC_BLOCK: r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), @@ -8213,6 +9146,42 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, jump_target); break; + case TRY_BLOCK: + r = cxx_eval_constant_expression (ctx, TRY_STMTS (t), lval, + non_constant_p, overflow_p, + jump_target); + if (!*non_constant_p && throws (jump_target)) + if (tree h = TRY_HANDLERS (t)) + { + tree type = strip_array_types (TREE_TYPE (*jump_target)); + if (TREE_CODE (h) == STATEMENT_LIST) + { + for (tree stmt : tsi_range (h)) + if (TREE_CODE (stmt) == HANDLER + && handler_match_for_exception_type (stmt, type)) + { + h = stmt; + break; + } + if (TREE_CODE (h) == STATEMENT_LIST) + h = NULL_TREE; + } + else if (TREE_CODE (h) != HANDLER + || !handler_match_for_exception_type (h, type)) + h = NULL_TREE; + if (h) + { + gcc_assert (VAR_P (*jump_target)); + ctx->global->caught_exceptions.safe_push (*jump_target); + ctx->global->caught_exceptions.safe_push (HANDLER_TYPE (h)); + *jump_target = NULL_TREE; + r = cxx_eval_constant_expression (ctx, HANDLER_BODY (h), + vc_discard, non_constant_p, + overflow_p, jump_target); + } + } + break; + case CLEANUP_POINT_EXPR: { auto_vec<tree, 2> cleanups; @@ -8230,47 +9199,132 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, ctx->global->cleanups = prev_cleanups; unsigned int i; - tree cleanup; + tree cleanup, jmp_target = NULL_TREE; + bool eh = throws (jump_target); /* Evaluate the cleanups. */ FOR_EACH_VEC_ELT_REVERSE (cleanups, i, cleanup) - cxx_eval_constant_expression (&new_ctx, cleanup, vc_discard, - non_constant_p, overflow_p); + if (cleanup == NULL_TREE) + { + /* NULL_TREE cleanup is a marker that before it is + CLEANUP_EH_ONLY cleanup. Skip the cleanup before it + if the body didn't throw. */ + if (!eh) + --i; + } + else + cxx_eval_constant_expression (&new_ctx, cleanup, vc_discard, + non_constant_p, overflow_p, + &jmp_target); /* Forget SAVE_EXPRs and TARGET_EXPRs created by this full-expression. */ for (tree save_expr : save_exprs) destroy_value_checked (ctx, save_expr, non_constant_p); + if (throws (&jmp_target)) + *jump_target = jmp_target; } break; + case MUST_NOT_THROW_EXPR: + r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), + lval, + non_constant_p, overflow_p, + jump_target); + if (throws (jump_target)) + { + /* [except.handle]/7 - If the search for a handler exits the + function body of a function with a non-throwing exception + specification, the function std::terminate is invoked. */ + if (!ctx->quiet) + { + auto_diagnostic_group d; + diagnose_std_terminate (loc, ctx, *jump_target); + if (MUST_NOT_THROW_NOEXCEPT_P (t) + && ctx->call + && ctx->call->fundef) + inform (loc, "uncaught exception exited from %<noexcept%> " + "function %qD", + ctx->call->fundef->decl); + else if (MUST_NOT_THROW_THROW_P (t)) + inform (loc, "destructor exited with an exception after " + "initializing the exception object"); + else if (MUST_NOT_THROW_CATCH_P (t)) + inform (loc, "constructor exited with another exception while " + "entering handler"); + } + *non_constant_p = true; + *jump_target = NULL_TREE; + r = NULL_TREE; + } + break; + + case TRY_CATCH_EXPR: + if (TREE_OPERAND (t, 0) == NULL_TREE) + { + r = void_node; + break; + } + r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p, + jump_target); + if (!*non_constant_p && throws (jump_target)) + { + tree jmp_target = NULL_TREE; + cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1), vc_discard, + non_constant_p, overflow_p, + &jmp_target); + r = merge_jump_target (loc, ctx, r, non_constant_p, jump_target, + jmp_target); + } + break; + case TRY_FINALLY_EXPR: r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, non_constant_p, overflow_p, jump_target); if (!*non_constant_p) - /* Also evaluate the cleanup. */ - cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1), vc_discard, - non_constant_p, overflow_p); + { + tree jmp_target = NULL_TREE; + /* Also evaluate the cleanup. */ + if (TREE_CODE (TREE_OPERAND (t, 1)) == EH_ELSE_EXPR + && throws (jump_target)) + cxx_eval_constant_expression (ctx, + TREE_OPERAND (TREE_OPERAND (t, 1), + 1), vc_discard, + non_constant_p, overflow_p, + &jmp_target); + else + cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 1), vc_discard, + non_constant_p, overflow_p, + &jmp_target); + r = merge_jump_target (loc, ctx, r, non_constant_p, jump_target, + jmp_target); + } break; case EH_ELSE_EXPR: /* Evaluate any cleanup that applies to non-EH exits. */ cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), vc_discard, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); - /* We do not have constexpr exceptions yet, so skip the EH path. */ + /* The EH path is handled in TRY_FINALLY_EXPR handling above. */ break; case CLEANUP_STMT: r = cxx_eval_constant_expression (ctx, CLEANUP_BODY (t), lval, non_constant_p, overflow_p, jump_target); - if (!CLEANUP_EH_ONLY (t) && !*non_constant_p) + if ((!CLEANUP_EH_ONLY (t) || throws (jump_target)) && !*non_constant_p) { iloc_sentinel ils (loc); + tree jmp_target = NULL_TREE; /* Also evaluate the cleanup. */ cxx_eval_constant_expression (ctx, CLEANUP_EXPR (t), vc_discard, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + &jmp_target); + r = merge_jump_target (loc, ctx, r, non_constant_p, jump_target, + jmp_target); } break; @@ -8280,14 +9334,18 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, case MEM_REF: case INDIRECT_REF: r = cxx_eval_indirect_ref (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case ADDR_EXPR: { tree oldop = TREE_OPERAND (t, 0); tree op = cxx_eval_constant_expression (ctx, oldop, vc_glvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; /* Don't VERIFY_CONSTANT here. */ if (*non_constant_p) return t; @@ -8307,7 +9365,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, if (lval) { r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; if (r == error_mark_node) ; else if (r == TREE_OPERAND (t, 0) || lval == vc_discard) @@ -8328,7 +9389,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, case FIXED_CONVERT_EXPR: case VEC_DUPLICATE_EXPR: r = cxx_eval_unary_expression (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case SIZEOF_EXPR: @@ -8366,6 +9428,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, cxx_eval_constant_expression (ctx, op0, vc_discard, non_constant_p, overflow_p, jump_target); + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; op1 = TREE_OPERAND (t, 1); @@ -8418,7 +9482,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, case RANGE_EXPR: case COMPLEX_EXPR: r = cxx_eval_binary_expression (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; /* fold can introduce non-IF versions of these; still treat them as @@ -8427,19 +9492,22 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, case TRUTH_ANDIF_EXPR: r = cxx_eval_logical_expression (ctx, t, boolean_false_node, boolean_true_node, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case TRUTH_OR_EXPR: case TRUTH_ORIF_EXPR: r = cxx_eval_logical_expression (ctx, t, boolean_true_node, boolean_false_node, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case ARRAY_REF: r = cxx_eval_array_reference (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case COMPONENT_REF: @@ -8454,17 +9522,19 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, return t; } r = cxx_eval_component_reference (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case BIT_FIELD_REF: r = cxx_eval_bit_field_ref (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case COND_EXPR: case IF_STMT: - if (jump_target && *jump_target) + if (*jump_target) { tree orig_jump = *jump_target; tree arg = ((TREE_CODE (t) != IF_STMT || TREE_OPERAND (t, 1)) @@ -8502,7 +9572,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, break; case VEC_COND_EXPR: r = cxx_eval_vector_conditional_expression (ctx, t, non_constant_p, - overflow_p); + overflow_p, jump_target); break; case CONSTRUCTOR: @@ -8514,7 +9584,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, return t; } r = cxx_eval_bare_aggregate (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, jump_target); break; case VEC_INIT_EXPR: @@ -8524,12 +9594,13 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, or xvalue of the same type, meaning direct-initialization from the corresponding member. */ r = cxx_eval_vec_init (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, jump_target); break; case VEC_PERM_EXPR: r = cxx_eval_trinary_expression (ctx, t, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case PAREN_EXPR: @@ -8537,7 +9608,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, /* A PAREN_EXPR resulting from __builtin_assoc_barrier has no effect in constant expressions since it's unaffected by -fassociative-math. */ r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); break; case NOP_EXPR: @@ -8561,7 +9633,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, ? vc_discard : tcode == VIEW_CONVERT_EXPR ? lval : vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; tree type = TREE_TYPE (t); @@ -8618,7 +9693,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, { if (integer_zerop (sop)) return build_int_cst (type, 0); - r = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (type), sop); + r = cxx_fold_indirect_ref (ctx, loc, TREE_TYPE (type), sop, + NULL, jump_target); + if (*jump_target) + return NULL_TREE; if (r) { r = build1 (ADDR_EXPR, type, r); @@ -8745,10 +9823,14 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, if (cxx_replaceable_global_alloc_fn (fun) && IDENTIFIER_NEW_OP_P (DECL_NAME (fun))) arg_size = CALL_EXPR_ARG (oldop, 0); - TREE_TYPE (var) + tree new_type = build_new_constexpr_heap_type (ctx, elt_type, cookie_size, var_size, arg_size, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; + TREE_TYPE (var) = new_type; TREE_TYPE (TREE_OPERAND (op, 0)) = build_pointer_type (TREE_TYPE (var)); } @@ -8787,7 +9869,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, tree op = cxx_eval_constant_expression (ctx, oldop, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; if (*non_constant_p) return t; r = fold_convert (TREE_TYPE (t), op); @@ -8824,14 +9909,20 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, case PREDECREMENT_EXPR: case POSTDECREMENT_EXPR: return cxx_eval_increment_expression (ctx, t, - lval, non_constant_p, overflow_p); + lval, non_constant_p, overflow_p, + jump_target); + case THROW_EXPR: + if (cxx_dialect >= cxx26) + return cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p, + jump_target); + /* FALLTHROUGH */ case LAMBDA_EXPR: case NEW_EXPR: case VEC_NEW_EXPR: case DELETE_EXPR: case VEC_DELETE_EXPR: - case THROW_EXPR: case MODOP_EXPR: /* GCC internal stuff. */ case VA_ARG_EXPR: @@ -8845,7 +9936,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, case OBJ_TYPE_REF: /* Virtual function lookup. We don't need to do anything fancy. */ return cxx_eval_constant_expression (ctx, OBJ_TYPE_REF_EXPR (t), - lval, non_constant_p, overflow_p); + lval, non_constant_p, overflow_p, + jump_target); case PLACEHOLDER_EXPR: /* Use of the value or address of the current object. */ @@ -8855,7 +9947,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, return ctor; else return cxx_eval_constant_expression (ctx, ctor, lval, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); } /* A placeholder without a referent. We can get here when checking whether NSDMIs are noexcept, or in massage_init_elt; @@ -8868,7 +9961,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, { tree cond = TREE_OPERAND (t, 0); cond = cxx_eval_constant_expression (ctx, cond, vc_prvalue, - non_constant_p, overflow_p); + non_constant_p, overflow_p, + jump_target); + if (*jump_target) + return NULL_TREE; VERIFY_CONSTANT (cond); if (integer_nonzerop (cond)) *jump_target = t; @@ -8980,7 +10076,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, *non_constant_p = true; return t; } - r = cxx_eval_bit_cast (ctx, t, non_constant_p, overflow_p); + r = cxx_eval_bit_cast (ctx, t, non_constant_p, overflow_p, jump_target); break; case OMP_PARALLEL: @@ -9299,8 +10395,34 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant, if (manifestly_const_eval == mce_true) instantiate_constexpr_fns (r); + tree jmp_target = NULL_TREE; r = cxx_eval_constant_expression (&ctx, r, vc_prvalue, - &non_constant_p, &overflow_p); + &non_constant_p, &overflow_p, + &jmp_target); + if (throws (&jmp_target) && !non_constant_p) + { + if (!ctx.quiet) + diagnose_uncaught_exception (input_location, &ctx, jmp_target); + non_constant_p = true; + jmp_target = NULL_TREE; + r = t; + } + else if (!non_constant_p && jmp_target) + { + non_constant_p = true; + if (!ctx.quiet) + { + if (breaks (&jmp_target)) + error ("%<break%> outside of a loop or %<switch%>"); + else if (continues (&jmp_target)) + error ("%<continue%> outside of a loop"); + else if (returns (&jmp_target)) + error ("%<return%> in a statement expression"); + else + gcc_unreachable (); + } + r = t; + } /* If we got a non-simple TARGET_EXPR, the initializer was a sequence of statements, and the result ought to be stored in ctx.ctor. */ @@ -9309,15 +10431,31 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant, unsigned int i; tree cleanup; + jmp_target = NULL_TREE; /* Evaluate the cleanups. */ FOR_EACH_VEC_ELT_REVERSE (cleanups, i, cleanup) - cxx_eval_constant_expression (&ctx, cleanup, vc_discard, - &non_constant_p, &overflow_p); + if (cleanup == NULL_TREE) + /* NULL_TREE cleanup is a marker that before it is + CLEANUP_EH_ONLY cleanup. Skip the cleanup before it. */ + --i; + else + cxx_eval_constant_expression (&ctx, cleanup, vc_discard, + &non_constant_p, &overflow_p, + &jmp_target); + if (throws (&jmp_target) && !non_constant_p) + { + if (!ctx.quiet) + diagnose_uncaught_exception (input_location, &ctx, jmp_target); + non_constant_p = true; + r = t; + } /* Mutable logic is a bit tricky: we want to allow initialization of constexpr variables with mutable members, but we can't copy those members to another constexpr variable. */ - if (TREE_CODE (r) == CONSTRUCTOR && CONSTRUCTOR_MUTABLE_POISON (r)) + if (!non_constant_p + && TREE_CODE (r) == CONSTRUCTOR + && CONSTRUCTOR_MUTABLE_POISON (r)) { if (!allow_non_constant) error ("%qE is not a constant expression because it refers to " @@ -9335,8 +10473,13 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant, { if (!allow_non_constant && !non_constant_p) { - error ("%qE is not a constant expression because it refers to " - "a result of %<operator new%>", t); + if (DECL_LANG_SPECIFIC (heap_var)) + error ("%qE is not a constant expression because it refers to " + "exception object allocated with " + "%<__cxa_allocate_exception%>", t); + else + error ("%qE is not a constant expression because it refers to " + "a result of %<operator new%>", t); inform (DECL_SOURCE_LOCATION (heap_var), "allocated here"); } r = t; @@ -9917,6 +11060,24 @@ cxx_constant_init (tree t, tree decl) return maybe_constant_init_1 (t, decl, false, mce_true); } +/* Return true if CALL_EXPR T might throw during constant evaluation. */ + +static bool +callee_might_throw (tree t) +{ + if (cxx_dialect < cxx26 || !flag_exceptions) + return false; + tree callee = cp_get_callee (t); + if (callee == NULL_TREE) + return false; + tree callee_fn = cp_get_fndecl_from_callee (callee, false); + return (!flag_enforce_eh_specs + || type_dependent_expression_p (callee) + || !POINTER_TYPE_P (TREE_TYPE (callee)) + || (!type_noexcept_p (TREE_TYPE (TREE_TYPE (callee))) + && (callee_fn == NULL_TREE || !TREE_NOTHROW (callee_fn)))); +} + #if 0 /* FIXME see ADDR_EXPR section in potential_constant_expression_1. */ /* Return true if the object referred to by REF has automatic or thread @@ -9949,11 +11110,13 @@ struct check_for_return_continue_data { hash_set<tree> *pset; tree continue_stmt; tree break_stmt; + bool could_throw; }; /* Helper function for potential_constant_expression_1 SWITCH_STMT handling, called through cp_walk_tree. Return the first RETURN_EXPR found, or note - the first CONTINUE_STMT and/or BREAK_STMT if RETURN_EXPR is not found. */ + the first CONTINUE_STMT and/or BREAK_STMT if RETURN_EXPR is not found. + For C++26 also note presence of possibly throwing calls. */ static tree check_for_return_continue (tree *tp, int *walk_subtrees, void *data) { @@ -10038,6 +11201,13 @@ check_for_return_continue (tree *tp, int *walk_subtrees, void *data) case CONSTRUCTOR: break; + case AGGR_INIT_EXPR: + case CALL_EXPR: + /* In C++26 a function could throw. */ + if (callee_might_throw (t)) + d->could_throw = true; + break; + default: if (!EXPR_P (t)) *walk_subtrees = 0; @@ -10243,8 +11413,27 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, || TREE_CODE (t) != CALL_EXPR || current_function_decl == NULL_TREE || !is_std_construct_at (current_function_decl)) - && !cxx_dynamic_cast_fn_p (fun)) + && !cxx_dynamic_cast_fn_p (fun) + && !cxx_cxa_builtin_fn_p (fun)) { + /* In C++26 evaluation of the function arguments might + throw and in that case it is irrelevant whether + fun is constexpr or not. */ + if (cxx_dialect >= cxx26) + for (; i < nargs; ++i) + { + tree x = get_nth_callarg (t, i); + bool rv = processing_template_decl ? any : rval; + bool sub_now = false; + if (!potential_constant_expression_1 (x, rv, strict, + sub_now, + fundef_p, + flags, + jump_target)) + return false; + if (throws (jump_target)) + return true; + } if ((flags & tf_error) && constexpr_error (loc, fundef_p, "call to non-%<constexpr%> " @@ -10289,7 +11478,12 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, sub_now, fundef_p, flags, jump_target)) return false; + if (throws (jump_target)) + return true; } + /* In C++26 a function could throw. */ + if (*jump_target == NULL_TREE && callee_might_throw (t)) + *jump_target = void_node; return true; } @@ -10512,11 +11706,13 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, a return. */ hash_set<tree> pset; check_for_return_continue_data data = { &pset, NULL_TREE, - NULL_TREE }; + NULL_TREE, false }; if (tree ret_expr = cp_walk_tree (&FOR_BODY (t), check_for_return_continue, &data, &pset)) *jump_target = ret_expr; + if (data.could_throw) + *jump_target = void_node; return true; } } @@ -10556,11 +11752,13 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, a return. */ hash_set<tree> pset; check_for_return_continue_data data = { &pset, NULL_TREE, - NULL_TREE }; + NULL_TREE, false }; if (tree ret_expr = cp_walk_tree (&WHILE_BODY (t), check_for_return_continue, &data, &pset)) *jump_target = ret_expr; + if (data.could_throw) + *jump_target = void_node; return true; } if (!RECUR (WHILE_BODY (t), any)) @@ -10584,7 +11782,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, { hash_set<tree> pset; check_for_return_continue_data data = { &pset, NULL_TREE, - NULL_TREE }; + NULL_TREE, false }; if (tree ret_expr = cp_walk_tree (&SWITCH_STMT_BODY (t), check_for_return_continue, &data, &pset)) @@ -10593,6 +11791,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, else if (data.continue_stmt) /* The switch can't return, but might continue. */ *jump_target = data.continue_stmt; + if (data.could_throw) + *jump_target = void_node; } return true; @@ -10622,7 +11822,6 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, case DYNAMIC_CAST_EXPR: case PSEUDO_DTOR_EXPR: - case THROW_EXPR: case OMP_PARALLEL: case OMP_TASK: case OMP_FOR: @@ -10678,6 +11877,11 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, constant. */ return true; + case THROW_EXPR: + if (cxx_dialect < cxx26) + goto fail; + return RECUR (TREE_OPERAND (t, 0), rval); + case ASM_EXPR: if (flags & tf_error) inline_asm_in_constexpr_error (loc, fundef_p); @@ -10806,6 +12010,22 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, case CLEANUP_POINT_EXPR: case MUST_NOT_THROW_EXPR: case TRY_CATCH_EXPR: + /* Even for C++26 handle TRY_BLOCK conservatively, if we detect the + body could throw, even with catch (...) among handlers we'd need + to analyze them in detail if they couldn't rethrow it. More + importantly though, throws (jump_target) is just conservative, + and there could be e.g. + try + { + possibly_throwing_fn (args); + break; + } + catch (...) + { + } + or continue or return instead of break. So, clearing *jump_target + because we see catch (...) handler might mean we missed break + etc. */ case TRY_BLOCK: case EH_SPEC_BLOCK: case EXPR_STMT: @@ -11047,9 +12267,9 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, want_rval, strict, now, fundef_p, tf_none, &this_jump_target)) { - if (returns (&this_jump_target)) + if (returns (&this_jump_target) || throws (&this_jump_target)) *jump_target = this_jump_target; - else if (!returns (jump_target)) + else if (!returns (jump_target) && !throws (jump_target)) { if (breaks (&this_jump_target) || continues (&this_jump_target)) @@ -11061,7 +12281,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, couldn't return, break or continue. */ hash_set<tree> pset; check_for_return_continue_data data = { &pset, NULL_TREE, - NULL_TREE }; + NULL_TREE, + false }; if (tree ret_expr = cp_walk_tree (&TREE_OPERAND (t, 2), check_for_return_continue, &data, @@ -11074,6 +12295,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, else if (data.break_stmt) *jump_target = data.break_stmt; } + if (data.could_throw) + *jump_target = void_node; } } return true; diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c8eef24..8d7aec3 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3205,6 +3205,9 @@ diagnose_trait_expr (tree expr, tree args) else inform (loc, " %qT is not nothrow invocable by %qE", t1, t2); break; + case CPTK_IS_NOTHROW_RELOCATABLE: + inform (loc, " %qT is not nothrow relocatable", t1); + break; case CPTK_IS_OBJECT: inform (loc, " %qT is not an object type", t1); break; @@ -3224,6 +3227,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_REFERENCE: inform (loc, " %qT is not a reference", t1); break; + case CPTK_IS_REPLACEABLE: + inform (loc, " %qT is not replaceable", t1); + break; case CPTK_IS_SAME: inform (loc, " %qT is not the same as %qT", t1, t2); break; @@ -3251,6 +3257,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_TRIVIALLY_DESTRUCTIBLE: inform (loc, " %qT is not trivially destructible", t1); break; + case CPTK_IS_TRIVIALLY_RELOCATABLE: + inform (loc, " %qT is not trivially relocatable", t1); + break; case CPTK_IS_UNBOUNDED_ARRAY: inform (loc, " %qT is not an unbounded array", t1); break; diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index ce69bd6..882a943 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -889,6 +889,12 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) (EXPR_LOCATION (*expr_p), call_expr_nargs (*expr_p), &CALL_EXPR_ARG (*expr_p, 0)); break; + case CP_BUILT_IN_EH_PTR_ADJUST_REF: + error_at (EXPR_LOCATION (*expr_p), + "%qs used outside of constant expressions", + "__builtin_eh_ptr_adjust_ref"); + *expr_p = void_node; + break; default: break; } diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index e71b28c..9fedfd7 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -87,12 +87,14 @@ DEFTRAIT_EXPR (IS_NOTHROW_CONSTRUCTIBLE, "__is_nothrow_constructible", -1) DEFTRAIT_EXPR (IS_NOTHROW_CONVERTIBLE, "__is_nothrow_convertible", 2) DEFTRAIT_EXPR (IS_NOTHROW_DESTRUCTIBLE, "__is_nothrow_destructible", 1) DEFTRAIT_EXPR (IS_NOTHROW_INVOCABLE, "__is_nothrow_invocable", -1) +DEFTRAIT_EXPR (IS_NOTHROW_RELOCATABLE, "__builtin_is_nothrow_relocatable", 1) DEFTRAIT_EXPR (IS_OBJECT, "__is_object", 1) DEFTRAIT_EXPR (IS_POINTER_INTERCONVERTIBLE_BASE_OF, "__is_pointer_interconvertible_base_of", 2) DEFTRAIT_EXPR (IS_POD, "__is_pod", 1) DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (IS_POLYMORPHIC, "__is_polymorphic", 1) DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) +DEFTRAIT_EXPR (IS_REPLACEABLE, "__builtin_is_replaceable", 1) DEFTRAIT_EXPR (IS_SAME, "__is_same", 2) DEFTRAIT_EXPR (IS_SCOPED_ENUM, "__is_scoped_enum", 1) DEFTRAIT_EXPR (IS_STD_LAYOUT, "__is_standard_layout", 1) @@ -101,6 +103,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_TRIVIALLY_DESTRUCTIBLE, "__is_trivially_destructible", 1) +DEFTRAIT_EXPR (IS_TRIVIALLY_RELOCATABLE, "__builtin_is_trivially_relocatable", 1) DEFTRAIT_EXPR (IS_UNBOUNDED_ARRAY, "__is_unbounded_array", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) DEFTRAIT_EXPR (IS_VIRTUAL_BASE_OF, "__builtin_is_virtual_base_of", 2) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 3b92d9a..5708aa1 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -452,6 +452,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; contract_semantic (in ASSERTION_, PRECONDITION_, POSTCONDITION_STMT) RETURN_EXPR_LOCAL_ADDR_P (in RETURN_EXPR) PACK_INDEX_PARENTHESIZED_P (in PACK_INDEX_*) + MUST_NOT_THROW_NOEXCEPT_P (in MUST_NOT_THROW_EXPR) 1: IDENTIFIER_KIND_BIT_1 (in IDENTIFIER_NODE) TI_PENDING_TEMPLATE_FLAG. TEMPLATE_PARMS_FOR_INLINE. @@ -472,6 +473,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; BIND_EXPR_VEC_DTOR (in BIND_EXPR) ATOMIC_CONSTR_EXPR_FROM_CONCEPT_P (in ATOMIC_CONSTR) STATIC_INIT_DECOMP_BASE_P (in the TREE_LIST for {static,tls}_aggregates) + MUST_NOT_THROW_THROW_P (in MUST_NOT_THROW_EXPR) 2: IDENTIFIER_KIND_BIT_2 (in IDENTIFIER_NODE) ICS_THIS_FLAG (in _CONV) DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (in VAR_DECL) @@ -493,6 +495,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; contract_semantic (in ASSERTION_, PRECONDITION_, POSTCONDITION_STMT) STATIC_INIT_DECOMP_NONBASE_P (in the TREE_LIST for {static,tls}_aggregates) + MUST_NOT_THROW_CATCH_P (in MUST_NOT_THROW_EXPR) 3: IMPLICIT_RVALUE_P (in NON_LVALUE_EXPR or STATIC_CAST_EXPR) ICS_BAD_FLAG (in _CONV) FN_TRY_BLOCK_P (in TRY_BLOCK) @@ -2497,6 +2500,11 @@ struct GTY(()) lang_type { bool erroneous : 1; bool non_pod_aggregate : 1; bool non_aggregate_pod : 1; + bool trivially_relocatable : 1; + bool trivially_relocatable_computed : 1; + + bool replaceable : 1; + bool replaceable_computed : 1; /* When adding a flag here, consider whether or not it ought to apply to a template instance if it applies to the template. If @@ -2505,7 +2513,7 @@ struct GTY(()) lang_type { /* There are some bits left to fill out a 32-bit word. Keep track of this by updating the size of this bitfield whenever you add or remove a flag. */ - unsigned dummy : 2; + unsigned dummy : 30; tree primary_base; vec<tree_pair_s, va_gc> *vcall_indices; @@ -2516,11 +2524,11 @@ struct GTY(()) lang_type { vec<tree, va_gc> *pure_virtuals; tree friend_classes; vec<tree, va_gc> * GTY((reorder ("resort_type_member_vec"))) members; + /* CLASSTYPE_KEY_METHOD for TYPE_POLYMORPHIC_P types, CLASSTYPE_LAMBDA_EXPR + otherwise. */ tree key_method; tree decl_list; tree befriending_classes; - /* FIXME reuse another field? */ - tree lambda_expr; union maybe_objc_info { /* If not c_dialect_objc, this part is not even allocated. */ char GTY((tag ("0"))) non_objc; @@ -2643,7 +2651,13 @@ struct GTY(()) lang_type { /* The member function with which the vtable will be emitted: the first noninline non-pure-virtual member function. NULL_TREE if there is no key function or if this is a class template */ -#define CLASSTYPE_KEY_METHOD(NODE) (LANG_TYPE_CLASS_CHECK (NODE)->key_method) +#define CLASSTYPE_KEY_METHOD(NODE) \ + (TYPE_POLYMORPHIC_P (NODE) \ + ? LANG_TYPE_CLASS_CHECK (NODE)->key_method \ + : NULL_TREE) +#define SET_CLASSTYPE_KEY_METHOD(NODE, VALUE) \ + (gcc_checking_assert (TYPE_POLYMORPHIC_P (NODE)), \ + LANG_TYPE_CLASS_CHECK (NODE)->key_method = (VALUE)) /* Vector of members. During definition, it is unordered and only member functions are present. After completion it is sorted and @@ -2775,7 +2789,12 @@ struct GTY(()) lang_type { /* The associated LAMBDA_EXPR that made this class. */ #define CLASSTYPE_LAMBDA_EXPR(NODE) \ - (LANG_TYPE_CLASS_CHECK (NODE)->lambda_expr) + (TYPE_POLYMORPHIC_P (NODE) \ + ? NULL_TREE \ + : LANG_TYPE_CLASS_CHECK (NODE)->key_method) +#define SET_CLASSTYPE_LAMBDA_EXPR(NODE, VALUE) \ + (gcc_checking_assert (!TYPE_POLYMORPHIC_P (NODE)), \ + LANG_TYPE_CLASS_CHECK (NODE)->key_method = (VALUE)) /* The extra mangling scope for this closure type. */ #define LAMBDA_TYPE_EXTRA_SCOPE(NODE) \ (LAMBDA_EXPR_EXTRA_SCOPE (CLASSTYPE_LAMBDA_EXPR (NODE))) @@ -2841,6 +2860,29 @@ struct GTY(()) lang_type { above (c++/120012). This could also be a hash_set. */ #define CLASSTYPE_NON_AGGREGATE_POD(NODE) \ (LANG_TYPE_CLASS_CHECK (NODE)->non_aggregate_pod) + +/* If CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED, true if this class is + trivially relocatable. + If !CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED, true if this class + is marked with trivially_relocatable_if_eligible conditional keyword. */ +#define CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT(NODE) \ + (LANG_TYPE_CLASS_CHECK (NODE)->trivially_relocatable) + +/* True if whether this class is trivially relocatable or not + has been computed already. */ +#define CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED(NODE) \ + (LANG_TYPE_CLASS_CHECK (NODE)->trivially_relocatable_computed) + +/* If CLASSTYPE_REPLACEABLE_COMPUTED, true if this class is replaceable. + If !CLASSTYPE_REPLACEABLE_COMPUTED, true if this class is marked with + replaceable_if_eligible conditional keyword. */ +#define CLASSTYPE_REPLACEABLE_BIT(NODE) \ + (LANG_TYPE_CLASS_CHECK (NODE)->replaceable) + +/* True if whether this class is replaceable or not has been computed + already. */ +#define CLASSTYPE_REPLACEABLE_COMPUTED(NODE) \ + (LANG_TYPE_CLASS_CHECK (NODE)->replaceable_computed) /* Additional macros for inheritance information. */ @@ -3016,6 +3058,8 @@ struct GTY(()) lang_decl_min { In a lambda-capture proxy VAR_DECL, this is DECL_CAPTURED_VARIABLE. In a function-scope TREE_STATIC VAR_DECL or IMPLICIT_TYPEDEF_P TYPE_DECL, this is DECL_DISCRIMINATOR. + In constexpr exception artificial VAR_DECL, this is + DECL_EXCEPTION_REFCOUNT. In a DECL_LOCAL_DECL_P decl, this is the namespace decl it aliases. Otherwise, in a class-scope DECL, this is DECL_ACCESS. */ tree access; @@ -4470,6 +4514,23 @@ get_vec_init_expr (tree t) #define MUST_NOT_THROW_COND(NODE) \ TREE_OPERAND (MUST_NOT_THROW_EXPR_CHECK (NODE), 1) +/* Reasons why MUST_NOT_THROW_EXPR has been created. */ + +/* Indicates MUST_NOT_THROW_EXPR has been created to wrap body of + a noexcept function. */ +#define MUST_NOT_THROW_NOEXCEPT_P(NODE) \ + TREE_LANG_FLAG_0 (MUST_NOT_THROW_EXPR_CHECK (NODE)) + +/* Indicates MUST_NOT_THROW_EXPR has been created to wrap construction of + exception object during throw. */ +#define MUST_NOT_THROW_THROW_P(NODE) \ + TREE_LANG_FLAG_1 (MUST_NOT_THROW_EXPR_CHECK (NODE)) + +/* Indicates MUST_NOT_THROW_EXPR has been created to wrap construction of + handler parameter during catch. */ +#define MUST_NOT_THROW_CATCH_P(NODE) \ + TREE_LANG_FLAG_2 (MUST_NOT_THROW_EXPR_CHECK (NODE)) + /* The TYPE_MAIN_DECL for a class template type is a TYPE_DECL, not a TEMPLATE_DECL. This macro determines whether or not a given class type is really a template type, as opposed to an instantiation or @@ -4512,7 +4573,7 @@ get_vec_init_expr (tree t) #define TYPE_CONTAINS_VPTR_P(NODE) \ (TYPE_POLYMORPHIC_P (NODE) || CLASSTYPE_VBASECLASSES (NODE)) -/* Nonzero if NODE is a FUNCTION_DECL or VARIABLE_DECL (for a decl +/* Nonzero if NODE is a FUNCTION_DECL or VAR_DECL (for a decl with namespace scope) declared in a local scope. */ #define DECL_LOCAL_DECL_P(NODE) \ DECL_LANG_FLAG_0 (VAR_OR_FUNCTION_DECL_CHECK (NODE)) @@ -5153,6 +5214,10 @@ get_vec_init_expr (tree t) protected_access_node will appear in the DECL_ACCESS for the node. */ #define DECL_ACCESS(NODE) (LANG_DECL_MIN_CHECK (NODE)->access) +/* In artificial VAR_DECL created by cxa_allocate_exception + this is reference count. */ +#define DECL_EXCEPTION_REFCOUNT(NODE) (LANG_DECL_MIN_CHECK (NODE)->access) + /* Nonzero if the FUNCTION_DECL is a global constructor. */ #define DECL_GLOBAL_CTOR_P(NODE) \ (LANG_DECL_FN_CHECK (NODE)->global_ctor_p) @@ -6471,7 +6536,9 @@ enum virt_specifier { VIRT_SPEC_UNSPECIFIED = 0x0, VIRT_SPEC_FINAL = 0x1, - VIRT_SPEC_OVERRIDE = 0x2 + VIRT_SPEC_OVERRIDE = 0x2, + VIRT_SPEC_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE = 0x4, + VIRT_SPEC_REPLACEABLE_IF_ELIGIBLE = 0x8 }; /* A type-qualifier, or bitmask therefore, using the VIRT_SPEC @@ -6813,6 +6880,7 @@ enum cp_built_in_function { CP_BUILT_IN_IS_CORRESPONDING_MEMBER, CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS, CP_BUILT_IN_SOURCE_LOCATION, + CP_BUILT_IN_EH_PTR_ADJUST_REF, CP_BUILT_IN_LAST }; @@ -6993,6 +7061,7 @@ extern bool type_has_extended_temps (tree); extern tree strip_top_quals (tree); extern bool reference_related_p (tree, tree); extern bool reference_compatible_p (tree, tree); +extern bool handler_match_for_exception_type (tree, tree); extern int remaining_arguments (tree); extern tree build_implicit_conv_flags (tree, tree, int); extern tree perform_implicit_conversion (tree, tree, tsubst_flags_t); @@ -8243,6 +8312,8 @@ extern bool pod_type_p (const_tree); extern bool layout_pod_type_p (const_tree); extern bool std_layout_type_p (const_tree); extern bool trivial_type_p (const_tree); +extern bool trivially_relocatable_type_p (tree); +extern bool replaceable_type_p (tree); extern bool trivially_copyable_p (const_tree); extern bool type_has_unique_obj_representations (const_tree); extern bool scalarish_type_p (const_tree); diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 0e6afbe..843f0e4 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -5082,6 +5082,18 @@ cxx_init_decl_processing (void) BUILT_IN_FRONTEND, NULL, NULL_TREE); set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF); + if (cxx_dialect >= cxx26) + { + tree void_ptrintftype + = build_function_type_list (void_type_node, ptr_type_node, + integer_type_node, NULL_TREE); + decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref", + void_ptrintftype, + CP_BUILT_IN_EH_PTR_ADJUST_REF, + BUILT_IN_FRONTEND, NULL, NULL_TREE); + set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF); + } + integer_two_node = build_int_cst (NULL_TREE, 2); /* Guess at the initial static decls size. */ @@ -17277,7 +17289,7 @@ xref_tag (enum tag_types tag_code, tree name, if (IDENTIFIER_LAMBDA_P (name)) /* Mark it as a lambda type right now. Our caller will correct the value. */ - CLASSTYPE_LAMBDA_EXPR (t) = error_mark_node; + SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node); t = pushtag (name, t, how); } else diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc index a9d8e2f..a7f35e4 100644 --- a/gcc/cp/except.cc +++ b/gcc/cp/except.cc @@ -367,6 +367,8 @@ initialize_handler_parm (tree decl, tree exp) MUST_NOT_THROW_EXPR. */ init = fold_build_cleanup_point_expr (TREE_TYPE (init), init); init = build_must_not_throw_expr (init, NULL_TREE); + if (init && TREE_CODE (init) == MUST_NOT_THROW_EXPR) + MUST_NOT_THROW_CATCH_P (init) = 1; } decl = pushdecl (decl); @@ -523,6 +525,7 @@ begin_eh_spec_block (void) r = build_stmt (spec_location, MUST_NOT_THROW_EXPR, NULL_TREE, NULL_TREE); TREE_SIDE_EFFECTS (r) = 1; + MUST_NOT_THROW_NOEXCEPT_P (r) = 1; } else r = build_stmt (spec_location, EH_SPEC_BLOCK, NULL_TREE, NULL_TREE); @@ -614,6 +617,7 @@ wrap_cleanups_r (tree *tp, int *walk_subtrees, void * /*data*/) { cleanup = build2 (MUST_NOT_THROW_EXPR, void_type_node, cleanup, NULL_TREE); + MUST_NOT_THROW_THROW_P (cleanup) = 1; TARGET_EXPR_CLEANUP (exp) = cleanup; } @@ -712,6 +716,11 @@ build_throw (location_t loc, tree exp, tsubst_flags_t complain) allocate_expr = do_allocate_exception (temp_type); if (allocate_expr == error_mark_node) return error_mark_node; + /* Copy ptr inside of the CLEANUP_POINT_EXPR + added below to a TARGET_EXPR slot added outside of it, + otherwise during constant evaluation of throw expression + we'd diagnose accessing ptr outside of its lifetime. */ + tree ptr_copy = get_internal_target_expr (null_pointer_node); allocate_expr = get_internal_target_expr (allocate_expr); ptr = TARGET_EXPR_SLOT (allocate_expr); TARGET_EXPR_CLEANUP (allocate_expr) = do_free_exception (ptr); @@ -763,10 +772,17 @@ build_throw (location_t loc, tree exp, tsubst_flags_t complain) /* Prepend the allocation. */ exp = build2 (COMPOUND_EXPR, TREE_TYPE (exp), allocate_expr, exp); + exp = build2 (COMPOUND_EXPR, void_type_node, exp, + build2 (MODIFY_EXPR, void_type_node, + TARGET_EXPR_SLOT (ptr_copy), ptr)); + ptr = TARGET_EXPR_SLOT (ptr_copy); + /* Force all the cleanups to be evaluated here so that we don't have to do them during unwinding. */ exp = build1 (CLEANUP_POINT_EXPR, void_type_node, exp); + exp = build2 (COMPOUND_EXPR, TREE_TYPE (exp), ptr_copy, exp); + throw_type = build_eh_type_type (prepare_eh_type (TREE_TYPE (object))); cleanup = NULL_TREE; diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 182cffa..525e8ef 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -150,7 +150,7 @@ begin_lambda_type (tree lambda) /* Cross-reference the expression and the type. */ LAMBDA_EXPR_CLOSURE (lambda) = type; - CLASSTYPE_LAMBDA_EXPR (type) = lambda; + SET_CLASSTYPE_LAMBDA_EXPR (type, lambda); /* In C++17, assume the closure is literal; we'll clear the flag later if necessary. */ diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 6b5a60a..689319a 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -13393,13 +13393,19 @@ trees_in::read_class_def (tree defn, tree maybe_template) if (TYPE_LANG_SPECIFIC (type)) { - CLASSTYPE_LAMBDA_EXPR (type) = lambda; + if (!TYPE_POLYMORPHIC_P (type)) + SET_CLASSTYPE_LAMBDA_EXPR (type, lambda); + else + gcc_checking_assert (lambda == NULL_TREE); CLASSTYPE_MEMBER_VEC (type) = member_vec; CLASSTYPE_PURE_VIRTUALS (type) = pure_virts; CLASSTYPE_VCALL_INDICES (type) = vcall_indices; - CLASSTYPE_KEY_METHOD (type) = key_method; + if (TYPE_POLYMORPHIC_P (type)) + SET_CLASSTYPE_KEY_METHOD (type, key_method); + else + gcc_checking_assert (key_method == NULL_TREE); CLASSTYPE_VBASECLASSES (type) = vbase_vec; diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index d96fdf8..0d9ed2e 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -3091,8 +3091,8 @@ static cp_token *cp_parser_require_keyword (cp_parser *, enum rid, required_token); static bool cp_parser_token_starts_function_definition_p (cp_token *); -static bool cp_parser_next_token_starts_class_definition_p - (cp_parser *); +static bool cp_parser_nth_token_starts_class_definition_p + (cp_parser *, size_t); static bool cp_parser_next_token_ends_template_argument_p (cp_parser *); static bool cp_parser_nth_token_starts_template_argument_list_p @@ -22031,7 +22031,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, bool template_p = (template_parm_lists_apply - && (cp_parser_next_token_starts_class_definition_p (parser) + && (cp_parser_nth_token_starts_class_definition_p (parser, 1) || cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))); /* An unqualified name was used to reference this type, so there were no qualifying templates. */ @@ -28068,6 +28068,98 @@ cp_parser_class_specifier (cp_parser* parser) return type; } +/* Parse an (optional) class-property-specifier-seq. + + class-property-specifier-seq: + class-property-specifier class-property-specifier-seq [opt] + + class-property-specifier: + final + trivially_relocatable_if_eligible (C++26) + replaceable_if_eligible (C++26) + + Returns a bitmask representing the class-property-specifiers. */ + +static cp_virt_specifiers +cp_parser_class_property_specifier_seq_opt (cp_parser *parser) +{ + cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED; + + while (true) + { + cp_token *token; + cp_virt_specifiers virt_specifier; + + /* Peek at the next token. */ + token = cp_lexer_peek_token (parser->lexer); + /* See if it's a class-property-specifier. */ + if (token->type != CPP_NAME) + break; + if (id_equal (token->u.value, "final")) + { + /* For C++98, quietly ignore final in e.g. + struct S final = 24; */ + if (cxx_dialect == cxx98 + && virt_specifiers == VIRT_SPEC_UNSPECIFIED + && !cp_parser_nth_token_starts_class_definition_p (parser, 2) + && !cp_lexer_nth_token_is (parser->lexer, 2, CPP_NAME)) + break; + maybe_warn_cpp0x (CPP0X_OVERRIDE_CONTROLS); + virt_specifier = VIRT_SPEC_FINAL; + } + else if (id_equal (token->u.value, "__final")) + virt_specifier = VIRT_SPEC_FINAL; + else if (id_equal (token->u.value, "trivially_relocatable_if_eligible")) + { + if (cxx_dialect < cxx26) + { + /* Warn about the C++26 conditional keyword (but don't parse + it). */ + warning_at (token->location, OPT_Wc__26_compat, + "identifier %qE is a conditional keyword in C++26", + token->u.value); + break; + } + virt_specifier = VIRT_SPEC_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE; + } + else if (id_equal (token->u.value, + "__trivially_relocatable_if_eligible")) + virt_specifier = VIRT_SPEC_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE; + else if (id_equal (token->u.value, "replaceable_if_eligible")) + { + if (cxx_dialect < cxx26) + { + /* Warn about the C++26 conditional keyword (but don't parse + it). */ + warning_at (token->location, OPT_Wc__26_compat, + "identifier %qE is a conditional keyword in C++26", + token->u.value); + break; + } + virt_specifier = VIRT_SPEC_REPLACEABLE_IF_ELIGIBLE; + } + else if (id_equal (token->u.value, + "__replaceable_if_eligible")) + virt_specifier = VIRT_SPEC_REPLACEABLE_IF_ELIGIBLE; + else + break; + + if (virt_specifiers & virt_specifier) + { + gcc_rich_location richloc (token->location); + richloc.add_fixit_remove (); + error_at (&richloc, "duplicate %qD specifier", token->u.value); + cp_lexer_purge_token (parser->lexer); + } + else + { + cp_lexer_consume_token (parser->lexer); + virt_specifiers |= virt_specifier; + } + } + return virt_specifiers; +} + /* Parse a class-head. class-head: @@ -28258,18 +28350,16 @@ cp_parser_class_head (cp_parser* parser, pop_deferring_access_checks (); if (id) - { - cp_parser_check_for_invalid_template_id (parser, id, - class_key, - type_start_token->location); - } - virt_specifiers = cp_parser_virt_specifier_seq_opt (parser); + cp_parser_check_for_invalid_template_id (parser, id, + class_key, + type_start_token->location); + virt_specifiers = cp_parser_class_property_specifier_seq_opt (parser); /* If it's not a `:' or a `{' then we can't really be looking at a class-head, since a class-head only appears as part of a class-specifier. We have to detect this situation before calling xref_tag, since that has irreversible side-effects. */ - if (!cp_parser_next_token_starts_class_definition_p (parser)) + if (!cp_parser_nth_token_starts_class_definition_p (parser, 1)) { cp_parser_error (parser, "expected %<{%> or %<:%>"); type = error_mark_node; @@ -28279,13 +28369,6 @@ cp_parser_class_head (cp_parser* parser, /* At this point, we're going ahead with the class-specifier, even if some other problem occurs. */ cp_parser_commit_to_tentative_parse (parser); - if (virt_specifiers & VIRT_SPEC_OVERRIDE) - { - cp_parser_error (parser, - "cannot specify %<override%> for a class"); - type = error_mark_node; - goto out; - } /* Issue the error about the overly-qualified name now. */ if (qualified_p) { @@ -28613,6 +28696,16 @@ cp_parser_class_head (cp_parser* parser, DECL_SOURCE_LOCATION (TYPE_NAME (type)) = type_start_token->location; if (type && (virt_specifiers & VIRT_SPEC_FINAL)) CLASSTYPE_FINAL (type) = 1; + if (type && (virt_specifiers & VIRT_SPEC_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE)) + { + gcc_assert (!CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED (type)); + CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (type) = 1; + } + if (type && (virt_specifiers & VIRT_SPEC_REPLACEABLE_IF_ELIGIBLE)) + { + gcc_assert (!CLASSTYPE_REPLACEABLE_COMPUTED (type)); + CLASSTYPE_REPLACEABLE_BIT (type) = 1; + } out: parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p; return type; @@ -35654,15 +35747,15 @@ cp_parser_token_starts_function_definition_p (cp_token* token) || token->keyword == RID_RETURN); } -/* Returns TRUE iff the next token is the ":" or "{" beginning a class +/* Returns TRUE iff the Nth token is the ":" or "{" beginning a class definition. */ static bool -cp_parser_next_token_starts_class_definition_p (cp_parser *parser) +cp_parser_nth_token_starts_class_definition_p (cp_parser *parser, size_t n) { cp_token *token; - token = cp_lexer_peek_token (parser->lexer); + token = cp_lexer_peek_nth_token (parser->lexer, n); return (token->type == CPP_OPEN_BRACE || (token->type == CPP_COLON && !parser->colon_doesnt_start_class_def_p)); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 40ce987..ca8d61d 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -12699,7 +12699,17 @@ instantiate_class_template (tree type) determine_visibility (TYPE_MAIN_DECL (type)); } if (CLASS_TYPE_P (type)) - CLASSTYPE_FINAL (type) = CLASSTYPE_FINAL (pattern); + { + CLASSTYPE_FINAL (type) = CLASSTYPE_FINAL (pattern); + CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (type) + = CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (pattern); + CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED (type) + = CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED (pattern); + CLASSTYPE_REPLACEABLE_BIT (type) + = CLASSTYPE_REPLACEABLE_BIT (pattern); + CLASSTYPE_REPLACEABLE_COMPUTED (type) + = CLASSTYPE_REPLACEABLE_COMPUTED (pattern); + } pbinfo = TYPE_BINFO (pattern); @@ -20147,7 +20157,14 @@ tsubst_stmt (tree t, tree args, tsubst_flags_t complain, tree in_decl) { tree op0 = RECUR (TREE_OPERAND (t, 0)); tree cond = RECUR (MUST_NOT_THROW_COND (t)); - RETURN (build_must_not_throw_expr (op0, cond)); + stmt = build_must_not_throw_expr (op0, cond); + if (stmt && TREE_CODE (stmt) == MUST_NOT_THROW_EXPR) + { + MUST_NOT_THROW_NOEXCEPT_P (stmt) = MUST_NOT_THROW_NOEXCEPT_P (t); + MUST_NOT_THROW_THROW_P (stmt) = MUST_NOT_THROW_THROW_P (t); + MUST_NOT_THROW_CATCH_P (stmt) = MUST_NOT_THROW_CATCH_P (t); + } + RETURN (stmt); } case EXPR_PACK_EXPANSION: diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index b57547c..77fac45 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -13361,6 +13361,18 @@ object_type_p (const_tree type) && !VOID_TYPE_P (type)); } +/* [defns.referenceable] True iff TYPE is a referenceable type. */ + +static bool +referenceable_type_p (const_tree type) +{ + return (TYPE_REF_P (type) + || object_type_p (type) + || (FUNC_OR_METHOD_TYPE_P (type) + && type_memfn_quals (type) == TYPE_UNQUALIFIED + && type_memfn_rqual (type) == REF_QUAL_NONE)); +} + /* Actually evaluates the trait. */ static bool @@ -13530,6 +13542,21 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_NOTHROW_INVOCABLE: return expr_noexcept_p (build_invoke (type1, type2, tf_none), tf_none); + case CPTK_IS_NOTHROW_RELOCATABLE: + if (trivially_relocatable_type_p (type1)) + return true; + else + { + type1 = strip_array_types (type1); + if (!referenceable_type_p (type1)) + return false; + tree arg = make_tree_vec (1); + TREE_VEC_ELT (arg, 0) + = cp_build_reference_type (type1, /*rval=*/true); + return (is_nothrow_xible (INIT_EXPR, type1, arg) + && is_nothrow_xible (BIT_NOT_EXPR, type1, NULL_TREE)); + } + case CPTK_IS_OBJECT: return object_type_p (type1); @@ -13548,6 +13575,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_REFERENCE: return type_code1 == REFERENCE_TYPE; + case CPTK_IS_REPLACEABLE: + return replaceable_type_p (type1); + case CPTK_IS_SAME: return same_type_p (type1, type2); @@ -13572,6 +13602,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_DESTRUCTIBLE: return is_trivially_xible (BIT_NOT_EXPR, type1, NULL_TREE); + case CPTK_IS_TRIVIALLY_RELOCATABLE: + return trivially_relocatable_type_p (type1); + case CPTK_IS_UNBOUNDED_ARRAY: return array_of_unknown_bound_p (type1); @@ -13702,18 +13735,6 @@ same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2) (non_reference (to), non_reference (from)))); } -/* [defns.referenceable] True iff TYPE is a referenceable type. */ - -static bool -referenceable_type_p (const_tree type) -{ - return (TYPE_REF_P (type) - || object_type_p (type) - || (FUNC_OR_METHOD_TYPE_P (type) - && (type_memfn_quals (type) == TYPE_UNQUALIFIED - && type_memfn_rqual (type) == REF_QUAL_NONE))); -} - /* Process a trait expression. */ tree @@ -13762,8 +13783,11 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_LITERAL_TYPE: case CPTK_IS_POD: case CPTK_IS_STD_LAYOUT: + case CPTK_IS_REPLACEABLE: + case CPTK_IS_NOTHROW_RELOCATABLE: case CPTK_IS_TRIVIAL: case CPTK_IS_TRIVIALLY_COPYABLE: + case CPTK_IS_TRIVIALLY_RELOCATABLE: case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: if (!check_trait_type (type1, /* kind = */ 2)) return error_mark_node; diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 5863b68..a7b8908 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -488,6 +488,7 @@ builtin_valid_in_constant_expr_p (const_tree decl) case CP_BUILT_IN_SOURCE_LOCATION: case CP_BUILT_IN_IS_CORRESPONDING_MEMBER: case CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS: + case CP_BUILT_IN_EH_PTR_ADJUST_REF: return true; default: break; @@ -4715,6 +4716,293 @@ trivial_type_p (const_tree t) return scalarish_type_p (t); } +/* Returns 1 iff type T is a default-movable type, as defined in + [class.prop]. */ + +static bool +default_movable_type_p (tree t) +{ + if (!CLASS_TYPE_P (t) || !COMPLETE_TYPE_P (t)) + return false; + if (CLASSTYPE_LAZY_DESTRUCTOR (t)) + lazily_declare_fn (sfk_destructor, t); + if (tree dtor = CLASSTYPE_DESTRUCTOR (t)) + if (user_provided_p (dtor) || DECL_DELETED_FN (dtor)) + return false; + + tree copy_ctor = NULL_TREE, move_ctor = NULL_TREE; + tree copy_assign = NULL_TREE, move_assign = NULL_TREE; + if (CLASSTYPE_LAZY_MOVE_CTOR (t)) + move_ctor = lazily_declare_fn (sfk_move_constructor, t); + if (CLASSTYPE_LAZY_MOVE_ASSIGN (t)) + move_assign = lazily_declare_fn (sfk_move_assignment, t); + if (!move_ctor) + for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter) + if (TREE_CODE (*iter) == FUNCTION_DECL) + { + if (copy_fn_p (*iter)) + copy_ctor = *iter; + else if (move_fn_p (*iter)) + { + move_ctor = *iter; + break; + } + } + if (!move_assign) + for (ovl_iterator iter (get_class_binding_direct (t, + assign_op_identifier)); + iter; ++iter) + if (TREE_CODE (*iter) == FUNCTION_DECL) + { + if (copy_fn_p (*iter)) + copy_assign = *iter; + else if (move_fn_p (*iter)) + { + move_assign = *iter; + break; + } + } + if (!move_ctor) + { + if (CLASSTYPE_LAZY_COPY_CTOR (t)) + copy_ctor = lazily_declare_fn (sfk_copy_constructor, t); + if (!copy_ctor) + return false; + if (user_provided_p (copy_ctor) + || DECL_DELETED_FN (copy_ctor) + || DECL_CONTEXT (copy_ctor) != t + || DECL_INHERITED_CTOR (copy_ctor)) + return false; + } + else if (user_provided_p (move_ctor) + || DECL_DELETED_FN (move_ctor) + || DECL_CONTEXT (move_ctor) != t + || DECL_INHERITED_CTOR (move_ctor)) + return false; + if (!move_assign) + { + if (CLASSTYPE_LAZY_COPY_ASSIGN (t)) + copy_assign = lazily_declare_fn (sfk_copy_assignment, t); + if (!copy_assign) + return false; + if (user_provided_p (copy_assign) + || DECL_DELETED_FN (copy_assign) + || DECL_CONTEXT (copy_assign) != t) + return false; + } + else if (user_provided_p (move_assign) + || DECL_DELETED_FN (move_assign) + || DECL_CONTEXT (move_assign) != t) + return false; + return true; +} + +/* Returns 1 iff type T is a union with no user declared special member + functions. */ + +static bool +union_with_no_declared_special_member_fns (tree t) +{ + if (TREE_CODE (t) != UNION_TYPE) + return false; + + for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter) + if (TREE_CODE (*iter) == FUNCTION_DECL + && !DECL_ARTIFICIAL (*iter) + && (default_ctor_p (*iter) || copy_fn_p (*iter) || move_fn_p (*iter))) + return false; + + for (ovl_iterator iter (get_class_binding_direct (t, assign_op_identifier)); + iter; ++iter) + if (TREE_CODE (*iter) == FUNCTION_DECL + && !DECL_ARTIFICIAL (*iter) + && (copy_fn_p (*iter) || move_fn_p (*iter))) + return false; + + if (tree dtor = CLASSTYPE_DESTRUCTOR (t)) + if (!DECL_ARTIFICIAL (dtor)) + return false; + + return true; +} + +/* Returns 1 iff type T is a trivially relocatable type, as defined in + [basic.types.general] and [class.prop]. */ + +bool +trivially_relocatable_type_p (tree t) +{ + t = strip_array_types (t); + + if (!CLASS_TYPE_P (t)) + return scalarish_type_p (t); + + t = TYPE_MAIN_VARIANT (t); + if (CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED (t)) + return CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (t); + if (!COMPLETE_TYPE_P (t)) + return false; + + if (!CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (t) + && !union_with_no_declared_special_member_fns (t) + && !default_movable_type_p (t)) + { + nontriv: + CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (t) = 0; + CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED (t) = 1; + return false; + } + + if (CLASSTYPE_VBASECLASSES (t)) + goto nontriv; + + if (CLASSTYPE_LAZY_DESTRUCTOR (t)) + lazily_declare_fn (sfk_destructor, t); + if (tree dtor = CLASSTYPE_DESTRUCTOR (t)) + if (DECL_DELETED_FN (dtor)) + goto nontriv; + + tree binfo, base_binfo; + unsigned int i; + for (binfo = TYPE_BINFO (t), i = 0; + BINFO_BASE_ITERATE (binfo, i, base_binfo); i++) + { + tree basetype = TREE_TYPE (base_binfo); + if (!trivially_relocatable_type_p (basetype)) + goto nontriv; + } + + for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) + if (TREE_CODE (field) == FIELD_DECL + && !DECL_ARTIFICIAL (field) + && !DECL_UNNAMED_BIT_FIELD (field)) + { + tree type = TREE_TYPE (field); + if (type == error_mark_node) + goto nontriv; + if (!TYPE_REF_P (type) && !trivially_relocatable_type_p (type)) + goto nontriv; + } + + CLASSTYPE_TRIVIALLY_RELOCATABLE_BIT (t) = 1; + CLASSTYPE_TRIVIALLY_RELOCATABLE_COMPUTED (t) = 1; + return true; +} + +/* Returns 1 iff type T is a replaceable type, as defined in [basic.types] + and [class]. */ + +bool +replaceable_type_p (tree t) +{ + t = strip_array_types (t); + + if (cv_qualified_p (t)) + return false; + + if (!CLASS_TYPE_P (t)) + return scalarish_type_p (t); + + t = TYPE_MAIN_VARIANT (t); + if (CLASSTYPE_REPLACEABLE_COMPUTED (t)) + return CLASSTYPE_REPLACEABLE_BIT (t); + if (!COMPLETE_TYPE_P (t)) + return false; + + if (!CLASSTYPE_REPLACEABLE_BIT (t) + && !union_with_no_declared_special_member_fns (t) + && !default_movable_type_p (t)) + { + nonrepl: + CLASSTYPE_REPLACEABLE_BIT (t) = 0; + CLASSTYPE_REPLACEABLE_COMPUTED (t) = 1; + return false; + } + + if (CLASSTYPE_LAZY_DESTRUCTOR (t)) + lazily_declare_fn (sfk_destructor, t); + if (tree dtor = CLASSTYPE_DESTRUCTOR (t)) + if (DECL_DELETED_FN (dtor)) + goto nonrepl; + + tree copy_ctor = NULL_TREE, move_ctor = NULL_TREE; + tree copy_assign = NULL_TREE, move_assign = NULL_TREE; + if (CLASSTYPE_LAZY_MOVE_CTOR (t)) + move_ctor = lazily_declare_fn (sfk_move_constructor, t); + if (CLASSTYPE_LAZY_MOVE_ASSIGN (t)) + move_assign = lazily_declare_fn (sfk_move_assignment, t); + if (!move_ctor) + for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter) + if (TREE_CODE (*iter) == FUNCTION_DECL) + { + if (copy_fn_p (*iter)) + copy_ctor = *iter; + else if (move_fn_p (*iter)) + { + move_ctor = *iter; + break; + } + } + if (!move_assign) + for (ovl_iterator iter (get_class_binding_direct (t, + assign_op_identifier)); + iter; ++iter) + if (TREE_CODE (*iter) == FUNCTION_DECL) + { + if (copy_fn_p (*iter)) + copy_assign = *iter; + else if (move_fn_p (*iter)) + { + move_assign = *iter; + break; + } + } + if (!move_ctor) + { + if (CLASSTYPE_LAZY_COPY_CTOR (t)) + copy_ctor = lazily_declare_fn (sfk_copy_constructor, t); + if (!copy_ctor || DECL_DELETED_FN (copy_ctor)) + goto nonrepl; + } + else if (DECL_DELETED_FN (move_ctor)) + goto nonrepl; + if (!move_assign) + { + if (CLASSTYPE_LAZY_COPY_ASSIGN (t)) + copy_assign = lazily_declare_fn (sfk_copy_assignment, t); + if (!copy_assign || DECL_DELETED_FN (copy_assign)) + goto nonrepl; + } + else if (DECL_DELETED_FN (move_assign)) + goto nonrepl; + + tree binfo, base_binfo; + unsigned int i; + for (binfo = TYPE_BINFO (t), i = 0; + BINFO_BASE_ITERATE (binfo, i, base_binfo); i++) + { + tree basetype = TREE_TYPE (base_binfo); + if (!replaceable_type_p (basetype)) + goto nonrepl; + } + + for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) + if (TREE_CODE (field) == FIELD_DECL + && !DECL_ARTIFICIAL (field) + && !DECL_UNNAMED_BIT_FIELD (field)) + { + tree type = TREE_TYPE (field); + if (type == error_mark_node) + goto nonrepl; + if (!replaceable_type_p (type)) + goto nonrepl; + } + + CLASSTYPE_REPLACEABLE_BIT (t) = 1; + CLASSTYPE_REPLACEABLE_COMPUTED (t) = 1; + return true; +} + /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */ bool diff --git a/gcc/diagnostic-digraphs.cc b/gcc/diagnostic-digraphs.cc new file mode 100644 index 0000000..85c0c51 --- /dev/null +++ b/gcc/diagnostic-digraphs.cc @@ -0,0 +1,484 @@ +/* Directed graphs associated with a diagnostic. + 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/>. */ + +#define INCLUDE_ALGORITHM +#define INCLUDE_MAP +#define INCLUDE_SET +#define INCLUDE_STRING +#define INCLUDE_VECTOR +#include "config.h" +#include "system.h" +#include "coretypes.h" + +#include "graphviz.h" +#include "diagnostic-digraphs.h" +#include "diagnostic-format-sarif.h" + +#include "selftest.h" + +using digraph = diagnostics::digraphs::digraph; +using digraph_node = diagnostics::digraphs::node; +using digraph_edge = diagnostics::digraphs::edge; + +namespace { + +class conversion_to_dot +{ +public: + std::unique_ptr<dot::graph> + make_dot_graph_from_diagnostic_graph (const digraph &); + + std::unique_ptr<dot::stmt> + make_dot_node_from_digraph_node (const digraph_node &); + + std::unique_ptr<dot::edge_stmt> + make_dot_edge_from_digraph_edge (const digraph_edge &); + + dot::id + get_dot_id_for_node (const digraph_node &); + + bool + has_edges_p (const digraph_node &); + +private: + std::set<const digraph_node *> m_nodes_with_edges; + std::map<const digraph_node *, dot::stmt *> m_node_map; +}; + +} // anonymous namespace + +// class conversion_to_dot + +std::unique_ptr<dot::graph> +conversion_to_dot:: +make_dot_graph_from_diagnostic_graph (const diagnostics::digraphs::digraph &input_graph) +{ + auto output_graph = std::make_unique<dot::graph> (); + + if (const char *description = input_graph.get_description ()) + output_graph->m_stmt_list.add_attr (dot::id ("label"), + dot::id (description)); + + const int num_nodes = input_graph.get_num_nodes (); + const int num_edges = input_graph.get_num_edges (); + + /* Determine which nodes have in-edges and out-edges. */ + for (int i = 0; i < num_edges; ++i) + { + const digraph_edge &input_edge = input_graph.get_edge (i); + m_nodes_with_edges.insert (&input_edge.get_src_node ()); + m_nodes_with_edges.insert (&input_edge.get_dst_node ()); + } + + for (int i = 0; i < num_nodes; ++i) + { + const digraph_node &input_node = input_graph.get_node (i); + auto dot_node_stmt = make_dot_node_from_digraph_node (input_node); + output_graph->m_stmt_list.add_stmt (std::move (dot_node_stmt)); + } + + for (int i = 0; i < num_edges; ++i) + { + const digraph_edge &input_edge = input_graph.get_edge (i); + auto dot_edge_stmt = make_dot_edge_from_digraph_edge (input_edge); + output_graph->m_stmt_list.add_stmt (std::move (dot_edge_stmt)); + } + + return output_graph; +} + +std::unique_ptr<dot::stmt> +conversion_to_dot:: +make_dot_node_from_digraph_node (const diagnostics::digraphs::node &input_node) +{ + dot::id dot_id (get_dot_id_for_node (input_node)); + + /* For now, we can only do either edges or children, not both + ...but see https://graphviz.org/docs/attrs/compound/ */ + + if (has_edges_p (input_node)) + { + auto output_node + = std::make_unique<dot::node_stmt> (std::move (dot_id)); + m_node_map[&input_node] = output_node.get (); + if (const char *label = input_node.get_label ()) + output_node->set_label (dot::id (label)); + return output_node; + } + else + { + auto output_node = std::make_unique<dot::subgraph> (std::move (dot_id)); + m_node_map[&input_node] = output_node.get (); + if (const char *label = input_node.get_label ()) + output_node->add_attr (dot::id ("label"), dot::id (label)); + const int num_children = input_node.get_num_children (); + for (int i = 0; i < num_children; ++i) + { + const digraph_node &input_child = input_node.get_child (i); + auto dot_child_stmt = make_dot_node_from_digraph_node (input_child); + output_node->m_stmt_list.add_stmt (std::move (dot_child_stmt)); + } + return output_node; + } +} + +std::unique_ptr<dot::edge_stmt> +conversion_to_dot:: +make_dot_edge_from_digraph_edge (const digraph_edge &input_edge) +{ + const digraph_node &src_dnode = input_edge.get_src_node (); + const digraph_node &dst_dnode = input_edge.get_dst_node (); + auto output_edge + = std::make_unique<dot::edge_stmt> + (get_dot_id_for_node (src_dnode), + get_dot_id_for_node (dst_dnode)); + if (const char *label = input_edge.get_label ()) + output_edge->set_label (dot::id (label)); + return output_edge; +} + +dot::id +conversion_to_dot::get_dot_id_for_node (const digraph_node &input_node) +{ + if (has_edges_p (input_node)) + return input_node.get_id (); + else + return std::string ("cluster_") + input_node.get_id (); +} + +bool +conversion_to_dot::has_edges_p (const digraph_node &input_node) +{ + return m_nodes_with_edges.find (&input_node) != m_nodes_with_edges.end (); +} + +// class object + +const char * +diagnostics::digraphs::object:: +get_attr (const char *key_prefix, const char *key) const +{ + if (!m_property_bag) + return nullptr; + std::string prefixed_key = std::string (key_prefix) + key; + if (json::value *jv = m_property_bag->get (prefixed_key.c_str ())) + if (json::string *jstr = jv->dyn_cast_string ()) + return jstr->get_string (); + return nullptr; +} + +void +diagnostics::digraphs::object:: +set_attr (const char *key_prefix, const char *key, const char *value) +{ + set_json_attr (key_prefix, key, std::make_unique<json::string> (value)); +} + +void +diagnostics::digraphs::object:: +set_json_attr (const char *key_prefix, const char *key, std::unique_ptr<json::value> value) +{ + std::string prefixed_key = std::string (key_prefix) + key; + if (!m_property_bag) + m_property_bag = std::make_unique<json::object> (); + m_property_bag->set (prefixed_key.c_str (), std::move (value)); +} + +// class digraph + +DEBUG_FUNCTION void +diagnostics::digraphs::digraph::dump () const +{ + make_json_sarif_graph ()->dump (); +} + +std::unique_ptr<json::object> +diagnostics::digraphs::digraph::make_json_sarif_graph () const +{ + return make_sarif_graph (*this, nullptr, nullptr); +} + +std::unique_ptr<dot::graph> +diagnostics::digraphs::digraph::make_dot_graph () const +{ + conversion_to_dot to_dot; + return to_dot.make_dot_graph_from_diagnostic_graph (*this); +} + +std::unique_ptr<diagnostics::digraphs::digraph> +diagnostics::digraphs::digraph::clone () const +{ + auto result = std::make_unique<diagnostics::digraphs::digraph> (); + + if (get_property_bag ()) + result->set_property_bag (get_property_bag ()->clone_as_object ()); + + std::map<diagnostics::digraphs::node *, diagnostics::digraphs::node *> node_mapping; + + for (auto &iter : m_nodes) + result->add_node (iter->clone (*result, node_mapping)); + for (auto &iter : m_edges) + result->add_edge (iter->clone (*result, node_mapping)); + + return result; +} + +void +diagnostics::digraphs::digraph::add_edge (const char *id, + node &src_node, + node &dst_node, + const char *label) +{ + auto e = std::make_unique<digraph_edge> (*this, + id, + src_node, + dst_node); + if (label) + e->set_label (label); + add_edge (std::move (e)); +} + +/* Utility function for edge ids: either use EDGE_ID, or + generate a unique one for when we don't care about the name. + + Edges in SARIF "SHALL" have an id that's unique within the graph + (SARIF 2.1.0 §3.41.2). This is so that graph traversals can refer + to edges by id (SARIF 2.1.0's §3.43.2 edgeId property). */ + +std::string +diagnostics::digraphs::digraph::make_edge_id (const char *edge_id) +{ + /* If we have an id, use it. */ + if (edge_id) + return edge_id; + + /* Otherwise, generate a unique one of the form "edgeN". */ + while (true) + { + auto candidate (std::string ("edge") + + std::to_string (m_next_edge_id_index++)); + auto iter = m_id_to_edge_map.find (candidate); + if (iter != m_id_to_edge_map.end ()) + { + // Try again with the next index... + continue; + } + return candidate; + } +} + +// class node + +DEBUG_FUNCTION void +diagnostics::digraphs::node::dump () const +{ + to_json_sarif_node ()->dump (); +} + +std::unique_ptr<json::object> +diagnostics::digraphs::node::to_json_sarif_node () const +{ + return make_sarif_node (*this, nullptr, nullptr); +} + +std::unique_ptr<diagnostics::digraphs::node> +diagnostics::digraphs::node::clone (digraph &new_graph, + std::map<node *, node *> &node_mapping) const +{ + auto result + = std::make_unique<diagnostics::digraphs::node> (new_graph, + get_id ()); + node_mapping.insert ({const_cast <node *> (this), result.get ()}); + + result->set_logical_loc (m_logical_loc); + + if (get_property_bag ()) + result->set_property_bag (get_property_bag ()->clone_as_object ()); + + for (auto &iter : m_children) + result->add_child (iter->clone (new_graph, node_mapping)); + + return result; +} + +// class edge + +std::unique_ptr<digraph_edge> +digraph_edge::clone (digraph &new_graph, + const std::map<node *, node *> &node_mapping) const +{ + auto iter_new_src = node_mapping.find (&m_src_node); + gcc_assert (iter_new_src != node_mapping.end ()); + auto iter_new_dst = node_mapping.find (&m_dst_node); + gcc_assert (iter_new_dst != node_mapping.end ()); + auto result + = std::make_unique<digraph_edge> (new_graph, + m_id.c_str (), + *iter_new_src->second, + *iter_new_dst->second); + if (get_property_bag ()) + result->set_property_bag (get_property_bag ()->clone_as_object ()); + + return result; +} + +DEBUG_FUNCTION void +diagnostics::digraphs::edge::dump () const +{ + to_json_sarif_edge ()->dump (); +} + +std::unique_ptr<json::object> +diagnostics::digraphs::edge::to_json_sarif_edge () const +{ + return make_sarif_edge (*this, nullptr); +} + +// class lazy_digraph + +const diagnostics::digraphs::digraph & +diagnostics::digraphs::lazy_digraph::get_or_create_digraph () const +{ + if (!m_digraph) + m_digraph = create_digraph (); + gcc_assert (m_digraph); + return *m_digraph; +} + +// class lazy_digraphs + +const std::vector<std::unique_ptr<diagnostics::digraphs::digraph>> & +diagnostics::digraphs::lazy_digraphs::get_or_create_digraphs () const +{ + if (!m_digraphs) + m_digraphs = create_digraphs (); + gcc_assert (m_digraphs); + return *m_digraphs; +} + +#if CHECKING_P + +namespace selftest { + +static void +test_empty_graph () +{ + digraph g; + + { + auto sarif = g.make_json_sarif_graph (); + + pretty_printer pp; + sarif->print (&pp, true); + ASSERT_STREQ + (pp_formatted_text (&pp), + ("{\"nodes\": [],\n" + " \"edges\": []}")); + } + + { + auto dg = g.make_dot_graph (); + + pretty_printer pp; + dot::writer w (pp); + dg->print (w); + ASSERT_STREQ + (pp_formatted_text (&pp), + ("digraph {\n" + "}\n")); + } +} + +static void +test_simple_graph () +{ +#define KEY_PREFIX "/placeholder/" + auto g = std::make_unique<digraph> (); + g->set_description ("test graph"); + g->set_attr (KEY_PREFIX, "date", "1066"); + + auto a = std::make_unique<digraph_node> (*g, "a"); + auto b = std::make_unique<digraph_node> (*g, "b"); + b->set_attr (KEY_PREFIX, "color", "red"); + auto c = std::make_unique<digraph_node> (*g, "c"); + c->set_label ("I am a node label"); + + auto e = std::make_unique<digraph_edge> (*g, nullptr, *a, *c); + e->set_attr (KEY_PREFIX, "status", "copacetic"); + e->set_label ("I am an edge label"); + g->add_edge (std::move (e)); + + g->add_node (std::move (a)); + + b->add_child (std::move (c)); + g->add_node (std::move (b)); +#undef KEY_PREFIX + + { + auto sarif = g->make_json_sarif_graph (); + + pretty_printer pp; + sarif->print (&pp, true); + ASSERT_STREQ + (pp_formatted_text (&pp), + ("{\"properties\": {\"/placeholder/date\": \"1066\"},\n" + " \"nodes\": [{\"id\": \"a\"},\n" + " {\"id\": \"b\",\n" + " \"properties\": {\"/placeholder/color\": \"red\"},\n" + " \"children\": [{\"id\": \"c\"}]}],\n" + " \"edges\": [{\"id\": \"edge0\",\n" + " \"properties\": {\"/placeholder/status\": \"copacetic\"},\n" + " \"sourceNodeId\": \"a\",\n" + " \"targetNodeId\": \"c\"}]}")); + } + + { + auto dg = g->make_dot_graph (); + + pretty_printer pp; + dot::writer w (pp); + dg->print (w); + ASSERT_STREQ + (pp_formatted_text (&pp), + ("digraph {\n" + " label=\"test graph\";\n" + " a;\n" + " \n" + " subgraph cluster_b {\n" + " c [label=\"I am a node label\"];\n" + "\n" + " };\n" + " a -> c [label=\"I am an edge label\"];\n" + "}\n")); + } +} + +/* Run all of the selftests within this file. */ + +void +diagnostic_digraphs_cc_tests () +{ + test_empty_graph (); + test_simple_graph (); +} + +} // namespace selftest + +#endif /* CHECKING_P */ diff --git a/gcc/diagnostic-digraphs.h b/gcc/diagnostic-digraphs.h new file mode 100644 index 0000000..94cb76e --- /dev/null +++ b/gcc/diagnostic-digraphs.h @@ -0,0 +1,411 @@ +/* Directed graphs associated with a diagnostic. + 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_DIAGNOSTIC_DIGRAPHS_H +#define GCC_DIAGNOSTIC_DIGRAPHS_H + +#include "json.h" +#include "logical-location.h" + +class graphviz_out; + +class sarif_graph; +class sarif_node; +class sarif_edge; + +namespace dot { class graph; } + +namespace diagnostics { +namespace digraphs { + +/* A family of classes: digraph, node, and edge, closely related to + SARIF's graph, node, and edge types (SARIF v2.1.0 sections 3.39-3.41). + + Nodes can have child nodes, allowing for arbitrarily deep nesting. + Edges can be between any pair of nodes (potentially at different + nesting levels). + + Digraphs, nodes, and edges also optionally have a JSON property bag, + allowing round-tripping of arbitrary key/value pairs through SARIF. */ + +class digraph; +class node; +class edge; + +/* A base class for digraph, node, and edge to allow them to have + an optional JSON property bag. */ + +class object +{ +public: + const char * + get_attr (const char *key_prefix, + const char *key) const; + + void + set_attr (const char *key_prefix, + const char *key, + const char *value); + + void + set_json_attr (const char *key_prefix, + const char *key, + std::unique_ptr<json::value> value); + + json::object * + get_property_bag () const { return m_property_bag.get (); } + + void + set_property_bag (std::unique_ptr<json::object> property_bag) + { + m_property_bag = std::move (property_bag); + } + +private: + std::unique_ptr<json::object> m_property_bag; +}; + +// A directed graph, corresponding to SARIF v2.1.0 section 3.39. + +class digraph : public object +{ + public: + friend class node; + friend class edge; + + digraph () : m_next_edge_id_index (0) {} + virtual ~digraph () {} + + const char * + get_description () const + { + if (!m_description) + return nullptr; + return m_description->c_str (); + } + + void + set_description (const char *desc) + { + if (desc) + m_description = std::make_unique<std::string> (desc); + else + m_description = nullptr; + } + + node * + get_node_by_id (const char *id) const + { + auto iter = m_id_to_node_map.find (id); + if (iter == m_id_to_node_map.end ()) + return nullptr; + return iter->second; + } + + edge * + get_edge_by_id (const char *id) const + { + auto iter = m_id_to_edge_map.find (id); + if (iter == m_id_to_edge_map.end ()) + return nullptr; + return iter->second; + } + + size_t + get_num_nodes () const + { + return m_nodes.size (); + } + + node & + get_node (size_t idx) const + { + return *m_nodes[idx].get (); + } + + size_t + get_num_edges () const + { + return m_edges.size (); + } + + edge & + get_edge (size_t idx) const + { + return *m_edges[idx].get (); + } + + void + dump () const; + + std::unique_ptr<json::object> + make_json_sarif_graph () const; + + std::unique_ptr<dot::graph> + make_dot_graph () const; + + void + add_node (std::unique_ptr<node> n) + { + gcc_assert (n); + m_nodes.push_back (std::move (n)); + } + + void + add_edge (std::unique_ptr<edge> e) + { + gcc_assert (e); + m_edges.push_back (std::move (e)); + } + + void + add_edge (const char *id, + node &src_node, + node &dst_node, + const char *label = nullptr); + + std::unique_ptr<digraph> clone () const; + + private: + void + add_node_id (std::string node_id, node &new_node) + { + m_id_to_node_map.insert ({std::move (node_id), &new_node}); + } + void + add_edge_id (std::string edge_id, edge &new_edge) + { + m_id_to_edge_map.insert ({std::move (edge_id), &new_edge}); + } + + std::string + make_edge_id (const char *edge_id); + + std::unique_ptr<std::string> m_description; + std::map<std::string, node *> m_id_to_node_map; + std::map<std::string, edge *> m_id_to_edge_map; + std::vector<std::unique_ptr<node>> m_nodes; + std::vector<std::unique_ptr<edge>> m_edges; + size_t m_next_edge_id_index; +}; + +// A node in a directed graph, corresponding to SARIF v2.1.0 section 3.40. + +class node : public object +{ + public: + virtual ~node () {} + + node (digraph &g, std::string id) + : m_id (id), + m_physical_loc (UNKNOWN_LOCATION) + { + g.add_node_id (std::move (id), *this); + } + node (const node &) = delete; + + std::string + get_id () const { return m_id; } + + const char * + get_label () const + { + if (!m_label) + return nullptr; + return m_label->c_str (); + } + + void + set_label (const char *label) + { + if (label) + m_label = std::make_unique<std::string> (label); + else + m_label = nullptr; + } + + size_t + get_num_children () const { return m_children.size (); } + + node & + get_child (size_t idx) const { return *m_children[idx].get (); } + + void + add_child (std::unique_ptr<node> child) + { + gcc_assert (child); + m_children.push_back (std::move (child)); + } + + location_t + get_physical_loc () const + { + return m_physical_loc; + } + + void + set_physical_loc (location_t physical_loc) + { + m_physical_loc = physical_loc; + } + + logical_location + get_logical_loc () const + { + return m_logical_loc; + } + + void + set_logical_loc (logical_location logical_loc) + { + m_logical_loc = logical_loc; + } + + void print (graphviz_out &gv) const; + + void + dump () const; + + std::unique_ptr<json::object> + to_json_sarif_node () const; + + std::unique_ptr<node> + clone (digraph &new_graph, + std::map<node *, node *> &node_mapping) const; + + private: + std::string m_id; + std::unique_ptr<std::string> m_label; + std::vector<std::unique_ptr<node>> m_children; + location_t m_physical_loc; + logical_location m_logical_loc; +}; + +// An edge in a directed graph, corresponding to SARIF v2.1.0 section 3.41. + +class edge : public object +{ + public: + virtual ~edge () {} + + /* SARIF requires us to provide unique edge IDs within a graph, + but otherwise we don't need them. + Pass in nullptr for the id to get the graph to generate a unique + edge id for us. */ + edge (digraph &g, + const char *id, + node &src_node, + node &dst_node) + : m_id (g.make_edge_id (id)), + m_src_node (src_node), + m_dst_node (dst_node) + { + g.add_edge_id (m_id, *this); + } + + std::string + get_id () const { return m_id; } + + const char * + get_label () const + { + if (!m_label) + return nullptr; + return m_label->c_str (); + } + + void + set_label (const char *label) + { + if (label) + m_label = std::make_unique<std::string> (label); + else + m_label = nullptr; + } + + node & + get_src_node () const { return m_src_node; } + + node & + get_dst_node () const { return m_dst_node; } + + void + dump () const; + + std::unique_ptr<json::object> + to_json_sarif_edge () const; + + std::unique_ptr<edge> + clone (digraph &new_graph, + const std::map<diagnostics::digraphs::node *, diagnostics::digraphs::node *> &node_mapping) const; + +private: + std::string m_id; + std::unique_ptr<std::string> m_label; + node &m_src_node; + node &m_dst_node; +}; + +/* Abstract base class for lazily creating + a digraph on demand. + + This allows us to avoid the work of creating the digraph for + the common case where we just have a text sink. */ + +class lazy_digraph +{ +public: + virtual ~lazy_digraph () {} + + const digraph & + get_or_create_digraph () const; + +private: + virtual std::unique_ptr<digraph> + create_digraph () const = 0; + + mutable std::unique_ptr<digraph> m_digraph; +}; + +/* Abstract base class for lazily creating a collection of + digraphs on demand. + + This allows us to avoid the work of creating the digraphs for + the common case where we just have a text sink. */ + +class lazy_digraphs +{ +public: + virtual ~lazy_digraphs () {} + + const std::vector<std::unique_ptr<digraph>> & + get_or_create_digraphs () const; + +private: + virtual std::unique_ptr<std::vector<std::unique_ptr<digraph>>> + create_digraphs () const = 0; + + mutable std::unique_ptr<std::vector<std::unique_ptr<digraph>>> m_digraphs; +}; + +} // namespace digraphs +} // namespace diagnostics + +#endif /* ! GCC_DIAGNOSTIC_DIGRAPHS_H */ diff --git a/gcc/diagnostic-format-html.cc b/gcc/diagnostic-format-html.cc index 473880f..becac39 100644 --- a/gcc/diagnostic-format-html.cc +++ b/gcc/diagnostic-format-html.cc @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-format.h" #include "diagnostic-format-html.h" #include "diagnostic-format-text.h" +#include "diagnostic-format-sarif.h" #include "diagnostic-output-file.h" #include "diagnostic-buffer.h" #include "diagnostic-path.h" @@ -41,7 +42,8 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "xml.h" #include "xml-printer.h" -#include "diagnostic-state.h" +#include "diagnostic-digraphs.h" +#include "diagnostic-state-graphs.h" #include "graphviz.h" #include "json.h" #include "selftest-xml.h" @@ -52,8 +54,8 @@ html_generation_options::html_generation_options () : m_css (true), m_javascript (true), m_show_state_diagrams (false), - m_show_state_diagram_xml (false), - m_show_state_diagram_dot_src (false) + m_show_state_diagrams_sarif (false), + m_show_state_diagrams_dot_src (false) { } @@ -119,6 +121,8 @@ public: diagnostic_t orig_diag_kind, diagnostic_html_format_buffer *buffer); void emit_diagram (const diagnostic_diagram &diagram); + void emit_global_graph (const diagnostics::digraphs::lazy_digraph &); + void end_group (); std::unique_ptr<xml::element> take_current_diagnostic () @@ -172,6 +176,10 @@ private: void pop_nesting_level (); + void + add_graph (const diagnostics::digraphs::digraph &dg, + xml::element &parent_element); + diagnostic_context &m_context; pretty_printer *m_printer; const line_maps *m_line_maps; @@ -181,6 +189,7 @@ private: std::unique_ptr<xml::document> m_document; xml::element *m_head_element; xml::element *m_title_element; + xml::element *m_body_element; xml::element *m_diagnostics_element; std::unique_ptr<xml::element> m_cur_diagnostic_element; std::vector<xml::element *> m_cur_nesting_levels; @@ -401,6 +410,7 @@ html_builder::html_builder (diagnostic_context &context, m_logical_loc_mgr (nullptr), m_head_element (nullptr), m_title_element (nullptr), + m_body_element (nullptr), m_diagnostics_element (nullptr), m_next_diag_id (0), m_last_location (UNKNOWN_LOCATION), @@ -447,6 +457,7 @@ html_builder::html_builder (diagnostic_context &context, { xml::auto_print_element body (xp, "body"); + m_body_element = xp.get_insertion_point (); { auto diagnostics_element = make_div ("gcc-diagnostic-list"); m_diagnostics_element = diagnostics_element.get (); @@ -599,39 +610,45 @@ html_builder::maybe_make_state_diagram (const diagnostic_event &event) if (!m_html_gen_opts.m_show_state_diagrams) return nullptr; - /* Get XML state document; if we're going to print it later, also request + if (!m_logical_loc_mgr) + return nullptr; + + /* Get state graph; if we're going to print it later, also request the debug version. */ - auto xml_state - = event.maybe_make_xml_state (m_html_gen_opts.m_show_state_diagram_xml); - if (!xml_state) + auto state_graph + = event.maybe_make_diagnostic_state_graph + (m_html_gen_opts.m_show_state_diagrams_sarif); + if (!state_graph) return nullptr; // Convert it to .dot AST - auto graph = make_dot_graph_from_xml_state (*xml_state); - gcc_assert (graph); + auto dot_graph + = diagnostics::state_graphs::make_dot_graph (*state_graph, + *m_logical_loc_mgr); + gcc_assert (dot_graph); auto wrapper = std::make_unique<xml::element> ("div", false); xml::printer xp (*wrapper); - if (m_html_gen_opts.m_show_state_diagram_xml) + if (m_html_gen_opts.m_show_state_diagrams_sarif) { - // For debugging, show the XML src inline: + // For debugging, show the SARIF src inline: pretty_printer pp; - xml_state->write_as_xml (&pp, 0, true); + state_graph->make_json_sarif_graph ()->print (&pp, true); print_pre_source (xp, pp_formatted_text (&pp)); } - if (m_html_gen_opts.m_show_state_diagram_dot_src) + if (m_html_gen_opts.m_show_state_diagrams_dot_src) { // For debugging, show the dot src inline: pretty_printer pp; dot::writer w (pp); - graph->print (w); + dot_graph->print (w); print_pre_source (xp, pp_formatted_text (&pp)); } // Turn the .dot into SVG and splice into place - auto svg = dot::make_svg_from_graph (*graph); + auto svg = dot::make_svg_from_graph (*dot_graph); if (svg) xp.append (std::move (svg)); @@ -1125,6 +1142,15 @@ html_builder::make_element_for_diagnostic (const diagnostic_info &diagnostic, gcc_assert (xp.get_num_open_tags () == depth_within_alert_div); + // Try to display any per-diagnostic graphs + if (diagnostic.metadata) + if (auto ldg = diagnostic.metadata->get_lazy_digraphs ()) + { + auto &digraphs = ldg->get_or_create_digraphs (); + for (auto &dg : digraphs) + add_graph (*dg, *xp.get_insertion_point ()); + } + if (auto patch_element = make_element_for_patch (diagnostic)) { xp.push_tag ("div"); @@ -1221,6 +1247,35 @@ html_builder::emit_diagram (const diagnostic_diagram &/*diagram*/) // TODO: currently a no-op } +void +html_builder::add_graph (const diagnostics::digraphs::digraph &dg, + xml::element &parent_element) +{ + if (auto dot_graph = dg.make_dot_graph ()) + if (auto svg_element = dot::make_svg_from_graph (*dot_graph)) + { + auto div = std::make_unique<xml::element> ("div", false); + div->set_attr ("class", "gcc-directed-graph"); + xml::printer xp (*div); + if (const char *description = dg.get_description ()) + { + xp.push_tag ("h2", true); + xp.add_text (description); + xp.pop_tag ("h2"); + } + xp.append (std::move (svg_element)); + parent_element.add_child (std::move (div)); + } +} + +void +html_builder::emit_global_graph (const diagnostics::digraphs::lazy_digraph &ldg) +{ + auto &dg = ldg.get_or_create_digraph (); + gcc_assert (m_body_element); + add_graph (dg, *m_body_element); +} + /* Implementation of "end_group_cb" for HTML output. */ void @@ -1334,6 +1389,12 @@ public: m_builder.set_printer (*get_printer ()); } + void + report_global_digraph (const diagnostics::digraphs::lazy_digraph &ldg) final override + { + m_builder.emit_global_graph (ldg); + } + const xml::document &get_document () const { return m_builder.get_document (); diff --git a/gcc/diagnostic-format-html.h b/gcc/diagnostic-format-html.h index 09a97e0..537ba54 100644 --- a/gcc/diagnostic-format-html.h +++ b/gcc/diagnostic-format-html.h @@ -36,11 +36,11 @@ struct html_generation_options // If true, attempt to show state diagrams at events bool m_show_state_diagrams; - // If true, show the XML form of the state with such diagrams - bool m_show_state_diagram_xml; + // If true, show the SARIF form of the state with such diagrams + bool m_show_state_diagrams_sarif; // If true, show the .dot source used for the diagram - bool m_show_state_diagram_dot_src; + bool m_show_state_diagrams_dot_src; }; extern diagnostic_output_file diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 14cdbc2..d20ca86 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -28,6 +28,8 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "diagnostic.h" #include "diagnostic-metadata.h" +#include "diagnostic-digraphs.h" +#include "diagnostic-state-graphs.h" #include "diagnostic-path.h" #include "diagnostic-format.h" #include "diagnostic-buffer.h" @@ -776,6 +778,9 @@ public: void emit_diagram (const diagnostic_diagram &diagram); void end_group (); + void + report_global_digraph (const diagnostics::digraphs::lazy_digraph &); + std::unique_ptr<sarif_result> take_current_result () { return std::move (m_cur_group_result); @@ -789,7 +794,7 @@ public: const diagnostic_info &diagnostic, enum diagnostic_artifact_role role); std::unique_ptr<sarif_location> - make_location_object (sarif_location_manager &loc_mgr, + make_location_object (sarif_location_manager *loc_mgr, const rich_location &rich_loc, logical_location logical_loc, enum diagnostic_artifact_role role); @@ -974,6 +979,8 @@ private: std::unique_ptr<sarif_array_of_unique<sarif_logical_location>> m_cached_logical_locs; + std::unique_ptr<sarif_array_of_unique<sarif_graph>> m_run_graphs; + int m_tabstop; std::unique_ptr<sarif_serialization_format> m_serialization_format; @@ -1305,7 +1312,7 @@ sarif_result::on_nested_diagnostic (const diagnostic_info &diagnostic, sometimes these will related to current_function_decl, but often they won't. */ auto location_obj - = builder.make_location_object (*this, *diagnostic.richloc, + = builder.make_location_object (this, *diagnostic.richloc, logical_location (), diagnostic_artifact_role::result_file); auto message_obj @@ -1663,6 +1670,8 @@ sarif_builder::sarif_builder (diagnostic_context &context, m_rules_arr (new json::array ()), m_cached_logical_locs (std::make_unique<sarif_array_of_unique<sarif_logical_location>> ()), + m_run_graphs + (std::make_unique<sarif_array_of_unique<sarif_graph>> ()), m_tabstop (context.m_tabstop), m_serialization_format (std::move (serialization_format)), m_sarif_gen_opts (sarif_gen_opts), @@ -1895,6 +1904,17 @@ sarif_builder::end_group () } } +void +sarif_builder:: +report_global_digraph (const diagnostics::digraphs::lazy_digraph &ldg) +{ + auto &dg = ldg.get_or_create_digraph (); + + /* Presumably the location manager must be nullptr; see + https://github.com/oasis-tcs/sarif-spec/issues/712 */ + m_run_graphs->append (make_sarif_graph (dg, this, nullptr)); +} + /* Create a top-level object, and add it to all the results (and other entities) we've seen so far, moving ownership to the object. */ @@ -2049,6 +2069,19 @@ sarif_builder::make_result_object (const diagnostic_info &diagnostic, result_obj->set<json::array> ("codeFlows", std::move (code_flows_arr)); } + // "graphs" property (SARIF v2.1.0 section 3.27.19). */ + if (diagnostic.metadata) + if (auto ldg = diagnostic.metadata->get_lazy_digraphs ()) + { + auto &digraphs = ldg->get_or_create_digraphs (); + auto graphs_arr = std::make_unique<json::array> (); + for (auto &iter : digraphs) + graphs_arr->append (make_sarif_graph (*iter, this, + result_obj.get ())); + if (graphs_arr->size () > 0) + result_obj->set<json::array> ("graphs", std::move (graphs_arr)); + } + /* The "relatedLocations" property (SARIF v2.1.0 section 3.27.22) is set up later, if any nested diagnostics occur within this diagnostic group. */ @@ -2176,7 +2209,7 @@ sarif_builder::make_locations_arr (sarif_location_manager &loc_mgr, logical_loc = client_data_hooks->get_current_logical_location (); auto location_obj - = make_location_object (loc_mgr, *diagnostic.richloc, logical_loc, role); + = make_location_object (&loc_mgr, *diagnostic.richloc, logical_loc, role); /* Don't add entirely empty location objects to the array. */ if (!location_obj->is_empty ()) locations_arr->append<sarif_location> (std::move (location_obj)); @@ -2210,10 +2243,12 @@ set_any_logical_locs_arr (sarif_location &location_obj, /* Make a "location" object (SARIF v2.1.0 section 3.28) for RICH_LOC and LOGICAL_LOC. Use LOC_MGR for any locations that need "id" values, and for - any worklist items. */ + any worklist items. + Note that we might not always have a LOC_MGR; see + https://github.com/oasis-tcs/sarif-spec/issues/712 */ std::unique_ptr<sarif_location> -sarif_builder::make_location_object (sarif_location_manager &loc_mgr, +sarif_builder::make_location_object (sarif_location_manager *loc_mgr, const rich_location &rich_loc, logical_location logical_loc, enum diagnostic_artifact_role role) @@ -2309,8 +2344,8 @@ sarif_builder::make_location_object (sarif_location_manager &loc_mgr, /* Add related locations for any secondary locations in RICH_LOC that don't have labels (and thus aren't added to "annotations"). */ - if (i > 0 && !handled) - loc_mgr.add_relationship_to_worklist + if (loc_mgr && i > 0 && !handled) + loc_mgr->add_relationship_to_worklist (*location_obj.get (), sarif_location_manager::worklist_item::kind::unlabelled_secondary_location, range->m_loc); @@ -2321,7 +2356,8 @@ sarif_builder::make_location_object (sarif_location_manager &loc_mgr, std::move (annotations_arr)); } - add_any_include_chain (loc_mgr, *location_obj.get (), loc); + if (loc_mgr) + add_any_include_chain (*loc_mgr, *location_obj.get (), loc); /* A flag for hinting that the diagnostic involves issues at the level of character encodings (such as homoglyphs, or misleading @@ -2799,6 +2835,142 @@ sarif_property_bag::set_logical_location (const char *property_name, builder.make_minimal_sarif_logical_location (logical_loc)); } +static void +copy_any_property_bag (const diagnostics::digraphs::object &input_obj, + sarif_object &output_obj) +{ + if (input_obj.get_property_bag ()) + { + const json::object &old_bag = *input_obj.get_property_bag (); + sarif_property_bag &new_bag = output_obj.get_or_create_properties (); + for (size_t i = 0; i < old_bag.get_num_keys (); ++i) + { + const char *key = old_bag.get_key (i); + json::value *val = old_bag.get (key); + new_bag.set (key, val->clone ()); + } + } +} + +std::unique_ptr<sarif_graph> +make_sarif_graph (const diagnostics::digraphs::digraph &g, + sarif_builder *builder, + sarif_location_manager *sarif_location_mgr) +{ + auto result = std::make_unique<sarif_graph> (); + + // 3.39.2 description property + if (const char *desc = g.get_description ()) + if (builder) + result->set<sarif_message> ("description", + builder->make_message_object (desc)); + + copy_any_property_bag (g, *result); + + // 3.39.3 nodes property + auto nodes_arr = std::make_unique<json::array> (); + const int num_nodes = g.get_num_nodes (); + for (int i = 0; i < num_nodes; ++i) + nodes_arr->append (make_sarif_node (g.get_node (i), + builder, + sarif_location_mgr)); + result->set ("nodes", std::move (nodes_arr)); + + // 3.39.4 edges property + auto edges_arr = std::make_unique<json::array> (); + const int num_edges = g.get_num_edges (); + for (int i = 0; i < num_edges; ++i) + edges_arr->append (make_sarif_edge (g.get_edge (i), builder)); + result->set ("edges", std::move (edges_arr)); + + return result; +} + +std::unique_ptr<sarif_node> +make_sarif_node (const diagnostics::digraphs::node &n, + sarif_builder *builder, + sarif_location_manager *sarif_location_mgr) +{ + auto result = std::make_unique<sarif_node> (); + + // 3.40.2 id property + result->set_string ("id", n.get_id ().c_str ()); + + copy_any_property_bag (n, *result); + + // 3.40.3 label property + if (const char *label = n.get_label ()) + if (builder) + result->set<sarif_message> ("label", + builder->make_message_object (label)); + + // 3.40.4 location property + if (n.get_logical_loc () + || n.get_physical_loc () != UNKNOWN_LOCATION) + if (builder) + { + rich_location rich_loc + (line_table, n.get_physical_loc ()); + auto loc_obj + = builder->make_location_object + (sarif_location_mgr, + rich_loc, + n.get_logical_loc (), + diagnostic_artifact_role::scanned_file); + result->set<sarif_location> ("location", + std::move (loc_obj)); + } + + // 3.40.5 children property + if (const int num_children = n.get_num_children ()) + { + auto children_arr = std::make_unique<json::array> (); + for (int i = 0; i < num_children; ++i) + children_arr->append (make_sarif_node (n.get_child (i), + builder, + sarif_location_mgr)); + result->set ("children", std::move (children_arr)); + } + + return result; +} + +std::unique_ptr<sarif_edge> +make_sarif_edge (const diagnostics::digraphs::edge &e, + sarif_builder *builder) +{ + auto result = std::make_unique<sarif_edge> (); + + // 3.41.2 id property + result->set_string ("id", e.get_id ().c_str ()); + + copy_any_property_bag (e, *result); + + // 3.41.3 label property + if (const char *label = e.get_label ()) + if (builder) + result->set<sarif_message> ("label", + builder->make_message_object (label)); + + // 3.41.4 sourceNodeId property + result->set_string ("sourceNodeId", e.get_src_node ().get_id ().c_str ()); + + // 3.41.5 targetNodeId property + result->set_string ("targetNodeId", e.get_dst_node ().get_id ().c_str ()); + + return result; +} + +void +sarif_property_bag::set_graph (const char *property_name, + sarif_builder &builder, + sarif_location_manager *sarif_location_mgr, + const diagnostics::digraphs::digraph &g) +{ + set<sarif_graph> (property_name, + make_sarif_graph (g, &builder, sarif_location_mgr)); +} + /* Ensure that m_cached_logical_locs has a "logicalLocation" object (SARIF v2.1.0 section 3.33) for K, and return its index within the array. */ @@ -2960,17 +3132,21 @@ populate_thread_flow_location_object (sarif_result &result, via a property bag. */ ev.maybe_add_sarif_properties (*this, tfl_obj); - if (get_opts ().m_xml_state) - if (auto xml_state = ev.maybe_make_xml_state (true)) + if (get_opts ().m_state_graph) + if (auto state_graph = ev.maybe_make_diagnostic_state_graph (true)) { sarif_property_bag &props = tfl_obj.get_or_create_properties (); - pretty_printer pp; - xml_state->write_as_xml (&pp, 0, true); - #define PROPERTY_PREFIX "gcc/diagnostic_event/" - props.set_string (PROPERTY_PREFIX "xml_state", - pp_formatted_text (&pp)); + props.set_graph (PROPERTY_PREFIX "state_graph", + *this, + /* Use RESULT for any related locations in the graph's + nodes. + It's not clear if this is correct; see: + https://github.com/oasis-tcs/sarif-spec/issues/712 + */ + &result, + *state_graph); #undef PROPERTY_PREFIX } @@ -3234,6 +3410,11 @@ make_run_object (std::unique_ptr<sarif_invocation> invocation_obj, std::move (m_cached_logical_locs)); } + // "graphs" property (SARIF v2.1.0 3.14.20) + if (m_run_graphs->size () > 0) + run_obj->set<json::array> ("graphs", + std::move (m_run_graphs)); + return run_obj; } @@ -3739,6 +3920,12 @@ public: /* No-op. */ } + void + report_global_digraph (const diagnostics::digraphs::lazy_digraph &lazy_digraph) final override + { + m_builder.report_global_digraph (lazy_digraph); + } + sarif_builder &get_builder () { return m_builder; } size_t num_results () const { return m_builder.num_results (); } @@ -4117,7 +4304,7 @@ make_sarif_sink (diagnostic_context &context, sarif_generation_options::sarif_generation_options () : m_version (sarif_version::v2_1_0), - m_xml_state (false) + m_state_graph (false) { } @@ -4299,7 +4486,7 @@ test_make_location_object (const sarif_generation_options &sarif_gen_opts, std::unique_ptr<sarif_location> location_obj = builder.make_location_object - (result, richloc, logical_location (), + (&result, richloc, logical_location (), diagnostic_artifact_role::analysis_target); ASSERT_NE (location_obj, nullptr); diff --git a/gcc/diagnostic-format-sarif.h b/gcc/diagnostic-format-sarif.h index c3ae330..60657c6 100644 --- a/gcc/diagnostic-format-sarif.h +++ b/gcc/diagnostic-format-sarif.h @@ -101,7 +101,7 @@ struct sarif_generation_options sarif_generation_options (); enum sarif_version m_version; - bool m_xml_state; + bool m_state_graph; }; extern std::unique_ptr<diagnostic_output_format> @@ -112,6 +112,14 @@ make_sarif_sink (diagnostic_context &context, diagnostic_output_file output_file); class sarif_builder; +class sarif_location_manager; + +namespace diagnostics { +namespace digraphs { + class digraph; + class node; + class edge; +}} /* Concrete subclass of json::object for SARIF property bags (SARIF v2.1.0 section 3.8). */ @@ -122,6 +130,10 @@ public: void set_logical_location (const char *property_name, sarif_builder &, logical_location logical_loc); + void set_graph (const char *property_name, + sarif_builder &, + sarif_location_manager *sarif_location_mgr, + const diagnostics::digraphs::digraph &g); }; /* Concrete subclass of json::object for SARIF objects that can @@ -136,4 +148,39 @@ public: sarif_property_bag &get_or_create_properties (); }; +/* Subclass of sarif_object for SARIF "graph" objects + (SARIF v2.1.0 section 3.39). */ + +class sarif_graph : public sarif_object +{ +}; + +/* Subclass of sarif_object for SARIF "node" objects + (SARIF v2.1.0 section 3.40). */ + +class sarif_node : public sarif_object +{ +}; + +/* Subclass of sarif_object for SARIF "edge" objects + (SARIF v2.1.0 section 3.41). */ + +class sarif_edge : public sarif_object +{ +}; + +extern std::unique_ptr<sarif_graph> +make_sarif_graph (const diagnostics::digraphs::digraph &g, + sarif_builder *builder, + sarif_location_manager *sarif_location_mgr); + +extern std::unique_ptr<sarif_node> +make_sarif_node (const diagnostics::digraphs::node &n, + sarif_builder *builder, + sarif_location_manager *sarif_location_mgr); + +extern std::unique_ptr<sarif_edge> +make_sarif_edge (const diagnostics::digraphs::edge &e, + sarif_builder *builder); + #endif /* ! GCC_DIAGNOSTIC_FORMAT_SARIF_H */ diff --git a/gcc/diagnostic-format-text.h b/gcc/diagnostic-format-text.h index 64f8e13..64a4452 100644 --- a/gcc/diagnostic-format-text.h +++ b/gcc/diagnostic-format-text.h @@ -70,6 +70,12 @@ public: void update_printer () override; + void + report_global_digraph (const diagnostics::digraphs::lazy_digraph &) final override + { + // no-op for text + } + /* Helpers for writing lang-specific starters/finalizers for text output. */ char *build_prefix (const diagnostic_info &) const; void report_current_module (location_t where); diff --git a/gcc/diagnostic-format.h b/gcc/diagnostic-format.h index 07db2cd..a4c776c 100644 --- a/gcc/diagnostic-format.h +++ b/gcc/diagnostic-format.h @@ -72,6 +72,9 @@ public: Subclasses should update their m_printer accordingly. */ virtual void update_printer () = 0; + virtual void + report_global_digraph (const diagnostics::digraphs::lazy_digraph &) = 0; + diagnostic_context &get_context () const { return m_context; } pretty_printer *get_printer () const { return m_printer.get (); } diff --git a/gcc/diagnostic-metadata.h b/gcc/diagnostic-metadata.h index baeeb6e..f6ea7dc 100644 --- a/gcc/diagnostic-metadata.h +++ b/gcc/diagnostic-metadata.h @@ -23,11 +23,20 @@ along with GCC; see the file COPYING3. If not see class sarif_object; +namespace diagnostics { + namespace digraphs { + class lazy_digraphs; + } // namespace digraphs +} // namespace diagnostics + /* A bundle of additional metadata that can be associated with a diagnostic. This supports an optional CWE identifier, and zero or more - "rules". */ + "rules". + + Additionally, this provides a place to associate a diagnostic + with zero or more directed graphs. */ class diagnostic_metadata { @@ -64,7 +73,7 @@ class diagnostic_metadata const char *m_url; }; - diagnostic_metadata () : m_cwe (0) {} + diagnostic_metadata () : m_cwe (0), m_lazy_digraphs (nullptr) {} virtual ~diagnostic_metadata () {} /* Hook for SARIF output to allow for adding diagnostic-specific @@ -87,9 +96,25 @@ class diagnostic_metadata unsigned get_num_rules () const { return m_rules.length (); } const rule &get_rule (unsigned idx) const { return *(m_rules[idx]); } + void + set_lazy_digraphs (const diagnostics::digraphs::lazy_digraphs *lazy_digraphs) + { + m_lazy_digraphs = lazy_digraphs; + } + + const diagnostics::digraphs::lazy_digraphs * + get_lazy_digraphs () const + { + return m_lazy_digraphs; + } + private: int m_cwe; auto_vec<const rule *> m_rules; + + /* An optional way to create directed graphs associated with the + diagnostic, for the sinks that support this (e.g. SARIF). */ + const diagnostics::digraphs::lazy_digraphs *m_lazy_digraphs; }; #endif /* ! GCC_DIAGNOSTIC_METADATA_H */ diff --git a/gcc/diagnostic-output-spec.cc b/gcc/diagnostic-output-spec.cc index 25ef86f..4fa3176 100644 --- a/gcc/diagnostic-output-spec.cc +++ b/gcc/diagnostic-output-spec.cc @@ -183,7 +183,7 @@ public: private: static sarif_generation_options make_sarif_gen_opts (enum sarif_version version, - bool xml_state); + bool state_graph); static std::unique_ptr<sarif_serialization_format> make_sarif_serialization_object (enum sarif_serialization_kind); @@ -431,7 +431,7 @@ sarif_scheme_handler::make_sink (const context &ctxt, enum sarif_serialization_kind serialization_kind = sarif_serialization_kind::json; enum sarif_version version = sarif_version::v2_1_0; - bool xml_state = false; + bool state_graph = false; for (auto& iter : parsed_arg.m_kvs) { const std::string &key = iter.first; @@ -469,10 +469,10 @@ sarif_scheme_handler::make_sink (const context &ctxt, return nullptr; continue; } - if (key == "xml-state") + if (key == "state-graphs") { if (!parse_bool_value (ctxt, unparsed_arg, key, value, - xml_state)) + state_graph)) return nullptr; continue; } @@ -481,8 +481,8 @@ sarif_scheme_handler::make_sink (const context &ctxt, auto_vec<const char *> known_keys; known_keys.safe_push ("file"); known_keys.safe_push ("serialization"); + known_keys.safe_push ("state-graphs"); known_keys.safe_push ("version"); - known_keys.safe_push ("xml-state"); ctxt.report_unknown_key (unparsed_arg, key, get_scheme_name (), known_keys); return nullptr; @@ -513,7 +513,7 @@ sarif_scheme_handler::make_sink (const context &ctxt, if (!output_file) return nullptr; - auto sarif_gen_opts = make_sarif_gen_opts (version, xml_state); + auto sarif_gen_opts = make_sarif_gen_opts (version, state_graph); auto serialization_obj = make_sarif_serialization_object (serialization_kind); @@ -527,11 +527,11 @@ sarif_scheme_handler::make_sink (const context &ctxt, sarif_generation_options sarif_scheme_handler::make_sarif_gen_opts (enum sarif_version version, - bool xml_state) + bool state_graph) { sarif_generation_options sarif_gen_opts; sarif_gen_opts.m_version = version; - sarif_gen_opts.m_xml_state = xml_state; + sarif_gen_opts.m_state_graph = state_graph; return sarif_gen_opts; } @@ -561,8 +561,8 @@ html_scheme_handler::make_sink (const context &ctxt, label_text filename; bool javascript = true; bool show_state_diagrams = false; - bool show_state_diagram_xml = false; - bool show_state_diagram_dot_src = false; + bool show_state_diagrams_sarif = false; + bool show_state_diagrams_dot_src = false; for (auto& iter : parsed_arg.m_kvs) { const std::string &key = iter.first; @@ -593,17 +593,17 @@ html_scheme_handler::make_sink (const context &ctxt, return nullptr; continue; } - if (key == "show-state-diagram-dot-src") + if (key == "show-state-diagrams-dot-src") { if (!parse_bool_value (ctxt, unparsed_arg, key, value, - show_state_diagram_dot_src)) + show_state_diagrams_dot_src)) return nullptr; continue; } - if (key == "show-state-diagram-xml") + if (key == "show-state-diagrams-sarif") { if (!parse_bool_value (ctxt, unparsed_arg, key, value, - show_state_diagram_xml)) + show_state_diagrams_sarif)) return nullptr; continue; } @@ -615,7 +615,7 @@ html_scheme_handler::make_sink (const context &ctxt, known_keys.safe_push ("javascript"); known_keys.safe_push ("show-state-diagrams"); known_keys.safe_push ("show-state-diagram-dot-src"); - known_keys.safe_push ("show-state-diagram-xml"); + known_keys.safe_push ("show-state-diagram-sarif"); ctxt.report_unknown_key (unparsed_arg, key, get_scheme_name (), known_keys); return nullptr; @@ -649,8 +649,8 @@ html_scheme_handler::make_sink (const context &ctxt, html_gen_opts.m_css = css; html_gen_opts.m_javascript = javascript; html_gen_opts.m_show_state_diagrams = show_state_diagrams; - html_gen_opts.m_show_state_diagram_xml = show_state_diagram_xml; - html_gen_opts.m_show_state_diagram_dot_src = show_state_diagram_dot_src; + html_gen_opts.m_show_state_diagrams_sarif = show_state_diagrams_sarif; + html_gen_opts.m_show_state_diagrams_dot_src = show_state_diagrams_dot_src; auto sink = make_html_sink (dc, *ctxt.get_affected_location_mgr (), diff --git a/gcc/diagnostic-path.cc b/gcc/diagnostic-path.cc index 3e169da..1ae87b7 100644 --- a/gcc/diagnostic-path.cc +++ b/gcc/diagnostic-path.cc @@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "diagnostic.h" #include "diagnostic-path.h" -#include "xml.h" +#include "diagnostic-state-graphs.h" /* Disable warnings about missing quoting in GCC diagnostics for the print calls below. */ @@ -156,12 +156,12 @@ diagnostic_event::get_desc (pretty_printer &ref_pp) const return label_text::take (xstrdup (pp_formatted_text (pp.get ()))); } -// Base implementation of diagnostic_event::maybe_make_xml_state +// Base implementation of diagnostic_event::maybe_make_diagnostic_state_graph -std::unique_ptr<xml::document> -diagnostic_event::maybe_make_xml_state (bool) const +std::unique_ptr<diagnostics::digraphs::digraph> +diagnostic_event::maybe_make_diagnostic_state_graph (bool) const { - // Don't attempt to make a state document: + // Don't attempt to make a state graph: return nullptr; } diff --git a/gcc/diagnostic-path.h b/gcc/diagnostic-path.h index e68f768..ca2628e 100644 --- a/gcc/diagnostic-path.h +++ b/gcc/diagnostic-path.h @@ -30,6 +30,12 @@ namespace xml { class document; } class sarif_builder; class sarif_object; +namespace diagnostics { +namespace digraphs { + class digraph; +} // namespace digraphs +} //namespace diagnostics + /* A diagnostic_path is an optional additional piece of metadata associated with a diagnostic (via its rich_location). @@ -173,9 +179,9 @@ class diagnostic_event } /* Hook for capturing state at this event, potentially for visualizing - in HTML output. */ - virtual std::unique_ptr<xml::document> - maybe_make_xml_state (bool debug) const; + in HTML output, or for adding to SARIF. */ + virtual std::unique_ptr<diagnostics::digraphs::digraph> + maybe_make_diagnostic_state_graph (bool debug) const; label_text get_desc (pretty_printer &ref_pp) const; }; diff --git a/gcc/diagnostic-state-graphs.cc b/gcc/diagnostic-state-graphs.cc new file mode 100644 index 0000000..62eb6f5 --- /dev/null +++ b/gcc/diagnostic-state-graphs.cc @@ -0,0 +1,158 @@ +/* Extensions to diagnostics::digraphs to support state graphs. + 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/>. */ + +#define INCLUDE_ALGORITHM +#define INCLUDE_MAP +#define INCLUDE_SET +#define INCLUDE_STRING +#define INCLUDE_VECTOR +#include "config.h" +#include "system.h" +#include "coretypes.h" + +#include "diagnostic-state-graphs.h" +#include "graphviz.h" +#include "xml.h" +#include "xml-printer.h" +#include "intl.h" +#include "selftest.h" + +using namespace diagnostics::state_graphs; + +const char * const node_kind_strs[] = { + "globals", + "code", + "function", + "stack", + "stack-frame", + "heap", + "thread-local", + "dynalloc-buffer", + "variable", + "field", + "padding", + "element", + "other", +}; + +const char * +diagnostics::state_graphs::node_kind_to_str (enum node_kind k) +{ + return node_kind_strs[static_cast<int> (k)]; +} + +// struct state_node_ref + +enum node_kind +state_node_ref::get_node_kind () const +{ + const char *value = get_attr ("kind"); + if (!value) + return node_kind::other; + + for (size_t i = 0; i < ARRAY_SIZE (node_kind_strs); ++i) + if (!strcmp (node_kind_strs[i], value)) + return static_cast<enum node_kind> (i); + + return node_kind::other; +} + +void +state_node_ref::set_node_kind (enum node_kind k) +{ + set_attr ("kind", node_kind_to_str (k)); +} + +const char * const dynalloc_state_strs[] = { + "unknown", + "nonnull", + "unchecked", + "freed" +}; + +enum node_dynalloc_state +state_node_ref::get_dynalloc_state () const +{ + const char *value = get_attr ("dynalloc-state"); + if (!value) + return node_dynalloc_state::unknown; + + for (size_t i = 0; i < ARRAY_SIZE (dynalloc_state_strs); ++i) + if (!strcmp (dynalloc_state_strs[i], value)) + return static_cast<enum node_dynalloc_state> (i); + + return node_dynalloc_state::unknown; +} + +void +state_node_ref::set_dynalloc_state (enum node_dynalloc_state s) const +{ + set_attr ("dynalloc-state", + dynalloc_state_strs[static_cast <size_t> (s)]); +} + +const char * +state_node_ref::get_dynamic_extents () const +{ + return m_node.get_attr (STATE_NODE_PREFIX, "dynamic-extents"); +} + +void +state_node_ref::set_json_attr (const char *key, + std::unique_ptr<json::value> value) const +{ + m_node.set_json_attr (STATE_NODE_PREFIX, key, std::move (value)); +} + +#if CHECKING_P + +namespace selftest { + +static void +test_node_attrs () +{ + diagnostics::digraphs::digraph g; + diagnostics::digraphs::node n (g, "a"); + state_node_ref node_ref (n); + + ASSERT_EQ (node_ref.get_node_kind (), node_kind::other); + node_ref.set_node_kind (node_kind::stack); + ASSERT_EQ (node_ref.get_node_kind (), node_kind::stack); + + ASSERT_EQ (node_ref.get_dynalloc_state (), node_dynalloc_state::unknown); + node_ref.set_dynalloc_state (node_dynalloc_state::freed); + ASSERT_EQ (node_ref.get_dynalloc_state (), node_dynalloc_state::freed); + + ASSERT_EQ (node_ref.get_type (), nullptr); + node_ref.set_type ("const char *"); + ASSERT_STREQ (node_ref.get_type (), "const char *"); +} + +/* Run all of the selftests within this file. */ + +void +diagnostic_state_graphs_cc_tests () +{ + test_node_attrs (); +} + +} // namespace selftest + +#endif /* CHECKING_P */ diff --git a/gcc/diagnostic-state-graphs.h b/gcc/diagnostic-state-graphs.h new file mode 100644 index 0000000..def6d05 --- /dev/null +++ b/gcc/diagnostic-state-graphs.h @@ -0,0 +1,156 @@ +/* Extensions to diagnostics::digraphs to support state graphs. + 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_DIAGNOSTIC_STATE_GRAPHS_H +#define GCC_DIAGNOSTIC_STATE_GRAPHS_H + +#include "diagnostic-digraphs.h" +#include "logical-location.h" + +/* diagnostics::digraphs provides support for directed graphs. + + diagnostics::state_graphs provides a way to extend these graphs + for representing "state graphs" i.e. a representation of the state + of memory inside a program, for use e.g. by -fanalyzer. + + Specifically, nodes represent memory regions, and we use property bags + in these nodes to stash extra properties (e.g. what kind of memory region + a node is e.g. stack vs heap). */ + +class sarif_graph; +namespace dot { class graph; } + +namespace diagnostics { +namespace state_graphs { + +enum class node_kind +{ + // Memory regions + globals, + code, + function, // code within a particular function + stack, + stack_frame, + heap_, + thread_local_, + + /* Dynamically-allocated buffer, + on heap or stack (depending on parent). */ + dynalloc_buffer, + + variable, + + field, // field within a struct or union + padding, // padding bits in a struct or union + element, // element within an array + + other // anything else +}; + +extern const char * +node_kind_to_str (enum node_kind); + +enum class node_dynalloc_state +{ + unknown, + nonnull, + unchecked, + freed +}; + +/* Prefixes to use in SARIF property bags. */ +#define STATE_GRAPH_PREFIX "gcc/diagnostic_state_graph/" +#define STATE_NODE_PREFIX "gcc/diagnostic_state_node/" +#define STATE_EDGE_PREFIX "gcc/diagnostic_state_edge/" + +/* A wrapper around a node that gets/sets attributes, using + the node's property bag for storage, so that the data roundtrips + through SARIF. */ + +struct state_node_ref +{ + state_node_ref (diagnostics::digraphs::node &node) + : m_node (node) + {} + + enum node_kind + get_node_kind () const; + void + set_node_kind (enum node_kind); + + // For node_kind::stack_frame, this will be the function + logical_location + get_logical_loc () const + { + return m_node.get_logical_loc (); + } + + // For node_kind::dynalloc_buffer + enum node_dynalloc_state + get_dynalloc_state () const; + + void + set_dynalloc_state (enum node_dynalloc_state) const; + + const char * + get_dynamic_extents () const; + + const char * + get_name () const { return get_attr ("name"); } + void + set_name (const char *name) const { set_attr ("name", name); } + + const char * + get_type () const { return get_attr ("type"); } + void + set_type (const char *type) const { set_attr ("type", type); } + + const char * + get_value () const { return get_attr ("value"); } + + const char * + get_index () const { return get_attr ("index"); } + + const char * + get_attr (const char *key) const + { + return m_node.get_attr (STATE_NODE_PREFIX, key); + } + + void + set_attr (const char *key, const char *value) const + { + return m_node.set_attr (STATE_NODE_PREFIX, key, value); + } + + void + set_json_attr (const char *key, std::unique_ptr<json::value> value) const; + + diagnostics::digraphs::node &m_node; +}; + +extern std::unique_ptr<dot::graph> +make_dot_graph (const diagnostics::digraphs::digraph &state_graph, + const logical_location_manager &logical_loc_mgr); + +} // namespace state_graphs +} // namespace diagnostics + +#endif /* ! GCC_DIAGNOSTIC_STATE_GRAPHS_H */ diff --git a/gcc/diagnostic-state-to-dot.cc b/gcc/diagnostic-state-to-dot.cc index ddae83b..8195c11 100644 --- a/gcc/diagnostic-state-to-dot.cc +++ b/gcc/diagnostic-state-to-dot.cc @@ -1,4 +1,4 @@ -/* Creating GraphViz .dot files from XML state documents. +/* Creating GraphViz .dot files from diagnostic state graphs. Copyright (C) 2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.com>. @@ -27,81 +27,59 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" +#include "diagnostic-state-graphs.h" +#include "graphviz.h" #include "xml.h" #include "xml-printer.h" -#include "graphviz.h" +#include "intl.h" + +using namespace diagnostics::state_graphs; static int -get_depth (const xml::element &e) +get_depth (const diagnostics::digraphs::node &n) { int deepest_child = 0; - for (auto &iter : e.m_children) - if (xml::element *child_element = iter->dyn_cast_element ()) + for (size_t i = 0; i < n.get_num_children (); ++i) deepest_child = std::max (deepest_child, - get_depth (*child_element)); + get_depth (n.get_child (i))); return deepest_child + 1; } -enum class dynalloc_state -{ - unknown, - nonnull, - unchecked, - freed -}; - static const char * -get_color_for_dynalloc_state (enum dynalloc_state dynalloc_st) +get_color_for_dynalloc_state (enum node_dynalloc_state dynalloc_st) { switch (dynalloc_st) { default: gcc_unreachable (); break; - case dynalloc_state::unknown: - case dynalloc_state::nonnull: + case node_dynalloc_state::unknown: + case node_dynalloc_state::nonnull: return nullptr; - case dynalloc_state::unchecked: + case node_dynalloc_state::unchecked: return "#ec7a08"; // pf-orange-400 - case dynalloc_state::freed: + case node_dynalloc_state::freed: return "#cc0000"; // pf-red-100 } } static void set_color_for_dynalloc_state (dot::attr_list &attrs, - enum dynalloc_state dynalloc_state) + enum node_dynalloc_state state) { - if (const char *color = get_color_for_dynalloc_state (dynalloc_state)) + if (const char *color = get_color_for_dynalloc_state (state)) attrs.add (dot::id ("color"), dot::id (color)); } -static enum dynalloc_state -get_dynalloc_state (const xml::element &input_element) -{ - const char *dyn_alloc_state = input_element.get_attr ("dynamic-alloc-state"); - if (!dyn_alloc_state) - return dynalloc_state::unknown; - - if (dyn_alloc_state == std::string ("unchecked")) - return dynalloc_state::unchecked; - - if (dyn_alloc_state == std::string ("nonnull")) - return dynalloc_state::nonnull; - - if (dyn_alloc_state == std::string ("freed")) - return dynalloc_state::freed; - - return dynalloc_state::unknown; -} - class state_diagram : public dot::graph { public: - state_diagram (const xml::document &input_state_doc) - : m_next_id (0), + state_diagram (const diagnostics::digraphs::digraph &input_state_graph, + const logical_location_manager &logical_loc_mgr) + : m_logical_loc_mgr (logical_loc_mgr), + // m_next_id (0), m_show_tags (false) { // "node [shape=plaintext]\n" @@ -112,41 +90,46 @@ public: add_stmt (std::move (attr_stmt)); } - /* Recurse down the XML state diagram, creating subgraphs + /* Determine which nodes are involved in edges. */ + for (size_t i = 0; i < input_state_graph.get_num_edges (); ++i) + { + auto &edge = input_state_graph.get_edge (i); + m_src_nodes.insert (&edge.get_src_node ()); + m_dst_nodes.insert (&edge.get_dst_node ()); + } + + /* Recurse down the nodes in the state graph, creating subgraphs and then eventually creating nodes, and recursively - creating XML tables, adding ports for the endpoints of edges, - and recording edges we'll want to create (into m_pending_edges). */ - xml::element *input_elmt_state_diagram - = input_state_doc.find_child_element ("state-diagram"); - gcc_assert (input_elmt_state_diagram); - xml::element *input_elmt_mem_regions - = input_elmt_state_diagram->find_child_element ("memory-regions"); - if (!input_elmt_mem_regions) - return; + creating XML tables, and adding ports for the endpoints of edges + where needed. */ + auto root_cluster = std::make_unique<dot::subgraph> (dot::id ("cluster_memory_regions")); - for (auto &iter : input_elmt_mem_regions->m_children) - on_input_xml_node (*root_cluster, *iter); + for (size_t i = 0; i < input_state_graph.get_num_nodes (); ++i) + on_input_state_node (*root_cluster, + state_node_ref (input_state_graph.get_node (i))); add_stmt (std::move (root_cluster)); - /* We should now have ports for edge endpoints for all region ids. - Use them now to create edges. */ - for (auto &pe : m_pending_edges) + /* Now create dot edges for edges in input_stage_graph. */ + for (size_t i = 0; i < input_state_graph.get_num_edges (); ++i) { - auto search = m_region_id_to_dst_node_id.find (pe.m_dst_region_id); - if (search != m_region_id_to_dst_node_id.end ()) - { - auto &dst_node_id = search->second; - auto e = std::make_unique<dot::edge_stmt> (pe.m_src_node_id, - dst_node_id); - - auto dynalloc_state = m_region_id_to_dynalloc_state.find (pe.m_dst_region_id); - if (dynalloc_state != m_region_id_to_dynalloc_state.end ()) - set_color_for_dynalloc_state (e->m_attrs, - dynalloc_state->second); - - add_stmt (std::move (e)); - } + auto &edge = input_state_graph.get_edge (i); + auto &src_node = edge.get_src_node (); + auto &dst_node = edge.get_dst_node (); + + auto src_port_id = m_src_node_to_port_id.find (&src_node); + if (src_port_id == m_src_node_to_port_id.end ()) + continue; + auto dst_port_id = m_dst_node_to_port_id.find (&dst_node); + if (dst_port_id == m_dst_node_to_port_id.end ()) + continue; + + auto e = std::make_unique<dot::edge_stmt> (src_port_id->second, + dst_port_id->second); + set_color_for_dynalloc_state + (e->m_attrs, state_node_ref (dst_node).get_dynalloc_state ()); + + add_stmt (std::move (e)); } } @@ -165,35 +148,58 @@ private: } dot::id - make_id (bool cluster = false) + make_id (state_node_ref state_node, bool cluster) { + std::string input_node_id = state_node.m_node.get_id (); if (cluster) - return std::string ("cluster_") + std::to_string (m_next_id++); + return std::string ("cluster_") + input_node_id; else - return std::string ("id_") + std::to_string (m_next_id++); + return input_node_id; } bool - starts_node_p (const xml::element &e) + starts_node_p (state_node_ref state_node) { - if (e.m_kind == "stack" - || e.m_kind == "heap-buffer" - || e.m_kind == "variable") // e.g. within globals - return true; - return false; + switch (state_node.get_node_kind ()) + { + default: + return false; + + case node_kind::stack: + /* We want all frames in the stack in the same table, + so they are grouped. */ + case node_kind::dynalloc_buffer: + case node_kind::variable: + return true; + } } - void - on_input_xml_node (dot::subgraph &parent_subgraph, - xml::node &input_node) + const char * + get_label_for_node (state_node_ref state_node) { - xml::element *input_element = input_node.dyn_cast_element (); - if (!input_element) - return; + switch (state_node.get_node_kind ()) + { + default: + return nullptr; + + case node_kind::globals: + return _("Globals"); + case node_kind::code: + return _("Code"); + case node_kind::stack: + return _("Stack"); + case node_kind::heap_: + return _("Heap"); + } + } - dot::id sg_id = make_id (true); + void + on_input_state_node (dot::subgraph &parent_subgraph, + state_node_ref state_node) + { + dot::id sg_id = make_id (state_node, true); - if (starts_node_p (*input_element)) + if (starts_node_p (state_node)) { // Create node with table xml::element table ("table", false); @@ -202,14 +208,14 @@ private: xp.set_attr ("cellborder", "1"); xp.set_attr ("cellspacing", "0"); - const int max_depth = get_depth (*input_element); + const int max_depth = get_depth (state_node.m_node); const int num_columns = max_depth + 2; - dot::id id_of_node = make_id (); - on_xml_node (id_of_node, xp, *input_element, - max_depth, 0, num_columns); + dot::id id_of_dot_node = make_id (state_node, false); + on_node_in_table (id_of_dot_node, xp, state_node, + max_depth, 0, num_columns); - auto node = std::make_unique<dot::node_stmt> (std::move (id_of_node)); + auto node = std::make_unique<dot::node_stmt> (std::move (id_of_dot_node)); node->m_attrs.add (dot::id ("shape"), dot::id ("plaintext")); @@ -224,12 +230,13 @@ private: { auto child_subgraph = std::make_unique<dot::subgraph> (std::move (sg_id)); - if (const char *label = input_element->get_attr ("label")) + if (const char *label = get_label_for_node (state_node)) child_subgraph->add_attr (dot::id ("label"), dot::id (label)); // recurse: - for (auto &iter : input_element->m_children) - on_input_xml_node (*child_subgraph, *iter); + for (size_t i = 0; i < state_node.m_node.get_num_children (); ++i) + on_input_state_node (*child_subgraph, + state_node.m_node.get_child (i)); parent_subgraph.m_stmt_list.add_stmt (std::move (child_subgraph)); } } @@ -237,13 +244,13 @@ private: enum class style { h1, h2 }; void - add_title_tr (const dot::id &id_of_node, + add_title_tr (const dot::id &id_of_dot_node, xml::printer &xp, int num_columns, - const xml::element &input_element, + state_node_ref state_node, std::string heading, enum style styl, - enum dynalloc_state dynalloc_state) + enum node_dynalloc_state dynalloc_state) { xp.push_tag ("tr", true); xp.push_tag ("td", false); @@ -282,183 +289,194 @@ private: xp.add_text (std::move (heading)); xp.pop_tag ("font"); - maybe_add_dst_port (id_of_node, xp, input_element); + maybe_add_dst_port (id_of_dot_node, xp, state_node); xp.pop_tag ("td"); xp.pop_tag ("tr"); } - /* Recursively add <TR> to XP for INPUT_NODE and its descendents. */ + /* Recursively add <TR> to XP for STATE_NODE and its descendents. */ void - on_xml_node (const dot::id &id_of_node, - xml::printer &xp, - xml::node &input_node, - int max_depth, - int depth, - int num_columns) + on_node_in_table (const dot::id &id_of_dot_node, + xml::printer &xp, + state_node_ref state_node, + int max_depth, + int depth, + int num_columns) { bool recurse = true; + auto input_node_kind = state_node.get_node_kind (); - xml::element *input_element = input_node.dyn_cast_element (); - if (!input_element) - return; - - if (input_element->m_kind == "concrete-bindings") - return; - if (input_element->m_kind == "padding") - return; - - if (input_element->m_kind == "stack") - { - add_title_tr (id_of_node, xp, num_columns, *input_element, "Stack", - style::h1, dynalloc_state::unknown); - } - else if (input_element->m_kind == "stack-frame") - { - if (const char *function = input_element->get_attr ("function")) - add_title_tr (id_of_node, xp, num_columns, *input_element, - std::string ("Frame: ") + function, - style::h2, dynalloc_state::unknown); - } - else if (input_element->m_kind == "heap-buffer") + switch (input_node_kind) { - const char *extents = input_element->get_attr ("dynamic-extents"); - enum dynalloc_state dynalloc_st = get_dynalloc_state (*input_element); - if (auto region_id = input_element->get_attr ("region_id")) - m_region_id_to_dynalloc_state[region_id] = dynalloc_st; - const char *type = input_element->get_attr ("type"); - pretty_printer pp; - switch (dynalloc_st) - { - default: - gcc_unreachable (); - - case dynalloc_state::unknown: - case dynalloc_state::nonnull: - if (type) - { + case node_kind::padding: + case node_kind::other: + return; + + case node_kind::stack: + add_title_tr (id_of_dot_node, xp, num_columns, state_node, "Stack", + style::h1, + node_dynalloc_state::unknown); + break; + case node_kind::stack_frame: + if (auto logical_loc = state_node.get_logical_loc ()) + if (const char *function + = m_logical_loc_mgr.get_short_name (logical_loc)) + add_title_tr (id_of_dot_node, xp, num_columns, state_node, + std::string ("Frame: ") + function, + style::h2, + node_dynalloc_state::unknown); + break; + case node_kind::dynalloc_buffer: + { + enum node_dynalloc_state dynalloc_st + = state_node.get_dynalloc_state (); + const char *extents = state_node.get_dynamic_extents (); + const char *type = state_node.get_type (); + pretty_printer pp; + switch (dynalloc_st) + { + default: + gcc_unreachable (); + + case node_dynalloc_state::unknown: + case node_dynalloc_state::nonnull: + if (type) + { if (extents) pp_printf (&pp, "%s (%s byte allocation)", type, extents); else pp_printf (&pp, "%s", type); - } - else + } + else + { + if (extents) + pp_printf (&pp, "%s byte allocation", + extents); + } + break; + + case node_dynalloc_state::unchecked: + if (type) + { + if (extents) + pp_printf (&pp, "%s (unchecked %s byte allocation)", + type, extents); + } + else + { + if (extents) + pp_printf (&pp, "Unchecked %s byte allocation", + extents); + } + break; + + case node_dynalloc_state::freed: + // TODO: show deallocator + // TODO: show deallocation event + pp_printf (&pp, "Freed buffer"); + break; + } + maybe_add_dst_port (id_of_dot_node, xp, state_node); + add_title_tr (id_of_dot_node, xp, num_columns, state_node, + pp_formatted_text (&pp), + style::h2, + dynalloc_st); + } + break; + + default: + { + xp.push_tag ("tr", true); + + maybe_add_dst_port (id_of_dot_node, xp, state_node); + + if (depth > 0) + { + /* Indent, by create a <td> spanning "depth" columns. */ + xp.push_tag ("td", false); + xp.set_attr ("colspan", std::to_string (depth)); + xp.add_text (" "); // graphviz doesn't like <td/> + xp.pop_tag ("td"); + } + + switch (input_node_kind) + { + default: + break; + case node_kind::variable: { - if (extents) - pp_printf (&pp, "%s byte allocation", - extents); + const char *name = state_node.get_name (); + gcc_assert (name); + xp.push_tag ("td", false); + maybe_add_dst_port (id_of_dot_node, xp, state_node); + push_src_text (xp); + xp.add_text (name); + pop_src_text (xp); + xp.pop_tag ("td"); } - break; - - case dynalloc_state::unchecked: - if (type) + break; + case node_kind::element: { - if (extents) - pp_printf (&pp, "%s (unchecked %s byte allocation)", - type, extents); + const char *index = state_node.get_index (); + gcc_assert (index); + xp.push_tag ("td", false); + maybe_add_dst_port (id_of_dot_node, xp, state_node); + push_src_text (xp); + xp.add_text ("["); + xp.add_text (index); + xp.add_text ("]"); + pop_src_text (xp); + xp.pop_tag ("td"); } - else + break; + case node_kind::field: { - if (extents) - pp_printf (&pp, "Unchecked %s byte allocation", - extents); + const char *name = state_node.get_name (); + gcc_assert (name); + xp.push_tag ("td", false); + maybe_add_dst_port (id_of_dot_node, xp, state_node); + push_src_text (xp); + xp.add_text ("."); + xp.add_text (name); + pop_src_text (xp); + xp.pop_tag ("td"); } - break; - - case dynalloc_state::freed: - // TODO: show deallocator - // TODO: show deallocation event - pp_printf (&pp, "Freed buffer"); - break; - } - add_title_tr (id_of_node, xp, num_columns, *input_element, - pp_formatted_text (&pp), - style::h2, - dynalloc_st); - } - else - { - xp.push_tag ("tr", true); - if (depth > 0) - { - /* Indent, by create a <td> spanning "depth" columns. */ - xp.push_tag ("td", false); - xp.set_attr ("colspan", std::to_string (depth)); - xp.add_text (" "); // graphviz doesn't like <td/> - xp.pop_tag ("td"); - } - if (m_show_tags) - { - // Debug: show XML tag - xp.push_tag ("td", false); - xp.add_text ("<"); - xp.add_text (input_element->m_kind); - xp.add_text (">"); - xp.pop_tag ("td"); - } - if (input_element->m_kind == "variable") - { - const char *name = input_element->get_attr ("name"); - gcc_assert (name); - xp.push_tag ("td", false); - maybe_add_dst_port (id_of_node, xp, *input_element); - push_src_text (xp); - xp.add_text (name); - pop_src_text (xp); - xp.pop_tag ("td"); - } - else if (input_element->m_kind == "element") - { - const char *index = input_element->get_attr ("index"); - gcc_assert (index); - xp.push_tag ("td", false); - maybe_add_dst_port (id_of_node, xp, *input_element); - push_src_text (xp); - xp.add_text ("["); - xp.add_text (index); - xp.add_text ("]"); - pop_src_text (xp); - xp.pop_tag ("td"); - } - else if (input_element->m_kind == "field") - { - const char *name = input_element->get_attr ("name"); - gcc_assert (name); - xp.push_tag ("td", false); - maybe_add_dst_port (id_of_node, xp, *input_element); - push_src_text (xp); - xp.add_text ("."); - xp.add_text (name); - pop_src_text (xp); - xp.pop_tag ("td"); - } - if (const char *type = input_element->get_attr ("type")) - { - xp.push_tag ("td", false); - if (max_depth > depth) - xp.set_attr ("colspan", std::to_string (max_depth - depth)); - xp.set_attr ("align", "right"); - push_src_text (xp); - xp.add_text (type); - pop_src_text (xp); - xp.pop_tag ("td"); - } - if (auto value = input_element->find_child_element ("value-of-region")) - { - xp.push_tag ("td", false); - for (auto &iter : value->m_children) - if (auto child_element = iter->dyn_cast_element ()) - print_value (id_of_node, xp, *child_element); - xp.pop_tag ("td"); - recurse = false; - } - xp.pop_tag ("tr"); + break; + } + + if (const char *type = state_node.get_type ()) + { + xp.push_tag ("td", false); + xp.set_attr ("align", "right"); + push_src_text (xp); + xp.add_text (type); + pop_src_text (xp); + xp.pop_tag ("td"); + } + + if (const char *value = state_node.get_value ()) + { + xp.push_tag ("td", false); + xp.set_attr ("align", "left"); + maybe_add_src_port (id_of_dot_node, xp, state_node); + push_src_text (xp); + xp.add_text (value); + pop_src_text (xp); + xp.pop_tag ("td"); + recurse = false; + } + xp.pop_tag ("tr"); + } + break; } if (recurse) - for (auto &iter : input_element->m_children) - on_xml_node (id_of_node, xp, *iter, max_depth, depth + 1, num_columns); + for (size_t i = 0; i < state_node.m_node.get_num_children (); ++i) + on_node_in_table (id_of_dot_node, xp, + state_node.m_node.get_child (i), + max_depth, depth + 1, num_columns); } void @@ -474,64 +492,63 @@ private: xp.pop_tag ("font"); } + /* If STATE_NODE is in m_src_nodes, add a port to XP for possible + incoming edges to use. */ + void - print_value (const dot::id &id_of_node, - xml::printer &xp, - xml::element &input_element) + maybe_add_src_port (const dot::id &id_of_dot_node, + xml::printer &xp, + state_node_ref state_node) { - if (input_element.m_kind == "pointer-to-region") - if (const char *dst_region_id = input_element.get_attr ("region_id")) - { - dot::id src_port_id = make_id (); - xp.set_attr ("port", src_port_id.m_str); - m_pending_edges.push_back - ({dot::node_id (id_of_node, - dot::port (src_port_id, - dot::compass_pt::e)), - dst_region_id}); - } - - if (input_element.m_kind == "uninitialized") - { - xp.add_text ("(uninitialized)"); - return; - } + auto iter = m_src_nodes.find (&state_node.m_node); + if (iter == m_src_nodes.end ()) + return; - if (auto dump_text = input_element.get_attr ("dump-text")) - xp.add_text (dump_text); + dot::id src_id = make_id (state_node, false); + dot::node_id node_id (id_of_dot_node, + dot::port (src_id, + dot::compass_pt::e)); + m_src_node_to_port_id.insert ({&state_node.m_node, node_id}); + xp.set_attr ("port", src_id.m_str); } - /* If INPUT_ELEMENT has a "region_id", add a port to XP for possible + /* If STATE_NODE is in m_dst_nodes, add a port to XP for possible incoming edges to use. */ void - maybe_add_dst_port (const dot::id &id_of_node, + maybe_add_dst_port (const dot::id &id_of_dot_node, xml::printer &xp, - const xml::element &input_element) + state_node_ref state_node) { - if (const char *region_id = input_element.get_attr ("region_id")) - { - dot::id dst_id = make_id (); - dot::node_id node_id (id_of_node, - dot::port (dst_id/*, - dot::compass_pt::w*/)); - xp.set_attr ("port", dst_id.m_str); - m_region_id_to_dst_node_id.emplace (std::string (region_id), - std::move (node_id)); - } - } + auto iter = m_dst_nodes.find (&state_node.m_node); + if (iter == m_dst_nodes.end ()) + return; + dot::id dst_id = make_id (state_node, false); + dot::node_id node_id (id_of_dot_node, + dot::port (dst_id/*, + dot::compass_pt::w*/)); + m_dst_node_to_port_id.insert ({&state_node.m_node, node_id}); + xp.set_attr ("port", dst_id.m_str); + } private: - int m_next_id; - std::vector<pending_edge> m_pending_edges; - std::map<std::string, dot::node_id> m_region_id_to_dst_node_id; - std::map<std::string, enum dynalloc_state> m_region_id_to_dynalloc_state; + const logical_location_manager &m_logical_loc_mgr; + + /* All nodes involved in edges (and thus will need a port). */ + std::set<diagnostics::digraphs::node *> m_src_nodes; + std::set<diagnostics::digraphs::node *> m_dst_nodes; + + std::map<diagnostics::digraphs::node *, dot::node_id> m_src_node_to_port_id; + std::map<diagnostics::digraphs::node *, dot::node_id> m_dst_node_to_port_id; + bool m_show_tags; }; std::unique_ptr<dot::graph> -make_dot_graph_from_xml_state (const xml::document &xml_state) +diagnostics::state_graphs:: +make_dot_graph (const diagnostics::digraphs::digraph &state_graph, + const logical_location_manager &logical_loc_mgr) { - return std::make_unique<state_diagram> (xml_state); + return std::make_unique<state_diagram> (state_graph, logical_loc_mgr); } diff --git a/gcc/diagnostic-state.h b/gcc/diagnostic-state.h deleted file mode 100644 index 68c3e00..0000000 --- a/gcc/diagnostic-state.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Capturing changing state in diagnostic paths. - 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_DIAGNOSTIC_STATE_H -#define GCC_DIAGNOSTIC_STATE_H - -/* We want to be able to express changing program states in diagnostic paths, - so that we can emit this in HTML and SARIF output, and to keep this - separate from implementation details of -fanalyzer. - - For now, we use xml::document as the type in the diagnostic subsystem - for (optionally) tracking the state at a diagnostic_event. */ - -namespace xml { class document; } -namespace dot { class graph; } - -extern std::unique_ptr<dot::graph> -make_dot_graph_from_xml_state (const xml::document &xml_state); - -#endif /* GCC_DIAGNOSTIC_STATE_H */ diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 088390b..7e5ac87 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -1624,6 +1624,14 @@ diagnostic_context::report_verbatim (text_info &text) } } +void +diagnostic_context:: +report_global_digraph (const diagnostics::digraphs::lazy_digraph &ldg) +{ + for (auto sink : m_output_sinks) + sink->report_global_digraph (ldg); +} + /* Get the number of digits in the decimal representation of VALUE. */ int diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 00f6e35..04eb2b1 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -26,6 +26,12 @@ along with GCC; see the file COPYING3. If not see #include "pretty-print.h" #include "diagnostic-core.h" +namespace diagnostics { + namespace digraphs { + class lazy_digraph; + } // namespace digraphs +} // namespace diagnostics + namespace text_art { class theme; @@ -616,6 +622,11 @@ public: bool report_diagnostic (diagnostic_info *); void report_verbatim (text_info &); + /* Report a directed graph associated with the run as a whole + to any sinks that support directed graphs. */ + void + report_global_digraph (const diagnostics::digraphs::lazy_digraph &); + diagnostic_t classify_diagnostic (diagnostic_option_id option_id, diagnostic_t new_kind, diff --git a/gcc/doc/analyzer.texi b/gcc/doc/analyzer.texi index 4dd14c8..4efba4d 100644 --- a/gcc/doc/analyzer.texi +++ b/gcc/doc/analyzer.texi @@ -624,17 +624,17 @@ which writes out the diagnostics in HTML form, and generates SVG state diagrams visualizing the state of memory at each event (inspired by the "ddd" debugger). These can be seen by pressing 'j' and 'k' to single-step forward and backward through events. Note that these SVG diagrams are -created from an intermediate XML representation generated from -@code{program_state} objects. The XML representation can be easier to +created from an intermediate SARIF directed graph representation generated from +@code{program_state} objects. The SARIF representation can be easier to read - for example, rather than storing the contents of memory via byte offsets, it uses fields for structs and element indexes for arrays, recursively. However it is a different representation, and thus bugs could be hidden by this transformation. Generating the SVG diagrams requires an invocation of "dot" per event, so it noticeably slows down diagnostic -emission, hence the opt-in command-line flag. The XML and ``dot'' +emission, hence the opt-in command-line flag. The SARIF and ``dot'' representations can be seen by @code{__analyzer_dump_xml} and @code{__analyzer_dump_dot} below (writing them to stderr), or by adding -@code{show-state-diagrams-xml=yes} and +@code{show-state-diagrams-sarif=yes} and @code{show-state-diagrams-dot-src=yes} to the html sink, which shows them within the generated HTML next to the generated SVG. @@ -792,9 +792,9 @@ will emit a warning describing the state of the 2nd argument a name matching the 1st argument (which must be a string literal). This is for use when debugging, and may be of use in DejaGnu tests. -@item __analyzer_dump_xml +@item __analyzer_dump_sarif @smallexample -__analyzer_dump_xml (); +__analyzer_dump_sarif (); @end smallexample will dump the copious information about the analyzer's state each time it diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 74f5ee2..9a1aa37 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -353,7 +353,7 @@ Objective-C and Objective-C++ Dialects}. -Wno-builtin-macro-redefined -Wc90-c99-compat -Wc99-c11-compat -Wc11-c23-compat -Wc23-c2y-compat -Wc++-compat -Wc++11-compat -Wc++14-compat -Wc++17-compat --Wc++20-compat +-Wc++20-compat -Wc++26-compat -Wno-c++11-extensions -Wno-c++14-extensions -Wno-c++17-extensions -Wno-c++20-extensions -Wno-c++23-extensions -Wcalloc-transposed-args @@ -6143,10 +6143,10 @@ end-users, and subject to change or removal without notice: @table @gcctabopt -@item xml-state=@r{[}yes@r{|}no@r{]} +@item state-graphs=@r{[}yes@r{|}no@r{]} This is a debugging feature and defaults to @code{no}. -If @code{xml-state=yes}, then attempt to capture detailed state information -from @option{-fanalyzer} in the generated SARIF. +If @code{state-graphs=yes}, then attempt to capture detailed state +information from @option{-fanalyzer} in the generated SARIF. @end table @@ -6194,11 +6194,11 @@ then if @code{show-state-diagrams=yes}, the generated state diagrams will also show the .dot source input to GraphViz used for the diagram. -@item show-state-diagrams-xml=@r{[}yes@r{|}no@r{]} +@item show-state-diagrams-sarif=@r{[}yes@r{|}no@r{]} This is a debugging feature and defaults to @code{no}. -If @code{show-state-diagrams-xml=yes} +If @code{show-state-diagrams-sarif=yes} then if @code{show-state-diagrams=yes}, the generated state diagrams will -also show an XML representation of the state. +also show a SARIF representation of the state. @end table @@ -9690,6 +9690,12 @@ and ISO C++ 2017. This warning is enabled by @option{-Wall}. Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020. This warning is enabled by @option{-Wall}. +@opindex Wc++26-compat +@opindex Wno-c++26-compat +@item -Wc++26-compat @r{(C++ and Objective-C++ only)} +Warn about C++ constructs whose meaning differs between ISO C++ 2023 +and upcoming ISO C++ 2026. This warning is enabled by @option{-Wall}. + @opindex Wc++11-extensions @opindex Wno-c++11-extensions @item -Wno-c++11-extensions @r{(C++ and Objective-C++ only)} diff --git a/gcc/doc/libgdiagnostics/topics/compatibility.rst b/gcc/doc/libgdiagnostics/topics/compatibility.rst index 10adcc5..0e078d0 100644 --- a/gcc/doc/libgdiagnostics/topics/compatibility.rst +++ b/gcc/doc/libgdiagnostics/topics/compatibility.rst @@ -178,6 +178,8 @@ acccessing values within a :type:`diagnostic_logical_location`: * :func:`diagnostic_logical_location_get_decorated_name` +.. _LIBGDIAGNOSTICS_ABI_2: + ``LIBGDIAGNOSTICS_ABI_2`` ------------------------- ``LIBGDIAGNOSTICS_ABI_2`` covers the addition of these functions for @@ -186,3 +188,34 @@ supporting command-line options and SARIF playback: * :func:`diagnostic_manager_add_sink_from_spec` * :func:`diagnostic_manager_set_analysis_target` + +.. _LIBGDIAGNOSTICS_ABI_3: + +``LIBGDIAGNOSTICS_ABI_3`` +------------------------- +``LIBGDIAGNOSTICS_ABI_3`` covers the addition of these functions for +working with directed graphs: + + * :func:`diagnostic_manager_new_graph` + + * :func:`diagnostic_manager_take_global_graph` + + * :func:`diagnostic_take_graph` + + * :func:`diagnostic_graph_release` + + * :func:`diagnostic_graph_set_description` + + * :func:`diagnostic_graph_add_node` + + * :func:`diagnostic_graph_add_edge` + + * :func:`diagnostic_graph_get_node_by_id` + + * :func:`diagnostic_graph_get_edge_by_id` + + * :func:`diagnostic_node_set_label` + + * :func:`diagnostic_node_set_location` + + * :func:`diagnostic_node_set_logical_location` diff --git a/gcc/doc/libgdiagnostics/topics/diagnostic-manager.rst b/gcc/doc/libgdiagnostics/topics/diagnostic-manager.rst index 0390704..c94d19e 100644 --- a/gcc/doc/libgdiagnostics/topics/diagnostic-manager.rst +++ b/gcc/doc/libgdiagnostics/topics/diagnostic-manager.rst @@ -63,17 +63,17 @@ Responsibilities include: diagnostic_manager *control_mgr) This function can be used to support option processing similar to GCC's - :option:`-fdiagnostics-add-output=`. This allows command-line tools to - support the same domain-specific language for specifying output sink - as GCC does. - - The function will attempt to parse :param:`spec` as if it were - an argument to GCC's :option:`-fdiagnostics-add-output=OUTPUT-SPEC`. - If successful, it will add an output sink to :param:`affected_mgr` and return zero. - Otherwise, it will emit an error diagnostic to :param:`control_mgr` and + `-fdiagnostics-add-output= <https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-add-output>`_. + This allows command-line tools to support the same domain-specific + language for specifying output sinks as GCC does. + + The function will attempt to parse ``spec`` as if it were + an argument to GCC's `-fdiagnostics-add-output= <https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html#index-fdiagnostics-add-output>`_. + If successful, it will add an output sink to ``affected_mgr`` and return zero. + Otherwise, it will emit an error diagnostic to ``control_mgr`` and return non-zero. - :param:`affected_mgr` and :param:`control_mgr` can be the same manager, + ``affected_mgr`` and ``control_mgr`` can be the same manager, or be different managers. This function was added in :ref:`LIBGDIAGNOSTICS_ABI_2`; you can @@ -83,14 +83,14 @@ Responsibilities include: #ifdef LIBDIAGNOSTICS_HAVE_diagnostic_manager_add_sink_from_spec - .. function:: void diagnostic_manager_set_analysis_target (diagnostic_manager *mgr, \ const diagnostic_file *file) - This function sets the "main input file" of :param:`mgr` to be - :param:`file`. + This function sets the "main input file" of ``mgr`` to be + ``file``. This affects the :code:`<title>` of generated HTML and - the :code:`role` of the artifact in SARIF output (SARIF v2.1.0 section 3.24.6). + the :code:`role` of the :code:`artifact` in SARIF output + (`SARIF v2.1.0 section 3.24.6 <https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790867>`_). This function was added in :ref:`LIBGDIAGNOSTICS_ABI_2`; you can test for its presence using diff --git a/gcc/doc/libgdiagnostics/topics/graphs.rst b/gcc/doc/libgdiagnostics/topics/graphs.rst new file mode 100644 index 0000000..b976013 --- /dev/null +++ b/gcc/doc/libgdiagnostics/topics/graphs.rst @@ -0,0 +1,197 @@ +.. Copyright (C) 2025 Free Software Foundation, Inc. + Originally contributed by David Malcolm <dmalcolm@redhat.com> + + This 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 of the License, or + (at your option) any later version. + + This program 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 this program. If not, see + <https://www.gnu.org/licenses/>. + +.. default-domain:: c + +Graphs +====== + +.. type:: diagnostic_graph + +SARIF has support for capturing directed graphs (such as callgraphs +and control flow graphs), both at the level of the run as a whole, +and at the level of individual results. + +libgdiagnostics supports this with the following entrypoints, allowing +directed graphs to be + +* created (with :func:`diagnostic_manager_new_graph`) + +* reported "globally" (with :func:`diagnostic_manager_take_global_graph`) + +* reported as part of a :type:`diagnostic` (with :func:`diagnostic_take_graph`), or + +* discarded (with :func:`diagnostic_graph_release`). + +.. function:: diagnostic_graph * diagnostic_manager_new_graph (diagnostic_manager *manager) + + Create a new directed graph. + + The resulting graph is owned by the caller and must have one of + :func:`diagnostic_manager_take_global_graph`, + :func:`diagnostic_take_graph`, + or :func:`diagnostic_graph_release` called on it to avoid leaks. + + The parameter ``manager`` must be non-null. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + +.. function:: void diagnostic_manager_take_global_graph (diagnostic_manager *manager, \ + diagnostic_graph *graph) + + Report this graph "globally", taking ownership of it. + This won't appear in text sinks, but in SARIF sinks the graph will be + added to theRun.graphs (SARIF v2.1.0 3.14.20). + + Parameters ``manager`` and ``graph`` must both be non-null. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + +.. function:: void diagnostic_take_graph (diagnostic *diag, \ + diagnostic_graph *graph) + + Add this graph to ``diag``, transferring ownership of it to ``diag``. + This won't appear in text sinks, but in SARIF sinks the graph will be + added to theResult.graphs (SARIF v2.1.0 3.27.19). + + Parameters ``diag`` and ``graph`` must both be non-null. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + +.. function:: void diagnostic_graph_release (diagnostic_graph *graph) + + Release ``graph`` which must still be owned by the caller + i.e. it must *not* have had + :func:`diagnostic_manager_take_global_graph` or + :func:`diagnostic_take_graph` called on it. + + Parameters ``graph`` can be null. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + + +.. function:: void diagnostic_graph_set_description (diagnostic_graph *graph, \ + const char *description) + + Set the description of ``graph`` for use in the value of the + SARIF ``description`` property (SARIF v2.1.0 section 3.39.2). + + The parameter ``graph`` must be non-null. + The parameter ``description`` can be null, for clearing any existing + description. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + +.. function:: diagnostic_node * diagnostic_graph_add_node (diagnostic_graph *graph, \ + const char *node_id, \ + diagnostic_node *parent_node) + + Create and add a new node within ``graph`` with the given `id``. + The id must be unique within nodes in ``graph``. + + The parameters ``graph`` and ``id`` must be non-null. + + ``parent_node`` can be NULL (for a top-level node in the graph), + or non-null for a child node, allowing for arbitrary nesting of + nodes. + + The new node is owned by ``graph``. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + +.. function:: diagnostic_edge * diagnostic_graph_add_edge (diagnostic_graph *graph, \ + const char *edge_id, \ + diagnostic_node *src_node, \ + diagnostic_node *dst_node, \ + const char *label) + + Create and add a new edge within ``graph``. + + The parameters ``graph``, ``src_node`` and ``dest_node`` + must be non-null. + + If non-null, then ``edge_id`` must be unique within ``graph``; + if ``edge_id`` is null then a unique id of the form "edge0", "edge1", + etc will be used automatically. + + If non-null, then ``label`` will be used for the value of the + SARIF ``label`` property (SARIF v2.1.0 section 3.41.3). + + The new edge is owned by ``graph``. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + +.. function:: diagnostic_node *diagnostic_graph_get_node_by_id (diagnostic_graph *graph, \ + const char *node_id) + + Get the node in ``graph`` with the given id, or null. + + The parameters ``graph`` and ``node_id`` must be non-null. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + +.. function:: diagnostic_edge *diagnostic_graph_get_edge_by_id (diagnostic_graph *graph, \ + const char *edge_id) + + Get the edge in ``graph`` with the given id, or null. + + The parameters ``graph`` and ``edge_id`` must be non-null. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + + +.. type:: diagnostic_node + +.. function:: void diagnostic_node_set_label (diagnostic_node *node, \ + const char *label) + + Set the label of ``node`` for use in the value of the + SARIF ``label`` property (SARIF v2.1.0 section 3.40.3). + + The parameter ``node`` must be non-null. + The parameter ``label`` can be null, for clearing any existing + label. + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + +.. function:: void diagnostic_node_set_location (diagnostic_node *node, \ + const diagnostic_physical_location *loc) + + Set the physical location of ``node``, if any. + + The parameter ``node`` must be non-null. + The parameter ``loc`` can be null, for clearing any existing + location. + + If set, the value will be used by SARIF sinks within the + ``location`` property (SARIF v2.1.0 section 3.40.4). + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. + +.. function:: void diagnostic_node_set_logical_location (diagnostic_node *node, \ + const diagnostic_logical_location *logical_loc) + + Set the logical location of ``node``, if any. + + The parameter ``node`` must be non-null. + The parameter ``logical_loc`` _can be null, for clearing any existing + location. + + If set, the value will be used by SARIF sinks within the + ``location`` property (SARIF v2.1.0 section 3.40.4). + + This function was added in :ref:`LIBGDIAGNOSTICS_ABI_3`. diff --git a/gcc/doc/libgdiagnostics/topics/index.rst b/gcc/doc/libgdiagnostics/topics/index.rst index 6eb3ed6..966f5ef 100644 --- a/gcc/doc/libgdiagnostics/topics/index.rst +++ b/gcc/doc/libgdiagnostics/topics/index.rst @@ -35,5 +35,6 @@ Topic reference execution-paths.rst text-output.rst sarif.rst + graphs.rst ux.rst compatibility.rst diff --git a/gcc/doc/libgdiagnostics/topics/logical-locations.rst b/gcc/doc/libgdiagnostics/topics/logical-locations.rst index 184b563..294d396 100644 --- a/gcc/doc/libgdiagnostics/topics/logical-locations.rst +++ b/gcc/doc/libgdiagnostics/topics/logical-locations.rst @@ -120,7 +120,7 @@ source location "equal" input values on the same :type:`diagnostic_manager` will return the same instance of :type:`diagnostic_logical_location`. "Equal" here includes different string buffers that compare as equal with - :func:``strcmp`. + :func:`strcmp`. .. function:: void diagnostic_manager_debug_dump_logical_location (const diagnostic_manager *diag_mgr, \ const diagnostic_logical_location *loc, \ @@ -147,8 +147,9 @@ Accessors The following functions can be used to access the data that was passed to a :type:`diagnostic_logical_location` when it was created. In each case, the -``loc`` parameter must be non-NULL. :type:`const char *` values will point -at copies of the original buffer. +``loc`` parameter must be non-NULL. The return values will point +at *copies* of the original buffer owned by the +:type:`diagnostic_logical_location`, or be null. .. function:: enum diagnostic_logical_location_kind_t diagnostic_logical_location_get_kind (const diagnostic_logical_location *loc) diff --git a/gcc/doc/libgdiagnostics/tutorial/02-physical-locations.rst b/gcc/doc/libgdiagnostics/tutorial/02-physical-locations.rst index 95b95ca..e64b668 100644 --- a/gcc/doc/libgdiagnostics/tutorial/02-physical-locations.rst +++ b/gcc/doc/libgdiagnostics/tutorial/02-physical-locations.rst @@ -112,10 +112,10 @@ leading to output like this:: foo.c:17: error: can't find 'foo.h'" 17 | #include <foo.h> -where libgdiagnostics will attempt to load the source file and +where libgdiagnostics will attempt to load ``foo.c`` and quote the pertinent line. -If libgdiagnostics cannot open the file, it will merely print:: +If libgdiagnostics cannot open ``foo.c``, it will merely print:: foo.c:17: error: can't find 'foo.h' @@ -160,14 +160,15 @@ On compiling and running the program, we should get this output:: 17 | #include <foo.h> | ^~~~~ -where libgdiagnostics will attempt to load the source file and +where libgdiagnostics will attempt to load ``foo.c`` and underling the pertinent part of the given line. -If libgdiagnostics cannot open the file, it will merely print:: +If libgdiagnostics cannot open ``foo.c``, it will merely print:: foo.c:17:8: error: can't find 'foo.h' -A range can span multiple lines within the same file. +A range can span multiple lines within the same file, but cannot +span multiple files. As before, you can use :func:`diagnostic_manager_debug_dump_location` to dump the locations. For the above example:: diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 168c475..b4fadac 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,30 @@ +2025-07-11 Paul Thomas <pault@gcc.gnu.org> + + PR fortran/106135 + * 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 + IMPORT statement. For scopes other than and interface body, if + the symbol cannot be found in the host scope, generate it and + set it up such that gfc_fixup_sibling_symbols can transfer its + 'imported attribute' if it turnes out to be a not yet parsed + procedure. Test for violations of C897-8100. + * gfortran.h : Add 'import_only' to the gfc_symtree structure. + Add the enum, 'importstate', which is used for values the new + field 'import_state' in gfc_namespace. + * parse.cc (gfc_fixup_sibling_symbols): Transfer the attribute + 'imported' to the new symbol. + * resolve.cc (check_sym_import_status, check_import_status): + New functions to test symbols and expressions for violations of + F2018:C8102. + (resolve_call): Test the 'resolved_sym' against C8102 by a call + to 'check_sym_import_status'. + (gfc_resolve_expr): If the expression is OK and an IMPORT + statement has been registered in the current scope, test C102 + by calling 'check_import_status'. + (resolve_select_type): Test the declared derived type in TYPE + IS and CLASS IS statements. + 2025-07-08 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/120637 diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc index 69acd2d..111ebc5 100644 --- a/gcc/fortran/decl.cc +++ b/gcc/fortran/decl.cc @@ -1723,13 +1723,17 @@ build_sym (const char *name, int elem, gfc_charlen *cl, bool cl_deferred, symbol_attribute attr; gfc_symbol *sym; int upper; - gfc_symtree *st; + gfc_symtree *st, *host_st = NULL; /* Symbols in a submodule are host associated from the parent module or submodules. Therefore, they can be overridden by declarations in the submodule scope. Deal with this by attaching the existing symbol to a new symtree and recycling the old symtree with a new symbol... */ st = gfc_find_symtree (gfc_current_ns->sym_root, name); + if (((st && st->import_only) || (gfc_current_ns->import_state == IMPORT_ALL)) + && gfc_current_ns->parent) + host_st = gfc_find_symtree (gfc_current_ns->parent->sym_root, name); + if (st != NULL && gfc_state_stack->state == COMP_SUBMODULE && st->n.sym != NULL && st->n.sym->attr.host_assoc && st->n.sym->attr.used_in_submodule) @@ -1742,6 +1746,20 @@ build_sym (const char *name, int elem, gfc_charlen *cl, bool cl_deferred, sym->refs++; gfc_set_sym_referenced (sym); } + /* ...Check that F2018 IMPORT, ONLY and IMPORT, ALL statements, within the + current scope are not violated by local redeclarations. Note that there is + no need to guard for std >= F2018 because import_only and IMPORT_ALL are + only set for these standards. */ + else if (host_st && host_st->n.sym + && host_st->n.sym != gfc_current_ns->proc_name + && !(st && st->n.sym + && (st->n.sym->attr.dummy || st->n.sym->attr.result))) + { + gfc_error ("F2018: C8102 %s at %L is already imported by an %s " + "statement and must not be re-declared", name, var_locus, + (st && st->import_only) ? "IMPORT, ONLY" : "IMPORT, ALL"); + return false; + } /* ...Otherwise generate a new symtree and new symbol. */ else if (gfc_get_symbol (name, NULL, &sym, var_locus)) return false; @@ -5100,6 +5118,54 @@ error: } +/* Match the IMPORT statement. IMPORT was added to F2003 as + + R1209 import-stmt is IMPORT [[ :: ] import-name-list ] + + C1210 (R1209) The IMPORT statement is allowed only in an interface-body. + + C1211 (R1209) Each import-name shall be the name of an entity in the + host scoping unit. + + under the description of an interface block. Under F2008, IMPORT was + split out of the interface block description to 12.4.3.3 and C1210 + became + + C1210 (R1209) The IMPORT statement is allowed only in an interface-body + that is not a module procedure interface body. + + Finally, F2018, section 8.8, has changed the IMPORT statement to + + R867 import-stmt is IMPORT [[ :: ] import-name-list ] + or IMPORT, ONLY : import-name-list + or IMPORT, NONE + or IMPORT, ALL + + C896 (R867) An IMPORT statement shall not appear in the scoping unit of + a main-program, external-subprogram, module, or block-data. + + C897 (R867) Each import-name shall be the name of an entity in the host + scoping unit. + + C898 If any IMPORT statement in a scoping unit has an ONLY specifier, + all IMPORT statements in that scoping unit shall have an ONLY + specifier. + + C899 IMPORT, NONE shall not appear in the scoping unit of a submodule. + + C8100 If an IMPORT, NONE or IMPORT, ALL statement appears in a scoping + unit, no other IMPORT statement shall appear in that scoping unit. + + C8101 Within an interface body, an entity that is accessed by host + association shall be accessible by host or use association within + the host scoping unit, or explicitly declared prior to the interface + body. + + C8102 An entity whose name appears as an import-name or which is made + accessible by an IMPORT, ALL statement shall not appear in any + context described in 19.5.1.4 that would cause the host entity + of that name to be inaccessible. */ + match gfc_match_import (void) { @@ -5107,16 +5173,28 @@ gfc_match_import (void) match m; gfc_symbol *sym; gfc_symtree *st; + bool f2018_allowed = gfc_option.allow_std & ~GFC_STD_OPT_F08;; + importstate current_import_state = gfc_current_ns->import_state; - if (gfc_current_ns->proc_name == NULL - || gfc_current_ns->proc_name->attr.if_source != IFSRC_IFBODY) + if (!f2018_allowed + && (gfc_current_ns->proc_name == NULL + || gfc_current_ns->proc_name->attr.if_source != IFSRC_IFBODY)) { gfc_error ("IMPORT statement at %C only permitted in " "an INTERFACE body"); return MATCH_ERROR; } + else if (f2018_allowed + && (!gfc_current_ns->parent || gfc_current_ns->is_block_data)) + goto C897; + + if (f2018_allowed + && (current_import_state == IMPORT_ALL + || current_import_state == IMPORT_NONE)) + goto C8100; - if (gfc_current_ns->proc_name->attr.module_procedure) + if (gfc_current_ns->proc_name + && gfc_current_ns->proc_name->attr.module_procedure) { gfc_error ("F2008: C1210 IMPORT statement at %C is not permitted " "in a module procedure interface body"); @@ -5126,20 +5204,65 @@ gfc_match_import (void) if (!gfc_notify_std (GFC_STD_F2003, "IMPORT statement at %C")) return MATCH_ERROR; + gfc_current_ns->import_state = IMPORT_NOT_SET; + if (f2018_allowed) + { + if (gfc_match (" , none") == MATCH_YES) + { + if (current_import_state == IMPORT_ONLY) + goto C898; + if (gfc_current_state () == COMP_SUBMODULE) + goto C899; + gfc_current_ns->import_state = IMPORT_NONE; + } + else if (gfc_match (" , only :") == MATCH_YES) + { + if (current_import_state != IMPORT_NOT_SET + && current_import_state != IMPORT_ONLY) + goto C898; + gfc_current_ns->import_state = IMPORT_ONLY; + } + else if (gfc_match (" , all") == MATCH_YES) + { + if (current_import_state == IMPORT_ONLY) + goto C898; + gfc_current_ns->import_state = IMPORT_ALL; + } + + if (current_import_state != IMPORT_NOT_SET + && (gfc_current_ns->import_state == IMPORT_NONE + || gfc_current_ns->import_state == IMPORT_ALL)) + goto C8100; + } + + /* F2008 IMPORT<eos> is distinct from F2018 IMPORT, ALL. */ if (gfc_match_eos () == MATCH_YES) { - /* All host variables should be imported. */ - gfc_current_ns->has_import_set = 1; + /* This is the F2008 variant. */ + if (gfc_current_ns->import_state == IMPORT_NOT_SET) + { + if (current_import_state == IMPORT_ONLY) + goto C898; + gfc_current_ns->import_state = IMPORT_F2008; + } + + /* Host variables should be imported. */ + if (gfc_current_ns->import_state != IMPORT_NONE) + gfc_current_ns->has_import_set = 1; return MATCH_YES; } - if (gfc_match (" ::") == MATCH_YES) + if (gfc_match (" ::") == MATCH_YES + && gfc_current_ns->import_state != IMPORT_ONLY) { if (gfc_match_eos () == MATCH_YES) - { - gfc_error ("Expecting list of named entities at %C"); - return MATCH_ERROR; - } + goto expecting_list; + gfc_current_ns->import_state = IMPORT_F2008; + } + else if (gfc_current_ns->import_state == IMPORT_ONLY) + { + if (gfc_match_eos () == MATCH_YES) + goto expecting_list; } for(;;) @@ -5166,12 +5289,28 @@ gfc_match_import (void) if (sym == NULL) { - gfc_error ("Cannot IMPORT %qs from host scoping unit " - "at %C - does not exist.", name); - return MATCH_ERROR; + if (gfc_current_ns->proc_name->attr.if_source == IFSRC_IFBODY) + { + gfc_error ("Cannot IMPORT %qs from host scoping unit " + "at %C - does not exist.", name); + return MATCH_ERROR; + } + else + { + /* 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, gfc_current_ns, &st, false, + &gfc_current_locus); + st->n.sym->refs++; + st->n.sym->attr.imported = 1; + st->import_only = 1; + goto next_item; + } } - if (gfc_find_symtree (gfc_current_ns->sym_root, name)) + st = gfc_find_symtree (gfc_current_ns->sym_root, name); + if (st && st->n.sym && st->n.sym->attr.imported) { gfc_warning (0, "%qs is already IMPORTed from host scoping unit " "at %C", name); @@ -5182,6 +5321,7 @@ gfc_match_import (void) st->n.sym = sym; sym->refs++; sym->attr.imported = 1; + st->import_only = 1; if (sym->attr.generic && (sym = gfc_find_dt_in_generic (sym))) { @@ -5193,6 +5333,7 @@ gfc_match_import (void) st->n.sym = sym; sym->refs++; sym->attr.imported = 1; + st->import_only = 1; } goto next_item; @@ -5216,6 +5357,34 @@ gfc_match_import (void) syntax: gfc_error ("Syntax error in IMPORT statement at %C"); return MATCH_ERROR; + +C897: + gfc_error ("F2018: C897 IMPORT statement at %C cannot appear in a main " + "program, an external subprogram, a module or block data"); + return MATCH_ERROR; + +C898: + gfc_error ("F2018: C898 IMPORT statement at %C is not permitted because " + "a scoping unit has an ONLY specifier, can only have IMPORT " + "with an ONLY specifier"); + return MATCH_ERROR; + +C899: + gfc_error ("F2018: C899 IMPORT, NONE shall not appear in the scoping unit" + " of a submodule as at %C"); + return MATCH_ERROR; + +C8100: + gfc_error ("F2018: C8100 IMPORT statement at %C is not permitted because " + "%s has already been declared, which must be unique in the " + "scoping unit", + gfc_current_ns->import_state == IMPORT_ALL ? "IMPORT, ALL" : + "IMPORT, NONE"); + return MATCH_ERROR; + +expecting_list: + gfc_error ("Expecting list of named entities at %C"); + return MATCH_ERROR; } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 6848bd1..4c85548 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2188,6 +2188,7 @@ typedef struct gfc_symtree gfc_omp_udr *omp_udr; } n; + unsigned import_only:1; } gfc_symtree; @@ -2215,6 +2216,17 @@ typedef struct gfc_was_finalized { } gfc_was_finalized; + + /* Flag F2018 import status */ +enum importstate +{ IMPORT_NOT_SET = 0, /* Default condition. */ + IMPORT_F2008, /* Old style IMPORT. */ + IMPORT_ONLY, /* Import list used. */ + IMPORT_NONE, /* No host association. Unique in scoping unit. */ + IMPORT_ALL /* Must be unique in the scoping unit. */ +}; + + /* A namespace describes the contents of procedure, module, interface block or BLOCK construct. */ /* ??? Anything else use these? */ @@ -2328,6 +2340,10 @@ typedef struct gfc_namespace /* Set to 1 if namespace is an interface body with "IMPORT" used. */ unsigned has_import_set:1; + /* Flag F2018 import status */ + ENUM_BITFIELD (importstate) import_state :3; + + /* Set to 1 if the namespace uses "IMPLICIT NONE (export)". */ unsigned has_implicit_none_export:1; diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index da085d1..0b893e8 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -1170,6 +1170,10 @@ A @code{CHARACTER} variable is declared with negative length. With @option{-fopenmp}, for fixed-form source code, when an @code{omx} vendor-extension sentinel is encountered. (The equivalent @code{ompx}, used in free-form source code, is diagnosed by default.) + +@item +With @option{-fopenacc}, when using named constances with clauses that +take a variable as doing so has no effect. @end itemize @opindex Wtabs diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index fe0a47a..f1acc00 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -8895,15 +8895,21 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses, if (list == OMP_LIST_MAP && n->sym->attr.flavor == FL_PARAMETER) { + /* OpenACC since 3.4 permits for Fortran named constants, but + permits removing then as optimization is not needed and such + ignore them. Likewise below for FIRSTPRIVATE. */ if (openacc) - gfc_error ("Object %qs is not a variable at %L; parameters" - " cannot be and need not be copied", n->sym->name, - &n->where); + gfc_warning (OPT_Wsurprising, "Clause for object %qs at %L is " + "ignored as parameters need not be copied", + n->sym->name, &n->where); else gfc_error ("Object %qs is not a variable at %L; parameters" " cannot be and need not be mapped", n->sym->name, &n->where); } + else if (openacc && n->sym->attr.flavor == FL_PARAMETER) + gfc_warning (OPT_Wsurprising, "Clause for object %qs at %L is ignored" + " as it is a parameter", n->sym->name, &n->where); else if (list != OMP_LIST_USES_ALLOCATORS) gfc_error ("Object %qs is not a variable at %L", n->sym->name, &n->where); @@ -12756,9 +12762,21 @@ gfc_resolve_oacc_declare (gfc_namespace *ns) && (n->sym->attr.flavor != FL_PROCEDURE || n->sym->result != n->sym)) { - gfc_error ("Object %qs is not a variable at %L", - n->sym->name, &oc->loc); - continue; + if (n->sym->attr.flavor != FL_PARAMETER) + { + gfc_error ("Object %qs is not a variable at %L", + n->sym->name, &oc->loc); + continue; + } + /* Note that OpenACC 3.4 permits name constants, but the + implementation is permitted to ignore the clause; + as semantically, device_resident kind of makes sense + (and the wording with it is a bit odd), the warning + is suppressed. */ + if (list != OMP_LIST_DEVICE_RESIDENT) + gfc_warning (OPT_Wsurprising, "Object %qs at %L is ignored as" + " parameters need not be copied", n->sym->name, + &oc->loc); } if (n->expr && n->expr->ref->type == REF_ARRAY) diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index 8d4ca39..847ff37 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -6793,6 +6793,7 @@ gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings) gfc_namespace *ns; gfc_symtree *st; gfc_symbol *old_sym; + bool imported; for (ns = siblings; ns; ns = ns->sibling) { @@ -6808,6 +6809,7 @@ gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings) goto fixup_contained; old_sym = st->n.sym; + imported = old_sym->attr.imported == 1; if (old_sym->ns == ns && !old_sym->attr.contained @@ -6834,7 +6836,8 @@ gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings) /* Replace it with the symbol from the parent namespace. */ st->n.sym = sym; sym->refs++; - + if (imported) + sym->attr.imported = 1; gfc_release_symbol (old_sym); } diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 4a6e951..93df5d0 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -3919,10 +3919,153 @@ found: } + +static bool +check_sym_import_status (gfc_symbol *sym, gfc_symtree *s, gfc_expr *e, + gfc_code *c, gfc_namespace *ns) +{ + locus *here; + + /* If the type has been imported then its vtype functions are OK. */ + if (e && e->expr_type == EXPR_FUNCTION && sym->attr.vtype) + return true; + + if (e) + here = &e->where; + else + here = &c->loc; + + if (s && !s->import_only) + s = gfc_find_symtree (ns->sym_root, sym->name); + + if (ns->import_state == IMPORT_ONLY + && sym->ns != ns + && (!s || !s->import_only)) + { + gfc_error ("F2018: C8102 %qs at %L is host associated but does not " + "appear in an IMPORT or IMPORT, ONLY list", sym->name, here); + return false; + } + else if (ns->import_state == IMPORT_NONE + && sym->ns != ns) + { + gfc_error ("F2018: C8102 %qs at %L is host associated in a scope that " + "has IMPORT, NONE", sym->name, here); + return false; + } + return true; +} + + +static bool +check_import_status (gfc_expr *e) +{ + gfc_symtree *st; + gfc_ref *ref; + gfc_symbol *sym, *der; + gfc_namespace *ns = gfc_current_ns; + + switch (e->expr_type) + { + case EXPR_VARIABLE: + case EXPR_FUNCTION: + case EXPR_SUBSTRING: + sym = e->symtree ? e->symtree->n.sym : NULL; + + /* Check the symbol itself. */ + if (sym + && !(ns->proc_name + && (sym == ns->proc_name)) + && !check_sym_import_status (sym, e->symtree, e, NULL, ns)) + return false; + + /* Check the declared derived type. */ + if (sym->ts.type == BT_DERIVED) + { + der = sym->ts.u.derived; + st = gfc_find_symtree (ns->sym_root, der->name); + + if (!check_sym_import_status (der, st, e, NULL, ns)) + return false; + } + else if (sym->ts.type == BT_CLASS && !UNLIMITED_POLY (sym)) + { + der = CLASS_DATA (sym) ? CLASS_DATA (sym)->ts.u.derived + : sym->ts.u.derived; + st = gfc_find_symtree (ns->sym_root, der->name); + + if (!check_sym_import_status (der, st, e, NULL, ns)) + return false; + } + + /* Check the declared derived types of component references. */ + for (ref = e->ref; ref; ref = ref->next) + if (ref->type == REF_COMPONENT) + { + gfc_component *c = ref->u.c.component; + if (c->ts.type == BT_DERIVED) + { + der = c->ts.u.derived; + st = gfc_find_symtree (ns->sym_root, der->name); + if (!check_sym_import_status (der, st, e, NULL, ns)) + return false; + } + else if (c->ts.type == BT_CLASS && !UNLIMITED_POLY (c)) + { + der = CLASS_DATA (c) ? CLASS_DATA (c)->ts.u.derived + : c->ts.u.derived; + st = gfc_find_symtree (ns->sym_root, der->name); + if (!check_sym_import_status (der, st, e, NULL, ns)) + return false; + } + } + + break; + + case EXPR_ARRAY: + case EXPR_STRUCTURE: + /* Check the declared derived type. */ + if (e->ts.type == BT_DERIVED) + { + der = e->ts.u.derived; + st = gfc_find_symtree (ns->sym_root, der->name); + + if (!check_sym_import_status (der, st, e, NULL, ns)) + return false; + } + else if (e->ts.type == BT_CLASS && !UNLIMITED_POLY (e)) + { + der = CLASS_DATA (e) ? CLASS_DATA (e)->ts.u.derived + : e->ts.u.derived; + st = gfc_find_symtree (ns->sym_root, der->name); + + if (!check_sym_import_status (der, st, e, NULL, ns)) + return false; + } + + break; + +/* Either not applicable or resolved away + case EXPR_OP: + case EXPR_UNKNOWN: + case EXPR_CONSTANT: + case EXPR_NULL: + case EXPR_COMPCALL: + case EXPR_PPC: */ + + default: + break; + } + + return true; +} + + /* Resolve a subroutine call. Although it was tempting to use the same code for functions, subroutines and functions are stored differently and this makes things awkward. */ + static bool resolve_call (gfc_code *c) { @@ -4080,6 +4223,11 @@ resolve_call (gfc_code *c) "Using subroutine %qs at %L is deprecated", c->resolved_sym->name, &c->loc); + csym = c->resolved_sym ? c->resolved_sym : csym; + if (t && gfc_current_ns->import_state != IMPORT_NOT_SET && !c->resolved_isym + && csym != gfc_current_ns->proc_name) + return check_sym_import_status (csym, c->symtree, NULL, c, gfc_current_ns); + return t; } @@ -7792,6 +7940,7 @@ fixup_unique_dummy (gfc_expr *e) e->symtree = st; } + /* Resolve an expression. That is, make sure that types of operands agree with their operators, intrinsic operators are converted to function calls for overloaded types and unresolved function references are resolved. */ @@ -7919,6 +8068,9 @@ gfc_resolve_expr (gfc_expr *e) && UNLIMITED_POLY (e->symtree->n.sym)) e->do_not_resolve_again = 1; + if (t && gfc_current_ns->import_state != IMPORT_NOT_SET) + t = check_import_status (e); + return t; } @@ -10572,6 +10724,7 @@ resolve_select_type (gfc_code *code, gfc_namespace *old_ns) int rank = 0, corank = 0; gfc_ref* ref = NULL; gfc_expr *selector_expr = NULL; + gfc_code *old_code = code; ns = code->ext.block.ns; if (code->expr2) @@ -10860,6 +11013,18 @@ resolve_select_type (gfc_code *code, gfc_namespace *old_ns) when this case is actually true, so build a new ASSOCIATE that does precisely this here (instead of using the 'global' one). */ + + /* First check the derived type import status. */ + if (gfc_current_ns->import_state != IMPORT_NOT_SET + && (c->ts.type == BT_DERIVED || c->ts.type == BT_CLASS)) + { + st = gfc_find_symtree (gfc_current_ns->sym_root, + c->ts.u.derived->name); + if (!check_sym_import_status (c->ts.u.derived, st, NULL, old_code, + gfc_current_ns)) + error++; + } + const char * var_name = gfc_var_name_for_select_type_temp (orig_expr1); if (c->ts.type == BT_CLASS) snprintf (name, sizeof (name), "__tmp_class_%s_%s", diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index a2e70fc..f3d7cd4 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -2792,8 +2792,13 @@ gfc_trans_omp_variable_list (enum omp_clause_code code, gfc_omp_namelist *namelist, tree list, bool declare_simd) { + /* PARAMETER (named constants) are excluded as OpenACC 3.4 permits them now + as 'var' but permits compilers to ignore them. In expressions, it should + have been replaced by the value (and this function should not be called + anyway) and for var-using clauses, they should just be skipped. */ for (; namelist != NULL; namelist = namelist->next) - if (namelist->sym->attr.referenced || declare_simd) + if ((namelist->sym->attr.referenced || declare_simd) + && namelist->sym->attr.flavor != FL_PARAMETER) { tree t = gfc_trans_omp_variable (namelist->sym, declare_simd); if (t != error_mark_node) @@ -4029,7 +4034,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, case OMP_LIST_MAP: for (; n != NULL; n = n->next) { - if (!n->sym->attr.referenced) + if (!n->sym->attr.referenced + || n->sym->attr.flavor == FL_PARAMETER) continue; location_t map_loc = gfc_get_location (&n->where); @@ -4986,7 +4992,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, case OMP_LIST_CACHE: for (; n != NULL; n = n->next) { - if (!n->sym->attr.referenced) + if (!n->sym->attr.referenced + && n->sym->attr.flavor != FL_PARAMETER) continue; switch (list) diff --git a/gcc/graphviz.h b/gcc/graphviz.h index 5943589..9a0fe6f 100644 --- a/gcc/graphviz.h +++ b/gcc/graphviz.h @@ -311,6 +311,16 @@ struct node_id : public ast_node m_port = std::make_unique<port> (*other.m_port); } + node_id &operator= (const node_id &other) + { + m_id = other.m_id; + if (other.m_port) + m_port = std::make_unique<port> (*other.m_port); + else + m_port = nullptr; + return *this; + } + void print (writer &w) const final override; id m_id; diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc index ed6ef0e..044bdc2 100644 --- a/gcc/internal-fn.cc +++ b/gcc/internal-fn.cc @@ -3442,25 +3442,23 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt) } /* Expand the IFN_ACCESS_WITH_SIZE function: - ACCESS_WITH_SIZE (REF_TO_OBJ, REF_TO_SIZE, CLASS_OF_SIZE, - TYPE_OF_SIZE, ACCESS_MODE) + ACCESS_WITH_SIZE (REF_TO_OBJ, REF_TO_SIZE, + TYPE_OF_SIZE + ACCESS_MODE, TYPE_SIZE_UNIT for element) which returns the REF_TO_OBJ same as the 1st argument; 1st argument REF_TO_OBJ: The reference to the object; 2nd argument REF_TO_SIZE: The reference to the size of the object, - 3rd argument CLASS_OF_SIZE: The size referenced by the REF_TO_SIZE represents - 0: the number of bytes. - 1: the number of the elements of the object type; - 4th argument TYPE_OF_SIZE: A constant 0 with its TYPE being the same as the TYPE - of the object referenced by REF_TO_SIZE - 5th argument ACCESS_MODE: - -1: Unknown access semantics - 0: none - 1: read_only - 2: write_only - 3: read_write - 6th argument: A constant 0 with the pointer TYPE to the original flexible - array type. + 3rd argument TYPE_OF_SIZE + ACCESS_MODE: An integer constant with a pointer + TYPE. + The pointee TYPE of the pointer TYPE is the TYPE of the object referenced + by REF_TO_SIZE. + The integer constant value represents the ACCESS_MODE: + 0: none + 1: read_only + 2: write_only + 3: read_write + + 4th argument: The TYPE_SIZE_UNIT of the element TYPE of the array. Both the return type and the type of the first argument of this function have been converted from the incomplete array type to diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def index 914ee9f2..d2480a1 100644 --- a/gcc/internal-fn.def +++ b/gcc/internal-fn.def @@ -525,7 +525,7 @@ DEF_INTERNAL_FN (DEFERRED_INIT, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) /* A function to associate the access size and access mode information with the corresponding reference to an object. It only reads from the - 2nd argument. */ + 2nd and the 4th arguments. */ DEF_INTERNAL_FN (ACCESS_WITH_SIZE, ECF_PURE | ECF_LEAF | ECF_NOTHROW, NULL) /* DIM_SIZE and DIM_POS return the size of a particular compute diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc index 48343a7..924a54b 100644 --- a/gcc/ipa-fnsummary.cc +++ b/gcc/ipa-fnsummary.cc @@ -3421,6 +3421,21 @@ compute_fn_summary (struct cgraph_node *node, bool early) info->inlinable = tree_inlinable_function_p (node->decl); bool no_signature = false; + + /* Don't allow signature changes for functions which have + [[gnu::musttail]] or [[clang::musttail]] calls. Sometimes + (more often on targets which pass everything on the stack) + signature changes can result in tail calls being impossible + even when without the signature changes they would be ok. + See PR121023. */ + if (cfun->has_musttail) + { + if (dump_file) + fprintf (dump_file, "No signature change:" + " function has calls with musttail attribute.\n"); + no_signature = true; + } + /* Type attributes can use parameter indices to describe them. Special case fn spec since we can safely preserve them in modref summaries. */ diff --git a/gcc/json.cc b/gcc/json.cc index f3f3645..7153f08 100644 --- a/gcc/json.cc +++ b/gcc/json.cc @@ -289,6 +289,30 @@ object::print (pretty_printer *pp, bool formatted) const pp_character (pp, '}'); } +std::unique_ptr<value> +object::clone () const +{ + return clone_as_object (); +} + +std::unique_ptr<object> +object::clone_as_object () const +{ + auto result = std::make_unique<object> (); + + /* Iterate in the order that the keys were inserted. */ + unsigned i; + const char *key; + FOR_EACH_VEC_ELT (m_keys, i, key) + { + map_t &mut_map = const_cast<map_t &> (m_map); + value *value = *mut_map.get (key); + result->set (key, value->clone ()); + } + + return result; +} + /* Set the json::value * for KEY, taking ownership of V (and taking a copy of KEY if necessary). */ @@ -443,6 +467,17 @@ array::print (pretty_printer *pp, bool formatted) const pp_character (pp, ']'); } +std::unique_ptr<value> +array::clone () const +{ + auto result = std::make_unique<array> (); + unsigned i; + value *v; + FOR_EACH_VEC_ELT (m_elements, i, v) + result->append (v->clone ()); + return result; +} + /* Append non-NULL value V to a json::array, taking ownership of V. */ void @@ -473,6 +508,12 @@ float_number::print (pretty_printer *pp, pp_string (pp, tmp); } +std::unique_ptr<value> +float_number::clone () const +{ + return std::make_unique<float_number> (m_value); +} + /* class json::integer_number, a subclass of json::value, wrapping a long. */ /* Implementation of json::value::print for json::integer_number. */ @@ -486,6 +527,11 @@ integer_number::print (pretty_printer *pp, pp_string (pp, tmp); } +std::unique_ptr<value> +integer_number::clone () const +{ + return std::make_unique<integer_number> (m_value); +} /* class json::string, a subclass of json::value. */ @@ -501,9 +547,10 @@ string::string (const char *utf8) string::string (const char *utf8, size_t len) { gcc_assert (utf8); - m_utf8 = XNEWVEC (char, len); + m_utf8 = XNEWVEC (char, len + 1); m_len = len; memcpy (m_utf8, utf8, len); + m_utf8[len] = '\0'; } /* Implementation of json::value::print for json::string. */ @@ -515,6 +562,12 @@ string::print (pretty_printer *pp, print_escaped_json_string (pp, m_utf8, m_len); } +std::unique_ptr<value> +string::clone () const +{ + return std::make_unique<string> (m_utf8, m_len); +} + /* class json::literal, a subclass of json::value. */ /* Implementation of json::value::print for json::literal. */ @@ -539,6 +592,12 @@ literal::print (pretty_printer *pp, } } +std::unique_ptr<value> +literal::clone () const +{ + return std::make_unique<literal> (m_kind); +} + #if CHECKING_P @@ -914,6 +973,65 @@ test_comparisons () ASSERT_JSON_NE (arr_1, arr_2); } +/* Ensure that json::string's get_string is usable as a C-style string. */ + +static void +test_strcmp () +{ + string str ("foobar", 3); + ASSERT_EQ (strcmp (str.get_string (), "foo"), 0); +} + +static void +test_cloning () +{ + // Objects + { + object obj; + obj.set_string ("foo", "bar"); + + auto obj_clone = obj.clone (); + ASSERT_JSON_EQ (obj, *obj_clone); + } + + // Arrays + { + array arr; + arr.append (std::make_unique<string> ("foo")); + + auto arr_clone = arr.clone (); + ASSERT_JSON_EQ (arr, *arr_clone); + } + + // float_number + { + float_number f_one (1.0); + auto f_clone = f_one.clone (); + ASSERT_JSON_EQ (f_one, *f_clone); + } + + // integer_number + { + integer_number num (42); + auto num_clone = num.clone (); + ASSERT_JSON_EQ (num, *num_clone); + } + + // string + { + string str ("foo"); + auto str_clone = str.clone (); + ASSERT_JSON_EQ (str, *str_clone); + } + + // literal + { + literal lit (JSON_TRUE); + auto lit_clone = lit.clone (); + ASSERT_JSON_EQ (lit, *lit_clone); + } +} + /* Run all of the selftests within this file. */ void @@ -928,6 +1046,8 @@ json_cc_tests () test_writing_literals (); test_formatting (); test_comparisons (); + test_strcmp (); + test_cloning (); } } // namespace selftest @@ -124,11 +124,13 @@ class value virtual ~value () {} virtual enum kind get_kind () const = 0; virtual void print (pretty_printer *pp, bool formatted) const = 0; + virtual std::unique_ptr<value> clone () const = 0; void dump (FILE *, bool formatted) const; void DEBUG_FUNCTION dump () const; virtual object *dyn_cast_object () { return nullptr; } + virtual string *dyn_cast_string () { return nullptr; } static int compare (const json::value &val_a, const json::value &val_b); @@ -150,6 +152,7 @@ class object : public value enum kind get_kind () const final override { return JSON_OBJECT; } void print (pretty_printer *pp, bool formatted) const final override; + std::unique_ptr<value> clone () const final override; object *dyn_cast_object () final override { return this; } @@ -182,6 +185,11 @@ class object : public value static int compare (const json::object &obj_a, const json::object &obj_b); + size_t get_num_keys () const { return m_keys.length (); } + const char *get_key (size_t i) const { return m_keys[i]; } + + std::unique_ptr<object> clone_as_object () const; + private: typedef hash_map <char *, value *, simple_hashmap_traits<nofree_string_hash, value *> > map_t; @@ -200,6 +208,7 @@ class array : public value enum kind get_kind () const final override { return JSON_ARRAY; } void print (pretty_printer *pp, bool formatted) const final override; + std::unique_ptr<value> clone () const final override; void append (value *v); void append_string (const char *utf8_value); @@ -241,6 +250,7 @@ class float_number : public value enum kind get_kind () const final override { return JSON_FLOAT; } void print (pretty_printer *pp, bool formatted) const final override; + std::unique_ptr<value> clone () const final override; double get () const { return m_value; } @@ -257,6 +267,7 @@ class integer_number : public value enum kind get_kind () const final override { return JSON_INTEGER; } void print (pretty_printer *pp, bool formatted) const final override; + std::unique_ptr<value> clone () const final override; long get () const { return m_value; } @@ -276,6 +287,8 @@ class string : public value enum kind get_kind () const final override { return JSON_STRING; } void print (pretty_printer *pp, bool formatted) const final override; + std::unique_ptr<value> clone () const final override; + string *dyn_cast_string () final override { return this; } const char *get_string () const { return m_utf8; } size_t get_length () const { return m_len; } @@ -298,6 +311,7 @@ class literal : public value enum kind get_kind () const final override { return m_kind; } void print (pretty_printer *pp, bool formatted) const final override; + std::unique_ptr<value> clone () const final override; private: enum kind m_kind; diff --git a/gcc/libgdiagnostics++.h b/gcc/libgdiagnostics++.h index 93b8f90..4beee44 100644 --- a/gcc/libgdiagnostics++.h +++ b/gcc/libgdiagnostics++.h @@ -34,6 +34,9 @@ class execution_path; class group; class manager; class diagnostic; +class graph; +class node; +class edge; /* Wrapper around a borrowed diagnostic_text_sink *. */ @@ -246,6 +249,9 @@ public: take_execution_path (execution_path path); void + take_graph (graph g); + + void finish (const char *fmt, ...) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (2) LIBGDIAGNOSTICS_PARAM_GCC_FORMAT_STRING (2, 3); @@ -395,10 +401,99 @@ public: void set_analysis_target (file f); + void + take_global_graph (graph g); + diagnostic_manager *m_inner; bool m_owned; }; +class graph +{ +public: + graph () : m_inner (nullptr), m_owned (false) {} + + graph (diagnostic_graph *graph) + : m_inner (graph), m_owned (true) + {} + + graph (const diagnostic_graph *graph) + : m_inner (const_cast<diagnostic_graph *> (graph)), + m_owned (false) + {} + + graph (const graph &other) = delete; + graph &operator= (const graph &other) = delete; + + graph (graph &&other) + : m_inner (other.m_inner), + m_owned (other.m_owned) + { + other.m_inner = nullptr; + other.m_owned = false; + } + + graph &operator= (graph &&other) + { + m_inner = other.m_inner; + m_owned = other.m_owned; + other.m_inner = nullptr; + other.m_owned = false; + return *this; + } + + ~graph () + { + if (m_owned) + diagnostic_graph_release (m_inner); + } + + void + set_description (const char *); + + node + get_node_by_id (const char *id) const; + + edge + get_edge_by_id (const char *id) const; + + edge + add_edge (const char *id, node src_node, node dst_node, const char *label); + + diagnostic_graph *m_inner; + bool m_owned; +}; + +// Borrowed pointer to a diagnostic_node. + +class node +{ +public: + node () : m_inner (nullptr) {} + node (diagnostic_node *node_) : m_inner (node_) {} + + void + set_label (const char *); + + void + set_location (physical_location loc); + + void + set_logical_location (logical_location loc); + + diagnostic_node *m_inner; +}; + +// Borrowed edge to a diagnostic_edge. + +class edge +{ +public: + edge (diagnostic_edge *edge_) : m_inner (edge_) {} + + diagnostic_edge *m_inner; +}; + // Implementation // class file @@ -593,6 +688,14 @@ diagnostic::take_execution_path (execution_path path) } inline void +diagnostic::take_graph (graph g) +{ + diagnostic_take_graph (m_inner, + g.m_inner); + g.m_owned = false; +} + +inline void diagnostic::finish (const char *fmt, ...) { va_list ap; @@ -702,6 +805,66 @@ manager::set_analysis_target (file f) diagnostic_manager_set_analysis_target (m_inner, f.m_inner); } +inline void +manager::take_global_graph (graph g) +{ + diagnostic_manager_take_global_graph (m_inner, + g.m_inner); + g.m_owned = false; +} + +// class graph + +inline void +graph::set_description (const char *desc) +{ + diagnostic_graph_set_description (m_inner, desc); +} + +inline node +graph::get_node_by_id (const char *id) const +{ + return node (diagnostic_graph_get_node_by_id (m_inner, id)); +} + +inline edge +graph::get_edge_by_id (const char *id) const +{ + return edge (diagnostic_graph_get_edge_by_id (m_inner, id)); +} + +inline edge +graph::add_edge (const char *id, + node src_node, node dst_node, + const char *label) +{ + return edge (diagnostic_graph_add_edge (m_inner, + id, + src_node.m_inner, + dst_node.m_inner, + label)); +} + +// class node + +inline void +node::set_label (const char *label) +{ + diagnostic_node_set_label (m_inner, label); +} + +inline void +node::set_location (physical_location loc) +{ + diagnostic_node_set_location (m_inner, loc.m_inner); +} + +inline void +node::set_logical_location (logical_location loc) +{ + diagnostic_node_set_logical_location (m_inner, loc.m_inner); +} + } // namespace libgdiagnostics #endif // #ifndef LIBGDIAGNOSTICSPP_H diff --git a/gcc/libgdiagnostics-private.h b/gcc/libgdiagnostics-private.h new file mode 100644 index 0000000..0f628e4 --- /dev/null +++ b/gcc/libgdiagnostics-private.h @@ -0,0 +1,62 @@ +/* Private API entrypoints to libgdiagnostics purely for use by sarif-replay. + Copyright (C) 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 LIBGDIAGNOSTICS_PRIVATE_H +#define LIBGDIAGNOSTICS_PRIVATE_H + +#include "libgdiagnostics.h" + +namespace json { class object; } + +extern "C" { + +/* Private entrypoints, for use only by sarif-replay. + These are subject to removal without notice. */ + +/* Entrypoints added in LIBGDIAGNOSTICS_ABI_3. */ + +extern diagnostic_event_id +private_diagnostic_execution_path_add_event_2 (diagnostic_execution_path *path, + const diagnostic_physical_location *physical_loc, + const diagnostic_logical_location *logical_loc, + unsigned stack_depth, + diagnostic_graph *state_graph, + const char *fmt, ...) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (2) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (3) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (5) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (6) + LIBGDIAGNOSTICS_PARAM_GCC_FORMAT_STRING (6, 7); + +extern void +private_diagnostic_graph_set_property_bag (diagnostic_graph &graph, + std::unique_ptr<json::object> properties); + +extern void +private_diagnostic_node_set_property_bag (diagnostic_node &node, + std::unique_ptr<json::object> properties); + +extern void +private_diagnostic_edge_set_property_bag (diagnostic_edge &edge, + std::unique_ptr<json::object> properties); + +} // extern "C" + +#endif /* LIBGDIAGNOSTICS_PRIVATE_H */ diff --git a/gcc/libgdiagnostics.cc b/gcc/libgdiagnostics.cc index 74814c7..04812dc 100644 --- a/gcc/libgdiagnostics.cc +++ b/gcc/libgdiagnostics.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #define INCLUDE_MAP +#define INCLUDE_STRING #define INCLUDE_VECTOR #include "system.h" #include "coretypes.h" @@ -32,9 +33,12 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-format-sarif.h" #include "diagnostic-format-text.h" #include "diagnostic-output-spec.h" +#include "diagnostic-digraphs.h" +#include "diagnostic-state-graphs.h" #include "logical-location.h" #include "edit-context.h" #include "libgdiagnostics.h" +#include "libgdiagnostics-private.h" class owned_nullable_string { @@ -644,6 +648,9 @@ public: return m_prev_diag_logical_loc; } + void + take_global_graph (std::unique_ptr<diagnostic_graph> graph); + private: void ensure_linemap_for_file_and_line (const diagnostic_file *file, @@ -743,17 +750,53 @@ private: owned_nullable_string m_url; }; +struct diagnostic_graph : public diagnostics::digraphs::digraph +{ + diagnostic_graph (diagnostic_manager &) {} + + diagnostic_node * + add_node_with_id (std::string id, + diagnostic_node *parent_node); + diagnostic_edge * + add_edge_with_label (const char *id, + diagnostic_node &src_node, + diagnostic_node &dst_node, + const char *label); +}; + +struct diagnostic_node : public diagnostics::digraphs::node +{ + diagnostic_node (diagnostic_graph &g, + std::string id) + : node (g, std::move (id)) + { + } +}; + +struct diagnostic_edge : public diagnostics::digraphs::edge +{ + diagnostic_edge (diagnostic_graph &g, + const char *id, + diagnostic_node &src_node, + diagnostic_node &dst_node) + : edge (g, id, src_node, dst_node) + { + } +}; + class libgdiagnostics_path_event : public diagnostic_event { public: libgdiagnostics_path_event (const diagnostic_physical_location *physical_loc, const diagnostic_logical_location *logical_loc, unsigned stack_depth, + std::unique_ptr<diagnostic_graph> state_graph, const char *gmsgid, va_list *args) : m_physical_loc (physical_loc), m_logical_loc (logical_loc), - m_stack_depth (stack_depth) + m_stack_depth (stack_depth), + m_state_graph (std::move (state_graph)) { m_desc_uncolored = make_desc (gmsgid, args, false); m_desc_colored = make_desc (gmsgid, args, true); @@ -799,6 +842,15 @@ public: return 0; } + std::unique_ptr<diagnostics::digraphs::digraph> + maybe_make_diagnostic_state_graph (bool) const final override + { + if (!m_state_graph) + return nullptr; + + return m_state_graph->clone (); + } + private: static label_text make_desc (const char *gmsgid, va_list *args, @@ -824,6 +876,7 @@ private: const diagnostic_physical_location *m_physical_loc; const diagnostic_logical_location *m_logical_loc; unsigned m_stack_depth; + std::unique_ptr<diagnostic_graph> m_state_graph; label_text m_desc_uncolored; label_text m_desc_colored; }; @@ -855,6 +908,7 @@ struct diagnostic_execution_path : public diagnostic_path add_event_va (const diagnostic_physical_location *physical_loc, const diagnostic_logical_location *logical_loc, unsigned stack_depth, + std::unique_ptr<diagnostic_graph> state_graph, const char *gmsgid, va_list *args) { @@ -862,6 +916,7 @@ struct diagnostic_execution_path : public diagnostic_path (std::make_unique<libgdiagnostics_path_event> (physical_loc, logical_loc, stack_depth, + std::move (state_graph), gmsgid, args)); return m_events.size () - 1; @@ -902,6 +957,27 @@ private: std::vector<std::unique_ptr<libgdiagnostics_path_event>> m_events; }; +class prebuilt_digraphs : public diagnostics::digraphs::lazy_digraphs +{ +public: + using digraph = diagnostics::digraphs::digraph; + + std::unique_ptr<std::vector<std::unique_ptr<digraph>>> + create_digraphs () const final override + { + return std::make_unique<std::vector<std::unique_ptr<digraph>>> (std::move (m_digraphs)); + } + + void + take_graph (std::unique_ptr<diagnostic_graph> graph) + { + m_digraphs.push_back (std::move (graph)); + } + +private: + mutable std::vector<std::unique_ptr<digraph>> m_digraphs; +}; + /* This has to be a "struct" as it is exposed in the C API. */ struct diagnostic @@ -914,7 +990,9 @@ public: m_rich_loc (diag_mgr.get_line_table ()), m_logical_loc (nullptr), m_path (nullptr) - {} + { + m_metadata.set_lazy_digraphs (&m_graphs); + } diagnostic_manager &get_manager () const { @@ -990,12 +1068,25 @@ public: m_rich_loc.set_path (path); } + void + take_graph (std::unique_ptr<diagnostic_graph> graph) + { + m_graphs.take_graph (std::move (graph)); + } + + const prebuilt_digraphs & + get_graphs () const + { + return m_graphs; + } + private: diagnostic_manager &m_diag_mgr; enum diagnostic_level m_level; impl_rich_location m_rich_loc; const diagnostic_logical_location *m_logical_loc; diagnostic_metadata m_metadata; + prebuilt_digraphs m_graphs; std::vector<std::unique_ptr<range_label>> m_labels; std::vector<std::unique_ptr<impl_rule>> m_rules; std::unique_ptr<diagnostic_execution_path> m_path; @@ -1248,6 +1339,29 @@ diagnostic_manager::new_execution_path () return new diagnostic_execution_path (*mgr); } +void +diagnostic_manager::take_global_graph (std::unique_ptr<diagnostic_graph> graph) +{ + class prebuilt_lazy_digraph : public diagnostics::digraphs::lazy_digraph + { + public: + prebuilt_lazy_digraph (std::unique_ptr<diagnostic_graph> graph) + : m_graph (std::move (graph)) + { + } + + std::unique_ptr<diagnostics::digraphs::digraph> + create_digraph () const final override + { + return std::move (m_graph); + } + + private: + mutable std::unique_ptr<diagnostic_graph> m_graph; + }; + + m_dc.report_global_digraph (prebuilt_lazy_digraph (std::move (graph))); +} /* Error-checking at the API boundary. */ #define FAIL_IF_NULL(PTR_ARG) \ @@ -1876,6 +1990,7 @@ diagnostic_execution_path_add_event (diagnostic_execution_path *path, diagnostic_event_id_t result = path->add_event_va (physical_loc, logical_loc, stack_depth, + nullptr, gmsgid, &args); va_end (args); @@ -1898,6 +2013,7 @@ diagnostic_execution_path_add_event_va (diagnostic_execution_path *path, diagnostic_event_id_t result = path->add_event_va (physical_loc, logical_loc, stack_depth, + nullptr, gmsgid, args); return as_diagnostic_event_id (result); } @@ -2048,3 +2164,223 @@ diagnostic_manager_set_analysis_target (diagnostic_manager *mgr, mgr->get_dc ().set_main_input_filename (file->get_name ()); } + +// struct diagnostic_graph : public diagnostics::digraphs::graph<foo_traits> + +diagnostic_node * +diagnostic_graph::add_node_with_id (std::string id, + diagnostic_node *parent_node) +{ + auto node_up = std::make_unique<diagnostic_node> (*this, std::move (id)); + diagnostic_node *new_node = node_up.get (); + if (parent_node) + parent_node->add_child (std::move (node_up)); + else + add_node (std::move (node_up)); + return new_node; +} + +diagnostic_edge * +diagnostic_graph::add_edge_with_label (const char *id, + diagnostic_node &src_node, + diagnostic_node &dst_node, + const char *label) +{ + auto edge_up + = std::make_unique<diagnostic_edge> (*this, id, + src_node, dst_node); + diagnostic_edge *new_edge = edge_up.get (); + if (label) + new_edge->set_label (label); + add_edge (std::move (edge_up)); + return new_edge; +} + +/* Public entrypoint. */ + +diagnostic_graph * +diagnostic_manager_new_graph (diagnostic_manager *manager) +{ + FAIL_IF_NULL (manager); + + return new diagnostic_graph (*manager); +} + +/* Public entrypoint. */ + +void +diagnostic_manager_take_global_graph (diagnostic_manager *manager, + diagnostic_graph *graph) +{ + FAIL_IF_NULL (manager); + FAIL_IF_NULL (graph); + + manager->take_global_graph (std::unique_ptr<diagnostic_graph> (graph)); +} + +void +diagnostic_take_graph (diagnostic *diag, + diagnostic_graph *graph) +{ + FAIL_IF_NULL (diag); + FAIL_IF_NULL (graph); + + diag->take_graph (std::unique_ptr<diagnostic_graph> (graph)); +} + +/* Public entrypoint. */ + +void +diagnostic_graph_release (diagnostic_graph *graph) +{ + delete graph; +} + +/* Public entrypoint. */ + +void +diagnostic_graph_set_description (diagnostic_graph *graph, + const char *desc) +{ + FAIL_IF_NULL (graph); + + graph->set_description (desc); +} + +diagnostic_node * +diagnostic_graph_add_node (diagnostic_graph *graph, + const char *id, + diagnostic_node *parent_node) +{ + FAIL_IF_NULL (graph); + FAIL_IF_NULL (id); + + return graph->add_node_with_id (id, parent_node); +} + +/* Public entrypoint. */ + +diagnostic_edge * +diagnostic_graph_add_edge (diagnostic_graph *graph, + const char *id, + diagnostic_node *src_node, + diagnostic_node *dst_node, + const char *label) +{ + FAIL_IF_NULL (graph); + FAIL_IF_NULL (src_node); + FAIL_IF_NULL (dst_node); + + return graph->add_edge_with_label (id, *src_node, *dst_node, label); +} + +/* Public entrypoint. */ + +diagnostic_node * +diagnostic_graph_get_node_by_id (diagnostic_graph *graph, + const char *id) +{ + FAIL_IF_NULL (graph); + FAIL_IF_NULL (id); + + return static_cast<diagnostic_node *> (graph->get_node_by_id (id)); +} + +/* Public entrypoint. */ + +diagnostic_edge * +diagnostic_graph_get_edge_by_id (diagnostic_graph *graph, + const char *id) +{ + FAIL_IF_NULL (graph); + FAIL_IF_NULL (id); + + return static_cast<diagnostic_edge *> (graph->get_edge_by_id (id)); +} + +/* Public entrypoint. */ + +void +diagnostic_node_set_location (diagnostic_node *node, + const diagnostic_physical_location *loc) +{ + FAIL_IF_NULL (node); + + node->set_physical_loc (loc ? loc->m_inner : UNKNOWN_LOCATION); +} + +/* Public entrypoint. */ + +void +diagnostic_node_set_label (diagnostic_node *node, + const char *label) +{ + FAIL_IF_NULL (node); + + node->set_label (label); +} + +void +diagnostic_node_set_logical_location (diagnostic_node *node, + const diagnostic_logical_location *logical_loc) +{ + FAIL_IF_NULL (node); + + node->set_logical_loc + (impl_logical_location_manager::key_from_ptr (logical_loc)); +} + +/* Private entrypoint. */ + +diagnostic_event_id +private_diagnostic_execution_path_add_event_2 (diagnostic_execution_path *path, + const diagnostic_physical_location *physical_loc, + const diagnostic_logical_location *logical_loc, + unsigned stack_depth, + diagnostic_graph *state_graph, + const char *gmsgid, ...) + +{ + FAIL_IF_NULL (path); + FAIL_IF_NULL (gmsgid); + + va_list args; + va_start (args, gmsgid); + diagnostic_event_id_t result + = path->add_event_va (physical_loc, + logical_loc, + stack_depth, + std::unique_ptr <diagnostic_graph> (state_graph), + gmsgid, &args); + va_end (args); + + return as_diagnostic_event_id (result); + +} + +/* Private entrypoint. */ + +void +private_diagnostic_graph_set_property_bag (diagnostic_graph &graph, + std::unique_ptr<json::object> properties) +{ + graph.set_property_bag (std::move (properties)); +} + +/* Private entrypoint. */ + +void +private_diagnostic_node_set_property_bag (diagnostic_node &node, + std::unique_ptr<json::object> properties) +{ + node.set_property_bag (std::move (properties)); +} + +/* Private entrypoint. */ + +void +private_diagnostic_edge_set_property_bag (diagnostic_edge &edge, + std::unique_ptr<json::object> properties) +{ + edge.set_property_bag (std::move (properties)); +} diff --git a/gcc/libgdiagnostics.h b/gcc/libgdiagnostics.h index 9af2747..f79790a 100644 --- a/gcc/libgdiagnostics.h +++ b/gcc/libgdiagnostics.h @@ -765,6 +765,140 @@ diagnostic_manager_set_analysis_target (diagnostic_manager *mgr, LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (2); +/* Directed graphs. */ + +typedef struct diagnostic_graph diagnostic_graph; +typedef struct diagnostic_node diagnostic_node; +typedef struct diagnostic_edge diagnostic_edge; + +/* Create a new graph. + This is owned by the caller and must have one of + diagnostic_manager_take_global_graph, diagnostic_take_graph, + or diagnostic_graph_release called on it. + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern diagnostic_graph * +diagnostic_manager_new_graph (diagnostic_manager *manager) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1); + +/* Report this graph "globally", taking ownership of it. + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern void +diagnostic_manager_take_global_graph (diagnostic_manager *manager, + diagnostic_graph *graph) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (2); + +/* Add this graph to DIAG, transferring ownership to it. + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern void +diagnostic_take_graph (diagnostic *diag, + diagnostic_graph *graph) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (2); + +/* Release this graph. Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern void +diagnostic_graph_release (diagnostic_graph *graph) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (1); + +/* Set the description of GRAPH for use + in the value of the SARIF "description" property + (SARIF v2.1.0 section 3.39.2). + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern void +diagnostic_graph_set_description (diagnostic_graph *graph, + const char *description) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (2); + +/* Create and add a new node within GRAPH. + NODE_ID must be unique within nodes in GRAPH. + The new node is owned by GRAPH. + PARENT_NODE can be NULL (for a top-level node in the graph), + or non-null for a child node. + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern diagnostic_node * +diagnostic_graph_add_node (diagnostic_graph *graph, + const char *node_id, + diagnostic_node *parent_node) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (2) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (3); + +/* Create and add a new edge within GRAPH. + + If non-null, then EDGE_ID must be unique within edges in GRAPH; + if EDGE_ID is null then a unique id of the form "edge0", "edge1", etc + will be used automatically. + + The new edge is owned by GRAPH. + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern diagnostic_edge * +diagnostic_graph_add_edge (diagnostic_graph *graph, + const char *edge_id, + diagnostic_node *src_node, + diagnostic_node *dst_node, + const char *label) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (2) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (3) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (4) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (5); + +/* Get the node in GRAPH with the given id, or null. + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern diagnostic_node * +diagnostic_graph_get_node_by_id (diagnostic_graph *graph, + const char *node_id) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (2); + +/* Get the edge in GRAPH with the given id, or null. + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern diagnostic_edge * +diagnostic_graph_get_edge_by_id (diagnostic_graph *graph, + const char *edge_id) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (2); + +/* Set the label of NODE for use + in the value of the SARIF "label" property + (SARIF v2.1.0 section 3.40.3). + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern void +diagnostic_node_set_label (diagnostic_node *node, + const char *label) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (2); + +/* Set the physical location of NODE. + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern void +diagnostic_node_set_location (diagnostic_node *node, + const diagnostic_physical_location *loc) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (2); + +/* Set the logical location of NODE. + Added in LIBGDIAGNOSTICS_ABI_3. */ + +extern void +diagnostic_node_set_logical_location (diagnostic_node *node, + const diagnostic_logical_location *logical_loc) + LIBGDIAGNOSTICS_PARAM_MUST_BE_NON_NULL (1) + LIBGDIAGNOSTICS_PARAM_CAN_BE_NULL (2); + /* DEFERRED: - thread-safety - plural forms diff --git a/gcc/libgdiagnostics.map b/gcc/libgdiagnostics.map index 49cabca..cae28d1 100644 --- a/gcc/libgdiagnostics.map +++ b/gcc/libgdiagnostics.map @@ -90,3 +90,26 @@ LIBGDIAGNOSTICS_ABI_2 { diagnostic_manager_add_sink_from_spec; diagnostic_manager_set_analysis_target; } LIBGDIAGNOSTICS_ABI_1; + +# Add hooks needed for diagnostic_graph support. +LIBGDIAGNOSTICS_ABI_3 { + global: + diagnostic_manager_new_graph; + diagnostic_manager_take_global_graph; + diagnostic_take_graph; + diagnostic_graph_release; + diagnostic_graph_set_description; + diagnostic_graph_add_node; + diagnostic_graph_add_edge; + diagnostic_graph_get_node_by_id; + diagnostic_graph_get_edge_by_id; + diagnostic_node_set_label; + diagnostic_node_set_location; + diagnostic_node_set_logical_location; + + # Private hooks used by sarif-replay + private_diagnostic_execution_path_add_event_2; + private_diagnostic_graph_set_property_bag; + private_diagnostic_node_set_property_bag; + private_diagnostic_edge_set_property_bag; +} LIBGDIAGNOSTICS_ABI_2; diff --git a/gcc/libsarifreplay.cc b/gcc/libsarifreplay.cc index 2d6c394..cad535b 100644 --- a/gcc/libsarifreplay.cc +++ b/gcc/libsarifreplay.cc @@ -26,6 +26,7 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "libgdiagnostics++.h" +#include "libgdiagnostics-private.h" #include "json-parsing.h" #include "intl.h" #include "sarif-spec-urls.def" @@ -291,6 +292,8 @@ public: label_text m_label; }; +using id_map = std::map<std::string, const json::string *>; + class sarif_replayer { public: @@ -413,6 +416,30 @@ private: const json::object &run_obj, libgdiagnostics::execution_path &out); + // "graph" object (§3.39) + enum status + handle_graph_object (const json::object &graph_obj, + const json::object &run_obj, + libgdiagnostics::graph &out); + // "node" object (§3.40) + libgdiagnostics::node + handle_node_object (const json::object &node_obj, + const json::object &run_obj, + libgdiagnostics::graph &graph, + libgdiagnostics::node parent_node, + id_map &node_id_map); + + // "edge" object (§3.41) + libgdiagnostics::edge + handle_edge_object (const json::object &edge_obj, + libgdiagnostics::graph &graph, + id_map &edge_id_map); + + libgdiagnostics::node + get_graph_node_by_id_property (const json::object &edge_json_object, + const property_spec_ref &id_prop, + libgdiagnostics::graph &graph); + // reportingDescriptor lookup (§3.52.3) const json::object * lookup_rule_by_id_in_tool (const char *rule_id, @@ -446,7 +473,7 @@ private: { va_list ap; va_start (ap, gmsgid); - report_problem (jv, ref, gmsgid, &ap, DIAGNOSTIC_LEVEL_ERROR); + report_problem (jv, &ref, gmsgid, &ap, DIAGNOSTIC_LEVEL_ERROR); va_end (ap); return status::err_invalid_sarif; } @@ -462,14 +489,25 @@ private: { va_list ap; va_start (ap, gmsgid); - report_problem (jv, ref, gmsgid, &ap, DIAGNOSTIC_LEVEL_SORRY); + report_problem (jv, &ref, gmsgid, &ap, DIAGNOSTIC_LEVEL_SORRY); va_end (ap); return status::err_unhandled_sarif; } void + report_note (const json::value &jv, + const char *gmsgid, ...) + LIBGDIAGNOSTICS_PARAM_GCC_FORMAT_STRING (3, 4) + { + va_list ap; + va_start (ap, gmsgid); + report_problem (jv, nullptr, gmsgid, &ap, DIAGNOSTIC_LEVEL_NOTE); + va_end (ap); + } + + void report_problem (const json::value &jv, - const spec_ref &ref, + const spec_ref *ref, const char *gmsgid, va_list *args, enum diagnostic_level level) @@ -481,11 +519,14 @@ private: There doesn't seem to be a systematic mapping from spec sections to HTML anchors, so we can't provide URLs (filed as https://github.com/oasis-tcs/sarif-spec/issues/533 ). */ - char *ref_desc = ref.make_description (); - char *ref_url = ref.make_url (); - diag.add_rule (ref_desc, ref_url); - free (ref_desc); - free (ref_url); + if (ref) + { + char *ref_desc = ref->make_description (); + char *ref_url = ref->make_url (); + diag.add_rule (ref_desc, ref_url); + free (ref_desc); + free (ref_url); + } auto loc_range = make_physical_location (m_control_mgr, @@ -651,6 +692,38 @@ private: const string_property_value<ValueType> *value_arr, size_t num_values); + const json::object * + maybe_get_property_bag (const json::object &obj) + { + const property_spec_ref properties + ("object", "properties", "3.8.1"); + return get_optional_property<json::object> (obj, properties); + } + + /* Look for a property bag within OBJ. + If found, look for a property within it named PROPERTY_NAME + of the given type. + If successful, return the property's value. + Otherwise, return nullptr without complaining (unless the property bag + is itself not an object). */ + template <typename JsonType> + const JsonType * + maybe_get_property_bag_value (const json::object &obj, + const char *property_name) + { + auto property_bag_obj = maybe_get_property_bag (obj); + if (!property_bag_obj) + return nullptr; + const json::value *property_val = property_bag_obj->get (property_name); + if (!property_val) + return nullptr; + const JsonType *sub = dyn_cast<const JsonType *> (property_val); + if (!sub) + /* Property is wrong kind of value. Don't treat this as an error. */ + return nullptr; + return sub; + } + /* The manager to replay the SARIF files to. */ libgdiagnostics::manager m_output_mgr; @@ -929,6 +1002,31 @@ sarif_replayer::handle_run_obj (const json::object &run_obj) break; } + // §3.14.20 "graphs" + const property_spec_ref prop_graphs ("run", "graphs", "3.14.20"); + if (const json::array *graphs + = get_optional_property<json::array> (run_obj, + prop_graphs)) + { + for (auto element : *graphs) + { + if (const json::object *graph_json_obj + = require_object_for_element (*element, prop_graphs)) + { + libgdiagnostics::graph graph; + enum status s = handle_graph_object (*graph_json_obj, + run_obj, + graph); + if (s != status::ok) + return s; + + m_output_mgr.take_global_graph (std::move (graph)); + } + else + return status::err_invalid_sarif; + } + } + return status::ok; } @@ -1244,6 +1342,31 @@ sarif_replayer::handle_result_obj (const json::object &result_obj, if (path.m_inner) err.take_execution_path (std::move (path)); + // §3.27.19 "graphs" property + const property_spec_ref prop_graphs ("result", "graphs", "3.27.19"); + if (const json::array *graphs + = get_optional_property<json::array> (result_obj, + prop_graphs)) + { + for (auto element : *graphs) + { + if (const json::object *graph_json_obj + = require_object_for_element (*element, prop_graphs)) + { + libgdiagnostics::graph graph; + enum status s = handle_graph_object (*graph_json_obj, + run_obj, + graph); + if (s != status::ok) + return s; + + err.take_graph (std::move (graph)); + } + else + return status::err_invalid_sarif; + } + } + // §3.27.22 relatedLocations property std::vector<std::pair<libgdiagnostics::diagnostic, label_text>> notes; const property_spec_ref prop_related_locations @@ -1740,16 +1863,32 @@ handle_thread_flow_location_object (const json::object &tflow_loc_obj, } } + libgdiagnostics::graph state_graph; + if (auto sarif_state_graph + = maybe_get_property_bag_value<json::object> (tflow_loc_obj, + "gcc/diagnostic_event/state_graph")) + { + enum status s + = handle_graph_object (*sarif_state_graph, run_obj, state_graph); + if (s != status::ok) + return s; + } + if (message.get ()) - path.add_event (physical_loc, - logical_loc, - stack_depth, - "%s", message.get ()); + private_diagnostic_execution_path_add_event_2 (path.m_inner, + physical_loc.m_inner, + logical_loc.m_inner, + stack_depth, + state_graph.m_inner, + "%s", message.get ()); else - path.add_event (physical_loc, - logical_loc, - stack_depth, - ""); + private_diagnostic_execution_path_add_event_2 (path.m_inner, + physical_loc.m_inner, + logical_loc.m_inner, + stack_depth, + state_graph.m_inner, + ""); + state_graph.m_owned = false; return status::ok; } @@ -2142,6 +2281,270 @@ handle_logical_location_object (const json::object &logical_loc_obj, return status::ok; } +// "graph" object (§3.39) + +enum status +sarif_replayer::handle_graph_object (const json::object &graph_json_obj, + const json::object &run_obj, + libgdiagnostics::graph &out_graph) +{ + out_graph = libgdiagnostics::graph + (diagnostic_manager_new_graph (m_output_mgr.m_inner)); + + id_map node_id_map; + id_map edge_id_map; + + if (auto properties = maybe_get_property_bag (graph_json_obj)) + private_diagnostic_graph_set_property_bag (*out_graph.m_inner, + properties->clone_as_object ()); + + // §3.39.2: MAY contain a "description" property + const property_spec_ref description_prop + ("graph", "description", "3.39.2"); + if (auto description_obj + = get_optional_property<json::object> (graph_json_obj, description_prop)) + { + label_text text + = make_plain_text_within_result_message (&run_obj, + *description_obj, + nullptr); + if (!text.get ()) + return status::err_invalid_sarif; + out_graph.set_description (text.get ()); + } + + // §3.39.3: MAY contain a "nodes" property + const property_spec_ref nodes_prop + ("graph", "nodes", "3.39.3"); + if (auto nodes_arr + = get_optional_property<json::array> (graph_json_obj, nodes_prop)) + { + for (auto element : *nodes_arr) + { + const json::object *node_json_obj + = require_object_for_element (*element, nodes_prop); + if (!node_json_obj) + return status::err_invalid_sarif; + libgdiagnostics::node node + = handle_node_object (*node_json_obj, run_obj, out_graph, + nullptr, node_id_map); + if (node.m_inner == nullptr) + return status::err_invalid_sarif; + } + } + else + // If we have no nodes, we can't handle the edges. + return status::ok; + + // §3.39.4 edges property + const property_spec_ref edges_prop + ("graph", "edges", "3.39.4"); + if (auto edges_arr + = get_optional_property<json::array> (graph_json_obj, edges_prop)) + { + for (auto element : *edges_arr) + { + const json::object *edge_json_obj + = require_object_for_element (*element, edges_prop); + if (!edge_json_obj) + return status::err_invalid_sarif; + libgdiagnostics::edge edge + = handle_edge_object (*edge_json_obj, out_graph, edge_id_map); + if (edge.m_inner == nullptr) + return status::err_invalid_sarif; + } + } + + return status::ok; +} + +// "node" object (§3.40) + +libgdiagnostics::node +sarif_replayer::handle_node_object (const json::object &node_json_obj, + const json::object &run_obj, + libgdiagnostics::graph &graph, + libgdiagnostics::node parent_node, + id_map &node_id_map) +{ + // §3.40.2 "id" property + const property_spec_ref id_prop ("node", "id", "3.40.2"); + auto id_str = get_required_property<json::string> (node_json_obj, id_prop); + if (!id_str) + return nullptr; + const char *id = id_str->get_string (); + if (diagnostic_graph_get_node_by_id (graph.m_inner, id)) + { + // Duplicate id; fail: + libgdiagnostics::group g (m_control_mgr); + report_invalid_sarif (*id_str, + id_prop, + "duplicate node id %qs within graph", + id); + gcc_assert (node_id_map[id]); + report_note (*node_id_map[id], + "%qs already used as node id within graph here", + id); + return nullptr; + } + node_id_map[id] = id_str; + + libgdiagnostics::node new_node + = libgdiagnostics::node (diagnostic_graph_add_node (graph.m_inner, + id, + parent_node.m_inner)); + if (auto properties = maybe_get_property_bag (node_json_obj)) + private_diagnostic_node_set_property_bag (*new_node.m_inner, + properties->clone_as_object ()); + + // §3.40.3 "label" property + const property_spec_ref label_prop + ("node", "label", "3.40.3"); + if (auto label_obj + = get_optional_property<json::object> (node_json_obj, label_prop)) + { + label_text text + = make_plain_text_within_result_message (&run_obj, + *label_obj, + nullptr); + if (!text.get ()) + return nullptr; + new_node.set_label (text.get ()); + } + + // §3.40.4 "location" property + const property_spec_ref location_prop ("node", "location", "3.40.4"); + if (auto location_json_obj + = get_optional_property<json::object> (node_json_obj, location_prop)) + { + libgdiagnostics::physical_location physical_loc; + libgdiagnostics::logical_location logical_loc; + enum status s = handle_location_object (*location_json_obj, + run_obj, + physical_loc, + logical_loc, + nullptr); // annotations + if (s != status::ok) + return nullptr; + + new_node.set_location (physical_loc); + new_node.set_logical_location (logical_loc); + } + + // §3.40.5: MAY contain a "children" property + const property_spec_ref children_prop + ("graph", "children", "3.40.5"); + if (auto children_json_arr + = get_optional_property<json::array> (node_json_obj, children_prop)) + { + for (auto json_element : *children_json_arr) + { + const json::object *child_json_obj + = require_object_for_element (*json_element, children_prop); + if (!child_json_obj) + return nullptr; + libgdiagnostics::node child_node + = handle_node_object (*child_json_obj, run_obj, graph, + new_node, node_id_map); + if (child_node.m_inner == nullptr) + return nullptr; + } + } + + return new_node; +} + +// "edge" object (§3.41) + +libgdiagnostics::edge +sarif_replayer::handle_edge_object (const json::object &edge_json_obj, + libgdiagnostics::graph &graph, + id_map &edge_id_map) +{ + // §3.41.2 "id" property + const property_spec_ref id_prop ("edge", "id", "3.41.2"); + auto id_str = get_required_property<json::string> (edge_json_obj, id_prop); + if (!id_str) + return nullptr; + const char *id = id_str->get_string (); + if (diagnostic_graph_get_edge_by_id (graph.m_inner, id)) + { + // Duplicate id; fail: + libgdiagnostics::group g (m_control_mgr); + report_invalid_sarif (*id_str, + id_prop, + "duplicate edge id %qs within graph", + id); + gcc_assert (edge_id_map[id]); + report_note (*edge_id_map[id], + "%qs already used as edge id within graph here", + id); + return nullptr; + } + edge_id_map[id] = id_str; + + // §3.41.3 "label" property + label_text label; + const property_spec_ref label_prop + ("edge", "label", "3.41.3"); + if (auto label_obj + = get_optional_property<json::object> (edge_json_obj, label_prop)) + { + label = make_plain_text_within_result_message (nullptr, + *label_obj, + nullptr); + if (!label.get ()) + return nullptr; + } + + // §3.41.4 "sourceNodeId" property + const property_spec_ref src_id_prop ("edge", "sourceNodeId", "3.41.4"); + auto src_node = get_graph_node_by_id_property (edge_json_obj, + src_id_prop, + graph); + if (!src_node.m_inner) + return nullptr; + + // §3.41.5 "targetNodeId" property + const property_spec_ref dst_id_prop ("edge", "targetNodeId", "3.41.5"); + auto dst_node = get_graph_node_by_id_property (edge_json_obj, + dst_id_prop, + graph); + if (!dst_node.m_inner) + return nullptr; + + auto result = graph.add_edge (id, src_node, dst_node, label.get ()); + + if (auto properties = maybe_get_property_bag (edge_json_obj)) + private_diagnostic_edge_set_property_bag (*result.m_inner, + properties->clone_as_object ()); + + return result; +} + +libgdiagnostics::node +sarif_replayer:: +get_graph_node_by_id_property (const json::object &edge_json_obj, + const property_spec_ref &id_prop, + libgdiagnostics::graph &graph) +{ + auto id_str = get_required_property<json::string> (edge_json_obj, id_prop); + if (!id_str) + return nullptr; + const char *id = id_str->get_string (); + auto node = graph.get_node_by_id (id); + if (!node.m_inner) + { + // id not found; complain: + report_invalid_sarif (*id_str, + id_prop, + "no node with id %qs in graph", + id); + return nullptr; + } + return node; +} + // 3.52.3 reportingDescriptor lookup // "For an example of the interaction between ruleId and rule.id, see §3.52.4." diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc index 68aaf86..c941d2f 100644 --- a/gcc/lra-constraints.cc +++ b/gcc/lra-constraints.cc @@ -2416,14 +2416,15 @@ process_alt_operands (int only_alternative) if (curr_static_id->operand[nop].type == OP_INOUT || curr_static_id->operand[m].type == OP_INOUT) break; - /* Operands don't match. If the operands are - different user defined explicit hard + /* Operands don't match. For asm if the operands + are different user defined explicit hard registers, then we cannot make them match when one is early clobber operand. */ if ((REG_P (*curr_id->operand_loc[nop]) || SUBREG_P (*curr_id->operand_loc[nop])) && (REG_P (*curr_id->operand_loc[m]) - || SUBREG_P (*curr_id->operand_loc[m]))) + || SUBREG_P (*curr_id->operand_loc[m])) + && INSN_CODE (curr_insn) < 0) { rtx nop_reg = *curr_id->operand_loc[nop]; if (SUBREG_P (nop_reg)) @@ -3328,19 +3329,15 @@ process_alt_operands (int only_alternative) first_conflict_j = j; last_conflict_j = j; /* Both the earlyclobber operand and conflicting operand - cannot both be user defined hard registers. */ + cannot both be user defined hard registers for asm. + Let curr_insn_transform diagnose it. */ if (HARD_REGISTER_P (operand_reg[i]) && REG_USERVAR_P (operand_reg[i]) && operand_reg[j] != NULL_RTX && HARD_REGISTER_P (operand_reg[j]) - && REG_USERVAR_P (operand_reg[j])) - { - /* For asm, let curr_insn_transform diagnose it. */ - if (INSN_CODE (curr_insn) < 0) + && REG_USERVAR_P (operand_reg[j]) + && INSN_CODE (curr_insn) < 0) return false; - fatal_insn ("unable to generate reloads for " - "impossible constraints:", curr_insn); - } } if (last_conflict_j < 0) continue; @@ -3930,6 +3927,16 @@ process_address_1 (int nop, bool check_only_p, enum reg_class cl; rtx set; rtx_insn *insns, *last_insn; + + cl = base_reg_class (ad.mode, ad.as, ad.base_outer_code, + get_index_code (&ad), curr_insn); + + if (REG_P (*ad.base_term) + && ira_class_subset_p[get_reg_class (REGNO (*ad.base_term))][cl]) + /* It seems base reg is already in the base reg class and changing it + does not make a progress. So reload the whole inner address. */ + goto reload_inner_addr; + /* Try to reload base into register only if the base is invalid for the address but with valid offset, case (4) above. */ start_sequence (); @@ -3975,8 +3982,6 @@ process_address_1 (int nop, bool check_only_p, { *ad.base_term = XEXP (SET_SRC (set), 0); *ad.disp_term = XEXP (SET_SRC (set), 1); - cl = base_reg_class (ad.mode, ad.as, ad.base_outer_code, - get_index_code (&ad), curr_insn); regno = REGNO (*ad.base_term); if (regno >= FIRST_PSEUDO_REGISTER && cl != lra_get_allocno_class (regno)) @@ -4019,11 +4024,11 @@ process_address_1 (int nop, bool check_only_p, } else { - enum reg_class cl = base_reg_class (ad.mode, ad.as, - SCRATCH, SCRATCH, - curr_insn); - rtx addr = *ad.inner; - + enum reg_class cl; + rtx addr; + reload_inner_addr: + cl = base_reg_class (ad.mode, ad.as, SCRATCH, SCRATCH, curr_insn); + addr = *ad.inner; new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "addr"); /* addr => new_base. */ lra_emit_move (new_reg, addr); @@ -4044,14 +4049,21 @@ process_address (int nop, bool check_only_p, rtx_insn **before, rtx_insn **after) { bool res = false; - - while (process_address_1 (nop, check_only_p, before, after)) + /* Use enough iterations to process all address parts: */ + for (int i = 0; i < 10; i++) { - if (check_only_p) - return true; - res = true; + if (!process_address_1 (nop, check_only_p, before, after)) + { + return res; + } + else + { + if (check_only_p) + return true; + res = true; + } } - return res; + fatal_insn ("unable to reload address in ", curr_insn); } /* Override the generic address_reload_context in order to diff --git a/gcc/optabs-tree.cc b/gcc/optabs-tree.cc index 6dfe8ee..9308a6d 100644 --- a/gcc/optabs-tree.cc +++ b/gcc/optabs-tree.cc @@ -82,6 +82,8 @@ optab_for_tree_code (enum tree_code code, const_tree type, return unknown_optab; /* FALLTHRU */ case RDIV_EXPR: + gcc_assert (FLOAT_TYPE_P (type)); + /* FALLTHRU */ case TRUNC_DIV_EXPR: case EXACT_DIV_EXPR: if (TYPE_SATURATING (type)) diff --git a/gcc/opts.cc b/gcc/opts.cc index 6ca1ec7..063fbd0 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -1411,11 +1411,14 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, opts->x_debug_info_level = DINFO_LEVEL_NONE; } + /* Also enable markers with -fauto-profile even when debug info is disabled, + so we assign same discriminators and can read back the profile info. */ if (!opts_set->x_debug_nonbind_markers_p) opts->x_debug_nonbind_markers_p = (opts->x_optimize - && opts->x_debug_info_level >= DINFO_LEVEL_NORMAL - && (dwarf_debuginfo_p (opts) || codeview_debuginfo_p ()) + && ((opts->x_debug_info_level >= DINFO_LEVEL_NORMAL + && (dwarf_debuginfo_p (opts) || codeview_debuginfo_p ())) + || opts->x_flag_auto_profile) && !(opts->x_flag_selective_scheduling || opts->x_flag_selective_scheduling2)); diff --git a/gcc/selftest-run-tests.cc b/gcc/selftest-run-tests.cc index 3245453..d43d9dd 100644 --- a/gcc/selftest-run-tests.cc +++ b/gcc/selftest-run-tests.cc @@ -102,7 +102,9 @@ selftest::run_tests () diagnostic_show_locus_cc_tests (); diagnostic_format_html_cc_tests (); diagnostic_format_sarif_cc_tests (); + diagnostic_digraphs_cc_tests (); diagnostic_output_spec_cc_tests (); + diagnostic_state_graphs_cc_tests (); edit_context_cc_tests (); fold_const_cc_tests (); spellcheck_cc_tests (); diff --git a/gcc/selftest.h b/gcc/selftest.h index eb9e604..06485e1 100644 --- a/gcc/selftest.h +++ b/gcc/selftest.h @@ -222,11 +222,13 @@ extern void cgraph_cc_tests (); extern void convert_cc_tests (); extern void dbgcnt_cc_tests (); extern void diagnostic_color_cc_tests (); +extern void diagnostic_digraphs_cc_tests (); extern void diagnostic_format_html_cc_tests (); extern void diagnostic_format_sarif_cc_tests (); extern void diagnostic_output_spec_cc_tests (); extern void diagnostic_path_output_cc_tests (); extern void diagnostic_show_locus_cc_tests (); +extern void diagnostic_state_graphs_cc_tests (); extern void digraph_cc_tests (); extern void dumpfile_cc_tests (); extern void edit_context_cc_tests (); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7cb2440..4f1b932 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,494 @@ +2025-07-11 David Malcolm <dmalcolm@redhat.com> + + * gcc.dg/analyzer/state-diagram-1-sarif.py (test_xml_state): + Rename to... + (test_state_graph): ...this. Port from XML to SARIF graphs. + * gcc.dg/analyzer/state-diagram-1.c: Update sink option + from "sarif:xml-state=yes" to "sarif:state-graphs=yes". + * gcc.dg/analyzer/state-diagram-5-sarif.c: Likewise. + * gcc.dg/analyzer/state-diagram-5-sarif.py: Drop import of ET. + (test_nested_types_in_xml_state): Rename to... + (test_nested_types_in_state_graph): ...this. Port from XML to + SARIF graphs. + * gcc.dg/plugin/diagnostic-test-graphs-html.c: New test. + * gcc.dg/plugin/diagnostic-test-graphs-html.py: New test script. + * gcc.dg/plugin/diagnostic-test-graphs-sarif.c: New test. + * gcc.dg/plugin/diagnostic-test-graphs-sarif.py: New test script. + * gcc.dg/plugin/diagnostic-test-graphs.c: New test. + * gcc.dg/plugin/diagnostic_plugin_test_graphs.cc: New test plugin. + * gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above. + * lib/sarif.py (get_xml_state): Delete. + (get_state_graph): New. + (def get_state_node_attr): New. + (get_state_node_kind): New. + (get_state_node_name): New. + (get_state_node_type): New. + (get_state_node_value): New. + * sarif-replay.dg/2.1.0-invalid/3.40.2-duplicate-node-id.sarif: + New test. + * sarif-replay.dg/2.1.0-invalid/3.41.4-unrecognized-node-id.sarif: + New test. + * sarif-replay.dg/2.1.0-valid/graphs-check-html.py: New test + script. + * sarif-replay.dg/2.1.0-valid/graphs-check-sarif-roundtrip.py: New + test script. + * sarif-replay.dg/2.1.0-valid/graphs.sarif: New test. + +2025-07-11 Vladimir N. Makarov <vmakarov@redhat.com> + + * gcc.target/powerpc/pr121007.c: New. + +2025-07-11 Jakub Jelinek <jakub@redhat.com> + + PR c++/119064 + * g++.dg/cpp26/feat-cxx26.C: Add test for + __cpp_trivial_relocatability. + * g++.dg/cpp26/trivially-relocatable1.C: New test. + * g++.dg/cpp26/trivially-relocatable2.C: New test. + * g++.dg/cpp26/trivially-relocatable3.C: New test. + * g++.dg/cpp26/trivially-relocatable4.C: New test. + * g++.dg/cpp26/trivially-relocatable5.C: New test. + * g++.dg/cpp26/trivially-relocatable6.C: New test. + * g++.dg/cpp26/trivially-relocatable7.C: New test. + * g++.dg/cpp26/trivially-relocatable8.C: New test. + * g++.dg/cpp26/trivially-relocatable9.C: New test. + * g++.dg/cpp26/trivially-relocatable10.C: New test. + * g++.dg/cpp26/trivially-relocatable11.C: New test. + +2025-07-11 Richard Sandiford <richard.sandiford@arm.com> + + PR target/121027 + * gcc.target/aarch64/sve/acle/general/perm_1.c: New test. + +2025-07-11 Kyrylo Tkachov <ktkachov@nvidia.com> + + * gcc.target/aarch64/simd/eor3_d.c: Add tests for DImode operands. + +2025-07-11 Kyrylo Tkachov <ktkachov@nvidia.com> + + * gcc.target/aarch64/simd/bcax_d.c: Add tests for DImode arguments. + +2025-07-11 Kyrylo Tkachov <ktkachov@nvidia.com> + + * gcc.target/aarch64/simd/eor3_d.c: New test. + +2025-07-11 Kyrylo Tkachov <ktkachov@nvidia.com> + + * gcc.target/aarch64/simd/bcax_d.c: New test. + +2025-07-11 Richard Biener <rguenther@suse.de> + + PR tree-optimization/121034 + * gcc.dg/vect/pr121034.c: New testcase. + +2025-07-11 Jakub Jelinek <jakub@redhat.com> + + PR c++/120954 + * c-c++-common/Warray-bounds-11.c: New test. + +2025-07-11 Jan Hubicka <hubicka@ucw.cz> + + * g++.dg/lto/pr114790_0.C: New test. + * g++.dg/lto/pr114790_1.C: New test. + +2025-07-11 Jakub Jelinek <jakub@redhat.com> + Martin Jambor <mjambor@suse.cz> + + PR ipa/121023 + * c-c++-common/musttail32.c: New test. + +2025-07-11 Hu, Lin1 <lin1.hu@intel.com> + + PR target/91384 + * gcc.target/i386/pr91384-1.c: New test. + +2025-07-11 Paul Thomas <pault@gcc.gnu.org> + + PR fortran/106135 + * gfortran.dg/import3.f90: Use -std=f2008 and comment on change + in error message texts with f2018. + * gfortran.dg/import12.f90: New test. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + PR c++/120628 + * g++.dg/cpp0x/final1.C: New test. + * g++.dg/cpp0x/final2.C: New test. + * g++.dg/cpp0x/override6.C: New test. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + PR c++/120569 + * g++.dg/cpp0x/override2.C: Expect different diagnostics with + override or duplicate final. + * g++.dg/cpp0x/override5.C: New test. + * g++.dg/cpp0x/duplicate1.C: Expect different diagnostics with + duplicate final. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + PR c++/117785 + * g++.dg/cpp0x/constexpr-ellipsis2.C: Expect different diagnostics for + C++26. + * g++.dg/cpp0x/constexpr-throw.C: Likewise. + * g++.dg/cpp1y/constexpr-84192.C: Expect different diagnostics. + * g++.dg/cpp1y/constexpr-throw.C: Expect different diagnostics for + C++26. + * g++.dg/cpp1z/constexpr-asm-5.C: Likewise. + * g++.dg/cpp26/constexpr-eh1.C: New test. + * g++.dg/cpp26/constexpr-eh2.C: New test. + * g++.dg/cpp26/constexpr-eh3.C: New test. + * g++.dg/cpp26/constexpr-eh4.C: New test. + * g++.dg/cpp26/constexpr-eh5.C: New test. + * g++.dg/cpp26/constexpr-eh6.C: New test. + * g++.dg/cpp26/constexpr-eh7.C: New test. + * g++.dg/cpp26/constexpr-eh8.C: New test. + * g++.dg/cpp26/constexpr-eh9.C: New test. + * g++.dg/cpp26/constexpr-eh10.C: New test. + * g++.dg/cpp26/constexpr-eh11.C: New test. + * g++.dg/cpp26/constexpr-eh12.C: New test. + * g++.dg/cpp26/constexpr-eh13.C: New test. + * g++.dg/cpp26/constexpr-eh14.C: New test. + * g++.dg/cpp26/constexpr-eh15.C: New test. + * g++.dg/cpp26/feat-cxx26.C: Change formatting in __cpp_pack_indexing + and __cpp_pp_embed test. Add __cpp_constexpr_exceptions test. + * g++.dg/cpp26/static_assert1.C: Expect different diagnostics for + C++26. + * g++.dg/cpp2a/consteval34.C: Likewise. + * g++.dg/cpp2a/consteval-memfn1.C: Likewise. + * g++.dg/cpp2a/constexpr-dynamic4.C: For C++26 add std::exception and + std::bad_cast definitions and expect different diagnostics. + * g++.dg/cpp2a/constexpr-dynamic6.C: Likewise. + * g++.dg/cpp2a/constexpr-dynamic7.C: Likewise. + * g++.dg/cpp2a/constexpr-dynamic8.C: Likewise. + * g++.dg/cpp2a/constexpr-dynamic9.C: Likewise. + * g++.dg/cpp2a/constexpr-dynamic11.C: Likewise. + * g++.dg/cpp2a/constexpr-dynamic14.C: Likewise. + * g++.dg/cpp2a/constexpr-dynamic18.C: Likewise. + * g++.dg/cpp2a/constexpr-new27.C: New test. + * g++.dg/cpp2a/constexpr-typeid5.C: New test. + +2025-07-10 Qing Zhao <qing.zhao@oracle.com> + + PR middle-end/121000 + * gcc.dg/flex-array-counted-by-pr121000.c: New test. + +2025-07-10 Mikael Morin <mikael@gcc.gnu.org> + + * gfortran.dg/asan/array_constructor_1.f90: Allocate array + before using it. + +2025-07-10 Jan Hubicka <hubicka@ucw.cz> + + * gcc.dg/tree-prof/afdo-inline.c: Add user symbol names. + +2025-07-10 Richard Sandiford <richard.sandiford@arm.com> + + * gcc.target/aarch64/sve/pfalse-binary.c: Add -funwind-tables. + * gcc.target/aarch64/sve/pfalse-binary_int_opt_n.c: Likewise. + * gcc.target/aarch64/sve/pfalse-binary_opt_n.c: Likewise. + * gcc.target/aarch64/sve/pfalse-binary_opt_single_n.c: Likewise. + * gcc.target/aarch64/sve/pfalse-binary_rotate.c: Likewise. + * gcc.target/aarch64/sve/pfalse-binary_uint64_opt_n.c: Likewise. + * gcc.target/aarch64/sve/pfalse-binary_uint_opt_n.c: Likewise. + * gcc.target/aarch64/sve/pfalse-binaryxn.c: Likewise. + * gcc.target/aarch64/sve/pfalse-clast.c: Likewise. + * gcc.target/aarch64/sve/pfalse-compare_opt_n.c: Likewise. + * gcc.target/aarch64/sve/pfalse-compare_wide_opt_n.c: Likewise. + * gcc.target/aarch64/sve/pfalse-count_pred.c: Likewise. + * gcc.target/aarch64/sve/pfalse-fold_left.c: Likewise. + * gcc.target/aarch64/sve/pfalse-load.c: Likewise. + * gcc.target/aarch64/sve/pfalse-load_ext.c: Likewise. + * gcc.target/aarch64/sve/pfalse-load_ext_gather_index.c: Likewise. + * gcc.target/aarch64/sve/pfalse-load_ext_gather_offset.c: Likewise. + * gcc.target/aarch64/sve/pfalse-load_gather_sv.c: Likewise. + * gcc.target/aarch64/sve/pfalse-load_gather_vs.c: Likewise. + * gcc.target/aarch64/sve/pfalse-load_replicate.c: Likewise. + * gcc.target/aarch64/sve/pfalse-prefetch.c: Likewise. + * gcc.target/aarch64/sve/pfalse-prefetch_gather_index.c: Likewise. + * gcc.target/aarch64/sve/pfalse-prefetch_gather_offset.c: Likewise. + * gcc.target/aarch64/sve/pfalse-ptest.c: Likewise. + * gcc.target/aarch64/sve/pfalse-rdffr.c: Likewise. + * gcc.target/aarch64/sve/pfalse-reduction.c: Likewise. + * gcc.target/aarch64/sve/pfalse-reduction_wide.c: Likewise. + * gcc.target/aarch64/sve/pfalse-shift_right_imm.c: Likewise. + * gcc.target/aarch64/sve/pfalse-store.c: Likewise. + * gcc.target/aarch64/sve/pfalse-store_scatter_index.c: Likewise. + * gcc.target/aarch64/sve/pfalse-store_scatter_offset.c: Likewise. + * gcc.target/aarch64/sve/pfalse-storexn.c: Likewise. + * gcc.target/aarch64/sve/pfalse-ternary_opt_n.c: Likewise. + * gcc.target/aarch64/sve/pfalse-ternary_rotate.c: Likewise. + * gcc.target/aarch64/sve/pfalse-unary.c: Likewise. + * gcc.target/aarch64/sve/pfalse-unary_convert_narrowt.c: Likewise. + * gcc.target/aarch64/sve/pfalse-unary_convertxn.c: Likewise. + * gcc.target/aarch64/sve/pfalse-unary_n.c: Likewise. + * gcc.target/aarch64/sve/pfalse-unary_pred.c: Likewise. + * gcc.target/aarch64/sve/pfalse-unary_to_uint.c: Likewise. + * gcc.target/aarch64/sve/pfalse-unaryxn.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-binary.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-binary_int_opt_n.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-binary_int_opt_single_n.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-binary_opt_n.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-binary_opt_single_n.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-binary_to_uint.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-binary_uint_opt_n.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-binary_wide.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-compare.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-load_ext_gather_index_restricted.c, + * gcc.target/aarch64/sve2/pfalse-load_ext_gather_offset_restricted.c, + * gcc.target/aarch64/sve2/pfalse-load_gather_sv_restricted.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-load_gather_vs.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-shift_left_imm_to_uint.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-shift_right_imm.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-store_scatter_index_restricted.c, + * gcc.target/aarch64/sve2/pfalse-store_scatter_offset_restricted.c, + * gcc.target/aarch64/sve2/pfalse-unary.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-unary_convert.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-unary_convert_narrowt.c: Likewise. + * gcc.target/aarch64/sve2/pfalse-unary_to_int.c: Likewise. + +2025-07-10 Kyrylo Tkachov <ktkachov@nvidia.com> + + PR target/120999 + * gcc.target/aarch64/sve2/pr120999.c: New test. + +2025-07-10 Richard Sandiford <richard.sandiford@arm.com> + + * lib/target-supports.exp (check_effective_target_aarch64_sve2p1_hw): + New proc. + * gcc.target/aarch64/sve2/dupq_1.c: Extend to big-endian. Add + noipa attributes. + * gcc.target/aarch64/sve2/extq_1.c: Likewise. + * gcc.target/aarch64/sve2/uzpq_1.c: Likewise. + * gcc.target/aarch64/sve2/zipq_1.c: Likewise. + * gcc.target/aarch64/sve2/dupq_1_run.c: New test. + * gcc.target/aarch64/sve2/extq_1_run.c: Likewise. + * gcc.target/aarch64/sve2/uzpq_1_run.c: Likewise. + * gcc.target/aarch64/sve2/zipq_1_run.c: Likewise. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + * gfortran.dg/g77/980310-3.f: Comment spelling fix: bellow -> below. + * jit.dg/test-debuginfo.c: Likewise. + +2025-07-10 Pan Li <pan2.li@intel.com> + + * gcc.target/riscv/sat/sat_s_add-run-1-i16.c: Take rv32 || rv64 + instead of riscv_v for scalar run test. + * gcc.target/riscv/sat/sat_s_add-run-1-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-1-i64.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-1-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-2-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-2-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-2-i64.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-2-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-3-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-3-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-3-i64.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-3-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-4-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-4-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-4-i64.c: Ditto. + * gcc.target/riscv/sat/sat_s_add-run-4-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-1-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-1-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-1-i64.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-1-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-2-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-2-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-2-i64.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-2-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-3-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-3-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-3-i64.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-3-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-4-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-4-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-4-i64.c: Ditto. + * gcc.target/riscv/sat/sat_s_sub-run-4-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-1-i16-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-1-i32-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-1-i32-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-1-i64-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-1-i64-to-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-1-i64-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-2-i16-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-2-i32-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-2-i32-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-2-i64-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-2-i64-to-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-2-i64-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-3-i16-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-3-i32-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-3-i32-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-3-i64-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-3-i64-to-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-3-i64-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-4-i16-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-4-i32-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-4-i32-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-4-i64-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-4-i64-to-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-4-i64-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-5-i16-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-5-i32-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-5-i32-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-5-i64-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-5-i64-to-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-5-i64-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-6-i16-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-6-i32-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-6-i32-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-6-i64-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-6-i64-to-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-6-i64-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-7-i16-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-7-i32-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-7-i32-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-7-i64-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-7-i64-to-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-7-i64-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-8-i16-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-8-i32-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-8-i32-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-8-i64-to-i16.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-8-i64-to-i32.c: Ditto. + * gcc.target/riscv/sat/sat_s_trunc-run-8-i64-to-i8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-1-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-1-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-1-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-1-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-2-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-2-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-2-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-2-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-3-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-3-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-3-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-3-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-4-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-4-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-4-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-4-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-5-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-5-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-5-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-5-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-6-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-6-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-6-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-6-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-7-u16-from-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-7-u16-from-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-7-u32-from-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-7-u8-from-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-7-u8-from-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add-run-7-u8-from-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-1-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-1-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-1-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-1-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-2-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-2-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-2-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-2-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-3-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-3-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-3-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-3-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-4-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-4-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-4-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_add_imm-run-4-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-1-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-1-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-1-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-1-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-10-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-10-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-10-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-10-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-11-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-11-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-11-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-11-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-12-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-12-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-12-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-12-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-2-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-2-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-2-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-2-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-3-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-3-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-3-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-3-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-4-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-4-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-4-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-4-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-5-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-5-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-5-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-5-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-6-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-6-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-6-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-6-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-7-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-7-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-7-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-7-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-8-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-8-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-8-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-8-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-9-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-9-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-9-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub-run-9-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-1-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-1-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-1-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-1-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-2-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-2-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-2-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-2-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-3-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-3-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-3-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-3-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-4-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-4-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-4-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_sub_imm-run-4-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-1-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-1-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-1-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-1-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-2-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-2-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-2-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-2-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-3-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-3-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-3-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-3-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-4-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-4-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-4-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-4-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-5-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-5-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-5-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-5-u8.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-6-u16.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-6-u32.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-6-u64.c: Ditto. + * gcc.target/riscv/sat/sat_u_trunc-run-6-u8.c: Ditto. + 2025-07-09 Jason Merrill <jason@redhat.com> PR c++/120243 diff --git a/gcc/testsuite/c-c++-common/Warray-bounds-11.c b/gcc/testsuite/c-c++-common/Warray-bounds-11.c new file mode 100644 index 0000000..686a94d --- /dev/null +++ b/gcc/testsuite/c-c++-common/Warray-bounds-11.c @@ -0,0 +1,21 @@ +/* PR c++/120954 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds=2" } */ + +static const int a[32] = { 11, 12, 13, 14, 15 }; +static const int b[32] = { 21, 22, 23, 24, 25 }; +static const int c[32] = { 31, 32, 33, 34, 35 }; +static const int d[32] = { 111, 112, 113, 114, 115 }; +static const int e[32] = { 121, 122, 123, 124, 125 }; +static const int f[32] = { 131, 132, 133, 134, 135 }; + +int +foo (int x, int y) +{ + int r = 0; + if (x >= 0 && x < 32) + r = (y >= 4 ? (y >= 0x65 ? a : b ) : c)[x]; + else if (x >= 0x100 && x < 0x120) + r = (y >= 4 ? (y >= 0x65 ? d : e ) : f)[x - 0x100]; + return r; +} diff --git a/gcc/testsuite/c-c++-common/musttail32.c b/gcc/testsuite/c-c++-common/musttail32.c new file mode 100644 index 0000000..f1b7052 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail32.c @@ -0,0 +1,23 @@ +/* PR ipa/121023 */ +/* { dg-do compile { target musttail } } */ +/* { dg-options "-O2" } */ + +struct S { int a, b; }; + +[[gnu::noipa]] int +foo (struct S x, int y, int z) +{ + return x.a + y + z; +} + +[[gnu::noinline]] static int +bar (struct S x, int y, int z) +{ + [[gnu::musttail]] return foo ((struct S) { x.a, 0 }, y, 1); +} + +int +baz (int x) +{ + return bar ((struct S) { 1, 2 }, x, 2) + bar ((struct S) { 2, 3 }, x + 1, 2); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ellipsis2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ellipsis2.C index b6a5323..c473257 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ellipsis2.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ellipsis2.C @@ -9,4 +9,6 @@ struct A constexpr int ellipsis(...) { return 1; } -static_assert(ellipsis(A().empty()), "Error"); // { dg-error "non-constant condition|empty" } +static_assert(ellipsis(A().empty()), "Error"); // { dg-error "non-constant condition" } +// { dg-error "call to non-'constexpr' function 'bool A::empty\\\(\\\)'" "" { target c++23_down } .-1 } +// { dg-error "temporary of non-literal type 'A' in a constant expression" "" { target c++26 } .-2 } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-throw.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-throw.C index 9c49fa4..9abf4a3 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-throw.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-throw.C @@ -2,8 +2,8 @@ // Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'. constexpr int may_throw(bool decide) { - return decide ? 42 : throw -1; // { dg-error "throw" } + return decide ? 42 : throw -1; // { dg-error "throw" "" { target c++23_down } } } -constexpr int x = may_throw(false); // { dg-message "may_throw" } -constexpr int y = may_throw(true); +constexpr int x = may_throw(false); // { dg-message "may_throw" "" { target c++23_down } } +constexpr int y = may_throw(true); // { dg-error "uncaught exception '-1'" "" { target c++26 } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp0x/duplicate1.C b/gcc/testsuite/g++.dg/cpp0x/duplicate1.C index 1545e1c..4e85edc 100644 --- a/gcc/testsuite/g++.dg/cpp0x/duplicate1.C +++ b/gcc/testsuite/g++.dg/cpp0x/duplicate1.C @@ -6,7 +6,7 @@ struct A virtual void foo() const; }; -struct B final final : A /* { dg-error "duplicate virt-specifier" } +struct B final final : A /* { dg-error "duplicate 'final' specifier" } { dg-begin-multiline-output "" } struct B final final : A ^~~~~ diff --git a/gcc/testsuite/g++.dg/cpp0x/final1.C b/gcc/testsuite/g++.dg/cpp0x/final1.C new file mode 100644 index 0000000..1d64095 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/final1.C @@ -0,0 +1,11 @@ +// PR c++/120628 +// { dg-do compile { target c++98_only } } + +namespace A { + struct B {}; + struct B final = {}; +} +namespace C { + struct D { D (int, int); }; + struct D final (42, 0); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/final2.C b/gcc/testsuite/g++.dg/cpp0x/final2.C new file mode 100644 index 0000000..d8d5866 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/final2.C @@ -0,0 +1,26 @@ +// PR c++/120628 +// { dg-do compile } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++14 } } + +namespace U { + struct A {}; + struct A final = {}; +} +namespace V { + template <int N> + struct B {}; + template <int N> + struct B<N> final = {}; // { dg-warning "variable templates only available with" "" { target c++11_down } } +} +struct C { + struct D {}; + static D foo (); + struct D final = foo (); // { dg-warning "non-static data member initializers only available with" "" { target c++98_only } } +}; +namespace W { + struct E { struct F {}; }; + struct E::F final = {}; +} +template <int N> +struct V::B<N> final = {}; // { dg-warning "variable templates only available with" "" { target c++11_down } } diff --git a/gcc/testsuite/g++.dg/cpp0x/override2.C b/gcc/testsuite/g++.dg/cpp0x/override2.C index ab4dec4..d7f542e 100644 --- a/gcc/testsuite/g++.dg/cpp0x/override2.C +++ b/gcc/testsuite/g++.dg/cpp0x/override2.C @@ -23,9 +23,9 @@ struct D5 : B3<D5> {}; struct D6 : B4<D6> {}; // { dg-error "cannot derive from 'final' base" } -struct B6 final final {}; // { dg-error "duplicate virt-specifier" } +struct B6 final final {}; // { dg-error "duplicate 'final' specifier" } -struct B7 override {}; // { dg-error "cannot specify 'override' for a class" } +struct B7 override {}; // { dg-error "variable 'B7 override' has initializer but incomplete type" } namespace N { @@ -45,7 +45,7 @@ int main() struct B2 final; // { dg-error "redeclaration" } struct B2 override; // { dg-message "previously declared here" } struct B2 final {}; // { dg-error "redefinition" } - struct B2 override {}; // { dg-error "cannot specify 'override' for a class" } + struct B2 override {}; // { dg-error "redeclaration of 'main\\\(\\\)::B2 override'" } B2 override{}; // { dg-error "redeclaration" } struct foo final {}; // { dg-message "previous definition" } struct foo final {}; // { dg-error "redefinition" } diff --git a/gcc/testsuite/g++.dg/cpp0x/override5.C b/gcc/testsuite/g++.dg/cpp0x/override5.C new file mode 100644 index 0000000..3382c14 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/override5.C @@ -0,0 +1,26 @@ +// PR c++/120569 +// { dg-do compile } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++14 } } + +namespace U { + struct A {}; + struct A override {}; // { dg-warning "extended initializer lists only available with" "" { target c++98_only } } +} +namespace V { + template <int N> + struct B {}; + template <int N> + struct B<N> override {}; // { dg-warning "extended initializer lists only available with" "" { target c++98_only } } +} // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +struct C { + struct D {}; + struct D override {}; // { dg-warning "extended initializer lists only available with" "" { target c++98_only } } +}; // { dg-warning "non-static data member initializers only available with" "" { target c++98_only } .-1 } +namespace W { + struct E { struct F {}; }; + struct E::F override {}; // { dg-warning "extended initializer lists only available with" "" { target c++98_only } } +} +template <int N> +struct V::B<N> override {}; // { dg-warning "extended initializer lists only available with" "" { target c++98_only } } + // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp0x/override6.C b/gcc/testsuite/g++.dg/cpp0x/override6.C new file mode 100644 index 0000000..601e91d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/override6.C @@ -0,0 +1,26 @@ +// PR c++/120628 +// { dg-do compile } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++14 } } + +namespace U { + struct A {}; + struct A override = {}; +} +namespace V { + template <int N> + struct B {}; + template <int N> + struct B<N> override = {}; // { dg-warning "variable templates only available with" "" { target c++11_down } } +} +struct C { + struct D {}; + static D foo (); + struct D override = foo (); // { dg-warning "non-static data member initializers only available with" "" { target c++98_only } } +}; +namespace W { + struct E { struct F {}; }; + struct E::F override = {}; +} +template <int N> +struct V::B<N> override = {}; // { dg-warning "variable templates only available with" "" { target c++11_down } } diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C index f7439d8..18efd23 100644 --- a/gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C @@ -12,7 +12,7 @@ void f2 () { for (;;) - constexpr bool b = ({ break; false; }) && false; // { dg-error "is not a constant expression" } + constexpr bool b = ({ break; false; }) && false; // { dg-error "'break' outside of a loop or 'switch'" } } constexpr bool diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-throw.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-throw.C index b5fa6ca..75e2fb8 100644 --- a/gcc/testsuite/g++.dg/cpp1y/constexpr-throw.C +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-throw.C @@ -27,8 +27,8 @@ constexpr int fun(int n) { case 0: return 1; default: - throw; // { dg-error "not a constant expression" } - } + throw; // { dg-error "not a constant expression" "" { target c++23_down } } + } // { dg-error "'void __cxa_rethrow\\\(\\\)' called with no caught exceptions active" "" { target c++26 } .-1 } } static_assert(fun(0), ""); diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C index 35beb27..2c69b3b 100644 --- a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C @@ -18,7 +18,7 @@ struct H { short size () const { return 0; } constexpr const char *data () const { return ""; } }; struct I { constexpr signed char size () const { return 0; } const char *data () const { return ""; } }; -struct J { constexpr int size () const { return j ? throw 1 : 0; } // { dg-error "expression '<throw-expression>' is not a constant expression" } +struct J { constexpr int size () const { return j ? throw 1 : 0; } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23_down } } constexpr const char *data () const { return ""; }; constexpr J (int x) : j (x) {} int j; }; @@ -114,6 +114,7 @@ foo () asm ((J (0))); asm ("" :: (J (1)) (1)); // { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } asm ((M {})); #if __cpp_constexpr_dynamic_alloc >= 201907L asm ((N {})); // { dg-error "constexpr string 'data\\\(\\\)\\\[0\\\]' must be a constant expression" "" { target c++20 } } @@ -188,6 +189,7 @@ bar () asm ((J (0))); asm ("" :: (J (1)) (1)); // { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } asm ((M {})); #if __cpp_constexpr_dynamic_alloc >= 201907L asm ((N {})); // { dg-error "constexpr string 'data\\\(\\\)\\\[0\\\]' must be a constant expression" "" { target c++20 } } @@ -272,7 +274,7 @@ namespace NN #if __cplusplus >= 201402L struct J { static constexpr int size () { return 0; } - static constexpr const char *data (int x = 0) { if (x) return nullptr; else throw 1; } }; // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++14 } } + static constexpr const char *data (int x = 0) { if (x) return nullptr; else throw 1; } }; // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target { c++14 && c++23_down } } } #endif #if __cpp_if_consteval >= 202106L struct K { @@ -284,12 +286,12 @@ namespace NN static constexpr const char *data () { if consteval { return "test"; } else { throw 1; } } }; struct M { - static constexpr int size () { if consteval { throw 1; } else { return 4; } } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23 } } + static constexpr int size () { if consteval { throw 1; } else { return 4; } } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23_only } } static constexpr const char *data () { return "test"; } }; struct N { static constexpr int size () { return 4; } - static constexpr const char *data () { if consteval { throw 1; } else { return "test"; } } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23 } } + static constexpr const char *data () { if consteval { throw 1; } else { return "test"; } } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23_only } } }; #endif struct O { constexpr int operator () () const { return 12; } }; @@ -318,12 +320,15 @@ namespace NN asm ((I {})); #if __cplusplus >= 201402L asm ((J {})); // { dg-error "constexpr string 'data\\\(\\\)' must be a core constant expression" "" { target c++14 } } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } #endif #if __cpp_if_consteval >= 202106L asm ((K {})); asm ((L {})); asm ((M {})); // { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" "" { target c++23 } } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } asm ((N {})); // { dg-error "constexpr string 'data\\\(\\\)\\\[0\\\]' must be a constant expression" "" { target c++23 } } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } #endif asm ((Q {})); asm ((R {})); @@ -348,12 +353,15 @@ namespace NN asm ((I {})); #if __cplusplus >= 201402L asm ((J {})); // { dg-error "constexpr string 'data\\\(\\\)' must be a core constant expression" "" { target c++14 } } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } #endif #if __cpp_if_consteval >= 202106L asm ((K {})); asm ((L {})); asm ((M {})); // { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" "" { target c++23 } } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } asm ((N {})); // { dg-error "constexpr string 'data\\\(\\\)\\\[0\\\]' must be a constant expression" "" { target c++23 } } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } #endif asm ((Q {})); asm ((R {})); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh1.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh1.C new file mode 100644 index 0000000..9eed3aa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh1.C @@ -0,0 +1,140 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +struct S { + constexpr S () : s (new int (0)) {} + constexpr S (int x) : s (new int (x)) {} + constexpr S (const S &x) : s (new int (*x.s)) {} + constexpr ~S () { delete s; } + int *s; +}; +struct T : public S { + constexpr T () : S () {} + constexpr T (int x) : S (x) {} + constexpr T (const T &x) : S (*x.s) {} + constexpr ~T () {} +}; +struct U : public T { + constexpr U () : T () {} + constexpr U (int x) : T (x) {} + constexpr U (const U &x) : T (*x.s) {} + constexpr ~U () {} +}; +struct V : public T { + constexpr V () : T () {} + constexpr V (int x) : T (x) {} + constexpr V (const U &x) : T (*x.s) {} + constexpr ~V () {} +}; + +template <typename X> +constexpr int +foo (X x) +{ + try { throw x; } + catch (int &a) { return 42 + a; } + catch (const unsigned b) { return 43 + b; } + catch (const long &c) { return 44 + c; } + catch (bool d) { return 45 + d; } + catch (const U &e) { return 46 + *e.s; } + catch (const T &f) { return 47 + *f.s; } + catch (S g) { return 48 + *g.s; } + catch (int *const &h) { return 49; } + catch (long long *) { return 50; } + catch (const S *const &) { return 51; } + catch (...) { return 52; } +} + +template <typename X> +constexpr int +bar (const X &x) +{ + throw x; +} + +template <typename X> +constexpr int +baz (const X &x) +{ + try + { + try { bar (x); } + catch (int &a) { a += 80; throw; } + catch (long b) { b += 80; throw; } + catch (U &c) { c.s[0] += 82; throw; } + catch (V d) { d.s[0] += 83; throw; } + } + catch (int a) { return 42 + a; } + catch (const long &b) { return 43 + b; } + catch (S &c) { return 44 + c.s[0]; } + catch (long long d) { return 45 + d; } + catch (...) { return -1; } +} + +constexpr int +qux (int x, bool y = true) +{ + try + { + switch (x) + { + case 0: throw 42; break; + case 1: x = y ? throw 43 : 5; break; + case 2: x = -(throw 44, 6); break; + case 3: x = x + (throw 45, 7); break; + case 4: x = (throw 46, 8) + x; break; + case 5: x = (throw 47, y) ? 4 : 5; break; + case 6: x += (throw 48, y); break; + case 7: x = (double) (throw 49, y); break; + case 8: x = foo ((throw 50, x)); break; + default: break; + } + } + catch (int a) { return a; } + return -1; +} + +constexpr int +corge () +{ + try { throw 0; } + catch (int *const &h) { return 49; } + catch (long long *) { return 50; } + catch (const S *const &) { return 51; } + catch (...) { return 52; } +} + +static_assert (foo (12) == 54); +static_assert (foo (12U) == 55); +static_assert (foo (12L) == 56); +static_assert (foo (false) == 45); +static_assert (foo (true) == 46); +static_assert (foo (U (12)) == 58); +static_assert (foo (T (20)) == 67); +static_assert (foo (S (30)) == 78); +static_assert (foo (nullptr) == 49); +static_assert (foo ((int *)nullptr) == 49); +static_assert (foo ((long long *)nullptr) == 50); +static_assert (foo ((const S *)nullptr) == 51); +static_assert (foo ((const T *)nullptr) == 51); +static_assert (foo ((const U *)nullptr) == 51); +static_assert (foo (12ULL) == 52); +static_assert (baz (5) == 127); +static_assert (baz (6L) == 49); +static_assert (baz (U (25)) == 151); +static_assert (baz (V (26)) == 70); +static_assert (baz (T (27)) == 71); +static_assert (baz (S (28)) == 72); +static_assert (baz (7LL) == 52); +static_assert (baz (8ULL) == -1); +static_assert (qux (0) == 42); +static_assert (qux (1) == 43); +static_assert (qux (2) == 44); +static_assert (qux (3) == 45); +static_assert (qux (4) == 46); +static_assert (qux (5) == 47); +static_assert (qux (6) == 48); +static_assert (qux (7) == 49); +static_assert (qux (8) == 50); +static_assert (corge () == 52); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh10.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh10.C new file mode 100644 index 0000000..a86cc4d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh10.C @@ -0,0 +1,110 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +struct S { +}; +struct T { + constexpr ~T () noexcept (false) { throw S {}; } +}; +struct U { + int u; +}; +struct V { + int v; + constexpr V (int x) + try : v { x } + { + if (v > 42) + throw U { 42 }; + } + catch (U &u) + { + --u.u; + } +}; +struct W { + constexpr ~W () { ++w; } + int &w; +}; +struct X : public V { + constexpr X (int x) + try : V(x) + { + } + catch (U &u) + { + --u.u; + } +}; + +constexpr int +foo (bool x) +{ + try + { + T t; // { dg-error "'std::terminate' called after throwing an exception '42'" } + if (x) // { dg-message "destructor exited with an exception" "" { target *-*-* } .-1 } + throw 42; + return 10; + } + catch (S) + { + return 11; + } +} + +constexpr int +bar () +{ + V v { 42 }; + try + { + V w { 43 }; + } + catch (const U &u) + { + if (u.u == 41) + return 44; + } + return -1; +} + +constexpr int +baz () +{ + int i = 42; + try + { + W w { i }; + throw S (); + } + catch (...) + { + if (i == 43) + return 42; + } + return -1; +} + +constexpr int +qux () +{ + X v { 42 }; + try + { + X w { 43 }; + } + catch (const U &u) + { + if (u.u == 40) + return 48; + } + return -1; +} + +static_assert (foo (false) == 11); +constexpr int a = foo (true); // { dg-message "in 'constexpr' expansion of" } +static_assert (bar () == 44); +static_assert (baz () == 42); +static_assert (qux () == 48); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh11.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh11.C new file mode 100644 index 0000000..287e066 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh11.C @@ -0,0 +1,69 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +struct A { + explicit constexpr A (int x) noexcept : a (x) {} + constexpr virtual int foo () const noexcept { return a; } + constexpr virtual ~A () {} + int a; +}; +struct B : public A { + explicit constexpr B (int x) noexcept : A (x) {} + constexpr int foo () const noexcept override { return a | 0x10; } +}; +struct C : public A { + explicit constexpr C (int x) noexcept : A (x) {} +}; +struct D : public A { + explicit constexpr D (int x) noexcept : A (x) {} +}; +struct E { + constexpr E () noexcept : e (0) {} + explicit constexpr E (int x) noexcept : e (x) {} + int e; +}; +struct F : public E, public B { + explicit constexpr F (int x) noexcept : B (x) {} +}; +struct G : public E, public C { + explicit constexpr G (int x) noexcept : C (x) {} +}; +struct H : public E, public D { + explicit constexpr H (int x) noexcept : D (x) {} +}; + +consteval int +bar (void (*fn) ()) +{ + try + { + fn (); + } + catch (C &a) + { + return a.foo () | 0x20; + } + catch (const C &b) // { dg-warning "exception of type 'C' will be caught by earlier handler" } + { + return b.foo () | 0x60; + } + catch (A &c) + { + return c.foo (); + } + catch (const A &d) // { dg-warning "exception of type 'A' will be caught by earlier handler" } + { + return d.foo () | 0x40; + } + return -1; +} + +static_assert (bar ([] { throw A { 1 }; }) == 1); +static_assert (bar ([] { throw B { 2 }; }) == 0x12); +static_assert (bar ([] { throw C { 3 }; }) == 0x23); +static_assert (bar ([] { throw D { 4 }; }) == 4); +constexpr int a = bar ([] { throw E { 5 }; }); // { dg-error "uncaught exception 'E\\\{5\\\}'" } +static_assert (bar ([] { throw F { 6 }; }) == 0x16); +static_assert (bar ([] { throw G { 7 }; }) == 0x27); +static_assert (bar ([] { throw H { 8 }; }) == 8); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh12.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh12.C new file mode 100644 index 0000000..4a85f15 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh12.C @@ -0,0 +1,74 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +struct A { + explicit constexpr A (int x) noexcept : a (x) {} + constexpr virtual int foo () const noexcept { return a; } + constexpr virtual ~A () {} + int a; +}; +struct B : public A { + explicit constexpr B (int x) noexcept : A (x) {} + constexpr int foo () const noexcept override { return a | 0x10; } +}; +struct C : public A { + explicit constexpr C (int x) noexcept : A (x) {} +}; +struct D : public A { + explicit constexpr D (int x) noexcept : A (x) {} +}; +struct E { + constexpr E () noexcept : e (0) {} + explicit constexpr E (int x) noexcept : e (x) {} + int e; +}; +struct F : public E, public B { + explicit constexpr F (int x) noexcept : B (x) {} +}; +struct G : public E, public C { + explicit constexpr G (int x) noexcept : C (x) {} +}; +struct H : public E, public D { + explicit constexpr H (int x) noexcept : D (x) {} +}; + +consteval int +bar (void (*fn) ()) +{ + int r = 0; + try + { + fn (); + } + catch (C *a) + { + r = a->foo () | 0x20; + delete a; + } + catch (const C *b) + { + r = b->foo () | 0x60; + delete b; + } + catch (A *c) + { + r = c->foo (); + delete c; + } + catch (const A *d) + { + r = d->foo () | 0x40; + delete d; + } + return r; +} + +static_assert (bar ([] { throw new A { 1 }; }) == 1); +static_assert (bar ([] { throw new B { 2 }; }) == 0x12); +static_assert (bar ([] { throw new C { 3 }; }) == 0x23); +static_assert (bar ([] { throw new D { 4 }; }) == 4); +constexpr int a = bar ([] { throw new E { 5 }; }); // { dg-error "uncaught exception of type 'E\\\*'" } +static_assert (bar ([] { throw new F { 6 }; }) == 0x16); +static_assert (bar ([] { throw new G { 7 }; }) == 0x27); +static_assert (bar ([] { throw new H { 8 }; }) == 8); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh13.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh13.C new file mode 100644 index 0000000..d62771c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh13.C @@ -0,0 +1,36 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +template <typename T> +consteval T +foo (T x) +{ + try + { + throw &x; + } + catch (void *ptr) // { dg-message "for type 'void\\\*'" } + { + return *static_cast<T *> (ptr) | 0x10; + } + catch (const void *ptr) // { dg-message "for type 'const void\\\*'" } + { + return *static_cast<const T *> (ptr) | 0x20; + } + catch (T *ptr) // { dg-warning "exception of type 'T\\\*' will be caught by earlier handler" } + { // { dg-warning "exception of type 'int\\\*' will be caught by earlier handler" "" { target *-*-* } .-1 } + return *ptr | 0x30; // { dg-warning "exception of type 'long long unsigned int\\\*' will be caught by earlier handler" "" { target *-*-* } .-2 } + } + catch (const T *ptr) + { + return *ptr | 0x40; + } + catch (...) + { + return -1; + } +} + +static_assert (foo (1) == 0x11); +static_assert (foo (2ULL) == 0x12ULL); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh14.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh14.C new file mode 100644 index 0000000..3e52f2b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh14.C @@ -0,0 +1,42 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +template <typename T> +constexpr T +foo (T x, auto... y) +{ + const T z[] = { x, y... }; + try + { + throw z; + } + catch (const T (&a)[4]) + { + return T (); + } + catch (const T *b) + { + return b[0]; + } + catch (...) + { + return T (); + } +} + +void +bar () +{ +} + +void +baz () +{ +} + +static_assert (foo (42, 43, 44, 45, 46) == 42); +static_assert (foo (43U, 44U, 45U, 46U) == 43U); +static_assert (foo (44LL, 45LL) == 44LL); +static_assert (foo (bar, baz, bar, baz) == bar); +static_assert (foo (baz, bar) == baz); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh15.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh15.C new file mode 100644 index 0000000..3dea461 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh15.C @@ -0,0 +1,39 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +int +foo (int x, int y) +{ + return x + y; +} + +constexpr int +bar (int x) +{ + if (x < 0) + throw x; + return x; +} + +constexpr int +baz (int x, int y) +{ + return foo (bar (x), bar (y)); +} + +constexpr int +qux (int x, int y) +{ + try + { + return baz (x, y); + } + catch (int) + { + return 42; + } +} + +static_assert (qux (12, -1) == 42); +static_assert (qux (-7, 12) == 42); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh2.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh2.C new file mode 100644 index 0000000..8bd6b6f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh2.C @@ -0,0 +1,112 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +struct S { + constexpr S () : s (0) {} + constexpr S (int x) : s (x) { if (x == 42) throw 42; } + constexpr S (const S &x) : s (x.s) {} + constexpr ~S () noexcept (false) { if (s == 41) throw 41; } + constexpr const char *what () const noexcept { return "S"; } + int s; +}; +struct T : public S { + constexpr T () {} + constexpr T (int x) : S (x) {} + constexpr T (const T &x) : S (x.s) {} + constexpr ~T () {} + constexpr const char *what () const noexcept { return "T"; } +}; +struct U { + constexpr U () : u (0) {} + constexpr U (int x) : u (x) {} + constexpr U (const S &x) : u (0) {} + constexpr U (const U &x) : u (x.u) { if (u == 42) throw 43; } + constexpr ~U () {} + constexpr const char *what () const noexcept { return "U"; } + int u; +}; + +constexpr int +foo (int x) +{ + if (x == 1) + throw 43; + return x; +} + +constexpr int +bar (int x) noexcept // { dg-error "'std::terminate' called" } +{ // { dg-message "uncaught exception exited from 'noexcept' function 'constexpr int bar\\\(int\\\)'" "" { target *-*-* } .-1 } + return foo (x); +} + +constexpr int +baz (int x) +{ + switch (x) + { + case 0: throw 1; break; + case 1: try { x = bar (x); } catch (...) {} break; // { dg-message "in 'constexpr' expansion of" } + case 2: throw S (2); break; + case 3: try { throw S (42); } catch (int a) { if (a != 42) throw -1; } break; + case 4: try { S s (41); throw 2; } catch (...) {} break; // { dg-error "'std::terminate' called" } + case 5: return 5; // { dg-message "destructor exited with an exception" "" { target *-*-* } .-1 } + case 6: + try + { + throw S (5); + } + catch (const T &) {} + catch (int) {} + catch (const bool &) {} + catch (const T **const &) {} + break; + case 7: try { constexpr int y = foo (2); } catch (...) {} break; + case 8: + try + { + try + { + throw U (); + } + catch (U &u) + { + u.u = 42; + throw; + } + } + catch (U u) // { dg-error "'std::terminate' called" } + { // { dg-message "constructor exited with another exception while entering handler" "" { target *-*-* } .-1 } + } + break; + case 9: + try + { + throw U (S (41)); // { dg-error "'std::terminate' called" } + } // { dg-message "destructor exited with an exception" "" { target *-*-* } .-1 } + catch (...) + { + } + break; + } + return -1; +} + +constexpr int +qux (int x) +{ + try { constexpr int y = foo (1); } catch (...) {} // { dg-error "uncaught exception" } + return 0; +} + +constexpr int a = baz (0); // { dg-error "uncaught exception" } +constexpr int b = baz (1); // { dg-message "in 'constexpr' expansion of" } +constexpr int c = baz (2); // { dg-error "uncaught exception" } +constexpr int d = baz (3); +constexpr int e = baz (4); // { dg-message "in 'constexpr' expansion of" } +constexpr int f = baz (5); +constexpr int g = baz (6); // { dg-error "uncaught exception" } +constexpr int h = baz (7); +constexpr int i = baz (8); // { dg-message "in 'constexpr' expansion of" } +constexpr int j = baz (9); // { dg-message "in 'constexpr' expansion of" } diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh3.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh3.C new file mode 100644 index 0000000..f844d11 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh3.C @@ -0,0 +1,442 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +#include <exception> +#include <new> +#include <typeinfo> + +constexpr std::exception a; +constexpr const char *b = a.what (); +constexpr std::bad_exception c; +constexpr const char *d = c.what (); +constexpr std::bad_alloc e; +constexpr const char *f = e.what (); +constexpr std::bad_array_new_length g; +constexpr const char *h = g.what (); +constexpr std::bad_cast i; +constexpr const char *j = i.what (); +constexpr std::bad_typeid k; +constexpr const char *l = k.what (); +constexpr std::exception_ptr m = nullptr; +static_assert (m == nullptr); +constexpr std::exception_ptr n = std::current_exception (); +static_assert (n == nullptr); +constexpr std::exception_ptr o; +static_assert (o == nullptr); +constexpr std::nested_exception p; +static_assert (p.nested_ptr () == nullptr); + +struct A { virtual ~A () {} }; +struct B { virtual void b (); }; +struct C { virtual void c (); }; +struct D : private B { virtual void d (); }; +struct E { virtual void e (); }; +struct F : D, E, private C { virtual void f (); }; +struct G { constexpr G () { if (std::uncaught_exceptions () != 0) asm (""); } }; +struct H { constexpr H () : h (0) {} constexpr ~H () { if (std::uncaught_exceptions () != h) asm (""); } int h; }; +struct I : std::nested_exception { }; +struct J { virtual ~J () noexcept = default; }; +struct K final { }; +struct L : J, std::nested_exception { }; +struct M { }; +struct N : I, L { }; +struct O : private std::nested_exception { }; + +constexpr int +foo (int x) +{ + if (std::uncaught_exceptions () != 0) + return -1; + switch (x) + { + case 0: + try + { + const std::type_info &s = typeid (*(A *) 0); + return -1; + } + catch (const std::bad_typeid &x) + { + if (std::uncaught_exceptions () != 0) + return -1; + const char *p = x.what (); + return 1; + } + catch (...) + { + return -1; + } + break; + case 1: + try + { + static constexpr F f; + D &d = dynamic_cast<D &>((B &) f); + return -1; + } + catch (std::bad_cast x) + { + const char *p = x.what (); + return 2; + } + catch (...) + { + return -1; + } + break; + case 2: + try + { + H h; + h.h = 1; + if (std::current_exception () != nullptr) + return -1; + throw G (); + } + catch (const G &g) + { + if (std::uncaught_exceptions () != 0) + return -1; + if (std::current_exception () == nullptr) + return -1; + return 3; + } + catch (...) + { + return -1; + } + break; + case 3: + try + { + decltype (sizeof 0) x = -64; + char (*a)[2] = new char[x][2]; + delete[] a; + } + catch (std::bad_array_new_length x) + { + return 4; + } + break; + case 4: + try + { + int y = -1; + int *a = new int[y]; + delete[] a; + } + catch (const std::bad_array_new_length &) + { + return 5; + } + break; + case 5: + try + { + int z = 1; + int *a = new int[z]{1, 2, 3}; + delete[] a; + } + catch (std::bad_array_new_length &) + { + return 6; + } + break; + case 6: + { + std::exception_ptr b, d; + if (b != nullptr || d != nullptr) + return -1; + try + { + throw 1; + } + catch (int a) + { + if (a != 1) + return -1; + b = std::current_exception (); + if (b == nullptr) + return -1; + try + { + throw 2L; + } + catch (long int c) + { + if (c != 2L) + return -1; + d = std::current_exception (); + if (d == nullptr || b == d) + return -1; + } + if (std::current_exception () != b) + return -1; + } + if (std::current_exception () != nullptr) + return -1; + try + { + std::rethrow_exception (d); + } + catch (long int &e) + { + if (e != 2L) + return -1; + try + { + std::rethrow_exception (b); + } + catch (const int &f) + { + if (f != 1) + return -1; + try + { + std::rethrow_exception (d); + } + catch (const long int g) + { + if (g != 2L) + return -1; + try + { + std::rethrow_exception (b); + } + catch (int h) + { + if (h != 1) + return -1; + std::exception_ptr i (b); + std::exception_ptr j; + if (j != nullptr || i == nullptr || i != b || bool (j)) + return -1; + j = i; + if (j != b || !bool (j)) + return -1; + j = nullptr; + std::swap (i, j); + if (j == nullptr || j != b || i != nullptr) + return -1; + } + } + } + } + return 7; + } + case 7: + { + std::exception_ptr a = std::make_exception_ptr (42); + std::exception_ptr b = std::make_exception_ptr (std::exception ()); + std::exception_ptr c + = std::make_exception_ptr (std::bad_array_new_length ()); + try + { + std::rethrow_exception (a); + } + catch (int d) + { + if (d != 42) + return -1; + try + { + std::rethrow_exception (b); + } + catch (const std::exception &e) + { + const char *f = e.what (); + try + { + std::rethrow_exception (c); + } + catch (const std::bad_alloc &g) + { + try + { + throw; + } + catch (const std::bad_array_new_length &h) + { + const char *i = h.what (); + const char *j = g.what (); + } + } + } + } + return 8; + } + case 8: + { + std::nested_exception a; + if (a.nested_ptr () != nullptr) + return -1; + try + { + std::nested_exception b; + if (b.nested_ptr () != nullptr) + return -1; + throw 42; + } + catch (...) + { + std::nested_exception c; + if (c.nested_ptr () != std::current_exception ()) + return -1; + std::nested_exception d = c; + if (d.nested_ptr () != c.nested_ptr ()) + return -1; + c = d; + try + { + c.rethrow_nested (); + } + catch (const int &e) + { + if (e != 42) + return -1; + } + } + return 9; + } + case 9: + try + { + std::throw_with_nested (I ()); + } + catch (const std::nested_exception &a) + { + if (a.nested_ptr () != nullptr) + return -1; + try + { + throw; + } + catch (const I &) + { + return 10; + } + } + return -1; + case 10: + try + { + std::throw_with_nested (J ()); + } + catch (const std::nested_exception &a) + { + if (a.nested_ptr () != nullptr) + return -1; + try + { + throw; + } + catch (const J &) + { + return 11; + } + } + return -1; + case 11: + try + { + std::throw_with_nested (K ()); + } + catch (const std::nested_exception &) + { + return -1; + } + catch (const K &) + { + return 12; + } + return -1; + case 12: + try + { + throw 42; + } + catch (...) + { + I a; + try + { + std::rethrow_if_nested (a); + } + catch (const int &b) + { + if (b == 42) + return 13; + } + } + return -1; + case 13: + try + { + throw J (); + } + catch (const J &a) + { + std::rethrow_if_nested (a); + return 14; + } + return -1; + case 14: + try + { + throw 42; + } + catch (...) + { + try + { + throw L (); + } + catch (const J &a) + { + try + { + std::rethrow_if_nested (a); + } + catch (const int &b) + { + if (b == 42) + return 15; + } + } + } + return -1; + case 15: + { + std::rethrow_if_nested (1); + M m; + std::rethrow_if_nested (m); + N n; + std::rethrow_if_nested (n); + O o; + std::rethrow_if_nested (o); + return 16; + } + default: + break; + } + return -1; +} + +static_assert (foo (0) == 1); +static_assert (foo (1) == 2); +static_assert (foo (2) == 3); +static_assert (foo (3) == 4); +static_assert (foo (4) == 5); +static_assert (foo (5) == 6); +static_assert (foo (6) == 7); +static_assert (foo (7) == 8); +static_assert (foo (8) == 9); +static_assert (foo (9) == 10); +static_assert (foo (10) == 11); +static_assert (foo (11) == 12); +static_assert (foo (12) == 13); +static_assert (foo (13) == 14); +static_assert (foo (14) == 15); +static_assert (foo (15) == 16); +static_assert (std::uncaught_exceptions () == 0); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh4.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh4.C new file mode 100644 index 0000000..24118ca --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh4.C @@ -0,0 +1,72 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +struct A { virtual ~A () {} }; +struct B { virtual void b (); }; +struct C { virtual void c (); }; +struct D : private B { virtual void d (); }; +struct E { virtual void e (); }; +struct F : D, E, private C { virtual void f (); }; + +constexpr int +foo (int x) +{ + switch (x) + { + case 1: + try + { + static constexpr F f; + D &d = dynamic_cast<D &>((B &) f); // { dg-error "called without 'std::bad_cast' being defined" } + return -1; + } + catch (...) + { + return -1; + } + break; + case 3: + try + { + decltype (sizeof 0) x = -64; + char (*a)[2] = new char[x][2]; // { dg-error "called without 'std::bad_array_new_length' being defined" } + delete[] a; + } + catch (...) + { + return -1; + } + break; + case 4: + try + { + int y = -1; + int *a = new int[y]; // { dg-error "called without 'std::bad_array_new_length' being defined" } + delete[] a; + } + catch (...) + { + return -1; + } + break; + case 5: + try + { + int z = 1; + int *a = new int[z]{1, 2, 3}; // { dg-error "called without 'std::bad_array_new_length' being defined" } + delete[] a; + } + catch (...) + { + return -1; + } + break; + } + return -1; +} + +constexpr int a = foo (1); // { dg-message "in 'constexpr' expansion of" } +constexpr int b = foo (3); // { dg-message "in 'constexpr' expansion of" } +constexpr int c = foo (4); // { dg-message "in 'constexpr' expansion of" } +constexpr int d = foo (5); // { dg-message "in 'constexpr' expansion of" } diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh5.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh5.C new file mode 100644 index 0000000..512aa34 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh5.C @@ -0,0 +1,55 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +constexpr void +foo () +{ + throw 1; +} + +void +bar () +{ +} + +constexpr void +baz () +{ + foo (); + bar (); +} + +constexpr void +qux () +{ + if consteval { + throw 2; + } + bar (); +} + +constexpr bool +corge () +{ + try + { + baz (); + } + catch (int a) + { + if (a != 1) + return false; + try + { + qux (); + } + catch (int b) + { + return b == 2; + } + } + return false; +} + +static_assert (corge ()); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh6.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh6.C new file mode 100644 index 0000000..6fd9462 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh6.C @@ -0,0 +1,134 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +struct S { + constexpr S () : s (0) {} + constexpr S (int x) : s (x) {} + constexpr S (const S &x) : s (x.s) {} + constexpr ~S () {} + int s; +}; +struct T { + constexpr T () : t (0) {} + constexpr T (int x) : t (x) {} + constexpr T (const T &x) : t (x.t) {} + constexpr ~T () {} + int t; +}; +struct U : public S, public T { + constexpr U () : S (0), T (0) {} + constexpr U (int x, int y) : S (x), T (y) {} + constexpr U (const U &x) : S (x.s), T (x.t) {} + constexpr ~U () {} +}; + +constexpr bool +foo () +{ + try + { + throw U (1, 2); + } + catch (const U &x) + { + if (x.s != 1 || x.t != 2) + return false; + try + { + throw; + } + catch (const S &y) + { + if (y.s != 1) + return false; + try + { + throw; + } + catch (const T &z) + { + if (z.t != 2) + return false; + return true; + } + } + } + return false; +} + +constexpr bool +bar () +{ + try + { + throw U (1, 2); + } + catch (U &x) + { + if (x.s != 1 || x.t != 2) + return false; + try + { + x.s = 3; + x.t = 4; + throw; + } + catch (S &y) + { + if (y.s != 3) + return false; + try + { + throw; + } + catch (T &z) + { + if (z.t != 4) + return false; + return true; + } + } + } + return false; +} + +constexpr bool +baz () +{ + try + { + throw U (1, 2); + } + catch (U x) + { + if (x.s != 1 || x.t != 2) + return false; + try + { + x.s = 3; + x.t = 4; + throw; + } + catch (S y) + { + if (y.s != 1) + return false; + try + { + throw; + } + catch (T z) + { + if (z.t != 2) + return false; + return true; + } + } + } + return false; +} + +static_assert (foo ()); +static_assert (bar ()); +static_assert (baz ()); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh7.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh7.C new file mode 100644 index 0000000..6bdf0c3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh7.C @@ -0,0 +1,151 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +constexpr char p[] = "hello"; +constexpr const char *q[] = { &p[0], &p[3] }; +constexpr const char *const *r = &q[0]; +const char *s[] = { &p[0], &p[3] }; +constexpr const char **t = &s[0]; + +constexpr bool +foo () +{ + try + { + throw t; + } + catch (const char **const &x) + { + if (x != t) + return false; + try + { + throw; + } + catch (const char **&y) + { + if (y != t) + return false; + try + { + throw; + } + catch (const char **z) + { + if (z != t) + return false; + try + { + throw; + } + catch (const char *const *const &v) + { + if (v != (const char *const *) t) + return false; + try + { + throw; + } + catch (const char *const *w) + { + if (w != (const char *const *) t) + return false; + return true; + } + } + } + } + } + return false; +} + +constexpr bool +bar () +{ + try + { + throw nullptr; + } + catch (const char **const &x) + { + if (x != nullptr) + return false; + try + { + throw; + } + catch (const char **&y) + { + if (y != nullptr) + return false; + try + { + throw; + } + catch (const char **z) + { + if (z != nullptr) + return false; + try + { + throw; + } + catch (const char *const *const &v) + { + if (v != nullptr) + return false; + try + { + throw; + } + catch (const char *const *w) + { + if (w != nullptr) + return false; + return true; + } + } + } + } + } + return false; +} + +constexpr bool +baz () +{ + try + { + throw r; + } + catch (const char *const *const &x) + { + if (x != r || **x != 'h') + return false; + try + { + throw; + } + catch (const char *const *&y) + { + if (y != r || **y != 'h') + return false; + try + { + throw; + } + catch (const char *const *z) + { + if (z != r || **z != 'h') + return false; + return true; + } + } + } + return false; +} + +static_assert (foo ()); +static_assert (bar ()); +static_assert (baz ()); diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh8.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh8.C new file mode 100644 index 0000000..2560364 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh8.C @@ -0,0 +1,36 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +#include <exception> + +constexpr std::exception_ptr +foo () +{ + try + { + throw 42; + } + catch (...) + { + return std::current_exception (); + } +} + +constexpr bool +bar () +{ + try + { + std::rethrow_exception (foo ()); + } + catch (const int &a) + { + return a == 42; + } + return false; +} + +static_assert (bar ()); +constexpr std::exception_ptr a = foo (); // { dg-error "is not a constant expression because it refers to exception object allocated with '__cxa_allocate_exception'" } +constexpr std::exception_ptr b = std::make_exception_ptr (42ULL); // { dg-error "is not a constant expression because it refers to exception object allocated with '__cxa_allocate_exception'" } diff --git a/gcc/testsuite/g++.dg/cpp26/constexpr-eh9.C b/gcc/testsuite/g++.dg/cpp26/constexpr-eh9.C new file mode 100644 index 0000000..fd39fe0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/constexpr-eh9.C @@ -0,0 +1,127 @@ +// C++26 P3068R5 - Allowing exception throwing in constant-evaluation +// { dg-do compile { target c++26 } } +// { dg-require-effective-target exceptions_enabled } + +namespace std +{ + struct exception + { + constexpr exception () noexcept { } + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr exception (exception &&) = default; + constexpr exception &operator= (exception &&) = default; + constexpr virtual const char *what () const noexcept + { return "std::exception"; } + }; +} + +struct S : public std::exception { + constexpr S () : s (0) {} + constexpr S (int x) : s (x) {} + constexpr S (const S &x) : s (x.s) {} + constexpr virtual ~S () {} + constexpr virtual const char *what () noexcept { return "this is S"; } + int s; +}; +struct T : public std::exception { + constexpr T () : s (new char[1]), t (0) { s[0] = '\0'; } + constexpr T (const char *p, int q) : s (new char[q + 1]), t (q) + { + for (int i = 0; i <= t; ++i) + s[i] = p[i]; + } + constexpr T (const T &x) : s (new char[x.t + 1]), t (x.t) + { + for (int i = 0; i <= t; ++i) + s[i] = x.s[i]; + } + constexpr virtual ~T () { delete[] s; } + constexpr virtual const char *what () noexcept { return s; } + char *s; + int t; +}; +struct U { + constexpr U () : x (0), y (0), z (0) {} + constexpr U (int a, long b, unsigned long long c) : x (a), y (b), z (c) {} + constexpr U (const U &u) = default; + int x; + long y; + unsigned long long z; +}; +struct V { + constexpr V () : v (0) {} + constexpr V (int x) : v (x) {} + constexpr V (const V &x) : v (x.v) {} + constexpr virtual ~V () {} + constexpr virtual const char *what () noexcept { return "this is V"; } + int v; +}; + +constexpr int +foo (int x) +{ + if (x == 1) + throw S (42); + else if (x == 2) + throw T ("hello, world", sizeof ("hello, world") - 1); + else if (x == 3) + throw U (1, -2L, 42ULL); + else if (x == 4) + throw 42; + else if (x == 5) + throw 1.0; + else if (x == 6) + throw V (42); + else + return 42; +} + +constexpr int +bar (int x) noexcept +// { dg-error "'std::terminate' called after throwing an exception of type 'S'; 'what\\\(\\\)': 'this is S'" "" { target *-*-* } .-1 } +// { dg-message "uncaught exception exited from 'noexcept' function 'constexpr int bar\\\(int\\\)'" "" { target *-*-* } .-2 } +// { dg-error "'std::terminate' called after throwing an exception of type 'T'; 'what\\\(\\\)': 'hello, world'" "" { target *-*-* } .-3 } +// { dg-error "'std::terminate' called after throwing an exception 'U\\\{1, -2, 42\\\}'" "" { target *-*-* } .-4 } +// { dg-error "'std::terminate' called after throwing an exception '42'" "" { target *-*-* } .-5 } +// { dg-error "'std::terminate' called after throwing an exception '1\\\.0e\\\+0'" "" { target *-*-* } .-6 } +// { dg-error "'std::terminate' called after throwing an exception 'V\\\{\[^\n\r]*42\\\}" "" { target *-*-* } .-7 } +{ + return foo (x); +} + +constexpr int +baz (int x) +{ + try + { + return foo (x); + } + catch (...) + { + return -1; + } +} + +static_assert (bar (0) == 42); +constexpr int a = bar (1); // { dg-message "in 'constexpr' expansion of" } +constexpr int b = bar (2); // { dg-message "in 'constexpr' expansion of" } +constexpr int c = bar (3); // { dg-message "in 'constexpr' expansion of" } +constexpr int d = bar (4); // { dg-message "in 'constexpr' expansion of" } +constexpr int e = bar (5); // { dg-message "in 'constexpr' expansion of" } +constexpr int f = bar (6); // { dg-message "in 'constexpr' expansion of" } +static_assert (baz (0) == 42); +static_assert (baz (1) == -1); +static_assert (baz (2) == -1); +static_assert (baz (3) == -1); +static_assert (baz (4) == -1); +static_assert (baz (5) == -1); +static_assert (baz (6) == -1); +static_assert (foo (0) == 42); +constexpr int g = foo (1); // { dg-error "uncaught exception of type 'S'; 'what\\\(\\\)': 'this is S'" } +constexpr int h = foo (2); // { dg-error "uncaught exception of type 'T'; 'what\\\(\\\)': 'hello, world'" } +constexpr int i = foo (3); // { dg-error "uncaught exception 'U\\\{1, -2, 42\\\}'" } +constexpr int j = foo (4); // { dg-error "uncaught exception '42'" } +constexpr int k = foo (5); // { dg-error "uncaught exception '1\\\.0e\\\+0'" } +constexpr int l = foo (6); // { dg-error "uncaught exception 'V\\\{\[^\n\r]*42\\\}'" } diff --git a/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C b/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C index e4ffc35..cfc5f61 100644 --- a/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C +++ b/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C @@ -624,19 +624,31 @@ #endif #ifndef __cpp_pack_indexing -# error "__cpp_pack_indexing" +# error "__cpp_pack_indexing" #elif __cpp_pack_indexing != 202311 # error "__cpp_pack_indexing != 202311" #endif #ifndef __cpp_pp_embed -# error "__cpp_pp_embed" +# error "__cpp_pp_embed" #elif __cpp_pp_embed != 202502 # error "__cpp_pp_embed != 202502" #endif #ifndef __cpp_constexpr_virtual_inheritance -# error "__cpp_constexpr_virtual_inheritance" +# error "__cpp_constexpr_virtual_inheritance" #elif __cpp_constexpr_virtual_inheritance != 202506 # error "__cpp_constexpr_virtual_inheritance != 202506" #endif + +#ifndef __cpp_constexpr_exceptions +# error "__cpp_constexpr_exceptions" +#elif __cpp_constexpr_exceptions != 202411 +# error "__cpp_constexpr_exceptions != 202411" +#endif + +#ifndef __cpp_trivial_relocatability +# error "__cpp_trivial_relocatability" +#elif __cpp_trivial_relocatability != 202502 +# error "__cpp_trivial_relocatability != 202502" +#endif diff --git a/gcc/testsuite/g++.dg/cpp26/static_assert1.C b/gcc/testsuite/g++.dg/cpp26/static_assert1.C index 1d0e6f2..a6eab3c 100644 --- a/gcc/testsuite/g++.dg/cpp26/static_assert1.C +++ b/gcc/testsuite/g++.dg/cpp26/static_assert1.C @@ -51,7 +51,7 @@ static_assert (true, H {}); // { dg-warning "'static_assert' with non-string mes struct I { constexpr signed char size () const { return 0; } const char *data () const { return ""; } }; static_assert (true, I {}); // { dg-warning "'static_assert' with non-string message only available with" "" { target c++23_down } } -struct J { constexpr int size () const { return j ? throw 1 : 0; } // { dg-error "expression '<throw-expression>' is not a constant expression" } +struct J { constexpr int size () const { return j ? throw 1 : 0; } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23_down } } constexpr const char *data () const { return ""; }; constexpr J (int x) : j (x) {} int j; }; @@ -60,6 +60,7 @@ static_assert (false, J (0)); // { dg-warning "'static_assert' with non-string m // { dg-error "static assertion failed" "" { target *-*-* } .-1 } static_assert (false, J (1)); // { dg-warning "'static_assert' with non-string message only available with" "" { target c++23_down } } // { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" "" { target *-*-* } .-1 } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-2 } struct K { constexpr operator int () { return 4; } }; struct L { constexpr operator const char * () { return "test"; } }; struct M { constexpr K size () const { return {}; } @@ -261,10 +262,11 @@ namespace NN #if __cplusplus >= 201402L struct J { static constexpr int size () { return 0; } - static constexpr const char *data (int x = 0) { if (x) return nullptr; else throw 1; } }; // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++14 } } + static constexpr const char *data (int x = 0) { if (x) return nullptr; else throw 1; } }; // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target { c++14 && c++23_down } } } static_assert (true, J{}); // { dg-warning "'static_assert' with non-string message only available with" "" { target { c++14 && c++23_down } } } static_assert (false, J{}); // { dg-warning "'static_assert' with non-string message only available with" "" { target { c++14 && c++23_down } } } // { dg-error "constexpr string 'data\\\(\\\)' must be a core constant expression" "" { target c++14 } .-1 } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-2 } #endif #if __cpp_if_consteval >= 202106L struct K { @@ -282,19 +284,21 @@ namespace NN static_assert (false, L{}); // { dg-warning "'static_assert' with non-string message only available with" "" { target c++23_only } } // { dg-error "static assertion failed: test" "" { target c++23 } .-1 } struct M { - static constexpr int size () { if consteval { throw 1; } else { return 4; } } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23 } } + static constexpr int size () { if consteval { throw 1; } else { return 4; } } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23_only } } static constexpr const char *data () { return "test"; } }; static_assert (true, M{}); // { dg-warning "'static_assert' with non-string message only available with" "" { target c++23_only } } static_assert (false, M{}); // { dg-warning "'static_assert' with non-string message only available with" "" { target c++23_only } } // { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" "" { target c++23 } .-1 } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-2 } struct N { static constexpr int size () { return 4; } - static constexpr const char *data () { if consteval { throw 1; } else { return "test"; } } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23 } } + static constexpr const char *data () { if consteval { throw 1; } else { return "test"; } } // { dg-error "expression '<throw-expression>' is not a constant expression" "" { target c++23_only } } }; static_assert (true, N{}); // { dg-warning "'static_assert' with non-string message only available with" "" { target c++23_only } } static_assert (false, N{}); // { dg-warning "'static_assert' with non-string message only available with" "" { target c++23_only } } // { dg-error "constexpr string 'data\\\(\\\)\\\[0\\\]' must be a constant expression" "" { target c++23 } .-1 } + // { dg-error "uncaught exception '1'" "" { target c++26 } .-2 } #endif struct O { constexpr int operator () () const { return 12; } }; struct P { constexpr const char *operator () () const { return "another test"; } }; diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable1.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable1.C new file mode 100644 index 0000000..29ba907 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable1.C @@ -0,0 +1,137 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++17 } } + +#if __cpp_trivial_relocatability < 202502L +#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible +#define replaceable_if_eligible __replaceable_if_eligible +#endif + +namespace std +{ +template <typename T, T v> +struct integral_constant +{ + static constexpr T value = v; +}; + +template <typename> +struct is_trivially_relocatable; + +template <typename> +struct is_replaceable; + +template<typename T> +struct is_trivially_relocatable + : public integral_constant <bool, __builtin_is_trivially_relocatable (T)> +{ +}; + +template<typename T> +struct is_replaceable + : public integral_constant <bool, __builtin_is_replaceable (T)> +{ +}; + +template <typename T> +inline constexpr bool is_trivially_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_trivially_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_replaceable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_replaceable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +} + +struct A {}; + +static_assert (std::is_trivially_relocatable_v <A>, ""); +static_assert (std::is_replaceable_v <A>, ""); + +struct B { + B (); + ~B (); + B (const B &); + B (B &&); + B &operator= (const B &); + B &operator= (B &&); +}; + +static_assert (!std::is_trivially_relocatable_v <B>, ""); +static_assert (!std::is_replaceable_v <B>, ""); + +struct C { + C (C &&) = delete; + C &operator= (C &&) = delete; + C () = default; +}; + +// Note, P2786R13 says it is trivially relocatable, but I think +// it isn't default-movable because overload resolution in both +// cases selects a deleted special member fn. +static_assert (!std::is_trivially_relocatable_v <C>, ""); +static_assert (!std::is_replaceable_v <C>, ""); + +struct D : A {}; + +static_assert (std::is_trivially_relocatable_v <D>, ""); +static_assert (std::is_replaceable_v <D>, ""); + +struct E : virtual A {}; + +static_assert (!std::is_trivially_relocatable_v <E>, ""); +static_assert (std::is_replaceable_v <E>, ""); + +struct F trivially_relocatable_if_eligible : virtual A {}; + +static_assert (!std::is_trivially_relocatable_v <F>, ""); +static_assert (std::is_replaceable_v <F>, ""); + +struct G { B data; }; + +static_assert (!std::is_trivially_relocatable_v <G>, ""); +static_assert (!std::is_replaceable_v <G>, ""); + +struct H { ~H () = default; }; + +static_assert (std::is_trivially_relocatable_v <H>, ""); +static_assert (std::is_replaceable_v <H>, ""); + +struct I { ~I (); }; +I::~I () = default; + +static_assert (!std::is_trivially_relocatable_v <I>, ""); +static_assert (!std::is_replaceable_v <I>, ""); + +struct J { virtual ~J () = default; }; + +// Note, P2786R13 says otherwise for both, but that looks like +// a bug in the paper, it otherwise says that polymorphic types +// can be both trivially relocatable and replaceable. +static_assert (std::is_trivially_relocatable_v <J>, ""); +static_assert (std::is_replaceable_v <J>, ""); + +struct K { ~K () = delete; }; + +static_assert (!std::is_trivially_relocatable_v <K>, ""); +static_assert (!std::is_replaceable_v <K>, ""); + +struct L { L (L &&) = default; }; + +// Note, P2786R13 says otherwise for both, but that looks like +// a bug in the paper to me. While move ctor is trivial here, +// copy assignment operator is implicitly declared as deleted +// and move assignent operator is not declared. +static_assert (!std::is_trivially_relocatable_v <L>, ""); +static_assert (!std::is_replaceable_v <L>, ""); + +struct M { M (M &&); }; +M::M (M &&) = default; + +static_assert (!std::is_trivially_relocatable_v <M>, ""); +static_assert (!std::is_replaceable_v <M>, ""); + +struct N { N (N &&) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <N>, ""); +static_assert (!std::is_replaceable_v <N>, ""); diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable10.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable10.C new file mode 100644 index 0000000..2ed1d5e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable10.C @@ -0,0 +1,135 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++17 } } + +#if __cpp_trivial_relocatability < 202502L +#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible +#define replaceable_if_eligible __replaceable_if_eligible +#endif + +namespace std +{ +template <typename T, T v> +struct integral_constant +{ + static constexpr T value = v; +}; + +template <typename> +struct is_trivially_relocatable; + +template <typename> +struct is_replaceable; + +template<typename T> +struct is_trivially_relocatable + : public integral_constant <bool, __builtin_is_trivially_relocatable (T)> +{ +}; + +template<typename T> +struct is_replaceable + : public integral_constant <bool, __builtin_is_replaceable (T)> +{ +}; + +template <typename T> +inline constexpr bool is_trivially_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_trivially_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_replaceable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_replaceable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +} + +struct A replaceable_if_eligible { A (A &&); A &operator= (A &&); ~A (); int a; }; + +static_assert (std::is_replaceable_v <A>, ""); +static_assert (!std::is_replaceable_v <const A>, ""); +static_assert (!std::is_replaceable_v <A volatile>, ""); +static_assert (!std::is_replaceable_v <const A volatile>, ""); + +struct B { B (B &&); B &operator= (B &&); ~B (); int a; }; + +static_assert (!std::is_replaceable_v <B>, ""); + +struct C replaceable_if_eligible : public A { C (C &&); C &operator= (C &&); ~C (); int a; }; + +static_assert (std::is_replaceable_v <C>, ""); + +struct D replaceable_if_eligible : public B { D (D &&); D &operator= (D &&); ~D (); int a; }; + +static_assert (!std::is_replaceable_v <D>, ""); + +struct E replaceable_if_eligible { E (E &&); E &operator= (E &&); ~E (); A a; }; + +static_assert (std::is_replaceable_v <E>, ""); + +struct F replaceable_if_eligible { F (F &&); F &operator= (F &&); ~F (); B a; }; + +static_assert (!std::is_replaceable_v <F>, ""); + +struct G replaceable_if_eligible { G (G &&); G &operator= (G &&); ~G () = delete; int a; }; + +static_assert (!std::is_replaceable_v <G>, ""); + +struct H replaceable_if_eligible : virtual A { H (H &&); H &operator= (H &&); ~H (); int a; }; + +static_assert (std::is_replaceable_v <H>, ""); + +struct I replaceable_if_eligible { I (I &&) = delete; I &operator= (I &&); ~I (); int a; }; + +static_assert (!std::is_replaceable_v <I>, ""); + +struct J replaceable_if_eligible { J (J &&); J &operator= (J &&) = delete; ~J (); int a; }; + +static_assert (!std::is_replaceable_v <J>, ""); + +struct K replaceable_if_eligible { K (const K &) = delete; K &operator= (K &&); ~K (); int a; }; + +static_assert (!std::is_replaceable_v <K>, ""); + +struct L replaceable_if_eligible { L (L &&); L &operator= (const L &) = delete; ~L (); int a; }; + +static_assert (!std::is_replaceable_v <L>, ""); + +struct M replaceable_if_eligible { M (); private: M (M &&); M &operator= (M &&); ~M (); int a; }; + +static_assert (std::is_replaceable_v <M>, ""); + +struct N replaceable_if_eligible { N (N &&); N &operator= (N &&); ~N (); const A a; }; + +static_assert (!std::is_replaceable_v <N>, ""); + +struct O replaceable_if_eligible { O (O &&); O &operator= (O &&); ~O (); volatile A a; }; + +static_assert (!std::is_replaceable_v <O>, ""); + +struct P replaceable_if_eligible { P (P &&); P &operator= (P &&); ~P (); const volatile A a; }; + +static_assert (!std::is_replaceable_v <P>, ""); + +struct Q replaceable_if_eligible { Q (Q &&); Q &operator= (Q &&); ~Q (); union { A a; int b; char c; }; }; + +static_assert (!std::is_replaceable_v <Q>, ""); + +struct R replaceable_if_eligible { R (R &&); R &operator= (R &&); ~R (); union { int a; B b; short c; }; }; + +static_assert (!std::is_replaceable_v <R>, ""); + +struct S replaceable_if_eligible { S (S &&); S &operator= (S &&); ~S (); union { int a; const int b; short c; }; }; + +static_assert (!std::is_replaceable_v <S>, ""); + +struct T replaceable_if_eligible { T (T &&); T &operator= (T &&); ~T () = default; int a; }; + +static_assert (std::is_replaceable_v <T>, ""); + +struct U replaceable_if_eligible { U (U &&); U &operator= (U &&); ~U (); union { T a; int b; char c; }; }; + +static_assert (!std::is_replaceable_v <U>, ""); + +struct V replaceable_if_eligible { V (V &&); V &operator= (V &&); ~V (); union { unsigned long long a; int b; char c; }; }; + +static_assert (std::is_replaceable_v <V>, ""); diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable11.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable11.C new file mode 100644 index 0000000..71fc6f1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable11.C @@ -0,0 +1,134 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++17 } } + +#if __cpp_trivial_relocatability < 202502L +#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible +#define replaceable_if_eligible __replaceable_if_eligible +#endif + +namespace std +{ +template <typename T, T v> +struct integral_constant +{ + static constexpr T value = v; +}; + +template <typename> +struct is_trivially_relocatable; + +template <typename> +struct is_replaceable; + +template<typename T> +struct is_trivially_relocatable + : public integral_constant <bool, __builtin_is_trivially_relocatable (T)> +{ +}; + +template<typename T> +struct is_replaceable + : public integral_constant <bool, __builtin_is_replaceable (T)> +{ +}; + +template <typename T> +inline constexpr bool is_trivially_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_trivially_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_replaceable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_replaceable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +} + +struct A { A (A &&) = default; A &operator= (A &&) = default; ~A () = default; int a; }; + +static_assert (std::is_trivially_relocatable_v <A>, ""); +static_assert (std::is_replaceable_v <A>, ""); + +struct B { B (B &&); B &operator= (B &&) = default; ~B () = default; int a; }; + +static_assert (!std::is_trivially_relocatable_v <B>, ""); +static_assert (!std::is_replaceable_v <B>, ""); + +union C { int a; A b; }; + +static_assert (std::is_trivially_relocatable_v <C>, ""); +static_assert (std::is_replaceable_v <C>, ""); + +union D { int a; A b; B c; }; + +static_assert (!std::is_trivially_relocatable_v <D>, ""); +static_assert (!std::is_replaceable_v <D>, ""); + +union E { E (); int a; A b; }; + +static_assert (std::is_trivially_relocatable_v <E>, ""); +static_assert (std::is_replaceable_v <E>, ""); + +union F { F () = default; int a; A b; }; + +static_assert (std::is_trivially_relocatable_v <F>, ""); +static_assert (std::is_replaceable_v <F>, ""); + +union G { G (const G &); int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <G>, ""); +static_assert (!std::is_replaceable_v <G>, ""); + +union H { H (const H &) = default; int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <H>, ""); +static_assert (!std::is_replaceable_v <H>, ""); + +union I { I (I &&); int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <I>, ""); +static_assert (!std::is_replaceable_v <I>, ""); + +union J { J (J &&) = default; int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <J>, ""); +static_assert (!std::is_replaceable_v <J>, ""); + +union K { K &operator= (const K &); int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <K>, ""); +static_assert (!std::is_replaceable_v <K>, ""); + +union L { L &operator= (const L &) = default; int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <L>, ""); +static_assert (!std::is_replaceable_v <L>, ""); + +union M { M &operator= (M &&); int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <M>, ""); +static_assert (!std::is_replaceable_v <M>, ""); + +union N { N &operator= (N &&) = default; int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <N>, ""); +static_assert (!std::is_replaceable_v <N>, ""); + +union O { ~O (); int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <O>, ""); +static_assert (!std::is_replaceable_v <O>, ""); + +union P { ~P () = default; int a; A b; }; + +static_assert (!std::is_trivially_relocatable_v <P>, ""); +static_assert (!std::is_replaceable_v <P>, ""); + +union Q { int a; const A b; }; + +static_assert (std::is_trivially_relocatable_v <Q>, ""); +static_assert (!std::is_replaceable_v <Q>, ""); + +union S { volatile int a; A b; }; + +static_assert (std::is_trivially_relocatable_v <S>, ""); +static_assert (!std::is_replaceable_v <S>, ""); diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable2.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable2.C new file mode 100644 index 0000000..b740061 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable2.C @@ -0,0 +1,204 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++17 } } + +#if __cpp_trivial_relocatability < 202502L +#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible +#define replaceable_if_eligible __replaceable_if_eligible +#endif + +namespace std +{ +template <typename T, T v> +struct integral_constant +{ + static constexpr T value = v; +}; + +template <typename> +struct is_trivially_relocatable; + +template <typename> +struct is_replaceable; + +template<typename T> +struct is_trivially_relocatable + : public integral_constant <bool, __builtin_is_trivially_relocatable (T)> +{ +}; + +template<typename T> +struct is_replaceable + : public integral_constant <bool, __builtin_is_replaceable (T)> +{ +}; + +template <typename T> +inline constexpr bool is_trivially_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_trivially_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_replaceable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_replaceable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +} + +class A {}; + +static_assert (std::is_trivially_relocatable_v <A>, ""); +static_assert (std::is_replaceable_v <A>, ""); +static_assert (std::is_trivially_relocatable <A>::value, ""); +static_assert (std::is_replaceable <A>::value, ""); + +struct B { ~B (); }; +static B z; + +static_assert (!std::is_trivially_relocatable_v <B>, ""); +static_assert (!std::is_replaceable_v <B>, ""); +static_assert (!std::is_trivially_relocatable <B>::value, ""); +static_assert (!std::is_replaceable <B>::value, ""); + +class C trivially_relocatable_if_eligible {}; + +static_assert (std::is_trivially_relocatable_v <C>, ""); +static_assert (std::is_replaceable_v <C>, ""); + +class D trivially_relocatable_if_eligible : A {}; + +static_assert (std::is_trivially_relocatable_v <D>, ""); +static_assert (std::is_replaceable_v <D>, ""); + +class E trivially_relocatable_if_eligible { + int a; + void *b; + int c[3]; + A d[3]; + B &e = z; +}; + +static_assert (std::is_trivially_relocatable_v <E>, ""); +static_assert (!std::is_replaceable_v <E>, ""); + +class F trivially_relocatable_if_eligible : A {}; + +static_assert (std::is_trivially_relocatable_v <F>, ""); +static_assert (std::is_replaceable_v <F>, ""); + +class G trivially_relocatable_if_eligible : virtual A {}; + +static_assert (!std::is_trivially_relocatable_v <G>, ""); +static_assert (std::is_replaceable_v <G>, ""); + +class H trivially_relocatable_if_eligible : B {}; + +static_assert (!std::is_trivially_relocatable_v <H>, ""); +static_assert (!std::is_replaceable_v <H>, ""); + +class I trivially_relocatable_if_eligible { I (I &&); }; + +static_assert (std::is_trivially_relocatable_v <I>, ""); +static_assert (!std::is_replaceable_v <I>, ""); + +class J trivially_relocatable_if_eligible { ~J (); }; + +static_assert (std::is_trivially_relocatable_v <J>, ""); +static_assert (!std::is_replaceable_v <J>, ""); + +class K trivially_relocatable_if_eligible { + B a; + B b[1]; + const B c; + const B d[1]; +}; + +static_assert (!std::is_trivially_relocatable_v <K>, ""); +static_assert (!std::is_replaceable_v <K>, ""); + +class L trivially_relocatable_if_eligible: virtual A, B { B a; }; + +static_assert (!std::is_trivially_relocatable_v <L>, ""); +static_assert (!std::is_replaceable_v <L>, ""); + +static_assert (!std::is_trivially_relocatable_v <void>, ""); +static_assert (!std::is_trivially_relocatable_v <const void>, ""); +static_assert (std::is_trivially_relocatable_v <int>, ""); +static_assert (std::is_trivially_relocatable_v <const int>, ""); +static_assert (std::is_trivially_relocatable_v <char>, ""); +static_assert (std::is_trivially_relocatable_v <char const volatile>, ""); +static_assert (std::is_trivially_relocatable_v <unsigned long long>, ""); +static_assert (std::is_trivially_relocatable_v <void *>, ""); +static_assert (std::is_trivially_relocatable_v <const int *>, ""); +static_assert (!std::is_trivially_relocatable_v <int &>, ""); +static_assert (!std::is_trivially_relocatable_v <A &>, ""); +static_assert (std::is_trivially_relocatable_v <const A>, ""); +static_assert (std::is_trivially_relocatable_v <A [1]>, ""); +static_assert (std::is_trivially_relocatable_v <A []>, ""); +static_assert (!std::is_replaceable_v <void>, ""); +static_assert (!std::is_replaceable_v <const void>, ""); +static_assert (std::is_replaceable_v <int>, ""); +static_assert (!std::is_replaceable_v <const int>, ""); +static_assert (std::is_replaceable_v <char>, ""); +static_assert (!std::is_replaceable_v <char const volatile>, ""); +static_assert (std::is_replaceable_v <unsigned long long>, ""); +static_assert (std::is_replaceable_v <void *>, ""); +static_assert (std::is_replaceable_v <const int *>, ""); +static_assert (!std::is_replaceable_v <int &>, ""); +static_assert (!std::is_replaceable_v <A &>, ""); +static_assert (!std::is_replaceable_v <const A>, ""); +static_assert (std::is_replaceable_v <A [1]>, ""); +static_assert (std::is_replaceable_v <A []>, ""); + +struct M { const int i; }; + +static_assert (!std::is_trivially_relocatable_v <M>, ""); +static_assert (!std::is_replaceable_v <M>, ""); + +struct N trivially_relocatable_if_eligible { const int i; }; + +static_assert (std::is_trivially_relocatable_v <N>, ""); +static_assert (!std::is_replaceable_v <N>, ""); + +struct O { ~O (); }; + +static_assert (!std::is_trivially_relocatable_v <O>, ""); +static_assert (!std::is_replaceable_v <O>, ""); + +struct P { ~P () = default; }; + +static_assert (std::is_trivially_relocatable_v <P>, ""); +static_assert (std::is_replaceable_v <P>, ""); + +struct Q { Q (Q &&); Q (const Q &) = default; }; + +static_assert (!std::is_trivially_relocatable_v <Q>, ""); +static_assert (!std::is_replaceable_v <Q>, ""); + +struct R { R (R &&); }; + +static_assert (!std::is_trivially_relocatable_v <R>, ""); +static_assert (!std::is_replaceable_v <R>, ""); + +struct S { S (S &&) = default; }; + +static_assert (!std::is_trivially_relocatable_v <S>, ""); +static_assert (!std::is_replaceable_v <S>, ""); + +struct T { T (T &&) = default; T &operator= (T &&) = default; }; + +static_assert (std::is_trivially_relocatable_v <T>, ""); +static_assert (std::is_replaceable_v <T>, ""); + +struct U { U (const U &); }; + +static_assert (!std::is_trivially_relocatable_v <U>, ""); +static_assert (!std::is_replaceable_v <U>, ""); + +struct V { V (const V&) = default; }; + +static_assert (std::is_trivially_relocatable_v <V>, ""); +static_assert (std::is_replaceable_v <V>, ""); + +struct W { W (W &&) = delete; W (const W &) = default; }; + +static_assert (!std::is_trivially_relocatable_v <W>, ""); +static_assert (!std::is_replaceable_v <W>, ""); diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable3.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable3.C new file mode 100644 index 0000000..312c11b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable3.C @@ -0,0 +1,213 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++17 } } + +#if __cpp_trivial_relocatability < 202502L +#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible +#define replaceable_if_eligible __replaceable_if_eligible +#endif + +namespace std +{ +template <typename T, T v> +struct integral_constant +{ + static constexpr T value = v; +}; + +template <typename> +struct is_trivially_relocatable; + +template <typename> +struct is_replaceable; + +template<typename T> +struct is_trivially_relocatable + : public integral_constant <bool, __builtin_is_trivially_relocatable (T)> +{ +}; + +template<typename T> +struct is_replaceable + : public integral_constant <bool, __builtin_is_replaceable (T)> +{ +}; + +template <typename T> +inline constexpr bool is_trivially_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_trivially_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_replaceable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_replaceable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +} + +class A {}; + +struct B { ~B (); }; + +class C trivially_relocatable_if_eligible { C (C &&); }; + +template <typename T> +class D trivially_relocatable_if_eligible : T {}; +D<A> a; +D<B> b; + +static_assert (std::is_trivially_relocatable_v <D<A>>, ""); +static_assert (!std::is_trivially_relocatable_v <D<B>>, ""); +static_assert (std::is_replaceable_v <D<A>>, ""); +static_assert (!std::is_replaceable_v <D<B>>, ""); + +struct E { E (E &&) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <E>, ""); +static_assert (!std::is_replaceable_v <E>, ""); + +struct F { F (const F &) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <F>, ""); +static_assert (!std::is_replaceable_v <F>, ""); + +struct G { G &operator= (G &&) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <G>, ""); +static_assert (!std::is_replaceable_v <G>, ""); + +struct H { ~H () = delete; }; + +static_assert (!std::is_trivially_relocatable_v <H>, ""); +static_assert (!std::is_replaceable_v <H>, ""); + +union U { C u; }; + +static_assert (std::is_trivially_relocatable_v <U>, ""); +static_assert (!std::is_replaceable_v <U>, ""); + +template <typename T> +struct I { int s; T t; }; + +static_assert (std::is_trivially_relocatable_v <I<int>>, ""); +static_assert (std::is_trivially_relocatable_v <I<volatile int>>, ""); +static_assert (!std::is_trivially_relocatable_v <I<const int>>, ""); +static_assert (!std::is_trivially_relocatable_v <I<const int &>>, ""); +static_assert (!std::is_trivially_relocatable_v <I<int &>>, ""); +static_assert (std::is_trivially_relocatable_v <I<int [2]>>, ""); +static_assert (!std::is_trivially_relocatable_v <I<const int [2]>>, ""); +static_assert (std::is_trivially_relocatable_v <I<int []>>, ""); +static_assert (std::is_replaceable_v <I<int>>, ""); +static_assert (!std::is_replaceable_v <I<volatile int>>, ""); +static_assert (!std::is_replaceable_v <I<const int>>, ""); +static_assert (!std::is_replaceable_v <I<const int &>>, ""); +static_assert (!std::is_replaceable_v <I<int &>>, ""); +static_assert (std::is_replaceable_v <I<int [2]>>, ""); +static_assert (!std::is_replaceable_v <I<const int [2]>>, ""); + +template <typename T> +struct J trivially_relocatable_if_eligible { int s; T t; }; + +static_assert (std::is_trivially_relocatable_v <J<int>>, ""); +static_assert (std::is_trivially_relocatable_v <J<volatile int>>, ""); +static_assert (std::is_trivially_relocatable_v <J<const int>>, ""); +static_assert (std::is_trivially_relocatable_v <J<const int &>>, ""); +static_assert (std::is_trivially_relocatable_v <J<int &>>, ""); +static_assert (std::is_trivially_relocatable_v <J<int [2]>>, ""); +static_assert (std::is_trivially_relocatable_v <J<const int [2]>>, ""); +static_assert (std::is_trivially_relocatable_v <J<int []>>, ""); +static_assert (std::is_replaceable_v <J<int>>, ""); +static_assert (!std::is_replaceable_v <J<volatile int>>, ""); +static_assert (!std::is_replaceable_v <J<const int>>, ""); +static_assert (!std::is_replaceable_v <J<const int &>>, ""); +static_assert (!std::is_replaceable_v <J<int &>>, ""); +static_assert (std::is_replaceable_v <J<int [2]>>, ""); +static_assert (!std::is_replaceable_v <J<const int [2]>>, ""); +static_assert (std::is_replaceable_v <J<int []>>, ""); + +struct K { K (K &&) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <K>, ""); +static_assert (!std::is_replaceable_v <K>, ""); + +struct L { L (const L &) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <L>, ""); +static_assert (!std::is_replaceable_v <L>, ""); + +struct M { M &operator= (M &&) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <M>, ""); +static_assert (!std::is_replaceable_v <M>, ""); + +struct N { N (N &&) = default; N &operator= (N &&) = default; }; + +static_assert (std::is_trivially_relocatable_v <N>, ""); +static_assert (std::is_replaceable_v <N>, ""); + +struct O { + O (const O &) = default; + O (O &&) = default; + O &operator= (O &&) = default; +}; + +static_assert (std::is_trivially_relocatable_v <O>, ""); +static_assert (std::is_replaceable_v <O>, ""); + +struct P { P (P &&) = default; P &operator= (P &&) = default; }; + +static_assert (std::is_trivially_relocatable_v <P>, ""); +static_assert (std::is_replaceable_v <P>, ""); + +struct Q { Q (Q &&) {} }; + +static_assert (!std::is_trivially_relocatable_v <Q>, ""); +static_assert (!std::is_replaceable_v <Q>, ""); + +struct R { R (const R &) {} }; + +static_assert (!std::is_trivially_relocatable_v <R>, ""); +static_assert (!std::is_replaceable_v <R>, ""); + +struct S { S &operator= (const S &) { return *this; }; }; + +static_assert (!std::is_trivially_relocatable_v <S>, ""); +static_assert (!std::is_replaceable_v <S>, ""); + +struct T {}; + +static_assert (std::is_trivially_relocatable_v <T>, ""); +static_assert (std::is_replaceable_v <T>, ""); + +struct V replaceable_if_eligible {}; + +static_assert (std::is_trivially_relocatable_v <V>, ""); +static_assert (std::is_replaceable_v <V>, ""); + +struct W { template <typename U> W (const U &) = delete; }; + +static_assert (std::is_trivially_relocatable_v <W>, ""); +static_assert (std::is_replaceable_v <W>, ""); + +template <typename T> +struct X : T {}; + +static_assert (!std::is_trivially_relocatable_v <X<Q>>, ""); +static_assert (!std::is_replaceable_v <X<Q>>, ""); + +template <typename T> +struct Y : virtual T {}; + +static_assert (!std::is_trivially_relocatable_v <Y<I<int>>>, ""); +static_assert (!std::is_trivially_relocatable_v <Y<I<const int>>>, ""); +static_assert (!std::is_trivially_relocatable_v <Y<Q>>, ""); +static_assert (std::is_replaceable_v <Y<I<int>>>, ""); +static_assert (!std::is_replaceable_v <Y<I<const int>>>, ""); +static_assert (!std::is_replaceable_v <Y<Q>>, ""); + +struct Z { + virtual ~Z () = default; + Z (Z &&) = default; + Z &operator= (Z &&) = default; +}; + +static_assert (std::is_trivially_relocatable_v <Z>, ""); +static_assert (std::is_replaceable_v <Z>, ""); diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable4.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable4.C new file mode 100644 index 0000000..10aafc1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable4.C @@ -0,0 +1,128 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++17 } } + +#if __cpp_trivial_relocatability < 202502L +#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible +#define replaceable_if_eligible __replaceable_if_eligible +#endif + +namespace std +{ +template <typename T, T v> +struct integral_constant +{ + static constexpr T value = v; +}; + +template <typename> +struct is_trivially_relocatable; + +template <typename> +struct is_replaceable; + +template<typename T> +struct is_trivially_relocatable + : public integral_constant <bool, __builtin_is_trivially_relocatable (T)> +{ +}; + +template<typename T> +struct is_replaceable + : public integral_constant <bool, __builtin_is_replaceable (T)> +{ +}; + +template <typename T> +inline constexpr bool is_trivially_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_trivially_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_replaceable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_replaceable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +} + +struct A replaceable_if_eligible { + ~A () = delete; + A (A &&) = default; + A &operator= (A &&) = default; +}; + +static_assert (!std::is_trivially_relocatable_v <A>, ""); +static_assert (!std::is_replaceable_v <A>, ""); + +struct B replaceable_if_eligible { B (const B &) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <B>, ""); +static_assert (!std::is_replaceable_v <B>, ""); + +template <typename T> +struct C replaceable_if_eligible : virtual T {}; + +static_assert (!std::is_trivially_relocatable_v <C<A>>, ""); +static_assert (!std::is_trivially_relocatable_v <C<B>>, ""); +static_assert (!std::is_replaceable_v <C<A>>, ""); +static_assert (!std::is_replaceable_v <C<B>>, ""); + +template <typename T> +struct D { int s; T t; }; + +static_assert (!std::is_trivially_relocatable_v <C<D<int>>>, ""); +static_assert (std::is_replaceable_v <C<D<int>>>, ""); + +struct E trivially_relocatable_if_eligible replaceable_if_eligible { + E (E &&); + E &operator= (E &&) = default; +}; + +static_assert (std::is_trivially_relocatable_v <E>, ""); +static_assert (std::is_replaceable_v <E>, ""); + +struct F trivially_relocatable_if_eligible replaceable_if_eligible { + F (F &&) = default; + F &operator= (F &&); +}; + +static_assert (std::is_trivially_relocatable_v <F>, ""); +static_assert (std::is_replaceable_v <F>, ""); + +struct G replaceable_if_eligible { G (G const &) = default; }; + +static_assert (std::is_trivially_relocatable_v <G>, ""); +static_assert (std::is_replaceable_v <G>, ""); + +struct H { H (H const &) = default; }; + +static_assert (std::is_trivially_relocatable_v <H>, ""); +static_assert (std::is_replaceable_v <H>, ""); + +struct I replaceable_if_eligible { I &operator= (const I &) = default; }; + +static_assert (std::is_trivially_relocatable_v <I>, ""); +static_assert (std::is_replaceable_v <I>, ""); + +struct J { J &operator= (J const &) = default; }; + +static_assert (std::is_trivially_relocatable_v <J>, ""); +static_assert (std::is_replaceable_v <J>, ""); + +struct K { K (const K &) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <K>, ""); +static_assert (!std::is_replaceable_v <K>, ""); + +struct L { L (L&&) = delete; }; + +static_assert (!std::is_trivially_relocatable_v <L>, ""); +static_assert (!std::is_replaceable_v <L>, ""); + +struct M { M operator= (M); }; + +static_assert (!std::is_trivially_relocatable_v <M>, ""); +static_assert (!std::is_replaceable_v <M>, ""); + +struct N { N operator= (N &&); }; + +static_assert (!std::is_trivially_relocatable_v <N>, ""); +static_assert (!std::is_replaceable_v <N>, ""); diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable5.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable5.C new file mode 100644 index 0000000..0416137 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable5.C @@ -0,0 +1,77 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-additional-options "-Wc++26-compat" } + +struct A __trivially_relocatable_if_eligible { A (const A &&); }; +struct B __replaceable_if_eligible { B (const B &&); B &operator= (B &&); }; +struct C __replaceable_if_eligible __final __trivially_relocatable_if_eligible { C (const C &&); C &operator= (C &&); }; +#if __cpp_trivial_relocatability >= 202502L +struct D trivially_relocatable_if_eligible { D (const D &&); }; +struct E replaceable_if_eligible { E (const E &&); E &operator= (E &&); }; +struct F trivially_relocatable_if_eligible replaceable_if_eligible final { F (const F &&); F &operator= (F &&); }; +#else +struct D trivially_relocatable_if_eligible {}; // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" "" { target c++23_down } } +// { dg-error "variable 'D trivially_relocatable_if_eligible' has initializer but incomplete type" "" { target c++23_down } .-1 } +struct E replaceable_if_eligible {}; // { dg-warning "identifier 'replaceable_if_eligible' is a conditional keyword in" "" { target c++23_down } } +// { dg-error "variable 'E replaceable_if_eligible' has initializer but incomplete type" "" { target c++23_down } .-1 } +struct F trivially_relocatable_if_eligible replaceable_if_eligible {}; // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" "" { target c++23_down } } +// { dg-error "expected initializer before 'replaceable_if_eligible'" "" { target c++23_down } .-1 } +#endif +#if __cplusplus <= 202302L +struct G {}; +struct G trivially_relocatable_if_eligible {}; // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" "" { target c++23_down } } +struct H {}; +struct H replaceable_if_eligible {}; // { dg-warning "identifier 'replaceable_if_eligible' is a conditional keyword in" "" { target c++23_down } } +struct I {}; +struct I trivially_relocatable_if_eligible replaceable_if_eligible {}; // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" "" { target c++23_down } } +#endif // { dg-error "expected initializer before 'replaceable_if_eligible'" "" { target c++23_down } .-1 } +struct J {}; +struct J __trivially_relocatable_if_eligible {}; // { dg-error "redefinition of 'struct J'" } +struct K {}; +struct K __replaceable_if_eligible {}; // { dg-error "redefinition of 'struct K'" } +struct L {}; +struct L __trivially_relocatable_if_eligible __replaceable_if_eligible {}; // { dg-error "redefinition of 'struct L'" } +struct M __trivially_relocatable_if_eligible __trivially_relocatable_if_eligible {}; // { dg-error "duplicate '__trivially_relocatable_if_eligible' specifier" } +struct N __replaceable_if_eligible __replaceable_if_eligible {}; // { dg-error "duplicate '__replaceable_if_eligible' specifier" } +struct O __trivially_relocatable_if_eligible __replaceable_if_eligible __replaceable_if_eligible __trivially_relocatable_if_eligible final final {}; +// { dg-error "duplicate '__replaceable_if_eligible' specifier" "" { target *-*-* } .-1 } +// { dg-error "duplicate '__trivially_relocatable_if_eligible' specifier" "" { target *-*-* } .-2 } +// { dg-error "duplicate 'final' specifier" "" { target *-*-* } .-3 } +#if __cpp_trivial_relocatability >= 202502L +struct P trivially_relocatable_if_eligible trivially_relocatable_if_eligible {}; // { dg-error "duplicate 'trivially_relocatable_if_eligible' specifier" "" { target c++26 } } +struct Q replaceable_if_eligible replaceable_if_eligible {}; // { dg-error "duplicate 'replaceable_if_eligible' specifier" "" { target c++26 } } +struct R trivially_relocatable_if_eligible replaceable_if_eligible replaceable_if_eligible trivially_relocatable_if_eligible final final {}; +// { dg-error "duplicate 'replaceable_if_eligible' specifier" "" { target c++26 } .-1 } +// { dg-error "duplicate 'trivially_relocatable_if_eligible' specifier" "" { target c++26 } .-2 } +// { dg-error "duplicate 'final' specifier" "" { target c++26 } .-3 } +struct S trivially_relocatable_if_eligible __trivially_relocatable_if_eligible {}; // { dg-error "duplicate '__trivially_relocatable_if_eligible' specifier" "" { target c++26 } } +struct T replaceable_if_eligible __replaceable_if_eligible {}; // { dg-error "duplicate '__replaceable_if_eligible' specifier" "" { target c++26 } } +struct U trivially_relocatable_if_eligible replaceable_if_eligible __replaceable_if_eligible __trivially_relocatable_if_eligible final __final {}; +// { dg-error "duplicate '__replaceable_if_eligible' specifier" "" { target c++26 } .-1 } +// { dg-error "duplicate '__trivially_relocatable_if_eligible' specifier" "" { target c++26 } .-2 } +// { dg-error "duplicate '__final' specifier" "" { target c++26 } .-3 } +struct V __trivially_relocatable_if_eligible trivially_relocatable_if_eligible {}; // { dg-error "duplicate 'trivially_relocatable_if_eligible' specifier" "" { target c++26 } } +struct W __replaceable_if_eligible replaceable_if_eligible {}; // { dg-error "duplicate 'replaceable_if_eligible' specifier" "" { target c++26 } } +struct X __trivially_relocatable_if_eligible __replaceable_if_eligible replaceable_if_eligible trivially_relocatable_if_eligible __final final {}; +// { dg-error "duplicate 'replaceable_if_eligible' specifier" "" { target c++26 } .-1 } +// { dg-error "duplicate 'trivially_relocatable_if_eligible' specifier" "" { target c++26 } .-2 } +// { dg-error "duplicate 'final' specifier" "" { target c++26 } .-3 } +#else +struct Y {}; +Y foo (); +struct Y trivially_relocatable_if_eligible = foo (); // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" "" { target c++23_down } } +struct Z {}; +Z bar (); +struct Z replaceable_if_eligible = bar (); // { dg-warning "identifier 'replaceable_if_eligible' is a conditional keyword in" "" { target c++23_down } } +#endif + +static_assert (__builtin_is_trivially_relocatable (A), ""); +static_assert (__builtin_is_replaceable (B), ""); +static_assert (__builtin_is_trivially_relocatable (C), ""); +static_assert (__builtin_is_replaceable (C), ""); +#if __cpp_trivial_relocatability >= 202502L +static_assert (__builtin_is_trivially_relocatable (D), ""); +static_assert (__builtin_is_replaceable (E), ""); +static_assert (__builtin_is_trivially_relocatable (F), ""); +static_assert (__builtin_is_replaceable (F), ""); +#endif diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable6.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable6.C new file mode 100644 index 0000000..ffcf12b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable6.C @@ -0,0 +1,30 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++98_only } } +// { dg-additional-options "-Wc++26-compat" } + +struct A __trivially_relocatable_if_eligible {}; +struct B __replaceable_if_eligible {}; +struct C __replaceable_if_eligible __final __trivially_relocatable_if_eligible {}; +struct D trivially_relocatable_if_eligible {}; // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" } +// { dg-error "variable 'D trivially_relocatable_if_eligible' has initializer but incomplete type" "" { target *-*-* } .-1 } +// { dg-error "extended initializer lists only available with" "" { target *-*-* } .-2 } +struct E replaceable_if_eligible {}; // { dg-warning "identifier 'replaceable_if_eligible' is a conditional keyword in" } +// { dg-error "variable 'E replaceable_if_eligible' has initializer but incomplete type" "" { target *-*-* } .-1 } +// { dg-error "extended initializer lists only available with" "" { target *-*-* } .-2 } +struct F trivially_relocatable_if_eligible replaceable_if_eligible {}; // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" } +// { dg-error "expected initializer before 'replaceable_if_eligible'" "" { target *-*-* } .-1 } +struct G {}; +struct G trivially_relocatable_if_eligible {}; // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" } +// { dg-error "extended initializer lists only available with" "" { target *-*-* } .-1 } +struct H {}; +struct H replaceable_if_eligible {}; // { dg-warning "identifier 'replaceable_if_eligible' is a conditional keyword in" } +// { dg-error "extended initializer lists only available with" "" { target *-*-* } .-1 } +struct I {}; +struct I trivially_relocatable_if_eligible replaceable_if_eligible {}; // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" } +// { dg-error "expected initializer before 'replaceable_if_eligible'" "" { target *-*-* } .-1 } +struct J {}; +J foo (); +struct J trivially_relocatable_if_eligible = foo (); // { dg-warning "identifier 'trivially_relocatable_if_eligible' is a conditional keyword in" } +struct K {}; +K bar (); +struct K replaceable_if_eligible = bar (); // { dg-warning "identifier 'replaceable_if_eligible' is a conditional keyword in" } diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable7.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable7.C new file mode 100644 index 0000000..608c245 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable7.C @@ -0,0 +1,33 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++17 } } + +namespace std +{ +template <typename T, T v> +struct integral_constant +{ + static constexpr T value = v; +}; + +template <typename T> +inline constexpr bool is_trivially_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_trivially_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + // { dg-error "invalid use of incomplete type 'struct A'" "" { target *-*-* } .-1 } + +template <typename T> +inline constexpr bool is_nothrow_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_nothrow_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + // { dg-error "invalid use of incomplete type 'struct A'" "" { target *-*-* } .-1 } + +template <typename T> +inline constexpr bool is_replaceable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_replaceable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +} // { dg-error "invalid use of incomplete type 'struct A'" "" { target *-*-* } .-1 } + +struct A; // { dg-message "forward declaration of 'struct A'" } + +auto a = std::is_trivially_relocatable_v <A>; // { dg-message "required from here" } +auto b = std::is_nothrow_relocatable_v <A>; // { dg-message "required from here" } +auto c = std::is_replaceable_v <A>; // { dg-message "required from here" } diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable8.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable8.C new file mode 100644 index 0000000..5f8390d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable8.C @@ -0,0 +1,190 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++17 } } + +#if __cpp_trivial_relocatability < 202502L +#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible +#define replaceable_if_eligible __replaceable_if_eligible +#endif + +namespace std +{ +template <typename T, T v> +struct integral_constant +{ + static constexpr T value = v; +}; + +template <typename> +struct is_trivially_relocatable; + +template <typename> +struct is_replaceable; + +template<typename T> +struct is_trivially_relocatable + : public integral_constant <bool, __builtin_is_trivially_relocatable (T)> +{ +}; + +template<typename T> +struct is_nothrow_relocatable + : public integral_constant <bool, __builtin_is_nothrow_relocatable (T)> +{ +}; + +template<typename T> +struct is_replaceable + : public integral_constant <bool, __builtin_is_replaceable (T)> +{ +}; + +template <typename T> +inline constexpr bool is_trivially_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_trivially_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_nothrow_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_nothrow_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_replaceable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_replaceable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +} + +struct A { A (A &&) = default; A &operator= (A &&) = default; ~A () = default; int a; }; + +static_assert (std::is_trivially_relocatable_v <A>, ""); +static_assert (std::is_nothrow_relocatable_v <A>, ""); +static_assert (std::is_replaceable_v <A>, ""); + +struct B { B (B &&); B &operator= (B &&) = default; ~B () = default; int a; }; + +static_assert (!std::is_trivially_relocatable_v <B>, ""); +static_assert (!std::is_nothrow_relocatable_v <B>, ""); +static_assert (!std::is_replaceable_v <B>, ""); + +struct C { C (C &&) = default; C &operator= (C &&); ~C () = default; int a; }; + +static_assert (!std::is_trivially_relocatable_v <C>, ""); +static_assert (std::is_nothrow_relocatable_v <C>, ""); +static_assert (!std::is_replaceable_v <C>, ""); + +struct D { D (D &&) = delete; D &operator= (D &&) = default; int a; }; + +static_assert (!std::is_trivially_relocatable_v <D>, ""); +static_assert (!std::is_nothrow_relocatable_v <D>, ""); +static_assert (!std::is_replaceable_v <D>, ""); + +struct E { E (E &&) = default; E &operator= (E &&) = delete; int a; }; + +static_assert (!std::is_trivially_relocatable_v <E>, ""); +static_assert (std::is_nothrow_relocatable_v <E>, ""); +static_assert (!std::is_replaceable_v <E>, ""); + +struct F { F (F &&) = default; F &operator= (F &&) = default; ~F () = delete; int a; }; + +static_assert (!std::is_trivially_relocatable_v <F>, ""); +static_assert (!std::is_nothrow_relocatable_v <F>, ""); +static_assert (!std::is_replaceable_v <F>, ""); + +struct G { G (const G &) = default; G &operator= (const G &) = default; int a; }; + +static_assert (std::is_trivially_relocatable_v <G>, ""); +static_assert (std::is_nothrow_relocatable_v <G>, ""); +static_assert (std::is_replaceable_v <G>, ""); + +struct H { H (const H &); H &operator= (const H &) = default; int a; }; + +static_assert (!std::is_trivially_relocatable_v <H>, ""); +static_assert (!std::is_nothrow_relocatable_v <H>, ""); +static_assert (!std::is_replaceable_v <H>, ""); + +struct I { I (const I &) = default; I &operator= (const I &); ~I () = default; int a; }; + +static_assert (!std::is_trivially_relocatable_v <I>, ""); +static_assert (std::is_nothrow_relocatable_v <I>, ""); +static_assert (!std::is_replaceable_v <I>, ""); + +struct J { J (const J &) = delete; J &operator= (const J &) = default; int a; }; + +static_assert (!std::is_trivially_relocatable_v <J>, ""); +static_assert (!std::is_nothrow_relocatable_v <J>, ""); +static_assert (!std::is_replaceable_v <J>, ""); + +struct K { K (const K &) = default; K &operator= (const K &) = delete; int a; }; + +static_assert (!std::is_trivially_relocatable_v <K>, ""); +static_assert (std::is_nothrow_relocatable_v <K>, ""); +static_assert (!std::is_replaceable_v <K>, ""); + +struct M; +struct L { L (L &&) = default; L (M &&); L &operator= (L &&) = default; int a; }; + +static_assert (std::is_trivially_relocatable_v <L>, ""); +static_assert (std::is_nothrow_relocatable_v <L>, ""); +static_assert (std::is_replaceable_v <L>, ""); + +struct M : public L { using L::L; M (const M &); M &operator= (M &&) = default; int b; }; + +static_assert (!std::is_trivially_relocatable_v <M>, ""); +static_assert (!std::is_nothrow_relocatable_v <M>, ""); +static_assert (!std::is_replaceable_v <M>, ""); + +struct O; +struct N { N (N &&) = default; N &operator= (N &&) = default; N &operator= (O &&); int a; }; + +static_assert (std::is_trivially_relocatable_v <N>, ""); +static_assert (std::is_nothrow_relocatable_v <N>, ""); +static_assert (std::is_replaceable_v <N>, ""); + +struct O : public N { using N::operator=; O (O &&) = default; int b; }; + +static_assert (!std::is_trivially_relocatable_v <O>, ""); +static_assert (std::is_nothrow_relocatable_v <O>, ""); +static_assert (!std::is_replaceable_v <O>, ""); + +struct Q; +struct P { template <typename T> P (T &&) {} }; + +static_assert (std::is_trivially_relocatable_v <P>, ""); +static_assert (std::is_nothrow_relocatable_v <P>, ""); +static_assert (std::is_replaceable_v <P>, ""); + +struct Q : public P { using P::P; Q (const Q &); }; + +static_assert (!std::is_trivially_relocatable_v <Q>, ""); +static_assert (!std::is_nothrow_relocatable_v <Q>, ""); +static_assert (!std::is_replaceable_v <Q>, ""); + +struct S; +struct R { R (const R &) = default; R (const M &); R &operator= (R &&) = default; int a; }; + +static_assert (std::is_trivially_relocatable_v <R>, ""); +static_assert (std::is_nothrow_relocatable_v <R>, ""); +static_assert (std::is_replaceable_v <R>, ""); + +struct S : public R { using R::R; S &operator= (S &&) = default; int b; }; + +static_assert (!std::is_trivially_relocatable_v <S>, ""); +static_assert (!std::is_nothrow_relocatable_v <S>, ""); +static_assert (!std::is_replaceable_v <S>, ""); + +struct T { T (T &&) = default; T &operator= (T &&) = default; ~T (); int a; }; + +static_assert (!std::is_trivially_relocatable_v <T>, ""); +static_assert (std::is_nothrow_relocatable_v <T>, ""); +static_assert (!std::is_replaceable_v <T>, ""); + +struct U { U (const U &) = default; U &operator= (const U &) = default; ~U (); int a; }; + +static_assert (!std::is_trivially_relocatable_v <U>, ""); +static_assert (std::is_nothrow_relocatable_v <U>, ""); +static_assert (!std::is_replaceable_v <U>, ""); + +struct V { public: V (); private: V (V &&) = default; V &operator= (V &&) = default; ~V () = default; int a; }; + +static_assert (std::is_trivially_relocatable_v <V>, ""); +static_assert (std::is_nothrow_relocatable_v <V>, ""); +static_assert (std::is_replaceable_v <V>, ""); diff --git a/gcc/testsuite/g++.dg/cpp26/trivially-relocatable9.C b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable9.C new file mode 100644 index 0000000..1c45b53 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/trivially-relocatable9.C @@ -0,0 +1,134 @@ +// P2786R13 - C++26 Trivial Relocatability +// { dg-do compile { target c++11 } } +// { dg-options "" } +// { dg-additional-options "-pedantic" { target c++17 } } + +#if __cpp_trivial_relocatability < 202502L +#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible +#define replaceable_if_eligible __replaceable_if_eligible +#endif + +namespace std +{ +template <typename T, T v> +struct integral_constant +{ + static constexpr T value = v; +}; + +template <typename> +struct is_trivially_relocatable; + +template <typename> +struct is_replaceable; + +template<typename T> +struct is_trivially_relocatable + : public integral_constant <bool, __builtin_is_trivially_relocatable (T)> +{ +}; + +template<typename T> +struct is_nothrow_relocatable + : public integral_constant <bool, __builtin_is_nothrow_relocatable (T)> +{ +}; + +template<typename T> +struct is_replaceable + : public integral_constant <bool, __builtin_is_replaceable (T)> +{ +}; + +template <typename T> +inline constexpr bool is_trivially_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_trivially_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_nothrow_relocatable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_nothrow_relocatable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } + +template <typename T> +inline constexpr bool is_replaceable_v // { dg-warning "inline variables are only available with" "" { target c++14_down } } + = __builtin_is_replaceable (T); // { dg-warning "variable templates only available with" "" { target c++11_down } .-1 } +} + +struct A trivially_relocatable_if_eligible { A (A &&); A &operator= (A &&); ~A (); int a; }; + +static_assert (std::is_trivially_relocatable_v <A>, ""); +static_assert (std::is_nothrow_relocatable_v <A>, ""); + +struct B { B (B &&); B &operator= (B &&); ~B (); int a; }; + +static_assert (!std::is_trivially_relocatable_v <B>, ""); +static_assert (!std::is_nothrow_relocatable_v <B>, ""); + +struct C trivially_relocatable_if_eligible : public A { C (C &&); C &operator= (C &&); ~C (); int a; }; + +static_assert (std::is_trivially_relocatable_v <C>, ""); +static_assert (std::is_nothrow_relocatable_v <C>, ""); + +struct D trivially_relocatable_if_eligible : public B { D (D &&); D &operator= (D &&); ~D (); int a; }; + +static_assert (!std::is_trivially_relocatable_v <D>, ""); +static_assert (!std::is_nothrow_relocatable_v <D>, ""); + +struct E trivially_relocatable_if_eligible { E (E &&); E &operator= (E &&); ~E (); A a; }; + +static_assert (std::is_trivially_relocatable_v <E>, ""); +static_assert (std::is_nothrow_relocatable_v <E>, ""); + +struct F trivially_relocatable_if_eligible { F (F &&) noexcept; F &operator= (F &&); ~F (); B a; }; + +static_assert (!std::is_trivially_relocatable_v <F>, ""); +static_assert (std::is_nothrow_relocatable_v <F>, ""); + +struct G trivially_relocatable_if_eligible { G (G &&); G &operator= (G &&); ~G () = delete; int a; }; + +static_assert (!std::is_trivially_relocatable_v <G>, ""); +static_assert (!std::is_nothrow_relocatable_v <G>, ""); + +struct H trivially_relocatable_if_eligible : virtual A { H (H &&); H &operator= (H &&); ~H (); int a; }; + +static_assert (!std::is_trivially_relocatable_v <H>, ""); +static_assert (!std::is_nothrow_relocatable_v <H>, ""); + +struct I trivially_relocatable_if_eligible { I (I &&); I &operator= (I &&); ~I (); A &a; int &b; }; + +static_assert (std::is_trivially_relocatable_v <I>, ""); +static_assert (std::is_nothrow_relocatable_v <I>, ""); + +struct J trivially_relocatable_if_eligible { J (J &&); J &operator= (J &&); ~J (); B &a; int &b; }; + +static_assert (std::is_trivially_relocatable_v <J>, ""); +static_assert (std::is_nothrow_relocatable_v <J>, ""); + +struct K trivially_relocatable_if_eligible { K (K &&) noexcept; K &operator= (K &&); ~K (); union { A a; int b; char c; }; }; + +static_assert (!std::is_trivially_relocatable_v <K>, ""); +static_assert (std::is_nothrow_relocatable_v <K>, ""); + +struct L trivially_relocatable_if_eligible { L (L &&); L &operator= (L &&); ~L (); union { int a; B b; short c; }; }; + +static_assert (!std::is_trivially_relocatable_v <L>, ""); +static_assert (!std::is_nothrow_relocatable_v <L>, ""); + +struct M trivially_relocatable_if_eligible { M (M &&); M &operator= (M &&); ~M () = default; int a; }; + +static_assert (std::is_trivially_relocatable_v <M>, ""); +static_assert (std::is_nothrow_relocatable_v <M>, ""); + +struct N trivially_relocatable_if_eligible { N (N &&); N &operator= (N &&); ~N (); union { M a; int b; char c; }; }; + +static_assert (std::is_trivially_relocatable_v <N>, ""); +static_assert (std::is_nothrow_relocatable_v <N>, ""); + +struct O trivially_relocatable_if_eligible { O (O &&); O &operator= (O &&); ~O (); union { unsigned long long a; int b; char c; }; }; + +static_assert (std::is_trivially_relocatable_v <O>, ""); +static_assert (std::is_nothrow_relocatable_v <O>, ""); + +struct P { P (P &&) noexcept; P &operator= (P &&); ~P (); int a; }; + +static_assert (!std::is_trivially_relocatable_v <P>, ""); +static_assert (std::is_nothrow_relocatable_v <P>, ""); diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval-memfn1.C b/gcc/testsuite/g++.dg/cpp2a/consteval-memfn1.C index ca92351..17a391b 100644 --- a/gcc/testsuite/g++.dg/cpp2a/consteval-memfn1.C +++ b/gcc/testsuite/g++.dg/cpp2a/consteval-memfn1.C @@ -4,13 +4,13 @@ struct fixed_string { consteval int size(int n) const { - if (n < 0) throw; // { dg-error "not a constant" } - return n; + if (n < 0) throw; // { dg-error "not a constant" "" { target c++23_down } } + return n; // { dg-error "'void __cxa_rethrow\\\(\\\)' called with no caught exceptions active" "" { target c++26 } .-1 } } static consteval int size_static(int n) { - if (n < 0) throw; // { dg-error "not a constant" } - return n; + if (n < 0) throw; // { dg-error "not a constant" "" { target c++23_down } } + return n; // { dg-error "'void __cxa_rethrow\\\(\\\)' called with no caught exceptions active" "" { target c++26 } .-1 } } consteval void operator()() const { } diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval34.C b/gcc/testsuite/g++.dg/cpp2a/consteval34.C index 7562f40..73bcf77 100644 --- a/gcc/testsuite/g++.dg/cpp2a/consteval34.C +++ b/gcc/testsuite/g++.dg/cpp2a/consteval34.C @@ -1,42 +1,51 @@ // { dg-do compile { target c++20 } } // Explicit { dg-require-effective-target exceptions_enabled } to avoid verify compiler messages FAILs for '-fno-exceptions'. -consteval int bar (int i) { if (i != 1) throw 1; return 0; } // { dg-error "is not a constant expression" } +consteval int bar (int i) { if (i != 1) throw 1; return 0; } // { dg-error "is not a constant expression" "" { target c++23_down } } constexpr int foo (bool b) { - return b ? bar (3) : 2; // { dg-message "in .constexpr. expansion" } + return b ? bar (3) : 2; // { dg-message "in .constexpr. expansion" "" { target c++23_down } } // { dg-error "call to consteval function" "" { target *-*-* } .-1 } -} +} // { dg-error "uncaught exception '1'" "" { target c++26 } } static_assert (foo (false) == 2); -__extension__ constexpr int g1 = false ?: bar (2); // { dg-message "in .constexpr. expansion" } -__extension__ constexpr int g2 = false ?: (1 + bar (2)); // { dg-message "in .constexpr. expansion" } +__extension__ constexpr int g1 = false ?: bar (2); // { dg-message "in .constexpr. expansion" "" { target c++23_down } } +// { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } +__extension__ constexpr int g2 = false ?: (1 + bar (2)); // { dg-message "in .constexpr. expansion" "" { target c++23_down } } +// { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } __extension__ constexpr int g3 = true ?: bar (2); __extension__ constexpr int g4 = true ?: (1 + bar (2)); -constexpr int g5 = bar (2) ? 1 : 2; // { dg-message "in .constexpr. expansion" } -constexpr int g6 = bar (2) - 1 ? 1 : 2; // { dg-message "in .constexpr. expansion" } +constexpr int g5 = bar (2) ? 1 : 2; // { dg-message "in .constexpr. expansion" "" { target c++23_down } } +// { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } +constexpr int g6 = bar (2) - 1 ? 1 : 2; // { dg-message "in .constexpr. expansion" "" { target c++23_down } } +// { dg-error "uncaught exception '1'" "" { target c++26 } .-1 } void g () { - __extension__ int a1[bar(3)]; // { dg-message "in .constexpr. expansion" } + __extension__ int a1[bar(3)]; // { dg-message "in .constexpr. expansion" "" { target c++23_down } } // { dg-error "call to consteval function" "" { target *-*-* } .-1 } int a2[sizeof (bar(3))]; - int a3 = false ? (1 + bar (8)) : 1; // { dg-message "in .constexpr. expansion" } + int a3 = false ? (1 + bar (8)) : 1; // { dg-message "in .constexpr. expansion" "" { target c++23_down } } // { dg-error "call to consteval function" "" { target *-*-* } .-1 } - a3 += false ? (1 + bar (8)) : 1; // { dg-message "in .constexpr. expansion" } +// { dg-error "uncaught exception '1'" "" { target c++26 } .-2 } + a3 += false ? (1 + bar (8)) : 1; // { dg-message "in .constexpr. expansion" "" { target c++23_down } } // { dg-error "call to consteval function" "" { target *-*-* } .-1 } - __extension__ int a4 = false ?: (1 + bar (8)); // { dg-message "in .constexpr. expansion" } + __extension__ int a4 = false ?: (1 + bar (8)); // { dg-message "in .constexpr. expansion" "" { target c++23_down } } // { dg-error "call to consteval function" "" { target *-*-* } .-1 } - __extension__ int a5 = true ?: (1 + bar (8)); // { dg-message "in .constexpr. expansion" } +// { dg-error "uncaught exception '1'" "" { target c++26 } .-2 } + __extension__ int a5 = true ?: (1 + bar (8)); // { dg-message "in .constexpr. expansion" "" { target c++23_down } } // { dg-error "call to consteval function" "" { target *-*-* } .-1 } - int a6 = bar (2) ? 1 : 2; // { dg-message "in .constexpr. expansion" } +// { dg-error "uncaught exception '1'" "" { target c++26 } .-2 } + int a6 = bar (2) ? 1 : 2; // { dg-message "in .constexpr. expansion" "" { target c++23_down } } // { dg-error "call to consteval function" "" { target *-*-* } .-1 } - int a7 = bar (2) - 1 ? 1 : 2; // { dg-message "in .constexpr. expansion" } +// { dg-error "uncaught exception '1'" "" { target c++26 } .-2 } + int a7 = bar (2) - 1 ? 1 : 2; // { dg-message "in .constexpr. expansion" "" { target c++23_down } } // { dg-error "call to consteval function" "" { target *-*-* } .-1 } -} +// { dg-error "uncaught exception '1'" "" { target c++26 } .-2 } +} // { dg-error "uncaught exception '1'" "" { target c++26 } } diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic11.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic11.C index 9ee93c3..12a071a 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic11.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic11.C @@ -8,6 +8,22 @@ // a pointer to or object of the constructor or destructor's own class or one // of its bases, the dynamic_cast results in undefined behavior. +#if __cpp_constexpr_exceptions >= 202411L +namespace std { + struct exception { + constexpr exception () noexcept {} + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr virtual const char *what () const noexcept { return "std::exception"; } + }; + struct bad_cast : public exception { + constexpr virtual ~bad_cast () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_cast"; } + }; +} +#endif + struct V { virtual void f(); }; @@ -19,7 +35,7 @@ struct B : V { }; struct D : A, B { - constexpr D() : B((A*)this, this) { } // { dg-message "in 'constexpr' expansion of" } + constexpr D() : B((A*)this, this) { } // { dg-message "in 'constexpr' expansion of" "" { target c++23_down } } }; constexpr B::B(V* v, A* a) @@ -29,8 +45,9 @@ constexpr B::B(V* v, A* a) if (b != nullptr) __builtin_abort (); - B& br = dynamic_cast<B&>(*v); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "dynamic type .A. of its operand does not have an unambiguous public base class .B." "" { target *-*-* } .-1 } + B& br = dynamic_cast<B&>(*v); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "dynamic type .A. of its operand does not have an unambiguous public base class .B." "" { target c++23_down } .-1 } } -constexpr D d; // { dg-message "in 'constexpr' expansion of" } +constexpr D d; // { dg-message "in 'constexpr' expansion of" "" { target c++23_down } } +// { dg-error "uncaught exception" "" { target c++26 } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic14.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic14.C index cc1cada..f966db4 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic14.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic14.C @@ -4,6 +4,22 @@ // Adopted from g++.old-deja/g++.other/dyncast1.C. // But use reference dynamic_cast. +#if __cpp_constexpr_exceptions >= 202411L +namespace std { + struct exception { + constexpr exception () noexcept {} + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr virtual const char *what () const noexcept { return "std::exception"; } + }; + struct bad_cast : public exception { + constexpr virtual ~bad_cast () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_cast"; } + }; +} +#endif + // 1. downcast // 1.1. single inheritance case @@ -21,27 +37,35 @@ class CCC : protected B {}; class DDD : protected CCC {}; constexpr D d; -constexpr bool b01 = (dynamic_cast<D&> ((A&)d), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const A. of its operand is a non-public base class of dynamic type .D." "" { target *-*-* } .-1 } -constexpr bool b02 = (dynamic_cast<D&> ((B&)d), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .D." "" { target *-*-* } .-1 } +constexpr bool b01 = (dynamic_cast<D&> ((A&)d), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const A. of its operand is a non-public base class of dynamic type .D." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr bool b02 = (dynamic_cast<D&> ((B&)d), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .D." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } static_assert (&d == &dynamic_cast<const D&> ((C&)d)); -constexpr bool b03 = (dynamic_cast<C&> ((B&)d), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .D." "" { target *-*-* } .-1 } +constexpr bool b03 = (dynamic_cast<C&> ((B&)d), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .D." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } constexpr DD dd; -constexpr bool b04 = (dynamic_cast<DD&> ((A&)dd), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const A. of its operand is a non-public base class of dynamic type .DD." "" { target *-*-* } .-1 } -constexpr bool b05 = (dynamic_cast<DD&> ((B&)dd), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .DD." "" { target *-*-* } .-1 } +constexpr bool b04 = (dynamic_cast<DD&> ((A&)dd), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const A. of its operand is a non-public base class of dynamic type .DD." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr bool b05 = (dynamic_cast<DD&> ((B&)dd), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .DD." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } constexpr DDD ddd; -constexpr bool b06 = (dynamic_cast<DDD&> ((A&)ddd), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const A. of its operand is a non-public base class of dynamic type .DDD." "" { target *-*-* } .-1 } -constexpr bool b07 = (dynamic_cast<DDD&> ((B&)ddd), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .DDD." "" { target *-*-* } .-1 } -constexpr bool b08 = (dynamic_cast<CCC&> ((B&)ddd), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .DDD." "" { target *-*-* } .-1 } +constexpr bool b06 = (dynamic_cast<DDD&> ((A&)ddd), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const A. of its operand is a non-public base class of dynamic type .DDD." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr bool b07 = (dynamic_cast<DDD&> ((B&)ddd), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .DDD." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr bool b08 = (dynamic_cast<CCC&> ((B&)ddd), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .DDD." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } // 1.2. multiple inheritance case // 1.2.1. all bases are public @@ -50,19 +74,23 @@ struct E : D, CC {}; struct EE : CC, D {}; //Will search in reverse order. constexpr E e; -constexpr bool b09 = (dynamic_cast<E&> ((A&)(D&)e), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .A. of its operand is a non-public base class of dynamic type .E." "" { target *-*-* } .-1 } -constexpr bool b10 = (dynamic_cast<E&> ((B&)(D&)e), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .B. of its operand is a non-public base class of dynamic type .E." "" { target *-*-* } .-1 } +constexpr bool b09 = (dynamic_cast<E&> ((A&)(D&)e), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .A. of its operand is a non-public base class of dynamic type .E." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr bool b10 = (dynamic_cast<E&> ((B&)(D&)e), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .B. of its operand is a non-public base class of dynamic type .E." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } static_assert (&e == &dynamic_cast<E&> ((C&)(D&)e)); static_assert (&e == &dynamic_cast<E&> ((B&)(CC&)e)); static_assert (&(CC&)e == &dynamic_cast<CC&> ((B&)(CC&)e)); constexpr EE ee; -constexpr bool b11 = (dynamic_cast<EE&> ((A&)(D&)ee), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .A. of its operand is a non-public base class of dynamic type .EE." "" { target *-*-* } .-1 } -constexpr bool b12 = (dynamic_cast<EE&> ((B&)(D&)ee), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .B. of its operand is a non-public base class of dynamic type .EE." "" { target *-*-* } .-1 } +constexpr bool b11 = (dynamic_cast<EE&> ((A&)(D&)ee), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .A. of its operand is a non-public base class of dynamic type .EE." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr bool b12 = (dynamic_cast<EE&> ((B&)(D&)ee), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .B. of its operand is a non-public base class of dynamic type .EE." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } static_assert (&ee == &dynamic_cast<EE&> ((C&)(D&)ee)); static_assert (&ee == &dynamic_cast<EE&> ((B&)(CC&)ee)); static_assert (&(CC&)ee == &dynamic_cast<CC&> ((B&)(CC&)ee)); @@ -78,14 +106,17 @@ constexpr X x; static_assert (&x == &dynamic_cast<X&>((B&)(CC&)(E&)x)); constexpr XX xx; -constexpr bool b13 = (dynamic_cast<XX&>((B&)(CC&)(E&)xx), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .B. of its operand is a non-public base class of dynamic type .XX." "" { target *-*-* } .-1 } +constexpr bool b13 = (dynamic_cast<XX&>((B&)(CC&)(E&)xx), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .B. of its operand is a non-public base class of dynamic type .XX." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } constexpr Y y; -constexpr bool b14 = (dynamic_cast<Y&>((B&)y), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .Y." "" { target *-*-* } .-1 } -constexpr bool b15 = (dynamic_cast<Y&>((A&)(B&)y), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .A. of its operand is a non-public base class of dynamic type .Y." "" { target *-*-* } .-1 } +constexpr bool b14 = (dynamic_cast<Y&>((B&)y), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const B. of its operand is a non-public base class of dynamic type .Y." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr bool b15 = (dynamic_cast<Y&>((A&)(B&)y), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .A. of its operand is a non-public base class of dynamic type .Y." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } // 2. crosscast @@ -93,13 +124,16 @@ struct J { virtual void j(); }; struct K : CC, private J {}; class KK : J, CC{}; -constexpr bool b16 = (dynamic_cast<CC&> ((B&)(D&)e), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .B. of its operand is a non-public base class of dynamic type .CC." "" { target *-*-* } .-1 } +constexpr bool b16 = (dynamic_cast<CC&> ((B&)(D&)e), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .B. of its operand is a non-public base class of dynamic type .CC." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } static_assert (&(CC&)e == &dynamic_cast<CC&> ((C&)(D&)e)); constexpr K k; -constexpr bool b17 = (dynamic_cast<J&> ((B&)k), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "dynamic type .K. of its operand does not have an unambiguous public base class .J." "" { target *-*-* } .-1 } +constexpr bool b17 = (dynamic_cast<J&> ((B&)k), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "dynamic type .K. of its operand does not have an unambiguous public base class .J." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } constexpr KK kk; -constexpr bool b18 = (dynamic_cast<J&> ((CC&)kk), true); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const CC. of its operand is a non-public base class of dynamic type .KK." "" { target *-*-* } .-1 } +constexpr bool b18 = (dynamic_cast<J&> ((CC&)kk), true); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const CC. of its operand is a non-public base class of dynamic type .KK." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic18.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic18.C index 25d98c2..112ff8a 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic18.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic18.C @@ -2,6 +2,22 @@ // { dg-do compile { target c++20 } } // Here 'b' doesn't point/refer to a public base of Derived. +#if __cpp_constexpr_exceptions >= 202411L +namespace std { + struct exception { + constexpr exception () noexcept {} + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr virtual const char *what () const noexcept { return "std::exception"; } + }; + struct bad_cast : public exception { + constexpr virtual ~bad_cast () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_cast"; } + }; +} +#endif + struct Base { constexpr virtual ~Base(){} }; @@ -11,12 +27,12 @@ struct Derived: Base { }; constexpr const Derived& cast(const Base& b) { - return dynamic_cast<const Derived&>(b); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "dynamic type .const Base. of its operand does not have a base class of type .Derived." "" { target *-*-* } .-1 } + return dynamic_cast<const Derived&>(b); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "dynamic type .const Base. of its operand does not have a base class of type .Derived." "" { target c++23_down } .-1 } } auto test() { static constexpr Base b; - constexpr auto res = cast(b); + constexpr auto res = cast(b); // { dg-error "uncaught exception" "" { target c++26 } } return res; } diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic4.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic4.C index da647bf..a237134 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic4.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic4.C @@ -4,6 +4,22 @@ // From clang's constant-expression-cxx2a.cpp. +#if __cpp_constexpr_exceptions >= 202411L +namespace std { + struct exception { + constexpr exception () noexcept {} + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr virtual const char *what () const noexcept { return "std::exception"; } + }; + struct bad_cast : public exception { + constexpr virtual ~bad_cast () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_cast"; } + }; +} +#endif + struct A2 { virtual void a2(); }; struct A : A2 { virtual void a(); }; struct B : A {}; @@ -26,31 +42,36 @@ static_assert(dynamic_cast<const A*>(static_cast<const C2*>(&g)) == nullptr); static_assert(g.f == (void*)(F*)&g); static_assert(dynamic_cast<const void*>(static_cast<const D*>(&g)) == &g); -constexpr int d_a = (dynamic_cast<const A&>(static_cast<const D&>(g)), 0); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message ".A. is an ambiguous base class of dynamic type .G." "" { target *-*-* } .-1 } - +constexpr int d_a = (dynamic_cast<const A&>(static_cast<const D&>(g)), 0); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message ".A. is an ambiguous base class of dynamic type .G." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } // Can navigate from A2 to its A... static_assert(&dynamic_cast<A&>((A2&)(B&)g) == &(A&)(B&)g); // ... and from B to its A ... static_assert(&dynamic_cast<A&>((B&)g) == &(A&)(B&)g); // ... but not from D. -static_assert(&dynamic_cast<A&>((D&)g) == &(A&)(B&)g); // { dg-error "non-constant condition for static assertion|reference .dynamic_cast. failed" } -// { dg-message ".A. is an ambiguous base class of dynamic type .G." "" { target *-*-* } .-1 } - +static_assert(&dynamic_cast<A&>((D&)g) == &(A&)(B&)g); // { dg-error "non-constant condition for static assertion" } +// { dg-message ".A. is an ambiguous base class of dynamic type .G." "" { target c++23_down } .-1 } +// { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } .-2 } +// { dg-error "uncaught exception" "" { target c++26 } .-3 } // Can cast from A2 to sibling class D. static_assert(&dynamic_cast<D&>((A2&)(B&)g) == &(D&)g); // Cannot cast from private base E to derived class F. -constexpr int e_f = (dynamic_cast<F&>((E&)g), 0); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const E. of its operand is a non-public base class of dynamic type .G." "" { target *-*-* } .-1 } +constexpr int e_f = (dynamic_cast<F&>((E&)g), 0); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const E. of its operand is a non-public base class of dynamic type .G." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } // Cannot cast from B to private sibling E. -constexpr int b_e = (dynamic_cast<E&>((B&)g), 0); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "dynamic type .G. of its operand does not have an unambiguous public base class .E." "" { target *-*-* } .-1 } +constexpr int b_e = (dynamic_cast<E&>((B&)g), 0); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "dynamic type .G. of its operand does not have an unambiguous public base class .E." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } struct Unrelated { virtual void unrelated(); }; -constexpr int b_unrelated = (dynamic_cast<Unrelated&>((B&)g), 0); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "dynamic type .G. of its operand does not have an unambiguous public base class .Unrelated." "" { target *-*-* } .-1 } -constexpr int e_unrelated = (dynamic_cast<Unrelated&>((E&)g), 0); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const E. of its operand is a non-public base class of dynamic type .G." "" { target *-*-* } .-1 } +constexpr int b_unrelated = (dynamic_cast<Unrelated&>((B&)g), 0); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "dynamic type .G. of its operand does not have an unambiguous public base class .Unrelated." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr int e_unrelated = (dynamic_cast<Unrelated&>((E&)g), 0); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const E. of its operand is a non-public base class of dynamic type .G." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic6.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic6.C index d67c307..4434a1a 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic6.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic6.C @@ -1,6 +1,22 @@ // PR c++/88337 - Implement P1327R1: Allow dynamic_cast/typeid in constexpr. // { dg-do compile { target c++20 } } +#if __cpp_constexpr_exceptions >= 202411L +namespace std { + struct exception { + constexpr exception () noexcept {} + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr virtual const char *what () const noexcept { return "std::exception"; } + }; + struct bad_cast : public exception { + constexpr virtual ~bad_cast () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_cast"; } + }; +} +#endif + // Private base. struct P1 { virtual void p1(); }; @@ -12,14 +28,16 @@ struct A : B, C, private P2 { virtual void a(); }; constexpr A a; // P1 is a non-public base of A. -constexpr bool b1 = (dynamic_cast<B&>((P1&)a), false); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const P1. of its operand is a non-public base class of dynamic type .A." "" { target *-*-* } .-1 } +constexpr bool b1 = (dynamic_cast<B&>((P1&)a), false); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const P1. of its operand is a non-public base class of dynamic type .A." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } // Don't error here. static_assert (dynamic_cast<B*>((P1*)&a) == nullptr); -constexpr bool b2 = (dynamic_cast<C&>((P2&)a), false); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const P2. of its operand is a non-public base class of dynamic type .A." "" { target *-*-* } .-1 } +constexpr bool b2 = (dynamic_cast<C&>((P2&)a), false); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const P2. of its operand is a non-public base class of dynamic type .A." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } static_assert (dynamic_cast<C*>((P1*)&a) == nullptr); static_assert (dynamic_cast<C*>((P2*)&a) == nullptr); diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic7.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic7.C index bc3efd0..d504efd 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic7.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic7.C @@ -1,6 +1,22 @@ // PR c++/88337 - Implement P1327R1: Allow dynamic_cast/typeid in constexpr. // { dg-do compile { target c++20 } } +#if __cpp_constexpr_exceptions >= 202411L +namespace std { + struct exception { + constexpr exception () noexcept {} + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr virtual const char *what () const noexcept { return "std::exception"; } + }; + struct bad_cast : public exception { + constexpr virtual ~bad_cast () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_cast"; } + }; +} +#endif + // Protected base. struct P1 { virtual void p1(); }; @@ -12,14 +28,16 @@ struct A : B, C, protected P2 { virtual void a(); }; constexpr A a; // P1 is a non-public base of A. -constexpr bool b1 = (dynamic_cast<B&>((P1&)a), false); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const P1. of its operand is a non-public base class of dynamic type .A." "" { target *-*-* } .-1 } +constexpr bool b1 = (dynamic_cast<B&>((P1&)a), false); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const P1. of its operand is a non-public base class of dynamic type .A." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } // Don't error here. static_assert (dynamic_cast<B*>((P1*)&a) == nullptr); -constexpr bool b2 = (dynamic_cast<C&>((P2&)a), false); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const P2. of its operand is a non-public base class of dynamic type .A." "" { target *-*-* } .-1 } +constexpr bool b2 = (dynamic_cast<C&>((P2&)a), false); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const P2. of its operand is a non-public base class of dynamic type .A." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } static_assert (dynamic_cast<C*>((P1*)&a) == nullptr); static_assert (dynamic_cast<C*>((P2*)&a) == nullptr); diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic8.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic8.C index 1958cae4..2fc8242 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic8.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic8.C @@ -1,6 +1,22 @@ // PR c++/88337 - Implement P1327R1: Allow dynamic_cast/typeid in constexpr. // { dg-do compile { target c++20 } } +#if __cpp_constexpr_exceptions >= 202411L +namespace std { + struct exception { + constexpr exception () noexcept {} + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr virtual const char *what () const noexcept { return "std::exception"; } + }; + struct bad_cast : public exception { + constexpr virtual ~bad_cast () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_cast"; } + }; +} +#endif + // Unrelated type. struct B { virtual void b(); }; @@ -12,12 +28,15 @@ constexpr A a; struct U { virtual void u(); }; -constexpr bool b1 = (dynamic_cast<U&>((B&)a), 0); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "dynamic type .A. of its operand does not have an unambiguous public base class .U." "" { target *-*-* } .-1 } -constexpr bool b2 = (dynamic_cast<U&>((P1&)a), 0); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const P1. of its operand is a non-public base class of dynamic type .A." "" { target *-*-* } .-1 } -constexpr bool b3 = (dynamic_cast<U&>((P2&)a), 0); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message "static type .const P2. of its operand is a non-public base class of dynamic type .A." "" { target *-*-* } .-1 } +constexpr bool b1 = (dynamic_cast<U&>((B&)a), 0); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "dynamic type .A. of its operand does not have an unambiguous public base class .U." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr bool b2 = (dynamic_cast<U&>((P1&)a), 0); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const P1. of its operand is a non-public base class of dynamic type .A." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } +constexpr bool b3 = (dynamic_cast<U&>((P2&)a), 0); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message "static type .const P2. of its operand is a non-public base class of dynamic type .A." "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } static_assert (dynamic_cast<U*>((B*)&a) == nullptr); static_assert (dynamic_cast<U*>((P1*)&a) == nullptr); diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic9.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic9.C index 7d42ffa..3a50dde 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic9.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic9.C @@ -1,6 +1,22 @@ // PR c++/88337 - Implement P1327R1: Allow dynamic_cast/typeid in constexpr. // { dg-do compile { target c++20 } } +#if __cpp_constexpr_exceptions >= 202411L +namespace std { + struct exception { + constexpr exception () noexcept {} + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr virtual const char *what () const noexcept { return "std::exception"; } + }; + struct bad_cast : public exception { + constexpr virtual ~bad_cast () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_cast"; } + }; +} +#endif + // Ambiguous base. struct A { virtual void a(); }; @@ -11,7 +27,8 @@ struct E : B, C, D { virtual void d(); }; constexpr E e; -constexpr bool b1 = (dynamic_cast<A&>((D&)e), false); // { dg-error "reference .dynamic_cast. failed" } -// { dg-message ".A. is an ambiguous base class of dynamic type .E. of its operand" "" { target *-*-* } .-1 } +constexpr bool b1 = (dynamic_cast<A&>((D&)e), false); // { dg-error "reference .dynamic_cast. failed" "" { target c++23_down } } +// { dg-message ".A. is an ambiguous base class of dynamic type .E. of its operand" "" { target c++23_down } .-1 } +// { dg-error "uncaught exception" "" { target c++26 } .-2 } static_assert (dynamic_cast<A*>((D*)&e) == nullptr); diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-new27.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-new27.C new file mode 100644 index 0000000..a26fc7e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-new27.C @@ -0,0 +1,41 @@ +// { dg-do compile { target c++20 } } + +#if __cpp_constexpr_exceptions >= 202411L +namespace std { + struct exception { + constexpr exception () noexcept {} + constexpr virtual ~exception () noexcept {} + constexpr exception (const exception &) = default; + constexpr exception &operator= (const exception &) = default; + constexpr virtual const char *what () const noexcept { return "std::exception"; } + }; + struct bad_alloc : public exception { + constexpr virtual ~bad_alloc () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_alloc"; } + }; + struct bad_array_new_length : public bad_alloc { + constexpr virtual ~bad_array_new_length () noexcept {} + constexpr virtual const char *what () const noexcept { return "std::bad_array_new_length"; } + }; +} +#endif + +constexpr int +foo (__SIZE_TYPE__ x, int y, int z) +{ + char (*a)[2] = new char[x][2]; // { dg-error "call to non-'constexpr' function 'void __cxa_throw_bad_array_new_length\\\(\\\)'" "" { target c++23_down } } + delete[] a; // { dg-message "declared here" "" { target c++23_down } .-1 } + int *b = new int[y]; // { dg-error "call to non-'constexpr' function 'void __cxa_throw_bad_array_new_length\\\(\\\)'" "" { target c++23_down } } + delete[] b; + int *c = new int[z]{1, 2, 3}; // { dg-error "call to non-'constexpr' function 'void __cxa_throw_bad_array_new_length\\\(\\\)'" "" { target c++23_down } } + delete[] c; + return 0; +} + +constexpr int a = foo (16, 2, 3); +constexpr int b = foo (-64, 2, 3); // { dg-message "in 'constexpr' expansion of" "" { target c++23_down } } + // { dg-error "uncaught exception" "" { target c++26 } .-1 } +constexpr int c = foo (16, -1, 3); // { dg-message "in 'constexpr' expansion of" "" { target c++23_down } } + // { dg-error "uncaught exception" "" { target c++26 } .-1 } +constexpr int d = foo (16, 2, 1); // { dg-message "in 'constexpr' expansion of" "" { target c++23_down } } + // { dg-error "uncaught exception" "" { target c++26 } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-typeid5.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-typeid5.C new file mode 100644 index 0000000..567383d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-typeid5.C @@ -0,0 +1,20 @@ +// PR c++/88337 - Implement P1327R1: Allow dynamic_cast/typeid in constexpr. +// { dg-do compile { target c++17 } } + +#include <typeinfo> + +template <class T> +constexpr bool foo () +{ + bool r = false; + const std::type_info &s = typeid( (r = true), *(T *) 0); // { dg-error "call to non-'constexpr' function 'void __cxa_bad_typeid\\\(\\\)'" "" { target c++23_down } } + return r; // { dg-message "declared here" "" { target c++23_down } .-1 } +} + +struct A {}; +struct B { virtual ~B () {} }; + +static_assert (!foo <int> ()); +static_assert (!foo <A> ()); +constexpr bool a = foo <B> (); // { dg-message "in 'constexpr' expansion of" "" { target c++23_down } } +// { dg-error "uncaught exception" "" { target c++26 } .-1 } diff --git a/gcc/testsuite/g++.dg/lto/pr114790_0.C b/gcc/testsuite/g++.dg/lto/pr114790_0.C new file mode 100644 index 0000000..eed112d --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/pr114790_0.C @@ -0,0 +1,16 @@ +// { dg-lto-do link } +// { dg-lto-options { { -w -flto -g -flto-partition=1to1 -O2 -shared -fPIC -fvisibility=hidden} } } +// { dg-require-effective-target fpic } +// { dg-require-effective-target shared } +struct APITracerContext { + virtual ~APITracerContext() = default; + virtual void releaseActivetracersList() = 0; +}; +struct APITracerContextImp : APITracerContext { + ~APITracerContextImp() override; + void releaseActivetracersList() override; +}; +struct APITracerContextImp globalAPITracerContextImp; +struct APITracerContextImp *pGlobalAPITracerContextImp = &globalAPITracerContextImp; +APITracerContextImp::~APITracerContextImp() {} + diff --git a/gcc/testsuite/g++.dg/lto/pr114790_1.C b/gcc/testsuite/g++.dg/lto/pr114790_1.C new file mode 100644 index 0000000..511fae4 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/pr114790_1.C @@ -0,0 +1,15 @@ +struct APITracerContext { + virtual void releaseActivetracersList() = 0; +}; +extern struct APITracerContextImp *pGlobalAPITracerContextImp; +struct APITracerContextImp : APITracerContext { void releaseActivetracersList();}; +int g(); +inline int +apiTracerWrapperImp( ) { + for (int i = 0; i < g(); i++) + pGlobalAPITracerContextImp->releaseActivetracersList(); +} +__attribute__((visibility("default"))) int +zeCommandListAppendMemoryCopyTracing() { + return apiTracerWrapperImp( ); +} diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-1-sarif.py b/gcc/testsuite/gcc.dg/analyzer/state-diagram-1-sarif.py index d2967d4..d92af83 100644 --- a/gcc/testsuite/gcc.dg/analyzer/state-diagram-1-sarif.py +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-1-sarif.py @@ -6,7 +6,7 @@ import pytest def sarif(): return sarif_from_env() -def test_xml_state(sarif): +def test_state_graph(sarif): result = get_result_by_index(sarif, 0) assert result['level'] == 'warning' @@ -17,16 +17,49 @@ def test_xml_state(sarif): # Event "(1)": "entry to 'test'" (index == 0) assert events[0]['location']['message']['text'] == "entry to 'test'" - state0 = get_xml_state(events, 0) - memory_regions = state0.find('memory-regions') - assert memory_regions is not None - stack = memory_regions.find('stack') - assert stack is not None - frame = stack.find('stack-frame') - assert frame.get('function') == 'test' + state0 = get_state_graph(events, 0) + + stack = state0['nodes'][0] + assert stack['id'] == 'stack' + assert get_state_node_kind(stack) == 'stack' + + frame = stack['children'][0] + assert frame['id'].startswith('frame-region-') + assert get_state_node_kind(frame) == 'stack-frame' + assert get_state_node_attr(frame, 'function') == 'test' + assert frame['location']['logicalLocations'][0]['fullyQualifiedName'] == 'test' # Final event: assert events[-1]['location']['message']['text'].startswith("use after 'free' of ") - state = get_xml_state(events, -1) - # TODO + state = get_state_graph(events, -1) + + stack = state['nodes'][0] + assert stack['id'] == 'stack' + assert get_state_node_kind(stack) == 'stack' + + frame = stack['children'][0] + assert frame['id'].startswith('frame-region-') + assert get_state_node_kind(frame) == 'stack-frame' + assert get_state_node_attr(frame, 'function') == 'test' + assert frame['location']['logicalLocations'][0]['fullyQualifiedName'] == 'test' + + heap = state['nodes'][1] + assert heap['id'] == 'heap' + assert get_state_node_kind(heap) == 'heap' + + assert len(heap['children']) == 3 + heap_buffer0 = heap['children'][0] + assert heap_buffer0['id'].startswith('heap-allocated-region-') + assert get_state_node_kind(heap_buffer0) == 'dynalloc-buffer' + + globals_ = state['nodes'][2] + assert globals_['id'] == 'globals' + assert get_state_node_kind(globals_) == 'globals' + first = globals_['children'][0] + assert first['id'].startswith('decl-region-') + assert get_state_node_kind(first) == 'variable' + assert get_state_node_name(first) == 'first' + assert get_state_node_type(first) == 'struct node *' + + assert len(state['edges']) == 3 diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-1.c b/gcc/testsuite/gcc.dg/analyzer/state-diagram-1.c index 3d853d2..3b35cfa 100644 --- a/gcc/testsuite/gcc.dg/analyzer/state-diagram-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-1.c @@ -1,4 +1,4 @@ -/* { dg-additional-options "-fdiagnostics-add-output=sarif:xml-state=yes" } */ +/* { dg-additional-options "-fdiagnostics-add-output=sarif:state-graphs=yes" } */ #include "analyzer-decls.h" diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c index 28cf580..b981cf9 100644 --- a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c @@ -1,4 +1,4 @@ -/* { dg-additional-options "-fdiagnostics-add-output=sarif:xml-state=yes" } */ +/* { dg-additional-options "-fdiagnostics-add-output=sarif:state-graphs=yes" } */ #include "analyzer-decls.h" diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.py b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.py index 484da96..3a2c6f8 100644 --- a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.py +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.py @@ -1,5 +1,3 @@ -import xml.etree.ElementTree as ET - from sarif import * import pytest @@ -8,7 +6,7 @@ import pytest def sarif(): return sarif_from_env() -def test_nested_types_in_xml_state(sarif): +def test_nested_types_in_state_graph(sarif): result = get_result_by_index(sarif, 0) assert result['level'] == 'note' @@ -16,16 +14,17 @@ def test_nested_types_in_xml_state(sarif): events = result["codeFlows"][0]["threadFlows"][0]['locations'] assert events[0]['location']['message']['text'] == 'here' - state = get_xml_state(events, 0) - - memory_regions = state.find('memory-regions') - assert memory_regions is not None + state = get_state_graph(events, 0) - stack = memory_regions.find('stack') - assert stack is not None + stack = state['nodes'][0] + assert stack['id'] == 'stack' + assert get_state_node_kind(stack) == 'stack' - frame = stack.find('stack-frame') - assert frame.get('function') == 'test' + frame = stack['children'][0] + assert frame['id'].startswith('frame-region-') + assert get_state_node_kind(frame) == 'stack-frame' + assert get_state_node_attr(frame, 'function') == 'test' + assert frame['location']['logicalLocations'][0]['fullyQualifiedName'] == 'test' # We have: # baz_arr[1].m_bars[1].m_foos[2].m_ints[1] = 42; @@ -34,40 +33,57 @@ def test_nested_types_in_xml_state(sarif): # representation to nested elements and fields. # "baz_arr": - baz_arr = frame.find("variable[@name='baz_arr']") - assert baz_arr.get('type') == 'struct baz[2]' + baz_arr = frame['children'][0] + assert get_state_node_kind(baz_arr) == 'variable' + assert get_state_node_type(baz_arr) == 'struct baz[2]' + + assert len(baz_arr['children']) == 2 + + bindings = baz_arr['children'][0] + assert bindings['id'].startswith('concrete-bindings-') + assert get_state_node_kind(bindings) == 'other' + assert get_state_node_value(bindings['children'][0]) == '(int)42' # "baz_arr[1]": - baz_arr_1 = baz_arr.find("element[@index='1']") - assert baz_arr_1.get('type') == 'struct baz' + baz_arr_1 = baz_arr['children'][1] + assert get_state_node_type(baz_arr_1) == 'struct baz' + assert get_state_node_kind(baz_arr_1) == 'element' + assert get_state_node_attr(baz_arr_1, 'index') == '1' - assert baz_arr.find("element[@index='0']") is None + assert len(baz_arr_1['children']) == 1 # "baz_arr[1].m_bars": - baz_arr_1_m_bars = baz_arr_1.find("field[@name='m_bars']") - assert baz_arr_1_m_bars.get('type') == 'struct bar[2]' + baz_arr_1_m_bars = baz_arr_1['children'][0] + assert get_state_node_name(baz_arr_1_m_bars) == 'm_bars' + assert get_state_node_type(baz_arr_1_m_bars) == 'struct bar[2]' # "baz_arr[1].m_bars[1]" - baz_arr_1_m_bars_1 = baz_arr_1_m_bars.find("element[@index='1']") - assert baz_arr_1_m_bars_1.get('type') == 'struct bar' + baz_arr_1_m_bars_1 = baz_arr_1_m_bars['children'][0] + assert get_state_node_type(baz_arr_1_m_bars_1) == 'struct bar' + assert get_state_node_kind(baz_arr_1_m_bars_1) == 'element' + assert get_state_node_attr(baz_arr_1_m_bars_1, 'index') == '1' # "baz_arr[1].m_bars[1].m_foos" - baz_arr_1_m_bars_1_m_foos = baz_arr_1_m_bars_1.find("field[@name='m_foos']") - assert baz_arr_1_m_bars_1_m_foos.get('type') == 'struct foo[3]' + baz_arr_1_m_bars_1_m_foos = baz_arr_1_m_bars_1['children'][0] + assert get_state_node_kind(baz_arr_1_m_bars_1_m_foos) == 'field' + assert get_state_node_name(baz_arr_1_m_bars_1_m_foos) == 'm_foos' + assert get_state_node_type(baz_arr_1_m_bars_1_m_foos) == 'struct foo[3]' # "baz_arr[1].m_bars[1].m_foos[2]" - baz_arr_1_m_bars_1_m_foos_2 = baz_arr_1_m_bars_1_m_foos.find("element[@index='2']") - assert baz_arr_1_m_bars_1_m_foos_2.get('type') == 'struct foo' - + baz_arr_1_m_bars_1_m_foos_2 = baz_arr_1_m_bars_1_m_foos['children'][0] + assert get_state_node_type(baz_arr_1_m_bars_1_m_foos_2) == 'struct foo' + assert get_state_node_kind(baz_arr_1_m_bars_1_m_foos_2) == 'element' + assert get_state_node_attr(baz_arr_1_m_bars_1_m_foos_2, 'index') == '2' + # "baz_arr[1].m_bars[1].m_foos[2].m_ints" - baz_arr_1_m_bars_1_m_foos_2_m_ints = baz_arr_1_m_bars_1_m_foos_2.find('field[@name="m_ints"]') - assert baz_arr_1_m_bars_1_m_foos_2_m_ints.get('type') == 'int[4]' - - # "baz_arr[1].m_bars[1].m_foos[2].m_ints[1]" - baz_arr_1_m_bars_1_m_foos_2_m_ints_1 = baz_arr_1_m_bars_1_m_foos_2_m_ints.find('element[@index="1"]') - assert baz_arr_1_m_bars_1_m_foos_2_m_ints_1.get('type') == 'int' + baz_arr_1_m_bars_1_m_foos_2_m_ints = baz_arr_1_m_bars_1_m_foos_2['children'][0] + assert get_state_node_kind(baz_arr_1_m_bars_1_m_foos_2_m_ints) == 'field' + assert get_state_node_name(baz_arr_1_m_bars_1_m_foos_2_m_ints) == 'm_ints' + assert get_state_node_type(baz_arr_1_m_bars_1_m_foos_2_m_ints) == 'int[4]' - value = baz_arr_1_m_bars_1_m_foos_2_m_ints_1.find('value-of-region') - constant = value.find('constant') - assert constant.get('value') == '42' - assert constant.get('type') == 'int' + # "baz_arr[1].m_bars[1].m_foos[2].m_ints[1]" + baz_arr_1_m_bars_1_m_foos_2_m_ints_1 = baz_arr_1_m_bars_1_m_foos_2_m_ints['children'][0] + assert get_state_node_type(baz_arr_1_m_bars_1_m_foos_2_m_ints_1) == 'int' + assert get_state_node_kind(baz_arr_1_m_bars_1_m_foos_2_m_ints_1) == 'element' + assert get_state_node_attr(baz_arr_1_m_bars_1_m_foos_2_m_ints_1, 'index') == '1' + assert get_state_node_value(baz_arr_1_m_bars_1_m_foos_2_m_ints_1) == '(int)42' diff --git a/gcc/testsuite/gcc.dg/flex-array-counted-by-pr121000.c b/gcc/testsuite/gcc.dg/flex-array-counted-by-pr121000.c new file mode 100644 index 0000000..5b9a2c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/flex-array-counted-by-pr121000.c @@ -0,0 +1,43 @@ +/* PR middle-end/121000 */ +/* { dg-do run } */ +/* { dg-options "-O" } */ + +#include "builtin-object-size-common.h" + +/* The parameter m must be const qualified to avoid the m is + marked as TREE_SIDE_EFFECTS in IR. + The __builtin_dynamic_object_size will be folded as -1 by + fold_builtin_object_size when m is NOT const qualified. */ + +void +foo (int n, const int m) +{ + typedef int A[m]; + struct S { int n, m; A a[2]; A b[] __attribute__((counted_by (n))); } *p; + p = __builtin_malloc (sizeof (struct S) + sizeof (A) * n); + p->n = n; + p->m = m; + EXPECT (__builtin_dynamic_object_size (p->b, 1), sizeof (A) * n); +} + +/* The parameter m1, m2 must be const qualified to avoid the m is + marked as TREE_SIDE_EFFECTS in IR. + The __builtin_dynamic_object_size will be folded as -1 by + fold_builtin_object_size when m1 or m2 is NOT const qualified. */ +void +foo_1 (int n, const int m1, const int m2) +{ + typedef int A[m1][m2]; + struct S { int n; A a[2]; A b[] __attribute__((counted_by (n))); } *p; + p = __builtin_malloc (sizeof (struct S) + sizeof (A) * n); + p->n = n; + EXPECT (__builtin_dynamic_object_size (p->b, 1), sizeof (A) * n); +} + +int +main () +{ + foo (2, 10); + foo_1 (2, 10, 20); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.c new file mode 100644 index 0000000..2256a63 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-fdiagnostics-add-output=experimental-html:javascript=no" } */ + +extern void here (void); + +void test_graphs (void) +{ + here (); /* { dg-error "this is a placeholder error, with graphs" } */ +} + +/* Use a Python script to verify various properties about the generated + HTML file: + { dg-final { run-html-pytest diagnostic-test-graphs-html.c "diagnostic-test-graphs-html.py" } } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.py new file mode 100644 index 0000000..11e5fd1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.py @@ -0,0 +1,48 @@ +# Verify that metadata works in HTML output. + +from htmltest import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def html_tree(): + return html_tree_from_env() + +def test_result_graph(html_tree): + root = html_tree.getroot () + assert root.tag == make_tag('html') + + body = root.find('xhtml:body', ns) + assert body is not None + + diag_list = body.find('xhtml:div', ns) + assert diag_list is not None + assert diag_list.attrib['class'] == 'gcc-diagnostic-list' + + diag = diag_list.find('xhtml:div', ns) + assert diag is not None + + message = diag.find("./xhtml:div[@class='gcc-message']", ns) + assert message.attrib['id'] == 'gcc-diag-0-message' + + assert message[0].tag == make_tag('strong') + assert message[0].tail == ' this is a placeholder error, with graphs ' + + graph = diag.find("./xhtml:div[@class='gcc-directed-graph']", ns) + assert graph is not None + + header = graph.find("./xhtml:h2", ns) + assert header.text == 'foo' + +def test_run_graph(html_tree): + root = html_tree.getroot () + assert root.tag == make_tag('html') + + body = root.find('xhtml:body', ns) + assert body is not None + + graph = body.find("./xhtml:div[@class='gcc-directed-graph']", ns) + assert graph is not None + + header = graph.find("./xhtml:h2", ns) + assert header.text == 'Optimization Passes' diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c new file mode 100644 index 0000000..4170f51 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fdiagnostics-add-output=sarif" } */ + +extern void here (void); + +void test_graphs (void) +{ + here (); /* { dg-error "this is a placeholder error, with graphs" } */ +} + +/* Verify that some JSON was written to a file with the expected name. */ +/* { dg-final { verify-sarif-file } } */ + +/* Use a Python script to verify various properties about the generated + .sarif file: + { dg-final { run-sarif-pytest diagnostic-test-graphs-sarif.c "diagnostic-test-graphs-sarif.py" } } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py new file mode 100644 index 0000000..4bb7535 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py @@ -0,0 +1,55 @@ +from sarif import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def sarif(): + return sarif_from_env() + +def test_basics(sarif): + schema = sarif['$schema'] + assert schema == "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" + + version = sarif['version'] + assert version == "2.1.0" + +def test_result_graph(sarif): + runs = sarif['runs'] + run = runs[0] + results = run['results'] + + assert len(results) == 1 + + result = results[0] + assert result['level'] == 'error' + assert result['message']['text'] == "this is a placeholder error, with graphs" + + assert len(result['graphs']) == 2 + + assert result['graphs'][0]['description']['text'] == 'foo' + + assert len(result['graphs'][0]['nodes']) == 2 + assert result['graphs'][0]['nodes'][0]['id'] == 'a' + assert result['graphs'][0]['nodes'][1]['id'] == 'b' + assert result['graphs'][0]['nodes'][1]['properties']['/placeholder-prefix/color'] == 'red' + assert len(result['graphs'][0]['nodes'][1]['children']) == 1 + assert result['graphs'][0]['nodes'][1]['children'][0]['id'] == 'c' + assert result['graphs'][0]['nodes'][1]['children'][0]['label']['text'] == 'I am a node label' + + assert len(result['graphs'][0]['edges']) == 1 + result['graphs'][0]['edges'][0]['id'] == 'my-edge' + assert result['graphs'][0]['edges'][0]['label']['text'] == 'I am an edge label' + assert result['graphs'][0]['edges'][0]['sourceNodeId'] == 'a' + assert result['graphs'][0]['edges'][0]['targetNodeId'] == 'c' + + assert result['graphs'][1]['description']['text'] == 'bar' + +def test_run_graph(sarif): + runs = sarif['runs'] + run = runs[0] + + assert len(run['graphs']) == 1 + + assert run['graphs'][0]['description']['text'] == 'Optimization Passes' + assert run['graphs'][0]['nodes'][0]['id'] == 'all_lowering_passes' + assert run['graphs'][0]['edges'][0]['id'] == 'edge0' diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs.c new file mode 100644 index 0000000..7973954 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ + +extern void here (void); + +void test_graphs (void) +{ + here (); /* { dg-error "this is a placeholder error, with graphs" } */ +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_graphs.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_graphs.cc new file mode 100644 index 0000000..d432161 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_graphs.cc @@ -0,0 +1,283 @@ +/* This plugin exercises diagnostic graphs. + We emit an error with a pair of digraphs associated with it, + and a global digraph showing the optimization passes. */ + +#define INCLUDE_MAP +#define INCLUDE_STRING +#define INCLUDE_VECTOR +#include "gcc-plugin.h" +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "tree.h" +#include "stringpool.h" +#include "toplev.h" +#include "basic-block.h" +#include "hash-table.h" +#include "vec.h" +#include "ggc.h" +#include "basic-block.h" +#include "tree-ssa-alias.h" +#include "internal-fn.h" +#include "gimple.h" +#include "gimple-iterator.h" +#include "gimple-fold.h" +#include "tree-eh.h" +#include "gimple-expr.h" +#include "is-a.h" +#include "tree.h" +#include "tree-pass.h" +#include "intl.h" +#include "plugin-version.h" +#include "diagnostic.h" +#include "context.h" +#include "gcc-rich-location.h" +#include "diagnostic-metadata.h" +#include "diagnostic-digraphs.h" +#include "pass_manager.h" + + +int plugin_is_GPL_compatible; + +const pass_data pass_data_test_graph_emission = +{ + GIMPLE_PASS, /* type */ + "test_graph_emission", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_NONE, /* tv_id */ + PROP_ssa, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_test_graph_emission : public gimple_opt_pass +{ +public: + pass_test_graph_emission(gcc::context *ctxt) + : gimple_opt_pass(pass_data_test_graph_emission, ctxt) + {} + + /* opt_pass methods: */ + bool gate (function *) { return true; } + virtual unsigned int execute (function *); + +}; // class pass_test_graph_emission + +/* Determine if STMT is a call with NUM_ARGS arguments to a function + named FUNCNAME. + If so, return STMT as a gcall *. Otherwise return NULL. */ + +static gcall * +check_for_named_call (gimple *stmt, + const char *funcname, unsigned int num_args) +{ + gcc_assert (funcname); + + gcall *call = dyn_cast <gcall *> (stmt); + if (!call) + return NULL; + + tree fndecl = gimple_call_fndecl (call); + if (!fndecl) + return NULL; + + if (strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), funcname)) + return NULL; + + if (gimple_call_num_args (call) != num_args) + { + error_at (stmt->location, "expected number of args: %i (got %i)", + num_args, gimple_call_num_args (call)); + return NULL; + } + + return call; +} + +class lazy_passes_graph : public diagnostics::digraphs::lazy_digraph +{ +public: + lazy_passes_graph (const ::gcc::pass_manager &pass_manager_) + : m_pass_manager (pass_manager_) + { + } + + std::unique_ptr<diagnostics::digraphs::digraph> + create_digraph () const final override + { + auto g = std::make_unique<diagnostics::digraphs::digraph> (); + g->set_description ("Optimization Passes"); + +#define DEF_PASS_LIST(NAME) \ + add_top_level_pass_list (*g, #NAME, m_pass_manager.NAME); + + GCC_PASS_LISTS + +#undef DEF_PASS_LIST + + return g; + } + + void + add_top_level_pass_list (diagnostics::digraphs::digraph &g, + const char *pass_list_name, + const opt_pass *p) const + { + gcc_assert (p); + auto n = std::make_unique<diagnostics::digraphs::node> (g, pass_list_name); + n->set_label (pass_list_name); + add_child_pass (g, *n, *p); + g.add_node (std::move (n)); + } + + diagnostics::digraphs::node & + add_child_pass (diagnostics::digraphs::digraph &g, + diagnostics::digraphs::node &parent_node, + const opt_pass &p) const + { + std::string node_label; + std::string node_id; + if (p.static_pass_number > 0 ) + { + node_label = std::to_string (p.static_pass_number) + "_" + p.name; + node_id = node_label; + } + else + { + node_label = std::string (p.name); + pretty_printer pp; + pp_printf (&pp, "%s_%p", p.name, &p); + node_id = pp_formatted_text (&pp); + } + auto n + = std::make_unique<diagnostics::digraphs::node> (g, + std::move (node_id)); + n->set_label (node_label.c_str ()); + diagnostics::digraphs::node &result = *n; + parent_node.add_child (std::move (n)); + + // TODO: add attrs for things like type, properties_*, etc + + if (p.sub) + { + auto &other_node = add_child_pass (g, parent_node, *p.sub); + g.add_edge (nullptr, result, other_node, "sub"); + } + + if (p.next) + { + auto &other_node = add_child_pass (g, parent_node, *p.next); + g.add_edge (nullptr, result, other_node, "next"); + } + + return result; + } + +private: + const ::gcc::pass_manager &m_pass_manager; +}; + +static void +report_diag_with_graphs (location_t loc) +{ + class my_lazy_digraphs : public diagnostics::digraphs::lazy_digraphs + { + public: + using diagnostic_graph = diagnostics::digraphs::digraph; + using diagnostic_node = diagnostics::digraphs::node; + using diagnostic_edge = diagnostics::digraphs::edge; + + std::unique_ptr<std::vector<std::unique_ptr<diagnostic_graph>>> + create_digraphs () const final override + { + auto graphs + = std::make_unique<std::vector<std::unique_ptr<diagnostic_graph>>> (); + + graphs->push_back (make_test_graph ("foo")); + graphs->push_back (make_test_graph ("bar")); + + return graphs; + } + + private: + std::unique_ptr<diagnostic_graph> + make_test_graph (const char *desc) const + { + auto g = std::make_unique<diagnostic_graph> (); + g->set_description (desc); + auto a = std::make_unique<diagnostic_node> (*g, "a"); + auto b = std::make_unique<diagnostic_node> (*g, "b"); +#define KEY_PREFIX "/placeholder-prefix/" + b->set_attr (KEY_PREFIX, "color", "red"); +#undef KEY_PREFIX + auto c = std::make_unique<diagnostic_node> (*g, "c"); + c->set_label ("I am a node label"); + + auto e = std::make_unique<diagnostic_edge> (*g, "my-edge", *a, *c); + e->set_label ("I am an edge label"); + g->add_edge (std::move (e)); + + g->add_node (std::move (a)); + + b->add_child (std::move (c)); + g->add_node (std::move (b)); + + return g; + } + }; + + gcc_rich_location rich_loc (loc); + diagnostic_metadata meta; + my_lazy_digraphs ldg; + meta.set_lazy_digraphs (&ldg); + error_meta (&rich_loc, meta, + "this is a placeholder error, with graphs"); +} + +/* Exercise diagnostic graph emission. */ + +unsigned int +pass_test_graph_emission::execute (function *fun) +{ + gimple_stmt_iterator gsi; + basic_block bb; + + FOR_EACH_BB_FN (bb, fun) + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + + if (gcall *call = check_for_named_call (stmt, "here", 0)) + report_diag_with_graphs (gimple_location (call)); + } + + return 0; +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + struct register_pass_info pass_info; + const char *plugin_name = plugin_info->base_name; + int argc = plugin_info->argc; + struct plugin_argument *argv = plugin_info->argv; + + if (!plugin_default_version_check (version, &gcc_version)) + return 1; + + pass_info.pass = new pass_test_graph_emission (g); + pass_info.reference_pass_name = "ssa"; + pass_info.ref_pass_instance_number = 1; + pass_info.pos_op = PASS_POS_INSERT_AFTER; + register_callback (plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, + &pass_info); + + gcc_assert (::g->get_passes ()); + global_dc->report_global_digraph (lazy_passes_graph (*::g->get_passes ())); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index d1d7f5d..ce25c0a 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -107,6 +107,10 @@ set plugin_test_list [list \ diagnostic-test-metadata.c \ diagnostic-test-metadata-html.c \ diagnostic-test-metadata-sarif.c } \ + { diagnostic_plugin_test_graphs.cc + diagnostic-test-graphs.c \ + diagnostic-test-graphs-html.c \ + diagnostic-test-graphs-sarif.c } \ { diagnostic_plugin_test_nesting.cc \ diagnostic-test-nesting-text-plain.c \ diagnostic-test-nesting-text-indented.c \ diff --git a/gcc/testsuite/gcc.dg/pr87600-1.c b/gcc/testsuite/gcc.dg/pr87600-1.c index 3517957..9d74cad 100644 --- a/gcc/testsuite/gcc.dg/pr87600-1.c +++ b/gcc/testsuite/gcc.dg/pr87600-1.c @@ -1,5 +1,5 @@ /* PR rtl-optimization/87600 */ -/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* loongarch*-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ /* { dg-options "-O2" } */ #include "pr87600.h" diff --git a/gcc/testsuite/gcc.dg/pr87600-2.c b/gcc/testsuite/gcc.dg/pr87600-2.c index e8a9f19..808ebe1 100644 --- a/gcc/testsuite/gcc.dg/pr87600-2.c +++ b/gcc/testsuite/gcc.dg/pr87600-2.c @@ -1,5 +1,5 @@ /* PR rtl-optimization/87600 */ -/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* loongarch*-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ /* { dg-options "-O2" } */ #include "pr87600.h" diff --git a/gcc/testsuite/gcc.dg/pr87600.h b/gcc/testsuite/gcc.dg/pr87600.h index c89071eb..29f065e 100644 --- a/gcc/testsuite/gcc.dg/pr87600.h +++ b/gcc/testsuite/gcc.dg/pr87600.h @@ -7,6 +7,9 @@ #elif defined (__i386__) # define REG1 "%eax" # define REG2 "%edx" +#elif defined (__loongarch__) +# define REG1 "$t0" +# define REG2 "$t1" #elif defined (__powerpc__) || defined (__POWERPC__) || defined (__PPC__) # define REG1 "r3" # define REG2 "r4" diff --git a/gcc/testsuite/gcc.dg/tree-prof/afdo-inline.c b/gcc/testsuite/gcc.dg/tree-prof/afdo-inline.c index b67b3cb..ded4068 100644 --- a/gcc/testsuite/gcc.dg/tree-prof/afdo-inline.c +++ b/gcc/testsuite/gcc.dg/tree-prof/afdo-inline.c @@ -1,6 +1,15 @@ /* { dg-options "-O2 -fdump-tree-einline-details --param early-inlining-insns=1" } */ /* { dg-require-profiling "-fauto-profile" } */ volatile int a[1000]; + +#define STR1(X) #X +#define STR2(X) STR1(X) + +int reta (int i) +asm(STR2(__USER_LABEL_PREFIX__) "renamed_reta"); +int test () +asm(STR2(__USER_LABEL_PREFIX__) "renamed_test"); + int reta (int i) { if (a[i]) diff --git a/gcc/testsuite/gcc.dg/vect/pr121034.c b/gcc/testsuite/gcc.dg/vect/pr121034.c new file mode 100644 index 0000000..de20781 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr121034.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O3" } */ + +int b, e; +char c, d; +unsigned g; +int abs(int); +void f() { + char *a = &d; + int h; + for (; e; e++) { + h = 0; + for (; h < 16; h++) + g += __builtin_abs(a[h] - c); + a += b; + } +} diff --git a/gcc/testsuite/gcc.target/aarch64/simd/bcax_d.c b/gcc/testsuite/gcc.target/aarch64/simd/bcax_d.c new file mode 100644 index 0000000..a7640c3 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/simd/bcax_d.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include <arm_neon.h> + +#pragma GCC target "+sha3" + +#define BCAX(x,y,z) ((x) ^ ((y) & ~(z))) + +/* When the inputs come from GP regs don't form a BCAX. */ +uint64_t bcax_d_gp (uint64_t a, uint64_t b, uint64_t c) { return BCAX (a, b, c); } + +uint64x1_t bcax_d (uint64x1_t a, uint64x1_t b, uint64x1_t c) { return BCAX (a, b, c); } +uint32x2_t bcax_s (uint32x2_t a, uint32x2_t b, uint32x2_t c) { return BCAX (a, b, c); } +uint16x4_t bcax_h (uint16x4_t a, uint16x4_t b, uint16x4_t c) { return BCAX (a, b, c); } +uint8x8_t bcax_b (uint8x8_t a, uint8x8_t b, uint8x8_t c) { return BCAX (a, b, c); } + +/* { dg-final { scan-assembler-times {bcax\tv0.16b, v0.16b, v1.16b, v2.16b} 4 } } */ + diff --git a/gcc/testsuite/gcc.target/aarch64/simd/eor3_d.c b/gcc/testsuite/gcc.target/aarch64/simd/eor3_d.c new file mode 100644 index 0000000..6c9595b --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/simd/eor3_d.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include <arm_neon.h> + +#pragma GCC target "+sha3" + +#define EOR3(x,y,z) ((x) ^ (y) ^ (z)) + +/* Should not use EOR3 when inputs come from GP regs. */ +uint64_t eor3_d_gp (uint64_t a, uint64_t b, uint64_t c) { return EOR3 (a, b, c); } + +uint64x1_t eor3_d (uint64x1_t a, uint64x1_t b, uint64x1_t c) { return EOR3 (a, b, c); } +uint32x2_t bcax_s (uint32x2_t a, uint32x2_t b, uint32x2_t c) { return EOR3 (a, b, c); } +uint16x4_t bcax_h (uint16x4_t a, uint16x4_t b, uint16x4_t c) { return EOR3 (a, b, c); } +uint8x8_t bcax_b (uint8x8_t a, uint8x8_t b, uint8x8_t c) { return EOR3 (a, b, c); } + +/* { dg-final { scan-assembler-times {eor3\tv0.16b, v[0-9]+.16b, v[0-9]+.16b, v[0-9]+.16b} 4 } } */ + diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/perm_1.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/perm_1.c new file mode 100644 index 0000000..6b920b8 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/perm_1.c @@ -0,0 +1,14 @@ +/* { dg-options "-O2 -msve-vector-bits=256" } */ + +#include <arm_sve.h> +typedef svbfloat16_t vls_bfloat16_t __attribute__((arm_sve_vector_bits(32 * 8))); +svbfloat16_t foo(vls_bfloat16_t a, vls_bfloat16_t b) +{ + svbfloat16_t zero = svreinterpret_bf16_f32 (svdup_n_f32 (0.0f)); + return svzip2_bf16(zero, svuzp1_bf16(a,b)); +} + + +/* { dg-final { scan-assembler-times {\tuzp1\t} 1 } } */ +/* { dg-final { scan-assembler-times {\tzip2\t} 1 } } */ +/* { dg-final { scan-assembler-not {\ttbl\t} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary.c index a8fd4c8..4708d57 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_int_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_int_opt_n.c index 08cd6a0..4530b18 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_int_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_int_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_opt_n.c index f5c9cbf..3097459 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_opt_single_n.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_opt_single_n.c index 91ae3c8..5e9d21c 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_opt_single_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_opt_single_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_rotate.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_rotate.c index 12368ce..768a740 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_rotate.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_rotate.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_uint64_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_uint64_opt_n.c index dd52a58..ce14abb 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_uint64_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_uint64_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_uint_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_uint_opt_n.c index e55ddfb..ceeb5ae 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_uint_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binary_uint_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binaryxn.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binaryxn.c index 6796229..f8b6b82 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binaryxn.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-binaryxn.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-clast.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-clast.c index 7f2ec4a..45f74ed 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-clast.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-clast.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-compare_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-compare_opt_n.c index d18427b..fc601a1 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-compare_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-compare_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-compare_wide_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-compare_wide_opt_n.c index 983ab5c..4959f1d 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-compare_wide_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-compare_wide_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-count_pred.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-count_pred.c index de36b66..d8a8a81 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-count_pred.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-count_pred.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-fold_left.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-fold_left.c index 333140d..6cf2683 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-fold_left.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-fold_left.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load.c index 93d6693..a32b636 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext.c index c88686a..72e743b 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext_gather_index.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext_gather_index.c index 5f4b562fc..1178104 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext_gather_index.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext_gather_index.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext_gather_offset.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext_gather_offset.c index 0fe8ab3..ebd313a 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext_gather_offset.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_ext_gather_offset.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_gather_sv.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_gather_sv.c index 758f00f..d531987 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_gather_sv.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_gather_sv.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_gather_vs.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_gather_vs.c index f82471f..55c9cef 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_gather_vs.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_gather_vs.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_replicate.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_replicate.c index ba500b6..5532232 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_replicate.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-load_replicate.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2 -march=armv8.2-a+sve+f64mm" } */ +/* { dg-options "-O2 -march=armv8.2-a+sve+f64mm -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch.c index 71894c4..78bdb0b 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch_gather_index.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch_gather_index.c index 1b7cc42..e219007 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch_gather_index.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch_gather_index.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch_gather_offset.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch_gather_offset.c index 7f4ff2d..98897e9 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch_gather_offset.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-prefetch_gather_offset.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ptest.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ptest.c index 0a587fc..c6fe6b9 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ptest.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ptest.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-rdffr.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-rdffr.c index d795f8e..7e2c1b9 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-rdffr.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-rdffr.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-reduction.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-reduction.c index 42b37ae..f7f75f6 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-reduction.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-reduction.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* { dg-options "-O2 -fdump-tree-optimized -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-reduction_wide.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-reduction_wide.c index bd9a980..54b6197 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-reduction_wide.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-reduction_wide.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-shift_right_imm.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-shift_right_imm.c index 62a0755..e8b8a55 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-shift_right_imm.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-shift_right_imm.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store.c index 751e60e..1539f58 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store_scatter_index.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store_scatter_index.c index 44792d3..21c8f6b 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store_scatter_index.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store_scatter_index.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store_scatter_offset.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store_scatter_offset.c index f3820e0..a908289 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store_scatter_offset.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-store_scatter_offset.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-storexn.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-storexn.c index e49266d..12b5e14 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-storexn.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-storexn.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ternary_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ternary_opt_n.c index acdd141..89873fc 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ternary_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ternary_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ternary_rotate.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ternary_rotate.c index 7698045..c6d2cfb 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ternary_rotate.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-ternary_rotate.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary.c index 037376b..8a3b3e0 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_convert_narrowt.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_convert_narrowt.c index 1287a70..04bc049 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_convert_narrowt.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_convert_narrowt.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2 -march=armv8.2-a+sve+bf16" } */ +/* { dg-options "-O2 -march=armv8.2-a+sve+bf16 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_convertxn.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_convertxn.c index f519266..f39d2c5 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_convertxn.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_convertxn.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2 -march=armv8.2-a+sve+bf16" } */ +/* { dg-options "-O2 -march=armv8.2-a+sve+bf16 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_n.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_n.c index fabde3e..4403e50 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_pred.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_pred.c index 46c9592..f06b067 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_pred.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_pred.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_to_uint.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_to_uint.c index b820bde..a851c4a 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_to_uint.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unary_to_uint.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unaryxn.c b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unaryxn.c index 1e99b7f..dde812b 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unaryxn.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pfalse-unaryxn.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary.c index 94470a5..977fa39 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_int_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_int_opt_n.c index b8747b8..b816fa1 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_int_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_int_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_int_opt_single_n.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_int_opt_single_n.c index 7cb7ee5..0e4427a 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_int_opt_single_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_int_opt_single_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_opt_n.c index 787126f..81d0c82 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_opt_single_n.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_opt_single_n.c index 6b2b0a42..3920bdb 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_opt_single_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_opt_single_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2 -march=armv8.2-a+sve2+faminmax" } */ +/* { dg-options "-O2 -march=armv8.2-a+sve2+faminmax -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_to_uint.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_to_uint.c index a0a7f80..c7d10b3 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_to_uint.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_to_uint.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_uint_opt_n.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_uint_opt_n.c index c13db48..122fba7 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_uint_opt_n.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_uint_opt_n.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_wide.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_wide.c index 145b077..7f35859 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_wide.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-binary_wide.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-compare.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-compare.c index da175db..b079a56 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-compare.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-compare.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-binary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_ext_gather_index_restricted.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_ext_gather_index_restricted.c index c0476ce..14e77c00 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_ext_gather_index_restricted.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_ext_gather_index_restricted.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_ext_gather_offset_restricted.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_ext_gather_offset_restricted.c index f644024..b680548 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_ext_gather_offset_restricted.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_ext_gather_offset_restricted.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_gather_sv_restricted.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_gather_sv_restricted.c index a48a8a9..6d1a356 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_gather_sv_restricted.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_gather_sv_restricted.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_gather_vs.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_gather_vs.c index 1fc08a3..9cb4471 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_gather_vs.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-load_gather_vs.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-shift_left_imm_to_uint.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-shift_left_imm_to_uint.c index bd2c937..e57a650 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-shift_left_imm_to_uint.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-shift_left_imm_to_uint.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-shift_right_imm.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-shift_right_imm.c index f4994de..710ca73 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-shift_right_imm.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-shift_right_imm.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-store_scatter_index_restricted.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-store_scatter_index_restricted.c index 6bec3b3..dc9cf46 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-store_scatter_index_restricted.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-store_scatter_index_restricted.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-store_scatter_offset_restricted.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-store_scatter_offset_restricted.c index bcb4a14..2728c9b 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-store_scatter_offset_restricted.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-store_scatter_offset_restricted.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary.c index ba7e931..9f33295 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2 -march=armv9.2-a+sve+sme" } */ +/* { dg-options "-O2 -march=armv9.2-a+sve+sme -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_convert.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_convert.c index 7aa59ff..68769fe 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_convert.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_convert.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_convert_narrowt.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_convert_narrowt.c index 1a4525c..692891f 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_convert_narrowt.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_convert_narrowt.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include <arm_sve.h> diff --git a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_to_int.c b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_to_int.c index b64bfc3..7dffa1c 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_to_int.c +++ b/gcc/testsuite/gcc.target/aarch64/sve2/pfalse-unary_to_int.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-require-effective-target elf } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 -funwind-tables" } */ #include "../pfalse-unary_0.h" diff --git a/gcc/testsuite/gcc.target/i386/pr91384-1.c b/gcc/testsuite/gcc.target/i386/pr91384-1.c new file mode 100644 index 0000000..4f8823d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr91384-1.c @@ -0,0 +1,20 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-O2 -mapxf" } */ + +void foo (void); +void bar (void); + +int +test (int a) +{ + int r; + + if (r = -a) + foo (); + else + bar (); + + return r; +} + +/* { dg-final { scan-assembler-not "testl" } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/pr121007.c b/gcc/testsuite/gcc.target/powerpc/pr121007.c new file mode 100644 index 0000000..9e6b1be --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr121007.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ + +typedef struct { int a; } A; +unsigned char *a; +char b; +int c; +void foo (vector char, vector char, vector char); + +void +bar (long stride) +{ + vector char v0, v1, v2, v3, v5; + vector char r0 = __builtin_vec_vsx_ld (0, a); + vector char r2 = __builtin_vec_vsx_ld (2 * stride, a - 3); + vector char r3 = __builtin_vec_vsx_ld (3 * stride, a - 3); + vector char r4; + vector char r6 = __builtin_vec_vsx_ld (6 * stride, a - 3); + vector char r7 = __builtin_vec_vsx_ld (7 * stride, a - 3); + vector char r14, h, i, j; + if (b) + return; + v1 = __builtin_vec_vsx_ld (9 * stride, a); + v2 = __builtin_vec_vsx_ld (10 * stride, a - 3); + v3 = __builtin_vec_vsx_ld (11 * stride, a - 3); + r3 = __builtin_vec_mergeh (r3, v3); + v5 = __builtin_vec_mergel (r2, r6); + r14 = __builtin_vec_mergeh (r3, r7); + r4 = __builtin_vec_mergeh (v2, r14); + v0 = __builtin_vec_mergeh (r0, r4); + union { unsigned char a[16]; A b; } temp; + vector signed char k; + h = __builtin_vec_ld (0, temp.a); + i = __builtin_vec_splat (h, 1); + temp.b.a = c; + k = __builtin_vec_ld (0, (signed char *) temp.a); + j = __builtin_vec_and (i, (vector char) k); + foo (v1, v0, j); + foo (v1, v5, j); +} diff --git a/gcc/testsuite/gfortran.dg/asan/array_constructor_1.f90 b/gcc/testsuite/gfortran.dg/asan/array_constructor_1.f90 index 45eafac..a0c5507 100644 --- a/gcc/testsuite/gfortran.dg/asan/array_constructor_1.f90 +++ b/gcc/testsuite/gfortran.dg/asan/array_constructor_1.f90 @@ -9,6 +9,8 @@ program grow_type_array type(container), allocatable :: list(:) + allocate(list(0)) + list = [list, new_elem(5)] deallocate(list) diff --git a/gcc/testsuite/gfortran.dg/goacc/parameter-3.f90 b/gcc/testsuite/gfortran.dg/goacc/parameter-3.f90 new file mode 100644 index 0000000..2c8aa61 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/parameter-3.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } + +subroutine x + integer :: var + integer, parameter :: ilog = 0 + integer, parameter :: array(*) = [11,22,33] + !$ACC DECLARE COPYIN(ilog, array, var, array) ! { dg-error "Symbol 'array' present on multiple clauses" } +end subroutine x + +integer :: a +integer, parameter :: b = 4 +integer, parameter :: c(*) = [1,2,3] + +!$acc parallel copy(a,c,b,c) ! { dg-error "Symbol 'c' present on multiple clauses" } +!$acc end parallel +end diff --git a/gcc/testsuite/gfortran.dg/goacc/parameter-4.f90 b/gcc/testsuite/gfortran.dg/goacc/parameter-4.f90 new file mode 100644 index 0000000..aadd7cf --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/parameter-4.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } +! { dg-additional-options "-fdump-tree-original" } + +subroutine x + integer :: var + integer, parameter :: ilog = 0 + integer, parameter :: array(*) = [11,22,33] + !$ACC DECLARE COPYIN(ilog, array, var) +end subroutine x + +integer :: a +integer, parameter :: b = 4 +integer, parameter :: c(*) = [1,2,3] + +!$acc parallel copy(a,c,b) + a = c(2) + b +!$acc end parallel + +!$acc parallel firstprivate(a,c,b) + a = c(2) + b +!$acc end parallel +end + +! { dg-final { scan-tree-dump-times "#pragma acc data map\\(to:var\\)" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma acc parallel map\\(tofrom:a\\)" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma acc parallel firstprivate\\(a\\)" 1 "original" } } diff --git a/gcc/testsuite/gfortran.dg/goacc/parameter.f95 b/gcc/testsuite/gfortran.dg/goacc/parameter.f95 index b581338..a9bde4a 100644 --- a/gcc/testsuite/gfortran.dg/goacc/parameter.f95 +++ b/gcc/testsuite/gfortran.dg/goacc/parameter.f95 @@ -1,4 +1,5 @@ ! { dg-do compile } +! { dg-additional-options "-Wsurprising" } module test contains @@ -6,37 +7,37 @@ contains implicit none integer :: i integer, parameter :: a = 1 - !$acc declare device_resident (a) ! { dg-error "is not a variable" } - !$acc data copy (a) ! { dg-error "not a variable" } + !$acc declare device_resident (a) ! (no warning here - for semi-good reasons) + !$acc data copy (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as parameters need not be copied \\\[-Wsurprising\\\]" } !$acc end data - !$acc data deviceptr (a) ! { dg-error "not a variable" } + !$acc data deviceptr (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as parameters need not be copied \\\[-Wsurprising\\\]" } !$acc end data - !$acc parallel private (a) ! { dg-error "not a variable" } + !$acc parallel private (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as it is a parameter \\\[-Wsurprising\\\]" } !$acc end parallel - !$acc serial private (a) ! { dg-error "not a variable" } + !$acc serial private (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as it is a parameter \\\[-Wsurprising\\\]" } !$acc end serial - !$acc host_data use_device (a) ! { dg-error "not a variable" } + !$acc host_data use_device (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as it is a parameter \\\[-Wsurprising\\\]" } !$acc end host_data - !$acc parallel loop reduction(+:a) ! { dg-error "not a variable" } + !$acc parallel loop reduction(+:a) ! { dg-warning "Clause for object 'a' at .1. is ignored as it is a parameter \\\[-Wsurprising\\\]" } do i = 1,5 enddo !$acc end parallel loop - !$acc serial loop reduction(+:a) ! { dg-error "not a variable" } + !$acc serial loop reduction(+:a) ! { dg-warning "Clause for object 'a' at .1. is ignored as it is a parameter \\\[-Wsurprising\\\]" } do i = 1,5 enddo !$acc end serial loop !$acc parallel loop do i = 1,5 - !$acc cache (a) ! { dg-error "not a variable" } + !$acc cache (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as it is a parameter \\\[-Wsurprising\\\]" } enddo !$acc end parallel loop !$acc serial loop do i = 1,5 - !$acc cache (a) ! { dg-error "not a variable" } + !$acc cache (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as it is a parameter \\\[-Wsurprising\\\]" } enddo !$acc end serial loop - !$acc update device (a) ! { dg-error "not a variable" } - !$acc update host (a) ! { dg-error "not a variable" } - !$acc update self (a) ! { dg-error "not a variable" } + !$acc update device (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as parameters need not be copied \\\[-Wsurprising\\\]" } + !$acc update host (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as parameters need not be copied \\\[-Wsurprising\\\]" } + !$acc update self (a) ! { dg-warning "Clause for object 'a' at .1. is ignored as parameters need not be copied \\\[-Wsurprising\\\]" } end subroutine oacc1 end module test diff --git a/gcc/testsuite/gfortran.dg/import12.f90 b/gcc/testsuite/gfortran.dg/import12.f90 new file mode 100644 index 0000000..df1aae6 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/import12.f90 @@ -0,0 +1,302 @@ +! { dg-do compile } +! +! Tests the variants of IMPORT introduced in F2018 +! +! Contributed by Paul Thomas <pault@gcc.gnu.org> +! +MODULE M + import, none ! { dg-error "F2018: C897 IMPORT statement" } + IMPLICIT NONE + integer :: z +end module + +MODULE N + IMPLICIT NONE + integer :: z +end module + +! Taken from gfortran.dg/pr103312.f90. These F2008-style invocations should +! be accepted. +module example + type, abstract :: foo + integer :: i + contains + procedure(foo_size), deferred :: size + procedure(foo_func), deferred :: func + end type + abstract interface + pure integer function foo_size (this) + import :: foo + class(foo), intent(in) :: this + end function + function foo_func (this) result (string) + import :: foo + class(foo) :: this + character(this%size()) :: string + end function + end interface +end module + +block data blk + import, all ! { dg-error "F2018: C897 IMPORT statement" } + integer a(2) + common /my_common/a + data a/1,2/ +end + +subroutine extern_sub1 + import ! { dg-error "F2018: C897 IMPORT statement" } +end + +subroutine extern_sub2 (arg1, arg2, arg3) + implicit none + integer :: arg1, arg2, arg3 + arg1 = int_fcn () +contains + integer function int_fcn () + import, only : arg2, arg3 + int_fcn = arg2 * arg3 + end +end + +program p + import, all ! { dg-error "F2018: C897 IMPORT statement" } + implicit none + integer :: x, y + type :: t + integer :: i + end type + type(t) :: progtype + type, extends(t) :: s + integer :: j + end type + class(t), allocatable :: progclass +contains + +! OK because arg is just that and x is declared in scope of sub1. + subroutine sub1 (arg) + import, none + implicit none + real :: arg, x + end + +! IMPORT, ALL must be the only IMPORT statement in the scope. + subroutine sub2 (arg) + import, none + import, all ! { dg-error "F2018: C8100 IMPORT statement" } + implicit none + real :: arg, x + end + +! Error message says it all. + subroutine sub3 (arg) + import, none + implicit none + integer :: arg + print *, arg + x = 1 ! { dg-error "F2018: C8102" } + end + +! Error messages say it all. + subroutine sub4 (arg) + import, only : y + implicit none + integer :: arg + print *, arg + x = 1 ! { dg-error "F2018: C8102" } + y = 2 + print *, x ! { dg-error "F2018: C8102" } + end + +! IMPORT eos and IMPORT, ALL must be unique in the scope. + subroutine sub5a (arg) + import, all + import ! { dg-error "F2018: C8100" } + implicit none + real :: arg + real :: x ! { dg-error "F2018: C8102" } + end + + subroutine sub5b (arg) + import, only : x + implicit none + real :: arg + real :: x ! { dg-error "F2018: C8102" } + end + +! Error message says it all. + integer function func1 () + import, only : x + func1 = x * y ! { dg-error "F2018: C8102" } + end + +! Error messages say it all. + subroutine sub6 (arg) + import, only : func1 + import, only : func2 + import, only : foobar ! { dg-error "has no IMPLICIT type" } + implicit none + integer :: arg + arg = func1 () * func2 () * func3 () ! { dg-error "F2018: C8102" } + end + +! Error message says it all. + integer function func2 () + use N + import, none + implicit none + func2 = y ! { dg-error "F2018: C8102" } + end + +! OK + integer function func3 () + func3 = 42 + end + + subroutine sub7 (arg) + implicit none + integer :: arg +! OK + block + import, only : arg, func1, func2, func3 + arg = func1 () * func2 () * func3 () + end block + block + arg = func1 () + import, only : arg, func1 ! { dg-error "Unexpected IMPORT statement" } + end block + end + +! Error messages say it all. + subroutine sub8 (arg) + implicit none + integer :: arg + block + import, only : func1 + import, only : func2 + import, only : foobar ! { dg-error "has no IMPLICIT type" } + arg = func1 () * func2 () * func3 () ! { dg-error "F2018: C8102" } + end block + end + +! ASSOCIATE does not have a specification part so IMPORT cannot appear. + subroutine sub9 (arg) + implicit none + integer :: arg + associate (f3 => func3 ()) ! { dg-error "F2018: C8102" } + import, only : arg, func1 ! { dg-error "Unexpected IMPORT statement" } + arg = func1 () * func2 () * f3 ! { dg-error "F2018: C8102" } + end associate + end + +! OK + subroutine sub10 (arg) + import, only : t + implicit none + type(t) :: arg, mytype + mytype%i = 1 + arg = mytype + end + +! TYPE t does not appear in the IMPORT list + subroutine sub11 (arg) + import, only : progtype + implicit none + type(t) :: arg + progtype%i = 1 ! { dg-error "F2018: C8102" } + arg = progtype ! { dg-error "F2018: C8102" } + end + +! TYPE t is excluded by IMPORT, NONE + subroutine sub12 (arg) + import, none + implicit none + type(t) :: arg, mytype + mytype%i = 1 ! { dg-error "F2018: C8102" } + arg = mytype ! { dg-error "F2018: C8102" } + end + +! TYPE t does not appear in the IMPORT list + subroutine sub13 (arg) + import, only : progclass + implicit none + class(t) :: arg + type(t) :: ca(2) = [t(1), t(2)] ! { dg-error "F2018: C8102" } + progclass%i = t(1) ! { dg-error "F2018: C8102" } + arg = progclass ! { dg-error "F2018: C8102" } + ca = [t(1), t(2)] ! { dg-error "has no IMPLICIT type|F2018: C8102" } + arg = ca(2) ! Note: The preceeding line catches 'ca' having no implicit type. + end + +! TYPE t is excluded by IMPORT, NONE + subroutine sub14 (arg) + import, none + implicit none + class(t) :: arg + class(t), allocatable :: myclass + myclass%i = t(1) ! { dg-error "F2018: C8102" } + arg%i = myclass%i ! { dg-error "F2018: C8102" } + select type (arg) ! { dg-error "F2018: C8102" } + type is (t) + arg%i = arg%i + 1 + type is (s) + arg%j = -1 + end select + end + +! TYPE s does not appear in the IMPORT, ONLY list + subroutine sub15 (arg) + import, only : t + implicit none + class(t) :: arg + class(t), allocatable :: myclass + myclass = t(1) + arg%i = myclass%i + select type (arg) ! { dg-error "F2018: C8102" } + type is (t) + arg%i = arg%i + 1 + type is (s) + arg%j = -1 ! s is caught at the SELECT TYPE statement + end select + end + +! This is OK + subroutine sub16 (arg) + import, only : t, s + implicit none + class(t) :: arg + class(t), allocatable :: myclass + myclass = t(1) + arg%i = myclass%i + select type (arg) + type is (t) + arg%i = arg%i + 1 + type is (s) + arg%j = -1 + end select + end + + subroutine sub17 (arg) + import, only : t + implicit none + class(t) :: arg + call sub16 (arg) ! { dg-error "F2018: C8102" } + end + +! Make sure that recursive procedures do not require the procedure itself to be imported. + recursive subroutine sub18 (arg) + import, none + implicit none + integer :: arg + if (arg <= 0) call sub18 (arg) + arg = 1 + end + + recursive integer function func4 (arg) result (res) + import, none + implicit none + integer :: arg + if (arg <= 0) arg = func4 (arg) + res = 1 + end +end diff --git a/gcc/testsuite/gfortran.dg/import3.f90 b/gcc/testsuite/gfortran.dg/import3.f90 index 74cd527..9288c6b 100644 --- a/gcc/testsuite/gfortran.dg/import3.f90 +++ b/gcc/testsuite/gfortran.dg/import3.f90 @@ -1,6 +1,8 @@ ! { dg-do compile } +! { dg-options "-std=f2008" } ! { dg-shouldfail "Invalid use of IMPORT" } ! Test invalid uses of import +! Wording of some error messages change for -std>=F2018 but all are caught. ! PR fortran/29601 subroutine test() diff --git a/gcc/testsuite/lib/sarif.py b/gcc/testsuite/lib/sarif.py index 384de2f..06d05c0 100644 --- a/gcc/testsuite/lib/sarif.py +++ b/gcc/testsuite/lib/sarif.py @@ -29,10 +29,24 @@ def get_result_by_index(sarif, idx): results = run['results'] return results[idx] -def get_xml_state(events, event_idx): - xml_src = events[event_idx]['properties']['gcc/diagnostic_event/xml_state'] +def get_state_graph(events, event_idx): + graph = events[event_idx]['properties']['gcc/diagnostic_event/state_graph'] if 0: - print(xml_src) - xml = ET.fromstring(xml_src) - assert xml.tag == 'state-diagram' - return xml + print(graph) + assert graph is not None + return graph + +def get_state_node_attr(obj, attr_name): + return obj['properties']['gcc/diagnostic_state_node/%s' % attr_name] + +def get_state_node_kind(obj): + return get_state_node_attr(obj, 'kind') + +def get_state_node_name(obj): + return get_state_node_attr(obj, 'name') + +def get_state_node_type(obj): + return get_state_node_attr(obj, 'type') + +def get_state_node_value(obj): + return get_state_node_attr(obj, 'value') diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-invalid/3.40.2-duplicate-node-id.sarif b/gcc/testsuite/sarif-replay.dg/2.1.0-invalid/3.40.2-duplicate-node-id.sarif new file mode 100644 index 0000000..a4eb9d4 --- /dev/null +++ b/gcc/testsuite/sarif-replay.dg/2.1.0-invalid/3.40.2-duplicate-node-id.sarif @@ -0,0 +1,23 @@ +{"$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json", + "version": "2.1.0", + "runs": [{"tool": { "driver": { "name": "example" } }, + "results": [], + "graphs": [{"nodes": [{"id": "a", /* { dg-message "'a' already used as node id within graph here" } */ + "children": [{"id": "a"}]}], /* { dg-error "duplicate node id 'a' within graph \\\[SARIF v2.1.0 §3.40.2\\\]" } */ + "edges": []}]}]} + +/* { dg-begin-multiline-output "" } +In JSON property '/runs/0/graphs/0/nodes/0/children/0/id': + { dg-end-multiline-output "" } */ +/* { dg-begin-multiline-output "" } + 6 | "children": [{"id": "a"}]}], + | ^~~ + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } +In JSON property '/runs/0/graphs/0/nodes/0/id': + { dg-end-multiline-output "" } */ +/* { dg-begin-multiline-output "" } + 5 | "graphs": [{"nodes": [{"id": "a", + | ^~~ + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-invalid/3.41.4-unrecognized-node-id.sarif b/gcc/testsuite/sarif-replay.dg/2.1.0-invalid/3.41.4-unrecognized-node-id.sarif new file mode 100644 index 0000000..b483346 --- /dev/null +++ b/gcc/testsuite/sarif-replay.dg/2.1.0-invalid/3.41.4-unrecognized-node-id.sarif @@ -0,0 +1,16 @@ +{"$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json", + "version": "2.1.0", + "runs": [{"tool": { "driver": { "name": "example" } }, + "results": [], + "graphs": [{"nodes": [], + "edges": [{"id": "edge0", + "sourceNodeId": "this-does-not-exist", /* { dg-error "no node with id 'this-does-not-exist' in graph \\\[SARIF v2.1.0 §3.41.4\\\]" } */ + "targetNodeId": "neither-does-this"}]}]}]} + +/* { dg-begin-multiline-output "" } +In JSON property '/runs/0/graphs/0/edges/0/sourceNodeId': + { dg-end-multiline-output "" } */ +/* { dg-begin-multiline-output "" } + 7 | "sourceNodeId": "this-does-not-exist", + | ^~~~~~~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/graphs-check-html.py b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/graphs-check-html.py new file mode 100644 index 0000000..63b80c9 --- /dev/null +++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/graphs-check-html.py @@ -0,0 +1,46 @@ +from htmltest import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def html_tree(): + return html_tree_from_env() + +def test_result_graph(html_tree): + root = html_tree.getroot () + assert root.tag == make_tag('html') + + body = root.find('xhtml:body', ns) + assert body is not None + + diag_list = body.find('xhtml:div', ns) + assert diag_list is not None + assert diag_list.attrib['class'] == 'gcc-diagnostic-list' + + diag = diag_list.find('xhtml:div', ns) + assert diag is not None + + message = diag.find("./xhtml:div[@class='gcc-message']", ns) + assert message.attrib['id'] == 'gcc-diag-0-message' + + assert message[0].tag == make_tag('strong') + assert message[0].tail == ' this is a placeholder error, with graphs ' + + graph = diag.find("./xhtml:div[@class='gcc-directed-graph']", ns) + assert graph is not None + + header = graph.find("./xhtml:h2", ns) + assert header.text == 'foo' + +def test_run_graph(html_tree): + root = html_tree.getroot () + assert root.tag == make_tag('html') + + body = root.find('xhtml:body', ns) + assert body is not None + + graph = body.find("./xhtml:div[@class='gcc-directed-graph']", ns) + assert graph is not None + + header = graph.find("./xhtml:h2", ns) + assert header.text == 'Optimization Passes' diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/graphs-check-sarif-roundtrip.py b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/graphs-check-sarif-roundtrip.py new file mode 100644 index 0000000..4bb7535 --- /dev/null +++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/graphs-check-sarif-roundtrip.py @@ -0,0 +1,55 @@ +from sarif import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def sarif(): + return sarif_from_env() + +def test_basics(sarif): + schema = sarif['$schema'] + assert schema == "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" + + version = sarif['version'] + assert version == "2.1.0" + +def test_result_graph(sarif): + runs = sarif['runs'] + run = runs[0] + results = run['results'] + + assert len(results) == 1 + + result = results[0] + assert result['level'] == 'error' + assert result['message']['text'] == "this is a placeholder error, with graphs" + + assert len(result['graphs']) == 2 + + assert result['graphs'][0]['description']['text'] == 'foo' + + assert len(result['graphs'][0]['nodes']) == 2 + assert result['graphs'][0]['nodes'][0]['id'] == 'a' + assert result['graphs'][0]['nodes'][1]['id'] == 'b' + assert result['graphs'][0]['nodes'][1]['properties']['/placeholder-prefix/color'] == 'red' + assert len(result['graphs'][0]['nodes'][1]['children']) == 1 + assert result['graphs'][0]['nodes'][1]['children'][0]['id'] == 'c' + assert result['graphs'][0]['nodes'][1]['children'][0]['label']['text'] == 'I am a node label' + + assert len(result['graphs'][0]['edges']) == 1 + result['graphs'][0]['edges'][0]['id'] == 'my-edge' + assert result['graphs'][0]['edges'][0]['label']['text'] == 'I am an edge label' + assert result['graphs'][0]['edges'][0]['sourceNodeId'] == 'a' + assert result['graphs'][0]['edges'][0]['targetNodeId'] == 'c' + + assert result['graphs'][1]['description']['text'] == 'bar' + +def test_run_graph(sarif): + runs = sarif['runs'] + run = runs[0] + + assert len(run['graphs']) == 1 + + assert run['graphs'][0]['description']['text'] == 'Optimization Passes' + assert run['graphs'][0]['nodes'][0]['id'] == 'all_lowering_passes' + assert run['graphs'][0]['edges'][0]['id'] == 'edge0' diff --git a/gcc/testsuite/sarif-replay.dg/2.1.0-valid/graphs.sarif b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/graphs.sarif new file mode 100644 index 0000000..da236ba --- /dev/null +++ b/gcc/testsuite/sarif-replay.dg/2.1.0-valid/graphs.sarif @@ -0,0 +1,2445 @@ +/* Test a replay of a .sarif file generated from GCC testsuite. + + The dg directives were stripped out from the generated .sarif + to avoid confusing DejaGnu for this test. */ +/* { dg-additional-options "-fdiagnostics-add-output=experimental-html:file=graphs.sarif.html,javascript=no" } */ +/* { dg-additional-options "-fdiagnostics-add-output=sarif:file=graphs.roundtrip.sarif" } */ + +{"$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json", + "version": "2.1.0", + "runs": [{"tool": {"driver": {"name": "GNU C23", + "fullName": "GNU C23 (GCC) version 16.0.0 20250702 (experimental) (x86_64-pc-linux-gnu)", + "version": "16.0.0 20250702 (experimental)", + "informationUri": "https://gcc.gnu.org/gcc-16/", + "rules": []}, + "extensions": [{"name": "diagnostic_plugin_test_graphs", + "fullName": "./diagnostic_plugin_test_graphs.so"}]}, + "invocations": [{"arguments": ["/home/david/gcc-newgit-gcc16/build/gcc/cc1", + "-quiet", + "-iprefix", + "/usr/local/lib/gcc/x86_64-pc-linux-gnu/16.0.0/", + "-isystem", + "/home/david/gcc-newgit-gcc16/build/gcc/include", + "-isystem", + "/home/david/gcc-newgit-gcc16/build/gcc/include-fixed", + "-iplugindir=/home/david/gcc-newgit-gcc16/build/gcc/plugin", + "/home/david/gcc-newgit-gcc16/src/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c", + "-iplugindir=/home/david/gcc-newgit-gcc16/build/gcc/plugin", + "-quiet", + "-dumpbase", + "diagnostic-test-graphs-sarif.c", + "-dumpbase-ext", + ".c", + "-mtune=generic", + "-march=x86-64", + "-fdiagnostics-color=never", + "-fdiagnostics-urls=never", + "-fno-diagnostics-show-caret", + "-fno-diagnostics-show-line-numbers", + "-fdiagnostics-path-format=separate-events", + "-fdiagnostics-text-art-charset=none", + "-fno-diagnostics-show-event-links", + "-fplugin=./diagnostic_plugin_test_graphs.so", + "-fdiagnostics-add-output=sarif", + "-o", + "diagnostic-test-graphs-sarif.s"], + "workingDirectory": {"uri": "/home/david/gcc-newgit-gcc16/build/gcc/testsuite/gcc"}, + "startTimeUtc": "2025-07-09T22:43:31Z", + "executionSuccessful": false, + "toolExecutionNotifications": [], + "endTimeUtc": "2025-07-09T22:43:31Z"}], + "artifacts": [{"location": {"uri": "/home/david/gcc-newgit-gcc16/src/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c"}, + "sourceLanguage": "c", + "roles": ["analysisTarget"]}], + "results": [{"ruleId": "error", + "level": "error", + "message": {"text": "this is a placeholder error, with graphs"}, + "locations": [{"physicalLocation": {"artifactLocation": {"uri": "/home/david/gcc-newgit-gcc16/src/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c"}, + "region": {"startLine": 8, + "startColumn": 3, + "endColumn": 10}, + "contextRegion": {"startLine": 8, + "snippet": {"text": " here ();"}}}, + "logicalLocations": [{"index": 0, + "fullyQualifiedName": "test_graphs"}]}], + "graphs": [{"description": {"text": "foo"}, + "nodes": [{"id": "a"}, + {"id": "b", + "properties": {"/placeholder-prefix/color": "red"}, + "children": [{"id": "c", + "label": {"text": "I am a node label"}}]}], + "edges": [{"id": "my-edge", + "label": {"text": "I am an edge label"}, + "sourceNodeId": "a", + "targetNodeId": "c"}]}, + {"description": {"text": "bar"}, + "nodes": [{"id": "a"}, + {"id": "b", + "properties": {"/placeholder-prefix/color": "red"}, + "children": [{"id": "c", + "label": {"text": "I am a node label"}}]}], + "edges": [{"id": "my-edge", + "label": {"text": "I am an edge label"}, + "sourceNodeId": "a", + "targetNodeId": "c"}]}]}], + "logicalLocations": [{"name": "test_graphs", + "fullyQualifiedName": "test_graphs", + "decoratedName": "test_graphs", + "kind": "function", + "index": 0}], + "graphs": [{"description": {"text": "Optimization Passes"}, + "nodes": [{"id": "all_lowering_passes", + "label": {"text": "all_lowering_passes"}, + "children": [{"id": "*warn_unused_result_0x101ef3d0", + "label": {"text": "*warn_unused_result"}}, + {"id": "*diagnose_omp_blocks_0x101ef430", + "label": {"text": "*diagnose_omp_blocks"}}, + {"id": "*diagnose_tm_blocks_0x101ef490", + "label": {"text": "*diagnose_tm_blocks"}}, + {"id": "13_omp_oacc_kernels_decompose", + "label": {"text": "13_omp_oacc_kernels_decompose"}}, + {"id": "14_omplower", + "label": {"text": "14_omplower"}}, + {"id": "15_lower", + "label": {"text": "15_lower"}}, + {"id": "16_tmlower", + "label": {"text": "16_tmlower"}}, + {"id": "17_ehopt", + "label": {"text": "17_ehopt"}}, + {"id": "18_eh", + "label": {"text": "18_eh"}}, + {"id": "19_coro-lower-builtins", + "label": {"text": "19_coro-lower-builtins"}}, + {"id": "20_cfg", + "label": {"text": "20_cfg"}}, + {"id": "*warn_function_return_0x101ef7f0", + "label": {"text": "*warn_function_return"}}, + {"id": "21_coro-early-expand-ifns", + "label": {"text": "21_coro-early-expand-ifns"}}, + {"id": "22_ompexp", + "label": {"text": "22_ompexp"}}, + {"id": "*build_cgraph_edges_0x101ef910", + "label": {"text": "*build_cgraph_edges"}}]}, + {"id": "all_small_ipa_passes", + "label": {"text": "all_small_ipa_passes"}, + "children": [{"id": "23_afdo_offline", + "label": {"text": "23_afdo_offline"}}, + {"id": "*free_lang_data_0x101ef9d0", + "label": {"text": "*free_lang_data"}}, + {"id": "24_visibility", + "label": {"text": "24_visibility"}}, + {"id": "25_strubm", + "label": {"text": "25_strubm"}}, + {"id": "26_build_ssa_passes", + "label": {"text": "26_build_ssa_passes"}}, + {"id": "27_fixup_cfg", + "label": {"text": "27_fixup_cfg"}}, + {"id": "28_ssa", + "label": {"text": "28_ssa"}}, + {"id": "376_test_graph_emission", + "label": {"text": "376_test_graph_emission"}}, + {"id": "29_walloca", + "label": {"text": "29_walloca"}}, + {"id": "30_warn-printf", + "label": {"text": "30_warn-printf"}}, + {"id": "*nonnullcmp_0x101efce0", + "label": {"text": "*nonnullcmp"}}, + {"id": "31_early_uninit", + "label": {"text": "31_early_uninit"}}, + {"id": "32_waccess", + "label": {"text": "32_waccess"}}, + {"id": "33_ubsan", + "label": {"text": "33_ubsan"}}, + {"id": "34_nothrow", + "label": {"text": "34_nothrow"}}, + {"id": "*rebuild_cgraph_edges_0x101f0020", + "label": {"text": "*rebuild_cgraph_edges"}}, + {"id": "35_opt_local_passes", + "label": {"text": "35_opt_local_passes"}}, + {"id": "36_fixup_cfg", + "label": {"text": "36_fixup_cfg"}}, + {"id": "*rebuild_cgraph_edges_0x101f0140", + "label": {"text": "*rebuild_cgraph_edges"}}, + {"id": "37_local-fnsummary", + "label": {"text": "37_local-fnsummary"}}, + {"id": "38_einline", + "label": {"text": "38_einline"}}, + {"id": "*infinite-recursion_0x101f0260", + "label": {"text": "*infinite-recursion"}}, + {"id": "39_early_optimizations", + "label": {"text": "39_early_optimizations"}}, + {"id": "*remove_cgraph_callee_edges_0x101f0340", + "label": {"text": "*remove_cgraph_callee_edges"}}, + {"id": "40_early_objsz", + "label": {"text": "40_early_objsz"}}, + {"id": "41_ccp", + "label": {"text": "41_ccp"}}, + {"id": "42_forwprop", + "label": {"text": "42_forwprop"}}, + {"id": "43_ethread", + "label": {"text": "43_ethread"}}, + {"id": "44_esra", + "label": {"text": "44_esra"}}, + {"id": "45_ealias", + "label": {"text": "45_ealias"}}, + {"id": "46_phiprop", + "label": {"text": "46_phiprop"}}, + {"id": "47_fre", + "label": {"text": "47_fre"}}, + {"id": "48_evrp", + "label": {"text": "48_evrp"}}, + {"id": "49_mergephi", + "label": {"text": "49_mergephi"}}, + {"id": "50_dse", + "label": {"text": "50_dse"}}, + {"id": "51_cddce", + "label": {"text": "51_cddce"}}, + {"id": "52_phiopt", + "label": {"text": "52_phiopt"}}, + {"id": "53_tailr", + "label": {"text": "53_tailr"}}, + {"id": "54_iftoswitch", + "label": {"text": "54_iftoswitch"}}, + {"id": "55_switchconv", + "label": {"text": "55_switchconv"}}, + {"id": "56_ehcleanup", + "label": {"text": "56_ehcleanup"}}, + {"id": "57_sccopy", + "label": {"text": "57_sccopy"}}, + {"id": "58_profile_estimate", + "label": {"text": "58_profile_estimate"}}, + {"id": "59_local-pure-const", + "label": {"text": "59_local-pure-const"}}, + {"id": "60_modref", + "label": {"text": "60_modref"}}, + {"id": "61_fnsplit", + "label": {"text": "61_fnsplit"}}, + {"id": "*strip_predict_hints_0x101f0c60", + "label": {"text": "*strip_predict_hints"}}, + {"id": "62_release_ssa", + "label": {"text": "62_release_ssa"}}, + {"id": "*rebuild_cgraph_edges_0x101f0d30", + "label": {"text": "*rebuild_cgraph_edges"}}, + {"id": "63_local-fnsummary", + "label": {"text": "63_local-fnsummary"}}, + {"id": "64_remove_symbols", + "label": {"text": "64_remove_symbols"}}, + {"id": "65_strub", + "label": {"text": "65_strub"}}, + {"id": "66_ipa_oacc", + "label": {"text": "66_ipa_oacc"}}, + {"id": "67_pta", + "label": {"text": "67_pta"}}, + {"id": "68_ipa_oacc_kernels", + "label": {"text": "68_ipa_oacc_kernels"}}, + {"id": "69_oacc_kernels", + "label": {"text": "69_oacc_kernels"}}, + {"id": "70_ch", + "label": {"text": "70_ch"}}, + {"id": "71_fre", + "label": {"text": "71_fre"}}, + {"id": "72_lim", + "label": {"text": "72_lim"}}, + {"id": "73_dom", + "label": {"text": "73_dom"}}, + {"id": "74_dce", + "label": {"text": "74_dce"}}, + {"id": "75_parloops", + "label": {"text": "75_parloops"}}, + {"id": "76_ompexpssa", + "label": {"text": "76_ompexpssa"}}, + {"id": "*rebuild_cgraph_edges_0x101f1310", + "label": {"text": "*rebuild_cgraph_edges"}}, + {"id": "77_targetclone", + "label": {"text": "77_targetclone"}}, + {"id": "78_afdo", + "label": {"text": "78_afdo"}}, + {"id": "79_feedback_fnsplit", + "label": {"text": "79_feedback_fnsplit"}}, + {"id": "80_profile", + "label": {"text": "80_profile"}}, + {"id": "81_feedback_fnsplit", + "label": {"text": "81_feedback_fnsplit"}}, + {"id": "82_free-fnsummary", + "label": {"text": "82_free-fnsummary"}}, + {"id": "83_increase_alignment", + "label": {"text": "83_increase_alignment"}}, + {"id": "84_tmipa", + "label": {"text": "84_tmipa"}}, + {"id": "85_emutls", + "label": {"text": "85_emutls"}}]}, + {"id": "all_regular_ipa_passes", + "label": {"text": "all_regular_ipa_passes"}, + "children": [{"id": "86_analyzer", + "label": {"text": "86_analyzer"}}, + {"id": "87_odr", + "label": {"text": "87_odr"}}, + {"id": "88_whole-program", + "label": {"text": "88_whole-program"}}, + {"id": "89_profile_estimate", + "label": {"text": "89_profile_estimate"}}, + {"id": "90_icf", + "label": {"text": "90_icf"}}, + {"id": "91_devirt", + "label": {"text": "91_devirt"}}, + {"id": "92_cdtor", + "label": {"text": "92_cdtor"}}, + {"id": "93_cp", + "label": {"text": "93_cp"}}, + {"id": "94_sra", + "label": {"text": "94_sra"}}, + {"id": "95_fnsummary", + "label": {"text": "95_fnsummary"}}, + {"id": "96_inline", + "label": {"text": "96_inline"}}, + {"id": "97_locality-clone", + "label": {"text": "97_locality-clone"}}, + {"id": "98_pure-const", + "label": {"text": "98_pure-const"}}, + {"id": "99_modref", + "label": {"text": "99_modref"}}, + {"id": "100_free-fnsummary", + "label": {"text": "100_free-fnsummary"}}, + {"id": "101_static-var", + "label": {"text": "101_static-var"}}, + {"id": "102_single-use", + "label": {"text": "102_single-use"}}, + {"id": "103_comdats", + "label": {"text": "103_comdats"}}]}, + {"id": "all_late_ipa_passes", + "label": {"text": "all_late_ipa_passes"}, + "children": [{"id": "104_pta", + "label": {"text": "104_pta"}}, + {"id": "105_simdclone", + "label": {"text": "105_simdclone"}}]}, + {"id": "all_passes", + "label": {"text": "all_passes"}, + "children": [{"id": "106_fixup_cfg", + "label": {"text": "106_fixup_cfg"}}, + {"id": "107_ehdisp", + "label": {"text": "107_ehdisp"}}, + {"id": "108_oaccloops", + "label": {"text": "108_oaccloops"}}, + {"id": "109_omp_oacc_neuter_broadcast", + "label": {"text": "109_omp_oacc_neuter_broadcast"}}, + {"id": "110_oaccdevlow", + "label": {"text": "110_oaccdevlow"}}, + {"id": "111_ompdevlow", + "label": {"text": "111_ompdevlow"}}, + {"id": "112_omptargetlink", + "label": {"text": "112_omptargetlink"}}, + {"id": "113_adjust_alignment", + "label": {"text": "113_adjust_alignment"}}, + {"id": "114_hardcfr", + "label": {"text": "114_hardcfr"}}, + {"id": "*all_optimizations_0x101f2720", + "label": {"text": "*all_optimizations"}}, + {"id": "*remove_cgraph_callee_edges_0x101f2780", + "label": {"text": "*remove_cgraph_callee_edges"}}, + {"id": "*strip_predict_hints_0x101f27e0", + "label": {"text": "*strip_predict_hints"}}, + {"id": "115_ccp", + "label": {"text": "115_ccp"}}, + {"id": "116_objsz", + "label": {"text": "116_objsz"}}, + {"id": "117_post_ipa_warn", + "label": {"text": "117_post_ipa_warn"}}, + {"id": "118_waccess", + "label": {"text": "118_waccess"}}, + {"id": "119_rebuild_frequencies", + "label": {"text": "119_rebuild_frequencies"}}, + {"id": "120_cunrolli", + "label": {"text": "120_cunrolli"}}, + {"id": "121_backprop", + "label": {"text": "121_backprop"}}, + {"id": "122_phiprop", + "label": {"text": "122_phiprop"}}, + {"id": "123_forwprop", + "label": {"text": "123_forwprop"}}, + {"id": "124_alias", + "label": {"text": "124_alias"}}, + {"id": "125_retslot", + "label": {"text": "125_retslot"}}, + {"id": "126_fre", + "label": {"text": "126_fre"}}, + {"id": "127_mergephi", + "label": {"text": "127_mergephi"}}, + {"id": "128_threadfull", + "label": {"text": "128_threadfull"}}, + {"id": "129_vrp", + "label": {"text": "129_vrp"}}, + {"id": "130_bounds", + "label": {"text": "130_bounds"}}, + {"id": "131_dse", + "label": {"text": "131_dse"}}, + {"id": "132_dce", + "label": {"text": "132_dce"}}, + {"id": "133_stdarg", + "label": {"text": "133_stdarg"}}, + {"id": "134_cdce", + "label": {"text": "134_cdce"}}, + {"id": "135_cselim", + "label": {"text": "135_cselim"}}, + {"id": "136_copyprop", + "label": {"text": "136_copyprop"}}, + {"id": "137_ifcombine", + "label": {"text": "137_ifcombine"}}, + {"id": "138_mergephi", + "label": {"text": "138_mergephi"}}, + {"id": "139_phiopt", + "label": {"text": "139_phiopt"}}, + {"id": "140_tailr", + "label": {"text": "140_tailr"}}, + {"id": "141_ch", + "label": {"text": "141_ch"}}, + {"id": "142_cplxlower", + "label": {"text": "142_cplxlower"}}, + {"id": "143_bitintlower", + "label": {"text": "143_bitintlower"}}, + {"id": "144_sra", + "label": {"text": "144_sra"}}, + {"id": "145_thread", + "label": {"text": "145_thread"}}, + {"id": "146_dom", + "label": {"text": "146_dom"}}, + {"id": "147_copyprop", + "label": {"text": "147_copyprop"}}, + {"id": "148_isolate-paths", + "label": {"text": "148_isolate-paths"}}, + {"id": "149_reassoc", + "label": {"text": "149_reassoc"}}, + {"id": "150_dce", + "label": {"text": "150_dce"}}, + {"id": "151_forwprop", + "label": {"text": "151_forwprop"}}, + {"id": "152_phiopt", + "label": {"text": "152_phiopt"}}, + {"id": "153_ccp", + "label": {"text": "153_ccp"}}, + {"id": "154_pow", + "label": {"text": "154_pow"}}, + {"id": "155_bswap", + "label": {"text": "155_bswap"}}, + {"id": "156_laddress", + "label": {"text": "156_laddress"}}, + {"id": "157_lim", + "label": {"text": "157_lim"}}, + {"id": "158_walloca", + "label": {"text": "158_walloca"}}, + {"id": "159_pre", + "label": {"text": "159_pre"}}, + {"id": "160_sink", + "label": {"text": "160_sink"}}, + {"id": "161_sancov", + "label": {"text": "161_sancov"}}, + {"id": "162_asan", + "label": {"text": "162_asan"}}, + {"id": "163_tsan", + "label": {"text": "163_tsan"}}, + {"id": "164_dse", + "label": {"text": "164_dse"}}, + {"id": "165_dce", + "label": {"text": "165_dce"}}, + {"id": "166_fix_loops", + "label": {"text": "166_fix_loops"}}, + {"id": "167_loop", + "label": {"text": "167_loop"}}, + {"id": "168_loopinit", + "label": {"text": "168_loopinit"}}, + {"id": "169_unswitch", + "label": {"text": "169_unswitch"}}, + {"id": "170_lsplit", + "label": {"text": "170_lsplit"}}, + {"id": "171_sccp", + "label": {"text": "171_sccp"}}, + {"id": "172_lversion", + "label": {"text": "172_lversion"}}, + {"id": "173_unrolljam", + "label": {"text": "173_unrolljam"}}, + {"id": "174_cddce", + "label": {"text": "174_cddce"}}, + {"id": "175_ivcanon", + "label": {"text": "175_ivcanon"}}, + {"id": "176_ldist", + "label": {"text": "176_ldist"}}, + {"id": "177_crc", + "label": {"text": "177_crc"}}, + {"id": "178_linterchange", + "label": {"text": "178_linterchange"}}, + {"id": "179_copyprop", + "label": {"text": "179_copyprop"}}, + {"id": "180_graphite0", + "label": {"text": "180_graphite0"}}, + {"id": "181_graphite", + "label": {"text": "181_graphite"}}, + {"id": "182_lim", + "label": {"text": "182_lim"}}, + {"id": "183_copyprop", + "label": {"text": "183_copyprop"}}, + {"id": "184_dce", + "label": {"text": "184_dce"}}, + {"id": "185_parloops", + "label": {"text": "185_parloops"}}, + {"id": "186_ompexpssa", + "label": {"text": "186_ompexpssa"}}, + {"id": "187_ch_vect", + "label": {"text": "187_ch_vect"}}, + {"id": "188_ifcvt", + "label": {"text": "188_ifcvt"}}, + {"id": "189_vect", + "label": {"text": "189_vect"}}, + {"id": "190_dce", + "label": {"text": "190_dce"}}, + {"id": "191_pcom", + "label": {"text": "191_pcom"}}, + {"id": "192_cunroll", + "label": {"text": "192_cunroll"}}, + {"id": "*pre_slp_scalar_cleanup_0x101f4880", + "label": {"text": "*pre_slp_scalar_cleanup"}}, + {"id": "193_fre", + "label": {"text": "193_fre"}}, + {"id": "194_dse", + "label": {"text": "194_dse"}}, + {"id": "195_slp", + "label": {"text": "195_slp"}}, + {"id": "196_aprefetch", + "label": {"text": "196_aprefetch"}}, + {"id": "197_ivopts", + "label": {"text": "197_ivopts"}}, + {"id": "198_lim", + "label": {"text": "198_lim"}}, + {"id": "199_loopdone", + "label": {"text": "199_loopdone"}}, + {"id": "200_no_loop", + "label": {"text": "200_no_loop"}}, + {"id": "201_slp", + "label": {"text": "201_slp"}}, + {"id": "202_simduid", + "label": {"text": "202_simduid"}}, + {"id": "203_veclower2", + "label": {"text": "203_veclower2"}}, + {"id": "204_switchlower", + "label": {"text": "204_switchlower"}}, + {"id": "205_sincos", + "label": {"text": "205_sincos"}}, + {"id": "206_recip", + "label": {"text": "206_recip"}}, + {"id": "207_reassoc", + "label": {"text": "207_reassoc"}}, + {"id": "208_slsr", + "label": {"text": "208_slsr"}}, + {"id": "209_split-paths", + "label": {"text": "209_split-paths"}}, + {"id": "210_tracer", + "label": {"text": "210_tracer"}}, + {"id": "211_fre", + "label": {"text": "211_fre"}}, + {"id": "212_thread", + "label": {"text": "212_thread"}}, + {"id": "213_dom", + "label": {"text": "213_dom"}}, + {"id": "214_strlen", + "label": {"text": "214_strlen"}}, + {"id": "215_threadfull", + "label": {"text": "215_threadfull"}}, + {"id": "216_vrp", + "label": {"text": "216_vrp"}}, + {"id": "217_ccp", + "label": {"text": "217_ccp"}}, + {"id": "218_wrestrict", + "label": {"text": "218_wrestrict"}}, + {"id": "219_dse", + "label": {"text": "219_dse"}}, + {"id": "220_dce", + "label": {"text": "220_dce"}}, + {"id": "221_forwprop", + "label": {"text": "221_forwprop"}}, + {"id": "222_sink", + "label": {"text": "222_sink"}}, + {"id": "223_phiopt", + "label": {"text": "223_phiopt"}}, + {"id": "224_fab", + "label": {"text": "224_fab"}}, + {"id": "225_widening_mul", + "label": {"text": "225_widening_mul"}}, + {"id": "226_store-merging", + "label": {"text": "226_store-merging"}}, + {"id": "227_cddce", + "label": {"text": "227_cddce"}}, + {"id": "228_sccopy", + "label": {"text": "228_sccopy"}}, + {"id": "229_tailc", + "label": {"text": "229_tailc"}}, + {"id": "230_crited", + "label": {"text": "230_crited"}}, + {"id": "231_uninit", + "label": {"text": "231_uninit"}}, + {"id": "232_local-pure-const", + "label": {"text": "232_local-pure-const"}}, + {"id": "233_modref", + "label": {"text": "233_modref"}}, + {"id": "234_uncprop", + "label": {"text": "234_uncprop"}}, + {"id": "*all_optimizations_g_0x101f5af0", + "label": {"text": "*all_optimizations_g"}}, + {"id": "*remove_cgraph_callee_edges_0x101f5b50", + "label": {"text": "*remove_cgraph_callee_edges"}}, + {"id": "*strip_predict_hints_0x101f5bb0", + "label": {"text": "*strip_predict_hints"}}, + {"id": "235_cplxlower", + "label": {"text": "235_cplxlower"}}, + {"id": "236_bitintlower", + "label": {"text": "236_bitintlower"}}, + {"id": "237_veclower2", + "label": {"text": "237_veclower2"}}, + {"id": "238_switchlower", + "label": {"text": "238_switchlower"}}, + {"id": "239_ccp", + "label": {"text": "239_ccp"}}, + {"id": "240_post_ipa_warn", + "label": {"text": "240_post_ipa_warn"}}, + {"id": "241_objsz", + "label": {"text": "241_objsz"}}, + {"id": "242_fab", + "label": {"text": "242_fab"}}, + {"id": "243_strlen", + "label": {"text": "243_strlen"}}, + {"id": "244_copyprop", + "label": {"text": "244_copyprop"}}, + {"id": "245_dce", + "label": {"text": "245_dce"}}, + {"id": "246_rebuild_frequencies", + "label": {"text": "246_rebuild_frequencies"}}, + {"id": "247_sancov", + "label": {"text": "247_sancov"}}, + {"id": "248_asan", + "label": {"text": "248_asan"}}, + {"id": "249_tsan", + "label": {"text": "249_tsan"}}, + {"id": "250_crited", + "label": {"text": "250_crited"}}, + {"id": "251_uninit", + "label": {"text": "251_uninit"}}, + {"id": "252_uncprop", + "label": {"text": "252_uncprop"}}, + {"id": "253_assumptions", + "label": {"text": "253_assumptions"}}, + {"id": "*tminit_0x101f6370", + "label": {"text": "*tminit"}}, + {"id": "254_tmmark", + "label": {"text": "254_tmmark"}}, + {"id": "255_tmmemopt", + "label": {"text": "255_tmmemopt"}}, + {"id": "256_tmedge", + "label": {"text": "256_tmedge"}}, + {"id": "257_simduid", + "label": {"text": "257_simduid"}}, + {"id": "258_vtable-verify", + "label": {"text": "258_vtable-verify"}}, + {"id": "259_lower_vaarg", + "label": {"text": "259_lower_vaarg"}}, + {"id": "260_veclower", + "label": {"text": "260_veclower"}}, + {"id": "261_cplxlower0", + "label": {"text": "261_cplxlower0"}}, + {"id": "262_bitintlower0", + "label": {"text": "262_bitintlower0"}}, + {"id": "263_sancov_O0", + "label": {"text": "263_sancov_O0"}}, + {"id": "264_switchlower_O0", + "label": {"text": "264_switchlower_O0"}}, + {"id": "265_asan0", + "label": {"text": "265_asan0"}}, + {"id": "266_tsan0", + "label": {"text": "266_tsan0"}}, + {"id": "267_musttail", + "label": {"text": "267_musttail"}}, + {"id": "268_sanopt", + "label": {"text": "268_sanopt"}}, + {"id": "269_ehcleanup", + "label": {"text": "269_ehcleanup"}}, + {"id": "270_resx", + "label": {"text": "270_resx"}}, + {"id": "271_nrv", + "label": {"text": "271_nrv"}}, + {"id": "272_isel", + "label": {"text": "272_isel"}}, + {"id": "273_hardcbr", + "label": {"text": "273_hardcbr"}}, + {"id": "274_hardcmp", + "label": {"text": "274_hardcmp"}}, + {"id": "275_waccess", + "label": {"text": "275_waccess"}}, + {"id": "276_optimized", + "label": {"text": "276_optimized"}}, + {"id": "*warn_function_noreturn_0x101f6dd0", + "label": {"text": "*warn_function_noreturn"}}, + {"id": "277_expand", + "label": {"text": "277_expand"}}, + {"id": "*rest_of_compilation_0x101f6e90", + "label": {"text": "*rest_of_compilation"}}, + {"id": "278_vregs", + "label": {"text": "278_vregs"}}, + {"id": "279_into_cfglayout", + "label": {"text": "279_into_cfglayout"}}, + {"id": "280_jump", + "label": {"text": "280_jump"}}, + {"id": "281_subreg1", + "label": {"text": "281_subreg1"}}, + {"id": "282_dfinit", + "label": {"text": "282_dfinit"}}, + {"id": "283_cse1", + "label": {"text": "283_cse1"}}, + {"id": "284_fwprop1", + "label": {"text": "284_fwprop1"}}, + {"id": "285_cprop", + "label": {"text": "285_cprop"}}, + {"id": "286_rtl pre", + "label": {"text": "286_rtl pre"}}, + {"id": "287_hoist", + "label": {"text": "287_hoist"}}, + {"id": "288_hardreg_pre", + "label": {"text": "288_hardreg_pre"}}, + {"id": "289_cprop", + "label": {"text": "289_cprop"}}, + {"id": "290_store_motion", + "label": {"text": "290_store_motion"}}, + {"id": "291_cse_local", + "label": {"text": "291_cse_local"}}, + {"id": "292_ce1", + "label": {"text": "292_ce1"}}, + {"id": "293_apx_nfcvt", + "label": {"text": "293_apx_nfcvt"}}, + {"id": "294_reginfo", + "label": {"text": "294_reginfo"}}, + {"id": "295_loop2", + "label": {"text": "295_loop2"}}, + {"id": "296_loop2_init", + "label": {"text": "296_loop2_init"}}, + {"id": "297_loop2_invariant", + "label": {"text": "297_loop2_invariant"}}, + {"id": "298_loop2_unroll", + "label": {"text": "298_loop2_unroll"}}, + {"id": "299_loop2_doloop", + "label": {"text": "299_loop2_doloop"}}, + {"id": "300_loop2_done", + "label": {"text": "300_loop2_done"}}, + {"id": "301_subreg2", + "label": {"text": "301_subreg2"}}, + {"id": "302_web", + "label": {"text": "302_web"}}, + {"id": "303_cprop", + "label": {"text": "303_cprop"}}, + {"id": "304_stv", + "label": {"text": "304_stv"}}, + {"id": "305_cse2", + "label": {"text": "305_cse2"}}, + {"id": "306_dse1", + "label": {"text": "306_dse1"}}, + {"id": "307_fwprop2", + "label": {"text": "307_fwprop2"}}, + {"id": "308_auto_inc_dec", + "label": {"text": "308_auto_inc_dec"}}, + {"id": "309_init-regs", + "label": {"text": "309_init-regs"}}, + {"id": "310_ud_dce", + "label": {"text": "310_ud_dce"}}, + {"id": "311_ext_dce", + "label": {"text": "311_ext_dce"}}, + {"id": "312_combine", + "label": {"text": "312_combine"}}, + {"id": "313_late_combine", + "label": {"text": "313_late_combine"}}, + {"id": "314_rpad", + "label": {"text": "314_rpad"}}, + {"id": "315_rrvl", + "label": {"text": "315_rrvl"}}, + {"id": "316_stv", + "label": {"text": "316_stv"}}, + {"id": "317_ce2", + "label": {"text": "317_ce2"}}, + {"id": "318_jump_after_combine", + "label": {"text": "318_jump_after_combine"}}, + {"id": "319_bbpart", + "label": {"text": "319_bbpart"}}, + {"id": "320_outof_cfglayout", + "label": {"text": "320_outof_cfglayout"}}, + {"id": "321_split1", + "label": {"text": "321_split1"}}, + {"id": "322_subreg3", + "label": {"text": "322_subreg3"}}, + {"id": "323_no-opt dfinit", + "label": {"text": "323_no-opt dfinit"}}, + {"id": "*stack_ptr_mod_0x101f8050", + "label": {"text": "*stack_ptr_mod"}}, + {"id": "324_mode_sw", + "label": {"text": "324_mode_sw"}}, + {"id": "325_asmcons", + "label": {"text": "325_asmcons"}}, + {"id": "326_sms", + "label": {"text": "326_sms"}}, + {"id": "327_lr_shrinkage", + "label": {"text": "327_lr_shrinkage"}}, + {"id": "328_sched1", + "label": {"text": "328_sched1"}}, + {"id": "329_avoid_store_forwarding", + "label": {"text": "329_avoid_store_forwarding"}}, + {"id": "330_early_remat", + "label": {"text": "330_early_remat"}}, + {"id": "331_ira", + "label": {"text": "331_ira"}}, + {"id": "332_reload", + "label": {"text": "332_reload"}}, + {"id": "*all-postreload_0x101f8410", + "label": {"text": "*all-postreload"}}, + {"id": "333_postreload", + "label": {"text": "333_postreload"}}, + {"id": "334_vzeroupper", + "label": {"text": "334_vzeroupper"}}, + {"id": "335_late_combine", + "label": {"text": "335_late_combine"}}, + {"id": "336_gcse2", + "label": {"text": "336_gcse2"}}, + {"id": "337_split2", + "label": {"text": "337_split2"}}, + {"id": "338_ree", + "label": {"text": "338_ree"}}, + {"id": "339_cmpelim", + "label": {"text": "339_cmpelim"}}, + {"id": "340_pro_and_epilogue", + "label": {"text": "340_pro_and_epilogue"}}, + {"id": "341_dse2", + "label": {"text": "341_dse2"}}, + {"id": "342_csa", + "label": {"text": "342_csa"}}, + {"id": "343_jump2", + "label": {"text": "343_jump2"}}, + {"id": "344_compgotos", + "label": {"text": "344_compgotos"}}, + {"id": "345_sched_fusion", + "label": {"text": "345_sched_fusion"}}, + {"id": "346_peephole2", + "label": {"text": "346_peephole2"}}, + {"id": "347_ce3", + "label": {"text": "347_ce3"}}, + {"id": "348_rnreg", + "label": {"text": "348_rnreg"}}, + {"id": "349_fold_mem_offsets", + "label": {"text": "349_fold_mem_offsets"}}, + {"id": "350_cprop_hardreg", + "label": {"text": "350_cprop_hardreg"}}, + {"id": "351_rtl_dce", + "label": {"text": "351_rtl_dce"}}, + {"id": "352_bbro", + "label": {"text": "352_bbro"}}, + {"id": "*leaf_regs_0x101f8bf0", + "label": {"text": "*leaf_regs"}}, + {"id": "353_split3", + "label": {"text": "353_split3"}}, + {"id": "354_sched2", + "label": {"text": "354_sched2"}}, + {"id": "*stack_regs_0x101f8d10", + "label": {"text": "*stack_regs"}}, + {"id": "355_split4", + "label": {"text": "355_split4"}}, + {"id": "356_stack", + "label": {"text": "356_stack"}}, + {"id": "357_late_pro_and_epilogue", + "label": {"text": "357_late_pro_and_epilogue"}}, + {"id": "*all-late_compilation_0x101f8e90", + "label": {"text": "*all-late_compilation"}}, + {"id": "358_zero_call_used_regs", + "label": {"text": "358_zero_call_used_regs"}}, + {"id": "359_alignments", + "label": {"text": "359_alignments"}}, + {"id": "360_vartrack", + "label": {"text": "360_vartrack"}}, + {"id": "*free_cfg_0x101f9010", + "label": {"text": "*free_cfg"}}, + {"id": "361_mach", + "label": {"text": "361_mach"}}, + {"id": "362_barriers", + "label": {"text": "362_barriers"}}, + {"id": "363_dbr", + "label": {"text": "363_dbr"}}, + {"id": "364_split5", + "label": {"text": "364_split5"}}, + {"id": "365_eh_ranges", + "label": {"text": "365_eh_ranges"}}, + {"id": "366_endbr_and_patchable_area", + "label": {"text": "366_endbr_and_patchable_area"}}, + {"id": "367_align_tight_loops", + "label": {"text": "367_align_tight_loops"}}, + {"id": "368_shorten", + "label": {"text": "368_shorten"}}, + {"id": "369_nothrow", + "label": {"text": "369_nothrow"}}, + {"id": "370_dwarf2", + "label": {"text": "370_dwarf2"}}, + {"id": "371_final", + "label": {"text": "371_final"}}, + {"id": "372_dfinish", + "label": {"text": "372_dfinish"}}, + {"id": "*clean_state_0x101f9500", + "label": {"text": "*clean_state"}}]}], + "edges": [{"id": "edge0", + "label": {"text": "next"}, + "sourceNodeId": "22_ompexp", + "targetNodeId": "*build_cgraph_edges_0x101ef910"}, + {"id": "edge1", + "label": {"text": "next"}, + "sourceNodeId": "21_coro-early-expand-ifns", + "targetNodeId": "22_ompexp"}, + {"id": "edge2", + "label": {"text": "next"}, + "sourceNodeId": "*warn_function_return_0x101ef7f0", + "targetNodeId": "21_coro-early-expand-ifns"}, + {"id": "edge3", + "label": {"text": "next"}, + "sourceNodeId": "20_cfg", + "targetNodeId": "*warn_function_return_0x101ef7f0"}, + {"id": "edge4", + "label": {"text": "next"}, + "sourceNodeId": "19_coro-lower-builtins", + "targetNodeId": "20_cfg"}, + {"id": "edge5", + "label": {"text": "next"}, + "sourceNodeId": "18_eh", + "targetNodeId": "19_coro-lower-builtins"}, + {"id": "edge6", + "label": {"text": "next"}, + "sourceNodeId": "17_ehopt", + "targetNodeId": "18_eh"}, + {"id": "edge7", + "label": {"text": "next"}, + "sourceNodeId": "16_tmlower", + "targetNodeId": "17_ehopt"}, + {"id": "edge8", + "label": {"text": "next"}, + "sourceNodeId": "15_lower", + "targetNodeId": "16_tmlower"}, + {"id": "edge9", + "label": {"text": "next"}, + "sourceNodeId": "14_omplower", + "targetNodeId": "15_lower"}, + {"id": "edge10", + "label": {"text": "next"}, + "sourceNodeId": "13_omp_oacc_kernels_decompose", + "targetNodeId": "14_omplower"}, + {"id": "edge11", + "label": {"text": "next"}, + "sourceNodeId": "*diagnose_tm_blocks_0x101ef490", + "targetNodeId": "13_omp_oacc_kernels_decompose"}, + {"id": "edge12", + "label": {"text": "next"}, + "sourceNodeId": "*diagnose_omp_blocks_0x101ef430", + "targetNodeId": "*diagnose_tm_blocks_0x101ef490"}, + {"id": "edge13", + "label": {"text": "next"}, + "sourceNodeId": "*warn_unused_result_0x101ef3d0", + "targetNodeId": "*diagnose_omp_blocks_0x101ef430"}, + {"id": "edge14", + "label": {"text": "next"}, + "sourceNodeId": "34_nothrow", + "targetNodeId": "*rebuild_cgraph_edges_0x101f0020"}, + {"id": "edge15", + "label": {"text": "next"}, + "sourceNodeId": "33_ubsan", + "targetNodeId": "34_nothrow"}, + {"id": "edge16", + "label": {"text": "next"}, + "sourceNodeId": "32_waccess", + "targetNodeId": "33_ubsan"}, + {"id": "edge17", + "label": {"text": "next"}, + "sourceNodeId": "31_early_uninit", + "targetNodeId": "32_waccess"}, + {"id": "edge18", + "label": {"text": "next"}, + "sourceNodeId": "*nonnullcmp_0x101efce0", + "targetNodeId": "31_early_uninit"}, + {"id": "edge19", + "label": {"text": "next"}, + "sourceNodeId": "30_warn-printf", + "targetNodeId": "*nonnullcmp_0x101efce0"}, + {"id": "edge20", + "label": {"text": "next"}, + "sourceNodeId": "29_walloca", + "targetNodeId": "30_warn-printf"}, + {"id": "edge21", + "label": {"text": "next"}, + "sourceNodeId": "376_test_graph_emission", + "targetNodeId": "29_walloca"}, + {"id": "edge22", + "label": {"text": "next"}, + "sourceNodeId": "28_ssa", + "targetNodeId": "376_test_graph_emission"}, + {"id": "edge23", + "label": {"text": "next"}, + "sourceNodeId": "27_fixup_cfg", + "targetNodeId": "28_ssa"}, + {"id": "edge24", + "label": {"text": "sub"}, + "sourceNodeId": "26_build_ssa_passes", + "targetNodeId": "27_fixup_cfg"}, + {"id": "edge25", + "label": {"text": "next"}, + "sourceNodeId": "61_fnsplit", + "targetNodeId": "*strip_predict_hints_0x101f0c60"}, + {"id": "edge26", + "label": {"text": "next"}, + "sourceNodeId": "60_modref", + "targetNodeId": "61_fnsplit"}, + {"id": "edge27", + "label": {"text": "next"}, + "sourceNodeId": "59_local-pure-const", + "targetNodeId": "60_modref"}, + {"id": "edge28", + "label": {"text": "next"}, + "sourceNodeId": "58_profile_estimate", + "targetNodeId": "59_local-pure-const"}, + {"id": "edge29", + "label": {"text": "next"}, + "sourceNodeId": "57_sccopy", + "targetNodeId": "58_profile_estimate"}, + {"id": "edge30", + "label": {"text": "next"}, + "sourceNodeId": "56_ehcleanup", + "targetNodeId": "57_sccopy"}, + {"id": "edge31", + "label": {"text": "next"}, + "sourceNodeId": "55_switchconv", + "targetNodeId": "56_ehcleanup"}, + {"id": "edge32", + "label": {"text": "next"}, + "sourceNodeId": "54_iftoswitch", + "targetNodeId": "55_switchconv"}, + {"id": "edge33", + "label": {"text": "next"}, + "sourceNodeId": "53_tailr", + "targetNodeId": "54_iftoswitch"}, + {"id": "edge34", + "label": {"text": "next"}, + "sourceNodeId": "52_phiopt", + "targetNodeId": "53_tailr"}, + {"id": "edge35", + "label": {"text": "next"}, + "sourceNodeId": "51_cddce", + "targetNodeId": "52_phiopt"}, + {"id": "edge36", + "label": {"text": "next"}, + "sourceNodeId": "50_dse", + "targetNodeId": "51_cddce"}, + {"id": "edge37", + "label": {"text": "next"}, + "sourceNodeId": "49_mergephi", + "targetNodeId": "50_dse"}, + {"id": "edge38", + "label": {"text": "next"}, + "sourceNodeId": "48_evrp", + "targetNodeId": "49_mergephi"}, + {"id": "edge39", + "label": {"text": "next"}, + "sourceNodeId": "47_fre", + "targetNodeId": "48_evrp"}, + {"id": "edge40", + "label": {"text": "next"}, + "sourceNodeId": "46_phiprop", + "targetNodeId": "47_fre"}, + {"id": "edge41", + "label": {"text": "next"}, + "sourceNodeId": "45_ealias", + "targetNodeId": "46_phiprop"}, + {"id": "edge42", + "label": {"text": "next"}, + "sourceNodeId": "44_esra", + "targetNodeId": "45_ealias"}, + {"id": "edge43", + "label": {"text": "next"}, + "sourceNodeId": "43_ethread", + "targetNodeId": "44_esra"}, + {"id": "edge44", + "label": {"text": "next"}, + "sourceNodeId": "42_forwprop", + "targetNodeId": "43_ethread"}, + {"id": "edge45", + "label": {"text": "next"}, + "sourceNodeId": "41_ccp", + "targetNodeId": "42_forwprop"}, + {"id": "edge46", + "label": {"text": "next"}, + "sourceNodeId": "40_early_objsz", + "targetNodeId": "41_ccp"}, + {"id": "edge47", + "label": {"text": "next"}, + "sourceNodeId": "*remove_cgraph_callee_edges_0x101f0340", + "targetNodeId": "40_early_objsz"}, + {"id": "edge48", + "label": {"text": "sub"}, + "sourceNodeId": "39_early_optimizations", + "targetNodeId": "*remove_cgraph_callee_edges_0x101f0340"}, + {"id": "edge49", + "label": {"text": "next"}, + "sourceNodeId": "*rebuild_cgraph_edges_0x101f0d30", + "targetNodeId": "63_local-fnsummary"}, + {"id": "edge50", + "label": {"text": "next"}, + "sourceNodeId": "62_release_ssa", + "targetNodeId": "*rebuild_cgraph_edges_0x101f0d30"}, + {"id": "edge51", + "label": {"text": "next"}, + "sourceNodeId": "39_early_optimizations", + "targetNodeId": "62_release_ssa"}, + {"id": "edge52", + "label": {"text": "next"}, + "sourceNodeId": "*infinite-recursion_0x101f0260", + "targetNodeId": "39_early_optimizations"}, + {"id": "edge53", + "label": {"text": "next"}, + "sourceNodeId": "38_einline", + "targetNodeId": "*infinite-recursion_0x101f0260"}, + {"id": "edge54", + "label": {"text": "next"}, + "sourceNodeId": "37_local-fnsummary", + "targetNodeId": "38_einline"}, + {"id": "edge55", + "label": {"text": "next"}, + "sourceNodeId": "*rebuild_cgraph_edges_0x101f0140", + "targetNodeId": "37_local-fnsummary"}, + {"id": "edge56", + "label": {"text": "next"}, + "sourceNodeId": "36_fixup_cfg", + "targetNodeId": "*rebuild_cgraph_edges_0x101f0140"}, + {"id": "edge57", + "label": {"text": "sub"}, + "sourceNodeId": "35_opt_local_passes", + "targetNodeId": "36_fixup_cfg"}, + {"id": "edge58", + "label": {"text": "next"}, + "sourceNodeId": "76_ompexpssa", + "targetNodeId": "*rebuild_cgraph_edges_0x101f1310"}, + {"id": "edge59", + "label": {"text": "next"}, + "sourceNodeId": "75_parloops", + "targetNodeId": "76_ompexpssa"}, + {"id": "edge60", + "label": {"text": "next"}, + "sourceNodeId": "74_dce", + "targetNodeId": "75_parloops"}, + {"id": "edge61", + "label": {"text": "next"}, + "sourceNodeId": "73_dom", + "targetNodeId": "74_dce"}, + {"id": "edge62", + "label": {"text": "next"}, + "sourceNodeId": "72_lim", + "targetNodeId": "73_dom"}, + {"id": "edge63", + "label": {"text": "next"}, + "sourceNodeId": "71_fre", + "targetNodeId": "72_lim"}, + {"id": "edge64", + "label": {"text": "next"}, + "sourceNodeId": "70_ch", + "targetNodeId": "71_fre"}, + {"id": "edge65", + "label": {"text": "sub"}, + "sourceNodeId": "69_oacc_kernels", + "targetNodeId": "70_ch"}, + {"id": "edge66", + "label": {"text": "sub"}, + "sourceNodeId": "68_ipa_oacc_kernels", + "targetNodeId": "69_oacc_kernels"}, + {"id": "edge67", + "label": {"text": "next"}, + "sourceNodeId": "67_pta", + "targetNodeId": "68_ipa_oacc_kernels"}, + {"id": "edge68", + "label": {"text": "sub"}, + "sourceNodeId": "66_ipa_oacc", + "targetNodeId": "67_pta"}, + {"id": "edge69", + "label": {"text": "sub"}, + "sourceNodeId": "78_afdo", + "targetNodeId": "79_feedback_fnsplit"}, + {"id": "edge70", + "label": {"text": "sub"}, + "sourceNodeId": "80_profile", + "targetNodeId": "81_feedback_fnsplit"}, + {"id": "edge71", + "label": {"text": "next"}, + "sourceNodeId": "84_tmipa", + "targetNodeId": "85_emutls"}, + {"id": "edge72", + "label": {"text": "next"}, + "sourceNodeId": "83_increase_alignment", + "targetNodeId": "84_tmipa"}, + {"id": "edge73", + "label": {"text": "next"}, + "sourceNodeId": "82_free-fnsummary", + "targetNodeId": "83_increase_alignment"}, + {"id": "edge74", + "label": {"text": "next"}, + "sourceNodeId": "80_profile", + "targetNodeId": "82_free-fnsummary"}, + {"id": "edge75", + "label": {"text": "next"}, + "sourceNodeId": "78_afdo", + "targetNodeId": "80_profile"}, + {"id": "edge76", + "label": {"text": "next"}, + "sourceNodeId": "77_targetclone", + "targetNodeId": "78_afdo"}, + {"id": "edge77", + "label": {"text": "next"}, + "sourceNodeId": "66_ipa_oacc", + "targetNodeId": "77_targetclone"}, + {"id": "edge78", + "label": {"text": "next"}, + "sourceNodeId": "65_strub", + "targetNodeId": "66_ipa_oacc"}, + {"id": "edge79", + "label": {"text": "next"}, + "sourceNodeId": "64_remove_symbols", + "targetNodeId": "65_strub"}, + {"id": "edge80", + "label": {"text": "next"}, + "sourceNodeId": "35_opt_local_passes", + "targetNodeId": "64_remove_symbols"}, + {"id": "edge81", + "label": {"text": "next"}, + "sourceNodeId": "26_build_ssa_passes", + "targetNodeId": "35_opt_local_passes"}, + {"id": "edge82", + "label": {"text": "next"}, + "sourceNodeId": "25_strubm", + "targetNodeId": "26_build_ssa_passes"}, + {"id": "edge83", + "label": {"text": "next"}, + "sourceNodeId": "24_visibility", + "targetNodeId": "25_strubm"}, + {"id": "edge84", + "label": {"text": "next"}, + "sourceNodeId": "*free_lang_data_0x101ef9d0", + "targetNodeId": "24_visibility"}, + {"id": "edge85", + "label": {"text": "next"}, + "sourceNodeId": "23_afdo_offline", + "targetNodeId": "*free_lang_data_0x101ef9d0"}, + {"id": "edge86", + "label": {"text": "next"}, + "sourceNodeId": "102_single-use", + "targetNodeId": "103_comdats"}, + {"id": "edge87", + "label": {"text": "next"}, + "sourceNodeId": "101_static-var", + "targetNodeId": "102_single-use"}, + {"id": "edge88", + "label": {"text": "next"}, + "sourceNodeId": "100_free-fnsummary", + "targetNodeId": "101_static-var"}, + {"id": "edge89", + "label": {"text": "next"}, + "sourceNodeId": "99_modref", + "targetNodeId": "100_free-fnsummary"}, + {"id": "edge90", + "label": {"text": "next"}, + "sourceNodeId": "98_pure-const", + "targetNodeId": "99_modref"}, + {"id": "edge91", + "label": {"text": "next"}, + "sourceNodeId": "97_locality-clone", + "targetNodeId": "98_pure-const"}, + {"id": "edge92", + "label": {"text": "next"}, + "sourceNodeId": "96_inline", + "targetNodeId": "97_locality-clone"}, + {"id": "edge93", + "label": {"text": "next"}, + "sourceNodeId": "95_fnsummary", + "targetNodeId": "96_inline"}, + {"id": "edge94", + "label": {"text": "next"}, + "sourceNodeId": "94_sra", + "targetNodeId": "95_fnsummary"}, + {"id": "edge95", + "label": {"text": "next"}, + "sourceNodeId": "93_cp", + "targetNodeId": "94_sra"}, + {"id": "edge96", + "label": {"text": "next"}, + "sourceNodeId": "92_cdtor", + "targetNodeId": "93_cp"}, + {"id": "edge97", + "label": {"text": "next"}, + "sourceNodeId": "91_devirt", + "targetNodeId": "92_cdtor"}, + {"id": "edge98", + "label": {"text": "next"}, + "sourceNodeId": "90_icf", + "targetNodeId": "91_devirt"}, + {"id": "edge99", + "label": {"text": "next"}, + "sourceNodeId": "89_profile_estimate", + "targetNodeId": "90_icf"}, + {"id": "edge100", + "label": {"text": "next"}, + "sourceNodeId": "88_whole-program", + "targetNodeId": "89_profile_estimate"}, + {"id": "edge101", + "label": {"text": "next"}, + "sourceNodeId": "87_odr", + "targetNodeId": "88_whole-program"}, + {"id": "edge102", + "label": {"text": "next"}, + "sourceNodeId": "86_analyzer", + "targetNodeId": "87_odr"}, + {"id": "edge103", + "label": {"text": "next"}, + "sourceNodeId": "104_pta", + "targetNodeId": "105_simdclone"}, + {"id": "edge104", + "label": {"text": "next"}, + "sourceNodeId": "183_copyprop", + "targetNodeId": "184_dce"}, + {"id": "edge105", + "label": {"text": "next"}, + "sourceNodeId": "182_lim", + "targetNodeId": "183_copyprop"}, + {"id": "edge106", + "label": {"text": "next"}, + "sourceNodeId": "181_graphite", + "targetNodeId": "182_lim"}, + {"id": "edge107", + "label": {"text": "sub"}, + "sourceNodeId": "180_graphite0", + "targetNodeId": "181_graphite"}, + {"id": "edge108", + "label": {"text": "sub"}, + "sourceNodeId": "189_vect", + "targetNodeId": "190_dce"}, + {"id": "edge109", + "label": {"text": "next"}, + "sourceNodeId": "193_fre", + "targetNodeId": "194_dse"}, + {"id": "edge110", + "label": {"text": "sub"}, + "sourceNodeId": "*pre_slp_scalar_cleanup_0x101f4880", + "targetNodeId": "193_fre"}, + {"id": "edge111", + "label": {"text": "next"}, + "sourceNodeId": "198_lim", + "targetNodeId": "199_loopdone"}, + {"id": "edge112", + "label": {"text": "next"}, + "sourceNodeId": "197_ivopts", + "targetNodeId": "198_lim"}, + {"id": "edge113", + "label": {"text": "next"}, + "sourceNodeId": "196_aprefetch", + "targetNodeId": "197_ivopts"}, + {"id": "edge114", + "label": {"text": "next"}, + "sourceNodeId": "195_slp", + "targetNodeId": "196_aprefetch"}, + {"id": "edge115", + "label": {"text": "next"}, + "sourceNodeId": "*pre_slp_scalar_cleanup_0x101f4880", + "targetNodeId": "195_slp"}, + {"id": "edge116", + "label": {"text": "next"}, + "sourceNodeId": "192_cunroll", + "targetNodeId": "*pre_slp_scalar_cleanup_0x101f4880"}, + {"id": "edge117", + "label": {"text": "next"}, + "sourceNodeId": "191_pcom", + "targetNodeId": "192_cunroll"}, + {"id": "edge118", + "label": {"text": "next"}, + "sourceNodeId": "189_vect", + "targetNodeId": "191_pcom"}, + {"id": "edge119", + "label": {"text": "next"}, + "sourceNodeId": "188_ifcvt", + "targetNodeId": "189_vect"}, + {"id": "edge120", + "label": {"text": "next"}, + "sourceNodeId": "187_ch_vect", + "targetNodeId": "188_ifcvt"}, + {"id": "edge121", + "label": {"text": "next"}, + "sourceNodeId": "186_ompexpssa", + "targetNodeId": "187_ch_vect"}, + {"id": "edge122", + "label": {"text": "next"}, + "sourceNodeId": "185_parloops", + "targetNodeId": "186_ompexpssa"}, + {"id": "edge123", + "label": {"text": "next"}, + "sourceNodeId": "180_graphite0", + "targetNodeId": "185_parloops"}, + {"id": "edge124", + "label": {"text": "next"}, + "sourceNodeId": "179_copyprop", + "targetNodeId": "180_graphite0"}, + {"id": "edge125", + "label": {"text": "next"}, + "sourceNodeId": "178_linterchange", + "targetNodeId": "179_copyprop"}, + {"id": "edge126", + "label": {"text": "next"}, + "sourceNodeId": "177_crc", + "targetNodeId": "178_linterchange"}, + {"id": "edge127", + "label": {"text": "next"}, + "sourceNodeId": "176_ldist", + "targetNodeId": "177_crc"}, + {"id": "edge128", + "label": {"text": "next"}, + "sourceNodeId": "175_ivcanon", + "targetNodeId": "176_ldist"}, + {"id": "edge129", + "label": {"text": "next"}, + "sourceNodeId": "174_cddce", + "targetNodeId": "175_ivcanon"}, + {"id": "edge130", + "label": {"text": "next"}, + "sourceNodeId": "173_unrolljam", + "targetNodeId": "174_cddce"}, + {"id": "edge131", + "label": {"text": "next"}, + "sourceNodeId": "172_lversion", + "targetNodeId": "173_unrolljam"}, + {"id": "edge132", + "label": {"text": "next"}, + "sourceNodeId": "171_sccp", + "targetNodeId": "172_lversion"}, + {"id": "edge133", + "label": {"text": "next"}, + "sourceNodeId": "170_lsplit", + "targetNodeId": "171_sccp"}, + {"id": "edge134", + "label": {"text": "next"}, + "sourceNodeId": "169_unswitch", + "targetNodeId": "170_lsplit"}, + {"id": "edge135", + "label": {"text": "next"}, + "sourceNodeId": "168_loopinit", + "targetNodeId": "169_unswitch"}, + {"id": "edge136", + "label": {"text": "sub"}, + "sourceNodeId": "167_loop", + "targetNodeId": "168_loopinit"}, + {"id": "edge137", + "label": {"text": "sub"}, + "sourceNodeId": "200_no_loop", + "targetNodeId": "201_slp"}, + {"id": "edge138", + "label": {"text": "next"}, + "sourceNodeId": "233_modref", + "targetNodeId": "234_uncprop"}, + {"id": "edge139", + "label": {"text": "next"}, + "sourceNodeId": "232_local-pure-const", + "targetNodeId": "233_modref"}, + {"id": "edge140", + "label": {"text": "next"}, + "sourceNodeId": "231_uninit", + "targetNodeId": "232_local-pure-const"}, + {"id": "edge141", + "label": {"text": "next"}, + "sourceNodeId": "230_crited", + "targetNodeId": "231_uninit"}, + {"id": "edge142", + "label": {"text": "next"}, + "sourceNodeId": "229_tailc", + "targetNodeId": "230_crited"}, + {"id": "edge143", + "label": {"text": "next"}, + "sourceNodeId": "228_sccopy", + "targetNodeId": "229_tailc"}, + {"id": "edge144", + "label": {"text": "next"}, + "sourceNodeId": "227_cddce", + "targetNodeId": "228_sccopy"}, + {"id": "edge145", + "label": {"text": "next"}, + "sourceNodeId": "226_store-merging", + "targetNodeId": "227_cddce"}, + {"id": "edge146", + "label": {"text": "next"}, + "sourceNodeId": "225_widening_mul", + "targetNodeId": "226_store-merging"}, + {"id": "edge147", + "label": {"text": "next"}, + "sourceNodeId": "224_fab", + "targetNodeId": "225_widening_mul"}, + {"id": "edge148", + "label": {"text": "next"}, + "sourceNodeId": "223_phiopt", + "targetNodeId": "224_fab"}, + {"id": "edge149", + "label": {"text": "next"}, + "sourceNodeId": "222_sink", + "targetNodeId": "223_phiopt"}, + {"id": "edge150", + "label": {"text": "next"}, + "sourceNodeId": "221_forwprop", + "targetNodeId": "222_sink"}, + {"id": "edge151", + "label": {"text": "next"}, + "sourceNodeId": "220_dce", + "targetNodeId": "221_forwprop"}, + {"id": "edge152", + "label": {"text": "next"}, + "sourceNodeId": "219_dse", + "targetNodeId": "220_dce"}, + {"id": "edge153", + "label": {"text": "next"}, + "sourceNodeId": "218_wrestrict", + "targetNodeId": "219_dse"}, + {"id": "edge154", + "label": {"text": "next"}, + "sourceNodeId": "217_ccp", + "targetNodeId": "218_wrestrict"}, + {"id": "edge155", + "label": {"text": "next"}, + "sourceNodeId": "216_vrp", + "targetNodeId": "217_ccp"}, + {"id": "edge156", + "label": {"text": "next"}, + "sourceNodeId": "215_threadfull", + "targetNodeId": "216_vrp"}, + {"id": "edge157", + "label": {"text": "next"}, + "sourceNodeId": "214_strlen", + "targetNodeId": "215_threadfull"}, + {"id": "edge158", + "label": {"text": "next"}, + "sourceNodeId": "213_dom", + "targetNodeId": "214_strlen"}, + {"id": "edge159", + "label": {"text": "next"}, + "sourceNodeId": "212_thread", + "targetNodeId": "213_dom"}, + {"id": "edge160", + "label": {"text": "next"}, + "sourceNodeId": "211_fre", + "targetNodeId": "212_thread"}, + {"id": "edge161", + "label": {"text": "next"}, + "sourceNodeId": "210_tracer", + "targetNodeId": "211_fre"}, + {"id": "edge162", + "label": {"text": "next"}, + "sourceNodeId": "209_split-paths", + "targetNodeId": "210_tracer"}, + {"id": "edge163", + "label": {"text": "next"}, + "sourceNodeId": "208_slsr", + "targetNodeId": "209_split-paths"}, + {"id": "edge164", + "label": {"text": "next"}, + "sourceNodeId": "207_reassoc", + "targetNodeId": "208_slsr"}, + {"id": "edge165", + "label": {"text": "next"}, + "sourceNodeId": "206_recip", + "targetNodeId": "207_reassoc"}, + {"id": "edge166", + "label": {"text": "next"}, + "sourceNodeId": "205_sincos", + "targetNodeId": "206_recip"}, + {"id": "edge167", + "label": {"text": "next"}, + "sourceNodeId": "204_switchlower", + "targetNodeId": "205_sincos"}, + {"id": "edge168", + "label": {"text": "next"}, + "sourceNodeId": "203_veclower2", + "targetNodeId": "204_switchlower"}, + {"id": "edge169", + "label": {"text": "next"}, + "sourceNodeId": "202_simduid", + "targetNodeId": "203_veclower2"}, + {"id": "edge170", + "label": {"text": "next"}, + "sourceNodeId": "200_no_loop", + "targetNodeId": "202_simduid"}, + {"id": "edge171", + "label": {"text": "next"}, + "sourceNodeId": "167_loop", + "targetNodeId": "200_no_loop"}, + {"id": "edge172", + "label": {"text": "next"}, + "sourceNodeId": "166_fix_loops", + "targetNodeId": "167_loop"}, + {"id": "edge173", + "label": {"text": "next"}, + "sourceNodeId": "165_dce", + "targetNodeId": "166_fix_loops"}, + {"id": "edge174", + "label": {"text": "next"}, + "sourceNodeId": "164_dse", + "targetNodeId": "165_dce"}, + {"id": "edge175", + "label": {"text": "next"}, + "sourceNodeId": "163_tsan", + "targetNodeId": "164_dse"}, + {"id": "edge176", + "label": {"text": "next"}, + "sourceNodeId": "162_asan", + "targetNodeId": "163_tsan"}, + {"id": "edge177", + "label": {"text": "next"}, + "sourceNodeId": "161_sancov", + "targetNodeId": "162_asan"}, + {"id": "edge178", + "label": {"text": "next"}, + "sourceNodeId": "160_sink", + "targetNodeId": "161_sancov"}, + {"id": "edge179", + "label": {"text": "next"}, + "sourceNodeId": "159_pre", + "targetNodeId": "160_sink"}, + {"id": "edge180", + "label": {"text": "next"}, + "sourceNodeId": "158_walloca", + "targetNodeId": "159_pre"}, + {"id": "edge181", + "label": {"text": "next"}, + "sourceNodeId": "157_lim", + "targetNodeId": "158_walloca"}, + {"id": "edge182", + "label": {"text": "next"}, + "sourceNodeId": "156_laddress", + "targetNodeId": "157_lim"}, + {"id": "edge183", + "label": {"text": "next"}, + "sourceNodeId": "155_bswap", + "targetNodeId": "156_laddress"}, + {"id": "edge184", + "label": {"text": "next"}, + "sourceNodeId": "154_pow", + "targetNodeId": "155_bswap"}, + {"id": "edge185", + "label": {"text": "next"}, + "sourceNodeId": "153_ccp", + "targetNodeId": "154_pow"}, + {"id": "edge186", + "label": {"text": "next"}, + "sourceNodeId": "152_phiopt", + "targetNodeId": "153_ccp"}, + {"id": "edge187", + "label": {"text": "next"}, + "sourceNodeId": "151_forwprop", + "targetNodeId": "152_phiopt"}, + {"id": "edge188", + "label": {"text": "next"}, + "sourceNodeId": "150_dce", + "targetNodeId": "151_forwprop"}, + {"id": "edge189", + "label": {"text": "next"}, + "sourceNodeId": "149_reassoc", + "targetNodeId": "150_dce"}, + {"id": "edge190", + "label": {"text": "next"}, + "sourceNodeId": "148_isolate-paths", + "targetNodeId": "149_reassoc"}, + {"id": "edge191", + "label": {"text": "next"}, + "sourceNodeId": "147_copyprop", + "targetNodeId": "148_isolate-paths"}, + {"id": "edge192", + "label": {"text": "next"}, + "sourceNodeId": "146_dom", + "targetNodeId": "147_copyprop"}, + {"id": "edge193", + "label": {"text": "next"}, + "sourceNodeId": "145_thread", + "targetNodeId": "146_dom"}, + {"id": "edge194", + "label": {"text": "next"}, + "sourceNodeId": "144_sra", + "targetNodeId": "145_thread"}, + {"id": "edge195", + "label": {"text": "next"}, + "sourceNodeId": "143_bitintlower", + "targetNodeId": "144_sra"}, + {"id": "edge196", + "label": {"text": "next"}, + "sourceNodeId": "142_cplxlower", + "targetNodeId": "143_bitintlower"}, + {"id": "edge197", + "label": {"text": "next"}, + "sourceNodeId": "141_ch", + "targetNodeId": "142_cplxlower"}, + {"id": "edge198", + "label": {"text": "next"}, + "sourceNodeId": "140_tailr", + "targetNodeId": "141_ch"}, + {"id": "edge199", + "label": {"text": "next"}, + "sourceNodeId": "139_phiopt", + "targetNodeId": "140_tailr"}, + {"id": "edge200", + "label": {"text": "next"}, + "sourceNodeId": "138_mergephi", + "targetNodeId": "139_phiopt"}, + {"id": "edge201", + "label": {"text": "next"}, + "sourceNodeId": "137_ifcombine", + "targetNodeId": "138_mergephi"}, + {"id": "edge202", + "label": {"text": "next"}, + "sourceNodeId": "136_copyprop", + "targetNodeId": "137_ifcombine"}, + {"id": "edge203", + "label": {"text": "next"}, + "sourceNodeId": "135_cselim", + "targetNodeId": "136_copyprop"}, + {"id": "edge204", + "label": {"text": "next"}, + "sourceNodeId": "134_cdce", + "targetNodeId": "135_cselim"}, + {"id": "edge205", + "label": {"text": "next"}, + "sourceNodeId": "133_stdarg", + "targetNodeId": "134_cdce"}, + {"id": "edge206", + "label": {"text": "next"}, + "sourceNodeId": "132_dce", + "targetNodeId": "133_stdarg"}, + {"id": "edge207", + "label": {"text": "next"}, + "sourceNodeId": "131_dse", + "targetNodeId": "132_dce"}, + {"id": "edge208", + "label": {"text": "next"}, + "sourceNodeId": "130_bounds", + "targetNodeId": "131_dse"}, + {"id": "edge209", + "label": {"text": "next"}, + "sourceNodeId": "129_vrp", + "targetNodeId": "130_bounds"}, + {"id": "edge210", + "label": {"text": "next"}, + "sourceNodeId": "128_threadfull", + "targetNodeId": "129_vrp"}, + {"id": "edge211", + "label": {"text": "next"}, + "sourceNodeId": "127_mergephi", + "targetNodeId": "128_threadfull"}, + {"id": "edge212", + "label": {"text": "next"}, + "sourceNodeId": "126_fre", + "targetNodeId": "127_mergephi"}, + {"id": "edge213", + "label": {"text": "next"}, + "sourceNodeId": "125_retslot", + "targetNodeId": "126_fre"}, + {"id": "edge214", + "label": {"text": "next"}, + "sourceNodeId": "124_alias", + "targetNodeId": "125_retslot"}, + {"id": "edge215", + "label": {"text": "next"}, + "sourceNodeId": "123_forwprop", + "targetNodeId": "124_alias"}, + {"id": "edge216", + "label": {"text": "next"}, + "sourceNodeId": "122_phiprop", + "targetNodeId": "123_forwprop"}, + {"id": "edge217", + "label": {"text": "next"}, + "sourceNodeId": "121_backprop", + "targetNodeId": "122_phiprop"}, + {"id": "edge218", + "label": {"text": "next"}, + "sourceNodeId": "120_cunrolli", + "targetNodeId": "121_backprop"}, + {"id": "edge219", + "label": {"text": "next"}, + "sourceNodeId": "119_rebuild_frequencies", + "targetNodeId": "120_cunrolli"}, + {"id": "edge220", + "label": {"text": "next"}, + "sourceNodeId": "118_waccess", + "targetNodeId": "119_rebuild_frequencies"}, + {"id": "edge221", + "label": {"text": "next"}, + "sourceNodeId": "117_post_ipa_warn", + "targetNodeId": "118_waccess"}, + {"id": "edge222", + "label": {"text": "next"}, + "sourceNodeId": "116_objsz", + "targetNodeId": "117_post_ipa_warn"}, + {"id": "edge223", + "label": {"text": "next"}, + "sourceNodeId": "115_ccp", + "targetNodeId": "116_objsz"}, + {"id": "edge224", + "label": {"text": "next"}, + "sourceNodeId": "*strip_predict_hints_0x101f27e0", + "targetNodeId": "115_ccp"}, + {"id": "edge225", + "label": {"text": "next"}, + "sourceNodeId": "*remove_cgraph_callee_edges_0x101f2780", + "targetNodeId": "*strip_predict_hints_0x101f27e0"}, + {"id": "edge226", + "label": {"text": "sub"}, + "sourceNodeId": "*all_optimizations_0x101f2720", + "targetNodeId": "*remove_cgraph_callee_edges_0x101f2780"}, + {"id": "edge227", + "label": {"text": "next"}, + "sourceNodeId": "251_uninit", + "targetNodeId": "252_uncprop"}, + {"id": "edge228", + "label": {"text": "next"}, + "sourceNodeId": "250_crited", + "targetNodeId": "251_uninit"}, + {"id": "edge229", + "label": {"text": "next"}, + "sourceNodeId": "249_tsan", + "targetNodeId": "250_crited"}, + {"id": "edge230", + "label": {"text": "next"}, + "sourceNodeId": "248_asan", + "targetNodeId": "249_tsan"}, + {"id": "edge231", + "label": {"text": "next"}, + "sourceNodeId": "247_sancov", + "targetNodeId": "248_asan"}, + {"id": "edge232", + "label": {"text": "next"}, + "sourceNodeId": "246_rebuild_frequencies", + "targetNodeId": "247_sancov"}, + {"id": "edge233", + "label": {"text": "next"}, + "sourceNodeId": "245_dce", + "targetNodeId": "246_rebuild_frequencies"}, + {"id": "edge234", + "label": {"text": "next"}, + "sourceNodeId": "244_copyprop", + "targetNodeId": "245_dce"}, + {"id": "edge235", + "label": {"text": "next"}, + "sourceNodeId": "243_strlen", + "targetNodeId": "244_copyprop"}, + {"id": "edge236", + "label": {"text": "next"}, + "sourceNodeId": "242_fab", + "targetNodeId": "243_strlen"}, + {"id": "edge237", + "label": {"text": "next"}, + "sourceNodeId": "241_objsz", + "targetNodeId": "242_fab"}, + {"id": "edge238", + "label": {"text": "next"}, + "sourceNodeId": "240_post_ipa_warn", + "targetNodeId": "241_objsz"}, + {"id": "edge239", + "label": {"text": "next"}, + "sourceNodeId": "239_ccp", + "targetNodeId": "240_post_ipa_warn"}, + {"id": "edge240", + "label": {"text": "next"}, + "sourceNodeId": "238_switchlower", + "targetNodeId": "239_ccp"}, + {"id": "edge241", + "label": {"text": "next"}, + "sourceNodeId": "237_veclower2", + "targetNodeId": "238_switchlower"}, + {"id": "edge242", + "label": {"text": "next"}, + "sourceNodeId": "236_bitintlower", + "targetNodeId": "237_veclower2"}, + {"id": "edge243", + "label": {"text": "next"}, + "sourceNodeId": "235_cplxlower", + "targetNodeId": "236_bitintlower"}, + {"id": "edge244", + "label": {"text": "next"}, + "sourceNodeId": "*strip_predict_hints_0x101f5bb0", + "targetNodeId": "235_cplxlower"}, + {"id": "edge245", + "label": {"text": "next"}, + "sourceNodeId": "*remove_cgraph_callee_edges_0x101f5b50", + "targetNodeId": "*strip_predict_hints_0x101f5bb0"}, + {"id": "edge246", + "label": {"text": "sub"}, + "sourceNodeId": "*all_optimizations_g_0x101f5af0", + "targetNodeId": "*remove_cgraph_callee_edges_0x101f5b50"}, + {"id": "edge247", + "label": {"text": "next"}, + "sourceNodeId": "255_tmmemopt", + "targetNodeId": "256_tmedge"}, + {"id": "edge248", + "label": {"text": "next"}, + "sourceNodeId": "254_tmmark", + "targetNodeId": "255_tmmemopt"}, + {"id": "edge249", + "label": {"text": "sub"}, + "sourceNodeId": "*tminit_0x101f6370", + "targetNodeId": "254_tmmark"}, + {"id": "edge250", + "label": {"text": "next"}, + "sourceNodeId": "299_loop2_doloop", + "targetNodeId": "300_loop2_done"}, + {"id": "edge251", + "label": {"text": "next"}, + "sourceNodeId": "298_loop2_unroll", + "targetNodeId": "299_loop2_doloop"}, + {"id": "edge252", + "label": {"text": "next"}, + "sourceNodeId": "297_loop2_invariant", + "targetNodeId": "298_loop2_unroll"}, + {"id": "edge253", + "label": {"text": "next"}, + "sourceNodeId": "296_loop2_init", + "targetNodeId": "297_loop2_invariant"}, + {"id": "edge254", + "label": {"text": "sub"}, + "sourceNodeId": "295_loop2", + "targetNodeId": "296_loop2_init"}, + {"id": "edge255", + "label": {"text": "next"}, + "sourceNodeId": "355_split4", + "targetNodeId": "356_stack"}, + {"id": "edge256", + "label": {"text": "sub"}, + "sourceNodeId": "*stack_regs_0x101f8d10", + "targetNodeId": "355_split4"}, + {"id": "edge257", + "label": {"text": "next"}, + "sourceNodeId": "354_sched2", + "targetNodeId": "*stack_regs_0x101f8d10"}, + {"id": "edge258", + "label": {"text": "next"}, + "sourceNodeId": "353_split3", + "targetNodeId": "354_sched2"}, + {"id": "edge259", + "label": {"text": "next"}, + "sourceNodeId": "*leaf_regs_0x101f8bf0", + "targetNodeId": "353_split3"}, + {"id": "edge260", + "label": {"text": "next"}, + "sourceNodeId": "352_bbro", + "targetNodeId": "*leaf_regs_0x101f8bf0"}, + {"id": "edge261", + "label": {"text": "next"}, + "sourceNodeId": "351_rtl_dce", + "targetNodeId": "352_bbro"}, + {"id": "edge262", + "label": {"text": "next"}, + "sourceNodeId": "350_cprop_hardreg", + "targetNodeId": "351_rtl_dce"}, + {"id": "edge263", + "label": {"text": "next"}, + "sourceNodeId": "349_fold_mem_offsets", + "targetNodeId": "350_cprop_hardreg"}, + {"id": "edge264", + "label": {"text": "next"}, + "sourceNodeId": "348_rnreg", + "targetNodeId": "349_fold_mem_offsets"}, + {"id": "edge265", + "label": {"text": "next"}, + "sourceNodeId": "347_ce3", + "targetNodeId": "348_rnreg"}, + {"id": "edge266", + "label": {"text": "next"}, + "sourceNodeId": "346_peephole2", + "targetNodeId": "347_ce3"}, + {"id": "edge267", + "label": {"text": "next"}, + "sourceNodeId": "345_sched_fusion", + "targetNodeId": "346_peephole2"}, + {"id": "edge268", + "label": {"text": "next"}, + "sourceNodeId": "344_compgotos", + "targetNodeId": "345_sched_fusion"}, + {"id": "edge269", + "label": {"text": "next"}, + "sourceNodeId": "343_jump2", + "targetNodeId": "344_compgotos"}, + {"id": "edge270", + "label": {"text": "next"}, + "sourceNodeId": "342_csa", + "targetNodeId": "343_jump2"}, + {"id": "edge271", + "label": {"text": "next"}, + "sourceNodeId": "341_dse2", + "targetNodeId": "342_csa"}, + {"id": "edge272", + "label": {"text": "next"}, + "sourceNodeId": "340_pro_and_epilogue", + "targetNodeId": "341_dse2"}, + {"id": "edge273", + "label": {"text": "next"}, + "sourceNodeId": "339_cmpelim", + "targetNodeId": "340_pro_and_epilogue"}, + {"id": "edge274", + "label": {"text": "next"}, + "sourceNodeId": "338_ree", + "targetNodeId": "339_cmpelim"}, + {"id": "edge275", + "label": {"text": "next"}, + "sourceNodeId": "337_split2", + "targetNodeId": "338_ree"}, + {"id": "edge276", + "label": {"text": "next"}, + "sourceNodeId": "336_gcse2", + "targetNodeId": "337_split2"}, + {"id": "edge277", + "label": {"text": "next"}, + "sourceNodeId": "335_late_combine", + "targetNodeId": "336_gcse2"}, + {"id": "edge278", + "label": {"text": "next"}, + "sourceNodeId": "334_vzeroupper", + "targetNodeId": "335_late_combine"}, + {"id": "edge279", + "label": {"text": "next"}, + "sourceNodeId": "333_postreload", + "targetNodeId": "334_vzeroupper"}, + {"id": "edge280", + "label": {"text": "sub"}, + "sourceNodeId": "*all-postreload_0x101f8410", + "targetNodeId": "333_postreload"}, + {"id": "edge281", + "label": {"text": "next"}, + "sourceNodeId": "370_dwarf2", + "targetNodeId": "371_final"}, + {"id": "edge282", + "label": {"text": "next"}, + "sourceNodeId": "369_nothrow", + "targetNodeId": "370_dwarf2"}, + {"id": "edge283", + "label": {"text": "next"}, + "sourceNodeId": "368_shorten", + "targetNodeId": "369_nothrow"}, + {"id": "edge284", + "label": {"text": "next"}, + "sourceNodeId": "367_align_tight_loops", + "targetNodeId": "368_shorten"}, + {"id": "edge285", + "label": {"text": "next"}, + "sourceNodeId": "366_endbr_and_patchable_area", + "targetNodeId": "367_align_tight_loops"}, + {"id": "edge286", + "label": {"text": "next"}, + "sourceNodeId": "365_eh_ranges", + "targetNodeId": "366_endbr_and_patchable_area"}, + {"id": "edge287", + "label": {"text": "next"}, + "sourceNodeId": "364_split5", + "targetNodeId": "365_eh_ranges"}, + {"id": "edge288", + "label": {"text": "next"}, + "sourceNodeId": "363_dbr", + "targetNodeId": "364_split5"}, + {"id": "edge289", + "label": {"text": "next"}, + "sourceNodeId": "362_barriers", + "targetNodeId": "363_dbr"}, + {"id": "edge290", + "label": {"text": "next"}, + "sourceNodeId": "361_mach", + "targetNodeId": "362_barriers"}, + {"id": "edge291", + "label": {"text": "next"}, + "sourceNodeId": "*free_cfg_0x101f9010", + "targetNodeId": "361_mach"}, + {"id": "edge292", + "label": {"text": "next"}, + "sourceNodeId": "360_vartrack", + "targetNodeId": "*free_cfg_0x101f9010"}, + {"id": "edge293", + "label": {"text": "next"}, + "sourceNodeId": "359_alignments", + "targetNodeId": "360_vartrack"}, + {"id": "edge294", + "label": {"text": "next"}, + "sourceNodeId": "358_zero_call_used_regs", + "targetNodeId": "359_alignments"}, + {"id": "edge295", + "label": {"text": "sub"}, + "sourceNodeId": "*all-late_compilation_0x101f8e90", + "targetNodeId": "358_zero_call_used_regs"}, + {"id": "edge296", + "label": {"text": "next"}, + "sourceNodeId": "*all-late_compilation_0x101f8e90", + "targetNodeId": "372_dfinish"}, + {"id": "edge297", + "label": {"text": "next"}, + "sourceNodeId": "357_late_pro_and_epilogue", + "targetNodeId": "*all-late_compilation_0x101f8e90"}, + {"id": "edge298", + "label": {"text": "next"}, + "sourceNodeId": "*all-postreload_0x101f8410", + "targetNodeId": "357_late_pro_and_epilogue"}, + {"id": "edge299", + "label": {"text": "next"}, + "sourceNodeId": "332_reload", + "targetNodeId": "*all-postreload_0x101f8410"}, + {"id": "edge300", + "label": {"text": "next"}, + "sourceNodeId": "331_ira", + "targetNodeId": "332_reload"}, + {"id": "edge301", + "label": {"text": "next"}, + "sourceNodeId": "330_early_remat", + "targetNodeId": "331_ira"}, + {"id": "edge302", + "label": {"text": "next"}, + "sourceNodeId": "329_avoid_store_forwarding", + "targetNodeId": "330_early_remat"}, + {"id": "edge303", + "label": {"text": "next"}, + "sourceNodeId": "328_sched1", + "targetNodeId": "329_avoid_store_forwarding"}, + {"id": "edge304", + "label": {"text": "next"}, + "sourceNodeId": "327_lr_shrinkage", + "targetNodeId": "328_sched1"}, + {"id": "edge305", + "label": {"text": "next"}, + "sourceNodeId": "326_sms", + "targetNodeId": "327_lr_shrinkage"}, + {"id": "edge306", + "label": {"text": "next"}, + "sourceNodeId": "325_asmcons", + "targetNodeId": "326_sms"}, + {"id": "edge307", + "label": {"text": "next"}, + "sourceNodeId": "324_mode_sw", + "targetNodeId": "325_asmcons"}, + {"id": "edge308", + "label": {"text": "next"}, + "sourceNodeId": "*stack_ptr_mod_0x101f8050", + "targetNodeId": "324_mode_sw"}, + {"id": "edge309", + "label": {"text": "next"}, + "sourceNodeId": "323_no-opt dfinit", + "targetNodeId": "*stack_ptr_mod_0x101f8050"}, + {"id": "edge310", + "label": {"text": "next"}, + "sourceNodeId": "322_subreg3", + "targetNodeId": "323_no-opt dfinit"}, + {"id": "edge311", + "label": {"text": "next"}, + "sourceNodeId": "321_split1", + "targetNodeId": "322_subreg3"}, + {"id": "edge312", + "label": {"text": "next"}, + "sourceNodeId": "320_outof_cfglayout", + "targetNodeId": "321_split1"}, + {"id": "edge313", + "label": {"text": "next"}, + "sourceNodeId": "319_bbpart", + "targetNodeId": "320_outof_cfglayout"}, + {"id": "edge314", + "label": {"text": "next"}, + "sourceNodeId": "318_jump_after_combine", + "targetNodeId": "319_bbpart"}, + {"id": "edge315", + "label": {"text": "next"}, + "sourceNodeId": "317_ce2", + "targetNodeId": "318_jump_after_combine"}, + {"id": "edge316", + "label": {"text": "next"}, + "sourceNodeId": "316_stv", + "targetNodeId": "317_ce2"}, + {"id": "edge317", + "label": {"text": "next"}, + "sourceNodeId": "315_rrvl", + "targetNodeId": "316_stv"}, + {"id": "edge318", + "label": {"text": "next"}, + "sourceNodeId": "314_rpad", + "targetNodeId": "315_rrvl"}, + {"id": "edge319", + "label": {"text": "next"}, + "sourceNodeId": "313_late_combine", + "targetNodeId": "314_rpad"}, + {"id": "edge320", + "label": {"text": "next"}, + "sourceNodeId": "312_combine", + "targetNodeId": "313_late_combine"}, + {"id": "edge321", + "label": {"text": "next"}, + "sourceNodeId": "311_ext_dce", + "targetNodeId": "312_combine"}, + {"id": "edge322", + "label": {"text": "next"}, + "sourceNodeId": "310_ud_dce", + "targetNodeId": "311_ext_dce"}, + {"id": "edge323", + "label": {"text": "next"}, + "sourceNodeId": "309_init-regs", + "targetNodeId": "310_ud_dce"}, + {"id": "edge324", + "label": {"text": "next"}, + "sourceNodeId": "308_auto_inc_dec", + "targetNodeId": "309_init-regs"}, + {"id": "edge325", + "label": {"text": "next"}, + "sourceNodeId": "307_fwprop2", + "targetNodeId": "308_auto_inc_dec"}, + {"id": "edge326", + "label": {"text": "next"}, + "sourceNodeId": "306_dse1", + "targetNodeId": "307_fwprop2"}, + {"id": "edge327", + "label": {"text": "next"}, + "sourceNodeId": "305_cse2", + "targetNodeId": "306_dse1"}, + {"id": "edge328", + "label": {"text": "next"}, + "sourceNodeId": "304_stv", + "targetNodeId": "305_cse2"}, + {"id": "edge329", + "label": {"text": "next"}, + "sourceNodeId": "303_cprop", + "targetNodeId": "304_stv"}, + {"id": "edge330", + "label": {"text": "next"}, + "sourceNodeId": "302_web", + "targetNodeId": "303_cprop"}, + {"id": "edge331", + "label": {"text": "next"}, + "sourceNodeId": "301_subreg2", + "targetNodeId": "302_web"}, + {"id": "edge332", + "label": {"text": "next"}, + "sourceNodeId": "295_loop2", + "targetNodeId": "301_subreg2"}, + {"id": "edge333", + "label": {"text": "next"}, + "sourceNodeId": "294_reginfo", + "targetNodeId": "295_loop2"}, + {"id": "edge334", + "label": {"text": "next"}, + "sourceNodeId": "293_apx_nfcvt", + "targetNodeId": "294_reginfo"}, + {"id": "edge335", + "label": {"text": "next"}, + "sourceNodeId": "292_ce1", + "targetNodeId": "293_apx_nfcvt"}, + {"id": "edge336", + "label": {"text": "next"}, + "sourceNodeId": "291_cse_local", + "targetNodeId": "292_ce1"}, + {"id": "edge337", + "label": {"text": "next"}, + "sourceNodeId": "290_store_motion", + "targetNodeId": "291_cse_local"}, + {"id": "edge338", + "label": {"text": "next"}, + "sourceNodeId": "289_cprop", + "targetNodeId": "290_store_motion"}, + {"id": "edge339", + "label": {"text": "next"}, + "sourceNodeId": "288_hardreg_pre", + "targetNodeId": "289_cprop"}, + {"id": "edge340", + "label": {"text": "next"}, + "sourceNodeId": "287_hoist", + "targetNodeId": "288_hardreg_pre"}, + {"id": "edge341", + "label": {"text": "next"}, + "sourceNodeId": "286_rtl pre", + "targetNodeId": "287_hoist"}, + {"id": "edge342", + "label": {"text": "next"}, + "sourceNodeId": "285_cprop", + "targetNodeId": "286_rtl pre"}, + {"id": "edge343", + "label": {"text": "next"}, + "sourceNodeId": "284_fwprop1", + "targetNodeId": "285_cprop"}, + {"id": "edge344", + "label": {"text": "next"}, + "sourceNodeId": "283_cse1", + "targetNodeId": "284_fwprop1"}, + {"id": "edge345", + "label": {"text": "next"}, + "sourceNodeId": "282_dfinit", + "targetNodeId": "283_cse1"}, + {"id": "edge346", + "label": {"text": "next"}, + "sourceNodeId": "281_subreg1", + "targetNodeId": "282_dfinit"}, + {"id": "edge347", + "label": {"text": "next"}, + "sourceNodeId": "280_jump", + "targetNodeId": "281_subreg1"}, + {"id": "edge348", + "label": {"text": "next"}, + "sourceNodeId": "279_into_cfglayout", + "targetNodeId": "280_jump"}, + {"id": "edge349", + "label": {"text": "next"}, + "sourceNodeId": "278_vregs", + "targetNodeId": "279_into_cfglayout"}, + {"id": "edge350", + "label": {"text": "sub"}, + "sourceNodeId": "*rest_of_compilation_0x101f6e90", + "targetNodeId": "278_vregs"}, + {"id": "edge351", + "label": {"text": "next"}, + "sourceNodeId": "*rest_of_compilation_0x101f6e90", + "targetNodeId": "*clean_state_0x101f9500"}, + {"id": "edge352", + "label": {"text": "next"}, + "sourceNodeId": "277_expand", + "targetNodeId": "*rest_of_compilation_0x101f6e90"}, + {"id": "edge353", + "label": {"text": "next"}, + "sourceNodeId": "*warn_function_noreturn_0x101f6dd0", + "targetNodeId": "277_expand"}, + {"id": "edge354", + "label": {"text": "next"}, + "sourceNodeId": "276_optimized", + "targetNodeId": "*warn_function_noreturn_0x101f6dd0"}, + {"id": "edge355", + "label": {"text": "next"}, + "sourceNodeId": "275_waccess", + "targetNodeId": "276_optimized"}, + {"id": "edge356", + "label": {"text": "next"}, + "sourceNodeId": "274_hardcmp", + "targetNodeId": "275_waccess"}, + {"id": "edge357", + "label": {"text": "next"}, + "sourceNodeId": "273_hardcbr", + "targetNodeId": "274_hardcmp"}, + {"id": "edge358", + "label": {"text": "next"}, + "sourceNodeId": "272_isel", + "targetNodeId": "273_hardcbr"}, + {"id": "edge359", + "label": {"text": "next"}, + "sourceNodeId": "271_nrv", + "targetNodeId": "272_isel"}, + {"id": "edge360", + "label": {"text": "next"}, + "sourceNodeId": "270_resx", + "targetNodeId": "271_nrv"}, + {"id": "edge361", + "label": {"text": "next"}, + "sourceNodeId": "269_ehcleanup", + "targetNodeId": "270_resx"}, + {"id": "edge362", + "label": {"text": "next"}, + "sourceNodeId": "268_sanopt", + "targetNodeId": "269_ehcleanup"}, + {"id": "edge363", + "label": {"text": "next"}, + "sourceNodeId": "267_musttail", + "targetNodeId": "268_sanopt"}, + {"id": "edge364", + "label": {"text": "next"}, + "sourceNodeId": "266_tsan0", + "targetNodeId": "267_musttail"}, + {"id": "edge365", + "label": {"text": "next"}, + "sourceNodeId": "265_asan0", + "targetNodeId": "266_tsan0"}, + {"id": "edge366", + "label": {"text": "next"}, + "sourceNodeId": "264_switchlower_O0", + "targetNodeId": "265_asan0"}, + {"id": "edge367", + "label": {"text": "next"}, + "sourceNodeId": "263_sancov_O0", + "targetNodeId": "264_switchlower_O0"}, + {"id": "edge368", + "label": {"text": "next"}, + "sourceNodeId": "262_bitintlower0", + "targetNodeId": "263_sancov_O0"}, + {"id": "edge369", + "label": {"text": "next"}, + "sourceNodeId": "261_cplxlower0", + "targetNodeId": "262_bitintlower0"}, + {"id": "edge370", + "label": {"text": "next"}, + "sourceNodeId": "260_veclower", + "targetNodeId": "261_cplxlower0"}, + {"id": "edge371", + "label": {"text": "next"}, + "sourceNodeId": "259_lower_vaarg", + "targetNodeId": "260_veclower"}, + {"id": "edge372", + "label": {"text": "next"}, + "sourceNodeId": "258_vtable-verify", + "targetNodeId": "259_lower_vaarg"}, + {"id": "edge373", + "label": {"text": "next"}, + "sourceNodeId": "257_simduid", + "targetNodeId": "258_vtable-verify"}, + {"id": "edge374", + "label": {"text": "next"}, + "sourceNodeId": "*tminit_0x101f6370", + "targetNodeId": "257_simduid"}, + {"id": "edge375", + "label": {"text": "next"}, + "sourceNodeId": "253_assumptions", + "targetNodeId": "*tminit_0x101f6370"}, + {"id": "edge376", + "label": {"text": "next"}, + "sourceNodeId": "*all_optimizations_g_0x101f5af0", + "targetNodeId": "253_assumptions"}, + {"id": "edge377", + "label": {"text": "next"}, + "sourceNodeId": "*all_optimizations_0x101f2720", + "targetNodeId": "*all_optimizations_g_0x101f5af0"}, + {"id": "edge378", + "label": {"text": "next"}, + "sourceNodeId": "114_hardcfr", + "targetNodeId": "*all_optimizations_0x101f2720"}, + {"id": "edge379", + "label": {"text": "next"}, + "sourceNodeId": "113_adjust_alignment", + "targetNodeId": "114_hardcfr"}, + {"id": "edge380", + "label": {"text": "next"}, + "sourceNodeId": "112_omptargetlink", + "targetNodeId": "113_adjust_alignment"}, + {"id": "edge381", + "label": {"text": "next"}, + "sourceNodeId": "111_ompdevlow", + "targetNodeId": "112_omptargetlink"}, + {"id": "edge382", + "label": {"text": "next"}, + "sourceNodeId": "110_oaccdevlow", + "targetNodeId": "111_ompdevlow"}, + {"id": "edge383", + "label": {"text": "next"}, + "sourceNodeId": "109_omp_oacc_neuter_broadcast", + "targetNodeId": "110_oaccdevlow"}, + {"id": "edge384", + "label": {"text": "next"}, + "sourceNodeId": "108_oaccloops", + "targetNodeId": "109_omp_oacc_neuter_broadcast"}, + {"id": "edge385", + "label": {"text": "next"}, + "sourceNodeId": "107_ehdisp", + "targetNodeId": "108_oaccloops"}, + {"id": "edge386", + "label": {"text": "next"}, + "sourceNodeId": "106_fixup_cfg", + "targetNodeId": "107_ehdisp"}]}]}]} + +/* { dg-begin-multiline-output "" } +In function 'test_graphs': +/home/david/gcc-newgit-gcc16/src/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c:8:3: error: this is a placeholder error, with graphs + { dg-end-multiline-output "" } */ + +/* Use a Python script to verify various properties about the generated + .html file: + { dg-final { run-html-pytest graphs.sarif "2.1.0-valid/graphs-check-html.py" } } */ + +/* Use a Python script to verify various properties about the *generated* + .sarif file: + { dg-final { run-sarif-pytest graphs.roundtrip "2.1.0-valid/graphs-check-sarif-roundtrip.py" } } */ diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 9a5479a..3d23f17 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -114,43 +114,6 @@ struct replace_decls_d tree to_context; }; -/* Hash table to store last discriminator assigned for each locus. */ -struct locus_discrim_map -{ - int location_line; - int discriminator; -}; - -/* Hashtable helpers. */ - -struct locus_discrim_hasher : free_ptr_hash <locus_discrim_map> -{ - static inline hashval_t hash (const locus_discrim_map *); - static inline bool equal (const locus_discrim_map *, - const locus_discrim_map *); -}; - -/* Trivial hash function for a location_t. ITEM is a pointer to - a hash table entry that maps a location_t to a discriminator. */ - -inline hashval_t -locus_discrim_hasher::hash (const locus_discrim_map *item) -{ - return item->location_line; -} - -/* Equality function for the locus-to-discriminator map. A and B - point to the two hash table entries to compare. */ - -inline bool -locus_discrim_hasher::equal (const locus_discrim_map *a, - const locus_discrim_map *b) -{ - return a->location_line == b->location_line; -} - -static hash_table<locus_discrim_hasher> *discriminator_per_locus; - /* Basic blocks and flowgraphs. */ static void make_blocks (gimple_seq); @@ -168,7 +131,6 @@ static edge gimple_try_redirect_by_replacing_jump (edge, basic_block); static inline bool stmt_starts_bb_p (gimple *, gimple *); static bool gimple_verify_flow_info (void); static void gimple_make_forwarder_block (edge); -static gimple *first_non_label_nondebug_stmt (basic_block); static bool verify_gimple_transaction (gtransaction *); static bool call_can_make_abnormal_goto (gimple *); @@ -247,12 +209,9 @@ build_gimple_cfg (gimple_seq seq) group_case_labels (); /* Create the edges of the flowgraph. */ - discriminator_per_locus = new hash_table<locus_discrim_hasher> (13); make_edges (); assign_discriminators (); cleanup_dead_labels (); - delete discriminator_per_locus; - discriminator_per_locus = NULL; } /* Look for ANNOTATE calls with loop annotation kind in BB; if found, remove @@ -1120,77 +1079,41 @@ gimple_find_sub_bbs (gimple_seq seq, gimple_stmt_iterator *gsi) return true; } -/* Find the next available discriminator value for LOCUS. The - discriminator distinguishes among several basic blocks that - share a common locus, allowing for more accurate sample-based - profiling. */ - -static int -next_discriminator_for_locus (int line) +/* Auto-profile needs discriminator to distinguish statements with same line + number (file name is ignored) which are in different basic block. This + map keeps track of current discriminator for a given line number. */ +struct discrim_entry { - struct locus_discrim_map item; - struct locus_discrim_map **slot; - - item.location_line = line; - item.discriminator = 0; - slot = discriminator_per_locus->find_slot_with_hash (&item, line, INSERT); - gcc_assert (slot); - if (*slot == HTAB_EMPTY_ENTRY) - { - *slot = XNEW (struct locus_discrim_map); - gcc_assert (*slot); - (*slot)->location_line = line; - (*slot)->discriminator = 0; - } - (*slot)->discriminator++; - return (*slot)->discriminator; -} - -/* Return TRUE if LOCUS1 and LOCUS2 refer to the same source line. */ - -static bool -same_line_p (location_t locus1, expanded_location *from, location_t locus2) -{ - expanded_location to; - - if (locus1 == locus2) - return true; - - to = expand_location (locus2); - - if (from->line != to.line) - return false; - if (from->file == to.file) - return true; - return (from->file != NULL - && to.file != NULL - && filename_cmp (from->file, to.file) == 0); -} + /* ID of basic block we saw line number last time. */ + unsigned int bb_id; + /* Discriminator we used. */ + unsigned int discrim; +}; -/* Assign a unique discriminator value to all statements in block bb that - have the same line number as locus. */ +/* Return updated LOC with discriminator for use in basic block BB_ID. + MAP keeps track of current values. */ -static void -assign_discriminator (location_t locus, basic_block bb) +location_t +assign_discriminator (location_t loc, unsigned int bb_id, + hash_map<int_hash <int64_t, -1, -2>, discrim_entry> &map) { - gimple_stmt_iterator gsi; - int discriminator; - - if (locus == UNKNOWN_LOCATION) - return; - - expanded_location locus_e = expand_location (locus); - - discriminator = next_discriminator_for_locus (locus_e.line); - - for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + bool existed; + discrim_entry &e = map.get_or_insert (LOCATION_LINE (loc), &existed); + gcc_checking_assert (!has_discriminator (loc)); + if (!existed) { - gimple *stmt = gsi_stmt (gsi); - location_t stmt_locus = gimple_location (stmt); - if (same_line_p (locus, &locus_e, stmt_locus)) - gimple_set_location (stmt, - location_with_discriminator (stmt_locus, discriminator)); + e.bb_id = bb_id; + e.discrim = 0; + return loc; + } + if (e.bb_id != bb_id) + { + e.bb_id = bb_id; + e.discrim++; } + if (e.discrim) + return location_with_discriminator (loc, e.discrim); + return loc; } /* Assign discriminators to statement locations. */ @@ -1198,92 +1121,54 @@ assign_discriminator (location_t locus, basic_block bb) static void assign_discriminators (void) { + hash_map<int_hash <int64_t, -1, -2>, discrim_entry> map (13); + unsigned int bb_id = 0; basic_block bb; - FOR_EACH_BB_FN (bb, cfun) { - edge e; - edge_iterator ei; - gimple_stmt_iterator gsi; - location_t curr_locus = UNKNOWN_LOCATION; - expanded_location curr_locus_e = {}; - int curr_discr = 0; - + location_t prev_loc = UNKNOWN_LOCATION, prev_replacement = UNKNOWN_LOCATION; /* Traverse the basic block, if two function calls within a basic block are mapped to the same line, assign a new discriminator because a call stmt could be a split point of a basic block. */ - for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + for (gimple_stmt_iterator gsi = gsi_start_bb (bb); + !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); - - /* Don't allow debug stmts to affect discriminators, but - allow them to take discriminators when they're on the - same line as the preceding nondebug stmt. */ - if (is_gimple_debug (stmt)) - { - if (curr_locus != UNKNOWN_LOCATION - && same_line_p (curr_locus, &curr_locus_e, - gimple_location (stmt))) - { - location_t loc = gimple_location (stmt); - location_t dloc = location_with_discriminator (loc, - curr_discr); - gimple_set_location (stmt, dloc); - } - continue; - } - if (curr_locus == UNKNOWN_LOCATION) - { - curr_locus = gimple_location (stmt); - curr_locus_e = expand_location (curr_locus); - } - else if (!same_line_p (curr_locus, &curr_locus_e, gimple_location (stmt))) - { - curr_locus = gimple_location (stmt); - curr_locus_e = expand_location (curr_locus); - curr_discr = 0; - } - else if (curr_discr != 0) + location_t loc = gimple_location (stmt); + if (loc == UNKNOWN_LOCATION) + continue; + if (loc == prev_loc) + gimple_set_location (stmt, prev_replacement); + else { - location_t loc = gimple_location (stmt); - location_t dloc = location_with_discriminator (loc, curr_discr); - gimple_set_location (stmt, dloc); + prev_loc = loc; + prev_replacement = assign_discriminator (loc, bb_id, map); + gimple_set_location (stmt, prev_replacement); } - /* Allocate a new discriminator for CALL stmt. */ + /* Break basic blocks after each call. This is requires so each + call site has unque discriminator. + More correctly, we can break after each statement that can possibly + terinate execution of the basic block, but for auto-profile this + precision is probably not useful. */ if (gimple_code (stmt) == GIMPLE_CALL) - curr_discr = next_discriminator_for_locus (curr_locus_e.line); - } - - gimple *last = last_nondebug_stmt (bb); - location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION; - if (locus == UNKNOWN_LOCATION) - continue; - - expanded_location locus_e = expand_location (locus); - - FOR_EACH_EDGE (e, ei, bb->succs) - { - gimple *first = first_non_label_nondebug_stmt (e->dest); - gimple *last = last_nondebug_stmt (e->dest); - - gimple *stmt_on_same_line = NULL; - if (first && same_line_p (locus, &locus_e, - gimple_location (first))) - stmt_on_same_line = first; - else if (last && same_line_p (locus, &locus_e, - gimple_location (last))) - stmt_on_same_line = last; - - if (stmt_on_same_line) { - if (has_discriminator (gimple_location (stmt_on_same_line)) - && !has_discriminator (locus)) - assign_discriminator (locus, bb); - else - assign_discriminator (locus, e->dest); + prev_loc = UNKNOWN_LOCATION; + bb_id++; } } + /* IF basic block has multiple sucessors, consdier every edge as a separate + block. */ + if (!single_succ_p (bb)) + bb_id++; + for (edge e : bb->succs) + if (e->goto_locus != UNKNOWN_LOCATION) + { + e->goto_locus = assign_discriminator (e->goto_locus, bb_id, map); + bb_id++; + } + bb_id++; } + } /* Create the edges for a GIMPLE_COND starting at block BB. */ @@ -2948,16 +2833,6 @@ first_stmt (basic_block bb) return stmt; } -/* Return the first non-label/non-debug statement in basic block BB. */ - -static gimple * -first_non_label_nondebug_stmt (basic_block bb) -{ - gimple_stmt_iterator i; - i = gsi_start_nondebug_after_labels_bb (bb); - return !gsi_end_p (i) ? gsi_stmt (i) : NULL; -} - /* Return the last statement in basic block BB. */ gimple * diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc index 2d13ab7..8545eff 100644 --- a/gcc/tree-object-size.cc +++ b/gcc/tree-object-size.cc @@ -851,37 +851,32 @@ addr_object_size (struct object_size_info *osi, const_tree ptr, /* Compute __builtin_object_size for a CALL to .ACCESS_WITH_SIZE, OBJECT_SIZE_TYPE is the second argument from __builtin_object_size. - The 2nd, 3rd, and the 4th parameters of the call determine the size of + + The 2nd, 3rd, and 4th parameters of the call determine the size of the CALL: 2nd argument REF_TO_SIZE: The reference to the size of the object, - 3rd argument CLASS_OF_SIZE: The size referenced by the REF_TO_SIZE represents - 0: the number of bytes; - 1: the number of the elements of the object type; - 4th argument TYPE_OF_SIZE: A constant 0 with its TYPE being the same as the TYPE - of the object referenced by REF_TO_SIZE - 6th argument: A constant 0 with the pointer TYPE to the original flexible - array type. - - The size of the element can be retrived from the TYPE of the 6th argument - of the call, which is the pointer to the array type. */ + 3rd argument TYPE_OF_SIZE + ACCESS_MODE: An integer constant with a pointer + TYPE. + The pointee TYPE of this pointer TYPE is the TYPE of the object referenced + by REF_TO_SIZE. + + 4th argument: The TYPE_SIZE_UNIT of the element TYPE of the array. */ + static tree access_with_size_object_size (const gcall *call, int object_size_type) { /* If not for dynamic object size, return. */ if ((object_size_type & OST_DYNAMIC) == 0) return size_unknown (object_size_type); - gcc_assert (gimple_call_internal_p (call, IFN_ACCESS_WITH_SIZE)); - /* The type of the 6th argument type is the pointer TYPE to the original - flexible array type. */ - tree pointer_to_array_type = TREE_TYPE (gimple_call_arg (call, 5)); - gcc_assert (POINTER_TYPE_P (pointer_to_array_type)); - tree element_type = TREE_TYPE (TREE_TYPE (pointer_to_array_type)); - tree element_size = TYPE_SIZE_UNIT (element_type); + tree ref_to_size = gimple_call_arg (call, 1); - unsigned int class_of_size = TREE_INT_CST_LOW (gimple_call_arg (call, 2)); - tree type = TREE_TYPE (gimple_call_arg (call, 3)); + tree type = TREE_TYPE (TREE_TYPE (gimple_call_arg (call, 2))); + + /* The 4th argument is the TYPE_SIZE_UNIT for the element of the original + flexible array. */ + tree element_size = gimple_call_arg (call, 3); tree size = fold_build2 (MEM_REF, type, ref_to_size, build_int_cst (ptr_type_node, 0)); @@ -895,12 +890,9 @@ access_with_size_object_size (const gcall *call, int object_size_type) build_zero_cst (type), size); } - if (class_of_size == 1) - size = size_binop (MULT_EXPR, - fold_convert (sizetype, size), - fold_convert (sizetype, element_size)); - else - size = fold_convert (sizetype, size); + size = size_binop (MULT_EXPR, + fold_convert (sizetype, size), + fold_convert (sizetype, element_size)); if (!todo) todo = TODO_update_ssa_only_virtuals; diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 8ea0f45..734b7ef 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -7316,17 +7316,17 @@ vectorizable_reduction (loop_vec_info loop_vinfo, unsigned reduc_chain_length = 0; bool only_slp_reduc_chain = true; stmt_info = NULL; - slp_tree slp_for_stmt_info = slp_node_instance->root; + slp_tree slp_for_stmt_info = NULL; + slp_tree vdef_slp = slp_node_instance->root; /* For double-reductions we start SLP analysis at the inner loop LC PHI which is the def of the outer loop live stmt. */ if (STMT_VINFO_DEF_TYPE (reduc_info) == vect_double_reduction_def) - slp_for_stmt_info = SLP_TREE_CHILDREN (slp_for_stmt_info)[0]; + vdef_slp = SLP_TREE_CHILDREN (vdef_slp)[0]; while (reduc_def != PHI_RESULT (reduc_def_phi)) { stmt_vec_info def = loop_vinfo->lookup_def (reduc_def); stmt_vec_info vdef = vect_stmt_to_vectorize (def); int reduc_idx = STMT_VINFO_REDUC_IDX (vdef); - if (reduc_idx == -1) { if (dump_enabled_p ()) @@ -7343,14 +7343,9 @@ vectorizable_reduction (loop_vec_info loop_vinfo, the SLP node with live lane zero the other live lanes also need to be identified as part of a reduction to be able to skip code generation for them. */ - if (slp_for_stmt_info) - { - for (auto s : SLP_TREE_SCALAR_STMTS (slp_for_stmt_info)) - if (STMT_VINFO_LIVE_P (s)) - STMT_VINFO_REDUC_DEF (vect_orig_stmt (s)) = phi_info; - } - else if (STMT_VINFO_LIVE_P (vdef)) - STMT_VINFO_REDUC_DEF (def) = phi_info; + for (auto s : SLP_TREE_SCALAR_STMTS (vdef_slp)) + if (STMT_VINFO_LIVE_P (s)) + STMT_VINFO_REDUC_DEF (vect_orig_stmt (s)) = phi_info; gimple_match_op op; if (!gimple_extract_op (vdef->stmt, &op)) { @@ -7369,12 +7364,16 @@ vectorizable_reduction (loop_vec_info loop_vinfo, "conversion in the reduction chain.\n"); return false; } + vdef_slp = SLP_TREE_CHILDREN (vdef_slp)[0]; } else { /* First non-conversion stmt. */ if (!stmt_info) - stmt_info = vdef; + { + stmt_info = vdef; + slp_for_stmt_info = vdef_slp; + } if (lane_reducing_op_p (op.code)) { @@ -7382,7 +7381,7 @@ vectorizable_reduction (loop_vec_info loop_vinfo, reduction. */ gcc_assert (reduc_idx > 0 && reduc_idx == (int) op.num_ops - 1); - slp_tree op_node = SLP_TREE_CHILDREN (slp_for_stmt_info)[0]; + slp_tree op_node = SLP_TREE_CHILDREN (vdef_slp)[0]; tree vectype_op = SLP_TREE_VECTYPE (op_node); tree type_op = TREE_TYPE (op.ops[0]); if (!vectype_op) @@ -7413,14 +7412,14 @@ vectorizable_reduction (loop_vec_info loop_vinfo, < GET_MODE_SIZE (SCALAR_TYPE_MODE (type_op)))) vectype_in = vectype_op; } - else + else if (!vectype_in) vectype_in = STMT_VINFO_VECTYPE (phi_info); + if (!REDUC_GROUP_FIRST_ELEMENT (vdef)) + vdef_slp = SLP_TREE_CHILDREN (vdef_slp)[reduc_idx]; } reduc_def = op.ops[reduc_idx]; reduc_chain_length++; - if (!stmt_info) - slp_for_stmt_info = SLP_TREE_CHILDREN (slp_for_stmt_info)[0]; } /* PHIs should not participate in patterns. */ gcc_assert (!STMT_VINFO_RELATED_STMT (phi_info)); @@ -11079,7 +11078,7 @@ vect_get_loop_len (loop_vec_info loop_vinfo, gimple_stmt_iterator *gsi, factor = exact_div (nunits1, nunits2).to_constant (); tree iv_type = LOOP_VINFO_RGROUP_IV_TYPE (loop_vinfo); gimple_seq seq = NULL; - loop_len = gimple_build (&seq, RDIV_EXPR, iv_type, loop_len, + loop_len = gimple_build (&seq, EXACT_DIV_EXPR, iv_type, loop_len, build_int_cst (iv_type, factor)); if (seq) gsi_insert_seq_before (gsi, seq, GSI_SAME_STMT); diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 5ef45fd..ad753869 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -5068,9 +5068,15 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size, tree args0 = gimple_cond_lhs (stmt); tree args1 = gimple_cond_rhs (stmt); - /* These should be enforced by cond lowering. */ - gcc_assert (gimple_cond_code (stmt) == NE_EXPR); - gcc_assert (zerop (args1)); + /* These should be enforced by cond lowering, but if it failed + bail. */ + if (gimple_cond_code (stmt) != NE_EXPR + || TREE_TYPE (args0) != boolean_type_node + || !integer_zerop (args1)) + { + roots.release (); + continue; + } /* An argument without a loop def will be codegened from vectorizing the root gcond itself. As such we don't need to try to build an SLP tree diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index 7e907b6..f05492e 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,9 @@ +2025-07-10 Jan Dubiec <jdx@o2.pl> + + PR target/116363 + * libgcc2.c (__fixunssfDI): Fix SFtype to UDWtype conversion for targets + without LIBGCC2_HAS_DF_MODE defined + 2025-05-27 Jakub Jelinek <jakub@redhat.com> * config/t-softfp (softfp_bid_list): Don't guard with diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c index faefff3..df99c78 100644 --- a/libgcc/libgcc2.c +++ b/libgcc/libgcc2.c @@ -2187,36 +2187,21 @@ __fixunssfDI (SFtype a) if (a < 1) return 0; if (a < Wtype_MAXp1_F) - return (UWtype)a; + return (UWtype) a; if (a < Wtype_MAXp1_F * Wtype_MAXp1_F) { - /* Since we know that there are fewer significant bits in the SFmode - quantity than in a word, we know that we can convert out all the - significant bits in one step, and thus avoid losing bits. */ - - /* ??? This following loop essentially performs frexpf. If we could - use the real libm function, or poke at the actual bits of the fp - format, it would be significantly faster. */ - - UWtype shift = 0, counter; - SFtype msb; - - a /= Wtype_MAXp1_F; - for (counter = W_TYPE_SIZE / 2; counter != 0; counter >>= 1) - { - SFtype counterf = (UWtype)1 << counter; - if (a >= counterf) - { - shift |= counter; - a /= counterf; - } - } - - /* Rescale into the range of one word, extract the bits of that - one word, and shift the result into position. */ - a *= Wtype_MAXp1_F; - counter = a; - return (DWtype)counter << shift; + /* We assume that SFtype -> UWtype and UWtype -> UDWtype casts work + properly. Obviously, we *cannot* assume that SFtype -> UDWtype + works as expected. */ + SFtype a_hi, a_lo; + + a_hi = a / Wtype_MAXp1_F; + a_lo = a - a_hi * Wtype_MAXp1_F; + + /* A lot of parentheses. This is to make it very clear what is + the sequence of operations. */ + return ((UDWtype) ((UWtype) a_hi)) << W_TYPE_SIZE + | (UDWtype) ((UWtype) a_lo); } return -1; #else diff --git a/libgcobol/ChangeLog b/libgcobol/ChangeLog index 25ef409..221b3009 100644 --- a/libgcobol/ChangeLog +++ b/libgcobol/ChangeLog @@ -1,3 +1,7 @@ +2025-07-10 James K. Lowden <jklowden@cobolworx.com> + + * common-defs.h (cdf_enabled_exceptions): Use new CDF state. + 2025-07-09 Robert Dubner <rdubner@symas.com> James K. Lowden <jklowden@cobolworx.com> diff --git a/libgcobol/common-defs.h b/libgcobol/common-defs.h index a78022a..a3884fd 100644 --- a/libgcobol/common-defs.h +++ b/libgcobol/common-defs.h @@ -589,7 +589,7 @@ class cbl_enabled_exceptions_t : protected std::set<cbl_enabled_exception_t> cbl_enabled_exceptions_t& operator=( const cbl_enabled_exceptions_t& ) = default; }; -extern cbl_enabled_exceptions_t enabled_exceptions; +cbl_enabled_exceptions_t& cdf_enabled_exceptions(); template <typename T> T enabled_exception_match( T beg, T end, ec_type_t type, size_t file ) { diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8abb719..716a516 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,122 @@ +2025-07-11 Jakub Jelinek <jakub@redhat.com> + + * libsupc++/exception_ptr.h: Implement C++26 P3748R0 - Inspecting + exception_ptr should be constexpr. + (std::exception_ptr_cast): Make constexpr, remove inline keyword. Add + static_asserts for Mandates. For if consteval use std::rethrow_exception, + catch it and return its address or nullptr. + * testsuite/18_support/exception_ptr/exception_ptr_cast.cc (E::~E): Add + constexpr. + (G::G): Likewise. + (test01): Likewise. Return bool and take bool argument, throw if the + argument is true. Add static_assert(test01(false)). + (main): Call test01(true) in try. + +2025-07-11 Jonathan Wakely <jwakely@redhat.com> + + * include/bits/cpp_type_traits.h (__is_floating<__float128>): + Do not depend on __STRICT_ANSI__. + * include/bits/stl_algobase.h (__size_to_integer(__float128)): + Likewise. + * include/std/type_traits (__is_floating_point_helper<__float128>): + Likewise. + +2025-07-11 Jonathan Wakely <jwakely@redhat.com> + + PR libstdc++/96710 + * include/bits/cpp_type_traits.h (__is_integer): Define explicit + specializations for __int128. + (__memcpyable_integer): Remove explicit specializations for + __int128. + * include/bits/iterator_concepts.h (incrementable_traits): + Likewise. + (__is_signed_int128, __is_unsigned_int128, __is_int128): Remove. + (__is_integer_like, __is_signed_integer_like): Remove check for + __int128. + * include/bits/max_size_type.h: Remove all uses of __is_int128 + in constraints. + * include/bits/ranges_base.h (__to_unsigned_like): Remove + overloads for __int128. + (ranges::ssize): Remove special case for __int128. + * include/bits/stl_algobase.h (__size_to_integer): Define + __int128 overloads for strict modes. + * include/ext/numeric_traits.h (__is_integer_nonstrict): Remove + explicit specializations for __int128. + * include/std/charconv (to_chars): Define overloads for + __int128. + * include/std/format (__format::make_unsigned_t): Remove. + (__format::to_chars): Remove. + * include/std/limits (numeric_limits): Define explicit + specializations for __int128. + * include/std/type_traits (__is_integral_helper): Likewise. + (__make_unsigned, __make_signed): Likewise. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + PR c++/117785 + * include/bits/version.def (constexpr_exceptions): New. + * include/bits/version.h: Regenerate. + * libsupc++/exception (std::bad_exception::bad_exception): Add + _GLIBCXX26_CONSTEXPR. + (std::bad_exception::~bad_exception, std::bad_exception::what): For + C++26 add constexpr and define inline. + * libsupc++/exception.h (std::exception::exception, + std::exception::operator=): Add _GLIBCXX26_CONSTEXPR. + (std::exception::~exception, std::exception::what): For C++26 add + constexpr and define inline. + * libsupc++/exception_ptr.h (std::make_exception_ptr): Add + _GLIBCXX26_CONSTEXPR. For if consteval use just throw with + current_exception() in catch. + (std::exception_ptr::exception_ptr(void*)): For C++26 add constexpr + and define inline. + (std::exception_ptr::exception_ptr()): Add _GLIBCXX26_CONSTEXPR. + (std::exception_ptr::exception_ptr(const exception_ptr&)): Likewise. + Use __builtin_eh_ptr_adjust_ref if consteval and compiler has it + instead of _M_addref. + (std::exception_ptr::exception_ptr(nullptr_t)): Add + _GLIBCXX26_CONSTEXPR. + (std::exception_ptr::exception_ptr(exception_ptr&&)): Likewise. + (std::exception_ptr::operator=): Likewise. + (std::exception_ptr::~exception_ptr): Likewise. Use + __builtin_eh_ptr_adjust_ref if consteval and compiler has it + instead of _M_release. + (std::exception_ptr::swap): Add _GLIBCXX26_CONSTEXPR. + (std::exception_ptr::operator bool): Likewise. + (std::exception_ptr::operator==): Likewise. + * libsupc++/nested_exception.h + (std::nested_exception::nested_exception): Add _GLIBCXX26_CONSTEXPR. + (std::nested_exception::operator=): Likewise. + (std::nested_exception::~nested_exception): For C++26 add constexpr + and define inline. + (std::nested_exception::rethrow_if_nested): Add _GLIBCXX26_CONSTEXPR. + (std::nested_exception::nested_ptr): Likewise. + (std::_Nested_exception::_Nested_exception): Likewise. + (std::throw_with_nested, std::rethrow_if_nested): Likewise. + * libsupc++/new (std::bad_alloc::bad_alloc): Likewise. + (std::bad_alloc::operator=): Likewise. + (std::bad_alloc::~bad_alloc): For C++26 add constexpr and define + inline. + (std::bad_alloc::what): Likewise. + (std::bad_array_new_length::bad_array_new_length): Add + _GLIBCXX26_CONSTEXPR. + (std::bad_array_new_length::~bad_array_new_length): For C++26 add + constexpr and define inline. + (std::bad_array_new_length::what): Likewise. + * libsupc++/typeinfo (std::bad_cast::bad_cast): Add + _GLIBCXX26_CONSTEXPR. + (std::bad_cast::~bad_cast): For C++26 add constexpr and define inline. + (std::bad_cast::what): Likewise. + (std::bad_typeid::bad_typeid): Add _GLIBCXX26_CONSTEXPR. + (std::bad_typeid::~bad_typeid): For C++26 add constexpr and define + inline. + (std::bad_typeid::what): Likewise. + +2025-07-10 Jakub Jelinek <jakub@redhat.com> + + * testsuite/22_locale/codecvt/codecvt_unicode.h + (ucs2_to_utf8_out_error): Comment spelling fix: bellow -> below. + (utf16_to_ucs2_in_error): Likewise. + 2025-07-09 Jonathan Wakely <jwakely@redhat.com> * include/bits/stl_uninitialized.h (__uninitialized_default): diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index b1a6206..38cea4c 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -273,6 +273,12 @@ __INT_N(__GLIBCXX_TYPE_INT_N_2) __INT_N(__GLIBCXX_TYPE_INT_N_3) #endif +#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ +// In strict modes __GLIBCXX_TYPE_INT_N_0 is not defined for __int128, +// but we want to always treat signed/unsigned __int128 as integral types. +__INT_N(__int128) +#endif + #undef __INT_N // @@ -307,6 +313,15 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) typedef __true_type __type; }; +#ifdef _GLIBCXX_USE_FLOAT128 + template<> + struct __is_floating<__float128> + { + enum { __value = 1 }; + typedef __true_type __type; + }; +#endif + #ifdef __STDCPP_FLOAT16_T__ template<> struct __is_floating<_Float16> @@ -545,17 +560,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) { enum { __width = __GLIBCXX_BITSIZE_INT_N_3 }; }; #endif -#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ - // In strict modes __is_integer<__int128> is false, - // but we want to allow memcpy between signed/unsigned __int128. - __extension__ - template<> - struct __memcpyable_integer<__int128> { enum { __width = 128 }; }; - __extension__ - template<> - struct __memcpyable_integer<unsigned __int128> { enum { __width = 128 }; }; -#endif - #if _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 && _GLIBCXX_LDOUBLE_IS_IEEE_BINARY64 template<> struct __memcpyable<double*, long double*> { enum { __value = true }; }; diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index d31e4f1..979039e 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -214,17 +214,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = make_signed_t<decltype(std::declval<_Tp>() - std::declval<_Tp>())>; }; -#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ - // __int128 is incrementable even if !integral<__int128> - template<> - struct incrementable_traits<__int128> - { using difference_type = __int128; }; - - template<> - struct incrementable_traits<unsigned __int128> - { using difference_type = __int128; }; -#endif - namespace __detail { // An iterator such that iterator_traits<_Iter> names a specialization @@ -611,24 +600,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class __max_diff_type; class __max_size_type; - __extension__ - template<typename _Tp> - concept __is_signed_int128 -#if __SIZEOF_INT128__ - = same_as<_Tp, __int128>; -#else - = false; -#endif - - __extension__ - template<typename _Tp> - concept __is_unsigned_int128 -#if __SIZEOF_INT128__ - = same_as<_Tp, unsigned __int128>; -#else - = false; -#endif - template<typename _Tp> concept __cv_bool = same_as<const volatile _Tp, const volatile bool>; @@ -636,16 +607,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION concept __integral_nonbool = integral<_Tp> && !__cv_bool<_Tp>; template<typename _Tp> - concept __is_int128 = __is_signed_int128<_Tp> || __is_unsigned_int128<_Tp>; - - template<typename _Tp> concept __is_integer_like = __integral_nonbool<_Tp> - || __is_int128<_Tp> || same_as<_Tp, __max_diff_type> || same_as<_Tp, __max_size_type>; template<typename _Tp> concept __is_signed_integer_like = signed_integral<_Tp> - || __is_signed_int128<_Tp> || same_as<_Tp, __max_diff_type>; } // namespace ranges::__detail diff --git a/libstdc++-v3/include/bits/max_size_type.h b/libstdc++-v3/include/bits/max_size_type.h index 30c5b12..a34b91a 100644 --- a/libstdc++-v3/include/bits/max_size_type.h +++ b/libstdc++-v3/include/bits/max_size_type.h @@ -65,7 +65,7 @@ namespace ranges public: __max_size_type() = default; - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> constexpr __max_size_type(_Tp __i) noexcept : _M_val(__i), _M_msb(__i < 0) @@ -74,7 +74,7 @@ namespace ranges constexpr explicit __max_size_type(const __max_diff_type& __d) noexcept; - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> constexpr explicit operator _Tp() const noexcept { return _M_val; } @@ -260,52 +260,52 @@ namespace ranges return *this; } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator+=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a + __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator-=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a - __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator*=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a * __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator/=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a / __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator%=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a % __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator&=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a & __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator|=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a | __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator^=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a ^ __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator<<=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a << __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator>>=(_Tp& __a, const __max_size_type& __b) noexcept { return (__a = static_cast<_Tp>(__a >> __b)); } @@ -447,7 +447,7 @@ namespace ranges public: __max_diff_type() = default; - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> constexpr __max_diff_type(_Tp __i) noexcept : _M_rep(__i) @@ -458,7 +458,7 @@ namespace ranges : _M_rep(__d) { } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> constexpr explicit operator _Tp() const noexcept { return static_cast<_Tp>(_M_rep); } @@ -591,52 +591,52 @@ namespace ranges return *this; } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator+=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a + __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator-=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a - __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator*=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a * __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator/=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a / __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator%=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a % __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator&=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a & __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator|=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a | __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator^=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a ^ __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator<<=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a << __b)); } - template<typename _Tp> requires integral<_Tp> || __is_int128<_Tp> + template<typename _Tp> requires integral<_Tp> friend constexpr _Tp& operator>>=(_Tp& __a, const __max_diff_type& __b) noexcept { return (__a = static_cast<_Tp>(__a >> __b)); } diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index c09f729..0251e5d 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -81,16 +81,6 @@ namespace ranges __to_unsigned_like(_Tp __t) noexcept { return static_cast<make_unsigned_t<_Tp>>(__t); } -#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ - constexpr unsigned __int128 - __to_unsigned_like(__int128 __t) noexcept - { return __t; } - - constexpr unsigned __int128 - __to_unsigned_like(unsigned __int128 __t) noexcept - { return __t; } -#endif - template<typename _Tp> using __make_unsigned_like_t = decltype(__detail::__to_unsigned_like(std::declval<_Tp>())); @@ -398,11 +388,6 @@ namespace ranges else return static_cast<make_signed_t<__size_type>>(__size); } -#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ - // For strict-ansi modes integral<__int128> is false - else if constexpr (__detail::__is_int128<__size_type>) - return static_cast<__int128>(__size); -#endif else // Must be one of __max_diff_type or __max_size_type. return __detail::__max_diff_type(__size); } diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 4d5662c..b104ec2 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -1052,13 +1052,20 @@ _GLIBCXX_END_NAMESPACE_CONTAINER __size_to_integer(unsigned __GLIBCXX_TYPE_INT_N_3 __n) { return __n; } #endif +#if defined(__STRICT_ANSI__) && defined(__SIZEOF_INT128__) + __extension__ inline _GLIBCXX_CONSTEXPR __int128 + __size_to_integer(__int128 __n) { return __n; } + __extension__ inline _GLIBCXX_CONSTEXPR unsigned __int128 + __size_to_integer(unsigned __int128 __n) { return __n; } +#endif + inline _GLIBCXX_CONSTEXPR long long __size_to_integer(float __n) { return (long long)__n; } inline _GLIBCXX_CONSTEXPR long long __size_to_integer(double __n) { return (long long)__n; } inline _GLIBCXX_CONSTEXPR long long __size_to_integer(long double __n) { return (long long)__n; } -#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) +#ifdef _GLIBCXX_USE_FLOAT128 __extension__ inline _GLIBCXX_CONSTEXPR long long __size_to_integer(__float128 __n) { return (long long)__n; } #endif diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 31385b5..df58e70 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -2050,6 +2050,15 @@ ftms = { }; }; +ftms = { + name = constexpr_exceptions; + values = { + v = 202502; + cxxmin = 26; + extra_cond = "__cpp_constexpr_exceptions >= 202411L"; + }; +}; + // Standard test specifications. stds[97] = ">= 199711L"; stds[03] = ">= 199711L"; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index aa53f29..1414dd7 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2299,4 +2299,14 @@ #endif /* !defined(__cpp_lib_bitset) && defined(__glibcxx_want_bitset) */ #undef __glibcxx_want_bitset +#if !defined(__cpp_lib_constexpr_exceptions) +# if (__cplusplus > 202302L) && (__cpp_constexpr_exceptions >= 202411L) +# define __glibcxx_constexpr_exceptions 202502L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_constexpr_exceptions) +# define __cpp_lib_constexpr_exceptions 202502L +# endif +# endif +#endif /* !defined(__cpp_lib_constexpr_exceptions) && defined(__glibcxx_want_constexpr_exceptions) */ +#undef __glibcxx_want_constexpr_exceptions + #undef __glibcxx_want_all diff --git a/libstdc++-v3/include/ext/numeric_traits.h b/libstdc++-v3/include/ext/numeric_traits.h index 2cd8943..6786dc6 100644 --- a/libstdc++-v3/include/ext/numeric_traits.h +++ b/libstdc++-v3/include/ext/numeric_traits.h @@ -126,12 +126,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_3, __GLIBCXX_BITSIZE_INT_N_3) #endif -#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ - // In strict modes __is_integer<__int128> is false, - // but we still want to define __numeric_traits_integer<__int128>. - _GLIBCXX_INT_N_TRAITS(__int128, 128) -#endif - #undef _GLIBCXX_INT_N_TRAITS #if __cplusplus >= 201103L diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index dda49ce..8cf2c0b 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -390,6 +390,10 @@ _GLIBCXX_TO_CHARS(unsigned __GLIBCXX_TYPE_INT_N_2) _GLIBCXX_TO_CHARS(signed __GLIBCXX_TYPE_INT_N_3) _GLIBCXX_TO_CHARS(unsigned __GLIBCXX_TYPE_INT_N_3) #endif +#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__ +_GLIBCXX_TO_CHARS(signed __int128) +_GLIBCXX_TO_CHARS(unsigned __int128) +#endif #undef _GLIBCXX_TO_CHARS // _GLIBCXX_RESOLVE_LIB_DEFECTS diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index d584b81..d63c6fc 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -1854,20 +1854,6 @@ namespace __format __align, __nfill, __fill_char); } -#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__ - template<typename _Tp> - using make_unsigned_t - = typename __conditional_t<(sizeof(_Tp) <= sizeof(long long)), - std::make_unsigned<_Tp>, - type_identity<unsigned __int128>>::type; - - // std::to_chars is not overloaded for int128 in strict mode. - template<typename _Int> - static to_chars_result - to_chars(char* __first, char* __last, _Int __value, int __base) - { return std::__to_chars_i<_Int>(__first, __last, __value, __base); } -#endif - _Spec<_CharT> _M_spec{}; }; diff --git a/libstdc++-v3/include/std/limits b/libstdc++-v3/include/std/limits index 2331c25..3567a32 100644 --- a/libstdc++-v3/include/std/limits +++ b/libstdc++-v3/include/std/limits @@ -1639,7 +1639,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #define __INT_N_U201103(TYPE) #endif -#if !defined(__STRICT_ANSI__) #ifdef __GLIBCXX_TYPE_INT_N_0 __INT_N(__GLIBCXX_TYPE_INT_N_0, __GLIBCXX_BITSIZE_INT_N_0, __INT_N_201103 (__GLIBCXX_TYPE_INT_N_0), @@ -1661,7 +1660,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __INT_N_U201103 (__GLIBCXX_TYPE_INT_N_3)) #endif -#elif defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ +#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__ __INT_N(__int128, 128, __INT_N_201103 (__int128), __INT_N_U201103 (__int128)) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 0554111..78a5ee8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -464,6 +464,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3> : public true_type { }; #endif + +#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__ + __extension__ + template<> + struct __is_integral_helper<__int128> + : public true_type { }; + + __extension__ + template<> + struct __is_integral_helper<unsigned __int128> + : public true_type { }; +#endif + /// @endcond /// is_integral @@ -519,7 +532,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public true_type { }; #endif -#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) +#ifdef _GLIBCXX_USE_FLOAT128 template<> struct __is_floating_point_helper<__float128> : public true_type { }; @@ -1927,6 +1940,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3> { using __type = unsigned __GLIBCXX_TYPE_INT_N_3; }; #endif +#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__ + __extension__ + template<> + struct __make_unsigned<__int128> + { using __type = unsigned __int128; }; +#endif // Select between integral and enum: not possible to be both. template<typename _Tp, @@ -2087,6 +2106,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3> { using __type = __GLIBCXX_TYPE_INT_N_3; }; #endif +#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__ + __extension__ + template<> + struct __make_signed<unsigned __int128> + { using __type = __int128; }; +#endif // Select between integral and enum: not possible to be both. template<typename _Tp, diff --git a/libstdc++-v3/libsupc++/exception b/libstdc++-v3/libsupc++/exception index 61d4131..25ce8d9 100644 --- a/libstdc++-v3/libsupc++/exception +++ b/libstdc++-v3/libsupc++/exception @@ -57,8 +57,16 @@ namespace std _GLIBCXX_VISIBILITY(default) class bad_exception : public exception { public: - bad_exception() _GLIBCXX_USE_NOEXCEPT { } + _GLIBCXX26_CONSTEXPR bad_exception() _GLIBCXX_USE_NOEXCEPT { } +#if __cplusplus >= 202400L + constexpr virtual ~bad_exception() _GLIBCXX_TXN_SAFE_DYN noexcept {} + + constexpr virtual const char* what() const _GLIBCXX_TXN_SAFE_DYN noexcept + { + return "std::bad_exception"; + } +#else // This declaration is not useless: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 virtual ~bad_exception() _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT; @@ -66,6 +74,7 @@ namespace std _GLIBCXX_VISIBILITY(default) // See comment in eh_exception.cc. virtual const char* what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_USE_NOEXCEPT; +#endif }; /// If you write a replacement %terminate handler, it must be of this type. diff --git a/libstdc++-v3/libsupc++/exception.h b/libstdc++-v3/libsupc++/exception.h index f8bca91..efb5fea 100644 --- a/libstdc++-v3/libsupc++/exception.h +++ b/libstdc++-v3/libsupc++/exception.h @@ -61,19 +61,28 @@ namespace std _GLIBCXX_VISIBILITY(default) class exception { public: - exception() _GLIBCXX_NOTHROW { } + _GLIBCXX26_CONSTEXPR exception() _GLIBCXX_NOTHROW { } +#if __cplusplus >= 202400L + constexpr virtual ~exception() _GLIBCXX_TXN_SAFE_DYN noexcept {} +#else virtual ~exception() _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW; +#endif #if __cplusplus >= 201103L - exception(const exception&) = default; - exception& operator=(const exception&) = default; - exception(exception&&) = default; - exception& operator=(exception&&) = default; + _GLIBCXX26_CONSTEXPR exception(const exception&) = default; + _GLIBCXX26_CONSTEXPR exception& operator=(const exception&) = default; + _GLIBCXX26_CONSTEXPR exception(exception&&) = default; + _GLIBCXX26_CONSTEXPR exception& operator=(exception&&) = default; #endif /** Returns a C-style character string describing the general cause * of the current error. */ +#if __cplusplus >= 202400L + constexpr virtual const char* + what() const _GLIBCXX_TXN_SAFE_DYN noexcept { return "std::exception"; } +#else virtual const char* what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW; +#endif }; /// @} diff --git a/libstdc++-v3/libsupc++/exception_ptr.h b/libstdc++-v3/libsupc++/exception_ptr.h index a6ff8c0..ee00915 100644 --- a/libstdc++-v3/libsupc++/exception_ptr.h +++ b/libstdc++-v3/libsupc++/exception_ptr.h @@ -75,14 +75,15 @@ namespace std _GLIBCXX_VISIBILITY(default) exception_ptr current_exception() _GLIBCXX_USE_NOEXCEPT; template<typename _Ex> - exception_ptr make_exception_ptr(_Ex) _GLIBCXX_USE_NOEXCEPT; + _GLIBCXX26_CONSTEXPR exception_ptr make_exception_ptr(_Ex) + _GLIBCXX_USE_NOEXCEPT; /// Throw the object pointed to by the exception_ptr. void rethrow_exception(exception_ptr) __attribute__ ((__noreturn__)); #if __cpp_lib_exception_ptr_cast >= 202506L template<typename _Ex> - const _Ex* exception_ptr_cast(const exception_ptr&) noexcept; + constexpr const _Ex* exception_ptr_cast(const exception_ptr&) noexcept; template<typename _Ex> void exception_ptr_cast(const exception_ptr&&) = delete; #endif @@ -105,7 +106,25 @@ namespace std _GLIBCXX_VISIBILITY(default) { void* _M_exception_object; +#if __cplusplus >= 202400L + constexpr explicit exception_ptr(void* __e) noexcept + : _M_exception_object(__e) + { + if (_M_exception_object) + { +#if __cpp_if_consteval >= 202106L \ + && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref) + if consteval { + __builtin_eh_ptr_adjust_ref(_M_exception_object, 1); + return; + } +#endif + _M_addref(); + } + } +#else explicit exception_ptr(void* __e) _GLIBCXX_USE_NOEXCEPT; +#endif void _M_addref() _GLIBCXX_USE_NOEXCEPT; void _M_release() _GLIBCXX_USE_NOEXCEPT; @@ -115,26 +134,29 @@ namespace std _GLIBCXX_VISIBILITY(default) friend exception_ptr std::current_exception() _GLIBCXX_USE_NOEXCEPT; friend void std::rethrow_exception(exception_ptr); template<typename _Ex> - friend exception_ptr std::make_exception_ptr(_Ex) _GLIBCXX_USE_NOEXCEPT; + friend _GLIBCXX26_CONSTEXPR exception_ptr std::make_exception_ptr(_Ex) + _GLIBCXX_USE_NOEXCEPT; #if __cpp_lib_exception_ptr_cast >= 202506L template<typename _Ex> - friend const _Ex* std::exception_ptr_cast(const exception_ptr&) noexcept; + friend constexpr const _Ex* std::exception_ptr_cast(const exception_ptr&) + noexcept; #endif const void* _M_exception_ptr_cast(const type_info&) const _GLIBCXX_USE_NOEXCEPT; public: - exception_ptr() _GLIBCXX_USE_NOEXCEPT; + _GLIBCXX26_CONSTEXPR exception_ptr() _GLIBCXX_USE_NOEXCEPT; - exception_ptr(const exception_ptr&) _GLIBCXX_USE_NOEXCEPT; + _GLIBCXX26_CONSTEXPR exception_ptr(const exception_ptr&) + _GLIBCXX_USE_NOEXCEPT; #if __cplusplus >= 201103L - exception_ptr(nullptr_t) noexcept + _GLIBCXX26_CONSTEXPR exception_ptr(nullptr_t) noexcept : _M_exception_object(nullptr) { } - exception_ptr(exception_ptr&& __o) noexcept + _GLIBCXX26_CONSTEXPR exception_ptr(exception_ptr&& __o) noexcept : _M_exception_object(__o._M_exception_object) { __o._M_exception_object = nullptr; } #endif @@ -146,11 +168,11 @@ namespace std _GLIBCXX_VISIBILITY(default) exception_ptr(__safe_bool) _GLIBCXX_USE_NOEXCEPT; #endif - exception_ptr& + _GLIBCXX26_CONSTEXPR exception_ptr& operator=(const exception_ptr&) _GLIBCXX_USE_NOEXCEPT; #if __cplusplus >= 201103L - exception_ptr& + _GLIBCXX26_CONSTEXPR exception_ptr& operator=(exception_ptr&& __o) noexcept { exception_ptr(static_cast<exception_ptr&&>(__o)).swap(*this); @@ -158,9 +180,9 @@ namespace std _GLIBCXX_VISIBILITY(default) } #endif - ~exception_ptr() _GLIBCXX_USE_NOEXCEPT; + _GLIBCXX26_CONSTEXPR ~exception_ptr() _GLIBCXX_USE_NOEXCEPT; - void + _GLIBCXX26_CONSTEXPR void swap(exception_ptr&) _GLIBCXX_USE_NOEXCEPT; #ifdef _GLIBCXX_EH_PTR_COMPAT @@ -172,13 +194,13 @@ namespace std _GLIBCXX_VISIBILITY(default) #endif #if __cplusplus >= 201103L - explicit operator bool() const noexcept + _GLIBCXX26_CONSTEXPR explicit operator bool() const noexcept { return _M_exception_object; } #endif #if __cpp_impl_three_way_comparison >= 201907L \ && ! defined _GLIBCXX_EH_PTR_RELOPS_COMPAT - friend bool + _GLIBCXX26_CONSTEXPR friend bool operator==(const exception_ptr&, const exception_ptr&) noexcept = default; #else friend _GLIBCXX_EH_PTR_USED bool @@ -198,31 +220,49 @@ namespace std _GLIBCXX_VISIBILITY(default) }; _GLIBCXX_EH_PTR_USED - inline + _GLIBCXX26_CONSTEXPR inline exception_ptr::exception_ptr() _GLIBCXX_USE_NOEXCEPT : _M_exception_object(0) { } _GLIBCXX_EH_PTR_USED - inline + _GLIBCXX26_CONSTEXPR inline exception_ptr::exception_ptr(const exception_ptr& __other) _GLIBCXX_USE_NOEXCEPT : _M_exception_object(__other._M_exception_object) { if (_M_exception_object) - _M_addref(); + { +#if __cpp_if_consteval >= 202106L \ + && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref) + if consteval { + __builtin_eh_ptr_adjust_ref(_M_exception_object, 1); + return; + } +#endif + _M_addref(); + } } _GLIBCXX_EH_PTR_USED - inline + _GLIBCXX26_CONSTEXPR inline exception_ptr::~exception_ptr() _GLIBCXX_USE_NOEXCEPT { if (_M_exception_object) - _M_release(); + { +#if __cpp_if_consteval >= 202106L \ + && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref) + if consteval { + __builtin_eh_ptr_adjust_ref(_M_exception_object, -1); + return; + } +#endif + _M_release(); + } } _GLIBCXX_EH_PTR_USED - inline exception_ptr& + _GLIBCXX26_CONSTEXPR inline exception_ptr& exception_ptr::operator=(const exception_ptr& __other) _GLIBCXX_USE_NOEXCEPT { exception_ptr(__other).swap(*this); @@ -230,7 +270,7 @@ namespace std _GLIBCXX_VISIBILITY(default) } _GLIBCXX_EH_PTR_USED - inline void + _GLIBCXX26_CONSTEXPR inline void exception_ptr::swap(exception_ptr &__other) _GLIBCXX_USE_NOEXCEPT { void *__tmp = _M_exception_object; @@ -239,7 +279,7 @@ namespace std _GLIBCXX_VISIBILITY(default) } /// @relates exception_ptr - inline void + _GLIBCXX26_CONSTEXPR inline void swap(exception_ptr& __lhs, exception_ptr& __rhs) { __lhs.swap(__rhs); } @@ -258,9 +298,21 @@ namespace std _GLIBCXX_VISIBILITY(default) /// Obtain an exception_ptr pointing to a copy of the supplied object. #if (__cplusplus >= 201103L && __cpp_rtti) || __cpp_exceptions template<typename _Ex> - exception_ptr + _GLIBCXX26_CONSTEXPR exception_ptr make_exception_ptr(_Ex __ex) _GLIBCXX_USE_NOEXCEPT { +#if __cplusplus >= 202400L + if consteval { + try + { + throw __ex; + } + catch(...) + { + return current_exception(); + } + } +#endif #if __cplusplus >= 201103L && __cpp_rtti using _Ex2 = typename decay<_Ex>::type; void* __e = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ex)); @@ -293,7 +345,7 @@ namespace std _GLIBCXX_VISIBILITY(default) // instead of a working one compiled with RTTI and/or exceptions enabled. template<typename _Ex> __attribute__ ((__always_inline__)) - inline exception_ptr + _GLIBCXX26_CONSTEXPR inline exception_ptr make_exception_ptr(_Ex) _GLIBCXX_USE_NOEXCEPT { return exception_ptr(); } #endif @@ -301,11 +353,33 @@ namespace std _GLIBCXX_VISIBILITY(default) #if __cpp_lib_exception_ptr_cast >= 202506L template<typename _Ex> [[__gnu__::__always_inline__]] - inline const _Ex* exception_ptr_cast(const exception_ptr& __p) noexcept + constexpr const _Ex* exception_ptr_cast(const exception_ptr& __p) noexcept { + static_assert(!std::is_const_v<_Ex>); + static_assert(!std::is_reference_v<_Ex>); + static_assert(std::is_object_v<_Ex>); + static_assert(!std::is_array_v<_Ex>); + static_assert(!std::is_pointer_v<_Ex>); + static_assert(!std::is_member_pointer_v<_Ex>); #ifdef __cpp_rtti - const type_info &__id = typeid(const _Ex&); - return static_cast<const _Ex*>(__p._M_exception_ptr_cast(__id)); + if consteval { + if (__p._M_exception_object) + try + { + std::rethrow_exception(__p); + } + catch (const _Ex& __exc) + { + return &__exc; + } + catch (...) + { + } + return nullptr; + } else { + const type_info &__id = typeid(const _Ex&); + return static_cast<const _Ex*>(__p._M_exception_ptr_cast(__id)); + } #else return nullptr; #endif diff --git a/libstdc++-v3/libsupc++/nested_exception.h b/libstdc++-v3/libsupc++/nested_exception.h index c9f63e5..aff47bc 100644 --- a/libstdc++-v3/libsupc++/nested_exception.h +++ b/libstdc++-v3/libsupc++/nested_exception.h @@ -62,17 +62,24 @@ namespace std _GLIBCXX_VISIBILITY(default) public: /// The default constructor stores the current exception (if any). + _GLIBCXX26_CONSTEXPR nested_exception() noexcept : _M_ptr(current_exception()) { } + _GLIBCXX26_CONSTEXPR nested_exception(const nested_exception&) noexcept = default; + _GLIBCXX26_CONSTEXPR nested_exception& operator=(const nested_exception&) noexcept = default; +#if __cplusplus >= 202400L + constexpr virtual ~nested_exception() noexcept {} +#else virtual ~nested_exception() noexcept; +#endif /// Rethrow the stored exception, or terminate if none was stored. [[noreturn]] - void + _GLIBCXX26_CONSTEXPR void rethrow_nested() const { if (_M_ptr) @@ -81,7 +88,7 @@ namespace std _GLIBCXX_VISIBILITY(default) } /// Access the stored exception. - exception_ptr + _GLIBCXX26_CONSTEXPR exception_ptr nested_ptr() const noexcept { return _M_ptr; } }; @@ -91,11 +98,11 @@ namespace std _GLIBCXX_VISIBILITY(default) template<typename _Except> struct _Nested_exception : public _Except, public nested_exception { - explicit _Nested_exception(const _Except& __ex) + _GLIBCXX26_CONSTEXPR explicit _Nested_exception(const _Except& __ex) : _Except(__ex) { } - explicit _Nested_exception(_Except&& __ex) + _GLIBCXX26_CONSTEXPR explicit _Nested_exception(_Except&& __ex) : _Except(static_cast<_Except&&>(__ex)) { } }; @@ -144,7 +151,7 @@ namespace std _GLIBCXX_VISIBILITY(default) */ template<typename _Tp> [[noreturn]] - inline void + _GLIBCXX26_CONSTEXPR inline void throw_with_nested(_Tp&& __t) { using _Up = typename decay<_Tp>::type; @@ -204,7 +211,7 @@ namespace std _GLIBCXX_VISIBILITY(default) # if ! __cpp_rtti [[__gnu__::__always_inline__]] #endif - inline void + _GLIBCXX26_CONSTEXPR inline void rethrow_if_nested(const _Ex& __ex) { const _Ex* __ptr = __builtin_addressof(__ex); diff --git a/libstdc++-v3/libsupc++/new b/libstdc++-v3/libsupc++/new index a550373..fb36dae 100644 --- a/libstdc++-v3/libsupc++/new +++ b/libstdc++-v3/libsupc++/new @@ -66,33 +66,51 @@ namespace std class bad_alloc : public exception { public: - bad_alloc() throw() { } + _GLIBCXX26_CONSTEXPR bad_alloc() throw() { } #if __cplusplus >= 201103L - bad_alloc(const bad_alloc&) = default; - bad_alloc& operator=(const bad_alloc&) = default; + _GLIBCXX26_CONSTEXPR bad_alloc(const bad_alloc&) = default; + _GLIBCXX26_CONSTEXPR bad_alloc& operator=(const bad_alloc&) = default; #endif +#if __cplusplus >= 202400L + constexpr virtual ~bad_alloc() noexcept {} + + constexpr virtual const char* what() const noexcept + { + return "std::bad_alloc"; + } +#else // This declaration is not useless: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 virtual ~bad_alloc() throw(); // See comment in eh_exception.cc. virtual const char* what() const throw(); +#endif }; #if __cplusplus >= 201103L class bad_array_new_length : public bad_alloc { public: - bad_array_new_length() throw() { } + _GLIBCXX26_CONSTEXPR bad_array_new_length() throw() { } +#if __cplusplus >= 202400L + constexpr virtual ~bad_array_new_length() noexcept {} + + constexpr virtual const char* what() const noexcept + { + return "std::bad_array_new_length"; + } +#else // This declaration is not useless: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 virtual ~bad_array_new_length() throw(); // See comment in eh_exception.cc. virtual const char* what() const throw(); +#endif }; #endif diff --git a/libstdc++-v3/libsupc++/typeinfo b/libstdc++-v3/libsupc++/typeinfo index 0a94b86..a31be7c 100644 --- a/libstdc++-v3/libsupc++/typeinfo +++ b/libstdc++-v3/libsupc++/typeinfo @@ -224,14 +224,23 @@ namespace std class bad_cast : public exception { public: - bad_cast() _GLIBCXX_USE_NOEXCEPT { } + _GLIBCXX26_CONSTEXPR bad_cast() _GLIBCXX_USE_NOEXCEPT { } +#if __cplusplus >= 202400L + constexpr virtual ~bad_cast() noexcept {} + + constexpr virtual const char* what() const noexcept + { + return "std::bad_cast"; + } +#else // This declaration is not useless: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 virtual ~bad_cast() _GLIBCXX_USE_NOEXCEPT; // See comment in eh_exception.cc. virtual const char* what() const _GLIBCXX_USE_NOEXCEPT; +#endif }; /** @@ -241,14 +250,23 @@ namespace std class bad_typeid : public exception { public: - bad_typeid () _GLIBCXX_USE_NOEXCEPT { } + _GLIBCXX26_CONSTEXPR bad_typeid () _GLIBCXX_USE_NOEXCEPT { } +#if __cplusplus >= 202400L + constexpr virtual ~bad_typeid() noexcept {} + + constexpr virtual const char* what() const noexcept + { + return "std::bad_typeid"; + } +#else // This declaration is not useless: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 virtual ~bad_typeid() _GLIBCXX_USE_NOEXCEPT; // See comment in eh_exception.cc. virtual const char* what() const _GLIBCXX_USE_NOEXCEPT; +#endif }; } // namespace std diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/exception_ptr_cast.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/exception_ptr_cast.cc index 6a6fbfe..de371d1 100644 --- a/libstdc++-v3/testsuite/18_support/exception_ptr/exception_ptr_cast.cc +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/exception_ptr_cast.cc @@ -30,13 +30,13 @@ struct A { int a; }; struct B : A {}; struct C : B {}; struct D {}; -struct E : virtual C { int e; virtual ~E () {} }; +struct E : virtual C { int e; constexpr virtual ~E () {} }; struct F : virtual E, virtual C { int f; }; struct G : virtual F, virtual C, virtual E { - G () : g (4) { a = 1; e = 2; f = 3; } int g; + constexpr G () : g (4) { a = 1; e = 2; f = 3; } int g; }; -void test01() +constexpr bool test01(bool x) { auto a = std::make_exception_ptr(C{ 42 }); auto b = std::exception_ptr_cast<C>(a); @@ -73,9 +73,20 @@ void test01() auto n = std::exception_ptr_cast<G>(a); VERIFY( n == nullptr ); } + if (x) + throw 1; + return true; } +static_assert(test01(false)); + int main() { - test01(); + try + { + test01(true); + } + catch (...) + { + } } |